diff options
author | Adam Cozzette <acozzette@google.com> | 2017-09-12 10:32:01 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2017-09-14 10:03:57 -0700 |
commit | 13fd045dbb2b4dacea32be162a41d5a4b0d1802f (patch) | |
tree | c219e7eb18b82523e36c6748861c403a14ea66ae /src/google/protobuf/compiler/cpp/cpp_enum.cc | |
parent | d1bc27caef8377a710370189675cb0958443e8f1 (diff) |
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_enum.cc')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_enum.cc | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 3b4b97e6..8adee0f5 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -197,6 +197,8 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) { vars["nested_name"] = descriptor_->name(); vars["classname"] = classname_; vars["constexpr"] = options_.proto_h ? "constexpr " : ""; + vars["{"] = ""; + vars["}"] = ""; printer->Print(vars, "typedef $classname$ $nested_name$;\n"); for (int j = 0; j < descriptor_->value_count(); j++) { @@ -204,22 +206,27 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) { vars["deprecated_attr"] = descriptor_->value(j)->options().deprecated() ? "GOOGLE_PROTOBUF_DEPRECATED_ATTR " : ""; printer->Print(vars, - "$deprecated_attr$static $constexpr$const $nested_name$ $tag$ =\n" + "$deprecated_attr$static $constexpr$const $nested_name$ ${$$tag$$}$ =\n" " $classname$_$tag$;\n"); + printer->Annotate("{", "}", descriptor_->value(j)); } printer->Print(vars, "static inline bool $nested_name$_IsValid(int value) {\n" " return $classname$_IsValid(value);\n" "}\n" - "static const $nested_name$ $nested_name$_MIN =\n" - " $classname$_$nested_name$_MIN;\n" - "static const $nested_name$ $nested_name$_MAX =\n" + "static const $nested_name$ ${$$nested_name$_MIN$}$ =\n" + " $classname$_$nested_name$_MIN;\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(vars, + "static const $nested_name$ ${$$nested_name$_MAX$}$ =\n" " $classname$_$nested_name$_MAX;\n"); + printer->Annotate("{", "}", descriptor_); if (generate_array_size_) { printer->Print(vars, - "static const int $nested_name$_ARRAYSIZE =\n" + "static const int ${$$nested_name$_ARRAYSIZE$}$ =\n" " $classname$_$nested_name$_ARRAYSIZE;\n"); + printer->Annotate("{", "}", descriptor_); } if (HasDescriptorMethods(descriptor_->file(), options_)) { @@ -242,27 +249,10 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) { } } -void EnumGenerator::GenerateDescriptorInitializer(io::Printer* printer) { - std::map<string, string> vars; - vars["index"] = SimpleItoa(descriptor_->index()); - vars["index_in_metadata"] = SimpleItoa(index_in_metadata_); - - if (descriptor_->containing_type() == NULL) { - printer->Print(vars, - "file_level_enum_descriptors[$index_in_metadata$] = " - "file->enum_type($index$);\n"); - } else { - vars["parent"] = ClassName(descriptor_->containing_type(), false); - printer->Print(vars, - "file_level_enum_descriptors[$index_in_metadata$] = " - "$parent$_descriptor->enum_type($index$);\n"); - } -} - -void EnumGenerator::GenerateMethods(io::Printer* printer) { +void EnumGenerator::GenerateMethods(int idx, io::Printer* printer) { std::map<string, string> vars; vars["classname"] = classname_; - vars["index_in_metadata"] = SimpleItoa(index_in_metadata_); + vars["index_in_metadata"] = SimpleItoa(idx); vars["constexpr"] = options_.proto_h ? "constexpr " : ""; vars["file_namespace"] = FileLevelNamespace(descriptor_->file()->name()); |