diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index 09950412ce..307bca8264 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -449,9 +449,12 @@ void FileGenerator::GenerateGlobalSource(io::Printer* p) const { }); } -void FileGenerator::GenerateSourceForEnum(int idx, io::Printer* p) const { - GenerateFile(p, GeneratedFileType::kSource, - [&] { enum_generators_[idx]->GenerateSource(p); }); +void FileGenerator::GenerateSourceForEnums(io::Printer* p) const { + GenerateFile(p, GeneratedFileType::kSource, [&] { + for (const auto& generator : enum_generators_) { + generator->GenerateSource(p); + } + }); } void FileGenerator::GenerateSourceForMessage(int idx, io::Printer* p) const { diff --git a/src/google/protobuf/compiler/objectivec/file.h b/src/google/protobuf/compiler/objectivec/file.h index 73e501db28..51c6a9656c 100644 --- a/src/google/protobuf/compiler/objectivec/file.h +++ b/src/google/protobuf/compiler/objectivec/file.h @@ -89,15 +89,16 @@ class FileGenerator { void GenerateGlobalSource(io::Printer* p) const; void GenerateSourceForMessage(int idx, io::Printer* p) const; - void GenerateSourceForEnum(int idx, io::Printer* p) const; + void GenerateSourceForEnums(io::Printer* p) const; private: enum class GeneratedFileType : int { kHeader, kSource }; - void GenerateFile(io::Printer* p, GeneratedFileType file_type, - const std::vector& ignored_warnings, - const std::vector& extra_files, - std::function body) const; + void GenerateFile( + io::Printer* p, GeneratedFileType file_type, + const std::vector& ignored_warnings, + const std::vector& extra_files_to_import, + std::function body) const; void GenerateFile(io::Printer* p, GeneratedFileType file_type, std::function body) const { GenerateFile(p, file_type, {}, {}, body); diff --git a/src/google/protobuf/compiler/objectivec/generator.cc b/src/google/protobuf/compiler/objectivec/generator.cc index df64463a1d..66f625c5a2 100644 --- a/src/google/protobuf/compiler/objectivec/generator.cc +++ b/src/google/protobuf/compiler/objectivec/generator.cc @@ -262,11 +262,10 @@ bool ObjectiveCGenerator::GenerateAll( // This is an experimental option, and could be removed or change at any // time; it is not documented in the README.md for that reason. // - // Enables a mode where each type (message & enum) generates to a unique - // .m file; this is to explore impacts on code size when not + // Enables a mode where each ObjC class (messages and roots) generates to + // a unique .m file; this is to explore impacts on code size when not // compiling/linking with `-ObjC` as then only linker visible needs should // be pulled into the builds. - if (!StringToBool( options[i].second, &generation_options.experimental_multi_source_generation)) { @@ -346,15 +345,17 @@ bool ObjectiveCGenerator::GenerateAll( } } - for (int i = 0; i < file_generator.NumEnums(); ++i) { + // Enums only generate C functions, so they can all go in one file as + // dead stripping anything not used. + if (file_generator.NumEnums() > 0) { std::unique_ptr output( context->Open(NumberedObjCMFileName(filepath, file_number++))); io::Printer printer(output.get()); - file_generator.GenerateSourceForEnum(i, &printer); + file_generator.GenerateSourceForEnums(&printer); if (printer.failed()) { *error = absl::StrCat( - "error: internal error generating an enum implementation:", - file->name(), "::", i); + "error: internal error generating an enum implementation(s):", + file->name()); return false; } }