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.js.enqueue; | 5 library dart2js.js.enqueue; |
6 | 6 |
7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
8 | 8 |
9 import '../common/tasks.dart' show CompilerTask; | 9 import '../common/tasks.dart' show CompilerTask; |
10 import '../common/work.dart' show WorkItem; | 10 import '../common/work.dart' show WorkItem; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 _impactVisitor = new EnqueuerImplImpactVisitor(this); | 59 _impactVisitor = new EnqueuerImplImpactVisitor(this); |
60 } | 60 } |
61 | 61 |
62 CodegenWorldBuilder get worldBuilder => _worldBuilder; | 62 CodegenWorldBuilder get worldBuilder => _worldBuilder; |
63 | 63 |
64 bool get queueIsEmpty => _queue.isEmpty; | 64 bool get queueIsEmpty => _queue.isEmpty; |
65 | 65 |
66 @override | 66 @override |
67 void checkQueueIsEmpty() { | 67 void checkQueueIsEmpty() { |
68 if (_queue.isNotEmpty) { | 68 if (_queue.isNotEmpty) { |
69 throw new SpannableAssertionFailure( | 69 failedAt(_queue.first.element, "$name queue is not empty."); |
70 _queue.first.element, "$name queue is not empty."); | |
71 } | 70 } |
72 } | 71 } |
73 | 72 |
74 /// Returns [:true:] if this enqueuer is the resolution enqueuer. | 73 /// Returns [:true:] if this enqueuer is the resolution enqueuer. |
75 bool get isResolutionQueue => false; | 74 bool get isResolutionQueue => false; |
76 | 75 |
77 /// Create a [WorkItem] for [entity] and add it to the work list if it has not | 76 /// Create a [WorkItem] for [entity] and add it to the work list if it has not |
78 /// already been processed. | 77 /// already been processed. |
79 void _addToWorkList(MemberEntity entity) { | 78 void _addToWorkList(MemberEntity entity) { |
80 if (_processedEntities.contains(entity)) return; | 79 if (_processedEntities.contains(entity)) return; |
81 | 80 |
82 WorkItem workItem = _workItemBuilder.createWorkItem(entity); | 81 WorkItem workItem = _workItemBuilder.createWorkItem(entity); |
83 if (workItem == null) return; | 82 if (workItem == null) return; |
84 | 83 |
85 if (queueIsClosed) { | 84 if (queueIsClosed) { |
86 throw new SpannableAssertionFailure( | 85 failedAt(entity, "Codegen work list is closed. Trying to add $entity"); |
87 entity, "Codegen work list is closed. Trying to add $entity"); | |
88 } | 86 } |
89 | 87 |
90 applyImpact(listener.registerUsedElement(entity)); | 88 applyImpact(listener.registerUsedElement(entity)); |
91 _queue.add(workItem); | 89 _queue.add(workItem); |
92 } | 90 } |
93 | 91 |
94 void applyImpact(WorldImpact worldImpact, {var impactSource}) { | 92 void applyImpact(WorldImpact worldImpact, {var impactSource}) { |
95 if (worldImpact.isEmpty) return; | 93 if (worldImpact.isEmpty) return; |
96 impactStrategy.visitImpact( | 94 impactStrategy.visitImpact( |
97 impactSource, worldImpact, _impactVisitor, impactUse); | 95 impactSource, worldImpact, _impactVisitor, impactUse); |
98 } | 96 } |
99 | 97 |
100 void _registerInstantiatedType(InterfaceType type, | 98 void _registerInstantiatedType(InterfaceType type, |
101 {bool mirrorUsage: false, bool nativeUsage: false}) { | 99 {bool mirrorUsage: false, bool nativeUsage: false}) { |
102 task.measure(() { | 100 task.measure(() { |
103 _worldBuilder.registerTypeInstantiation(type, _applyClassUse, | 101 _worldBuilder.registerTypeInstantiation(type, _applyClassUse, |
104 byMirrors: mirrorUsage); | 102 byMirrors: mirrorUsage); |
105 listener.registerInstantiatedType(type, nativeUsage: nativeUsage); | 103 listener.registerInstantiatedType(type, nativeUsage: nativeUsage); |
106 }); | 104 }); |
107 } | 105 } |
108 | 106 |
109 bool checkNoEnqueuedInvokedInstanceMethods( | 107 bool checkNoEnqueuedInvokedInstanceMethods( |
110 ElementEnvironment elementEnvironment) { | 108 ElementEnvironment elementEnvironment) { |
111 return strategy.checkEnqueuerConsistency(this, elementEnvironment); | 109 return strategy.checkEnqueuerConsistency(this, elementEnvironment); |
112 } | 110 } |
113 | 111 |
114 void checkClass(ClassEntity cls) { | 112 void checkClass(ClassEntity cls) { |
115 _worldBuilder.processClassMembers(cls, (MemberEntity member, useSet) { | 113 _worldBuilder.processClassMembers(cls, (MemberEntity member, useSet) { |
116 if (useSet.isNotEmpty) { | 114 if (useSet.isNotEmpty) { |
117 throw new SpannableAssertionFailure(member, | 115 failedAt(member, |
118 'Unenqueued use of $member: ${useSet.iterable(MemberUse.values)}'); | 116 'Unenqueued use of $member: ${useSet.iterable(MemberUse.values)}'); |
119 } | 117 } |
120 }); | 118 }); |
121 } | 119 } |
122 | 120 |
123 /// Callback for applying the use of a [cls]. | 121 /// Callback for applying the use of a [cls]. |
124 void _applyClassUse(ClassEntity cls, EnumSet<ClassUse> useSet) { | 122 void _applyClassUse(ClassEntity cls, EnumSet<ClassUse> useSet) { |
125 if (useSet.contains(ClassUse.INSTANTIATED)) { | 123 if (useSet.contains(ClassUse.INSTANTIATED)) { |
126 _recentClasses.add(cls); | 124 _recentClasses.add(cls); |
127 _worldBuilder.processClassMembers(cls, _applyMemberUse); | 125 _worldBuilder.processClassMembers(cls, _applyMemberUse); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 String toString() => 'Enqueuer($name)'; | 254 String toString() => 'Enqueuer($name)'; |
257 | 255 |
258 ImpactUseCase get impactUse => IMPACT_USE; | 256 ImpactUseCase get impactUse => IMPACT_USE; |
259 | 257 |
260 @override | 258 @override |
261 Iterable<MemberEntity> get processedEntities => _processedEntities; | 259 Iterable<MemberEntity> get processedEntities => _processedEntities; |
262 | 260 |
263 @override | 261 @override |
264 Iterable<ClassEntity> get processedClasses => _worldBuilder.processedClasses; | 262 Iterable<ClassEntity> get processedClasses => _worldBuilder.processedClasses; |
265 } | 263 } |
OLD | NEW |