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; |
528 if (LookingAtType(io::Tokenizer::TYPE_START)) { | 529 if (LookingAtType(io::Tokenizer::TYPE_START)) { |
529 // Advance to first token. | 530 // Advance to first token. |
530 input_->NextWithComments(NULL, &upcoming_detached_comments_, | 531 input_->NextWithComments(NULL, &upcoming_detached_comments_, |
531 &upcoming_doc_comments_); | 532 &upcoming_doc_comments_); |
532 } | 533 } |
533 | 534 |
534 { | 535 { |
535 LocationRecorder root_location(this); | 536 LocationRecorder root_location(this); |
536 | 537 |
537 if (require_syntax_identifier_ || LookingAt("syntax")) { | 538 if (require_syntax_identifier_ || LookingAt("syntax")) { |
(...skipping 25 matching lines...) Expand all Loading... |
563 AddError("Unmatched \"}\"."); | 564 AddError("Unmatched \"}\"."); |
564 input_->NextWithComments(NULL, &upcoming_detached_comments_, | 565 input_->NextWithComments(NULL, &upcoming_detached_comments_, |
565 &upcoming_doc_comments_); | 566 &upcoming_doc_comments_); |
566 } | 567 } |
567 } | 568 } |
568 } | 569 } |
569 } | 570 } |
570 | 571 |
571 input_ = NULL; | 572 input_ = NULL; |
572 source_code_info_ = NULL; | 573 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 | |
1643 // Print a nice error if the user accidentally tries to place a label | 1633 // Print a nice error if the user accidentally tries to place a label |
1644 // on an individual member of a oneof. | 1634 // on an individual member of a oneof. |
1645 if (LookingAt("required") || | 1635 if (LookingAt("required") || |
1646 LookingAt("optional") || | 1636 LookingAt("optional") || |
1647 LookingAt("repeated")) { | 1637 LookingAt("repeated")) { |
1648 AddError("Fields in oneofs must not have labels (required / optional " | 1638 AddError("Fields in oneofs must not have labels (required / optional " |
1649 "/ repeated)."); | 1639 "/ repeated)."); |
1650 // We can continue parsing here because we understand what the user | 1640 // We can continue parsing here because we understand what the user |
1651 // meant. The error report will still make parsing fail overall. | 1641 // meant. The error report will still make parsing fail overall. |
1652 input_->Next(); | 1642 input_->Next(); |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 std::make_pair(line, column); | 2100 std::make_pair(line, column); |
2111 } | 2101 } |
2112 | 2102 |
2113 void SourceLocationTable::Clear() { | 2103 void SourceLocationTable::Clear() { |
2114 location_map_.clear(); | 2104 location_map_.clear(); |
2115 } | 2105 } |
2116 | 2106 |
2117 } // namespace compiler | 2107 } // namespace compiler |
2118 } // namespace protobuf | 2108 } // namespace protobuf |
2119 } // namespace google | 2109 } // namespace google |
OLD | NEW |