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

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

Issue 1284103008: Clean up code capturing variables explicitly. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: use correct scope Created 5 years, 4 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 | runtime/vm/scopes.cc » ('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 6716 matching lines...) Expand 10 before | Expand all | Expand 10 after
6727 6727
6728 void Parser::AddContinuationVariables() { 6728 void Parser::AddContinuationVariables() {
6729 // Add to current block's scope: 6729 // Add to current block's scope:
6730 // var :await_jump_var; 6730 // var :await_jump_var;
6731 // var :await_ctx_var; 6731 // var :await_ctx_var;
6732 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6732 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6733 LocalVariable* await_jump_var = new (Z) LocalVariable( 6733 LocalVariable* await_jump_var = new (Z) LocalVariable(
6734 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type); 6734 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type);
6735 current_block_->scope->AddVariable(await_jump_var); 6735 current_block_->scope->AddVariable(await_jump_var);
6736 current_block_->scope->CaptureVariable(Symbols::AwaitJumpVar()); 6736 current_block_->scope->CaptureVariable(Symbols::AwaitJumpVar());
6737 await_jump_var->set_is_captured();
6738 LocalVariable* await_ctx_var = new (Z) LocalVariable( 6737 LocalVariable* await_ctx_var = new (Z) LocalVariable(
6739 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type); 6738 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type);
6740 current_block_->scope->AddVariable(await_ctx_var); 6739 current_block_->scope->AddVariable(await_ctx_var);
6741 current_block_->scope->CaptureVariable(Symbols::AwaitContextVar()); 6740 current_block_->scope->CaptureVariable(Symbols::AwaitContextVar());
6742 await_ctx_var->set_is_captured();
6743 } 6741 }
6744 6742
6745 6743
6746 void Parser::AddAsyncClosureVariables() { 6744 void Parser::AddAsyncClosureVariables() {
6747 // Add to current block's scope: 6745 // Add to current block's scope:
6748 // var :async_op; 6746 // var :async_op;
6749 // var :async_then_callback; 6747 // var :async_then_callback;
6750 // var :async_catch_error_callback; 6748 // var :async_catch_error_callback;
6751 // var :async_completer; 6749 // var :async_completer;
6752 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6750 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6753 LocalVariable* async_op_var = new(Z) LocalVariable( 6751 LocalVariable* async_op_var = new(Z) LocalVariable(
6754 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6752 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6755 current_block_->scope->AddVariable(async_op_var); 6753 current_block_->scope->AddVariable(async_op_var);
6756 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6754 current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
6757 async_op_var->set_is_captured();
6758 LocalVariable* async_then_callback_var = new(Z) LocalVariable( 6755 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6759 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); 6756 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6760 current_block_->scope->AddVariable(async_then_callback_var); 6757 current_block_->scope->AddVariable(async_then_callback_var);
6761 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback()); 6758 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
6762 async_then_callback_var->set_is_captured();
6763 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( 6759 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6764 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); 6760 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6765 current_block_->scope->AddVariable(async_catch_error_callback_var); 6761 current_block_->scope->AddVariable(async_catch_error_callback_var);
6766 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback()); 6762 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
6767 async_catch_error_callback_var->set_is_captured();
6768 LocalVariable* async_completer = new(Z) LocalVariable( 6763 LocalVariable* async_completer = new(Z) LocalVariable(
6769 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type); 6764 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type);
6770 current_block_->scope->AddVariable(async_completer); 6765 current_block_->scope->AddVariable(async_completer);
6771 current_block_->scope->CaptureVariable(Symbols::AsyncCompleter()); 6766 current_block_->scope->CaptureVariable(Symbols::AsyncCompleter());
6772 async_completer->set_is_captured();
6773 } 6767 }
6774 6768
6775 6769
6776 void Parser::AddAsyncGeneratorVariables() { 6770 void Parser::AddAsyncGeneratorVariables() {
6777 // Add to current block's scope: 6771 // Add to current block's scope:
6778 // var :controller; 6772 // var :controller;
6779 // The :controller variable is used by the async generator closure to 6773 // The :controller variable is used by the async generator closure to
6780 // store the StreamController object to which the yielded expressions 6774 // store the StreamController object to which the yielded expressions
6781 // are added. 6775 // are added.
6782 // var :async_op; 6776 // var :async_op;
6783 // var :async_then_callback; 6777 // var :async_then_callback;
6784 // var :async_catch_error_callback; 6778 // var :async_catch_error_callback;
6785 // These variables are used to store the async generator closure containing 6779 // These variables are used to store the async generator closure containing
6786 // the body of the async* function. They are used by the await operator. 6780 // the body of the async* function. They are used by the await operator.
6787 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); 6781 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType());
6788 LocalVariable* controller_var = new(Z) LocalVariable( 6782 LocalVariable* controller_var = new(Z) LocalVariable(
6789 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type); 6783 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type);
6790 current_block_->scope->AddVariable(controller_var); 6784 current_block_->scope->AddVariable(controller_var);
6791 current_block_->scope->CaptureVariable(Symbols::Controller()); 6785 current_block_->scope->CaptureVariable(Symbols::Controller());
6792 controller_var->set_is_captured();
6793 6786
6794 LocalVariable* async_op_var = new(Z) LocalVariable( 6787 LocalVariable* async_op_var = new(Z) LocalVariable(
6795 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); 6788 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type);
6796 current_block_->scope->AddVariable(async_op_var); 6789 current_block_->scope->AddVariable(async_op_var);
6797 current_block_->scope->CaptureVariable(Symbols::AsyncOperation()); 6790 current_block_->scope->CaptureVariable(Symbols::AsyncOperation());
6798 async_op_var->set_is_captured();
6799 LocalVariable* async_then_callback_var = new(Z) LocalVariable( 6791 LocalVariable* async_then_callback_var = new(Z) LocalVariable(
6800 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); 6792 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type);
6801 current_block_->scope->AddVariable(async_then_callback_var); 6793 current_block_->scope->AddVariable(async_then_callback_var);
6802 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback()); 6794 current_block_->scope->CaptureVariable(Symbols::AsyncThenCallback());
6803 async_then_callback_var->set_is_captured();
6804 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( 6795 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable(
6805 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); 6796 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type);
6806 current_block_->scope->AddVariable(async_catch_error_callback_var); 6797 current_block_->scope->AddVariable(async_catch_error_callback_var);
6807 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback()); 6798 current_block_->scope->CaptureVariable(Symbols::AsyncCatchErrorCallback());
6808 async_catch_error_callback_var->set_is_captured();
6809 } 6799 }
6810 6800
6811 6801
6812 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) { 6802 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) {
6813 TRACE_PARSER("OpenAsyncGeneratorFunction"); 6803 TRACE_PARSER("OpenAsyncGeneratorFunction");
6814 AddContinuationVariables(); 6804 AddContinuationVariables();
6815 AddAsyncGeneratorVariables(); 6805 AddAsyncGeneratorVariables();
6816 6806
6817 Function& closure = Function::Handle(Z); 6807 Function& closure = Function::Handle(Z);
6818 bool is_new_closure = false; 6808 bool is_new_closure = false;
(...skipping 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after
9557 Symbols::New(String::Handle(Z, 9547 Symbols::New(String::Handle(Z,
9558 String::NewFormatted("%s%d", 9548 String::NewFormatted("%s%d",
9559 Symbols::AsyncSavedTryCtxVarPrefix().ToCString(), 9549 Symbols::AsyncSavedTryCtxVarPrefix().ToCString(),
9560 last_used_try_index_ - 1)))); 9550 last_used_try_index_ - 1))));
9561 LocalVariable* async_saved_try_ctx = new (Z) LocalVariable( 9551 LocalVariable* async_saved_try_ctx = new (Z) LocalVariable(
9562 Scanner::kNoSourcePos, 9552 Scanner::kNoSourcePos,
9563 async_saved_try_ctx_name, 9553 async_saved_try_ctx_name,
9564 Type::ZoneHandle(Z, Type::DynamicType())); 9554 Type::ZoneHandle(Z, Type::DynamicType()));
9565 ASSERT(async_temp_scope_ != NULL); 9555 ASSERT(async_temp_scope_ != NULL);
9566 async_temp_scope_->AddVariable(async_saved_try_ctx); 9556 async_temp_scope_->AddVariable(async_saved_try_ctx);
9567 async_saved_try_ctx->set_is_captured(); 9557 current_block_->scope->CaptureVariable(async_saved_try_ctx_name);
9568 async_saved_try_ctx = current_block_->scope->LookupVariable(
9569 async_saved_try_ctx_name, false);
9570 ASSERT(async_saved_try_ctx != NULL);
9571 ASSERT(saved_try_context != NULL); 9558 ASSERT(saved_try_context != NULL);
9572 current_block_->statements->Add(new(Z) StoreLocalNode( 9559 current_block_->statements->Add(new(Z) StoreLocalNode(
9573 Scanner::kNoSourcePos, 9560 Scanner::kNoSourcePos,
9574 async_saved_try_ctx, 9561 async_saved_try_ctx,
9575 new(Z) LoadLocalNode(Scanner::kNoSourcePos, saved_try_context))); 9562 new(Z) LoadLocalNode(Scanner::kNoSourcePos, saved_try_context)));
9576 } 9563 }
9577 9564
9578 9565
9579 // We create three variables for exceptions: 9566 // We create three variables for exceptions:
9580 // ':saved_try_context_var' - Used to save the context before the start of 9567 // ':saved_try_context_var' - Used to save the context before the start of
(...skipping 4619 matching lines...) Expand 10 before | Expand all | Expand 10 after
14200 void Parser::SkipQualIdent() { 14187 void Parser::SkipQualIdent() {
14201 ASSERT(IsIdentifier()); 14188 ASSERT(IsIdentifier());
14202 ConsumeToken(); 14189 ConsumeToken();
14203 if (CurrentToken() == Token::kPERIOD) { 14190 if (CurrentToken() == Token::kPERIOD) {
14204 ConsumeToken(); // Consume the kPERIOD token. 14191 ConsumeToken(); // Consume the kPERIOD token.
14205 ExpectIdentifier("identifier expected after '.'"); 14192 ExpectIdentifier("identifier expected after '.'");
14206 } 14193 }
14207 } 14194 }
14208 14195
14209 } // namespace dart 14196 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698