Chromium Code Reviews| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "tools/gn/functions.h" | 8 #include "tools/gn/functions.h" |
| 9 #include "tools/gn/operators.h" | 9 #include "tools/gn/operators.h" |
| 10 #include "tools/gn/token.h" | 10 #include "tools/gn/token.h" |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 492 |
| 493 scoped_ptr<ParseNode> Parser::ParseCondition() { | 493 scoped_ptr<ParseNode> Parser::ParseCondition() { |
| 494 scoped_ptr<ConditionNode> condition(new ConditionNode); | 494 scoped_ptr<ConditionNode> condition(new ConditionNode); |
| 495 condition->set_if_token(Consume(Token::IF, "Expected 'if'")); | 495 condition->set_if_token(Consume(Token::IF, "Expected 'if'")); |
| 496 Consume(Token::LEFT_PAREN, "Expected '(' after 'if'."); | 496 Consume(Token::LEFT_PAREN, "Expected '(' after 'if'."); |
| 497 condition->set_condition(ParseExpression()); | 497 condition->set_condition(ParseExpression()); |
| 498 if (IsAssignment(condition->condition())) | 498 if (IsAssignment(condition->condition())) |
| 499 *err_ = Err(condition->condition(), "Assignment not allowed in 'if'."); | 499 *err_ = Err(condition->condition(), "Assignment not allowed in 'if'."); |
| 500 Consume(Token::RIGHT_PAREN, "Expected ')' after condition of 'if'."); | 500 Consume(Token::RIGHT_PAREN, "Expected ')' after condition of 'if'."); |
| 501 condition->set_if_true(ParseBlock().Pass()); | 501 condition->set_if_true(ParseBlock().Pass()); |
| 502 if (Match(Token::ELSE)) | 502 if (Match(Token::ELSE)) { |
| 503 if (!LookAhead(Token::LEFT_BRACE) && !LookAhead(Token::IF)) { | |
|
tfarina
2015/03/10 20:37:24
|| here does the wrong thing?
Anyway, thanks for
scottmg
2015/03/10 21:21:00
I'm not sure what you mean. Right now it says "if
| |
| 504 *err_ = Err(cur_token(), "Expected '{' or 'if' after 'else'."); | |
| 505 return scoped_ptr<ParseNode>(); | |
|
tfarina
2015/03/10 20:37:24
This can be return nullptr;
scottmg
2015/03/10 21:21:00
There's a whole bunch that predate nullptr in this
| |
| 506 } | |
| 503 condition->set_if_false(ParseStatement().Pass()); | 507 condition->set_if_false(ParseStatement().Pass()); |
| 508 } | |
| 504 if (has_error()) | 509 if (has_error()) |
| 505 return scoped_ptr<ParseNode>(); | 510 return scoped_ptr<ParseNode>(); |
| 506 return condition.Pass(); | 511 return condition.Pass(); |
| 507 } | 512 } |
| 508 | 513 |
| 509 void Parser::TraverseOrder(const ParseNode* root, | 514 void Parser::TraverseOrder(const ParseNode* root, |
| 510 std::vector<const ParseNode*>* pre, | 515 std::vector<const ParseNode*>* pre, |
| 511 std::vector<const ParseNode*>* post) { | 516 std::vector<const ParseNode*>* post) { |
| 512 if (root) { | 517 if (root) { |
| 513 pre->push_back(root); | 518 pre->push_back(root); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 break; | 615 break; |
| 611 } | 616 } |
| 612 } | 617 } |
| 613 | 618 |
| 614 // Suffix comments were assigned in reverse, so if there were multiple on | 619 // Suffix comments were assigned in reverse, so if there were multiple on |
| 615 // the same node, they need to be reversed. | 620 // the same node, they need to be reversed. |
| 616 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) | 621 if ((*i)->comments() && !(*i)->comments()->suffix().empty()) |
| 617 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); | 622 const_cast<ParseNode*>(*i)->comments_mutable()->ReverseSuffix(); |
| 618 } | 623 } |
| 619 } | 624 } |
| OLD | NEW |