| Index: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc
|
| ===================================================================
|
| --- third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc (revision 216642)
|
| +++ third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc (working copy)
|
| @@ -51,7 +51,7 @@
|
| // ===================================================================
|
|
|
| FileGenerator::FileGenerator(const FileDescriptor* file,
|
| - const string& dllexport_decl)
|
| + const Options& options)
|
| : file_(file),
|
| message_generators_(
|
| new scoped_ptr<MessageGenerator>[file->message_type_count()]),
|
| @@ -61,26 +61,26 @@
|
| new scoped_ptr<ServiceGenerator>[file->service_count()]),
|
| extension_generators_(
|
| new scoped_ptr<ExtensionGenerator>[file->extension_count()]),
|
| - dllexport_decl_(dllexport_decl) {
|
| + options_(options) {
|
|
|
| for (int i = 0; i < file->message_type_count(); i++) {
|
| message_generators_[i].reset(
|
| - new MessageGenerator(file->message_type(i), dllexport_decl));
|
| + new MessageGenerator(file->message_type(i), options));
|
| }
|
|
|
| for (int i = 0; i < file->enum_type_count(); i++) {
|
| enum_generators_[i].reset(
|
| - new EnumGenerator(file->enum_type(i), dllexport_decl));
|
| + new EnumGenerator(file->enum_type(i), options));
|
| }
|
|
|
| for (int i = 0; i < file->service_count(); i++) {
|
| service_generators_[i].reset(
|
| - new ServiceGenerator(file->service(i), dllexport_decl));
|
| + new ServiceGenerator(file->service(i), options));
|
| }
|
|
|
| for (int i = 0; i < file->extension_count(); i++) {
|
| extension_generators_[i].reset(
|
| - new ExtensionGenerator(file->extension(i), dllexport_decl));
|
| + new ExtensionGenerator(file->extension(i), options));
|
| }
|
|
|
| SplitStringUsing(file_->package(), ".", &package_parts_);
|
| @@ -104,6 +104,7 @@
|
| "filename", file_->name(),
|
| "filename_identifier", filename_identifier);
|
|
|
| +
|
| printer->Print(
|
| "#include <google/protobuf/stubs/common.h>\n"
|
| "\n");
|
| @@ -128,7 +129,17 @@
|
|
|
| // OK, it's now safe to #include other files.
|
| printer->Print(
|
| - "#include <google/protobuf/generated_message_util.h>\n"
|
| + "#include <google/protobuf/generated_message_util.h>\n");
|
| + if (file_->message_type_count() > 0) {
|
| + if (HasDescriptorMethods(file_)) {
|
| + printer->Print(
|
| + "#include <google/protobuf/message.h>\n");
|
| + } else {
|
| + printer->Print(
|
| + "#include <google/protobuf/message_lite.h>\n");
|
| + }
|
| + }
|
| + printer->Print(
|
| "#include <google/protobuf/repeated_field.h>\n"
|
| "#include <google/protobuf/extension_set.h>\n");
|
|
|
| @@ -137,9 +148,9 @@
|
| "#include <google/protobuf/unknown_field_set.h>\n");
|
| }
|
|
|
| - if (HasDescriptorMethods(file_)) {
|
| + if (HasDescriptorMethods(file_) && HasEnumDefinitions(file_)) {
|
| printer->Print(
|
| - "#include <google/protobuf/generated_message_reflection.h>\n");
|
| + "#include <google/protobuf/generated_enum_reflection.h>\n");
|
| }
|
|
|
| if (HasGenericServices(file_)) {
|
| @@ -147,16 +158,23 @@
|
| "#include <google/protobuf/service.h>\n");
|
| }
|
|
|
| + if (HasUnknownFields(file_) && file_->message_type_count() > 0) {
|
| + printer->Print(
|
| + "#include <google/protobuf/unknown_field_set.h>\n");
|
| + }
|
|
|
| +
|
| for (int i = 0; i < file_->dependency_count(); i++) {
|
| printer->Print(
|
| "#include \"$dependency$.pb.h\"\n",
|
| "dependency", StripProto(file_->dependency(i)->name()));
|
| }
|
|
|
| +
|
| printer->Print(
|
| "// @@protoc_insertion_point(includes)\n");
|
|
|
| +
|
| // Open namespace.
|
| GenerateNamespaceOpeners(printer);
|
|
|
| @@ -167,7 +185,7 @@
|
| "// Internal implementation detail -- do not call these.\n"
|
| "void $dllexport_decl$ $adddescriptorsname$();\n",
|
| "adddescriptorsname", GlobalAddDescriptorsName(file_->name()),
|
| - "dllexport_decl", dllexport_decl_);
|
| + "dllexport_decl", options_.dllexport_decl);
|
|
|
| printer->Print(
|
| // Note that we don't put dllexport_decl on these because they are only
|
| @@ -287,6 +305,7 @@
|
| void FileGenerator::GenerateSource(io::Printer* printer) {
|
| printer->Print(
|
| "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
|
| + "// source: $filename$\n"
|
| "\n"
|
|
|
| // The generated code calls accessors that might be deprecated. We don't
|
| @@ -296,14 +315,17 @@
|
| "\n"
|
| "#include <algorithm>\n" // for swap()
|
| "\n"
|
| + "#include <google/protobuf/stubs/common.h>\n"
|
| "#include <google/protobuf/stubs/once.h>\n"
|
| "#include <google/protobuf/io/coded_stream.h>\n"
|
| "#include <google/protobuf/wire_format_lite_inl.h>\n",
|
| + "filename", file_->name(),
|
| "basename", StripProto(file_->name()));
|
|
|
| if (HasDescriptorMethods(file_)) {
|
| printer->Print(
|
| "#include <google/protobuf/descriptor.h>\n"
|
| + "#include <google/protobuf/generated_message_reflection.h>\n"
|
| "#include <google/protobuf/reflection_ops.h>\n"
|
| "#include <google/protobuf/wire_format.h>\n");
|
| }
|
| @@ -509,10 +531,12 @@
|
| " static bool already_here = false;\n"
|
| " if (already_here) return;\n"
|
| " already_here = true;\n"
|
| - " GOOGLE_PROTOBUF_VERIFY_VERSION;\n",
|
| + " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
|
| + "\n",
|
| // Without.
|
| "void $adddescriptorsname$_impl() {\n"
|
| - " GOOGLE_PROTOBUF_VERIFY_VERSION;\n",
|
| + " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
|
| + "\n",
|
| // Vars.
|
| "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
|
|
|
| @@ -526,9 +550,9 @@
|
| vector<string> dependency_package_parts;
|
| SplitStringUsing(dependency->package(), ".", &dependency_package_parts);
|
| printer->Print("::");
|
| - for (int i = 0; i < dependency_package_parts.size(); i++) {
|
| + for (int j = 0; j < dependency_package_parts.size(); j++) {
|
| printer->Print("$name$::",
|
| - "name", dependency_package_parts[i]);
|
| + "name", dependency_package_parts[j]);
|
| }
|
| // Call its AddDescriptors function.
|
| printer->Print(
|
| @@ -552,10 +576,12 @@
|
| static const int kBytesPerLine = 40;
|
| for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
|
| printer->Print("\n \"$data$\"",
|
| - "data", EscapeTrigraphs(CEscape(file_data.substr(i, kBytesPerLine))));
|
| + "data",
|
| + EscapeTrigraphs(
|
| + CEscape(file_data.substr(i, kBytesPerLine))));
|
| }
|
| printer->Print(
|
| - ", $size$);\n",
|
| + ", $size$);\n",
|
| "size", SimpleItoa(file_data.size()));
|
|
|
| // Call MessageFactory::InternalRegisterGeneratedFile().
|
|
|