OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/parser.h" | 5 #include "tools/gn/parser.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 return left; | 455 return left; |
456 } | 456 } |
457 | 457 |
458 std::unique_ptr<ParseNode> Parser::Block(const Token& token) { | 458 std::unique_ptr<ParseNode> Parser::Block(const Token& token) { |
459 // This entrypoint into ParseBlock means it's part of an expression and we | 459 // This entrypoint into ParseBlock means it's part of an expression and we |
460 // always want the result. | 460 // always want the result. |
461 return ParseBlock(token, BlockNode::RETURNS_SCOPE); | 461 return ParseBlock(token, BlockNode::RETURNS_SCOPE); |
462 } | 462 } |
463 | 463 |
464 std::unique_ptr<ParseNode> Parser::Literal(const Token& token) { | 464 std::unique_ptr<ParseNode> Parser::Literal(const Token& token) { |
465 return base::WrapUnique(new LiteralNode(token)); | 465 return base::MakeUnique<LiteralNode>(token); |
466 } | 466 } |
467 | 467 |
468 std::unique_ptr<ParseNode> Parser::Name(const Token& token) { | 468 std::unique_ptr<ParseNode> Parser::Name(const Token& token) { |
469 return IdentifierOrCall(std::unique_ptr<ParseNode>(), token); | 469 return IdentifierOrCall(std::unique_ptr<ParseNode>(), token); |
470 } | 470 } |
471 | 471 |
472 std::unique_ptr<ParseNode> Parser::BlockComment(const Token& token) { | 472 std::unique_ptr<ParseNode> Parser::BlockComment(const Token& token) { |
473 std::unique_ptr<BlockCommentNode> comment(new BlockCommentNode()); | 473 std::unique_ptr<BlockCommentNode> comment(new BlockCommentNode()); |
474 comment->set_comment(token); | 474 comment->set_comment(token); |
475 return std::move(comment); | 475 return std::move(comment); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 binary_op->set_left(std::move(left)); | 522 binary_op->set_left(std::move(left)); |
523 binary_op->set_right(std::move(right)); | 523 binary_op->set_right(std::move(right)); |
524 return std::move(binary_op); | 524 return std::move(binary_op); |
525 } | 525 } |
526 | 526 |
527 std::unique_ptr<ParseNode> Parser::IdentifierOrCall( | 527 std::unique_ptr<ParseNode> Parser::IdentifierOrCall( |
528 std::unique_ptr<ParseNode> left, | 528 std::unique_ptr<ParseNode> left, |
529 const Token& token) { | 529 const Token& token) { |
530 std::unique_ptr<ListNode> list(new ListNode); | 530 std::unique_ptr<ListNode> list(new ListNode); |
531 list->set_begin_token(token); | 531 list->set_begin_token(token); |
532 list->set_end(base::WrapUnique(new EndNode(token))); | 532 list->set_end(base::MakeUnique<EndNode>(token)); |
533 std::unique_ptr<BlockNode> block; | 533 std::unique_ptr<BlockNode> block; |
534 bool has_arg = false; | 534 bool has_arg = false; |
535 if (LookAhead(Token::LEFT_PAREN)) { | 535 if (LookAhead(Token::LEFT_PAREN)) { |
536 const Token& start_token = Consume(); | 536 const Token& start_token = Consume(); |
537 // Parsing a function call. | 537 // Parsing a function call. |
538 has_arg = true; | 538 has_arg = true; |
539 if (Match(Token::RIGHT_PAREN)) { | 539 if (Match(Token::RIGHT_PAREN)) { |
540 // Nothing, just an empty call. | 540 // Nothing, just an empty call. |
541 } else { | 541 } else { |
542 list = ParseList(start_token, Token::RIGHT_PAREN, false); | 542 list = ParseList(start_token, Token::RIGHT_PAREN, false); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 // next item, so pretend we got one, if we're expecting one. | 662 // next item, so pretend we got one, if we're expecting one. |
663 just_got_comma = allow_trailing_comma; | 663 just_got_comma = allow_trailing_comma; |
664 } else { | 664 } else { |
665 just_got_comma = Match(Token::COMMA); | 665 just_got_comma = Match(Token::COMMA); |
666 } | 666 } |
667 } | 667 } |
668 if (just_got_comma && !allow_trailing_comma) { | 668 if (just_got_comma && !allow_trailing_comma) { |
669 *err_ = Err(cur_token(), "Trailing comma"); | 669 *err_ = Err(cur_token(), "Trailing comma"); |
670 return std::unique_ptr<ListNode>(); | 670 return std::unique_ptr<ListNode>(); |
671 } | 671 } |
672 list->set_end(base::WrapUnique(new EndNode(cur_token()))); | 672 list->set_end(base::MakeUnique<EndNode>(cur_token())); |
673 return list; | 673 return list; |
674 } | 674 } |
675 | 675 |
676 std::unique_ptr<ParseNode> Parser::ParseFile() { | 676 std::unique_ptr<ParseNode> Parser::ParseFile() { |
677 std::unique_ptr<BlockNode> file(new BlockNode(BlockNode::DISCARDS_RESULT)); | 677 std::unique_ptr<BlockNode> file(new BlockNode(BlockNode::DISCARDS_RESULT)); |
678 for (;;) { | 678 for (;;) { |
679 if (at_end()) | 679 if (at_end()) |
680 break; | 680 break; |
681 std::unique_ptr<ParseNode> statement = ParseStatement(); | 681 std::unique_ptr<ParseNode> statement = ParseStatement(); |
682 if (!statement) | 682 if (!statement) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 std::unique_ptr<BlockNode> Parser::ParseBlock( | 721 std::unique_ptr<BlockNode> Parser::ParseBlock( |
722 const Token& begin_brace, | 722 const Token& begin_brace, |
723 BlockNode::ResultMode result_mode) { | 723 BlockNode::ResultMode result_mode) { |
724 if (has_error()) | 724 if (has_error()) |
725 return std::unique_ptr<BlockNode>(); | 725 return std::unique_ptr<BlockNode>(); |
726 std::unique_ptr<BlockNode> block(new BlockNode(result_mode)); | 726 std::unique_ptr<BlockNode> block(new BlockNode(result_mode)); |
727 block->set_begin_token(begin_brace); | 727 block->set_begin_token(begin_brace); |
728 | 728 |
729 for (;;) { | 729 for (;;) { |
730 if (LookAhead(Token::RIGHT_BRACE)) { | 730 if (LookAhead(Token::RIGHT_BRACE)) { |
731 block->set_end(base::WrapUnique(new EndNode(Consume()))); | 731 block->set_end(base::MakeUnique<EndNode>(Consume())); |
732 break; | 732 break; |
733 } | 733 } |
734 | 734 |
735 std::unique_ptr<ParseNode> statement = ParseStatement(); | 735 std::unique_ptr<ParseNode> statement = ParseStatement(); |
736 if (!statement) | 736 if (!statement) |
737 return std::unique_ptr<BlockNode>(); | 737 return std::unique_ptr<BlockNode>(); |
738 block->append_statement(std::move(statement)); | 738 block->append_statement(std::move(statement)); |
739 } | 739 } |
740 return block; | 740 return block; |
741 } | 741 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 break; | 875 break; |
876 } | 876 } |
877 } | 877 } |
878 | 878 |
879 // Suffix comments were assigned in reverse, so if there were multiple on | 879 // Suffix comments were assigned in reverse, so if there were multiple on |
880 // the same node, they need to be reversed. | 880 // the same node, they need to be reversed. |
881 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) | 881 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) |
882 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); | 882 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); |
883 } | 883 } |
884 } | 884 } |
OLD | NEW |