diff options
Diffstat (limited to 'src')
23 files changed, 455 insertions, 273 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/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/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc index 072cccad..5d7163fa 100644 --- a/src/google/protobuf/compiler/js/embed.cc +++ b/src/google/protobuf/compiler/js/embed.cc @@ -28,6 +28,7 @@ // (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> 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 316069e1..a2179446 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 aac4e8af..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 { @@ -54,16 +59,14 @@ namespace php { std::string PhpName(const std::string& full_name, bool is_descriptor); std::string DefaultForField(FieldDescriptor* field); std::string IntToString(int32 value); -std::string GeneratedFileName(const std::string& proto_file, - bool is_descriptor); +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 Descriptor* message, - bool is_descriptor, io::Printer* printer); -void GenerateEnum(const EnumDescriptor* en, io::Printer* printer); void Indent(io::Printer* printer); void Outdent(io::Printer* printer); void GenerateMessageDocComment(io::Printer* printer, const Descriptor* message); @@ -73,6 +76,14 @@ 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" && @@ -177,14 +188,63 @@ std::string DefaultForField(const 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) { @@ -381,7 +441,8 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, 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( @@ -449,107 +510,11 @@ void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor, } } -void GenerateRepeatedFieldDecode(const FieldDescriptor* field, - 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 FieldDescriptor* field, - 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 FieldDescriptor* field, 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 Descriptor* message, - bool is_descriptor, 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; - } - - GenerateMessageDocComment(printer, message); - - string message_name = - name_prefix.empty() - ? message->name() - : name_prefix + "_" + MessagePrefix(message) + message->name(); - +void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) { 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 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 EnumDescriptor* en, bool is_descriptor, - 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); @@ -565,7 +530,7 @@ void GenerateEnumToPool(const EnumDescriptor* en, bool is_descriptor, } void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, - bool is_descriptor, io::Printer* printer) { + 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()) { @@ -575,8 +540,9 @@ void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, 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); @@ -589,21 +555,22 @@ void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, 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)); } } @@ -616,11 +583,12 @@ void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, 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); @@ -635,32 +603,48 @@ void GenerateMessageToPool(const string& name_prefix, const Descriptor* message, "\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 FileDescriptor* file, bool is_descriptor, io::Printer* printer) { - if (is_descriptor) { - printer->Print("$pool = DescriptorPool::getGeneratedPool();\n\n"); + 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); @@ -683,38 +667,20 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor, printer->Print( "));\n\n"); } - -} - -void GenerateEnum(const EnumDescriptor* en, io::Printer* printer) { - GenerateEnumDocComment(printer, en); 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); - GenerateEnumValueDocComment(printer, value); - 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, 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" @@ -723,35 +689,212 @@ void GenerateUseDeclaration(bool is_descriptor, io::Printer* printer) { } } -void GenerateFile(const FileDescriptor* file, bool is_descriptor, - 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" "\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); - 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)); + // 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"); + + printer.Print( + "public function __construct() {\n"); + Indent(&printer); - GenerateUseDeclaration(is_descriptor, 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()); + } + + 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); } - - GenerateAddFileToPool(file, is_descriptor, printer); } static string EscapePhpdoc(const string& input) { @@ -932,12 +1075,7 @@ bool Generator::Generate(const FileDescriptor* file, const string& parameter, 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.pb.h b/src/google/protobuf/compiler/plugin.pb.h index e1e999bc..0948ab2d 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -33,92 +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; -extern VersionDefaultTypeInternal _Version_default_instance_; +LIBPROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_; } // namespace compiler } // namespace protobuf } // namespace google 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/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..19bac7dc 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -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/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/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/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 |