| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.resolution.registry; | 5 library dart2js.resolution.registry; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart' show | 8 import '../common/backend_api.dart' show |
| 9 Backend, | 9 Backend, |
| 10 ForeignResolver; | 10 ForeignResolver; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 world.registerGetOfStaticFunction(element); | 72 world.registerGetOfStaticFunction(element); |
| 73 } | 73 } |
| 74 | 74 |
| 75 @override | 75 @override |
| 76 void registerInstantiation(InterfaceType type) { | 76 void registerInstantiation(InterfaceType type) { |
| 77 world.registerInstantiatedType(type); | 77 world.registerInstantiatedType(type); |
| 78 } | 78 } |
| 79 | 79 |
| 80 @override | 80 @override |
| 81 void registerStaticInvocation(Element element) { | 81 void registerStaticInvocation(Element element) { |
| 82 registerDependency(element); | |
| 83 world.registerStaticUse(element); | 82 world.registerStaticUse(element); |
| 84 } | 83 } |
| 85 | 84 |
| 86 String toString() => 'EagerRegistry for ${mapping.analyzedElement}'; | 85 String toString() => 'EagerRegistry for ${mapping.analyzedElement}'; |
| 87 } | 86 } |
| 88 | 87 |
| 89 class _ResolutionWorldImpact implements ResolutionImpact { | 88 class _ResolutionWorldImpact extends ResolutionImpact { |
| 90 final Registry registry; | 89 final String name; |
| 91 // TODO(johnniwinther): Do we benefit from lazy initialization of the | 90 // TODO(johnniwinther): Do we benefit from lazy initialization of the |
| 92 // [Setlet]s? | 91 // [Setlet]s? |
| 93 Setlet<UniverseSelector> _dynamicInvocations; | 92 Setlet<UniverseSelector> _dynamicInvocations; |
| 94 Setlet<UniverseSelector> _dynamicGetters; | 93 Setlet<UniverseSelector> _dynamicGetters; |
| 95 Setlet<UniverseSelector> _dynamicSetters; | 94 Setlet<UniverseSelector> _dynamicSetters; |
| 96 Setlet<InterfaceType> _instantiatedTypes; | 95 Setlet<InterfaceType> _instantiatedTypes; |
| 97 Setlet<Element> _staticUses; | 96 Setlet<Element> _staticUses; |
| 98 Setlet<DartType> _isChecks; | 97 Setlet<DartType> _isChecks; |
| 99 Setlet<DartType> _asCasts; | 98 Setlet<DartType> _asCasts; |
| 100 Setlet<DartType> _checkedModeChecks; | 99 Setlet<DartType> _checkedModeChecks; |
| 101 Setlet<MethodElement> _closurizedFunctions; | 100 Setlet<MethodElement> _closurizedFunctions; |
| 102 Setlet<LocalFunctionElement> _closures; | 101 Setlet<LocalFunctionElement> _closures; |
| 103 Setlet<Feature> _features; | 102 Setlet<Feature> _features; |
| 104 // TODO(johnniwinther): This seems to be a union of other sets. | 103 // TODO(johnniwinther): This seems to be a union of other sets. |
| 105 Setlet<DartType> _requiredTypes; | 104 Setlet<DartType> _requiredTypes; |
| 106 Setlet<MapLiteralUse> _mapLiterals; | 105 Setlet<MapLiteralUse> _mapLiterals; |
| 107 Setlet<ListLiteralUse> _listLiterals; | 106 Setlet<ListLiteralUse> _listLiterals; |
| 108 Setlet<DartType> _typeLiterals; | 107 Setlet<DartType> _typeLiterals; |
| 109 Setlet<String> _constSymbolNames; | 108 Setlet<String> _constSymbolNames; |
| 110 | 109 |
| 111 _ResolutionWorldImpact(Compiler compiler, TreeElementMapping mapping) | 110 _ResolutionWorldImpact(this.name); |
| 112 : this.registry = new EagerRegistry(compiler, mapping); | |
| 113 | |
| 114 void registerDependency(Element element) { | |
| 115 assert(element != null); | |
| 116 registry.registerDependency(element); | |
| 117 } | |
| 118 | 111 |
| 119 void registerDynamicGetter(UniverseSelector selector) { | 112 void registerDynamicGetter(UniverseSelector selector) { |
| 120 assert(selector != null); | 113 assert(selector != null); |
| 121 if (_dynamicGetters == null) { | 114 if (_dynamicGetters == null) { |
| 122 _dynamicGetters = new Setlet<UniverseSelector>(); | 115 _dynamicGetters = new Setlet<UniverseSelector>(); |
| 123 } | 116 } |
| 124 _dynamicGetters.add(selector); | 117 _dynamicGetters.add(selector); |
| 125 } | 118 } |
| 126 | 119 |
| 127 @override | 120 @override |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 _features = new Setlet<Feature>(); | 318 _features = new Setlet<Feature>(); |
| 326 } | 319 } |
| 327 _features.add(feature); | 320 _features.add(feature); |
| 328 } | 321 } |
| 329 | 322 |
| 330 @override | 323 @override |
| 331 Iterable<Feature> get features { | 324 Iterable<Feature> get features { |
| 332 return _features != null ? _features : const <Feature>[]; | 325 return _features != null ? _features : const <Feature>[]; |
| 333 } | 326 } |
| 334 | 327 |
| 335 String toString() => '$registry'; | 328 String toString() => '_ResolutionWorldImpact($name)'; |
| 336 } | 329 } |
| 337 | 330 |
| 338 /// [ResolutionRegistry] collects all resolution information. It stores node | 331 /// [ResolutionRegistry] collects all resolution information. It stores node |
| 339 /// related information in a [TreeElements] mapping and registers calls with | 332 /// related information in a [TreeElements] mapping and registers calls with |
| 340 /// [Backend], [World] and [Enqueuer]. | 333 /// [Backend], [World] and [Enqueuer]. |
| 341 // TODO(johnniwinther): Split this into an interface and implementation class. | 334 // TODO(johnniwinther): Split this into an interface and implementation class. |
| 342 class ResolutionRegistry extends Registry { | 335 class ResolutionRegistry extends Registry { |
| 343 final Compiler compiler; | 336 final Compiler compiler; |
| 344 final TreeElementMapping mapping; | 337 final TreeElementMapping mapping; |
| 345 final _ResolutionWorldImpact worldImpact; | 338 final _ResolutionWorldImpact worldImpact; |
| 346 | 339 |
| 347 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) | 340 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) |
| 348 : this.compiler = compiler, | 341 : this.compiler = compiler, |
| 349 this.mapping = mapping, | 342 this.mapping = mapping, |
| 350 this.worldImpact = new _ResolutionWorldImpact(compiler, mapping); | 343 this.worldImpact = new _ResolutionWorldImpact( |
| 344 mapping.analyzedElement.toString()); |
| 351 | 345 |
| 352 bool get isForResolution => true; | 346 bool get isForResolution => true; |
| 353 | 347 |
| 354 ResolutionEnqueuer get world => compiler.enqueuer.resolution; | 348 ResolutionEnqueuer get world => compiler.enqueuer.resolution; |
| 355 | 349 |
| 356 World get universe => compiler.world; | 350 World get universe => compiler.world; |
| 357 | 351 |
| 358 Backend get backend => compiler.backend; | 352 Backend get backend => compiler.backend; |
| 359 | 353 |
| 360 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; | 354 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 519 |
| 526 ////////////////////////////////////////////////////////////////////////////// | 520 ////////////////////////////////////////////////////////////////////////////// |
| 527 // Various Backend/Enqueuer/World registration. | 521 // Various Backend/Enqueuer/World registration. |
| 528 ////////////////////////////////////////////////////////////////////////////// | 522 ////////////////////////////////////////////////////////////////////////////// |
| 529 | 523 |
| 530 void registerStaticUse(Element element) { | 524 void registerStaticUse(Element element) { |
| 531 worldImpact.registerStaticUse(element); | 525 worldImpact.registerStaticUse(element); |
| 532 } | 526 } |
| 533 | 527 |
| 534 void registerImplicitSuperCall(FunctionElement superConstructor) { | 528 void registerImplicitSuperCall(FunctionElement superConstructor) { |
| 535 registerDependency(superConstructor); | 529 registerStaticUse(superConstructor); |
| 536 } | 530 } |
| 537 | 531 |
| 538 // TODO(johnniwinther): Remove this. | 532 // TODO(johnniwinther): Remove this. |
| 539 // Use [registerInstantiatedType] of `rawType` instead. | 533 // Use [registerInstantiatedType] of `rawType` instead. |
| 540 @deprecated | 534 @deprecated |
| 541 void registerInstantiatedClass(ClassElement element) { | 535 void registerInstantiatedClass(ClassElement element) { |
| 542 element.ensureResolved(compiler.resolution); | 536 element.ensureResolved(compiler.resolution); |
| 543 registerInstantiatedType(element.rawType); | 537 registerInstantiatedType(element.rawType); |
| 544 } | 538 } |
| 545 | 539 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 void registerMixinUse(MixinApplicationElement mixinApplication, | 690 void registerMixinUse(MixinApplicationElement mixinApplication, |
| 697 ClassElement mixin) { | 691 ClassElement mixin) { |
| 698 universe.registerMixinUse(mixinApplication, mixin); | 692 universe.registerMixinUse(mixinApplication, mixin); |
| 699 } | 693 } |
| 700 | 694 |
| 701 void registerThrowExpression() { | 695 void registerThrowExpression() { |
| 702 worldImpact.registerFeature(Feature.THROW_EXPRESSION); | 696 worldImpact.registerFeature(Feature.THROW_EXPRESSION); |
| 703 } | 697 } |
| 704 | 698 |
| 705 void registerStaticInvocation(Element element) { | 699 void registerStaticInvocation(Element element) { |
| 706 // TODO(johnniwinther): Increase precision of [registerStaticUse] and | 700 // TODO(johnniwinther): Increase precision of [registerStaticUse]. |
| 707 // [registerDependency]. | |
| 708 if (element == null) return; | 701 if (element == null) return; |
| 709 registerStaticUse(element); | 702 registerStaticUse(element); |
| 710 } | 703 } |
| 711 | 704 |
| 712 void registerInstantiation(InterfaceType type) { | 705 void registerInstantiation(InterfaceType type) { |
| 713 registerInstantiatedType(type); | 706 registerInstantiatedType(type); |
| 714 } | 707 } |
| 715 | 708 |
| 716 void registerAssert(bool hasMessage) { | 709 void registerAssert(bool hasMessage) { |
| 717 worldImpact.registerFeature( | 710 worldImpact.registerFeature( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 @override | 764 @override |
| 772 void registerInstantiatedType(InterfaceType type) { | 765 void registerInstantiatedType(InterfaceType type) { |
| 773 registry.registerInstantiatedType(type); | 766 registry.registerInstantiatedType(type); |
| 774 } | 767 } |
| 775 | 768 |
| 776 @override | 769 @override |
| 777 DartType resolveTypeFromString(Node node, String typeName) { | 770 DartType resolveTypeFromString(Node node, String typeName) { |
| 778 return visitor.resolveTypeFromString(node, typeName); | 771 return visitor.resolveTypeFromString(node, typeName); |
| 779 } | 772 } |
| 780 } | 773 } |
| OLD | NEW |