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

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

Issue 2064663002: Make VM accept function values in assert statements. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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
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 9157 matching lines...) Expand 10 before | Expand all | Expand 10 after
9168 arguments->Add(new(Z) LiteralNode(begin, 9168 arguments->Add(new(Z) LiteralNode(begin,
9169 Integer::ZoneHandle(Z, Integer::New(begin.value(), Heap::kOld)))); 9169 Integer::ZoneHandle(Z, Integer::New(begin.value(), Heap::kOld))));
9170 arguments->Add(new(Z) LiteralNode(end, 9170 arguments->Add(new(Z) LiteralNode(end,
9171 Integer::ZoneHandle(Z, Integer::New(end.value(), Heap::kOld)))); 9171 Integer::ZoneHandle(Z, Integer::New(end.value(), Heap::kOld))));
9172 return MakeStaticCall(Symbols::AssertionError(), 9172 return MakeStaticCall(Symbols::AssertionError(),
9173 Library::PrivateCoreLibName(Symbols::ThrowNew()), 9173 Library::PrivateCoreLibName(Symbols::ThrowNew()),
9174 arguments); 9174 arguments);
9175 } 9175 }
9176 9176
9177 9177
9178 AstNode* Parser::InsertClosureCallNodes(AstNode* condition) { 9178 AstNode* Parser::HandleAssertCondition(AstNode* condition) {
9179 if (condition->IsClosureNode() || 9179 const TokenPosition pos = condition->token_pos();
9180 (condition->IsStoreLocalNode() && 9180 ArgumentListNode* arguments = new(Z) ArgumentListNode(pos);
9181 condition->AsStoreLocalNode()->value()->IsClosureNode())) { 9181 arguments->Add(condition);
9182 // Function literal in assert implies a call. 9182 return MakeStaticCall(Symbols::AssertionError(),
9183 const TokenPosition pos = condition->token_pos(); 9183 Library::PrivateCoreLibName(Symbols::HandleCondition()),
9184 condition = BuildClosureCall(pos, 9184 arguments);
9185 condition,
9186 new(Z) ArgumentListNode(pos));
9187 } else if (condition->IsConditionalExprNode()) {
9188 ConditionalExprNode* cond_expr = condition->AsConditionalExprNode();
9189 cond_expr->set_true_expr(InsertClosureCallNodes(cond_expr->true_expr()));
9190 cond_expr->set_false_expr(InsertClosureCallNodes(cond_expr->false_expr()));
9191 }
9192 return condition;
9193 } 9185 }
9194 9186
9195 9187
9196 AstNode* Parser::ParseAssertStatement() { 9188 AstNode* Parser::ParseAssertStatement() {
9197 TRACE_PARSER("ParseAssertStatement"); 9189 TRACE_PARSER("ParseAssertStatement");
9198 ConsumeToken(); // Consume assert keyword. 9190 ConsumeToken(); // Consume assert keyword.
9199 ExpectToken(Token::kLPAREN); 9191 ExpectToken(Token::kLPAREN);
9200 const TokenPosition condition_pos = TokenPos(); 9192 const TokenPosition condition_pos = TokenPos();
9201 if (!I->asserts()) { 9193 if (!I->asserts()) {
9202 SkipExpr(); 9194 SkipExpr();
9203 ExpectToken(Token::kRPAREN); 9195 ExpectToken(Token::kRPAREN);
9204 return NULL; 9196 return NULL;
9205 } 9197 }
9206 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL); 9198 AstNode* condition = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL);
9207 const TokenPosition condition_end = TokenPos(); 9199 const TokenPosition condition_end = TokenPos();
9208 ExpectToken(Token::kRPAREN); 9200 ExpectToken(Token::kRPAREN);
9209 condition = InsertClosureCallNodes(condition); 9201 condition = HandleAssertCondition(condition);
9210 condition = new(Z) UnaryOpNode(condition_pos, Token::kNOT, condition); 9202 condition = new(Z) UnaryOpNode(condition_pos, Token::kNOT, condition);
9211 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); 9203 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end);
9212 return new(Z) IfNode( 9204 return new(Z) IfNode(
hausner 2016/06/14 17:51:31 Since you now call a Dart function to evaluate the
Lasse Reichstein Nielsen 2016/06/15 05:57:02 I'm not particularly worried about passing two ext
9213 condition_pos, 9205 condition_pos,
9214 condition, 9206 condition,
9215 NodeAsSequenceNode(condition_pos, assert_throw, NULL), 9207 NodeAsSequenceNode(condition_pos, assert_throw, NULL),
9216 NULL); 9208 NULL);
9217 } 9209 }
9218 9210
9219 9211
9220 // Populate local scope of the catch block with the catch parameters. 9212 // Populate local scope of the catch block with the catch parameters.
9221 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, 9213 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param,
9222 CatchParamDesc* stack_trace_param, 9214 CatchParamDesc* stack_trace_param,
(...skipping 5407 matching lines...) Expand 10 before | Expand all | Expand 10 after
14630 const ArgumentListNode& function_args, 14622 const ArgumentListNode& function_args,
14631 const LocalVariable* temp_for_last_arg, 14623 const LocalVariable* temp_for_last_arg,
14632 bool is_super_invocation) { 14624 bool is_super_invocation) {
14633 UNREACHABLE(); 14625 UNREACHABLE();
14634 return NULL; 14626 return NULL;
14635 } 14627 }
14636 14628
14637 } // namespace dart 14629 } // namespace dart
14638 14630
14639 #endif // DART_PRECOMPILED_RUNTIME 14631 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« runtime/lib/errors_patch.dart ('K') | « runtime/vm/parser.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698