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

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

Issue 10446102: Insert closure calls in conditional expression of assert (issue 1584). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
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 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/compiler_stats.h" 10 #include "vm/compiler_stats.h"
(...skipping 4969 matching lines...) Expand 10 before | Expand all | Expand 10 after
4980 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) { 4980 AstNode* Parser::MakeAssertCall(intptr_t begin, intptr_t end) {
4981 ArgumentListNode* arguments = new ArgumentListNode(begin); 4981 ArgumentListNode* arguments = new ArgumentListNode(begin);
4982 arguments->Add(new LiteralNode(begin, 4982 arguments->Add(new LiteralNode(begin,
4983 Integer::ZoneHandle(Integer::New(begin)))); 4983 Integer::ZoneHandle(Integer::New(begin))));
4984 arguments->Add(new LiteralNode(end, 4984 arguments->Add(new LiteralNode(end,
4985 Integer::ZoneHandle(Integer::New(end)))); 4985 Integer::ZoneHandle(Integer::New(end))));
4986 return MakeStaticCall(kAssertionErrorName, kThrowNewName, arguments); 4986 return MakeStaticCall(kAssertionErrorName, kThrowNewName, arguments);
4987 } 4987 }
4988 4988
4989 4989
4990 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) {
4991 if (condition->IsClosureNode() ||
4992 (condition->IsStoreLocalNode() &&
4993 condition->AsStoreLocalNode()->value()->IsClosureNode())) {
4994 EnsureExpressionTemp();
4995 // Function literal in assert implies a call.
4996 const intptr_t pos = condition->token_index();
4997 condition = new ClosureCallNode(pos, condition, new ArgumentListNode(pos));
4998 } else if (condition->IsConditionalExprNode()) {
4999 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode();
5000 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr()));
5001 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr()));
5002 }
5003 return condition;
5004 }
5005
5006
4990 AstNode* Parser::ParseAssertStatement() { 5007 AstNode* Parser::ParseAssertStatement() {
4991 TRACE_PARSER("ParseAssertStatement"); 5008 TRACE_PARSER("ParseAssertStatement");
4992 ConsumeToken(); // Consume assert keyword. 5009 ConsumeToken(); // Consume assert keyword.
4993 ExpectToken(Token::kLPAREN); 5010 ExpectToken(Token::kLPAREN);
4994 const intptr_t condition_pos = token_index_; 5011 const intptr_t condition_pos = token_index_;
4995 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) { 5012 if (!FLAG_enable_asserts && !FLAG_enable_type_checks) {
4996 SkipExpr(); 5013 SkipExpr();
4997 ExpectToken(Token::kRPAREN); 5014 ExpectToken(Token::kRPAREN);
4998 return NULL; 5015 return NULL;
4999 } 5016 }
5000 AstNode* condition = ParseExpr(kAllowConst); 5017 AstNode* condition = ParseExpr(kAllowConst);
5001 const intptr_t condition_end = token_index_; 5018 const intptr_t condition_end = token_index_;
5002 ExpectToken(Token::kRPAREN); 5019 ExpectToken(Token::kRPAREN);
5003 if (condition->IsClosureNode()) { 5020 condition = InsertClosureCallNodes(condition);
5004 EnsureExpressionTemp();
5005 // Function literal in assert implies a call.
5006 condition =
5007 new ClosureCallNode(condition_pos,
5008 condition,
5009 new ArgumentListNode(condition_pos));
5010 }
5011 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition); 5021 condition = new UnaryOpNode(condition_pos, Token::kNOT, condition);
5012 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); 5022 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end);
5013 return new IfNode(condition_pos, 5023 return new IfNode(condition_pos,
5014 condition, 5024 condition,
5015 NodeAsSequenceNode(condition_pos, assert_throw, NULL), 5025 NodeAsSequenceNode(condition_pos, assert_throw, NULL),
5016 NULL); 5026 NULL);
5017 } 5027 }
5018 5028
5019 5029
5020 struct CatchParamDesc { 5030 struct CatchParamDesc {
(...skipping 3495 matching lines...) Expand 10 before | Expand all | Expand 10 after
8516 void Parser::SkipQualIdent() { 8526 void Parser::SkipQualIdent() {
8517 ASSERT(IsIdentifier()); 8527 ASSERT(IsIdentifier());
8518 ConsumeToken(); 8528 ConsumeToken();
8519 if (CurrentToken() == Token::kPERIOD) { 8529 if (CurrentToken() == Token::kPERIOD) {
8520 ConsumeToken(); // Consume the kPERIOD token. 8530 ConsumeToken(); // Consume the kPERIOD token.
8521 ExpectIdentifier("identifier expected after '.'"); 8531 ExpectIdentifier("identifier expected after '.'");
8522 } 8532 }
8523 } 8533 }
8524 8534
8525 } // namespace dart 8535 } // namespace dart
OLDNEW
« runtime/vm/ast.h ('K') | « runtime/vm/parser.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698