[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
pull/11056/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 64d3eeb1b3
commit cd6180d4c3
  1. 4
      src/google/protobuf/compiler/objectivec/enum.cc
  2. 4
      src/google/protobuf/compiler/objectivec/enum.h
  3. 9
      src/google/protobuf/compiler/objectivec/extension.cc
  4. 8
      src/google/protobuf/compiler/objectivec/extension.h
  5. 7
      src/google/protobuf/compiler/objectivec/message.cc
  6. 19
      src/google/protobuf/compiler/objectivec/message.h

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

@ -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_; }

@ -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<absl::string_view, std::string> 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<absl::string_view, std::string> 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<std::string>* fwd_decls) {
absl::btree_set<std::string>* 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",

@ -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<std::string>* fwd_decls);
absl::btree_set<std::string>* fwd_decls) const;
private:
std::string method_name_;

@ -204,7 +204,8 @@ void MessageGenerator::AddExtensionGenerators(
}
void MessageGenerator::DetermineForwardDeclarations(
absl::btree_set<std::string>* fwd_decls, bool include_external_types) {
absl::btree_set<std::string>* fwd_decls,
bool include_external_types) const {
if (IsMapEntryMessage(descriptor_)) {
return;
}
@ -216,7 +217,7 @@ void MessageGenerator::DetermineForwardDeclarations(
}
void MessageGenerator::DetermineObjectiveCClassDefinitions(
absl::btree_set<std::string>* fwd_decls) {
absl::btree_set<std::string>* 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;

@ -60,34 +60,23 @@ class MessageGenerator {
void AddExtensionGenerators(
std::vector<std::unique_ptr<ExtensionGenerator>>* extension_generators);
void GenerateMessageHeader(io::Printer* printer);
void GenerateMessageHeader(io::Printer* printer) const;
void GenerateSource(io::Printer* printer);
void DetermineObjectiveCClassDefinitions(
absl::btree_set<std::string>* fwd_decls);
absl::btree_set<std::string>* fwd_decls) const;
void DetermineForwardDeclarations(absl::btree_set<std::string>* 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<ExtensionGenerator*> extension_generators_;
std::vector<const ExtensionGenerator*> extension_generators_;
std::vector<std::unique_ptr<OneofGenerator>> oneof_generators_;
};

Loading…
Cancel
Save