OLD | NEW |
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 // http://code.google.com/p/protobuf/ | 3 // http://code.google.com/p/protobuf/ |
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 Loading... |
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 map<string, string>* variables, |
84 SetCommonFieldVariables(descriptor, variables); | 84 const Options& options) { |
| 85 SetCommonFieldVariables(descriptor, variables, options); |
85 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type()); | 86 (*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type()); |
86 (*variables)["default"] = DefaultValue(descriptor); | 87 (*variables)["default"] = DefaultValue(descriptor); |
87 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); | 88 (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor)); |
88 int fixed_size = FixedSize(descriptor->type()); | 89 int fixed_size = FixedSize(descriptor->type()); |
89 if (fixed_size != -1) { | 90 if (fixed_size != -1) { |
90 (*variables)["fixed_size"] = SimpleItoa(fixed_size); | 91 (*variables)["fixed_size"] = SimpleItoa(fixed_size); |
91 } | 92 } |
92 (*variables)["wire_format_field_type"] = | 93 (*variables)["wire_format_field_type"] = |
93 "::google::protobuf::internal::WireFormatLite::" + FieldDescriptorProto_Ty
pe_Name( | 94 "::google::protobuf::internal::WireFormatLite::" + FieldDescriptorProto_Ty
pe_Name( |
94 static_cast<FieldDescriptorProto_Type>(descriptor->type())); | 95 static_cast<FieldDescriptorProto_Type>(descriptor->type())); |
95 } | 96 } |
96 | 97 |
97 } // namespace | 98 } // namespace |
98 | 99 |
99 // =================================================================== | 100 // =================================================================== |
100 | 101 |
101 PrimitiveFieldGenerator:: | 102 PrimitiveFieldGenerator:: |
102 PrimitiveFieldGenerator(const FieldDescriptor* descriptor) | 103 PrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 104 const Options& options) |
103 : descriptor_(descriptor) { | 105 : descriptor_(descriptor) { |
104 SetPrimitiveVariables(descriptor, &variables_); | 106 SetPrimitiveVariables(descriptor, &variables_, options); |
105 } | 107 } |
106 | 108 |
107 PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} | 109 PrimitiveFieldGenerator::~PrimitiveFieldGenerator() {} |
108 | 110 |
109 void PrimitiveFieldGenerator:: | 111 void PrimitiveFieldGenerator:: |
110 GeneratePrivateMembers(io::Printer* printer) const { | 112 GeneratePrivateMembers(io::Printer* printer) const { |
111 printer->Print(variables_, "$type$ $name$_;\n"); | 113 printer->Print(variables_, "$type$ $name$_;\n"); |
112 } | 114 } |
113 | 115 |
114 void PrimitiveFieldGenerator:: | 116 void PrimitiveFieldGenerator:: |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 " this->$name$());\n"); | 185 " this->$name$());\n"); |
184 } else { | 186 } else { |
185 printer->Print(variables_, | 187 printer->Print(variables_, |
186 "total_size += $tag_size$ + $fixed_size$;\n"); | 188 "total_size += $tag_size$ + $fixed_size$;\n"); |
187 } | 189 } |
188 } | 190 } |
189 | 191 |
190 // =================================================================== | 192 // =================================================================== |
191 | 193 |
192 RepeatedPrimitiveFieldGenerator:: | 194 RepeatedPrimitiveFieldGenerator:: |
193 RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor) | 195 RepeatedPrimitiveFieldGenerator(const FieldDescriptor* descriptor, |
| 196 const Options& options) |
194 : descriptor_(descriptor) { | 197 : descriptor_(descriptor) { |
195 SetPrimitiveVariables(descriptor, &variables_); | 198 SetPrimitiveVariables(descriptor, &variables_, options); |
196 | 199 |
197 if (descriptor->options().packed()) { | 200 if (descriptor->options().packed()) { |
198 variables_["packed_reader"] = "ReadPackedPrimitive"; | 201 variables_["packed_reader"] = "ReadPackedPrimitive"; |
199 variables_["repeated_reader"] = "ReadRepeatedPrimitiveNoInline"; | 202 variables_["repeated_reader"] = "ReadRepeatedPrimitiveNoInline"; |
200 } else { | 203 } else { |
201 variables_["packed_reader"] = "ReadPackedPrimitiveNoInline"; | 204 variables_["packed_reader"] = "ReadPackedPrimitiveNoInline"; |
202 variables_["repeated_reader"] = "ReadRepeatedPrimitive"; | 205 variables_["repeated_reader"] = "ReadRepeatedPrimitive"; |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 printer->Print(variables_, | 362 printer->Print(variables_, |
360 "data_size = $fixed_size$ * this->$name$_size();\n"); | 363 "data_size = $fixed_size$ * this->$name$_size();\n"); |
361 } | 364 } |
362 | 365 |
363 if (descriptor_->options().packed()) { | 366 if (descriptor_->options().packed()) { |
364 printer->Print(variables_, | 367 printer->Print(variables_, |
365 "if (data_size > 0) {\n" | 368 "if (data_size > 0) {\n" |
366 " total_size += $tag_size$ +\n" | 369 " total_size += $tag_size$ +\n" |
367 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n
" | 370 " ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);\n
" |
368 "}\n" | 371 "}\n" |
| 372 "GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" |
369 "_$name$_cached_byte_size_ = data_size;\n" | 373 "_$name$_cached_byte_size_ = data_size;\n" |
| 374 "GOOGLE_SAFE_CONCURRENT_WRITES_END();\n" |
370 "total_size += data_size;\n"); | 375 "total_size += data_size;\n"); |
371 } else { | 376 } else { |
372 printer->Print(variables_, | 377 printer->Print(variables_, |
373 "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); | 378 "total_size += $tag_size$ * this->$name$_size() + data_size;\n"); |
374 } | 379 } |
375 printer->Outdent(); | 380 printer->Outdent(); |
376 printer->Print("}\n"); | 381 printer->Print("}\n"); |
377 } | 382 } |
378 | 383 |
379 } // namespace cpp | 384 } // namespace cpp |
380 } // namespace compiler | 385 } // namespace compiler |
381 } // namespace protobuf | 386 } // namespace protobuf |
382 } // namespace google | 387 } // namespace google |
OLD | NEW |