| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 inferrer_visitor; | 5 library inferrer_visitor; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' hide Selector, TypedSelector; | 7 import '../dart2jslib.dart' hide Selector, TypedSelector; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 bool isNull(T type); | 42 bool isNull(T type); |
| 43 Selector newTypedSelector(T receiver, Selector selector); | 43 Selector newTypedSelector(T receiver, Selector selector); |
| 44 | 44 |
| 45 T allocateList(T type, | 45 T allocateList(T type, |
| 46 Node node, | 46 Node node, |
| 47 Element enclosing, | 47 Element enclosing, |
| 48 [T elementType, int length]); | 48 [T elementType, int length]); |
| 49 | 49 |
| 50 T allocateMap(T keyType, T valueType, T type); | 50 T allocateMap(T keyType, T valueType, T type); |
| 51 | 51 |
| 52 T allocateClosure(Node node, Element element); |
| 53 |
| 52 /** | 54 /** |
| 53 * Returns the least upper bound between [firstType] and | 55 * Returns the least upper bound between [firstType] and |
| 54 * [secondType]. | 56 * [secondType]. |
| 55 */ | 57 */ |
| 56 T computeLUB(T firstType, T secondType); | 58 T computeLUB(T firstType, T secondType); |
| 57 | 59 |
| 58 /** | 60 /** |
| 59 * Returns the intersection between [T] and [annotation]. | 61 * Returns the intersection between [T] and [annotation]. |
| 60 * [isNullable] indicates whether the annotation implies a null | 62 * [isNullable] indicates whether the annotation implies a null |
| 61 * type. | 63 * type. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 266 } |
| 265 | 267 |
| 266 void forEach(void f(T type)) { | 268 void forEach(void f(T type)) { |
| 267 positional.forEach(f); | 269 positional.forEach(f); |
| 268 named.values.forEach(f); | 270 named.values.forEach(f); |
| 269 } | 271 } |
| 270 | 272 |
| 271 bool every(bool f(T type)) { | 273 bool every(bool f(T type)) { |
| 272 return positional.every(f) && named.values.every(f); | 274 return positional.every(f) && named.values.every(f); |
| 273 } | 275 } |
| 276 |
| 277 bool contains(T type) { |
| 278 return positional.contains(type) || named.containsValue(type); |
| 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 276 abstract class MinimalInferrerEngine<T> { | 282 abstract class MinimalInferrerEngine<T> { |
| 277 /** | 283 /** |
| 278 * Returns the type of [element]. | 284 * Returns the type of [element]. |
| 279 */ | 285 */ |
| 280 T typeOfElement(Element element); | 286 T typeOfElement(Element element); |
| 281 | 287 |
| 282 /** | 288 /** |
| 283 * Records that [node] sets non-final field [element] to be of type | 289 * Records that [node] sets non-final field [element] to be of type |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 if (_superType != null) return _superType; | 733 if (_superType != null) return _superType; |
| 728 return _superType = types.nonNullExact( | 734 return _superType = types.nonNullExact( |
| 729 outermostElement.getEnclosingClass().superclass); | 735 outermostElement.getEnclosingClass().superclass); |
| 730 } | 736 } |
| 731 | 737 |
| 732 T visitIdentifier(Identifier node) { | 738 T visitIdentifier(Identifier node) { |
| 733 if (node.isThis()) { | 739 if (node.isThis()) { |
| 734 return thisType; | 740 return thisType; |
| 735 } else if (node.isSuper()) { | 741 } else if (node.isSuper()) { |
| 736 return superType; | 742 return superType; |
| 743 } else { |
| 744 Element element = elements[node]; |
| 745 if (Elements.isLocal(element)) { |
| 746 return locals.use(element); |
| 747 } |
| 737 } | 748 } |
| 738 } | 749 } |
| 739 | 750 |
| 740 void potentiallyAddIsCheck(Send node) { | 751 void potentiallyAddIsCheck(Send node) { |
| 741 if (!accumulateIsChecks) return; | 752 if (!accumulateIsChecks) return; |
| 742 if (!Elements.isLocal(elements[node.receiver])) return; | 753 if (!Elements.isLocal(elements[node.receiver])) return; |
| 743 isChecks.add(node); | 754 isChecks.add(node); |
| 744 } | 755 } |
| 745 | 756 |
| 746 void potentiallyAddNullCheck(Send node, Node receiver) { | 757 void potentiallyAddNullCheck(Send node, Node receiver) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 return type; | 1165 return type; |
| 1155 } | 1166 } |
| 1156 | 1167 |
| 1157 T visitCascade(Cascade node) { | 1168 T visitCascade(Cascade node) { |
| 1158 // Ignore the result of the cascade send and return the type of the cascade | 1169 // Ignore the result of the cascade send and return the type of the cascade |
| 1159 // receiver. | 1170 // receiver. |
| 1160 visit(node.expression); | 1171 visit(node.expression); |
| 1161 return cascadeReceiverStack.removeLast(); | 1172 return cascadeReceiverStack.removeLast(); |
| 1162 } | 1173 } |
| 1163 } | 1174 } |
| OLD | NEW |