Add clang-format directives.

The sources haven't yet been reformatted, but this get things into a better
state where that can start to be done.
pull/10736/head
Thomas Van Lenten 2 years ago
parent 5028da4153
commit 2b42bea6e7
  1. 52
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 4
      src/google/protobuf/compiler/objectivec/enum_field.cc
  3. 36
      src/google/protobuf/compiler/objectivec/extension.cc
  4. 16
      src/google/protobuf/compiler/objectivec/field.cc
  5. 57
      src/google/protobuf/compiler/objectivec/file.cc
  6. 2
      src/google/protobuf/compiler/objectivec/import_writer.cc
  7. 28
      src/google/protobuf/compiler/objectivec/message.cc
  8. 8
      src/google/protobuf/compiler/objectivec/oneof.cc

@ -130,13 +130,15 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
if (HasPreservingUnknownEnumSemantics(descriptor_->file())) { if (HasPreservingUnknownEnumSemantics(descriptor_->file())) {
// Include the unknown value. // Include the unknown value.
printer->Print( printer->Print(
"/**\n" // clang-format off
" * Value used if any message's field encounters a value that is not defined\n" "/**\n"
" * by this enum. The message will also have C functions to get/set the rawValue\n" " * Value used if any message's field encounters a value that is not defined\n"
" * of the field.\n" " * by this enum. The message will also have C functions to get/set the rawValue\n"
" **/\n" " * of the field.\n"
"$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n", " **/\n"
"name", name_); "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n",
// clang-format on
"name", name_);
} }
for (int i = 0; i < all_values_.size(); i++) { for (int i = 0; i < all_values_.size(); i++) {
if (alias_values_to_skip_.find(all_values_[i]) != alias_values_to_skip_.end()) { if (alias_values_to_skip_.find(all_values_[i]) != alias_values_to_skip_.end()) {
@ -160,6 +162,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
} }
printer->Outdent(); printer->Outdent();
printer->Print( printer->Print(
// clang-format off
"};\n" "};\n"
"\n" "\n"
"GPBEnumDescriptor *$name$_EnumDescriptor(void);\n" "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n"
@ -169,6 +172,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
" * the time this source was generated.\n" " * the time this source was generated.\n"
" **/\n" " **/\n"
"BOOL $name$_IsValidValue(int32_t value);\n" "BOOL $name$_IsValidValue(int32_t value);\n"
// clang-format on
"\n", "\n",
"name", name_); "name", name_);
} }
@ -199,9 +203,11 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
} }
printer->Print( printer->Print(
// clang-format off
"GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n" "GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
" static _Atomic(GPBEnumDescriptor*) descriptor = nil;\n" " static _Atomic(GPBEnumDescriptor*) descriptor = nil;\n"
" if (!descriptor) {\n", " if (!descriptor) {\n",
// clang-format on
"name", name_); "name", name_);
static const int kBytesPerLine = 40; // allow for escaping static const int kBytesPerLine = 40; // allow for escaping
@ -222,15 +228,18 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
if (text_format_decode_data.num_entries() == 0) { if (text_format_decode_data.num_entries() == 0) {
printer->Print( printer->Print(
// clang-format off
" GPBEnumDescriptor *worker =\n" " GPBEnumDescriptor *worker =\n"
" [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n" " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
" valueNames:valueNames\n" " valueNames:valueNames\n"
" values:values\n" " values:values\n"
" count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n" " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
" enumVerifier:$name$_IsValidValue];\n", " enumVerifier:$name$_IsValidValue];\n",
// clang-format on
"name", name_); "name", name_);
} else { } else {
printer->Print( printer->Print(
// clang-format off
" static const char *extraTextFormatInfo = \"$extraTextFormatInfo$\";\n" " static const char *extraTextFormatInfo = \"$extraTextFormatInfo$\";\n"
" GPBEnumDescriptor *worker =\n" " GPBEnumDescriptor *worker =\n"
" [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n" " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
@ -239,21 +248,26 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
" count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n" " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
" enumVerifier:$name$_IsValidValue\n" " enumVerifier:$name$_IsValidValue\n"
" extraTextFormatInfo:extraTextFormatInfo];\n", " extraTextFormatInfo:extraTextFormatInfo];\n",
// clang-format on
"name", name_, "name", name_,
"extraTextFormatInfo", absl::CEscape(text_format_decode_data.Data())); "extraTextFormatInfo", absl::CEscape(text_format_decode_data.Data()));
} }
printer->Print( // clang-format off
" GPBEnumDescriptor *expected = nil;\n" printer->Print(
" if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n" " GPBEnumDescriptor *expected = nil;\n"
" [worker release];\n" " if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n"
" }\n" " [worker release];\n"
" }\n" " }\n"
" return descriptor;\n" " }\n"
"}\n\n"); " return descriptor;\n"
"}\n\n");
// clang-format on
printer->Print( printer->Print(
// clang-format off
"BOOL $name$_IsValidValue(int32_t value__) {\n" "BOOL $name$_IsValidValue(int32_t value__) {\n"
" switch (value__) {\n", " switch (value__) {\n",
// clang-format on
"name", name_); "name", name_);
for (int i = 0; i < base_values_.size(); i++) { for (int i = 0; i < base_values_.size(); i++) {
@ -262,12 +276,14 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"name", EnumValueName(base_values_[i])); "name", EnumValueName(base_values_[i]));
} }
// clang-format off
printer->Print( printer->Print(
" return YES;\n" " return YES;\n"
" default:\n" " default:\n"
" return NO;\n" " return NO;\n"
" }\n" " }\n"
"}\n\n"); "}\n\n");
// clang-format on
} }
} // namespace objectivec } // namespace objectivec
} // namespace compiler } // namespace compiler

