aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2017-10-11 14:44:03 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2017-10-11 14:44:03 -0700
commitde15e73d5862e8ac618bc7be90594adacbaa1ec6 (patch)
tree9d1f71f76902010963e0dc28db266de22b82646d /src
parentc4083bb3d1231f8a94f2f000434e38528bdff64a (diff)
parentbd798dfc81443cb95ff3b6e0b787c92031b113e5 (diff)
Merge remote-tracking branch 'origin/3.4.x' into master
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am10
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc60
-rw-r--r--src/google/protobuf/stubs/io_win32.cc4
3 files changed, 65 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2bc65664..b035fbd2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -564,8 +564,8 @@ protoc_inputs = \
google/protobuf/unittest_preserve_unknown_enum.proto \
google/protobuf/unittest.proto \
google/protobuf/unittest_proto3_arena.proto \
- google/protobuf/unittest_proto3_arena_lite.proto \
- google/protobuf/unittest_proto3_lite.proto \
+ google/protobuf/unittest_proto3_arena_lite.proto \
+ google/protobuf/unittest_proto3_lite.proto \
google/protobuf/unittest_well_known_types.proto \
google/protobuf/util/internal/testdata/anys.proto \
google/protobuf/util/internal/testdata/books.proto \
@@ -586,6 +586,12 @@ EXTRA_DIST = \
$(protoc_inputs) \
$(js_well_known_types_sources) \
solaris/libstdc++.la \
+ google/protobuf/unittest_proto3.proto \
+ google/protobuf/unittest_import_public_proto3.proto \
+ google/protobuf/unittest_import_proto3.proto \
+ google/protobuf/test_messages_proto3.proto \
+ google/protobuf/test_messages_proto2.proto \
+ google/protobuf/map_unittest_proto3.proto \
google/protobuf/io/gzip_stream.h \
google/protobuf/io/gzip_stream_unittest.sh \
google/protobuf/testdata/golden_message \
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])) {