| 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<ClassElement>> typesImplementedBySubclasses; |
| 10 final Set<ClassElement> classesNeedingRti; | 11 final Set<ClassElement> classesNeedingRti; |
| 11 final Map<ClassElement, Set<ClassElement>> rtiDependencies; | 12 final Map<ClassElement, Set<ClassElement>> rtiDependencies; |
| 12 final FunctionSet userDefinedGetters; | 13 final FunctionSet userDefinedGetters; |
| 13 final FunctionSet userDefinedSetters; | 14 final FunctionSet userDefinedSetters; |
| 14 | 15 |
| 15 World(Compiler compiler) | 16 World(Compiler compiler) |
| 16 : subtypes = new Map<ClassElement, Set<ClassElement>>(), | 17 : subtypes = new Map<ClassElement, Set<ClassElement>>(), |
| 18 typesImplementedBySubclasses = |
| 19 new Map<ClassElement, Set<ClassElement>>(), |
| 17 userDefinedGetters = new FunctionSet(compiler), | 20 userDefinedGetters = new FunctionSet(compiler), |
| 18 userDefinedSetters = new FunctionSet(compiler), | 21 userDefinedSetters = new FunctionSet(compiler), |
| 19 classesNeedingRti = new Set<ClassElement>(), | 22 classesNeedingRti = new Set<ClassElement>(), |
| 20 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), | 23 rtiDependencies = new Map<ClassElement, Set<ClassElement>>(), |
| 21 this.compiler = compiler; | 24 this.compiler = compiler; |
| 22 | 25 |
| 23 void populate() { | 26 void populate() { |
| 24 void addSubtypes(ClassElement cls) { | 27 void addSubtypes(ClassElement cls) { |
| 25 if (cls.resolutionState != STATE_DONE) { | 28 if (cls.resolutionState != STATE_DONE) { |
| 26 compiler.internalErrorOnElement( | 29 compiler.internalErrorOnElement( |
| 27 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); | 30 cls, 'Class "${cls.name.slowToString()}" is not resolved.'); |
| 28 } | 31 } |
| 32 |
| 29 for (DartType type in cls.allSupertypes) { | 33 for (DartType type in cls.allSupertypes) { |
| 30 Set<Element> subtypesOfCls = | 34 Set<Element> subtypesOfCls = |
| 31 subtypes.putIfAbsent(type.element, () => new Set<ClassElement>()); | 35 subtypes.putIfAbsent(type.element, () => new Set<ClassElement>()); |
| 32 subtypesOfCls.add(cls); | 36 subtypesOfCls.add(cls); |
| 33 } | 37 } |
| 38 |
| 39 // Walk through the superclasses, and record the types |
| 40 // implemented by that type on the superclasses. |
| 41 DartType type = cls.supertype; |
| 42 while (type != null) { |
| 43 Set<Element> typesImplementedBySubclassesOfCls = |
| 44 typesImplementedBySubclasses.putIfAbsent( |
| 45 type.element, () => new Set<ClassElement>()); |
| 46 typesImplementedBySubclassesOfCls.addAll(cls.allSupertypes); |
| 47 type = type.element.supertype; |
| 48 } |
| 34 } | 49 } |
| 35 | 50 |
| 36 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); | 51 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); |
| 37 | 52 |
| 38 // Find the classes that need runtime type information. Such | 53 // Find the classes that need runtime type information. Such |
| 39 // classes are: | 54 // classes are: |
| 40 // (1) used in a is check with type variables, | 55 // (1) used in a is check with type variables, |
| 41 // (2) dependencies of classes in (1), | 56 // (2) dependencies of classes in (1), |
| 42 // (3) subclasses of (2) and (3). | 57 // (3) subclasses of (2) and (3). |
| 43 | 58 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 final SourceString name; | 201 final SourceString name; |
| 187 | 202 |
| 188 MemberSet(SourceString this.name) : elements = new Set<Element>(); | 203 MemberSet(SourceString this.name) : elements = new Set<Element>(); |
| 189 | 204 |
| 190 void add(Element element) { | 205 void add(Element element) { |
| 191 elements.add(element); | 206 elements.add(element); |
| 192 } | 207 } |
| 193 | 208 |
| 194 bool get isEmpty => elements.isEmpty; | 209 bool get isEmpty => elements.isEmpty; |
| 195 } | 210 } |
| OLD | NEW |