@ -30,8 +30,6 @@
# include "google/protobuf/compiler/objectivec/field.h"
# include <iostream>
# include <ostream>
# include <string>
# include <vector>
@ -69,12 +67,6 @@ void SetCommonFieldVariables(
UnCamelCaseFieldName ( camel_case_name , descriptor ) ) ;
const bool needs_custom_name = ( raw_field_name ! = un_camel_case_name ) ;
SourceLocation location ;
if ( descriptor - > GetSourceLocation ( & location ) ) {
( * variables ) [ " comments " ] = BuildCommentsString ( location , true ) ;
} else {
( * variables ) [ " comments " ] = " \n " ;
}
const std : : string & classname = ClassName ( descriptor - > containing_type ( ) ) ;
( * variables ) [ " classname " ] = classname ;
( * variables ) [ " name " ] = camel_case_name ;
@ -222,7 +214,8 @@ FieldGenerator::FieldGenerator(const FieldDescriptor* descriptor)
}
void FieldGenerator : : GenerateFieldNumberConstant ( io : : Printer * printer ) const {
printer - > Print ( variables_ , " $field_number_name$ = $field_number$, \n " ) ;
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit ( " $field_number_name$ = $field_number$, \n " ) ;
}
void FieldGenerator : : GenerateCFunctionDeclarations ( io : : Printer * printer ) const {
@ -248,36 +241,27 @@ void FieldGenerator::DetermineObjectiveCClassDefinitions(
void FieldGenerator : : GenerateFieldDescription ( io : : Printer * printer ,
bool include_default ) const {
// Printed in the same order as the structure decl.
if ( include_default ) {
// clang-format off
printer - > Print (
variables_ ,
" { \n "
" .defaultValue.$default_name$ = $default$, \n "
" .core.name = \" $name$ \" , \n "
" .core.dataTypeSpecific.$dataTypeSpecific_name$ = $dataTypeSpecific_value$, \n "
" .core.number = $field_number_name$, \n "
" .core.hasIndex = $has_index$, \n "
" .core.offset = $storage_offset_value$,$storage_offset_comment$ \n "
" .core.flags = $fieldflags$, \n "
" .core.dataType = GPBDataType$field_type$, \n "
" }, \n " ) ;
// clang-format on
} else {
// clang-format off
printer - > Print (
variables_ ,
" { \n "
" .name = \" $name$ \" , \n "
" .dataTypeSpecific.$dataTypeSpecific_name$ = $dataTypeSpecific_value$, \n "
" .number = $field_number_name$, \n "
" .hasIndex = $has_index$, \n "
" .offset = $storage_offset_value$,$storage_offset_comment$ \n "
" .flags = $fieldflags$, \n "
" .dataType = GPBDataType$field_type$, \n "
" }, \n " ) ;
// clang-format on
}
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit (
{ { " prefix " , include_default ? " .core " : " " } ,
{ " maybe_default " ,
[ & ] {
if ( include_default ) {
printer - > Emit ( " .defaultValue.$default_name$ = $default$, \n " ) ;
}
} } } ,
R " objc(
{
$ maybe_default $ ,
$ prefix $ . name = " $name$ " ,
$ prefix $ . dataTypeSpecific . $ dataTypeSpecific_name $ = $ dataTypeSpecific_value $ ,
$ prefix $ . number = $ field_number_name $ ,
$ prefix $ . hasIndex = $ has_index $ ,
$ prefix $ . offset = $ storage_offset_value $ , $ storage_offset_comment $
$ prefix $ . flags = $ fieldflags $ ,
$ prefix $ . dataType = GPBDataType $ field_type $ ,
} ,
) objc " );
}
void FieldGenerator : : SetRuntimeHasBit ( int has_index ) {
@ -321,33 +305,34 @@ SingleFieldGenerator::SingleFieldGenerator(const FieldDescriptor* descriptor)
void SingleFieldGenerator : : GenerateFieldStorageDeclaration (
io : : Printer * printer ) const {
printer - > Print ( variables_ , " $storage_type$ $name$; \n " ) ;
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit ( " $storage_type$ $name$; \n " ) ;
}
void SingleFieldGenerator : : GeneratePropertyDeclaration (
io : : Printer * printer ) const {
printer - > Print ( variables_ , " $comments$ " ) ;
// clang-format off
printer - > Print (
variables_ ,
" @property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$; \n " ) ;
// clang-format on
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit (
{ { " comments " , [ & ] { EmitCommentsString ( printer , descriptor_ , true ) ; } } } ,
R " objc(
$ comments $
@ property ( nonatomic , readwrite ) $ property_type $ $ name $ $ deprecated_attribute $ ;
) objc " );
if ( WantsHasProperty ( ) ) {
// clang-format off
printer - > Print (
variables_ ,
" @property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$; \n " ) ;
// clang-format on
printer - > Emit ( R " objc(
@ property ( nonatomic , readwrite ) BOOL has $ capitalized_name $ $ deprecated_attribute $ ;
) objc " );
}
printer - > Prin t( " \n " ) ;
printer - > Emit ( " \n " ) ;
}
void SingleFieldGenerator : : GeneratePropertyImplementation (
io : : Printer * printer ) const {
auto vars = printer - > WithVars ( variables_ ) ;
if ( WantsHasProperty ( ) ) {
printer - > Print ( variables_ , " @dynamic has$capitalized_name$, $name$; \n " ) ;
printer - > Emit ( " @dynamic has$capitalized_name$, $name$; \n " ) ;
} else {
printer - > Print ( variables_ , " @dynamic $name$; \n " ) ;
printer - > Emit ( " @dynamic $name$; \n " ) ;
}
}
@ -369,7 +354,8 @@ ObjCObjFieldGenerator::ObjCObjFieldGenerator(const FieldDescriptor* descriptor)
void ObjCObjFieldGenerator : : GenerateFieldStorageDeclaration (
io : : Printer * printer ) const {
printer - > Print ( variables_ , " $storage_type$ *$name$; \n " ) ;
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit ( " $storage_type$ *$name$; \n " ) ;
}
void ObjCObjFieldGenerator : : GeneratePropertyDeclaration (
@ -378,36 +364,32 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
// it uses pointers and deals with Objective-C's rules around storage name
// conventions (init*, new*, etc.)
printer - > Print ( variables_ , " $comments$ " ) ;
// clang-format off
printer - > Print (
variables_ ,
" @property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$deprecated_attribute$; \n " ) ;
// clang-format on
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit (
{ { " comments " , [ & ] { EmitCommentsString ( printer , descriptor_ , true ) ; } } } ,
R " objc(
$ comments $
@ property ( nonatomic , readwrite , $ property_storage_attribute $ , null_resettable ) $ property_type $ * $ name $ $ storage_attribute $ $ deprecated_attribute $ ;
) objc " );
if ( WantsHasProperty ( ) ) {
// clang-format off
printer - > Print (
variables_ ,
" /** Test to see if @c $name$ has been set. */ \n "
" @property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$; \n " ) ;
// clang-format on
printer - > Emit ( R " objc(
/** Test to see if @c $name$ has been set. */
@ property ( nonatomic , readwrite ) BOOL has $ capitalized_name $ $ deprecated_attribute $ ;
) objc " );
}
if ( IsInitName ( variables_ . find ( " name " ) - > second ) ) {
// If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
printer - > Print ( variables_ ,
" - ($property_type$ *)$name$ "
" GPB_METHOD_FAMILY_NONE$deprecated_attribute$; \n " ) ;
printer - > Emit ( R " objc(
- ( $ property_type $ * ) $ name $ GPB_METHOD_FAMILY_NONE $ deprecated_attribute $ ;
) objc " ) ;
}
printer - > Prin t( " \n " ) ;
printer - > Emi t( " \n " ) ;
}
RepeatedFieldGenerator : : RepeatedFieldGenerator (
const FieldDescriptor * descriptor )
: ObjCObjFieldGenerator ( descriptor ) {
// Default to no comment and let the cases needing it fill it in.
variables_ [ " array_comment " ] = " " ;
}
: ObjCObjFieldGenerator ( descriptor ) { }
void RepeatedFieldGenerator : : FinishInitialization ( ) {
FieldGenerator : : FinishInitialization ( ) ;
@ -418,12 +400,14 @@ void RepeatedFieldGenerator::FinishInitialization() {
void RepeatedFieldGenerator : : GenerateFieldStorageDeclaration (
io : : Printer * printer ) const {
printer - > Print ( variables_ , " $array_storage_type$ *$name$; \n " ) ;
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit ( " $array_storage_type$ *$name$; \n " ) ;
}
void RepeatedFieldGenerator : : GeneratePropertyImplementation (
io : : Printer * printer ) const {
printer - > Print ( variables_ , " @dynamic $name$, $name$_Count; \n " ) ;
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit ( " @dynamic $name$, $name$_Count; \n " ) ;
}
void RepeatedFieldGenerator : : GeneratePropertyDeclaration (
@ -434,30 +418,35 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
// dealing with needing Objective-C's rules around storage name conventions
// (init*, new*, etc.)
// clang-format off
printer - > Print (
variables_ ,
" $comments$ "
" $array_comment$ "
" @property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$; \n "
" /** The number of items in @c $name$ without causing the container to be created. */ \n "
" @property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$; \n " ) ;
// clang-format on
auto vars = printer - > WithVars ( variables_ ) ;
printer - > Emit (
{ { " comments " , [ & ] { EmitCommentsString ( printer , descriptor_ , true ) ; } } ,
{ " array_comment " , [ & ] { EmitArrayComment ( printer ) ; } } } ,
R " objc(
$ comments $
$ array_comment $
@ property ( nonatomic , readwrite , strong , null_resettable ) $ array_property_type $ * $ name $ $ storage_attribute $ $ deprecated_attribute $ ;
/** The number of items in @c $name$ without causing the container to be created. */
@ property ( nonatomic , readonly ) NSUInteger $ name $ _Count $ deprecated_attribute $ ;
) objc " );
if ( IsInitName ( variables_ . find ( " name " ) - > second ) ) {
// If property name starts with init we need to annotate it to get past ARC.
// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
// clang-format off
printer - > Print ( variables_ ,
" - ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$; \n " ) ;
// clang-format on
printer - > Emit ( R " objc(
- ( $ array_property_type $ * ) $ name $ GPB_METHOD_FAMILY_NONE $ deprecated_attribute $ ;
) objc " );
}
printer - > Prin t( " \n " ) ;
printer - > Emi t( " \n " ) ;
}
bool RepeatedFieldGenerator : : RuntimeUsesHasBit ( ) const {
return false ; // The array (or map/dict) having anything is what is used.
}
void RepeatedFieldGenerator : : EmitArrayComment ( io : : Printer * printer ) const {
// Nothing for the default
}
FieldGeneratorMap : : FieldGeneratorMap ( const Descriptor * descriptor )
: descriptor_ ( descriptor ) ,
field_generators_ ( descriptor - > field_count ( ) ) ,