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

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

Issue 23825007: Reapply r27285: "Support dynamic as type literal." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Try to resolve dynamic in scope before testing for the name. Created 7 years, 3 months 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 get currentElement; 8 Element get currentElement;
9 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 // TODO(karlklose): clean this up (dartbug.com/8870). 1744 // TODO(karlklose): clean this up (dartbug.com/8870).
1745 inCheckContext = compiler.enableTypeAssertions && 1745 inCheckContext = compiler.enableTypeAssertions &&
1746 !element.isLibrary() && 1746 !element.isLibrary() &&
1747 !element.isTypedef() && 1747 !element.isTypedef() &&
1748 !element.enclosingElement.isTypedef(), 1748 !element.enclosingElement.isTypedef(),
1749 inCatchBlock = false, 1749 inCatchBlock = false,
1750 super(compiler, mapping); 1750 super(compiler, mapping);
1751 1751
1752 ResolutionEnqueuer get world => compiler.enqueuer.resolution; 1752 ResolutionEnqueuer get world => compiler.enqueuer.resolution;
1753 1753
1754 Element lookup(Node node, SourceString name) { 1754 Element reportLookupErrorIfAny(Element result, Node node, SourceString name) {
1755 Element result = scope.lookup(name);
1756 if (!Elements.isUnresolved(result)) { 1755 if (!Elements.isUnresolved(result)) {
1757 if (!inInstanceContext && result.isInstanceMember()) { 1756 if (!inInstanceContext && result.isInstanceMember()) {
1758 compiler.reportError( 1757 compiler.reportError(
1759 node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': name}); 1758 node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': name});
1760 return new ErroneousElementX(MessageKind.NO_INSTANCE_AVAILABLE, 1759 return new ErroneousElementX(MessageKind.NO_INSTANCE_AVAILABLE,
1761 {'name': name}, 1760 {'name': name},
1762 name, enclosingElement); 1761 name, enclosingElement);
1763 } else if (result.isAmbiguous()) { 1762 } else if (result.isAmbiguous()) {
1764 AmbiguousElement ambiguous = result; 1763 AmbiguousElement ambiguous = result;
1765 compiler.reportError( 1764 compiler.reportError(
1766 node, ambiguous.messageKind.error, ambiguous.messageArguments); 1765 node, ambiguous.messageKind.error, ambiguous.messageArguments);
1767 ambiguous.diagnose(enclosingElement, compiler); 1766 ambiguous.diagnose(enclosingElement, compiler);
1768 return new ErroneousElementX(ambiguous.messageKind.error, 1767 return new ErroneousElementX(ambiguous.messageKind.error,
1769 ambiguous.messageArguments, 1768 ambiguous.messageArguments,
1770 name, enclosingElement); 1769 name, enclosingElement);
1771 } 1770 }
1772 } 1771 }
1773 return result; 1772 return result;
1774 } 1773 }
1775 1774
1775 Element lookupAndReport(Node node, SourceString name) {
ngeoffray 2013/09/10 08:21:18 Since this is only called once, I'd prefer inlinin
karlklose 2013/09/10 11:42:33 Done.
1776 Element result = scope.lookup(name);
1777 return reportLookupErrorIfAny(result, node, name);
1778 }
1779
1776 // Create, or reuse an already created, statement element for a statement. 1780 // Create, or reuse an already created, statement element for a statement.
1777 TargetElement getOrCreateTargetElement(Node statement) { 1781 TargetElement getOrCreateTargetElement(Node statement) {
1778 TargetElement element = mapping[statement]; 1782 TargetElement element = mapping[statement];
1779 if (element == null) { 1783 if (element == null) {
1780 element = new TargetElementX(statement, 1784 element = new TargetElementX(statement,
1781 statementScope.nestingLevel, 1785 statementScope.nestingLevel,
1782 enclosingElement); 1786 enclosingElement);
1783 mapping[statement] = element; 1787 mapping[statement] = element;
1784 } 1788 }
1785 return element; 1789 return element;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); 1825 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node});
1822 } 1826 }
1823 return null; 1827 return null;
1824 } else if (node.isSuper()) { 1828 } else if (node.isSuper()) {
1825 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC); 1829 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC);
1826 if ((ElementCategory.SUPER & allowedCategory) == 0) { 1830 if ((ElementCategory.SUPER & allowedCategory) == 0) {
1827 error(node, MessageKind.INVALID_USE_OF_SUPER); 1831 error(node, MessageKind.INVALID_USE_OF_SUPER);
1828 } 1832 }
1829 return null; 1833 return null;
1830 } else { 1834 } else {
1831 Element element = lookup(node, node.source); 1835 SourceString name = node.source;
1836 Element element = scope.lookup(name);
1837 if (Elements.isUnresolved(element) && name.slowToString() == 'dynamic') {
1838 element = compiler.dynamicClass;
1839 }
1840 element = reportLookupErrorIfAny(element, node, node.source);
1832 if (element == null) { 1841 if (element == null) {
1833 if (!inInstanceContext) { 1842 if (!inInstanceContext) {
1834 element = warnAndCreateErroneousElement( 1843 element = warnAndCreateErroneousElement(
1835 node, node.source, MessageKind.CANNOT_RESOLVE, 1844 node, node.source, MessageKind.CANNOT_RESOLVE,
1836 {'name': node}); 1845 {'name': node});
1837 compiler.backend.registerThrowNoSuchMethod(mapping); 1846 compiler.backend.registerThrowNoSuchMethod(mapping);
1838 } 1847 }
1839 } else if (element.isErroneous()) { 1848 } else if (element.isErroneous()) {
1840 // Use the erroneous element. 1849 // Use the erroneous element.
1841 } else { 1850 } else {
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after
4121 error(node, MessageKind.NOT_A_TYPE.error, {'node': name}); 4130 error(node, MessageKind.NOT_A_TYPE.error, {'node': name});
4122 } 4131 }
4123 } else { 4132 } else {
4124 internalError(node.receiver, 'unexpected element $e'); 4133 internalError(node.receiver, 'unexpected element $e');
4125 } 4134 }
4126 return e; 4135 return e;
4127 } 4136 }
4128 4137
4129 Element visitIdentifier(Identifier node) { 4138 Element visitIdentifier(Identifier node) {
4130 SourceString name = node.source; 4139 SourceString name = node.source;
4131 Element e = resolver.lookup(node, name); 4140 Element e = resolver.lookupAndReport(node, name);
4132 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. 4141 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1.
4133 if (e == null) { 4142 if (e == null) {
4134 return failOrReturnErroneousElement(resolver.enclosingElement, node, name, 4143 return failOrReturnErroneousElement(resolver.enclosingElement, node, name,
4135 MessageKind.CANNOT_RESOLVE, 4144 MessageKind.CANNOT_RESOLVE,
4136 {'name': name}); 4145 {'name': name});
4137 } else if (e.isErroneous()) { 4146 } else if (e.isErroneous()) {
4138 return e; 4147 return e;
4139 } else if (identical(e.kind, ElementKind.TYPEDEF)) { 4148 } else if (identical(e.kind, ElementKind.TYPEDEF)) {
4140 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, 4149 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF,
4141 {'typedefName': name}); 4150 {'typedefName': name});
4142 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { 4151 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) {
4143 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, 4152 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE,
4144 {'typeVariableName': name}); 4153 {'typeVariableName': name});
4145 } else if (!identical(e.kind, ElementKind.CLASS) 4154 } else if (!identical(e.kind, ElementKind.CLASS)
4146 && !identical(e.kind, ElementKind.PREFIX)) { 4155 && !identical(e.kind, ElementKind.PREFIX)) {
4147 error(node, MessageKind.NOT_A_TYPE.error, {'node': name}); 4156 error(node, MessageKind.NOT_A_TYPE.error, {'node': name});
4148 } 4157 }
4149 return e; 4158 return e;
4150 } 4159 }
4151 4160
4152 /// Assumed to be called by [resolveRedirectingFactory]. 4161 /// Assumed to be called by [resolveRedirectingFactory].
4153 Element visitReturn(Return node) { 4162 Element visitReturn(Return node) {
4154 Node expression = node.expression; 4163 Node expression = node.expression;
4155 return finishConstructorReference(visit(expression), 4164 return finishConstructorReference(visit(expression),
4156 expression, expression); 4165 expression, expression);
4157 } 4166 }
4158 } 4167 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_backend/namer.dart ('k') | tests/language/first_class_types_literals_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698