diff options
author | Jisi Liu <liujisi@google.com> | 2017-10-12 11:02:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 11:02:57 -0700 |
commit | a632f0dbac406227fad0951262f3b6160eaabebe (patch) | |
tree | dc1deefbd5f9261836f1cd0f3f9fc5a3b6c93c36 /src/google | |
parent | c4083bb3d1231f8a94f2f000434e38528bdff64a (diff) | |
parent | dd980ccf578892615a0090d6b5e7538142cb5690 (diff) | |
download | protobuf-a632f0dbac406227fad0951262f3b6160eaabebe.tar.gz protobuf-a632f0dbac406227fad0951262f3b6160eaabebe.tar.bz2 protobuf-a632f0dbac406227fad0951262f3b6160eaabebe.zip |
Merge pull request #3739 from pherl/merge3.4
Merge3.4
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/compiler/php/php_generator.cc | 60 | ||||
-rw-r--r-- | src/google/protobuf/stubs/io_win32.cc | 4 |
2 files changed, 57 insertions, 7 deletions
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 60e6fce9..e4364ac2 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -49,8 +49,28 @@ 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[] = {"ARRAY", "Empty", "ECHO"}; -const int kReservedNamesSize = 3; +const char* const kReservedNames[] = { + "abstract", "and", "array", "as", "break", + "callable", "case", "catch", "class", "clone", + "const", "continue", "declare", "default", "die", + "do", "echo", "else", "elseif", "empty", + "enddeclare", "endfor", "endforeach", "endif", "endswitch", + "endwhile", "eval", "exit", "extends", "final", + "for", "foreach", "function", "global", "goto", + "if", "implements", "include", "include_once", "instanceof", + "insteadof", "interface", "isset", "list", "namespace", + "new", "or", "print", "private", "protected", + "public", "require", "require_once", "return", "static", + "switch", "throw", "trait", "try", "unset", + "use", "var", "while", "xor", "int", + "float", "bool", "string", "true", "false", + "null", "void", "iterable"}; +const char* const kValidConstantNames[] = { + "int", "float", "bool", "string", "true", + "false", "null", "void", "iterable", +}; +const int kReservedNamesSize = 73; +const int kValidConstantNamesSize = 9; const int kFieldSetter = 1; const int kFieldGetter = 2; const int kFieldProperty = 3; @@ -125,8 +145,11 @@ std::string ClassNamePrefix(const string& classname, bool is_reserved = false; + string lower = classname; + transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + for (int i = 0; i < kReservedNamesSize; i++) { - if (classname == kReservedNames[i]) { + if (lower == kReservedNames[i]) { is_reserved = true; break; } @@ -143,6 +166,33 @@ std::string ClassNamePrefix(const string& classname, return ""; } +std::string ConstantNamePrefix(const string& classname) { + bool is_reserved = false; + + string lower = classname; + transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + for (int i = 0; i < kReservedNamesSize; i++) { + if (lower == kReservedNames[i]) { + is_reserved = true; + break; + } + } + + for (int i = 0; i < kValidConstantNamesSize; i++) { + if (lower == kValidConstantNames[i]) { + is_reserved = false; + break; + } + } + + if (is_reserved) { + return "PB"; + } + + return ""; +} + template <typename DescriptorType> std::string NamespacedName(const string& classname, const DescriptorType* desc, bool is_descriptor) { @@ -678,7 +728,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { const EnumValueDescriptor* value = en->value(i); printer->Print( "->value(\"^name^\", ^number^)\n", - "name", ClassNamePrefix(value->name(), en) + value->name(), + "name", ConstantNamePrefix(value->name()) + value->name(), "number", IntToString(value->number())); } printer->Print("->finalizeToPool();\n\n"); @@ -981,7 +1031,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", ClassNamePrefix(value->name(), en) + value->name(), + "name", ConstantNamePrefix(value->name()) + value->name(), "number", IntToString(value->number())); } diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index 51656a78..7e1cf785 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -195,12 +195,12 @@ string normalize(string path) { // Join all segments. bool first = true; std::ostringstream result; - for (const auto& s : segments) { + for (int i = 0; i < segments.size(); ++i) { if (!first) { result << '\\'; } first = false; - result << s; + result << segments[i]; } // Preserve trailing separator if the input contained it. if (!path.empty() && is_separator(path[path.size() - 1])) { |