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

Side by Side Diff: third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } else { 57 } else {
58 raw_field_name = descriptor->name(); 58 raw_field_name = descriptor->name();
59 } 59 }
60 // The logic here has to match -[GGPBFieldDescriptor textFormatName]. 60 // The logic here has to match -[GGPBFieldDescriptor textFormatName].
61 const string un_camel_case_name( 61 const string un_camel_case_name(
62 UnCamelCaseFieldName(camel_case_name, descriptor)); 62 UnCamelCaseFieldName(camel_case_name, descriptor));
63 const bool needs_custom_name = (raw_field_name != un_camel_case_name); 63 const bool needs_custom_name = (raw_field_name != un_camel_case_name);
64 64
65 SourceLocation location; 65 SourceLocation location;
66 if (descriptor->GetSourceLocation(&location)) { 66 if (descriptor->GetSourceLocation(&location)) {
67 (*variables)["comments"] = BuildCommentsString(location); 67 (*variables)["comments"] = BuildCommentsString(location, true);
68 } else { 68 } else {
69 (*variables)["comments"] = "\n"; 69 (*variables)["comments"] = "\n";
70 } 70 }
71 const string& classname = ClassName(descriptor->containing_type()); 71 const string& classname = ClassName(descriptor->containing_type());
72 (*variables)["classname"] = classname; 72 (*variables)["classname"] = classname;
73 (*variables)["name"] = camel_case_name; 73 (*variables)["name"] = camel_case_name;
74 const string& capitalized_name = FieldNameCapitalized(descriptor); 74 const string& capitalized_name = FieldNameCapitalized(descriptor);
75 (*variables)["capitalized_name"] = capitalized_name; 75 (*variables)["capitalized_name"] = capitalized_name;
76 (*variables)["raw_field_name"] = raw_field_name; 76 (*variables)["raw_field_name"] = raw_field_name;
77 (*variables)["field_number_name"] = 77 (*variables)["field_number_name"] =
78 classname + "_FieldNumber_" + capitalized_name; 78 classname + "_FieldNumber_" + capitalized_name;
79 (*variables)["field_number"] = SimpleItoa(descriptor->number()); 79 (*variables)["field_number"] = SimpleItoa(descriptor->number());
80 (*variables)["field_type"] = GetCapitalizedType(descriptor); 80 (*variables)["field_type"] = GetCapitalizedType(descriptor);
81 (*variables)["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descript or); 81 (*variables)["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descript or);
82 std::vector<string> field_flags; 82 std::vector<string> field_flags;
83 if (descriptor->is_repeated()) field_flags.push_back("GPBFieldRepeated"); 83 if (descriptor->is_repeated()) field_flags.push_back("GPBFieldRepeated");
84 if (descriptor->is_required()) field_flags.push_back("GPBFieldRequired"); 84 if (descriptor->is_required()) field_flags.push_back("GPBFieldRequired");
85 if (descriptor->is_optional()) field_flags.push_back("GPBFieldOptional"); 85 if (descriptor->is_optional()) field_flags.push_back("GPBFieldOptional");
86 if (descriptor->is_packed()) field_flags.push_back("GPBFieldPacked"); 86 if (descriptor->is_packed()) field_flags.push_back("GPBFieldPacked");
87 87
88 // ObjC custom flags. 88 // ObjC custom flags.
89 if (descriptor->has_default_value()) 89 if (descriptor->has_default_value())
90 field_flags.push_back("GPBFieldHasDefaultValue"); 90 field_flags.push_back("GPBFieldHasDefaultValue");
91 if (needs_custom_name) field_flags.push_back("GPBFieldTextFormatNameCustom"); 91 if (needs_custom_name) field_flags.push_back("GPBFieldTextFormatNameCustom");
92 if (descriptor->type() == FieldDescriptor::TYPE_ENUM) { 92 if (descriptor->type() == FieldDescriptor::TYPE_ENUM) {
93 field_flags.push_back("GPBFieldHasEnumDescriptor"); 93 field_flags.push_back("GPBFieldHasEnumDescriptor");
94 } 94 }
95 95
96 (*variables)["fieldflags"] = BuildFlagsString(field_flags); 96 (*variables)["fieldflags"] = BuildFlagsString(FLAGTYPE_FIELD, field_flags);
97 97
98 (*variables)["default"] = DefaultValue(descriptor); 98 (*variables)["default"] = DefaultValue(descriptor);
99 (*variables)["default_name"] = GPBGenericValueFieldName(descriptor); 99 (*variables)["default_name"] = GPBGenericValueFieldName(descriptor);
100 100
101 (*variables)["dataTypeSpecific_name"] = "className"; 101 (*variables)["dataTypeSpecific_name"] = "className";
102 (*variables)["dataTypeSpecific_value"] = "NULL"; 102 (*variables)["dataTypeSpecific_value"] = "NULL";
103 103
104 (*variables)["storage_offset_value"] = 104 (*variables)["storage_offset_value"] =
105 "(uint32_t)offsetof(" + classname + "__storage_, " + camel_case_name + ")" ; 105 "(uint32_t)offsetof(" + classname + "__storage_, " + camel_case_name + ")" ;
106 (*variables)["storage_offset_comment"] = ""; 106 (*variables)["storage_offset_comment"] = "";
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 variables_["has_index"] = "GPBNoHasBit"; 221 variables_["has_index"] = "GPBNoHasBit";
222 } 222 }
223 223
224 int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const { 224 int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const {
225 return 0; 225 return 0;
226 } 226 }
227 227
228 void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) { 228 void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) {
229 // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some 229 // NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
230 // error cases, so it seems to be ok to use as a back door for errors. 230 // error cases, so it seems to be ok to use as a back door for errors.
231 cerr << "Error: should have overriden SetExtraRuntimeHasBitsBase()." << endl; 231 cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << endl;
232 cerr.flush(); 232 cerr.flush();
233 abort(); 233 abort();
234 } 234 }
235 235
236 void FieldGenerator::SetOneofIndexBase(int index_base) { 236 void FieldGenerator::SetOneofIndexBase(int index_base) {
237 if (descriptor_->containing_oneof() != NULL) { 237 if (descriptor_->containing_oneof() != NULL) {
238 int index = descriptor_->containing_oneof()->index() + index_base; 238 int index = descriptor_->containing_oneof()->index() + index_base;
239 // Flip the sign to mark it as a oneof. 239 // Flip the sign to mark it as a oneof.
240 variables_["has_index"] = SimpleItoa(-index); 240 variables_["has_index"] = SimpleItoa(-index);
241 } 241 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // it uses pointers and deals with Objective C's rules around storage name 328 // it uses pointers and deals with Objective C's rules around storage name
329 // conventions (init*, new*, etc.) 329 // conventions (init*, new*, etc.)
330 330
331 printer->Print(variables_, "$comments$"); 331 printer->Print(variables_, "$comments$");
332 printer->Print( 332 printer->Print(
333 variables_, 333 variables_,
334 "@property(nonatomic, readwrite, $property_storage_attribute$, null_resett able) $property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n"); 334 "@property(nonatomic, readwrite, $property_storage_attribute$, null_resett able) $property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n");
335 if (WantsHasProperty()) { 335 if (WantsHasProperty()) {
336 printer->Print( 336 printer->Print(
337 variables_, 337 variables_,
338 "/// Test to see if @c $name$ has been set.\n" 338 "/** Test to see if @c $name$ has been set. */\n"
339 "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_a ttribute$;\n"); 339 "@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_a ttribute$;\n");
340 } 340 }
341 if (IsInitName(variables_.find("name")->second)) { 341 if (IsInitName(variables_.find("name")->second)) {
342 // If property name starts with init we need to annotate it to get past ARC. 342 // If property name starts with init we need to annotate it to get past ARC.
343 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objectiv e-c-property-with-an-objc-method-family/18723227#18723227 343 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objectiv e-c-property-with-an-objc-method-family/18723227#18723227
344 printer->Print(variables_, 344 printer->Print(variables_,
345 "- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecate d_attribute$;\n"); 345 "- ($property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$deprecate d_attribute$;\n");
346 } 346 }
347 printer->Print("\n"); 347 printer->Print("\n");
348 } 348 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // *Count (to check without autocreation). So for the field property we need 380 // *Count (to check without autocreation). So for the field property we need
381 // the same logic as ObjCObjFieldGenerator::GeneratePropertyDeclaration() for 381 // the same logic as ObjCObjFieldGenerator::GeneratePropertyDeclaration() for
382 // dealing with needing Objective C's rules around storage name conventions 382 // dealing with needing Objective C's rules around storage name conventions
383 // (init*, new*, etc.) 383 // (init*, new*, etc.)
384 384
385 printer->Print( 385 printer->Print(
386 variables_, 386 variables_,
387 "$comments$" 387 "$comments$"
388 "$array_comment$" 388 "$array_comment$"
389 "@property(nonatomic, readwrite, strong, null_resettable) $array_property_ type$ *$name$$storage_attribute$$deprecated_attribute$;\n" 389 "@property(nonatomic, readwrite, strong, null_resettable) $array_property_ type$ *$name$$storage_attribute$$deprecated_attribute$;\n"
390 "/// The number of items in @c $name$ without causing the array to be crea ted.\n" 390 "/** The number of items in @c $name$ without causing the array to be crea ted. */\n"
391 "@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribu te$;\n"); 391 "@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribu te$;\n");
392 if (IsInitName(variables_.find("name")->second)) { 392 if (IsInitName(variables_.find("name")->second)) {
393 // If property name starts with init we need to annotate it to get past ARC. 393 // If property name starts with init we need to annotate it to get past ARC.
394 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objectiv e-c-property-with-an-objc-method-family/18723227#18723227 394 // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objectiv e-c-property-with-an-objc-method-family/18723227#18723227
395 printer->Print(variables_, 395 printer->Print(variables_,
396 "- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$dep recated_attribute$;\n"); 396 "- ($array_property_type$ *)$name$ GPB_METHOD_FAMILY_NONE$dep recated_attribute$;\n");
397 } 397 }
398 printer->Print("\n"); 398 printer->Print("\n");
399 } 399 }
400 400
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 } 468 }
469 } 469 }
470 470
471 return false; 471 return false;
472 } 472 }
473 473
474 } // namespace objectivec 474 } // namespace objectivec
475 } // namespace compiler 475 } // namespace compiler
476 } // namespace protobuf 476 } // namespace protobuf
477 } // namespace google 477 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698