Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: tools/gn/parser.cc

Issue 996893002: gn: Enforce braces after 'else' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn/parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698