| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 14434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14445 } | 14445 } |
| 14446 } | 14446 } |
| 14447 _setElement(typeName, _dynamicType.element); | 14447 _setElement(typeName, _dynamicType.element); |
| 14448 typeName.staticType = _dynamicType; | 14448 typeName.staticType = _dynamicType; |
| 14449 node.type = _dynamicType; | 14449 node.type = _dynamicType; |
| 14450 return null; | 14450 return null; |
| 14451 } | 14451 } |
| 14452 if (argumentList != null) { | 14452 if (argumentList != null) { |
| 14453 NodeList<TypeName> arguments = argumentList.arguments; | 14453 NodeList<TypeName> arguments = argumentList.arguments; |
| 14454 int argumentCount = arguments.length; | 14454 int argumentCount = arguments.length; |
| 14455 List<DartType> parameters = _getTypeArguments(type); | 14455 List<DartType> parameters = _getTypeParameters(type); |
| 14456 int parameterCount = parameters.length; | 14456 int parameterCount = parameters.length; |
| 14457 List<DartType> typeArguments = new List<DartType>(parameterCount); | 14457 List<DartType> typeArguments = new List<DartType>(parameterCount); |
| 14458 if (argumentCount == parameterCount) { | 14458 if (argumentCount == parameterCount) { |
| 14459 for (int i = 0; i < parameterCount; i++) { | 14459 for (int i = 0; i < parameterCount; i++) { |
| 14460 TypeName argumentTypeName = arguments[i]; | 14460 TypeName argumentTypeName = arguments[i]; |
| 14461 DartType argumentType = _getType(argumentTypeName); | 14461 DartType argumentType = _getType(argumentTypeName); |
| 14462 if (argumentType == null) { | 14462 if (argumentType == null) { |
| 14463 argumentType = _dynamicType; | 14463 argumentType = _dynamicType; |
| 14464 } | 14464 } |
| 14465 typeArguments[i] = argumentType; | 14465 typeArguments[i] = argumentType; |
| 14466 } | 14466 } |
| 14467 } else { | 14467 } else { |
| 14468 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, | 14468 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, |
| 14469 [typeName.name, parameterCount, argumentCount]); | 14469 [typeName.name, parameterCount, argumentCount]); |
| 14470 for (int i = 0; i < parameterCount; i++) { | 14470 for (int i = 0; i < parameterCount; i++) { |
| 14471 typeArguments[i] = _dynamicType; | 14471 typeArguments[i] = _dynamicType; |
| 14472 } | 14472 } |
| 14473 } | 14473 } |
| 14474 if (type is InterfaceTypeImpl) { | 14474 type = _instantiateType(type, typeArguments); |
| 14475 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; | |
| 14476 type = interfaceType.substitute4(typeArguments); | |
| 14477 } else if (type is FunctionTypeImpl) { | |
| 14478 FunctionTypeImpl functionType = type as FunctionTypeImpl; | |
| 14479 type = functionType.substitute3(typeArguments); | |
| 14480 } else { | |
| 14481 // TODO(brianwilkerson) Report this internal error. | |
| 14482 } | |
| 14483 } else { | 14475 } else { |
| 14484 // | 14476 // |
| 14485 // Check for the case where there are no type arguments given for a | 14477 // Check for the case where there are no type arguments given for a |
| 14486 // parameterized type. | 14478 // parameterized type. |
| 14487 // | 14479 // |
| 14488 List<DartType> parameters = _getTypeArguments(type); | 14480 List<DartType> parameters = _getTypeParameters(type); |
| 14489 int parameterCount = parameters.length; | 14481 int parameterCount = parameters.length; |
| 14490 if (parameterCount > 0) { | 14482 if (parameterCount > 0) { |
| 14491 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; | 14483 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; |
| 14492 List<DartType> arguments = new List<DartType>(parameterCount); | 14484 List<DartType> arguments = new List<DartType>(parameterCount); |
| 14493 for (int i = 0; i < parameterCount; i++) { | 14485 for (int i = 0; i < parameterCount; i++) { |
| 14494 arguments[i] = dynamicType; | 14486 arguments[i] = dynamicType; |
| 14495 } | 14487 } |
| 14496 type = type.substitute2(arguments, parameters); | 14488 type = _instantiateType(type, arguments); |
| 14497 } | 14489 } |
| 14498 } | 14490 } |
| 14499 typeName.staticType = type; | 14491 typeName.staticType = type; |
| 14500 node.type = type; | 14492 node.type = type; |
| 14501 return null; | 14493 return null; |
| 14502 } | 14494 } |
| 14503 | 14495 |
| 14504 @override | 14496 @override |
| 14505 Object visitTypeParameter(TypeParameter node) { | 14497 Object visitTypeParameter(TypeParameter node) { |
| 14506 super.visitTypeParameter(node); | 14498 super.visitTypeParameter(node); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14671 } | 14663 } |
| 14672 return type; | 14664 return type; |
| 14673 } | 14665 } |
| 14674 | 14666 |
| 14675 /** | 14667 /** |
| 14676 * Return the type arguments associated with the given type. | 14668 * Return the type arguments associated with the given type. |
| 14677 * | 14669 * |
| 14678 * @param type the type whole type arguments are to be returned | 14670 * @param type the type whole type arguments are to be returned |
| 14679 * @return the type arguments associated with the given type | 14671 * @return the type arguments associated with the given type |
| 14680 */ | 14672 */ |
| 14681 List<DartType> _getTypeArguments(DartType type) { | 14673 List<DartType> _getTypeParameters(DartType type) { |
| 14682 if (type is InterfaceType) { | 14674 if (type is InterfaceType) { |
| 14683 return type.typeArguments; | 14675 return type.typeArguments; |
| 14684 } else if (type is FunctionType) { | 14676 } else if (type is FunctionType) { |
| 14685 return type.typeArguments; | 14677 return TypeParameterTypeImpl.getTypes(type.boundTypeParameters); |
| 14686 } | 14678 } |
| 14687 return DartType.EMPTY_LIST; | 14679 return DartType.EMPTY_LIST; |
| 14688 } | 14680 } |
| 14689 | 14681 |
| 14690 /** | 14682 /** |
| 14691 * Returns the simple identifier of the given (may be qualified) type name. | 14683 * Returns the simple identifier of the given (may be qualified) type name. |
| 14692 * | 14684 * |
| 14693 * @param typeName the (may be qualified) qualified type name | 14685 * @param typeName the (may be qualified) qualified type name |
| 14694 * @return the simple identifier of the given (may be qualified) type name. | 14686 * @return the simple identifier of the given (may be qualified) type name. |
| 14695 */ | 14687 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 14714 if (element is ClassElement) { | 14706 if (element is ClassElement) { |
| 14715 if (type != null) { | 14707 if (type != null) { |
| 14716 return null; | 14708 return null; |
| 14717 } | 14709 } |
| 14718 type = element.type; | 14710 type = element.type; |
| 14719 } | 14711 } |
| 14720 } | 14712 } |
| 14721 return type; | 14713 return type; |
| 14722 } | 14714 } |
| 14723 | 14715 |
| 14716 DartType _instantiateType(DartType type, List<DartType> typeArguments) { |
| 14717 if (type is InterfaceTypeImpl) { |
| 14718 return type.substitute4(typeArguments); |
| 14719 } else if (type is FunctionTypeImpl) { |
| 14720 return type.instantiate(typeArguments); |
| 14721 } else { |
| 14722 // TODO(brianwilkerson) Report this internal error. |
| 14723 return type; |
| 14724 } |
| 14725 } |
| 14726 |
| 14724 /** | 14727 /** |
| 14725 * Checks if the given type name is used as the type in an as expression. | 14728 * Checks if the given type name is used as the type in an as expression. |
| 14726 * | 14729 * |
| 14727 * @param typeName the type name to analyzer | 14730 * @param typeName the type name to analyzer |
| 14728 * @return `true` if the given type name is used as the type in an as expressi
on | 14731 * @return `true` if the given type name is used as the type in an as expressi
on |
| 14729 */ | 14732 */ |
| 14730 bool _isTypeNameInAsExpression(TypeName typeName) { | 14733 bool _isTypeNameInAsExpression(TypeName typeName) { |
| 14731 AstNode parent = typeName.parent; | 14734 AstNode parent = typeName.parent; |
| 14732 if (parent is AsExpression) { | 14735 if (parent is AsExpression) { |
| 14733 AsExpression asExpression = parent; | 14736 AsExpression asExpression = parent; |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15562 nonFields.add(node); | 15565 nonFields.add(node); |
| 15563 return null; | 15566 return null; |
| 15564 } | 15567 } |
| 15565 | 15568 |
| 15566 @override | 15569 @override |
| 15567 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15570 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15568 | 15571 |
| 15569 @override | 15572 @override |
| 15570 Object visitWithClause(WithClause node) => null; | 15573 Object visitWithClause(WithClause node) => null; |
| 15571 } | 15574 } |
| OLD | NEW |