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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 bool oldSendIsMemberAccess = sendIsMemberAccess; | 2605 bool oldSendIsMemberAccess = sendIsMemberAccess; |
2587 sendIsMemberAccess = false; | 2606 sendIsMemberAccess = false; |
2588 visit(node.expression); | 2607 visit(node.expression); |
2589 sendIsMemberAccess = oldSendIsMemberAccess; | 2608 sendIsMemberAccess = oldSendIsMemberAccess; |
2590 } | 2609 } |
2591 | 2610 |
2592 visitNewExpression(NewExpression node) { | 2611 visitNewExpression(NewExpression node) { |
2593 Node selector = node.send.selector; | 2612 Node selector = node.send.selector; |
2594 FunctionElement constructor = resolveConstructor(node); | 2613 FunctionElement constructor = resolveConstructor(node); |
2595 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; | 2614 final bool isSymbolConstructor = constructor == compiler.symbolConstructor; |
| 2615 final bool isMirrorsUsedConstant = |
| 2616 node.isConst() && (constructor == compiler.mirrorsUsedConstructor); |
2596 resolveSelector(node.send, constructor); | 2617 resolveSelector(node.send, constructor); |
2597 resolveArguments(node.send.argumentsNode); | 2618 resolveArguments(node.send.argumentsNode); |
2598 useElement(node.send, constructor); | 2619 useElement(node.send, constructor); |
2599 if (Elements.isUnresolved(constructor)) return constructor; | 2620 if (Elements.isUnresolved(constructor)) return constructor; |
2600 Selector callSelector = mapping.getSelector(node.send); | 2621 Selector callSelector = mapping.getSelector(node.send); |
2601 if (!callSelector.applies(constructor, compiler)) { | 2622 if (!callSelector.applies(constructor, compiler)) { |
2602 warnArgumentMismatch(node.send, constructor); | 2623 warnArgumentMismatch(node.send, constructor); |
2603 compiler.backend.registerThrowNoSuchMethod(mapping); | 2624 compiler.backend.registerThrowNoSuchMethod(mapping); |
2604 } | 2625 } |
2605 | 2626 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2638 } | 2659 } |
2639 } else { | 2660 } else { |
2640 if (!compiler.mirrorUsageAnalyzerTask.hasMirrorUsage( | 2661 if (!compiler.mirrorUsageAnalyzerTask.hasMirrorUsage( |
2641 enclosingElement)) { | 2662 enclosingElement)) { |
2642 compiler.reportHint( | 2663 compiler.reportHint( |
2643 node.newToken, MessageKind.NON_CONST_BLOAT, | 2664 node.newToken, MessageKind.NON_CONST_BLOAT, |
2644 {'name': compiler.symbolClass.name}); | 2665 {'name': compiler.symbolClass.name}); |
2645 } | 2666 } |
2646 world.registerNewSymbol(mapping); | 2667 world.registerNewSymbol(mapping); |
2647 } | 2668 } |
| 2669 } else if (isMirrorsUsedConstant) { |
| 2670 compiler.mirrorUsageAnalyzerTask.validate(node, mapping); |
2648 } | 2671 } |
2649 | 2672 |
2650 return null; | 2673 return null; |
2651 } | 2674 } |
2652 | 2675 |
2653 bool validateSymbol(Node node, String name) { | 2676 bool validateSymbol(Node node, String name) { |
2654 if (name.isEmpty) return true; | 2677 if (name.isEmpty) return true; |
2655 if (name.startsWith('_')) { | 2678 if (name.startsWith('_')) { |
2656 compiler.reportError(node, MessageKind.PRIVATE_IDENTIFIER, | 2679 compiler.reportError(node, MessageKind.PRIVATE_IDENTIFIER, |
2657 {'value': name}); | 2680 {'value': name}); |
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3932 Map arguments) { | 3955 Map arguments) { |
3933 if (kind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { | 3956 if (kind == MessageKind.CANNOT_FIND_CONSTRUCTOR) { |
3934 compiler.backend.registerThrowNoSuchMethod(resolver.mapping); | 3957 compiler.backend.registerThrowNoSuchMethod(resolver.mapping); |
3935 } else { | 3958 } else { |
3936 compiler.backend.registerThrowRuntimeError(resolver.mapping); | 3959 compiler.backend.registerThrowRuntimeError(resolver.mapping); |
3937 } | 3960 } |
3938 if (inConstContext) { | 3961 if (inConstContext) { |
3939 error(diagnosticNode, kind.error, arguments); | 3962 error(diagnosticNode, kind.error, arguments); |
3940 } else { | 3963 } else { |
3941 ResolutionWarning warning = | 3964 ResolutionWarning warning = |
3942 new ResolutionWarning(kind.warning, arguments); | 3965 new ResolutionWarning( |
| 3966 kind.warning, arguments, compiler.terseDiagnostics); |
3943 compiler.reportWarning(diagnosticNode, warning); | 3967 compiler.reportWarning(diagnosticNode, warning); |
3944 return new ErroneousElementX( | 3968 return new ErroneousElementX( |
3945 kind.error, arguments, targetName, enclosing); | 3969 kind.error, arguments, targetName, enclosing); |
3946 } | 3970 } |
3947 } | 3971 } |
3948 | 3972 |
3949 Selector createConstructorSelector(SourceString constructorName) { | 3973 Selector createConstructorSelector(SourceString constructorName) { |
3950 return constructorName == const SourceString('') | 3974 return constructorName == const SourceString('') |
3951 ? new Selector.callDefaultConstructor( | 3975 ? new Selector.callDefaultConstructor( |
3952 resolver.enclosingElement.getLibrary()) | 3976 resolver.enclosingElement.getLibrary()) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4068 return e; | 4092 return e; |
4069 } | 4093 } |
4070 | 4094 |
4071 /// Assumed to be called by [resolveRedirectingFactory]. | 4095 /// Assumed to be called by [resolveRedirectingFactory]. |
4072 Element visitReturn(Return node) { | 4096 Element visitReturn(Return node) { |
4073 Node expression = node.expression; | 4097 Node expression = node.expression; |
4074 return finishConstructorReference(visit(expression), | 4098 return finishConstructorReference(visit(expression), |
4075 expression, expression); | 4099 expression, expression); |
4076 } | 4100 } |
4077 } | 4101 } |
OLD | NEW |