OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js; | 5 part of dart2js; |
6 | 6 |
7 class World { | 7 class World { |
8 final Compiler compiler; | 8 final Compiler compiler; |
9 final Map<ClassElement, Set<ClassElement>> subtypes; | 9 final Map<ClassElement, Set<ClassElement>> subtypes; |
10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; | 10 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; |
11 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; | 11 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; |
12 final Set<ClassElement> classesNeedingRti; | 12 final Set<ClassElement> classesNeedingRti; |
13 final Map<ClassElement, Set<ClassElement>> rtiDependencies; | 13 final Map<ClassElement, Set<ClassElement>> rtiDependencies; |
14 final FunctionSet userDefinedGetters; | 14 final FunctionSet userDefinedGetters; |
15 final FunctionSet userDefinedSetters; | 15 final FunctionSet userDefinedSetters; |
| 16 Link<ClassElement> classesUsingTypeVariableTests; |
16 | 17 |
17 World(Compiler compiler) | 18 World(Compiler compiler) |
18 : subtypes = new Map<ClassElement, Set<ClassElement>>(), | 19 : subtypes = new Map<ClassElement, Set<ClassElement>>(), |
19 mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), | 20 mixinUses = new Map<ClassElement, Set<MixinApplicationElement>>(), |
20 typesImplementedBySubclasses = | 21 typesImplementedBySubclasses = |
21 new Map<ClassElement, Set<ClassElement>>(), | 22 new Map<ClassElement, Set<ClassElement>>(), |
22 userDefinedGetters = new FunctionSet(compiler), | 23 userDefinedGetters = new FunctionSet(compiler), |
23 userDefinedSetters = new FunctionSet(compiler), | 24 userDefinedSetters = new FunctionSet(compiler), |
24 classesNeedingRti = new Set<ClassElement>(), | 25 classesNeedingRti = new Set<ClassElement>(), |
25 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), | 26 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), |
| 27 classesUsingTypeVariableTests = const Link<ClassElement>(), |
26 this.compiler = compiler; | 28 this.compiler = compiler; |
27 | 29 |
28 void populate() { | 30 void populate() { |
29 void addSubtypes(ClassElement cls) { | 31 void addSubtypes(ClassElement cls) { |
30 if (cls.resolutionState != STATE_DONE) { | 32 if (cls.resolutionState != STATE_DONE) { |
31 compiler.internalErrorOnElement( | 33 compiler.internalErrorOnElement( |
32 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); | 34 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); |
33 } | 35 } |
34 | 36 |
35 for (DartType type in cls.allSupertypes) { | 37 for (DartType type in cls.allSupertypes) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 MemberSet memberSet = _memberSetFor(type, noSuchMethodSelector); | 214 MemberSet memberSet = _memberSetFor(type, noSuchMethodSelector); |
213 for (Element element in memberSet.elements) { | 215 for (Element element in memberSet.elements) { |
214 ClassElement holder = element.getEnclosingClass(); | 216 ClassElement holder = element.getEnclosingClass(); |
215 if (!identical(holder, compiler.objectClass) && | 217 if (!identical(holder, compiler.objectClass) && |
216 noSuchMethodSelector.applies(element, compiler)) { | 218 noSuchMethodSelector.applies(element, compiler)) { |
217 result.add(holder); | 219 result.add(holder); |
218 } | 220 } |
219 } | 221 } |
220 return result; | 222 return result; |
221 } | 223 } |
| 224 |
| 225 /** |
| 226 * Register a class that contains an is-test against one of it type variables. |
| 227 * The class and all its subtypes need runtime type information and we need to |
| 228 * register the type arguments of their instantiations. |
| 229 */ |
| 230 registerTypeVariableCheck(ClassElement cls) { |
| 231 classesUsingTypeVariableTests = classesUsingTypeVariableTests.prepend(cls); |
| 232 classesNeedingRti.add(cls); |
| 233 } |
222 } | 234 } |
223 | 235 |
224 /** | 236 /** |
225 * A [MemberSet] contains all the possible targets for a selector. | 237 * A [MemberSet] contains all the possible targets for a selector. |
226 */ | 238 */ |
227 class MemberSet { | 239 class MemberSet { |
228 final Set<Element> elements; | 240 final Set<Element> elements; |
229 final SourceString name; | 241 final SourceString name; |
230 | 242 |
231 MemberSet(SourceString this.name) : elements = new Set<Element>(); | 243 MemberSet(SourceString this.name) : elements = new Set<Element>(); |
232 | 244 |
233 void add(Element element) { | 245 void add(Element element) { |
234 elements.add(element); | 246 elements.add(element); |
235 } | 247 } |
236 | 248 |
237 bool get isEmpty => elements.isEmpty; | 249 bool get isEmpty => elements.isEmpty; |
238 } | 250 } |
OLD | NEW |