aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2017-12-01 10:05:19 -0800
committerGravatar Adam Cozzette <acozzette@google.com>2017-12-01 10:05:19 -0800
commit0ba8eea655a5e40d19ab95c773192b5d908c5a61 (patch)
tree4c2c97ade1ab197d361c146bacae5adde55986bf /src/google/protobuf/compiler
parent92a7e778e7394386f413cec28d67a07630f784b1 (diff)
parenta711e3d5b4ee1dd7f9d21197dca8432a5819a64e (diff)
Merge branch 'master' into down-integrate
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc2
-rw-r--r--src/google/protobuf/compiler/command_line_interface_unittest.cc2
-rw-r--r--src/google/protobuf/compiler/importer.cc2
-rw-r--r--src/google/protobuf/compiler/objectivec/objectivec_helpers.cc17
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc36
-rw-r--r--src/google/protobuf/compiler/php/php_generator.h9
-rw-r--r--src/google/protobuf/compiler/plugin.cc2
-rw-r--r--src/google/protobuf/compiler/plugin.pb.h4
8 files changed, 53 insertions, 21 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 6c2fc164..1f6d748d 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -100,7 +100,7 @@ namespace compiler {
#endif
namespace {
-#if defined(_MSC_VER)
+#if defined(_WIN32)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 38d0e388..ef7579a2 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -70,7 +70,7 @@ namespace google {
namespace protobuf {
namespace compiler {
-#if defined(_MSC_VER)
+#if defined(_WIN32)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index 9792ffe8..a5341e0d 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -65,7 +65,7 @@ namespace google {
namespace protobuf {
namespace compiler {
-#ifdef _MSC_VER
+#ifdef _WIN32
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::access;
diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
index 54dc7455..14715ef6 100644
--- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -50,11 +50,6 @@
#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/strutil.h>
-#if defined(_MSC_VER)
-// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
-// them like we do below.
-using google::protobuf::internal::win32::open;
-#endif
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
@@ -64,6 +59,16 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
+// <io.h> is transitively included in this file. Import the functions explicitly
+// in this port namespace to avoid ambiguous definition.
+namespace posix {
+#ifdef _WIN32
+using ::google::protobuf::internal::win32::open;
+#else
+using ::open;
+#endif
+} // namespace port
+
Options::Options() {
// Default is the value of the env for the package prefixes.
const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES");
@@ -1469,7 +1474,7 @@ bool ParseSimpleFile(
const string& path, LineConsumer* line_consumer, string* out_error) {
int fd;
do {
- fd = open(path.c_str(), O_RDONLY);
+ fd = posix::open(path.c_str(), O_RDONLY);
} while (fd < 0 && errno == EINTR);
if (fd < 0) {
*out_error =
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index e4364ac2..dd4392c2 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -215,19 +215,12 @@ std::string NamespacedName(const string& classname,
template <typename DescriptorType>
std::string FullClassName(const DescriptorType* desc, bool is_descriptor) {
- string classname = desc->name();
- const Descriptor* containing = desc->containing_type();
- while (containing != NULL) {
- classname = containing->name() + '_' + classname;
- containing = containing->containing_type();
- }
- classname = ClassNamePrefix(classname, desc) + classname;
+ string classname = GeneratedClassName(desc);
return NamespacedName(classname, desc, is_descriptor);
}
std::string FullClassName(const ServiceDescriptor* desc, bool is_descriptor) {
- string classname = desc->name();
- classname = ClassNamePrefix(classname, desc) + classname;
+ string classname = GeneratedClassName(desc);
return NamespacedName(classname, desc, is_descriptor);
}
@@ -1419,6 +1412,31 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter,
return true;
}
+std::string GeneratedClassName(const Descriptor* desc) {
+ std::string classname = desc->name();
+ const Descriptor* containing = desc->containing_type();
+ while (containing != NULL) {
+ classname = containing->name() + '_' + classname;
+ containing = containing->containing_type();
+ }
+ return ClassNamePrefix(classname, desc) + classname;
+}
+
+std::string GeneratedClassName(const EnumDescriptor* desc) {
+ std::string classname = desc->name();
+ const Descriptor* containing = desc->containing_type();
+ while (containing != NULL) {
+ classname = containing->name() + '_' + classname;
+ containing = containing->containing_type();
+ }
+ return ClassNamePrefix(classname, desc) + classname;
+}
+
+std::string GeneratedClassName(const ServiceDescriptor* desc) {
+ std::string classname = desc->name();
+ return ClassNamePrefix(classname, desc) + classname;
+}
+
} // namespace php
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/php/php_generator.h b/src/google/protobuf/compiler/php/php_generator.h
index ce2b000a..67e70bc7 100644
--- a/src/google/protobuf/compiler/php/php_generator.h
+++ b/src/google/protobuf/compiler/php/php_generator.h
@@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/descriptor.h>
#include <string>
@@ -47,8 +48,16 @@ class LIBPROTOC_EXPORT Generator
const string& parameter,
GeneratorContext* generator_context,
string* error) const;
+
};
+// To skip reserved keywords in php, some generated classname are prefixed.
+// Other code generators may need following API to figure out the actual
+// classname.
+std::string GeneratedClassName(const google::protobuf::Descriptor* desc);
+std::string GeneratedClassName(const google::protobuf::EnumDescriptor* desc);
+std::string GeneratedClassName(const google::protobuf::ServiceDescriptor* desc);
+
} // namespace php
} // namespace compiler
} // namespace protobuf
diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc
index 7f975510..bde3d798 100644
--- a/src/google/protobuf/compiler/plugin.cc
+++ b/src/google/protobuf/compiler/plugin.cc
@@ -54,7 +54,7 @@ namespace google {
namespace protobuf {
namespace compiler {
-#if defined(_MSC_VER)
+#if defined(_WIN32)
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
// them like we do below.
using google::protobuf::internal::win32::setmode;
diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h
index 617fd799..9618ec00 100644
--- a/src/google/protobuf/compiler/plugin.pb.h
+++ b/src/google/protobuf/compiler/plugin.pb.h
@@ -8,12 +8,12 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3004000
+#if GOOGLE_PROTOBUF_VERSION < 3005000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3004000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.