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 } | 8 } |
9 | 9 |
10 class TreeElementMapping implements TreeElements { | 10 class TreeElementMapping implements TreeElements { |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 604 } |
605 if (className == const SourceString('var')) return null; | 605 if (className == const SourceString('var')) return null; |
606 if (className == const SourceString('void')) return null; | 606 if (className == const SourceString('void')) return null; |
607 Element element = context.lookup(className); | 607 Element element = context.lookup(className); |
608 if (element === null) { | 608 if (element === null) { |
609 if (typeRequired) { | 609 if (typeRequired) { |
610 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]); | 610 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]); |
611 } else { | 611 } else { |
612 warning(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]); | 612 warning(node, MessageKind.CANNOT_RESOLVE_TYPE, [className]); |
613 } | 613 } |
614 } else if (element.kind !== ElementKind.CLASS) { | 614 } else if (!element.isClassOrInterfaceOrAlias()) { |
615 if (typeRequired) { | 615 if (typeRequired) { |
616 error(node, MessageKind.NOT_A_TYPE, [className]); | 616 error(node, MessageKind.NOT_A_TYPE, [className]); |
617 } else { | 617 } else { |
618 warning(node, MessageKind.NOT_A_TYPE, [className]); | 618 warning(node, MessageKind.NOT_A_TYPE, [className]); |
619 } | 619 } |
620 } else { | 620 } else { |
621 ClassElement cls = element; | 621 if (element.isClass()) { |
622 compiler.resolver.toResolve.add(element); | 622 // TODO(ngeoffray): Should we also resolve typedef? |
| 623 ClassElement cls = element; |
| 624 compiler.resolver.toResolve.add(element); |
| 625 } |
623 // TODO(ahe): This should be a Type. | 626 // TODO(ahe): This should be a Type. |
624 useElement(node, element); | 627 useElement(node, element); |
625 } | 628 } |
626 return element; | 629 return element; |
627 } | 630 } |
628 | 631 |
629 Element defineElement(Node node, Element element, | 632 Element defineElement(Node node, Element element, |
630 [bool doAddToScope = true]) { | 633 [bool doAddToScope = true]) { |
631 compiler.ensure(element !== null); | 634 compiler.ensure(element !== null); |
632 mapping[node] = element; | 635 mapping[node] = element; |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 if (name === null) { | 1227 if (name === null) { |
1225 unimplemented(node.typeName, "prefixes"); | 1228 unimplemented(node.typeName, "prefixes"); |
1226 } | 1229 } |
1227 return visit(name); | 1230 return visit(name); |
1228 } | 1231 } |
1229 | 1232 |
1230 Type visitIdentifier(Identifier node) { | 1233 Type visitIdentifier(Identifier node) { |
1231 Element element = context.lookup(node.source); | 1234 Element element = context.lookup(node.source); |
1232 if (element === null) { | 1235 if (element === null) { |
1233 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node]); | 1236 error(node, MessageKind.CANNOT_RESOLVE_TYPE, [node]); |
1234 } else if (element.kind !== ElementKind.CLASS) { | 1237 } else if (!element.isClassOrInterfaceOrAlias()) { |
1235 error(node, MessageKind.NOT_A_TYPE, [node]); | 1238 error(node, MessageKind.NOT_A_TYPE, [node]); |
1236 } else { | 1239 } else { |
1237 compiler.resolver.toResolve.add(element); | 1240 compiler.resolver.toResolve.add(element); |
1238 // TODO(ngeoffray): Use type variables. | 1241 // TODO(ngeoffray): Use type variables. |
1239 return element.computeType(compiler); | 1242 return element.computeType(compiler); |
1240 } | 1243 } |
1241 return null; | 1244 return null; |
1242 } | 1245 } |
1243 } | 1246 } |
1244 | 1247 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 class TopScope extends Scope { | 1481 class TopScope extends Scope { |
1479 LibraryElement get library() => element; | 1482 LibraryElement get library() => element; |
1480 | 1483 |
1481 TopScope(LibraryElement library) : super(null, library); | 1484 TopScope(LibraryElement library) : super(null, library); |
1482 Element lookup(SourceString name) => library.find(name); | 1485 Element lookup(SourceString name) => library.find(name); |
1483 | 1486 |
1484 Element add(Element element) { | 1487 Element add(Element element) { |
1485 throw "Cannot add an element in the top scope"; | 1488 throw "Cannot add an element in the top scope"; |
1486 } | 1489 } |
1487 } | 1490 } |
OLD | NEW |