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