| 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 dart2js.enqueue; | 5 library dart2js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import 'common/resolution.dart' show Resolution; | 9 import 'common/resolution.dart' show Resolution; |
| 10 import 'common/tasks.dart' show CompilerTask; | 10 import 'common/tasks.dart' show CompilerTask; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 /// Apply the [worldImpact] to this enqueuer. If the [impactSource] is | 84 /// Apply the [worldImpact] to this enqueuer. If the [impactSource] is |
| 85 /// provided the impact strategy will remove it from the element impact cache, | 85 /// provided the impact strategy will remove it from the element impact cache, |
| 86 /// if it is no longer needed. | 86 /// if it is no longer needed. |
| 87 void applyImpact(WorldImpact worldImpact, {var impactSource}); | 87 void applyImpact(WorldImpact worldImpact, {var impactSource}); |
| 88 bool checkNoEnqueuedInvokedInstanceMethods(); | 88 bool checkNoEnqueuedInvokedInstanceMethods(); |
| 89 | 89 |
| 90 /// Check the enqueuer queue is empty or fail otherwise. | 90 /// Check the enqueuer queue is empty or fail otherwise. |
| 91 void checkQueueIsEmpty(); | 91 void checkQueueIsEmpty(); |
| 92 void logSummary(void log(String message)); | 92 void logSummary(void log(String message)); |
| 93 | 93 |
| 94 Iterable<Entity> get processedEntities; | 94 Iterable<MemberEntity> get processedEntities; |
| 95 | 95 |
| 96 Iterable<ClassEntity> get processedClasses; | 96 Iterable<ClassEntity> get processedClasses; |
| 97 } | 97 } |
| 98 | 98 |
| 99 abstract class EnqueuerListener { | 99 abstract class EnqueuerListener { |
| 100 /// Called to instruct to the backend that [type] has been instantiated. | 100 /// Called to instruct to the backend that [type] has been instantiated. |
| 101 void registerInstantiatedType(InterfaceType type, | 101 void registerInstantiatedType(InterfaceType type, |
| 102 {bool isGlobal: false, bool nativeUsage: false}); | 102 {bool isGlobal: false, bool nativeUsage: false}); |
| 103 | 103 |
| 104 /// Called to notify to the backend that a class is being instantiated. Any | 104 /// Called to notify to the backend that a class is being instantiated. Any |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 bool _recentConstants = false; | 198 bool _recentConstants = false; |
| 199 final ResolutionEnqueuerWorldBuilder _worldBuilder; | 199 final ResolutionEnqueuerWorldBuilder _worldBuilder; |
| 200 final WorkItemBuilder _workItemBuilder; | 200 final WorkItemBuilder _workItemBuilder; |
| 201 final DiagnosticReporter _reporter; | 201 final DiagnosticReporter _reporter; |
| 202 | 202 |
| 203 bool queueIsClosed = false; | 203 bool queueIsClosed = false; |
| 204 | 204 |
| 205 WorldImpactVisitor _impactVisitor; | 205 WorldImpactVisitor _impactVisitor; |
| 206 | 206 |
| 207 /// All declaration elements that have been processed by the resolver. | 207 /// All declaration elements that have been processed by the resolver. |
| 208 final Set<Entity> _processedEntities = new Set<Entity>(); | 208 final Set<MemberEntity> _processedEntities = new Set<MemberEntity>(); |
| 209 | 209 |
| 210 final Queue<WorkItem> _queue = new Queue<WorkItem>(); | 210 final Queue<WorkItem> _queue = new Queue<WorkItem>(); |
| 211 | 211 |
| 212 /// Queue of deferred resolution actions to execute when the resolution queue | 212 /// Queue of deferred resolution actions to execute when the resolution queue |
| 213 /// has been emptied. | 213 /// has been emptied. |
| 214 final Queue<DeferredAction> _deferredQueue = new Queue<DeferredAction>(); | 214 final Queue<DeferredAction> _deferredQueue = new Queue<DeferredAction>(); |
| 215 | 215 |
| 216 ResolutionEnqueuer(this.task, this._options, this._reporter, this.strategy, | 216 ResolutionEnqueuer(this.task, this._options, this._reporter, this.strategy, |
| 217 this.listener, this._worldBuilder, this._workItemBuilder, | 217 this.listener, this._worldBuilder, this._workItemBuilder, |
| 218 [this.name = 'resolution enqueuer']) { | 218 [this.name = 'resolution enqueuer']) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 _recentConstants); | 398 _recentConstants); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void logSummary(void log(String message)) { | 401 void logSummary(void log(String message)) { |
| 402 log('Resolved ${_processedEntities.length} elements.'); | 402 log('Resolved ${_processedEntities.length} elements.'); |
| 403 listener.logSummary(log); | 403 listener.logSummary(log); |
| 404 } | 404 } |
| 405 | 405 |
| 406 String toString() => 'Enqueuer($name)'; | 406 String toString() => 'Enqueuer($name)'; |
| 407 | 407 |
| 408 Iterable<Entity> get processedEntities => _processedEntities; | 408 Iterable<MemberEntity> get processedEntities => _processedEntities; |
| 409 | 409 |
| 410 ImpactUseCase get impactUse => IMPACT_USE; | 410 ImpactUseCase get impactUse => IMPACT_USE; |
| 411 | 411 |
| 412 bool get isResolutionQueue => true; | 412 bool get isResolutionQueue => true; |
| 413 | 413 |
| 414 /// Returns `true` if [element] has been processed by the resolution enqueuer. | 414 /// Returns `true` if [element] has been processed by the resolution enqueuer. |
| 415 // TODO(johnniwinther): Remove this together with the resolver. | 415 // TODO(johnniwinther): Remove this together with the resolver. |
| 416 bool hasBeenProcessed(MemberElement element) { | 416 bool hasBeenProcessed(MemberElement element) { |
| 417 assert(invariant(element, element == element.analyzableElement.declaration, | 417 assert(invariant(element, element == element.analyzableElement.declaration, |
| 418 message: "Unexpected element $element")); | 418 message: "Unexpected element $element")); |
| 419 return _processedEntities.contains(element); | 419 return _processedEntities.contains(element); |
| 420 } | 420 } |
| 421 | 421 |
| 422 /// Registers [entity] as processed by the resolution enqueuer. Used only for | 422 /// Registers [entity] as processed by the resolution enqueuer. Used only for |
| 423 /// testing. | 423 /// testing. |
| 424 void registerProcessedElementInternal(Entity entity) { | 424 void registerProcessedElementInternal(MemberEntity entity) { |
| 425 _processedEntities.add(entity); | 425 _processedEntities.add(entity); |
| 426 } | 426 } |
| 427 | 427 |
| 428 /// Create a [WorkItem] for [entity] and add it to the work list if it has not | 428 /// Create a [WorkItem] for [entity] and add it to the work list if it has not |
| 429 /// already been processed. | 429 /// already been processed. |
| 430 void _addToWorkList(MemberEntity entity) { | 430 void _addToWorkList(MemberEntity entity) { |
| 431 if (_processedEntities.contains(entity)) return; | 431 if (_processedEntities.contains(entity)) return; |
| 432 WorkItem workItem = _workItemBuilder.createWorkItem(entity); | 432 WorkItem workItem = _workItemBuilder.createWorkItem(entity); |
| 433 if (workItem == null) return; | 433 if (workItem == null) return; |
| 434 | 434 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 @override | 609 @override |
| 610 WorkItem createWorkItem(MemberElement element) { | 610 WorkItem createWorkItem(MemberElement element) { |
| 611 assert(invariant(element, element.isDeclaration)); | 611 assert(invariant(element, element.isDeclaration)); |
| 612 if (element.isMalformed) return null; | 612 if (element.isMalformed) return null; |
| 613 | 613 |
| 614 assert(invariant(element, element is AnalyzableElement, | 614 assert(invariant(element, element is AnalyzableElement, |
| 615 message: 'Element $element is not analyzable.')); | 615 message: 'Element $element is not analyzable.')); |
| 616 return _resolution.createWorkItem(element); | 616 return _resolution.createWorkItem(element); |
| 617 } | 617 } |
| 618 } | 618 } |
| OLD | NEW |