| 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 abstract class TreeElements { | 5 abstract class TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 DartType getType(Node node); | 8 DartType getType(Node node); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 // the error message below. | 341 // the error message below. |
| 342 error(node, | 342 error(node, |
| 343 MessageKind.CANNOT_FIND_CONSTRUCTOR2, | 343 MessageKind.CANNOT_FIND_CONSTRUCTOR2, |
| 344 [selector.name, defaultClass.name]); | 344 [selector.name, defaultClass.name]); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 TreeElements resolveField(VariableElement element) { | 348 TreeElements resolveField(VariableElement element) { |
| 349 Node tree = element.parseNode(compiler); | 349 Node tree = element.parseNode(compiler); |
| 350 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { | 350 if(element.modifiers.isStatic() && element.variables.isTopLevel()) { |
| 351 error(element.modifiers.getStatic(), MessageKind.TOP_LEVEL_VARIABLE_DECLAR
ED_STATIC); | 351 error(element.modifiers.getStatic(), |
| 352 MessageKind.TOP_LEVEL_VARIABLE_DECLARED_STATIC); |
| 352 } | 353 } |
| 353 ResolverVisitor visitor = new ResolverVisitor(compiler, element); | 354 ResolverVisitor visitor = new ResolverVisitor(compiler, element); |
| 354 initializerDo(tree, visitor.visit); | 355 initializerDo(tree, visitor.visit); |
| 355 return visitor.mapping; | 356 return visitor.mapping; |
| 356 } | 357 } |
| 357 | 358 |
| 358 TreeElements resolveParameter(Element element) { | 359 TreeElements resolveParameter(Element element) { |
| 359 Node tree = element.parseNode(compiler); | 360 Node tree = element.parseNode(compiler); |
| 360 ResolverVisitor visitor = | 361 ResolverVisitor visitor = |
| 361 new ResolverVisitor(compiler, element.enclosingElement); | 362 new ResolverVisitor(compiler, element.enclosingElement); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 } | 1079 } |
| 1079 } else { | 1080 } else { |
| 1080 return scope.lookup(typeName.source); | 1081 return scope.lookup(typeName.source); |
| 1081 } | 1082 } |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean | 1085 // TODO(johnniwinther): Change [onFailure] and [whenResolved] to use boolean |
| 1085 // flags instead of closures. | 1086 // flags instead of closures. |
| 1086 // TODO(johnniwinther): Should never return [null] but instead an erroneous | 1087 // TODO(johnniwinther): Should never return [null] but instead an erroneous |
| 1087 // type. | 1088 // type. |
| 1088 DartType resolveTypeAnnotation(TypeAnnotation node, | 1089 DartType resolveTypeAnnotation( |
| 1089 {Scope inScope, ClassElement inClass, | 1090 TypeAnnotation node, |
| 1090 onFailure(Node, MessageKind, [List arguments]), | 1091 Scope scope, |
| 1091 whenResolved(Node, Type)}) { | 1092 {onFailure(Node node, MessageKind kind, [List arguments]), |
| 1093 whenResolved(Node node, DartType type)}) { |
| 1092 if (onFailure == null) { | 1094 if (onFailure == null) { |
| 1093 onFailure = (n, k, [arguments]) {}; | 1095 onFailure = (n, k, [arguments]) {}; |
| 1094 } | 1096 } |
| 1095 if (whenResolved == null) { | 1097 if (whenResolved == null) { |
| 1096 whenResolved = (n, t) {}; | 1098 whenResolved = (n, t) {}; |
| 1097 } | 1099 } |
| 1098 if (inClass != null) { | 1100 if (scope == null) { |
| 1099 inScope = inClass.buildScope(); | |
| 1100 } | |
| 1101 if (inScope == null) { | |
| 1102 compiler.internalError('resolveTypeAnnotation: no scope specified'); | 1101 compiler.internalError('resolveTypeAnnotation: no scope specified'); |
| 1103 } | 1102 } |
| 1104 return resolveTypeAnnotationInContext(inScope, node, onFailure, | 1103 return resolveTypeAnnotationInContext(scope, node, onFailure, |
| 1105 whenResolved); | 1104 whenResolved); |
| 1106 } | 1105 } |
| 1107 | 1106 |
| 1108 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, | 1107 DartType resolveTypeAnnotationInContext(Scope scope, TypeAnnotation node, |
| 1109 onFailure, whenResolved) { | 1108 onFailure, whenResolved) { |
| 1110 Element element = resolveTypeName(scope, node); | 1109 Element element = resolveTypeName(scope, node); |
| 1111 DartType type; | 1110 DartType type; |
| 1112 if (element == null) { | 1111 if (element == null) { |
| 1113 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); | 1112 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); |
| 1114 } else if (element.isErroneous()) { | 1113 } else if (element.isErroneous()) { |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 argument.element.enclosingElement); | 1952 argument.element.enclosingElement); |
| 1954 } else if (argument is InterfaceType) { | 1953 } else if (argument is InterfaceType) { |
| 1955 InterfaceType type = argument; | 1954 InterfaceType type = argument; |
| 1956 type.arguments.forEach((DartType argument) { | 1955 type.arguments.forEach((DartType argument) { |
| 1957 analyzeTypeArgument(type, argument); | 1956 analyzeTypeArgument(type, argument); |
| 1958 }); | 1957 }); |
| 1959 } | 1958 } |
| 1960 } | 1959 } |
| 1961 | 1960 |
| 1962 DartType resolveTypeAnnotation(TypeAnnotation node) { | 1961 DartType resolveTypeAnnotation(TypeAnnotation node) { |
| 1962 // TODO(johnniwinther): Remove this together with the named arguments |
| 1963 // on [TypeResolver.resolveTypeAnnotation]. |
| 1964 void checkAndUseType(TypeAnnotation annotation, DartType type) { |
| 1965 useType(annotation, type); |
| 1966 if (type != null && |
| 1967 identical(type.kind, TypeKind.TYPE_VARIABLE) && |
| 1968 enclosingElement.isInStaticMember()) { |
| 1969 warning(annotation, MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, |
| 1970 [type]); |
| 1971 } |
| 1972 } |
| 1973 |
| 1963 Function report = typeRequired ? error : warning; | 1974 Function report = typeRequired ? error : warning; |
| 1964 DartType type = typeResolver.resolveTypeAnnotation(node, inScope: scope, | 1975 DartType type = typeResolver.resolveTypeAnnotation( |
| 1965 onFailure: report, | 1976 node, scope, onFailure: report, whenResolved: checkAndUseType); |
| 1966 whenResolved: useType); | |
| 1967 if (type == null) return null; | 1977 if (type == null) return null; |
| 1968 if (inCheckContext) { | 1978 if (inCheckContext) { |
| 1969 compiler.enqueuer.resolution.registerIsCheck(type); | 1979 compiler.enqueuer.resolution.registerIsCheck(type); |
| 1970 } | 1980 } |
| 1971 if (typeRequired || inCheckContext) { | 1981 if (typeRequired || inCheckContext) { |
| 1972 if (type is InterfaceType) { | 1982 if (type is InterfaceType) { |
| 1973 InterfaceType itf = type; | 1983 InterfaceType itf = type; |
| 1974 itf.arguments.forEach((DartType argument) { | 1984 itf.arguments.forEach((DartType argument) { |
| 1975 analyzeTypeArgument(type, argument); | 1985 analyzeTypeArgument(type, argument); |
| 1976 }); | 1986 }); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2311 SourceString typeName = typeVariable.name; | 2321 SourceString typeName = typeVariable.name; |
| 2312 TypeVariable typeNode = nodeLink.head; | 2322 TypeVariable typeNode = nodeLink.head; |
| 2313 if (nameSet.contains(typeName)) { | 2323 if (nameSet.contains(typeName)) { |
| 2314 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); | 2324 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); |
| 2315 } | 2325 } |
| 2316 nameSet.add(typeName); | 2326 nameSet.add(typeName); |
| 2317 | 2327 |
| 2318 TypeVariableElement variableElement = typeVariable.element; | 2328 TypeVariableElement variableElement = typeVariable.element; |
| 2319 if (typeNode.bound != null) { | 2329 if (typeNode.bound != null) { |
| 2320 DartType boundType = typeResolver.resolveTypeAnnotation( | 2330 DartType boundType = typeResolver.resolveTypeAnnotation( |
| 2321 typeNode.bound, inScope: scope, onFailure: warning); | 2331 typeNode.bound, scope, onFailure: warning); |
| 2322 if (boundType != null && boundType.element == variableElement) { | 2332 if (boundType != null && boundType.element == variableElement) { |
| 2323 // TODO(johnniwinther): Check for more general cycles, like | 2333 // TODO(johnniwinther): Check for more general cycles, like |
| 2324 // [: <A extends B, B extends C, C extends B> :]. | 2334 // [: <A extends B, B extends C, C extends B> :]. |
| 2325 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, | 2335 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, |
| 2326 [variableElement.name]); | 2336 [variableElement.name]); |
| 2327 } else if (boundType != null) { | 2337 } else if (boundType != null) { |
| 2328 variableElement.bound = boundType; | 2338 variableElement.bound = boundType; |
| 2329 } else { | 2339 } else { |
| 2330 // TODO(johnniwinther): Should be an erroneous type. | 2340 // TODO(johnniwinther): Should be an erroneous type. |
| 2331 variableElement.bound = compiler.objectClass.computeType(compiler); | 2341 variableElement.bound = compiler.objectClass.computeType(compiler); |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2964 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 2974 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 2965 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { | 2975 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { |
| 2966 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); | 2976 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); |
| 2967 } else if (!identical(e.kind, ElementKind.CLASS) | 2977 } else if (!identical(e.kind, ElementKind.CLASS) |
| 2968 && !identical(e.kind, ElementKind.PREFIX)) { | 2978 && !identical(e.kind, ElementKind.PREFIX)) { |
| 2969 error(node, MessageKind.NOT_A_TYPE, [name]); | 2979 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 2970 } | 2980 } |
| 2971 return e; | 2981 return e; |
| 2972 } | 2982 } |
| 2973 } | 2983 } |
| OLD | NEW |