Skip to content

Commit

Permalink
[ObjC] Final const cleanups for generator.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 491355456
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 28, 2022
1 parent e8a9dcb commit 7a7bdde
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/objectivec/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -241,7 +241,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file,
}
}

void FileGenerator::GenerateHeader(io::Printer* printer) {
void FileGenerator::GenerateHeader(io::Printer* printer) const {
std::vector<std::string> headers;
// Generated files bundled with the library get minimal imports, everything
// else gets the wrapper so everything is usable.
Expand Down Expand Up @@ -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<std::string> headers;
headers.push_back("GPBProtocolBuffers_RuntimeSupport.h");
Expand All @@ -410,7 +410,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
}

std::vector<const FileDescriptor*> 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 =
Expand Down
10 changes: 5 additions & 5 deletions src/google/protobuf/compiler/objectivec/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::unique_ptr<EnumGenerator>> enum_generators_;
std::vector<std::unique_ptr<MessageGenerator>> message_generators_;
Expand Down
15 changes: 9 additions & 6 deletions src/google/protobuf/compiler/objectivec/oneof.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_,
Expand All @@ -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_,
Expand All @@ -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_,
Expand Down
10 changes: 5 additions & 5 deletions src/google/protobuf/compiler/objectivec/oneof.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7a7bdde

Please sign in to comment.