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 js_backend.backend; | 5 part of js_backend.backend; |
6 | 6 |
7 /// For each class, stores the possible class subtype tests that could succeed. | 7 /// For each class, stores the possible class subtype tests that could succeed. |
8 abstract class TypeChecks { | 8 abstract class TypeChecks { |
9 /// Get the set of checks required for class [element]. | 9 /// Get the set of checks required for class [element]. |
10 Iterable<TypeCheck> operator [](ClassElement element); | 10 Iterable<TypeCheck> operator [](ClassElement element); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // If there are no classes that use their variables in checks, there is | 174 // If there are no classes that use their variables in checks, there is |
175 // nothing to do. | 175 // nothing to do. |
176 if (classesUsingChecks.isEmpty) return; | 176 if (classesUsingChecks.isEmpty) return; |
177 Set<DartType> instantiatedTypes = universe.instantiatedTypes; | 177 Set<DartType> instantiatedTypes = universe.instantiatedTypes; |
178 if (cannotDetermineInstantiatedTypesPrecisely) { | 178 if (cannotDetermineInstantiatedTypesPrecisely) { |
179 for (DartType type in instantiatedTypes) { | 179 for (DartType type in instantiatedTypes) { |
180 if (type.kind != TypeKind.INTERFACE) continue; | 180 if (type.kind != TypeKind.INTERFACE) continue; |
181 InterfaceType interface = type; | 181 InterfaceType interface = type; |
182 do { | 182 do { |
183 for (DartType argument in interface.typeArguments) { | 183 for (DartType argument in interface.typeArguments) { |
184 universe.registerIsCheck(argument, compiler.resolution); | 184 universe.registerIsCheck(argument); |
185 } | 185 } |
186 interface = interface.element.supertype; | 186 interface = interface.element.supertype; |
187 } while (interface != null && !instantiatedTypes.contains(interface)); | 187 } while (interface != null && !instantiatedTypes.contains(interface)); |
188 } | 188 } |
189 } else { | 189 } else { |
190 // Find all instantiated types that are a subtype of a class that uses | 190 // Find all instantiated types that are a subtype of a class that uses |
191 // one of its type arguments in an is-check and add the arguments to the | 191 // one of its type arguments in an is-check and add the arguments to the |
192 // set of is-checks. | 192 // set of is-checks. |
193 // TODO(karlklose): replace this with code that uses a subtype lookup | 193 // TODO(karlklose): replace this with code that uses a subtype lookup |
194 // datastructure in the world. | 194 // datastructure in the world. |
195 for (DartType type in instantiatedTypes) { | 195 for (DartType type in instantiatedTypes) { |
196 if (type.kind != TypeKind.INTERFACE) continue; | 196 if (type.kind != TypeKind.INTERFACE) continue; |
197 InterfaceType classType = type; | 197 InterfaceType classType = type; |
198 for (ClassElement cls in classesUsingChecks) { | 198 for (ClassElement cls in classesUsingChecks) { |
199 InterfaceType current = classType; | 199 InterfaceType current = classType; |
200 do { | 200 do { |
201 // We need the type as instance of its superclass anyway, so we just | 201 // We need the type as instance of its superclass anyway, so we just |
202 // try to compute the substitution; if the result is [:null:], the | 202 // try to compute the substitution; if the result is [:null:], the |
203 // classes are not related. | 203 // classes are not related. |
204 InterfaceType instance = current.asInstanceOf(cls); | 204 InterfaceType instance = current.asInstanceOf(cls); |
205 if (instance == null) break; | 205 if (instance == null) break; |
206 for (DartType argument in instance.typeArguments) { | 206 for (DartType argument in instance.typeArguments) { |
207 universe.registerIsCheck(argument, compiler.resolution); | 207 universe.registerIsCheck(argument); |
208 } | 208 } |
209 current = current.element.supertype; | 209 current = current.element.supertype; |
210 } while (current != null && !instantiatedTypes.contains(current)); | 210 } while (current != null && !instantiatedTypes.contains(current)); |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 @override | 216 @override |
217 void computeClassesNeedingRti() { | 217 void computeClassesNeedingRti() { |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 * substition for this check. | 1034 * substition for this check. |
1035 */ | 1035 */ |
1036 class TypeCheck { | 1036 class TypeCheck { |
1037 final ClassElement cls; | 1037 final ClassElement cls; |
1038 final Substitution substitution; | 1038 final Substitution substitution; |
1039 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); | 1039 final int hashCode = _nextHash = (_nextHash + 100003).toUnsigned(30); |
1040 static int _nextHash = 0; | 1040 static int _nextHash = 0; |
1041 | 1041 |
1042 TypeCheck(this.cls, this.substitution); | 1042 TypeCheck(this.cls, this.substitution); |
1043 } | 1043 } |
OLD | NEW |