@ -78,6 +78,7 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations(
return; return;
} }
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"/**\n" "/**\n"
@ -92,12 +93,14 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations(
" **/\n" " **/\n"
"void Set$owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message, int32_t value);\n" "void Set$owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message, int32_t value);\n"
"\n"); "\n");
// clang-format on
} }
void EnumFieldGenerator::GenerateCFunctionImplementations( void EnumFieldGenerator::GenerateCFunctionImplementations(
io::Printer* printer) const { io::Printer* printer) const {
if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) return; if (!HasPreservingUnknownEnumSemantics(descriptor_->file())) return;
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"int32_t $owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message) {\n" "int32_t $owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message) {\n"
@ -112,6 +115,7 @@ void EnumFieldGenerator::GenerateCFunctionImplementations(
" GPBSetMessageRawEnumField(message, field, value);\n" " GPBSetMessageRawEnumField(message, field, value);\n"
"}\n" "}\n"
"\n"); "\n");
// clang-format on
} }
void EnumFieldGenerator::DetermineForwardDeclarations( void EnumFieldGenerator::DetermineForwardDeclarations(

@ -77,9 +77,12 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) {
// Unlike normal message fields, check if the file for the extension was // Unlike normal message fields, check if the file for the extension was
// deprecated. // deprecated.
vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()); vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file());
printer->Print(vars, // clang-format off
"$comments$" printer->Print(
"+ (GPBExtensionDescriptor *)$method_name$$storage_attribute$$deprecated_attribute$;\n"); vars,
"$comments$"
"+ (GPBExtensionDescriptor *)$method_name$$storage_attribute$$deprecated_attribute$;\n");
// clang-format on
} }
void ExtensionGenerator::GenerateStaticVariablesInitialization( void ExtensionGenerator::GenerateStaticVariablesInitialization(
@ -122,17 +125,20 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
vars["enum_desc_func_name"] = "NULL"; vars["enum_desc_func_name"] = "NULL";
} }
printer->Print(vars, // clang-format off
"{\n" printer->Print(
" .defaultValue.$default_name$ = $default$,\n" vars,
" .singletonName = GPBStringifySymbol($root_class_and_method_name$),\n" "{\n"
" .extendedClass.clazz = $extended_type$,\n" " .defaultValue.$default_name$ = $default$,\n"
" .messageOrGroupClass.clazz = $type$,\n" " .singletonName = GPBStringifySymbol($root_class_and_method_name$),\n"
" .enumDescriptorFunc = $enum_desc_func_name$,\n" " .extendedClass.clazz = $extended_type$,\n"
" .fieldNumber = $number$,\n" " .messageOrGroupClass.clazz = $type$,\n"
" .dataType = $extension_type$,\n" " .enumDescriptorFunc = $enum_desc_func_name$,\n"
" .options = $options$,\n" " .fieldNumber = $number$,\n"
"},\n"); " .dataType = $extension_type$,\n"
" .options = $options$,\n"
"},\n");
// clang-format on
} }
void ExtensionGenerator::DetermineObjectiveCClassDefinitions( void ExtensionGenerator::DetermineObjectiveCClassDefinitions(
@ -147,9 +153,11 @@ void ExtensionGenerator::DetermineObjectiveCClassDefinitions(
} }
void ExtensionGenerator::GenerateRegistrationSource(io::Printer* printer) { void ExtensionGenerator::GenerateRegistrationSource(io::Printer* printer) {
// clang-format off
printer->Print( printer->Print(
"[registry addExtension:$root_class_and_method_name$];\n", "[registry addExtension:$root_class_and_method_name$];\n",
"root_class_and_method_name", root_class_and_method_name_); "root_class_and_method_name", root_class_and_method_name_);
// clang-format on
} }
} // namespace objectivec } // namespace objectivec

