| 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; |
| 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 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 if (node.isRedirectingFactoryBody) { | 1962 if (node.isRedirectingFactoryBody) { |
| 1955 handleRedirectingFactoryBody(node); | 1963 handleRedirectingFactoryBody(node); |
| 1956 } else { | 1964 } else { |
| 1957 visit(node.expression); | 1965 visit(node.expression); |
| 1958 } | 1966 } |
| 1959 } | 1967 } |
| 1960 | 1968 |
| 1961 void handleRedirectingFactoryBody(Return node) { | 1969 void handleRedirectingFactoryBody(Return node) { |
| 1962 Element redirectionTarget = resolveRedirectingFactory(node); | 1970 Element redirectionTarget = resolveRedirectingFactory(node); |
| 1963 var type = mapping.getType(node.expression); | 1971 var type = mapping.getType(node.expression); |
| 1964 if (type is InterfaceType && !type.typeArguments.isEmpty) { | 1972 if (type is InterfaceType && !type.isRaw) { |
| 1965 unimplemented(node.expression, 'type arguments on redirecting factory'); | 1973 unimplemented(node.expression, 'type arguments on redirecting factory'); |
| 1966 } | 1974 } |
| 1967 useElement(node.expression, redirectionTarget); | 1975 useElement(node.expression, redirectionTarget); |
| 1968 assert(invariant(node, enclosingElement.isFactoryConstructor())); | 1976 assert(invariant(node, enclosingElement.isFactoryConstructor())); |
| 1969 FunctionElement constructor = enclosingElement; | 1977 FunctionElement constructor = enclosingElement; |
| 1970 if (constructor.modifiers.isConst() && | 1978 if (constructor.modifiers.isConst() && |
| 1971 !redirectionTarget.modifiers.isConst()) { | 1979 !redirectionTarget.modifiers.isConst()) { |
| 1972 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 1980 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 1973 } | 1981 } |
| 1974 // TODO(ahe): Check that this doesn't lead to a cycle. For now, | 1982 // 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... |
| 2542 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); | 2550 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); |
| 2543 } | 2551 } |
| 2544 final objectElement = compiler.objectClass; | 2552 final objectElement = compiler.objectClass; |
| 2545 if (!identical(element, objectElement) && element.supertype == null) { | 2553 if (!identical(element, objectElement) && element.supertype == null) { |
| 2546 if (objectElement == null) { | 2554 if (objectElement == null) { |
| 2547 compiler.internalError("Internal error: cannot resolve Object", | 2555 compiler.internalError("Internal error: cannot resolve Object", |
| 2548 node: node); | 2556 node: node); |
| 2549 } else { | 2557 } else { |
| 2550 objectElement.ensureResolved(compiler); | 2558 objectElement.ensureResolved(compiler); |
| 2551 } | 2559 } |
| 2552 // TODO(ahe): This should be objectElement.computeType(...). | 2560 element.supertype = objectElement.computeType(compiler); |
| 2553 element.supertype = new InterfaceType(objectElement); | |
| 2554 } | 2561 } |
| 2555 assert(element.interfaces == null); | 2562 assert(element.interfaces == null); |
| 2556 Link<DartType> interfaces = const Link<DartType>(); | 2563 Link<DartType> interfaces = const Link<DartType>(); |
| 2557 for (Link<Node> link = node.interfaces.nodes; | 2564 for (Link<Node> link = node.interfaces.nodes; |
| 2558 !link.isEmpty; | 2565 !link.isEmpty; |
| 2559 link = link.tail) { | 2566 link = link.tail) { |
| 2560 DartType interfaceType = visit(link.head); | 2567 DartType interfaceType = visit(link.head); |
| 2561 if (interfaceType != null && interfaceType.element.isExtendable()) { | 2568 if (interfaceType != null && interfaceType.element.isExtendable()) { |
| 2562 interfaces = interfaces.prepend(interfaceType); | 2569 interfaces = interfaces.prepend(interfaceType); |
| 2563 if (isBlackListed(interfaceType)) { | 2570 if (isBlackListed(interfaceType)) { |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3140 return e; | 3147 return e; |
| 3141 } | 3148 } |
| 3142 | 3149 |
| 3143 /// Assumed to be called by [resolveRedirectingFactory]. | 3150 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3144 Element visitReturn(Return node) { | 3151 Element visitReturn(Return node) { |
| 3145 Node expression = node.expression; | 3152 Node expression = node.expression; |
| 3146 return finishConstructorReference(visit(expression), | 3153 return finishConstructorReference(visit(expression), |
| 3147 expression, expression); | 3154 expression, expression); |
| 3148 } | 3155 } |
| 3149 } | 3156 } |
| OLD | NEW |