diff --git a/src/google/protobuf/compiler/objectivec/file.cc b/src/google/protobuf/compiler/objectivec/file.cc index c2093ddda3..3ede6ee965 100644 --- a/src/google/protobuf/compiler/objectivec/file.cc +++ b/src/google/protobuf/compiler/objectivec/file.cc @@ -221,7 +221,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, CommonState& common_state) : file_(file), generation_options_(generation_options), - common_state_(common_state), + common_state_(&common_state), root_class_name_(FileClassName(file)), is_bundled_proto_(IsProtobufLibraryBundledProtoFile(file)) { for (int i = 0; i < file_->enum_type_count(); i++) { @@ -241,7 +241,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, } } -void FileGenerator::GenerateHeader(io::Printer* printer) { +void FileGenerator::GenerateHeader(io::Printer* printer) const { std::vector headers; // Generated files bundled with the library get minimal imports, everything // else gets the wrapper so everything is usable. @@ -393,7 +393,7 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { // clang-format on } -void FileGenerator::GenerateSource(io::Printer* printer) { +void FileGenerator::GenerateSource(io::Printer* printer) const { // #import the runtime support. std::vector headers; headers.push_back("GPBProtocolBuffers_RuntimeSupport.h"); @@ -410,7 +410,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) { } std::vector deps_with_extensions = - common_state_.CollectMinimalFileDepsContainingExtensions(file_); + common_state_->CollectMinimalFileDepsContainingExtensions(file_); // The bundled protos (WKTs) don't use of forward declarations. bool headers_use_forward_declarations = diff --git a/src/google/protobuf/compiler/objectivec/file.h b/src/google/protobuf/compiler/objectivec/file.h index 3946a05cf3..b62a8562e8 100644 --- a/src/google/protobuf/compiler/objectivec/file.h +++ b/src/google/protobuf/compiler/objectivec/file.h @@ -80,15 +80,15 @@ class FileGenerator { FileGenerator(const FileGenerator&) = delete; FileGenerator& operator=(const FileGenerator&) = delete; - void GenerateSource(io::Printer* printer); - void GenerateHeader(io::Printer* printer); + void GenerateSource(io::Printer* printer) const; + void GenerateHeader(io::Printer* printer) const; private: const FileDescriptor* file_; const GenerationOptions& generation_options_; - CommonState& common_state_; - std::string root_class_name_; - bool is_bundled_proto_; + mutable CommonState* common_state_; + const std::string root_class_name_; + const bool is_bundled_proto_; std::vector> enum_generators_; std::vector> message_generators_; diff --git a/src/google/protobuf/compiler/objectivec/oneof.cc b/src/google/protobuf/compiler/objectivec/oneof.cc index 4dfaf98171..99b2149379 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.cc +++ b/src/google/protobuf/compiler/objectivec/oneof.cc @@ -67,11 +67,11 @@ void OneofGenerator::SetOneofIndexBase(int index_base) { variables_["index"] = absl::StrCat(-index); } -void OneofGenerator::GenerateCaseEnum(io::Printer* printer) { +void OneofGenerator::GenerateCaseEnum(io::Printer* printer) const { printer->Print(variables_, "typedef GPB_ENUM($enum_name$) {\n"); printer->Indent(); printer->Print(variables_, "$enum_name$_GPBUnsetOneOfCase = 0,\n"); - std::string enum_name = variables_["enum_name"]; + std::string enum_name = variables_.find("enum_name")->second; for (int j = 0; j < descriptor_->field_count(); j++) { const FieldDescriptor* field = descriptor_->field(j); std::string field_name = FieldNameCapitalized(field); @@ -88,7 +88,7 @@ void OneofGenerator::GenerateCaseEnum(io::Printer* printer) { } void OneofGenerator::GeneratePublicCasePropertyDeclaration( - io::Printer* printer) { + io::Printer* printer) const { // clang-format off printer->Print( variables_, @@ -98,7 +98,8 @@ void OneofGenerator::GeneratePublicCasePropertyDeclaration( // clang-format on } -void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { +void OneofGenerator::GenerateClearFunctionDeclaration( + io::Printer* printer) const { // clang-format off printer->Print( variables_, @@ -109,11 +110,13 @@ void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { // clang-format on } -void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) { +void OneofGenerator::GeneratePropertyImplementation( + io::Printer* printer) const { printer->Print(variables_, "@dynamic $name$OneOfCase;\n"); } -void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { +void OneofGenerator::GenerateClearFunctionImplementation( + io::Printer* printer) const { // clang-format off printer->Print( variables_, diff --git a/src/google/protobuf/compiler/objectivec/oneof.h b/src/google/protobuf/compiler/objectivec/oneof.h index d9a23f902c..398a9623dd 100644 --- a/src/google/protobuf/compiler/objectivec/oneof.h +++ b/src/google/protobuf/compiler/objectivec/oneof.h @@ -53,13 +53,13 @@ class OneofGenerator { void SetOneofIndexBase(int index_base); - void GenerateCaseEnum(io::Printer* printer); + void GenerateCaseEnum(io::Printer* printer) const; - void GeneratePublicCasePropertyDeclaration(io::Printer* printer); - void GenerateClearFunctionDeclaration(io::Printer* printer); + void GeneratePublicCasePropertyDeclaration(io::Printer* printer) const; + void GenerateClearFunctionDeclaration(io::Printer* printer) const; - void GeneratePropertyImplementation(io::Printer* printer); - void GenerateClearFunctionImplementation(io::Printer* printer); + void GeneratePropertyImplementation(io::Printer* printer) const; + void GenerateClearFunctionImplementation(io::Printer* printer) const; std::string DescriptorName() const; std::string HasIndexAsString() const;