| 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 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 Setlet<Node> get superUses; | 9 Setlet<Node> get superUses; |
| 10 | 10 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 cls.ensureResolved(compiler); | 276 cls.ensureResolved(compiler); |
| 277 return null; | 277 return null; |
| 278 } else if (element.isTypedef()) { | 278 } else if (element.isTypedef()) { |
| 279 TypedefElement typdef = element; | 279 TypedefElement typdef = element; |
| 280 return resolveTypedef(typdef); | 280 return resolveTypedef(typdef); |
| 281 } else if (element.isTypeVariable()) { | 281 } else if (element.isTypeVariable()) { |
| 282 element.computeType(compiler); | 282 element.computeType(compiler); |
| 283 return null; | 283 return null; |
| 284 } | 284 } |
| 285 | 285 |
| 286 compiler.unimplemented("resolve($element)", | 286 compiler.unimplemented(element, "resolve($element)"); |
| 287 node: element.parseNode(compiler)); | |
| 288 }); | 287 }); |
| 289 } | 288 } |
| 290 | 289 |
| 291 String constructorNameForDiagnostics(String className, | 290 String constructorNameForDiagnostics(String className, |
| 292 String constructorName) { | 291 String constructorName) { |
| 293 String classNameString = className; | 292 String classNameString = className; |
| 294 String constructorNameString = constructorName; | 293 String constructorNameString = constructorName; |
| 295 return (constructorName == '') | 294 return (constructorName == '') |
| 296 ? classNameString | 295 ? classNameString |
| 297 : "$classNameString.$constructorNameString"; | 296 : "$classNameString.$constructorNameString"; |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 void checkAbstractField(Element member) { | 978 void checkAbstractField(Element member) { |
| 980 // Only check for getters. The test can only fail if there is both a setter | 979 // Only check for getters. The test can only fail if there is both a setter |
| 981 // and a getter with the same name, and we only need to check each abstract | 980 // and a getter with the same name, and we only need to check each abstract |
| 982 // field once, so we just ignore setters. | 981 // field once, so we just ignore setters. |
| 983 if (!member.isGetter()) return; | 982 if (!member.isGetter()) return; |
| 984 | 983 |
| 985 // Find the associated abstract field. | 984 // Find the associated abstract field. |
| 986 ClassElement classElement = member.getEnclosingClass(); | 985 ClassElement classElement = member.getEnclosingClass(); |
| 987 Element lookupElement = classElement.lookupLocalMember(member.name); | 986 Element lookupElement = classElement.lookupLocalMember(member.name); |
| 988 if (lookupElement == null) { | 987 if (lookupElement == null) { |
| 989 compiler.internalErrorOnElement(member, | 988 compiler.internalError(member, |
| 990 "No abstract field for accessor"); | 989 "No abstract field for accessor"); |
| 991 } else if (!identical(lookupElement.kind, ElementKind.ABSTRACT_FIELD)) { | 990 } else if (!identical(lookupElement.kind, ElementKind.ABSTRACT_FIELD)) { |
| 992 compiler.internalErrorOnElement( | 991 compiler.internalError(member, |
| 993 member, "Inaccessible abstract field for accessor"); | 992 "Inaccessible abstract field for accessor"); |
| 994 } | 993 } |
| 995 AbstractFieldElement field = lookupElement; | 994 AbstractFieldElement field = lookupElement; |
| 996 | 995 |
| 997 if (field.getter == null) return; | 996 if (field.getter == null) return; |
| 998 if (field.setter == null) return; | 997 if (field.setter == null) return; |
| 999 int getterFlags = field.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT; | 998 int getterFlags = field.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT; |
| 1000 int setterFlags = field.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT; | 999 int setterFlags = field.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT; |
| 1001 if (!identical(getterFlags, setterFlags)) { | 1000 if (!identical(getterFlags, setterFlags)) { |
| 1002 final mismatchedFlags = | 1001 final mismatchedFlags = |
| 1003 new Modifiers.withFlags(null, getterFlags ^ setterFlags); | 1002 new Modifiers.withFlags(null, getterFlags ^ setterFlags); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1034 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; | 1033 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; |
| 1035 requiredParameterCount = 0; | 1034 requiredParameterCount = 0; |
| 1036 } else if (isBinaryOperator(value)) { | 1035 } else if (isBinaryOperator(value)) { |
| 1037 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY; | 1036 messageKind = MessageKind.BINARY_OPERATOR_BAD_ARITY; |
| 1038 requiredParameterCount = 1; | 1037 requiredParameterCount = 1; |
| 1039 if (identical(value, '==')) checkOverrideHashCode(member); | 1038 if (identical(value, '==')) checkOverrideHashCode(member); |
| 1040 } else if (isTernaryOperator(value)) { | 1039 } else if (isTernaryOperator(value)) { |
| 1041 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY; | 1040 messageKind = MessageKind.TERNARY_OPERATOR_BAD_ARITY; |
| 1042 requiredParameterCount = 2; | 1041 requiredParameterCount = 2; |
| 1043 } else { | 1042 } else { |
| 1044 compiler.internalErrorOnElement(function, | 1043 compiler.internalError(function, |
| 1045 'Unexpected user defined operator $value'); | 1044 'Unexpected user defined operator $value'); |
| 1046 } | 1045 } |
| 1047 checkArity(function, requiredParameterCount, messageKind, isMinus); | 1046 checkArity(function, requiredParameterCount, messageKind, isMinus); |
| 1048 } | 1047 } |
| 1049 | 1048 |
| 1050 void checkOverrideHashCode(FunctionElement operatorEquals) { | 1049 void checkOverrideHashCode(FunctionElement operatorEquals) { |
| 1051 if (operatorEquals.isAbstract) return; | 1050 if (operatorEquals.isAbstract) return; |
| 1052 ClassElement cls = operatorEquals.getEnclosingClass(); | 1051 ClassElement cls = operatorEquals.getEnclosingClass(); |
| 1053 Element hashCodeImplementation = | 1052 Element hashCodeImplementation = |
| 1054 cls.lookupLocalMember('hashCode'); | 1053 cls.lookupLocalMember('hashCode'); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 return null; // If there was no redirection always return null. | 1525 return null; // If there was no redirection always return null. |
| 1527 } | 1526 } |
| 1528 } | 1527 } |
| 1529 | 1528 |
| 1530 class CommonResolverVisitor<R> extends Visitor<R> { | 1529 class CommonResolverVisitor<R> extends Visitor<R> { |
| 1531 final Compiler compiler; | 1530 final Compiler compiler; |
| 1532 | 1531 |
| 1533 CommonResolverVisitor(Compiler this.compiler); | 1532 CommonResolverVisitor(Compiler this.compiler); |
| 1534 | 1533 |
| 1535 R visitNode(Node node) { | 1534 R visitNode(Node node) { |
| 1536 cancel(node, | 1535 internalError(node, |
| 1537 'internal error: Unhandled node: ${node.getObjectDescription()}'); | 1536 'internal error: Unhandled node: ${node.getObjectDescription()}'); |
| 1538 return null; | 1537 return null; |
| 1539 } | 1538 } |
| 1540 | 1539 |
| 1541 R visitEmptyStatement(Node node) => null; | 1540 R visitEmptyStatement(Node node) => null; |
| 1542 | 1541 |
| 1543 /** Convenience method for visiting nodes that may be null. */ | 1542 /** Convenience method for visiting nodes that may be null. */ |
| 1544 R visit(Node node) => (node == null) ? null : node.accept(this); | 1543 R visit(Node node) => (node == null) ? null : node.accept(this); |
| 1545 | 1544 |
| 1546 void error(Spannable node, MessageKind kind, [Map arguments = const {}]) { | 1545 void error(Spannable node, MessageKind kind, [Map arguments = const {}]) { |
| 1547 compiler.reportFatalError(node, kind, arguments); | 1546 compiler.reportFatalError(node, kind, arguments); |
| 1548 } | 1547 } |
| 1549 | 1548 |
| 1550 void warning(Spannable node, MessageKind kind, [Map arguments = const {}]) { | 1549 void warning(Spannable node, MessageKind kind, [Map arguments = const {}]) { |
| 1551 compiler.reportWarning(node, kind, arguments); | 1550 compiler.reportWarning(node, kind, arguments); |
| 1552 } | 1551 } |
| 1553 | 1552 |
| 1554 void cancel(Node node, String message) { | 1553 void internalError(Spannable node, message) { |
| 1555 compiler.cancel(message, node: node); | 1554 compiler.internalError(node, message); |
| 1556 } | |
| 1557 | |
| 1558 void internalError(Node node, String message) { | |
| 1559 compiler.internalError(message, node: node); | |
| 1560 } | 1555 } |
| 1561 | 1556 |
| 1562 void addDeferredAction(Element element, DeferredAction action) { | 1557 void addDeferredAction(Element element, DeferredAction action) { |
| 1563 compiler.enqueuer.resolution.addDeferredAction(element, action); | 1558 compiler.enqueuer.resolution.addDeferredAction(element, action); |
| 1564 } | 1559 } |
| 1565 } | 1560 } |
| 1566 | 1561 |
| 1567 abstract class LabelScope { | 1562 abstract class LabelScope { |
| 1568 LabelScope get outer; | 1563 LabelScope get outer; |
| 1569 LabelElement lookup(String label); | 1564 LabelElement lookup(String label); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 compiler.backend.registerThrowRuntimeError(visitor.mapping); | 1827 compiler.backend.registerThrowRuntimeError(visitor.mapping); |
| 1833 type = reportFailureAndCreateType( | 1828 type = reportFailureAndCreateType( |
| 1834 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, | 1829 MessageKind.TYPE_VARIABLE_WITHIN_STATIC_MEMBER, |
| 1835 {'typeVariableName': node}, | 1830 {'typeVariableName': node}, |
| 1836 userProvidedBadType: element.computeType(compiler)); | 1831 userProvidedBadType: element.computeType(compiler)); |
| 1837 } else { | 1832 } else { |
| 1838 type = element.computeType(compiler); | 1833 type = element.computeType(compiler); |
| 1839 } | 1834 } |
| 1840 type = checkNoTypeArguments(type); | 1835 type = checkNoTypeArguments(type); |
| 1841 } else { | 1836 } else { |
| 1842 compiler.cancel("unexpected element kind ${element.kind}", | 1837 compiler.internalError(node, |
| 1843 node: node); | 1838 "Unexpected element kind ${element.kind}."); |
| 1844 } | 1839 } |
| 1845 // TODO(johnniwinther): We should not resolve type annotations after the | 1840 // TODO(johnniwinther): We should not resolve type annotations after the |
| 1846 // resolution queue has been closed. Currently the dart backend does so. | 1841 // resolution queue has been closed. Currently the dart backend does so. |
| 1847 // Remove the guarded when this is fixed. | 1842 // Remove the guarded when this is fixed. |
| 1848 if (!compiler.enqueuer.resolution.queueIsClosed && | 1843 if (!compiler.enqueuer.resolution.queueIsClosed && |
| 1849 addTypeVariableBoundsCheck) { | 1844 addTypeVariableBoundsCheck) { |
| 1850 visitor.addDeferredAction( | 1845 visitor.addDeferredAction( |
| 1851 visitor.enclosingElement, | 1846 visitor.enclosingElement, |
| 1852 () => checkTypeVariableBounds(visitor.mapping, node, type)); | 1847 () => checkTypeVariableBounds(visitor.mapping, node, type)); |
| 1853 } | 1848 } |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2258 | 2253 |
| 2259 visitCascade(Cascade node) { | 2254 visitCascade(Cascade node) { |
| 2260 visit(node.expression); | 2255 visit(node.expression); |
| 2261 } | 2256 } |
| 2262 | 2257 |
| 2263 visitCascadeReceiver(CascadeReceiver node) { | 2258 visitCascadeReceiver(CascadeReceiver node) { |
| 2264 visit(node.expression); | 2259 visit(node.expression); |
| 2265 } | 2260 } |
| 2266 | 2261 |
| 2267 visitClassNode(ClassNode node) { | 2262 visitClassNode(ClassNode node) { |
| 2268 cancel(node, "shouldn't be called"); | 2263 internalError(node, "shouldn't be called"); |
| 2269 } | 2264 } |
| 2270 | 2265 |
| 2271 visitIn(Node node, Scope nestedScope) { | 2266 visitIn(Node node, Scope nestedScope) { |
| 2272 Scope oldScope = scope; | 2267 Scope oldScope = scope; |
| 2273 scope = nestedScope; | 2268 scope = nestedScope; |
| 2274 Element element = visit(node); | 2269 Element element = visit(node); |
| 2275 scope = oldScope; | 2270 scope = oldScope; |
| 2276 return element; | 2271 return element; |
| 2277 } | 2272 } |
| 2278 | 2273 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2873 | 2868 |
| 2874 visitLiteralNull(LiteralNull node) { | 2869 visitLiteralNull(LiteralNull node) { |
| 2875 world.registerInstantiatedClass(compiler.nullClass, mapping); | 2870 world.registerInstantiatedClass(compiler.nullClass, mapping); |
| 2876 } | 2871 } |
| 2877 | 2872 |
| 2878 visitLiteralSymbol(LiteralSymbol node) { | 2873 visitLiteralSymbol(LiteralSymbol node) { |
| 2879 world.registerInstantiatedClass(compiler.symbolClass, mapping); | 2874 world.registerInstantiatedClass(compiler.symbolClass, mapping); |
| 2880 world.registerStaticUse(compiler.symbolConstructor.declaration); | 2875 world.registerStaticUse(compiler.symbolConstructor.declaration); |
| 2881 world.registerConstSymbol(node.slowNameString, mapping); | 2876 world.registerConstSymbol(node.slowNameString, mapping); |
| 2882 if (!validateSymbol(node, node.slowNameString, reportError: false)) { | 2877 if (!validateSymbol(node, node.slowNameString, reportError: false)) { |
| 2883 compiler.reportInternalError(node, | 2878 compiler.reportError(node, |
| 2884 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, | 2879 MessageKind.UNSUPPORTED_LITERAL_SYMBOL, |
| 2885 {'value': node.slowNameString}); | 2880 {'value': node.slowNameString}); |
| 2886 } | 2881 } |
| 2887 analyzeConstant(node); | 2882 analyzeConstant(node); |
| 2888 } | 2883 } |
| 2889 | 2884 |
| 2890 visitStringJuxtaposition(StringJuxtaposition node) { | 2885 visitStringJuxtaposition(StringJuxtaposition node) { |
| 2891 world.registerInstantiatedClass(compiler.stringClass, mapping); | 2886 world.registerInstantiatedClass(compiler.stringClass, mapping); |
| 2892 node.visitChildren(this); | 2887 node.visitChildren(this); |
| 2893 } | 2888 } |
| (...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3983 } | 3978 } |
| 3984 // If the super type isn't specified, we provide a default. The language | 3979 // If the super type isn't specified, we provide a default. The language |
| 3985 // specifies [Object] but the backend can pick a specific 'implementation' | 3980 // specifies [Object] but the backend can pick a specific 'implementation' |
| 3986 // of Object - the JavaScript backend chooses between Object and | 3981 // of Object - the JavaScript backend chooses between Object and |
| 3987 // Interceptor. | 3982 // Interceptor. |
| 3988 if (element.supertype == null) { | 3983 if (element.supertype == null) { |
| 3989 ClassElement superElement = compiler.backend.defaultSuperclass(element); | 3984 ClassElement superElement = compiler.backend.defaultSuperclass(element); |
| 3990 // Avoid making the superclass (usually Object) extend itself. | 3985 // Avoid making the superclass (usually Object) extend itself. |
| 3991 if (element != superElement) { | 3986 if (element != superElement) { |
| 3992 if (superElement == null) { | 3987 if (superElement == null) { |
| 3993 compiler.internalError( | 3988 compiler.internalError(node, |
| 3994 "Cannot resolve default superclass for $element", | 3989 "Cannot resolve default superclass for $element."); |
| 3995 node: node); | |
| 3996 } else { | 3990 } else { |
| 3997 superElement.ensureResolved(compiler); | 3991 superElement.ensureResolved(compiler); |
| 3998 } | 3992 } |
| 3999 element.supertype = superElement.computeType(compiler); | 3993 element.supertype = superElement.computeType(compiler); |
| 4000 } | 3994 } |
| 4001 } | 3995 } |
| 4002 | 3996 |
| 4003 if (element.interfaces == null) { | 3997 if (element.interfaces == null) { |
| 4004 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); | 3998 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); |
| 4005 } else { | 3999 } else { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4686 TreeElements _treeElements; | 4680 TreeElements _treeElements; |
| 4687 | 4681 |
| 4688 bool get hasTreeElements => _treeElements != null; | 4682 bool get hasTreeElements => _treeElements != null; |
| 4689 | 4683 |
| 4690 TreeElements get treeElements { | 4684 TreeElements get treeElements { |
| 4691 assert(invariant(this, _treeElements !=null, | 4685 assert(invariant(this, _treeElements !=null, |
| 4692 message: "TreeElements have not been computed for $this.")); | 4686 message: "TreeElements have not been computed for $this.")); |
| 4693 return _treeElements; | 4687 return _treeElements; |
| 4694 } | 4688 } |
| 4695 } | 4689 } |
| OLD | NEW |