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

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

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 3 years, 12 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 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 std::map<string, string>* variables, 83 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 std::map<string, string> variables(variables_); 125 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::
165 GenerateMergeFromCodedStream(io::Printer* printer) const { 160 GenerateMergeFromCodedStream(io::Printer* printer) const {
166 printer->Print(variables_, 161 printer->Print(variables_,
167 "$set_hasbit$\n"
168 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" 162 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
169 " $type$, $wire_format_field_type$>(\n" 163 " $type$, $wire_format_field_type$>(\n"
170 " input, &$name$_)));\n"); 164 " input, &$name$_)));\n"
165 "$set_hasbit$\n");
171 } 166 }
172 167
173 void PrimitiveFieldGenerator:: 168 void PrimitiveFieldGenerator::
174 GenerateSerializeWithCachedSizes(io::Printer* printer) const { 169 GenerateSerializeWithCachedSizes(io::Printer* printer) const {
175 printer->Print(variables_, 170 printer->Print(variables_,
176 "::google::protobuf::internal::WireFormatLite::Write$declared_type$(" 171 "::google::protobuf::internal::WireFormatLite::Write$declared_type$("
177 "$number$, this->$name$(), output);\n"); 172 "$number$, this->$name$(), output);\n");
178 } 173 }
179 174
180 void PrimitiveFieldGenerator:: 175 void PrimitiveFieldGenerator::
(...skipping 23 matching lines...) Expand all
204 PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor, 199 PrimitiveOneofFieldGenerator(const FieldDescriptor* descriptor,
205 const Options& options) 200 const Options& options)
206 : PrimitiveFieldGenerator(descriptor, options) { 201 : PrimitiveFieldGenerator(descriptor, options) {
207 SetCommonOneofFieldVariables(descriptor, &variables_); 202 SetCommonOneofFieldVariables(descriptor, &variables_);
208 } 203 }
209 204
210 PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {} 205 PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {}
211 206
212 void PrimitiveOneofFieldGenerator:: 207 void PrimitiveOneofFieldGenerator::
213 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { 208 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
214 std::map<string, string> variables(variables_); 209 map<string, string> variables(variables_);
215 variables["inline"] = is_inline ? "inline " : ""; 210 variables["inline"] = is_inline ? "inline" : "";
216 printer->Print(variables, 211 printer->Print(variables,
217 "$inline$$type$ $classname$::$name$() const {\n" 212 "$inline$ $type$ $classname$::$name$() const {\n"
218 " // @@protoc_insertion_point(field_get:$full_name$)\n" 213 " // @@protoc_insertion_point(field_get:$full_name$)\n"
219 " if (has_$name$()) {\n" 214 " if (has_$name$()) {\n"
220 " return $oneof_prefix$$name$_;\n" 215 " return $oneof_prefix$$name$_;\n"
221 " }\n" 216 " }\n"
222 " return $default$;\n" 217 " return $default$;\n"
223 "}\n" 218 "}\n"
224 "$inline$void $classname$::set_$name$($type$ value) {\n" 219 "$inline$ void $classname$::set_$name$($type$ value) {\n"
225 " if (!has_$name$()) {\n" 220 " if (!has_$name$()) {\n"
226 " clear_$oneof_name$();\n" 221 " clear_$oneof_name$();\n"
227 " set_has_$name$();\n" 222 " set_has_$name$();\n"
228 " }\n" 223 " }\n"
229 " $oneof_prefix$$name$_ = value;\n" 224 " $oneof_prefix$$name$_ = value;\n"
230 " // @@protoc_insertion_point(field_set:$full_name$)\n" 225 " // @@protoc_insertion_point(field_set:$full_name$)\n"
231 "}\n"); 226 "}\n");
232 } 227 }
233 228
234 void PrimitiveOneofFieldGenerator:: 229 void PrimitiveOneofFieldGenerator::
235 GenerateClearingCode(io::Printer* printer) const { 230 GenerateClearingCode(io::Printer* printer) const {
236 printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n"); 231 printer->Print(variables_, "$oneof_prefix$$name$_ = $default$;\n");
237 } 232 }
238 233
239 void PrimitiveOneofFieldGenerator:: 234 void PrimitiveOneofFieldGenerator::
240 GenerateSwappingCode(io::Printer* printer) const { 235 GenerateSwappingCode(io::Printer* printer) const {
241 // Don't print any swapping code. Swapping the union will swap this field. 236 // Don't print any swapping code. Swapping the union will swap this field.
242 } 237 }
243 238
244 void PrimitiveOneofFieldGenerator:: 239 void PrimitiveOneofFieldGenerator::
245 GenerateConstructorCode(io::Printer* printer) const { 240 GenerateConstructorCode(io::Printer* printer) const {
246 printer->Print( 241 printer->Print(
247 variables_, 242 variables_,
248 " $classname$_default_oneof_instance_.$name$_ = $default$;\n"); 243 " $classname$_default_oneof_instance_->$name$_ = $default$;\n");
249 } 244 }
250 245
251 void PrimitiveOneofFieldGenerator:: 246 void PrimitiveOneofFieldGenerator::
252 GenerateMergeFromCodedStream(io::Printer* printer) const { 247 GenerateMergeFromCodedStream(io::Printer* printer) const {
253 printer->Print(variables_, 248 printer->Print(variables_,
254 "clear_$oneof_name$();\n" 249 "clear_$oneof_name$();\n"
255 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n" 250 "DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<\n"
256 " $type$, $wire_format_field_type$>(\n" 251 " $type$, $wire_format_field_type$>(\n"
257 " input, &$oneof_prefix$$name$_)));\n" 252 " input, &$oneof_prefix$$name$_)));\n"
258 "set_has_$name$();\n"); 253 "set_has_$name$();\n");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 "$deprecated_attr$void add_$name$($type$ value);\n"); 290 "$deprecated_attr$void add_$name$($type$ value);\n");
296 printer->Print(variables_, 291 printer->Print(variables_,
297 "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n" 292 "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n"
298 " $name$() const;\n" 293 " $name$() const;\n"
299 "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n" 294 "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n"
300 " mutable_$name$();\n"); 295 " mutable_$name$();\n");
301 } 296 }
302 297
303 void RepeatedPrimitiveFieldGenerator:: 298 void RepeatedPrimitiveFieldGenerator::
304 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { 299 GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
305 std::map<string, string> variables(variables_); 300 map<string, string> variables(variables_);
306 variables["inline"] = is_inline ? "inline " : ""; 301 variables["inline"] = is_inline ? "inline" : "";
307 printer->Print(variables, 302 printer->Print(variables,
308 "$inline$$type$ $classname$::$name$(int index) const {\n" 303 "$inline$ $type$ $classname$::$name$(int index) const {\n"
309 " // @@protoc_insertion_point(field_get:$full_name$)\n" 304 " // @@protoc_insertion_point(field_get:$full_name$)\n"
310 " return $name$_.Get(index);\n" 305 " return $name$_.Get(index);\n"
311 "}\n" 306 "}\n"
312 "$inline$void $classname$::set_$name$(int index, $type$ value) {\n" 307 "$inline$ void $classname$::set_$name$(int index, $type$ value) {\n"
313 " $name$_.Set(index, value);\n" 308 " $name$_.Set(index, value);\n"
314 " // @@protoc_insertion_point(field_set:$full_name$)\n" 309 " // @@protoc_insertion_point(field_set:$full_name$)\n"
315 "}\n" 310 "}\n"
316 "$inline$void $classname$::add_$name$($type$ value) {\n" 311 "$inline$ void $classname$::add_$name$($type$ value) {\n"
317 " $name$_.Add(value);\n" 312 " $name$_.Add(value);\n"
318 " // @@protoc_insertion_point(field_add:$full_name$)\n" 313 " // @@protoc_insertion_point(field_add:$full_name$)\n"
319 "}\n"); 314 "}\n");
320 printer->Print(variables, 315 printer->Print(variables,
321 "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n" 316 "$inline$ const ::google::protobuf::RepeatedField< $type$ >&\n"
322 "$classname$::$name$() const {\n" 317 "$classname$::$name$() const {\n"
323 " // @@protoc_insertion_point(field_list:$full_name$)\n" 318 " // @@protoc_insertion_point(field_list:$full_name$)\n"
324 " return $name$_;\n" 319 " return $name$_;\n"
325 "}\n" 320 "}\n"
326 "$inline$::google::protobuf::RepeatedField< $type$ >*\n" 321 "$inline$ ::google::protobuf::RepeatedField< $type$ >*\n"
327 "$classname$::mutable_$name$() {\n" 322 "$classname$::mutable_$name$() {\n"
328 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" 323 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
329 " return &$name$_;\n" 324 " return &$name$_;\n"
330 "}\n"); 325 "}\n");
331 } 326 }
332 327
333 void RepeatedPrimitiveFieldGenerator:: 328 void RepeatedPrimitiveFieldGenerator::
334 GenerateClearingCode(io::Printer* printer) const { 329 GenerateClearingCode(io::Printer* printer) const {
335 printer->Print(variables_, "$name$_.Clear();\n"); 330 printer->Print(variables_, "$name$_.Clear();\n");
336 } 331 }
337 332
338 void RepeatedPrimitiveFieldGenerator:: 333 void RepeatedPrimitiveFieldGenerator::
339 GenerateMergingCode(io::Printer* printer) const { 334 GenerateMergingCode(io::Printer* printer) const {
340 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); 335 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n");
341 } 336 }
342 337
343 void RepeatedPrimitiveFieldGenerator:: 338 void RepeatedPrimitiveFieldGenerator::
344 GenerateSwappingCode(io::Printer* printer) const { 339 GenerateSwappingCode(io::Printer* printer) const {
345 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); 340 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n");
346 } 341 }
347 342
348 void RepeatedPrimitiveFieldGenerator:: 343 void RepeatedPrimitiveFieldGenerator::
349 GenerateConstructorCode(io::Printer* printer) const { 344 GenerateConstructorCode(io::Printer* printer) const {
350 // Not needed for repeated fields. 345 // Not needed for repeated fields.
351 } 346 }
352 347
353 void RepeatedPrimitiveFieldGenerator:: 348 void RepeatedPrimitiveFieldGenerator::
354 GenerateCopyConstructorCode(io::Printer* printer) const {
355 printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);\n");
356 }
357
358 void RepeatedPrimitiveFieldGenerator::
359 GenerateMergeFromCodedStream(io::Printer* printer) const { 349 GenerateMergeFromCodedStream(io::Printer* printer) const {
360 printer->Print(variables_, 350 printer->Print(variables_,
361 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n" 351 "DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n"
362 " $type$, $wire_format_field_type$>(\n" 352 " $type$, $wire_format_field_type$>(\n"
363 " $tag_size$, $tag$u, input, this->mutable_$name$())));\n"); 353 " $tag_size$, $tag$, input, this->mutable_$name$())));\n");
364 } 354 }
365 355
366 void RepeatedPrimitiveFieldGenerator:: 356 void RepeatedPrimitiveFieldGenerator::
367 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const { 357 GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
368 printer->Print(variables_, 358 printer->Print(variables_,
369 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n" 359 "DO_((::google::protobuf::internal::WireFormatLite::$packed_reader$<\n"
370 " $type$, $wire_format_field_type$>(\n" 360 " $type$, $wire_format_field_type$>(\n"
371 " input, this->mutable_$name$())));\n"); 361 " input, this->mutable_$name$())));\n");
372 } 362 }
373 363
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 " target = ::google::protobuf::internal::WireFormatLite::\n" 413 " target = ::google::protobuf::internal::WireFormatLite::\n"
424 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"); 414 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n");
425 } 415 }
426 printer->Print("}\n"); 416 printer->Print("}\n");
427 } 417 }
428 418
429 void RepeatedPrimitiveFieldGenerator:: 419 void RepeatedPrimitiveFieldGenerator::
430 GenerateByteSize(io::Printer* printer) const { 420 GenerateByteSize(io::Printer* printer) const {
431 printer->Print(variables_, 421 printer->Print(variables_,
432 "{\n" 422 "{\n"
433 " size_t data_size = 0;\n" 423 " int data_size = 0;\n");
434 " unsigned int count = this->$name$_size();\n");
435 printer->Indent(); 424 printer->Indent();
436 int fixed_size = FixedSize(descriptor_->type()); 425 int fixed_size = FixedSize(descriptor_->type());
437 if (fixed_size == -1) { 426 if (fixed_size == -1) {
438 printer->Print(variables_, 427 printer->Print(variables_,
439 "for (unsigned int i = 0; i < count; i++) {\n" 428 "for (int i = 0; i < this->$name$_size(); i++) {\n"
440 " data_size += ::google::protobuf::internal::WireFormatLite::\n" 429 " data_size += ::google::protobuf::internal::WireFormatLite::\n"
441 " $declared_type$Size(this->$name$(i));\n" 430 " $declared_type$Size(this->$name$(i));\n"
442 "}\n"); 431 "}\n");
443 } else { 432 } else {
444 printer->Print(variables_, 433 printer->Print(variables_,
445 "data_size = $fixed_size$UL * count;\n"); 434 "data_size = $fixed_size$ * this->$name$_size();\n");
446 } 435 }
447 436
448 if (descriptor_->is_packed()) { 437 if (descriptor_->is_packed()) {
449 printer->Print(variables_, 438 printer->Print(variables_,
450 "if (data_size > 0) {\n" 439 "if (data_size > 0) {\n"
451 " total_size += $tag_size$ +\n" 440 " total_size += $tag_size$ +\n"
452 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n " 441 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n "
453 "}\n" 442 "}\n"
454 "int cached_size = ::google::protobuf::internal::ToCachedSize(data_size);\ n"
455 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" 443 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n"
456 "_$name$_cached_byte_size_ = cached_size;\n" 444 "_$name$_cached_byte_size_ = data_size;\n"
457 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" 445 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n"
458 "total_size += data_size;\n"); 446 "total_size += data_size;\n");
459 } else { 447 } else {
460 printer->Print(variables_, 448 printer->Print(variables_,
461 "total_size += $tag_size$ *\n" 449 "total_size += $tag_size$ * this->$name$_size() + data_size;\n");
462 " ::google::protobuf::internal::FromIntSize(this->$name$_size ());\n"
463 "total_size += data_size;\n");
464 } 450 }
465 printer->Outdent(); 451 printer->Outdent();
466 printer->Print("}\n"); 452 printer->Print("}\n");
467 } 453 }
468 454
469 } // namespace cpp 455 } // namespace cpp
470 } // namespace compiler 456 } // namespace compiler
471 } // namespace protobuf 457 } // namespace protobuf
472 } // namespace google 458 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698