| 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 '../elements/resolution_types.dart'; | 9 import '../elements/resolution_types.dart'; |
| 10 import '../diagnostics/source_span.dart'; | 10 import '../diagnostics/source_span.dart'; |
| 11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 12 import '../tree/tree.dart'; | 12 import '../tree/tree.dart'; |
| 13 import '../universe/selector.dart' show Selector; | 13 import '../universe/selector.dart' show Selector; |
| 14 import '../util/util.dart'; | 14 import '../util/util.dart'; |
| 15 import 'secret_tree_element.dart' show getTreeElement, setTreeElement; | 15 import 'secret_tree_element.dart' show getTreeElement, setTreeElement; |
| 16 import 'send_structure.dart'; | 16 import 'send_structure.dart'; |
| 17 | 17 |
| 18 abstract class TreeElements { | 18 abstract class TreeElements { |
| 19 AnalyzableElement get analyzedElement; | 19 AnalyzableElement get analyzedElement; |
| 20 Iterable<SourceSpan> get superUses; | 20 Iterable<SourceSpan> get superUses; |
| 21 | 21 |
| 22 void forEachConstantNode(f(Node n, ConstantExpression c)); | 22 void forEachConstantNode(f(Node n, ConstantExpression c)); |
| 23 | 23 |
| 24 Element operator [](Node node); | 24 Element operator [](Node node); |
| 25 Map<Node, DartType> get typesCache; | 25 Map<Node, ResolutionDartType> get typesCache; |
| 26 | 26 |
| 27 /// Returns the [SendStructure] that describes the semantics of [node]. | 27 /// Returns the [SendStructure] that describes the semantics of [node]. |
| 28 SendStructure getSendStructure(Send node); | 28 SendStructure getSendStructure(Send node); |
| 29 | 29 |
| 30 /// Returns the [NewStructure] that describes the semantics of [node]. | 30 /// Returns the [NewStructure] that describes the semantics of [node]. |
| 31 NewStructure getNewStructure(NewExpression node); | 31 NewStructure getNewStructure(NewExpression node); |
| 32 | 32 |
| 33 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. | 33 // TODO(johnniwinther): Investigate whether [Node] could be a [Send]. |
| 34 Selector getSelector(Node node); | 34 Selector getSelector(Node node); |
| 35 Selector getGetterSelectorInComplexSendSet(SendSet node); | 35 Selector getGetterSelectorInComplexSendSet(SendSet node); |
| 36 Selector getOperatorSelectorInComplexSendSet(SendSet node); | 36 Selector getOperatorSelectorInComplexSendSet(SendSet node); |
| 37 DartType getType(Node node); | 37 ResolutionDartType getType(Node node); |
| 38 | 38 |
| 39 /// Returns the for-in loop variable for [node]. | 39 /// Returns the for-in loop variable for [node]. |
| 40 Element getForInVariable(ForIn node); | 40 Element getForInVariable(ForIn node); |
| 41 void setConstant(Node node, ConstantExpression constant); | 41 void setConstant(Node node, ConstantExpression constant); |
| 42 ConstantExpression getConstant(Node node); | 42 ConstantExpression getConstant(Node node); |
| 43 | 43 |
| 44 /// Returns the [FunctionElement] defined by [node]. | 44 /// Returns the [FunctionElement] defined by [node]. |
| 45 FunctionElement getFunctionDefinition(FunctionExpression node); | 45 FunctionElement getFunctionDefinition(FunctionExpression node); |
| 46 | 46 |
| 47 /// Returns target constructor for the redirecting factory body [node]. | 47 /// Returns target constructor for the redirecting factory body [node]. |
| 48 ConstructorElement getRedirectingTargetConstructor( | 48 ConstructorElement getRedirectingTargetConstructor( |
| 49 RedirectingFactoryBody node); | 49 RedirectingFactoryBody node); |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Returns [:true:] if [node] is a type literal. | 52 * Returns [:true:] if [node] is a type literal. |
| 53 * | 53 * |
| 54 * Resolution marks this by setting the type on the node to be the | 54 * Resolution marks this by setting the type on the node to be the |
| 55 * type that the literal refers to. | 55 * type that the literal refers to. |
| 56 */ | 56 */ |
| 57 bool isTypeLiteral(Send node); | 57 bool isTypeLiteral(Send node); |
| 58 | 58 |
| 59 /// Returns the type that the type literal [node] refers to. | 59 /// Returns the type that the type literal [node] refers to. |
| 60 DartType getTypeLiteralType(Send node); | 60 ResolutionDartType getTypeLiteralType(Send node); |
| 61 | 61 |
| 62 /// Returns a list of nodes that potentially mutate [element] anywhere in its | 62 /// Returns a list of nodes that potentially mutate [element] anywhere in its |
| 63 /// scope. | 63 /// scope. |
| 64 List<Node> getPotentialMutations(VariableElement element); | 64 List<Node> getPotentialMutations(VariableElement element); |
| 65 | 65 |
| 66 /// Returns a list of nodes that potentially mutate [element] in [node]. | 66 /// Returns a list of nodes that potentially mutate [element] in [node]. |
| 67 List<Node> getPotentialMutationsIn(Node node, VariableElement element); | 67 List<Node> getPotentialMutationsIn(Node node, VariableElement element); |
| 68 | 68 |
| 69 /// Returns a list of nodes that potentially mutate [element] in a closure. | 69 /// Returns a list of nodes that potentially mutate [element] in a closure. |
| 70 List<Node> getPotentialMutationsInClosure(VariableElement element); | 70 List<Node> getPotentialMutationsInClosure(VariableElement element); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 /// `true` if the [analyzedElement]'s source code contains a [TryStatement]. | 87 /// `true` if the [analyzedElement]'s source code contains a [TryStatement]. |
| 88 bool get containsTryStatement; | 88 bool get containsTryStatement; |
| 89 | 89 |
| 90 /// Returns native data stored with [node]. | 90 /// Returns native data stored with [node]. |
| 91 getNativeData(Node node); | 91 getNativeData(Node node); |
| 92 } | 92 } |
| 93 | 93 |
| 94 class TreeElementMapping extends TreeElements { | 94 class TreeElementMapping extends TreeElements { |
| 95 final AnalyzableElement analyzedElement; | 95 final AnalyzableElement analyzedElement; |
| 96 Map<Spannable, Selector> _selectors; | 96 Map<Spannable, Selector> _selectors; |
| 97 Map<Node, DartType> _types; | 97 Map<Node, ResolutionDartType> _types; |
| 98 | 98 |
| 99 Map<Node, DartType> _typesCache; | 99 Map<Node, ResolutionDartType> _typesCache; |
| 100 Map<Node, DartType> get typesCache => _typesCache ??= <Node, DartType>{}; | 100 Map<Node, ResolutionDartType> get typesCache => |
| 101 _typesCache ??= <Node, ResolutionDartType>{}; |
| 101 | 102 |
| 102 Setlet<SourceSpan> _superUses; | 103 Setlet<SourceSpan> _superUses; |
| 103 Map<Node, ConstantExpression> _constants; | 104 Map<Node, ConstantExpression> _constants; |
| 104 Map<VariableElement, List<Node>> _potentiallyMutated; | 105 Map<VariableElement, List<Node>> _potentiallyMutated; |
| 105 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; | 106 Map<Node, Map<VariableElement, List<Node>>> _potentiallyMutatedIn; |
| 106 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; | 107 Map<VariableElement, List<Node>> _potentiallyMutatedInClosure; |
| 107 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; | 108 Map<Node, Map<VariableElement, List<Node>>> _accessedByClosureIn; |
| 108 Maplet<Send, SendStructure> _sendStructureMap; | 109 Maplet<Send, SendStructure> _sendStructureMap; |
| 109 Maplet<NewExpression, NewStructure> _newStructureMap; | 110 Maplet<NewExpression, NewStructure> _newStructureMap; |
| 110 bool containsTryStatement = false; | 111 bool containsTryStatement = false; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return _newStructureMap[node]; | 170 return _newStructureMap[node]; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void setNewStructure(NewExpression node, NewStructure newStructure) { | 173 void setNewStructure(NewExpression node, NewStructure newStructure) { |
| 173 if (_newStructureMap == null) { | 174 if (_newStructureMap == null) { |
| 174 _newStructureMap = new Maplet<NewExpression, NewStructure>(); | 175 _newStructureMap = new Maplet<NewExpression, NewStructure>(); |
| 175 } | 176 } |
| 176 _newStructureMap[node] = newStructure; | 177 _newStructureMap[node] = newStructure; |
| 177 } | 178 } |
| 178 | 179 |
| 179 void setType(Node node, DartType type) { | 180 void setType(Node node, ResolutionDartType type) { |
| 180 if (_types == null) { | 181 if (_types == null) { |
| 181 _types = new Maplet<Node, DartType>(); | 182 _types = new Maplet<Node, ResolutionDartType>(); |
| 182 } | 183 } |
| 183 _types[node] = type; | 184 _types[node] = type; |
| 184 } | 185 } |
| 185 | 186 |
| 186 @override | 187 @override |
| 187 DartType getType(Node node) => _types != null ? _types[node] : null; | 188 ResolutionDartType getType(Node node) => _types != null ? _types[node] : null; |
| 188 | 189 |
| 189 @override | 190 @override |
| 190 Iterable<SourceSpan> get superUses { | 191 Iterable<SourceSpan> get superUses { |
| 191 return _superUses != null ? _superUses : const <SourceSpan>[]; | 192 return _superUses != null ? _superUses : const <SourceSpan>[]; |
| 192 } | 193 } |
| 193 | 194 |
| 194 void addSuperUse(SourceSpan span) { | 195 void addSuperUse(SourceSpan span) { |
| 195 if (_superUses == null) { | 196 if (_superUses == null) { |
| 196 _superUses = new Setlet<SourceSpan>(); | 197 _superUses = new Setlet<SourceSpan>(); |
| 197 } | 198 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ConstantExpression getConstant(Node node) { | 254 ConstantExpression getConstant(Node node) { |
| 254 return _constants != null ? _constants[node] : null; | 255 return _constants != null ? _constants[node] : null; |
| 255 } | 256 } |
| 256 | 257 |
| 257 @override | 258 @override |
| 258 bool isTypeLiteral(Send node) { | 259 bool isTypeLiteral(Send node) { |
| 259 return getType(node) != null; | 260 return getType(node) != null; |
| 260 } | 261 } |
| 261 | 262 |
| 262 @override | 263 @override |
| 263 DartType getTypeLiteralType(Send node) { | 264 ResolutionDartType getTypeLiteralType(Send node) { |
| 264 return getType(node); | 265 return getType(node); |
| 265 } | 266 } |
| 266 | 267 |
| 267 @override | 268 @override |
| 268 List<Node> getPotentialMutations(VariableElement element) { | 269 List<Node> getPotentialMutations(VariableElement element) { |
| 269 if (_potentiallyMutated == null) return const <Node>[]; | 270 if (_potentiallyMutated == null) return const <Node>[]; |
| 270 List<Node> mutations = _potentiallyMutated[element]; | 271 List<Node> mutations = _potentiallyMutated[element]; |
| 271 if (mutations == null) return const <Node>[]; | 272 if (mutations == null) return const <Node>[]; |
| 272 return mutations; | 273 return mutations; |
| 273 } | 274 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 _nativeData = <Node, dynamic>{}; | 428 _nativeData = <Node, dynamic>{}; |
| 428 } | 429 } |
| 429 _nativeData[node] = nativeData; | 430 _nativeData[node] = nativeData; |
| 430 } | 431 } |
| 431 | 432 |
| 432 @override | 433 @override |
| 433 dynamic getNativeData(Node node) { | 434 dynamic getNativeData(Node node) { |
| 434 return _nativeData != null ? _nativeData[node] : null; | 435 return _nativeData != null ? _nativeData[node] : null; |
| 435 } | 436 } |
| 436 } | 437 } |
| OLD | NEW |