| 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 library universe; | 5 library universe; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../compiler.dart' show | 10 import '../compiler.dart' show |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // [_instantiatedTypes] sets should be merged. | 117 // [_instantiatedTypes] sets should be merged. |
| 118 final Set<ClassElement> _directlyInstantiatedClasses = | 118 final Set<ClassElement> _directlyInstantiatedClasses = |
| 119 new Set<ClassElement>(); | 119 new Set<ClassElement>(); |
| 120 | 120 |
| 121 /// The set of all directly instantiated types, that is, the types of the | 121 /// The set of all directly instantiated types, that is, the types of the |
| 122 /// directly instantiated classes. | 122 /// directly instantiated classes. |
| 123 /// | 123 /// |
| 124 /// See [_directlyInstantiatedClasses]. | 124 /// See [_directlyInstantiatedClasses]. |
| 125 final Set<DartType> _instantiatedTypes = new Set<DartType>(); | 125 final Set<DartType> _instantiatedTypes = new Set<DartType>(); |
| 126 | 126 |
| 127 /// The set of all instantiated classes, either directly, as superclasses or | |
| 128 /// as supertypes. | |
| 129 /// | |
| 130 /// Invariant: Elements are declaration elements. | |
| 131 final Set<ClassElement> _allInstantiatedClasses = new Set<ClassElement>(); | |
| 132 | |
| 133 /// Classes implemented by directly instantiated classes. | 127 /// Classes implemented by directly instantiated classes. |
| 134 final Set<ClassElement> _implementedClasses = new Set<ClassElement>(); | 128 final Set<ClassElement> _implementedClasses = new Set<ClassElement>(); |
| 135 | 129 |
| 136 /// The set of all referenced static fields. | 130 /// The set of all referenced static fields. |
| 137 /// | 131 /// |
| 138 /// Invariant: Elements are declaration elements. | 132 /// Invariant: Elements are declaration elements. |
| 139 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); | 133 final Set<FieldElement> allReferencedStaticFields = new Set<FieldElement>(); |
| 140 | 134 |
| 141 /** | 135 /** |
| 142 * Documentation wanted -- johnniwinther | 136 * Documentation wanted -- johnniwinther |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Universe(this.selectorConstraintsStrategy); | 193 Universe(this.selectorConstraintsStrategy); |
| 200 | 194 |
| 201 /// All directly instantiated classes, that is, classes with a generative | 195 /// All directly instantiated classes, that is, classes with a generative |
| 202 /// constructor that has been called directly and not only through a | 196 /// constructor that has been called directly and not only through a |
| 203 /// super-call. | 197 /// super-call. |
| 204 // TODO(johnniwinther): Improve semantic precision. | 198 // TODO(johnniwinther): Improve semantic precision. |
| 205 Iterable<ClassElement> get directlyInstantiatedClasses { | 199 Iterable<ClassElement> get directlyInstantiatedClasses { |
| 206 return _directlyInstantiatedClasses; | 200 return _directlyInstantiatedClasses; |
| 207 } | 201 } |
| 208 | 202 |
| 209 /// All instantiated classes, either directly, as superclasses or as | |
| 210 /// supertypes. | |
| 211 // TODO(johnniwinther): Improve semantic precision. | |
| 212 Iterable<ClassElement> get allInstantiatedClasses { | |
| 213 return _allInstantiatedClasses; | |
| 214 } | |
| 215 | |
| 216 /// All directly instantiated types, that is, the types of the directly | 203 /// All directly instantiated types, that is, the types of the directly |
| 217 /// instantiated classes. | 204 /// instantiated classes. |
| 218 /// | 205 /// |
| 219 /// See [directlyInstantiatedClasses]. | 206 /// See [directlyInstantiatedClasses]. |
| 220 // TODO(johnniwinther): Improve semantic precision. | 207 // TODO(johnniwinther): Improve semantic precision. |
| 221 Iterable<DartType> get instantiatedTypes => _instantiatedTypes; | 208 Iterable<DartType> get instantiatedTypes => _instantiatedTypes; |
| 222 | 209 |
| 223 /// Returns `true` if [cls] is considered to be instantiated, either directly, | |
| 224 /// through subclasses. | |
| 225 // TODO(johnniwinther): Improve semantic precision. | |
| 226 bool isInstantiated(ClassElement cls) { | |
| 227 return _allInstantiatedClasses.contains(cls.declaration); | |
| 228 } | |
| 229 | |
| 230 /// Returns `true` if [cls] is considered to be implemented by an | 210 /// Returns `true` if [cls] is considered to be implemented by an |
| 231 /// instantiated class, either directly, through subclasses or through | 211 /// instantiated class, either directly, through subclasses or through |
| 232 /// subtypes. The latter case only contains spurious information from | 212 /// subtypes. The latter case only contains spurious information from |
| 233 /// instantiations through factory constructors and mixins. | 213 /// instantiations through factory constructors and mixins. |
| 234 // TODO(johnniwinther): Improve semantic precision. | 214 // TODO(johnniwinther): Improve semantic precision. |
| 235 bool isImplemented(ClassElement cls) { | 215 bool isImplemented(ClassElement cls) { |
| 236 return _implementedClasses.contains(cls.declaration); | 216 return _implementedClasses.contains(cls.declaration); |
| 237 } | 217 } |
| 238 | 218 |
| 239 /// Register [type] as (directly) instantiated. | 219 /// Register [type] as (directly) instantiated. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 264 // TODO(johnniwinther): Replace this by separate more specific mappings that | 244 // TODO(johnniwinther): Replace this by separate more specific mappings that |
| 265 // include the type arguments. | 245 // include the type arguments. |
| 266 if (_implementedClasses.add(cls)) { | 246 if (_implementedClasses.add(cls)) { |
| 267 onImplemented(cls); | 247 onImplemented(cls); |
| 268 cls.allSupertypes.forEach((InterfaceType supertype) { | 248 cls.allSupertypes.forEach((InterfaceType supertype) { |
| 269 if (_implementedClasses.add(supertype.element)) { | 249 if (_implementedClasses.add(supertype.element)) { |
| 270 onImplemented(supertype.element); | 250 onImplemented(supertype.element); |
| 271 } | 251 } |
| 272 }); | 252 }); |
| 273 } | 253 } |
| 274 while (cls != null) { | |
| 275 if (!_allInstantiatedClasses.add(cls)) { | |
| 276 return; | |
| 277 } | |
| 278 cls = cls.superclass; | |
| 279 } | |
| 280 } | 254 } |
| 281 | 255 |
| 282 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, | 256 bool _hasMatchingSelector(Map<Selector, SelectorConstraints> selectors, |
| 283 Element member, | 257 Element member, |
| 284 World world) { | 258 World world) { |
| 285 if (selectors == null) return false; | 259 if (selectors == null) return false; |
| 286 for (Selector selector in selectors.keys) { | 260 for (Selector selector in selectors.keys) { |
| 287 if (selector.appliesUnnamed(member, world)) { | 261 if (selector.appliesUnnamed(member, world)) { |
| 288 SelectorConstraints masks = selectors[selector]; | 262 SelectorConstraints masks = selectors[selector]; |
| 289 if (masks.applies(member, selector, world)) { | 263 if (masks.applies(member, selector, world)) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 370 } |
| 397 } | 371 } |
| 398 | 372 |
| 399 void forgetElement(Element element, Compiler compiler) { | 373 void forgetElement(Element element, Compiler compiler) { |
| 400 allClosures.remove(element); | 374 allClosures.remove(element); |
| 401 slowDirectlyNestedClosures(element).forEach(compiler.forgetElement); | 375 slowDirectlyNestedClosures(element).forEach(compiler.forgetElement); |
| 402 closurizedMembers.remove(element); | 376 closurizedMembers.remove(element); |
| 403 fieldSetters.remove(element); | 377 fieldSetters.remove(element); |
| 404 fieldGetters.remove(element); | 378 fieldGetters.remove(element); |
| 405 _directlyInstantiatedClasses.remove(element); | 379 _directlyInstantiatedClasses.remove(element); |
| 406 _allInstantiatedClasses.remove(element); | |
| 407 if (element is ClassElement) { | 380 if (element is ClassElement) { |
| 408 assert(invariant( | 381 assert(invariant( |
| 409 element, element.thisType.isRaw, | 382 element, element.thisType.isRaw, |
| 410 message: 'Generic classes not supported (${element.thisType}).')); | 383 message: 'Generic classes not supported (${element.thisType}).')); |
| 411 _instantiatedTypes | 384 _instantiatedTypes |
| 412 ..remove(element.rawType) | 385 ..remove(element.rawType) |
| 413 ..remove(element.thisType); | 386 ..remove(element.thisType); |
| 414 } | 387 } |
| 415 } | 388 } |
| 416 | 389 |
| 417 // TODO(ahe): Replace this method with something that is O(1), for example, | 390 // TODO(ahe): Replace this method with something that is O(1), for example, |
| 418 // by using a map. | 391 // by using a map. |
| 419 List<LocalFunctionElement> slowDirectlyNestedClosures(Element element) { | 392 List<LocalFunctionElement> slowDirectlyNestedClosures(Element element) { |
| 420 // Return new list to guard against concurrent modifications. | 393 // Return new list to guard against concurrent modifications. |
| 421 return new List<LocalFunctionElement>.from( | 394 return new List<LocalFunctionElement>.from( |
| 422 allClosures.where((LocalFunctionElement closure) { | 395 allClosures.where((LocalFunctionElement closure) { |
| 423 return closure.executableContext == element; | 396 return closure.executableContext == element; |
| 424 })); | 397 })); |
| 425 } | 398 } |
| 426 } | 399 } |
| OLD | NEW |