OLD | NEW |
---|---|
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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 5408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5419 current_block_->scope->function_level() + 1, | 5419 current_block_->scope->function_level() + 1, |
5420 0); | 5420 0); |
5421 } | 5421 } |
5422 ChainNewBlock(outer_scope); | 5422 ChainNewBlock(outer_scope); |
5423 } | 5423 } |
5424 | 5424 |
5425 | 5425 |
5426 void Parser::OpenAsyncClosure() { | 5426 void Parser::OpenAsyncClosure() { |
5427 TRACE_PARSER("OpenAsyncClosure"); | 5427 TRACE_PARSER("OpenAsyncClosure"); |
5428 parsed_function()->set_await_temps_scope(current_block_->scope); | 5428 parsed_function()->set_await_temps_scope(current_block_->scope); |
5429 // TODO(mlippautz): Set up explicit jump table for await continuations. | 5429 current_block_->scope->LookupVariable(Symbols::Completer(), false); |
hausner
2014/08/20 19:47:48
Could you add a comment why the variable is looked
Michael Lippautz (Google)
2014/08/20 20:56:06
Yes, it's about capturing it. Moved into CloseAsyn
| |
5430 } | 5430 } |
5431 | 5431 |
5432 | 5432 |
5433 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) { | 5433 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) { |
5434 TRACE_PARSER("OpenAsyncFunction"); | 5434 TRACE_PARSER("OpenAsyncFunction"); |
5435 // Create the closure containing the old body of this function. | 5435 // Create the closure containing the old body of this function. |
5436 Class& sig_cls = Class::ZoneHandle(I); | 5436 Class& sig_cls = Class::ZoneHandle(I); |
5437 Type& sig_type = Type::ZoneHandle(I); | 5437 Type& sig_type = Type::ZoneHandle(I); |
5438 Function& closure = Function::ZoneHandle(I); | 5438 Function& closure = Function::ZoneHandle(I); |
5439 String& sig = String::ZoneHandle(I); | 5439 String& sig = String::ZoneHandle(I); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5516 const Class& completer = Class::ZoneHandle(I, | 5516 const Class& completer = Class::ZoneHandle(I, |
5517 GetClassForAsync(Symbols::Completer())); | 5517 GetClassForAsync(Symbols::Completer())); |
5518 ASSERT(!completer.IsNull()); | 5518 ASSERT(!completer.IsNull()); |
5519 const Function& completer_constructor = Function::ZoneHandle(I, | 5519 const Function& completer_constructor = Function::ZoneHandle(I, |
5520 completer.LookupFunction(Symbols::CompleterConstructor())); | 5520 completer.LookupFunction(Symbols::CompleterConstructor())); |
5521 ASSERT(!completer_constructor.IsNull()); | 5521 ASSERT(!completer_constructor.IsNull()); |
5522 | 5522 |
5523 // Add to AST: | 5523 // Add to AST: |
5524 // var :async_op; | 5524 // var :async_op; |
5525 // var :async_completer; | 5525 // var :async_completer; |
5526 // var :await_jump_var; | |
5527 // var :await_ctx_var; | |
5526 LocalVariable* async_op_var = new (I) LocalVariable( | 5528 LocalVariable* async_op_var = new (I) LocalVariable( |
5527 Scanner::kNoSourcePos, | 5529 Scanner::kNoSourcePos, |
5528 Symbols::AsyncOperation(), | 5530 Symbols::AsyncOperation(), |
5529 Type::ZoneHandle(I, Type::DynamicType())); | 5531 Type::ZoneHandle(I, Type::DynamicType())); |
5530 current_block_->scope->AddVariable(async_op_var); | 5532 current_block_->scope->AddVariable(async_op_var); |
5531 found = closure_body->scope()->CaptureVariable(Symbols::AsyncOperation()); | 5533 found = closure_body->scope()->CaptureVariable(Symbols::AsyncOperation()); |
5532 ASSERT(found); | 5534 ASSERT(found); |
5533 LocalVariable* async_completer = new (I) LocalVariable( | 5535 LocalVariable* async_completer = new (I) LocalVariable( |
5534 Scanner::kNoSourcePos, | 5536 Scanner::kNoSourcePos, |
5535 Symbols::AsyncCompleter(), | 5537 Symbols::AsyncCompleter(), |
5536 Type::ZoneHandle(I, Type::DynamicType())); | 5538 Type::ZoneHandle(I, Type::DynamicType())); |
5537 current_block_->scope->AddVariable(async_completer); | 5539 current_block_->scope->AddVariable(async_completer); |
5538 found = closure_body->scope()->CaptureVariable(Symbols::AsyncCompleter()); | 5540 found = closure_body->scope()->CaptureVariable(Symbols::AsyncCompleter()); |
5539 ASSERT(found); | 5541 ASSERT(found); |
5542 LocalVariable* await_jump_var = new (I) LocalVariable( | |
5543 Scanner::kNoSourcePos, | |
5544 Symbols::AwaitJumpVar(), | |
5545 Type::ZoneHandle(I, Type::DynamicType())); | |
5546 current_block_->scope->AddVariable(await_jump_var); | |
5547 found = closure_body->scope()->CaptureVariable(Symbols::AwaitJumpVar()); | |
5548 ASSERT(found); | |
5549 LocalVariable* await_ctx_var = new (I) LocalVariable( | |
5550 Scanner::kNoSourcePos, | |
5551 Symbols::AwaitContextVar(), | |
5552 Type::ZoneHandle(I, Type::DynamicType())); | |
5553 current_block_->scope->AddVariable(await_ctx_var); | |
5554 found = closure_body->scope()->CaptureVariable(Symbols::AwaitContextVar()); | |
5555 ASSERT(found); | |
5556 | |
5557 // Add to AST: | |
5558 // :await_jump_var = null; | |
5559 // :await_ctx_var = null; | |
5560 AstNode* null_literal = new(I) LiteralNode( | |
hausner
2014/08/20 19:47:48
You should not need to initialize these to null ex
Michael Lippautz (Google)
2014/08/20 20:56:06
Done.
| |
5561 Scanner::kNoSourcePos, Object::null_instance()); | |
5562 current_block_->statements->Add(new(I) StoreLocalNode( | |
5563 Scanner::kNoSourcePos, await_jump_var, null_literal)); | |
5564 current_block_->statements->Add(new(I) StoreLocalNode( | |
5565 Scanner::kNoSourcePos, await_ctx_var, null_literal)); | |
5540 | 5566 |
5541 // Add to AST: | 5567 // Add to AST: |
5542 // :async_completer = new Completer(); | 5568 // :async_completer = new Completer(); |
5543 ArgumentListNode* empty_args = new (I) ArgumentListNode( | 5569 ArgumentListNode* empty_args = new(I) ArgumentListNode(Scanner::kNoSourcePos); |
srdjan
2014/08/20 17:50:06
The prevalent type is new (I) (with space), please
Michael Lippautz (Google)
2014/08/20 20:56:06
Done. I have seen "new(I)" and "new (I)" all aroun
| |
5544 Scanner::kNoSourcePos); | |
5545 ConstructorCallNode* completer_constructor_node = new (I) ConstructorCallNode( | 5570 ConstructorCallNode* completer_constructor_node = new (I) ConstructorCallNode( |
5546 Scanner::kNoSourcePos, | 5571 Scanner::kNoSourcePos, |
5547 TypeArguments::ZoneHandle(I), | 5572 TypeArguments::ZoneHandle(I), |
5548 completer_constructor, | 5573 completer_constructor, |
5549 empty_args); | 5574 empty_args); |
5550 StoreLocalNode* store_completer = new (I) StoreLocalNode( | 5575 StoreLocalNode* store_completer = new (I) StoreLocalNode( |
5551 Scanner::kNoSourcePos, | 5576 Scanner::kNoSourcePos, |
5552 async_completer, | 5577 async_completer, |
5553 completer_constructor_node); | 5578 completer_constructor_node); |
5554 current_block_->statements->Add(store_completer); | 5579 current_block_->statements->Add(store_completer); |
(...skipping 30 matching lines...) Expand all Loading... | |
5585 Symbols::CompleterFuture())); | 5610 Symbols::CompleterFuture())); |
5586 current_block_->statements->Add(return_node); | 5611 current_block_->statements->Add(return_node); |
5587 return CloseBlock(); | 5612 return CloseBlock(); |
5588 } | 5613 } |
5589 | 5614 |
5590 | 5615 |
5591 void Parser::CloseAsyncClosure(SequenceNode* body) { | 5616 void Parser::CloseAsyncClosure(SequenceNode* body) { |
5592 TRACE_PARSER("CloseAsyncClosure"); | 5617 TRACE_PARSER("CloseAsyncClosure"); |
5593 // We need a temporary expression to store intermediate return values. | 5618 // We need a temporary expression to store intermediate return values. |
5594 parsed_function()->EnsureExpressionTemp(); | 5619 parsed_function()->EnsureExpressionTemp(); |
5620 body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); | |
hausner
2014/08/20 19:47:48
A comment would be nice explaining why you are loo
Michael Lippautz (Google)
2014/08/20 20:56:06
Added a comment in the source.
Currently, all var
| |
5621 body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); | |
5622 body->scope()->RecursivelyCaptureAllVariables(); | |
5595 } | 5623 } |
5596 | 5624 |
5597 | 5625 |
5598 // Set up default values for all optional parameters to the function. | 5626 // Set up default values for all optional parameters to the function. |
5599 void Parser::SetupDefaultsForOptionalParams(const ParamList* params, | 5627 void Parser::SetupDefaultsForOptionalParams(const ParamList* params, |
5600 Array* default_values) { | 5628 Array* default_values) { |
5601 if (params->num_optional_parameters > 0) { | 5629 if (params->num_optional_parameters > 0) { |
5602 // Build array of default parameter values. | 5630 // Build array of default parameter values. |
5603 ParamDesc* param = | 5631 ParamDesc* param = |
5604 params->parameters->data() + params->num_fixed_parameters; | 5632 params->parameters->data() + params->num_fixed_parameters; |
(...skipping 5653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11258 void Parser::SkipQualIdent() { | 11286 void Parser::SkipQualIdent() { |
11259 ASSERT(IsIdentifier()); | 11287 ASSERT(IsIdentifier()); |
11260 ConsumeToken(); | 11288 ConsumeToken(); |
11261 if (CurrentToken() == Token::kPERIOD) { | 11289 if (CurrentToken() == Token::kPERIOD) { |
11262 ConsumeToken(); // Consume the kPERIOD token. | 11290 ConsumeToken(); // Consume the kPERIOD token. |
11263 ExpectIdentifier("identifier expected after '.'"); | 11291 ExpectIdentifier("identifier expected after '.'"); |
11264 } | 11292 } |
11265 } | 11293 } |
11266 | 11294 |
11267 } // namespace dart | 11295 } // namespace dart |
OLD | NEW |