Chromium Code Reviews| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 } | 114 } |
| 100 | 115 |
| 101 bool hasAnyUserDefinedGetter(Selector selector) { | 116 bool hasAnyUserDefinedGetter(Selector selector) { |
| 102 return userDefinedGetters.hasAnyElementMatchingSelector(selector); | 117 return userDefinedGetters.hasAnyElementMatchingSelector(selector); |
| 103 } | 118 } |
| 104 | 119 |
| 105 bool hasAnyUserDefinedSetter(Selector selector) { | 120 bool hasAnyUserDefinedSetter(Selector selector) { |
| 106 return userDefinedSetters.hasAnyElementMatchingSelector(selector); | 121 return userDefinedSetters.hasAnyElementMatchingSelector(selector); |
| 107 } | 122 } |
| 108 | 123 |
| 124 // Returnw whether a subclass of [superClass] implements [type]. | |
|
ahe
2012/10/29 14:22:14
// -> ///
Returnw -> Return
superclass is one word
ngeoffray
2012/10/29 14:37:53
Done.
| |
| 125 bool hasOneSubclassThatImplements(ClassElement superClass, Type type) { | |
|
sra1
2012/10/29 13:46:10
By 'One' do you mean exactly 1, or 'Any'?
Perhaps
ngeoffray
2012/10/29 14:05:38
Good point. Changed 'One' to 'Any' to make it cons
ahe
2012/10/29 14:22:14
superclass is one word
ngeoffray
2012/10/29 14:37:53
Done.
| |
| 126 Set<ClassElement> typesImplementedBySubclasses = | |
| 127 typesImplementedBySubclasses[superClass]; | |
| 128 if (typesImplementedBySubclasses == null) return false; | |
| 129 return typesImplementedBySubclasses.contains(type); | |
| 130 } | |
| 131 | |
| 132 | |
| 109 void registerUsedElement(Element element) { | 133 void registerUsedElement(Element element) { |
| 110 if (element.isMember()) { | 134 if (element.isMember()) { |
| 111 if (element.isGetter()) { | 135 if (element.isGetter()) { |
| 112 // We're collecting user-defined getters to let the codegen know which | 136 // We're collecting user-defined getters to let the codegen know which |
| 113 // field accesses might have side effects. | 137 // field accesses might have side effects. |
| 114 recordUserDefinedGetter(element); | 138 recordUserDefinedGetter(element); |
| 115 } else if (element.isSetter()) { | 139 } else if (element.isSetter()) { |
| 116 recordUserDefinedSetter(element); | 140 recordUserDefinedSetter(element); |
| 117 } | 141 } |
| 118 } | 142 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 final SourceString name; | 210 final SourceString name; |
| 187 | 211 |
| 188 MemberSet(SourceString this.name) : elements = new Set<Element>(); | 212 MemberSet(SourceString this.name) : elements = new Set<Element>(); |
| 189 | 213 |
| 190 void add(Element element) { | 214 void add(Element element) { |
| 191 elements.add(element); | 215 elements.add(element); |
| 192 } | 216 } |
| 193 | 217 |
| 194 bool get isEmpty => elements.isEmpty; | 218 bool get isEmpty => elements.isEmpty; |
| 195 } | 219 } |
| OLD | NEW |