|
|
@ -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
|
|
|
|