@ -243,6 +243,7 @@ void FieldGenerator::GenerateFieldDescription(
io::Printer* printer, bool include_default) const { io::Printer* printer, bool include_default) const {
// Printed in the same order as the structure decl. // Printed in the same order as the structure decl.
if (include_default) { if (include_default) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"{\n" "{\n"
@ -255,7 +256,9 @@ void FieldGenerator::GenerateFieldDescription(
" .core.flags = $fieldflags$,\n" " .core.flags = $fieldflags$,\n"
" .core.dataType = GPBDataType$field_type$,\n" " .core.dataType = GPBDataType$field_type$,\n"
"},\n"); "},\n");
// clang-format on
} else { } else {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"{\n" "{\n"
@ -267,6 +270,7 @@ void FieldGenerator::GenerateFieldDescription(
" .flags = $fieldflags$,\n" " .flags = $fieldflags$,\n"
" .dataType = GPBDataType$field_type$,\n" " .dataType = GPBDataType$field_type$,\n"
"},\n"); "},\n");
// clang-format on
} }
} }
@ -326,14 +330,18 @@ void SingleFieldGenerator::GenerateFieldStorageDeclaration(
void SingleFieldGenerator::GeneratePropertyDeclaration( void SingleFieldGenerator::GeneratePropertyDeclaration(
io::Printer* printer) const { io::Printer* printer) const {
printer->Print(variables_, "$comments$"); printer->Print(variables_, "$comments$");
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;\n" "@property(nonatomic, readwrite) $property_type$ $name$$deprecated_attribute$;\n"
"\n"); "\n");
// clang-format on
if (WantsHasProperty()) { if (WantsHasProperty()) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n"); "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n");
// clang-format on
} }
} }
@ -377,14 +385,18 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
// conventions (init*, new*, etc.) // conventions (init*, new*, etc.)
printer->Print(variables_, "$comments$"); printer->Print(variables_, "$comments$");
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n"); "@property(nonatomic, readwrite, $property_storage_attribute$, null_resettable) $property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n");
// clang-format on
if (WantsHasProperty()) { if (WantsHasProperty()) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"/** Test to see if @c $name$ has been set. */\n" "/** Test to see if @c $name$ has been set. */\n"
"@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n"); "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n");
// clang-format on
} }
if (IsInitName(variables_.find("name")->second)) { if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC. // If property name starts with init we need to annotate it to get past ARC.
@ -430,6 +442,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
// dealing with needing Objective C's rules around storage name conventions // dealing with needing Objective C's rules around storage name conventions
// (init*, new*, etc.) // (init*, new*, etc.)
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"$comments$" "$comments$"
@ -437,11 +450,14 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
"@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n" "@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" "/** The number of items in @c $name$ without causing the container to be created. */\n"
"@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;\n"); "@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;\n");
// clang-format on
if (IsInitName(variables_.find("name")->second)) { if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC. // 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 // 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_, printer->Print(variables_,
"- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$;\n"); "- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecated_attribute$;\n");
// clang-format on
} }
printer->Print("\n"); printer->Print("\n");
} }

