| 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 Set<Node> get superUses; | 9 Set<Node> get superUses; |
| 10 | 10 |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 annotation.resolutionState = STATE_DONE; | 967 annotation.resolutionState = STATE_DONE; |
| 968 })); | 968 })); |
| 969 } | 969 } |
| 970 | 970 |
| 971 error(Node node, MessageKind kind, [arguments = const {}]) { | 971 error(Node node, MessageKind kind, [arguments = const {}]) { |
| 972 // TODO(ahe): Make non-fatal. | 972 // TODO(ahe): Make non-fatal. |
| 973 compiler.reportFatalError(node, kind, arguments); | 973 compiler.reportFatalError(node, kind, arguments); |
| 974 } | 974 } |
| 975 } | 975 } |
| 976 | 976 |
| 977 class ConstantMapper extends Visitor { |
| 978 final Map<Constant, Node> constantToNodeMap = new Map<Constant, Node>(); |
| 979 final CompileTimeConstantEvaluator evaluator; |
| 980 |
| 981 ConstantMapper(ConstantHandler handler, |
| 982 TreeElements elements, |
| 983 Compiler compiler) |
| 984 : evaluator = new CompileTimeConstantEvaluator( |
| 985 handler, elements, compiler, isConst: false); |
| 986 |
| 987 visitNode(Node node) { |
| 988 Constant constant = evaluator.evaluate(node); |
| 989 if (constant != null) constantToNodeMap[constant] = node; |
| 990 node.visitChildren(this); |
| 991 } |
| 992 } |
| 993 |
| 977 class InitializerResolver { | 994 class InitializerResolver { |
| 978 final ResolverVisitor visitor; | 995 final ResolverVisitor visitor; |
| 979 final Map<Element, Node> initialized; | 996 final Map<Element, Node> initialized; |
| 980 Link<Node> initializers; | 997 Link<Node> initializers; |
| 981 bool hasSuper; | 998 bool hasSuper; |
| 982 | 999 |
| 983 InitializerResolver(this.visitor) | 1000 InitializerResolver(this.visitor) |
| 984 : initialized = new Map<Element, Node>(), hasSuper = false; | 1001 : initialized = new Map<Element, Node>(), hasSuper = false; |
| 985 | 1002 |
| 986 error(Node node, MessageKind kind, [arguments = const {}]) { | 1003 error(Node node, MessageKind kind, [arguments = const {}]) { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 | 1284 |
| 1268 void error(Node node, MessageKind kind, [Map arguments = const {}]) { | 1285 void error(Node node, MessageKind kind, [Map arguments = const {}]) { |
| 1269 compiler.reportFatalError(node, kind, arguments); | 1286 compiler.reportFatalError(node, kind, arguments); |
| 1270 } | 1287 } |
| 1271 | 1288 |
| 1272 void dualError(Node node, DualKind kind, [Map arguments = const {}]) { | 1289 void dualError(Node node, DualKind kind, [Map arguments = const {}]) { |
| 1273 error(node, kind.error, arguments); | 1290 error(node, kind.error, arguments); |
| 1274 } | 1291 } |
| 1275 | 1292 |
| 1276 void warning(Node node, MessageKind kind, [Map arguments = const {}]) { | 1293 void warning(Node node, MessageKind kind, [Map arguments = const {}]) { |
| 1277 ResolutionWarning message = new ResolutionWarning(kind, arguments); | 1294 ResolutionWarning message = |
| 1295 new ResolutionWarning(kind, arguments, compiler.terseDiagnostics); |
| 1278 compiler.reportWarning(node, message); | 1296 compiler.reportWarning(node, message); |
| 1279 } | 1297 } |
| 1280 | 1298 |
| 1281 void dualWarning(Node node, DualKind kind, [Map arguments = const {}]) { | 1299 void dualWarning(Node node, DualKind kind, [Map arguments = const {}]) { |
| 1282 warning(node, kind.warning, arguments); | 1300 warning(node, kind.warning, arguments); |
| 1283 } | 1301 } |
| 1284 | 1302 |
| 1285 void cancel(Node node, String message) { | 1303 void cancel(Node node, String message) { |
| 1286 compiler.cancel(message, node: node); | 1304 compiler.cancel(message, node: node); |
| 1287 } | 1305 } |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1743 } | 1761 } |
| 1744 | 1762 |
| 1745 visitInStaticContext(Node node) { | 1763 visitInStaticContext(Node node) { |
| 1746 inStaticContext(() => visit(node)); | 1764 inStaticContext(() => visit(node)); |
| 1747 } | 1765 } |
| 1748 | 1766 |
| 1749 ErroneousElement warnAndCreateErroneousElement(Node node, | 1767 ErroneousElement warnAndCreateErroneousElement(Node node, |
| 1750 SourceString name, | 1768 SourceString name, |
| 1751 DualKind kind, | 1769 DualKind kind, |
| 1752 [Map arguments = const {}]) { | 1770 [Map arguments = const {}]) { |
| 1753 ResolutionWarning warning = new ResolutionWarning(kind.warning, arguments); | 1771 ResolutionWarning warning = new ResolutionWarning( |
| 1772 kind.warning, arguments, compiler.terseDiagnostics); |
| 1754 compiler.reportWarning(node, warning); | 1773 compiler.reportWarning(node, warning); |
| 1755 return new ErroneousElementX(kind.error, arguments, name, enclosingElement); | 1774 return new ErroneousElementX(kind.error, arguments, name, enclosingElement); |
| 1756 } | 1775 } |
| 1757 | 1776 |
| 1758 Element visitIdentifier(Identifier node) { | 1777 Element visitIdentifier(Identifier node) { |
| 1759 if (node.isThis()) { | 1778 if (node.isThis()) { |
| 1760 if (!inInstanceContext) { | 1779 if (!inInstanceContext) { |
| 1761 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); | 1780 error(node, MessageKind.NO_INSTANCE_AVAILABLE, {'name': node}); |
| 1762 } | 1781 } |
| 1763 return null; | 1782 return null; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2591 bool oldSendIsMemberAccess = sendIsMemberAccess; | 2610 bool oldSendIsMemberAccess = sendIsMemberAccess; |
| 2592 sendIsMemberAccess = false; | 2611 sendIsMemberAccess = false; |
| 2593 visit(node.expression); | 2612 visit(node.expression); |
| 2594 sendIsMemberAccess = oldSendIsMemberAccess; | 2613 sendIsMemberAccess = oldSendIsMemberAccess; |
| 2595 } | 2614 } |
| 2596 | 2615 |
| 2597 visitNewExpression(NewExpression node) { | 2616 visitNewExpression(NewExpression node) { |
| 2598 Node selector = node.send.selector; | 2617 Node selector = node.send.selector; |
| 2599 FunctionElement constructor = resolveConstructor(node); | 2618 FunctionElement constructor = resolveConstructor(node); |
| 2600 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; | 2619 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; |
| 2620 final bool isMirrorsUsedConstant = |
| 2621 node.isConst() && (constructor == compiler.mirrorsUsedConstructor); |
| 2601 resolveSelector(node.send, constructor); | 2622 resolveSelector(node.send, constructor); |
| 2602 resolveArguments(node.send.argumentsNode); | 2623 resolveArguments(node.send.argumentsNode); |
| 2603 useElement(node.send, constructor); | 2624 useElement(node.send, constructor); |
| 2604 if (Elements.isUnresolved(constructor)) return constructor; | 2625 if (Elements.isUnresolved(constructor)) return constructor; |
| 2605 Selector callSelector = mapping.getSelector(node.send); | 2626 Selector callSelector = mapping.getSelector(node.send); |
| 2606 if (!callSelector.applies(constructor, compiler)) { | 2627 if (!callSelector.applies(constructor, compiler)) { |
| 2607 warnArgumentMismatch(node.send, constructor); | 2628 warnArgumentMismatch(node.send, constructor); |
| 2608 compiler.backend.registerThrowNoSuchMethod(mapping); | 2629 compiler.backend.registerThrowNoSuchMethod(mapping); |
| 2609 } | 2630 } |
| 2610 | 2631 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2643 } | 2664 } |
| 2644 } else { | 2665 } else { |
| 2645 if (!compiler.mirrorUsageAnalyzerTask.hasMirrorUsage( | 2666 if (!compiler.mirrorUsageAnalyzerTask.hasMirrorUsage( |
| 2646 enclosingElement)) { | 2667 enclosingElement)) { |
| 2647 compiler.reportHint( | 2668 compiler.reportHint( |
| 2648 node.newToken, MessageKind.NON_CONST_BLOAT, | 2669 node.newToken, MessageKind.NON_CONST_BLOAT, |
| 2649 {'name': compiler.symbolClass.name}); | 2670 {'name': compiler.symbolClass.name}); |
| 2650 } | 2671 } |
| 2651 world.registerNewSymbol(mapping); | 2672 world.registerNewSymbol(mapping); |
| 2652 } | 2673 } |
| 2674 } else if (isMirrorsUsedConstant) { |
| 2675 compiler.mirrorUsageAnalyzerTask.validate(node, mapping); |
| 2653 } | 2676 } |
| 2654 | 2677 |
| 2655 return null; | 2678 return null; |
| 2656 } | 2679 } |
| 2657 | 2680 |
| 2658 bool validateSymbol(Node node, String name) { | 2681 bool validateSymbol(Node node, String name) { |
| 2659 if (name.isEmpty) return true; | 2682 if (name.isEmpty) return true; |
| 2660 if (name.startsWith('_')) { | 2683 if (name.startsWith('_')) { |
| 2661 compiler.reportError(node, MessageKind.PRIVATE_IDENTIFIER, | 2684 compiler.reportError(node, MessageKind.PRIVATE_IDENTIFIER, |
| 2662 {'value': name}); | 2685 {'value': name}); |
| (...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3927 Map arguments) { | 3950 Map arguments) { |
| 3928 if (kind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { | 3951 if (kind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { |
| 3929 compiler.backend.registerThrowNoSuchMethod(resolver.mapping); | 3952 compiler.backend.registerThrowNoSuchMethod(resolver.mapping); |
| 3930 } else { | 3953 } else { |
| 3931 compiler.backend.registerThrowRuntimeError(resolver.mapping); | 3954 compiler.backend.registerThrowRuntimeError(resolver.mapping); |
| 3932 } | 3955 } |
| 3933 if (inConstContext) { | 3956 if (inConstContext) { |
| 3934 error(diagnosticNode, kind.error, arguments); | 3957 error(diagnosticNode, kind.error, arguments); |
| 3935 } else { | 3958 } else { |
| 3936 ResolutionWarning warning = | 3959 ResolutionWarning warning = |
| 3937 new ResolutionWarning(kind.warning, arguments); | 3960 new ResolutionWarning( |
| 3961 kind.warning, arguments, compiler.terseDiagnostics); |
| 3938 compiler.reportWarning(diagnosticNode, warning); | 3962 compiler.reportWarning(diagnosticNode, warning); |
| 3939 return new ErroneousElementX( | 3963 return new ErroneousElementX( |
| 3940 kind.error, arguments, targetName, enclosing); | 3964 kind.error, arguments, targetName, enclosing); |
| 3941 } | 3965 } |
| 3942 } | 3966 } |
| 3943 | 3967 |
| 3944 Selector createConstructorSelector(SourceString constructorName) { | 3968 Selector createConstructorSelector(SourceString constructorName) { |
| 3945 return constructorName == const SourceString('') | 3969 return constructorName == const SourceString('') |
| 3946 ? new Selector.callDefaultConstructor( | 3970 ? new Selector.callDefaultConstructor( |
| 3947 resolver.enclosingElement.getLibrary()) | 3971 resolver.enclosingElement.getLibrary()) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4063 return e; | 4087 return e; |
| 4064 } | 4088 } |
| 4065 | 4089 |
| 4066 /// Assumed to be called by [resolveRedirectingFactory]. | 4090 /// Assumed to be called by [resolveRedirectingFactory]. |
| 4067 Element visitReturn(Return node) { | 4091 Element visitReturn(Return node) { |
| 4068 Node expression = node.expression; | 4092 Node expression = node.expression; |
| 4069 return finishConstructorReference(visit(expression), | 4093 return finishConstructorReference(visit(expression), |
| 4070 expression, expression); | 4094 expression, expression); |
| 4071 } | 4095 } |
| 4072 } | 4096 } |
| OLD | NEW |