| 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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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()) { | 1184 // ParseFunc has recorded the generic function type arguments variable. |
| 1185 const String* variable_name = &Symbols::FunctionInstantiatorVar(); | 1185 ASSERT(!FLAG_generic_method_semantics || |
| 1186 const bool kTestOnly = true; | 1186 !parser.current_function().IsGeneric() || |
| 1187 LocalVariable* instantiator = | 1187 (parsed_function->function_type_arguments() != NULL)); |
| 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 } | |
| 1194 } | 1188 } |
| 1195 | 1189 |
| 1196 | 1190 |
| 1197 RawObject* Parser::ParseMetadata(const Field& meta_data) { | 1191 RawObject* Parser::ParseMetadata(const Field& meta_data) { |
| 1198 LongJumpScope jump; | 1192 LongJumpScope jump; |
| 1199 if (setjmp(*jump.Set()) == 0) { | 1193 if (setjmp(*jump.Set()) == 0) { |
| 1200 Thread* thread = Thread::Current(); | 1194 Thread* thread = Thread::Current(); |
| 1201 StackZone stack_zone(thread); | 1195 StackZone stack_zone(thread); |
| 1202 Zone* zone = stack_zone.GetZone(); | 1196 Zone* zone = stack_zone.GetZone(); |
| 1203 const Class& owner_class = Class::Handle(zone, meta_data.Owner()); | 1197 const Class& owner_class = Class::Handle(zone, meta_data.Owner()); |
| (...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3464 if (func.IsGenerativeConstructor()) { | 3458 if (func.IsGenerativeConstructor()) { |
| 3465 SequenceNode* statements = ParseConstructor(func); | 3459 SequenceNode* statements = ParseConstructor(func); |
| 3466 last_used_try_index_ = saved_try_index; | 3460 last_used_try_index_ = saved_try_index; |
| 3467 return statements; | 3461 return statements; |
| 3468 } | 3462 } |
| 3469 | 3463 |
| 3470 ASSERT(!func.IsGenerativeConstructor()); | 3464 ASSERT(!func.IsGenerativeConstructor()); |
| 3471 OpenFunctionBlock(func); // Build local scope for function. | 3465 OpenFunctionBlock(func); // Build local scope for function. |
| 3472 | 3466 |
| 3473 if (FLAG_generic_method_semantics && func.IsGeneric()) { | 3467 if (FLAG_generic_method_semantics && func.IsGeneric()) { |
| 3474 // Insert function instantiator variable to scope. | 3468 // Lookup function type arguments variable in parent function scope, if any. |
| 3475 LocalVariable* function_instantiator = new (Z) LocalVariable( | 3469 if (func.HasGenericParent()) { |
| 3470 const String* variable_name = &Symbols::FunctionTypeArgumentsVar(); |
| 3471 LocalVariable* parent_type_arguments = |
| 3472 current_block_->scope->LookupVariable(*variable_name, true); |
| 3473 ASSERT(parent_type_arguments != NULL); |
| 3474 // TODO(regis): It may be too early to capture parent_type_arguments here. |
| 3475 // In case it is never used, we could save capturing and concatenating. |
| 3476 current_block_->scope->CaptureVariable(parent_type_arguments); |
| 3477 parsed_function_->set_parent_type_arguments(parent_type_arguments); |
| 3478 } |
| 3479 // Insert function type arguments variable to scope. |
| 3480 LocalVariable* function_type_arguments = new (Z) LocalVariable( |
| 3476 TokenPosition::kNoSource, TokenPosition::kNoSource, | 3481 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 3477 Symbols::FunctionInstantiatorVar(), Object::dynamic_type()); | 3482 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); |
| 3478 current_block_->scope->AddVariable(function_instantiator); | 3483 current_block_->scope->AddVariable(function_type_arguments); |
| 3484 parsed_function_->set_function_type_arguments(function_type_arguments); |
| 3479 } | 3485 } |
| 3480 | 3486 |
| 3481 ParamList params; | 3487 ParamList params; |
| 3482 // An instance closure function may capture and access the receiver, but via | 3488 // An instance closure function may capture and access the receiver, but via |
| 3483 // the context and not via the first formal parameter. | 3489 // the context and not via the first formal parameter. |
| 3484 if (func.IsClosureFunction()) { | 3490 if (func.IsClosureFunction()) { |
| 3485 // The first parameter of a closure function is the closure object. | 3491 // The first parameter of a closure function is the closure object. |
| 3486 ASSERT(!func.is_const()); // Closure functions cannot be const. | 3492 ASSERT(!func.is_const()); // Closure functions cannot be const. |
| 3487 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), | 3493 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), |
| 3488 &Object::dynamic_type()); | 3494 &Object::dynamic_type()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3631 // We are parsing, but not compiling, a local function. | 3637 // We are parsing, but not compiling, a local function. |
| 3632 // The instantiator may be required at run time for generic type checks. | 3638 // 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 | 3639 // 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 | 3640 // generic type explicitly. However, it may assign a value to a captured |
| 3635 // variable declared with its generic type in the enclosing function. | 3641 // variable declared with its generic type in the enclosing function. |
| 3636 // Make sure that the receiver of the enclosing instance function | 3642 // Make sure that the receiver of the enclosing instance function |
| 3637 // (or implicit first parameter of an enclosing factory) is marked as | 3643 // (or implicit first parameter of an enclosing factory) is marked as |
| 3638 // captured if type checks are enabled, because they may access it to | 3644 // captured if type checks are enabled, because they may access it to |
| 3639 // instantiate types. | 3645 // instantiate types. |
| 3640 // If any enclosing parent of the function being parsed is generic, capture | 3646 // If any enclosing parent of the function being parsed is generic, capture |
| 3641 // their function instantiators. | 3647 // their function type arguments. |
| 3642 CaptureAllInstantiators(); | 3648 CaptureAllInstantiators(); |
| 3643 } | 3649 } |
| 3644 | 3650 |
| 3645 BoolScope allow_await(&this->await_is_keyword_, | 3651 BoolScope allow_await(&this->await_is_keyword_, |
| 3646 func.IsAsyncOrGenerator() || func.is_generated_body()); | 3652 func.IsAsyncOrGenerator() || func.is_generated_body()); |
| 3647 TokenPosition end_token_pos = TokenPosition::kNoSource; | 3653 TokenPosition end_token_pos = TokenPosition::kNoSource; |
| 3648 if (CurrentToken() == Token::kLBRACE) { | 3654 if (CurrentToken() == Token::kLBRACE) { |
| 3649 ConsumeToken(); | 3655 ConsumeToken(); |
| 3650 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { | 3656 if (String::Handle(Z, func.name()).Equals(Symbols::EqualOperator())) { |
| 3651 const Class& owner = Class::Handle(Z, func.Owner()); | 3657 const Class& owner = Class::Handle(Z, func.Owner()); |
| (...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5527 ConsumeToken(); | 5533 ConsumeToken(); |
| 5528 // TODO(regis): Handle 'super' differently than 'extends'. | 5534 // TODO(regis): Handle 'super' differently than 'extends'. |
| 5529 // A bound may refer to the owner of the type parameter it applies to, | 5535 // A bound may refer to the owner of the type parameter it applies to, |
| 5530 // i.e. to the class or function currently being parsed. | 5536 // i.e. to the class or function currently being parsed. |
| 5531 // Postpone resolution in order to avoid resolving the owner and its | 5537 // Postpone resolution in order to avoid resolving the owner and its |
| 5532 // type parameters, as they are not fully parsed yet. | 5538 // type parameters, as they are not fully parsed yet. |
| 5533 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); | 5539 type_parameter_bound = ParseType(ClassFinalizer::kDoNotResolve); |
| 5534 } else { | 5540 } else { |
| 5535 type_parameter_bound = I->object_store()->object_type(); | 5541 type_parameter_bound = I->object_store()->object_type(); |
| 5536 } | 5542 } |
| 5543 // Note that we cannot yet calculate the final index of a function type |
| 5544 // parameter, because we may not have parsed the parent function yet. |
| 5537 type_parameter = TypeParameter::New( | 5545 type_parameter = TypeParameter::New( |
| 5538 parameterizing_class ? current_class() : Class::Handle(Z), | 5546 parameterizing_class ? current_class() : Class::Handle(Z), |
| 5539 parameterizing_class ? Function::Handle(Z) : innermost_function(), | 5547 parameterizing_class ? Function::Handle(Z) : innermost_function(), |
| 5540 index, 0, type_parameter_name, type_parameter_bound, declaration_pos); | 5548 index, type_parameter_name, type_parameter_bound, declaration_pos); |
| 5541 if (!parameterizing_class) { | |
| 5542 type_parameter.SetIsFinalized(); | |
| 5543 } | |
| 5544 type_parameters_array.Add( | 5549 type_parameters_array.Add( |
| 5545 &AbstractType::ZoneHandle(Z, type_parameter.raw())); | 5550 &AbstractType::ZoneHandle(Z, type_parameter.raw())); |
| 5546 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { | 5551 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { |
| 5547 library_.AddTypeParameterMetadata(type_parameter, metadata_pos); | 5552 library_.AddTypeParameterMetadata(type_parameter, metadata_pos); |
| 5548 } | 5553 } |
| 5549 index++; | 5554 index++; |
| 5550 } while (CurrentToken() == Token::kCOMMA); | 5555 } while (CurrentToken() == Token::kCOMMA); |
| 5551 Token::Kind token = CurrentToken(); | 5556 Token::Kind token = CurrentToken(); |
| 5552 if ((token == Token::kGT) || (token == Token::kSHR)) { | 5557 if ((token == Token::kGT) || (token == Token::kSHR)) { |
| 5553 ConsumeRightAngleBracket(); | 5558 ConsumeRightAngleBracket(); |
| (...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7727 void Parser::CaptureInstantiator() { | 7732 void Parser::CaptureInstantiator() { |
| 7728 ASSERT(FunctionLevel() > 0); | 7733 ASSERT(FunctionLevel() > 0); |
| 7729 const String* variable_name = current_function().IsInFactoryScope() | 7734 const String* variable_name = current_function().IsInFactoryScope() |
| 7730 ? &Symbols::TypeArgumentsParameter() | 7735 ? &Symbols::TypeArgumentsParameter() |
| 7731 : &Symbols::This(); | 7736 : &Symbols::This(); |
| 7732 current_block_->scope->CaptureVariable( | 7737 current_block_->scope->CaptureVariable( |
| 7733 current_block_->scope->LookupVariable(*variable_name, true)); | 7738 current_block_->scope->LookupVariable(*variable_name, true)); |
| 7734 } | 7739 } |
| 7735 | 7740 |
| 7736 | 7741 |
| 7737 void Parser::CaptureFunctionInstantiators() { | 7742 void Parser::CaptureFunctionTypeArguments() { |
| 7738 ASSERT(InGenericFunctionScope()); | 7743 ASSERT(InGenericFunctionScope()); |
| 7739 ASSERT(FunctionLevel() > 0); | 7744 ASSERT(FunctionLevel() > 0); |
| 7740 if (!FLAG_generic_method_semantics) { | 7745 if (!FLAG_generic_method_semantics) { |
| 7741 return; | 7746 return; |
| 7742 } | 7747 } |
| 7743 // Capture function instantiators starting at parent of innermost function. | 7748 const String* variable_name = &Symbols::FunctionTypeArgumentsVar(); |
| 7744 intptr_t variable_function_level = FunctionLevel() - 1; | 7749 current_block_->scope->CaptureVariable( |
| 7745 const String* variable_name = &Symbols::FunctionInstantiatorVar(); | 7750 current_block_->scope->LookupVariable(*variable_name, true)); |
| 7746 LocalScope* scope = current_block_->scope; | |
| 7747 do { | |
| 7748 while (scope->function_level() > variable_function_level) { | |
| 7749 scope = scope->parent(); | |
| 7750 } | |
| 7751 // Function instantiator is in top scope at that function level. | |
| 7752 LocalScope* parent_scope = scope->parent(); | |
| 7753 while ((parent_scope != NULL) && | |
| 7754 (parent_scope->function_level() == scope->function_level())) { | |
| 7755 scope = parent_scope; | |
| 7756 parent_scope = scope->parent(); | |
| 7757 } | |
| 7758 LocalVariable* function_instantiator_var = | |
| 7759 scope->LookupVariable(*variable_name, true); | |
| 7760 if (function_instantiator_var != NULL) { | |
| 7761 current_block_->scope->CaptureVariable(function_instantiator_var); | |
| 7762 } | |
| 7763 scope = scope->parent(); | |
| 7764 variable_function_level--; | |
| 7765 } while (variable_function_level >= 0); | |
| 7766 } | 7751 } |
| 7767 | 7752 |
| 7768 | 7753 |
| 7769 void Parser::CaptureAllInstantiators() { | 7754 void Parser::CaptureAllInstantiators() { |
| 7770 if (IsInstantiatorRequired()) { | 7755 if (IsInstantiatorRequired()) { |
| 7771 CaptureInstantiator(); | 7756 CaptureInstantiator(); |
| 7772 } | 7757 } |
| 7773 if (AreFunctionInstantiatorsRequired()) { | 7758 if (innermost_function().HasGenericParent()) { |
| 7774 CaptureFunctionInstantiators(); | 7759 CaptureFunctionTypeArguments(); |
| 7775 } | 7760 } |
| 7776 } | 7761 } |
| 7777 | 7762 |
| 7778 | 7763 |
| 7779 AstNode* Parser::LoadReceiver(TokenPosition token_pos) { | 7764 AstNode* Parser::LoadReceiver(TokenPosition token_pos) { |
| 7780 // A nested function may access 'this', referring to the receiver of the | 7765 // A nested function may access 'this', referring to the receiver of the |
| 7781 // outermost enclosing function. | 7766 // outermost enclosing function. |
| 7782 const bool kTestOnly = false; | 7767 const bool kTestOnly = false; |
| 7783 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 7768 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| 7784 if (receiver == NULL) { | 7769 if (receiver == NULL) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8021 if (!FLAG_generic_method_syntax) { | 8006 if (!FLAG_generic_method_syntax) { |
| 8022 ReportError("generic functions not supported"); | 8007 ReportError("generic functions not supported"); |
| 8023 } | 8008 } |
| 8024 if (!found_func) { | 8009 if (!found_func) { |
| 8025 ParseTypeParameters(false); // Not parameterizing class, but function. | 8010 ParseTypeParameters(false); // Not parameterizing class, but function. |
| 8026 } else { | 8011 } else { |
| 8027 TryParseTypeParameters(); | 8012 TryParseTypeParameters(); |
| 8028 } | 8013 } |
| 8029 } | 8014 } |
| 8030 | 8015 |
| 8031 if (!found_func && !result_type.IsFinalized()) { | |
| 8032 // Now that type parameters are declared, the result type can be resolved | |
| 8033 // and finalized. | |
| 8034 ResolveType(&result_type); | |
| 8035 result_type = CanonicalizeType(result_type); | |
| 8036 function.set_result_type(result_type); | |
| 8037 } | |
| 8038 | |
| 8039 CheckToken(Token::kLPAREN); | 8016 CheckToken(Token::kLPAREN); |
| 8040 | 8017 |
| 8041 // The function type needs to be finalized at compile time, since the closure | 8018 // The function type needs to be finalized at compile time, since the closure |
| 8042 // may be type checked at run time when assigned to a function variable, | 8019 // may be type checked at run time when assigned to a function variable, |
| 8043 // passed as a function argument, or returned as a function result. | 8020 // passed as a function argument, or returned as a function result. |
| 8044 | 8021 |
| 8045 LocalVariable* function_variable = NULL; | 8022 LocalVariable* function_variable = NULL; |
| 8046 Type& function_type = Type::ZoneHandle(Z); | 8023 Type& function_type = Type::ZoneHandle(Z); |
| 8047 if (!is_literal) { | 8024 if (!is_literal) { |
| 8048 // Since the function type depends on the signature of the closure function, | 8025 // Since the function type depends on the signature of the closure function, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 8075 } | 8052 } |
| 8076 } | 8053 } |
| 8077 | 8054 |
| 8078 Type& signature_type = Type::ZoneHandle(Z); | 8055 Type& signature_type = Type::ZoneHandle(Z); |
| 8079 SequenceNode* statements = NULL; | 8056 SequenceNode* statements = NULL; |
| 8080 if (!found_func) { | 8057 if (!found_func) { |
| 8081 // Parse the local function. As a side effect of the parsing, the | 8058 // Parse the local function. As a side effect of the parsing, the |
| 8082 // variables of this function's scope that are referenced by the local | 8059 // variables of this function's scope that are referenced by the local |
| 8083 // function (and its inner nested functions) will be marked as captured. | 8060 // function (and its inner nested functions) will be marked as captured. |
| 8084 | 8061 |
| 8085 ASSERT(AbstractType::Handle(Z, function.result_type()).IsResolved()); | 8062 ResolveType(&result_type); // Parameter types are resolved in ParseFunc. |
| 8063 function.set_result_type(result_type); |
| 8086 statements = Parser::ParseFunc(function, !is_literal); | 8064 statements = Parser::ParseFunc(function, !is_literal); |
| 8087 INC_STAT(thread(), num_functions_parsed, 1); | 8065 INC_STAT(thread(), num_functions_parsed, 1); |
| 8088 | 8066 |
| 8089 // Now that the local function has formal parameters, lookup the signature | 8067 // Now that the local function has formal parameters, finalize its signature |
| 8090 signature_type = function.SignatureType(); | 8068 signature_type = function.SignatureType(); |
| 8091 signature_type ^= CanonicalizeType(signature_type); | 8069 signature_type ^= CanonicalizeType(signature_type); |
| 8092 function.SetSignatureType(signature_type); | 8070 function.SetSignatureType(signature_type); |
| 8093 } else { | 8071 } else { |
| 8094 // The local function was parsed before. The captured variables are | 8072 // The local function was parsed before. The captured variables are |
| 8095 // saved in the function's context scope. Iterate over the context scope | 8073 // saved in the function's context scope. Iterate over the context scope |
| 8096 // and mark its variables as captured. | 8074 // and mark its variables as captured. |
| 8097 const ContextScope& context_scope = | 8075 const ContextScope& context_scope = |
| 8098 ContextScope::Handle(Z, function.context_scope()); | 8076 ContextScope::Handle(Z, function.context_scope()); |
| 8099 ASSERT(!context_scope.IsNull()); | 8077 ASSERT(!context_scope.IsNull()); |
| (...skipping 3816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11916 // Make sure that the class instantiator is captured. | 11894 // Make sure that the class instantiator is captured. |
| 11917 CaptureInstantiator(); | 11895 CaptureInstantiator(); |
| 11918 } | 11896 } |
| 11919 type_parameter ^= CanonicalizeType(type_parameter); | 11897 type_parameter ^= CanonicalizeType(type_parameter); |
| 11920 } else { | 11898 } else { |
| 11921 ASSERT(type_parameter.IsFunctionTypeParameter()); | 11899 ASSERT(type_parameter.IsFunctionTypeParameter()); |
| 11922 if (!FLAG_generic_method_semantics) { | 11900 if (!FLAG_generic_method_semantics) { |
| 11923 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); | 11901 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); |
| 11924 return new (Z) TypeNode(primary_pos, type); | 11902 return new (Z) TypeNode(primary_pos, type); |
| 11925 } | 11903 } |
| 11926 if (type_parameter.parent_level() > 0) { | 11904 if (FunctionLevel() > 0) { |
| 11927 // Make sure that the function instantiators are captured. | 11905 // Make sure that the parent function type arguments are captured. |
| 11928 CaptureFunctionInstantiators(); | 11906 CaptureFunctionTypeArguments(); |
| 11929 } | 11907 } |
| 11930 } | 11908 } |
| 11931 ASSERT(type_parameter.IsFinalized()); | 11909 ASSERT(type_parameter.IsFinalized()); |
| 11932 ASSERT(!type_parameter.IsMalformed()); | 11910 ASSERT(!type_parameter.IsMalformed()); |
| 11933 return new (Z) TypeNode(primary_pos, type_parameter); | 11911 return new (Z) TypeNode(primary_pos, type_parameter); |
| 11934 } | 11912 } |
| 11935 | 11913 |
| 11936 | 11914 |
| 11937 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) { | 11915 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) { |
| 11938 AstNode* left = primary; | 11916 AstNode* left = primary; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12422 // malformed if type arguments have previously been parsed. | 12400 // malformed if type arguments have previously been parsed. |
| 12423 if (type->arguments() != TypeArguments::null()) { | 12401 if (type->arguments() != TypeArguments::null()) { |
| 12424 *type = ClassFinalizer::NewFinalizedMalformedType( | 12402 *type = ClassFinalizer::NewFinalizedMalformedType( |
| 12425 Error::Handle(Z), // No previous error. | 12403 Error::Handle(Z), // No previous error. |
| 12426 script_, type_parameter.token_pos(), | 12404 script_, type_parameter.token_pos(), |
| 12427 "type parameter '%s' cannot be parameterized", | 12405 "type parameter '%s' cannot be parameterized", |
| 12428 String::Handle(Z, type_parameter.name()).ToCString()); | 12406 String::Handle(Z, type_parameter.name()).ToCString()); |
| 12429 return; | 12407 return; |
| 12430 } | 12408 } |
| 12431 if (FLAG_generic_method_semantics) { | 12409 if (FLAG_generic_method_semantics) { |
| 12432 ASSERT(type_parameter.IsFinalized()); | |
| 12433 ASSERT(!type_parameter.IsMalformed()); | 12410 ASSERT(!type_parameter.IsMalformed()); |
| 12434 *type = type_parameter.raw(); | 12411 *type = type_parameter.raw(); |
| 12435 } else { | 12412 } else { |
| 12436 *type = Type::DynamicType(); | 12413 *type = Type::DynamicType(); |
| 12437 } | 12414 } |
| 12438 return; | 12415 return; |
| 12439 } | 12416 } |
| 12440 } | 12417 } |
| 12441 // Then check if the type is a class type parameter. | 12418 // Then check if the type is a class type parameter. |
| 12442 const TypeParameter& type_parameter = TypeParameter::Handle( | 12419 const TypeParameter& type_parameter = TypeParameter::Handle( |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12560 bool Parser::IsInstantiatorRequired() const { | 12537 bool Parser::IsInstantiatorRequired() const { |
| 12561 ASSERT(!current_function().IsNull()); | 12538 ASSERT(!current_function().IsNull()); |
| 12562 if (current_function().is_static() && | 12539 if (current_function().is_static() && |
| 12563 !current_function().IsInFactoryScope()) { | 12540 !current_function().IsInFactoryScope()) { |
| 12564 return false; | 12541 return false; |
| 12565 } | 12542 } |
| 12566 return current_class().IsGeneric(); | 12543 return current_class().IsGeneric(); |
| 12567 } | 12544 } |
| 12568 | 12545 |
| 12569 | 12546 |
| 12570 bool Parser::AreFunctionInstantiatorsRequired() const { | |
| 12571 ASSERT(!innermost_function().IsNull()); | |
| 12572 Function& parent = Function::Handle(innermost_function().parent_function()); | |
| 12573 while (!parent.IsNull()) { | |
| 12574 if (parent.IsGeneric()) { | |
| 12575 return true; | |
| 12576 } | |
| 12577 parent = parent.parent_function(); | |
| 12578 } | |
| 12579 return false; | |
| 12580 } | |
| 12581 | |
| 12582 | |
| 12583 bool Parser::InGenericFunctionScope() const { | 12547 bool Parser::InGenericFunctionScope() const { |
| 12584 if (!innermost_function().IsNull()) { | 12548 if (!innermost_function().IsNull()) { |
| 12585 // With one more free tag bit in Function, we could cache this information. | 12549 // With one more free tag bit in Function, we could cache this information. |
| 12586 if (innermost_function().IsGeneric() || | 12550 if (innermost_function().IsGeneric() || |
| 12587 innermost_function().HasGenericParent()) { | 12551 innermost_function().HasGenericParent()) { |
| 12588 return true; | 12552 return true; |
| 12589 } | 12553 } |
| 12590 } | 12554 } |
| 12591 return false; | 12555 return false; |
| 12592 } | 12556 } |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13743 // Factory call at runtime. | 13707 // Factory call at runtime. |
| 13744 const Class& factory_class = | 13708 const Class& factory_class = |
| 13745 Class::Handle(Z, Library::LookupCoreClass(Symbols::Map())); | 13709 Class::Handle(Z, Library::LookupCoreClass(Symbols::Map())); |
| 13746 ASSERT(!factory_class.IsNull()); | 13710 ASSERT(!factory_class.IsNull()); |
| 13747 const Function& factory_method = Function::ZoneHandle( | 13711 const Function& factory_method = Function::ZoneHandle( |
| 13748 Z, factory_class.LookupFactory( | 13712 Z, factory_class.LookupFactory( |
| 13749 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); | 13713 Library::PrivateCoreLibName(Symbols::MapLiteralFactory()))); |
| 13750 ASSERT(!factory_method.IsNull()); | 13714 ASSERT(!factory_method.IsNull()); |
| 13751 if (!map_type_arguments.IsNull() && !map_type_arguments.IsInstantiated() && | 13715 if (!map_type_arguments.IsNull() && !map_type_arguments.IsInstantiated() && |
| 13752 (FunctionLevel() > 0)) { | 13716 (FunctionLevel() > 0)) { |
| 13753 // Make sure that the instantiator is captured. | 13717 // Make sure that the instantiators are captured. |
| 13754 CaptureAllInstantiators(); | 13718 CaptureAllInstantiators(); |
| 13755 } | 13719 } |
| 13756 TypeArguments& factory_type_args = | 13720 TypeArguments& factory_type_args = |
| 13757 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); | 13721 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); |
| 13758 // If the factory class extends other parameterized classes, adjust the | 13722 // If the factory class extends other parameterized classes, adjust the |
| 13759 // type argument vector. | 13723 // type argument vector. |
| 13760 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { | 13724 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { |
| 13761 ASSERT(factory_type_args.Length() == 2); | 13725 ASSERT(factory_type_args.Length() == 2); |
| 13762 Type& factory_type = Type::Handle( | 13726 Type& factory_type = Type::Handle( |
| 13763 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); | 13727 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15199 const ArgumentListNode& function_args, | 15163 const ArgumentListNode& function_args, |
| 15200 const LocalVariable* temp_for_last_arg, | 15164 const LocalVariable* temp_for_last_arg, |
| 15201 bool is_super_invocation) { | 15165 bool is_super_invocation) { |
| 15202 UNREACHABLE(); | 15166 UNREACHABLE(); |
| 15203 return NULL; | 15167 return NULL; |
| 15204 } | 15168 } |
| 15205 | 15169 |
| 15206 } // namespace dart | 15170 } // namespace dart |
| 15207 | 15171 |
| 15208 #endif // DART_PRECOMPILED_RUNTIME | 15172 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |