Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: lib/compiler/implementation/resolution/members.dart

Issue 10942028: Support class and typedef literals as expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add a test for literals. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 Element enclosingElement; 1169 Element enclosingElement;
1170 final TypeResolver typeResolver; 1170 final TypeResolver typeResolver;
1171 bool inInstanceContext; 1171 bool inInstanceContext;
1172 bool inCheckContext; 1172 bool inCheckContext;
1173 bool inCatchBlock; 1173 bool inCatchBlock;
1174 Scope scope; 1174 Scope scope;
1175 ClassElement currentClass; 1175 ClassElement currentClass;
1176 ExpressionStatement currentExpressionStatement; 1176 ExpressionStatement currentExpressionStatement;
1177 bool typeRequired = false; 1177 bool typeRequired = false;
1178 StatementScope statementScope; 1178 StatementScope statementScope;
1179 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION; 1179 int allowedCategory = ElementCategory.VARIABLE | ElementCategory.FUNCTION
1180 | ElementCategory.IMPLIES_TYPE;
1180 1181
1181 ResolverVisitor(Compiler compiler, Element element, this.mapping) 1182 ResolverVisitor(Compiler compiler, Element element, this.mapping)
1182 : this.enclosingElement = element, 1183 : this.enclosingElement = element,
1183 // When the element is a field, we are actually resolving its 1184 // When the element is a field, we are actually resolving its
1184 // initial value, which should not have access to instance 1185 // initial value, which should not have access to instance
1185 // fields. 1186 // fields.
1186 inInstanceContext = (element.isInstanceMember() && !element.isField()) 1187 inInstanceContext = (element.isInstanceMember() && !element.isField())
1187 || element.isGenerativeConstructor(), 1188 || element.isGenerativeConstructor(),
1188 this.currentClass = element.isMember() ? element.getEnclosingClass() 1189 this.currentClass = element.isMember() ? element.getEnclosingClass()
1189 : null, 1190 : null,
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 error(node.selector, 1500 error(node.selector,
1500 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, 1501 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT,
1501 [selector.argumentCount]); 1502 [selector.argumentCount]);
1502 } else if (selector.namedArgumentCount != 0) { 1503 } else if (selector.namedArgumentCount != 0) {
1503 error(node.selector, 1504 error(node.selector,
1504 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, 1505 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS,
1505 [selector.namedArgumentCount]); 1506 [selector.namedArgumentCount]);
1506 } 1507 }
1507 return compiler.assertMethod; 1508 return compiler.assertMethod;
1508 } 1509 }
1509 return node.selector.accept(this); 1510
1511 Element result = node.selector.accept(this);
1512 if (result != null) {
1513 if (result.kind == ElementKind.CLASS) {
1514 ClassElement classElement = result;
1515 classElement.ensureResolved(compiler);
1516 }
1517 }
1518 return result;
1510 } 1519 }
1511 1520
1512 var oldCategory = allowedCategory; 1521 var oldCategory = allowedCategory;
1513 allowedCategory |= 1522 allowedCategory |= ElementCategory.PREFIX | ElementCategory.SUPER;
1514 ElementCategory.CLASS | ElementCategory.PREFIX | ElementCategory.SUPER;
1515 Element resolvedReceiver = visit(node.receiver); 1523 Element resolvedReceiver = visit(node.receiver);
1516 allowedCategory = oldCategory; 1524 allowedCategory = oldCategory;
1517 1525
1526 if (resolvedReceiver != null
1527 && resolvedReceiver.kind == ElementKind.CLASS) {
1528 ClassElement classElement = resolvedReceiver;
1529 classElement.ensureResolved(compiler);
1530 if (node.isOperator) {
1531 // In operator expressions like 'Class + 1', the operator call goes the
1532 // instance of [Type] that is the result of the expression 'Class'.
ngeoffray 2012/10/31 10:33:03 The comment is not helping me understand what's ha
karlklose 2012/10/31 13:01:18 Rephrased. Is it better to understand now?
1533 resolvedReceiver = null;
1534 }
1535 }
1536
1518 Element target; 1537 Element target;
1519 SourceString name = node.selector.asIdentifier().source; 1538 SourceString name = node.selector.asIdentifier().source;
1520 if (identical(name.stringValue, 'this')) { 1539 if (identical(name.stringValue, 'this')) {
1521 error(node.selector, MessageKind.GENERIC, ["expected an identifier"]); 1540 error(node.selector, MessageKind.GENERIC, ["expected an identifier"]);
1522 } else if (node.isSuperCall) { 1541 } else if (node.isSuperCall) {
1523 if (node.isOperator) { 1542 if (node.isOperator) {
1524 if (isUserDefinableOperator(name.stringValue)) { 1543 if (isUserDefinableOperator(name.stringValue)) {
1525 name = selector.name; 1544 name = selector.name;
1526 } else { 1545 } else {
1527 error(node.selector, MessageKind.ILLEGAL_SUPER_SEND, [name]); 1546 error(node.selector, MessageKind.ILLEGAL_SUPER_SEND, [name]);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 } 1582 }
1564 } else if (identical(resolvedReceiver.kind, ElementKind.PREFIX)) { 1583 } else if (identical(resolvedReceiver.kind, ElementKind.PREFIX)) {
1565 PrefixElement prefix = resolvedReceiver; 1584 PrefixElement prefix = resolvedReceiver;
1566 target = prefix.lookupLocalMember(name); 1585 target = prefix.lookupLocalMember(name);
1567 if (target == null) { 1586 if (target == null) {
1568 return warnAndCreateErroneousElement( 1587 return warnAndCreateErroneousElement(
1569 node, name, MessageKind.NO_SUCH_LIBRARY_MEMBER, 1588 node, name, MessageKind.NO_SUCH_LIBRARY_MEMBER,
1570 [prefix.name, name]); 1589 [prefix.name, name]);
1571 } 1590 }
1572 } 1591 }
1592 if (target != null && target.kind == ElementKind.CLASS) {
ngeoffray 2012/10/31 10:33:03 Should that check be in the prefix check?
karlklose 2012/10/31 13:01:18 Where exactly do you mean this should be?
ngeoffray 2012/10/31 14:32:43 line 1590
karlklose 2012/10/31 16:32:17 Yes, makes sense.
1593 ClassElement classElement = target;
1594 classElement.ensureResolved(compiler);
1595 }
1573 return target; 1596 return target;
1574 } 1597 }
1575 1598
1576 DartType resolveTypeTest(Node argument) { 1599 DartType resolveTypeTest(Node argument) {
1577 TypeAnnotation node = argument.asTypeAnnotation(); 1600 TypeAnnotation node = argument.asTypeAnnotation();
1578 if (node == null) { 1601 if (node == null) {
1579 // node is of the form !Type. 1602 // node is of the form !Type.
1580 node = argument.asSend().receiver.asTypeAnnotation(); 1603 node = argument.asSend().receiver.asTypeAnnotation();
1581 if (node == null) compiler.cancel("malformed send"); 1604 if (node == null) compiler.cancel("malformed send");
1582 } 1605 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 1723
1701 if (node.isCall) { 1724 if (node.isCall) {
1702 if (Elements.isUnresolved(target) || 1725 if (Elements.isUnresolved(target) ||
1703 target.isGetter() || 1726 target.isGetter() ||
1704 Elements.isClosureSend(node, target)) { 1727 Elements.isClosureSend(node, target)) {
1705 // If we don't know what we're calling or if we are calling a getter, 1728 // If we don't know what we're calling or if we are calling a getter,
1706 // we need to register that fact that we may be calling a closure 1729 // we need to register that fact that we may be calling a closure
1707 // with the same arguments. 1730 // with the same arguments.
1708 Selector call = new Selector.callClosureFrom(selector); 1731 Selector call = new Selector.callClosureFrom(selector);
1709 world.registerDynamicInvocation(call.name, call); 1732 world.registerDynamicInvocation(call.name, call);
1710 } else if (!selector.applies(target, compiler)) { 1733 } else if (target is FunctionElement
ngeoffray 2012/10/31 10:33:03 target.isFunction() ? Or have selector.applies do
karlklose 2012/10/31 13:01:18 I added a case for targets that imply a type.
1734 && !selector.applies(target, compiler)) {
1711 warnArgumentMismatch(node, target); 1735 warnArgumentMismatch(node, target);
1712 } 1736 }
1713 } 1737 }
1714 1738
1715 // TODO(ngeoffray): Warn if target is null and the send is 1739 // TODO(ngeoffray): Warn if target is null and the send is
1716 // unqualified. 1740 // unqualified.
1717 useElement(node, target); 1741 useElement(node, target);
1718 registerSend(selector, target); 1742 registerSend(selector, target);
1719 return node.isPropertyAccess ? target : null; 1743 return node.isPropertyAccess ? target : null;
1720 } 1744 }
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); 3014 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]);
2991 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { 3015 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) {
2992 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); 3016 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]);
2993 } else if (!identical(e.kind, ElementKind.CLASS) 3017 } else if (!identical(e.kind, ElementKind.CLASS)
2994 && !identical(e.kind, ElementKind.PREFIX)) { 3018 && !identical(e.kind, ElementKind.PREFIX)) {
2995 error(node, MessageKind.NOT_A_TYPE, [name]); 3019 error(node, MessageKind.NOT_A_TYPE, [name]);
2996 } 3020 }
2997 return e; 3021 return e;
2998 } 3022 }
2999 } 3023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698