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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 had_errors_ = false; | 518 had_errors_ = false; |
519 syntax_identifier_.clear(); | 519 syntax_identifier_.clear(); |
520 | 520 |
521 // Note that |file| could be NULL at this point if | 521 // Note that |file| could be NULL at this point if |
522 // stop_after_syntax_identifier_ is true. So, we conservatively allocate | 522 // stop_after_syntax_identifier_ is true. So, we conservatively allocate |
523 // SourceCodeInfo on the stack, then swap it into the FileDescriptorProto | 523 // SourceCodeInfo on the stack, then swap it into the FileDescriptorProto |
524 // later on. | 524 // later on. |
525 SourceCodeInfo source_code_info; | 525 SourceCodeInfo source_code_info; |
526 source_code_info_ = &source_code_info; | 526 source_code_info_ = &source_code_info; |
527 | 527 |
528 vector<string> top_doc_comments; | |
529 if (LookingAtType(io::Tokenizer::TYPE_START)) { | 528 if (LookingAtType(io::Tokenizer::TYPE_START)) { |
530 // Advance to first token. | 529 // Advance to first token. |
531 input_->NextWithComments(NULL, &upcoming_detached_comments_, | 530 input_->NextWithComments(NULL, &upcoming_detached_comments_, |
532 &upcoming_doc_comments_); | 531 &upcoming_doc_comments_); |
533 } | 532 } |
534 | 533 |
535 { | 534 { |
536 LocationRecorder root_location(this); | 535 LocationRecorder root_location(this); |
537 | 536 |
538 if (require_syntax_identifier_ || LookingAt("syntax")) { | 537 if (require_syntax_identifier_ || LookingAt("syntax")) { |
(...skipping 25 matching lines...) Expand all Loading... |
564 AddError("Unmatched \"}\"."); | 563 AddError("Unmatched \"}\"."); |
565 input_->NextWithComments(NULL, &upcoming_detached_comments_, | 564 input_->NextWithComments(NULL, &upcoming_detached_comments_, |
566 &upcoming_doc_comments_); | 565 &upcoming_doc_comments_); |
567 } | 566 } |
568 } | 567 } |
569 } | 568 } |
570 } | 569 } |
571 | 570 |
572 input_ = NULL; | 571 input_ = NULL; |
573 source_code_info_ = NULL; | 572 source_code_info_ = NULL; |
| 573 assert(file != NULL); |
574 source_code_info.Swap(file->mutable_source_code_info()); | 574 source_code_info.Swap(file->mutable_source_code_info()); |
575 return !had_errors_; | 575 return !had_errors_; |
576 } | 576 } |
577 | 577 |
578 bool Parser::ParseSyntaxIdentifier(const LocationRecorder& parent) { | 578 bool Parser::ParseSyntaxIdentifier(const LocationRecorder& parent) { |
579 LocationRecorder syntax_location(parent, | 579 LocationRecorder syntax_location(parent, |
580 FileDescriptorProto::kSyntaxFieldNumber); | 580 FileDescriptorProto::kSyntaxFieldNumber); |
581 DO(Consume( | 581 DO(Consume( |
582 "syntax", | 582 "syntax", |
583 "File must begin with a syntax statement, e.g. 'syntax = \"proto2\";'.")); | 583 "File must begin with a syntax statement, e.g. 'syntax = \"proto2\";'.")); |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 } | 1623 } |
1624 | 1624 |
1625 DO(ConsumeEndOfDeclaration("{", &oneof_location)); | 1625 DO(ConsumeEndOfDeclaration("{", &oneof_location)); |
1626 | 1626 |
1627 do { | 1627 do { |
1628 if (AtEnd()) { | 1628 if (AtEnd()) { |
1629 AddError("Reached end of input in oneof definition (missing '}')."); | 1629 AddError("Reached end of input in oneof definition (missing '}')."); |
1630 return false; | 1630 return false; |
1631 } | 1631 } |
1632 | 1632 |
| 1633 if (LookingAt("option")) { |
| 1634 LocationRecorder option_location( |
| 1635 oneof_location, OneofDescriptorProto::kOptionsFieldNumber); |
| 1636 if (!ParseOption(oneof_decl->mutable_options(), option_location, |
| 1637 containing_file, OPTION_STATEMENT)) { |
| 1638 return false; |
| 1639 } |
| 1640 continue; |
| 1641 } |
| 1642 |
1633 // Print a nice error if the user accidentally tries to place a label | 1643 // Print a nice error if the user accidentally tries to place a label |
1634 // on an individual member of a oneof. | 1644 // on an individual member of a oneof. |
1635 if (LookingAt("required") || | 1645 if (LookingAt("required") || |
1636 LookingAt("optional") || | 1646 LookingAt("optional") || |
1637 LookingAt("repeated")) { | 1647 LookingAt("repeated")) { |
1638 AddError("Fields in oneofs must not have labels (required / optional " | 1648 AddError("Fields in oneofs must not have labels (required / optional " |
1639 "/ repeated)."); | 1649 "/ repeated)."); |
1640 // We can continue parsing here because we understand what the user | 1650 // We can continue parsing here because we understand what the user |
1641 // meant. The error report will still make parsing fail overall. | 1651 // meant. The error report will still make parsing fail overall. |
1642 input_->Next(); | 1652 input_->Next(); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 std::make_pair(line, column); | 2110 std::make_pair(line, column); |
2101 } | 2111 } |
2102 | 2112 |
2103 void SourceLocationTable::Clear() { | 2113 void SourceLocationTable::Clear() { |
2104 location_map_.clear(); | 2114 location_map_.clear(); |
2105 } | 2115 } |
2106 | 2116 |
2107 } // namespace compiler | 2117 } // namespace compiler |
2108 } // namespace protobuf | 2118 } // namespace protobuf |
2109 } // namespace google | 2119 } // namespace google |
OLD | NEW |