| 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 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1435 | 1435 |
| 1436 visitTypeAnnotation(TypeAnnotation node) { | 1436 visitTypeAnnotation(TypeAnnotation node) { |
| 1437 // TODO(ahe): Do not ignore type arguments. | 1437 // TODO(ahe): Do not ignore type arguments. |
| 1438 return visit(node.typeName); | 1438 return visit(node.typeName); |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 visitSend(Send node) { | 1441 visitSend(Send node) { |
| 1442 Element e = visit(node.receiver); | 1442 Element e = visit(node.receiver); |
| 1443 if (e === null) return null; // TODO(ahe): Return erroneous element. | 1443 if (e === null) return null; // TODO(ahe): Return erroneous element. |
| 1444 | 1444 |
| 1445 Identifier name = node.selector.asIdentifier(); |
| 1446 if (name === null) internalError(node.selector, 'unexpected node'); |
| 1447 |
| 1445 if (e.kind === ElementKind.CLASS) { | 1448 if (e.kind === ElementKind.CLASS) { |
| 1446 ClassElement cls = e; | 1449 ClassElement cls = e; |
| 1447 cls.resolve(compiler); | 1450 cls.resolve(compiler); |
| 1448 compiler.resolver.toResolve.add(cls); | 1451 compiler.resolver.toResolve.add(cls); |
| 1449 if (cls.isInterface() && (cls.defaultClass === null)) { | 1452 if (cls.isInterface() && (cls.defaultClass === null)) { |
| 1450 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE, | 1453 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE, |
| 1451 [cls.name]); | 1454 [cls.name]); |
| 1452 } | 1455 } |
| 1453 Identifier name = node.selector.asIdentifier(); | |
| 1454 if (name === null) { | |
| 1455 internalError(node.selector, 'unexpected node'); | |
| 1456 } | |
| 1457 SourceString constructorName = | 1456 SourceString constructorName = |
| 1458 Elements.constructConstructorName(cls.name, name.source); | 1457 Elements.constructConstructorName(cls.name, name.source); |
| 1459 FunctionElement constructor = cls.lookupConstructor(constructorName); | 1458 FunctionElement constructor = cls.lookupConstructor(constructorName); |
| 1460 if (constructor === null) { | 1459 if (constructor === null) { |
| 1461 error(name, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]); | 1460 error(name, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]); |
| 1462 } | 1461 } |
| 1463 e = constructor; | 1462 e = constructor; |
| 1463 } else if (e.kind === ElementKind.PREFIX) { |
| 1464 PrefixElement prefix = e; |
| 1465 e = prefix.library.lookupLocalMember(name.source); |
| 1466 if (e === null) { |
| 1467 error(name, MessageKind.CANNOT_RESOLVE, [name]); |
| 1468 // TODO(ahe): Return erroneous element. |
| 1469 } else if (e.kind !== ElementKind.CLASS) { |
| 1470 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 1471 } |
| 1464 } else { | 1472 } else { |
| 1465 internalError(node.resolve, 'unexpected element $e'); | 1473 internalError(node.receiver, 'unexpected element $e'); |
| 1466 } | 1474 } |
| 1467 return e; | 1475 return e; |
| 1468 } | 1476 } |
| 1469 | 1477 |
| 1470 Element visitIdentifier(Identifier node) { | 1478 Element visitIdentifier(Identifier node) { |
| 1471 SourceString name = node.source; | 1479 SourceString name = node.source; |
| 1472 Element e = resolver.lookup(node, name); | 1480 Element e = resolver.lookup(node, name); |
| 1473 if (e === null) { | 1481 if (e === null) { |
| 1474 error(node, MessageKind.CANNOT_RESOLVE, [name]); | 1482 error(node, MessageKind.CANNOT_RESOLVE, [name]); |
| 1475 // TODO(ahe): Return erroneous element. | 1483 // TODO(ahe): Return erroneous element. |
| 1476 } else if (e.kind === ElementKind.TYPEDEF) { | 1484 } else if (e.kind === ElementKind.TYPEDEF) { |
| 1477 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 1485 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 1478 } else if (e.kind !== ElementKind.CLASS) { | 1486 } else if (e.kind !== ElementKind.CLASS && e.kind !== ElementKind.PREFIX) { |
| 1479 error(node, MessageKind.NOT_A_TYPE, [name]); | 1487 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 1480 } | 1488 } |
| 1481 return e; | 1489 return e; |
| 1482 } | 1490 } |
| 1483 } | 1491 } |
| 1484 | 1492 |
| 1485 class Scope { | 1493 class Scope { |
| 1486 final Element element; | 1494 final Element element; |
| 1487 final Scope parent; | 1495 final Scope parent; |
| 1488 | 1496 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 class TopScope extends Scope { | 1544 class TopScope extends Scope { |
| 1537 LibraryElement get library() => element; | 1545 LibraryElement get library() => element; |
| 1538 | 1546 |
| 1539 TopScope(LibraryElement library) : super(null, library); | 1547 TopScope(LibraryElement library) : super(null, library); |
| 1540 Element lookup(SourceString name) => library.find(name); | 1548 Element lookup(SourceString name) => library.find(name); |
| 1541 | 1549 |
| 1542 Element add(Element element) { | 1550 Element add(Element element) { |
| 1543 throw "Cannot add an element in the top scope"; | 1551 throw "Cannot add an element in the top scope"; |
| 1544 } | 1552 } |
| 1545 } | 1553 } |
| OLD | NEW |