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