aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_map_field.cc
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/cpp/cpp_map_field.cc
parentf00300d7f04f1c38a7d70e271f9232b94dd0e326 (diff)
Down integrate from Google internal.
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_map_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_map_field.cc65
1 files changed, 33 insertions, 32 deletions
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();