From cd6180d4c3c37d2e5a4f79a82c079125e850b6d4 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 28 Nov 2022 07:57:37 -0800 Subject: [PATCH] [ObjC] Generator const cleanups Label some more methods as const. Remove some method decls that don't exist (not sure where they came from). PiperOrigin-RevId: 491344000 --- .../protobuf/compiler/objectivec/enum.cc | 4 ++-- .../protobuf/compiler/objectivec/enum.h | 4 ++-- .../protobuf/compiler/objectivec/extension.cc | 9 +++++---- .../protobuf/compiler/objectivec/extension.h | 8 ++++---- .../protobuf/compiler/objectivec/message.cc | 7 ++++--- .../protobuf/compiler/objectivec/message.h | 19 ++++--------------- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/google/protobuf/compiler/objectivec/enum.cc b/src/google/protobuf/compiler/objectivec/enum.cc index 772751700a..6f9fbdae38 100644 --- a/src/google/protobuf/compiler/objectivec/enum.cc +++ b/src/google/protobuf/compiler/objectivec/enum.cc @@ -88,7 +88,7 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor) } } -void EnumGenerator::GenerateHeader(io::Printer* printer) { +void EnumGenerator::GenerateHeader(io::Printer* printer) const { std::string enum_comments; SourceLocation location; if (descriptor_->GetSourceLocation(&location)) { @@ -173,7 +173,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { "name", name_); } -void EnumGenerator::GenerateSource(io::Printer* printer) { +void EnumGenerator::GenerateSource(io::Printer* printer) const { printer->Print( "#pragma mark - Enum $name$\n" "\n", diff --git a/src/google/protobuf/compiler/objectivec/enum.h b/src/google/protobuf/compiler/objectivec/enum.h index 93b80ca12f..61338c8c48 100644 --- a/src/google/protobuf/compiler/objectivec/enum.h +++ b/src/google/protobuf/compiler/objectivec/enum.h @@ -51,8 +51,8 @@ class EnumGenerator { EnumGenerator(const EnumGenerator&) = delete; EnumGenerator& operator=(const EnumGenerator&) = delete; - void GenerateHeader(io::Printer* printer); - void GenerateSource(io::Printer* printer); + void GenerateHeader(io::Printer* printer) const; + void GenerateSource(io::Printer* printer) const; const std::string& name() const { return name_; } diff --git a/src/google/protobuf/compiler/objectivec/extension.cc b/src/google/protobuf/compiler/objectivec/extension.cc index c16a1e55e0..d70b9a4123 100644 --- a/src/google/protobuf/compiler/objectivec/extension.cc +++ b/src/google/protobuf/compiler/objectivec/extension.cc @@ -63,7 +63,7 @@ ExtensionGenerator::ExtensionGenerator(const std::string& root_class_name, } } -void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { +void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) const { absl::flat_hash_map vars; vars["method_name"] = method_name_; if (IsRetainedName(method_name_)) { @@ -90,7 +90,7 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { } void ExtensionGenerator::GenerateStaticVariablesInitialization( - io::Printer* printer) { + io::Printer* printer) const { absl::flat_hash_map vars; vars["root_class_and_method_name"] = root_class_and_method_name_; const std::string containing_type = ClassName(descriptor_->containing_type()); @@ -146,7 +146,7 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization( } void ExtensionGenerator::DetermineObjectiveCClassDefinitions( - absl::btree_set* fwd_decls) { + absl::btree_set* fwd_decls) const { std::string extended_type = ClassName(descriptor_->containing_type()); fwd_decls->insert(ObjCClassDeclaration(extended_type)); ObjectiveCType objc_type = GetObjectiveCType(descriptor_); @@ -156,7 +156,8 @@ void ExtensionGenerator::DetermineObjectiveCClassDefinitions( } } -void ExtensionGenerator::GenerateRegistrationSource(io::Printer* printer) { +void ExtensionGenerator::GenerateRegistrationSource( + io::Printer* printer) const { // clang-format off printer->Print( "[registry addExtension:$root_class_and_method_name$];\n", diff --git a/src/google/protobuf/compiler/objectivec/extension.h b/src/google/protobuf/compiler/objectivec/extension.h index 9975c12ec1..c174e95b6c 100644 --- a/src/google/protobuf/compiler/objectivec/extension.h +++ b/src/google/protobuf/compiler/objectivec/extension.h @@ -51,11 +51,11 @@ class ExtensionGenerator { ExtensionGenerator(const ExtensionGenerator&) = delete; ExtensionGenerator& operator=(const ExtensionGenerator&) = delete; - void GenerateMembersHeader(io::Printer* printer); - void GenerateStaticVariablesInitialization(io::Printer* printer); - void GenerateRegistrationSource(io::Printer* printer); + void GenerateMembersHeader(io::Printer* printer) const; + void GenerateStaticVariablesInitialization(io::Printer* printer) const; + void GenerateRegistrationSource(io::Printer* printer) const; void DetermineObjectiveCClassDefinitions( - absl::btree_set* fwd_decls); + absl::btree_set* fwd_decls) const; private: std::string method_name_; diff --git a/src/google/protobuf/compiler/objectivec/message.cc b/src/google/protobuf/compiler/objectivec/message.cc index 5a909f672c..372a8186ae 100644 --- a/src/google/protobuf/compiler/objectivec/message.cc +++ b/src/google/protobuf/compiler/objectivec/message.cc @@ -204,7 +204,8 @@ void MessageGenerator::AddExtensionGenerators( } void MessageGenerator::DetermineForwardDeclarations( - absl::btree_set* fwd_decls, bool include_external_types) { + absl::btree_set* fwd_decls, + bool include_external_types) const { if (IsMapEntryMessage(descriptor_)) { return; } @@ -216,7 +217,7 @@ void MessageGenerator::DetermineForwardDeclarations( } void MessageGenerator::DetermineObjectiveCClassDefinitions( - absl::btree_set* fwd_decls) { + absl::btree_set* fwd_decls) const { if (!IsMapEntryMessage(descriptor_)) { for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* fieldDescriptor = descriptor_->field(i); @@ -232,7 +233,7 @@ void MessageGenerator::DetermineObjectiveCClassDefinitions( } } -void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { +void MessageGenerator::GenerateMessageHeader(io::Printer* printer) const { // This a a map entry message, just recurse and do nothing directly. if (IsMapEntryMessage(descriptor_)) { return; diff --git a/src/google/protobuf/compiler/objectivec/message.h b/src/google/protobuf/compiler/objectivec/message.h index f7ae1453c1..9a732d61b6 100644 --- a/src/google/protobuf/compiler/objectivec/message.h +++ b/src/google/protobuf/compiler/objectivec/message.h @@ -60,34 +60,23 @@ class MessageGenerator { void AddExtensionGenerators( std::vector>* extension_generators); - void GenerateMessageHeader(io::Printer* printer); + void GenerateMessageHeader(io::Printer* printer) const; void GenerateSource(io::Printer* printer); void DetermineObjectiveCClassDefinitions( - absl::btree_set* fwd_decls); + absl::btree_set* fwd_decls) const; void DetermineForwardDeclarations(absl::btree_set* fwd_decls, - bool include_external_types); + bool include_external_types) const; // Checks if the message or a nested message includes a oneof definition. bool IncludesOneOfDefinition() const { return !oneof_generators_.empty(); } private: - void GenerateParseFromMethodsHeader(io::Printer* printer); - - void GenerateSerializeOneFieldSource(io::Printer* printer, - const FieldDescriptor* field); - void GenerateSerializeOneExtensionRangeSource( - io::Printer* printer, const Descriptor::ExtensionRange* range); - - void GenerateMessageDescriptionSource(io::Printer* printer); - void GenerateDescriptionOneFieldSource(io::Printer* printer, - const FieldDescriptor* field); - const std::string root_classname_; const Descriptor* descriptor_; FieldGeneratorMap field_generators_; const std::string class_name_; const std::string deprecated_attribute_; - std::vector extension_generators_; + std::vector extension_generators_; std::vector> oneof_generators_; };