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

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_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 28 matching lines...) Expand all
39 #include <google/protobuf/stubs/strutil.h> 39 #include <google/protobuf/stubs/strutil.h>
40 40
41 namespace google { 41 namespace google {
42 namespace protobuf { 42 namespace protobuf {
43 namespace compiler { 43 namespace compiler {
44 namespace cpp { 44 namespace cpp {
45 45
46 namespace { 46 namespace {
47 47
48 void SetStringVariables(const FieldDescriptor* descriptor, 48 void SetStringVariables(const FieldDescriptor* descriptor,
49 std::map<string, string>* variables, 49 map<string, string>* variables,
50 const Options& options) { 50 const Options& options) {
51 SetCommonFieldVariables(descriptor, variables, options); 51 SetCommonFieldVariables(descriptor, variables, options);
52 (*variables)["default"] = DefaultValue(descriptor); 52 (*variables)["default"] = DefaultValue(descriptor);
53 (*variables)["default_length"] = 53 (*variables)["default_length"] =
54 SimpleItoa(descriptor->default_value_string().length()); 54 SimpleItoa(descriptor->default_value_string().length());
55 string default_variable_string = "_default_" + FieldName(descriptor) + "_"; 55 string default_variable_string =
56 (*variables)["default_variable_name"] = default_variable_string;
57 (*variables)["default_variable"] =
58 descriptor->default_value_string().empty() 56 descriptor->default_value_string().empty()
59 ? "&::google::protobuf::internal::GetEmptyStringAlreadyInited()" 57 ? "&::google::protobuf::internal::GetEmptyStringAlreadyInited()"
60 : "&" + (*variables)["classname"] + "::" + default_variable_string + 58 : "_default_" + FieldName(descriptor) + "_";
61 ".get()"; 59 (*variables)["default_variable"] = default_variable_string;
60 (*variables)["default_value_init"] =
61 descriptor->default_value_string().empty()
62 ? "" : "*" + default_variable_string;
62 (*variables)["pointer_type"] = 63 (*variables)["pointer_type"] =
63 descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char"; 64 descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char";
64 // NOTE: Escaped here to unblock proto1->proto2 migration. 65 // NOTE: Escaped here to unblock proto1->proto2 migration.
65 // TODO(liujisi): Extend this to apply for other conflicting methods. 66 // TODO(liujisi): Extend this to apply for other conflicting methods.
66 (*variables)["release_name"] = 67 (*variables)["release_name"] =
67 SafeFunctionName(descriptor->containing_type(), 68 SafeFunctionName(descriptor->containing_type(),
68 descriptor, "release_"); 69 descriptor, "release_");
69 (*variables)["full_name"] = descriptor->full_name(); 70 (*variables)["full_name"] = descriptor->full_name();
70 71
71 (*variables)["string_piece"] = "::std::string"; 72 (*variables)["string_piece"] = "::std::string";
(...skipping 24 matching lines...) Expand all
96 // and littering the runtime code paths with conditionals. It's simpler to 97 // and littering the runtime code paths with conditionals. It's simpler to
97 // stick with this but use lightweight accessors that assume arena == NULL. 98 // stick with this but use lightweight accessors that assume arena == NULL.
98 // There should be very little overhead anyway because it's just a tagged 99 // There should be very little overhead anyway because it's just a tagged
99 // pointer in-memory. 100 // pointer in-memory.
100 printer->Print(variables_, "::google::protobuf::internal::ArenaStringPtr $name $_;\n"); 101 printer->Print(variables_, "::google::protobuf::internal::ArenaStringPtr $name $_;\n");
101 } 102 }
102 103
103 void StringFieldGenerator:: 104 void StringFieldGenerator::
104 GenerateStaticMembers(io::Printer* printer) const { 105 GenerateStaticMembers(io::Printer* printer) const {
105 if (!descriptor_->default_value_string().empty()) { 106 if (!descriptor_->default_value_string().empty()) {
106 printer->Print(variables_, 107 printer->Print(variables_, "static ::std::string* $default_variable$;\n");
107 "static ::google::protobuf::internal::ExplicitlyConstructed< ::std::string>"
108 " $default_variable_name$;\n");
109 } 108 }
110 } 109 }
111 110
112 void StringFieldGenerator:: 111 void StringFieldGenerator::
113 GenerateAccessorDeclarations(io::Printer* printer) const { 112 GenerateAccessorDeclarations(io::Printer* printer) const {
114 // If we're using StringFieldGenerator for a field with a ctype, it's 113 // If we're using StringFieldGenerator for a field with a ctype, it's
115 // because that ctype isn't actually implemented. In particular, this is 114 // because that ctype isn't actually implemented. In particular, this is
116 // true of ctype=CORD and ctype=STRING_PIECE in the open source release. 115 // true of ctype=CORD and ctype=STRING_PIECE in the open source release.
117 // We aren't releasing Cord because it has too many Google-specific 116 // We aren't releasing Cord because it has too many Google-specific
118 // dependencies and we aren't releasing StringPiece because it's hardly 117 // dependencies and we aren't releasing StringPiece because it's hardly
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (unknown_ctype) { 158 if (unknown_ctype) {
160 printer->Outdent(); 159 printer->Outdent();
161 printer->Print(" public:\n"); 160 printer->Print(" public:\n");
162 printer->Indent(); 161 printer->Indent();
163 } 162 }
164 } 163 }
165 164
166 void StringFieldGenerator:: 165 void StringFieldGenerator::
167 GenerateInlineAccessorDefinitions(io::Printer* printer, 166 GenerateInlineAccessorDefinitions(io::Printer* printer,
168 bool is_inline) const { 167 bool is_inline) const {
169 std::map<string, string> variables(variables_); 168 map<string, string> variables(variables_);
170 variables["inline"] = is_inline ? "inline " : ""; 169 variables["inline"] = is_inline ? "inline" : "";
171 if (SupportsArenas(descriptor_)) { 170 if (SupportsArenas(descriptor_)) {
172 printer->Print( 171 printer->Print(variables,
173 variables, 172 "$inline$ const ::std::string& $classname$::$name$() const {\n"
174 "$inline$const ::std::string& $classname$::$name$() const {\n" 173 " // @@protoc_insertion_point(field_get:$full_name$)\n"
175 " // @@protoc_insertion_point(field_get:$full_name$)\n" 174 " return $name$_.Get($default_variable$);\n"
176 " return $name$_.Get();\n" 175 "}\n"
177 "}\n" 176 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n"
178 "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" 177 " $set_hasbit$\n"
179 " $set_hasbit$\n" 178 " $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n"
180 " $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n" 179 " // @@protoc_insertion_point(field_set:$full_name$)\n"
181 " // @@protoc_insertion_point(field_set:$full_name$)\n" 180 "}\n"
182 "}\n" 181 "$inline$ void $classname$::set_$name$(const char* value) {\n"
183 "$inline$void $classname$::set_$name$(const char* value) {\n" 182 " $set_hasbit$\n"
184 " $set_hasbit$\n" 183 " $name$_.Set($default_variable$, $string_piece$(value),\n"
185 " $name$_.Set($default_variable$, $string_piece$(value),\n" 184 " GetArenaNoVirtual());\n"
186 " GetArenaNoVirtual());\n" 185 " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
187 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" 186 "}\n"
188 "}\n" 187 "$inline$ "
189 "$inline$" 188 "void $classname$::set_$name$(const $pointer_type$* value,\n"
190 "void $classname$::set_$name$(const $pointer_type$* value,\n" 189 " size_t size) {\n"
191 " size_t size) {\n" 190 " $set_hasbit$\n"
192 " $set_hasbit$\n" 191 " $name$_.Set($default_variable$, $string_piece$(\n"
193 " $name$_.Set($default_variable$, $string_piece$(\n" 192 " reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());\ n"
194 " reinterpret_cast<const char*>(value), size), " 193 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
195 "GetArenaNoVirtual());\n" 194 "}\n"
196 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" 195 "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
197 "}\n" 196 " $set_hasbit$\n"
198 "$inline$::std::string* $classname$::mutable_$name$() {\n" 197 " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
199 " $set_hasbit$\n" 198 " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n"
200 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" 199 "}\n"
201 " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" 200 "$inline$ ::std::string* $classname$::$release_name$() {\n"
202 "}\n" 201 " // @@protoc_insertion_point(field_release:$full_name$)\n"
203 "$inline$::std::string* $classname$::$release_name$() {\n" 202 " $clear_hasbit$\n"
204 " // @@protoc_insertion_point(field_release:$full_name$)\n" 203 " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n"
205 " $clear_hasbit$\n" 204 "}\n"
206 " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n" 205 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n"
207 "}\n" 206 " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
208 "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" 207 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
209 " // " 208 " $clear_hasbit$\n"
210 "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" 209 " return $name$_.UnsafeArenaRelease($default_variable$,\n"
211 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" 210 " GetArenaNoVirtual());\n"
212 " $clear_hasbit$\n" 211 "}\n"
213 " return $name$_.UnsafeArenaRelease($default_variable$,\n" 212 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\ n"
214 " GetArenaNoVirtual());\n" 213 " if ($name$ != NULL) {\n"
215 "}\n" 214 " $set_hasbit$\n"
216 "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) { \n" 215 " } else {\n"
217 " if ($name$ != NULL) {\n" 216 " $clear_hasbit$\n"
218 " $set_hasbit$\n" 217 " }\n"
219 " } else {\n" 218 " $name$_.SetAllocated($default_variable$, $name$,\n"
220 " $clear_hasbit$\n" 219 " GetArenaNoVirtual());\n"
221 " }\n" 220 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
222 " $name$_.SetAllocated($default_variable$, $name$,\n" 221 "}\n"
223 " GetArenaNoVirtual());\n" 222 "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(\n"
224 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" 223 " ::std::string* $name$) {\n"
225 "}\n" 224 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
226 "$inline$void $classname$::unsafe_arena_set_allocated_$name$(\n" 225 " if ($name$ != NULL) {\n"
227 " ::std::string* $name$) {\n" 226 " $set_hasbit$\n"
228 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" 227 " } else {\n"
229 " if ($name$ != NULL) {\n" 228 " $clear_hasbit$\n"
230 " $set_hasbit$\n" 229 " }\n"
231 " } else {\n" 230 " $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
232 " $clear_hasbit$\n" 231 " $name$, GetArenaNoVirtual());\n"
233 " }\n" 232 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
234 " $name$_.UnsafeArenaSetAllocated($default_variable$,\n" 233 "$full_name$)\n"
235 " $name$, GetArenaNoVirtual());\n" 234 "}\n");
236 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
237 "$full_name$)\n"
238 "}\n");
239 } else { 235 } else {
240 // No-arena case. 236 // No-arena case.
241 printer->Print( 237 printer->Print(variables,
242 variables, 238 "$inline$ const ::std::string& $classname$::$name$() const {\n"
243 "$inline$const ::std::string& $classname$::$name$() const {\n" 239 " // @@protoc_insertion_point(field_get:$full_name$)\n"
244 " // @@protoc_insertion_point(field_get:$full_name$)\n" 240 " return $name$_.GetNoArena($default_variable$);\n"
245 " return $name$_.GetNoArena();\n" 241 "}\n"
246 "}\n" 242 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n"
247 "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" 243 " $set_hasbit$\n"
248 " $set_hasbit$\n" 244 " $name$_.SetNoArena($default_variable$, value);\n"
249 " $name$_.SetNoArena($default_variable$, value);\n" 245 " // @@protoc_insertion_point(field_set:$full_name$)\n"
250 " // @@protoc_insertion_point(field_set:$full_name$)\n" 246 "}\n"
251 "}\n" 247 "$inline$ void $classname$::set_$name$(const char* value) {\n"
252 "$inline$void $classname$::set_$name$(const char* value) {\n" 248 " $set_hasbit$\n"
253 " $set_hasbit$\n" 249 " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n"
254 " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n" 250 " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
255 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" 251 "}\n"
256 "}\n" 252 "$inline$ "
257 "$inline$" 253 "void $classname$::set_$name$(const $pointer_type$* value, "
258 "void $classname$::set_$name$(const $pointer_type$* value, " 254 "size_t size) {\n"
259 "size_t size) {\n" 255 " $set_hasbit$\n"
260 " $set_hasbit$\n" 256 " $name$_.SetNoArena($default_variable$,\n"
261 " $name$_.SetNoArena($default_variable$,\n" 257 " $string_piece$(reinterpret_cast<const char*>(value), size));\n"
262 " $string_piece$(reinterpret_cast<const char*>(value), size));\n" 258 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
263 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" 259 "}\n"
264 "}\n" 260 "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
265 "$inline$::std::string* $classname$::mutable_$name$() {\n" 261 " $set_hasbit$\n"
266 " $set_hasbit$\n" 262 " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
267 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" 263 " return $name$_.MutableNoArena($default_variable$);\n"
268 " return $name$_.MutableNoArena($default_variable$);\n" 264 "}\n"
269 "}\n" 265 "$inline$ ::std::string* $classname$::$release_name$() {\n"
270 "$inline$::std::string* $classname$::$release_name$() {\n" 266 " // @@protoc_insertion_point(field_release:$full_name$)\n"
271 " // @@protoc_insertion_point(field_release:$full_name$)\n" 267 " $clear_hasbit$\n"
272 " $clear_hasbit$\n" 268 " return $name$_.ReleaseNoArena($default_variable$);\n"
273 " return $name$_.ReleaseNoArena($default_variable$);\n" 269 "}\n"
274 "}\n" 270 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\ n"
275 "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) { \n" 271 " if ($name$ != NULL) {\n"
276 " if ($name$ != NULL) {\n" 272 " $set_hasbit$\n"
277 " $set_hasbit$\n" 273 " } else {\n"
278 " } else {\n" 274 " $clear_hasbit$\n"
279 " $clear_hasbit$\n" 275 " }\n"
280 " }\n" 276 " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n"
281 " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n" 277 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
282 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" 278 "}\n");
283 "}\n");
284 } 279 }
285 } 280 }
286 281
287 void StringFieldGenerator:: 282 void StringFieldGenerator::
288 GenerateNonInlineAccessorDefinitions(io::Printer* printer) const { 283 GenerateNonInlineAccessorDefinitions(io::Printer* printer) const {
289 if (!descriptor_->default_value_string().empty()) { 284 if (!descriptor_->default_value_string().empty()) {
290 // Initialized in GenerateDefaultInstanceAllocator. 285 // Initialized in GenerateDefaultInstanceAllocator.
291 printer->Print(variables_, 286 printer->Print(variables_,
292 "::google::protobuf::internal::ExplicitlyConstructed< ::std:: string> " 287 "::std::string* $classname$::$default_variable$ = NULL;\n");
293 "$classname$::$default_variable_name$;\n");
294 } 288 }
295 } 289 }
296 290
297 void StringFieldGenerator:: 291 void StringFieldGenerator::
298 GenerateClearingCode(io::Printer* printer) const { 292 GenerateClearingCode(io::Printer* printer) const {
299 // Two-dimension specialization here: supporting arenas or not, and default 293 // Two-dimension specialization here: supporting arenas or not, and default
300 // value is the empty string or not. Complexity here ensures the minimal 294 // value is the empty string or not. Complexity here ensures the minimal
301 // number of branches / amount of extraneous code at runtime (given that the 295 // number of branches / amount of extraneous code at runtime (given that the
302 // below methods are inlined one-liners)! 296 // below methods are inlined one-liners)!
303 if (SupportsArenas(descriptor_)) { 297 if (SupportsArenas(descriptor_)) {
304 if (descriptor_->default_value_string().empty()) { 298 if (descriptor_->default_value_string().empty()) {
305 printer->Print(variables_, 299 printer->Print(variables_,
306 "$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n"); 300 "$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
307 } else { 301 } else {
308 printer->Print(variables_, 302 printer->Print(variables_,
309 "$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n"); 303 "$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
310 } 304 }
311 } else { 305 } else {
312 if (descriptor_->default_value_string().empty()) { 306 if (descriptor_->default_value_string().empty()) {
313 printer->Print(variables_, 307 printer->Print(variables_,
314 "$name$_.ClearToEmptyNoArena($default_variable$);\n"); 308 "$name$_.ClearToEmptyNoArena($default_variable$);\n");
315 } else { 309 } else {
316 printer->Print(variables_, 310 printer->Print(variables_,
317 "$name$_.ClearToDefaultNoArena($default_variable$);\n"); 311 "$name$_.ClearToDefaultNoArena($default_variable$);\n");
318 } 312 }
319 } 313 }
320 } 314 }
321 315
322 void StringFieldGenerator:: 316 void StringFieldGenerator::
323 GenerateMessageClearingCode(io::Printer* printer) const {
324 // Two-dimension specialization here: supporting arenas, field presence, or
325 // not, and default value is the empty string or not. Complexity here ensures
326 // the minimal number of branches / amount of extraneous code at runtime
327 // (given that the below methods are inlined one-liners)!
328
329 // If we have field presence, then the Clear() method of the protocol buffer
330 // will have checked that this field is set. If so, we can avoid redundant
331 // checks against default_variable.
332 const bool must_be_present = HasFieldPresence(descriptor_->file());
333
334 if (must_be_present) {
335 printer->Print(variables_,
336 "GOOGLE_DCHECK(!$name$_.IsDefault($default_variable$));\n");
337 }
338
339 if (SupportsArenas(descriptor_)) {
340 if (descriptor_->default_value_string().empty()) {
341 printer->Print(variables_,
342 "$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
343 } else {
344 printer->Print(variables_,
345 "$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
346 }
347 } else if (must_be_present) {
348 // When Arenas are disabled and field presence has been checked, we can
349 // safely treat the ArenaStringPtr as a string*.
350 if (descriptor_->default_value_string().empty()) {
351 printer->Print(variables_,
352 "(*$name$_.UnsafeRawStringPointer())->clear();\n");
353 } else {
354 printer->Print(variables_,
355 "(*$name$_.UnsafeRawStringPointer())->assign(*$default_variable$);\n");
356 }
357 } else {
358 if (descriptor_->default_value_string().empty()) {
359 printer->Print(variables_,
360 "$name$_.ClearToEmptyNoArena($default_variable$);\n");
361 } else {
362 printer->Print(variables_,
363 "$name$_.ClearToDefaultNoArena($default_variable$);\n");
364 }
365 }
366 }
367
368 void StringFieldGenerator::
369 GenerateMergingCode(io::Printer* printer) const { 317 GenerateMergingCode(io::Printer* printer) const {
370 if (SupportsArenas(descriptor_) || descriptor_->containing_oneof() != NULL) { 318 if (SupportsArenas(descriptor_) || descriptor_->containing_oneof() != NULL) {
371 // TODO(gpike): improve this 319 // TODO(gpike): improve this
372 printer->Print(variables_, "set_$name$(from.$name$());\n"); 320 printer->Print(variables_, "set_$name$(from.$name$());\n");
373 } else { 321 } else {
374 printer->Print(variables_, 322 printer->Print(variables_,
375 "$set_hasbit$\n" 323 "$set_hasbit$\n"
376 "$name$_.AssignWithDefault($default_variable$, from.$name$_);\n"); 324 "$name$_.AssignWithDefault($default_variable$, from.$name$_);\n");
377 } 325 }
378 } 326 }
379 327
380 void StringFieldGenerator:: 328 void StringFieldGenerator::
381 GenerateSwappingCode(io::Printer* printer) const { 329 GenerateSwappingCode(io::Printer* printer) const {
382 printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n"); 330 printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n");
383 } 331 }
384 332
385 void StringFieldGenerator:: 333 void StringFieldGenerator::
386 GenerateConstructorCode(io::Printer* printer) const { 334 GenerateConstructorCode(io::Printer* printer) const {
387 printer->Print(variables_, 335 printer->Print(variables_,
388 "$name$_.UnsafeSetDefault($default_variable$);\n"); 336 "$name$_.UnsafeSetDefault($default_variable$);\n");
389 } 337 }
390 338
391 void StringFieldGenerator:: 339 void StringFieldGenerator::
392 GenerateCopyConstructorCode(io::Printer* printer) const {
393 GenerateConstructorCode(printer);
394
395 if (HasFieldPresence(descriptor_->file())) {
396 printer->Print(variables_,
397 "if (from.has_$name$()) {\n");
398 } else {
399 printer->Print(variables_,
400 "if (from.$name$().size() > 0) {\n");
401 }
402
403 printer->Indent();
404
405 if (SupportsArenas(descriptor_) || descriptor_->containing_oneof() != NULL) {
406 // TODO(gpike): improve this
407 printer->Print(variables_,
408 "$name$_.Set($default_variable$, from.$name$(),\n"
409 " GetArenaNoVirtual());\n");
410 } else {
411 printer->Print(variables_,
412 "$name$_.AssignWithDefault($default_variable$, from.$name$_);\n");
413 }
414
415 printer->Outdent();
416 printer->Print("}\n");
417 }
418
419 void StringFieldGenerator::
420 GenerateDestructorCode(io::Printer* printer) const { 340 GenerateDestructorCode(io::Printer* printer) const {
421 if (SupportsArenas(descriptor_)) { 341 if (SupportsArenas(descriptor_)) {
422 // The variable |arena| is defined by the enclosing code.
423 // See MessageGenerator::GenerateSharedDestructorCode.
424 printer->Print(variables_, 342 printer->Print(variables_,
425 "$name$_.Destroy($default_variable$, arena);\n"); 343 "$name$_.Destroy($default_variable$, GetArenaNoVirtual());\n");
426 } else { 344 } else {
427 printer->Print(variables_, 345 printer->Print(variables_,
428 "$name$_.DestroyNoArena($default_variable$);\n"); 346 "$name$_.DestroyNoArena($default_variable$);\n");
429 } 347 }
430 } 348 }
431 349
432 void StringFieldGenerator:: 350 void StringFieldGenerator::
433 GenerateDefaultInstanceAllocator(io::Printer* printer) const { 351 GenerateDefaultInstanceAllocator(io::Printer* printer) const {
434 if (!descriptor_->default_value_string().empty()) { 352 if (!descriptor_->default_value_string().empty()) {
435 printer->Print(variables_, 353 printer->Print(variables_,
436 "$classname$::$default_variable_name$.DefaultConstruct();\n" 354 "$classname$::$default_variable$ =\n"
437 "*$classname$::$default_variable_name$.get_mutable() = " 355 " new ::std::string($default$, $default_length$);\n");
438 "::std::string($default$, $default_length$);\n");
439 } 356 }
440 } 357 }
441 358
442 void StringFieldGenerator:: 359 void StringFieldGenerator::
443 GenerateShutdownCode(io::Printer* printer) const { 360 GenerateShutdownCode(io::Printer* printer) const {
444 if (!descriptor_->default_value_string().empty()) { 361 if (!descriptor_->default_value_string().empty()) {
445 printer->Print(variables_, 362 printer->Print(variables_,
446 "$classname$::$default_variable_name$.Shutdown();\n"); 363 "delete $classname$::$default_variable$;\n");
447 } 364 }
448 } 365 }
449 366
450 void StringFieldGenerator:: 367 void StringFieldGenerator::
451 GenerateMergeFromCodedStream(io::Printer* printer) const { 368 GenerateMergeFromCodedStream(io::Printer* printer) const {
452 printer->Print(variables_, 369 printer->Print(variables_,
453 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" 370 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n"
454 " input, this->mutable_$name$()));\n"); 371 " input, this->mutable_$name$()));\n");
455 372
456 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { 373 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 : StringFieldGenerator(descriptor, options), 418 : StringFieldGenerator(descriptor, options),
502 dependent_field_(options.proto_h) { 419 dependent_field_(options.proto_h) {
503 SetCommonOneofFieldVariables(descriptor, &variables_); 420 SetCommonOneofFieldVariables(descriptor, &variables_);
504 } 421 }
505 422
506 StringOneofFieldGenerator::~StringOneofFieldGenerator() {} 423 StringOneofFieldGenerator::~StringOneofFieldGenerator() {}
507 424
508 void StringOneofFieldGenerator:: 425 void StringOneofFieldGenerator::
509 GenerateInlineAccessorDefinitions(io::Printer* printer, 426 GenerateInlineAccessorDefinitions(io::Printer* printer,
510 bool is_inline) const { 427 bool is_inline) const {
511 std::map<string, string> variables(variables_); 428 map<string, string> variables(variables_);
512 variables["inline"] = is_inline ? "inline " : ""; 429 variables["inline"] = is_inline ? "inline" : "";
513 if (SupportsArenas(descriptor_)) { 430 if (SupportsArenas(descriptor_)) {
514 printer->Print( 431 printer->Print(variables,
515 variables, 432 "$inline$ const ::std::string& $classname$::$name$() const {\n"
516 "$inline$const ::std::string& $classname$::$name$() const {\n" 433 " // @@protoc_insertion_point(field_get:$full_name$)\n"
517 " // @@protoc_insertion_point(field_get:$full_name$)\n" 434 " if (has_$name$()) {\n"
518 " if (has_$name$()) {\n" 435 " return $oneof_prefix$$name$_.Get($default_variable$);\n"
519 " return $oneof_prefix$$name$_.Get();\n" 436 " }\n"
520 " }\n" 437 " return *$default_variable$;\n"
521 " return *$default_variable$;\n" 438 "}\n"
522 "}\n" 439 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n"
523 "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" 440 " if (!has_$name$()) {\n"
524 " if (!has_$name$()) {\n" 441 " clear_$oneof_name$();\n"
525 " clear_$oneof_name$();\n" 442 " set_has_$name$();\n"
526 " set_has_$name$();\n" 443 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
527 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 444 " }\n"
528 " }\n" 445 " $oneof_prefix$$name$_.Set($default_variable$, value,\n"
529 " $oneof_prefix$$name$_.Set($default_variable$, value,\n" 446 " GetArenaNoVirtual());\n"
530 " GetArenaNoVirtual());\n" 447 " // @@protoc_insertion_point(field_set:$full_name$)\n"
531 " // @@protoc_insertion_point(field_set:$full_name$)\n" 448 "}\n"
532 "}\n" 449 "$inline$ void $classname$::set_$name$(const char* value) {\n"
533 "$inline$void $classname$::set_$name$(const char* value) {\n" 450 " if (!has_$name$()) {\n"
534 " if (!has_$name$()) {\n" 451 " clear_$oneof_name$();\n"
535 " clear_$oneof_name$();\n" 452 " set_has_$name$();\n"
536 " set_has_$name$();\n" 453 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
537 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 454 " }\n"
538 " }\n" 455 " $oneof_prefix$$name$_.Set($default_variable$,\n"
539 " $oneof_prefix$$name$_.Set($default_variable$,\n" 456 " $string_piece$(value), GetArenaNoVirtual());\n"
540 " $string_piece$(value), GetArenaNoVirtual());\n" 457 " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
541 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" 458 "}\n"
542 "}\n" 459 "$inline$ "
543 "$inline$" 460 "void $classname$::set_$name$(const $pointer_type$* value,\n"
544 "void $classname$::set_$name$(const $pointer_type$* value,\n" 461 " size_t size) {\n"
545 " size_t size) {\n" 462 " if (!has_$name$()) {\n"
546 " if (!has_$name$()) {\n" 463 " clear_$oneof_name$();\n"
547 " clear_$oneof_name$();\n" 464 " set_has_$name$();\n"
548 " set_has_$name$();\n" 465 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
549 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 466 " }\n"
550 " }\n" 467 " $oneof_prefix$$name$_.Set($default_variable$, $string_piece$(\n"
551 " $oneof_prefix$$name$_.Set($default_variable$, $string_piece$(\n" 468 " reinterpret_cast<const char*>(value), size),\n"
552 " reinterpret_cast<const char*>(value), size),\n" 469 " GetArenaNoVirtual());\n"
553 " GetArenaNoVirtual());\n" 470 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
554 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" 471 "}\n"
555 "}\n" 472 "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
556 "$inline$::std::string* $classname$::mutable_$name$() {\n" 473 " if (!has_$name$()) {\n"
557 " if (!has_$name$()) {\n" 474 " clear_$oneof_name$();\n"
558 " clear_$oneof_name$();\n" 475 " set_has_$name$();\n"
559 " set_has_$name$();\n" 476 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
560 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 477 " }\n"
561 " }\n" 478 " return $oneof_prefix$$name$_.Mutable($default_variable$,\n"
562 " return $oneof_prefix$$name$_.Mutable($default_variable$,\n" 479 " GetArenaNoVirtual());\n"
563 " GetArenaNoVirtual());\n" 480 " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
564 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" 481 "}\n"
565 "}\n" 482 "$inline$ ::std::string* $classname$::$release_name$() {\n"
566 "$inline$::std::string* $classname$::$release_name$() {\n" 483 " // @@protoc_insertion_point(field_release:$full_name$)\n"
567 " // @@protoc_insertion_point(field_release:$full_name$)\n" 484 " if (has_$name$()) {\n"
568 " if (has_$name$()) {\n" 485 " clear_has_$oneof_name$();\n"
569 " clear_has_$oneof_name$();\n" 486 " return $oneof_prefix$$name$_.Release($default_variable$,\n"
570 " return $oneof_prefix$$name$_.Release($default_variable$,\n" 487 " GetArenaNoVirtual());\n"
571 " GetArenaNoVirtual());\n" 488 " } else {\n"
572 " } else {\n" 489 " return NULL;\n"
573 " return NULL;\n" 490 " }\n"
574 " }\n" 491 "}\n"
575 "}\n" 492 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n"
576 "$inline$::std::string* $classname$::unsafe_arena_release_$name$() {\n" 493 " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
577 " // " 494 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
578 "@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" 495 " if (has_$name$()) {\n"
579 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" 496 " clear_has_$oneof_name$();\n"
580 " if (has_$name$()) {\n" 497 " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n"
581 " clear_has_$oneof_name$();\n" 498 " $default_variable$, GetArenaNoVirtual());\n"
582 " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n" 499 " } else {\n"
583 " $default_variable$, GetArenaNoVirtual());\n" 500 " return NULL;\n"
584 " } else {\n" 501 " }\n"
585 " return NULL;\n" 502 "}\n"
586 " }\n" 503 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\ n"
587 "}\n" 504 " if (!has_$name$()) {\n"
588 "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) { \n" 505 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
589 " if (!has_$name$()) {\n" 506 " }\n"
590 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 507 " clear_$oneof_name$();\n"
591 " }\n" 508 " if ($name$ != NULL) {\n"
592 " clear_$oneof_name$();\n" 509 " set_has_$name$();\n"
593 " if ($name$ != NULL) {\n" 510 " $oneof_prefix$$name$_.SetAllocated($default_variable$, $name$,\n"
594 " set_has_$name$();\n" 511 " GetArenaNoVirtual());\n"
595 " $oneof_prefix$$name$_.SetAllocated($default_variable$, $name$,\n" 512 " }\n"
596 " GetArenaNoVirtual());\n" 513 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
597 " }\n" 514 "}\n"
598 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" 515 "$inline$ void $classname$::unsafe_arena_set_allocated_$name$("
599 "}\n" 516 "::std::string* $name$) {\n"
600 "$inline$void $classname$::unsafe_arena_set_allocated_$name$(" 517 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
601 "::std::string* $name$) {\n" 518 " if (!has_$name$()) {\n"
602 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" 519 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
603 " if (!has_$name$()) {\n" 520 " }\n"
604 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 521 " clear_$oneof_name$();\n"
605 " }\n" 522 " if ($name$) {\n"
606 " clear_$oneof_name$();\n" 523 " set_has_$name$();\n"
607 " if ($name$) {\n" 524 " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, "
608 " set_has_$name$();\n" 525 "$name$, GetArenaNoVirtual());\n"
609 " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, " 526 " }\n"
610 "$name$, GetArenaNoVirtual());\n" 527 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
611 " }\n" 528 "$full_name$)\n"
612 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" 529 "}\n");
613 "$full_name$)\n"
614 "}\n");
615 } else { 530 } else {
616 // No-arena case. 531 // No-arena case.
617 printer->Print( 532 printer->Print(variables,
618 variables, 533 "$inline$ const ::std::string& $classname$::$name$() const {\n"
619 "$inline$const ::std::string& $classname$::$name$() const {\n" 534 " // @@protoc_insertion_point(field_get:$full_name$)\n"
620 " // @@protoc_insertion_point(field_get:$full_name$)\n" 535 " if (has_$name$()) {\n"
621 " if (has_$name$()) {\n" 536 " return $oneof_prefix$$name$_.GetNoArena($default_variable$);\n"
622 " return $oneof_prefix$$name$_.GetNoArena();\n" 537 " }\n"
623 " }\n" 538 " return *$default_variable$;\n"
624 " return *$default_variable$;\n" 539 "}\n"
625 "}\n" 540 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n"
626 "$inline$void $classname$::set_$name$(const ::std::string& value) {\n" 541 " // @@protoc_insertion_point(field_set:$full_name$)\n"
627 " // @@protoc_insertion_point(field_set:$full_name$)\n" 542 " if (!has_$name$()) {\n"
628 " if (!has_$name$()) {\n" 543 " clear_$oneof_name$();\n"
629 " clear_$oneof_name$();\n" 544 " set_has_$name$();\n"
630 " set_has_$name$();\n" 545 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
631 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 546 " }\n"
632 " }\n" 547 " $oneof_prefix$$name$_.SetNoArena($default_variable$, value);\n"
633 " $oneof_prefix$$name$_.SetNoArena($default_variable$, value);\n" 548 " // @@protoc_insertion_point(field_set:$full_name$)\n"
634 " // @@protoc_insertion_point(field_set:$full_name$)\n" 549 "}\n"
635 "}\n" 550 "$inline$ void $classname$::set_$name$(const char* value) {\n"
636 "$inline$void $classname$::set_$name$(const char* value) {\n" 551 " if (!has_$name$()) {\n"
637 " if (!has_$name$()) {\n" 552 " clear_$oneof_name$();\n"
638 " clear_$oneof_name$();\n" 553 " set_has_$name$();\n"
639 " set_has_$name$();\n" 554 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
640 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 555 " }\n"
641 " }\n" 556 " $oneof_prefix$$name$_.SetNoArena($default_variable$,\n"
642 " $oneof_prefix$$name$_.SetNoArena($default_variable$,\n" 557 " $string_piece$(value));\n"
643 " $string_piece$(value));\n" 558 " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
644 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" 559 "}\n"
645 "}\n" 560 "$inline$ "
646 "$inline$" 561 "void $classname$::set_$name$(const $pointer_type$* value, size_t size) {\ n"
647 "void $classname$::set_$name$(const $pointer_type$* value, size_t " 562 " if (!has_$name$()) {\n"
648 "size) {\n" 563 " clear_$oneof_name$();\n"
649 " if (!has_$name$()) {\n" 564 " set_has_$name$();\n"
650 " clear_$oneof_name$();\n" 565 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
651 " set_has_$name$();\n" 566 " }\n"
652 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 567 " $oneof_prefix$$name$_.SetNoArena($default_variable$, $string_piece$(\n"
653 " }\n" 568 " reinterpret_cast<const char*>(value), size));\n"
654 " $oneof_prefix$$name$_.SetNoArena($default_variable$, " 569 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
655 "$string_piece$(\n" 570 "}\n"
656 " reinterpret_cast<const char*>(value), size));\n" 571 "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
657 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" 572 " if (!has_$name$()) {\n"
658 "}\n" 573 " clear_$oneof_name$();\n"
659 "$inline$::std::string* $classname$::mutable_$name$() {\n" 574 " set_has_$name$();\n"
660 " if (!has_$name$()) {\n" 575 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
661 " clear_$oneof_name$();\n" 576 " }\n"
662 " set_has_$name$();\n" 577 " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
663 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 578 " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n"
664 " }\n" 579 "}\n"
665 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" 580 "$inline$ ::std::string* $classname$::$release_name$() {\n"
666 " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n" 581 " // @@protoc_insertion_point(field_release:$full_name$)\n"
667 "}\n" 582 " if (has_$name$()) {\n"
668 "$inline$::std::string* $classname$::$release_name$() {\n" 583 " clear_has_$oneof_name$();\n"
669 " // @@protoc_insertion_point(field_release:$full_name$)\n" 584 " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n"
670 " if (has_$name$()) {\n" 585 " } else {\n"
671 " clear_has_$oneof_name$();\n" 586 " return NULL;\n"
672 " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n" 587 " }\n"
673 " } else {\n" 588 "}\n"
674 " return NULL;\n" 589 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\ n"
675 " }\n" 590 " if (!has_$name$()) {\n"
676 "}\n" 591 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
677 "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) { \n" 592 " }\n"
678 " if (!has_$name$()) {\n" 593 " clear_$oneof_name$();\n"
679 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" 594 " if ($name$ != NULL) {\n"
680 " }\n" 595 " set_has_$name$();\n"
681 " clear_$oneof_name$();\n" 596 " $oneof_prefix$$name$_.SetAllocatedNoArena($default_variable$,\n"
682 " if ($name$ != NULL) {\n" 597 " $name$);\n"
683 " set_has_$name$();\n" 598 " }\n"
684 " $oneof_prefix$$name$_.SetAllocatedNoArena($default_variable$,\n" 599 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
685 " $name$);\n" 600 "}\n");
686 " }\n"
687 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
688 "}\n");
689 } 601 }
690 } 602 }
691 603
692 void StringOneofFieldGenerator:: 604 void StringOneofFieldGenerator::
693 GenerateClearingCode(io::Printer* printer) const { 605 GenerateClearingCode(io::Printer* printer) const {
694 std::map<string, string> variables(variables_); 606 map<string, string> variables(variables_);
695 if (dependent_field_) { 607 if (dependent_field_) {
696 variables["this_message"] = DependentBaseDownCast(); 608 variables["this_message"] = DependentBaseDownCast();
697 // This clearing code may be in the dependent base class. If the default 609 // This clearing code may be in the dependent base class. If the default
698 // value is an empty string, then the $default_variable$ is a global 610 // value is an empty string, then the $default_variable$ is a global
699 // singleton. If the default is not empty, we need to down-cast to get the 611 // singleton. If the default is not empty, we need to down-cast to get the
700 // default value's global singleton instance. See SetStringVariables() for 612 // default value's global singleton instance. See SetStringVariables() for
701 // possible values of default_variable. 613 // possible values of default_variable.
702 if (!descriptor_->default_value_string().empty()) { 614 if (!descriptor_->default_value_string().empty()) {
703 variables["default_variable"] = "&" + DependentBaseDownCast() + 615 variables["default_variable"] =
704 variables["default_variable_name"] + 616 DependentBaseDownCast() + variables["default_variable"];
705 ".get()";
706 } 617 }
707 } else { 618 } else {
708 variables["this_message"] = ""; 619 variables["this_message"] = "";
709 } 620 }
710 if (SupportsArenas(descriptor_)) { 621 if (SupportsArenas(descriptor_)) {
711 printer->Print(variables, 622 printer->Print(variables,
712 "$this_message$$oneof_prefix$$name$_.Destroy($default_variable$,\n" 623 "$this_message$$oneof_prefix$$name$_.Destroy($default_variable$,\n"
713 " $this_message$GetArenaNoVirtual());\n"); 624 " $this_message$GetArenaNoVirtual());\n");
714 } else { 625 } else {
715 printer->Print(variables, 626 printer->Print(variables,
716 "$this_message$$oneof_prefix$$name$_." 627 "$this_message$$oneof_prefix$$name$_."
717 "DestroyNoArena($default_variable$);\n"); 628 "DestroyNoArena($default_variable$);\n");
718 } 629 }
719 } 630 }
720 631
721 void StringOneofFieldGenerator:: 632 void StringOneofFieldGenerator::
722 GenerateMessageClearingCode(io::Printer* printer) const {
723 return GenerateClearingCode(printer);
724 }
725
726 void StringOneofFieldGenerator::
727 GenerateSwappingCode(io::Printer* printer) const { 633 GenerateSwappingCode(io::Printer* printer) const {
728 // Don't print any swapping code. Swapping the union will swap this field. 634 // Don't print any swapping code. Swapping the union will swap this field.
729 } 635 }
730 636
731 void StringOneofFieldGenerator:: 637 void StringOneofFieldGenerator::
732 GenerateConstructorCode(io::Printer* printer) const { 638 GenerateConstructorCode(io::Printer* printer) const {
733 printer->Print( 639 printer->Print(variables_,
734 variables_, 640 " $classname$_default_oneof_instance_->$name$_.UnsafeSetDefault("
735 "$classname$_default_oneof_instance_.$name$_.UnsafeSetDefault(\n" 641 "$default_variable$);\n");
736 " $default_variable$);\n");
737 } 642 }
738 643
739 void StringOneofFieldGenerator:: 644 void StringOneofFieldGenerator::
740 GenerateDestructorCode(io::Printer* printer) const { 645 GenerateDestructorCode(io::Printer* printer) const {
741 if (SupportsArenas(descriptor_)) { 646 if (SupportsArenas(descriptor_)) {
742 printer->Print(variables_, 647 printer->Print(variables_,
743 "if (has_$name$()) {\n" 648 "if (has_$name$()) {\n"
744 " $oneof_prefix$$name$_.Destroy($default_variable$,\n" 649 " $oneof_prefix$$name$_.Destroy($default_variable$,\n"
745 " GetArenaNoVirtual());\n" 650 " GetArenaNoVirtual());\n"
746 "}\n"); 651 "}\n");
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 if (unknown_ctype) { 724 if (unknown_ctype) {
820 printer->Outdent(); 725 printer->Outdent();
821 printer->Print(" public:\n"); 726 printer->Print(" public:\n");
822 printer->Indent(); 727 printer->Indent();
823 } 728 }
824 } 729 }
825 730
826 void RepeatedStringFieldGenerator:: 731 void RepeatedStringFieldGenerator::
827 GenerateInlineAccessorDefinitions(io::Printer* printer, 732 GenerateInlineAccessorDefinitions(io::Printer* printer,
828 bool is_inline) const { 733 bool is_inline) const {
829 std::map<string, string> variables(variables_); 734 map<string, string> variables(variables_);
830 variables["inline"] = is_inline ? "inline " : ""; 735 variables["inline"] = is_inline ? "inline" : "";
831 printer->Print(variables, 736 printer->Print(variables,
832 "$inline$const ::std::string& $classname$::$name$(int index) const {\n" 737 "$inline$ const ::std::string& $classname$::$name$(int index) const {\n"
833 " // @@protoc_insertion_point(field_get:$full_name$)\n" 738 " // @@protoc_insertion_point(field_get:$full_name$)\n"
834 " return $name$_.$cppget$(index);\n" 739 " return $name$_.$cppget$(index);\n"
835 "}\n" 740 "}\n"
836 "$inline$::std::string* $classname$::mutable_$name$(int index) {\n" 741 "$inline$ ::std::string* $classname$::mutable_$name$(int index) {\n"
837 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" 742 " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
838 " return $name$_.Mutable(index);\n" 743 " return $name$_.Mutable(index);\n"
839 "}\n" 744 "}\n"
840 "$inline$void $classname$::set_$name$(int index, const ::std::string& value) {\n" 745 "$inline$ void $classname$::set_$name$(int index, const ::std::string& value ) {\n"
841 " // @@protoc_insertion_point(field_set:$full_name$)\n" 746 " // @@protoc_insertion_point(field_set:$full_name$)\n"
842 " $name$_.Mutable(index)->assign(value);\n" 747 " $name$_.Mutable(index)->assign(value);\n"
843 "}\n" 748 "}\n"
844 "$inline$void $classname$::set_$name$(int index, const char* value) {\n" 749 "$inline$ void $classname$::set_$name$(int index, const char* value) {\n"
845 " $name$_.Mutable(index)->assign(value);\n" 750 " $name$_.Mutable(index)->assign(value);\n"
846 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" 751 " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
847 "}\n" 752 "}\n"
848 "$inline$void " 753 "$inline$ void "
849 "$classname$::set_$name$" 754 "$classname$::set_$name$"
850 "(int index, const $pointer_type$* value, size_t size) {\n" 755 "(int index, const $pointer_type$* value, size_t size) {\n"
851 " $name$_.Mutable(index)->assign(\n" 756 " $name$_.Mutable(index)->assign(\n"
852 " reinterpret_cast<const char*>(value), size);\n" 757 " reinterpret_cast<const char*>(value), size);\n"
853 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" 758 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
854 "}\n" 759 "}\n"
855 "$inline$::std::string* $classname$::add_$name$() {\n" 760 "$inline$ ::std::string* $classname$::add_$name$() {\n"
856 " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n" 761 " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n"
857 " return $name$_.Add();\n" 762 " return $name$_.Add();\n"
858 "}\n" 763 "}\n"
859 "$inline$void $classname$::add_$name$(const ::std::string& value) {\n" 764 "$inline$ void $classname$::add_$name$(const ::std::string& value) {\n"
860 " $name$_.Add()->assign(value);\n" 765 " $name$_.Add()->assign(value);\n"
861 " // @@protoc_insertion_point(field_add:$full_name$)\n" 766 " // @@protoc_insertion_point(field_add:$full_name$)\n"
862 "}\n" 767 "}\n"
863 "$inline$void $classname$::add_$name$(const char* value) {\n" 768 "$inline$ void $classname$::add_$name$(const char* value) {\n"
864 " $name$_.Add()->assign(value);\n" 769 " $name$_.Add()->assign(value);\n"
865 " // @@protoc_insertion_point(field_add_char:$full_name$)\n" 770 " // @@protoc_insertion_point(field_add_char:$full_name$)\n"
866 "}\n" 771 "}\n"
867 "$inline$void " 772 "$inline$ void "
868 "$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n" 773 "$classname$::add_$name$(const $pointer_type$* value, size_t size) {\n"
869 " $name$_.Add()->assign(reinterpret_cast<const char*>(value), size);\n" 774 " $name$_.Add()->assign(reinterpret_cast<const char*>(value), size);\n"
870 " // @@protoc_insertion_point(field_add_pointer:$full_name$)\n" 775 " // @@protoc_insertion_point(field_add_pointer:$full_name$)\n"
871 "}\n"); 776 "}\n");
872 printer->Print(variables, 777 printer->Print(variables,
873 "$inline$const ::google::protobuf::RepeatedPtrField< ::std::string>&\n" 778 "$inline$ const ::google::protobuf::RepeatedPtrField< ::std::string>&\n"
874 "$classname$::$name$() const {\n" 779 "$classname$::$name$() const {\n"
875 " // @@protoc_insertion_point(field_list:$full_name$)\n" 780 " // @@protoc_insertion_point(field_list:$full_name$)\n"
876 " return $name$_;\n" 781 " return $name$_;\n"
877 "}\n" 782 "}\n"
878 "$inline$::google::protobuf::RepeatedPtrField< ::std::string>*\n" 783 "$inline$ ::google::protobuf::RepeatedPtrField< ::std::string>*\n"
879 "$classname$::mutable_$name$() {\n" 784 "$classname$::mutable_$name$() {\n"
880 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n" 785 " // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
881 " return &$name$_;\n" 786 " return &$name$_;\n"
882 "}\n"); 787 "}\n");
883 } 788 }
884 789
885 void RepeatedStringFieldGenerator:: 790 void RepeatedStringFieldGenerator::
886 GenerateClearingCode(io::Printer* printer) const { 791 GenerateClearingCode(io::Printer* printer) const {
887 printer->Print(variables_, "$name$_.Clear();\n"); 792 printer->Print(variables_, "$name$_.Clear();\n");
888 } 793 }
889 794
890 void RepeatedStringFieldGenerator:: 795 void RepeatedStringFieldGenerator::
891 GenerateMergingCode(io::Printer* printer) const { 796 GenerateMergingCode(io::Printer* printer) const {
892 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n"); 797 printer->Print(variables_, "$name$_.MergeFrom(from.$name$_);\n");
893 } 798 }
894 799
895 void RepeatedStringFieldGenerator:: 800 void RepeatedStringFieldGenerator::
896 GenerateSwappingCode(io::Printer* printer) const { 801 GenerateSwappingCode(io::Printer* printer) const {
897 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n"); 802 printer->Print(variables_, "$name$_.UnsafeArenaSwap(&other->$name$_);\n");
898 } 803 }
899 804
900 void RepeatedStringFieldGenerator:: 805 void RepeatedStringFieldGenerator::
901 GenerateConstructorCode(io::Printer* printer) const { 806 GenerateConstructorCode(io::Printer* printer) const {
902 // Not needed for repeated fields. 807 // Not needed for repeated fields.
903 } 808 }
904 809
905 void RepeatedStringFieldGenerator:: 810 void RepeatedStringFieldGenerator::
906 GenerateCopyConstructorCode(io::Printer* printer) const {
907 printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);");
908 }
909
910 void RepeatedStringFieldGenerator::
911 GenerateMergeFromCodedStream(io::Printer* printer) const { 811 GenerateMergeFromCodedStream(io::Printer* printer) const {
912 printer->Print(variables_, 812 printer->Print(variables_,
913 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" 813 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n"
914 " input, this->add_$name$()));\n"); 814 " input, this->add_$name$()));\n");
915 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { 815 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
916 GenerateUtf8CheckCodeForString( 816 GenerateUtf8CheckCodeForString(
917 descriptor_, options_, true, variables_, 817 descriptor_, options_, true, variables_,
918 "this->$name$(this->$name$_size() - 1).data(),\n" 818 "this->$name$(this->$name$_size() - 1).data(),\n"
919 "this->$name$(this->$name$_size() - 1).length(),\n", 819 "this->$name$(this->$name$_size() - 1).length(),\n",
920 printer); 820 printer);
(...skipping 30 matching lines...) Expand all
951 printer->Outdent(); 851 printer->Outdent();
952 printer->Print(variables_, 852 printer->Print(variables_,
953 " target = ::google::protobuf::internal::WireFormatLite::\n" 853 " target = ::google::protobuf::internal::WireFormatLite::\n"
954 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n" 854 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n"
955 "}\n"); 855 "}\n");
956 } 856 }
957 857
958 void RepeatedStringFieldGenerator:: 858 void RepeatedStringFieldGenerator::
959 GenerateByteSize(io::Printer* printer) const { 859 GenerateByteSize(io::Printer* printer) const {
960 printer->Print(variables_, 860 printer->Print(variables_,
961 "total_size += $tag_size$ *\n" 861 "total_size += $tag_size$ * this->$name$_size();\n"
962 " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n"
963 "for (int i = 0; i < this->$name$_size(); i++) {\n" 862 "for (int i = 0; i < this->$name$_size(); i++) {\n"
964 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ e$Size(\n" 863 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ e$Size(\n"
965 " this->$name$(i));\n" 864 " this->$name$(i));\n"
966 "}\n"); 865 "}\n");
967 } 866 }
968 867
969 } // namespace cpp 868 } // namespace cpp
970 } // namespace compiler 869 } // namespace compiler
971 } // namespace protobuf 870 } // namespace protobuf
972 } // namespace google 871 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698