diff options
author | Adam Cozzette <acozzette@google.com> | 2017-09-12 10:32:01 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2017-09-14 10:03:57 -0700 |
commit | 13fd045dbb2b4dacea32be162a41d5a4b0d1802f (patch) | |
tree | c219e7eb18b82523e36c6748861c403a14ea66ae /src/google/protobuf/compiler/cpp/cpp_generator.cc | |
parent | d1bc27caef8377a710370189675cb0958443e8f1 (diff) |
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_generator.cc')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_generator.cc | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc index 68abd0ef..e01e5dca 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc @@ -46,6 +46,7 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/descriptor.pb.h> +#include <google/protobuf/stubs/strutil.h> namespace google { namespace protobuf { @@ -84,7 +85,7 @@ bool CppGenerator::Generate(const FileDescriptor* file, // __declspec(dllimport) depending on what is being compiled. // Options file_options; - + bool split_source = false; for (int i = 0; i < options.size(); i++) { if (options[i].first == "dllexport_decl") { file_options.dllexport_decl = options[i].second; @@ -98,10 +99,14 @@ bool CppGenerator::Generate(const FileDescriptor* file, file_options.annotation_guard_name = options[i].second; } else if (options[i].first == "lite") { file_options.enforce_lite = true; + } else if (options[i].first == "lite_implicit_weak_fields") { + file_options.lite_implicit_weak_fields = true; } else if (options[i].first == "table_driven_parsing") { file_options.table_driven_parsing = true; } else if (options[i].first == "table_driven_serialization") { file_options.table_driven_serialization = true; + } else if (options[i].first == "split_source") { + split_source = true; } else { *error = "Unknown generator option: " + options[i].first; return false; @@ -135,14 +140,13 @@ bool CppGenerator::Generate(const FileDescriptor* file, } } - basename.append(".pb"); { google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( - generator_context->Open(basename + ".h")); + generator_context->Open(basename + ".pb.h")); GeneratedCodeInfo annotations; io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( &annotations); - string info_path = basename + ".h.meta"; + string info_path = basename + ".pb.h.meta"; io::Printer printer(output.get(), '$', file_options.annotate_headers ? &annotation_collector : NULL); @@ -156,9 +160,24 @@ bool CppGenerator::Generate(const FileDescriptor* file, } // Generate cc file. - { + if (split_source) { + { + // This is the global .cc file, containing enum/services/tables/reflection + google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(basename + ".pb.cc")); + io::Printer printer(output.get(), '$'); + file_generator.GenerateGlobalSource(&printer); + } + for (int i = 0; i < file_generator.NumMessages(); i++) { + // TODO(gerbens) Agree on naming scheme. + google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( + generator_context->Open(basename + "." + SimpleItoa(i) + ".cc")); + io::Printer printer(output.get(), '$'); + file_generator.GenerateSourceForMessage(i, &printer); + } + } else { google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( - generator_context->Open(basename + ".cc")); + generator_context->Open(basename + ".pb.cc")); io::Printer printer(output.get(), '$'); file_generator.GenerateSource(&printer); } |