| 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 AnalyzableElement get analyzedElement; | 8 AnalyzableElement get analyzedElement; |
| 9 Iterable<Node> get superUses; | 9 Iterable<Node> get superUses; |
| 10 | 10 |
| 11 /// Iterables of the dependencies that this [TreeElement] records of | 11 /// Iterables of the dependencies that this [TreeElement] records of |
| 12 /// [analyzedElement]. | 12 /// [analyzedElement]. |
| 13 Iterable<Element> get allElements; | 13 Iterable<Element> get allElements; |
| 14 void forEachConstantNode(f(Node n, ConstantExpression c)); | 14 void forEachConstantNode(f(Node n, ConstantExpression c)); |
| 15 | 15 |
| 16 /// A set of additional dependencies. See [registerDependency] below. | 16 /// A set of additional dependencies. See [registerDependency] below. |
| 17 Iterable<Element> get otherDependencies; | 17 Iterable<Element> get otherDependencies; |
| 18 | 18 |
| 19 Element operator[](Node node); | 19 Element operator[](Node node); |
| 20 | 20 |
| 21 SendStructure getSendStructure(Send send); |
| 22 |
| 21 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. | 23 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. |
| 22 Selector getSelector(Node node); | 24 Selector getSelector(Node node); |
| 23 Selector getGetterSelectorInComplexSendSet(SendSet node); | 25 Selector getGetterSelectorInComplexSendSet(SendSet node); |
| 24 Selector getOperatorSelectorInComplexSendSet(SendSet node); | 26 Selector getOperatorSelectorInComplexSendSet(SendSet node); |
| 25 DartType getType(Node node); | 27 DartType getType(Node node); |
| 26 void setSelector(Node node, Selector selector); | 28 void setSelector(Node node, Selector selector); |
| 27 void setGetterSelectorInComplexSendSet(SendSet node, Selector selector); | 29 void setGetterSelectorInComplexSendSet(SendSet node, Selector selector); |
| 28 void setOperatorSelectorInComplexSendSet(SendSet node, Selector selector); | 30 void setOperatorSelectorInComplexSendSet(SendSet node, Selector selector); |
| 29 | 31 |
| 30 /// Returns the for-in loop variable for [node]. | 32 /// Returns the for-in loop variable for [node]. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 Map<Node, DartType> _types; | 95 Map<Node, DartType> _types; |
| 94 Setlet<Node> _superUses; | 96 Setlet<Node> _superUses; |
| 95 Setlet<Element> _otherDependencies; | 97 Setlet<Element> _otherDependencies; |
| 96 Map<Node, ConstantExpression> _constants; | 98 Map<Node, ConstantExpression> _constants; |
| 97 Map<VariableElement, List<Node>> _potentiallyMutated; | 99 Map<VariableElement, List<Node>> _potentiallyMutated; |
| 98 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; | 100 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; |
| 99 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; | 101 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; |
| 100 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; | 102 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; |
| 101 Setlet<Element> _elements; | 103 Setlet<Element> _elements; |
| 102 Setlet<Send> _asserts; | 104 Setlet<Send> _asserts; |
| 105 Maplet<Send, SendStructure> _sendStructureMap; |
| 103 | 106 |
| 104 /// Map from nodes to the targets they define. | 107 /// Map from nodes to the targets they define. |
| 105 Map<Node, JumpTarget> _definedTargets; | 108 Map<Node, JumpTarget> _definedTargets; |
| 106 | 109 |
| 107 /// Map from goto statements to their targets. | 110 /// Map from goto statements to their targets. |
| 108 Map<GotoStatement, JumpTarget> _usedTargets; | 111 Map<GotoStatement, JumpTarget> _usedTargets; |
| 109 | 112 |
| 110 /// Map from labels to their label definition. | 113 /// Map from labels to their label definition. |
| 111 Map<Label, LabelDefinition> _definedLabels; | 114 Map<Label, LabelDefinition> _definedLabels; |
| 112 | 115 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 | 138 |
| 136 if (_elements == null) { | 139 if (_elements == null) { |
| 137 _elements = new Setlet<Element>(); | 140 _elements = new Setlet<Element>(); |
| 138 } | 141 } |
| 139 _elements.add(element); | 142 _elements.add(element); |
| 140 setTreeElement(node, element); | 143 setTreeElement(node, element); |
| 141 } | 144 } |
| 142 | 145 |
| 143 operator [](Node node) => getTreeElement(node); | 146 operator [](Node node) => getTreeElement(node); |
| 144 | 147 |
| 148 SendStructure getSendStructure(Send send) { |
| 149 if (_sendStructureMap == null) return null; |
| 150 return _sendStructureMap[send]; |
| 151 } |
| 152 |
| 153 void setSendStructure(Send send, SendStructure sendStructure) { |
| 154 if (_sendStructureMap == null) { |
| 155 _sendStructureMap = new Maplet<Send, SendStructure>(); |
| 156 } |
| 157 _sendStructureMap[send] = sendStructure; |
| 158 } |
| 159 |
| 145 void setType(Node node, DartType type) { | 160 void setType(Node node, DartType type) { |
| 146 if (_types == null) { | 161 if (_types == null) { |
| 147 _types = new Maplet<Node, DartType>(); | 162 _types = new Maplet<Node, DartType>(); |
| 148 } | 163 } |
| 149 _types[node] = type; | 164 _types[node] = type; |
| 150 } | 165 } |
| 151 | 166 |
| 152 DartType getType(Node node) => _types != null ? _types[node] : null; | 167 DartType getType(Node node) => _types != null ? _types[node] : null; |
| 153 | 168 |
| 154 Iterable<Node> get superUses { | 169 Iterable<Node> get superUses { |
| (...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2572 } | 2587 } |
| 2573 | 2588 |
| 2574 ResolutionResult resolveSend(Send node) { | 2589 ResolutionResult resolveSend(Send node) { |
| 2575 Selector selector = resolveSelector(node, null); | 2590 Selector selector = resolveSelector(node, null); |
| 2576 if (node.isSuperCall) registry.registerSuperUse(node); | 2591 if (node.isSuperCall) registry.registerSuperUse(node); |
| 2577 | 2592 |
| 2578 if (node.receiver == null) { | 2593 if (node.receiver == null) { |
| 2579 // If this send is of the form "assert(expr);", then | 2594 // If this send is of the form "assert(expr);", then |
| 2580 // this is an assertion. | 2595 // this is an assertion. |
| 2581 if (selector.isAssert) { | 2596 if (selector.isAssert) { |
| 2597 SendStructure sendStructure = const AssertStructure(); |
| 2582 if (selector.argumentCount != 1) { | 2598 if (selector.argumentCount != 1) { |
| 2583 error(node.selector, | 2599 error(node.selector, |
| 2584 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, | 2600 MessageKind.WRONG_NUMBER_OF_ARGUMENTS_FOR_ASSERT, |
| 2585 {'argumentCount': selector.argumentCount}); | 2601 {'argumentCount': selector.argumentCount}); |
| 2602 sendStructure = const InvalidAssertStructure(); |
| 2586 } else if (selector.namedArgumentCount != 0) { | 2603 } else if (selector.namedArgumentCount != 0) { |
| 2587 error(node.selector, | 2604 error(node.selector, |
| 2588 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, | 2605 MessageKind.ASSERT_IS_GIVEN_NAMED_ARGUMENTS, |
| 2589 {'argumentCount': selector.namedArgumentCount}); | 2606 {'argumentCount': selector.namedArgumentCount}); |
| 2607 sendStructure = const InvalidAssertStructure(); |
| 2590 } | 2608 } |
| 2591 registry.registerAssert(node); | 2609 registry.registerAssert(node); |
| 2610 registry.registerSendStructure(node, sendStructure); |
| 2592 return const AssertResult(); | 2611 return const AssertResult(); |
| 2593 } | 2612 } |
| 2594 | 2613 |
| 2595 return node.selector.accept(this); | 2614 return node.selector.accept(this); |
| 2596 } | 2615 } |
| 2597 | 2616 |
| 2598 var oldCategory = allowedCategory; | 2617 var oldCategory = allowedCategory; |
| 2599 allowedCategory |= ElementCategory.PREFIX | ElementCategory.SUPER; | 2618 allowedCategory |= ElementCategory.PREFIX | ElementCategory.SUPER; |
| 2600 ResolutionResult resolvedReceiver = visit(node.receiver); | 2619 ResolutionResult resolvedReceiver = visit(node.receiver); |
| 2601 allowedCategory = oldCategory; | 2620 allowedCategory = oldCategory; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2892 for (Node scope in promotionScope) { | 2911 for (Node scope in promotionScope) { |
| 2893 registry.setAccessedByClosureIn(scope, target, node); | 2912 registry.setAccessedByClosureIn(scope, target, node); |
| 2894 } | 2913 } |
| 2895 } | 2914 } |
| 2896 } | 2915 } |
| 2897 } | 2916 } |
| 2898 | 2917 |
| 2899 bool resolvedArguments = false; | 2918 bool resolvedArguments = false; |
| 2900 if (node.isOperator) { | 2919 if (node.isOperator) { |
| 2901 String operatorString = node.selector.asOperator().source; | 2920 String operatorString = node.selector.asOperator().source; |
| 2902 if (identical(operatorString, 'is')) { | 2921 SendStructure sendStructure; |
| 2922 if (operatorString == 'is') { |
| 2903 // TODO(johnniwinther): Use seen type tests to avoid registration of | 2923 // TODO(johnniwinther): Use seen type tests to avoid registration of |
| 2904 // mutation/access to unpromoted variables. | 2924 // mutation/access to unpromoted variables. |
| 2905 DartType type = | 2925 DartType type = |
| 2906 resolveTypeAnnotation(node.typeAnnotationFromIsCheckOrCast); | 2926 resolveTypeAnnotation(node.typeAnnotationFromIsCheckOrCast); |
| 2907 if (type != null) { | 2927 if (type != null) { |
| 2928 sendStructure = node.isIsNotCheck |
| 2929 ? new IsNotStructure(type) : new IsStructure(type); |
| 2908 registry.registerIsCheck(type); | 2930 registry.registerIsCheck(type); |
| 2909 } | 2931 } |
| 2910 resolvedArguments = true; | 2932 resolvedArguments = true; |
| 2911 } else if (identical(operatorString, 'as')) { | 2933 } else if (identical(operatorString, 'as')) { |
| 2912 DartType type = resolveTypeAnnotation(node.arguments.head); | 2934 DartType type = resolveTypeAnnotation(node.arguments.head); |
| 2913 if (type != null) { | 2935 if (type != null) { |
| 2936 sendStructure = new AsStructure(type); |
| 2914 registry.registerAsCheck(type); | 2937 registry.registerAsCheck(type); |
| 2915 } | 2938 } |
| 2916 resolvedArguments = true; | 2939 resolvedArguments = true; |
| 2917 } else if (identical(operatorString, '&&')) { | 2940 } else if (identical(operatorString, '&&')) { |
| 2918 doInPromotionScope(node.arguments.head, | 2941 doInPromotionScope(node.arguments.head, |
| 2919 () => resolveArguments(node.argumentsNode)); | 2942 () => resolveArguments(node.argumentsNode)); |
| 2943 sendStructure = const LogicalAndStructure(); |
| 2920 resolvedArguments = true; | 2944 resolvedArguments = true; |
| 2945 } else if (operatorString == '||') { |
| 2946 sendStructure = const LogicalOrStructure(); |
| 2947 } |
| 2948 if (sendStructure != null) { |
| 2949 registry.registerSendStructure(node, sendStructure); |
| 2921 } | 2950 } |
| 2922 } | 2951 } |
| 2923 | 2952 |
| 2924 if (!resolvedArguments) { | 2953 if (!resolvedArguments) { |
| 2925 resolveArguments(node.argumentsNode); | 2954 resolveArguments(node.argumentsNode); |
| 2926 } | 2955 } |
| 2927 | 2956 |
| 2928 // If the selector is null, it means that we will not be generating | 2957 // If the selector is null, it means that we will not be generating |
| 2929 // code for this as a send. | 2958 // code for this as a send. |
| 2930 Selector selector = registry.getSelector(node); | 2959 Selector selector = registry.getSelector(node); |
| (...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5166 } | 5195 } |
| 5167 | 5196 |
| 5168 /// The result for the resolution of the `assert` method. | 5197 /// The result for the resolution of the `assert` method. |
| 5169 class AssertResult implements ResolutionResult { | 5198 class AssertResult implements ResolutionResult { |
| 5170 const AssertResult(); | 5199 const AssertResult(); |
| 5171 | 5200 |
| 5172 Element get element => null; | 5201 Element get element => null; |
| 5173 | 5202 |
| 5174 String toString() => 'AssertResult()'; | 5203 String toString() => 'AssertResult()'; |
| 5175 } | 5204 } |
| OLD | NEW |