diff options
Diffstat (limited to 'src')
59 files changed, 2091 insertions, 500 deletions
diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index 482db72f..0d8deab6 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -33,7 +33,7 @@ namespace google { namespace protobuf { class Any; class AnyDefaultTypeInternal; -extern AnyDefaultTypeInternal _Any_default_instance_; +LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 255eb4e3..f4699a5c 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -34,31 +34,31 @@ namespace google { namespace protobuf { class Api; class ApiDefaultTypeInternal; -extern ApiDefaultTypeInternal _Api_default_instance_; +LIBPROTOBUF_EXPORT extern ApiDefaultTypeInternal _Api_default_instance_; class Enum; class EnumDefaultTypeInternal; -extern EnumDefaultTypeInternal _Enum_default_instance_; +LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_; class EnumValue; class EnumValueDefaultTypeInternal; -extern EnumValueDefaultTypeInternal _EnumValue_default_instance_; +LIBPROTOBUF_EXPORT extern EnumValueDefaultTypeInternal _EnumValue_default_instance_; class Field; class FieldDefaultTypeInternal; -extern FieldDefaultTypeInternal _Field_default_instance_; +LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_; class Method; class MethodDefaultTypeInternal; -extern MethodDefaultTypeInternal _Method_default_instance_; +LIBPROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_; class Mixin; class MixinDefaultTypeInternal; -extern MixinDefaultTypeInternal _Mixin_default_instance_; +LIBPROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_; class Option; class OptionDefaultTypeInternal; -extern OptionDefaultTypeInternal _Option_default_instance_; +LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_; class SourceContext; class SourceContextDefaultTypeInternal; -extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; +LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; class Type; class TypeDefaultTypeInternal; -extern TypeDefaultTypeInternal _Type_default_instance_; +LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/compiler/code_generator.cc b/src/google/protobuf/compiler/code_generator.cc index 6bf101c3..11d0f334 100644 --- a/src/google/protobuf/compiler/code_generator.cc +++ b/src/google/protobuf/compiler/code_generator.cc @@ -34,6 +34,7 @@ #include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/compiler/plugin.pb.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/descriptor.h> @@ -89,6 +90,13 @@ void GeneratorContext::ListParsedFiles( GOOGLE_LOG(FATAL) << "This GeneratorContext does not support ListParsedFiles"; } +void GeneratorContext::GetCompilerVersion(Version* version) const { + version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000); + version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000); + version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000); + version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX); +} + // Parses a set of comma-delimited name/value pairs. void ParseGeneratorParameter(const string& text, std::vector<std::pair<string, string> >* output) { diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index a8b7e762..e2b2a661 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -50,6 +50,7 @@ namespace io { class ZeroCopyOutputStream; } class FileDescriptor; namespace compiler { +class Version; // Defined in this file. class CodeGenerator; @@ -143,6 +144,10 @@ class LIBPROTOC_EXPORT GeneratorContext { // differently when compiled as a set rather than individually. virtual void ListParsedFiles(std::vector<const FileDescriptor*>* output); + // Retrieves the version number of the protocol compiler associated with + // this GeneratorContext. + virtual void GetCompilerVersion(Version* version) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); }; diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 78ceb68c..bef0fe5a 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -1619,6 +1619,13 @@ bool CommandLineInterface::GeneratePluginOutput( &already_seen, request.mutable_proto_file()); } + google::protobuf::compiler::Version* version = + request.mutable_compiler_version(); + version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000); + version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000); + version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000); + version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX); + // Invoke the plugin. Subprocess subprocess; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index d5b5b185..b2ec8426 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -57,6 +57,7 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/unittest.pb.h> #include <google/protobuf/testing/file.h> +#include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> @@ -1582,6 +1583,21 @@ TEST_F(CommandLineInterfaceTest, PluginReceivesJsonName) { ExpectErrorSubstring("Saw json_name: 1"); } +TEST_F(CommandLineInterfaceTest, PluginReceivesCompilerVersion) { + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "message MockCodeGenerator_ShowVersionNumber {\n" + " optional int32 value = 1;\n" + "}\n"); + + Run("protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto"); + + ExpectErrorSubstring( + StringPrintf("Saw compiler_version: %d %s", + GOOGLE_PROTOBUF_VERSION, + GOOGLE_PROTOBUF_VERSION_SUFFIX)); +} + TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) { // Test what happens if the plugin isn't found. diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index bc664c70..d8fda59c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -403,7 +403,7 @@ class FileGenerator::ForwardDeclarations { std::map<string, const Descriptor*>& classes() { return classes_; } std::map<string, const EnumDescriptor*>& enums() { return enums_; } - void Print(io::Printer* printer) const { + void Print(io::Printer* printer, const Options& options) const { for (std::map<string, const EnumDescriptor *>::const_iterator it = enums_.begin(), end = enums_.end(); @@ -422,8 +422,11 @@ class FileGenerator::ForwardDeclarations { printer->Print( "class $classname$DefaultTypeInternal;\n" + "$dllexport_decl$" "extern $classname$DefaultTypeInternal " "_$classname$_default_instance_;\n", // NOLINT + "dllexport_decl", + options.dllexport_decl.empty() ? "" : options.dllexport_decl + " ", "classname", it->first); } @@ -433,7 +436,7 @@ class FileGenerator::ForwardDeclarations { it != end; ++it) { printer->Print("namespace $nsname$ {\n", "nsname", it->first); - it->second->Print(printer); + it->second->Print(printer, options); printer->Print("} // namespace $nsname$\n", "nsname", it->first); } @@ -808,7 +811,7 @@ void FileGenerator::GenerateForwardDeclarations(io::Printer* printer) { dependency.FillForwardDeclarations(&decls); } FillForwardDeclarations(&decls); - decls.Print(printer); + decls.Print(printer, options_); } void FileGenerator::FillForwardDeclarations(ForwardDeclarations* decls) { diff --git a/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc b/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc index 587e0222..636a76a0 100644 --- a/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc +++ b/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc @@ -74,7 +74,7 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) { printer->Print("///\n"); } last_was_empty = false; - printer->Print("/// $line$\n", "line", *it); + printer->Print("///$line$\n", "line", *it); } } printer->Print("/// </summary>\n"); diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc index 072cccad..be2ffdd4 100644 --- a/src/google/protobuf/compiler/js/embed.cc +++ b/src/google/protobuf/compiler/js/embed.cc @@ -28,9 +28,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <cassert> #include <cstdlib> #include <fstream> #include <iostream> +#include <string> const char output_file[] = "well_known_types_embed.cc"; diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.cc b/src/google/protobuf/compiler/js/well_known_types_embed.cc index b589ccb5..71fd557f 100755 --- a/src/google/protobuf/compiler/js/well_known_types_embed.cc +++ b/src/google/protobuf/compiler/js/well_known_types_embed.cc @@ -1,4 +1,4 @@ -#include "google/protobuf/compiler/js/well_known_types_embed.h" +#include <google/protobuf/compiler/js/well_known_types_embed.h> struct FileToc well_known_types_js[] = { {"any.js", "// Protocol Buffers - Google's data interchange format\n" diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 979814ec..e82e6ae1 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -40,6 +40,7 @@ #endif #include <vector> +#include <google/protobuf/compiler/plugin.pb.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/testing/file.h> @@ -160,6 +161,15 @@ bool MockCodeGenerator::Generate( std::cerr << "Saw json_name: " << field_descriptor_proto.has_json_name() << std::endl; abort(); + } else if (command == "ShowVersionNumber") { + Version compiler_version; + context->GetCompilerVersion(&compiler_version); + std::cerr << "Saw compiler_version: " + << compiler_version.major() * 1000000 + + compiler_version.minor() * 1000 + + compiler_version.patch() + << " " << compiler_version.suffix() << std::endl; + abort(); } else { GOOGLE_LOG(FATAL) << "Unknown MockCodeGenerator command: " << command; } diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc index 34e17823..02d60b3e 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum.cc @@ -74,7 +74,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) { printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n", "comments", enum_comments, - "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_), + "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()), "name", name_); printer->Indent(); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc index d0de1eca..7073173c 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_extension.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_extension.cc @@ -67,9 +67,12 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) { } else { vars["comments"] = ""; } + // Unlike normal message fields, check if the file for the extension was + // deprecated. + vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()); printer->Print(vars, "$comments$" - "+ (GPBExtensionDescriptor *)$method_name$;\n"); + "+ (GPBExtensionDescriptor *)$method_name$$deprecated_attribute$;\n"); } void ExtensionGenerator::GenerateStaticVariablesInitialization( diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index bbc6d8e9..c99262a1 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -150,8 +150,18 @@ enum FlagType { }; template<class TDescriptor> -string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpace = true, bool postNewline = false) { - if (descriptor->options().deprecated()) { +string GetOptionalDeprecatedAttribute( + const TDescriptor* descriptor, + const FileDescriptor* file = NULL, + bool preSpace = true, bool postNewline = false) { + bool isDeprecated = descriptor->options().deprecated(); + // The file is only passed when checking Messages & Enums, so those types + // get tagged. At the moment, it doesn't seem to make sense to tag every + // field or enum value with when the file is deprecated. + if (!isDeprecated && file) { + isDeprecated = file->options().deprecated(); + } + if (isDeprecated) { string result = "DEPRECATED_ATTRIBUTE"; if (preSpace) { result.insert(0, " "); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 4c6e1b55..e0bd3dac 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -180,7 +180,10 @@ MessageGenerator::MessageGenerator(const string& root_classname, : root_classname_(root_classname), descriptor_(descriptor), field_generators_(descriptor, options), - class_name_(ClassName(descriptor_)) { + class_name_(ClassName(descriptor_)), + deprecated_attribute_( + GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false, true)) { + for (int i = 0; i < descriptor_->extension_count(); i++) { extension_generators_.push_back( new ExtensionGenerator(class_name_, descriptor_->extension(i))); @@ -339,7 +342,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) { printer->Print( "$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n", "classname", class_name_, - "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, false, true), + "deprecated_attribute", deprecated_attribute_, "comments", message_comments); vector<char> seen_oneofs(descriptor_->oneof_decl_count(), 0); @@ -396,6 +399,14 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { "\n", "classname", class_name_); + if (!deprecated_attribute_.empty()) { + // No warnings when compiling the impl of this deprecated class. + printer->Print( + "#pragma clang diagnostic push\n" + "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n" + "\n"); + } + printer->Print("@implementation $classname$\n\n", "classname", class_name_); @@ -601,6 +612,12 @@ void MessageGenerator::GenerateSource(io::Printer* printer) { "}\n\n" "@end\n\n"); + if (!deprecated_attribute_.empty()) { + printer->Print( + "#pragma clang diagnostic pop\n" + "\n"); + } + for (int i = 0; i < descriptor_->field_count(); i++) { field_generators_.get(descriptor_->field(i)) .GenerateCFunctionImplementations(printer); diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.h b/src/google/protobuf/compiler/objectivec/objectivec_message.h index 910535ac..0fb78bc0 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.h @@ -85,6 +85,7 @@ class MessageGenerator { const Descriptor* descriptor_; FieldGeneratorMap field_generators_; const string class_name_; + const string deprecated_attribute_; vector<ExtensionGenerator*> extension_generators_; vector<EnumGenerator*> enum_generators_; vector<MessageGenerator*> nested_message_generators_; diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 83e629b9..be2739ff 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -43,6 +43,11 @@ using google::protobuf::internal::scoped_ptr; const std::string kDescriptorFile = "google/protobuf/descriptor.proto"; +const std::string kEmptyFile = "google/protobuf/empty.proto"; +const std::string kEmptyMetadataFile = "GPBMetadata/Google/Protobuf/GPBEmpty.php"; +const std::string kDescriptorMetadataFile = + "GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; +const std::string kDescriptorDirName = "Google/Protobuf/Internal"; const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; namespace google { @@ -52,25 +57,34 @@ namespace php { // Forward decls. std::string PhpName(const std::string& full_name, bool is_descriptor); -std::string DefaultForField(google::protobuf::FieldDescriptor* field); +std::string DefaultForField(FieldDescriptor* field); std::string IntToString(int32 value); -std::string GeneratedFileName(const std::string& proto_file, - bool is_descriptor); -std::string LabelForField(google::protobuf::FieldDescriptor* field); -std::string TypeName(google::protobuf::FieldDescriptor* field); +std::string FilenameToClassname(const string& filename); +std::string GeneratedMetadataFileName(const std::string& proto_file, + bool is_descriptor); +std::string LabelForField(FieldDescriptor* field); +std::string TypeName(FieldDescriptor* field); std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter); std::string EscapeDollor(const string& to_escape); std::string BinaryToHex(const string& binary); -void GenerateMessage(const string& name_prefix, - const google::protobuf::Descriptor* message, - bool is_descriptor, - google::protobuf::io::Printer* printer); -void GenerateEnum(const google::protobuf::EnumDescriptor* en, - google::protobuf::io::Printer* printer); -void Indent(google::protobuf::io::Printer* printer); -void Outdent(google::protobuf::io::Printer* printer); - -std::string MessagePrefix(const google::protobuf::Descriptor* message) { +void Indent(io::Printer* printer); +void Outdent(io::Printer* printer); +void GenerateMessageDocComment(io::Printer* printer, const Descriptor* message); +void GenerateFieldDocComment(io::Printer* printer, + const FieldDescriptor* field); +void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_); +void GenerateEnumValueDocComment(io::Printer* printer, + const EnumValueDescriptor* value); + +std::string RenameEmpty(const std::string& name) { + if (name == "Empty") { + return "GPBEmpty"; + } else { + return name; + } +} + +std::string MessagePrefix(const Descriptor* message) { // Empty cannot be php class name. if (message->name() == "Empty" && message->file()->package() == "google.protobuf") { @@ -80,10 +94,9 @@ std::string MessagePrefix(const google::protobuf::Descriptor* message) { } } -std::string MessageName(const google::protobuf::Descriptor* message, - bool is_descriptor) { +std::string MessageName(const Descriptor* message, bool is_descriptor) { string message_name = message->name(); - const google::protobuf::Descriptor* descriptor = message->containing_type(); + const Descriptor* descriptor = message->containing_type(); while (descriptor != NULL) { message_name = descriptor->name() + '_' + message_name; descriptor = descriptor->containing_type(); @@ -94,8 +107,7 @@ std::string MessageName(const google::protobuf::Descriptor* message, message_name; } -std::string MessageFullName(const google::protobuf::Descriptor* message, - bool is_descriptor) { +std::string MessageFullName(const Descriptor* message, bool is_descriptor) { if (is_descriptor) { return StringReplace(message->full_name(), "google.protobuf", @@ -105,8 +117,7 @@ std::string MessageFullName(const google::protobuf::Descriptor* message, } } -std::string EnumFullName(const google::protobuf::EnumDescriptor* envm, - bool is_descriptor) { +std::string EnumFullName(const EnumDescriptor* envm, bool is_descriptor) { if (is_descriptor) { return StringReplace(envm->full_name(), "google.protobuf", @@ -116,9 +127,9 @@ std::string EnumFullName(const google::protobuf::EnumDescriptor* envm, } } -std::string EnumClassName(const google::protobuf::EnumDescriptor* envm) { +std::string EnumClassName(const EnumDescriptor* envm) { string enum_class_name = envm->name(); - const google::protobuf::Descriptor* descriptor = envm->containing_type(); + const Descriptor* descriptor = envm->containing_type(); while (descriptor != NULL) { enum_class_name = descriptor->name() + '_' + enum_class_name; descriptor = descriptor->containing_type(); @@ -126,8 +137,7 @@ std::string EnumClassName(const google::protobuf::EnumDescriptor* envm) { return enum_class_name; } -std::string EnumName(const google::protobuf::EnumDescriptor* envm, - bool is_descriptor) { +std::string EnumName(const EnumDescriptor* envm, bool is_descriptor) { string enum_name = EnumClassName(envm); return PhpName(envm->file()->package(), is_descriptor) + '\\' + enum_name; } @@ -154,7 +164,7 @@ std::string PhpName(const std::string& full_name, bool is_descriptor) { return result; } -std::string DefaultForField(const google::protobuf::FieldDescriptor* field) { +std::string DefaultForField(const FieldDescriptor* field) { switch (field->type()) { case FieldDescriptor::TYPE_INT32: case FieldDescriptor::TYPE_INT64: @@ -178,14 +188,63 @@ std::string DefaultForField(const google::protobuf::FieldDescriptor* field) { } } -std::string GeneratedFileName(const std::string& proto_file, - bool is_descriptor) { +std::string GeneratedMetadataFileName(const std::string& proto_file, + bool is_descriptor) { + int start_index = 0; + int first_index = proto_file.find_first_of("/", start_index); + std::string result = "GPBMetadata/"; + + if (proto_file == kEmptyFile) { + return kEmptyMetadataFile; + } if (is_descriptor) { - return "descriptor_internal.pb.php"; + return kDescriptorMetadataFile; + } + + // Append directory name. + std::string file_no_suffix; + int lastindex = proto_file.find_last_of("."); + if (proto_file == kEmptyFile) { + return kEmptyMetadataFile; } else { - int lastindex = proto_file.find_last_of("."); - return proto_file.substr(0, lastindex) + ".pb.php"; + file_no_suffix = proto_file.substr(0, lastindex); + } + + while (first_index != string::npos) { + result += UnderscoresToCamelCase( + file_no_suffix.substr(start_index, first_index - start_index), true); + result += "/"; + start_index = first_index + 1; + first_index = file_no_suffix.find_first_of("/", start_index); } + + // Append file name. + result += RenameEmpty(UnderscoresToCamelCase( + file_no_suffix.substr(start_index, first_index - start_index), true)); + + return result += ".php"; +} + +std::string GeneratedMessageFileName(const Descriptor* message, + bool is_descriptor) { + std::string result = MessageName(message, is_descriptor); + for (int i = 0; i < result.size(); i++) { + if (result[i] == '\\') { + result[i] = '/'; + } + } + return result + ".php"; +} + +std::string GeneratedEnumFileName(const EnumDescriptor* en, + bool is_descriptor) { + std::string result = EnumName(en, is_descriptor); + for (int i = 0; i < result.size(); i++) { + if (result[i] == '\\') { + result[i] = '/'; + } + } + return result + ".php"; } std::string IntToString(int32 value) { @@ -194,7 +253,7 @@ std::string IntToString(int32 value) { return os.str(); } -std::string LabelForField(const google::protobuf::FieldDescriptor* field) { +std::string LabelForField(const FieldDescriptor* field) { switch (field->label()) { case FieldDescriptor::LABEL_OPTIONAL: return "optional"; case FieldDescriptor::LABEL_REQUIRED: return "required"; @@ -203,7 +262,7 @@ std::string LabelForField(const google::protobuf::FieldDescriptor* field) { } } -std::string TypeName(const google::protobuf::FieldDescriptor* field) { +std::string TypeName(const FieldDescriptor* field) { switch (field->type()) { case FieldDescriptor::TYPE_INT32: return "int32"; case FieldDescriptor::TYPE_INT64: return "int64"; @@ -228,7 +287,7 @@ std::string TypeName(const google::protobuf::FieldDescriptor* field) { } std::string EnumOrMessageSuffix( - const google::protobuf::FieldDescriptor* field, bool is_descriptor) { + const FieldDescriptor* field, bool is_descriptor) { if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { return ", '" + MessageFullName(field->message_type(), is_descriptor) + "'"; } @@ -299,74 +358,77 @@ std::string BinaryToHex(const string& src) { return dest; } -void Indent(google::protobuf::io::Printer* printer) { +void Indent(io::Printer* printer) { printer->Indent(); printer->Indent(); } -void Outdent(google::protobuf::io::Printer* printer) { +void Outdent(io::Printer* printer) { printer->Outdent(); printer->Outdent(); } -void GenerateField(const google::protobuf::FieldDescriptor* field, - google::protobuf::io::Printer* printer, bool is_descriptor) { +void GenerateField(const FieldDescriptor* field, io::Printer* printer, + bool is_descriptor) { if (field->is_repeated()) { + GenerateFieldDocComment(printer, field); printer->Print( - "private $@name@;\n", + "private $^name^;\n", "name", field->name()); } else if (field->containing_oneof()) { // Oneof fields are handled by GenerateOneofField. return; } else { + GenerateFieldDocComment(printer, field); printer->Print( - "private $@name@ = @default@;\n", + "private $^name^ = ^default^;\n", "name", field->name(), "default", DefaultForField(field)); } if (is_descriptor) { printer->Print( - "private $has_@name@ = false;\n", + "private $has_^name^ = false;\n", "name", field->name()); } } -void GenerateOneofField(const google::protobuf::OneofDescriptor* oneof, - google::protobuf::io::Printer* printer) { +void GenerateOneofField(const OneofDescriptor* oneof, io::Printer* printer) { // Oneof property needs to be protected in order to be accessed by parent // class in implementation. printer->Print( - "protected $@name@;\n", + "protected $^name^;\n", "name", oneof->name()); } -void GenerateFieldAccessor(const google::protobuf::FieldDescriptor* field, - bool is_descriptor, - google::protobuf::io::Printer* printer) { +void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, + io::Printer* printer) { const OneofDescriptor* oneof = field->containing_oneof(); // Generate getter. if (oneof != NULL) { + GenerateFieldDocComment(printer, field); printer->Print( - "public function get@camel_name@()\n" + "public function get^camel_name^()\n" "{\n" - " return $this->readOneof(@number@);\n" + " return $this->readOneof(^number^);\n" "}\n\n", "camel_name", UnderscoresToCamelCase(field->name(), true), "number", IntToString(field->number())); } else { + GenerateFieldDocComment(printer, field); printer->Print( - "public function get@camel_name@()\n" + "public function get^camel_name^()\n" "{\n" - " return $this->@name@;\n" + " return $this->^name^;\n" "}\n\n", "camel_name", UnderscoresToCamelCase(field->name(), true), "name", field->name()); } // Generate setter. + GenerateFieldDocComment(printer, field); printer->Print( - "public function set@camel_name@(@var@)\n" + "public function set^camel_name^(^var^)\n" "{\n", "camel_name", UnderscoresToCamelCase(field->name(), true), "var", (field->is_repeated() || @@ -379,16 +441,17 @@ void GenerateFieldAccessor(const google::protobuf::FieldDescriptor* field, if (field->is_map()) { } else if (field->is_repeated()) { printer->Print( - "GPBUtil::checkRepeatedField($var, GPBType::@type@", + "GPBUtil::checkRepeatedField($var, " + "\\Google\\Protobuf\\Internal\\GPBType::^type^", "type", ToUpper(field->type_name())); if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print( - ", \\@class_name@);\n", + ", \\^class_name^);\n", "class_name", MessageName(field->message_type(), is_descriptor) + "::class"); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer->Print( - ", @class_name@);\n", + ", ^class_name^);\n", "class_name", EnumName(field->enum_type(), is_descriptor) + "::class"); } else { @@ -396,37 +459,37 @@ void GenerateFieldAccessor(const google::protobuf::FieldDescriptor* field, } } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { printer->Print( - "GPBUtil::checkMessage($var, \\@class_name@::class);\n", + "GPBUtil::checkMessage($var, \\^class_name^::class);\n", "class_name", MessageName(field->message_type(), is_descriptor)); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { printer->Print( - "GPBUtil::checkEnum($var, \\@class_name@::class);\n", + "GPBUtil::checkEnum($var, \\^class_name^::class);\n", "class_name", EnumName(field->enum_type(), is_descriptor)); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { printer->Print( - "GPBUtil::checkString($var, @utf8@);\n", + "GPBUtil::checkString($var, ^utf8^);\n", "utf8", field->type() == FieldDescriptor::TYPE_STRING ? "True": "False"); } else { printer->Print( - "GPBUtil::check@type@($var);\n", + "GPBUtil::check^type^($var);\n", "type", UnderscoresToCamelCase(field->cpp_type_name(), true)); } if (oneof != NULL) { printer->Print( - "$this->writeOneof(@number@, $var);\n", + "$this->writeOneof(^number^, $var);\n", "number", IntToString(field->number())); } else { printer->Print( - "$this->@name@ = $var;\n", + "$this->^name^ = $var;\n", "name", field->name()); } // Set has bit for proto2 only. if (is_descriptor) { printer->Print( - "$this->has_@field_name@ = true;\n", + "$this->has_^field_name^ = true;\n", "field_name", field->name()); } @@ -438,127 +501,27 @@ void GenerateFieldAccessor(const google::protobuf::FieldDescriptor* field, // Generate has method for proto2 only. if (is_descriptor) { printer->Print( - "public function has@camel_name@()\n" + "public function has^camel_name^()\n" "{\n" - " return $this->has_@field_name@;\n" + " return $this->has_^field_name^;\n" "}\n\n", "camel_name", UnderscoresToCamelCase(field->name(), true), "field_name", field->name()); } } -void GenerateRepeatedFieldDecode( - const google::protobuf::FieldDescriptor* field, - google::protobuf::io::Printer* printer) { - printer->Print( - "if ($input->read@cap_wire_type@($var)) return False;\n" - "$this->get@cap_field_name@() []= $var;\n", - "cap_field_name", UnderscoresToCamelCase(field->name(), true), - "cap_wire_type", UnderscoresToCamelCase(field->type_name(), true)); -} - -void GeneratePrimitiveFieldDecode( - const google::protobuf::FieldDescriptor* field, - google::protobuf::io::Printer* printer) { - printer->Print( - "if ($input->read@cap_wire_type@($var)) return False;\n" - "$this->set@cap_field_name@($var);\n", - "cap_field_name", UnderscoresToCamelCase(field->name(), true), - "cap_wire_type", UnderscoresToCamelCase(field->type_name(), true)); -} - -void GenerateFieldDecode(const google::protobuf::FieldDescriptor* field, - google::protobuf::io::Printer* printer) { - printer->Print( - "case @number@:\n", - "number", IntToString(field->number())); - Indent(printer); - - if (field->is_repeated()) { - GenerateRepeatedFieldDecode(field, printer); - } else { - GeneratePrimitiveFieldDecode(field, printer); - } - - printer->Print( - "break;\n"); - Outdent(printer); -} - -void GenerateMessage(const string& name_prefix, - const google::protobuf::Descriptor* message, - bool is_descriptor, - google::protobuf::io::Printer* printer) { - // Don't generate MapEntry messages -- we use the PHP extension's native - // support for map fields instead. - if (message->options().map_entry()) { - return; - } - - string message_name = - name_prefix.empty() - ? message->name() - : name_prefix + "_" + MessagePrefix(message) + message->name(); - - printer->Print( - "class @name@ extends \\Google\\Protobuf\\Internal\\Message\n" - "{\n", - "name", message_name); - Indent(printer); - - // Field and oneof definitions. - for (int i = 0; i < message->field_count(); i++) { - const FieldDescriptor* field = message->field(i); - GenerateField(field, printer, is_descriptor); - } - for (int i = 0; i < message->oneof_decl_count(); i++) { - const OneofDescriptor* oneof = message->oneof_decl(i); - GenerateOneofField(oneof, printer); - } - printer->Print("\n"); - - // Field and oneof accessors. - for (int i = 0; i < message->field_count(); i++) { - const FieldDescriptor* field = message->field(i); - GenerateFieldAccessor(field, is_descriptor, printer); - } - for (int i = 0; i < message->oneof_decl_count(); i++) { - const google::protobuf::OneofDescriptor* oneof = message->oneof_decl(i); - printer->Print( - "public function get@camel_name@()\n" - "{\n" - " return $this->@name@;\n" - "}\n\n", - "camel_name", UnderscoresToCamelCase(oneof->name(), true), "name", - oneof->name()); - } - - Outdent(printer); - printer->Print("}\n\n"); - - // Nested messages and enums. - for (int i = 0; i < message->nested_type_count(); i++) { - GenerateMessage(message_name, message->nested_type(i), is_descriptor, - printer); - } - for (int i = 0; i < message->enum_type_count(); i++) { - GenerateEnum(message->enum_type(i), printer); - } -} - -void GenerateEnumToPool(const google::protobuf::EnumDescriptor* en, - bool is_descriptor, - google::protobuf::io::Printer* printer) { +void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { printer->Print( - "$pool->addEnum('@name@', @class_name@::class)\n", - "name", EnumFullName(en, is_descriptor), + "$pool->addEnum('^name^', " + "\\Google\\Protobuf\\Internal\\^class_name^::class)\n", + "name", EnumFullName(en, true), "class_name", en->name()); Indent(printer); for (int i = 0; i < en->value_count(); i++) { const EnumValueDescriptor* value = en->value(i); printer->Print( - "->value(\"@name@\", @number@)\n", + "->value(\"^name^\", ^number^)\n", "name", value->name(), "number", IntToString(value->number())); } @@ -566,10 +529,8 @@ void GenerateEnumToPool(const google::protobuf::EnumDescriptor* en, Outdent(printer); } -void GenerateMessageToPool(const string& name_prefix, - const google::protobuf::Descriptor* message, - bool is_descriptor, - google::protobuf::io::Printer* printer) { +void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, + io::Printer* printer) { // Don't generate MapEntry messages -- we use the PHP extension's native // support for map fields instead. if (message->options().map_entry()) { @@ -579,8 +540,9 @@ void GenerateMessageToPool(const string& name_prefix, message->name() : name_prefix + "_" + message->name(); printer->Print( - "$pool->addMessage('@message@', @class_name@::class)\n", - "message", MessageFullName(message, is_descriptor), + "$pool->addMessage('^message^', " + "\\Google\\Protobuf\\Internal\\^class_name^::class)\n", + "message", MessageFullName(message, true), "class_name", class_name); Indent(printer); @@ -593,38 +555,40 @@ void GenerateMessageToPool(const string& name_prefix, const FieldDescriptor* val = field->message_type()->FindFieldByName("value"); printer->Print( - "->map('@field@', GPBType::@key@, " - "GPBType::@value@, @number@@other@)\n", + "->map('^field^', \\Google\\Protobuf\\Internal\\GPBType::^key^, " + "\\Google\\Protobuf\\Internal\\GPBType::^value^, ^number^^other^)\n", "field", field->name(), "key", ToUpper(key->type_name()), "value", ToUpper(val->type_name()), "number", SimpleItoa(field->number()), - "other", EnumOrMessageSuffix(val, is_descriptor)); + "other", EnumOrMessageSuffix(val, true)); } else if (!field->containing_oneof()) { printer->Print( - "->@label@('@field@', GPBType::@type@, @number@@other@)\n", + "->^label^('^field^', " + "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n", "field", field->name(), "label", LabelForField(field), "type", ToUpper(field->type_name()), "number", SimpleItoa(field->number()), - "other", EnumOrMessageSuffix(field, is_descriptor)); + "other", EnumOrMessageSuffix(field, true)); } } // oneofs. for (int i = 0; i < message->oneof_decl_count(); i++) { const OneofDescriptor* oneof = message->oneof_decl(i); - printer->Print("->oneof(@name@)\n", + printer->Print("->oneof(^name^)\n", "name", oneof->name()); Indent(printer); for (int index = 0; index < oneof->field_count(); index++) { const FieldDescriptor* field = oneof->field(index); printer->Print( - "->value('@field@', GPBType::@type@, @number@@other@)\n", + "->value('^field^', " + "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n", "field", field->name(), "type", ToUpper(field->type_name()), "number", SimpleItoa(field->number()), - "other", EnumOrMessageSuffix(field, is_descriptor)); + "other", EnumOrMessageSuffix(field, true)); } printer->Print("->finish()\n"); Outdent(printer); @@ -639,33 +603,48 @@ void GenerateMessageToPool(const string& name_prefix, "\n"); for (int i = 0; i < message->nested_type_count(); i++) { - GenerateMessageToPool(class_name, message->nested_type(i), is_descriptor, - printer); + GenerateMessageToPool(class_name, message->nested_type(i), printer); } for (int i = 0; i < message->enum_type_count(); i++) { - GenerateEnumToPool(message->enum_type(i), is_descriptor, printer); + GenerateEnumToPool(message->enum_type(i), printer); } } -void GenerateAddFileToPool(const google::protobuf::FileDescriptor* file, - bool is_descriptor, - google::protobuf::io::Printer* printer) { - if (is_descriptor) { - printer->Print("$pool = DescriptorPool::getGeneratedPool();\n\n"); +void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, + io::Printer* printer) { + printer->Print( + "public static $is_initialized = false;\n\n" + "public static function initOnce() {\n"); + Indent(printer); + printer->Print( + "$pool = \\Google\\Protobuf\\Internal\\" + "DescriptorPool::getGeneratedPool();\n\n" + "if (static::$is_initialized == true) {\n" + " return;\n" + "}\n"); + + if (is_descriptor) { for (int i = 0; i < file->message_type_count(); i++) { - GenerateMessageToPool("", file->message_type(i), is_descriptor, printer); + GenerateMessageToPool("", file->message_type(i), printer); } for (int i = 0; i < file->enum_type_count(); i++) { - GenerateEnumToPool(file->enum_type(i), is_descriptor, printer); + GenerateEnumToPool(file->enum_type(i), printer); } printer->Print( "$pool->finish();\n"); } else { - // Add messages and enums to descriptor pool. - printer->Print("$pool = DescriptorPool::getGeneratedPool();\n\n"); + for (int i = 0; i < file->dependency_count(); i++) { + const std::string& name = file->dependency(i)->name(); + std::string dependency_filename = + GeneratedMetadataFileName(name, is_descriptor); + printer->Print( + "\\^name^::initOnce();\n", + "name", FilenameToClassname(dependency_filename)); + } + // Add messages and enums to descriptor pool. FileDescriptorSet files; FileDescriptorProto* file_proto = files.add_file(); file->CopyTo(file_proto); @@ -679,7 +658,7 @@ void GenerateAddFileToPool(const google::protobuf::FileDescriptor* file, static const int kBytesPerLine = 30; for (int i = 0; i < files_data.size(); i += kBytesPerLine) { printer->Print( - "\"@data@\"@dot@\n", + "\"^data^\"^dot^\n", "data", BinaryToHex(files_data.substr(i, kBytesPerLine)), "dot", i + kBytesPerLine < files_data.size() ? " ." : ""); } @@ -688,38 +667,20 @@ void GenerateAddFileToPool(const google::protobuf::FileDescriptor* file, printer->Print( "));\n\n"); } - -} - -void GenerateEnum(const google::protobuf::EnumDescriptor* en, - google::protobuf::io::Printer* printer) { printer->Print( - "class @name@\n" - "{\n", - "name", EnumClassName(en)); - Indent(printer); - - for (int i = 0; i < en->value_count(); i++) { - const EnumValueDescriptor* value = en->value(i); - printer->Print("const @name@ = @number@;\n", - "name", value->name(), - "number", IntToString(value->number())); - } + "static::$is_initialized = true;\n"); Outdent(printer); - printer->Print("}\n\n"); + printer->Print("}\n"); } -void GenerateUseDeclaration(bool is_descriptor, - google::protobuf::io::Printer* printer) { +void GenerateUseDeclaration(bool is_descriptor, io::Printer* printer) { if (!is_descriptor) { printer->Print( - "use Google\\Protobuf\\Internal\\DescriptorPool;\n" "use Google\\Protobuf\\Internal\\GPBType;\n" "use Google\\Protobuf\\Internal\\RepeatedField;\n" "use Google\\Protobuf\\Internal\\GPBUtil;\n\n"); } else { printer->Print( - "use Google\\Protobuf\\Internal\\DescriptorPool;\n" "use Google\\Protobuf\\Internal\\GPBType;\n" "use Google\\Protobuf\\Internal\\GPBWire;\n" "use Google\\Protobuf\\Internal\\RepeatedField;\n" @@ -728,42 +689,377 @@ void GenerateUseDeclaration(bool is_descriptor, } } -void GenerateFile(const google::protobuf::FileDescriptor* file, - bool is_descriptor, google::protobuf::io::Printer* printer) { +void GenerateHead(const FileDescriptor* file, io::Printer* printer) { printer->Print( "<?php\n" "# Generated by the protocol buffer compiler. DO NOT EDIT!\n" - "# source: @filename@\n" + "# source: ^filename^\n" "\n", "filename", file->name()); +} + +std::string FilenameToClassname(const string& filename) { + int lastindex = filename.find_last_of("."); + std::string result = filename.substr(0, lastindex); + for (int i = 0; i < result.size(); i++) { + if (result[i] == '/') { + result[i] = '\\'; + } + } + return result; +} + +void GenerateMetadataFile(const FileDescriptor* file, + bool is_descriptor, + GeneratorContext* generator_context) { + std::string filename = GeneratedMetadataFileName(file->name(), is_descriptor); + scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(filename)); + io::Printer printer(output.get(), '^'); + + GenerateHead(file, &printer); + + std::string fullname = FilenameToClassname(filename); + int lastindex = fullname.find_last_of("\\"); + + printer.Print( + "namespace ^name^;\n\n", + "name", fullname.substr(0, lastindex)); + + if (lastindex != string::npos) { + printer.Print( + "class ^name^\n" + "{\n", + "name", fullname.substr(lastindex + 1)); + } else { + printer.Print( + "class ^name^\n" + "{\n", + "name", fullname); + } + Indent(&printer); + + GenerateAddFileToPool(file, is_descriptor, &printer); + + Outdent(&printer); + printer.Print("}\n\n"); +} + +void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, + bool is_descriptor, GeneratorContext* generator_context) { + std::string filename = GeneratedEnumFileName(en, is_descriptor); + scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(filename)); + io::Printer printer(output.get(), '^'); + + GenerateHead(file, &printer); + + std::string fullname = FilenameToClassname(filename); + int lastindex = fullname.find_last_of("\\"); + + GenerateEnumDocComment(&printer, en); + if (lastindex != string::npos) { + printer.Print( + "namespace ^name^;\n\n", + "name", fullname.substr(0, lastindex)); + + printer.Print( + "class ^name^\n" + "{\n", + "name", fullname.substr(lastindex + 1)); + } else { + printer.Print( + "class ^name^\n" + "{\n", + "name", fullname); + } + Indent(&printer); + + for (int i = 0; i < en->value_count(); i++) { + const EnumValueDescriptor* value = en->value(i); + GenerateEnumValueDocComment(&printer, value); + printer.Print("const ^name^ = ^number^;\n", + "name", value->name(), + "number", IntToString(value->number())); + } + + Outdent(&printer); + printer.Print("}\n\n"); +} + +void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message, + bool is_descriptor, + GeneratorContext* generator_context) { + // Don't generate MapEntry messages -- we use the PHP extension's native + // support for map fields instead. + if (message->options().map_entry()) { + return; + } + + std::string filename = GeneratedMessageFileName(message, is_descriptor); + scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(filename)); + io::Printer printer(output.get(), '^'); + + GenerateHead(file, &printer); + + std::string fullname = FilenameToClassname(filename); + int lastindex = fullname.find_last_of("\\"); + if (!file->package().empty()) { - printer->Print("namespace @name@;\n\n", - "name", PhpName(file->package(), is_descriptor)); + printer.Print( + "namespace ^name^;\n\n", + "name", fullname.substr(0, lastindex)); + } + + GenerateUseDeclaration(is_descriptor, &printer); + + GenerateMessageDocComment(&printer, message); + if (lastindex != string::npos) { + printer.Print( + "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n" + "{\n", + "name", fullname.substr(lastindex + 1)); + } else { + printer.Print( + "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n" + "{\n", + "name", fullname); + } + Indent(&printer); + + // Field and oneof definitions. + for (int i = 0; i < message->field_count(); i++) { + const FieldDescriptor* field = message->field(i); + GenerateField(field, &printer, is_descriptor); + } + for (int i = 0; i < message->oneof_decl_count(); i++) { + const OneofDescriptor* oneof = message->oneof_decl(i); + GenerateOneofField(oneof, &printer); } + printer.Print("\n"); - for (int i = 0; i < file->dependency_count(); i++) { - const std::string& name = file->dependency(i)->name(); - printer->Print("require_once('@name@');\n", "name", - GeneratedFileName(name, is_descriptor)); + printer.Print( + "public function __construct() {\n"); + Indent(&printer); + + std::string metadata_filename = + GeneratedMetadataFileName(file->name(), is_descriptor); + std::string metadata_fullname = FilenameToClassname(metadata_filename); + printer.Print( + "\\^fullname^::initOnce();\n" + "parent::__construct();\n", + "fullname", metadata_fullname); + + Outdent(&printer); + printer.Print("}\n\n"); + + // Field and oneof accessors. + for (int i = 0; i < message->field_count(); i++) { + const FieldDescriptor* field = message->field(i); + GenerateFieldAccessor(field, is_descriptor, &printer); + } + for (int i = 0; i < message->oneof_decl_count(); i++) { + const OneofDescriptor* oneof = message->oneof_decl(i); + printer.Print( + "public function get^camel_name^()\n" + "{\n" + " return $this->^name^;\n" + "}\n\n", + "camel_name", UnderscoresToCamelCase(oneof->name(), true), "name", + oneof->name()); } - GenerateUseDeclaration(is_descriptor, printer); + Outdent(&printer); + printer.Print("}\n\n"); + + // Nested messages and enums. + for (int i = 0; i < message->nested_type_count(); i++) { + GenerateMessageFile(file, message->nested_type(i), is_descriptor, + generator_context); + } + for (int i = 0; i < message->enum_type_count(); i++) { + GenerateEnumFile(file, message->enum_type(i), is_descriptor, + generator_context); + } +} +void GenerateFile(const FileDescriptor* file, bool is_descriptor, + GeneratorContext* generator_context) { + GenerateMetadataFile(file, is_descriptor, generator_context); for (int i = 0; i < file->message_type_count(); i++) { - GenerateMessage("", file->message_type(i), is_descriptor, printer); + GenerateMessageFile(file, file->message_type(i), is_descriptor, + generator_context); } for (int i = 0; i < file->enum_type_count(); i++) { - GenerateEnum(file->enum_type(i), printer); + GenerateEnumFile(file, file->enum_type(i), is_descriptor, + generator_context); } +} + +static string EscapePhpdoc(const string& input) { + string result; + result.reserve(input.size() * 2); + + char prev = '*'; + + for (string::size_type i = 0; i < input.size(); i++) { + char c = input[i]; + switch (c) { + case '*': + // Avoid "/*". + if (prev == '/') { + result.append("*"); + } else { + result.push_back(c); + } + break; + case '/': + // Avoid "*/". + if (prev == '*') { + result.append("/"); + } else { + result.push_back(c); + } + break; + case '@': + // '@' starts phpdoc tags including the @deprecated tag, which will + // cause a compile-time error if inserted before a declaration that + // does not have a corresponding @Deprecated annotation. + result.append("@"); + break; + case '<': + // Avoid interpretation as HTML. + result.append("<"); + break; + case '>': + // Avoid interpretation as HTML. + result.append(">"); + break; + case '&': + // Avoid interpretation as HTML. + result.append("&"); + break; + case '\\': + // Java interprets Unicode escape sequences anywhere! + result.append("\"); + break; + default: + result.push_back(c); + break; + } - GenerateAddFileToPool(file, is_descriptor, printer); + prev = c; + } + + return result; } -bool Generator::Generate( - const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const { +static void GenerateDocCommentBodyForLocation( + io::Printer* printer, const SourceLocation& location) { + string comments = location.leading_comments.empty() ? + location.trailing_comments : location.leading_comments; + if (!comments.empty()) { + // TODO(teboring): Ideally we should parse the comment text as Markdown and + // write it back as HTML, but this requires a Markdown parser. For now + // we just use <pre> to get fixed-width text formatting. + + // If the comment itself contains block comment start or end markers, + // HTML-escape them so that they don't accidentally close the doc comment. + comments = EscapePhpdoc(comments); + + vector<string> lines = Split(comments, "\n"); + while (!lines.empty() && lines.back().empty()) { + lines.pop_back(); + } + + printer->Print(" * <pre>\n"); + for (int i = 0; i < lines.size(); i++) { + // Most lines should start with a space. Watch out for lines that start + // with a /, since putting that right after the leading asterisk will + // close the comment. + if (!lines[i].empty() && lines[i][0] == '/') { + printer->Print(" * ^line^\n", "line", lines[i]); + } else { + printer->Print(" *^line^\n", "line", lines[i]); + } + } + printer->Print( + " * </pre>\n" + " *\n"); + } +} + +template <typename DescriptorType> +static void GenerateDocCommentBody( + io::Printer* printer, const DescriptorType* descriptor) { + SourceLocation location; + if (descriptor->GetSourceLocation(&location)) { + GenerateDocCommentBodyForLocation(printer, location); + } +} + +static string FirstLineOf(const string& value) { + string result = value; + + string::size_type pos = result.find_first_of('\n'); + if (pos != string::npos) { + result.erase(pos); + } + + return result; +} + +void GenerateMessageDocComment(io::Printer* printer, + const Descriptor* message) { + printer->Print("/**\n"); + GenerateDocCommentBody(printer, message); + printer->Print( + " * Protobuf type <code>^fullname^</code>\n" + " */\n", + "fullname", EscapePhpdoc(message->full_name())); +} + +void GenerateFieldDocComment(io::Printer* printer, + const FieldDescriptor* field) { + // In theory we should have slightly different comments for setters, getters, + // etc., but in practice everyone already knows the difference between these + // so it's redundant information. + + // We start the comment with the main body based on the comments from the + // .proto file (if present). We then end with the field declaration, e.g.: + // optional string foo = 5; + // If the field is a group, the debug string might end with {. + printer->Print("/**\n"); + GenerateDocCommentBody(printer, field); + printer->Print( + " * <code>^def^</code>\n", + "def", EscapePhpdoc(FirstLineOf(field->DebugString()))); + printer->Print(" */\n"); +} + +void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) { + printer->Print("/**\n"); + GenerateDocCommentBody(printer, enum_); + printer->Print( + " * Protobuf enum <code>^fullname^</code>\n" + " */\n", + "fullname", EscapePhpdoc(enum_->full_name())); +} + +void GenerateEnumValueDocComment(io::Printer* printer, + const EnumValueDescriptor* value) { + printer->Print("/**\n"); + GenerateDocCommentBody(printer, value); + printer->Print( + " * <code>^def^</code>\n" + " */\n", + "def", EscapePhpdoc(FirstLineOf(value->DebugString()))); +} + +bool Generator::Generate(const FileDescriptor* file, const string& parameter, + GeneratorContext* generator_context, + string* error) const { bool is_descriptor = parameter == "internal"; if (is_descriptor && file->name() != kDescriptorFile) { @@ -779,12 +1075,7 @@ bool Generator::Generate( return false; } - std::string filename = GeneratedFileName(file->name(), is_descriptor); - scoped_ptr<io::ZeroCopyOutputStream> output( - generator_context->Open(filename)); - io::Printer printer(output.get(), '@'); - - GenerateFile(file, is_descriptor, &printer); + GenerateFile(file, is_descriptor, generator_context); return true; } diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index dcccb3d4..3848101d 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -63,9 +63,12 @@ namespace compiler { class GeneratorResponseContext : public GeneratorContext { public: GeneratorResponseContext( + const Version& compiler_version, CodeGeneratorResponse* response, const std::vector<const FileDescriptor*>& parsed_files) - : response_(response), parsed_files_(parsed_files) {} + : compiler_version_(compiler_version), + response_(response), + parsed_files_(parsed_files) {} virtual ~GeneratorResponseContext() {} // implements GeneratorContext -------------------------------------- @@ -88,7 +91,12 @@ class GeneratorResponseContext : public GeneratorContext { *output = parsed_files_; } + void GetCompilerVersion(Version* version) const { + *version = compiler_version_; + } + private: + Version compiler_version_; CodeGeneratorResponse* response_; const std::vector<const FileDescriptor*>& parsed_files_; }; @@ -116,7 +124,8 @@ bool GenerateCode(const CodeGeneratorRequest& request, } } - GeneratorResponseContext context(response, parsed_files); + GeneratorResponseContext context( + request.compiler_version(), response, parsed_files); string error; bool succeeded = generator.GenerateAll( diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index 0239e05f..bb78eff6 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -20,6 +20,8 @@ namespace google { namespace protobuf { namespace compiler { +class VersionDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Version> {}; +VersionDefaultTypeInternal _Version_default_instance_; class CodeGeneratorRequestDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorRequest> {}; CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; class CodeGeneratorResponse_FileDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse_File> {}; @@ -29,7 +31,7 @@ CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance namespace { -::google::protobuf::Metadata file_level_metadata[3]; +::google::protobuf::Metadata file_level_metadata[4]; } // namespace @@ -37,6 +39,18 @@ namespace { const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_2fplugin_2eproto() GOOGLE_ATTRIBUTE_COLD; const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { static const ::google::protobuf::uint32 offsets[] = { + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, major_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, minor_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, patch_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, suffix_), + 1, + 2, + 3, + 0, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_), ~0u, // no _extensions_ @@ -44,9 +58,11 @@ const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, file_to_generate_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, parameter_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, proto_file_), - 1, - 0, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, compiler_version_), 2, + 0, + 3, + 1, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_), ~0u, // no _extensions_ @@ -70,12 +86,14 @@ const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_ } static const ::google::protobuf::internal::MigrationSchema schemas[] = { - { 0, 7, sizeof(CodeGeneratorRequest)}, - { 10, 17, sizeof(CodeGeneratorResponse_File)}, - { 20, 26, sizeof(CodeGeneratorResponse)}, + { 0, 8, sizeof(Version)}, + { 12, 20, sizeof(CodeGeneratorRequest)}, + { 24, 31, sizeof(CodeGeneratorResponse_File)}, + { 34, 40, sizeof(CodeGeneratorResponse)}, }; static const ::google::protobuf::internal::DefaultInstanceData file_default_instances[] = { + {reinterpret_cast<const ::google::protobuf::Message*>(&_Version_default_instance_), NULL}, {reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorRequest_default_instance_), NULL}, {reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorResponse_File_default_instance_), NULL}, {reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorResponse_default_instance_), NULL}, @@ -99,18 +117,20 @@ void protobuf_AssignDescriptorsOnce() { void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); - ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4); } } // namespace void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { - _CodeGeneratorRequest_default_instance_.Shutdown(); + _Version_default_instance_.Shutdown(); delete file_level_metadata[0].reflection; - _CodeGeneratorResponse_File_default_instance_.Shutdown(); + _CodeGeneratorRequest_default_instance_.Shutdown(); delete file_level_metadata[1].reflection; - _CodeGeneratorResponse_default_instance_.Shutdown(); + _CodeGeneratorResponse_File_default_instance_.Shutdown(); delete file_level_metadata[2].reflection; + _CodeGeneratorResponse_default_instance_.Shutdown(); + delete file_level_metadata[3].reflection; } void protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl() { @@ -118,9 +138,12 @@ void protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl() ::google::protobuf::protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); ::google::protobuf::internal::InitProtobufDefaults(); + _Version_default_instance_.DefaultConstruct(); _CodeGeneratorRequest_default_instance_.DefaultConstruct(); _CodeGeneratorResponse_File_default_instance_.DefaultConstruct(); _CodeGeneratorResponse_default_instance_.DefaultConstruct(); + _CodeGeneratorRequest_default_instance_.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>( + ::google::protobuf::compiler::Version::internal_default_instance()); } void protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto() { @@ -132,19 +155,22 @@ void protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl() { static const char descriptor[] = { "\n%google/protobuf/compiler/plugin.proto\022" "\030google.protobuf.compiler\032 google/protob" - "uf/descriptor.proto\"}\n\024CodeGeneratorRequ" - "est\022\030\n\020file_to_generate\030\001 \003(\t\022\021\n\tparamet" - "er\030\002 \001(\t\0228\n\nproto_file\030\017 \003(\0132$.google.pr" - "otobuf.FileDescriptorProto\"\252\001\n\025CodeGener" - "atorResponse\022\r\n\005error\030\001 \001(\t\022B\n\004file\030\017 \003(" - "\01324.google.protobuf.compiler.CodeGenerat" - "orResponse.File\032>\n\004File\022\014\n\004name\030\001 \001(\t\022\027\n" - "\017insertion_point\030\002 \001(\t\022\017\n\007content\030\017 \001(\tB" - "7\n\034com.google.protobuf.compilerB\014PluginP" - "rotosZ\tplugin_go" + "uf/descriptor.proto\"F\n\007Version\022\r\n\005major\030" + "\001 \001(\005\022\r\n\005minor\030\002 \001(\005\022\r\n\005patch\030\003 \001(\005\022\016\n\006s" + "uffix\030\004 \001(\t\"\272\001\n\024CodeGeneratorRequest\022\030\n\020" + "file_to_generate\030\001 \003(\t\022\021\n\tparameter\030\002 \001(" + "\t\0228\n\nproto_file\030\017 \003(\0132$.google.protobuf." + "FileDescriptorProto\022;\n\020compiler_version\030" + "\003 \001(\0132!.google.protobuf.compiler.Version" + "\"\252\001\n\025CodeGeneratorResponse\022\r\n\005error\030\001 \001(" + "\t\022B\n\004file\030\017 \003(\01324.google.protobuf.compil" + "er.CodeGeneratorResponse.File\032>\n\004File\022\014\n" + "\004name\030\001 \001(\t\022\027\n\017insertion_point\030\002 \001(\t\022\017\n\007" + "content\030\017 \001(\tB7\n\034com.google.protobuf.com" + "pilerB\014PluginProtosZ\tplugin_go" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 456); + descriptor, 590); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/compiler/plugin.proto", &protobuf_RegisterTypes); ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); @@ -166,9 +192,505 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int Version::kMajorFieldNumber; +const int Version::kMinorFieldNumber; +const int Version::kPatchFieldNumber; +const int Version::kSuffixFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +Version::Version() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:google.protobuf.compiler.Version) +} +Version::Version(const Version& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _has_bits_(from._has_bits_), + _cached_size_(0) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + suffix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (from.has_suffix()) { + suffix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.suffix_); + } + ::memcpy(&major_, &from.major_, + reinterpret_cast<char*>(&patch_) - + reinterpret_cast<char*>(&major_) + sizeof(patch_)); + // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.Version) +} + +void Version::SharedCtor() { + _cached_size_ = 0; + suffix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + ::memset(&major_, 0, reinterpret_cast<char*>(&patch_) - + reinterpret_cast<char*>(&major_) + sizeof(patch_)); +} + +Version::~Version() { + // @@protoc_insertion_point(destructor:google.protobuf.compiler.Version) + SharedDtor(); +} + +void Version::SharedDtor() { + suffix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} + +void Version::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* Version::descriptor() { + protobuf_AssignDescriptorsOnce(); + return file_level_metadata[0].descriptor; +} + +const Version& Version::default_instance() { + protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + return *internal_default_instance(); +} + +Version* Version::New(::google::protobuf::Arena* arena) const { + Version* n = new Version; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void Version::Clear() { +// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.Version) + if (has_suffix()) { + GOOGLE_DCHECK(!suffix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); + (*suffix_.UnsafeRawStringPointer())->clear(); + } + if (_has_bits_[0 / 32] & 14u) { + ::memset(&major_, 0, reinterpret_cast<char*>(&patch_) - + reinterpret_cast<char*>(&major_) + sizeof(patch_)); + } + _has_bits_.Clear(); + _internal_metadata_.Clear(); +} + +bool Version::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:google.protobuf.compiler.Version) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // optional int32 major = 1; + case 1: { + if (tag == 8u) { + set_has_major(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &major_))); + } else { + goto handle_unusual; + } + break; + } + + // optional int32 minor = 2; + case 2: { + if (tag == 16u) { + set_has_minor(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &minor_))); + } else { + goto handle_unusual; + } + break; + } + + // optional int32 patch = 3; + case 3: { + if (tag == 24u) { + set_has_patch(); + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( + input, &patch_))); + } else { + goto handle_unusual; + } + break; + } + + // optional string suffix = 4; + case 4: { + if (tag == 34u) { + DO_(::google::protobuf::internal::WireFormatLite::ReadString( + input, this->mutable_suffix())); + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->suffix().data(), this->suffix().length(), + ::google::protobuf::internal::WireFormat::PARSE, + "google.protobuf.compiler.Version.suffix"); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0 || + ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == + ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + goto success; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:google.protobuf.compiler.Version) + return true; +failure: + // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.Version) + return false; +#undef DO_ +} + +void Version::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.Version) + // optional int32 major = 1; + if (has_major()) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->major(), output); + } + + // optional int32 minor = 2; + if (has_minor()) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->minor(), output); + } + + // optional int32 patch = 3; + if (has_patch()) { + ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->patch(), output); + } + + // optional string suffix = 4; + if (has_suffix()) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->suffix().data(), this->suffix().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.Version.suffix"); + ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased( + 4, this->suffix(), output); + } + + if (_internal_metadata_.have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + unknown_fields(), output); + } + // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.Version) +} + +::google::protobuf::uint8* Version::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + (void)deterministic; // Unused + // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version) + // optional int32 major = 1; + if (has_major()) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->major(), target); + } + + // optional int32 minor = 2; + if (has_minor()) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->minor(), target); + } + + // optional int32 patch = 3; + if (has_patch()) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->patch(), target); + } + + // optional string suffix = 4; + if (has_suffix()) { + ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( + this->suffix().data(), this->suffix().length(), + ::google::protobuf::internal::WireFormat::SERIALIZE, + "google.protobuf.compiler.Version.suffix"); + target = + ::google::protobuf::internal::WireFormatLite::WriteStringToArray( + 4, this->suffix(), target); + } + + if (_internal_metadata_.have_unknown_fields()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + unknown_fields(), target); + } + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.Version) + return target; +} + +size_t Version::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.Version) + size_t total_size = 0; + + if (_internal_metadata_.have_unknown_fields()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + unknown_fields()); + } + if (_has_bits_[0 / 32] & 15u) { + // optional string suffix = 4; + if (has_suffix()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->suffix()); + } + + // optional int32 major = 1; + if (has_major()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->major()); + } + + // optional int32 minor = 2; + if (has_minor()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->minor()); + } + + // optional int32 patch = 3; + if (has_patch()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int32Size( + this->patch()); + } + + } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void Version::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.Version) + GOOGLE_DCHECK_NE(&from, this); + const Version* source = + ::google::protobuf::internal::DynamicCastToGenerated<const Version>( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.Version) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.Version) + MergeFrom(*source); + } +} + +void Version::MergeFrom(const Version& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom(from._internal_metadata_); + if (from._has_bits_[0 / 32] & 15u) { + if (from.has_suffix()) { + set_has_suffix(); + suffix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.suffix_); + } + if (from.has_major()) { + set_major(from.major()); + } + if (from.has_minor()) { + set_minor(from.minor()); + } + if (from.has_patch()) { + set_patch(from.patch()); + } + } +} + +void Version::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.Version) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void Version::CopyFrom(const Version& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.Version) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Version::IsInitialized() const { + return true; +} + +void Version::Swap(Version* other) { + if (other == this) return; + InternalSwap(other); +} +void Version::InternalSwap(Version* other) { + suffix_.Swap(&other->suffix_); + std::swap(major_, other->major_); + std::swap(minor_, other->minor_); + std::swap(patch_, other->patch_); + std::swap(_has_bits_[0], other->_has_bits_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + std::swap(_cached_size_, other->_cached_size_); +} + +::google::protobuf::Metadata Version::GetMetadata() const { + protobuf_AssignDescriptorsOnce(); + return file_level_metadata[0]; +} + +#if PROTOBUF_INLINE_NOT_IN_HEADERS +// Version + +// optional int32 major = 1; +bool Version::has_major() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +void Version::set_has_major() { + _has_bits_[0] |= 0x00000002u; +} +void Version::clear_has_major() { + _has_bits_[0] &= ~0x00000002u; +} +void Version::clear_major() { + major_ = 0; + clear_has_major(); +} +::google::protobuf::int32 Version::major() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.major) + return major_; +} +void Version::set_major(::google::protobuf::int32 value) { + set_has_major(); + major_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.major) +} + +// optional int32 minor = 2; +bool Version::has_minor() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +void Version::set_has_minor() { + _has_bits_[0] |= 0x00000004u; +} +void Version::clear_has_minor() { + _has_bits_[0] &= ~0x00000004u; +} +void Version::clear_minor() { + minor_ = 0; + clear_has_minor(); +} +::google::protobuf::int32 Version::minor() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.minor) + return minor_; +} +void Version::set_minor(::google::protobuf::int32 value) { + set_has_minor(); + minor_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.minor) +} + +// optional int32 patch = 3; +bool Version::has_patch() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +void Version::set_has_patch() { + _has_bits_[0] |= 0x00000008u; +} +void Version::clear_has_patch() { + _has_bits_[0] &= ~0x00000008u; +} +void Version::clear_patch() { + patch_ = 0; + clear_has_patch(); +} +::google::protobuf::int32 Version::patch() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.patch) + return patch_; +} +void Version::set_patch(::google::protobuf::int32 value) { + set_has_patch(); + patch_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.patch) +} + +// optional string suffix = 4; +bool Version::has_suffix() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +void Version::set_has_suffix() { + _has_bits_[0] |= 0x00000001u; +} +void Version::clear_has_suffix() { + _has_bits_[0] &= ~0x00000001u; +} +void Version::clear_suffix() { + suffix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_suffix(); +} +const ::std::string& Version::suffix() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.suffix) + return suffix_.GetNoArena(); +} +void Version::set_suffix(const ::std::string& value) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix) +} +void Version::set_suffix(const char* value) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix) +} +void Version::set_suffix(const char* value, size_t size) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast<const char*>(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.Version.suffix) +} +::std::string* Version::mutable_suffix() { + set_has_suffix(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.Version.suffix) + return suffix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +::std::string* Version::release_suffix() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix) + clear_has_suffix(); + return suffix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +void Version::set_allocated_suffix(::std::string* suffix) { + if (suffix != NULL) { + set_has_suffix(); + } else { + clear_has_suffix(); + } + suffix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), suffix); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix) +} + +#endif // PROTOBUF_INLINE_NOT_IN_HEADERS + +// =================================================================== + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 const int CodeGeneratorRequest::kFileToGenerateFieldNumber; const int CodeGeneratorRequest::kParameterFieldNumber; const int CodeGeneratorRequest::kProtoFileFieldNumber; +const int CodeGeneratorRequest::kCompilerVersionFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 CodeGeneratorRequest::CodeGeneratorRequest() @@ -191,12 +713,18 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from) if (from.has_parameter()) { parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_); } + if (from.has_compiler_version()) { + compiler_version_ = new ::google::protobuf::compiler::Version(*from.compiler_version_); + } else { + compiler_version_ = NULL; + } // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.CodeGeneratorRequest) } void CodeGeneratorRequest::SharedCtor() { _cached_size_ = 0; parameter_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + compiler_version_ = NULL; } CodeGeneratorRequest::~CodeGeneratorRequest() { @@ -206,6 +734,9 @@ CodeGeneratorRequest::~CodeGeneratorRequest() { void CodeGeneratorRequest::SharedDtor() { parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + if (this != internal_default_instance()) { + delete compiler_version_; + } } void CodeGeneratorRequest::SetCachedSize(int size) const { @@ -215,7 +746,7 @@ void CodeGeneratorRequest::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorRequest::descriptor() { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[0].descriptor; + return file_level_metadata[1].descriptor; } const CodeGeneratorRequest& CodeGeneratorRequest::default_instance() { @@ -235,9 +766,15 @@ void CodeGeneratorRequest::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest) file_to_generate_.Clear(); proto_file_.Clear(); - if (has_parameter()) { - GOOGLE_DCHECK(!parameter_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); - (*parameter_.UnsafeRawStringPointer())->clear(); + if (_has_bits_[0 / 32] & 3u) { + if (has_parameter()) { + GOOGLE_DCHECK(!parameter_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); + (*parameter_.UnsafeRawStringPointer())->clear(); + } + if (has_compiler_version()) { + GOOGLE_DCHECK(compiler_version_ != NULL); + compiler_version_->::google::protobuf::compiler::Version::Clear(); + } } _has_bits_.Clear(); _internal_metadata_.Clear(); @@ -284,6 +821,17 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( break; } + // optional .google.protobuf.compiler.Version compiler_version = 3; + case 3: { + if (tag == 26u) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_compiler_version())); + } else { + goto handle_unusual; + } + break; + } + // repeated .google.protobuf.FileDescriptorProto proto_file = 15; case 15: { if (tag == 122u) { @@ -342,6 +890,12 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( 2, this->parameter(), output); } + // optional .google.protobuf.compiler.Version compiler_version = 3; + if (has_compiler_version()) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 3, *this->compiler_version_, output); + } + // repeated .google.protobuf.FileDescriptorProto proto_file = 15; for (unsigned int i = 0, n = this->proto_file_size(); i < n; i++) { ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( @@ -380,6 +934,13 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( 2, this->parameter(), target); } + // optional .google.protobuf.compiler.Version compiler_version = 3; + if (has_compiler_version()) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 3, *this->compiler_version_, false, target); + } + // repeated .google.protobuf.FileDescriptorProto proto_file = 15; for (unsigned int i = 0, n = this->proto_file_size(); i < n; i++) { target = ::google::protobuf::internal::WireFormatLite:: @@ -423,13 +984,22 @@ size_t CodeGeneratorRequest::ByteSizeLong() const { } } - // optional string parameter = 2; - if (has_parameter()) { - total_size += 1 + - ::google::protobuf::internal::WireFormatLite::StringSize( - this->parameter()); - } + if (_has_bits_[0 / 32] & 3u) { + // optional string parameter = 2; + if (has_parameter()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::StringSize( + this->parameter()); + } + // optional .google.protobuf.compiler.Version compiler_version = 3; + if (has_compiler_version()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->compiler_version_); + } + + } int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = cached_size; @@ -458,9 +1028,14 @@ void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) { _internal_metadata_.MergeFrom(from._internal_metadata_); file_to_generate_.MergeFrom(from.file_to_generate_); proto_file_.MergeFrom(from.proto_file_); - if (from.has_parameter()) { - set_has_parameter(); - parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_); + if (from._has_bits_[0 / 32] & 3u) { + if (from.has_parameter()) { + set_has_parameter(); + parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_); + } + if (from.has_compiler_version()) { + mutable_compiler_version()->::google::protobuf::compiler::Version::MergeFrom(from.compiler_version()); + } } } @@ -491,6 +1066,7 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { file_to_generate_.UnsafeArenaSwap(&other->file_to_generate_); proto_file_.UnsafeArenaSwap(&other->proto_file_); parameter_.Swap(&other->parameter_); + std::swap(compiler_version_, other->compiler_version_); std::swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); std::swap(_cached_size_, other->_cached_size_); @@ -498,7 +1074,7 @@ void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { ::google::protobuf::Metadata CodeGeneratorRequest::GetMetadata() const { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[0]; + return file_level_metadata[1]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -643,6 +1219,51 @@ CodeGeneratorRequest::proto_file() const { return proto_file_; } +// optional .google.protobuf.compiler.Version compiler_version = 3; +bool CodeGeneratorRequest::has_compiler_version() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +void CodeGeneratorRequest::set_has_compiler_version() { + _has_bits_[0] |= 0x00000002u; +} +void CodeGeneratorRequest::clear_has_compiler_version() { + _has_bits_[0] &= ~0x00000002u; +} +void CodeGeneratorRequest::clear_compiler_version() { + if (compiler_version_ != NULL) compiler_version_->::google::protobuf::compiler::Version::Clear(); + clear_has_compiler_version(); +} +const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + return compiler_version_ != NULL ? *compiler_version_ + : *::google::protobuf::compiler::Version::internal_default_instance(); +} +::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() { + set_has_compiler_version(); + if (compiler_version_ == NULL) { + compiler_version_ = new ::google::protobuf::compiler::Version; + } + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + return compiler_version_; +} +::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + clear_has_compiler_version(); + ::google::protobuf::compiler::Version* temp = compiler_version_; + compiler_version_ = NULL; + return temp; +} +void CodeGeneratorRequest::set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version) { + delete compiler_version_; + compiler_version_ = compiler_version; + if (compiler_version) { + set_has_compiler_version(); + } else { + clear_has_compiler_version(); + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) +} + #endif // PROTOBUF_INLINE_NOT_IN_HEADERS // =================================================================== @@ -707,7 +1328,7 @@ void CodeGeneratorResponse_File::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorResponse_File::descriptor() { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[1].descriptor; + return file_level_metadata[2].descriptor; } const CodeGeneratorResponse_File& CodeGeneratorResponse_File::default_instance() { @@ -1012,7 +1633,7 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) ::google::protobuf::Metadata CodeGeneratorResponse_File::GetMetadata() const { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[1]; + return file_level_metadata[2]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS @@ -1232,7 +1853,7 @@ void CodeGeneratorResponse::SetCachedSize(int size) const { } const ::google::protobuf::Descriptor* CodeGeneratorResponse::descriptor() { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[2].descriptor; + return file_level_metadata[3].descriptor; } const CodeGeneratorResponse& CodeGeneratorResponse::default_instance() { @@ -1467,7 +2088,7 @@ void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { ::google::protobuf::Metadata CodeGeneratorResponse::GetMetadata() const { protobuf_AssignDescriptorsOnce(); - return file_level_metadata[2]; + return file_level_metadata[3]; } #if PROTOBUF_INLINE_NOT_IN_HEADERS diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 11c837a3..0948ab2d 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -33,89 +33,92 @@ namespace google { namespace protobuf { class DescriptorProto; class DescriptorProtoDefaultTypeInternal; -extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; class DescriptorProto_ExtensionRange; class DescriptorProto_ExtensionRangeDefaultTypeInternal; -extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; +LIBPROTOC_EXPORT extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; class DescriptorProto_ReservedRange; class DescriptorProto_ReservedRangeDefaultTypeInternal; -extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; +LIBPROTOC_EXPORT extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; class EnumDescriptorProto; class EnumDescriptorProtoDefaultTypeInternal; -extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; class EnumOptions; class EnumOptionsDefaultTypeInternal; -extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; +LIBPROTOC_EXPORT extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; class EnumValueDescriptorProto; class EnumValueDescriptorProtoDefaultTypeInternal; -extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; class EnumValueOptions; class EnumValueOptionsDefaultTypeInternal; -extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; +LIBPROTOC_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; class FieldDescriptorProto; class FieldDescriptorProtoDefaultTypeInternal; -extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; class FieldOptions; class FieldOptionsDefaultTypeInternal; -extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; +LIBPROTOC_EXPORT extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; class FileDescriptorProto; class FileDescriptorProtoDefaultTypeInternal; -extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; class FileDescriptorSet; class FileDescriptorSetDefaultTypeInternal; -extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; +LIBPROTOC_EXPORT extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; class FileOptions; class FileOptionsDefaultTypeInternal; -extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_; +LIBPROTOC_EXPORT extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_; class GeneratedCodeInfo; class GeneratedCodeInfoDefaultTypeInternal; -extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; +LIBPROTOC_EXPORT extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; class GeneratedCodeInfo_Annotation; class GeneratedCodeInfo_AnnotationDefaultTypeInternal; -extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; +LIBPROTOC_EXPORT extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; class MessageOptions; class MessageOptionsDefaultTypeInternal; -extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; +LIBPROTOC_EXPORT extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; class MethodDescriptorProto; class MethodDescriptorProtoDefaultTypeInternal; -extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; class MethodOptions; class MethodOptionsDefaultTypeInternal; -extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; +LIBPROTOC_EXPORT extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; class OneofDescriptorProto; class OneofDescriptorProtoDefaultTypeInternal; -extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; class OneofOptions; class OneofOptionsDefaultTypeInternal; -extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; +LIBPROTOC_EXPORT extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; class ServiceDescriptorProto; class ServiceDescriptorProtoDefaultTypeInternal; -extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; +LIBPROTOC_EXPORT extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; class ServiceOptions; class ServiceOptionsDefaultTypeInternal; -extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; +LIBPROTOC_EXPORT extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; class SourceCodeInfo; class SourceCodeInfoDefaultTypeInternal; -extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; +LIBPROTOC_EXPORT extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; class SourceCodeInfo_Location; class SourceCodeInfo_LocationDefaultTypeInternal; -extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; +LIBPROTOC_EXPORT extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; class UninterpretedOption; class UninterpretedOptionDefaultTypeInternal; -extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; +LIBPROTOC_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; class UninterpretedOption_NamePart; class UninterpretedOption_NamePartDefaultTypeInternal; -extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; +LIBPROTOC_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; namespace compiler { class CodeGeneratorRequest; class CodeGeneratorRequestDefaultTypeInternal; -extern CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; +LIBPROTOC_EXPORT extern CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_; class CodeGeneratorResponse; class CodeGeneratorResponseDefaultTypeInternal; -extern CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; +LIBPROTOC_EXPORT extern CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_; class CodeGeneratorResponse_File; class CodeGeneratorResponse_FileDefaultTypeInternal; -extern CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; +LIBPROTOC_EXPORT extern CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_; +class Version; +class VersionDefaultTypeInternal; +LIBPROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_; } // namespace compiler } // namespace protobuf } // namespace google @@ -130,6 +133,139 @@ void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugi // =================================================================== +class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ { + public: + Version(); + virtual ~Version(); + + Version(const Version& from); + + inline Version& operator=(const Version& from) { + CopyFrom(from); + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields(); + } + + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields(); + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const Version& default_instance(); + + static inline const Version* internal_default_instance() { + return reinterpret_cast<const Version*>( + &_Version_default_instance_); + } + + void Swap(Version* other); + + // implements Message ---------------------------------------------- + + inline Version* New() const PROTOBUF_FINAL { return New(NULL); } + + Version* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const Version& from); + void MergeFrom(const Version& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) + const PROTOBUF_FINAL { + return InternalSerializeWithCachedSizesToArray(false, output); + } + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(Version* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // optional int32 major = 1; + bool has_major() const; + void clear_major(); + static const int kMajorFieldNumber = 1; + ::google::protobuf::int32 major() const; + void set_major(::google::protobuf::int32 value); + + // optional int32 minor = 2; + bool has_minor() const; + void clear_minor(); + static const int kMinorFieldNumber = 2; + ::google::protobuf::int32 minor() const; + void set_minor(::google::protobuf::int32 value); + + // optional int32 patch = 3; + bool has_patch() const; + void clear_patch(); + static const int kPatchFieldNumber = 3; + ::google::protobuf::int32 patch() const; + void set_patch(::google::protobuf::int32 value); + + // optional string suffix = 4; + bool has_suffix() const; + void clear_suffix(); + static const int kSuffixFieldNumber = 4; + const ::std::string& suffix() const; + void set_suffix(const ::std::string& value); + void set_suffix(const char* value); + void set_suffix(const char* value, size_t size); + ::std::string* mutable_suffix(); + ::std::string* release_suffix(); + void set_allocated_suffix(::std::string* suffix); + + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.Version) + private: + void set_has_major(); + void clear_has_major(); + void set_has_minor(); + void clear_has_minor(); + void set_has_patch(); + void clear_has_patch(); + void set_has_suffix(); + void clear_has_suffix(); + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable int _cached_size_; + ::google::protobuf::internal::ArenaStringPtr suffix_; + ::google::protobuf::int32 major_; + ::google::protobuf::int32 minor_; + ::google::protobuf::int32 patch_; + friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); + friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); + friend const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); + +}; +// ------------------------------------------------------------------- + class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { public: CodeGeneratorRequest(); @@ -244,10 +380,21 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& proto_file() const; + // optional .google.protobuf.compiler.Version compiler_version = 3; + bool has_compiler_version() const; + void clear_compiler_version(); + static const int kCompilerVersionFieldNumber = 3; + const ::google::protobuf::compiler::Version& compiler_version() const; + ::google::protobuf::compiler::Version* mutable_compiler_version(); + ::google::protobuf::compiler::Version* release_compiler_version(); + void set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version); + // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest) private: void set_has_parameter(); void clear_has_parameter(); + void set_has_compiler_version(); + void clear_has_compiler_version(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; @@ -255,6 +402,7 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message ::google::protobuf::RepeatedPtrField< ::std::string> file_to_generate_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_; ::google::protobuf::internal::ArenaStringPtr parameter_; + ::google::protobuf::compiler::Version* compiler_version_; friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); friend const ::google::protobuf::uint32* protobuf_Offsets_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); @@ -518,6 +666,136 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +// Version + +// optional int32 major = 1; +inline bool Version::has_major() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void Version::set_has_major() { + _has_bits_[0] |= 0x00000002u; +} +inline void Version::clear_has_major() { + _has_bits_[0] &= ~0x00000002u; +} +inline void Version::clear_major() { + major_ = 0; + clear_has_major(); +} +inline ::google::protobuf::int32 Version::major() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.major) + return major_; +} +inline void Version::set_major(::google::protobuf::int32 value) { + set_has_major(); + major_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.major) +} + +// optional int32 minor = 2; +inline bool Version::has_minor() const { + return (_has_bits_[0] & 0x00000004u) != 0; +} +inline void Version::set_has_minor() { + _has_bits_[0] |= 0x00000004u; +} +inline void Version::clear_has_minor() { + _has_bits_[0] &= ~0x00000004u; +} +inline void Version::clear_minor() { + minor_ = 0; + clear_has_minor(); +} +inline ::google::protobuf::int32 Version::minor() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.minor) + return minor_; +} +inline void Version::set_minor(::google::protobuf::int32 value) { + set_has_minor(); + minor_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.minor) +} + +// optional int32 patch = 3; +inline bool Version::has_patch() const { + return (_has_bits_[0] & 0x00000008u) != 0; +} +inline void Version::set_has_patch() { + _has_bits_[0] |= 0x00000008u; +} +inline void Version::clear_has_patch() { + _has_bits_[0] &= ~0x00000008u; +} +inline void Version::clear_patch() { + patch_ = 0; + clear_has_patch(); +} +inline ::google::protobuf::int32 Version::patch() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.patch) + return patch_; +} +inline void Version::set_patch(::google::protobuf::int32 value) { + set_has_patch(); + patch_ = value; + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.patch) +} + +// optional string suffix = 4; +inline bool Version::has_suffix() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void Version::set_has_suffix() { + _has_bits_[0] |= 0x00000001u; +} +inline void Version::clear_has_suffix() { + _has_bits_[0] &= ~0x00000001u; +} +inline void Version::clear_suffix() { + suffix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + clear_has_suffix(); +} +inline const ::std::string& Version::suffix() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.suffix) + return suffix_.GetNoArena(); +} +inline void Version::set_suffix(const ::std::string& value) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); + // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix) +} +inline void Version::set_suffix(const char* value) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); + // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix) +} +inline void Version::set_suffix(const char* value, size_t size) { + set_has_suffix(); + suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast<const char*>(value), size)); + // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.Version.suffix) +} +inline ::std::string* Version::mutable_suffix() { + set_has_suffix(); + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.Version.suffix) + return suffix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline ::std::string* Version::release_suffix() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix) + clear_has_suffix(); + return suffix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); +} +inline void Version::set_allocated_suffix(::std::string* suffix) { + if (suffix != NULL) { + set_has_suffix(); + } else { + clear_has_suffix(); + } + suffix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), suffix); + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix) +} + +// ------------------------------------------------------------------- + // CodeGeneratorRequest // repeated string file_to_generate = 1; @@ -659,6 +937,51 @@ CodeGeneratorRequest::proto_file() const { return proto_file_; } +// optional .google.protobuf.compiler.Version compiler_version = 3; +inline bool CodeGeneratorRequest::has_compiler_version() const { + return (_has_bits_[0] & 0x00000002u) != 0; +} +inline void CodeGeneratorRequest::set_has_compiler_version() { + _has_bits_[0] |= 0x00000002u; +} +inline void CodeGeneratorRequest::clear_has_compiler_version() { + _has_bits_[0] &= ~0x00000002u; +} +inline void CodeGeneratorRequest::clear_compiler_version() { + if (compiler_version_ != NULL) compiler_version_->::google::protobuf::compiler::Version::Clear(); + clear_has_compiler_version(); +} +inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const { + // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + return compiler_version_ != NULL ? *compiler_version_ + : *::google::protobuf::compiler::Version::internal_default_instance(); +} +inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() { + set_has_compiler_version(); + if (compiler_version_ == NULL) { + compiler_version_ = new ::google::protobuf::compiler::Version; + } + // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + return compiler_version_; +} +inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() { + // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) + clear_has_compiler_version(); + ::google::protobuf::compiler::Version* temp = compiler_version_; + compiler_version_ = NULL; + return temp; +} +inline void CodeGeneratorRequest::set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version) { + delete compiler_version_; + compiler_version_ = compiler_version; + if (compiler_version) { + set_has_compiler_version(); + } else { + clear_has_compiler_version(); + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) +} + // ------------------------------------------------------------------- // CodeGeneratorResponse_File @@ -918,6 +1241,8 @@ CodeGeneratorResponse::file() const { // ------------------------------------------------------------------- +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/compiler/plugin.proto b/src/google/protobuf/compiler/plugin.proto index acaee1f4..6e4da2c1 100644 --- a/src/google/protobuf/compiler/plugin.proto +++ b/src/google/protobuf/compiler/plugin.proto @@ -53,6 +53,16 @@ option go_package = "plugin_go"; import "google/protobuf/descriptor.proto"; +// The version number of protocol compiler. +message Version { + optional int32 major = 1; + optional int32 minor = 2; + optional int32 patch = 3; + // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should + // be empty for mainline stable releases. + optional string suffix = 4; +} + // An encoded CodeGeneratorRequest is written to the plugin's stdin. message CodeGeneratorRequest { // The .proto files that were explicitly listed on the command-line. The @@ -75,6 +85,9 @@ message CodeGeneratorRequest { // is not similarly optimized on protoc's end -- it will store all fields in // memory at once before sending them to the plugin. repeated FileDescriptorProto proto_file = 15; + + // The version number of protocol compiler. + optional Version compiler_version = 3; } // The plugin writes an encoded CodeGeneratorResponse to stdout. diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 56e75fa4..7c72a5a1 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -734,12 +734,13 @@ void protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl() { "(\0132-.google.protobuf.GeneratedCodeInfo.A" "nnotation\032O\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020" "\001\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n" - "\003end\030\004 \001(\005BX\n\023com.google.protobufB\020Descr" - "iptorProtosH\001Z\ndescriptor\242\002\003GPB\252\002\032Google" - ".Protobuf.Reflection" + "\003end\030\004 \001(\005B\214\001\n\023com.google.protobufB\020Desc" + "riptorProtosH\001Z>github.com/golang/protob" + "uf/protoc-gen-go/descriptor;descriptor\242\002" + "\003GPB\252\002\032Google.Protobuf.Reflection" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 5500); + descriptor, 5553); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto); diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 00956cbf..8459b138 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -33,79 +33,79 @@ namespace google { namespace protobuf { class DescriptorProto; class DescriptorProtoDefaultTypeInternal; -extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; class DescriptorProto_ExtensionRange; class DescriptorProto_ExtensionRangeDefaultTypeInternal; -extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; +LIBPROTOBUF_EXPORT extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; class DescriptorProto_ReservedRange; class DescriptorProto_ReservedRangeDefaultTypeInternal; -extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; +LIBPROTOBUF_EXPORT extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; class EnumDescriptorProto; class EnumDescriptorProtoDefaultTypeInternal; -extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; class EnumOptions; class EnumOptionsDefaultTypeInternal; -extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; +LIBPROTOBUF_EXPORT extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; class EnumValueDescriptorProto; class EnumValueDescriptorProtoDefaultTypeInternal; -extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; class EnumValueOptions; class EnumValueOptionsDefaultTypeInternal; -extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; +LIBPROTOBUF_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; class FieldDescriptorProto; class FieldDescriptorProtoDefaultTypeInternal; -extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; class FieldOptions; class FieldOptionsDefaultTypeInternal; -extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; +LIBPROTOBUF_EXPORT extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; class FileDescriptorProto; class FileDescriptorProtoDefaultTypeInternal; -extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; class FileDescriptorSet; class FileDescriptorSetDefaultTypeInternal; -extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; +LIBPROTOBUF_EXPORT extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; class FileOptions; class FileOptionsDefaultTypeInternal; -extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_; +LIBPROTOBUF_EXPORT extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_; class GeneratedCodeInfo; class GeneratedCodeInfoDefaultTypeInternal; -extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; +LIBPROTOBUF_EXPORT extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; class GeneratedCodeInfo_Annotation; class GeneratedCodeInfo_AnnotationDefaultTypeInternal; -extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; +LIBPROTOBUF_EXPORT extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; class MessageOptions; class MessageOptionsDefaultTypeInternal; -extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; +LIBPROTOBUF_EXPORT extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; class MethodDescriptorProto; class MethodDescriptorProtoDefaultTypeInternal; -extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; class MethodOptions; class MethodOptionsDefaultTypeInternal; -extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; +LIBPROTOBUF_EXPORT extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; class OneofDescriptorProto; class OneofDescriptorProtoDefaultTypeInternal; -extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; class OneofOptions; class OneofOptionsDefaultTypeInternal; -extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; +LIBPROTOBUF_EXPORT extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; class ServiceDescriptorProto; class ServiceDescriptorProtoDefaultTypeInternal; -extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; +LIBPROTOBUF_EXPORT extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; class ServiceOptions; class ServiceOptionsDefaultTypeInternal; -extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; +LIBPROTOBUF_EXPORT extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; class SourceCodeInfo; class SourceCodeInfoDefaultTypeInternal; -extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; +LIBPROTOBUF_EXPORT extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; class SourceCodeInfo_Location; class SourceCodeInfo_LocationDefaultTypeInternal; -extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; +LIBPROTOBUF_EXPORT extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; class UninterpretedOption; class UninterpretedOptionDefaultTypeInternal; -extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; +LIBPROTOBUF_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; class UninterpretedOption_NamePart; class UninterpretedOption_NamePartDefaultTypeInternal; -extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; +LIBPROTOBUF_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index eae31601..03aba076 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -40,7 +40,7 @@ syntax = "proto2"; package google.protobuf; -option go_package = "descriptor"; +option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor"; option java_package = "com.google.protobuf"; option java_outer_classname = "DescriptorProtos"; option csharp_namespace = "Google.Protobuf.Reflection"; diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 24414d28..f8e67cc5 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -32,7 +32,7 @@ namespace google { namespace protobuf { class Duration; class DurationDefaultTypeInternal; -extern DurationDefaultTypeInternal _Duration_default_instance_; +LIBPROTOBUF_EXPORT extern DurationDefaultTypeInternal _Duration_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index e2aca67d..4a84bb4f 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -32,7 +32,7 @@ namespace google { namespace protobuf { class Empty; class EmptyDefaultTypeInternal; -extern EmptyDefaultTypeInternal _Empty_default_instance_; +LIBPROTOBUF_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 6b4c5f99..d7600c1b 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -32,7 +32,7 @@ namespace google { namespace protobuf { class FieldMask; class FieldMaskDefaultTypeInternal; -extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_; +LIBPROTOBUF_EXPORT extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index ea97a7c8..2633ab62 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -660,14 +660,14 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL : public Refl // choose 16 rather than some other number just in case the compiler would // be confused by an unaligned pointer. #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - static_cast<int>( \ - reinterpret_cast<const char*>( \ - &reinterpret_cast<const TYPE*>(16)->FIELD) - \ + static_cast< ::google::protobuf::uint32>( \ + reinterpret_cast<const char*>( \ + &reinterpret_cast<const TYPE*>(16)->FIELD) - \ reinterpret_cast<const char*>(16)) #endif #define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ - static_cast< ::google::protobuf::uint32>( \ + static_cast< ::google::protobuf::uint32>( \ reinterpret_cast<const char*>(&(ONEOF->FIELD)) \ - reinterpret_cast<const char*>(ONEOF)) diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index b1c49e37..14101832 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -46,7 +46,7 @@ #include <google/protobuf/has_bits.h> #ifndef PROTOBUF_FINAL -#if __cplusplus >= 201103L +#if LANG_CXX11 #define PROTOBUF_FINAL final #else #define PROTOBUF_FINAL @@ -99,7 +99,7 @@ class ExplicitlyConstructed { } } -#if __cplusplus >= 201103L +#if LANG_CXX11 constexpr #endif const T& @@ -125,7 +125,7 @@ class ExplicitlyConstructed { // Default empty string object. Don't use this directly. Instead, call // GetEmptyString() to get the reference. -extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; +LIBPROTOBUF_EXPORT extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; LIBPROTOBUF_EXPORT void InitEmptyString(); diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index d2a3e279..dc42e2fe 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -110,6 +110,7 @@ #define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ #include <assert.h> +#include <climits> #include <string> #include <utility> #ifdef _MSC_VER diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index efd421e6..47ced29f 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -615,7 +615,6 @@ class Map { #if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) && \ !defined(GOOGLE_PROTOBUF_OS_NACL) && \ - !defined(GOOGLE_PROTOBUF_OS_ANDROID) && \ !defined(GOOGLE_PROTOBUF_OS_EMSCRIPTEN) template<class NodeType, class... Args> void construct(NodeType* p, Args&&... args) { diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index d5de8cdb..5e5ed306 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -39,6 +39,7 @@ #ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ +#include <climits> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 281249d9..22150b5e 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -32,7 +32,7 @@ namespace google { namespace protobuf { class SourceContext; class SourceContextDefaultTypeInternal; -extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; +LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index 4d89c11c..1037d84c 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -35,13 +35,13 @@ namespace google { namespace protobuf { class ListValue; class ListValueDefaultTypeInternal; -extern ListValueDefaultTypeInternal _ListValue_default_instance_; +LIBPROTOBUF_EXPORT extern ListValueDefaultTypeInternal _ListValue_default_instance_; class Struct; class StructDefaultTypeInternal; -extern StructDefaultTypeInternal _Struct_default_instance_; +LIBPROTOBUF_EXPORT extern StructDefaultTypeInternal _Struct_default_instance_; class Value; class ValueDefaultTypeInternal; -extern ValueDefaultTypeInternal _Value_default_instance_; +LIBPROTOBUF_EXPORT extern ValueDefaultTypeInternal _Value_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index 10a71ed4..c25492f3 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -123,8 +123,8 @@ Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, // ensure that no later memory access can be reordered ahead of the operation. // "Release" operations ensure that no previous memory access can be reordered // after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. +// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no +// memory access. Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value); @@ -132,10 +132,10 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value); -#if defined(__MINGW32__) && defined(MemoryBarrier) -#undef MemoryBarrier -#endif -void MemoryBarrier(); +// This function was renamed from MemoryBarrier to MemoryBarrierInternal +// because MemoryBarrier is a define in Windows ARM builds and we do not +// undefine it because we call it from this function. +void MemoryBarrierInternal(); void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); void Release_Store(volatile Atomic32* ptr, Atomic32 value); @@ -180,7 +180,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr); #include <google/protobuf/stubs/atomicops_internals_tsan.h> // MSVC. #elif defined(_MSC_VER) -#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) +#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) || defined(GOOGLE_PROTOBUF_ARCH_ARM) #include <google/protobuf/stubs/atomicops_internals_x86_msvc.h> #else #error GOOGLE_PROTOBUF_ATOMICOPS_ERROR diff --git a/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h b/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h index 0a2d2b89..9a69d21a 100644 --- a/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h @@ -37,7 +37,7 @@ namespace google { namespace protobuf { namespace internal { -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __asm__ __volatile__ ("dmb ish" ::: "memory"); // NOLINT } @@ -117,9 +117,9 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic32 result = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return result; } @@ -128,7 +128,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return prev; } @@ -136,7 +136,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); return prev; @@ -148,7 +148,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { @@ -178,7 +178,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } @@ -253,9 +253,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic64 result = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return result; } @@ -264,7 +264,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return prev; } @@ -272,7 +272,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); return prev; @@ -284,7 +284,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { @@ -314,7 +314,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h b/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h index 90e727b0..6e2de67f 100644 --- a/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h @@ -115,17 +115,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { pLinuxKernelMemoryBarrier(); } inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -135,12 +135,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { Atomic32 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h b/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h index 17dfaa51..cd97e0c9 100644 --- a/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +++ b/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h @@ -110,17 +110,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __sync_synchronize(); } inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -130,12 +130,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { Atomic32 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h b/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h index 7bc584eb..44ef9c9e 100644 --- a/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h +++ b/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h @@ -52,7 +52,7 @@ typedef volatile std::atomic<Atomic32>* AtomicLocation32; static_assert(sizeof(*(AtomicLocation32) nullptr) == sizeof(Atomic32), "incompatible 32-bit atomic layout"); -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { #if defined(__GLIBCXX__) // Work around libstdc++ bug 51038 where atomic_thread_fence was declared but // not defined, leading to the linker complaining about undefined references. @@ -119,7 +119,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { ((AtomicLocation32)ptr)->store(value, std::memory_order_relaxed); - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { @@ -135,7 +135,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return ((AtomicLocation32)ptr)->load(std::memory_order_relaxed); } @@ -202,7 +202,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { ((AtomicLocation64)ptr)->store(value, std::memory_order_relaxed); - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { @@ -218,7 +218,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed); } diff --git a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h index 7f17b30d..0b0b06ce 100644 --- a/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h @@ -78,7 +78,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { __atomic_store_n(ptr, value, __ATOMIC_RELAXED); } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __sync_synchronize(); } diff --git a/src/google/protobuf/stubs/atomicops_internals_macosx.h b/src/google/protobuf/stubs/atomicops_internals_macosx.h index 79633241..c242ef73 100644 --- a/src/google/protobuf/stubs/atomicops_internals_macosx.h +++ b/src/google/protobuf/stubs/atomicops_internals_macosx.h @@ -73,7 +73,7 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, return OSAtomicAdd32Barrier(increment, const_cast<Atomic32*>(ptr)); } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { OSMemoryBarrier(); } @@ -103,11 +103,11 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -117,12 +117,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { Atomic32 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } @@ -193,11 +193,11 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -207,12 +207,12 @@ inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { Atomic64 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h b/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h index f5837c9e..6ce6820e 100644 --- a/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h @@ -125,8 +125,8 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, // ensure that no later memory access can be reordered ahead of the operation. // "Release" operations ensure that no previous memory access can be reordered // after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. +// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no +// memory access. inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { @@ -149,17 +149,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __asm__ __volatile__("sync" : : : "memory"); } inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -169,12 +169,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { Atomic32 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } @@ -247,9 +247,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic64 res = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return res; } @@ -257,20 +257,20 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, // ensure that no later memory access can be reordered ahead of the operation. // "Release" operations ensure that no previous memory access can be reordered // after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. +// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no +// memory access. inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { Atomic64 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return res; } inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } @@ -280,11 +280,11 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -294,12 +294,12 @@ inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { Atomic64 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } #endif diff --git a/src/google/protobuf/stubs/atomicops_internals_power.h b/src/google/protobuf/stubs/atomicops_internals_power.h index b8a42f21..cad9f1e3 100644 --- a/src/google/protobuf/stubs/atomicops_internals_power.h +++ b/src/google/protobuf/stubs/atomicops_internals_power.h @@ -93,7 +93,7 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, return result; } -inline void MemoryBarrier(void) { +inline void MemoryBarrierInternal(void) { asm volatile ( " lwsync \n\t" " isync \n\t" diff --git a/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h b/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h index 8231a578..d477dc6d 100644 --- a/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h @@ -97,22 +97,22 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, Atomic32 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return res; } inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value) { Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return res; } inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr, Atomic32 old_value, Atomic32 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); return res; } @@ -121,15 +121,15 @@ inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) { *ptr = value; } -inline void MemoryBarrier() { __asm__ __volatile__("sync" : : : "memory"); } +inline void MemoryBarrierInternal() { __asm__ __volatile__("sync" : : : "memory"); } inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) { - MemoryBarrier(); + MemoryBarrierInternal(); *ptr = value; } @@ -137,12 +137,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { return *ptr; } inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) { Atomic32 value = *ptr; - MemoryBarrier(); + MemoryBarrierInternal(); return value; } inline Atomic32 Release_Load(volatile const Atomic32 *ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_solaris.h b/src/google/protobuf/stubs/atomicops_internals_solaris.h index d8057ecd..baecb993 100644 --- a/src/google/protobuf/stubs/atomicops_internals_solaris.h +++ b/src/google/protobuf/stubs/atomicops_internals_solaris.h @@ -54,16 +54,16 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment); } -inline void MemoryBarrier(void) { +inline void MemoryBarrierInternal(void) { membar_producer(); membar_consumer(); } inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return ret; } @@ -72,7 +72,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return ret; } @@ -80,7 +80,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, Atomic32 old_value, Atomic32 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } @@ -129,9 +129,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 incre } inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) { - MemoryBarrier(); + MemoryBarrierInternal(); Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment); - MemoryBarrier(); + MemoryBarrierInternal(); return ret; } @@ -139,14 +139,14 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); + MemoryBarrierInternal(); return ret; } inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, Atomic64 old_value, Atomic64 new_value) { - MemoryBarrier(); + MemoryBarrierInternal(); return NoBarrier_CompareAndSwap(ptr, old_value, new_value); } diff --git a/src/google/protobuf/stubs/atomicops_internals_tsan.h b/src/google/protobuf/stubs/atomicops_internals_tsan.h index 0c903545..676380b1 100644 --- a/src/google/protobuf/stubs/atomicops_internals_tsan.h +++ b/src/google/protobuf/stubs/atomicops_internals_tsan.h @@ -206,7 +206,7 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr, return cmp; } -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); } diff --git a/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h b/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h index edccc59d..e80121fd 100644 --- a/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +++ b/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h @@ -119,18 +119,18 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { // 64-bit implementations of memory barrier can be simpler, because it // "mfence" is guaranteed to exist. -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { __asm__ __volatile__("mfence" : : : "memory"); } inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } #else -inline void MemoryBarrier() { +inline void MemoryBarrierInternal() { if (AtomicOps_Internalx86CPUFeatures.has_sse2) { __asm__ __volatile__("mfence" : : : "memory"); } else { // mfence is faster but not present on PIII @@ -168,7 +168,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } @@ -225,7 +225,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { *ptr = value; - MemoryBarrier(); + MemoryBarrierInternal(); } inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { @@ -262,7 +262,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc b/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc index 741b164f..74a1bd4e 100644 --- a/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +++ b/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc @@ -44,9 +44,10 @@ namespace google { namespace protobuf { namespace internal { -inline void MemoryBarrier() { - // We use MemoryBarrier from WinNT.h - ::MemoryBarrier(); +inline void MemoryBarrierInternal() { + // On ARM this is a define while on x86/x64 this is + // a function declared in WinNT.h + MemoryBarrier(); } Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, diff --git a/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h b/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h index e53a641f..34d60d98 100644 --- a/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +++ b/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h @@ -82,7 +82,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { } inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } @@ -125,7 +125,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { } inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); + MemoryBarrierInternal(); return *ptr; } diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 54dbafab..14655916 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -108,11 +108,17 @@ string VersionString(int version) { // =================================================================== // emulates google3/base/logging.cc +// If the minimum logging level is not set, we default to logging messages for +// all levels. +#ifndef GOOGLE_PROTOBUF_MIN_LOG_LEVEL +#define GOOGLE_PROTOBUF_MIN_LOG_LEVEL LOGLEVEL_INFO +#endif + namespace internal { + #if defined(__ANDROID__) inline void DefaultLogHandler(LogLevel level, const char* filename, int line, const string& message) { -#ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { return; } @@ -143,11 +149,14 @@ inline void DefaultLogHandler(LogLevel level, const char* filename, int line, __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", "terminating.\n"); } -#endif } + #else void DefaultLogHandler(LogLevel level, const char* filename, int line, const string& message) { + if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { + return; + } static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; // We use fprintf() instead of cerr because we want this to work at static diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 43e88ff2..c595e205 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -98,6 +98,9 @@ namespace internal { // easier: major * 10^6 + minor * 10^3 + micro #define GOOGLE_PROTOBUF_VERSION 3001000 +// A suffix string for alpha, beta or rc releases. Empty for stable releases. +#define GOOGLE_PROTOBUF_VERSION_SUFFIX "" + // The minimum library version which works with the current version of the // headers. #define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3001000 diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index 4eac7d5d..bf0b88b4 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -41,15 +41,10 @@ #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 -// Android -#if defined(__ANDROID__) -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP - // Use C++11 unordered_{map|set} if available. -#elif ((_LIBCPP_STD_VER >= 11) || \ - (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ - (__GLIBCXX__ > 20090421))) +#if ((_LIBCPP_STD_VER >= 11) || \ + (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ + (__GLIBCXX__ > 20090421))) # define GOOGLE_PROTOBUF_HAS_CXX11_HASH // For XCode >= 4.6: the compiler is clang with libc++. diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h index 8b7f224f..7a54060d 100644 --- a/src/google/protobuf/stubs/platform_macros.h +++ b/src/google/protobuf/stubs/platform_macros.h @@ -47,7 +47,7 @@ #elif defined(__QNX__) #define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__ARMEL__) +#elif defined(_M_ARM) || defined(__ARMEL__) #define GOOGLE_PROTOBUF_ARCH_ARM 1 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1 #elif defined(__aarch64__) diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index 376be5f7..72adba6d 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -60,8 +60,12 @@ #endif #else #include <sys/param.h> // __BYTE_ORDER + #if defined(__OpenBSD__) + #include <endian.h> + #endif #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \ + (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \ + (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) && \ !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) #define PROTOBUF_LITTLE_ENDIAN 1 #endif @@ -93,6 +97,15 @@ // =================================================================== // from google3/base/port.h + +#if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \ + (defined(_MSC_VER) && _MSC_VER >= 1900)) +// Define this to 1 if the code is compiled in C++11 mode; leave it +// undefined otherwise. Do NOT define it to 0 -- that causes +// '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'. +#define LANG_CXX11 1 +#endif + namespace google { namespace protobuf { diff --git a/src/google/protobuf/stubs/strutil.cc b/src/google/protobuf/stubs/strutil.cc index 4fa8e99f..15b6e53f 100644 --- a/src/google/protobuf/stubs/strutil.cc +++ b/src/google/protobuf/stubs/strutil.cc @@ -981,7 +981,7 @@ static const char two_ASCII_digits[100][2] = { }; char* FastUInt32ToBufferLeft(uint32 u, char* buffer) { - int digits; + uint32 digits; const char *ASCII_digits = NULL; // The idea of this implementation is to trim the number of divides to as few // as possible by using multiplication and subtraction rather than mod (%), diff --git a/src/google/protobuf/test_messages_proto3.proto b/src/google/protobuf/test_messages_proto3.proto new file mode 100644 index 00000000..79230334 --- /dev/null +++ b/src/google/protobuf/test_messages_proto3.proto @@ -0,0 +1,227 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Test schema for proto3 messages. This test schema is used by: +// +// - benchmarks +// - fuzz tests +// - conformance tests +// + +syntax = "proto3"; + +package protobuf_test_messages.proto3; +option java_package = "com.google.protobuf_test_messages.proto3"; + +// This is the default, but we specify it here explicitly. +option optimize_for = SPEED; + +import "google/protobuf/any.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; + +option cc_enable_arenas = true; + +// This proto includes every type of field in both singular and repeated +// forms. +// +// Also, crucially, all messages and enums in this file are eventually +// submessages of this message. So for example, a fuzz test of TestAllTypes +// could trigger bugs that occur in any message type in this file. We verify +// this stays true in a unit test. +message TestAllTypes { + message NestedMessage { + int32 a = 1; + TestAllTypes corecursive = 2; + } + + enum NestedEnum { + FOO = 0; + BAR = 1; + BAZ = 2; + NEG = -1; // Intentionally negative. + } + + // Singular + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; + sfixed64 optional_sfixed64 = 10; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; + + NestedMessage optional_nested_message = 18; + ForeignMessage optional_foreign_message = 19; + + NestedEnum optional_nested_enum = 21; + ForeignEnum optional_foreign_enum = 22; + + string optional_string_piece = 24 [ctype=STRING_PIECE]; + string optional_cord = 25 [ctype=CORD]; + + TestAllTypes recursive_message = 27; + + // Repeated + repeated int32 repeated_int32 = 31; + repeated int64 repeated_int64 = 32; + repeated uint32 repeated_uint32 = 33; + repeated uint64 repeated_uint64 = 34; + repeated sint32 repeated_sint32 = 35; + repeated sint64 repeated_sint64 = 36; + repeated fixed32 repeated_fixed32 = 37; + repeated fixed64 repeated_fixed64 = 38; + repeated sfixed32 repeated_sfixed32 = 39; + repeated sfixed64 repeated_sfixed64 = 40; + repeated float repeated_float = 41; + repeated double repeated_double = 42; + repeated bool repeated_bool = 43; + repeated string repeated_string = 44; + repeated bytes repeated_bytes = 45; + + repeated NestedMessage repeated_nested_message = 48; + repeated ForeignMessage repeated_foreign_message = 49; + + repeated NestedEnum repeated_nested_enum = 51; + repeated ForeignEnum repeated_foreign_enum = 52; + + repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; + repeated string repeated_cord = 55 [ctype=CORD]; + + // Map + map < int32, int32> map_int32_int32 = 56; + map < int64, int64> map_int64_int64 = 57; + map < uint32, uint32> map_uint32_uint32 = 58; + map < uint64, uint64> map_uint64_uint64 = 59; + map < sint32, sint32> map_sint32_sint32 = 60; + map < sint64, sint64> map_sint64_sint64 = 61; + map < fixed32, fixed32> map_fixed32_fixed32 = 62; + map < fixed64, fixed64> map_fixed64_fixed64 = 63; + map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64; + map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65; + map < int32, float> map_int32_float = 66; + map < int32, double> map_int32_double = 67; + map < bool, bool> map_bool_bool = 68; + map < string, string> map_string_string = 69; + map < string, bytes> map_string_bytes = 70; + map < string, NestedMessage> map_string_nested_message = 71; + map < string, ForeignMessage> map_string_foreign_message = 72; + map < string, NestedEnum> map_string_nested_enum = 73; + map < string, ForeignEnum> map_string_foreign_enum = 74; + + oneof oneof_field { + uint32 oneof_uint32 = 111; + NestedMessage oneof_nested_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + bool oneof_bool = 115; + uint64 oneof_uint64 = 116; + float oneof_float = 117; + double oneof_double = 118; + NestedEnum oneof_enum = 119; + } + + // Well-known types + google.protobuf.BoolValue optional_bool_wrapper = 201; + google.protobuf.Int32Value optional_int32_wrapper = 202; + google.protobuf.Int64Value optional_int64_wrapper = 203; + google.protobuf.UInt32Value optional_uint32_wrapper = 204; + google.protobuf.UInt64Value optional_uint64_wrapper = 205; + google.protobuf.FloatValue optional_float_wrapper = 206; + google.protobuf.DoubleValue optional_double_wrapper = 207; + google.protobuf.StringValue optional_string_wrapper = 208; + google.protobuf.BytesValue optional_bytes_wrapper = 209; + + repeated google.protobuf.BoolValue repeated_bool_wrapper = 211; + repeated google.protobuf.Int32Value repeated_int32_wrapper = 212; + repeated google.protobuf.Int64Value repeated_int64_wrapper = 213; + repeated google.protobuf.UInt32Value repeated_uint32_wrapper = 214; + repeated google.protobuf.UInt64Value repeated_uint64_wrapper = 215; + repeated google.protobuf.FloatValue repeated_float_wrapper = 216; + repeated google.protobuf.DoubleValue repeated_double_wrapper = 217; + repeated google.protobuf.StringValue repeated_string_wrapper = 218; + repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219; + + google.protobuf.Duration optional_duration = 301; + google.protobuf.Timestamp optional_timestamp = 302; + google.protobuf.FieldMask optional_field_mask = 303; + google.protobuf.Struct optional_struct = 304; + google.protobuf.Any optional_any = 305; + google.protobuf.Value optional_value = 306; + + repeated google.protobuf.Duration repeated_duration = 311; + repeated google.protobuf.Timestamp repeated_timestamp = 312; + repeated google.protobuf.FieldMask repeated_fieldmask = 313; + repeated google.protobuf.Struct repeated_struct = 324; + repeated google.protobuf.Any repeated_any = 315; + repeated google.protobuf.Value repeated_value = 316; + + // Test field-name-to-JSON-name convention. + // (protobuf says names can be any valid C/C++ identifier.) + int32 fieldname1 = 401; + int32 field_name2 = 402; + int32 _field_name3 = 403; + int32 field__name4_ = 404; + int32 field0name5 = 405; + int32 field_0_name6 = 406; + int32 fieldName7 = 407; + int32 FieldName8 = 408; + int32 field_Name9 = 409; + int32 Field_Name10 = 410; + int32 FIELD_NAME11 = 411; + int32 FIELD_name12 = 412; + int32 __field_name13 = 413; + int32 __Field_name14 = 414; + int32 field__name15 = 415; + int32 field__Name16 = 416; + int32 field_name17__ = 417; + int32 Field_name18__ = 418; +} + +message ForeignMessage { + int32 c = 1; +} + +enum ForeignEnum { + FOREIGN_FOO = 0; + FOREIGN_BAR = 1; + FOREIGN_BAZ = 2; +} diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 38ddb635..63875c68 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -32,7 +32,7 @@ namespace google { namespace protobuf { class Timestamp; class TimestampDefaultTypeInternal; -extern TimestampDefaultTypeInternal _Timestamp_default_instance_; +LIBPROTOBUF_EXPORT extern TimestampDefaultTypeInternal _Timestamp_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index 6f29ab61..73fa35a3 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -35,25 +35,25 @@ namespace google { namespace protobuf { class Any; class AnyDefaultTypeInternal; -extern AnyDefaultTypeInternal _Any_default_instance_; +LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_; class Enum; class EnumDefaultTypeInternal; -extern EnumDefaultTypeInternal _Enum_default_instance_; +LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_; class EnumValue; class EnumValueDefaultTypeInternal; -extern EnumValueDefaultTypeInternal _EnumValue_default_instance_; +LIBPROTOBUF_EXPORT extern EnumValueDefaultTypeInternal _EnumValue_default_instance_; class Field; class FieldDefaultTypeInternal; -extern FieldDefaultTypeInternal _Field_default_instance_; +LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_; class Option; class OptionDefaultTypeInternal; -extern OptionDefaultTypeInternal _Option_default_instance_; +LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_; class SourceContext; class SourceContextDefaultTypeInternal; -extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; +LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; class Type; class TypeDefaultTypeInternal; -extern TypeDefaultTypeInternal _Type_default_instance_; +LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_; } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 0197b6c5..cf8e1693 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -32,31 +32,31 @@ namespace google { namespace protobuf { class BoolValue; class BoolValueDefaultTypeInternal; -extern BoolValueDefaultTypeInternal _BoolValue_default_instance_; +LIBPROTOBUF_EXPORT extern BoolValueDefaultTypeInternal _BoolValue_default_instance_; class BytesValue; class BytesValueDefaultTypeInternal; -extern BytesValueDefaultTypeInternal _BytesValue_default_instance_; +LIBPROTOBUF_EXPORT extern BytesValueDefaultTypeInternal _BytesValue_default_instance_; class DoubleValue; class DoubleValueDefaultTypeInternal; -extern DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; +LIBPROTOBUF_EXPORT extern DoubleValueDefaultTypeInternal _DoubleValue_default_instance_; class FloatValue; class FloatValueDefaultTypeInternal; -extern FloatValueDefaultTypeInternal _FloatValue_default_instance_; +LIBPROTOBUF_EXPORT extern FloatValueDefaultTypeInternal _FloatValue_default_instance_; class Int32Value; class Int32ValueDefaultTypeInternal; -extern Int32ValueDefaultTypeInternal _Int32Value_default_instance_; +LIBPROTOBUF_EXPORT extern Int32ValueDefaultTypeInternal _Int32Value_default_instance_; class Int64Value; class Int64ValueDefaultTypeInternal; -extern Int64ValueDefaultTypeInternal _Int64Value_default_instance_; +LIBPROTOBUF_EXPORT extern Int64ValueDefaultTypeInternal _Int64Value_default_instance_; class StringValue; class StringValueDefaultTypeInternal; -extern StringValueDefaultTypeInternal _StringValue_default_instance_; +LIBPROTOBUF_EXPORT extern StringValueDefaultTypeInternal _StringValue_default_instance_; class UInt32Value; class UInt32ValueDefaultTypeInternal; -extern UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; +LIBPROTOBUF_EXPORT extern UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_; class UInt64Value; class UInt64ValueDefaultTypeInternal; -extern UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; +LIBPROTOBUF_EXPORT extern UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_; } // namespace protobuf } // namespace google |