@ -261,6 +261,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
// compiled, since that will be the versions for the ObjC runtime at that // compiled, since that will be the versions for the ObjC runtime at that
// time. The constants in the generated code will then get their values at // time. The constants in the generated code will then get their values at
// at compile time (so checking against the headers being used to compile). // at compile time (so checking against the headers being used to compile).
// clang-format off
printer->Print( printer->Print(
"#if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$\n" "#if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$\n"
"#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.\n" "#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.\n"
@ -270,6 +271,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"#endif\n" "#endif\n"
"\n", "\n",
"google_protobuf_objc_version", absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); "google_protobuf_objc_version", absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION));
// clang-format on
// The bundled protos (WKTs) don't use of forward declarations. // The bundled protos (WKTs) don't use of forward declarations.
bool headers_use_forward_declarations = bool headers_use_forward_declarations =
@ -299,6 +301,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
// deprecated-declarations suppression is only needed if some place in this // deprecated-declarations suppression is only needed if some place in this
// proto file is something deprecated or if it references something from // proto file is something deprecated or if it references something from
// another file that is deprecated. // another file that is deprecated.
// clang-format off
printer->Print( printer->Print(
"// @@protoc_insertion_point(imports)\n" "// @@protoc_insertion_point(imports)\n"
"\n" "\n"
@ -307,6 +310,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"\n" "\n"
"CF_EXTERN_C_BEGIN\n" "CF_EXTERN_C_BEGIN\n"
"\n"); "\n");
// clang-format on
std::set<std::string> fwd_decls; std::set<std::string> fwd_decls;
for (const auto& generator : message_generators_) { for (const auto& generator : message_generators_) {
@ -338,6 +342,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
// For extensions to chain together, the Root gets created even if there // For extensions to chain together, the Root gets created even if there
// are no extensions. // are no extensions.
printer->Print( printer->Print(
// clang-format off
"#pragma mark - $root_class_name$\n" "#pragma mark - $root_class_name$\n"
"\n" "\n"
"/**\n" "/**\n"
@ -353,6 +358,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"GPB_FINAL @interface $root_class_name$ : GPBRootObject\n" "GPB_FINAL @interface $root_class_name$ : GPBRootObject\n"
"@end\n" "@end\n"
"\n", "\n",
// clang-format off
"root_class_name", root_class_name_); "root_class_name", root_class_name_);
if (!extension_generators_.empty()) { if (!extension_generators_.empty()) {
@ -372,6 +378,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
generator->GenerateMessageHeader(printer); generator->GenerateMessageHeader(printer);
} }
// clang-format off
printer->Print( printer->Print(
"NS_ASSUME_NONNULL_END\n" "NS_ASSUME_NONNULL_END\n"
"\n" "\n"
@ -382,6 +389,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
"// @@protoc_insertion_point(global_scope)\n" "// @@protoc_insertion_point(global_scope)\n"
"\n" "\n"
"// clange-format on\n"); "// clange-format on\n");
// clang-format on
} }
void FileGenerator::GenerateSource(io::Printer* printer) { void FileGenerator::GenerateSource(io::Printer* printer) {
@ -471,11 +479,13 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
// another file that is deprecated. // another file that is deprecated.
// dollar-in-identifier-extension is needed because we use references to // dollar-in-identifier-extension is needed because we use references to
// objc class names that have $ in identifiers. // objc class names that have $ in identifiers.
// clang-format off
printer->Print( printer->Print(
"// @@protoc_insertion_point(imports)\n" "// @@protoc_insertion_point(imports)\n"
"\n" "\n"
"#pragma clang diagnostic push\n" "#pragma clang diagnostic push\n"
"#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"); "#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n");
// clang-format on
if (includes_oneof) { if (includes_oneof) {
// The generated code for oneof's uses direct ivar access, suppress the // The generated code for oneof's uses direct ivar access, suppress the
// warning in case developer turn that on in the context they compile the // warning in case developer turn that on in the context they compile the
@ -484,17 +494,21 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
"#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n"); "#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n");
} }
if (!fwd_decls.empty()) { if (!fwd_decls.empty()) {
// clang-format off
printer->Print( printer->Print(
"#pragma clang diagnostic ignored \"-Wdollar-in-identifier-extension\"\n"); "#pragma clang diagnostic ignored \"-Wdollar-in-identifier-extension\"\n");
// clang-format on
} }
printer->Print( printer->Print(
"\n"); "\n");
if (!fwd_decls.empty()) { if (!fwd_decls.empty()) {
// clang-format off
printer->Print( printer->Print(
"#pragma mark - Objective C Class declarations\n" "#pragma mark - Objective C Class declarations\n"
"// Forward declarations of Objective C classes that we can use as\n" "// Forward declarations of Objective C classes that we can use as\n"
"// static values in struct initializers.\n" "// static values in struct initializers.\n"
"// We don't use [Foo class] because it is not a static value.\n"); "// We don't use [Foo class] because it is not a static value.\n");
// clang-format on
} }
for (const auto& i : fwd_decls) { for (const auto& i : fwd_decls) {
printer->Print("$value$\n", "value", i); printer->Print("$value$\n", "value", i);
@ -503,9 +517,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
printer->Print("\n"); printer->Print("\n");
} }
printer->Print( printer->Print(
// clang-format off
"#pragma mark - $root_class_name$\n" "#pragma mark - $root_class_name$\n"
"\n" "\n"
"@implementation $root_class_name$\n\n", "@implementation $root_class_name$\n\n",
// clang-format on
"root_class_name", root_class_name_); "root_class_name", root_class_name_);
const bool file_contains_extensions = FileContainsExtensions(file_); const bool file_contains_extensions = FileContainsExtensions(file_);
@ -513,6 +529,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
// If there were any extensions or this file has any dependencies, output // If there were any extensions or this file has any dependencies, output
// a registry to override to create the file specific registry. // a registry to override to create the file specific registry.
if (file_contains_extensions || !deps_with_extensions.empty()) { if (file_contains_extensions || !deps_with_extensions.empty()) {
// clang-format off
printer->Print( printer->Print(
"+ (GPBExtensionRegistry*)extensionRegistry {\n" "+ (GPBExtensionRegistry*)extensionRegistry {\n"
" // This is called by +initialize so there is no need to worry\n" " // This is called by +initialize so there is no need to worry\n"
@ -521,6 +538,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
" if (!registry) {\n" " if (!registry) {\n"
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n" " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"
" registry = [[GPBExtensionRegistry alloc] init];\n"); " registry = [[GPBExtensionRegistry alloc] init];\n");
// clang-format on
printer->Indent(); printer->Indent();
printer->Indent(); printer->Indent();
@ -536,6 +554,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
generator->GenerateStaticVariablesInitialization(printer); generator->GenerateStaticVariablesInitialization(printer);
} }
printer->Outdent(); printer->Outdent();
// clang-format off
printer->Print( printer->Print(
"};\n" "};\n"
"for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {\n" "for (size_t i = 0; i < sizeof(descriptions) / sizeof(descriptions[0]); ++i) {\n"
@ -546,15 +565,20 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
" [self globallyRegisterExtension:extension];\n" " [self globallyRegisterExtension:extension];\n"
" [extension release];\n" " [extension release];\n"
"}\n"); "}\n");
// clang-format on
} }
if (deps_with_extensions.empty()) { if (deps_with_extensions.empty()) {
// clang-format off
printer->Print( printer->Print(
"// None of the imports (direct or indirect) defined extensions, so no need to add\n" "// None of the imports (direct or indirect) defined extensions, so no need to add\n"
"// them to this registry.\n"); "// them to this registry.\n");
// clang-format on
} else { } else {
// clang-format off
printer->Print( printer->Print(
"// Merge in the imports (direct or indirect) that defined extensions.\n"); "// Merge in the imports (direct or indirect) that defined extensions.\n");
// clang-format on
for (std::vector<const FileDescriptor*>::iterator iter = for (std::vector<const FileDescriptor*>::iterator iter =
deps_with_extensions.begin(); deps_with_extensions.begin();
iter != deps_with_extensions.end(); ++iter) { iter != deps_with_extensions.end(); ++iter) {
@ -568,19 +592,25 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
printer->Outdent(); printer->Outdent();
printer->Outdent(); printer->Outdent();
// clang-format off
printer->Print( printer->Print(
" }\n" " }\n"
" return registry;\n" " return registry;\n"
"}\n"); "}\n");
// clang-format on
} else { } else {
if (file_->dependency_count() > 0) { if (file_->dependency_count() > 0) {
// clang-format off
printer->Print( printer->Print(
"// No extensions in the file and none of the imports (direct or indirect)\n" "// No extensions in the file and none of the imports (direct or indirect)\n"
"// defined extensions, so no need to generate +extensionRegistry.\n"); "// defined extensions, so no need to generate +extensionRegistry.\n");
// clang-format on
} else { } else {
// clang-format off
printer->Print( printer->Print(
"// No extensions in the file and no imports, so no need to generate\n" "// No extensions in the file and no imports, so no need to generate\n"
"// +extensionRegistry.\n"); "// +extensionRegistry.\n");
// clang-format on
} }
} }
@ -603,7 +633,9 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
vars["syntax"] = "GPBFileSyntaxProto3"; vars["syntax"] = "GPBFileSyntaxProto3";
break; break;
} }
printer->Print(vars, // clang-format off
printer->Print(
vars,
"#pragma mark - $root_class_name$_FileDescriptor\n" "#pragma mark - $root_class_name$_FileDescriptor\n"
"\n" "\n"
"static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {\n" "static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {\n"
@ -612,23 +644,30 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
" static GPBFileDescriptor *descriptor = NULL;\n" " static GPBFileDescriptor *descriptor = NULL;\n"
" if (!descriptor) {\n" " if (!descriptor) {\n"
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"); " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n");
// clang-format on
if (!vars["objc_prefix"].empty()) { if (!vars["objc_prefix"].empty()) {
// clang-format off
printer->Print( printer->Print(
vars, vars,
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n"
" objcPrefix:@\"$objc_prefix$\"\n" " objcPrefix:@\"$objc_prefix$\"\n"
" syntax:$syntax$];\n"); " syntax:$syntax$];\n");
// clang-format on
} else { } else {
// clang-format off
printer->Print( printer->Print(
vars, vars,
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n"
" syntax:$syntax$];\n"); " syntax:$syntax$];\n");
// clang-format on
} }
// clang-format off
printer->Print( printer->Print(
" }\n" " }\n"
" return descriptor;\n" " return descriptor;\n"
"}\n" "}\n"
"\n"); "\n");
// clang-format on
} }
for (const auto& generator : enum_generators_) { for (const auto& generator : enum_generators_) {
@ -638,13 +677,15 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
generator->GenerateSource(printer); generator->GenerateSource(printer);
} }
// clang-format off
printer->Print( printer->Print(
"\n" "\n"
"#pragma clang diagnostic pop\n" "#pragma clang diagnostic pop\n"
"\n" "\n"
"// @@protoc_insertion_point(global_scope)\n" "// @@protoc_insertion_point(global_scope)\n"
"\n" "\n"
"// clang-format on\n"); "// clang-format on\n");
// clang-format on
} }
// Helper to print the import of the runtime support at the top of generated // Helper to print the import of the runtime support at the top of generated

