|
|
|
@ -261,6 +261,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
// 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
|
|
|
|
|
// at compile time (so checking against the headers being used to compile).
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"#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" |
|
|
|
@ -270,6 +271,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
"#endif\n" |
|
|
|
|
"\n", |
|
|
|
|
"google_protobuf_objc_version", absl::StrCat(GOOGLE_PROTOBUF_OBJC_VERSION)); |
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
// The bundled protos (WKTs) don't use of 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
|
|
|
|
|
// proto file is something deprecated or if it references something from
|
|
|
|
|
// another file that is deprecated.
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// @@protoc_insertion_point(imports)\n" |
|
|
|
|
"\n" |
|
|
|
@ -307,6 +310,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
"\n" |
|
|
|
|
"CF_EXTERN_C_BEGIN\n" |
|
|
|
|
"\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
std::set<std::string> fwd_decls; |
|
|
|
|
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
|
|
|
|
|
// are no extensions.
|
|
|
|
|
printer->Print( |
|
|
|
|
// clang-format off
|
|
|
|
|
"#pragma mark - $root_class_name$\n" |
|
|
|
|
"\n" |
|
|
|
|
"/**\n" |
|
|
|
@ -353,6 +358,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
"GPB_FINAL @interface $root_class_name$ : GPBRootObject\n" |
|
|
|
|
"@end\n" |
|
|
|
|
"\n", |
|
|
|
|
// clang-format off
|
|
|
|
|
"root_class_name", root_class_name_); |
|
|
|
|
|
|
|
|
|
if (!extension_generators_.empty()) { |
|
|
|
@ -372,6 +378,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
generator->GenerateMessageHeader(printer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"NS_ASSUME_NONNULL_END\n" |
|
|
|
|
"\n" |
|
|
|
@ -382,6 +389,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { |
|
|
|
|
"// @@protoc_insertion_point(global_scope)\n" |
|
|
|
|
"\n" |
|
|
|
|
"// clange-format on\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
@ -471,11 +479,13 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
// another file that is deprecated.
|
|
|
|
|
// dollar-in-identifier-extension is needed because we use references to
|
|
|
|
|
// objc class names that have $ in identifiers.
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// @@protoc_insertion_point(imports)\n" |
|
|
|
|
"\n" |
|
|
|
|
"#pragma clang diagnostic push\n" |
|
|
|
|
"#pragma clang diagnostic ignored \"-Wdeprecated-declarations\"\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
if (includes_oneof) { |
|
|
|
|
// 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
|
|
|
|
@ -484,17 +494,21 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
"#pragma clang diagnostic ignored \"-Wdirect-ivar-access\"\n"); |
|
|
|
|
} |
|
|
|
|
if (!fwd_decls.empty()) { |
|
|
|
|
// clang-format off
|
|
|
|
|
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( |
|
|
|
|
"\n"); |
|
|
|
|
if (!fwd_decls.empty()) { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"#pragma mark - Objective C Class declarations\n" |
|
|
|
|
"// Forward declarations of Objective C classes that we can use as\n" |
|
|
|
|
"// static values in struct initializers.\n" |
|
|
|
|
"// We don't use [Foo class] because it is not a static value.\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
for (const auto& i : fwd_decls) { |
|
|
|
|
printer->Print("$value$\n", "value", i); |
|
|
|
@ -503,9 +517,11 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
printer->Print("\n"); |
|
|
|
|
} |
|
|
|
|
printer->Print( |
|
|
|
|
// clang-format off
|
|
|
|
|
"#pragma mark - $root_class_name$\n" |
|
|
|
|
"\n" |
|
|
|
|
"@implementation $root_class_name$\n\n", |
|
|
|
|
// clang-format on
|
|
|
|
|
"root_class_name", root_class_name_); |
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
// a registry to override to create the file specific registry.
|
|
|
|
|
if (file_contains_extensions || !deps_with_extensions.empty()) { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"+ (GPBExtensionRegistry*)extensionRegistry {\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" |
|
|
|
|
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n" |
|
|
|
|
" registry = [[GPBExtensionRegistry alloc] init];\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
printer->Indent(); |
|
|
|
|
printer->Indent(); |
|
|
|
@ -536,6 +554,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
generator->GenerateStaticVariablesInitialization(printer); |
|
|
|
|
} |
|
|
|
|
printer->Outdent(); |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"};\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" |
|
|
|
|
" [extension release];\n" |
|
|
|
|
"}\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (deps_with_extensions.empty()) { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// None of the imports (direct or indirect) defined extensions, so no need to add\n" |
|
|
|
|
"// them to this registry.\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} else { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// Merge in the imports (direct or indirect) that defined extensions.\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
for (std::vector<const FileDescriptor*>::iterator iter = |
|
|
|
|
deps_with_extensions.begin(); |
|
|
|
|
iter != deps_with_extensions.end(); ++iter) { |
|
|
|
@ -568,19 +592,25 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
printer->Outdent(); |
|
|
|
|
printer->Outdent(); |
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
" }\n" |
|
|
|
|
" return registry;\n" |
|
|
|
|
"}\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} else { |
|
|
|
|
if (file_->dependency_count() > 0) { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// No extensions in the file and none of the imports (direct or indirect)\n" |
|
|
|
|
"// defined extensions, so no need to generate +extensionRegistry.\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} else { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"// No extensions in the file and no imports, so no need to generate\n" |
|
|
|
|
"// +extensionRegistry.\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -603,7 +633,9 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
vars["syntax"] = "GPBFileSyntaxProto3"; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
printer->Print(vars, |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
vars, |
|
|
|
|
"#pragma mark - $root_class_name$_FileDescriptor\n" |
|
|
|
|
"\n" |
|
|
|
|
"static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {\n" |
|
|
|
@ -612,23 +644,30 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
" static GPBFileDescriptor *descriptor = NULL;\n" |
|
|
|
|
" if (!descriptor) {\n" |
|
|
|
|
" GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
if (!vars["objc_prefix"].empty()) { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
vars, |
|
|
|
|
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" |
|
|
|
|
" objcPrefix:@\"$objc_prefix$\"\n" |
|
|
|
|
" syntax:$syntax$];\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} else { |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
vars, |
|
|
|
|
" descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n" |
|
|
|
|
" syntax:$syntax$];\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
" }\n" |
|
|
|
|
" return descriptor;\n" |
|
|
|
|
"}\n" |
|
|
|
|
"\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const auto& generator : enum_generators_) { |
|
|
|
@ -638,13 +677,15 @@ void FileGenerator::GenerateSource(io::Printer* printer) { |
|
|
|
|
generator->GenerateSource(printer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
printer->Print( |
|
|
|
|
"\n" |
|
|
|
|
"#pragma clang diagnostic pop\n" |
|
|
|
|
"\n" |
|
|
|
|
"// @@protoc_insertion_point(global_scope)\n" |
|
|
|
|
"\n" |
|
|
|
|
"// clang-format on\n"); |
|
|
|
|
"\n" |
|
|
|
|
"#pragma clang diagnostic pop\n" |
|
|
|
|
"\n" |
|
|
|
|
"// @@protoc_insertion_point(global_scope)\n" |
|
|
|
|
"\n" |
|
|
|
|
"// clang-format on\n"); |
|
|
|
|
// clang-format on
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Helper to print the import of the runtime support at the top of generated
|
|
|
|
|