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 part of types; | 5 part of types; |
6 | 6 |
7 class UnionTypeMask implements TypeMask { | 7 class UnionTypeMask implements TypeMask { |
8 final Iterable<FlatTypeMask> disjointMasks; | 8 final Iterable<FlatTypeMask> disjointMasks; |
9 | 9 |
10 static const int MAX_UNION_LENGTH = 4; | 10 static const int MAX_UNION_LENGTH = 4; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 for (FlatTypeMask flatOther in other.disjointMasks) { | 159 for (FlatTypeMask flatOther in other.disjointMasks) { |
160 intersections.add(current.intersection(flatOther, classWorld)); | 160 intersections.add(current.intersection(flatOther, classWorld)); |
161 } | 161 } |
162 } else { | 162 } else { |
163 intersections.add(current.intersection(other, classWorld)); | 163 intersections.add(current.intersection(other, classWorld)); |
164 } | 164 } |
165 } | 165 } |
166 return new TypeMask.unionOf(intersections, classWorld); | 166 return new TypeMask.unionOf(intersections, classWorld); |
167 } | 167 } |
168 | 168 |
| 169 bool isDisjoint(TypeMask other, ClassWorld classWorld) { |
| 170 for (var current in disjointMasks) { |
| 171 if (!current.isDisjoint(other, classWorld)) return false; |
| 172 } |
| 173 return true; |
| 174 } |
| 175 |
169 TypeMask nullable() { | 176 TypeMask nullable() { |
170 if (isNullable) return this; | 177 if (isNullable) return this; |
171 List<FlatTypeMask> newList = new List<FlatTypeMask>.from(disjointMasks); | 178 List<FlatTypeMask> newList = new List<FlatTypeMask>.from(disjointMasks); |
172 newList[0] = newList[0].nullable(); | 179 newList[0] = newList[0].nullable(); |
173 return new UnionTypeMask._internal(newList); | 180 return new UnionTypeMask._internal(newList); |
174 } | 181 } |
175 | 182 |
176 TypeMask nonNullable() { | 183 TypeMask nonNullable() { |
177 if (!isNullable) return this; | 184 if (!isNullable) return this; |
178 Iterable<FlatTypeMask> newIterable = | 185 Iterable<FlatTypeMask> newIterable = |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 int get hashCode { | 365 int get hashCode { |
359 int hashCode = isNullable ? 86 : 43; | 366 int hashCode = isNullable ? 86 : 43; |
360 // The order of the masks in [disjointMasks] must not affect the | 367 // The order of the masks in [disjointMasks] must not affect the |
361 // hashCode. | 368 // hashCode. |
362 for (var mask in disjointMasks) { | 369 for (var mask in disjointMasks) { |
363 hashCode = (hashCode ^ mask.nonNullable().hashCode) & 0x3fffffff; | 370 hashCode = (hashCode ^ mask.nonNullable().hashCode) & 0x3fffffff; |
364 } | 371 } |
365 return hashCode; | 372 return hashCode; |
366 } | 373 } |
367 } | 374 } |
OLD | NEW |