| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 set_saved_entry_context_var(context_var); | 216 set_saved_entry_context_var(context_var); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Frame indices are relative to the frame pointer and are decreasing. | 220 // Frame indices are relative to the frame pointer and are decreasing. |
| 221 ASSERT(next_free_frame_index <= first_stack_local_index_); | 221 ASSERT(next_free_frame_index <= first_stack_local_index_); |
| 222 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; | 222 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; |
| 223 } | 223 } |
| 224 | 224 |
| 225 | 225 |
| 226 struct CatchParamDesc { |
| 227 CatchParamDesc() |
| 228 : token_pos(0), type(NULL), name(NULL), var(NULL) { } |
| 229 intptr_t token_pos; |
| 230 const AbstractType* type; |
| 231 const String* name; |
| 232 LocalVariable* var; |
| 233 }; |
| 234 |
| 235 |
| 226 struct Parser::Block : public ZoneAllocated { | 236 struct Parser::Block : public ZoneAllocated { |
| 227 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) | 237 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) |
| 228 : parent(outer_block), scope(local_scope), statements(seq) { | 238 : parent(outer_block), scope(local_scope), statements(seq) { |
| 229 ASSERT(scope != NULL); | 239 ASSERT(scope != NULL); |
| 230 ASSERT(statements != NULL); | 240 ASSERT(statements != NULL); |
| 231 } | 241 } |
| 232 Block* parent; // Enclosing block, or NULL if outermost. | 242 Block* parent; // Enclosing block, or NULL if outermost. |
| 233 LocalScope* scope; | 243 LocalScope* scope; |
| 234 SequenceNode* statements; | 244 SequenceNode* statements; |
| 235 }; | 245 }; |
| (...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2987 } | 2997 } |
| 2988 ASSERT((CurrentToken() == Token::kLPAREN) || | 2998 ASSERT((CurrentToken() == Token::kLPAREN) || |
| 2989 func.IsGetterFunction() || | 2999 func.IsGetterFunction() || |
| 2990 func.is_async_closure()); | 3000 func.is_async_closure()); |
| 2991 const bool allow_explicit_default_values = true; | 3001 const bool allow_explicit_default_values = true; |
| 2992 if (func.IsGetterFunction()) { | 3002 if (func.IsGetterFunction()) { |
| 2993 // Populate function scope with the formal parameters. Since in this case | 3003 // Populate function scope with the formal parameters. Since in this case |
| 2994 // we are compiling a getter this will at most populate the receiver. | 3004 // we are compiling a getter this will at most populate the receiver. |
| 2995 AddFormalParamsToScope(¶ms, current_block_->scope); | 3005 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2996 } else if (func.is_async_closure()) { | 3006 } else if (func.is_async_closure()) { |
| 2997 // Async closures have one optional parameter for continuation results. | 3007 // Async closures have two optional parameters: |
| 3008 // * A continuation result. |
| 3009 // * A continuation error. |
| 3010 // |
| 3011 // If the error!=null we rethrow the error at the next await. |
| 3012 const Type& dynamic_type = Type::ZoneHandle(I, Type::DynamicType()); |
| 2998 ParamDesc result_param; | 3013 ParamDesc result_param; |
| 2999 result_param.name = &Symbols::AsyncOperationParam(); | 3014 result_param.name = &Symbols::AsyncOperationParam(); |
| 3000 result_param.default_value = &Object::null_instance(); | 3015 result_param.default_value = &Object::null_instance(); |
| 3001 result_param.type = &Type::ZoneHandle(I, Type::DynamicType()); | 3016 result_param.type = &dynamic_type; |
| 3017 ParamDesc error_param; |
| 3018 error_param.name = &Symbols::AsyncOperationErrorParam(); |
| 3019 error_param.default_value = &Object::null_instance(); |
| 3020 error_param.type = &dynamic_type; |
| 3002 params.parameters->Add(result_param); | 3021 params.parameters->Add(result_param); |
| 3003 params.num_optional_parameters++; | 3022 params.parameters->Add(error_param); |
| 3023 params.num_optional_parameters += 2; |
| 3004 params.has_optional_positional_parameters = true; | 3024 params.has_optional_positional_parameters = true; |
| 3005 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 3025 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 3006 AddFormalParamsToScope(¶ms, current_block_->scope); | 3026 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3007 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); | 3027 ASSERT(AbstractType::Handle(I, func.result_type()).IsResolved()); |
| 3008 ASSERT(func.NumParameters() == params.parameters->length()); | 3028 ASSERT(func.NumParameters() == params.parameters->length()); |
| 3009 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { | 3029 if (!Function::Handle(func.parent_function()).IsGetterFunction()) { |
| 3010 // Parse away any formal parameters, as they are accessed as as context | 3030 // Parse away any formal parameters, as they are accessed as as context |
| 3011 // variables. | 3031 // variables. |
| 3012 ParamList parse_away; | 3032 ParamList parse_away; |
| 3013 ParseFormalParameterList(allow_explicit_default_values, | 3033 ParseFormalParameterList(allow_explicit_default_values, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3055 } | 3075 } |
| 3056 | 3076 |
| 3057 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); | 3077 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); |
| 3058 func.set_modifier(func_modifier); | 3078 func.set_modifier(func_modifier); |
| 3059 | 3079 |
| 3060 OpenBlock(); // Open a nested scope for the outermost function block. | 3080 OpenBlock(); // Open a nested scope for the outermost function block. |
| 3061 | 3081 |
| 3062 Function& async_closure = Function::ZoneHandle(I); | 3082 Function& async_closure = Function::ZoneHandle(I); |
| 3063 if (func.IsAsyncFunction() && !func.is_async_closure()) { | 3083 if (func.IsAsyncFunction() && !func.is_async_closure()) { |
| 3064 async_closure = OpenAsyncFunction(formal_params_pos); | 3084 async_closure = OpenAsyncFunction(formal_params_pos); |
| 3065 async_temp_scope_ = current_block_->scope; | |
| 3066 } else if (func.is_async_closure()) { | 3085 } else if (func.is_async_closure()) { |
| 3067 OpenAsyncClosure(); | 3086 OpenAsyncClosure(); |
| 3068 async_temp_scope_ = current_block_->scope; | |
| 3069 } | 3087 } |
| 3070 | 3088 |
| 3071 bool saved_await_is_keyword = await_is_keyword_; | 3089 bool saved_await_is_keyword = await_is_keyword_; |
| 3072 if (func.IsAsyncFunction() || func.is_async_closure()) { | 3090 if (func.IsAsyncFunction() || func.is_async_closure()) { |
| 3073 await_is_keyword_ = true; | 3091 await_is_keyword_ = true; |
| 3074 } | 3092 } |
| 3075 | 3093 |
| 3076 intptr_t end_token_pos = 0; | 3094 intptr_t end_token_pos = 0; |
| 3077 if (CurrentToken() == Token::kLBRACE) { | 3095 if (CurrentToken() == Token::kLBRACE) { |
| 3078 ConsumeToken(); | 3096 ConsumeToken(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3129 UnexpectedToken(); | 3147 UnexpectedToken(); |
| 3130 } | 3148 } |
| 3131 | 3149 |
| 3132 ASSERT(func.end_token_pos() == func.token_pos() || | 3150 ASSERT(func.end_token_pos() == func.token_pos() || |
| 3133 func.end_token_pos() == end_token_pos); | 3151 func.end_token_pos() == end_token_pos); |
| 3134 func.set_end_token_pos(end_token_pos); | 3152 func.set_end_token_pos(end_token_pos); |
| 3135 SequenceNode* body = CloseBlock(); | 3153 SequenceNode* body = CloseBlock(); |
| 3136 if (func.IsAsyncFunction() && !func.is_async_closure()) { | 3154 if (func.IsAsyncFunction() && !func.is_async_closure()) { |
| 3137 body = CloseAsyncFunction(async_closure, body); | 3155 body = CloseAsyncFunction(async_closure, body); |
| 3138 } else if (func.is_async_closure()) { | 3156 } else if (func.is_async_closure()) { |
| 3139 CloseAsyncClosure(body); | 3157 body = CloseAsyncClosure(body); |
| 3140 } | 3158 } |
| 3141 current_block_->statements->Add(body); | 3159 current_block_->statements->Add(body); |
| 3142 innermost_function_ = saved_innermost_function.raw(); | 3160 innermost_function_ = saved_innermost_function.raw(); |
| 3143 last_used_try_index_ = saved_try_index; | 3161 last_used_try_index_ = saved_try_index; |
| 3144 await_is_keyword_ = saved_await_is_keyword; | 3162 await_is_keyword_ = saved_await_is_keyword; |
| 3145 async_temp_scope_ = saved_async_temp_scope; | 3163 async_temp_scope_ = saved_async_temp_scope; |
| 3146 parsed_function()->set_saved_try_ctx(saved_saved_try_ctx); | 3164 parsed_function()->set_saved_try_ctx(saved_saved_try_ctx); |
| 3147 parsed_function()->set_async_saved_try_ctx_name( | 3165 parsed_function()->set_async_saved_try_ctx_name( |
| 3148 saved_async_saved_try_ctx_name); | 3166 saved_async_saved_try_ctx_name); |
| 3149 return CloseBlock(); | 3167 return CloseBlock(); |
| (...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5538 new(I) LocalScope(current_block_->scope, | 5556 new(I) LocalScope(current_block_->scope, |
| 5539 current_block_->scope->function_level() + 1, | 5557 current_block_->scope->function_level() + 1, |
| 5540 0); | 5558 0); |
| 5541 } | 5559 } |
| 5542 ChainNewBlock(outer_scope); | 5560 ChainNewBlock(outer_scope); |
| 5543 } | 5561 } |
| 5544 | 5562 |
| 5545 | 5563 |
| 5546 void Parser::OpenAsyncClosure() { | 5564 void Parser::OpenAsyncClosure() { |
| 5547 TRACE_PARSER("OpenAsyncClosure"); | 5565 TRACE_PARSER("OpenAsyncClosure"); |
| 5566 |
| 5567 async_temp_scope_ = current_block_->scope; |
| 5568 |
| 5569 OpenAsyncTryBlock(); |
| 5548 } | 5570 } |
| 5549 | 5571 |
| 5550 | 5572 |
| 5573 SequenceNode* Parser::CloseAsyncTryBlock(SequenceNode* try_block) { |
| 5574 try_blocks_list_->enter_catch(); |
| 5575 |
| 5576 OpenBlock(); |
| 5577 OpenBlock(); |
| 5578 const AbstractType& dynamic_type = |
| 5579 AbstractType::ZoneHandle(I, Type::DynamicType()); |
| 5580 CatchParamDesc exception_param; |
| 5581 CatchParamDesc stack_trace_param; |
| 5582 exception_param.token_pos = Scanner::kNoSourcePos; |
| 5583 exception_param.type = &dynamic_type; |
| 5584 exception_param.name = &Symbols::ExceptionParameter(); |
| 5585 stack_trace_param.token_pos = Scanner::kNoSourcePos; |
| 5586 stack_trace_param.type = &dynamic_type; |
| 5587 stack_trace_param.name = &Symbols::StackTraceParameter(); |
| 5588 |
| 5589 AddCatchParamsToScope( |
| 5590 &exception_param, &stack_trace_param, current_block_->scope); |
| 5591 |
| 5592 LocalVariable* context_var = current_block_->scope->LookupVariable( |
| 5593 Symbols::SavedTryContextVar(), false); |
| 5594 ASSERT(context_var != NULL); |
| 5595 LocalVariable* exception_var = current_block_->scope->LookupVariable( |
| 5596 Symbols::ExceptionVar(), false); |
| 5597 if (exception_param.var != NULL) { |
| 5598 // Generate code to load the exception object (:exception_var) into |
| 5599 // the exception variable specified in this block. |
| 5600 ASSERT(exception_var != NULL); |
| 5601 current_block_->statements->Add(new(I) StoreLocalNode( |
| 5602 Scanner::kNoSourcePos, |
| 5603 exception_param.var, |
| 5604 new(I) LoadLocalNode(Scanner::kNoSourcePos, exception_var))); |
| 5605 } |
| 5606 LocalVariable* stack_trace_var = |
| 5607 current_block_->scope->LookupVariable(Symbols::StackTraceVar(), false); |
| 5608 if (stack_trace_param.var != NULL) { |
| 5609 // A stack trace variable is specified in this block, so generate code |
| 5610 // to load the stack trace object (:stack_trace_var) into the stack |
| 5611 // trace variable specified in this block. |
| 5612 ArgumentListNode* no_args = new(I) ArgumentListNode(Scanner::kNoSourcePos); |
| 5613 ASSERT(stack_trace_var != NULL); |
| 5614 current_block_->statements->Add(new(I) StoreLocalNode( |
| 5615 Scanner::kNoSourcePos, |
| 5616 stack_trace_param.var, |
| 5617 new(I) LoadLocalNode(Scanner::kNoSourcePos, stack_trace_var))); |
| 5618 current_block_->statements->Add(new(I) InstanceCallNode( |
| 5619 Scanner::kNoSourcePos, |
| 5620 new(I) LoadLocalNode(Scanner::kNoSourcePos, stack_trace_param.var), |
| 5621 Library::PrivateCoreLibName(Symbols::_setupFullStackTrace()), |
| 5622 no_args)); |
| 5623 } |
| 5624 |
| 5625 ASSERT(try_blocks_list_ != NULL); |
| 5626 if (innermost_function().is_async_closure() || |
| 5627 innermost_function().IsAsyncFunction()) { |
| 5628 if ((try_blocks_list_->outer_try_block() != NULL) && |
| 5629 (try_blocks_list_->outer_try_block()->try_block() |
| 5630 ->scope->function_level() == |
| 5631 current_block_->scope->function_level())) { |
| 5632 // We need to unchain three scope levels: catch clause, catch |
| 5633 // parameters, and the general try block. |
| 5634 RestoreSavedTryContext( |
| 5635 current_block_->scope->parent()->parent()->parent(), |
| 5636 try_blocks_list_->outer_try_block()->try_index(), |
| 5637 current_block_->statements); |
| 5638 } else { |
| 5639 parsed_function()->reset_saved_try_ctx_vars(); |
| 5640 } |
| 5641 } |
| 5642 |
| 5643 // Complete the async future with an error. |
| 5644 // Since we control the catch block there is no need to generate a nested |
| 5645 // if/then/else. |
| 5646 LocalVariable* async_completer = current_block_->scope->LookupVariable( |
| 5647 Symbols::AsyncCompleter(), false); |
| 5648 ASSERT(async_completer != NULL); |
| 5649 ArgumentListNode* completer_args = |
| 5650 new (I) ArgumentListNode(Scanner::kNoSourcePos); |
| 5651 completer_args->Add( |
| 5652 new (I) LoadLocalNode(Scanner::kNoSourcePos, exception_param.var)); |
| 5653 completer_args->Add( |
| 5654 new (I) LoadLocalNode(Scanner::kNoSourcePos, stack_trace_param.var)); |
| 5655 current_block_->statements->Add(new (I) InstanceCallNode( |
| 5656 Scanner::kNoSourcePos, |
| 5657 new (I) LoadLocalNode(Scanner::kNoSourcePos, async_completer), |
| 5658 Symbols::CompleterCompleteError(), |
| 5659 completer_args)); |
| 5660 ReturnNode* return_node = new (I) ReturnNode(Scanner::kNoSourcePos); |
| 5661 // Behavior like a continuation return, i.e,. don't call a completer. |
| 5662 return_node->set_return_type(ReturnNode::kContinuation); |
| 5663 current_block_->statements->Add(return_node); |
| 5664 AstNode* catch_block = CloseBlock(); |
| 5665 current_block_->statements->Add(catch_block); |
| 5666 SequenceNode* catch_handler_list = CloseBlock(); |
| 5667 |
| 5668 const GrowableObjectArray& handler_types = |
| 5669 GrowableObjectArray::Handle(I, GrowableObjectArray::New()); |
| 5670 handler_types.SetLength(0); |
| 5671 handler_types.Add(*exception_param.type); |
| 5672 |
| 5673 TryBlocks* inner_try_block = PopTryBlock(); |
| 5674 const intptr_t try_index = inner_try_block->try_index(); |
| 5675 |
| 5676 CatchClauseNode* catch_clause = new (I) CatchClauseNode( |
| 5677 Scanner::kNoSourcePos, |
| 5678 catch_handler_list, |
| 5679 Array::ZoneHandle(I, Array::MakeArray(handler_types)), |
| 5680 context_var, |
| 5681 exception_var, |
| 5682 stack_trace_var, |
| 5683 CatchClauseNode::kInvalidTryIndex, |
| 5684 true); |
| 5685 AstNode* try_catch_node = new (I) TryCatchNode( |
| 5686 Scanner::kNoSourcePos, |
| 5687 try_block, |
| 5688 context_var, |
| 5689 catch_clause, |
| 5690 NULL, |
| 5691 try_index); |
| 5692 current_block_->statements->Add(try_catch_node); |
| 5693 return CloseBlock(); |
| 5694 } |
| 5695 |
| 5696 |
| 5697 void Parser::OpenAsyncTryBlock() { |
| 5698 // Manually wrapping the actual body into a try/catch block. |
| 5699 LocalVariable* context_var = |
| 5700 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); |
| 5701 if (context_var == NULL) { |
| 5702 context_var = new(I) LocalVariable( |
| 5703 TokenPos(), |
| 5704 Symbols::SavedTryContextVar(), |
| 5705 Type::ZoneHandle(I, Type::DynamicType())); |
| 5706 current_block_->scope->AddVariable(context_var); |
| 5707 } |
| 5708 LocalVariable* exception_var = |
| 5709 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); |
| 5710 if (exception_var == NULL) { |
| 5711 exception_var = new(I) LocalVariable( |
| 5712 TokenPos(), |
| 5713 Symbols::ExceptionVar(), |
| 5714 Type::ZoneHandle(I, Type::DynamicType())); |
| 5715 current_block_->scope->AddVariable(exception_var); |
| 5716 } |
| 5717 LocalVariable* stack_trace_var = |
| 5718 current_block_->scope->LocalLookupVariable(Symbols::StackTraceVar()); |
| 5719 if (stack_trace_var == NULL) { |
| 5720 stack_trace_var = new(I) LocalVariable( |
| 5721 TokenPos(), |
| 5722 Symbols::StackTraceVar(), |
| 5723 Type::ZoneHandle(I, Type::DynamicType())); |
| 5724 current_block_->scope->AddVariable(stack_trace_var); |
| 5725 } |
| 5726 |
| 5727 // Open the try block. |
| 5728 OpenBlock(); |
| 5729 PushTryBlock(current_block_); |
| 5730 |
| 5731 if (innermost_function().is_async_closure() || |
| 5732 innermost_function().IsAsyncFunction()) { |
| 5733 SetupSavedTryContext(context_var); |
| 5734 } |
| 5735 } |
| 5736 |
| 5737 |
| 5551 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) { | 5738 RawFunction* Parser::OpenAsyncFunction(intptr_t formal_param_pos) { |
| 5552 TRACE_PARSER("OpenAsyncFunction"); | 5739 TRACE_PARSER("OpenAsyncFunction"); |
| 5553 | 5740 |
| 5554 AddAsyncClosureVariables(); | 5741 AddAsyncClosureVariables(); |
| 5555 | 5742 |
| 5556 // Create the closure containing the old body of this function. | 5743 // Create the closure containing the old body of this function. |
| 5557 Class& sig_cls = Class::ZoneHandle(I); | 5744 Class& sig_cls = Class::ZoneHandle(I); |
| 5558 Type& sig_type = Type::ZoneHandle(I); | 5745 Type& sig_type = Type::ZoneHandle(I); |
| 5559 Function& closure = Function::ZoneHandle(I); | 5746 Function& closure = Function::ZoneHandle(I); |
| 5560 String& sig = String::ZoneHandle(I); | 5747 String& sig = String::ZoneHandle(I); |
| 5561 ParamList closure_params; | 5748 ParamList closure_params; |
| 5749 const Type& dynamic_type = Type::ZoneHandle(I, Type::DynamicType()); |
| 5562 closure_params.AddFinalParameter( | 5750 closure_params.AddFinalParameter( |
| 5563 formal_param_pos, | 5751 formal_param_pos, &Symbols::ClosureParameter(), &dynamic_type); |
| 5564 &Symbols::ClosureParameter(), | |
| 5565 &Type::ZoneHandle(I, Type::DynamicType())); | |
| 5566 ParamDesc result_param; | 5752 ParamDesc result_param; |
| 5567 result_param.name = &Symbols::AsyncOperationParam(); | 5753 result_param.name = &Symbols::AsyncOperationParam(); |
| 5568 result_param.default_value = &Object::null_instance(); | 5754 result_param.default_value = &Object::null_instance(); |
| 5569 result_param.type = &Type::ZoneHandle(I, Type::DynamicType()); | 5755 result_param.type = &dynamic_type; |
| 5756 ParamDesc error_param; |
| 5757 error_param.name = &Symbols::AsyncOperationErrorParam(); |
| 5758 error_param.default_value = &Object::null_instance(); |
| 5759 error_param.type = &dynamic_type; |
| 5570 closure_params.parameters->Add(result_param); | 5760 closure_params.parameters->Add(result_param); |
| 5761 closure_params.parameters->Add(error_param); |
| 5571 closure_params.has_optional_positional_parameters = true; | 5762 closure_params.has_optional_positional_parameters = true; |
| 5572 closure_params.num_optional_parameters++; | 5763 closure_params.num_optional_parameters += 2; |
| 5573 closure = Function::NewClosureFunction( | 5764 closure = Function::NewClosureFunction( |
| 5574 Symbols::AnonymousClosure(), | 5765 Symbols::AnonymousClosure(), |
| 5575 innermost_function(), | 5766 innermost_function(), |
| 5576 formal_param_pos); | 5767 formal_param_pos); |
| 5577 AddFormalParamsToFunction(&closure_params, closure); | 5768 AddFormalParamsToFunction(&closure_params, closure); |
| 5578 closure.set_is_async_closure(true); | 5769 closure.set_is_async_closure(true); |
| 5579 closure.set_result_type(AbstractType::Handle(Type::DynamicType())); | 5770 closure.set_result_type(AbstractType::Handle(Type::DynamicType())); |
| 5580 sig = closure.Signature(); | 5771 sig = closure.Signature(); |
| 5581 sig_cls = library_.LookupLocalClass(sig); | 5772 sig_cls = library_.LookupLocalClass(sig); |
| 5582 if (sig_cls.IsNull()) { | 5773 if (sig_cls.IsNull()) { |
| 5583 sig_cls = Class::NewSignatureClass(sig, closure, script_, formal_param_pos); | 5774 sig_cls = Class::NewSignatureClass(sig, closure, script_, formal_param_pos); |
| 5584 library_.AddClass(sig_cls); | 5775 library_.AddClass(sig_cls); |
| 5585 } | 5776 } |
| 5586 closure.set_signature_class(sig_cls); | 5777 closure.set_signature_class(sig_cls); |
| 5587 sig_type = sig_cls.SignatureType(); | 5778 sig_type = sig_cls.SignatureType(); |
| 5588 if (!sig_type.IsFinalized()) { | 5779 if (!sig_type.IsFinalized()) { |
| 5589 ClassFinalizer::FinalizeType( | 5780 ClassFinalizer::FinalizeType( |
| 5590 sig_cls, sig_type, ClassFinalizer::kCanonicalize); | 5781 sig_cls, sig_type, ClassFinalizer::kCanonicalize); |
| 5591 } | 5782 } |
| 5592 ASSERT(AbstractType::Handle(I, closure.result_type()).IsResolved()); | 5783 ASSERT(AbstractType::Handle(I, closure.result_type()).IsResolved()); |
| 5593 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 5784 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
| 5594 OpenFunctionBlock(closure); | 5785 OpenFunctionBlock(closure); |
| 5595 AddFormalParamsToScope(&closure_params, current_block_->scope); | 5786 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| 5596 OpenBlock(); | 5787 OpenBlock(); |
| 5788 |
| 5789 async_temp_scope_ = current_block_->scope; |
| 5790 |
| 5597 return closure.raw(); | 5791 return closure.raw(); |
| 5598 } | 5792 } |
| 5599 | 5793 |
| 5600 | 5794 |
| 5601 void Parser::AddAsyncClosureVariables() { | 5795 void Parser::AddAsyncClosureVariables() { |
| 5602 // Add to AST: | 5796 // Add to AST: |
| 5603 // var :await_jump_var; | 5797 // var :await_jump_var; |
| 5604 // var :await_ctx_var; | 5798 // var :await_ctx_var; |
| 5605 // var :async_op; | 5799 // var :async_op; |
| 5606 // var :async_completer; | 5800 // var :async_completer; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5730 Scanner::kNoSourcePos, | 5924 Scanner::kNoSourcePos, |
| 5731 new (I) LoadLocalNode( | 5925 new (I) LoadLocalNode( |
| 5732 Scanner::kNoSourcePos, | 5926 Scanner::kNoSourcePos, |
| 5733 async_completer), | 5927 async_completer), |
| 5734 Symbols::CompleterFuture())); | 5928 Symbols::CompleterFuture())); |
| 5735 current_block_->statements->Add(return_node); | 5929 current_block_->statements->Add(return_node); |
| 5736 return CloseBlock(); | 5930 return CloseBlock(); |
| 5737 } | 5931 } |
| 5738 | 5932 |
| 5739 | 5933 |
| 5740 void Parser::CloseAsyncClosure(SequenceNode* body) { | 5934 SequenceNode* Parser::CloseAsyncClosure(SequenceNode* body) { |
| 5741 TRACE_PARSER("CloseAsyncClosure"); | 5935 TRACE_PARSER("CloseAsyncClosure"); |
| 5936 |
| 5742 // We need a temporary expression to store intermediate return values. | 5937 // We need a temporary expression to store intermediate return values. |
| 5743 parsed_function()->EnsureExpressionTemp(); | 5938 parsed_function()->EnsureExpressionTemp(); |
| 5744 // Implicitly mark those variables below as captured. We currently mark all | 5939 // Implicitly mark those variables below as captured. We currently mark all |
| 5745 // variables of all scopes as captured (below), but as soon as we do something | 5940 // variables of all scopes as captured (below), but as soon as we do something |
| 5746 // smarter we rely on these internal variables to be available. | 5941 // smarter we rely on these internal variables to be available. |
| 5747 body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); | 5942 SequenceNode* new_body = CloseAsyncTryBlock(body); |
| 5748 body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); | 5943 ASSERT(new_body != NULL); |
| 5749 body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); | 5944 ASSERT(new_body->scope() != NULL); |
| 5750 body->scope()->RecursivelyCaptureAllVariables(); | 5945 new_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); |
| 5946 new_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); |
| 5947 new_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); |
| 5948 new_body->scope()->RecursivelyCaptureAllVariables(); |
| 5949 return new_body; |
| 5751 } | 5950 } |
| 5752 | 5951 |
| 5753 | 5952 |
| 5754 // Set up default values for all optional parameters to the function. | 5953 // Set up default values for all optional parameters to the function. |
| 5755 void Parser::SetupDefaultsForOptionalParams(const ParamList* params, | 5954 void Parser::SetupDefaultsForOptionalParams(const ParamList* params, |
| 5756 Array* default_values) { | 5955 Array* default_values) { |
| 5757 if (params->num_optional_parameters > 0) { | 5956 if (params->num_optional_parameters > 0) { |
| 5758 // Build array of default parameter values. | 5957 // Build array of default parameter values. |
| 5759 ParamDesc* param = | 5958 ParamDesc* param = |
| 5760 params->parameters->data() + params->num_fixed_parameters; | 5959 params->parameters->data() + params->num_fixed_parameters; |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7263 condition = new(I) UnaryOpNode(condition_pos, Token::kNOT, condition); | 7462 condition = new(I) UnaryOpNode(condition_pos, Token::kNOT, condition); |
| 7264 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); | 7463 AstNode* assert_throw = MakeAssertCall(condition_pos, condition_end); |
| 7265 return new(I) IfNode( | 7464 return new(I) IfNode( |
| 7266 condition_pos, | 7465 condition_pos, |
| 7267 condition, | 7466 condition, |
| 7268 NodeAsSequenceNode(condition_pos, assert_throw, NULL), | 7467 NodeAsSequenceNode(condition_pos, assert_throw, NULL), |
| 7269 NULL); | 7468 NULL); |
| 7270 } | 7469 } |
| 7271 | 7470 |
| 7272 | 7471 |
| 7273 struct CatchParamDesc { | |
| 7274 CatchParamDesc() | |
| 7275 : token_pos(0), type(NULL), name(NULL), var(NULL) { } | |
| 7276 intptr_t token_pos; | |
| 7277 const AbstractType* type; | |
| 7278 const String* name; | |
| 7279 LocalVariable* var; | |
| 7280 }; | |
| 7281 | |
| 7282 | |
| 7283 // Populate local scope of the catch block with the catch parameters. | 7472 // Populate local scope of the catch block with the catch parameters. |
| 7284 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, | 7473 void Parser::AddCatchParamsToScope(CatchParamDesc* exception_param, |
| 7285 CatchParamDesc* stack_trace_param, | 7474 CatchParamDesc* stack_trace_param, |
| 7286 LocalScope* scope) { | 7475 LocalScope* scope) { |
| 7287 if (exception_param->name != NULL) { | 7476 if (exception_param->name != NULL) { |
| 7288 LocalVariable* var = new(I) LocalVariable( | 7477 LocalVariable* var = new(I) LocalVariable( |
| 7289 exception_param->token_pos, | 7478 exception_param->token_pos, |
| 7290 *exception_param->name, | 7479 *exception_param->name, |
| 7291 *exception_param->type); | 7480 *exception_param->type); |
| 7292 var->set_is_final(); | 7481 var->set_is_final(); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7576 type_tests.RemoveLast(); | 7765 type_tests.RemoveLast(); |
| 7577 current_block_->statements->Add(catch_blocks.RemoveLast()); | 7766 current_block_->statements->Add(catch_blocks.RemoveLast()); |
| 7578 current = CloseBlock(); | 7767 current = CloseBlock(); |
| 7579 } | 7768 } |
| 7580 // If the last body was entered conditionally and there is no need to add | 7769 // If the last body was entered conditionally and there is no need to add |
| 7581 // a rethrow, use an empty else body (current = NULL above). | 7770 // a rethrow, use an empty else body (current = NULL above). |
| 7582 | 7771 |
| 7583 while (!type_tests.is_empty()) { | 7772 while (!type_tests.is_empty()) { |
| 7584 AstNode* type_test = type_tests.RemoveLast(); | 7773 AstNode* type_test = type_tests.RemoveLast(); |
| 7585 SequenceNode* catch_block = catch_blocks.RemoveLast(); | 7774 SequenceNode* catch_block = catch_blocks.RemoveLast(); |
| 7775 |
| 7776 // In case of async closures we need to restore the saved try index of an |
| 7777 // outer try block (if it exists). |
| 7778 ASSERT(try_blocks_list_ != NULL); |
| 7779 if (innermost_function().is_async_closure() || |
| 7780 innermost_function().IsAsyncFunction()) { |
| 7781 if ((try_blocks_list_->outer_try_block() != NULL) && |
| 7782 (try_blocks_list_->outer_try_block()->try_block() |
| 7783 ->scope->function_level() == |
| 7784 current_block_->scope->function_level())) { |
| 7785 // We need to unchain three scope levels: catch clause, catch |
| 7786 // parameters, and the general try block. |
| 7787 RestoreSavedTryContext( |
| 7788 current_block_->scope->parent()->parent(), |
| 7789 try_blocks_list_->outer_try_block()->try_index(), |
| 7790 current_block_->statements); |
| 7791 } else { |
| 7792 parsed_function()->reset_saved_try_ctx_vars(); |
| 7793 } |
| 7794 } |
| 7795 |
| 7586 current_block_->statements->Add(new(I) IfNode( | 7796 current_block_->statements->Add(new(I) IfNode( |
| 7587 type_test->token_pos(), type_test, catch_block, current)); | 7797 type_test->token_pos(), type_test, catch_block, current)); |
| 7588 current = CloseBlock(); | 7798 current = CloseBlock(); |
| 7589 } | 7799 } |
| 7590 return current; | 7800 return current; |
| 7591 } | 7801 } |
| 7592 | 7802 |
| 7593 | 7803 |
| 7594 void Parser::SetupSavedTryContext(LocalVariable* saved_try_context) { | 7804 void Parser::SetupSavedTryContext(LocalVariable* saved_try_context) { |
| 7595 const String& async_saved_try_ctx_name = | 7805 const String& async_saved_try_ctx_name = |
| (...skipping 3968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11564 void Parser::SkipQualIdent() { | 11774 void Parser::SkipQualIdent() { |
| 11565 ASSERT(IsIdentifier()); | 11775 ASSERT(IsIdentifier()); |
| 11566 ConsumeToken(); | 11776 ConsumeToken(); |
| 11567 if (CurrentToken() == Token::kPERIOD) { | 11777 if (CurrentToken() == Token::kPERIOD) { |
| 11568 ConsumeToken(); // Consume the kPERIOD token. | 11778 ConsumeToken(); // Consume the kPERIOD token. |
| 11569 ExpectIdentifier("identifier expected after '.'"); | 11779 ExpectIdentifier("identifier expected after '.'"); |
| 11570 } | 11780 } |
| 11571 } | 11781 } |
| 11572 | 11782 |
| 11573 } // namespace dart | 11783 } // namespace dart |
| OLD | NEW |