| Index: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
|
| diff --git a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
|
| index 0786176bac44033df9af55ffff0a10ee711fef9e..8d47d4e086999a2105f1aa244f62f9a5e4929b3f 100644
|
| --- a/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
|
| +++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
|
| @@ -1,6 +1,6 @@
|
| // Protocol Buffers - Google's data interchange format
|
| // Copyright 2008 Google Inc. All rights reserved.
|
| -// http://code.google.com/p/protobuf/
|
| +// https://developers.google.com/protocol-buffers/
|
| //
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| @@ -33,14 +33,21 @@
|
| // Sanjay Ghemawat, Jeff Dean, and others.
|
|
|
| #include <google/protobuf/compiler/cpp/cpp_field.h>
|
| +#include <memory>
|
| +#ifndef _SHARED_PTR_H
|
| +#include <google/protobuf/stubs/shared_ptr.h>
|
| +#endif
|
| +
|
| #include <google/protobuf/compiler/cpp/cpp_helpers.h>
|
| #include <google/protobuf/compiler/cpp/cpp_primitive_field.h>
|
| #include <google/protobuf/compiler/cpp/cpp_string_field.h>
|
| #include <google/protobuf/compiler/cpp/cpp_enum_field.h>
|
| +#include <google/protobuf/compiler/cpp/cpp_map_field.h>
|
| #include <google/protobuf/compiler/cpp/cpp_message_field.h>
|
| #include <google/protobuf/descriptor.pb.h>
|
| #include <google/protobuf/wire_format.h>
|
| #include <google/protobuf/io/printer.h>
|
| +#include <google/protobuf/stubs/logging.h>
|
| #include <google/protobuf/stubs/common.h>
|
| #include <google/protobuf/stubs/strutil.h>
|
|
|
| @@ -60,12 +67,41 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
|
| (*variables)["classname"] = ClassName(FieldScope(descriptor), false);
|
| (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type());
|
|
|
| + // non_null_ptr_to_name is usable only if has_$name$ is true. It yields a
|
| + // pointer that will not be NULL. Subclasses of FieldGenerator may set
|
| + // (*variables)["non_null_ptr_to_name"] differently.
|
| + (*variables)["non_null_ptr_to_name"] =
|
| + StrCat("&this->", FieldName(descriptor), "()");
|
| +
|
| (*variables)["tag_size"] = SimpleItoa(
|
| WireFormat::TagSize(descriptor->number(), descriptor->type()));
|
| (*variables)["deprecation"] = descriptor->options().deprecated()
|
| ? " PROTOBUF_DEPRECATED" : "";
|
|
|
| (*variables)["cppget"] = "Get";
|
| +
|
| + if (HasFieldPresence(descriptor->file())) {
|
| + (*variables)["set_hasbit"] =
|
| + "set_has_" + FieldName(descriptor) + "();";
|
| + (*variables)["clear_hasbit"] =
|
| + "clear_has_" + FieldName(descriptor) + "();";
|
| + } else {
|
| + (*variables)["set_hasbit"] = "";
|
| + (*variables)["clear_hasbit"] = "";
|
| + }
|
| +
|
| + // By default, empty string, so that generic code used for both oneofs and
|
| + // singular fields can be written.
|
| + (*variables)["oneof_prefix"] = "";
|
| +}
|
| +
|
| +void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
|
| + map<string, string>* variables) {
|
| + const string prefix = descriptor->containing_oneof()->name() + "_.";
|
| + (*variables)["oneof_prefix"] = prefix;
|
| + (*variables)["oneof_name"] = descriptor->containing_oneof()->name();
|
| + (*variables)["non_null_ptr_to_name"] =
|
| + StrCat(prefix, (*variables)["name"], "_");
|
| }
|
|
|
| FieldGenerator::~FieldGenerator() {}
|
| @@ -84,8 +120,9 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
|
|
|
| FieldGeneratorMap::FieldGeneratorMap(const Descriptor* descriptor,
|
| const Options& options)
|
| - : descriptor_(descriptor),
|
| - field_generators_(new scoped_ptr<FieldGenerator>[descriptor->field_count()]) {
|
| + : descriptor_(descriptor),
|
| + field_generators_(
|
| + new google::protobuf::scoped_ptr<FieldGenerator>[descriptor->field_count()]) {
|
| // Construct all the FieldGenerators.
|
| for (int i = 0; i < descriptor->field_count(); i++) {
|
| field_generators_[i].reset(MakeGenerator(descriptor->field(i), options));
|
| @@ -97,7 +134,11 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field,
|
| if (field->is_repeated()) {
|
| switch (field->cpp_type()) {
|
| case FieldDescriptor::CPPTYPE_MESSAGE:
|
| - return new RepeatedMessageFieldGenerator(field, options);
|
| + if (field->is_map()) {
|
| + return new MapFieldGenerator(field, options);
|
| + } else {
|
| + return new RepeatedMessageFieldGenerator(field, options);
|
| + }
|
| case FieldDescriptor::CPPTYPE_STRING:
|
| switch (field->options().ctype()) {
|
| default: // RepeatedStringFieldGenerator handles unknown ctypes.
|
| @@ -109,6 +150,21 @@ FieldGenerator* FieldGeneratorMap::MakeGenerator(const FieldDescriptor* field,
|
| default:
|
| return new RepeatedPrimitiveFieldGenerator(field, options);
|
| }
|
| + } else if (field->containing_oneof()) {
|
| + switch (field->cpp_type()) {
|
| + case FieldDescriptor::CPPTYPE_MESSAGE:
|
| + return new MessageOneofFieldGenerator(field, options);
|
| + case FieldDescriptor::CPPTYPE_STRING:
|
| + switch (field->options().ctype()) {
|
| + default: // StringOneofFieldGenerator handles unknown ctypes.
|
| + case FieldOptions::STRING:
|
| + return new StringOneofFieldGenerator(field, options);
|
| + }
|
| + case FieldDescriptor::CPPTYPE_ENUM:
|
| + return new EnumOneofFieldGenerator(field, options);
|
| + default:
|
| + return new PrimitiveOneofFieldGenerator(field, options);
|
| + }
|
| } else {
|
| switch (field->cpp_type()) {
|
| case FieldDescriptor::CPPTYPE_MESSAGE:
|
|
|