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 abstract class TreeElements { | 5 abstract class TreeElements { |
6 Element operator[](Node node); | 6 Element operator[](Node node); |
7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
8 DartType getType(Node node); | 8 DartType getType(Node node); |
9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
10 } | 10 } |
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1473 visit(node.condition); | 1473 visit(node.condition); |
1474 visit(node.thenPart); | 1474 visit(node.thenPart); |
1475 visit(node.elsePart); | 1475 visit(node.elsePart); |
1476 } | 1476 } |
1477 | 1477 |
1478 static bool isLogicalOperator(Identifier op) { | 1478 static bool isLogicalOperator(Identifier op) { |
1479 String str = op.source.stringValue; | 1479 String str = op.source.stringValue; |
1480 return (identical(str, '&&') || str == '||' || str == '!'); | 1480 return (identical(str, '&&') || str == '||' || str == '!'); |
1481 } | 1481 } |
1482 | 1482 |
1483 Element resolveSend(Send node) { | 1483 Element resolveSend(Send node) { |
ahe
2012/10/23 11:54:26
Karl, this is getting too horrible. Let's take a l
| |
1484 void withAdditionalCategories(int categories, void f()) { | |
1485 var oldCategory = allowedCategory; | |
1486 allowedCategory |= categories; | |
1487 f(); | |
1488 allowedCategory = oldCategory; | |
1489 } | |
1490 | |
1484 Selector selector = resolveSelector(node); | 1491 Selector selector = resolveSelector(node); |
1485 | 1492 |
1486 if (node.receiver == null) { | 1493 if (node.receiver == null) { |
1487 // If this send is of the form "assert(expr);", then | 1494 // If this send is of the form "assert(expr);", then |
1488 // this is an assertion. | 1495 // this is an assertion. |
1489 if (selector.isAssert()) { | 1496 if (selector.isAssert()) { |
1490 if (selector.argumentCount != 1) { | 1497 if (selector.argumentCount != 1) { |
1491 error(node.selector, | 1498 error(node.selector, |
1492 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | 1499 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, |
1493 [selector.argumentCount]); | 1500 [selector.argumentCount]); |
1494 } else if (selector.namedArgumentCount != 0) { | 1501 } else if (selector.namedArgumentCount != 0) { |
1495 error(node.selector, | 1502 error(node.selector, |
1496 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, | 1503 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, |
1497 [selector.namedArgumentCount]); | 1504 [selector.namedArgumentCount]); |
1498 } | 1505 } |
1499 return compiler.assertMethod; | 1506 return compiler.assertMethod; |
1500 } | 1507 } |
1501 return node.selector.accept(this); | 1508 |
1509 Element result; | |
1510 withAdditionalCategories(ElementCategory.CLASS, () { | |
1511 result = node.selector.accept(this); | |
1512 }); | |
1513 if (result != null && result.kind == ElementKind.CLASS) { | |
1514 ClassElement classElement = result; | |
1515 classElement.ensureResolved(compiler); | |
1516 } | |
1517 return result; | |
1502 } | 1518 } |
1503 | 1519 |
1504 var oldCategory = allowedCategory; | 1520 Element resolvedReceiver; |
1505 allowedCategory |= | 1521 withAdditionalCategories( |
1506 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER; | 1522 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER, |
1507 Element resolvedReceiver = visit(node.receiver); | 1523 () { resolvedReceiver = visit(node.receiver); }); |
1508 allowedCategory = oldCategory; | 1524 |
1525 if (resolvedReceiver != null | |
1526 && resolvedReceiver.kind == ElementKind.CLASS) { | |
1527 ClassElement classElement = resolvedReceiver; | |
1528 classElement.ensureResolved(compiler); | |
1529 if (node.isOperator) { | |
1530 // In operator expressions like 'Class + 1', the operator call goes the | |
1531 // instance of [Type] that is the result of the expression 'Class'. | |
1532 resolvedReceiver = null; | |
1533 } | |
1534 } | |
1509 | 1535 |
1510 Element target; | 1536 Element target; |
1511 SourceString name = node.selector.asIdentifier().source; | 1537 SourceString name = node.selector.asIdentifier().source; |
1512 if (identical(name.stringValue, 'this')) { | 1538 if (identical(name.stringValue, 'this')) { |
1513 error(node.selector, MessageKind.GENERIC, ["expected an identifier"]); | 1539 error(node.selector, MessageKind.GENERIC, ["expected an identifier"]); |
1514 } else if (node.isSuperCall) { | 1540 } else if (node.isSuperCall) { |
1515 if (node.isOperator) { | 1541 if (node.isOperator) { |
1516 if (isUserDefinableOperator(name.stringValue)) { | 1542 if (isUserDefinableOperator(name.stringValue)) { |
1517 name = selector.name; | 1543 name = selector.name; |
1518 } else { | 1544 } else { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1553 } else if (target.isInstanceMember()) { | 1579 } else if (target.isInstanceMember()) { |
1554 error(node, MessageKind.MEMBER_NOT_STATIC, [receiverClass.name, name]); | 1580 error(node, MessageKind.MEMBER_NOT_STATIC, [receiverClass.name, name]); |
1555 } | 1581 } |
1556 } else if (identical(resolvedReceiver.kind, ElementKind.PREFIX)) { | 1582 } else if (identical(resolvedReceiver.kind, ElementKind.PREFIX)) { |
1557 PrefixElement prefix = resolvedReceiver; | 1583 PrefixElement prefix = resolvedReceiver; |
1558 target = prefix.lookupLocalMember(name); | 1584 target = prefix.lookupLocalMember(name); |
1559 if (target == null) { | 1585 if (target == null) { |
1560 error(node, MessageKind.NO_SUCH_LIBRARY_MEMBER, [prefix.name, name]); | 1586 error(node, MessageKind.NO_SUCH_LIBRARY_MEMBER, [prefix.name, name]); |
1561 } | 1587 } |
1562 } | 1588 } |
1589 if (target != null && target.kind == ElementKind.CLASS) { | |
1590 ClassElement classElement = target; | |
1591 classElement.ensureResolved(compiler); | |
1592 } | |
1563 return target; | 1593 return target; |
1564 } | 1594 } |
1565 | 1595 |
1566 DartType resolveTypeTest(Node argument) { | 1596 DartType resolveTypeTest(Node argument) { |
1567 TypeAnnotation node = argument.asTypeAnnotation(); | 1597 TypeAnnotation node = argument.asTypeAnnotation(); |
1568 if (node == null) { | 1598 if (node == null) { |
1569 // node is of the form !Type. | 1599 // node is of the form !Type. |
1570 node = argument.asSend().receiver.asTypeAnnotation(); | 1600 node = argument.asSend().receiver.asTypeAnnotation(); |
1571 if (node == null) compiler.cancel("malformed send"); | 1601 if (node == null) compiler.cancel("malformed send"); |
1572 } | 1602 } |
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3117 | 3147 |
3118 Element localLookup(SourceString name) => library.find(name); | 3148 Element localLookup(SourceString name) => library.find(name); |
3119 Element lookup(SourceString name) => localLookup(name); | 3149 Element lookup(SourceString name) => localLookup(name); |
3120 | 3150 |
3121 Element add(Element newElement) { | 3151 Element add(Element newElement) { |
3122 throw "Cannot add an element to a library scope"; | 3152 throw "Cannot add an element to a library scope"; |
3123 } | 3153 } |
3124 | 3154 |
3125 String toString() => 'LibraryScope($library)'; | 3155 String toString() => 'LibraryScope($library)'; |
3126 } | 3156 } |
OLD | NEW |