| 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 // 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return fields; | 173 return fields; |
| 174 } | 174 } |
| 175 } // namespace | 175 } // namespace |
| 176 | 176 |
| 177 MessageGenerator::MessageGenerator(const string& root_classname, | 177 MessageGenerator::MessageGenerator(const string& root_classname, |
| 178 const Descriptor* descriptor, | 178 const Descriptor* descriptor, |
| 179 const Options& options) | 179 const Options& options) |
| 180 : root_classname_(root_classname), | 180 : root_classname_(root_classname), |
| 181 descriptor_(descriptor), | 181 descriptor_(descriptor), |
| 182 field_generators_(descriptor, options), | 182 field_generators_(descriptor, options), |
| 183 class_name_(ClassName(descriptor_)) { | 183 class_name_(ClassName(descriptor_)), |
| 184 deprecated_attribute_( |
| 185 GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false,
true)) { |
| 186 |
| 184 for (int i = 0; i < descriptor_->extension_count(); i++) { | 187 for (int i = 0; i < descriptor_->extension_count(); i++) { |
| 185 extension_generators_.push_back( | 188 extension_generators_.push_back( |
| 186 new ExtensionGenerator(class_name_, descriptor_->extension(i))); | 189 new ExtensionGenerator(class_name_, descriptor_->extension(i))); |
| 187 } | 190 } |
| 188 | 191 |
| 189 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { | 192 for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { |
| 190 OneofGenerator* generator = new OneofGenerator(descriptor_->oneof_decl(i)); | 193 OneofGenerator* generator = new OneofGenerator(descriptor_->oneof_decl(i)); |
| 191 oneof_generators_.push_back(generator); | 194 oneof_generators_.push_back(generator); |
| 192 } | 195 } |
| 193 | 196 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 242 } |
| 240 } | 243 } |
| 241 | 244 |
| 242 for (vector<MessageGenerator*>::iterator iter = | 245 for (vector<MessageGenerator*>::iterator iter = |
| 243 nested_message_generators_.begin(); | 246 nested_message_generators_.begin(); |
| 244 iter != nested_message_generators_.end(); ++iter) { | 247 iter != nested_message_generators_.end(); ++iter) { |
| 245 (*iter)->DetermineForwardDeclarations(fwd_decls); | 248 (*iter)->DetermineForwardDeclarations(fwd_decls); |
| 246 } | 249 } |
| 247 } | 250 } |
| 248 | 251 |
| 252 bool MessageGenerator::IncludesOneOfDefinition() const { |
| 253 if (!oneof_generators_.empty()) { |
| 254 return true; |
| 255 } |
| 256 |
| 257 for (vector<MessageGenerator*>::const_iterator iter = |
| 258 nested_message_generators_.begin(); |
| 259 iter != nested_message_generators_.end(); ++iter) { |
| 260 if ((*iter)->IncludesOneOfDefinition()) { |
| 261 return true; |
| 262 } |
| 263 } |
| 264 |
| 265 return false; |
| 266 } |
| 267 |
| 249 void MessageGenerator::GenerateEnumHeader(io::Printer* printer) { | 268 void MessageGenerator::GenerateEnumHeader(io::Printer* printer) { |
| 250 for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin(); | 269 for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin(); |
| 251 iter != enum_generators_.end(); ++iter) { | 270 iter != enum_generators_.end(); ++iter) { |
| 252 (*iter)->GenerateHeader(printer); | 271 (*iter)->GenerateHeader(printer); |
| 253 } | 272 } |
| 254 | 273 |
| 255 for (vector<MessageGenerator*>::iterator iter = | 274 for (vector<MessageGenerator*>::iterator iter = |
| 256 nested_message_generators_.begin(); | 275 nested_message_generators_.begin(); |
| 257 iter != nested_message_generators_.end(); ++iter) { | 276 iter != nested_message_generators_.end(); ++iter) { |
| 258 (*iter)->GenerateEnumHeader(printer); | 277 (*iter)->GenerateEnumHeader(printer); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 327 } |
| 309 | 328 |
| 310 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); | 329 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); |
| 311 iter != oneof_generators_.end(); ++iter) { | 330 iter != oneof_generators_.end(); ++iter) { |
| 312 (*iter)->GenerateCaseEnum(printer); | 331 (*iter)->GenerateCaseEnum(printer); |
| 313 } | 332 } |
| 314 | 333 |
| 315 string message_comments; | 334 string message_comments; |
| 316 SourceLocation location; | 335 SourceLocation location; |
| 317 if (descriptor_->GetSourceLocation(&location)) { | 336 if (descriptor_->GetSourceLocation(&location)) { |
| 318 message_comments = BuildCommentsString(location); | 337 message_comments = BuildCommentsString(location, false); |
| 319 } else { | 338 } else { |
| 320 message_comments = ""; | 339 message_comments = ""; |
| 321 } | 340 } |
| 322 | 341 |
| 323 printer->Print( | 342 printer->Print( |
| 324 "$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n", | 343 "$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n", |
| 325 "classname", class_name_, | 344 "classname", class_name_, |
| 326 "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, false,
true), | 345 "deprecated_attribute", deprecated_attribute_, |
| 327 "comments", message_comments); | 346 "comments", message_comments); |
| 328 | 347 |
| 329 vector<char> seen_oneofs(descriptor_->oneof_decl_count(), 0); | 348 vector<char> seen_oneofs(descriptor_->oneof_decl_count(), 0); |
| 330 for (int i = 0; i < descriptor_->field_count(); i++) { | 349 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 331 const FieldDescriptor* field = descriptor_->field(i); | 350 const FieldDescriptor* field = descriptor_->field(i); |
| 332 if (field->containing_oneof() != NULL) { | 351 if (field->containing_oneof() != NULL) { |
| 333 const int oneof_index = field->containing_oneof()->index(); | 352 const int oneof_index = field->containing_oneof()->index(); |
| 334 if (!seen_oneofs[oneof_index]) { | 353 if (!seen_oneofs[oneof_index]) { |
| 335 seen_oneofs[oneof_index] = 1; | 354 seen_oneofs[oneof_index] = 1; |
| 336 oneof_generators_[oneof_index]->GeneratePublicCasePropertyDeclaration( | 355 oneof_generators_[oneof_index]->GeneratePublicCasePropertyDeclaration( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 392 } |
| 374 } | 393 } |
| 375 | 394 |
| 376 void MessageGenerator::GenerateSource(io::Printer* printer) { | 395 void MessageGenerator::GenerateSource(io::Printer* printer) { |
| 377 if (!IsMapEntryMessage(descriptor_)) { | 396 if (!IsMapEntryMessage(descriptor_)) { |
| 378 printer->Print( | 397 printer->Print( |
| 379 "#pragma mark - $classname$\n" | 398 "#pragma mark - $classname$\n" |
| 380 "\n", | 399 "\n", |
| 381 "classname", class_name_); | 400 "classname", class_name_); |
| 382 | 401 |
| 402 if (!deprecated_attribute_.empty()) { |
| 403 // No warnings when compiling the impl of this deprecated class. |
| 404 printer->Print( |
| 405 "#pragma clang diagnostic push\n" |
| 406 "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n" |
| 407 "\n"); |
| 408 } |
| 409 |
| 383 printer->Print("@implementation $classname$\n\n", | 410 printer->Print("@implementation $classname$\n\n", |
| 384 "classname", class_name_); | 411 "classname", class_name_); |
| 385 | 412 |
| 386 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); | 413 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); |
| 387 iter != oneof_generators_.end(); ++iter) { | 414 iter != oneof_generators_.end(); ++iter) { |
| 388 (*iter)->GeneratePropertyImplementation(printer); | 415 (*iter)->GeneratePropertyImplementation(printer); |
| 389 } | 416 } |
| 390 | 417 |
| 391 for (int i = 0; i < descriptor_->field_count(); i++) { | 418 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 392 field_generators_.get(descriptor_->field(i)) | 419 field_generators_.get(descriptor_->field(i)) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 vars["fields_count"] = "0"; | 525 vars["fields_count"] = "0"; |
| 499 } | 526 } |
| 500 | 527 |
| 501 std::vector<string> init_flags; | 528 std::vector<string> init_flags; |
| 502 if (need_defaults) { | 529 if (need_defaults) { |
| 503 init_flags.push_back("GPBDescriptorInitializationFlag_FieldsWithDefault"); | 530 init_flags.push_back("GPBDescriptorInitializationFlag_FieldsWithDefault"); |
| 504 } | 531 } |
| 505 if (descriptor_->options().message_set_wire_format()) { | 532 if (descriptor_->options().message_set_wire_format()) { |
| 506 init_flags.push_back("GPBDescriptorInitializationFlag_WireFormat"); | 533 init_flags.push_back("GPBDescriptorInitializationFlag_WireFormat"); |
| 507 } | 534 } |
| 508 vars["init_flags"] = BuildFlagsString(init_flags); | 535 vars["init_flags"] = BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION, |
| 536 init_flags); |
| 509 | 537 |
| 510 printer->Print( | 538 printer->Print( |
| 511 vars, | 539 vars, |
| 512 " GPBDescriptor *localDescriptor =\n" | 540 " GPBDescriptor *localDescriptor =\n" |
| 513 " [GPBDescriptor allocDescriptorForClass:[$classname$ class]\n" | 541 " [GPBDescriptor allocDescriptorForClass:[$classname$ class]\n" |
| 514 " rootClass:[$rootclassname$ class]\
n" | 542 " rootClass:[$rootclassname$ class]\
n" |
| 515 " file:$rootclassname$_FileDesc
riptor()\n" | 543 " file:$rootclassname$_FileDesc
riptor()\n" |
| 516 " fields:$fields$\n" | 544 " fields:$fields$\n" |
| 517 " fieldCount:$fields_count$\n" | 545 " fieldCount:$fields_count$\n" |
| 518 " storageSize:sizeof($classname$__stor
age_)\n" | 546 " storageSize:sizeof($classname$__stor
age_)\n" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 for (int i = 0; i < sorted_extensions.size(); i++) { | 584 for (int i = 0; i < sorted_extensions.size(); i++) { |
| 557 printer->Print(" { .start = $start$, .end = $end$ },\n", | 585 printer->Print(" { .start = $start$, .end = $end$ },\n", |
| 558 "start", SimpleItoa(sorted_extensions[i]->start), | 586 "start", SimpleItoa(sorted_extensions[i]->start), |
| 559 "end", SimpleItoa(sorted_extensions[i]->end)); | 587 "end", SimpleItoa(sorted_extensions[i]->end)); |
| 560 } | 588 } |
| 561 printer->Print( | 589 printer->Print( |
| 562 " };\n" | 590 " };\n" |
| 563 " [localDescriptor setupExtensionRanges:ranges\n" | 591 " [localDescriptor setupExtensionRanges:ranges\n" |
| 564 " count:(uint32_t)(sizeof(ranges) /
sizeof(GPBExtensionRange))];\n"); | 592 " count:(uint32_t)(sizeof(ranges) /
sizeof(GPBExtensionRange))];\n"); |
| 565 } | 593 } |
| 594 if (descriptor_->containing_type() != NULL) { |
| 595 string parent_class_name = ClassName(descriptor_->containing_type()); |
| 596 printer->Print( |
| 597 " [localDescriptor setupContainingMessageClassName:GPBStringifySymb
ol($parent_name$)];\n", |
| 598 "parent_name", parent_class_name); |
| 599 } |
| 600 string suffix_added; |
| 601 ClassName(descriptor_, &suffix_added); |
| 602 if (suffix_added.size() > 0) { |
| 603 printer->Print( |
| 604 " [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n", |
| 605 "suffix", suffix_added); |
| 606 } |
| 566 printer->Print( | 607 printer->Print( |
| 567 " NSAssert(descriptor == nil, @\"Startup recursed!\");\n" | 608 " NSAssert(descriptor == nil, @\"Startup recursed!\");\n" |
| 568 " descriptor = localDescriptor;\n" | 609 " descriptor = localDescriptor;\n" |
| 569 " }\n" | 610 " }\n" |
| 570 " return descriptor;\n" | 611 " return descriptor;\n" |
| 571 "}\n\n" | 612 "}\n\n" |
| 572 "@end\n\n"); | 613 "@end\n\n"); |
| 573 | 614 |
| 615 if (!deprecated_attribute_.empty()) { |
| 616 printer->Print( |
| 617 "#pragma clang diagnostic pop\n" |
| 618 "\n"); |
| 619 } |
| 620 |
| 574 for (int i = 0; i < descriptor_->field_count(); i++) { | 621 for (int i = 0; i < descriptor_->field_count(); i++) { |
| 575 field_generators_.get(descriptor_->field(i)) | 622 field_generators_.get(descriptor_->field(i)) |
| 576 .GenerateCFunctionImplementations(printer); | 623 .GenerateCFunctionImplementations(printer); |
| 577 } | 624 } |
| 578 | 625 |
| 579 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); | 626 for (vector<OneofGenerator*>::iterator iter = oneof_generators_.begin(); |
| 580 iter != oneof_generators_.end(); ++iter) { | 627 iter != oneof_generators_.end(); ++iter) { |
| 581 (*iter)->GenerateClearFunctionImplementation(printer); | 628 (*iter)->GenerateClearFunctionImplementation(printer); |
| 582 } | 629 } |
| 583 } | 630 } |
| 584 | 631 |
| 585 for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin(); | 632 for (vector<EnumGenerator*>::iterator iter = enum_generators_.begin(); |
| 586 iter != enum_generators_.end(); ++iter) { | 633 iter != enum_generators_.end(); ++iter) { |
| 587 (*iter)->GenerateSource(printer); | 634 (*iter)->GenerateSource(printer); |
| 588 } | 635 } |
| 589 | 636 |
| 590 for (vector<MessageGenerator*>::iterator iter = | 637 for (vector<MessageGenerator*>::iterator iter = |
| 591 nested_message_generators_.begin(); | 638 nested_message_generators_.begin(); |
| 592 iter != nested_message_generators_.end(); ++iter) { | 639 iter != nested_message_generators_.end(); ++iter) { |
| 593 (*iter)->GenerateSource(printer); | 640 (*iter)->GenerateSource(printer); |
| 594 } | 641 } |
| 595 } | 642 } |
| 596 | 643 |
| 597 } // namespace objectivec | 644 } // namespace objectivec |
| 598 } // namespace compiler | 645 } // namespace compiler |
| 599 } // namespace protobuf | 646 } // namespace protobuf |
| 600 } // namespace google | 647 } // namespace google |
| OLD | NEW |