Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.cc

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 bool IsProto3Field(const FieldDescriptor* field_descriptor) { 42 bool IsProto3Field(const FieldDescriptor* field_descriptor) {
43 const FileDescriptor* file_descriptor = field_descriptor->file(); 43 const FileDescriptor* file_descriptor = field_descriptor->file();
44 return file_descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3; 44 return file_descriptor->syntax() == FileDescriptor::SYNTAX_PROTO3;
45 } 45 }
46 46
47 void SetMessageVariables(const FieldDescriptor* descriptor, 47 void SetMessageVariables(const FieldDescriptor* descriptor,
48 map<string, string>* variables, 48 map<string, string>* variables,
49 const Options& options) { 49 const Options& options) {
50 SetCommonFieldVariables(descriptor, variables, options); 50 SetCommonFieldVariables(descriptor, variables, options);
51 (*variables)["type"] = FieldMessageTypeName(descriptor); 51 (*variables)["type"] = FieldMessageTypeName(descriptor);
52 (*variables)["stream_writer"] = (*variables)["declared_type"] + 52 (*variables)["stream_writer"] =
53 (HasFastArraySerialization(descriptor->message_type()->file()) ? 53 (*variables)["declared_type"] +
54 "MaybeToArray" : 54 (HasFastArraySerialization(descriptor->message_type()->file(), options)
55 ""); 55 ? "MaybeToArray"
56 : "");
56 (*variables)["full_name"] = descriptor->full_name(); 57 (*variables)["full_name"] = descriptor->full_name();
57 58
58 const FieldDescriptor* key = 59 const FieldDescriptor* key =
59 descriptor->message_type()->FindFieldByName("key"); 60 descriptor->message_type()->FindFieldByName("key");
60 const FieldDescriptor* val = 61 const FieldDescriptor* val =
61 descriptor->message_type()->FindFieldByName("value"); 62 descriptor->message_type()->FindFieldByName("value");
62 (*variables)["key_cpp"] = PrimitiveTypeName(key->cpp_type()); 63 (*variables)["key_cpp"] = PrimitiveTypeName(key->cpp_type());
63 switch (val->cpp_type()) { 64 switch (val->cpp_type()) {
64 case FieldDescriptor::CPPTYPE_MESSAGE: 65 case FieldDescriptor::CPPTYPE_MESSAGE:
65 (*variables)["val_cpp"] = FieldMessageTypeName(val); 66 (*variables)["val_cpp"] = FieldMessageTypeName(val);
(...skipping 10 matching lines...) Expand all
76 (*variables)["key_wire_type"] = 77 (*variables)["key_wire_type"] =
77 "::google::protobuf::internal::WireFormatLite::TYPE_" + 78 "::google::protobuf::internal::WireFormatLite::TYPE_" +
78 ToUpper(DeclaredTypeMethodName(key->type())); 79 ToUpper(DeclaredTypeMethodName(key->type()));
79 (*variables)["val_wire_type"] = 80 (*variables)["val_wire_type"] =
80 "::google::protobuf::internal::WireFormatLite::TYPE_" + 81 "::google::protobuf::internal::WireFormatLite::TYPE_" +
81 ToUpper(DeclaredTypeMethodName(val->type())); 82 ToUpper(DeclaredTypeMethodName(val->type()));
82 (*variables)["map_classname"] = ClassName(descriptor->message_type(), false); 83 (*variables)["map_classname"] = ClassName(descriptor->message_type(), false);
83 (*variables)["number"] = SimpleItoa(descriptor->number()); 84 (*variables)["number"] = SimpleItoa(descriptor->number());
84 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); 85 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor));
85 86
86 if (HasDescriptorMethods(descriptor->file())) { 87 if (HasDescriptorMethods(descriptor->file(), options)) {
87 (*variables)["lite"] = ""; 88 (*variables)["lite"] = "";
88 } else { 89 } else {
89 (*variables)["lite"] = "Lite"; 90 (*variables)["lite"] = "Lite";
90 } 91 }
91 92
92 if (!IsProto3Field(descriptor) && 93 if (!IsProto3Field(descriptor) &&
93 val->type() == FieldDescriptor::TYPE_ENUM) { 94 val->type() == FieldDescriptor::TYPE_ENUM) {
94 const EnumValueDescriptor* default_value = val->default_value_enum(); 95 const EnumValueDescriptor* default_value = val->default_value_enum();
95 (*variables)["default_enum_value"] = Int32ToString(default_value->number()); 96 (*variables)["default_enum_value"] = Int32ToString(default_value->number());
96 } else { 97 } else {
97 (*variables)["default_enum_value"] = "0"; 98 (*variables)["default_enum_value"] = "0";
98 } 99 }
99 } 100 }
100 101
101 MapFieldGenerator:: 102 MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
102 MapFieldGenerator(const FieldDescriptor* descriptor, 103 const Options& options)
103 const Options& options) 104 : FieldGenerator(options),
104 : descriptor_(descriptor), 105 descriptor_(descriptor),
105 dependent_field_(options.proto_h && IsFieldDependent(descriptor)) { 106 dependent_field_(options.proto_h && IsFieldDependent(descriptor)) {
106 SetMessageVariables(descriptor, &variables_, options); 107 SetMessageVariables(descriptor, &variables_, options);
107 } 108 }
108 109
109 MapFieldGenerator::~MapFieldGenerator() {} 110 MapFieldGenerator::~MapFieldGenerator() {}
110 111
111 void MapFieldGenerator:: 112 void MapFieldGenerator::
112 GeneratePrivateMembers(io::Printer* printer) const { 113 GeneratePrivateMembers(io::Printer* printer) const {
113 printer->Print(variables_, 114 printer->Print(variables_,
114 "typedef ::google::protobuf::internal::MapEntryLite<\n" 115 "typedef ::google::protobuf::internal::MapEntryLite<\n"
115 " $key_cpp$, $val_cpp$,\n" 116 " $key_cpp$, $val_cpp$,\n"
116 " $key_wire_type$,\n" 117 " $key_wire_type$,\n"
117 " $val_wire_type$,\n" 118 " $val_wire_type$,\n"
118 " $default_enum_value$ >\n" 119 " $default_enum_value$ >\n"
119 " $map_classname$;\n" 120 " $map_classname$;\n"
120 "::google::protobuf::internal::MapField$lite$<\n" 121 "::google::protobuf::internal::MapField$lite$<\n"
121 " $key_cpp$, $val_cpp$,\n" 122 " $key_cpp$, $val_cpp$,\n"
122 " $key_wire_type$,\n" 123 " $key_wire_type$,\n"
123 " $val_wire_type$,\n" 124 " $val_wire_type$,\n"
124 " $default_enum_value$ > $name$_;\n"); 125 " $default_enum_value$ > $name$_;\n");
125 } 126 }
126 127
127 void MapFieldGenerator:: 128 void MapFieldGenerator::
128 GenerateAccessorDeclarations(io::Printer* printer) const { 129 GenerateAccessorDeclarations(io::Printer* printer) const {
129 printer->Print(variables_, 130 printer->Print(variables_,
130 "const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n" 131 "$deprecated_attr$const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n "
131 " $name$() const$deprecation$;\n" 132 " $name$() const;\n"
132 "::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n" 133 "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n"
133 " mutable_$name$()$deprecation$;\n"); 134 " mutable_$name$();\n");
134 } 135 }
135 136
136 void MapFieldGenerator:: 137 void MapFieldGenerator::
137 GenerateInlineAccessorDefinitions(io::Printer* printer, 138 GenerateInlineAccessorDefinitions(io::Printer* printer,
138 bool is_inline) const { 139 bool is_inline) const {
139 map<string, string> variables(variables_); 140 map<string, string> variables(variables_);
140 variables["inline"] = is_inline ? "inline" : ""; 141 variables["inline"] = is_inline ? "inline" : "";
141 printer->Print(variables, 142 printer->Print(variables,
142 "$inline$ const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n" 143 "$inline$ const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n"
143 "$classname$::$name$() const {\n" 144 "$classname$::$name$() const {\n"
(...skipping 19 matching lines...) Expand all
163 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); 164 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n");
164 } 165 }
165 166
166 void MapFieldGenerator:: 167 void MapFieldGenerator::
167 GenerateSwappingCode(io::Printer* printer) const { 168 GenerateSwappingCode(io::Printer* printer) const {
168 printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n"); 169 printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n");
169 } 170 }
170 171
171 void MapFieldGenerator:: 172 void MapFieldGenerator::
172 GenerateConstructorCode(io::Printer* printer) const { 173 GenerateConstructorCode(io::Printer* printer) const {
173 if (HasDescriptorMethods(descriptor_->file())) { 174 if (HasDescriptorMethods(descriptor_->file(), options_)) {
174 printer->Print(variables_, 175 printer->Print(variables_,
175 "$name$_.SetAssignDescriptorCallback(\n" 176 "$name$_.SetAssignDescriptorCallback(\n"
176 " protobuf_AssignDescriptorsOnce);\n" 177 " protobuf_AssignDescriptorsOnce);\n"
177 "$name$_.SetEntryDescriptor(\n" 178 "$name$_.SetEntryDescriptor(\n"
178 " &$type$_descriptor_);\n"); 179 " &$type$_descriptor_);\n");
179 } 180 }
180 } 181 }
181 182
182 void MapFieldGenerator:: 183 void MapFieldGenerator::
183 GenerateMergeFromCodedStream(io::Printer* printer) const { 184 GenerateMergeFromCodedStream(io::Printer* printer) const {
(...skipping 26 matching lines...) Expand all
210 } else { 211 } else {
211 printer->Print(variables_, 212 printer->Print(variables_,
212 "{\n" 213 "{\n"
213 " ::std::string data;\n" 214 " ::std::string data;\n"
214 " DO_(::google::protobuf::internal::WireFormatLite::ReadString(input, & data));\n" 215 " DO_(::google::protobuf::internal::WireFormatLite::ReadString(input, & data));\n"
215 " DO_(entry->ParseFromString(data));\n" 216 " DO_(entry->ParseFromString(data));\n"
216 " if ($val_cpp$_IsValid(*entry->mutable_value())) {\n" 217 " if ($val_cpp$_IsValid(*entry->mutable_value())) {\n"
217 " (*mutable_$name$())[entry->key()] =\n" 218 " (*mutable_$name$())[entry->key()] =\n"
218 " static_cast< $val_cpp$ >(*entry->mutable_value());\n" 219 " static_cast< $val_cpp$ >(*entry->mutable_value());\n"
219 " } else {\n"); 220 " } else {\n");
220 if (HasDescriptorMethods(descriptor_->file())) { 221 if (HasDescriptorMethods(descriptor_->file(), options_)) {
221 printer->Print(variables_, 222 printer->Print(variables_,
222 " mutable_unknown_fields()" 223 " mutable_unknown_fields()"
223 "->AddLengthDelimited($number$, data);\n"); 224 "->AddLengthDelimited($number$, data);\n");
224 } else { 225 } else {
225 printer->Print(variables_, 226 printer->Print(variables_,
226 " unknown_fields_stream.WriteVarint32($tag$);\n" 227 " unknown_fields_stream.WriteVarint32($tag$);\n"
227 " unknown_fields_stream.WriteVarint32(data.size());\n" 228 " unknown_fields_stream.WriteVarint32(data.size());\n"
228 " unknown_fields_stream.WriteString(data);\n"); 229 " unknown_fields_stream.WriteString(data);\n");
229 } 230 }
230 231
231 232
232 printer->Print(variables_, 233 printer->Print(variables_,
233 " }\n" 234 " }\n"
234 "}\n"); 235 "}\n");
235 } 236 }
236 237
237 const FieldDescriptor* key_field = 238 const FieldDescriptor* key_field =
238 descriptor_->message_type()->FindFieldByName("key"); 239 descriptor_->message_type()->FindFieldByName("key");
239 if (key_field->type() == FieldDescriptor::TYPE_STRING) { 240 if (key_field->type() == FieldDescriptor::TYPE_STRING) {
240 GenerateUtf8CheckCodeForString( 241 GenerateUtf8CheckCodeForString(
241 key_field, true, variables_, 242 key_field, options_, true, variables_,
242 "entry->key().data(), entry->key().length(),\n", printer); 243 "entry->key().data(), entry->key().length(),\n", printer);
243 } 244 }
244 if (value_field->type() == FieldDescriptor::TYPE_STRING) { 245 if (value_field->type() == FieldDescriptor::TYPE_STRING) {
245 GenerateUtf8CheckCodeForString( 246 GenerateUtf8CheckCodeForString(value_field, options_, true, variables_,
246 value_field, true, variables_, 247 "entry->mutable_value()->data(),\n"
247 "entry->mutable_value()->data(),\n" 248 "entry->mutable_value()->length(),\n",
248 "entry->mutable_value()->length(),\n", printer); 249 printer);
249 } 250 }
250 251
251 // If entry is allocated by arena, its desctructor should be avoided. 252 // If entry is allocated by arena, its desctructor should be avoided.
252 if (SupportsArenas(descriptor_)) { 253 if (SupportsArenas(descriptor_)) {
253 printer->Print(variables_, 254 printer->Print(variables_,
254 "if (entry->GetArena() != NULL) entry.release();\n"); 255 "if (entry->GetArena() != NULL) entry.release();\n");
255 } 256 }
256 } 257 }
257 258
258 void MapFieldGenerator:: 259 void MapFieldGenerator::
(...skipping 19 matching lines...) Expand all
278 " $number$, *entry, output);\n"); 279 " $number$, *entry, output);\n");
279 280
280 printer->Indent(); 281 printer->Indent();
281 printer->Indent(); 282 printer->Indent();
282 283
283 const FieldDescriptor* key_field = 284 const FieldDescriptor* key_field =
284 descriptor_->message_type()->FindFieldByName("key"); 285 descriptor_->message_type()->FindFieldByName("key");
285 const FieldDescriptor* value_field = 286 const FieldDescriptor* value_field =
286 descriptor_->message_type()->FindFieldByName("value"); 287 descriptor_->message_type()->FindFieldByName("value");
287 if (key_field->type() == FieldDescriptor::TYPE_STRING) { 288 if (key_field->type() == FieldDescriptor::TYPE_STRING) {
288 GenerateUtf8CheckCodeForString( 289 GenerateUtf8CheckCodeForString(key_field, options_, false, variables_,
289 key_field, false, variables_, 290 "it->first.data(), it->first.length(),\n",
290 "it->first.data(), it->first.length(),\n", printer); 291 printer);
291 } 292 }
292 if (value_field->type() == FieldDescriptor::TYPE_STRING) { 293 if (value_field->type() == FieldDescriptor::TYPE_STRING) {
293 GenerateUtf8CheckCodeForString( 294 GenerateUtf8CheckCodeForString(value_field, options_, false, variables_,
294 value_field, false, variables_, 295 "it->second.data(), it->second.length(),\n",
295 "it->second.data(), it->second.length(),\n", printer); 296 printer);
296 } 297 }
297 298
298 printer->Outdent(); 299 printer->Outdent();
299 printer->Outdent(); 300 printer->Outdent();
300 301
301 printer->Print( 302 printer->Print(
302 " }\n"); 303 " }\n");
303 304
304 // If entry is allocated by arena, its desctructor should be avoided. 305 // If entry is allocated by arena, its desctructor should be avoided.
305 if (SupportsArenas(descriptor_)) { 306 if (SupportsArenas(descriptor_)) {
(...skipping 30 matching lines...) Expand all
336 " $number$, *entry, target);\n"); 337 " $number$, *entry, target);\n");
337 338
338 printer->Indent(); 339 printer->Indent();
339 printer->Indent(); 340 printer->Indent();
340 341
341 const FieldDescriptor* key_field = 342 const FieldDescriptor* key_field =
342 descriptor_->message_type()->FindFieldByName("key"); 343 descriptor_->message_type()->FindFieldByName("key");
343 const FieldDescriptor* value_field = 344 const FieldDescriptor* value_field =
344 descriptor_->message_type()->FindFieldByName("value"); 345 descriptor_->message_type()->FindFieldByName("value");
345 if (key_field->type() == FieldDescriptor::TYPE_STRING) { 346 if (key_field->type() == FieldDescriptor::TYPE_STRING) {
346 GenerateUtf8CheckCodeForString( 347 GenerateUtf8CheckCodeForString(key_field, options_, false, variables_,
347 key_field, false, variables_, 348 "it->first.data(), it->first.length(),\n",
348 "it->first.data(), it->first.length(),\n", printer); 349 printer);
349 } 350 }
350 if (value_field->type() == FieldDescriptor::TYPE_STRING) { 351 if (value_field->type() == FieldDescriptor::TYPE_STRING) {
351 GenerateUtf8CheckCodeForString( 352 GenerateUtf8CheckCodeForString(value_field, options_, false, variables_,
352 value_field, false, variables_, 353 "it->second.data(), it->second.length(),\n",
353 "it->second.data(), it->second.length(),\n", printer); 354 printer);
354 } 355 }
355 356
356 printer->Outdent(); 357 printer->Outdent();
357 printer->Outdent(); 358 printer->Outdent();
358 printer->Print( 359 printer->Print(
359 " }\n"); 360 " }\n");
360 361
361 // If entry is allocated by arena, its desctructor should be avoided. 362 // If entry is allocated by arena, its desctructor should be avoided.
362 if (SupportsArenas(descriptor_)) { 363 if (SupportsArenas(descriptor_)) {
363 printer->Print(variables_, 364 printer->Print(variables_,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 " }\n"); 402 " }\n");
402 } 403 }
403 404
404 printer->Print("}\n"); 405 printer->Print("}\n");
405 } 406 }
406 407
407 } // namespace cpp 408 } // namespace cpp
408 } // namespace compiler 409 } // namespace compiler
409 } // namespace protobuf 410 } // namespace protobuf
410 } // namespace google 411 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698