| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element operator[](Node node); | 8 Element operator[](Node node); |
| 9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
| 10 DartType getType(Node node); | 10 DartType getType(Node node); |
| (...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 if (cls.typeVariables.isEmpty && arguments.isEmpty) { | 1135 if (cls.typeVariables.isEmpty && arguments.isEmpty) { |
| 1136 // Use the canonical type if it has no type parameters. | 1136 // Use the canonical type if it has no type parameters. |
| 1137 type = cls.computeType(compiler); | 1137 type = cls.computeType(compiler); |
| 1138 } else { | 1138 } else { |
| 1139 // In checked mode malformed-ness of the type argument bubbles up. | 1139 // In checked mode malformed-ness of the type argument bubbles up. |
| 1140 if (anyMalformedTypesInThere(arguments) && | 1140 if (anyMalformedTypesInThere(arguments) && |
| 1141 compiler.enableTypeAssertions) { | 1141 compiler.enableTypeAssertions) { |
| 1142 type = new MalformedType( | 1142 type = new MalformedType( |
| 1143 new MalformedTypeElement(node, element)); | 1143 new MalformedTypeElement(node, element)); |
| 1144 } else { | 1144 } else { |
| 1145 if (arguments.isEmpty) { | 1145 type = new InterfaceType(cls.declaration, arguments); |
| 1146 // Use the canonical raw type if the class is generic. | |
| 1147 type = cls.rawType; | |
| 1148 } else { | |
| 1149 type = new InterfaceType(cls.declaration, arguments); | |
| 1150 } | |
| 1151 } | 1146 } |
| 1152 } | 1147 } |
| 1153 } else if (element.isTypedef()) { | 1148 } else if (element.isTypedef()) { |
| 1154 TypedefElement typdef = element; | 1149 TypedefElement typdef = element; |
| 1155 // TODO(ahe): Should be [ensureResolved]. | 1150 // TODO(ahe): Should be [ensureResolved]. |
| 1156 compiler.resolveTypedef(typdef); | 1151 compiler.resolveTypedef(typdef); |
| 1152 typdef.computeType(compiler); |
| 1157 Link<DartType> arguments = resolveTypeArguments( | 1153 Link<DartType> arguments = resolveTypeArguments( |
| 1158 node, typdef.typeVariables, inStaticContext, | 1154 node, typdef.typeVariables, inStaticContext, |
| 1159 scope, onFailure, whenResolved); | 1155 scope, onFailure, whenResolved); |
| 1160 if (typdef.typeVariables.isEmpty && arguments.isEmpty) { | 1156 if (typdef.typeVariables.isEmpty && arguments.isEmpty) { |
| 1161 // Return the canonical type if it has no type parameters. | 1157 // Return the canonical type if it has no type parameters. |
| 1162 type = typdef.computeType(compiler); | 1158 type = typdef.computeType(compiler); |
| 1163 } else { | 1159 } else { |
| 1164 if (arguments.isEmpty) { | 1160 type = new TypedefType(typdef, arguments); |
| 1165 type = typdef.rawType; | |
| 1166 } else { | |
| 1167 type = new TypedefType(typdef, arguments); | |
| 1168 } | |
| 1169 } | 1161 } |
| 1170 } else if (element.isTypeVariable()) { | 1162 } else if (element.isTypeVariable()) { |
| 1171 if (inStaticContext) { | 1163 if (inStaticContext) { |
| 1172 compiler.reportWarning(node, | 1164 compiler.reportWarning(node, |
| 1173 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message( | 1165 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER.message( |
| 1174 [element])); | 1166 [element])); |
| 1175 type = new MalformedType(new MalformedTypeElement(node, element)); | 1167 type = new MalformedType(new MalformedTypeElement(node, element)); |
| 1176 } else { | 1168 } else { |
| 1177 type = element.computeType(compiler); | 1169 type = element.computeType(compiler); |
| 1178 } | 1170 } |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 if (node.isRedirectingFactoryBody) { | 1960 if (node.isRedirectingFactoryBody) { |
| 1969 handleRedirectingFactoryBody(node); | 1961 handleRedirectingFactoryBody(node); |
| 1970 } else { | 1962 } else { |
| 1971 visit(node.expression); | 1963 visit(node.expression); |
| 1972 } | 1964 } |
| 1973 } | 1965 } |
| 1974 | 1966 |
| 1975 void handleRedirectingFactoryBody(Return node) { | 1967 void handleRedirectingFactoryBody(Return node) { |
| 1976 Element redirectionTarget = resolveRedirectingFactory(node); | 1968 Element redirectionTarget = resolveRedirectingFactory(node); |
| 1977 var type = mapping.getType(node.expression); | 1969 var type = mapping.getType(node.expression); |
| 1978 if (type is InterfaceType && !type.isRaw) { | 1970 if (type is InterfaceType && !type.typeArguments.isEmpty) { |
| 1979 unimplemented(node.expression, 'type arguments on redirecting factory'); | 1971 unimplemented(node.expression, 'type arguments on redirecting factory'); |
| 1980 } | 1972 } |
| 1981 useElement(node.expression, redirectionTarget); | 1973 useElement(node.expression, redirectionTarget); |
| 1982 assert(invariant(node, enclosingElement.isFactoryConstructor())); | 1974 assert(invariant(node, enclosingElement.isFactoryConstructor())); |
| 1983 FunctionElement constructor = enclosingElement; | 1975 FunctionElement constructor = enclosingElement; |
| 1984 if (constructor.modifiers.isConst() && | 1976 if (constructor.modifiers.isConst() && |
| 1985 !redirectionTarget.modifiers.isConst()) { | 1977 !redirectionTarget.modifiers.isConst()) { |
| 1986 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 1978 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 1987 } | 1979 } |
| 1988 // TODO(ahe): Check that this doesn't lead to a cycle. For now, | 1980 // TODO(ahe): Check that this doesn't lead to a cycle. For now, |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2556 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); | 2548 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); |
| 2557 } | 2549 } |
| 2558 final objectElement = compiler.objectClass; | 2550 final objectElement = compiler.objectClass; |
| 2559 if (!identical(element, objectElement) && element.supertype == null) { | 2551 if (!identical(element, objectElement) && element.supertype == null) { |
| 2560 if (objectElement == null) { | 2552 if (objectElement == null) { |
| 2561 compiler.internalError("Internal error: cannot resolve Object", | 2553 compiler.internalError("Internal error: cannot resolve Object", |
| 2562 node: node); | 2554 node: node); |
| 2563 } else { | 2555 } else { |
| 2564 objectElement.ensureResolved(compiler); | 2556 objectElement.ensureResolved(compiler); |
| 2565 } | 2557 } |
| 2566 element.supertype = objectElement.computeType(compiler); | 2558 // TODO(ahe): This should be objectElement.computeType(...). |
| 2559 element.supertype = new InterfaceType(objectElement); |
| 2567 } | 2560 } |
| 2568 assert(element.interfaces == null); | 2561 assert(element.interfaces == null); |
| 2569 Link<DartType> interfaces = const Link<DartType>(); | 2562 Link<DartType> interfaces = const Link<DartType>(); |
| 2570 for (Link<Node> link = node.interfaces.nodes; | 2563 for (Link<Node> link = node.interfaces.nodes; |
| 2571 !link.isEmpty; | 2564 !link.isEmpty; |
| 2572 link = link.tail) { | 2565 link = link.tail) { |
| 2573 DartType interfaceType = visit(link.head); | 2566 DartType interfaceType = visit(link.head); |
| 2574 if (interfaceType != null && interfaceType.element.isExtendable()) { | 2567 if (interfaceType != null && interfaceType.element.isExtendable()) { |
| 2575 interfaces = interfaces.prepend(interfaceType); | 2568 interfaces = interfaces.prepend(interfaceType); |
| 2576 if (isBlackListed(interfaceType)) { | 2569 if (isBlackListed(interfaceType)) { |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3157 return e; | 3150 return e; |
| 3158 } | 3151 } |
| 3159 | 3152 |
| 3160 /// Assumed to be called by [resolveRedirectingFactory]. | 3153 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3161 Element visitReturn(Return node) { | 3154 Element visitReturn(Return node) { |
| 3162 Node expression = node.expression; | 3155 Node expression = node.expression; |
| 3163 return finishConstructorReference(visit(expression), | 3156 return finishConstructorReference(visit(expression), |
| 3164 expression, expression); | 3157 expression, expression); |
| 3165 } | 3158 } |
| 3166 } | 3159 } |
| OLD | NEW |