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

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

Issue 1317213003: Improve async code in VM by not unnecessarily capturing parameters of async and (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Avoid duplicate aliases Created 5 years, 3 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 | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/scopes.h » ('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 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 6584 matching lines...) Expand 10 before | Expand all | Expand 10 after
6595 // signature type is not computed twice. 6595 // signature type is not computed twice.
6596 ClassFinalizer::FinalizeTypesInClass(sig_cls); 6596 ClassFinalizer::FinalizeTypesInClass(sig_cls);
6597 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); 6597 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType());
6598 ASSERT(sig_type.IsFinalized()); 6598 ASSERT(sig_type.IsFinalized());
6599 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); 6599 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved());
6600 ASSERT(body.NumParameters() == closure_params.parameters->length()); 6600 ASSERT(body.NumParameters() == closure_params.parameters->length());
6601 } 6601 }
6602 6602
6603 OpenFunctionBlock(body); 6603 OpenFunctionBlock(body);
6604 AddFormalParamsToScope(&closure_params, current_block_->scope); 6604 AddFormalParamsToScope(&closure_params, current_block_->scope);
6605 OpenBlock();
6606 async_temp_scope_ = current_block_->scope; 6605 async_temp_scope_ = current_block_->scope;
6607 return body.raw(); 6606 return body.raw();
6608 } 6607 }
6609 6608
6610 SequenceNode* Parser::CloseSyncGenFunction(const Function& closure, 6609 SequenceNode* Parser::CloseSyncGenFunction(const Function& closure,
6611 SequenceNode* closure_body) { 6610 SequenceNode* closure_body) {
6612 // The block for the closure body has already been closed. Close the
6613 // corresponding function block.
6614 CloseBlock();
6615
6616 LocalVariable* existing_var = 6611 LocalVariable* existing_var =
6617 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); 6612 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
6618 ASSERT((existing_var != NULL) && existing_var->is_captured()); 6613 ASSERT((existing_var != NULL) && existing_var->is_captured());
6619 existing_var = 6614 existing_var =
6620 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); 6615 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false);
6621 ASSERT((existing_var != NULL) && existing_var->is_captured()); 6616 ASSERT((existing_var != NULL) && existing_var->is_captured());
6622 6617
6623 // :await_jump_var = -1; 6618 // :await_jump_var = -1;
6624 LocalVariable* jump_var = 6619 LocalVariable* jump_var =
6625 current_block_->scope->LookupVariable(Symbols::AwaitJumpVar(), false); 6620 current_block_->scope->LookupVariable(Symbols::AwaitJumpVar(), false);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
6738 // Finalize types in signature class here, so that the 6733 // Finalize types in signature class here, so that the
6739 // signature type is not computed twice. 6734 // signature type is not computed twice.
6740 ClassFinalizer::FinalizeTypesInClass(sig_cls); 6735 ClassFinalizer::FinalizeTypesInClass(sig_cls);
6741 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); 6736 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType());
6742 ASSERT(sig_type.IsFinalized()); 6737 ASSERT(sig_type.IsFinalized());
6743 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 6738 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
6744 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 6739 ASSERT(closure.NumParameters() == closure_params.parameters->length());
6745 } 6740 }
6746 OpenFunctionBlock(closure); 6741 OpenFunctionBlock(closure);
6747 AddFormalParamsToScope(&closure_params, current_block_->scope); 6742 AddFormalParamsToScope(&closure_params, current_block_->scope);
6748 OpenBlock();
6749 async_temp_scope_ = current_block_->scope; 6743 async_temp_scope_ = current_block_->scope;
6750 return closure.raw(); 6744 return closure.raw();
6751 } 6745 }
6752 6746
6753 6747
6754 void Parser::AddContinuationVariables() { 6748 void Parser::AddContinuationVariables() {
6755 // Add to current block's scope: 6749 // Add to current block's scope:
6756 // var :await_jump_var; 6750 // var :await_jump_var;
6757 // var :await_ctx_var; 6751 // var :await_ctx_var;
6758 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6752 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6759 LocalVariable* await_jump_var = new (Z) LocalVariable( 6753 LocalVariable* await_jump_var = new (Z) LocalVariable(
6760 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type); 6754 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type);
6761 current_block_->scope->AddVariable(await_jump_var); 6755 current_block_->scope->AddVariable(await_jump_var);
6762 current_block_->scope->CaptureVariable(Symbols::AwaitJumpVar()); 6756 current_block_->scope->CaptureVariable(await_jump_var);
6763 LocalVariable* await_ctx_var = new (Z) LocalVariable( 6757 LocalVariable* await_ctx_var = new (Z) LocalVariable(
6764 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type); 6758 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type);
6765 current_block_->scope->AddVariable(await_ctx_var); 6759 current_block_->scope->AddVariable(await_ctx_var);
6766 current_block_->scope->CaptureVariable(Symbols::AwaitContextVar()); 6760 current_block_->scope->CaptureVariable(await_ctx_var);
6767 } 6761 }
6768 6762
6769 6763
6770 void Parser::AddAsyncClosureVariables() { 6764 void Parser::AddAsyncClosureVariables() {
6771 // Add to current block's scope: 6765 // Add to current block's scope:
6772 // var :async_op; 6766 // var :async_op;
6773 // var :async_then_callback; 6767 // var :async_then_callback;
6774 // var :async_catch_error_callback; 6768 // var :async_catch_error_callback;
6775 // var :async_completer; 6769 // var :async_completer;
6776 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6770 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6777 LocalVariable* async_op_var = new(Z) LocalVariable( 6771 LocalVariable* async_op_var = new(Z) LocalVariable(
6778 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6772 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6779 current_block_->scope->AddVariable(async_op_var); 6773 current_block_->scope->AddVariable(async_op_var);
6780 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6774 current_block_->scope->CaptureVariable(async_op_var);
6781 LocalVariable* async_then_callback_var = new(Z) LocalVariable( 6775 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6782 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); 6776 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6783 current_block_->scope->AddVariable(async_then_callback_var); 6777 current_block_->scope->AddVariable(async_then_callback_var);
6784 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback()); 6778 current_block_->scope->CaptureVariable(async_then_callback_var);
6785 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( 6779 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6786 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); 6780 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6787 current_block_->scope->AddVariable(async_catch_error_callback_var); 6781 current_block_->scope->AddVariable(async_catch_error_callback_var);
6788 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback()); 6782 current_block_->scope->CaptureVariable(async_catch_error_callback_var);
6789 LocalVariable* async_completer = new(Z) LocalVariable( 6783 LocalVariable* async_completer = new(Z) LocalVariable(
6790 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type); 6784 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type);
6791 current_block_->scope->AddVariable(async_completer); 6785 current_block_->scope->AddVariable(async_completer);
6792 current_block_->scope->CaptureVariable(Symbols::AsyncCompleter()); 6786 current_block_->scope->CaptureVariable(async_completer);
6793 } 6787 }
6794 6788
6795 6789
6796 void Parser::AddAsyncGeneratorVariables() { 6790 void Parser::AddAsyncGeneratorVariables() {
6797 // Add to current block's scope: 6791 // Add to current block's scope:
6798 // var :controller; 6792 // var :controller;
6799 // The :controller variable is used by the async generator closure to 6793 // The :controller variable is used by the async generator closure to
6800 // store the StreamController object to which the yielded expressions 6794 // store the StreamController object to which the yielded expressions
6801 // are added. 6795 // are added.
6802 // var :async_op; 6796 // var :async_op;
6803 // var :async_then_callback; 6797 // var :async_then_callback;
6804 // var :async_catch_error_callback; 6798 // var :async_catch_error_callback;
6805 // These variables are used to store the async generator closure containing 6799 // These variables are used to store the async generator closure containing
6806 // the body of the async* function. They are used by the await operator. 6800 // the body of the async* function. They are used by the await operator.
6807 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6801 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6808 LocalVariable* controller_var = new(Z) LocalVariable( 6802 LocalVariable* controller_var = new(Z) LocalVariable(
6809 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type); 6803 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type);
6810 current_block_->scope->AddVariable(controller_var); 6804 current_block_->scope->AddVariable(controller_var);
6811 current_block_->scope->CaptureVariable(Symbols::Controller()); 6805 current_block_->scope->CaptureVariable(controller_var);
6812
6813 LocalVariable* async_op_var = new(Z) LocalVariable( 6806 LocalVariable* async_op_var = new(Z) LocalVariable(
6814 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6807 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6815 current_block_->scope->AddVariable(async_op_var); 6808 current_block_->scope->AddVariable(async_op_var);
6816 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6809 current_block_->scope->CaptureVariable(async_op_var);
6817 LocalVariable* async_then_callback_var = new(Z) LocalVariable( 6810 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6818 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); 6811 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6819 current_block_->scope->AddVariable(async_then_callback_var); 6812 current_block_->scope->AddVariable(async_then_callback_var);
6820 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback()); 6813 current_block_->scope->CaptureVariable(async_then_callback_var);
6821 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( 6814 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6822 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); 6815 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6823 current_block_->scope->AddVariable(async_catch_error_callback_var); 6816 current_block_->scope->AddVariable(async_catch_error_callback_var);
6824 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback()); 6817 current_block_->scope->CaptureVariable(async_catch_error_callback_var);
6825 } 6818 }
6826 6819
6827 6820
6828 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) { 6821 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) {
6829 TRACE_PARSER("OpenAsyncGeneratorFunction"); 6822 TRACE_PARSER("OpenAsyncGeneratorFunction");
6830 AddContinuationVariables(); 6823 AddContinuationVariables();
6831 AddAsyncGeneratorVariables(); 6824 AddAsyncGeneratorVariables();
6832 6825
6833 Function& closure = Function::Handle(Z); 6826 Function& closure = Function::Handle(Z);
6834 bool is_new_closure = false; 6827 bool is_new_closure = false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6880 // signature type is not computed twice. 6873 // signature type is not computed twice.
6881 ClassFinalizer::FinalizeTypesInClass(sig_cls); 6874 ClassFinalizer::FinalizeTypesInClass(sig_cls);
6882 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); 6875 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType());
6883 ASSERT(sig_type.IsFinalized()); 6876 ASSERT(sig_type.IsFinalized());
6884 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 6877 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
6885 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 6878 ASSERT(closure.NumParameters() == closure_params.parameters->length());
6886 } 6879 }
6887 6880
6888 OpenFunctionBlock(closure); 6881 OpenFunctionBlock(closure);
6889 AddFormalParamsToScope(&closure_params, current_block_->scope); 6882 AddFormalParamsToScope(&closure_params, current_block_->scope);
6890 OpenBlock();
6891 async_temp_scope_ = current_block_->scope; 6883 async_temp_scope_ = current_block_->scope;
6892 return closure.raw(); 6884 return closure.raw();
6893 } 6885 }
6894 6886
6895 6887
6896 // Generate the Ast nodes for the implicit code of the async* function. 6888 // Generate the Ast nodes for the implicit code of the async* function.
6897 // 6889 //
6898 // f(...) async* { 6890 // f(...) async* {
6899 // var :controller; 6891 // var :controller;
6900 // var :await_jump_var = -1; 6892 // var :await_jump_var = -1;
6901 // var :await_context_var; 6893 // var :await_context_var;
6902 // f_async_body() { 6894 // f_async_body() {
6903 // ... source code of f ... 6895 // ... source code of f ...
6904 // } 6896 // }
6905 // var :async_op = f_async_body; 6897 // var :async_op = f_async_body;
6906 // var :async_then_callback = _asyncThenWrapperHelper(:async_op); 6898 // var :async_then_callback = _asyncThenWrapperHelper(:async_op);
6907 // var :async_catch_error_callback = _asyncCatchErrorWrapperHelper(:async_op); 6899 // var :async_catch_error_callback = _asyncCatchErrorWrapperHelper(:async_op);
6908 // :controller = new _AsyncStarStreamController(:async_op); 6900 // :controller = new _AsyncStarStreamController(:async_op);
6909 // return :controller.stream; 6901 // return :controller.stream;
6910 // } 6902 // }
6911 SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func, 6903 SequenceNode* Parser::CloseAsyncGeneratorFunction(const Function& closure_func,
6912 SequenceNode* closure_body) { 6904 SequenceNode* closure_body) {
6913 TRACE_PARSER("CloseAsyncGeneratorFunction"); 6905 TRACE_PARSER("CloseAsyncGeneratorFunction");
6914 ASSERT(!closure_func.IsNull()); 6906 ASSERT(!closure_func.IsNull());
6915 ASSERT(closure_body != NULL); 6907 ASSERT(closure_body != NULL);
6916 6908
6917 // The block for the async closure body has already been closed. Close the
6918 // corresponding function block.
6919 CloseBlock();
6920
6921 // Make sure the implicit variables of the async generator function 6909 // Make sure the implicit variables of the async generator function
6922 // are captured. 6910 // are captured.
6923 LocalVariable* existing_var = closure_body->scope()->LookupVariable( 6911 LocalVariable* existing_var = closure_body->scope()->LookupVariable(
6924 Symbols::AwaitJumpVar(), false); 6912 Symbols::AwaitJumpVar(), false);
6925 ASSERT((existing_var != NULL) && existing_var->is_captured()); 6913 ASSERT((existing_var != NULL) && existing_var->is_captured());
6926 existing_var = closure_body->scope()->LookupVariable( 6914 existing_var = closure_body->scope()->LookupVariable(
6927 Symbols::AwaitContextVar(), false); 6915 Symbols::AwaitContextVar(), false);
6928 ASSERT((existing_var != NULL) && existing_var->is_captured()); 6916 ASSERT((existing_var != NULL) && existing_var->is_captured());
6929 existing_var = closure_body->scope()->LookupVariable( 6917 existing_var = closure_body->scope()->LookupVariable(
6930 Symbols::Controller(), false); 6918 Symbols::Controller(), false);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
7112 return statements; 7100 return statements;
7113 } 7101 }
7114 7102
7115 7103
7116 SequenceNode* Parser::CloseAsyncFunction(const Function& closure, 7104 SequenceNode* Parser::CloseAsyncFunction(const Function& closure,
7117 SequenceNode* closure_body) { 7105 SequenceNode* closure_body) {
7118 TRACE_PARSER("CloseAsyncFunction"); 7106 TRACE_PARSER("CloseAsyncFunction");
7119 ASSERT(!closure.IsNull()); 7107 ASSERT(!closure.IsNull());
7120 ASSERT(closure_body != NULL); 7108 ASSERT(closure_body != NULL);
7121 7109
7122 // The block for the async closure body has already been closed. Close the
7123 // corresponding function block.
7124 CloseBlock();
7125
7126 LocalVariable* existing_var = 7110 LocalVariable* existing_var =
7127 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); 7111 closure_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false);
7128 ASSERT((existing_var != NULL) && existing_var->is_captured()); 7112 ASSERT((existing_var != NULL) && existing_var->is_captured());
7129 existing_var = 7113 existing_var =
7130 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); 7114 closure_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false);
7131 ASSERT((existing_var != NULL) && existing_var->is_captured()); 7115 ASSERT((existing_var != NULL) && existing_var->is_captured());
7132 existing_var = 7116 existing_var =
7133 closure_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); 7117 closure_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false);
7134 ASSERT((existing_var != NULL) && existing_var->is_captured()); 7118 ASSERT((existing_var != NULL) && existing_var->is_captured());
7135 7119
7136 // Create and return a new future that executes a closure with the current 7120 // Create and return a new future that executes a closure with the current
7137 // body. 7121 // body.
7138 7122
7139 // No need to capture parameters or other variables, since they have already 7123 // No need to capture parameters or other variables, since they have already
7140 // been captured in the corresponding scope as the body has been parsed within 7124 // been captured in the corresponding scope as the body has been parsed within
7141 // a nested block (contained in the async funtion's block). 7125 // a nested block (contained in the async function's block).
7142 const Class& future = 7126 const Class& future =
7143 Class::ZoneHandle(Z, I->object_store()->future_class()); 7127 Class::ZoneHandle(Z, I->object_store()->future_class());
7144 ASSERT(!future.IsNull()); 7128 ASSERT(!future.IsNull());
7145 const Function& constructor = Function::ZoneHandle(Z, 7129 const Function& constructor = Function::ZoneHandle(Z,
7146 future.LookupFunction(Symbols::FutureMicrotask())); 7130 future.LookupFunction(Symbols::FutureMicrotask()));
7147 ASSERT(!constructor.IsNull()); 7131 ASSERT(!constructor.IsNull());
7148 const Class& completer = 7132 const Class& completer =
7149 Class::ZoneHandle(Z, I->object_store()->completer_class()); 7133 Class::ZoneHandle(Z, I->object_store()->completer_class());
7150 ASSERT(!completer.IsNull()); 7134 ASSERT(!completer.IsNull());
7151 const Function& completer_constructor = Function::ZoneHandle(Z, 7135 const Function& completer_constructor = Function::ZoneHandle(Z,
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
7422 7406
7423 LocalVariable* Parser::LookupPhaseParameter() { 7407 LocalVariable* Parser::LookupPhaseParameter() {
7424 const bool kTestOnly = false; 7408 const bool kTestOnly = false;
7425 return current_block_->scope->LookupVariable(Symbols::PhaseParameter(), 7409 return current_block_->scope->LookupVariable(Symbols::PhaseParameter(),
7426 kTestOnly); 7410 kTestOnly);
7427 } 7411 }
7428 7412
7429 7413
7430 void Parser::CaptureInstantiator() { 7414 void Parser::CaptureInstantiator() {
7431 ASSERT(current_block_->scope->function_level() > 0); 7415 ASSERT(current_block_->scope->function_level() > 0);
7432 bool found = false; 7416 const String* variable_name = current_function().IsInFactoryScope() ?
7433 if (current_function().IsInFactoryScope()) { 7417 &Symbols::TypeArgumentsParameter() : &Symbols::This();
7434 found = current_block_->scope->CaptureVariable( 7418 current_block_->scope->CaptureVariable(
7435 Symbols::TypeArgumentsParameter()); 7419 current_block_->scope->LookupVariable(*variable_name, true));
7436 } else {
7437 found = current_block_->scope->CaptureVariable(Symbols::This());
7438 }
7439 ASSERT(found);
7440 } 7420 }
7441 7421
7442 7422
7443 AstNode* Parser::LoadReceiver(intptr_t token_pos) { 7423 AstNode* Parser::LoadReceiver(intptr_t token_pos) {
7444 // A nested function may access 'this', referring to the receiver of the 7424 // A nested function may access 'this', referring to the receiver of the
7445 // outermost enclosing function. 7425 // outermost enclosing function.
7446 const bool kTestOnly = false; 7426 const bool kTestOnly = false;
7447 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); 7427 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly);
7448 if (receiver == NULL) { 7428 if (receiver == NULL) {
7449 ReportError(token_pos, "illegal implicit access to receiver 'this'"); 7429 ReportError(token_pos, "illegal implicit access to receiver 'this'");
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
7517 line_number); 7497 line_number);
7518 } 7498 }
7519 } 7499 }
7520 7500
7521 // Add variable to scope after parsing the initalizer expression. 7501 // Add variable to scope after parsing the initalizer expression.
7522 // The expression must not be able to refer to the variable. 7502 // The expression must not be able to refer to the variable.
7523 if (!current_block_->scope->AddVariable(variable)) { 7503 if (!current_block_->scope->AddVariable(variable)) {
7524 LocalVariable* existing_var = 7504 LocalVariable* existing_var =
7525 current_block_->scope->LookupVariable(variable->name(), true); 7505 current_block_->scope->LookupVariable(variable->name(), true);
7526 ASSERT(existing_var != NULL); 7506 ASSERT(existing_var != NULL);
7527 if (existing_var->owner() == current_block_->scope) { 7507 // Use before define cases have already been detected and reported above.
7528 ReportError(ident_pos, "identifier '%s' already defined", 7508 ASSERT(existing_var->owner() == current_block_->scope);
7529 variable->name().ToCString()); 7509 ReportError(ident_pos, "identifier '%s' already defined",
7530 } else { 7510 variable->name().ToCString());
7531 ReportError(ident_pos, "'%s' from outer scope has already been used, "
7532 "cannot redefine",
7533 variable->name().ToCString());
7534 }
7535 } 7511 }
7536 if (is_final || is_const) { 7512 if (is_final || is_const) {
7537 variable->set_is_final(); 7513 variable->set_is_final();
7538 } 7514 }
7539 return initialization; 7515 return initialization;
7540 } 7516 }
7541 7517
7542 7518
7543 // Parses ('var' | 'final' [type] | 'const' [type] | type). 7519 // Parses ('var' | 'final' [type] | 'const' [type] | type).
7544 // The presence of 'final' or 'const' must be detected and remembered 7520 // The presence of 'final' or 'const' must be detected and remembered
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7717 *variable_name, 7693 *variable_name,
7718 function_type); 7694 function_type);
7719 function_variable->set_is_final(); 7695 function_variable->set_is_final();
7720 ASSERT(current_block_ != NULL); 7696 ASSERT(current_block_ != NULL);
7721 ASSERT(current_block_->scope != NULL); 7697 ASSERT(current_block_->scope != NULL);
7722 if (!current_block_->scope->AddVariable(function_variable)) { 7698 if (!current_block_->scope->AddVariable(function_variable)) {
7723 LocalVariable* existing_var = 7699 LocalVariable* existing_var =
7724 current_block_->scope->LookupVariable(function_variable->name(), 7700 current_block_->scope->LookupVariable(function_variable->name(),
7725 true); 7701 true);
7726 ASSERT(existing_var != NULL); 7702 ASSERT(existing_var != NULL);
7727 if (existing_var->owner() == current_block_->scope) { 7703 // Use before define cases have already been detected and reported above.
7728 ReportError(function_pos, "identifier '%s' already defined", 7704 ASSERT(existing_var->owner() == current_block_->scope);
7729 function_variable->name().ToCString()); 7705 ReportError(function_pos, "identifier '%s' already defined",
7730 } else { 7706 function_variable->name().ToCString());
7731 ReportError(function_pos,
7732 "'%s' from outer scope has already been used, "
7733 "cannot redefine",
7734 function_variable->name().ToCString());
7735 }
7736 } 7707 }
7737 } 7708 }
7738 7709
7739 // Parse the local function. 7710 // Parse the local function.
7740 SequenceNode* statements = Parser::ParseFunc(function); 7711 SequenceNode* statements = Parser::ParseFunc(function);
7741 7712
7742 // Now that the local function has formal parameters, lookup the signature 7713 // Now that the local function has formal parameters, lookup the signature
7743 // class in the current library (but not in its imports) and only create a new 7714 // class in the current library (but not in its imports) and only create a new
7744 // canonical signature class if it does not exist yet. 7715 // canonical signature class if it does not exist yet.
7745 const String& signature = String::Handle(Z, function.Signature()); 7716 const String& signature = String::Handle(Z, function.Signature());
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
9595 Symbols::New(String::Handle(Z, 9566 Symbols::New(String::Handle(Z,
9596 String::NewFormatted("%s%d", 9567 String::NewFormatted("%s%d",
9597 Symbols::AsyncSavedTryCtxVarPrefix().ToCString(), 9568 Symbols::AsyncSavedTryCtxVarPrefix().ToCString(),
9598 last_used_try_index_ - 1)))); 9569 last_used_try_index_ - 1))));
9599 LocalVariable* async_saved_try_ctx = new (Z) LocalVariable( 9570 LocalVariable* async_saved_try_ctx = new (Z) LocalVariable(
9600 Scanner::kNoSourcePos, 9571 Scanner::kNoSourcePos,
9601 async_saved_try_ctx_name, 9572 async_saved_try_ctx_name,
9602 Type::ZoneHandle(Z, Type::DynamicType())); 9573 Type::ZoneHandle(Z, Type::DynamicType()));
9603 ASSERT(async_temp_scope_ != NULL); 9574 ASSERT(async_temp_scope_ != NULL);
9604 async_temp_scope_->AddVariable(async_saved_try_ctx); 9575 async_temp_scope_->AddVariable(async_saved_try_ctx);
9605 current_block_->scope->CaptureVariable(async_saved_try_ctx_name); 9576 current_block_->scope->CaptureVariable(async_saved_try_ctx);
9606 ASSERT(saved_try_context != NULL); 9577 ASSERT(saved_try_context != NULL);
9607 current_block_->statements->Add(new(Z) StoreLocalNode( 9578 current_block_->statements->Add(new(Z) StoreLocalNode(
9608 Scanner::kNoSourcePos, 9579 Scanner::kNoSourcePos,
9609 async_saved_try_ctx, 9580 async_saved_try_ctx,
9610 new(Z) LoadLocalNode(Scanner::kNoSourcePos, saved_try_context))); 9581 new(Z) LoadLocalNode(Scanner::kNoSourcePos, saved_try_context)));
9611 } 9582 }
9612 9583
9613 9584
9614 // We create three variables for exceptions: 9585 // We create three variables for exceptions:
9615 // ':saved_try_context_var' - Used to save the context before the start of 9586 // ':saved_try_context_var' - Used to save the context before the start of
(...skipping 4702 matching lines...) Expand 10 before | Expand all | Expand 10 after
14318 void Parser::SkipQualIdent() { 14289 void Parser::SkipQualIdent() {
14319 ASSERT(IsIdentifier()); 14290 ASSERT(IsIdentifier());
14320 ConsumeToken(); 14291 ConsumeToken();
14321 if (CurrentToken() == Token::kPERIOD) { 14292 if (CurrentToken() == Token::kPERIOD) {
14322 ConsumeToken(); // Consume the kPERIOD token. 14293 ConsumeToken(); // Consume the kPERIOD token.
14323 ExpectIdentifier("identifier expected after '.'"); 14294 ExpectIdentifier("identifier expected after '.'");
14324 } 14295 }
14325 } 14296 }
14326 14297
14327 } // namespace dart 14298 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698