| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.resolution.tree_elements; | 5 library dart2js.resolution.tree_elements; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 11 import '../types/types.dart' show | 11 import '../types/types.dart' show |
| 12 TypeMask; | 12 TypeMask; |
| 13 import '../tree/tree.dart'; | 13 import '../tree/tree.dart'; |
| 14 import '../util/util.dart'; | 14 import '../util/util.dart'; |
| 15 import '../universe/selector.dart' show | 15 import '../universe/selector.dart' show |
| 16 Selector; | 16 Selector; |
| 17 | 17 |
| 18 import 'secret_tree_element.dart' show | 18 import 'secret_tree_element.dart' show |
| 19 getTreeElement, | 19 getTreeElement, |
| 20 setTreeElement; | 20 setTreeElement; |
| 21 import 'send_structure.dart'; | 21 import 'send_structure.dart'; |
| 22 | 22 |
| 23 abstract class TreeElements { | 23 abstract class TreeElements { |
| 24 AnalyzableElement get analyzedElement; | 24 AnalyzableElement get analyzedElement; |
| 25 Iterable<Node> get superUses; | 25 Iterable<Node> get superUses; |
| 26 | 26 |
| 27 /// Iterables of the dependencies that this [TreeElement] records of | |
| 28 /// [analyzedElement]. | |
| 29 Iterable<Element> get allElements; | |
| 30 | |
| 31 /// The set of types that this TreeElement depends on. | 27 /// The set of types that this TreeElement depends on. |
| 32 /// This includes instantiated types, types in is-checks and as-expressions | 28 /// This includes instantiated types, types in is-checks and as-expressions |
| 33 /// and in checked mode the types of all type-annotations. | 29 /// and in checked mode the types of all type-annotations. |
| 34 Iterable<DartType> get requiredTypes; | 30 Iterable<DartType> get requiredTypes; |
| 35 | 31 |
| 36 void forEachConstantNode(f(Node n, ConstantExpression c)); | 32 void forEachConstantNode(f(Node n, ConstantExpression c)); |
| 37 | 33 |
| 38 /// A set of additional dependencies. See [registerDependency] below. | |
| 39 Iterable<Element> get otherDependencies; | |
| 40 | |
| 41 Element operator[](Node node); | 34 Element operator[](Node node); |
| 42 Map<Node, DartType> get typesCache; | 35 Map<Node, DartType> get typesCache; |
| 43 | 36 |
| 44 SendStructure getSendStructure(Send send); | 37 SendStructure getSendStructure(Send send); |
| 45 | 38 |
| 46 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. | 39 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. |
| 47 Selector getSelector(Node node); | 40 Selector getSelector(Node node); |
| 48 Selector getGetterSelectorInComplexSendSet(SendSet node); | 41 Selector getGetterSelectorInComplexSendSet(SendSet node); |
| 49 Selector getOperatorSelectorInComplexSendSet(SendSet node); | 42 Selector getOperatorSelectorInComplexSendSet(SendSet node); |
| 50 DartType getType(Node node); | 43 DartType getType(Node node); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 80 * Returns [:true:] if [node] is a type literal. | 73 * Returns [:true:] if [node] is a type literal. |
| 81 * | 74 * |
| 82 * Resolution marks this by setting the type on the node to be the | 75 * Resolution marks this by setting the type on the node to be the |
| 83 * type that the literal refers to. | 76 * type that the literal refers to. |
| 84 */ | 77 */ |
| 85 bool isTypeLiteral(Send node); | 78 bool isTypeLiteral(Send node); |
| 86 | 79 |
| 87 /// Returns the type that the type literal [node] refers to. | 80 /// Returns the type that the type literal [node] refers to. |
| 88 DartType getTypeLiteralType(Send node); | 81 DartType getTypeLiteralType(Send node); |
| 89 | 82 |
| 90 /// Register additional dependencies required by [analyzedElement]. | |
| 91 /// For example, elements that are used by a backend. | |
| 92 void registerDependency(Element element); | |
| 93 | |
| 94 /// Register a dependency on [type]. | 83 /// Register a dependency on [type]. |
| 95 void addRequiredType(DartType type); | 84 void addRequiredType(DartType type); |
| 96 | 85 |
| 97 /// Returns a list of nodes that potentially mutate [element] anywhere in its | 86 /// Returns a list of nodes that potentially mutate [element] anywhere in its |
| 98 /// scope. | 87 /// scope. |
| 99 List<Node> getPotentialMutations(VariableElement element); | 88 List<Node> getPotentialMutations(VariableElement element); |
| 100 | 89 |
| 101 /// Returns a list of nodes that potentially mutate [element] in [node]. | 90 /// Returns a list of nodes that potentially mutate [element] in [node]. |
| 102 List<Node> getPotentialMutationsIn(Node node, VariableElement element); | 91 List<Node> getPotentialMutationsIn(Node node, VariableElement element); |
| 103 | 92 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 123 bool get containsTryStatement; | 112 bool get containsTryStatement; |
| 124 } | 113 } |
| 125 | 114 |
| 126 class TreeElementMapping extends TreeElements { | 115 class TreeElementMapping extends TreeElements { |
| 127 final AnalyzableElement analyzedElement; | 116 final AnalyzableElement analyzedElement; |
| 128 Map<Spannable, Selector> _selectors; | 117 Map<Spannable, Selector> _selectors; |
| 129 Map<Spannable, TypeMask> _typeMasks; | 118 Map<Spannable, TypeMask> _typeMasks; |
| 130 Map<Node, DartType> _types; | 119 Map<Node, DartType> _types; |
| 131 Map<Node, DartType> typesCache = <Node, DartType>{}; | 120 Map<Node, DartType> typesCache = <Node, DartType>{}; |
| 132 Setlet<Node> _superUses; | 121 Setlet<Node> _superUses; |
| 133 Setlet<Element> _otherDependencies; | |
| 134 Map<Node, ConstantExpression> _constants; | 122 Map<Node, ConstantExpression> _constants; |
| 135 Map<VariableElement, List<Node>> _potentiallyMutated; | 123 Map<VariableElement, List<Node>> _potentiallyMutated; |
| 136 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; | 124 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; |
| 137 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; | 125 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; |
| 138 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; | 126 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; |
| 139 Setlet<Element> _elements; | |
| 140 Maplet<Send, SendStructure> _sendStructureMap; | 127 Maplet<Send, SendStructure> _sendStructureMap; |
| 141 Setlet<DartType> _requiredTypes; | 128 Setlet<DartType> _requiredTypes; |
| 142 bool containsTryStatement = false; | 129 bool containsTryStatement = false; |
| 143 | 130 |
| 144 /// Map from nodes to the targets they define. | 131 /// Map from nodes to the targets they define. |
| 145 Map<Node, JumpTarget> _definedTargets; | 132 Map<Node, JumpTarget> _definedTargets; |
| 146 | 133 |
| 147 /// Map from goto statements to their targets. | 134 /// Map from goto statements to their targets. |
| 148 Map<GotoStatement, JumpTarget> _usedTargets; | 135 Map<GotoStatement, JumpTarget> _usedTargets; |
| 149 | 136 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 166 return analyzedElement.implementationLibrary.isPatch; | 153 return analyzedElement.implementationLibrary.isPatch; |
| 167 } | 154 } |
| 168 return true; | 155 return true; |
| 169 })); | 156 })); |
| 170 // TODO(ahe): Investigate why the invariant below doesn't hold. | 157 // TODO(ahe): Investigate why the invariant below doesn't hold. |
| 171 // assert(invariant(node, | 158 // assert(invariant(node, |
| 172 // getTreeElement(node) == element || | 159 // getTreeElement(node) == element || |
| 173 // getTreeElement(node) == null, | 160 // getTreeElement(node) == null, |
| 174 // message: '${getTreeElement(node)}; $element')); | 161 // message: '${getTreeElement(node)}; $element')); |
| 175 | 162 |
| 176 if (_elements == null) { | |
| 177 _elements = new Setlet<Element>(); | |
| 178 } | |
| 179 _elements.add(element); | |
| 180 setTreeElement(node, element); | 163 setTreeElement(node, element); |
| 181 } | 164 } |
| 182 | 165 |
| 183 operator [](Node node) => getTreeElement(node); | 166 operator [](Node node) => getTreeElement(node); |
| 184 | 167 |
| 185 SendStructure getSendStructure(Send send) { | 168 SendStructure getSendStructure(Send send) { |
| 186 if (_sendStructureMap == null) return null; | 169 if (_sendStructureMap == null) return null; |
| 187 return _sendStructureMap[send]; | 170 return _sendStructureMap[send]; |
| 188 } | 171 } |
| 189 | 172 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 289 } |
| 307 | 290 |
| 308 bool isTypeLiteral(Send node) { | 291 bool isTypeLiteral(Send node) { |
| 309 return getType(node) != null; | 292 return getType(node) != null; |
| 310 } | 293 } |
| 311 | 294 |
| 312 DartType getTypeLiteralType(Send node) { | 295 DartType getTypeLiteralType(Send node) { |
| 313 return getType(node); | 296 return getType(node); |
| 314 } | 297 } |
| 315 | 298 |
| 316 void registerDependency(Element element) { | |
| 317 if (element == null) return; | |
| 318 if (_otherDependencies == null) { | |
| 319 _otherDependencies = new Setlet<Element>(); | |
| 320 } | |
| 321 _otherDependencies.add(element.implementation); | |
| 322 } | |
| 323 | |
| 324 Iterable<Element> get otherDependencies { | |
| 325 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | |
| 326 } | |
| 327 | |
| 328 List<Node> getPotentialMutations(VariableElement element) { | 299 List<Node> getPotentialMutations(VariableElement element) { |
| 329 if (_potentiallyMutated == null) return const <Node>[]; | 300 if (_potentiallyMutated == null) return const <Node>[]; |
| 330 List<Node> mutations = _potentiallyMutated[element]; | 301 List<Node> mutations = _potentiallyMutated[element]; |
| 331 if (mutations == null) return const <Node>[]; | 302 if (mutations == null) return const <Node>[]; |
| 332 return mutations; | 303 return mutations; |
| 333 } | 304 } |
| 334 | 305 |
| 335 void registerPotentialMutation(VariableElement element, Node mutationNode) { | 306 void registerPotentialMutation(VariableElement element, Node mutationNode) { |
| 336 if (_potentiallyMutated == null) { | 307 if (_potentiallyMutated == null) { |
| 337 _potentiallyMutated = new Maplet<VariableElement, List<Node>>(); | 308 _potentiallyMutated = new Maplet<VariableElement, List<Node>>(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 _accessedByClosureIn = new Map<Node, Map<VariableElement, List<Node>>>(); | 362 _accessedByClosureIn = new Map<Node, Map<VariableElement, List<Node>>>(); |
| 392 } | 363 } |
| 393 Map<VariableElement, List<Node>> accessMap = | 364 Map<VariableElement, List<Node>> accessMap = |
| 394 _accessedByClosureIn.putIfAbsent(contextNode, | 365 _accessedByClosureIn.putIfAbsent(contextNode, |
| 395 () => new Maplet<VariableElement, List<Node>>()); | 366 () => new Maplet<VariableElement, List<Node>>()); |
| 396 accessMap.putIfAbsent(element, () => <Node>[]).add(accessNode); | 367 accessMap.putIfAbsent(element, () => <Node>[]).add(accessNode); |
| 397 } | 368 } |
| 398 | 369 |
| 399 String toString() => 'TreeElementMapping($analyzedElement)'; | 370 String toString() => 'TreeElementMapping($analyzedElement)'; |
| 400 | 371 |
| 401 Iterable<Element> get allElements { | |
| 402 return _elements != null ? _elements : const <Element>[]; | |
| 403 } | |
| 404 | |
| 405 void forEachConstantNode(f(Node n, ConstantExpression c)) { | 372 void forEachConstantNode(f(Node n, ConstantExpression c)) { |
| 406 if (_constants != null) { | 373 if (_constants != null) { |
| 407 _constants.forEach(f); | 374 _constants.forEach(f); |
| 408 } | 375 } |
| 409 } | 376 } |
| 410 | 377 |
| 411 FunctionElement getFunctionDefinition(FunctionExpression node) { | 378 FunctionElement getFunctionDefinition(FunctionExpression node) { |
| 412 return this[node]; | 379 return this[node]; |
| 413 } | 380 } |
| 414 | 381 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 502 } |
| 536 | 503 |
| 537 void setCurrentTypeMask(ForIn node, TypeMask mask) { | 504 void setCurrentTypeMask(ForIn node, TypeMask mask) { |
| 538 _setTypeMask(node.inToken, mask); | 505 _setTypeMask(node.inToken, mask); |
| 539 } | 506 } |
| 540 | 507 |
| 541 TypeMask getCurrentTypeMask(ForIn node) { | 508 TypeMask getCurrentTypeMask(ForIn node) { |
| 542 return _getTypeMask(node.inToken); | 509 return _getTypeMask(node.inToken); |
| 543 } | 510 } |
| 544 } | 511 } |
| OLD | NEW |