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

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

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 case FieldDescriptor::TYPE_MESSAGE : return -1; 73 case FieldDescriptor::TYPE_MESSAGE : return -1;
74 74
75 // No default because we want the compiler to complain if any new 75 // No default because we want the compiler to complain if any new
76 // types are added. 76 // types are added.
77 } 77 }
78 GOOGLE_LOG(FATAL) << "Can't get here."; 78 GOOGLE_LOG(FATAL) << "Can't get here.";
79 return -1; 79 return -1;
80 } 80 }
81 81
82 void SetPrimitiveVariables(const FieldDescriptor* descriptor, 82 void SetPrimitiveVariables(const FieldDescriptor* descriptor,
83 map<string, string>* variables, 83 std::map<string, string>* variables,
84 const Options& options) { 84 const Options& options) {
85 SetCommonFieldVariables(descriptor, variables, options); 85 SetCommonFieldVariables(descriptor, variables, options);
86 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type()); 86 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type());
87 (*variables)["default"] = DefaultValue(descriptor); 87 (*variables)["default"] = DefaultValue(descriptor);
88 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); 88 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor));
89 int fixed_size = FixedSize(descriptor->type()); 89 int fixed_size = FixedSize(descriptor->type());
90 if (fixed_size != -1) { 90 if (fixed_size != -1) {
91 (*variables)["fixed_size"] = SimpleItoa(fixed_size); 91 (*variables)["fixed_size"] = SimpleItoa(fixed_size);
92 } 92 }
93 (*variables)["wire_format_field_type"] = 93 (*variables)["wire_format_field_type"] =
(...skipping 21 matching lines...) Expand all
115 115
116 void PrimitiveFieldGenerator:: 116 void PrimitiveFieldGenerator::
117 GenerateAccessorDeclarations(io::Printer* printer) const { 117 GenerateAccessorDeclarations(io::Printer* printer) const {
118 printer->Print(variables_, 118 printer->Print(variables_,
119 "$deprecated_attr$$type$ $name$() const;\n" 119 "$deprecated_attr$$type$ $name$() const;\n"
120 "$deprecated_attr$void set_$name$($type$ value);\n"); 120 "$deprecated_attr$void set_$name$($type$ value);\n");
121 } 121 }
122 122
123 void PrimitiveFieldGenerator:: 123 void PrimitiveFieldGenerator::
124 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { 124 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
125 map<string, string> variables(variables_); 125 std::map<string, string> variables(variables_);
126 variables["inline"] = is_inline ? "inline" : ""; 126 variables["inline"] = is_inline ? "inline " : "";
127 printer->Print(variables, 127 printer->Print(variables,
128 "$inline$ $type$ $classname$::$name$() const {\n" 128 "$inline$$type$ $classname$::$name$() const {\n"
129 " // @@protoc_insertion_point(field_get:$full_name$)\n" 129 " // @@protoc_insertion_point(field_get:$full_name$)\n"
130 " return $name$_;\n" 130 " return $name$_;\n"
131 "}\n" 131 "}\n"
132 "$inline$ void $classname$::set_$name$($type$ value) {\n" 132 "$inline$void $classname$::set_$name$($type$ value) {\n"
133 " $set_hasbit$\n" 133 " $set_hasbit$\n"
134 " $name$_ = value;\n" 134 " $name$_ = value;\n"
135 " // @@protoc_insertion_point(field_set:$full_name$)\n" 135 " // @@protoc_insertion_point(field_set:$full_name$)\n"
136 "}\n"); 136 "}\n");
137 } 137 }
138 138
139 void PrimitiveFieldGenerator:: 139 void PrimitiveFieldGenerator::
140 GenerateClearingCode(io::Printer* printer) const { 140 GenerateClearingCode(io::Printer* printer) const {
141 printer->Print(variables_, "$name$_ = $default$;\n"); 141 printer->Print(variables_, "$name$_ = $default$;\n");
142 } 142 }
143 143
144 void PrimitiveFieldGenerator:: 144 void PrimitiveFieldGenerator::
145 GenerateMergingCode(io::Printer* printer) const { 145 GenerateMergingCode(io::Printer* printer) const {
146 printer->Print(variables_, "set_$name$(from.$name$());\n"); 146 printer->Print(variables_, "set_$name$(from.$name$());\n");
147 } 147 }
148 148
149 void PrimitiveFieldGenerator:: 149 void PrimitiveFieldGenerator::
150 GenerateSwappingCode(io::Printer* printer) const { 150 GenerateSwappingCode(io::Printer* printer) const {
151 printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); 151 printer->Print(variables_, "std::swap($name$_, other->$name$_);\n");
152 } 152 }
153 153
154 void PrimitiveFieldGenerator:: 154 void PrimitiveFieldGenerator::
155 GenerateConstructorCode(io::Printer* printer) const { 155 GenerateConstructorCode(io::Printer* printer) const {
156 printer->Print(variables_, "$name$_ = $default$;\n"); 156 printer->Print(variables_, "$name$_ = $default$;\n");
157 } 157 }
158 158
159 void PrimitiveFieldGenerator:: 159 void PrimitiveFieldGenerator::
160 GenerateCopyConstructorCode(io::Printer* printer) const {
161 printer->Print(variables_, "$name$_ = from.$name$_;\n");
162 }
163
164 void PrimitiveFieldGenerator::
160 GenerateMergeFromCodedStream(io::Printer* printer) const { 165 GenerateMergeFromCodedStream(io::Printer* printer) const {
161 printer->Print(variables_, 166 printer->Print(variables_,
167 "$set_hasbit$\n"
162 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" 168 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
163 " $type$, $wire_format_field_type$>(\n" 169 " $type$, $wire_format_field_type$>(\n"
164 " input, &$name$_)));\n" 170 " input, &$name$_)));\n");
165 "$set_hasbit$\n");
166 } 171 }
167 172
168 void PrimitiveFieldGenerator:: 173 void PrimitiveFieldGenerator::
169 GenerateSerializeWithCachedSizes(io::Printer* printer) const { 174 GenerateSerializeWithCachedSizes(io::Printer* printer) const {
170 printer->Print(variables_, 175 printer->Print(variables_,
171 "::google::protobuf::internal::WireFormatLite::Write$declared_type$(" 176 "::google::protobuf::internal::WireFormatLite::Write$declared_type$("
172 "$number$, this->$name$(), output);\n"); 177 "$number$, this->$name$(), output);\n");
173 } 178 }
174 179
175 void PrimitiveFieldGenerator:: 180 void PrimitiveFieldGenerator::
(...skipping 23 matching lines...) Expand all
199 PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, 204 PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
200 const Options& options) 205 const Options& options)
201 : PrimitiveFieldGenerator(descriptor, options) { 206 : PrimitiveFieldGenerator(descriptor, options) {
202 SetCommonOneofFieldVariables(descriptor, &variables_); 207 SetCommonOneofFieldVariables(descriptor, &variables_);
203 } 208 }
204 209
205 PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {} 210 PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {}
206 211
207 void PrimitiveOneofFieldGenerator:: 212 void PrimitiveOneofFieldGenerator::
208 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { 213 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
209 map<string, string> variables(variables_); 214 std::map<string, string> variables(variables_);
210 variables["inline"] = is_inline ? "inline" : ""; 215 variables["inline"] = is_inline ? "inline " : "";
211 printer->Print(variables, 216 printer->Print(variables,
212 "$inline$ $type$ $classname$::$name$() const {\n" 217 "$inline$$type$ $classname$::$name$() const {\n"
213 " // @@protoc_insertion_point(field_get:$full_name$)\n" 218 " // @@protoc_insertion_point(field_get:$full_name$)\n"
214 " if (has_$name$()) {\n" 219 " if (has_$name$()) {\n"
215 " return $oneof_prefix$$name$_;\n" 220 " return $oneof_prefix$$name$_;\n"
216 " }\n" 221 " }\n"
217 " return $default$;\n" 222 " return $default$;\n"
218 "}\n" 223 "}\n"
219 "$inline$ void $classname$::set_$name$($type$ value) {\n" 224 "$inline$void $classname$::set_$name$($type$ value) {\n"
220 " if (!has_$name$()) {\n" 225 " if (!has_$name$()) {\n"
221 " clear_$oneof_name$();\n" 226 " clear_$oneof_name$();\n"
222 " set_has_$name$();\n" 227 " set_has_$name$();\n"
223 " }\n" 228 " }\n"
224 " $oneof_prefix$$name$_ = value;\n" 229 " $oneof_prefix$$name$_ = value;\n"
225 " // @@protoc_insertion_point(field_set:$full_name$)\n" 230 " // @@protoc_insertion_point(field_set:$full_name$)\n"
226 "}\n"); 231 "}\n");
227 } 232 }
228 233
229 void PrimitiveOneofFieldGenerator:: 234 void PrimitiveOneofFieldGenerator::
230 GenerateClearingCode(io::Printer* printer) const { 235 GenerateClearingCode(io::Printer* printer) const {
231 printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n"); 236 printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n");
232 } 237 }
233 238
234 void PrimitiveOneofFieldGenerator:: 239 void PrimitiveOneofFieldGenerator::
235 GenerateSwappingCode(io::Printer* printer) const { 240 GenerateSwappingCode(io::Printer* printer) const {
236 // Don't print any swapping code. Swapping the union will swap this field. 241 // Don't print any swapping code. Swapping the union will swap this field.
237 } 242 }
238 243
239 void PrimitiveOneofFieldGenerator:: 244 void PrimitiveOneofFieldGenerator::
240 GenerateConstructorCode(io::Printer* printer) const { 245 GenerateConstructorCode(io::Printer* printer) const {
241 printer->Print( 246 printer->Print(
242 variables_, 247 variables_,
243 " $classname$_default_oneof_instance_->$name$_ = $default$;\n"); 248 " $classname$_default_oneof_instance_.$name$_ = $default$;\n");
244 } 249 }
245 250
246 void PrimitiveOneofFieldGenerator:: 251 void PrimitiveOneofFieldGenerator::
247 GenerateMergeFromCodedStream(io::Printer* printer) const { 252 GenerateMergeFromCodedStream(io::Printer* printer) const {
248 printer->Print(variables_, 253 printer->Print(variables_,
249 "clear_$oneof_name$();\n" 254 "clear_$oneof_name$();\n"
250 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" 255 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
251 " $type$, $wire_format_field_type$>(\n" 256 " $type$, $wire_format_field_type$>(\n"
252 " input, &$oneof_prefix$$name$_)));\n" 257 " input, &$oneof_prefix$$name$_)));\n"
253 "set_has_$name$();\n"); 258 "set_has_$name$();\n");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 "$deprecated_attr$void add_$name$($type$ value);\n"); 295 "$deprecated_attr$void add_$name$($type$ value);\n");
291 printer->Print(variables_, 296 printer->Print(variables_,
292 "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n" 297 "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n"
293 " $name$() const;\n" 298 " $name$() const;\n"
294 "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n" 299 "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n"
295 " mutable_$name$();\n"); 300 " mutable_$name$();\n");
296 } 301 }
297 302
298 void RepeatedPrimitiveFieldGenerator:: 303 void RepeatedPrimitiveFieldGenerator::
299 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { 304 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
300 map<string, string> variables(variables_); 305 std::map<string, string> variables(variables_);
301 variables["inline"] = is_inline ? "inline" : ""; 306 variables["inline"] = is_inline ? "inline " : "";
302 printer->Print(variables, 307 printer->Print(variables,
303 "$inline$ $type$ $classname$::$name$(int index) const {\n" 308 "$inline$$type$ $classname$::$name$(int index) const {\n"
304 " // @@protoc_insertion_point(field_get:$full_name$)\n" 309 " // @@protoc_insertion_point(field_get:$full_name$)\n"
305 " return $name$_.Get(index);\n" 310 " return $name$_.Get(index);\n"
306 "}\n" 311 "}\n"
307 "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n" 312 "$inline$void $classname$::set_$name$(int index, $type$ value) {\n"
308 " $name$_.Set(index, value);\n" 313 " $name$_.Set(index, value);\n"
309 " // @@protoc_insertion_point(field_set:$full_name$)\n" 314 " // @@protoc_insertion_point(field_set:$full_name$)\n"
310 "}\n" 315 "}\n"
311 "$inline$ void $classname$::add_$name$($type$ value) {\n" 316 "$inline$void $classname$::add_$name$($type$ value) {\n"
312 " $name$_.Add(value);\n" 317 " $name$_.Add(value);\n"
313 " // @@protoc_insertion_point(field_add:$full_name$)\n" 318 " // @@protoc_insertion_point(field_add:$full_name$)\n"
314 "}\n"); 319 "}\n");
315 printer->Print(variables, 320 printer->Print(variables,
316 "$inline$ const ::google::protobuf::RepeatedField< $type$ >&\n" 321 "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n"
317 "$classname$::$name$() const {\n" 322 "$classname$::$name$() const {\n"
318 " // @@protoc_insertion_point(field_list:$full_name$)\n" 323 " // @@protoc_insertion_point(field_list:$full_name$)\n"
319 " return $name$_;\n" 324 " return $name$_;\n"
320 "}\n" 325 "}\n"
321 "$inline$ ::google::protobuf::RepeatedField< $type$ >*\n" 326 "$inline$::google::protobuf::RepeatedField< $type$ >*\n"
322 "$classname$::mutable_$name$() {\n" 327 "$classname$::mutable_$name$() {\n"
323 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" 328 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
324 " return &$name$_;\n" 329 " return &$name$_;\n"
325 "}\n"); 330 "}\n");
326 } 331 }
327 332
328 void RepeatedPrimitiveFieldGenerator:: 333 void RepeatedPrimitiveFieldGenerator::
329 GenerateClearingCode(io::Printer* printer) const { 334 GenerateClearingCode(io::Printer* printer) const {
330 printer->Print(variables_, "$name$_.Clear();\n"); 335 printer->Print(variables_, "$name$_.Clear();\n");
331 } 336 }
332 337
333 void RepeatedPrimitiveFieldGenerator:: 338 void RepeatedPrimitiveFieldGenerator::
334 GenerateMergingCode(io::Printer* printer) const { 339 GenerateMergingCode(io::Printer* printer) const {
335 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); 340 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n");
336 } 341 }
337 342
338 void RepeatedPrimitiveFieldGenerator:: 343 void RepeatedPrimitiveFieldGenerator::
339 GenerateSwappingCode(io::Printer* printer) const { 344 GenerateSwappingCode(io::Printer* printer) const {
340 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); 345 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n");
341 } 346 }
342 347
343 void RepeatedPrimitiveFieldGenerator:: 348 void RepeatedPrimitiveFieldGenerator::
344 GenerateConstructorCode(io::Printer* printer) const { 349 GenerateConstructorCode(io::Printer* printer) const {
345 // Not needed for repeated fields. 350 // Not needed for repeated fields.
346 } 351 }
347 352
348 void RepeatedPrimitiveFieldGenerator:: 353 void RepeatedPrimitiveFieldGenerator::
354 GenerateCopyConstructorCode(io::Printer* printer) const {
355 printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);\n");
356 }
357
358 void RepeatedPrimitiveFieldGenerator::
349 GenerateMergeFromCodedStream(io::Printer* printer) const { 359 GenerateMergeFromCodedStream(io::Printer* printer) const {
350 printer->Print(variables_, 360 printer->Print(variables_,
351 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n" 361 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n"
352 " $type$, $wire_format_field_type$>(\n" 362 " $type$, $wire_format_field_type$>(\n"
353 " $tag_size$, $tag$, input, this->mutable_$name$())));\n"); 363 " $tag_size$, $tag$u, input, this->mutable_$name$())));\n");
354 } 364 }
355 365
356 void RepeatedPrimitiveFieldGenerator:: 366 void RepeatedPrimitiveFieldGenerator::
357 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { 367 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
358 printer->Print(variables_, 368 printer->Print(variables_,
359 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n" 369 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n"
360 " $type$, $wire_format_field_type$>(\n" 370 " $type$, $wire_format_field_type$>(\n"
361 " input, this->mutable_$name$())));\n"); 371 " input, this->mutable_$name$())));\n");
362 } 372 }
363 373
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 " target = ::google::protobuf::internal::WireFormatLite::\n" 423 " target = ::google::protobuf::internal::WireFormatLite::\n"
414 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"); 424 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n");
415 } 425 }
416 printer->Print("}\n"); 426 printer->Print("}\n");
417 } 427 }
418 428
419 void RepeatedPrimitiveFieldGenerator:: 429 void RepeatedPrimitiveFieldGenerator::
420 GenerateByteSize(io::Printer* printer) const { 430 GenerateByteSize(io::Printer* printer) const {
421 printer->Print(variables_, 431 printer->Print(variables_,
422 "{\n" 432 "{\n"
423 " int data_size = 0;\n"); 433 " size_t data_size = 0;\n"
434 " unsigned int count = this->$name$_size();\n");
424 printer->Indent(); 435 printer->Indent();
425 int fixed_size = FixedSize(descriptor_->type()); 436 int fixed_size = FixedSize(descriptor_->type());
426 if (fixed_size == -1) { 437 if (fixed_size == -1) {
427 printer->Print(variables_, 438 printer->Print(variables_,
428 "for (int i = 0; i < this->$name$_size(); i++) {\n" 439 "for (unsigned int i = 0; i < count; i++) {\n"
429 " data_size += ::google::protobuf::internal::WireFormatLite::\n" 440 " data_size += ::google::protobuf::internal::WireFormatLite::\n"
430 " $declared_type$Size(this->$name$(i));\n" 441 " $declared_type$Size(this->$name$(i));\n"
431 "}\n"); 442 "}\n");
432 } else { 443 } else {
433 printer->Print(variables_, 444 printer->Print(variables_,
434 "data_size = $fixed_size$ * this->$name$_size();\n"); 445 "data_size = $fixed_size$UL * count;\n");
435 } 446 }
436 447
437 if (descriptor_->is_packed()) { 448 if (descriptor_->is_packed()) {
438 printer->Print(variables_, 449 printer->Print(variables_,
439 "if (data_size > 0) {\n" 450 "if (data_size > 0) {\n"
440 " total_size += $tag_size$ +\n" 451 " total_size += $tag_size$ +\n"
441 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n " 452 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n "
442 "}\n" 453 "}\n"
454 "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\ n"
443 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" 455 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
444 "_$name$_cached_byte_size_ = data_size;\n" 456 "_$name$_cached_byte_size_ = cached_size;\n"
445 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" 457 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n"
446 "total_size += data_size;\n"); 458 "total_size += data_size;\n");
447 } else { 459 } else {
448 printer->Print(variables_, 460 printer->Print(variables_,
449 "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); 461 "total_size += $tag_size$ *\n"
462 " ::google::protobuf::internal::FromIntSize(this->$name$_size ());\n"
463 "total_size += data_size;\n");
450 } 464 }
451 printer->Outdent(); 465 printer->Outdent();
452 printer->Print("}\n"); 466 printer->Print("}\n");
453 } 467 }
454 468
455 } // namespace cpp 469 } // namespace cpp
456 } // namespace compiler 470 } // namespace compiler
457 } // namespace protobuf 471 } // namespace protobuf
458 } // namespace google 472 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698