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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 param.type = type; | 551 param.type = type; |
552 this->parameters->Add(param); | 552 this->parameters->Add(param); |
553 } | 553 } |
554 | 554 |
555 void AddReceiver(const AbstractType* receiver_type, intptr_t token_pos) { | 555 void AddReceiver(const AbstractType* receiver_type, intptr_t token_pos) { |
556 ASSERT(this->parameters->is_empty()); | 556 ASSERT(this->parameters->is_empty()); |
557 AddFinalParameter(token_pos, &Symbols::This(), receiver_type); | 557 AddFinalParameter(token_pos, &Symbols::This(), receiver_type); |
558 } | 558 } |
559 | 559 |
560 void EraseParameterTypes() { | 560 void EraseParameterTypes() { |
561 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType()); | |
562 const int num_parameters = parameters->length(); | 561 const int num_parameters = parameters->length(); |
563 for (int i = 0; i < num_parameters; i++) { | 562 for (int i = 0; i < num_parameters; i++) { |
564 (*parameters)[i].type = &dynamic_type; | 563 (*parameters)[i].type = &Object::dynamic_type(); |
565 } | 564 } |
566 } | 565 } |
567 | 566 |
568 // Make the parameter variables visible/invisible. | 567 // Make the parameter variables visible/invisible. |
569 // Field initializer parameters are always invisible. | 568 // Field initializer parameters are always invisible. |
570 void SetInvisible(bool invisible) { | 569 void SetInvisible(bool invisible) { |
571 const intptr_t num_params = parameters->length(); | 570 const intptr_t num_params = parameters->length(); |
572 for (int i = 0; i < num_params; i++) { | 571 for (int i = 0; i < num_params; i++) { |
573 ParamDesc& param = (*parameters)[i]; | 572 ParamDesc& param = (*parameters)[i]; |
574 ASSERT(param.var != NULL); | 573 ASSERT(param.var != NULL); |
(...skipping 4139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 | 4713 |
4715 SkipMetadata(); | 4714 SkipMetadata(); |
4716 ExpectToken(Token::kENUM); | 4715 ExpectToken(Token::kENUM); |
4717 | 4716 |
4718 const String& enum_name = String::Handle(Z, cls.PrettyName()); | 4717 const String& enum_name = String::Handle(Z, cls.PrettyName()); |
4719 ClassDesc enum_members(Z, cls, enum_name, false, cls.token_pos()); | 4718 ClassDesc enum_members(Z, cls, enum_name, false, cls.token_pos()); |
4720 | 4719 |
4721 // Add instance field 'final int index'. | 4720 // Add instance field 'final int index'. |
4722 Field& index_field = Field::ZoneHandle(Z); | 4721 Field& index_field = Field::ZoneHandle(Z); |
4723 const Type& int_type = Type::Handle(Z, Type::IntType()); | 4722 const Type& int_type = Type::Handle(Z, Type::IntType()); |
4724 const Type& dynamic_type = Type::Handle(Type::DynamicType()); | |
4725 index_field = Field::New(Symbols::Index(), | 4723 index_field = Field::New(Symbols::Index(), |
4726 false, // Not static. | 4724 false, // Not static. |
4727 true, // Field is final. | 4725 true, // Field is final. |
4728 false, // Not const. | 4726 false, // Not const. |
4729 true, // Is reflectable. | 4727 true, // Is reflectable. |
4730 cls, | 4728 cls, |
4731 cls.token_pos()); | 4729 cls.token_pos()); |
4732 index_field.set_type(int_type); | 4730 index_field.set_type(int_type); |
4733 enum_members.AddField(index_field); | 4731 enum_members.AddField(index_field); |
4734 | 4732 |
4735 // Add implicit getter for index field. | 4733 // Add implicit getter for index field. |
4736 const String& getter_name = | 4734 const String& getter_name = |
4737 String::Handle(Z, Field::GetterSymbol(Symbols::Index())); | 4735 String::Handle(Z, Field::GetterSymbol(Symbols::Index())); |
4738 Function& getter = Function::Handle(Z); | 4736 Function& getter = Function::Handle(Z); |
4739 getter = Function::New(getter_name, | 4737 getter = Function::New(getter_name, |
4740 RawFunction::kImplicitGetter, | 4738 RawFunction::kImplicitGetter, |
4741 /* is_static = */ false, | 4739 /* is_static = */ false, |
4742 /* is_const = */ true, | 4740 /* is_const = */ true, |
4743 /* is_abstract = */ false, | 4741 /* is_abstract = */ false, |
4744 /* is_external = */ false, | 4742 /* is_external = */ false, |
4745 /* is_native = */ false, | 4743 /* is_native = */ false, |
4746 cls, | 4744 cls, |
4747 cls.token_pos()); | 4745 cls.token_pos()); |
4748 getter.set_result_type(int_type); | 4746 getter.set_result_type(int_type); |
4749 getter.set_is_debuggable(false); | 4747 getter.set_is_debuggable(false); |
4750 ParamList params; | 4748 ParamList params; |
4751 params.AddReceiver(&dynamic_type, cls.token_pos()); | 4749 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); |
4752 AddFormalParamsToFunction(¶ms, getter); | 4750 AddFormalParamsToFunction(¶ms, getter); |
4753 enum_members.AddFunction(getter); | 4751 enum_members.AddFunction(getter); |
4754 | 4752 |
4755 GrowableObjectArray& enum_names = GrowableObjectArray::Handle(Z, | 4753 GrowableObjectArray& enum_names = GrowableObjectArray::Handle(Z, |
4756 GrowableObjectArray::New(8, Heap::kOld)); | 4754 GrowableObjectArray::New(8, Heap::kOld)); |
4757 const String& name_prefix = | 4755 const String& name_prefix = |
4758 String::Handle(String::Concat(enum_name, Symbols::Dot())); | 4756 String::Handle(String::Concat(enum_name, Symbols::Dot())); |
4759 | 4757 |
4760 ASSERT(IsIdentifier()); | 4758 ASSERT(IsIdentifier()); |
4761 ASSERT(CurrentLiteral()->raw() == cls.Name()); | 4759 ASSERT(CurrentLiteral()->raw() == cls.Name()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4794 declared_names.Add(enum_ident); | 4792 declared_names.Add(enum_ident); |
4795 | 4793 |
4796 // Create the static const field for the enumeration value. | 4794 // Create the static const field for the enumeration value. |
4797 enum_value = Field::New(*enum_ident, | 4795 enum_value = Field::New(*enum_ident, |
4798 /* is_static = */ true, | 4796 /* is_static = */ true, |
4799 /* is_final = */ true, | 4797 /* is_final = */ true, |
4800 /* is_const = */ true, | 4798 /* is_const = */ true, |
4801 /* is_reflectable = */ true, | 4799 /* is_reflectable = */ true, |
4802 cls, | 4800 cls, |
4803 cls.token_pos()); | 4801 cls.token_pos()); |
4804 enum_value.set_type(dynamic_type); | 4802 enum_value.set_type(Object::dynamic_type()); |
4805 enum_value.set_has_initializer(false); | 4803 enum_value.set_has_initializer(false); |
4806 enum_members.AddField(enum_value); | 4804 enum_members.AddField(enum_value); |
4807 // Initialize the field with the ordinal value. It will be patched | 4805 // Initialize the field with the ordinal value. It will be patched |
4808 // later with the enum constant instance. | 4806 // later with the enum constant instance. |
4809 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); | 4807 const Smi& ordinal_value = Smi::Handle(Z, Smi::New(i)); |
4810 enum_value.SetStaticValue(ordinal_value, true); | 4808 enum_value.SetStaticValue(ordinal_value, true); |
4811 enum_value.RecordStore(ordinal_value); | 4809 enum_value.RecordStore(ordinal_value); |
4812 i++; | 4810 i++; |
4813 | 4811 |
4814 // For the user-visible name of the enumeration value, we need to | 4812 // For the user-visible name of the enumeration value, we need to |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6230 const intptr_t try_end_pos = innermost_function().end_token_pos(); | 6228 const intptr_t try_end_pos = innermost_function().end_token_pos(); |
6231 | 6229 |
6232 // The try-block (closure body code) has been parsed. We are now | 6230 // The try-block (closure body code) has been parsed. We are now |
6233 // generating the code for the catch block. | 6231 // generating the code for the catch block. |
6234 LocalScope* try_scope = current_block_->scope; | 6232 LocalScope* try_scope = current_block_->scope; |
6235 try_stack_->enter_catch(); | 6233 try_stack_->enter_catch(); |
6236 OpenBlock(); // Catch handler list. | 6234 OpenBlock(); // Catch handler list. |
6237 OpenBlock(); // Catch block. | 6235 OpenBlock(); // Catch block. |
6238 | 6236 |
6239 // Add the exception and stack trace parameters to the scope. | 6237 // Add the exception and stack trace parameters to the scope. |
6240 const AbstractType& dynamic_type = | |
6241 AbstractType::ZoneHandle(Z, Type::DynamicType()); | |
6242 CatchParamDesc exception_param; | 6238 CatchParamDesc exception_param; |
6243 CatchParamDesc stack_trace_param; | 6239 CatchParamDesc stack_trace_param; |
6244 exception_param.token_pos = Scanner::kNoSourcePos; | 6240 exception_param.token_pos = Scanner::kNoSourcePos; |
6245 exception_param.type = &dynamic_type; | 6241 exception_param.type = &Object::dynamic_type(); |
6246 exception_param.name = &Symbols::ExceptionParameter(); | 6242 exception_param.name = &Symbols::ExceptionParameter(); |
6247 stack_trace_param.token_pos = Scanner::kNoSourcePos; | 6243 stack_trace_param.token_pos = Scanner::kNoSourcePos; |
6248 stack_trace_param.type = &dynamic_type; | 6244 stack_trace_param.type = &Object::dynamic_type(); |
6249 stack_trace_param.name = &Symbols::StackTraceParameter(); | 6245 stack_trace_param.name = &Symbols::StackTraceParameter(); |
6250 | 6246 |
6251 AddCatchParamsToScope( | 6247 AddCatchParamsToScope( |
6252 &exception_param, &stack_trace_param, current_block_->scope); | 6248 &exception_param, &stack_trace_param, current_block_->scope); |
6253 | 6249 |
6254 // Generate code to save the exception object and stack trace | 6250 // Generate code to save the exception object and stack trace |
6255 // in local variables. | 6251 // in local variables. |
6256 LocalVariable* context_var = try_scope->LocalLookupVariable( | 6252 LocalVariable* context_var = try_scope->LocalLookupVariable( |
6257 Symbols::SavedTryContextVar()); | 6253 Symbols::SavedTryContextVar()); |
6258 ASSERT(context_var != NULL); | 6254 ASSERT(context_var != NULL); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6360 node_index++; | 6356 node_index++; |
6361 } | 6357 } |
6362 } while (finally_clause == NULL); | 6358 } while (finally_clause == NULL); |
6363 | 6359 |
6364 if (try_stack_ != NULL) { | 6360 if (try_stack_ != NULL) { |
6365 try_stack_->exit_finally(); | 6361 try_stack_->exit_finally(); |
6366 } | 6362 } |
6367 | 6363 |
6368 const GrowableObjectArray& handler_types = | 6364 const GrowableObjectArray& handler_types = |
6369 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 6365 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
6370 handler_types.Add(dynamic_type); // Catch block handles all exceptions. | 6366 // Catch block handles all exceptions. |
| 6367 handler_types.Add(Object::dynamic_type()); |
6371 | 6368 |
6372 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( | 6369 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( |
6373 Scanner::kNoSourcePos, | 6370 Scanner::kNoSourcePos, |
6374 catch_handler_list, | 6371 catch_handler_list, |
6375 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), | 6372 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), |
6376 context_var, | 6373 context_var, |
6377 exception_var, | 6374 exception_var, |
6378 stack_trace_var, | 6375 stack_trace_var, |
6379 saved_exception_var, | 6376 saved_exception_var, |
6380 saved_stack_trace_var, | 6377 saved_stack_trace_var, |
(...skipping 18 matching lines...) Expand all Loading... |
6399 // This is the outermost try-catch of the function. | 6396 // This is the outermost try-catch of the function. |
6400 ASSERT(try_stack_ != NULL); | 6397 ASSERT(try_stack_ != NULL); |
6401 ASSERT(try_stack_->outer_try() == NULL); | 6398 ASSERT(try_stack_->outer_try() == NULL); |
6402 ASSERT(innermost_function().IsAsyncClosure()); | 6399 ASSERT(innermost_function().IsAsyncClosure()); |
6403 LocalScope* try_scope = current_block_->scope; | 6400 LocalScope* try_scope = current_block_->scope; |
6404 | 6401 |
6405 try_stack_->enter_catch(); | 6402 try_stack_->enter_catch(); |
6406 | 6403 |
6407 OpenBlock(); // Catch handler list. | 6404 OpenBlock(); // Catch handler list. |
6408 OpenBlock(); // Catch block. | 6405 OpenBlock(); // Catch block. |
6409 const AbstractType& dynamic_type = | |
6410 AbstractType::ZoneHandle(Z, Type::DynamicType()); | |
6411 CatchParamDesc exception_param; | 6406 CatchParamDesc exception_param; |
6412 CatchParamDesc stack_trace_param; | 6407 CatchParamDesc stack_trace_param; |
6413 exception_param.token_pos = Scanner::kNoSourcePos; | 6408 exception_param.token_pos = Scanner::kNoSourcePos; |
6414 exception_param.type = &dynamic_type; | 6409 exception_param.type = &Object::dynamic_type(); |
6415 exception_param.name = &Symbols::ExceptionParameter(); | 6410 exception_param.name = &Symbols::ExceptionParameter(); |
6416 stack_trace_param.token_pos = Scanner::kNoSourcePos; | 6411 stack_trace_param.token_pos = Scanner::kNoSourcePos; |
6417 stack_trace_param.type = &dynamic_type; | 6412 stack_trace_param.type = &Object::dynamic_type(); |
6418 stack_trace_param.name = &Symbols::StackTraceParameter(); | 6413 stack_trace_param.name = &Symbols::StackTraceParameter(); |
6419 | 6414 |
6420 AddCatchParamsToScope( | 6415 AddCatchParamsToScope( |
6421 &exception_param, &stack_trace_param, current_block_->scope); | 6416 &exception_param, &stack_trace_param, current_block_->scope); |
6422 | 6417 |
6423 LocalVariable* context_var = try_scope->LocalLookupVariable( | 6418 LocalVariable* context_var = try_scope->LocalLookupVariable( |
6424 Symbols::SavedTryContextVar()); | 6419 Symbols::SavedTryContextVar()); |
6425 ASSERT(context_var != NULL); | 6420 ASSERT(context_var != NULL); |
6426 | 6421 |
6427 LocalVariable* exception_var = try_scope->LocalLookupVariable( | 6422 LocalVariable* exception_var = try_scope->LocalLookupVariable( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6537 PushTry(current_block_); | 6532 PushTry(current_block_); |
6538 | 6533 |
6539 SetupSavedTryContext(context_var); | 6534 SetupSavedTryContext(context_var); |
6540 } | 6535 } |
6541 | 6536 |
6542 | 6537 |
6543 void Parser::AddSyncGenClosureParameters(ParamList* params) { | 6538 void Parser::AddSyncGenClosureParameters(ParamList* params) { |
6544 // Create the parameter list for the body closure of a sync generator: | 6539 // Create the parameter list for the body closure of a sync generator: |
6545 // 1) Implicit closure parameter; | 6540 // 1) Implicit closure parameter; |
6546 // 2) Iterator | 6541 // 2) Iterator |
6547 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
6548 // Add implicit closure parameter if not already present. | 6542 // Add implicit closure parameter if not already present. |
6549 if (params->parameters->length() == 0) { | 6543 if (params->parameters->length() == 0) { |
6550 params->AddFinalParameter(0, &Symbols::ClosureParameter(), &dynamic_type); | 6544 params->AddFinalParameter( |
| 6545 0, &Symbols::ClosureParameter(), &Object::dynamic_type()); |
6551 } | 6546 } |
6552 ParamDesc iterator_param; | 6547 ParamDesc iterator_param; |
6553 iterator_param.name = &Symbols::IteratorParameter(); | 6548 iterator_param.name = &Symbols::IteratorParameter(); |
6554 iterator_param.type = &dynamic_type; | 6549 iterator_param.type = &Object::dynamic_type(); |
6555 params->parameters->Add(iterator_param); | 6550 params->parameters->Add(iterator_param); |
6556 params->num_fixed_parameters++; | 6551 params->num_fixed_parameters++; |
6557 } | 6552 } |
6558 | 6553 |
6559 | 6554 |
6560 void Parser::AddAsyncGenClosureParameters(ParamList* params) { | 6555 void Parser::AddAsyncGenClosureParameters(ParamList* params) { |
6561 // Create the parameter list for the body closure of an async generator. | 6556 // Create the parameter list for the body closure of an async generator. |
6562 // The closure has the same parameters as an asynchronous non-generator. | 6557 // The closure has the same parameters as an asynchronous non-generator. |
6563 AddAsyncClosureParameters(params); | 6558 AddAsyncClosureParameters(params); |
6564 } | 6559 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6672 current_block_->statements->Add(return_node); | 6667 current_block_->statements->Add(return_node); |
6673 return CloseBlock(); | 6668 return CloseBlock(); |
6674 } | 6669 } |
6675 | 6670 |
6676 | 6671 |
6677 void Parser::AddAsyncClosureParameters(ParamList* params) { | 6672 void Parser::AddAsyncClosureParameters(ParamList* params) { |
6678 // Async closures have three optional parameters: | 6673 // Async closures have three optional parameters: |
6679 // * A continuation result. | 6674 // * A continuation result. |
6680 // * A continuation error. | 6675 // * A continuation error. |
6681 // * A continuation stack trace. | 6676 // * A continuation stack trace. |
6682 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
6683 ASSERT(params->parameters->length() <= 1); | 6677 ASSERT(params->parameters->length() <= 1); |
6684 // Add implicit closure parameter if not yet present. | 6678 // Add implicit closure parameter if not yet present. |
6685 if (params->parameters->length() == 0) { | 6679 if (params->parameters->length() == 0) { |
6686 params->AddFinalParameter(0, &Symbols::ClosureParameter(), &dynamic_type); | 6680 params->AddFinalParameter( |
| 6681 0, &Symbols::ClosureParameter(), &Object::dynamic_type()); |
6687 } | 6682 } |
6688 ParamDesc result_param; | 6683 ParamDesc result_param; |
6689 result_param.name = &Symbols::AsyncOperationParam(); | 6684 result_param.name = &Symbols::AsyncOperationParam(); |
6690 result_param.default_value = &Object::null_instance(); | 6685 result_param.default_value = &Object::null_instance(); |
6691 result_param.type = &dynamic_type; | 6686 result_param.type = &Object::dynamic_type(); |
6692 params->parameters->Add(result_param); | 6687 params->parameters->Add(result_param); |
6693 ParamDesc error_param; | 6688 ParamDesc error_param; |
6694 error_param.name = &Symbols::AsyncOperationErrorParam(); | 6689 error_param.name = &Symbols::AsyncOperationErrorParam(); |
6695 error_param.default_value = &Object::null_instance(); | 6690 error_param.default_value = &Object::null_instance(); |
6696 error_param.type = &dynamic_type; | 6691 error_param.type = &Object::dynamic_type(); |
6697 params->parameters->Add(error_param); | 6692 params->parameters->Add(error_param); |
6698 ParamDesc stack_trace_param; | 6693 ParamDesc stack_trace_param; |
6699 stack_trace_param.name = &Symbols::AsyncOperationStackTraceParam(); | 6694 stack_trace_param.name = &Symbols::AsyncOperationStackTraceParam(); |
6700 stack_trace_param.default_value = &Object::null_instance(); | 6695 stack_trace_param.default_value = &Object::null_instance(); |
6701 stack_trace_param.type = &dynamic_type; | 6696 stack_trace_param.type = &Object::dynamic_type(); |
6702 params->parameters->Add(stack_trace_param); | 6697 params->parameters->Add(stack_trace_param); |
6703 params->has_optional_positional_parameters = true; | 6698 params->has_optional_positional_parameters = true; |
6704 params->num_optional_parameters += 3; | 6699 params->num_optional_parameters += 3; |
6705 } | 6700 } |
6706 | 6701 |
6707 | 6702 |
6708 RawFunction* Parser::OpenAsyncFunction(intptr_t async_func_pos) { | 6703 RawFunction* Parser::OpenAsyncFunction(intptr_t async_func_pos) { |
6709 TRACE_PARSER("OpenAsyncFunction"); | 6704 TRACE_PARSER("OpenAsyncFunction"); |
6710 AddContinuationVariables(); | 6705 AddContinuationVariables(); |
6711 AddAsyncClosureVariables(); | 6706 AddAsyncClosureVariables(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6765 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6760 AddFormalParamsToScope(&closure_params, current_block_->scope); |
6766 async_temp_scope_ = current_block_->scope; | 6761 async_temp_scope_ = current_block_->scope; |
6767 return closure.raw(); | 6762 return closure.raw(); |
6768 } | 6763 } |
6769 | 6764 |
6770 | 6765 |
6771 void Parser::AddContinuationVariables() { | 6766 void Parser::AddContinuationVariables() { |
6772 // Add to current block's scope: | 6767 // Add to current block's scope: |
6773 // var :await_jump_var; | 6768 // var :await_jump_var; |
6774 // var :await_ctx_var; | 6769 // var :await_ctx_var; |
6775 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
6776 LocalVariable* await_jump_var = new (Z) LocalVariable( | 6770 LocalVariable* await_jump_var = new (Z) LocalVariable( |
6777 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), dynamic_type); | 6771 Scanner::kNoSourcePos, Symbols::AwaitJumpVar(), Object::dynamic_type()); |
6778 current_block_->scope->AddVariable(await_jump_var); | 6772 current_block_->scope->AddVariable(await_jump_var); |
6779 LocalVariable* await_ctx_var = new (Z) LocalVariable( | 6773 LocalVariable* await_ctx_var = new (Z) LocalVariable( |
6780 Scanner::kNoSourcePos, Symbols::AwaitContextVar(), dynamic_type); | 6774 Scanner::kNoSourcePos, |
| 6775 Symbols::AwaitContextVar(), |
| 6776 Object::dynamic_type()); |
6781 current_block_->scope->AddVariable(await_ctx_var); | 6777 current_block_->scope->AddVariable(await_ctx_var); |
6782 } | 6778 } |
6783 | 6779 |
6784 | 6780 |
6785 void Parser::AddAsyncClosureVariables() { | 6781 void Parser::AddAsyncClosureVariables() { |
6786 // Add to current block's scope: | 6782 // Add to current block's scope: |
6787 // var :async_op; | 6783 // var :async_op; |
6788 // var :async_then_callback; | 6784 // var :async_then_callback; |
6789 // var :async_catch_error_callback; | 6785 // var :async_catch_error_callback; |
6790 // var :async_completer; | 6786 // var :async_completer; |
6791 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
6792 LocalVariable* async_op_var = new(Z) LocalVariable( | 6787 LocalVariable* async_op_var = new(Z) LocalVariable( |
6793 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); | 6788 Scanner::kNoSourcePos, Symbols::AsyncOperation(), Object::dynamic_type()); |
6794 current_block_->scope->AddVariable(async_op_var); | 6789 current_block_->scope->AddVariable(async_op_var); |
6795 LocalVariable* async_then_callback_var = new(Z) LocalVariable( | 6790 LocalVariable* async_then_callback_var = new(Z) LocalVariable( |
6796 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); | 6791 Scanner::kNoSourcePos, |
| 6792 Symbols::AsyncThenCallback(), |
| 6793 Object::dynamic_type()); |
6797 current_block_->scope->AddVariable(async_then_callback_var); | 6794 current_block_->scope->AddVariable(async_then_callback_var); |
6798 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( | 6795 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( |
6799 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); | 6796 Scanner::kNoSourcePos, |
| 6797 Symbols::AsyncCatchErrorCallback(), |
| 6798 Object::dynamic_type()); |
6800 current_block_->scope->AddVariable(async_catch_error_callback_var); | 6799 current_block_->scope->AddVariable(async_catch_error_callback_var); |
6801 LocalVariable* async_completer = new(Z) LocalVariable( | 6800 LocalVariable* async_completer = new(Z) LocalVariable( |
6802 Scanner::kNoSourcePos, Symbols::AsyncCompleter(), dynamic_type); | 6801 Scanner::kNoSourcePos, |
| 6802 Symbols::AsyncCompleter(), |
| 6803 Object::dynamic_type()); |
6803 current_block_->scope->AddVariable(async_completer); | 6804 current_block_->scope->AddVariable(async_completer); |
6804 } | 6805 } |
6805 | 6806 |
6806 | 6807 |
6807 void Parser::AddAsyncGeneratorVariables() { | 6808 void Parser::AddAsyncGeneratorVariables() { |
6808 // Add to current block's scope: | 6809 // Add to current block's scope: |
6809 // var :controller; | 6810 // var :controller; |
6810 // The :controller variable is used by the async generator closure to | 6811 // The :controller variable is used by the async generator closure to |
6811 // store the StreamController object to which the yielded expressions | 6812 // store the StreamController object to which the yielded expressions |
6812 // are added. | 6813 // are added. |
6813 // var :async_op; | 6814 // var :async_op; |
6814 // var :async_then_callback; | 6815 // var :async_then_callback; |
6815 // var :async_catch_error_callback; | 6816 // var :async_catch_error_callback; |
6816 // These variables are used to store the async generator closure containing | 6817 // These variables are used to store the async generator closure containing |
6817 // the body of the async* function. They are used by the await operator. | 6818 // the body of the async* function. They are used by the await operator. |
6818 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
6819 LocalVariable* controller_var = new(Z) LocalVariable( | 6819 LocalVariable* controller_var = new(Z) LocalVariable( |
6820 Scanner::kNoSourcePos, Symbols::Controller(), dynamic_type); | 6820 Scanner::kNoSourcePos, Symbols::Controller(), Object::dynamic_type()); |
6821 current_block_->scope->AddVariable(controller_var); | 6821 current_block_->scope->AddVariable(controller_var); |
6822 LocalVariable* async_op_var = new(Z) LocalVariable( | 6822 LocalVariable* async_op_var = new(Z) LocalVariable( |
6823 Scanner::kNoSourcePos, Symbols::AsyncOperation(), dynamic_type); | 6823 Scanner::kNoSourcePos, Symbols::AsyncOperation(), Object::dynamic_type()); |
6824 current_block_->scope->AddVariable(async_op_var); | 6824 current_block_->scope->AddVariable(async_op_var); |
6825 LocalVariable* async_then_callback_var = new(Z) LocalVariable( | 6825 LocalVariable* async_then_callback_var = new(Z) LocalVariable( |
6826 Scanner::kNoSourcePos, Symbols::AsyncThenCallback(), dynamic_type); | 6826 Scanner::kNoSourcePos, |
| 6827 Symbols::AsyncThenCallback(), |
| 6828 Object::dynamic_type()); |
6827 current_block_->scope->AddVariable(async_then_callback_var); | 6829 current_block_->scope->AddVariable(async_then_callback_var); |
6828 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( | 6830 LocalVariable* async_catch_error_callback_var = new(Z) LocalVariable( |
6829 Scanner::kNoSourcePos, Symbols::AsyncCatchErrorCallback(), dynamic_type); | 6831 Scanner::kNoSourcePos, |
| 6832 Symbols::AsyncCatchErrorCallback(), |
| 6833 Object::dynamic_type()); |
6830 current_block_->scope->AddVariable(async_catch_error_callback_var); | 6834 current_block_->scope->AddVariable(async_catch_error_callback_var); |
6831 } | 6835 } |
6832 | 6836 |
6833 | 6837 |
6834 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) { | 6838 RawFunction* Parser::OpenAsyncGeneratorFunction(intptr_t async_func_pos) { |
6835 TRACE_PARSER("OpenAsyncGeneratorFunction"); | 6839 TRACE_PARSER("OpenAsyncGeneratorFunction"); |
6836 AddContinuationVariables(); | 6840 AddContinuationVariables(); |
6837 AddAsyncGeneratorVariables(); | 6841 AddAsyncGeneratorVariables(); |
6838 | 6842 |
6839 Function& closure = Function::Handle(Z); | 6843 Function& closure = Function::Handle(Z); |
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8854 } | 8858 } |
8855 } while (finally_clause == NULL); | 8859 } while (finally_clause == NULL); |
8856 | 8860 |
8857 if (try_stack_ != NULL) { | 8861 if (try_stack_ != NULL) { |
8858 try_stack_->exit_finally(); | 8862 try_stack_->exit_finally(); |
8859 } | 8863 } |
8860 | 8864 |
8861 // Create the try-statement and add to the current sequence, which is | 8865 // Create the try-statement and add to the current sequence, which is |
8862 // the block around the loop statement. | 8866 // the block around the loop statement. |
8863 | 8867 |
8864 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
8865 const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld)); | 8868 const Array& handler_types = Array::ZoneHandle(Z, Array::New(1, Heap::kOld)); |
8866 handler_types.SetAt(0, dynamic_type); // Catch block handles all exceptions. | 8869 // Catch block handles all exceptions. |
| 8870 handler_types.SetAt(0, Object::dynamic_type()); |
8867 | 8871 |
8868 CatchClauseNode* catch_clause = new(Z) CatchClauseNode(await_for_pos, | 8872 CatchClauseNode* catch_clause = new(Z) CatchClauseNode(await_for_pos, |
8869 catch_block, | 8873 catch_block, |
8870 handler_types, | 8874 handler_types, |
8871 context_var, | 8875 context_var, |
8872 exception_var, | 8876 exception_var, |
8873 stack_trace_var, | 8877 stack_trace_var, |
8874 exception_var, | 8878 exception_var, |
8875 stack_trace_var, | 8879 stack_trace_var, |
8876 AllocateTryIndex(), | 8880 AllocateTryIndex(), |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9577 // In case of async code, we create two additional variables: | 9581 // In case of async code, we create two additional variables: |
9578 // ':saved_exception_var' - Used to capture the exception object above. | 9582 // ':saved_exception_var' - Used to capture the exception object above. |
9579 // ':saved_stack_trace_var' - Used to capture the stack trace object above. | 9583 // ':saved_stack_trace_var' - Used to capture the stack trace object above. |
9580 void Parser::SetupExceptionVariables(LocalScope* try_scope, | 9584 void Parser::SetupExceptionVariables(LocalScope* try_scope, |
9581 bool is_async, | 9585 bool is_async, |
9582 LocalVariable** context_var, | 9586 LocalVariable** context_var, |
9583 LocalVariable** exception_var, | 9587 LocalVariable** exception_var, |
9584 LocalVariable** stack_trace_var, | 9588 LocalVariable** stack_trace_var, |
9585 LocalVariable** saved_exception_var, | 9589 LocalVariable** saved_exception_var, |
9586 LocalVariable** saved_stack_trace_var) { | 9590 LocalVariable** saved_stack_trace_var) { |
9587 const Type& dynamic_type = Type::ZoneHandle(Z, Type::DynamicType()); | |
9588 // Consecutive try statements share the same set of variables. | 9591 // Consecutive try statements share the same set of variables. |
9589 *context_var = try_scope->LocalLookupVariable(Symbols::SavedTryContextVar()); | 9592 *context_var = try_scope->LocalLookupVariable(Symbols::SavedTryContextVar()); |
9590 if (*context_var == NULL) { | 9593 if (*context_var == NULL) { |
9591 *context_var = new(Z) LocalVariable( | 9594 *context_var = new(Z) LocalVariable( |
9592 TokenPos(), | 9595 TokenPos(), |
9593 Symbols::SavedTryContextVar(), | 9596 Symbols::SavedTryContextVar(), |
9594 dynamic_type); | 9597 Object::dynamic_type()); |
9595 try_scope->AddVariable(*context_var); | 9598 try_scope->AddVariable(*context_var); |
9596 } | 9599 } |
9597 *exception_var = try_scope->LocalLookupVariable(Symbols::ExceptionVar()); | 9600 *exception_var = try_scope->LocalLookupVariable(Symbols::ExceptionVar()); |
9598 if (*exception_var == NULL) { | 9601 if (*exception_var == NULL) { |
9599 *exception_var = new(Z) LocalVariable( | 9602 *exception_var = new(Z) LocalVariable( |
9600 TokenPos(), | 9603 TokenPos(), |
9601 Symbols::ExceptionVar(), | 9604 Symbols::ExceptionVar(), |
9602 dynamic_type); | 9605 Object::dynamic_type()); |
9603 try_scope->AddVariable(*exception_var); | 9606 try_scope->AddVariable(*exception_var); |
9604 } | 9607 } |
9605 *stack_trace_var = try_scope->LocalLookupVariable(Symbols::StackTraceVar()); | 9608 *stack_trace_var = try_scope->LocalLookupVariable(Symbols::StackTraceVar()); |
9606 if (*stack_trace_var == NULL) { | 9609 if (*stack_trace_var == NULL) { |
9607 *stack_trace_var = new(Z) LocalVariable( | 9610 *stack_trace_var = new(Z) LocalVariable( |
9608 TokenPos(), | 9611 TokenPos(), |
9609 Symbols::StackTraceVar(), | 9612 Symbols::StackTraceVar(), |
9610 dynamic_type); | 9613 Object::dynamic_type()); |
9611 try_scope->AddVariable(*stack_trace_var); | 9614 try_scope->AddVariable(*stack_trace_var); |
9612 } | 9615 } |
9613 if (is_async) { | 9616 if (is_async) { |
9614 *saved_exception_var = try_scope->LocalLookupVariable( | 9617 *saved_exception_var = try_scope->LocalLookupVariable( |
9615 Symbols::SavedExceptionVar()); | 9618 Symbols::SavedExceptionVar()); |
9616 if (*saved_exception_var == NULL) { | 9619 if (*saved_exception_var == NULL) { |
9617 *saved_exception_var = new(Z) LocalVariable( | 9620 *saved_exception_var = new(Z) LocalVariable( |
9618 TokenPos(), | 9621 TokenPos(), |
9619 Symbols::SavedExceptionVar(), | 9622 Symbols::SavedExceptionVar(), |
9620 dynamic_type); | 9623 Object::dynamic_type()); |
9621 try_scope->AddVariable(*saved_exception_var); | 9624 try_scope->AddVariable(*saved_exception_var); |
9622 } | 9625 } |
9623 *saved_stack_trace_var = try_scope->LocalLookupVariable( | 9626 *saved_stack_trace_var = try_scope->LocalLookupVariable( |
9624 Symbols::SavedStackTraceVar()); | 9627 Symbols::SavedStackTraceVar()); |
9625 if (*saved_stack_trace_var == NULL) { | 9628 if (*saved_stack_trace_var == NULL) { |
9626 *saved_stack_trace_var = new(Z) LocalVariable( | 9629 *saved_stack_trace_var = new(Z) LocalVariable( |
9627 TokenPos(), | 9630 TokenPos(), |
9628 Symbols::SavedStackTraceVar(), | 9631 Symbols::SavedStackTraceVar(), |
9629 dynamic_type); | 9632 Object::dynamic_type()); |
9630 try_scope->AddVariable(*saved_stack_trace_var); | 9633 try_scope->AddVariable(*saved_stack_trace_var); |
9631 } | 9634 } |
9632 } | 9635 } |
9633 } | 9636 } |
9634 | 9637 |
9635 | 9638 |
9636 AstNode* Parser::ParseTryStatement(String* label_name) { | 9639 AstNode* Parser::ParseTryStatement(String* label_name) { |
9637 TRACE_PARSER("ParseTryStatement"); | 9640 TRACE_PARSER("ParseTryStatement"); |
9638 | 9641 |
9639 const intptr_t try_pos = TokenPos(); | 9642 const intptr_t try_pos = TokenPos(); |
(...skipping 4663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14303 void Parser::SkipQualIdent() { | 14306 void Parser::SkipQualIdent() { |
14304 ASSERT(IsIdentifier()); | 14307 ASSERT(IsIdentifier()); |
14305 ConsumeToken(); | 14308 ConsumeToken(); |
14306 if (CurrentToken() == Token::kPERIOD) { | 14309 if (CurrentToken() == Token::kPERIOD) { |
14307 ConsumeToken(); // Consume the kPERIOD token. | 14310 ConsumeToken(); // Consume the kPERIOD token. |
14308 ExpectIdentifier("identifier expected after '.'"); | 14311 ExpectIdentifier("identifier expected after '.'"); |
14309 } | 14312 } |
14310 } | 14313 } |
14311 | 14314 |
14312 } // namespace dart | 14315 } // namespace dart |
OLD | NEW |