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