aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2016-04-28 14:34:59 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2016-04-28 14:34:59 -0700
commitcf14183bcd5485b4a71541599ddce0b35eb71352 (patch)
tree12f6e5eb731d7a70cdac4cdafc8b3131629413e2 /src/google/protobuf/compiler
parentf00300d7f04f1c38a7d70e271f9232b94dd0e326 (diff)
Down integrate from Google internal.
Diffstat (limited to 'src/google/protobuf/compiler')
-rw-r--r--src/google/protobuf/compiler/command_line_interface.cc15
-rw-r--r--src/google/protobuf/compiler/command_line_interface.h1
-rw-r--r--src/google/protobuf/compiler/command_line_interface_unittest.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc1
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum.cc36
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum.h11
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.cc40
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_enum_field.h11
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_field.cc3
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_field.h8
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc122
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.h5
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_generator.cc6
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.cc69
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.h85
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_map_field.cc65
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_map_field.h3
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message.cc336
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.cc100
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.h12
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_options.h7
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc3
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_primitive_field.cc35
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_primitive_field.h12
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc93
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.h12
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_unittest.cc2
-rw-r--r--src/google/protobuf/compiler/cpp/metadata_test.cc3
-rw-r--r--src/google/protobuf/compiler/importer_unittest.cc13
-rw-r--r--src/google/protobuf/compiler/java/java_doc_comment.cc56
-rw-r--r--src/google/protobuf/compiler/java/java_enum.cc69
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field_lite.cc91
-rw-r--r--src/google/protobuf/compiler/java/java_enum_field_lite.h6
-rw-r--r--src/google/protobuf/compiler/java/java_field.h2
-rw-r--r--src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc27
-rw-r--r--src/google/protobuf/compiler/java/java_lazy_message_field_lite.h4
-rw-r--r--src/google/protobuf/compiler/java/java_map_field.cc4
-rw-r--r--src/google/protobuf/compiler/java/java_map_field_lite.cc4
-rw-r--r--src/google/protobuf/compiler/java/java_map_field_lite.h2
-rw-r--r--src/google/protobuf/compiler/java/java_message.cc4
-rw-r--r--src/google/protobuf/compiler/java/java_message_field_lite.cc54
-rw-r--r--src/google/protobuf/compiler/java/java_message_field_lite.h6
-rw-r--r--src/google/protobuf/compiler/java/java_message_lite.cc354
-rw-r--r--src/google/protobuf/compiler/java/java_message_lite.h5
-rw-r--r--src/google/protobuf/compiler/java/java_plugin_unittest.cc3
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field_lite.cc58
-rw-r--r--src/google/protobuf/compiler/java/java_primitive_field_lite.h6
-rw-r--r--src/google/protobuf/compiler/java/java_string_field_lite.cc49
-rw-r--r--src/google/protobuf/compiler/java/java_string_field_lite.h6
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc5
-rw-r--r--src/google/protobuf/compiler/plugin.pb.cc36
-rw-r--r--src/google/protobuf/compiler/plugin.pb.h6
-rw-r--r--src/google/protobuf/compiler/python/python_plugin_unittest.cc3
53 files changed, 980 insertions, 995 deletions
diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc
index 87843f62..fcad6b61 100644
--- a/src/google/protobuf/compiler/command_line_interface.cc
+++ b/src/google/protobuf/compiler/command_line_interface.cc
@@ -46,6 +46,7 @@
#include <unistd.h>
#endif
#include <errno.h>
+#include <fstream>
#include <iostream>
#include <ctype.h>
@@ -948,17 +949,23 @@ bool CommandLineInterface::MakeInputsBeProtoPathRelative(
return true;
}
+
CommandLineInterface::ParseArgumentStatus
CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
executable_name_ = argv[0];
+ vector<string> arguments;
+ for (int i = 1; i < argc; ++i) {
+ arguments.push_back(argv[i]);
+ }
+
// Iterate through all arguments and parse them.
- for (int i = 1; i < argc; i++) {
+ for (int i = 0; i < arguments.size(); ++i) {
string name, value;
- if (ParseArgument(argv[i], &name, &value)) {
+ if (ParseArgument(arguments[i].c_str(), &name, &value)) {
// Returned true => Use the next argument as the flag value.
- if (i + 1 == argc || argv[i+1][0] == '-') {
+ if (i + 1 == arguments.size() || arguments[i + 1][0] == '-') {
std::cerr << "Missing value for flag: " << name << std::endl;
if (name == "--decode") {
std::cerr << "To decode an unknown message, use --decode_raw."
@@ -967,7 +974,7 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
return PARSE_ARGUMENT_FAIL;
} else {
++i;
- value = argv[i];
+ value = arguments[i];
}
}
diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h
index f196ffc5..d1377666 100644
--- a/src/google/protobuf/compiler/command_line_interface.h
+++ b/src/google/protobuf/compiler/command_line_interface.h
@@ -212,6 +212,7 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// Parse all command-line arguments.
ParseArgumentStatus ParseArguments(int argc, const char* const argv[]);
+
// Parses a command-line argument into a name/value pair. Returns
// true if the next argument in the argv should be used as the value,
// false otherwise.
diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc
index e3dd2295..ae2900b1 100644
--- a/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -60,6 +60,7 @@
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@@ -376,7 +377,9 @@ void CommandLineInterfaceTest::CreateTempFile(
// Write file.
string full_name = temp_directory_ + "/" + name;
- GOOGLE_CHECK_OK(File::SetContents(full_name, contents, true));
+ GOOGLE_CHECK_OK(File::SetContents(
+ full_name, StringReplace(contents, "$tmpdir", temp_directory_, true),
+ true));
}
void CommandLineInterfaceTest::CreateTempDir(const string& name) {
@@ -1090,6 +1093,7 @@ TEST_F(CommandLineInterfaceTest, WriteDependencyManifestFileForAbsolutePath) {
}
#endif // !_WIN32
+
// -------------------------------------------------------------------
TEST_F(CommandLineInterfaceTest, ParseErrors) {
diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
index 47729e1c..77451ab1 100644
--- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
@@ -54,6 +54,7 @@
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc
index 415ae60f..c81c5982 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc
@@ -98,9 +98,11 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
vars["number"] = Int32ToString(descriptor_->value(i)->number());
vars["prefix"] = (descriptor_->containing_type() == NULL) ?
"" : classname_ + "_";
+ vars["deprecation"] = descriptor_->value(i)->options().deprecated() ?
+ " PROTOBUF_DEPRECATED" : "";
if (i > 0) printer->Print(",\n");
- printer->Print(vars, "$prefix$$name$ = $number$");
+ printer->Print(vars, "$prefix$$name$$deprecation$ = $number$");
if (descriptor_->value(i)->number() < min_value->number()) {
min_value = descriptor_->value(i);
@@ -142,15 +144,16 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) {
"$prefix$$short_name$_MAX + 1;\n\n");
}
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(vars,
"$dllexport$const ::google::protobuf::EnumDescriptor* $classname$_descriptor();\n");
// The _Name and _Parse methods
- printer->Print(vars,
- "inline const ::std::string& $classname$_Name($classname$ value) {\n"
- " return ::google::protobuf::internal::NameOfEnum(\n"
- " $classname$_descriptor(), value);\n"
- "}\n");
+ printer->Print(
+ vars,
+ "inline const ::std::string& $classname$_Name($classname$ value) {\n"
+ " return ::google::protobuf::internal::NameOfEnum(\n"
+ " $classname$_descriptor(), value);\n"
+ "}\n");
printer->Print(vars,
"inline bool $classname$_Parse(\n"
" const ::std::string& name, $classname$* value) {\n"
@@ -166,7 +169,7 @@ GenerateGetEnumDescriptorSpecializations(io::Printer* printer) {
"template <> struct is_proto_enum< $classname$> : ::google::protobuf::internal::true_type "
"{};\n",
"classname", ClassName(descriptor_, true));
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
"template <>\n"
"inline const EnumDescriptor* GetEnumDescriptor< $classname$>() {\n"
@@ -185,8 +188,11 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) {
for (int j = 0; j < descriptor_->value_count(); j++) {
vars["tag"] = EnumValueName(descriptor_->value(j));
+ vars["deprecated_attr"] = descriptor_->value(j)->options().deprecated() ?
+ "PROTOBUF_DEPRECATED_ATTR " : "";
printer->Print(vars,
- "static $constexpr$const $nested_name$ $tag$ = $classname$_$tag$;\n");
+ "$deprecated_attr$static $constexpr$const $nested_name$ $tag$ =\n"
+ " $classname$_$tag$;\n");
}
printer->Print(vars,
@@ -203,16 +209,18 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) {
" $classname$_$nested_name$_ARRAYSIZE;\n");
}
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(vars,
"static inline const ::google::protobuf::EnumDescriptor*\n"
"$nested_name$_descriptor() {\n"
" return $classname$_descriptor();\n"
"}\n");
printer->Print(vars,
- "static inline const ::std::string& $nested_name$_Name($nested_name$ value) {\n"
- " return $classname$_Name(value);\n"
- "}\n");
+ "static inline const ::std::string& "
+ "$nested_name$_Name($nested_name$ value) {"
+ "\n"
+ " return $classname$_Name(value);\n"
+ "}\n");
printer->Print(vars,
"static inline bool $nested_name$_Parse(const ::std::string& name,\n"
" $nested_name$* value) {\n"
@@ -242,7 +250,7 @@ void EnumGenerator::GenerateMethods(io::Printer* printer) {
vars["classname"] = classname_;
vars["constexpr"] = options_.proto_h ? "constexpr " : "";
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(vars,
"const ::google::protobuf::EnumDescriptor* $classname$_descriptor() {\n"
" protobuf_AssignDescriptorsOnce();\n"
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.h b/src/google/protobuf/compiler/cpp/cpp_enum.h
index 61e40346..90edf001 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum.h
+++ b/src/google/protobuf/compiler/cpp/cpp_enum.h
@@ -35,12 +35,12 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__
#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__
+#include <map>
#include <set>
#include <string>
#include <google/protobuf/compiler/cpp/cpp_options.h>
#include <google/protobuf/descriptor.h>
-
namespace google {
namespace protobuf {
namespace io {
@@ -55,8 +55,7 @@ namespace cpp {
class EnumGenerator {
public:
// See generator.cc for the meaning of dllexport_decl.
- explicit EnumGenerator(const EnumDescriptor* descriptor,
- const Options& options);
+ EnumGenerator(const EnumDescriptor* descriptor, const Options& options);
~EnumGenerator();
// Header stuff.
@@ -96,10 +95,10 @@ class EnumGenerator {
private:
const EnumDescriptor* descriptor_;
- string classname_;
- Options options_;
+ const string classname_;
+ const Options& options_;
// whether to generate the *_ARRAYSIZE constant.
- bool generate_array_size_;
+ const bool generate_array_size_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index 824e2205..78a4c402 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
@@ -58,10 +58,9 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
// ===================================================================
-EnumFieldGenerator::
-EnumFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetEnumVariables(descriptor, &variables_, options);
}
@@ -75,8 +74,8 @@ GeneratePrivateMembers(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$type$ $name$() const$deprecation$;\n"
- "void set_$name$($type$ value)$deprecation$;\n");
+ "$deprecated_attr$$type$ $name$() const;\n"
+ "$deprecated_attr$void set_$name$($type$ value);\n");
}
void EnumFieldGenerator::
@@ -135,7 +134,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"if ($type$_IsValid(value)) {\n"
" set_$name$(static_cast< $type$ >(value));\n");
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(variables_,
"} else {\n"
" mutable_unknown_fields()->AddVarint($number$, value);\n");
@@ -228,10 +227,9 @@ GenerateConstructorCode(io::Printer* printer) const {
// ===================================================================
-RepeatedEnumFieldGenerator::
-RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
+ const FieldDescriptor* descriptor, const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetEnumVariables(descriptor, &variables_, options);
}
@@ -241,8 +239,8 @@ void RepeatedEnumFieldGenerator::
GeneratePrivateMembers(io::Printer* printer) const {
printer->Print(variables_,
"::google::protobuf::RepeatedField<int> $name$_;\n");
- if (descriptor_->is_packed()
- && HasGeneratedMethods(descriptor_->file())) {
+ if (descriptor_->is_packed() &&
+ HasGeneratedMethods(descriptor_->file(), options_)) {
printer->Print(variables_,
"mutable int _$name$_cached_byte_size_;\n");
}
@@ -251,12 +249,12 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedEnumFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$type$ $name$(int index) const$deprecation$;\n"
- "void set_$name$(int index, $type$ value)$deprecation$;\n"
- "void add_$name$($type$ value)$deprecation$;\n");
+ "$deprecated_attr$$type$ $name$(int index) const;\n"
+ "$deprecated_attr$void set_$name$(int index, $type$ value);\n"
+ "$deprecated_attr$void add_$name$($type$ value);\n");
printer->Print(variables_,
- "const ::google::protobuf::RepeatedField<int>& $name$() const$deprecation$;\n"
- "::google::protobuf::RepeatedField<int>* mutable_$name$()$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::RepeatedField<int>& $name$() const;\n"
+ "$deprecated_attr$::google::protobuf::RepeatedField<int>* mutable_$name$();\n");
}
void RepeatedEnumFieldGenerator::
@@ -335,7 +333,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"if ($type$_IsValid(value)) {\n"
" add_$name$(static_cast< $type$ >(value));\n");
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(variables_,
"} else {\n"
" mutable_unknown_fields()->AddVarint($number$, value);\n");
@@ -362,7 +360,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
" NULL,\n"
" NULL,\n"
" this->mutable_$name$())));\n");
- } else if (UseUnknownFieldSet(descriptor_->file())) {
+ } else if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(variables_,
"DO_((::google::protobuf::internal::WireFormat::ReadPackedEnumPreserveUnknowns(\n"
" input,\n"
@@ -399,7 +397,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
" if ($type$_IsValid(value)) {\n"
" add_$name$(static_cast< $type$ >(value));\n"
" } else {\n");
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(variables_,
" mutable_unknown_fields()->AddVarint($number$, value);\n");
} else {
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/src/google/protobuf/compiler/cpp/cpp_enum_field.h
index 5b1d01ea..fe21c575 100644
--- a/src/google/protobuf/compiler/cpp/cpp_enum_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.h
@@ -46,8 +46,7 @@ namespace cpp {
class EnumFieldGenerator : public FieldGenerator {
public:
- explicit EnumFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options);
~EnumFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -74,8 +73,8 @@ class EnumFieldGenerator : public FieldGenerator {
class EnumOneofFieldGenerator : public EnumFieldGenerator {
public:
- explicit EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~EnumOneofFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -91,8 +90,8 @@ class EnumOneofFieldGenerator : public EnumFieldGenerator {
class RepeatedEnumFieldGenerator : public FieldGenerator {
public:
- explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~RepeatedEnumFieldGenerator();
// implements FieldGenerator ---------------------------------------
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc
index 8d47d4e0..b3ba3a2e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_field.cc
@@ -77,6 +77,8 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
WireFormat::TagSize(descriptor->number(), descriptor->type()));
(*variables)["deprecation"] = descriptor->options().deprecated()
? " PROTOBUF_DEPRECATED" : "";
+ (*variables)["deprecated_attr"] = descriptor->options().deprecated()
+ ? "PROTOBUF_DEPRECATED_ATTR " : "";
(*variables)["cppget"] = "Get";
@@ -121,6 +123,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor,
const Options& options)
: descriptor_(descriptor),
+ options_(options),
field_generators_(
new google::protobuf::scoped_ptr<FieldGenerator>[descriptor->field_count()]) {
// Construct all the FieldGenerators.
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h
index 1d7f8233..3b012527 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_field.h
@@ -69,7 +69,7 @@ void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
class FieldGenerator {
public:
- FieldGenerator() {}
+ explicit FieldGenerator(const Options& options) : options_(options) {}
virtual ~FieldGenerator();
// Generate lines of code declaring members fields of the message class
@@ -194,6 +194,9 @@ class FieldGenerator {
// are placed in the message's ByteSize() method.
virtual void GenerateByteSize(io::Printer* printer) const = 0;
+ protected:
+ const Options& options_;
+
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
};
@@ -201,13 +204,14 @@ class FieldGenerator {
// Convenience class which constructs FieldGenerators for a Descriptor.
class FieldGeneratorMap {
public:
- explicit FieldGeneratorMap(const Descriptor* descriptor, const Options& options);
+ FieldGeneratorMap(const Descriptor* descriptor, const Options& options);
~FieldGeneratorMap();
const FieldGenerator& get(const FieldDescriptor* field) const;
private:
const Descriptor* descriptor_;
+ const Options& options_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<FieldGenerator> > field_generators_;
static FieldGenerator* MakeGenerator(const FieldDescriptor* field,
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index d48171b0..385b973e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -59,6 +59,7 @@ namespace cpp {
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
: file_(file),
+ options_(options),
message_generators_(
new google::protobuf::scoped_ptr<MessageGenerator>[file->message_type_count()]),
enum_generators_(
@@ -66,8 +67,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
service_generators_(
new google::protobuf::scoped_ptr<ServiceGenerator>[file->service_count()]),
extension_generators_(
- new google::protobuf::scoped_ptr<ExtensionGenerator>[file->extension_count()]),
- options_(options) {
+ new google::protobuf::scoped_ptr<ExtensionGenerator>[file->extension_count()]) {
for (int i = 0; i < file->message_type_count(); i++) {
message_generators_[i].reset(
@@ -267,12 +267,12 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
"right", use_system_include ? ">" : "\"");
// Unknown fields implementation in lite mode uses StringOutputStream
- if (!UseUnknownFieldSet(file_) && file_->message_type_count() > 0) {
+ if (!UseUnknownFieldSet(file_, options_) && file_->message_type_count() > 0) {
printer->Print(
"#include <google/protobuf/io/zero_copy_stream_impl_lite.h>\n");
}
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"#include <google/protobuf/descriptor.h>\n"
"#include <google/protobuf/generated_message_reflection.h>\n"
@@ -297,7 +297,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
GenerateNamespaceOpeners(printer);
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"\n"
"namespace {\n"
@@ -311,7 +311,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
"name", ClassName(file_->enum_type(i), false));
}
- if (HasGenericServices(file_)) {
+ if (HasGenericServices(file_, options_)) {
for (int i = 0; i < file_->service_count(); i++) {
printer->Print(
"const ::google::protobuf::ServiceDescriptor* $name$_descriptor_ = NULL;\n",
@@ -336,7 +336,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
// Generate classes.
for (int i = 0; i < file_->message_type_count(); i++) {
- if (i == 0 && HasGeneratedMethods(file_)) {
+ if (i == 0 && HasGeneratedMethods(file_, options_)) {
printer->Print(
"\n"
"namespace {\n"
@@ -361,7 +361,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
printer->Print("#endif // PROTOBUF_INLINE_NOT_IN_HEADERS\n");
}
- if (HasGenericServices(file_)) {
+ if (HasGenericServices(file_, options_)) {
// Generate services.
for (int i = 0; i < file_->service_count(); i++) {
if (i == 0) printer->Print("\n");
@@ -462,7 +462,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// In optimize_for = LITE_RUNTIME mode, we don't generate AssignDescriptors()
// and we only use AddDescriptors() to allocate default instances.
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"\n"
"void $assigndescriptorsname$() {\n",
@@ -495,7 +495,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
for (int i = 0; i < file_->enum_type_count(); i++) {
enum_generators_[i]->GenerateDescriptorInitializer(printer, i);
}
- if (HasGenericServices(file_)) {
+ if (HasGenericServices(file_, options_)) {
for (int i = 0; i < file_->service_count(); i++) {
service_generators_[i]->GenerateDescriptorInitializer(printer, i);
}
@@ -561,22 +561,23 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// Now generate the AddDescriptors() function.
PrintHandlingOptionalStaticInitializers(
- file_, printer,
- // With static initializers.
- // Note that we don't need any special synchronization in the following code
- // because it is called at static init time before any threads exist.
- "void $adddescriptorsname$() {\n"
- " static bool already_here = false;\n"
- " if (already_here) return;\n"
- " already_here = true;\n"
- " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
- "\n",
- // Without.
- "void $adddescriptorsname$_impl() {\n"
- " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
- "\n",
- // Vars.
- "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
+ file_, options_, printer,
+ // With static initializers.
+ // Note that we don't need any special synchronization in the following
+ // code
+ // because it is called at static init time before any threads exist.
+ "void $adddescriptorsname$() {\n"
+ " static bool already_here = false;\n"
+ " if (already_here) return;\n"
+ " already_here = true;\n"
+ " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
+ "\n",
+ // Without.
+ "void $adddescriptorsname$_impl() {\n"
+ " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
+ "\n",
+ // Vars.
+ "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
printer->Indent();
@@ -593,7 +594,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
"name", add_desc_name);
}
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
// Embed the descriptor. We simply serialize the entire FileDescriptorProto
// and embed it as a string literal, which is parsed and built into real
// descriptors at initialization time.
@@ -687,23 +688,23 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
"\n");
PrintHandlingOptionalStaticInitializers(
- file_, printer,
- // With static initializers.
- "// Force AddDescriptors() to be called at static initialization time.\n"
- "struct StaticDescriptorInitializer_$filename$ {\n"
- " StaticDescriptorInitializer_$filename$() {\n"
- " $adddescriptorsname$();\n"
- " }\n"
- "} static_descriptor_initializer_$filename$_;\n",
- // Without.
- "GOOGLE_PROTOBUF_DECLARE_ONCE($adddescriptorsname$_once_);\n"
- "void $adddescriptorsname$() {\n"
- " ::google::protobuf::GoogleOnceInit(&$adddescriptorsname$_once_,\n"
- " &$adddescriptorsname$_impl);\n"
- "}\n",
- // Vars.
- "adddescriptorsname", GlobalAddDescriptorsName(file_->name()),
- "filename", FilenameIdentifier(file_->name()));
+ file_, options_, printer,
+ // With static initializers.
+ "// Force AddDescriptors() to be called at static initialization time.\n"
+ "struct StaticDescriptorInitializer_$filename$ {\n"
+ " StaticDescriptorInitializer_$filename$() {\n"
+ " $adddescriptorsname$();\n"
+ " }\n"
+ "} static_descriptor_initializer_$filename$_;\n",
+ // Without.
+ "GOOGLE_PROTOBUF_DECLARE_ONCE($adddescriptorsname$_once_);\n"
+ "void $adddescriptorsname$() {\n"
+ " ::google::protobuf::GoogleOnceInit(&$adddescriptorsname$_once_,\n"
+ " &$adddescriptorsname$_impl);\n"
+ "}\n",
+ // Vars.
+ "adddescriptorsname", GlobalAddDescriptorsName(file_->name()), "filename",
+ FilenameIdentifier(file_->name()));
}
void FileGenerator::GenerateNamespaceOpeners(io::Printer* printer) {
@@ -760,16 +761,15 @@ void FileGenerator::GenerateTopHeaderGuard(io::Printer* printer,
const string& filename_identifier) {
// Generate top of header.
printer->Print(
- "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
- "// source: $filename$\n"
- "\n"
- "#ifndef PROTOBUF_$filename_identifier$__INCLUDED\n"
- "#define PROTOBUF_$filename_identifier$__INCLUDED\n"
- "\n"
- "#include <string>\n"
- "\n",
- "filename", file_->name(),
- "filename_identifier", filename_identifier);
+ "// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
+ "// source: $filename$\n"
+ "\n"
+ "#ifndef PROTOBUF_$filename_identifier$__INCLUDED\n"
+ "#define PROTOBUF_$filename_identifier$__INCLUDED\n"
+ "\n"
+ "#include <string>\n",
+ "filename", file_->name(), "filename_identifier", filename_identifier);
+ printer->Print("\n");
}
void FileGenerator::GenerateBottomHeaderGuard(
@@ -808,12 +808,12 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
"#include <google/protobuf/arena.h>\n"
"#include <google/protobuf/arenastring.h>\n"
"#include <google/protobuf/generated_message_util.h>\n");
- if (UseUnknownFieldSet(file_)) {
+ if (UseUnknownFieldSet(file_, options_)) {
printer->Print(
"#include <google/protobuf/metadata.h>\n");
}
if (file_->message_type_count() > 0) {
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"#include <google/protobuf/message.h>\n");
} else {
@@ -827,7 +827,7 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
if (HasMapFields(file_)) {
printer->Print(
"#include <google/protobuf/map.h>\n");
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"#include <google/protobuf/map_field_inl.h>\n");
} else {
@@ -837,7 +837,7 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
}
if (HasEnumDefinitions(file_)) {
- if (HasDescriptorMethods(file_)) {
+ if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"#include <google/protobuf/generated_enum_reflection.h>\n");
} else {
@@ -846,12 +846,12 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
}
}
- if (HasGenericServices(file_)) {
+ if (HasGenericServices(file_, options_)) {
printer->Print(
"#include <google/protobuf/service.h>\n");
}
- if (UseUnknownFieldSet(file_) && file_->message_type_count() > 0) {
+ if (UseUnknownFieldSet(file_, options_) && file_->message_type_count() > 0) {
printer->Print(
"#include <google/protobuf/unknown_field_set.h>\n");
}
@@ -955,7 +955,7 @@ void FileGenerator::GenerateEnumDefinitions(io::Printer* printer) {
}
void FileGenerator::GenerateServiceDefinitions(io::Printer* printer) {
- if (HasGenericServices(file_)) {
+ if (HasGenericServices(file_, options_)) {
// Generate service definitions.
for (int i = 0; i < file_->service_count(); i++) {
if (i > 0) {
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.h b/src/google/protobuf/compiler/cpp/cpp_file.h
index ebe990c2..5dcf692b 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.h
+++ b/src/google/protobuf/compiler/cpp/cpp_file.h
@@ -65,8 +65,7 @@ class ExtensionGenerator; // extension.h
class FileGenerator {
public:
// See generator.cc for the meaning of dllexport_decl.
- explicit FileGenerator(const FileDescriptor* file,
- const Options& options);
+ FileGenerator(const FileDescriptor* file, const Options& options);
~FileGenerator();
// info_path, if non-empty, should be the path (relative to printer's output)
@@ -144,6 +143,7 @@ class FileGenerator {
void GenerateProto2NamespaceEnumSpecializations(io::Printer* printer);
const FileDescriptor* file_;
+ const Options options_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator> > message_generators_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<EnumGenerator> > enum_generators_;
@@ -152,7 +152,6 @@ class FileGenerator {
// E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
vector<string> package_parts_;
- const Options options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc
index c7aec93a..31d189c2 100644
--- a/src/google/protobuf/compiler/cpp/cpp_generator.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc
@@ -96,6 +96,8 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_options.annotation_pragma_name = options[i].second;
} else if (options[i].first == "annotation_guard_name") {
file_options.annotation_guard_name = options[i].second;
+ } else if (options[i].first == "lite") {
+ file_options.enforce_lite = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
@@ -123,7 +125,7 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_generator.GenerateProtoHeader(
&printer, file_options.annotate_headers ? info_path : "");
if (file_options.annotate_headers) {
- scoped_ptr<io::ZeroCopyOutputStream> info_output(
+ google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> info_output(
generator_context->Open(info_path));
annotations.SerializeToZeroCopyStream(info_output.get());
}
@@ -143,7 +145,7 @@ bool CppGenerator::Generate(const FileDescriptor* file,
file_generator.GeneratePBHeader(
&printer, file_options.annotate_headers ? info_path : "");
if (file_options.annotate_headers) {
- scoped_ptr<io::ZeroCopyOutputStream> info_output(
+ google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> info_output(
generator_context->Open(info_path));
annotations.SerializeToZeroCopyStream(info_output.get());
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index fb46e387..2ad4d36a 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -68,14 +68,15 @@ const char* const kKeywordList[] = {
"alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor",
"bool", "break", "case", "catch", "char", "class", "compl", "const",
"constexpr", "const_cast", "continue", "decltype", "default", "delete", "do",
- "double", "dynamic_cast", "else", "enum", "explicit", "extern", "false",
- "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable",
- "namespace", "new", "noexcept", "not", "not_eq", "NULL", "operator", "or",
- "or_eq", "private", "protected", "public", "register", "reinterpret_cast",
- "return", "short", "signed", "sizeof", "static", "static_assert",
- "static_cast", "struct", "switch", "template", "this", "thread_local",
- "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned",
- "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq"
+ "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern",
+ "false", "float", "for", "friend", "goto", "if", "inline", "int", "long",
+ "mutable", "namespace", "new", "noexcept", "not", "not_eq", "NULL",
+ "operator", "or", "or_eq", "private", "protected", "public", "register",
+ "reinterpret_cast", "return", "short", "signed", "sizeof", "static",
+ "static_assert", "static_cast", "struct", "switch", "template", "this",
+ "thread_local", "throw", "true", "try", "typedef", "typeid", "typename",
+ "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t",
+ "while", "xor", "xor_eq"
};
hash_set<string> MakeKeywordsMap() {
@@ -171,9 +172,10 @@ string DependentBaseClassTemplateName(const Descriptor* descriptor) {
return ClassName(descriptor, false) + "_InternalBase";
}
-string SuperClassName(const Descriptor* descriptor) {
- return HasDescriptorMethods(descriptor->file()) ?
- "::google::protobuf::Message" : "::google::protobuf::MessageLite";
+string SuperClassName(const Descriptor* descriptor, const Options& options) {
+ return HasDescriptorMethods(descriptor->file(), options)
+ ? "::google::protobuf::Message"
+ : "::google::protobuf::MessageLite";
}
string DependentBaseDownCast() {
@@ -485,8 +487,9 @@ string SafeFunctionName(const Descriptor* descriptor,
return function_name;
}
-bool StaticInitializersForced(const FileDescriptor* file) {
- if (HasDescriptorMethods(file) || file->extension_count() > 0) {
+bool StaticInitializersForced(const FileDescriptor* file,
+ const Options& options) {
+ if (HasDescriptorMethods(file, options) || file->extension_count() > 0) {
return true;
}
for (int i = 0; i < file->message_type_count(); ++i) {
@@ -498,10 +501,10 @@ bool StaticInitializersForced(const FileDescriptor* file) {
}
void PrintHandlingOptionalStaticInitializers(
- const FileDescriptor* file, io::Printer* printer,
+ const FileDescriptor* file, const Options& options, io::Printer* printer,
const char* with_static_init, const char* without_static_init,
- const char* var1, const string& val1,
- const char* var2, const string& val2) {
+ const char* var1, const string& val1, const char* var2,
+ const string& val2) {
map<string, string> vars;
if (var1) {
vars[var1] = val1;
@@ -510,14 +513,16 @@ void PrintHandlingOptionalStaticInitializers(
vars[var2] = val2;
}
PrintHandlingOptionalStaticInitializers(
- vars, file, printer, with_static_init, without_static_init);
+ vars, file, options, printer, with_static_init, without_static_init);
}
-void PrintHandlingOptionalStaticInitializers(
- const map<string, string>& vars, const FileDescriptor* file,
- io::Printer* printer, const char* with_static_init,
- const char* without_static_init) {
- if (StaticInitializersForced(file)) {
+void PrintHandlingOptionalStaticInitializers(const map<string, string>& vars,
+ const FileDescriptor* file,
+ const Options& options,
+ io::Printer* printer,
+ const char* with_static_init,
+ const char* without_static_init) {
+ if (StaticInitializersForced(file, options)) {
printer->Print(vars, with_static_init);
} else {
printer->Print(vars, (string(
@@ -612,10 +617,11 @@ enum Utf8CheckMode {
};
// Which level of UTF-8 enforcemant is placed on this file.
-static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field) {
+static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field,
+ const Options& options) {
if (field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) {
return STRICT;
- } else if (field->file()->options().optimize_for() !=
+ } else if (GetOptimizeFor(field->file(), options) !=
FileOptions::LITE_RUNTIME) {
return VERIFY;
} else {
@@ -624,13 +630,13 @@ static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field) {
}
static void GenerateUtf8CheckCode(const FieldDescriptor* field,
- bool for_parse,
+ const Options& options, bool for_parse,
const map<string, string>& variables,
const char* parameters,
const char* strict_function,
const char* verify_function,
io::Printer* printer) {
- switch (GetUtf8CheckMode(field)) {
+ switch (GetUtf8CheckMode(field, options)) {
case STRICT: {
if (for_parse) {
printer->Print("DO_(");
@@ -674,23 +680,22 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field,
}
void GenerateUtf8CheckCodeForString(const FieldDescriptor* field,
- bool for_parse,
+ const Options& options, bool for_parse,
const map<string, string>& variables,
const char* parameters,
io::Printer* printer) {
- GenerateUtf8CheckCode(field, for_parse, variables, parameters,
+ GenerateUtf8CheckCode(field, options, for_parse, variables, parameters,
"VerifyUtf8String", "VerifyUTF8StringNamedField",
printer);
}
void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field,
- bool for_parse,
+ const Options& options, bool for_parse,
const map<string, string>& variables,
const char* parameters,
io::Printer* printer) {
- GenerateUtf8CheckCode(field, for_parse, variables, parameters,
- "VerifyUtf8Cord", "VerifyUTF8CordNamedField",
- printer);
+ GenerateUtf8CheckCode(field, options, for_parse, variables, parameters,
+ "VerifyUtf8Cord", "VerifyUTF8CordNamedField", printer);
}
} // namespace cpp
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index a22d414d..018acfca 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -37,8 +37,9 @@
#include <map>
#include <string>
-#include <google/protobuf/descriptor.h>
+#include <google/protobuf/compiler/cpp/cpp_options.h>
#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/descriptor.h>
namespace google {
namespace protobuf {
@@ -72,7 +73,7 @@ string DependentBaseClassTemplateName(const Descriptor* descriptor);
// Name of the base class: either the dependent base class (for use with
// proto_h) or google::protobuf::Message.
-string SuperClassName(const Descriptor* descriptor);
+string SuperClassName(const Descriptor* descriptor, const Options& options);
// Returns a string that down-casts from the dependent base class to the
// derived class.
@@ -118,7 +119,7 @@ string DependentTypeName(const FieldDescriptor* field);
string FieldMessageTypeName(const FieldDescriptor* field);
// Strips ".proto" or ".protodevel" from the end of a filename.
-string StripProto(const string& filename);
+LIBPROTOC_EXPORT string StripProto(const string& filename);
// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
// Note: non-built-in type names will be qualified, meaning they will start
@@ -168,12 +169,17 @@ inline bool PreserveUnknownFields(const Descriptor* message) {
return message->file()->syntax() != FileDescriptor::SYNTAX_PROTO3;
}
+// Returns the optimize mode for <file>, respecting <options.enforce_lite>.
+::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor(
+ const FileDescriptor* file, const Options& options);
+
// If PreserveUnknownFields() is true, determines whether unknown
// fields will be stored in an UnknownFieldSet or a string.
// If PreserveUnknownFields() is false, this method will not be
// used.
-inline bool UseUnknownFieldSet(const FileDescriptor* file) {
- return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
+inline bool UseUnknownFieldSet(const FileDescriptor* file,
+ const Options& options) {
+ return GetOptimizeFor(file, options) != FileOptions::LITE_RUNTIME;
}
@@ -186,45 +192,52 @@ bool HasEnumDefinitions(const FileDescriptor* file);
// Does this file have generated parsing, serialization, and other
// standard methods for which reflection-based fallback implementations exist?
-inline bool HasGeneratedMethods(const FileDescriptor* file) {
- return file->options().optimize_for() != FileOptions::CODE_SIZE;
+inline bool HasGeneratedMethods(const FileDescriptor* file,
+ const Options& options) {
+ return GetOptimizeFor(file, options) != FileOptions::CODE_SIZE;
}
// Do message classes in this file have descriptor and reflection methods?
-inline bool HasDescriptorMethods(const FileDescriptor* file) {
- return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
+inline bool HasDescriptorMethods(const FileDescriptor* file,
+ const Options& options) {
+ return GetOptimizeFor(file, options) != FileOptions::LITE_RUNTIME;
}
// Should we generate generic services for this file?
-inline bool HasGenericServices(const FileDescriptor* file) {
+inline bool HasGenericServices(const FileDescriptor* file,
+ const Options& options) {
return file->service_count() > 0 &&
- file->options().optimize_for() != FileOptions::LITE_RUNTIME &&
+ GetOptimizeFor(file, options) != FileOptions::LITE_RUNTIME &&
file->options().cc_generic_services();
}
// Should we generate a separate, super-optimized code path for serializing to
// flat arrays? We don't do this in Lite mode because we'd rather reduce code
// size.
-inline bool HasFastArraySerialization(const FileDescriptor* file) {
- return file->options().optimize_for() == FileOptions::SPEED;
+inline bool HasFastArraySerialization(const FileDescriptor* file,
+ const Options& options) {
+ return GetOptimizeFor(file, options) == FileOptions::SPEED;
}
// Returns whether we have to generate code with static initializers.
-bool StaticInitializersForced(const FileDescriptor* file);
+bool StaticInitializersForced(const FileDescriptor* file,
+ const Options& options);
// Prints 'with_static_init' if static initializers have to be used for the
// provided file. Otherwise emits both 'with_static_init' and
// 'without_static_init' using #ifdef.
void PrintHandlingOptionalStaticInitializers(
- const FileDescriptor* file, io::Printer* printer,
+ const FileDescriptor* file, const Options& options, io::Printer* printer,
const char* with_static_init, const char* without_static_init,
- const char* var1 = NULL, const string& val1 = "",
- const char* var2 = NULL, const string& val2 = "");
+ const char* var1 = NULL, const string& val1 = "", const char* var2 = NULL,
+ const string& val2 = "");
-void PrintHandlingOptionalStaticInitializers(
- const map<string, string>& vars, const FileDescriptor* file,
- io::Printer* printer, const char* with_static_init,
- const char* without_static_init);
+void PrintHandlingOptionalStaticInitializers(const map<string, string>& vars,
+ const FileDescriptor* file,
+ const Options& options,
+ io::Printer* printer,
+ const char* with_static_init,
+ const char* without_static_init);
inline bool IsMapEntryMessage(const Descriptor* descriptor) {
@@ -267,19 +280,23 @@ bool IsAnyMessage(const Descriptor* descriptor);
bool IsWellKnownMessage(const FileDescriptor* descriptor);
-void GenerateUtf8CheckCodeForString(
- const FieldDescriptor* field,
- bool for_parse,
- const map<string, string>& variables,
- const char* parameters,
- io::Printer* printer);
-
-void GenerateUtf8CheckCodeForCord(
- const FieldDescriptor* field,
- bool for_parse,
- const map<string, string>& variables,
- const char* parameters,
- io::Printer* printer);
+void GenerateUtf8CheckCodeForString(const FieldDescriptor* field,
+ const Options& options, bool for_parse,
+ const map<string, string>& variables,
+ const char* parameters,
+ io::Printer* printer);
+
+void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field,
+ const Options& options, bool for_parse,
+ const map<string, string>& variables,
+ const char* parameters, io::Printer* printer);
+
+inline ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor(
+ const FileDescriptor* file, const Options& options) {
+ return options.enforce_lite
+ ? FileOptions::LITE_RUNTIME
+ : file->options().optimize_for();
+}
} // namespace cpp
} // namespace compiler
diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc
index e5e2f07d..f585c31b 100644
--- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc
@@ -49,10 +49,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = FieldMessageTypeName(descriptor);
- (*variables)["stream_writer"] = (*variables)["declared_type"] +
- (HasFastArraySerialization(descriptor->message_type()->file()) ?
- "MaybeToArray" :
- "");
+ (*variables)["stream_writer"] =
+ (*variables)["declared_type"] +
+ (HasFastArraySerialization(descriptor->message_type()->file(), options)
+ ? "MaybeToArray"
+ : "");
(*variables)["full_name"] = descriptor->full_name();
const FieldDescriptor* key =
@@ -83,7 +84,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
(*variables)["number"] = SimpleItoa(descriptor->number());
(*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor));
- if (HasDescriptorMethods(descriptor->file())) {
+ if (HasDescriptorMethods(descriptor->file(), options)) {
(*variables)["lite"] = "";
} else {
(*variables)["lite"] = "Lite";
@@ -98,10 +99,10 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
}
}
-MapFieldGenerator::
-MapFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor),
+MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options)
+ : FieldGenerator(options),
+ descriptor_(descriptor),
dependent_field_(options.proto_h && IsFieldDependent(descriptor)) {
SetMessageVariables(descriptor, &variables_, options);
}
@@ -127,10 +128,10 @@ GeneratePrivateMembers(io::Printer* printer) const {
void MapFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n"
- " $name$() const$deprecation$;\n"
- "::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n"
- " mutable_$name$()$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n"
+ " $name$() const;\n"
+ "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n"
+ " mutable_$name$();\n");
}
void MapFieldGenerator::
@@ -170,7 +171,7 @@ GenerateSwappingCode(io::Printer* printer) const {
void MapFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(variables_,
"$name$_.SetAssignDescriptorCallback(\n"
" protobuf_AssignDescriptorsOnce);\n"
@@ -217,7 +218,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
" (*mutable_$name$())[entry->key()] =\n"
" static_cast< $val_cpp$ >(*entry->mutable_value());\n"
" } else {\n");
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(variables_,
" mutable_unknown_fields()"
"->AddLengthDelimited($number$, data);\n");
@@ -238,14 +239,14 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
descriptor_->message_type()->FindFieldByName("key");
if (key_field->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- key_field, true, variables_,
+ key_field, options_, true, variables_,
"entry->key().data(), entry->key().length(),\n", printer);
}
if (value_field->type() == FieldDescriptor::TYPE_STRING) {
- GenerateUtf8CheckCodeForString(
- value_field, true, variables_,
- "entry->mutable_value()->data(),\n"
- "entry->mutable_value()->length(),\n", printer);
+ GenerateUtf8CheckCodeForString(value_field, options_, true, variables_,
+ "entry->mutable_value()->data(),\n"
+ "entry->mutable_value()->length(),\n",
+ printer);
}
// If entry is allocated by arena, its desctructor should be avoided.
@@ -285,14 +286,14 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
const FieldDescriptor* value_field =
descriptor_->message_type()->FindFieldByName("value");
if (key_field->type() == FieldDescriptor::TYPE_STRING) {
- GenerateUtf8CheckCodeForString(
- key_field, false, variables_,
- "it->first.data(), it->first.length(),\n", printer);
+ GenerateUtf8CheckCodeForString(key_field, options_, false, variables_,
+ "it->first.data(), it->first.length(),\n",
+ printer);
}
if (value_field->type() == FieldDescriptor::TYPE_STRING) {
- GenerateUtf8CheckCodeForString(
- value_field, false, variables_,
- "it->second.data(), it->second.length(),\n", printer);
+ GenerateUtf8CheckCodeForString(value_field, options_, false, variables_,
+ "it->second.data(), it->second.length(),\n",
+ printer);
}
printer->Outdent();
@@ -343,14 +344,14 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
const FieldDescriptor* value_field =
descriptor_->message_type()->FindFieldByName("value");
if (key_field->type() == FieldDescriptor::TYPE_STRING) {
- GenerateUtf8CheckCodeForString(
- key_field, false, variables_,
- "it->first.data(), it->first.length(),\n", printer);
+ GenerateUtf8CheckCodeForString(key_field, options_, false, variables_,
+ "it->first.data(), it->first.length(),\n",
+ printer);
}
if (value_field->type() == FieldDescriptor::TYPE_STRING) {
- GenerateUtf8CheckCodeForString(
- value_field, false, variables_,
- "it->second.data(), it->second.length(),\n", printer);
+ GenerateUtf8CheckCodeForString(value_field, options_, false, variables_,
+ "it->second.data(), it->second.length(),\n",
+ printer);
}
printer->Outdent();
diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.h b/src/google/protobuf/compiler/cpp/cpp_map_field.h
index 5e205623..087dcde0 100644
--- a/src/google/protobuf/compiler/cpp/cpp_map_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_map_field.h
@@ -43,8 +43,7 @@ namespace cpp {
class MapFieldGenerator : public FieldGenerator {
public:
- explicit MapFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ MapFieldGenerator(const FieldDescriptor* descriptor, const Options& options);
~MapFieldGenerator();
// implements FieldGenerator ---------------------------------------
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index c3166611..da2a4c92 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -106,8 +106,8 @@ struct ExtensionRangeSorter {
// Returns true if the "required" restriction check should be ignored for the
// given field.
-inline static bool ShouldIgnoreRequiredFieldCheck(
- const FieldDescriptor* field) {
+inline static bool ShouldIgnoreRequiredFieldCheck(const FieldDescriptor* field,
+ const Options& options) {
return false;
}
@@ -116,9 +116,8 @@ inline static bool ShouldIgnoreRequiredFieldCheck(
//
// already_seen is used to avoid checking the same type multiple times
// (and also to protect against recursion).
-static bool HasRequiredFields(
- const Descriptor* type,
- hash_set<const Descriptor*>* already_seen) {
+static bool HasRequiredFields(const Descriptor* type, const Options& options,
+ hash_set<const Descriptor*>* already_seen) {
if (already_seen->count(type) > 0) {
// Since the first occurrence of a required field causes the whole
// function to return true, we can assume that if the type is already
@@ -138,8 +137,8 @@ static bool HasRequiredFields(
return true;
}
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- !ShouldIgnoreRequiredFieldCheck(field)) {
- if (HasRequiredFields(field->message_type(), already_seen)) {
+ !ShouldIgnoreRequiredFieldCheck(field, options)) {
+ if (HasRequiredFields(field->message_type(), options, already_seen)) {
return true;
}
}
@@ -148,9 +147,9 @@ static bool HasRequiredFields(
return false;
}
-static bool HasRequiredFields(const Descriptor* type) {
+static bool HasRequiredFields(const Descriptor* type, const Options& options) {
hash_set<const Descriptor*> already_seen;
- return HasRequiredFields(type, &already_seen);
+ return HasRequiredFields(type, options, &already_seen);
}
// This returns an estimate of the compiler's alignment for the field. This
@@ -480,7 +479,7 @@ GenerateDependentFieldAccessorDeclarations(io::Printer* printer) {
// If the message is dependent, the inline clear_*() method will need
// to delete the message type, so it must be in the dependent base
// class. (See also GenerateFieldAccessorDeclarations.)
- printer->Print(vars, "void clear_$name$()$deprecation$;\n");
+ printer->Print(vars, "$deprecated_attr$void clear_$name$();\n");
}
// Generate type-specific accessor declarations.
field_generators_.get(field).GenerateDependentAccessorDeclarations(printer);
@@ -515,22 +514,24 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) {
}
if (field->is_repeated()) {
- printer->Print(vars, "int $name$_size() const$deprecation$;\n");
+ printer->Print(vars, "$deprecated_attr$int $name$_size() const;\n");
} else if (HasHasMethod(field)) {
- printer->Print(vars, "bool has_$name$() const$deprecation$;\n");
+ printer->Print(vars, "$deprecated_attr$bool has_$name$() const;\n");
} else if (HasPrivateHasMethod(field)) {
printer->Print(vars,
"private:\n"
- "bool has_$name$() const$deprecation$;\n"
+ "bool has_$name$() const;\n"
"public:\n");
}
if (!dependent_field) {
// If this field is dependent, then its clear_() method is in the
// depenent base class. (See also GenerateDependentAccessorDeclarations.)
- printer->Print(vars, "void clear_$name$()$deprecation$;\n");
+ printer->Print(vars, "$deprecated_attr$void clear_$name$();\n");
}
- printer->Print(vars, "static const int $constant_name$ = $number$;\n");
+ printer->Print(vars,
+ "$deprecated_attr$static const int $constant_name$ = "
+ "$number$;\n");
// Generate type-specific accessor declarations.
field_generators_.get(field).GenerateAccessorDeclarations(printer);
@@ -837,7 +838,7 @@ GenerateDependentBaseClassDefinition(io::Printer* printer) {
map<string, string> vars;
vars["classname"] = DependentBaseClassTemplateName(descriptor_);
- vars["superclass"] = SuperClassName(descriptor_);
+ vars["superclass"] = SuperClassName(descriptor_, options_);
printer->Print(vars,
"template <class T>\n"
@@ -888,7 +889,7 @@ GenerateClassDefinition(io::Printer* printer) {
vars["superclass"] =
DependentBaseClassTemplateName(descriptor_) + "<" + classname_ + ">";
} else {
- vars["superclass"] = SuperClassName(descriptor_);
+ vars["superclass"] = SuperClassName(descriptor_, options_);
}
printer->Print(vars,
"class $dllexport$$classname$ : public $superclass$ {\n");
@@ -912,7 +913,7 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {\n"
" return _internal_metadata_.unknown_fields();\n"
@@ -966,7 +967,7 @@ GenerateClassDefinition(io::Printer* printer) {
}
// Only generate this member if it's not disabled.
- if (HasDescriptorMethods(descriptor_->file()) &&
+ if (HasDescriptorMethods(descriptor_->file(), options_) &&
!descriptor_->options().no_standard_descriptor_accessor()) {
printer->Print(vars,
"static const ::google::protobuf::Descriptor* descriptor();\n");
@@ -1003,7 +1004,7 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
}
- if (!StaticInitializersForced(descriptor_->file())) {
+ if (!StaticInitializersForced(descriptor_->file(), options_)) {
printer->Print(vars,
"#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"
"// Returns the internal default instance pointer. This function can\n"
@@ -1046,8 +1047,8 @@ GenerateClassDefinition(io::Printer* printer) {
"\n"
"$classname$* New(::google::protobuf::Arena* arena) const;\n");
- if (HasGeneratedMethods(descriptor_->file())) {
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasGeneratedMethods(descriptor_->file(), options_)) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(vars,
"void CopyFrom(const ::google::protobuf::Message& from);\n"
"void MergeFrom(const ::google::protobuf::Message& from);\n");
@@ -1069,11 +1070,11 @@ GenerateClassDefinition(io::Printer* printer) {
" ::google::protobuf::io::CodedOutputStream* output) const;\n");
// DiscardUnknownFields() is implemented in message.cc using reflections. We
// need to implement this function in generated code for messages.
- if (!UseUnknownFieldSet(descriptor_->file())) {
+ if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"void DiscardUnknownFields();\n");
}
- if (HasFastArraySerialization(descriptor_->file())) {
+ if (HasFastArraySerialization(descriptor_->file(), options_)) {
printer->Print(
"::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;\n");
}
@@ -1096,7 +1097,7 @@ GenerateClassDefinition(io::Printer* printer) {
}
uses_string_ = false;
if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file())) {
+ !UseUnknownFieldSet(descriptor_->file(), options_)) {
uses_string_ = true;
}
for (int i = 0; i < descriptors.size(); i++) {
@@ -1126,7 +1127,7 @@ GenerateClassDefinition(io::Printer* printer) {
"classname", classname_);
}
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"private:\n"
"inline ::google::protobuf::Arena* GetArenaNoVirtual() const {\n"
@@ -1150,7 +1151,7 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
}
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
"::google::protobuf::Metadata GetMetadata() const;\n"
"\n");
@@ -1239,7 +1240,7 @@ GenerateClassDefinition(io::Printer* printer) {
"oneof_name", descriptor_->oneof_decl(i)->name());
}
- if (HasGeneratedMethods(descriptor_->file()) &&
+ if (HasGeneratedMethods(descriptor_->file(), options_) &&
!descriptor_->options().message_set_wire_format() &&
num_required_fields_ > 1) {
printer->Print(
@@ -1281,7 +1282,7 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
}
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;\n");
} else {
@@ -1408,15 +1409,14 @@ GenerateClassDefinition(io::Printer* printer) {
// friends so that they can access private static variables like
// default_instance_ and reflection_.
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- "friend void $dllexport_decl$ $adddescriptorsname$();\n",
- // Without.
- "friend void $dllexport_decl$ $adddescriptorsname$_impl();\n",
- // Vars.
- "dllexport_decl", options_.dllexport_decl,
- "adddescriptorsname",
- GlobalAddDescriptorsName(descriptor_->file()->name()));
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ "friend void $dllexport_decl$ $adddescriptorsname$();\n",
+ // Without.
+ "friend void $dllexport_decl$ $adddescriptorsname$_impl();\n",
+ // Vars.
+ "dllexport_decl", options_.dllexport_decl, "adddescriptorsname",
+ GlobalAddDescriptorsName(descriptor_->file()->name()));
printer->Print(
"friend void $assigndescriptorsname$();\n"
@@ -1579,7 +1579,7 @@ GenerateDescriptorInitializer(io::Printer* printer, int index) {
// Unknown field offset: either points to the unknown field set if embedded
// directly, or indicates that the unknown field set is stored as part of the
// internal metadata if not.
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(vars,
" -1,\n");
} else {
@@ -1619,7 +1619,7 @@ GenerateDescriptorInitializer(io::Printer* printer, int index) {
// arena pointer and unknown field set (in a space-efficient way) if we use
// that implementation strategy, or an offset directly to the arena pointer if
// not (because e.g. we don't have an unknown field set).
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(vars,
" GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
"$classname$, _internal_metadata_),\n");
@@ -1709,7 +1709,7 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) {
"classname", classname_);
if ((descriptor_->oneof_decl_count() > 0) &&
- HasDescriptorMethods(descriptor_->file())) {
+ HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
"$classname$_default_oneof_instance_ = new $classname$OneofInstance();\n",
"classname", classname_);
@@ -1749,7 +1749,7 @@ GenerateShutdownCode(io::Printer* printer) {
"delete $classname$::default_instance_;\n",
"classname", classname_);
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
if (descriptor_->oneof_decl_count() > 0) {
printer->Print(
"delete $classname$_default_oneof_instance_;\n",
@@ -1777,7 +1777,8 @@ void MessageGenerator::
GenerateClassMethods(io::Printer* printer) {
// mutable_unknown_fields wrapper function for LazyStringOutputStream
// callback.
- if (!UseUnknownFieldSet(descriptor_->file())) {
+ if (PreserveUnknownFields(descriptor_) &&
+ !UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"static ::std::string* MutableUnknownFieldsFor$classname$(\n"
" $classname$* ptr) {\n"
@@ -1851,7 +1852,7 @@ GenerateClassMethods(io::Printer* printer) {
printer->Print("\n");
}
- if (HasGeneratedMethods(descriptor_->file())) {
+ if (HasGeneratedMethods(descriptor_->file(), options_)) {
GenerateClear(printer);
printer->Print("\n");
@@ -1861,7 +1862,7 @@ GenerateClassMethods(io::Printer* printer) {
GenerateSerializeWithCachedSizes(printer);
printer->Print("\n");
- if (HasFastArraySerialization(descriptor_->file())) {
+ if (HasFastArraySerialization(descriptor_->file(), options_)) {
GenerateSerializeWithCachedSizesToArray(printer);
printer->Print("\n");
}
@@ -1882,7 +1883,7 @@ GenerateClassMethods(io::Printer* printer) {
GenerateSwap(printer);
printer->Print("\n");
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
"::google::protobuf::Metadata $classname$::GetMetadata() const {\n"
" protobuf_AssignDescriptorsOnce();\n"
@@ -1959,7 +1960,7 @@ GenerateSharedConstructorCode(io::Printer* printer) {
"_cached_size_ = 0;\n").c_str());
if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file())) {
+ !UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"_unknown_fields_.UnsafeSetDefault(\n"
" &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n");
@@ -2004,7 +2005,7 @@ GenerateSharedDestructorCode(io::Printer* printer) {
// Write the desctructor for _unknown_fields_ in lite runtime.
if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file())) {
+ !UseUnknownFieldSet(descriptor_->file(), options_)) {
if (SupportsArenas(descriptor_)) {
printer->Print(
"_unknown_fields_.Destroy(\n"
@@ -2035,11 +2036,11 @@ GenerateSharedDestructorCode(io::Printer* printer) {
}
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- "if (this != default_instance_) {\n",
- // Without.
- "if (this != &default_instance()) {\n");
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ "if (this != default_instance_) {\n",
+ // Without.
+ "if (this != &default_instance()) {\n");
// We need to delete all embedded messages.
// TODO(kenton): If we make unset messages point at default instances
@@ -2119,7 +2120,7 @@ GenerateStructors(io::Printer* printer) {
superclass =
DependentBaseClassTemplateName(descriptor_) + "<" + classname_ + ">";
} else {
- superclass = SuperClassName(descriptor_);
+ superclass = SuperClassName(descriptor_, options_);
}
string initializer_with_arena = superclass + "()";
@@ -2127,7 +2128,7 @@ GenerateStructors(io::Printer* printer) {
initializer_with_arena += ",\n _extensions_(arena)";
}
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
initializer_with_arena += ",\n _internal_metadata_(arena)";
} else {
initializer_with_arena += ",\n _arena_ptr_(arena)";
@@ -2147,7 +2148,7 @@ GenerateStructors(io::Printer* printer) {
}
string initializer_null;
- initializer_null = (UseUnknownFieldSet(descriptor_->file()) ?
+ initializer_null = (UseUnknownFieldSet(descriptor_->file(), options_) ?
", _internal_metadata_(NULL)" : ", _arena_ptr_(NULL)");
if (IsAnyMessage(descriptor_)) {
initializer_null += ", _any_metadata_(&type_url_, &value_)";
@@ -2201,24 +2202,23 @@ GenerateStructors(io::Printer* printer) {
if (!field->is_repeated() &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
(field->containing_oneof() == NULL ||
- HasDescriptorMethods(descriptor_->file()))) {
+ HasDescriptorMethods(descriptor_->file(), options_))) {
string name;
if (field->containing_oneof()) {
name = classname_ + "_default_oneof_instance_->";
}
name += FieldName(field);
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " $name$_ = const_cast< $type$*>(&$type$::default_instance());\n",
- // Without.
- " $name$_ = const_cast< $type$*>(\n"
- " $type$::internal_default_instance());\n",
- // Vars.
- "name", name,
- "type", FieldMessageTypeName(field));
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " $name$_ = const_cast< $type$*>(&$type$::default_instance());\n",
+ // Without.
+ " $name$_ = const_cast< $type$*>(\n"
+ " $type$::internal_default_instance());\n",
+ // Vars.
+ "name", name, "type", FieldMessageTypeName(field));
} else if (field->containing_oneof() &&
- HasDescriptorMethods(descriptor_->file())) {
+ HasDescriptorMethods(descriptor_->file(), options_)) {
field_generators_.get(descriptor_->field(i))
.GenerateConstructorCode(printer);
}
@@ -2234,10 +2234,10 @@ GenerateStructors(io::Printer* printer) {
"classname", classname_,
"superclass", superclass,
"full_name", descriptor_->full_name());
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
",\n _internal_metadata_(NULL)");
- } else if (!UseUnknownFieldSet(descriptor_->file())) {
+ } else if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(",\n _arena_ptr_(NULL)");
}
if (IsAnyMessage(descriptor_)) {
@@ -2285,7 +2285,7 @@ GenerateStructors(io::Printer* printer) {
"classname", classname_);
// Only generate this member if it's not disabled.
- if (HasDescriptorMethods(descriptor_->file()) &&
+ if (HasDescriptorMethods(descriptor_->file(), options_) &&
!descriptor_->options().no_standard_descriptor_accessor()) {
printer->Print(
"const ::google::protobuf::Descriptor* $classname$::descriptor() {\n"
@@ -2303,14 +2303,14 @@ GenerateStructors(io::Printer* printer) {
"classname", classname_);
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " if (default_instance_ == NULL) $adddescriptorsname$();\n",
- // Without.
- " $adddescriptorsname$();\n",
- // Vars.
- "adddescriptorsname",
- GlobalAddDescriptorsName(descriptor_->file()->name()));
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " if (default_instance_ == NULL) $adddescriptorsname$();\n",
+ // Without.
+ " $adddescriptorsname$();\n",
+ // Vars.
+ "adddescriptorsname",
+ GlobalAddDescriptorsName(descriptor_->file()->name()));
printer->Print(
" return *default_instance_;\n"
@@ -2352,8 +2352,10 @@ static int popcnt(uint32 n) {
void MessageGenerator::
GenerateClear(io::Printer* printer) {
- printer->Print("void $classname$::Clear() {\n",
- "classname", classname_);
+ printer->Print(
+ "void $classname$::Clear() {\n"
+ "// @@protoc_insertion_point(message_clear_start:$full_name$)\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
// Step 1: Extensions
@@ -2390,8 +2392,16 @@ GenerateClear(io::Printer* printer) {
// positions of two fields in the Message.
// ZR_ zeroes a non-empty range of fields via memset.
const char* macros =
+ "#if defined(__clang__)\n"
+ "#define ZR_HELPER_(f) \\\n"
+ " _Pragma(\"clang diagnostic push\") \\\n"
+ " _Pragma(\"clang diagnostic ignored \\\"-Winvalid-offsetof\\\"\") \\\n"
+ " __builtin_offsetof($classname$, f) \\\n"
+ " _Pragma(\"clang diagnostic pop\")\n"
+ "#else\n"
"#define ZR_HELPER_(f) reinterpret_cast<char*>(\\\n"
- " &reinterpret_cast<$classname$*>(16)->f)\n\n"
+ " &reinterpret_cast<$classname$*>(16)->f)\n"
+ "#endif\n\n"
"#define ZR_(first, last) do {\\\n"
" ::memset(&first, 0,\\\n"
" ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\\\n"
@@ -2519,7 +2529,7 @@ GenerateClear(io::Printer* printer) {
}
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"if (_internal_metadata_.have_unknown_fields()) {\n"
" mutable_unknown_fields()->Clear();\n"
@@ -2549,10 +2559,13 @@ GenerateOneofClear(io::Printer* printer) {
map<string, string> oneof_vars;
oneof_vars["classname"] = classname_;
oneof_vars["oneofname"] = descriptor_->oneof_decl(i)->name();
+ oneof_vars["full_name"] = descriptor_->full_name();
string message_class;
printer->Print(oneof_vars,
- "void $classname$::clear_$oneofname$() {\n");
+ "void $classname$::clear_$oneofname$() {\n"
+ "// @@protoc_insertion_point(one_of_clear_start:"
+ "$full_name$)\n");
printer->Indent();
printer->Print(oneof_vars,
"switch($oneofname$_case()) {\n");
@@ -2635,7 +2648,7 @@ GenerateSwap(io::Printer* printer) {
"classname", classname_);
printer->Indent();
- if (HasGeneratedMethods(descriptor_->file())) {
+ if (HasGeneratedMethods(descriptor_->file(), options_)) {
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
field_generators_.get(field).GenerateSwappingCode(printer);
@@ -2656,19 +2669,15 @@ GenerateSwap(io::Printer* printer) {
}
}
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
- printer->Print(
+ // Ignore PreserveUnknownFields here - always swap internal_metadata as it
+ // may contain more than just unknown fields.
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(
"_internal_metadata_.Swap(&other->_internal_metadata_);\n");
- } else {
- printer->Print("_unknown_fields_.Swap(&other->_unknown_fields_);\n");
- }
} else {
- // Still swap internal_metadata as it may contain more than just
- // unknown fields.
- printer->Print(
- "_internal_metadata_.Swap(&other->_internal_metadata_);\n");
+ printer->Print("_unknown_fields_.Swap(&other->_unknown_fields_);\n");
}
+
printer->Print("std::swap(_cached_size_, other->_cached_size_);\n");
if (descriptor_->extension_range_count() > 0) {
printer->Print("_extensions_.Swap(&other->_extensions_);\n");
@@ -2683,13 +2692,15 @@ GenerateSwap(io::Printer* printer) {
void MessageGenerator::
GenerateMergeFrom(io::Printer* printer) {
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
// Generate the generalized MergeFrom (aka that which takes in the Message
// base class as a parameter).
printer->Print(
- "void $classname$::MergeFrom(const ::google::protobuf::Message& from) {\n"
- " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n",
- "classname", classname_);
+ "void $classname$::MergeFrom(const ::google::protobuf::Message& from) {\n"
+ "// @@protoc_insertion_point(generalized_merge_from_start:"
+ "$full_name$)\n"
+ " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
// Cast the message to the proper type. If we find that the message is
@@ -2701,11 +2712,15 @@ GenerateMergeFrom(io::Printer* printer) {
" ::google::protobuf::internal::DynamicCastToGenerated<const $classname$>(\n"
" &from);\n"
"if (source == NULL) {\n"
+ "// @@protoc_insertion_point(generalized_merge_from_cast_fail:"
+ "$full_name$)\n"
" ::google::protobuf::internal::ReflectionOps::Merge(from, this);\n"
"} else {\n"
+ "// @@protoc_insertion_point(generalized_merge_from_cast_success:"
+ "$full_name$)\n"
" MergeFrom(*source);\n"
"}\n",
- "classname", classname_);
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Outdent();
printer->Print("}\n\n");
@@ -2722,9 +2737,11 @@ GenerateMergeFrom(io::Printer* printer) {
// Generate the class-specific MergeFrom, which avoids the GOOGLE_CHECK and cast.
printer->Print(
- "void $classname$::MergeFrom(const $classname$& from) {\n"
- " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n",
- "classname", classname_);
+ "void $classname$::MergeFrom(const $classname$& from) {\n"
+ "// @@protoc_insertion_point(class_specific_merge_from_start:"
+ "$full_name$)\n"
+ " if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
// Merge Repeated fields. These fields do not require a
@@ -2825,7 +2842,7 @@ GenerateMergeFrom(io::Printer* printer) {
}
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"if (from._internal_metadata_.have_unknown_fields()) {\n"
" mutable_unknown_fields()->MergeFrom(from.unknown_fields());\n"
@@ -2844,12 +2861,14 @@ GenerateMergeFrom(io::Printer* printer) {
void MessageGenerator::
GenerateCopyFrom(io::Printer* printer) {
- if (HasDescriptorMethods(descriptor_->file())) {
+ if (HasDescriptorMethods(descriptor_->file(), options_)) {
// Generate the generalized CopyFrom (aka that which takes in the Message
// base class as a parameter).
printer->Print(
- "void $classname$::CopyFrom(const ::google::protobuf::Message& from) {\n",
- "classname", classname_);
+ "void $classname$::CopyFrom(const ::google::protobuf::Message& from) {\n"
+ "// @@protoc_insertion_point(generalized_copy_from_start:"
+ "$full_name$)\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
printer->Print(
@@ -2863,8 +2882,10 @@ GenerateCopyFrom(io::Printer* printer) {
// Generate the class-specific CopyFrom.
printer->Print(
- "void $classname$::CopyFrom(const $classname$& from) {\n",
- "classname", classname_);
+ "void $classname$::CopyFrom(const $classname$& from) {\n"
+ "// @@protoc_insertion_point(class_specific_copy_from_start:"
+ "$full_name$)\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
printer->Print(
@@ -2886,15 +2907,15 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
"classname", classname_);
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " return _extensions_.ParseMessageSet(input, default_instance_,\n"
- " mutable_unknown_fields());\n",
- // Without.
- " return _extensions_.ParseMessageSet(input, &default_instance(),\n"
- " mutable_unknown_fields());\n",
- // Vars.
- "classname", classname_);
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " return _extensions_.ParseMessageSet(input, default_instance_,\n"
+ " mutable_unknown_fields());\n",
+ // Without.
+ " return _extensions_.ParseMessageSet(input, &default_instance(),\n"
+ " mutable_unknown_fields());\n",
+ // Vars.
+ "classname", classname_);
printer->Print(
"}\n");
@@ -2904,17 +2925,18 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
printer->Print(
"bool $classname$::MergePartialFromCodedStream(\n"
" ::google::protobuf::io::CodedInputStream* input) {\n"
- "#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure\n"
+ "#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure\n"
" ::google::protobuf::uint32 tag;\n",
"classname", classname_);
- if (!UseUnknownFieldSet(descriptor_->file())) {
+ if (PreserveUnknownFields(descriptor_) &&
+ !UseUnknownFieldSet(descriptor_->file(), options_)) {
// Use LazyStringOutputString to avoid initializing unknown fields string
// unless it is actually needed. For the same reason, disable eager refresh
// on the CodedOutputStream.
printer->Print(
" ::google::protobuf::io::LazyStringOutputStream unknown_fields_string(\n"
- " google::protobuf::internal::NewPermanentCallback(\n"
+ " ::google::protobuf::internal::NewPermanentCallback(\n"
" &MutableUnknownFieldsFor$classname$, this));\n"
" ::google::protobuf::io::CodedOutputStream unknown_fields_stream(\n"
" &unknown_fields_string, false);\n",
@@ -3136,32 +3158,32 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
}
printer->Print(") {\n");
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " DO_(_extensions_.ParseField(tag, input, default_instance_,\n"
- " mutable_unknown_fields()));\n",
- // Without.
- " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n"
- " mutable_unknown_fields()));\n");
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " DO_(_extensions_.ParseField(tag, input, default_instance_,\n"
+ " mutable_unknown_fields()));\n",
+ // Without.
+ " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n"
+ " mutable_unknown_fields()));\n");
} else {
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " DO_(_extensions_.ParseField(tag, input, default_instance_,\n"
- " &unknown_fields_stream));\n",
- // Without.
- " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n"
- " &unknown_fields_stream));\n");
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " DO_(_extensions_.ParseField(tag, input, default_instance_,\n"
+ " &unknown_fields_stream));\n",
+ // Without.
+ " DO_(_extensions_.ParseField(tag, input, &default_instance(),\n"
+ " &unknown_fields_stream));\n");
}
} else {
PrintHandlingOptionalStaticInitializers(
- descriptor_->file(), printer,
- // With static initializers.
- " DO_(_extensions_.ParseField(tag, input, default_instance_);\n",
- // Without.
- " DO_(_extensions_.ParseField(tag, input, &default_instance());\n");
+ descriptor_->file(), options_, printer,
+ // With static initializers.
+ " DO_(_extensions_.ParseField(tag, input, default_instance_);\n",
+ // Without.
+ " DO_(_extensions_.ParseField(tag, input, &default_instance());\n");
}
printer->Print(
" continue;\n"
@@ -3170,7 +3192,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
// We really don't recognize this tag. Skip it.
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"DO_(::google::protobuf::internal::WireFormat::SkipField(\n"
" input, tag, mutable_unknown_fields()));\n");
@@ -3263,7 +3285,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) {
" ::google::protobuf::io::CodedOutputStream* output) const {\n"
" _extensions_.SerializeMessageSetWithCachedSizes(output);\n",
"classname", classname_);
- GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file()));
+ GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
printer->Print(
" ::google::protobuf::internal::WireFormat::SerializeUnknownMessageSetItems(\n"
" unknown_fields(), output);\n");
@@ -3303,7 +3325,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) {
" target =\n"
" _extensions_.SerializeMessageSetWithCachedSizesToArray(target);\n",
"classname", classname_);
- GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file()));
+ GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
printer->Print(
" target = ::google::protobuf::internal::WireFormat::\n"
" SerializeUnknownMessageSetItemsToArray(\n"
@@ -3369,7 +3391,7 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) {
}
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print("if (_internal_metadata_.have_unknown_fields()) {\n");
printer->Indent();
if (to_array) {
@@ -3436,10 +3458,11 @@ GenerateByteSize(io::Printer* printer) {
if (descriptor_->options().message_set_wire_format()) {
// Special-case MessageSet.
printer->Print(
- "int $classname$::ByteSize() const {\n"
- " int total_size = _extensions_.MessageSetByteSize();\n",
- "classname", classname_);
- GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file()));
+ "int $classname$::ByteSize() const {\n"
+ "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n"
+ " int total_size = _extensions_.MessageSetByteSize();\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
+ GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_));
printer->Print(
"if (_internal_metadata_.have_unknown_fields()) {\n"
" total_size += ::google::protobuf::internal::WireFormat::\n"
@@ -3458,8 +3481,10 @@ GenerateByteSize(io::Printer* printer) {
// Emit a function (rarely used, we hope) that handles the required fields
// by checking for each one individually.
printer->Print(
- "int $classname$::RequiredFieldsByteSizeFallback() const {\n",
- "classname", classname_);
+ "int $classname$::RequiredFieldsByteSizeFallback() const {\n"
+ "// @@protoc_insertion_point(required_fields_byte_size_fallback_start:"
+ "$full_name$)\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
printer->Print("int total_size = 0;\n");
for (int i = 0; i < descriptor_->field_count(); i++) {
@@ -3482,8 +3507,9 @@ GenerateByteSize(io::Printer* printer) {
}
printer->Print(
- "int $classname$::ByteSize() const {\n",
- "classname", classname_);
+ "int $classname$::ByteSize() const {\n"
+ "// @@protoc_insertion_point(message_byte_size_start:$full_name$)\n",
+ "classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
printer->Print(
"int total_size = 0;\n"
@@ -3659,7 +3685,7 @@ GenerateByteSize(io::Printer* printer) {
}
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file())) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
"if (_internal_metadata_.have_unknown_fields()) {\n"
" total_size +=\n"
@@ -3725,8 +3751,8 @@ GenerateIsInitialized(io::Printer* printer) {
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- !ShouldIgnoreRequiredFieldCheck(field) &&
- HasRequiredFields(field->message_type())) {
+ !ShouldIgnoreRequiredFieldCheck(field, options_) &&
+ HasRequiredFields(field->message_type(), options_)) {
if (field->is_repeated()) {
printer->Print(
"if (!::google::protobuf::internal::AllAreInitialized(this->$name$()))"
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index b4545892..332c0264 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -53,10 +53,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
(*variables)["non_null_ptr_to_name"] =
StrCat("this->", (*variables)["name"], "_");
}
- (*variables)["stream_writer"] = (*variables)["declared_type"] +
- (HasFastArraySerialization(descriptor->message_type()->file()) ?
- "MaybeToArray" :
- "");
+ (*variables)["stream_writer"] =
+ (*variables)["declared_type"] +
+ (HasFastArraySerialization(descriptor->message_type()->file(), options)
+ ? "MaybeToArray"
+ : "");
// NOTE: Escaped here to unblock proto1->proto2 migration.
// TODO(liujisi): Extend this to apply for other conflicting methods.
(*variables)["release_name"] =
@@ -77,11 +78,11 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
// ===================================================================
-MessageFieldGenerator::
-MessageFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor),
- dependent_field_(options.proto_h && IsFieldDependent(descriptor)) {
+MessageFieldGenerator::MessageFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options)
+ : FieldGenerator(options),
+ descriptor_(descriptor),
+ dependent_field_(options.proto_h && IsFieldDependent(descriptor)) {
SetMessageVariables(descriptor, &variables_, options);
}
@@ -95,7 +96,7 @@ GeneratePrivateMembers(io::Printer* printer) const {
void MessageFieldGenerator::
GenerateGetterDeclaration(io::Printer* printer) const {
printer->Print(variables_,
- "const $type$& $name$() const$deprecation$;\n");
+ "$deprecated_attr$const $type$& $name$() const;\n");
}
void MessageFieldGenerator::
@@ -105,9 +106,9 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const {
}
// Arena manipulation code is out-of-line in the derived message class.
printer->Print(variables_,
- "$type$* mutable_$name$()$deprecation$;\n"
- "$type$* $release_name$()$deprecation$;\n"
- "void set_allocated_$name$($type$* $name$)$deprecation$;\n");
+ "$deprecated_attr$$type$* mutable_$name$();\n"
+ "$deprecated_attr$$type$* $release_name$();\n"
+ "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n");
}
void MessageFieldGenerator::
@@ -115,28 +116,28 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
if (SupportsArenas(descriptor_)) {
printer->Print(variables_,
"private:\n"
- "void _slow_mutable_$name$()$deprecation$;\n");
+ "void _slow_mutable_$name$();\n");
if (SupportsArenas(descriptor_->message_type())) {
printer->Print(variables_,
"void _slow_set_allocated_$name$(\n"
- " ::google::protobuf::Arena* message_arena, $type$** $name$)$deprecation$;\n");
+ " ::google::protobuf::Arena* message_arena, $type$** $name$);\n");
}
printer->Print(variables_,
- "$type$* _slow_$release_name$()$deprecation$;\n"
+ "$type$* _slow_$release_name$();\n"
"public:\n");
}
GenerateGetterDeclaration(printer);
if (!dependent_field_) {
printer->Print(variables_,
- "$type$* mutable_$name$()$deprecation$;\n"
- "$type$* $release_name$()$deprecation$;\n"
- "void set_allocated_$name$($type$* $name$)$deprecation$;\n");
+ "$deprecated_attr$$type$* mutable_$name$();\n"
+ "$deprecated_attr$$type$* $release_name$();\n"
+ "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n");
}
if (SupportsArenas(descriptor_)) {
printer->Print(variables_,
- "$type$* unsafe_arena_release_$name$()$deprecation$;\n"
- "void unsafe_arena_set_allocated_$name$(\n"
- " $type$* $name$)$deprecation$;\n");
+ "$deprecated_attr$$type$* unsafe_arena_release_$name$();\n"
+ "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n"
+ " $type$* $name$);\n");
}
}
@@ -167,6 +168,7 @@ void MessageFieldGenerator::GenerateNonInlineAccessorDefinitions(
" }\n"
"}\n"
"$type$* $classname$::unsafe_arena_release_$name$() {\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" $clear_hasbit$\n"
" $type$* temp = $name$_;\n"
" $name$_ = NULL;\n"
@@ -246,6 +248,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
"}\n"
"template <class T>\n"
"inline $type$* $dependent_classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $dependent_typename$*& $name$_ = $this_message$$name$_;\n"
" $clear_hasbit$\n"
" if ($this_message$GetArenaNoVirtual() != NULL) {\n"
@@ -305,6 +308,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
"}\n"
"template <class T>\n"
"inline $type$* $dependent_classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $clear_hasbit$\n"
" $dependent_typename$*& $name$_ = $this_message$$name$_;\n"
" $dependent_typename$* temp = $name$_;\n"
@@ -349,11 +353,11 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_get:$full_name$)\n");
PrintHandlingOptionalStaticInitializers(
- variables, descriptor_->file(), printer,
- // With static initializers.
- " return $name$_ != NULL ? *$name$_ : *default_instance_->$name$_;\n",
- // Without.
- " return $name$_ != NULL ? *$name$_ : *default_instance().$name$_;\n");
+ variables, descriptor_->file(), options_, printer,
+ // With static initializers.
+ " return $name$_ != NULL ? *$name$_ : *default_instance_->$name$_;\n",
+ // Without.
+ " return $name$_ != NULL ? *$name$_ : *default_instance().$name$_;\n");
printer->Print(variables, "}\n");
if (dependent_field_) {
@@ -373,6 +377,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"$inline$"
"$type$* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $clear_hasbit$\n"
" if (GetArenaNoVirtual() != NULL) {\n"
" return _slow_$release_name$();\n"
@@ -426,6 +431,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n"
"$inline$"
"$type$* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $clear_hasbit$\n"
" $type$* temp = $name$_;\n"
" $name$_ = NULL;\n"
@@ -547,7 +553,7 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const {
return;
}
printer->Print(variables_,
- "const $type$& $name$() const$deprecation$;\n");
+ "$deprecated_attr$const $type$& $name$() const;\n");
MessageFieldGenerator::GenerateDependentAccessorDeclarations(printer);
}
@@ -560,7 +566,7 @@ GenerateGetterDeclaration(io::Printer* printer) const {
return;
}
printer->Print(variables_,
- "const $type$& $name$() const$deprecation$;\n");
+ "$deprecated_attr$const $type$& $name$() const;\n");
}
void MessageOneofFieldGenerator::
@@ -651,6 +657,7 @@ InternalGenerateInlineAccessorDefinitions(const map<string, string>& variables,
"$tmpl$"
"$inline$"
"$type$* $dependent_classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if ($this_message$has_$name$()) {\n"
" $this_message$clear_has_$oneof_name$();\n"
" if ($this_message$GetArenaNoVirtual() != NULL) {\n"
@@ -706,6 +713,8 @@ InternalGenerateInlineAccessorDefinitions(const map<string, string>& variables,
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n"
"$inline$ $type$* $classname$::unsafe_arena_release_$name$() {\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_release"
+ ":$full_name$)\n"
" if (has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" $type$* temp = $oneof_prefix$$name$_;\n"
@@ -744,6 +753,7 @@ InternalGenerateInlineAccessorDefinitions(const map<string, string>& variables,
"$tmpl$"
"$inline$"
"$type$* $dependent_classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if ($this_message$has_$name$()) {\n"
" $this_message$clear_has_$oneof_name$();\n"
" $dependent_typename$* temp = $field_member$;\n"
@@ -805,12 +815,12 @@ GenerateConstructorCode(io::Printer* printer) const {
// ===================================================================
-RepeatedMessageFieldGenerator::
-RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor),
- dependent_field_(options.proto_h && IsFieldDependent(descriptor)),
- dependent_getter_(dependent_field_ && options.safe_boundary_check) {
+RepeatedMessageFieldGenerator::RepeatedMessageFieldGenerator(
+ const FieldDescriptor* descriptor, const Options& options)
+ : FieldGenerator(options),
+ descriptor_(descriptor),
+ dependent_field_(options.proto_h && IsFieldDependent(descriptor)),
+ dependent_getter_(dependent_field_ && options.safe_boundary_check) {
SetMessageVariables(descriptor, &variables_, options);
}
@@ -825,23 +835,23 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
InternalGenerateTypeDependentAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$type$* mutable_$name$(int index)$deprecation$;\n"
- "$type$* add_$name$()$deprecation$;\n");
+ "$deprecated_attr$$type$* mutable_$name$(int index);\n"
+ "$deprecated_attr$$type$* add_$name$();\n");
if (dependent_getter_) {
printer->Print(variables_,
- "const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
- " $name$() const$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
+ " $name$() const;\n");
}
printer->Print(variables_,
- "::google::protobuf::RepeatedPtrField< $type$ >*\n"
- " mutable_$name$()$deprecation$;\n");
+ "$deprecated_attr$::google::protobuf::RepeatedPtrField< $type$ >*\n"
+ " mutable_$name$();\n");
}
void RepeatedMessageFieldGenerator::
GenerateDependentAccessorDeclarations(io::Printer* printer) const {
if (dependent_getter_) {
printer->Print(variables_,
- "const $type$& $name$(int index) const$deprecation$;\n");
+ "$deprecated_attr$const $type$& $name$(int index) const;\n");
}
if (dependent_field_) {
InternalGenerateTypeDependentAccessorDeclarations(printer);
@@ -852,15 +862,15 @@ void RepeatedMessageFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
if (!dependent_getter_) {
printer->Print(variables_,
- "const $type$& $name$(int index) const$deprecation$;\n");
+ "$deprecated_attr$const $type$& $name$(int index) const;\n");
}
if (!dependent_field_) {
InternalGenerateTypeDependentAccessorDeclarations(printer);
}
if (!dependent_getter_) {
printer->Print(variables_,
- "const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
- " $name$() const$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n"
+ " $name$() const;\n");
}
}
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.h b/src/google/protobuf/compiler/cpp/cpp_message_field.h
index 35efd0fa..d8d9279c 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_message_field.h
@@ -46,8 +46,8 @@ namespace cpp {
class MessageFieldGenerator : public FieldGenerator {
public:
- explicit MessageFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ MessageFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~MessageFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -83,8 +83,8 @@ class MessageFieldGenerator : public FieldGenerator {
class MessageOneofFieldGenerator : public MessageFieldGenerator {
public:
- explicit MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~MessageOneofFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -110,8 +110,8 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
class RepeatedMessageFieldGenerator : public FieldGenerator {
public:
- explicit RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~RepeatedMessageFieldGenerator();
// implements FieldGenerator ---------------------------------------
diff --git a/src/google/protobuf/compiler/cpp/cpp_options.h b/src/google/protobuf/compiler/cpp/cpp_options.h
index e908362b..ab1d2ed3 100644
--- a/src/google/protobuf/compiler/cpp/cpp_options.h
+++ b/src/google/protobuf/compiler/cpp/cpp_options.h
@@ -44,11 +44,16 @@ namespace cpp {
// Generator options (see generator.cc for a description of each):
struct Options {
Options()
- : safe_boundary_check(false), proto_h(false), annotate_headers(false) {}
+ : safe_boundary_check(false),
+ proto_h(false),
+ annotate_headers(false),
+ enforce_lite(false) {}
+
string dllexport_decl;
bool safe_boundary_check;
bool proto_h;
bool annotate_headers;
+ bool enforce_lite;
string annotation_pragma_name;
string annotation_guard_name;
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
index d1efbfe6..34a41d82 100644
--- a/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
@@ -44,9 +44,10 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/printer.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
-#include <google/protobuf/testing/file.h>
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
index 9f929d37..650f0381 100644
--- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
@@ -100,10 +100,9 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
// ===================================================================
-PrimitiveFieldGenerator::
-PrimitiveFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+PrimitiveFieldGenerator::PrimitiveFieldGenerator(
+ const FieldDescriptor* descriptor, const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetPrimitiveVariables(descriptor, &variables_, options);
}
@@ -117,8 +116,8 @@ GeneratePrivateMembers(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$type$ $name$() const$deprecation$;\n"
- "void set_$name$($type$ value)$deprecation$;\n");
+ "$deprecated_attr$$type$ $name$() const;\n"
+ "$deprecated_attr$void set_$name$($type$ value);\n");
}
void PrimitiveFieldGenerator::
@@ -256,10 +255,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
// ===================================================================
-RepeatedPrimitiveFieldGenerator::
-RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+RepeatedPrimitiveFieldGenerator::RepeatedPrimitiveFieldGenerator(
+ const FieldDescriptor* descriptor, const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetPrimitiveVariables(descriptor, &variables_, options);
if (descriptor->is_packed()) {
@@ -277,7 +275,8 @@ void RepeatedPrimitiveFieldGenerator::
GeneratePrivateMembers(io::Printer* printer) const {
printer->Print(variables_,
"::google::protobuf::RepeatedField< $type$ > $name$_;\n");
- if (descriptor_->is_packed() && HasGeneratedMethods(descriptor_->file())) {
+ if (descriptor_->is_packed() &&
+ HasGeneratedMethods(descriptor_->file(), options_)) {
printer->Print(variables_,
"mutable int _$name$_cached_byte_size_;\n");
}
@@ -286,14 +285,14 @@ GeneratePrivateMembers(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
- "$type$ $name$(int index) const$deprecation$;\n"
- "void set_$name$(int index, $type$ value)$deprecation$;\n"
- "void add_$name$($type$ value)$deprecation$;\n");
+ "$deprecated_attr$$type$ $name$(int index) const;\n"
+ "$deprecated_attr$void set_$name$(int index, $type$ value);\n"
+ "$deprecated_attr$void add_$name$($type$ value);\n");
printer->Print(variables_,
- "const ::google::protobuf::RepeatedField< $type$ >&\n"
- " $name$() const$deprecation$;\n"
- "::google::protobuf::RepeatedField< $type$ >*\n"
- " mutable_$name$()$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n"
+ " $name$() const;\n"
+ "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n"
+ " mutable_$name$();\n");
}
void RepeatedPrimitiveFieldGenerator::
diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
index fcd7d684..655ebde4 100644
--- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
@@ -46,8 +46,8 @@ namespace cpp {
class PrimitiveFieldGenerator : public FieldGenerator {
public:
- explicit PrimitiveFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ PrimitiveFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~PrimitiveFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -74,8 +74,8 @@ class PrimitiveFieldGenerator : public FieldGenerator {
class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
public:
- explicit PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~PrimitiveOneofFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -92,8 +92,8 @@ class PrimitiveOneofFieldGenerator : public PrimitiveFieldGenerator {
class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
public:
- explicit RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~RepeatedPrimitiveFieldGenerator();
// implements FieldGenerator ---------------------------------------
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 6b0821a6..1d743457 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -76,10 +76,9 @@ void SetStringVariables(const FieldDescriptor* descriptor,
// ===================================================================
-StringFieldGenerator::
-StringFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+StringFieldGenerator::StringFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetStringVariables(descriptor, &variables_, options);
}
@@ -140,19 +139,19 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "const ::std::string& $name$() const$deprecation$;\n"
- "void set_$name$(const ::std::string& value)$deprecation$;\n"
- "void set_$name$(const char* value)$deprecation$;\n"
- "void set_$name$(const $pointer_type$* value, size_t size)"
- "$deprecation$;\n"
- "::std::string* mutable_$name$()$deprecation$;\n"
- "::std::string* $release_name$()$deprecation$;\n"
- "void set_allocated_$name$(::std::string* $name$)$deprecation$;\n");
+ "$deprecated_attr$const ::std::string& $name$() const;\n"
+ "$deprecated_attr$void set_$name$(const ::std::string& value);\n"
+ "$deprecated_attr$void set_$name$(const char* value);\n"
+ "$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)"
+ ";\n"
+ "$deprecated_attr$::std::string* mutable_$name$();\n"
+ "$deprecated_attr$::std::string* $release_name$();\n"
+ "$deprecated_attr$void set_allocated_$name$(::std::string* $name$);\n");
if (SupportsArenas(descriptor_)) {
printer->Print(variables_,
- "::std::string* unsafe_arena_release_$name$()$deprecation$;\n"
- "void unsafe_arena_set_allocated_$name$(\n"
- " ::std::string* $name$)$deprecation$;\n");
+ "$deprecated_attr$::std::string* unsafe_arena_release_$name$();\n"
+ "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n"
+ " ::std::string* $name$);\n");
}
@@ -199,10 +198,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n"
"}\n"
"$inline$ ::std::string* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $clear_hasbit$\n"
" return $name$_.Release($default_variable$, GetArenaNoVirtual());\n"
"}\n"
"$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
" $clear_hasbit$\n"
" return $name$_.UnsafeArenaRelease($default_variable$,\n"
@@ -228,7 +229,8 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" }\n"
" $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
" $name$, GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
+ "$full_name$)\n"
"}\n");
} else {
// No-arena case.
@@ -261,6 +263,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" return $name$_.MutableNoArena($default_variable$);\n"
"}\n"
"$inline$ ::std::string* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" $clear_hasbit$\n"
" return $name$_.ReleaseNoArena($default_variable$);\n"
"}\n"
@@ -369,7 +372,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, true, variables_,
+ descriptor_, options_, true, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
}
}
@@ -378,7 +381,7 @@ void StringFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, false, variables_,
+ descriptor_, options_, false, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
}
printer->Print(variables_,
@@ -390,7 +393,7 @@ void StringFieldGenerator::
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, false, variables_,
+ descriptor_, options_, false, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
}
printer->Print(variables_,
@@ -477,6 +480,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_mutable:$full_name$)\n"
"}\n"
"$inline$ ::std::string* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" return $oneof_prefix$$name$_.Release($default_variable$,\n"
@@ -486,6 +490,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" }\n"
"}\n"
"$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
" if (has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
@@ -519,7 +524,8 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, "
"$name$, GetArenaNoVirtual());\n"
" }\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
+ "$full_name$)\n"
"}\n");
} else {
// No-arena case.
@@ -572,6 +578,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n"
"}\n"
"$inline$ ::std::string* $classname$::$release_name$() {\n"
+ " // @@protoc_insertion_point(field_release:$full_name$)\n"
" if (has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n"
@@ -658,7 +665,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, true, variables_,
+ descriptor_, options_, true, variables_,
"this->$name$().data(), this->$name$().length(),\n", printer);
}
}
@@ -666,10 +673,9 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
// ===================================================================
-RepeatedStringFieldGenerator::
-RepeatedStringFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options)
- : descriptor_(descriptor) {
+RepeatedStringFieldGenerator::RepeatedStringFieldGenerator(
+ const FieldDescriptor* descriptor, const Options& options)
+ : FieldGenerator(options), descriptor_(descriptor) {
SetStringVariables(descriptor, &variables_, options);
}
@@ -696,24 +702,24 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "const ::std::string& $name$(int index) const$deprecation$;\n"
- "::std::string* mutable_$name$(int index)$deprecation$;\n"
- "void set_$name$(int index, const ::std::string& value)$deprecation$;\n"
- "void set_$name$(int index, const char* value)$deprecation$;\n"
+ "$deprecated_attr$const ::std::string& $name$(int index) const;\n"
+ "$deprecated_attr$::std::string* mutable_$name$(int index);\n"
+ "$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n"
+ "$deprecated_attr$void set_$name$(int index, const char* value);\n"
""
- "void set_$name$(int index, const $pointer_type$* value, size_t size)"
- "$deprecation$;\n"
- "::std::string* add_$name$()$deprecation$;\n"
- "void add_$name$(const ::std::string& value)$deprecation$;\n"
- "void add_$name$(const char* value)$deprecation$;\n"
- "void add_$name$(const $pointer_type$* value, size_t size)"
- "$deprecation$;\n");
+ "$deprecated_attr$void set_$name$("
+ "int index, const $pointer_type$* value, size_t size);\n"
+ "$deprecated_attr$::std::string* add_$name$();\n"
+ "$deprecated_attr$void add_$name$(const ::std::string& value);\n"
+ "$deprecated_attr$void add_$name$(const char* value);\n"
+ "$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)"
+ ";\n");
printer->Print(variables_,
- "const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() const"
- "$deprecation$;\n"
- "::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()"
- "$deprecation$;\n");
+ "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
+ "const;\n"
+ "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()"
+ ";\n");
if (unknown_ctype) {
printer->Outdent();
@@ -752,6 +758,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
"}\n"
"$inline$ ::std::string* $classname$::add_$name$() {\n"
+ " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n"
" return $name$_.Add();\n"
"}\n"
"$inline$ void $classname$::add_$name$(const ::std::string& value) {\n"
@@ -807,7 +814,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
" input, this->add_$name$()));\n");
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, true, variables_,
+ descriptor_, options_, true, variables_,
"this->$name$(this->$name$_size() - 1).data(),\n"
"this->$name$(this->$name$_size() - 1).length(),\n",
printer);
@@ -821,7 +828,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, false, variables_,
+ descriptor_, options_, false, variables_,
"this->$name$(i).data(), this->$name$(i).length(),\n", printer);
}
printer->Outdent();
@@ -838,7 +845,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
- descriptor_, false, variables_,
+ descriptor_, options_, false, variables_,
"this->$name$(i).data(), this->$name$(i).length(),\n", printer);
}
printer->Outdent();
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.h b/src/google/protobuf/compiler/cpp/cpp_string_field.h
index 616e2067..cb4e8772 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.h
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.h
@@ -46,8 +46,8 @@ namespace cpp {
class StringFieldGenerator : public FieldGenerator {
public:
- explicit StringFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ StringFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~StringFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -79,8 +79,8 @@ class StringFieldGenerator : public FieldGenerator {
class StringOneofFieldGenerator : public StringFieldGenerator {
public:
- explicit StringOneofFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ StringOneofFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~StringOneofFieldGenerator();
// implements FieldGenerator ---------------------------------------
@@ -99,8 +99,8 @@ class StringOneofFieldGenerator : public StringFieldGenerator {
class RepeatedStringFieldGenerator : public FieldGenerator {
public:
- explicit RepeatedStringFieldGenerator(const FieldDescriptor* descriptor,
- const Options& options);
+ RepeatedStringFieldGenerator(const FieldDescriptor* descriptor,
+ const Options& options);
~RepeatedStringFieldGenerator();
// implements FieldGenerator ---------------------------------------
diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
index 148da883..5d82946d 100644
--- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
@@ -1252,7 +1252,7 @@ class GeneratedServiceTest : public testing::Test {
foo_(descriptor_->FindMethodByName("Foo")),
bar_(descriptor_->FindMethodByName("Bar")),
stub_(&mock_channel_),
- done_(google::protobuf::internal::NewPermanentCallback(&DoNothing)) {}
+ done_(::google::protobuf::internal::NewPermanentCallback(&DoNothing)) {}
virtual void SetUp() {
ASSERT_TRUE(foo_ != NULL);
diff --git a/src/google/protobuf/compiler/cpp/metadata_test.cc b/src/google/protobuf/compiler/cpp/metadata_test.cc
index 61dc283a..edd30780 100644
--- a/src/google/protobuf/compiler/cpp/metadata_test.cc
+++ b/src/google/protobuf/compiler/cpp/metadata_test.cc
@@ -41,9 +41,10 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
-#include <google/protobuf/testing/file.h>
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/importer_unittest.cc b/src/google/protobuf/compiler/importer_unittest.cc
index be19aa2e..1b6e9700 100644
--- a/src/google/protobuf/compiler/importer_unittest.cc
+++ b/src/google/protobuf/compiler/importer_unittest.cc
@@ -32,25 +32,26 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
+#include <google/protobuf/compiler/importer.h>
+
#include <google/protobuf/stubs/hash.h>
#include <memory>
#ifndef _SHARED_PTR_H
#include <google/protobuf/stubs/shared_ptr.h>
#endif
-#include <google/protobuf/compiler/importer.h>
-#include <google/protobuf/descriptor.h>
-#include <google/protobuf/testing/file.h>
-#include <google/protobuf/io/zero_copy_stream_impl.h>
-
-#include <google/protobuf/stubs/map_util.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
+#include <google/protobuf/stubs/map_util.h>
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/java/java_doc_comment.cc b/src/google/protobuf/compiler/java/java_doc_comment.cc
index 663f0c97..0b5caba4 100644
--- a/src/google/protobuf/compiler/java/java_doc_comment.cc
+++ b/src/google/protobuf/compiler/java/java_doc_comment.cc
@@ -120,9 +120,7 @@ static void WriteDocCommentBodyForLocation(
lines.pop_back();
}
- printer->Print(
- " *\n"
- " * <pre>\n");
+ 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
@@ -133,7 +131,9 @@ static void WriteDocCommentBodyForLocation(
printer->Print(" *$line$\n", "line", lines[i]);
}
}
- printer->Print(" * </pre>\n");
+ printer->Print(
+ " * </pre>\n"
+ " *\n");
}
}
@@ -163,12 +163,12 @@ static string FirstLineOf(const string& value) {
}
void WriteMessageDocComment(io::Printer* printer, const Descriptor* message) {
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, message);
printer->Print(
- "/**\n"
- " * Protobuf type {@code $fullname$}\n",
+ " * Protobuf type {@code $fullname$}\n"
+ " */\n",
"fullname", EscapeJavadoc(message->full_name()));
- WriteDocCommentBody(printer, message);
- printer->Print(" */\n");
}
void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
@@ -176,55 +176,55 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
// etc., but in practice everyone already knows the difference between these
// so it's redundant information.
- // We use the field declaration as the first line of the comment, e.g.:
+ // 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;
- // This communicates a lot of information about the field in a small space.
// If the field is a group, the debug string might end with {.
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, field);
printer->Print(
- "/**\n"
" * <code>$def$</code>\n",
"def", EscapeJavadoc(FirstLineOf(field->DebugString())));
- WriteDocCommentBody(printer, field);
printer->Print(" */\n");
}
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) {
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, enum_);
printer->Print(
- "/**\n"
- " * Protobuf enum {@code $fullname$}\n",
+ " * Protobuf enum {@code $fullname$}\n"
+ " */\n",
"fullname", EscapeJavadoc(enum_->full_name()));
- WriteDocCommentBody(printer, enum_);
- printer->Print(" */\n");
}
void WriteEnumValueDocComment(io::Printer* printer,
const EnumValueDescriptor* value) {
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, value);
printer->Print(
- "/**\n"
- " * <code>$def$</code>\n",
+ " * <code>$def$</code>\n"
+ " */\n",
"def", EscapeJavadoc(FirstLineOf(value->DebugString())));
- WriteDocCommentBody(printer, value);
- printer->Print(" */\n");
}
void WriteServiceDocComment(io::Printer* printer,
const ServiceDescriptor* service) {
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, service);
printer->Print(
- "/**\n"
- " * Protobuf service {@code $fullname$}\n",
+ " * Protobuf service {@code $fullname$}\n"
+ " */\n",
"fullname", EscapeJavadoc(service->full_name()));
- WriteDocCommentBody(printer, service);
- printer->Print(" */\n");
}
void WriteMethodDocComment(io::Printer* printer,
const MethodDescriptor* method) {
+ printer->Print("/**\n");
+ WriteDocCommentBody(printer, method);
printer->Print(
- "/**\n"
- " * <code>$def$</code>\n",
+ " * <code>$def$</code>\n"
+ " */\n",
"def", EscapeJavadoc(FirstLineOf(method->DebugString())));
- WriteDocCommentBody(printer, method);
- printer->Print(" */\n");
}
} // namespace java
diff --git a/src/google/protobuf/compiler/java/java_enum.cc b/src/google/protobuf/compiler/java/java_enum.cc
index 9eea873a..947b80e4 100644
--- a/src/google/protobuf/compiler/java/java_enum.cc
+++ b/src/google/protobuf/compiler/java/java_enum.cc
@@ -92,6 +92,16 @@ void EnumGenerator::Generate(io::Printer* printer) {
"classname", descriptor_->name());
printer->Indent();
+ bool ordinal_is_index = true;
+ string index_text = "ordinal()";
+ for (int i = 0; i < canonical_values_.size(); i++) {
+ if (canonical_values_[i]->index() != i) {
+ ordinal_is_index = false;
+ index_text = "index";
+ break;
+ }
+ }
+
for (int i = 0; i < canonical_values_.size(); i++) {
map<string, string> vars;
vars["name"] = canonical_values_[i]->name();
@@ -101,12 +111,21 @@ void EnumGenerator::Generate(io::Printer* printer) {
if (canonical_values_[i]->options().deprecated()) {
printer->Print("@java.lang.Deprecated\n");
}
- printer->Print(vars,
- "$name$($index$, $number$),\n");
+ if (ordinal_is_index) {
+ printer->Print(vars,
+ "$name$($number$),\n");
+ } else {
+ printer->Print(vars,
+ "$name$($index$, $number$),\n");
+ }
}
if (SupportUnknownEnumValue(descriptor_->file())) {
- printer->Print("UNRECOGNIZED(-1, -1),\n");
+ if (ordinal_is_index) {
+ printer->Print("UNRECOGNIZED(-1),\n");
+ } else {
+ printer->Print("UNRECOGNIZED(-1, -1),\n");
+ }
}
printer->Print(
@@ -141,11 +160,19 @@ void EnumGenerator::Generate(io::Printer* printer) {
"\n"
"public final int getNumber() {\n");
if (SupportUnknownEnumValue(descriptor_->file())) {
- printer->Print(
- " if (index == -1) {\n"
- " throw new java.lang.IllegalArgumentException(\n"
- " \"Can't get the number of an unknown enum value.\");\n"
- " }\n");
+ if (ordinal_is_index) {
+ printer->Print(
+ " if (this == UNRECOGNIZED) {\n"
+ " throw new java.lang.IllegalArgumentException(\n"
+ " \"Can't get the number of an unknown enum value.\");\n"
+ " }\n");
+ } else {
+ printer->Print(
+ " if (index == -1) {\n"
+ " throw new java.lang.IllegalArgumentException(\n"
+ " \"Can't get the number of an unknown enum value.\");\n"
+ " }\n");
+ }
}
printer->Print(
" return value;\n"
@@ -200,14 +227,15 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
"public final com.google.protobuf.Descriptors.EnumValueDescriptor\n"
" getValueDescriptor() {\n"
- " return getDescriptor().getValues().get(index);\n"
+ " return getDescriptor().getValues().get($index_text$);\n"
"}\n"
"public final com.google.protobuf.Descriptors.EnumDescriptor\n"
" getDescriptorForType() {\n"
" return getDescriptor();\n"
"}\n"
"public static final com.google.protobuf.Descriptors.EnumDescriptor\n"
- " getDescriptor() {\n");
+ " getDescriptor() {\n",
+ "index_text", index_text);
// TODO(kenton): Cache statically? Note that we can't access descriptors
// at module init time because it wouldn't work with descriptor.proto, but
@@ -313,16 +341,27 @@ void EnumGenerator::Generate(io::Printer* printer) {
"}\n"
"\n");
- printer->Print("private final int index;\n");
+ if (!ordinal_is_index) {
+ printer->Print("private final int index;\n");
+ }
}
// -----------------------------------------------------------------
printer->Print(
- "private final int value;\n\n"
- "private $classname$(int index, int value) {\n",
- "classname", descriptor_->name());
- if (HasDescriptorMethods(descriptor_, context_->EnforceLite())) {
+ "private final int value;\n\n");
+
+ if (ordinal_is_index) {
+ printer->Print(
+ "private $classname$(int value) {\n",
+ "classname", descriptor_->name());
+ } else {
+ printer->Print(
+ "private $classname$(int index, int value) {\n",
+ "classname", descriptor_->name());
+ }
+ if (HasDescriptorMethods(descriptor_, context_->EnforceLite()) &&
+ !ordinal_is_index) {
printer->Print(" this.index = index;\n");
}
printer->Print(
diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc
index 5b98637b..908d6db4 100644
--- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc
@@ -262,17 +262,15 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void ImmutableEnumFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
- "if (other.has$capitalized_name$()) {\n"
- " set$capitalized_name$(other.get$capitalized_name$());\n"
- "}\n");
+ "$name$_ = visitor.visitInt(has$capitalized_name$(), $name$_,\n"
+ " other.has$capitalized_name$(), other.$name$_);\n");
} else if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
- "if (other.$name$_ != $default_number$) {\n"
- " set$capitalized_name$Value(other.get$capitalized_name$Value());\n"
- "}\n");
+ "$name$_ = visitor.visitInt($name$_ != $default_number$, $name$_,"
+ " other.$name$_ != $default_number$, other.$name$_);\n");
} else {
GOOGLE_LOG(FATAL) << "Can't reach here.";
}
@@ -466,14 +464,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
}
void ImmutableEnumOneofFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- if (SupportUnknownEnumValue(descriptor_->file())) {
- printer->Print(variables_,
- "set$capitalized_name$Value(other.get$capitalized_name$Value());\n");
- } else {
- printer->Print(variables_,
- "set$capitalized_name$(other.get$capitalized_name$());\n");
- }
+GenerateVisitCode(io::Printer* printer) const {
+ printer->Print(variables_,
+ "$oneof_name$_ = visitor.visitOneofInt(\n"
+ " $has_oneof_case_message$, $oneof_name$_, other.$oneof_name$_);\n");
}
void ImmutableEnumOneofFieldLiteGenerator::
@@ -645,7 +639,8 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
" if (!$is_mutable$) {\n"
- " $name$_ = newIntList($name$_);\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
" }\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
@@ -805,21 +800,9 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void RepeatedImmutableEnumFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- // The code below does two optimizations:
- // 1. If the other list is empty, there's nothing to do. This ensures we
- // don't allocate a new array if we already have an immutable one.
- // 2. If the other list is non-empty and our current list is empty, we can
- // reuse the other list which is guaranteed to be immutable.
- printer->Print(variables_,
- "if (!other.$name$_.isEmpty()) {\n"
- " if ($name$_.isEmpty()) {\n"
- " $name$_ = other.$name$_;\n"
- " } else {\n"
- " ensure$capitalized_name$IsMutable();\n"
- " $name$_.addAll(other.$name$_);\n"
- " }\n"
- "}\n");
+GenerateVisitCode(io::Printer* printer) const {
+ printer->Print(variables_,
+ "$name$_= visitor.visitIntList($name$_, other.$name$_);\n");
}
void RepeatedImmutableEnumFieldLiteGenerator::
@@ -831,27 +814,23 @@ GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const {
void RepeatedImmutableEnumFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
// Read and store the enum
+ printer->Print(variables_,
+ "if (!$is_mutable$) {\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
+ "}\n");
+
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(variables_,
- "int rawValue = input.readEnum();\n"
- "if (!$is_mutable$) {\n"
- " $name$_ = newIntList();\n"
- "}\n"
- "$name$_.addInt(rawValue);\n");
+ "$name$_.addInt(input.readEnum());\n");
} else {
printer->Print(variables_,
"int rawValue = input.readEnum();\n"
"$type$ value = $type$.forNumber(rawValue);\n"
- "if (value == null) {\n");
- if (PreserveUnknownFields(descriptor_->containing_type())) {
- printer->Print(variables_,
- " super.mergeVarintField($number$, rawValue);\n");
- }
- printer->Print(variables_,
+ "if (value == null) {\n"
+ // We store the unknown value in unknown fields.
+ " super.mergeVarintField($number$, rawValue);\n"
"} else {\n"
- " if (!$is_mutable$) {\n"
- " $name$_ = newIntList();\n"
- " }\n"
" $name$_.addInt(rawValue);\n"
"}\n");
}
@@ -859,7 +838,11 @@ GenerateParsingCode(io::Printer* printer) const {
void RepeatedImmutableEnumFieldLiteGenerator::
GenerateParsingCodeFromPacked(io::Printer* printer) const {
- // Wrap GenerateParsingCode's contents with a while loop.
+ printer->Print(variables_,
+ "if (!$is_mutable$) {\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
+ "}\n");
printer->Print(variables_,
"int length = input.readRawVarint32();\n"
@@ -867,7 +850,21 @@ GenerateParsingCodeFromPacked(io::Printer* printer) const {
"while(input.getBytesUntilLimit() > 0) {\n");
printer->Indent();
- GenerateParsingCode(printer);
+ // Read and store the enum
+ if (SupportUnknownEnumValue(descriptor_->file())) {
+ printer->Print(variables_,
+ "$name$_.addInt(input.readEnum());\n");
+ } else {
+ printer->Print(variables_,
+ "int rawValue = input.readEnum();\n"
+ "$type$ value = $type$.forNumber(rawValue);\n"
+ "if (value == null) {\n"
+ // We store the unknown value in unknown fields.
+ " super.mergeVarintField($number$, rawValue);\n"
+ "} else {\n"
+ " $name$_.addInt(rawValue);\n"
+ "}\n");
+ }
printer->Outdent();
printer->Print(variables_,
diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.h b/src/google/protobuf/compiler/java/java_enum_field_lite.h
index 2c41c3e4..9201b8d6 100644
--- a/src/google/protobuf/compiler/java/java_enum_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_enum_field_lite.h
@@ -67,7 +67,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
@@ -101,7 +101,7 @@ class ImmutableEnumOneofFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
@@ -127,7 +127,7 @@ class RepeatedImmutableEnumFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingCodeFromPacked(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/java/java_field.h b/src/google/protobuf/compiler/java/java_field.h
index 0e24da24..4dd4f57f 100644
--- a/src/google/protobuf/compiler/java/java_field.h
+++ b/src/google/protobuf/compiler/java/java_field.h
@@ -105,7 +105,7 @@ class ImmutableFieldLiteGenerator {
virtual void GenerateMembers(io::Printer* printer) const = 0;
virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
virtual void GenerateInitializationCode(io::Printer* printer) const = 0;
- virtual void GenerateMergingCode(io::Printer* printer) const = 0;
+ virtual void GenerateVisitCode(io::Printer* printer) const = 0;
virtual void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer)
const = 0;
virtual void GenerateParsingCode(io::Printer* printer) const = 0;
diff --git a/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc b/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
index a648f1c2..62f39302 100644
--- a/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
@@ -182,12 +182,11 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void ImmutableLazyMessageFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "if (other.has$capitalized_name$()) {\n"
- " $name$_.merge(other.$name$_);\n"
- " $set_has_field_bit_message$;\n"
- "}\n");
+ "$name$_ = visitor.visitLazyMessage(\n"
+ " has$capitalized_name$(), $name$_,\n"
+ " other.has$capitalized_name$(), other.$name$_);\n");
}
void ImmutableLazyMessageFieldLiteGenerator::
@@ -362,14 +361,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
}
void ImmutableLazyMessageOneofFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "if (!($has_oneof_case_message$)) {\n"
- " $oneof_name$_ = new $lazy_type$();\n"
- "}\n"
- "(($lazy_type$) $oneof_name$_).merge(\n"
- " ($lazy_type$) other.$oneof_name$_);\n"
- "$set_oneof_case_message$;\n");
+ "$oneof_name$_ = visitor.visitOneofLazyMessage(\n"
+ " $has_oneof_case_message$,\n"
+ " ($lazy_type$) $oneof_name$_,\n"
+ " ($lazy_type$) other.$oneof_name$_);\n");
}
void ImmutableLazyMessageOneofFieldLiteGenerator::
@@ -463,7 +460,8 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
" if (!$is_mutable$) {\n"
- " $name$_ = newProtobufList($name$_);\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
" }\n"
"}\n"
"\n");
@@ -678,7 +676,8 @@ void RepeatedImmutableLazyMessageFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"if (!$is_mutable$) {\n"
- " $name$_ = newProtobufList();\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
"}\n"
"$name$_.add(new com.google.protobuf.LazyFieldLite(\n"
" extensionRegistry, input.readBytes()));\n");
diff --git a/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h b/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
index e85ec0f3..47ebeb49 100644
--- a/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
@@ -63,7 +63,7 @@ class ImmutableLazyMessageFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
@@ -82,7 +82,7 @@ class ImmutableLazyMessageOneofFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc
index 17c3646f..2a551ca4 100644
--- a/src/google/protobuf/compiler/java/java_map_field.cc
+++ b/src/google/protobuf/compiler/java/java_map_field.cc
@@ -215,7 +215,7 @@ GenerateMembers(io::Printer* printer) const {
" if ($name$_ == null) {\n"
" return com.google.protobuf.MapField$lite$.emptyMapField(\n"
" $map_field_parameter$);\n"
- " }\n"
+ " }\n"
" return $name$_;\n"
"}\n");
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
@@ -270,7 +270,7 @@ GenerateBuilderMembers(io::Printer* printer) const {
" if ($name$_ == null) {\n"
" return com.google.protobuf.MapField$lite$.emptyMapField(\n"
" $map_field_parameter$);\n"
- " }\n"
+ " }\n"
" return $name$_;\n"
"}\n"
"private com.google.protobuf.MapField$lite$<$type_parameters$>\n"
diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc
index 6bdebb0d..b80d4139 100644
--- a/src/google/protobuf/compiler/java/java_map_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc
@@ -374,10 +374,10 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void ImmutableMapFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(
variables_,
- "internalGetMutable$capitalized_name$().mergeFrom(\n"
+ "$name$_ = visitor.visitMap(internalGetMutable$capitalized_name$(),\n"
" other.internalGet$capitalized_name$());\n");
}
diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.h b/src/google/protobuf/compiler/java/java_map_field_lite.h
index a09cd536..555b5c5b 100644
--- a/src/google/protobuf/compiler/java/java_map_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_map_field_lite.h
@@ -52,7 +52,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator {
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc
index dfd8ad08..4c474a48 100644
--- a/src/google/protobuf/compiler/java/java_message.cc
+++ b/src/google/protobuf/compiler/java/java_message.cc
@@ -89,7 +89,6 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor)
MessageGenerator::~MessageGenerator() {}
// ===================================================================
-// TODO(api): Move this class to a separate immutable_message.cc file.
ImmutableMessageGenerator::ImmutableMessageGenerator(
const Descriptor* descriptor, Context* context)
: MessageGenerator(descriptor), context_(context),
@@ -1226,7 +1225,8 @@ GenerateParsingConstructor(io::Printer* printer) {
"default: {\n"
" if (!input.skipField(tag)) {\n"
" done = true;\n" // it's an endgroup tag
- " }\n"
+ " }\n");
+ printer->Print(
" break;\n"
"}\n");
}
diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc
index 049679df..14281816 100644
--- a/src/google/protobuf/compiler/java/java_message_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc
@@ -286,11 +286,9 @@ void ImmutableMessageFieldLiteGenerator::
GenerateInitializationCode(io::Printer* printer) const {}
void ImmutableMessageFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "if (other.has$capitalized_name$()) {\n"
- " merge$capitalized_name$(other.get$capitalized_name$());\n"
- "}\n");
+ "$name$_ = visitor.visitMessage($name$_, other.$name$_);\n");
}
void ImmutableMessageFieldLiteGenerator::
@@ -300,11 +298,18 @@ GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const {
void ImmutableMessageFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
- printer->Print(variables_,
- "$type$.Builder subBuilder = null;\n"
- "if ($is_field_present_message$) {\n"
- " subBuilder = $name$_.toBuilder();\n"
- "}\n");
+ // TODO(dweis): Update this code to avoid the builder allocation and instead
+ // only allocate a submessage that isn't made immutable. Rely on the top
+ // message calling makeImmutable once done to actually traverse the tree and
+ // finalize state. This will avoid:
+ // - transitive builder allocations
+ // - the extra transitive iteration for streamed fields
+ // - reallocations for copying repeated fields
+ printer->Print(variables_,
+ "$type$.Builder subBuilder = null;\n"
+ "if ($is_field_present_message$) {\n"
+ " subBuilder = $name$_.toBuilder();\n"
+ "}\n");
if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) {
printer->Print(variables_,
@@ -504,9 +509,12 @@ GenerateBuilderMembers(io::Printer* printer) const {
}
void ImmutableMessageOneofFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "merge$capitalized_name$(other.get$capitalized_name$());\n");
+ "$oneof_name$_ = visitor.visitOneofMessage(\n"
+ " $has_oneof_case_message$,\n"
+ " $oneof_name$_,\n"
+ " other.$oneof_name$_);\n");
}
void ImmutableMessageOneofFieldLiteGenerator::
@@ -633,7 +641,8 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
" if (!$is_mutable$) {\n"
- " $name$_ = newProtobufList($name$_);\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
" }\n"
"}\n"
"\n");
@@ -851,21 +860,9 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void RepeatedImmutableMessageFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- // The code below does two optimizations (non-nested builder case):
- // 1. If the other list is empty, there's nothing to do. This ensures we
- // don't allocate a new array if we already have an immutable one.
- // 2. If the other list is non-empty and our current list is empty, we can
- // reuse the other list which is guaranteed to be immutable.
- printer->Print(variables_,
- "if (!other.$name$_.isEmpty()) {\n"
- " if ($name$_.isEmpty()) {\n"
- " $name$_ = other.$name$_;\n"
- " } else {\n"
- " ensure$capitalized_name$IsMutable();\n"
- " $name$_.addAll(other.$name$_);\n"
- " }\n"
- "}\n");
+GenerateVisitCode(io::Printer* printer) const {
+ printer->Print(variables_,
+ "$name$_= visitor.visitList($name$_, other.$name$_);\n");
}
void RepeatedImmutableMessageFieldLiteGenerator::
@@ -878,7 +875,8 @@ void RepeatedImmutableMessageFieldLiteGenerator::
GenerateParsingCode(io::Printer* printer) const {
printer->Print(variables_,
"if (!$is_mutable$) {\n"
- " $name$_ = newProtobufList();\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
"}\n");
if (GetType(descriptor_) == FieldDescriptor::TYPE_GROUP) {
diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.h b/src/google/protobuf/compiler/java/java_message_field_lite.h
index ae26c06a..61321547 100644
--- a/src/google/protobuf/compiler/java/java_message_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_message_field_lite.h
@@ -67,7 +67,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
@@ -101,7 +101,7 @@ class ImmutableMessageOneofFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
@@ -125,7 +125,7 @@ class RepeatedImmutableMessageFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc
index 14cc908b..d4d2593a 100644
--- a/src/google/protobuf/compiler/java/java_message_lite.cc
+++ b/src/google/protobuf/compiler/java/java_message_lite.cc
@@ -199,7 +199,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
printer->Indent();
- GenerateParsingConstructor(printer);
+ GenerateConstructor(printer);
// Nested types
for (int i = 0; i < descriptor_->enum_type_count(); i++) {
@@ -322,10 +322,6 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
GenerateMessageSerializationMethods(printer);
- if (HasEqualsAndHashCode(descriptor_)) {
- GenerateEqualsAndHashCode(printer);
- }
-
GenerateParseFromMethods(printer);
GenerateBuilder(printer);
@@ -342,16 +338,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
" com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
" Object arg0, Object arg1) {\n"
" switch (method) {\n"
- " case PARSE_PARTIAL_FROM: {\n"
- " return new $classname$("
- " (com.google.protobuf.CodedInputStream) arg0,\n"
- " (com.google.protobuf.ExtensionRegistryLite) arg1);\n"
- " }\n"
- " case NEW_INSTANCE: {\n"
- " return new $classname$(\n"
- " com.google.protobuf.Internal.EMPTY_CODED_INPUT_STREAM,\n"
- " com.google.protobuf.ExtensionRegistryLite\n"
- " .getEmptyRegistry());\n"
+ " case NEW_MUTABLE_INSTANCE: {\n"
+ " return new $classname$();\n"
" }\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
@@ -382,10 +370,18 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
printer->Print(
"}\n"
- "case MERGE_FROM: {\n");
+ "case VISIT: {\n");
printer->Indent();
- GenerateDynamicMethodMergeFrom(printer);
+ GenerateDynamicMethodVisit(printer);
+ printer->Outdent();
+
+ printer->Print(
+ "}\n"
+ "case MERGE_FROM_STREAM: {\n");
+
+ printer->Indent();
+ GenerateDynamicMethodMergeFromStream(printer);
printer->Outdent();
printer->Print(
@@ -433,11 +429,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
printer->Print(
"static {\n"
- " DEFAULT_INSTANCE = new $classname$(\n"
- " com.google.protobuf.Internal\n"
- " .EMPTY_CODED_INPUT_STREAM,\n"
- " com.google.protobuf.ExtensionRegistryLite\n"
- " .getEmptyRegistry());\n"
+ " DEFAULT_INSTANCE = new $classname$();\n"
+ " DEFAULT_INSTANCE.makeImmutable();\n"
"}\n"
"\n",
"classname", descriptor_->name());
@@ -802,11 +795,13 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodIsInitialized(
void ImmutableMessageLiteGenerator::GenerateDynamicMethodMakeImmutable(
io::Printer* printer) {
+
// Output generation code for each field.
for (int i = 0; i < descriptor_->field_count(); i++) {
field_generators_.get(descriptor_->field(i))
.GenerateDynamicMethodMakeImmutableCode(printer);
}
+
printer->Print(
"return null;\n");
}
@@ -821,19 +816,17 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodNewBuilder(
// ===================================================================
-void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
+void ImmutableMessageLiteGenerator::GenerateDynamicMethodVisit(
io::Printer* printer) {
printer->Print(
- // Optimization: If other is the default instance, we know none of its
- // fields are set so we can skip the merge.
- "if (arg0 == $classname$.getDefaultInstance()) return this;\n"
- "$classname$ other = ($classname$) arg0;\n",
+ "Visitor visitor = (Visitor) arg0;\n"
+ "$classname$ other = ($classname$) arg1;\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
for (int i = 0; i < descriptor_->field_count(); i++) {
if (!descriptor_->field(i)->containing_oneof()) {
field_generators_.get(
- descriptor_->field(i)).GenerateMergingCode(printer);
+ descriptor_->field(i)).GenerateVisitCode(printer);
}
}
@@ -852,7 +845,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
"field_name",
ToUpper(field->name()));
printer->Indent();
- field_generators_.get(field).GenerateMergingCode(printer);
+ field_generators_.get(field).GenerateVisitCode(printer);
printer->Print(
"break;\n");
printer->Outdent();
@@ -861,254 +854,66 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFrom(
}
printer->Print(
"case $cap_oneof_name$_NOT_SET: {\n"
+ " visitor.visitOneofNotSet($oneof_name$Case_ != 0);\n"
" break;\n"
"}\n",
"cap_oneof_name",
ToUpper(context_->GetOneofGeneratorInfo(
- descriptor_->oneof_decl(i))->name));
- printer->Outdent();
- printer->Print(
- "}\n");
- }
-
- // if message type has extensions
- if (descriptor_->extension_range_count() > 0) {
- printer->Print(
- "this.mergeExtensionFields(other);\n");
- }
-
- if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- "this.mergeUnknownFields(other.unknownFields);\n");
- }
-
- printer->Print(
- "return this;\n");
-}
-
-// ===================================================================
-
-namespace {
-bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) {
- if (field->is_repeated()) {
- return false;
- }
- if (SupportFieldPresence(field->file())) {
- return true;
- }
- return GetJavaType(field) == JAVATYPE_MESSAGE &&
- field->containing_oneof() == NULL;
-}
-} // namespace
-
-void ImmutableMessageLiteGenerator::
-GenerateEqualsAndHashCode(io::Printer* printer) {
- printer->Print(
- "@java.lang.Override\n"
- "public boolean equals(final java.lang.Object obj) {\n");
- printer->Indent();
- printer->Print(
- "if (obj == this) {\n"
- " return true;\n"
- "}\n"
- "if (!(obj instanceof $classname$)) {\n"
- " return super.equals(obj);\n"
- "}\n"
- "$classname$ other = ($classname$) obj;\n"
- "\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
-
- printer->Print("boolean result = true;\n");
- // Compare non-oneofs.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
- if (field->containing_oneof() == NULL) {
- const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
- bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
- if (check_has_bits) {
- printer->Print(
- "result = result && (has$name$() == other.has$name$());\n"
- "if (has$name$()) {\n",
- "name", info->capitalized_name);
- printer->Indent();
- }
- field_generators_.get(field).GenerateEqualsCode(printer);
- if (check_has_bits) {
- printer->Outdent();
- printer->Print(
- "}\n");
- }
- }
- }
-
- // Compare oneofs.
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- printer->Print(
- "result = result && get$oneof_capitalized_name$Case().equals(\n"
- " other.get$oneof_capitalized_name$Case());\n",
- "oneof_capitalized_name",
- context_->GetOneofGeneratorInfo(
- descriptor_->oneof_decl(i))->capitalized_name);
- printer->Print(
- "if (!result) return false;\n"
- "switch ($oneof_name$Case_) {\n",
+ descriptor_->oneof_decl(i))->name),
"oneof_name",
context_->GetOneofGeneratorInfo(
descriptor_->oneof_decl(i))->name);
- printer->Indent();
- for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
- const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
- printer->Print(
- "case $field_number$:\n",
- "field_number",
- SimpleItoa(field->number()));
- printer->Indent();
- field_generators_.get(field).GenerateEqualsCode(printer);
- printer->Print("break;\n");
- printer->Outdent();
- }
- printer->Print(
- "case 0:\n"
- "default:\n");
printer->Outdent();
- printer->Print("}\n");
- }
-
- if (PreserveUnknownFields(descriptor_)) {
- // Always consider unknown fields for equality. This will sometimes return
- // false for non-canonical ordering when running in LITE_RUNTIME but it's
- // the best we can do.
printer->Print(
- "result = result && unknownFields.equals(other.unknownFields);\n");
+ "}\n");
}
- printer->Print(
- "return result;\n");
- printer->Outdent();
- printer->Print(
- "}\n"
- "\n");
printer->Print(
- "@java.lang.Override\n"
- "public int hashCode() {\n");
- printer->Indent();
- printer->Print(
- "if (memoizedHashCode != 0) {\n");
+ "if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor\n"
+ " .INSTANCE) {\n");
printer->Indent();
- printer->Print(
- "return memoizedHashCode;\n");
- printer->Outdent();
- printer->Print(
- "}\n"
- "int hash = 41;\n");
-
- // Include the hash of the class so that two objects with different types
- // but the same field values will probably have different hashes.
- printer->Print("hash = (19 * hash) + $classname$.class.hashCode();\n",
- "classname", name_resolver_->GetImmutableClassName(descriptor_));
+ for (int i = 0; i < descriptor_->oneof_decl_count(); ++i) {
+ const OneofDescriptor* field = descriptor_->oneof_decl(i);
+ printer->Print(
+ "if (other.$oneof_name$Case_ != 0) {\n"
+ " $oneof_name$Case_ = other.$oneof_name$Case_;\n"
+ "}\n",
+ "oneof_name", context_->GetOneofGeneratorInfo(field)->name);
+ }
- // hashCode non-oneofs.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
- if (field->containing_oneof() == NULL) {
- const FieldGeneratorInfo* info = context_->GetFieldGeneratorInfo(field);
- bool check_has_bits = CheckHasBitsForEqualsAndHashCode(field);
- if (check_has_bits) {
- printer->Print(
- "if (has$name$()) {\n",
- "name", info->capitalized_name);
- printer->Indent();
- }
- field_generators_.get(field).GenerateHashCode(printer);
- if (check_has_bits) {
- printer->Outdent();
- printer->Print("}\n");
- }
+ if (GenerateHasBits(descriptor_)) {
+ // Integers for bit fields.
+ int totalBits = 0;
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ totalBits += field_generators_.get(descriptor_->field(i))
+ .GetNumBitsForMessage();
}
- }
+ int totalInts = (totalBits + 31) / 32;
- // hashCode oneofs.
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- printer->Print(
- "switch ($oneof_name$Case_) {\n",
- "oneof_name",
- context_->GetOneofGeneratorInfo(
- descriptor_->oneof_decl(i))->name);
- printer->Indent();
- for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
- const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
+ for (int i = 0; i < totalInts; i++) {
printer->Print(
- "case $field_number$:\n",
- "field_number",
- SimpleItoa(field->number()));
- printer->Indent();
- field_generators_.get(field).GenerateHashCode(printer);
- printer->Print("break;\n");
- printer->Outdent();
+ "$bit_field_name$ |= other.$bit_field_name$;\n",
+ "bit_field_name", GetBitFieldName(i));
}
- printer->Print(
- "case 0:\n"
- "default:\n");
- printer->Outdent();
- printer->Print("}\n");
}
-
- printer->Print(
- "hash = (29 * hash) + unknownFields.hashCode();\n");
- printer->Print(
- "memoizedHashCode = hash;\n"
- "return hash;\n");
printer->Outdent();
printer->Print(
- "}\n"
- "\n");
-}
+ "}\n");
-// ===================================================================
-void ImmutableMessageLiteGenerator::
-GenerateExtensionRegistrationCode(io::Printer* printer) {
- for (int i = 0; i < descriptor_->extension_count(); i++) {
- ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_)
- .GenerateRegistrationCode(printer);
- }
-
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_)
- .GenerateExtensionRegistrationCode(printer);
- }
+ printer->Print(
+ "return this;\n");
}
// ===================================================================
-void ImmutableMessageLiteGenerator::
-GenerateParsingConstructor(io::Printer* printer) {
- google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
- SortFieldsByNumber(descriptor_));
-
- printer->Print(
- "private $classname$(\n"
- " com.google.protobuf.CodedInputStream input,\n"
- " com.google.protobuf.ExtensionRegistryLite extensionRegistry) {\n",
- "classname", descriptor_->name());
- printer->Indent();
-
- // Initialize all fields to default.
- GenerateInitializers(printer);
-
- // Use builder bits to track mutable repeated fields.
- int totalBuilderBits = 0;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const ImmutableFieldLiteGenerator& field =
- field_generators_.get(descriptor_->field(i));
- totalBuilderBits += field.GetNumBitsForBuilder();
- }
- int totalBuilderInts = (totalBuilderBits + 31) / 32;
- for (int i = 0; i < totalBuilderInts; i++) {
- printer->Print("int mutable_$bit_field_name$ = 0;\n",
- "bit_field_name", GetBitFieldName(i));
- }
+void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
+ io::Printer* printer) {
printer->Print(
+ "com.google.protobuf.CodedInputStream input =\n"
+ " (com.google.protobuf.CodedInputStream) arg0;\n"
+ "com.google.protobuf.ExtensionRegistryLite extensionRegistry =\n"
+ " (com.google.protobuf.ExtensionRegistryLite) arg1;\n"
"try {\n");
printer->Indent();
@@ -1156,6 +961,8 @@ GenerateParsingConstructor(io::Printer* printer) {
"}\n");
}
+ google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
+ SortFieldsByNumber(descriptor_));
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = sorted_fields[i];
uint32 tag = WireFormatLite::MakeTag(field->number(),
@@ -1209,19 +1016,54 @@ GenerateParsingConstructor(io::Printer* printer) {
"} finally {\n");
printer->Indent();
- // Make repeated field list immutable.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = sorted_fields[i];
- field_generators_.get(field).GenerateParsingDoneCode(printer);
+ printer->Outdent();
+ printer->Print(
+ "}\n"); // finally
+}
+
+// ===================================================================
+
+namespace {
+bool CheckHasBitsForEqualsAndHashCode(const FieldDescriptor* field) {
+ if (field->is_repeated()) {
+ return false;
+ }
+ if (SupportFieldPresence(field->file())) {
+ return true;
}
+ return GetJavaType(field) == JAVATYPE_MESSAGE &&
+ field->containing_oneof() == NULL;
+}
+} // namespace
+
+// ===================================================================
+void ImmutableMessageLiteGenerator::
+GenerateExtensionRegistrationCode(io::Printer* printer) {
+ for (int i = 0; i < descriptor_->extension_count(); i++) {
+ ImmutableExtensionLiteGenerator(descriptor_->extension(i), context_)
+ .GenerateRegistrationCode(printer);
+ }
+
+ for (int i = 0; i < descriptor_->nested_type_count(); i++) {
+ ImmutableMessageLiteGenerator(descriptor_->nested_type(i), context_)
+ .GenerateExtensionRegistrationCode(printer);
+ }
+}
+
+// ===================================================================
+void ImmutableMessageLiteGenerator::
+GenerateConstructor(io::Printer* printer) {
printer->Print(
- "doneParsing();\n");
+ "private $classname$() {\n",
+ "classname", descriptor_->name());
+ printer->Indent();
+
+ // Initialize all fields to default.
+ GenerateInitializers(printer);
- printer->Outdent();
printer->Outdent();
printer->Print(
- " }\n" // finally
"}\n");
}
diff --git a/src/google/protobuf/compiler/java/java_message_lite.h b/src/google/protobuf/compiler/java/java_message_lite.h
index c8ee99bd..292c1c56 100644
--- a/src/google/protobuf/compiler/java/java_message_lite.h
+++ b/src/google/protobuf/compiler/java/java_message_lite.h
@@ -70,12 +70,13 @@ class ImmutableMessageLiteGenerator : public MessageGenerator {
void GenerateBuilder(io::Printer* printer);
void GenerateDynamicMethodIsInitialized(io::Printer* printer);
void GenerateDynamicMethodMakeImmutable(io::Printer* printer);
- void GenerateDynamicMethodMergeFrom(io::Printer* printer);
+ void GenerateDynamicMethodVisit(io::Printer* printer);
+ void GenerateDynamicMethodMergeFromStream(io::Printer* printer);
void GenerateDynamicMethodNewBuilder(io::Printer* printer);
void GenerateInitializers(io::Printer* printer);
void GenerateEqualsAndHashCode(io::Printer* printer);
void GenerateParser(io::Printer* printer);
- void GenerateParsingConstructor(io::Printer* printer);
+ void GenerateConstructor(io::Printer* printer);
Context* context_;
ClassNameResolver* name_resolver_;
diff --git a/src/google/protobuf/compiler/java/java_plugin_unittest.cc b/src/google/protobuf/compiler/java/java_plugin_unittest.cc
index fe527623..3e4910c8 100644
--- a/src/google/protobuf/compiler/java/java_plugin_unittest.cc
+++ b/src/google/protobuf/compiler/java/java_plugin_unittest.cc
@@ -44,9 +44,10 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/printer.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
-#include <google/protobuf/testing/file.h>
namespace google {
namespace protobuf {
diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
index d277e4f3..690dad12 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
@@ -86,9 +86,6 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
case JAVATYPE_BOOLEAN:
(*variables)["field_list_type"] =
"com.google.protobuf.Internal." + capitalized_type + "List";
- (*variables)["new_list"] = "new" + capitalized_type + "List";
- (*variables)["new_list_with_capacity"] =
- "new" + capitalized_type + "ListWithCapacity";
(*variables)["empty_list"] = "empty" + capitalized_type + "List()";
(*variables)["make_name_unmodifiable"] =
(*variables)["name"] + "_.makeImmutable()";
@@ -98,19 +95,21 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["name"] + "_.add" + capitalized_type;
(*variables)["repeated_set"] =
(*variables)["name"] + "_.set" + capitalized_type;
+ (*variables)["visit_type"] = capitalized_type;
+ (*variables)["visit_type_list"] = "visit" + capitalized_type + "List";
break;
default:
(*variables)["field_list_type"] =
"com.google.protobuf.Internal.ProtobufList<" +
(*variables)["boxed_type"] + ">";
- (*variables)["new_list"] = "newProtobufList";
- (*variables)["new_list_with_capacity"] = "newProtobufListWithCapacity";
(*variables)["empty_list"] = "emptyProtobufList()";
(*variables)["make_name_unmodifiable"] =
(*variables)["name"] + "_.makeImmutable()";
(*variables)["repeated_get"] = (*variables)["name"] + "_.get";
(*variables)["repeated_add"] = (*variables)["name"] + "_.add";
(*variables)["repeated_set"] = (*variables)["name"] + "_.set";
+ (*variables)["visit_type"] = "ByteString";
+ (*variables)["visit_type_list"] = "visitList";
}
if (IsReferenceType(GetJavaType(descriptor))) {
@@ -297,17 +296,16 @@ GenerateBuilderClearCode(io::Printer* printer) const {
}
void ImmutablePrimitiveFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
printer->Print(variables_,
- "if (other.has$capitalized_name$()) {\n"
- " set$capitalized_name$(other.get$capitalized_name$());\n"
- "}\n");
+ "$name$_ = visitor.visit$visit_type$(\n"
+ " has$capitalized_name$(), $name$_,\n"
+ " other.has$capitalized_name$(), other.$name$_);\n");
} else {
printer->Print(variables_,
- "if (other.get$capitalized_name$() != $default$) {\n"
- " set$capitalized_name$(other.get$capitalized_name$());\n"
- "}\n");
+ "$name$_ = visitor.visit$visit_type$($name$_ != $default$, $name$_,\n"
+ " other.$name$_ != $default$, other.$name$_);\n");
}
}
@@ -539,9 +537,10 @@ GenerateBuildingCode(io::Printer* printer) const {
}
void ImmutablePrimitiveOneofFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "set$capitalized_name$(other.get$capitalized_name$());\n");
+ "$oneof_name$_ = visitor.visitOneof$visit_type$(\n"
+ " $has_oneof_case_message$, $oneof_name$_, other.$oneof_name$_);\n");
}
void ImmutablePrimitiveOneofFieldLiteGenerator::
@@ -641,7 +640,8 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
" if (!$is_mutable$) {\n"
- " $name$_ = $new_list$($name$_);\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
" }\n"
"}\n");
@@ -742,21 +742,9 @@ GenerateBuilderClearCode(io::Printer* printer) const {
}
void RepeatedImmutablePrimitiveFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- // The code below does two optimizations:
- // 1. If the other list is empty, there's nothing to do. This ensures we
- // don't allocate a new array if we already have an immutable one.
- // 2. If the other list is non-empty and our current list is empty, we can
- // reuse the other list which is guaranteed to be immutable.
- printer->Print(variables_,
- "if (!other.$name$_.isEmpty()) {\n"
- " if ($name$_.isEmpty()) {\n"
- " $name$_ = other.$name$_;\n"
- " } else {\n"
- " ensure$capitalized_name$IsMutable();\n"
- " $name$_.addAll(other.$name$_);\n"
- " }\n"
- "}\n");
+GenerateVisitCode(io::Printer* printer) const {
+ printer->Print(variables_,
+ "$name$_= visitor.$visit_type_list$($name$_, other.$name$_);\n");
}
void RepeatedImmutablePrimitiveFieldLiteGenerator::
@@ -777,7 +765,8 @@ GenerateParsingCode(io::Printer* printer) const {
// TODO(dweis): Scan the input buffer to count and ensure capacity.
printer->Print(variables_,
"if (!$is_mutable$) {\n"
- " $name$_ = $new_list$();\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
"}\n"
"$repeated_add$(input.read$capitalized_type$());\n");
}
@@ -794,10 +783,13 @@ GenerateParsingCodeFromPacked(io::Printer* printer) const {
// TODO(dweis): Scan the input buffer to count, then initialize
// appropriately.
printer->Print(variables_,
- " $name$_ = $new_list$();\n");
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n");
} else {
printer->Print(variables_,
- " $name$_ = $new_list_with_capacity$(length/$fixed_size$);\n");
+ " final int currentSize = $name$_.size();\n"
+ " $name$_ = $name$_.mutableCopyWithCapacity(\n"
+ " currentSize + (length/$fixed_size$));\n");
}
// TODO(dweis): Scan the input buffer to count and ensure capacity.
diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/src/google/protobuf/compiler/java/java_primitive_field_lite.h
index ad603c2a..6cfbbb98 100644
--- a/src/google/protobuf/compiler/java/java_primitive_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.h
@@ -69,7 +69,7 @@ class ImmutablePrimitiveFieldLiteGenerator
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
void GenerateBuilderClearCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateBuildingCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
@@ -105,7 +105,7 @@ class ImmutablePrimitiveOneofFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateBuildingCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
@@ -130,7 +130,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
void GenerateBuilderClearCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateBuildingCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc
index 9012ab5e..0b92c021 100644
--- a/src/google/protobuf/compiler/java/java_string_field_lite.cc
+++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc
@@ -299,20 +299,16 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void ImmutableStringFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
+GenerateVisitCode(io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
- // Allow a slight breach of abstraction here in order to avoid forcing
- // all string fields to Strings when copying fields from a Message.
printer->Print(variables_,
- "if (other.has$capitalized_name$()) {\n"
- " $set_has_field_bit_message$\n"
- " $name$_ = other.$name$_;\n"
- "}\n");
+ "$name$_ = visitor.visitString(\n"
+ " has$capitalized_name$(), $name$_,\n"
+ " other.has$capitalized_name$(), other.$name$_);\n");
} else {
printer->Print(variables_,
- "if (!other.get$capitalized_name$().isEmpty()) {\n"
- " $name$_ = other.$name$_;\n"
- "}\n");
+ "$name$_ = visitor.visitString(!$name$_.isEmpty(), $name$_,\n"
+ " !other.$name$_.isEmpty(), other.$name$_);\n");
}
}
@@ -519,12 +515,10 @@ GenerateBuilderMembers(io::Printer* printer) const {
}
void ImmutableStringOneofFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- // Allow a slight breach of abstraction here in order to avoid forcing
- // all string fields to Strings when copying fields from a Message.
+GenerateVisitCode(io::Printer* printer) const {
printer->Print(variables_,
- "$set_oneof_case_message$;\n"
- "$oneof_name$_ = other.$oneof_name$_;\n");
+ "$oneof_name$_ = visitor.visitOneofString(\n"
+ " $has_oneof_case_message$, $oneof_name$_, other.$oneof_name$_);\n");
}
void ImmutableStringOneofFieldLiteGenerator::
@@ -645,8 +639,8 @@ GenerateMembers(io::Printer* printer) const {
printer->Print(variables_,
"private void ensure$capitalized_name$IsMutable() {\n"
" if (!$is_mutable$) {\n"
- " $name$_ = com.google.protobuf.GeneratedMessageLite.newProtobufList(\n"
- " $name$_);\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
" }\n"
"}\n");
@@ -773,21 +767,9 @@ GenerateInitializationCode(io::Printer* printer) const {
}
void RepeatedImmutableStringFieldLiteGenerator::
-GenerateMergingCode(io::Printer* printer) const {
- // The code below does two optimizations:
- // 1. If the other list is empty, there's nothing to do. This ensures we
- // don't allocate a new array if we already have an immutable one.
- // 2. If the other list is non-empty and our current list is empty, we can
- // reuse the other list which is guaranteed to be immutable.
- printer->Print(variables_,
- "if (!other.$name$_.isEmpty()) {\n"
- " if ($name$_.isEmpty()) {\n"
- " $name$_ = other.$name$_;\n"
- " } else {\n"
- " ensure$capitalized_name$IsMutable();\n"
- " $name$_.addAll(other.$name$_);\n"
- " }\n"
- "}\n");
+GenerateVisitCode(io::Printer* printer) const {
+ printer->Print(variables_,
+ "$name$_= visitor.visitList($name$_, other.$name$_);\n");
}
void RepeatedImmutableStringFieldLiteGenerator::
@@ -811,7 +793,8 @@ GenerateParsingCode(io::Printer* printer) const {
}
printer->Print(variables_,
"if (!$is_mutable$) {\n"
- " $name$_ = com.google.protobuf.GeneratedMessageLite.newProtobufList();\n"
+ " $name$_ =\n"
+ " com.google.protobuf.GeneratedMessageLite.mutableCopy($name$_);\n"
"}\n");
printer->Print(variables_,
"$name$_.add(s);\n");
diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.h b/src/google/protobuf/compiler/java/java_string_field_lite.h
index 4d9b4bd7..4148aa4d 100644
--- a/src/google/protobuf/compiler/java/java_string_field_lite.h
+++ b/src/google/protobuf/compiler/java/java_string_field_lite.h
@@ -68,7 +68,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
@@ -103,7 +103,7 @@ class ImmutableStringOneofFieldLiteGenerator
private:
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateSerializationCode(io::Printer* printer) const;
void GenerateSerializedSizeCode(io::Printer* printer) const;
@@ -126,7 +126,7 @@ class RepeatedImmutableStringFieldLiteGenerator
void GenerateMembers(io::Printer* printer) const;
void GenerateBuilderMembers(io::Printer* printer) const;
void GenerateInitializationCode(io::Printer* printer) const;
- void GenerateMergingCode(io::Printer* printer) const;
+ void GenerateVisitCode(io::Printer* printer) const;
void GenerateDynamicMethodMakeImmutableCode(io::Printer* printer) const;
void GenerateParsingCode(io::Printer* printer) const;
void GenerateParsingDoneCode(io::Printer* printer) const;
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 534a5b5b..3de61e80 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -1909,7 +1909,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options,
printer->Print(
" if (includeInstance) {\n"
- " obj.$$jspbMessageInstance = msg\n"
+ " obj.$$jspbMessageInstance = msg;\n"
" }\n"
" return obj;\n"
"};\n"
@@ -3032,8 +3032,7 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files,
const google::protobuf::FileDescriptor* file = files[i];
string filename = options.output_dir + "/" + GetJSFilename(file->name());
- scoped_ptr<io::ZeroCopyOutputStream> output(
- context->Open(filename));
+ google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_CHECK(output.get());
io::Printer printer(output.get(), '$');
diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc
index a2da8eee..e9d50a1d 100644
--- a/src/google/protobuf/compiler/plugin.pb.cc
+++ b/src/google/protobuf/compiler/plugin.pb.cc
@@ -240,6 +240,7 @@ CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena
}
void CodeGeneratorRequest::Clear() {
+// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest)
if (has_parameter()) {
parameter_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -253,7 +254,7 @@ void CodeGeneratorRequest::Clear() {
bool CodeGeneratorRequest::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorRequest)
for (;;) {
@@ -412,6 +413,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
}
int CodeGeneratorRequest::ByteSize() const {
+// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorRequest)
int total_size = 0;
// optional string parameter = 2;
@@ -448,18 +450,22 @@ int CodeGeneratorRequest::ByteSize() const {
}
void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
const CodeGeneratorRequest* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorRequest>(
&from);
if (source == NULL) {
+ // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.CodeGeneratorRequest)
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
+ // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorRequest)
MergeFrom(*source);
}
}
void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
file_to_generate_.MergeFrom(from.file_to_generate_);
proto_file_.MergeFrom(from.proto_file_);
@@ -475,12 +481,14 @@ void CodeGeneratorRequest::MergeFrom(const CodeGeneratorRequest& from) {
}
void CodeGeneratorRequest::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.CodeGeneratorRequest)
if (&from == this) return;
Clear();
MergeFrom(from);
}
void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorRequest)
if (&from == this) return;
Clear();
MergeFrom(from);
@@ -545,6 +553,7 @@ void CodeGeneratorRequest::clear_file_to_generate() {
// @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
::std::string* CodeGeneratorRequest::add_file_to_generate() {
+ // @@protoc_insertion_point(field_add_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
return file_to_generate_.Add();
}
void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) {
@@ -610,6 +619,7 @@ void CodeGeneratorRequest::clear_parameter() {
return parameter_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* CodeGeneratorRequest::release_parameter() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter)
clear_has_parameter();
return parameter_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -728,6 +738,7 @@ CodeGeneratorResponse_File* CodeGeneratorResponse_File::New(::google::protobuf::
}
void CodeGeneratorResponse_File::Clear() {
+// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (_has_bits_[0 / 32] & 7u) {
if (has_name()) {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -747,7 +758,7 @@ void CodeGeneratorResponse_File::Clear() {
bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse.File)
for (;;) {
@@ -912,6 +923,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes(
}
int CodeGeneratorResponse_File::ByteSize() const {
+// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse.File)
int total_size = 0;
if (_has_bits_[0 / 32] & 7u) {
@@ -949,18 +961,22 @@ int CodeGeneratorResponse_File::ByteSize() const {
}
void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
const CodeGeneratorResponse_File* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorResponse_File>(
&from);
if (source == NULL) {
+ // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.CodeGeneratorResponse.File)
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
+ // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorResponse.File)
MergeFrom(*source);
}
}
void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
if (from.has_name()) {
@@ -982,12 +998,14 @@ void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& fro
}
void CodeGeneratorResponse_File::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (&from == this) return;
Clear();
MergeFrom(from);
}
void CodeGeneratorResponse_File::CopyFrom(const CodeGeneratorResponse_File& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (&from == this) return;
Clear();
MergeFrom(from);
@@ -1088,6 +1106,7 @@ CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* are
}
void CodeGeneratorResponse::Clear() {
+// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse)
if (has_error()) {
error_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -1100,7 +1119,7 @@ void CodeGeneratorResponse::Clear() {
bool CodeGeneratorResponse::MergePartialFromCodedStream(
::google::protobuf::io::CodedInputStream* input) {
-#define DO_(EXPRESSION) if (!(EXPRESSION)) goto failure
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse)
for (;;) {
@@ -1219,6 +1238,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes(
}
int CodeGeneratorResponse::ByteSize() const {
+// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.CodeGeneratorResponse)
int total_size = 0;
// optional string error = 1;
@@ -1248,18 +1268,22 @@ int CodeGeneratorResponse::ByteSize() const {
}
void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
const CodeGeneratorResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorResponse>(
&from);
if (source == NULL) {
+ // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.CodeGeneratorResponse)
::google::protobuf::internal::ReflectionOps::Merge(from, this);
} else {
+ // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.CodeGeneratorResponse)
MergeFrom(*source);
}
}
void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.CodeGeneratorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
file_.MergeFrom(from.file_);
if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
@@ -1274,12 +1298,14 @@ void CodeGeneratorResponse::MergeFrom(const CodeGeneratorResponse& from) {
}
void CodeGeneratorResponse::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse)
if (&from == this) return;
Clear();
MergeFrom(from);
}
void CodeGeneratorResponse::CopyFrom(const CodeGeneratorResponse& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.CodeGeneratorResponse)
if (&from == this) return;
Clear();
MergeFrom(from);
@@ -1353,6 +1379,7 @@ void CodeGeneratorResponse_File::clear_name() {
return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* CodeGeneratorResponse_File::release_name() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name)
clear_has_name();
return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -1406,6 +1433,7 @@ void CodeGeneratorResponse_File::clear_insertion_point() {
return insertion_point_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* CodeGeneratorResponse_File::release_insertion_point() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
clear_has_insertion_point();
return insertion_point_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -1459,6 +1487,7 @@ void CodeGeneratorResponse_File::clear_content() {
return content_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* CodeGeneratorResponse_File::release_content() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content)
clear_has_content();
return content_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -1516,6 +1545,7 @@ void CodeGeneratorResponse::clear_error() {
return error_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
::std::string* CodeGeneratorResponse::release_error() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error)
clear_has_error();
return error_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h
index 0a03e979..510202f0 100644
--- a/src/google/protobuf/compiler/plugin.pb.h
+++ b/src/google/protobuf/compiler/plugin.pb.h
@@ -437,6 +437,7 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* va
// @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline ::std::string* CodeGeneratorRequest::add_file_to_generate() {
+ // @@protoc_insertion_point(field_add_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
return file_to_generate_.Add();
}
inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) {
@@ -502,6 +503,7 @@ inline ::std::string* CodeGeneratorRequest::mutable_parameter() {
return parameter_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* CodeGeneratorRequest::release_parameter() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter)
clear_has_parameter();
return parameter_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -589,6 +591,7 @@ inline ::std::string* CodeGeneratorResponse_File::mutable_name() {
return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* CodeGeneratorResponse_File::release_name() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name)
clear_has_name();
return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -642,6 +645,7 @@ inline ::std::string* CodeGeneratorResponse_File::mutable_insertion_point() {
return insertion_point_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* CodeGeneratorResponse_File::release_insertion_point() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
clear_has_insertion_point();
return insertion_point_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -695,6 +699,7 @@ inline ::std::string* CodeGeneratorResponse_File::mutable_content() {
return content_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* CodeGeneratorResponse_File::release_content() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content)
clear_has_content();
return content_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
@@ -752,6 +757,7 @@ inline ::std::string* CodeGeneratorResponse::mutable_error() {
return error_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline ::std::string* CodeGeneratorResponse::release_error() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error)
clear_has_error();
return error_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
diff --git a/src/google/protobuf/compiler/python/python_plugin_unittest.cc b/src/google/protobuf/compiler/python/python_plugin_unittest.cc
index e82bbae7..23f2449c 100644
--- a/src/google/protobuf/compiler/python/python_plugin_unittest.cc
+++ b/src/google/protobuf/compiler/python/python_plugin_unittest.cc
@@ -44,9 +44,10 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/printer.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
-#include <google/protobuf/testing/file.h>
namespace google {
namespace protobuf {