| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 world_builder; | 5 part of world_builder; |
| 6 | 6 |
| 7 /// [ResolutionEnqueuerWorldBuilder] based on the [Element] model. | 7 /// [ResolutionEnqueuerWorldBuilder] based on the [Element] model. |
| 8 class ElementResolutionWorldBuilder extends ResolutionWorldBuilderBase { | 8 class ElementResolutionWorldBuilder extends ResolutionWorldBuilderBase { |
| 9 /// Used for testing the new more precise computation of instantiated types | 9 /// Used for testing the new more precise computation of instantiated types |
| 10 /// and classes. | 10 /// and classes. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 ClassHierarchyNode node = _ensureClassHierarchyNode(cls); | 177 ClassHierarchyNode node = _ensureClassHierarchyNode(cls); |
| 178 _updateSuperClassHierarchyNodeForClass(node); | 178 _updateSuperClassHierarchyNodeForClass(node); |
| 179 if (directlyInstantiated) { | 179 if (directlyInstantiated) { |
| 180 node.isDirectlyInstantiated = true; | 180 node.isDirectlyInstantiated = true; |
| 181 } | 181 } |
| 182 if (abstractlyInstantiated) { | 182 if (abstractlyInstantiated) { |
| 183 node.isAbstractlyInstantiated = true; | 183 node.isAbstractlyInstantiated = true; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 ClosedWorld closeWorld() { | 187 ClosedWorld closeWorld(DiagnosticReporter reporter) { |
| 188 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses = | 188 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses = |
| 189 new Map<ClassEntity, Set<ClassEntity>>(); | 189 new Map<ClassEntity, Set<ClassEntity>>(); |
| 190 | 190 |
| 191 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` | 191 /// Updates the `isDirectlyInstantiated` and `isIndirectlyInstantiated` |
| 192 /// properties of the [ClassHierarchyNode] for [cls]. | 192 /// properties of the [ClassHierarchyNode] for [cls]. |
| 193 | 193 |
| 194 void addSubtypes(ClassElement cls, InstantiationInfo info) { | 194 void addSubtypes(ClassElement cls, InstantiationInfo info) { |
| 195 if (!info.hasInstantiation) { | 195 if (!info.hasInstantiation) { |
| 196 return; | 196 return; |
| 197 } | 197 } |
| 198 assert(cls.isDeclaration); | 198 assert(cls.isDeclaration); |
| 199 if (!cls.isResolved) { | 199 if (!cls.isResolved) { |
| 200 throw new SpannableAssertionFailure( | 200 reporter.internalError(cls, 'Class "${cls.name}" is not resolved.'); |
| 201 cls, 'Class "${cls.name}" is not resolved.'); | |
| 202 } | 201 } |
| 203 | 202 |
| 204 _updateClassHierarchyNodeForClass(cls, | 203 _updateClassHierarchyNodeForClass(cls, |
| 205 directlyInstantiated: info.isDirectlyInstantiated, | 204 directlyInstantiated: info.isDirectlyInstantiated, |
| 206 abstractlyInstantiated: info.isAbstractlyInstantiated); | 205 abstractlyInstantiated: info.isAbstractlyInstantiated); |
| 207 | 206 |
| 208 // Walk through the superclasses, and record the types | 207 // Walk through the superclasses, and record the types |
| 209 // implemented by that type on the superclasses. | 208 // implemented by that type on the superclasses. |
| 210 ClassElement superclass = cls.superclass; | 209 ClassElement superclass = cls.superclass; |
| 211 while (superclass != null) { | 210 while (superclass != null) { |
| 212 Set<ClassEntity> typesImplementedBySubclassesOfCls = | 211 Set<ClassEntity> typesImplementedBySubclassesOfCls = |
| 213 typesImplementedBySubclasses.putIfAbsent( | 212 typesImplementedBySubclasses.putIfAbsent( |
| 214 superclass, () => new Set<ClassEntity>()); | 213 superclass, () => new Set<ClassEntity>()); |
| 215 for (ResolutionInterfaceType current in cls.allSupertypes) { | 214 for (ResolutionInterfaceType current in cls.allSupertypes) { |
| 216 typesImplementedBySubclassesOfCls.add(current.element); | 215 typesImplementedBySubclassesOfCls.add(current.element); |
| 217 } | 216 } |
| 218 superclass = superclass.superclass; | 217 superclass = superclass.superclass; |
| 219 } | 218 } |
| 220 } | 219 } |
| 221 | 220 |
| 222 // Use the [:seenClasses:] set to include non-instantiated | 221 // Use the [:seenClasses:] set to include non-instantiated |
| 223 // classes: if the superclass of these classes require RTI, then | 222 // classes: if the superclass of these classes require RTI, then |
| 224 // they also need RTI, so that a constructor passes the type | 223 // they also need RTI, so that a constructor passes the type |
| 225 // variables to the super constructor. | 224 // variables to the super constructor. |
| 226 forEachInstantiatedClass(addSubtypes); | 225 forEachInstantiatedClass(addSubtypes); |
| 227 | 226 |
| 228 _closed = true; | 227 _closed = true; |
| 229 return _closedWorldCache = new ClosedWorldImpl( | 228 return _closedWorldCache = new ClosedWorldImpl( |
| 229 backend: _backend, |
| 230 commonElements: _commonElements, | 230 commonElements: _commonElements, |
| 231 constantSystem: _backend.constantSystem, | |
| 232 nativeData: _backend.nativeData, | |
| 233 interceptorData: _backend.interceptorData, | |
| 234 backendUsage: _backend.backendUsage, | |
| 235 resolutionWorldBuilder: this, | 231 resolutionWorldBuilder: this, |
| 236 functionSetBuilder: _allFunctions, | 232 functionSetBuilder: _allFunctions, |
| 237 allTypedefs: _allTypedefs, | 233 allTypedefs: _allTypedefs, |
| 238 mixinUses: _mixinUses, | 234 mixinUses: _mixinUses, |
| 239 typesImplementedBySubclasses: typesImplementedBySubclasses, | 235 typesImplementedBySubclasses: typesImplementedBySubclasses, |
| 240 classHierarchyNodes: _classHierarchyNodes, | 236 classHierarchyNodes: _classHierarchyNodes, |
| 241 classSets: _classSets); | 237 classSets: _classSets); |
| 242 } | 238 } |
| 243 | 239 |
| 244 @override | 240 @override |
| 245 void registerMixinUse( | 241 void registerMixinUse( |
| 246 MixinApplicationElement mixinApplication, ClassElement mixin) { | 242 MixinApplicationElement mixinApplication, ClassElement mixin) { |
| 247 assert(mixin.isDeclaration); | 243 assert(mixin.isDeclaration); |
| 248 super.registerMixinUse(mixinApplication, mixin); | 244 super.registerMixinUse(mixinApplication, mixin); |
| 249 } | 245 } |
| 250 } | 246 } |
| OLD | NEW |