@ -213,12 +213,14 @@ void ImportWriter::PrintRuntimeImports(
if (default_cpp_symbol) { if (default_cpp_symbol) {
printer->Print( printer->Print(
// clang-format off
"// This CPP symbol can be defined to use imports that match up to the framework\n" "// This CPP symbol can be defined to use imports that match up to the framework\n"
"// imports needed when using CocoaPods.\n" "// imports needed when using CocoaPods.\n"
"#if !defined($cpp_symbol$)\n" "#if !defined($cpp_symbol$)\n"
" #define $cpp_symbol$ 0\n" " #define $cpp_symbol$ 0\n"
"#endif\n" "#endif\n"
"\n", "\n",
// clang-format on
"cpp_symbol", cpp_symbol); "cpp_symbol", cpp_symbol);
} }

@ -305,8 +305,10 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
} }
printer->Print( printer->Print(
// clang-format off
"#pragma mark - $classname$\n" "#pragma mark - $classname$\n"
"\n", "\n",
// clang-format on
"classname", class_name_); "classname", class_name_);
if (descriptor_->field_count()) { if (descriptor_->field_count()) {
@ -339,7 +341,9 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
} }
printer->Print( printer->Print(
// clang-format off
"$comments$$deprecated_attribute$GPB_FINAL @interface $classname$ : GPBMessage\n\n", "$comments$$deprecated_attribute$GPB_FINAL @interface $classname$ : GPBMessage\n\n",
// clang-format on
"classname", class_name_, "classname", class_name_,
"deprecated_attribute", deprecated_attribute_, "deprecated_attribute", deprecated_attribute_,
"comments", message_comments); "comments", message_comments);
@ -390,16 +394,20 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
void MessageGenerator::GenerateSource(io::Printer* printer) { void MessageGenerator::GenerateSource(io::Printer* printer) {
if (!IsMapEntryMessage(descriptor_)) { if (!IsMapEntryMessage(descriptor_)) {
printer->Print( printer->Print(
// clang-format off
"#pragma mark - $classname$\n" "#pragma mark - $classname$\n"
"\n", "\n",
// clang-format on
"classname", class_name_); "classname", class_name_);
if (!deprecated_attribute_.empty()) { if (!deprecated_attribute_.empty()) {
// No warnings when compiling the impl of this deprecated class. // No warnings when compiling the impl of this deprecated class.
// clang-format off
printer->Print( printer->Print(
"#pragma clang diagnostic push\n" "#pragma clang diagnostic push\n"
"#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n" "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n"
"\n"); "\n");
// clang-format on
} }
printer->Print("@implementation $classname$\n\n", printer->Print("@implementation $classname$\n\n",
@ -452,9 +460,11 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
sizeof_has_storage += oneof_generators_.size(); sizeof_has_storage += oneof_generators_.size();
printer->Print( printer->Print(
// clang-format off
"\n" "\n"
"typedef struct $classname$__storage_ {\n" "typedef struct $classname$__storage_ {\n"
" uint32_t _has_storage_[$sizeof_has_storage$];\n", " uint32_t _has_storage_[$sizeof_has_storage$];\n",
// clang-format on
"classname", class_name_, "classname", class_name_,
"sizeof_has_storage", absl::StrCat(sizeof_has_storage)); "sizeof_has_storage", absl::StrCat(sizeof_has_storage));
printer->Indent(); printer->Indent();
@ -468,12 +478,14 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
printer->Print("} $classname$__storage_;\n\n", "classname", class_name_); printer->Print("} $classname$__storage_;\n\n", "classname", class_name_);
// clang-format off
printer->Print( printer->Print(
"// This method is threadsafe because it is initially called\n" "// This method is threadsafe because it is initially called\n"
"// in +initialize for each subclass.\n" "// in +initialize for each subclass.\n"
"+ (GPBDescriptor *)descriptor {\n" "+ (GPBDescriptor *)descriptor {\n"
" static GPBDescriptor *descriptor = nil;\n" " static GPBDescriptor *descriptor = nil;\n"
" if (!descriptor) {\n"); " if (!descriptor) {\n");
// clang-format on
TextFormatDecodeData text_format_decode_data; TextFormatDecodeData text_format_decode_data;
bool has_fields = descriptor_->field_count() > 0; bool has_fields = descriptor_->field_count() > 0;
@ -531,6 +543,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
vars["init_flags"] = BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION, vars["init_flags"] = BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION,
init_flags); init_flags);
// clang-format off
printer->Print( printer->Print(
vars, vars,
" GPBDescriptor *localDescriptor =\n" " GPBDescriptor *localDescriptor =\n"
@ -541,6 +554,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
" fieldCount:$fields_count$\n" " fieldCount:$fields_count$\n"
" storageSize:sizeof($classname$__storage_)\n" " storageSize:sizeof($classname$__storage_)\n"
" flags:$init_flags$];\n"); " flags:$init_flags$];\n");
// clang-format on
if (!oneof_generators_.empty()) { if (!oneof_generators_.empty()) {
printer->Print( printer->Print(
" static const char *oneofs[] = {\n"); " static const char *oneofs[] = {\n");
@ -549,17 +563,21 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
generator->DescriptorName()); generator->DescriptorName());
} }
printer->Print( printer->Print(
// clang-format off
" };\n" " };\n"
" [localDescriptor setupOneofs:oneofs\n" " [localDescriptor setupOneofs:oneofs\n"
" count:(uint32_t)(sizeof(oneofs) / sizeof(char*))\n" " count:(uint32_t)(sizeof(oneofs) / sizeof(char*))\n"
" firstHasIndex:$first_has_index$];\n", " firstHasIndex:$first_has_index$];\n",
// clang-format on
"first_has_index", oneof_generators_[0]->HasIndexAsString()); "first_has_index", oneof_generators_[0]->HasIndexAsString());
} }
if (text_format_decode_data.num_entries() != 0) { if (text_format_decode_data.num_entries() != 0) {
const std::string text_format_data_str(text_format_decode_data.Data()); const std::string text_format_data_str(text_format_decode_data.Data());
// clang-format off
printer->Print( printer->Print(
"#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n" "#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n"
" static const char *extraTextFormatInfo ="); " static const char *extraTextFormatInfo =");
// clang-format on
static const int kBytesPerLine = 40; // allow for escaping static const int kBytesPerLine = 40; // allow for escaping
for (int i = 0; i < text_format_data_str.size(); i += kBytesPerLine) { for (int i = 0; i < text_format_data_str.size(); i += kBytesPerLine) {
printer->Print( printer->Print(
@ -567,10 +585,12 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"data", EscapeTrigraphs( "data", EscapeTrigraphs(
absl::CEscape(text_format_data_str.substr(i, kBytesPerLine)))); absl::CEscape(text_format_data_str.substr(i, kBytesPerLine))));
} }
// clang-format off
printer->Print( printer->Print(
";\n" ";\n"
" [localDescriptor setupExtraTextInfo:extraTextFormatInfo];\n" " [localDescriptor setupExtraTextInfo:extraTextFormatInfo];\n"
"#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n"); "#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS\n");
// clang-format on
} }
if (!sorted_extensions.empty()) { if (!sorted_extensions.empty()) {
printer->Print( printer->Print(
@ -580,16 +600,20 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"start", absl::StrCat(sorted_extensions[i]->start), "start", absl::StrCat(sorted_extensions[i]->start),
"end", absl::StrCat(sorted_extensions[i]->end)); "end", absl::StrCat(sorted_extensions[i]->end));
} }
// clang-format off
printer->Print( printer->Print(
" };\n" " };\n"
" [localDescriptor setupExtensionRanges:ranges\n" " [localDescriptor setupExtensionRanges:ranges\n"
" count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];\n"); " count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];\n");
// clang-format on
} }
if (descriptor_->containing_type() != NULL) { if (descriptor_->containing_type() != NULL) {
std::string containing_class = ClassName(descriptor_->containing_type()); std::string containing_class = ClassName(descriptor_->containing_type());
std::string parent_class_ref = ObjCClass(containing_class); std::string parent_class_ref = ObjCClass(containing_class);
printer->Print( printer->Print(
// clang-format off
" [localDescriptor setupContainingMessageClass:$parent_class_ref$];\n", " [localDescriptor setupContainingMessageClass:$parent_class_ref$];\n",
// clang-format on
"parent_class_ref", parent_class_ref); "parent_class_ref", parent_class_ref);
} }
std::string suffix_added; std::string suffix_added;
@ -599,6 +623,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
" [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n", " [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n",
"suffix", suffix_added); "suffix", suffix_added);
} }
// clang-format off
printer->Print( printer->Print(
" #if defined(DEBUG) && DEBUG\n" " #if defined(DEBUG) && DEBUG\n"
" NSAssert(descriptor == nil, @\"Startup recursed!\");\n" " NSAssert(descriptor == nil, @\"Startup recursed!\");\n"
@ -608,11 +633,14 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
" return descriptor;\n" " return descriptor;\n"
"}\n\n" "}\n\n"
"@end\n\n"); "@end\n\n");
// clang-format on
if (!deprecated_attribute_.empty()) { if (!deprecated_attribute_.empty()) {
// clang-format off
printer->Print( printer->Print(
"#pragma clang diagnostic pop\n" "#pragma clang diagnostic pop\n"
"\n"); "\n");
// clang-format on
} }
for (int i = 0; i < descriptor_->field_count(); i++) { for (int i = 0; i < descriptor_->field_count(); i++) {

@ -89,27 +89,33 @@ void OneofGenerator::GenerateCaseEnum(io::Printer* printer) {
"field_number", absl::StrCat(field->number())); "field_number", absl::StrCat(field->number()));
} }
printer->Outdent(); printer->Outdent();
// clang-format off
printer->Print( printer->Print(
"};\n" "};\n"
"\n"); "\n");
// clang-format on
} }
void OneofGenerator::GeneratePublicCasePropertyDeclaration( void OneofGenerator::GeneratePublicCasePropertyDeclaration(
io::Printer* printer) { io::Printer* printer) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"$comments$" "$comments$"
"@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;\n" "@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;\n"
"\n"); "\n");
// clang-format on
} }
void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"/**\n" "/**\n"
" * Clears whatever value was set for the oneof '$name$'.\n" " * Clears whatever value was set for the oneof '$name$'.\n"
" **/\n" " **/\n"
"void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message);\n"); "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message);\n");
// clang-format on
} }
void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) { void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) {
@ -119,6 +125,7 @@ void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) {
} }
void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) {
// clang-format off
printer->Print( printer->Print(
variables_, variables_,
"void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message) {\n" "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message) {\n"
@ -126,6 +133,7 @@ void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) {
" GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:$raw_index$];\n" " GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:$raw_index$];\n"
" GPBClearOneof(message, oneof);\n" " GPBClearOneof(message, oneof);\n"
"}\n"); "}\n");
// clang-format on
} }
std::string OneofGenerator::DescriptorName(void) const { std::string OneofGenerator::DescriptorName(void) const {

Loading…
Cancel
Save