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

Side by Side Diff: runtime/vm/parser.cc

Issue 2946173002: VM: Allow trailing comma in assert statements. (Closed)
Patch Set: Created 3 years, 6 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 | tests/language/assert_trailing_comma_test.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 9679 matching lines...) Expand 10 before | Expand all | Expand 10 after
9690 9690
9691 AstNode* Parser::ParseAssertStatement(bool is_const) { 9691 AstNode* Parser::ParseAssertStatement(bool is_const) {
9692 TRACE_PARSER("ParseAssertStatement"); 9692 TRACE_PARSER("ParseAssertStatement");
9693 ConsumeToken(); // Consume assert keyword. 9693 ConsumeToken(); // Consume assert keyword.
9694 ExpectToken(Token::kLPAREN); 9694 ExpectToken(Token::kLPAREN);
9695 const TokenPosition condition_pos = TokenPos(); 9695 const TokenPosition condition_pos = TokenPos();
9696 if (!I->asserts()) { 9696 if (!I->asserts()) {
9697 SkipExpr(); 9697 SkipExpr();
9698 if (CurrentToken() == Token::kCOMMA) { 9698 if (CurrentToken() == Token::kCOMMA) {
9699 ConsumeToken(); 9699 ConsumeToken();
9700 SkipExpr(); 9700 if (CurrentToken() != Token::kRPAREN) {
9701 SkipExpr();
9702 if (CurrentToken() == Token::kCOMMA) {
9703 // Allow trailing comma.
9704 ConsumeToken();
9705 }
9706 }
9701 } 9707 }
9702 ExpectToken(Token::kRPAREN); 9708 ExpectToken(Token::kRPAREN);
9703 return NULL; 9709 return NULL;
9704 } 9710 }
9705 9711
9706 BoolScope saved_seen_await(&parsed_function()->have_seen_await_expr_, false); 9712 BoolScope saved_seen_await(&parsed_function()->have_seen_await_expr_, false);
9707 AstNode* condition = ParseExpr(kAllowConst, kConsumeCascades); 9713 AstNode* condition = ParseExpr(kAllowConst, kConsumeCascades);
9708 if (is_const && !condition->IsPotentiallyConst()) { 9714 if (is_const && !condition->IsPotentiallyConst()) {
9709 ReportError(condition_pos, 9715 ReportError(condition_pos,
9710 "initializer assert expression must be compile time constant."); 9716 "initializer assert expression must be compile time constant.");
9711 } 9717 }
9712 const TokenPosition condition_end = TokenPos(); 9718 const TokenPosition condition_end = TokenPos();
9713 AstNode* message = NULL; 9719 AstNode* message = NULL;
9714 TokenPosition message_pos = TokenPosition::kNoSource; 9720 TokenPosition message_pos = TokenPosition::kNoSource;
9715 if (CurrentToken() == Token::kCOMMA) { 9721 if (CurrentToken() == Token::kCOMMA) {
9716 ConsumeToken(); 9722 ConsumeToken();
9717 message_pos = TokenPos(); 9723 if (CurrentToken() != Token::kRPAREN) {
9718 message = ParseExpr(kAllowConst, kConsumeCascades); 9724 message_pos = TokenPos();
9719 if (is_const && !message->IsPotentiallyConst()) { 9725 message = ParseExpr(kAllowConst, kConsumeCascades);
9720 ReportError( 9726 if (is_const && !message->IsPotentiallyConst()) {
9721 message_pos, 9727 ReportError(
9722 "initializer assert expression must be compile time constant."); 9728 message_pos,
9729 "initializer assert expression must be compile time constant.");
9730 }
9731 if (CurrentToken() == Token::kCOMMA) {
9732 // Allow trailing comma.
9733 ConsumeToken();
9734 }
9723 } 9735 }
9724 } 9736 }
9725 ExpectToken(Token::kRPAREN); 9737 ExpectToken(Token::kRPAREN);
9726 9738
9727 if (!is_const) { 9739 if (!is_const) {
9728 // Check for assertion condition being a function if not const. 9740 // Check for assertion condition being a function if not const.
9729 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos); 9741 ArgumentListNode* arguments = new (Z) ArgumentListNode(condition_pos);
9730 arguments->Add(condition); 9742 arguments->Add(condition);
9731 condition = MakeStaticCall( 9743 condition = MakeStaticCall(
9732 Symbols::AssertionError(), 9744 Symbols::AssertionError(),
(...skipping 5580 matching lines...) Expand 10 before | Expand all | Expand 10 after
15313 TokenPosition* start, 15325 TokenPosition* start,
15314 TokenPosition* end) { 15326 TokenPosition* end) {
15315 UNREACHABLE(); 15327 UNREACHABLE();
15316 return false; 15328 return false;
15317 } 15329 }
15318 15330
15319 15331
15320 } // namespace dart 15332 } // namespace dart
15321 15333
15322 #endif // DART_PRECOMPILED_RUNTIME 15334 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « no previous file | tests/language/assert_trailing_comma_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698