aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-04-26 16:32:21 -0700
committerGitHub <noreply@github.com>2017-04-26 16:32:21 -0700
commita6189acd18b00611c1dc7042299ad75486f08a1a (patch)
tree6371eddb9a4192e9fa3117af6bf534baef9d737d
parent3c0855e94ac4cf6c3c2e899ac88acf4fa56e9770 (diff)
downloadprotobuf-a6189acd18b00611c1dc7042299ad75486f08a1a.tar.gz
protobuf-a6189acd18b00611c1dc7042299ad75486f08a1a.tar.bz2
protobuf-a6189acd18b00611c1dc7042299ad75486f08a1a.zip
Add prefix to enum value with reserved name. (#3020)v3.3.0
-rw-r--r--php/tests/proto/test.proto1
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc8
2 files changed, 5 insertions, 4 deletions
diff --git a/php/tests/proto/test.proto b/php/tests/proto/test.proto
index f0d009c8..39229254 100644
--- a/php/tests/proto/test.proto
+++ b/php/tests/proto/test.proto
@@ -119,6 +119,7 @@ enum TestEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
+ ECHO = 3; // Test reserved name.
}
// Test prefix for reserved words.
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index 4d475b1f..ea850c0f 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -49,8 +49,8 @@ const std::string kDescriptorMetadataFile =
"GPBMetadata/Google/Protobuf/Internal/Descriptor.php";
const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
-const char* const kReservedNames[] = {"Empty"};
-const int kReservedNamesSize = 1;
+const char* const kReservedNames[] = {"Empty", "ECHO"};
+const int kReservedNamesSize = 2;
namespace google {
namespace protobuf {
@@ -559,7 +559,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) {
const EnumValueDescriptor* value = en->value(i);
printer->Print(
"->value(\"^name^\", ^number^)\n",
- "name", value->name(),
+ "name", ClassNamePrefix(value->name(), en) + value->name(),
"number", IntToString(value->number()));
}
printer->Print("->finalizeToPool();\n\n");
@@ -845,7 +845,7 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
const EnumValueDescriptor* value = en->value(i);
GenerateEnumValueDocComment(&printer, value);
printer.Print("const ^name^ = ^number^;\n",
- "name", value->name(),
+ "name", ClassNamePrefix(value->name(), en) + value->name(),
"number", IntToString(value->number()));
}