| 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 interface TreeElements { | 5 interface TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 typeArguments = typeArguments.tail) { | 1098 typeArguments = typeArguments.tail) { |
| 1099 if (++index > cls.typeParameters.length) { | 1099 if (++index > cls.typeParameters.length) { |
| 1100 report(typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); | 1100 report(typeArguments.head, MessageKind.ADDITIONAL_TYPE_ARGUMENT); |
| 1101 } | 1101 } |
| 1102 arguments.addLast(resolveTypeAnnotation(typeArguments.head)); | 1102 arguments.addLast(resolveTypeAnnotation(typeArguments.head)); |
| 1103 } | 1103 } |
| 1104 if (index < cls.typeParameters.length) { | 1104 if (index < cls.typeParameters.length) { |
| 1105 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); | 1105 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 1106 } | 1106 } |
| 1107 } | 1107 } |
| 1108 type = new InterfaceType(cls.name, cls, arguments.toLink()); | 1108 if (cls.typeParameters.length == 0) { |
| 1109 } else if (element.isTypedef()) { | 1109 // Return the canonical type if it has no type parameters. |
| 1110 // TODO(karlklose): implement typedefs. We return a fake type that the | 1110 type = element.computeType(compiler); |
| 1111 // code generator can use to detect typedefs in is-checks. | 1111 } else { |
| 1112 type = new InterfaceType(element.name, element); | 1112 type = new InterfaceType(cls, arguments.toLink()); |
| 1113 } |
| 1114 } else if (element.isTypedef() || element.isTypeVariable()) { |
| 1115 type = element.computeType(compiler); |
| 1113 } else { | 1116 } else { |
| 1114 type = element.computeType(compiler); | 1117 compiler.cancel("unexpected element kind ${element.kind}", |
| 1118 node: node); |
| 1115 } | 1119 } |
| 1116 } | 1120 } |
| 1117 return useType(node, type); | 1121 return useType(node, type); |
| 1118 } | 1122 } |
| 1119 | 1123 |
| 1120 visitModifiers(Modifiers node) { | 1124 visitModifiers(Modifiers node) { |
| 1121 // TODO(ngeoffray): Implement this. | 1125 // TODO(ngeoffray): Implement this. |
| 1122 unimplemented(node, 'modifiers'); | 1126 unimplemented(node, 'modifiers'); |
| 1123 } | 1127 } |
| 1124 | 1128 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 } else if (supertype !== null) { | 1401 } else if (supertype !== null) { |
| 1398 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); | 1402 error(node.superclass, MessageKind.TYPE_NAME_EXPECTED); |
| 1399 } | 1403 } |
| 1400 if (classElement.name != Types.OBJECT && classElement.supertype === null) { | 1404 if (classElement.name != Types.OBJECT && classElement.supertype === null) { |
| 1401 ClassElement objectElement = context.lookup(Types.OBJECT); | 1405 ClassElement objectElement = context.lookup(Types.OBJECT); |
| 1402 if (objectElement !== null && !objectElement.isResolved) { | 1406 if (objectElement !== null && !objectElement.isResolved) { |
| 1403 compiler.resolver.toResolve.add(objectElement); | 1407 compiler.resolver.toResolve.add(objectElement); |
| 1404 } else if (objectElement === null){ | 1408 } else if (objectElement === null){ |
| 1405 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); | 1409 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [Types.OBJECT]); |
| 1406 } | 1410 } |
| 1407 classElement.supertype = new InterfaceType(Types.OBJECT, objectElement); | 1411 classElement.supertype = new InterfaceType(objectElement); |
| 1408 } | 1412 } |
| 1409 if (node.defaultClause !== null) { | 1413 if (node.defaultClause !== null) { |
| 1410 classElement.defaultClass = visit(node.defaultClause); | 1414 classElement.defaultClass = visit(node.defaultClause); |
| 1411 } | 1415 } |
| 1412 for (Link<Node> link = node.interfaces.nodes; | 1416 for (Link<Node> link = node.interfaces.nodes; |
| 1413 !link.isEmpty(); | 1417 !link.isEmpty(); |
| 1414 link = link.tail) { | 1418 link = link.tail) { |
| 1415 Type interfaceType = visit(link.head); | 1419 Type interfaceType = visit(link.head); |
| 1416 if (interfaceType !== null && interfaceType.element.isExtendable()) { | 1420 if (interfaceType !== null && interfaceType.element.isExtendable()) { |
| 1417 classElement.interfaces = | 1421 classElement.interfaces = |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 | 1736 |
| 1733 // TODO(ahe): This is temporary. | 1737 // TODO(ahe): This is temporary. |
| 1734 void resolveExpression(Node node) { | 1738 void resolveExpression(Node node) { |
| 1735 if (node == null) return; | 1739 if (node == null) return; |
| 1736 node.accept(new ResolverVisitor(compiler, enclosingElement)); | 1740 node.accept(new ResolverVisitor(compiler, enclosingElement)); |
| 1737 } | 1741 } |
| 1738 | 1742 |
| 1739 // TODO(ahe): This is temporary. | 1743 // TODO(ahe): This is temporary. |
| 1740 void resolveType(Node node) { | 1744 void resolveType(Node node) { |
| 1741 if (node == null) return; | 1745 if (node == null) return; |
| 1742 // Find the correct member context to perform the lookup in. | 1746 node.accept(new ResolverVisitor(compiler, enclosingElement)); |
| 1743 Element outer = enclosingElement; | |
| 1744 Element context = outer; | |
| 1745 while (outer !== null) { | |
| 1746 if (outer.isMember()) { | |
| 1747 context = outer; | |
| 1748 break; | |
| 1749 } | |
| 1750 outer = outer.enclosingElement; | |
| 1751 } | |
| 1752 node.accept(new ResolverVisitor(compiler, context)); | |
| 1753 } | 1747 } |
| 1754 | 1748 |
| 1755 // TODO(ahe): This is temporary. | 1749 // TODO(ahe): This is temporary. |
| 1756 ClassElement get currentClass() { | 1750 ClassElement get currentClass() { |
| 1757 return enclosingElement.isMember() | 1751 return enclosingElement.isMember() |
| 1758 ? enclosingElement.enclosingElement : null; | 1752 ? enclosingElement.enclosingElement : null; |
| 1759 } | 1753 } |
| 1760 } | 1754 } |
| 1761 | 1755 |
| 1762 class ConstructorResolver extends CommonResolverVisitor<Element> { | 1756 class ConstructorResolver extends CommonResolverVisitor<Element> { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 | 1905 |
| 1912 TopScope(LibraryElement library) : super(null, library); | 1906 TopScope(LibraryElement library) : super(null, library); |
| 1913 Element lookup(SourceString name) { | 1907 Element lookup(SourceString name) { |
| 1914 return library.find(name); | 1908 return library.find(name); |
| 1915 } | 1909 } |
| 1916 | 1910 |
| 1917 Element add(Element newElement) { | 1911 Element add(Element newElement) { |
| 1918 throw "Cannot add an element in the top scope"; | 1912 throw "Cannot add an element in the top scope"; |
| 1919 } | 1913 } |
| 1920 } | 1914 } |
| OLD | NEW |