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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 DEFINE_FLAG(bool, | 53 DEFINE_FLAG(bool, |
54 conditional_directives, | 54 conditional_directives, |
55 true, | 55 true, |
56 "Enable conditional directives"); | 56 "Enable conditional directives"); |
57 DEFINE_FLAG(bool, | 57 DEFINE_FLAG(bool, |
58 generic_method_syntax, | 58 generic_method_syntax, |
59 true, | 59 true, |
60 "Enable generic function syntax."); | 60 "Enable generic function syntax."); |
61 DEFINE_FLAG(bool, | 61 DEFINE_FLAG(bool, |
62 generic_method_semantics, | 62 generic_method_semantics, |
63 true, | 63 false, |
64 "Enable generic function semantics (not yet supported)."); | 64 "Enable generic function semantics (not yet supported)."); |
65 DEFINE_FLAG(bool, | 65 DEFINE_FLAG(bool, |
66 initializing_formal_access, | 66 initializing_formal_access, |
67 true, | 67 true, |
68 "Make initializing formal parameters visible in initializer list."); | 68 "Make initializing formal parameters visible in initializer list."); |
69 DEFINE_FLAG(bool, | 69 DEFINE_FLAG(bool, |
70 warn_super, | 70 warn_super, |
71 false, | 71 false, |
72 "Warning if super initializer not last in initializer list."); | 72 "Warning if super initializer not last in initializer list."); |
73 DEFINE_FLAG( | 73 DEFINE_FLAG( |
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 if (parsed_function->has_expression_temp_var()) { | 1156 if (parsed_function->has_expression_temp_var()) { |
1157 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); | 1157 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
1158 } | 1158 } |
1159 node_sequence->scope()->AddVariable(parsed_function->current_context_var()); | 1159 node_sequence->scope()->AddVariable(parsed_function->current_context_var()); |
1160 if (parsed_function->has_finally_return_temp_var()) { | 1160 if (parsed_function->has_finally_return_temp_var()) { |
1161 node_sequence->scope()->AddVariable( | 1161 node_sequence->scope()->AddVariable( |
1162 parsed_function->finally_return_temp_var()); | 1162 parsed_function->finally_return_temp_var()); |
1163 } | 1163 } |
1164 parsed_function->SetNodeSequence(node_sequence); | 1164 parsed_function->SetNodeSequence(node_sequence); |
1165 | 1165 |
1166 // The instantiator may be required at run time for generic type checks or | 1166 // The instantiators may be required at run time for generic type checks or |
1167 // allocation of generic types. | 1167 // allocation of generic types. |
1168 if (parser.IsInstantiatorRequired()) { | 1168 if (parser.IsInstantiatorRequired()) { |
1169 // In the case of a local function, only set the instantiator if the | 1169 // In the case of a local function, only set the instantiator if the |
1170 // receiver (or type arguments parameter of a factory) was captured. | 1170 // receiver (or type arguments parameter of a factory) was captured. |
1171 LocalVariable* instantiator = NULL; | 1171 LocalVariable* instantiator = NULL; |
1172 const bool kTestOnly = true; | 1172 const bool kTestOnly = true; |
1173 if (parser.current_function().IsInFactoryScope()) { | 1173 if (parser.current_function().IsInFactoryScope()) { |
1174 instantiator = parser.LookupTypeArgumentsParameter(node_sequence->scope(), | 1174 instantiator = parser.LookupTypeArgumentsParameter(node_sequence->scope(), |
1175 kTestOnly); | 1175 kTestOnly); |
1176 } else { | 1176 } else { |
1177 instantiator = parser.LookupReceiver(node_sequence->scope(), kTestOnly); | 1177 instantiator = parser.LookupReceiver(node_sequence->scope(), kTestOnly); |
1178 } | 1178 } |
1179 if (!parser.current_function().IsLocalFunction() || | 1179 if (!parser.current_function().IsLocalFunction() || |
1180 ((instantiator != NULL) && instantiator->is_captured())) { | 1180 ((instantiator != NULL) && instantiator->is_captured())) { |
1181 parsed_function->set_instantiator(instantiator); | 1181 parsed_function->set_instantiator(instantiator); |
1182 } | 1182 } |
1183 } | 1183 } |
1184 if (FLAG_generic_method_semantics && parser.current_function().IsGeneric()) { | |
1185 const String* variable_name = &Symbols::FunctionInstantiatorVar(); | |
1186 const bool kTestOnly = true; | |
1187 LocalVariable* instantiator = | |
1188 node_sequence->scope()->LookupVariable(*variable_name, kTestOnly); | |
1189 ASSERT(instantiator != NULL); | |
1190 parsed_function->set_function_instantiator(instantiator); | |
1191 // Function instantiator variables of parent generic functions, if any, are | |
1192 // captured and accessible via the context. | |
1193 } | |
1184 } | 1194 } |
1185 | 1195 |
1186 | 1196 |
1187 RawObject* Parser::ParseMetadata(const Field& meta_data) { | 1197 RawObject* Parser::ParseMetadata(const Field& meta_data) { |
1188 LongJumpScope jump; | 1198 LongJumpScope jump; |
1189 if (setjmp(*jump.Set()) == 0) { | 1199 if (setjmp(*jump.Set()) == 0) { |
1190 Thread* thread = Thread::Current(); | 1200 Thread* thread = Thread::Current(); |
1191 StackZone stack_zone(thread); | 1201 StackZone stack_zone(thread); |
1192 Zone* zone = stack_zone.GetZone(); | 1202 Zone* zone = stack_zone.GetZone(); |
1193 const Class& owner_class = Class::Handle(zone, meta_data.Owner()); | 1203 const Class& owner_class = Class::Handle(zone, meta_data.Owner()); |
(...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3453 | 3463 |
3454 if (func.IsGenerativeConstructor()) { | 3464 if (func.IsGenerativeConstructor()) { |
3455 SequenceNode* statements = ParseConstructor(func); | 3465 SequenceNode* statements = ParseConstructor(func); |
3456 last_used_try_index_ = saved_try_index; | 3466 last_used_try_index_ = saved_try_index; |
3457 return statements; | 3467 return statements; |
3458 } | 3468 } |
3459 | 3469 |
3460 ASSERT(!func.IsGenerativeConstructor()); | 3470 ASSERT(!func.IsGenerativeConstructor()); |
3461 OpenFunctionBlock(func); // Build local scope for function. | 3471 OpenFunctionBlock(func); // Build local scope for function. |
3462 | 3472 |
3473 if (FLAG_generic_method_semantics && func.IsGeneric()) { | |
3474 // Insert function instantiator variable to scope. | |
3475 LocalVariable* function_instantiator = new (Z) LocalVariable( | |
3476 TokenPosition::kNoSource, TokenPosition::kNoSource, | |
3477 Symbols::FunctionInstantiatorVar(), Object::dynamic_type()); | |
3478 current_block_->scope->AddVariable(function_instantiator); | |
3479 } | |
3480 | |
3463 ParamList params; | 3481 ParamList params; |
3464 // An instance closure function may capture and access the receiver, but via | 3482 // An instance closure function may capture and access the receiver, but via |
3465 // the context and not via the first formal parameter. | 3483 // the context and not via the first formal parameter. |
3466 if (func.IsClosureFunction()) { | 3484 if (func.IsClosureFunction()) { |
3467 // The first parameter of a closure function is the closure object. | 3485 // The first parameter of a closure function is the closure object. |
3468 ASSERT(!func.is_const()); // Closure functions cannot be const. | 3486 ASSERT(!func.is_const()); // Closure functions cannot be const. |
3469 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), | 3487 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), |
3470 &Object::dynamic_type()); | 3488 &Object::dynamic_type()); |
3471 } else if (!func.is_static()) { | 3489 } else if (!func.is_static()) { |
3472 // Static functions do not have a receiver. | 3490 // Static functions do not have a receiver. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3542 } | 3560 } |
3543 ResolveSignature(func); | 3561 ResolveSignature(func); |
3544 if (!is_top_level_) { | 3562 if (!is_top_level_) { |
3545 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); | 3563 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); |
3546 } | 3564 } |
3547 SetupDefaultsForOptionalParams(params); | 3565 SetupDefaultsForOptionalParams(params); |
3548 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3566 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
3549 | 3567 |
3550 // Populate function scope with the formal parameters. | 3568 // Populate function scope with the formal parameters. |
3551 AddFormalParamsToScope(¶ms, current_block_->scope); | 3569 AddFormalParamsToScope(¶ms, current_block_->scope); |
3552 | |
3553 if (I->type_checks() && (FunctionLevel() > 0)) { | |
3554 // We are parsing, but not compiling, a local function. | |
3555 // The instantiator may be required at run time for generic type checks. | |
3556 if (IsInstantiatorRequired()) { | |
3557 // Make sure that the receiver of the enclosing instance function | |
3558 // (or implicit first parameter of an enclosing factory) is marked as | |
3559 // captured if type checks are enabled, because they may access it to | |
3560 // instantiate types. | |
3561 CaptureInstantiator(); | |
3562 } | |
3563 } | |
3564 } | 3570 } |
3565 | 3571 |
3566 const TokenPosition modifier_pos = TokenPos(); | 3572 const TokenPosition modifier_pos = TokenPos(); |
3567 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); | 3573 RawFunction::AsyncModifier func_modifier = ParseFunctionModifier(); |
3568 if (!func.is_generated_body()) { | 3574 if (!func.is_generated_body()) { |
3569 // Don't add a modifier to the closure representing the body of | 3575 // Don't add a modifier to the closure representing the body of |
3570 // the asynchronous function or generator. | 3576 // the asynchronous function or generator. |
3571 func.set_modifier(func_modifier); | 3577 func.set_modifier(func_modifier); |
3572 } | 3578 } |
3573 | 3579 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3613 // The closure containing the body of an async* function is debuggable. | 3619 // The closure containing the body of an async* function is debuggable. |
3614 ASSERT(func.is_debuggable()); | 3620 ASSERT(func.is_debuggable()); |
3615 if (FLAG_causal_async_stacks) { | 3621 if (FLAG_causal_async_stacks) { |
3616 // In order to collect causal asynchronous stacks efficiently we rely on | 3622 // In order to collect causal asynchronous stacks efficiently we rely on |
3617 // this function not being inlined. | 3623 // this function not being inlined. |
3618 func.set_is_inlinable(false); | 3624 func.set_is_inlinable(false); |
3619 } | 3625 } |
3620 OpenAsyncGeneratorClosure(); | 3626 OpenAsyncGeneratorClosure(); |
3621 } | 3627 } |
3622 | 3628 |
3629 // Function level is now correctly set to parse the (possibly async) body. | |
3630 if (I->type_checks() && (FunctionLevel() > 0)) { | |
3631 // We are parsing, but not compiling, a local function. | |
3632 // The instantiator may be required at run time for generic type checks. | |
3633 // Note that the source of this local function may not reference the | |
3634 // generic type explicitly. However, it may assign a value to a captured | |
3635 // variable declared with its generic type in the enclosing function. | |
3636 // Make sure that the receiver of the enclosing instance function | |
3637 // (or implicit first parameter of an enclosing factory) is marked as | |
3638 // captured if type checks are enabled, because they may access it to | |
3639 // instantiate types. | |
3640 // If any enclosing parent of the function being parsed is generic, capture | |
3641 // their function instantiators. | |
3642 CaptureAllInstantiators(); | |
3643 } | |
3644 | |
3623 BoolScope allow_await(&this->await_is_keyword_, | 3645 BoolScope allow_await(&this->await_is_keyword_, |
3624 func.IsAsyncOrGenerator() || func.is_generated_body()); | 3646 func.IsAsyncOrGenerator() || func.is_generated_body()); |
3625 TokenPosition end_token_pos = TokenPosition::kNoSource; | 3647 TokenPosition end_token_pos = TokenPosition::kNoSource; |
3626 if (CurrentToken() == Token::kLBRACE) { | 3648 if (CurrentToken() == Token::kLBRACE) { |
3627 ConsumeToken(); | 3649 ConsumeToken(); |
3628 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { | 3650 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { |
3629 const Class& owner = Class::Handle(Z, func.Owner()); | 3651 const Class& owner = Class::Handle(Z, func.Owner()); |
3630 if (!owner.IsObjectClass()) { | 3652 if (!owner.IsObjectClass()) { |
3631 AddEqualityNullCheck(); | 3653 AddEqualityNullCheck(); |
3632 } | 3654 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3785 return LibraryPrefix::null(); | 3807 return LibraryPrefix::null(); |
3786 } | 3808 } |
3787 | 3809 |
3788 // A library prefix with the name exists. Now check whether it is | 3810 // A library prefix with the name exists. Now check whether it is |
3789 // shadowed by a local definition. | 3811 // shadowed by a local definition. |
3790 if (!is_top_level_ && | 3812 if (!is_top_level_ && |
3791 ResolveIdentInLocalScope(TokenPos(), ident, NULL, NULL)) { | 3813 ResolveIdentInLocalScope(TokenPos(), ident, NULL, NULL)) { |
3792 return LibraryPrefix::null(); | 3814 return LibraryPrefix::null(); |
3793 } | 3815 } |
3794 // Check whether the identifier is shadowed by a function type parameter. | 3816 // Check whether the identifier is shadowed by a function type parameter. |
3795 // TODO(regis): Shortcut this lookup if no generic functions in scope. | 3817 if (InGenericFunctionScope() && (innermost_function().LookupTypeParameter( |
3796 if (!innermost_function().IsNull() && | 3818 ident, NULL) != TypeParameter::null())) { |
hausner
2017/03/08 06:19:36
Nit: weird formatting, but git cl format probably
regis
2017/03/08 16:18:49
Yes, I had to run git cl format. I'll try to fix i
| |
3797 (innermost_function().LookupTypeParameter(ident, NULL) != | |
3798 TypeParameter::null())) { | |
3799 return LibraryPrefix::null(); | 3819 return LibraryPrefix::null(); |
3800 } | 3820 } |
3801 // Check whether the identifier is shadowed by a class type parameter. | 3821 // Check whether the identifier is shadowed by a class type parameter. |
3802 ASSERT(!current_class().IsNull()); | 3822 ASSERT(!current_class().IsNull()); |
3803 if (current_class().LookupTypeParameter(ident) != TypeParameter::null()) { | 3823 if (current_class().LookupTypeParameter(ident) != TypeParameter::null()) { |
3804 return LibraryPrefix::null(); | 3824 return LibraryPrefix::null(); |
3805 } | 3825 } |
3806 | 3826 |
3807 // We have a name that is not shadowed, followed by a period or #. | 3827 // We have a name that is not shadowed, followed by a period or #. |
3808 // Consume the identifier, let the caller consume the . or #. | 3828 // Consume the identifier, let the caller consume the . or #. |
(...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5520 // Postpone resolution in order to avoid resolving the owner and its | 5540 // Postpone resolution in order to avoid resolving the owner and its |
5521 // type parameters, as they are not fully parsed yet. | 5541 // type parameters, as they are not fully parsed yet. |
5522 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); | 5542 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); |
5523 } else { | 5543 } else { |
5524 type_parameter_bound = I->object_store()->object_type(); | 5544 type_parameter_bound = I->object_store()->object_type(); |
5525 } | 5545 } |
5526 type_parameter = TypeParameter::New( | 5546 type_parameter = TypeParameter::New( |
5527 parameterizing_class ? current_class() : Class::Handle(Z), | 5547 parameterizing_class ? current_class() : Class::Handle(Z), |
5528 parameterizing_class ? Function::Handle(Z) : innermost_function(), | 5548 parameterizing_class ? Function::Handle(Z) : innermost_function(), |
5529 index, 0, type_parameter_name, type_parameter_bound, declaration_pos); | 5549 index, 0, type_parameter_name, type_parameter_bound, declaration_pos); |
5550 if (!parameterizing_class) { | |
5551 type_parameter.SetIsFinalized(); | |
5552 } | |
5530 type_parameters_array.Add( | 5553 type_parameters_array.Add( |
5531 &AbstractType::ZoneHandle(Z, type_parameter.raw())); | 5554 &AbstractType::ZoneHandle(Z, type_parameter.raw())); |
5532 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { | 5555 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { |
5533 library_.AddTypeParameterMetadata(type_parameter, metadata_pos); | 5556 library_.AddTypeParameterMetadata(type_parameter, metadata_pos); |
5534 } | 5557 } |
5535 index++; | 5558 index++; |
5536 } while (CurrentToken() == Token::kCOMMA); | 5559 } while (CurrentToken() == Token::kCOMMA); |
5537 Token::Kind token = CurrentToken(); | 5560 Token::Kind token = CurrentToken(); |
5538 if ((token == Token::kGT) || (token == Token::kSHR)) { | 5561 if ((token == Token::kGT) || (token == Token::kSHR)) { |
5539 ConsumeRightAngleBracket(); | 5562 ConsumeRightAngleBracket(); |
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7015 // Finalize function type. | 7038 // Finalize function type. |
7016 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 7039 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
7017 signature_type ^= CanonicalizeType(signature_type); | 7040 signature_type ^= CanonicalizeType(signature_type); |
7018 closure.SetSignatureType(signature_type); | 7041 closure.SetSignatureType(signature_type); |
7019 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 7042 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
7020 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 7043 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
7021 } | 7044 } |
7022 OpenFunctionBlock(closure); | 7045 OpenFunctionBlock(closure); |
7023 AddFormalParamsToScope(&closure_params, current_block_->scope); | 7046 AddFormalParamsToScope(&closure_params, current_block_->scope); |
7024 async_temp_scope_ = current_block_->scope; | 7047 async_temp_scope_ = current_block_->scope; |
7025 | |
7026 // Capture instantiator in case it may be needed to generate the type | |
7027 // check of the return value. (C.f. handling of Token::kRETURN.) | |
7028 ASSERT(FunctionLevel() > 0); | |
7029 if (I->type_checks() && IsInstantiatorRequired()) { | |
7030 CaptureInstantiator(); | |
7031 } | |
7032 return closure.raw(); | 7048 return closure.raw(); |
7033 } | 7049 } |
7034 | 7050 |
7035 | 7051 |
7036 void Parser::AddContinuationVariables() { | 7052 void Parser::AddContinuationVariables() { |
7037 // Add to current block's scope: | 7053 // Add to current block's scope: |
7038 // var :await_jump_var; | 7054 // var :await_jump_var; |
7039 // var :await_ctx_var; | 7055 // var :await_ctx_var; |
7040 LocalVariable* await_jump_var = | 7056 LocalVariable* await_jump_var = |
7041 new (Z) LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, | 7057 new (Z) LocalVariable(TokenPosition::kNoSource, TokenPosition::kNoSource, |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7710 void Parser::CaptureInstantiator() { | 7726 void Parser::CaptureInstantiator() { |
7711 ASSERT(FunctionLevel() > 0); | 7727 ASSERT(FunctionLevel() > 0); |
7712 const String* variable_name = current_function().IsInFactoryScope() | 7728 const String* variable_name = current_function().IsInFactoryScope() |
7713 ? &Symbols::TypeArgumentsParameter() | 7729 ? &Symbols::TypeArgumentsParameter() |
7714 : &Symbols::This(); | 7730 : &Symbols::This(); |
7715 current_block_->scope->CaptureVariable( | 7731 current_block_->scope->CaptureVariable( |
7716 current_block_->scope->LookupVariable(*variable_name, true)); | 7732 current_block_->scope->LookupVariable(*variable_name, true)); |
7717 } | 7733 } |
7718 | 7734 |
7719 | 7735 |
7720 void Parser::CaptureFunctionInstantiator() { | 7736 void Parser::CaptureFunctionInstantiators() { |
7737 ASSERT(InGenericFunctionScope()); | |
7721 ASSERT(FunctionLevel() > 0); | 7738 ASSERT(FunctionLevel() > 0); |
7739 if (!FLAG_generic_method_semantics) { | |
7740 return; | |
7741 } | |
7742 // Capture function instantiators starting at parent of innermost function. | |
7743 intptr_t variable_function_level = FunctionLevel() - 1; | |
7722 const String* variable_name = &Symbols::FunctionInstantiatorVar(); | 7744 const String* variable_name = &Symbols::FunctionInstantiatorVar(); |
7723 current_block_->scope->CaptureVariable( | 7745 LocalScope* scope = current_block_->scope; |
7724 current_block_->scope->LookupVariable(*variable_name, true)); | 7746 do { |
7747 while (scope->function_level() > variable_function_level) { | |
7748 scope = scope->parent(); | |
7749 } | |
7750 // Function instantiator is in top scope at that function level. | |
7751 LocalScope* parent_scope = scope->parent(); | |
7752 while ((parent_scope != NULL) && | |
7753 (parent_scope->function_level() == scope->function_level())) { | |
7754 scope = parent_scope; | |
7755 parent_scope = scope->parent(); | |
7756 } | |
7757 LocalVariable* function_instantiator_var = | |
7758 scope->LookupVariable(*variable_name, true); | |
7759 if (function_instantiator_var != NULL) { | |
7760 current_block_->scope->CaptureVariable(function_instantiator_var); | |
7761 } | |
7762 scope = scope->parent(); | |
7763 variable_function_level--; | |
7764 } while (variable_function_level >= 0); | |
7725 } | 7765 } |
7726 | 7766 |
7727 | 7767 |
7768 void Parser::CaptureAllInstantiators() { | |
7769 if (IsInstantiatorRequired()) { | |
7770 CaptureInstantiator(); | |
7771 } | |
7772 if (AreFunctionInstantiatorsRequired()) { | |
7773 CaptureFunctionInstantiators(); | |
7774 } | |
7775 } | |
7776 | |
7777 | |
7728 AstNode* Parser::LoadReceiver(TokenPosition token_pos) { | 7778 AstNode* Parser::LoadReceiver(TokenPosition token_pos) { |
7729 // A nested function may access 'this', referring to the receiver of the | 7779 // A nested function may access 'this', referring to the receiver of the |
7730 // outermost enclosing function. | 7780 // outermost enclosing function. |
7731 const bool kTestOnly = false; | 7781 const bool kTestOnly = false; |
7732 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 7782 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
7733 if (receiver == NULL) { | 7783 if (receiver == NULL) { |
7734 ReportError(token_pos, "illegal implicit access to receiver 'this'"); | 7784 ReportError(token_pos, "illegal implicit access to receiver 'this'"); |
7735 } | 7785 } |
7736 return new (Z) LoadLocalNode(TokenPos(), receiver); | 7786 return new (Z) LoadLocalNode(TokenPos(), receiver); |
7737 } | 7787 } |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8058 SkipFunctionLiteral(); | 8108 SkipFunctionLiteral(); |
8059 signature_type = function.SignatureType(); | 8109 signature_type = function.SignatureType(); |
8060 } | 8110 } |
8061 | 8111 |
8062 // Local functions are registered in the enclosing class, but | 8112 // Local functions are registered in the enclosing class, but |
8063 // ignored during class finalization. The enclosing class has | 8113 // ignored during class finalization. The enclosing class has |
8064 // already been finalized. | 8114 // already been finalized. |
8065 ASSERT(current_class().is_finalized()); | 8115 ASSERT(current_class().is_finalized()); |
8066 ASSERT(signature_type.IsFinalized()); | 8116 ASSERT(signature_type.IsFinalized()); |
8067 | 8117 |
8068 // Make sure that the instantiator is captured. | 8118 // Make sure that the instantiators are captured. |
8069 if ((FunctionLevel() > 0) && | 8119 if ((FunctionLevel() > 0) && !signature_type.IsInstantiated()) { |
8070 Class::Handle(signature_type.type_class()).IsGeneric()) { | 8120 CaptureAllInstantiators(); |
8071 CaptureInstantiator(); | |
8072 } | 8121 } |
8073 | 8122 |
8074 // A local signature type itself cannot be malformed or malbounded, only its | 8123 // A local signature type itself cannot be malformed or malbounded, only its |
8075 // signature function's result type or parameter types may be. | 8124 // signature function's result type or parameter types may be. |
8076 ASSERT(!signature_type.IsMalformed()); | 8125 ASSERT(!signature_type.IsMalformed()); |
8077 ASSERT(!signature_type.IsMalbounded()); | 8126 ASSERT(!signature_type.IsMalbounded()); |
8078 | 8127 |
8079 if (!is_literal) { | 8128 if (!is_literal) { |
8080 // Patch the function type of the variable now that the signature is known. | 8129 // Patch the function type of the variable now that the signature is known. |
8081 function_type.set_type_class(Class::Handle(Z, signature_type.type_class())); | 8130 function_type.set_type_class(Class::Handle(Z, signature_type.type_class())); |
(...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9934 catch_blocks.Last() = block; | 9983 catch_blocks.Last() = block; |
9935 } | 9984 } |
9936 // This catch clause will handle all exceptions. We can safely forget | 9985 // This catch clause will handle all exceptions. We can safely forget |
9937 // all previous catch clause types. | 9986 // all previous catch clause types. |
9938 handler_types.SetLength(0); | 9987 handler_types.SetLength(0); |
9939 handler_types.Add(*exception_param.type); | 9988 handler_types.Add(*exception_param.type); |
9940 } else { | 9989 } else { |
9941 // Has a type specification that is not malformed or malbounded. Now | 9990 // Has a type specification that is not malformed or malbounded. Now |
9942 // form an 'if type check' to guard the catch handler code. | 9991 // form an 'if type check' to guard the catch handler code. |
9943 if (!exception_param.type->IsInstantiated() && (FunctionLevel() > 0)) { | 9992 if (!exception_param.type->IsInstantiated() && (FunctionLevel() > 0)) { |
9944 // Make sure that the instantiator is captured. | 9993 // Make sure that the instantiators are captured. |
9945 CaptureInstantiator(); | 9994 CaptureAllInstantiators(); |
9946 } | 9995 } |
9947 TypeNode* exception_type = | 9996 TypeNode* exception_type = |
9948 new (Z) TypeNode(catch_pos, *exception_param.type); | 9997 new (Z) TypeNode(catch_pos, *exception_param.type); |
9949 AstNode* exception_value = | 9998 AstNode* exception_value = |
9950 new (Z) LoadLocalNode(catch_pos, exception_var); | 9999 new (Z) LoadLocalNode(catch_pos, exception_var); |
9951 if (!exception_type->type().IsInstantiated()) { | 10000 if (!exception_type->type().IsInstantiated()) { |
9952 EnsureExpressionTemp(); | 10001 EnsureExpressionTemp(); |
9953 } | 10002 } |
9954 type_tests.Add(new (Z) ComparisonNode(catch_pos, Token::kIS, | 10003 type_tests.Add(new (Z) ComparisonNode(catch_pos, Token::kIS, |
9955 exception_value, exception_type)); | 10004 exception_value, exception_type)); |
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10965 } else { | 11014 } else { |
10966 // For 'is' and 'as' we expect the right operand to be a type. | 11015 // For 'is' and 'as' we expect the right operand to be a type. |
10967 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { | 11016 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { |
10968 ConsumeToken(); | 11017 ConsumeToken(); |
10969 op_kind = Token::kISNOT; | 11018 op_kind = Token::kISNOT; |
10970 } | 11019 } |
10971 const TokenPosition type_pos = TokenPos(); | 11020 const TokenPosition type_pos = TokenPos(); |
10972 const AbstractType& type = AbstractType::ZoneHandle( | 11021 const AbstractType& type = AbstractType::ZoneHandle( |
10973 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kCanonicalize)); | 11022 Z, ParseTypeOrFunctionType(false, ClassFinalizer::kCanonicalize)); |
10974 if (!type.IsInstantiated() && (FunctionLevel() > 0)) { | 11023 if (!type.IsInstantiated() && (FunctionLevel() > 0)) { |
10975 // Make sure that the instantiator is captured. | 11024 // Make sure that the instantiators are captured. |
10976 CaptureInstantiator(); | 11025 CaptureAllInstantiators(); |
10977 } | 11026 } |
10978 right_operand = new (Z) TypeNode(type_pos, type); | 11027 right_operand = new (Z) TypeNode(type_pos, type); |
10979 // In production mode, the type may be malformed. | 11028 // In production mode, the type may be malformed. |
10980 // In checked mode, the type may be malformed or malbounded. | 11029 // In checked mode, the type may be malformed or malbounded. |
10981 if (type.IsMalformedOrMalbounded()) { | 11030 if (type.IsMalformedOrMalbounded()) { |
10982 // Note that a type error is thrown in a type test or in | 11031 // Note that a type error is thrown in a type test or in |
10983 // a type cast even if the tested value is null. | 11032 // a type cast even if the tested value is null. |
10984 // We need to evaluate the left operand for potential | 11033 // We need to evaluate the left operand for potential |
10985 // side effects. | 11034 // side effects. |
10986 LetNode* let = new (Z) LetNode(left_operand->token_pos()); | 11035 LetNode* let = new (Z) LetNode(left_operand->token_pos()); |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11833 TypeParameter& type_parameter = TypeParameter::ZoneHandle(Z); | 11882 TypeParameter& type_parameter = TypeParameter::ZoneHandle(Z); |
11834 type_parameter = TypeParameter::Cast(primary->primary()).raw(); | 11883 type_parameter = TypeParameter::Cast(primary->primary()).raw(); |
11835 if (type_parameter.IsClassTypeParameter()) { | 11884 if (type_parameter.IsClassTypeParameter()) { |
11836 if (ParsingStaticMember()) { | 11885 if (ParsingStaticMember()) { |
11837 const String& name = String::Handle(Z, type_parameter.name()); | 11886 const String& name = String::Handle(Z, type_parameter.name()); |
11838 ReportError(primary_pos, | 11887 ReportError(primary_pos, |
11839 "cannot access type parameter '%s' " | 11888 "cannot access type parameter '%s' " |
11840 "from static function", | 11889 "from static function", |
11841 name.ToCString()); | 11890 name.ToCString()); |
11842 } | 11891 } |
11843 // TODO(regis): Verify that CaptureInstantiator() was already called | |
11844 // and remove call below. | |
11845 if (FunctionLevel() > 0) { | 11892 if (FunctionLevel() > 0) { |
11846 // Make sure that the class instantiator is captured. | 11893 // Make sure that the class instantiator is captured. |
11847 CaptureInstantiator(); | 11894 CaptureInstantiator(); |
11848 } | 11895 } |
11849 type_parameter ^= CanonicalizeType(type_parameter); | 11896 type_parameter ^= CanonicalizeType(type_parameter); |
11850 ASSERT(!type_parameter.IsMalformed()); | |
11851 return new (Z) TypeNode(primary_pos, type_parameter); | |
11852 } else { | 11897 } else { |
11853 ASSERT(type_parameter.IsFunctionTypeParameter()); | 11898 ASSERT(type_parameter.IsFunctionTypeParameter()); |
11854 // TODO(regis): Verify that CaptureFunctionInstantiator() was already | 11899 if (!FLAG_generic_method_semantics) { |
11855 // called if necessary. | 11900 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); |
11856 // TODO(regis): Finalize type parameter and return as type node. | 11901 return new (Z) TypeNode(primary_pos, type); |
11857 // For now, map to dynamic type. | 11902 } |
11858 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); | 11903 if (type_parameter.parent_level() > 0) { |
11859 return new (Z) TypeNode(primary_pos, type); | 11904 // Make sure that the function instantiators are captured. |
11905 CaptureFunctionInstantiators(); | |
11906 } | |
11860 } | 11907 } |
11908 ASSERT(type_parameter.IsFinalized()); | |
11909 ASSERT(!type_parameter.IsMalformed()); | |
11910 return new (Z) TypeNode(primary_pos, type_parameter); | |
11861 } | 11911 } |
11862 | 11912 |
11863 | 11913 |
11864 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) { | 11914 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) { |
11865 AstNode* left = primary; | 11915 AstNode* left = primary; |
11866 while (true) { | 11916 while (true) { |
11867 AstNode* selector = NULL; | 11917 AstNode* selector = NULL; |
11868 if ((CurrentToken() == Token::kPERIOD) || | 11918 if ((CurrentToken() == Token::kPERIOD) || |
11869 (CurrentToken() == Token::kQM_PERIOD)) { | 11919 (CurrentToken() == Token::kQM_PERIOD)) { |
11870 // Unconditional or conditional property extraction or method call. | 11920 // Unconditional or conditional property extraction or method call. |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12354 return; | 12404 return; |
12355 } | 12405 } |
12356 // Resolve type class. | 12406 // Resolve type class. |
12357 if (!type->HasResolvedTypeClass()) { | 12407 if (!type->HasResolvedTypeClass()) { |
12358 const UnresolvedClass& unresolved_class = | 12408 const UnresolvedClass& unresolved_class = |
12359 UnresolvedClass::Handle(Z, type->unresolved_class()); | 12409 UnresolvedClass::Handle(Z, type->unresolved_class()); |
12360 const String& unresolved_class_name = | 12410 const String& unresolved_class_name = |
12361 String::Handle(Z, unresolved_class.ident()); | 12411 String::Handle(Z, unresolved_class.ident()); |
12362 if (unresolved_class.library_or_library_prefix() == Object::null()) { | 12412 if (unresolved_class.library_or_library_prefix() == Object::null()) { |
12363 // First check if the type is a function type parameter. | 12413 // First check if the type is a function type parameter. |
12364 if (!innermost_function().IsNull()) { | 12414 if (InGenericFunctionScope()) { |
12365 // TODO(regis): Shortcut this lookup if no generic functions in scope. | 12415 intptr_t type_param_func_level = FunctionLevel(); |
12366 // A bit has_generic_parent() would be useful on Function. | |
12367 // Unfortunately, all 32 kind bits are used in Function. | |
12368 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 12416 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
12369 Z, innermost_function().LookupTypeParameter(unresolved_class_name, | 12417 Z, innermost_function().LookupTypeParameter( |
12370 NULL)); | 12418 unresolved_class_name, &type_param_func_level)); |
12371 if (!type_parameter.IsNull()) { | 12419 if (!type_parameter.IsNull()) { |
12372 // A type parameter cannot be parameterized, so make the type | 12420 // A type parameter cannot be parameterized, so make the type |
12373 // malformed if type arguments have previously been parsed. | 12421 // malformed if type arguments have previously been parsed. |
12374 if (type->arguments() != TypeArguments::null()) { | 12422 if (type->arguments() != TypeArguments::null()) { |
12375 *type = ClassFinalizer::NewFinalizedMalformedType( | 12423 *type = ClassFinalizer::NewFinalizedMalformedType( |
12376 Error::Handle(Z), // No previous error. | 12424 Error::Handle(Z), // No previous error. |
12377 script_, type_parameter.token_pos(), | 12425 script_, type_parameter.token_pos(), |
12378 "type parameter '%s' cannot be parameterized", | 12426 "type parameter '%s' cannot be parameterized", |
12379 String::Handle(Z, type_parameter.name()).ToCString()); | 12427 String::Handle(Z, type_parameter.name()).ToCString()); |
12380 return; | 12428 return; |
12381 } | 12429 } |
12382 // TODO(regis): Mark function type parameter as finalized (its index | 12430 if (FLAG_generic_method_semantics) { |
12383 // does not need adjustment upon finalization) and return it. | 12431 ASSERT(type_parameter.IsFinalized()); |
12384 // For now, resolve the function type parameter to dynamic. | 12432 ASSERT(!type_parameter.IsMalformed()); |
12385 *type = Type::DynamicType(); | 12433 *type = type_parameter.raw(); |
12434 } else { | |
12435 *type = Type::DynamicType(); | |
12436 } | |
12386 return; | 12437 return; |
12387 } | 12438 } |
12388 } | 12439 } |
12389 // Then check if the type is a class type parameter. | 12440 // Then check if the type is a class type parameter. |
12390 const TypeParameter& type_parameter = TypeParameter::Handle( | 12441 const TypeParameter& type_parameter = TypeParameter::Handle( |
12391 Z, current_class().LookupTypeParameter(unresolved_class_name)); | 12442 Z, current_class().LookupTypeParameter(unresolved_class_name)); |
12392 if (!type_parameter.IsNull()) { | 12443 if (!type_parameter.IsNull()) { |
12393 // A type parameter is considered to be a malformed type when | 12444 // A type parameter is considered to be a malformed type when |
12394 // referenced by a static member. | 12445 // referenced by a static member. |
12395 if (ParsingStaticMember()) { | 12446 if (ParsingStaticMember()) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12511 bool Parser::IsInstantiatorRequired() const { | 12562 bool Parser::IsInstantiatorRequired() const { |
12512 ASSERT(!current_function().IsNull()); | 12563 ASSERT(!current_function().IsNull()); |
12513 if (current_function().is_static() && | 12564 if (current_function().is_static() && |
12514 !current_function().IsInFactoryScope()) { | 12565 !current_function().IsInFactoryScope()) { |
12515 return false; | 12566 return false; |
12516 } | 12567 } |
12517 return current_class().IsGeneric(); | 12568 return current_class().IsGeneric(); |
12518 } | 12569 } |
12519 | 12570 |
12520 | 12571 |
12572 bool Parser::AreFunctionInstantiatorsRequired() const { | |
12573 ASSERT(!innermost_function().IsNull()); | |
12574 Function& parent = Function::Handle(innermost_function().parent_function()); | |
12575 while (!parent.IsNull()) { | |
12576 if (parent.IsGeneric()) { | |
12577 return true; | |
12578 } | |
12579 parent = parent.parent_function(); | |
12580 } | |
12581 return false; | |
12582 } | |
12583 | |
12584 | |
12585 bool Parser::InGenericFunctionScope() const { | |
12586 if (!innermost_function().IsNull()) { | |
12587 // With one more free tag bit in Function, we could cache this information. | |
12588 if (innermost_function().IsGeneric()) { | |
12589 return true; | |
12590 } | |
12591 Function& parent = Function::Handle(innermost_function().parent_function()); | |
12592 while (!parent.IsNull()) { | |
12593 if (parent.IsGeneric()) { | |
12594 return true; | |
12595 } | |
12596 parent = parent.parent_function(); | |
12597 } | |
12598 } | |
12599 return false; | |
12600 } | |
12601 | |
12602 | |
12521 void Parser::InsertCachedConstantValue(const Script& script, | 12603 void Parser::InsertCachedConstantValue(const Script& script, |
12522 TokenPosition token_pos, | 12604 TokenPosition token_pos, |
12523 const Instance& value) { | 12605 const Instance& value) { |
12524 ASSERT(Thread::Current()->IsMutatorThread()); | 12606 ASSERT(Thread::Current()->IsMutatorThread()); |
12525 const intptr_t kInitialConstMapSize = 16; | 12607 const intptr_t kInitialConstMapSize = 16; |
12526 ASSERT(!script.InVMHeap()); | 12608 ASSERT(!script.InVMHeap()); |
12527 if (script.compile_time_constants() == Array::null()) { | 12609 if (script.compile_time_constants() == Array::null()) { |
12528 const Array& array = Array::Handle( | 12610 const Array& array = Array::Handle( |
12529 HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kNew)); | 12611 HashTables::New<ConstantsMap>(kInitialConstMapSize, Heap::kNew)); |
12530 script.set_compile_time_constants(array); | 12612 script.set_compile_time_constants(array); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12958 // throw NoSuchMethodError if we're compiling a static method. | 13040 // throw NoSuchMethodError if we're compiling a static method. |
12959 AstNode* Parser::ResolveIdent(TokenPosition ident_pos, | 13041 AstNode* Parser::ResolveIdent(TokenPosition ident_pos, |
12960 const String& ident, | 13042 const String& ident, |
12961 bool allow_closure_names) { | 13043 bool allow_closure_names) { |
12962 TRACE_PARSER("ResolveIdent"); | 13044 TRACE_PARSER("ResolveIdent"); |
12963 // First try to find the variable in the local scope (block scope or | 13045 // First try to find the variable in the local scope (block scope or |
12964 // class scope). | 13046 // class scope). |
12965 AstNode* resolved = NULL; | 13047 AstNode* resolved = NULL; |
12966 intptr_t resolved_func_level = 0; | 13048 intptr_t resolved_func_level = 0; |
12967 ResolveIdentInLocalScope(ident_pos, ident, &resolved, &resolved_func_level); | 13049 ResolveIdentInLocalScope(ident_pos, ident, &resolved, &resolved_func_level); |
12968 if (!innermost_function().IsNull()) { | 13050 if (InGenericFunctionScope()) { |
12969 // TODO(regis): Shortcut this lookup if no generic functions in scope. | |
12970 intptr_t type_param_func_level = FunctionLevel(); | 13051 intptr_t type_param_func_level = FunctionLevel(); |
12971 const TypeParameter& type_parameter = | 13052 const TypeParameter& type_parameter = |
12972 TypeParameter::ZoneHandle(Z, innermost_function().LookupTypeParameter( | 13053 TypeParameter::ZoneHandle(Z, innermost_function().LookupTypeParameter( |
12973 ident, &type_param_func_level)); | 13054 ident, &type_param_func_level)); |
12974 if (!type_parameter.IsNull()) { | 13055 if (!type_parameter.IsNull()) { |
12975 if ((resolved == NULL) || (resolved_func_level < type_param_func_level)) { | 13056 if ((resolved == NULL) || (resolved_func_level < type_param_func_level)) { |
12976 // The identifier is a function type parameter, possibly shadowing | 13057 // The identifier is a function type parameter, possibly shadowing |
12977 // 'resolved'. | 13058 // 'resolved'. |
12978 if ((FunctionLevel() > 0) && | 13059 if (!FLAG_generic_method_semantics) { |
12979 (type_param_func_level < FunctionLevel())) { | 13060 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); |
12980 // Make sure that the function instantiator is captured. | 13061 return new (Z) TypeNode(ident_pos, type); |
12981 CaptureFunctionInstantiator(); | |
12982 } | 13062 } |
12983 // TODO(regis): Mark function type parameter as finalized (its index | 13063 ASSERT(type_parameter.IsFinalized()); |
12984 // does not need adjustment upon finalization) and return as type node. | 13064 ASSERT(!type_parameter.IsMalformed()); |
12985 // For now, resolve the function type parameter to dynamic. | 13065 return new (Z) TypeNode(ident_pos, type_parameter); |
12986 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); | |
12987 return new (Z) TypeNode(ident_pos, type); | |
12988 } | 13066 } |
12989 } | 13067 } |
12990 } | 13068 } |
12991 if (resolved == NULL) { | 13069 if (resolved == NULL) { |
12992 // Check whether the identifier is a class type parameter. | 13070 // Check whether the identifier is a class type parameter. |
12993 if (!current_class().IsNull()) { | 13071 if (!current_class().IsNull()) { |
12994 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 13072 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
12995 Z, current_class().LookupTypeParameter(ident)); | 13073 Z, current_class().LookupTypeParameter(ident)); |
12996 if (!type_parameter.IsNull()) { | 13074 if (!type_parameter.IsNull()) { |
12997 if (FunctionLevel() > 0) { | |
12998 // Make sure that the class instantiator is captured. | |
12999 CaptureInstantiator(); | |
13000 } | |
13001 type_parameter ^= CanonicalizeType(type_parameter); | 13075 type_parameter ^= CanonicalizeType(type_parameter); |
13002 ASSERT(!type_parameter.IsMalformed()); | 13076 ASSERT(!type_parameter.IsMalformed()); |
13003 return new (Z) TypeNode(ident_pos, type_parameter); | 13077 return new (Z) TypeNode(ident_pos, type_parameter); |
13004 } | 13078 } |
13005 } | 13079 } |
13006 // Not found in the local scope, and the name is not a type parameter. | 13080 // Not found in the local scope, and the name is not a type parameter. |
13007 // Try finding the variable in the library scope (current library | 13081 // Try finding the variable in the library scope (current library |
13008 // and all libraries imported by it without a library prefix). | 13082 // and all libraries imported by it without a library prefix). |
13009 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); | 13083 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); |
13010 } | 13084 } |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13425 // Factory call at runtime. | 13499 // Factory call at runtime. |
13426 const Class& factory_class = | 13500 const Class& factory_class = |
13427 Class::Handle(Z, Library::LookupCoreClass(Symbols::List())); | 13501 Class::Handle(Z, Library::LookupCoreClass(Symbols::List())); |
13428 ASSERT(!factory_class.IsNull()); | 13502 ASSERT(!factory_class.IsNull()); |
13429 const Function& factory_method = Function::ZoneHandle( | 13503 const Function& factory_method = Function::ZoneHandle( |
13430 Z, factory_class.LookupFactory( | 13504 Z, factory_class.LookupFactory( |
13431 Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); | 13505 Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); |
13432 ASSERT(!factory_method.IsNull()); | 13506 ASSERT(!factory_method.IsNull()); |
13433 if (!list_type_arguments.IsNull() && | 13507 if (!list_type_arguments.IsNull() && |
13434 !list_type_arguments.IsInstantiated() && (FunctionLevel() > 0)) { | 13508 !list_type_arguments.IsInstantiated() && (FunctionLevel() > 0)) { |
13435 // Make sure that the instantiator is captured. | 13509 // Make sure that the instantiators are captured. |
13436 CaptureInstantiator(); | 13510 CaptureAllInstantiators(); |
13437 } | 13511 } |
13438 TypeArguments& factory_type_args = | 13512 TypeArguments& factory_type_args = |
13439 TypeArguments::ZoneHandle(Z, list_type_arguments.raw()); | 13513 TypeArguments::ZoneHandle(Z, list_type_arguments.raw()); |
13440 // If the factory class extends other parameterized classes, adjust the | 13514 // If the factory class extends other parameterized classes, adjust the |
13441 // type argument vector. | 13515 // type argument vector. |
13442 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { | 13516 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { |
13443 ASSERT(factory_type_args.Length() == 1); | 13517 ASSERT(factory_type_args.Length() == 1); |
13444 Type& factory_type = Type::Handle( | 13518 Type& factory_type = Type::Handle( |
13445 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); | 13519 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); |
13446 // It is not strictly necessary to canonicalize factory_type, but only its | 13520 // It is not strictly necessary to canonicalize factory_type, but only its |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13676 const Class& factory_class = | 13750 const Class& factory_class = |
13677 Class::Handle(Z, Library::LookupCoreClass(Symbols::Map())); | 13751 Class::Handle(Z, Library::LookupCoreClass(Symbols::Map())); |
13678 ASSERT(!factory_class.IsNull()); | 13752 ASSERT(!factory_class.IsNull()); |
13679 const Function& factory_method = Function::ZoneHandle( | 13753 const Function& factory_method = Function::ZoneHandle( |
13680 Z, factory_class.LookupFactory( | 13754 Z, factory_class.LookupFactory( |
13681 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); | 13755 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); |
13682 ASSERT(!factory_method.IsNull()); | 13756 ASSERT(!factory_method.IsNull()); |
13683 if (!map_type_arguments.IsNull() && !map_type_arguments.IsInstantiated() && | 13757 if (!map_type_arguments.IsNull() && !map_type_arguments.IsInstantiated() && |
13684 (FunctionLevel() > 0)) { | 13758 (FunctionLevel() > 0)) { |
13685 // Make sure that the instantiator is captured. | 13759 // Make sure that the instantiator is captured. |
13686 CaptureInstantiator(); | 13760 CaptureAllInstantiators(); |
13687 } | 13761 } |
13688 TypeArguments& factory_type_args = | 13762 TypeArguments& factory_type_args = |
13689 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); | 13763 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); |
13690 // If the factory class extends other parameterized classes, adjust the | 13764 // If the factory class extends other parameterized classes, adjust the |
13691 // type argument vector. | 13765 // type argument vector. |
13692 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { | 13766 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { |
13693 ASSERT(factory_type_args.Length() == 2); | 13767 ASSERT(factory_type_args.Length() == 2); |
13694 Type& factory_type = Type::Handle( | 13768 Type& factory_type = Type::Handle( |
13695 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); | 13769 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); |
13696 // It is not strictly necessary to canonicalize factory_type, but only its | 13770 // It is not strictly necessary to canonicalize factory_type, but only its |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14161 const Function& tearoff_func = Function::ZoneHandle( | 14235 const Function& tearoff_func = Function::ZoneHandle( |
14162 Z, BuildConstructorClosureFunction(constructor, new_pos)); | 14236 Z, BuildConstructorClosureFunction(constructor, new_pos)); |
14163 | 14237 |
14164 // Local functions normally get parsed when the enclosing function is | 14238 // Local functions normally get parsed when the enclosing function is |
14165 // compiled. Since constructor tearoff closures don't get parsed here, | 14239 // compiled. Since constructor tearoff closures don't get parsed here, |
14166 // we need to duplicate some of the side effects of parsing, namely | 14240 // we need to duplicate some of the side effects of parsing, namely |
14167 // creating a function scope, and capturing the instantiator of the | 14241 // creating a function scope, and capturing the instantiator of the |
14168 // enclosing function if necessary. | 14242 // enclosing function if necessary. |
14169 OpenFunctionBlock(tearoff_func); | 14243 OpenFunctionBlock(tearoff_func); |
14170 // If there are type arguments in the tearoff expression that are | 14244 // If there are type arguments in the tearoff expression that are |
14171 // not yet instantiated, capture the instantiator. | 14245 // not yet instantiated, capture the instantiators. |
14172 if (IsInstantiatorRequired() && !type_arguments.IsNull() && | 14246 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated()) { |
14173 !type_arguments.IsInstantiated()) { | 14247 CaptureAllInstantiators(); |
14174 CaptureInstantiator(); | |
14175 } | 14248 } |
14176 SequenceNode* tearoff_body = CloseBlock(); | 14249 SequenceNode* tearoff_body = CloseBlock(); |
14177 ClosureNode* closure_obj = | 14250 ClosureNode* closure_obj = |
14178 new (Z) ClosureNode(new_pos, tearoff_func, NULL, tearoff_body->scope()); | 14251 new (Z) ClosureNode(new_pos, tearoff_func, NULL, tearoff_body->scope()); |
14179 return closure_obj; | 14252 return closure_obj; |
14180 } | 14253 } |
14181 | 14254 |
14182 ASSERT(!is_tearoff_expression); | 14255 ASSERT(!is_tearoff_expression); |
14183 String& error_message = String::Handle(Z); | 14256 String& error_message = String::Handle(Z); |
14184 if (!constructor.AreValidArguments(arguments_length, arguments->names(), | 14257 if (!constructor.AreValidArguments(arguments_length, arguments->names(), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14248 "const factory result is not an instance of '%s'", | 14321 "const factory result is not an instance of '%s'", |
14249 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); | 14322 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); |
14250 new_object = ThrowTypeError(new_pos, type_bound); | 14323 new_object = ThrowTypeError(new_pos, type_bound); |
14251 } | 14324 } |
14252 type_bound = AbstractType::null(); | 14325 type_bound = AbstractType::null(); |
14253 } | 14326 } |
14254 } else { | 14327 } else { |
14255 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); | 14328 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
14256 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated() && | 14329 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated() && |
14257 (FunctionLevel() > 0)) { | 14330 (FunctionLevel() > 0)) { |
14258 // Make sure that the instantiator is captured. | 14331 // Make sure that the instantiators are captured. |
14259 CaptureInstantiator(); | 14332 CaptureAllInstantiators(); |
14260 } | 14333 } |
14261 // If the type argument vector is not instantiated, we verify in checked | 14334 // If the type argument vector is not instantiated, we verify in checked |
14262 // mode at runtime that it is within its declared bounds. | 14335 // mode at runtime that it is within its declared bounds. |
14263 new_object = CreateConstructorCallNode(new_pos, type_arguments, constructor, | 14336 new_object = CreateConstructorCallNode(new_pos, type_arguments, constructor, |
14264 arguments); | 14337 arguments); |
14265 } | 14338 } |
14266 if (!type_bound.IsNull()) { | 14339 if (!type_bound.IsNull()) { |
14267 new_object = new (Z) AssignableNode(new_pos, new_object, type_bound, | 14340 new_object = new (Z) AssignableNode(new_pos, new_object, type_bound, |
14268 Symbols::FactoryResult()); | 14341 Symbols::FactoryResult()); |
14269 } | 14342 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14433 ExpectToken(Token::kPERIOD); | 14506 ExpectToken(Token::kPERIOD); |
14434 } | 14507 } |
14435 } | 14508 } |
14436 String& ident = *CurrentLiteral(); | 14509 String& ident = *CurrentLiteral(); |
14437 ConsumeToken(); | 14510 ConsumeToken(); |
14438 if (prefix.IsNull()) { | 14511 if (prefix.IsNull()) { |
14439 intptr_t primary_func_level = 0; | 14512 intptr_t primary_func_level = 0; |
14440 ResolveIdentInLocalScope(qual_ident_pos, ident, &primary, | 14513 ResolveIdentInLocalScope(qual_ident_pos, ident, &primary, |
14441 &primary_func_level); | 14514 &primary_func_level); |
14442 // Check whether the identifier is shadowed by a function type parameter. | 14515 // Check whether the identifier is shadowed by a function type parameter. |
14443 if (!innermost_function().IsNull()) { | 14516 if (InGenericFunctionScope()) { |
14444 // TODO(regis): Shortcut this lookup if no generic functions in scope. | |
14445 intptr_t type_param_func_level = FunctionLevel(); | 14517 intptr_t type_param_func_level = FunctionLevel(); |
14446 TypeParameter& type_param = TypeParameter::ZoneHandle( | 14518 TypeParameter& type_param = TypeParameter::ZoneHandle( |
14447 Z, innermost_function().LookupTypeParameter( | 14519 Z, innermost_function().LookupTypeParameter( |
14448 ident, &type_param_func_level)); | 14520 ident, &type_param_func_level)); |
14449 if (!type_param.IsNull()) { | 14521 if (!type_param.IsNull()) { |
14450 if ((primary == NULL) || | 14522 if ((primary == NULL) || |
14451 (primary_func_level < type_param_func_level)) { | 14523 (primary_func_level < type_param_func_level)) { |
14452 // The identifier is a function type parameter, possibly shadowing | 14524 // The identifier is a function type parameter, possibly shadowing |
14453 // already resolved 'primary'. | 14525 // already resolved 'primary'. |
14454 if ((FunctionLevel() > 0) && | |
14455 (type_param_func_level < FunctionLevel())) { | |
14456 // Make sure that the function instantiator is captured. | |
14457 CaptureFunctionInstantiator(); | |
14458 } | |
14459 return new (Z) PrimaryNode(qual_ident_pos, type_param); | 14526 return new (Z) PrimaryNode(qual_ident_pos, type_param); |
14460 } | 14527 } |
14461 } | 14528 } |
14462 } | 14529 } |
14463 if (primary == NULL) { | 14530 if (primary == NULL) { |
14464 // Check whether the identifier is a type parameter. | 14531 // Check whether the identifier is a type parameter. |
14465 if (!current_class().IsNull()) { | 14532 if (!current_class().IsNull()) { |
14466 TypeParameter& type_param = TypeParameter::ZoneHandle( | 14533 TypeParameter& type_param = TypeParameter::ZoneHandle( |
14467 Z, current_class().LookupTypeParameter(ident)); | 14534 Z, current_class().LookupTypeParameter(ident)); |
14468 if (!type_param.IsNull()) { | 14535 if (!type_param.IsNull()) { |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15133 const ArgumentListNode& function_args, | 15200 const ArgumentListNode& function_args, |
15134 const LocalVariable* temp_for_last_arg, | 15201 const LocalVariable* temp_for_last_arg, |
15135 bool is_super_invocation) { | 15202 bool is_super_invocation) { |
15136 UNREACHABLE(); | 15203 UNREACHABLE(); |
15137 return NULL; | 15204 return NULL; |
15138 } | 15205 } |
15139 | 15206 |
15140 } // namespace dart | 15207 } // namespace dart |
15141 | 15208 |
15142 #endif // DART_PRECOMPILED_RUNTIME | 15209 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |