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.type_mask_system; | 5 library dart2js.type_mask_system; |
6 | 6 |
7 import '../common/names.dart' show Selectors, Identifiers; | 7 import '../common/names.dart' show Selectors, Identifiers; |
8 import '../compiler.dart' as dart2js show Compiler; | 8 import '../compiler.dart' as dart2js show Compiler; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../dart_types.dart' as types; | 10 import '../dart_types.dart' as types; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 } | 126 } |
127 | 127 |
128 TypeMask getFieldType(FieldElement field) { | 128 TypeMask getFieldType(FieldElement field) { |
129 return inferrer.getGuaranteedTypeOfElement(field); | 129 return inferrer.getGuaranteedTypeOfElement(field); |
130 } | 130 } |
131 | 131 |
132 TypeMask join(TypeMask a, TypeMask b) { | 132 TypeMask join(TypeMask a, TypeMask b) { |
133 return a.union(b, classWorld); | 133 return a.union(b, classWorld); |
134 } | 134 } |
135 | 135 |
| 136 TypeMask intersection(TypeMask a, TypeMask b) { |
| 137 if (a == null) return b; |
| 138 if (b == null) return a; |
| 139 return a.intersection(b, classWorld); |
| 140 } |
| 141 |
136 TypeMask getTypeOf(ConstantValue constant) { | 142 TypeMask getTypeOf(ConstantValue constant) { |
137 return computeTypeMask(inferrer.compiler, constant); | 143 return computeTypeMask(inferrer.compiler, constant); |
138 } | 144 } |
139 | 145 |
140 // Returns the constant value if a TypeMask represents a single value. | 146 // Returns the constant value if a TypeMask represents a single value. |
141 // Returns `null` if [mask] is not a constant. | 147 // Returns `null` if [mask] is not a constant. |
142 ConstantValue getConstantOf(TypeMask mask) { | 148 ConstantValue getConstantOf(TypeMask mask) { |
143 if (!mask.isValue) return null; | 149 if (!mask.isValue) return null; |
144 if (mask.isNullable) return null; // e.g. 'true or null'. | 150 if (mask.isNullable) return null; // e.g. 'true or null'. |
145 ValueTypeMask valueMask = mask; | 151 ValueTypeMask valueMask = mask; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 389 |
384 /// The length of something of [type], or `null` if unknown. | 390 /// The length of something of [type], or `null` if unknown. |
385 int getContainerLength(TypeMask type) { | 391 int getContainerLength(TypeMask type) { |
386 if (type is ContainerTypeMask) { | 392 if (type is ContainerTypeMask) { |
387 return type.length; | 393 return type.length; |
388 } else { | 394 } else { |
389 return null; | 395 return null; |
390 } | 396 } |
391 } | 397 } |
392 } | 398 } |
OLD | NEW |