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 '../task/strong/info.dart' show InferredType, StaticInfo; | 9 import '../task/strong/info.dart' show InferredType, StaticInfo; |
10 import '../task/strong/rules.dart' show TypeRules; | 10 import '../task/strong/rules.dart' show TypeRules; |
(...skipping 14941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14952 } | 14952 } |
14953 } | 14953 } |
14954 _setElement(typeName, _dynamicType.element); | 14954 _setElement(typeName, _dynamicType.element); |
14955 typeName.staticType = _dynamicType; | 14955 typeName.staticType = _dynamicType; |
14956 node.type = _dynamicType; | 14956 node.type = _dynamicType; |
14957 return null; | 14957 return null; |
14958 } | 14958 } |
14959 if (argumentList != null) { | 14959 if (argumentList != null) { |
14960 NodeList<TypeName> arguments = argumentList.arguments; | 14960 NodeList<TypeName> arguments = argumentList.arguments; |
14961 int argumentCount = arguments.length; | 14961 int argumentCount = arguments.length; |
14962 List<DartType> parameters = _getTypeArguments(type); | 14962 List<DartType> parameters = _getTypeParameters(type); |
14963 int parameterCount = parameters.length; | 14963 int parameterCount = parameters.length; |
14964 List<DartType> typeArguments = new List<DartType>(parameterCount); | 14964 List<DartType> typeArguments = new List<DartType>(parameterCount); |
14965 if (argumentCount == parameterCount) { | 14965 if (argumentCount == parameterCount) { |
14966 for (int i = 0; i < parameterCount; i++) { | 14966 for (int i = 0; i < parameterCount; i++) { |
14967 TypeName argumentTypeName = arguments[i]; | 14967 TypeName argumentTypeName = arguments[i]; |
14968 DartType argumentType = _getType(argumentTypeName); | 14968 DartType argumentType = _getType(argumentTypeName); |
14969 if (argumentType == null) { | 14969 if (argumentType == null) { |
14970 argumentType = _dynamicType; | 14970 argumentType = _dynamicType; |
14971 } | 14971 } |
14972 typeArguments[i] = argumentType; | 14972 typeArguments[i] = argumentType; |
14973 } | 14973 } |
14974 } else { | 14974 } else { |
14975 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, | 14975 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, |
14976 [typeName.name, parameterCount, argumentCount]); | 14976 [typeName.name, parameterCount, argumentCount]); |
14977 for (int i = 0; i < parameterCount; i++) { | 14977 for (int i = 0; i < parameterCount; i++) { |
14978 typeArguments[i] = _dynamicType; | 14978 typeArguments[i] = _dynamicType; |
14979 } | 14979 } |
14980 } | 14980 } |
14981 if (type is InterfaceTypeImpl) { | 14981 type = _instantiateType(type, typeArguments); |
14982 InterfaceTypeImpl interfaceType = type as InterfaceTypeImpl; | |
14983 type = interfaceType.substitute4(typeArguments); | |
14984 } else if (type is FunctionTypeImpl) { | |
14985 FunctionTypeImpl functionType = type as FunctionTypeImpl; | |
14986 type = functionType.substitute3(typeArguments); | |
14987 } else { | |
14988 // TODO(brianwilkerson) Report this internal error. | |
14989 } | |
14990 } else { | 14982 } else { |
14991 // | 14983 // |
14992 // Check for the case where there are no type arguments given for a | 14984 // Check for the case where there are no type arguments given for a |
14993 // parameterized type. | 14985 // parameterized type. |
14994 // | 14986 // |
14995 List<DartType> parameters = _getTypeArguments(type); | 14987 List<DartType> parameters = _getTypeParameters(type); |
14996 int parameterCount = parameters.length; | 14988 int parameterCount = parameters.length; |
14997 if (parameterCount > 0) { | 14989 if (parameterCount > 0) { |
14998 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; | 14990 DynamicTypeImpl dynamicType = DynamicTypeImpl.instance; |
14999 List<DartType> arguments = new List<DartType>(parameterCount); | 14991 List<DartType> arguments = new List<DartType>(parameterCount); |
15000 for (int i = 0; i < parameterCount; i++) { | 14992 for (int i = 0; i < parameterCount; i++) { |
15001 arguments[i] = dynamicType; | 14993 arguments[i] = dynamicType; |
15002 } | 14994 } |
15003 type = type.substitute2(arguments, parameters); | 14995 type = _instantiateType(type, arguments); |
15004 } | 14996 } |
15005 } | 14997 } |
15006 typeName.staticType = type; | 14998 typeName.staticType = type; |
15007 node.type = type; | 14999 node.type = type; |
15008 return null; | 15000 return null; |
15009 } | 15001 } |
15010 | 15002 |
15011 @override | 15003 @override |
15012 Object visitTypeParameter(TypeParameter node) { | 15004 Object visitTypeParameter(TypeParameter node) { |
15013 super.visitTypeParameter(node); | 15005 super.visitTypeParameter(node); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15178 } | 15170 } |
15179 return type; | 15171 return type; |
15180 } | 15172 } |
15181 | 15173 |
15182 /** | 15174 /** |
15183 * Return the type arguments associated with the given type. | 15175 * Return the type arguments associated with the given type. |
15184 * | 15176 * |
15185 * @param type the type whole type arguments are to be returned | 15177 * @param type the type whole type arguments are to be returned |
15186 * @return the type arguments associated with the given type | 15178 * @return the type arguments associated with the given type |
15187 */ | 15179 */ |
15188 List<DartType> _getTypeArguments(DartType type) { | 15180 List<DartType> _getTypeParameters(DartType type) { |
15189 if (type is InterfaceType) { | 15181 if (type is InterfaceType) { |
15190 return type.typeArguments; | 15182 return type.typeArguments; |
15191 } else if (type is FunctionType) { | 15183 } else if (type is FunctionType) { |
15192 return type.typeArguments; | 15184 return TypeParameterTypeImpl.getTypes(type.boundTypeParameters); |
15193 } | 15185 } |
15194 return DartType.EMPTY_LIST; | 15186 return DartType.EMPTY_LIST; |
15195 } | 15187 } |
15196 | 15188 |
15197 /** | 15189 /** |
15198 * Returns the simple identifier of the given (may be qualified) type name. | 15190 * Returns the simple identifier of the given (may be qualified) type name. |
15199 * | 15191 * |
15200 * @param typeName the (may be qualified) qualified type name | 15192 * @param typeName the (may be qualified) qualified type name |
15201 * @return the simple identifier of the given (may be qualified) type name. | 15193 * @return the simple identifier of the given (may be qualified) type name. |
15202 */ | 15194 */ |
(...skipping 18 matching lines...) Expand all Loading... |
15221 if (element is ClassElement) { | 15213 if (element is ClassElement) { |
15222 if (type != null) { | 15214 if (type != null) { |
15223 return null; | 15215 return null; |
15224 } | 15216 } |
15225 type = element.type; | 15217 type = element.type; |
15226 } | 15218 } |
15227 } | 15219 } |
15228 return type; | 15220 return type; |
15229 } | 15221 } |
15230 | 15222 |
| 15223 DartType _instantiateType(DartType type, List<DartType> typeArguments) { |
| 15224 if (type is InterfaceTypeImpl) { |
| 15225 return type.substitute4(typeArguments); |
| 15226 } else if (type is FunctionTypeImpl) { |
| 15227 return type.instantiate(typeArguments); |
| 15228 } else { |
| 15229 // TODO(brianwilkerson) Report this internal error. |
| 15230 return type; |
| 15231 } |
| 15232 } |
| 15233 |
15231 /** | 15234 /** |
15232 * Checks if the given type name is used as the type in an as expression. | 15235 * Checks if the given type name is used as the type in an as expression. |
15233 * | 15236 * |
15234 * @param typeName the type name to analyzer | 15237 * @param typeName the type name to analyzer |
15235 * @return `true` if the given type name is used as the type in an as expressi
on | 15238 * @return `true` if the given type name is used as the type in an as expressi
on |
15236 */ | 15239 */ |
15237 bool _isTypeNameInAsExpression(TypeName typeName) { | 15240 bool _isTypeNameInAsExpression(TypeName typeName) { |
15238 AstNode parent = typeName.parent; | 15241 AstNode parent = typeName.parent; |
15239 if (parent is AsExpression) { | 15242 if (parent is AsExpression) { |
15240 AsExpression asExpression = parent; | 15243 AsExpression asExpression = parent; |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16069 nonFields.add(node); | 16072 nonFields.add(node); |
16070 return null; | 16073 return null; |
16071 } | 16074 } |
16072 | 16075 |
16073 @override | 16076 @override |
16074 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 16077 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
16075 | 16078 |
16076 @override | 16079 @override |
16077 Object visitWithClause(WithClause node) => null; | 16080 Object visitWithClause(WithClause node) => null; |
16078 } | 16081 } |
OLD | NEW |