Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: pkg/compiler/lib/src/universe/world_impact.dart

Issue 1467733002: Revert "Remove WorldImpact from caches when no longer needed." (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_backend.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.universe.world_impact; 5 library dart2js.universe.world_impact;
6 6
7 import '../dart_types.dart' show 7 import '../dart_types.dart' show
8 DartType, 8 DartType,
9 InterfaceType; 9 InterfaceType;
10 import '../elements/elements.dart' show 10 import '../elements/elements.dart' show
(...skipping 16 matching lines...) Expand all
27 27
28 Iterable<StaticUse> get staticUses => const <StaticUse>[]; 28 Iterable<StaticUse> get staticUses => const <StaticUse>[];
29 29
30 // TODO(johnniwinther): Replace this by called constructors with type 30 // TODO(johnniwinther): Replace this by called constructors with type
31 // arguments. 31 // arguments.
32 // TODO(johnniwinther): Collect all checked types for checked mode separately 32 // TODO(johnniwinther): Collect all checked types for checked mode separately
33 // to support serialization. 33 // to support serialization.
34 34
35 Iterable<TypeUse> get typeUses => const <TypeUse>[]; 35 Iterable<TypeUse> get typeUses => const <TypeUse>[];
36 36
37 void apply(WorldImpactVisitor visitor) {
38 staticUses.forEach(visitor.visitStaticUse);
39 dynamicUses.forEach(visitor.visitDynamicUse);
40 typeUses.forEach(visitor.visitTypeUse);
41 }
42
43 String toString() => dump(this); 37 String toString() => dump(this);
44 38
45 static String dump(WorldImpact worldImpact) { 39 static String dump(WorldImpact worldImpact) {
46 StringBuffer sb = new StringBuffer(); 40 StringBuffer sb = new StringBuffer();
47 printOn(sb, worldImpact); 41 printOn(sb, worldImpact);
48 return sb.toString(); 42 return sb.toString();
49 } 43 }
50 44
51 static void printOn(StringBuffer sb, WorldImpact worldImpact) { 45 static void printOn(StringBuffer sb, WorldImpact worldImpact) {
52 void add(String title, Iterable iterable) { 46 void add(String title, Iterable iterable) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 _staticUses.addAll(worldImpact.staticUses); 147 _staticUses.addAll(worldImpact.staticUses);
154 } 148 }
155 _staticUses.add(staticUse); 149 _staticUses.add(staticUse);
156 } 150 }
157 151
158 @override 152 @override
159 Iterable<StaticUse> get staticUses { 153 Iterable<StaticUse> get staticUses {
160 return _staticUses != null ? _staticUses : worldImpact.staticUses; 154 return _staticUses != null ? _staticUses : worldImpact.staticUses;
161 } 155 }
162 156
163 void apply(WorldImpactVisitor visitor) {
164 staticUses.forEach(visitor.visitStaticUse);
165 dynamicUses.forEach(visitor.visitDynamicUse);
166 typeUses.forEach(visitor.visitTypeUse);
167 }
168
169 String toString() { 157 String toString() {
170 StringBuffer sb = new StringBuffer(); 158 StringBuffer sb = new StringBuffer();
171 sb.write('TransformedWorldImpact($worldImpact)'); 159 sb.write('TransformedWorldImpact($worldImpact)');
172 WorldImpact.printOn(sb, this); 160 WorldImpact.printOn(sb, this);
173 return sb.toString(); 161 return sb.toString();
174 } 162 }
175 } 163 }
176
177 /// Constant used to denote a specific use of a [WorldImpact].
178 class ImpactUseCase {
179 final String name;
180
181 const ImpactUseCase(this.name);
182
183 String toString() => 'ImpactUseCase($name)';
184 }
185
186 /// Strategy used for processing [WorldImpact] object in various use cases.
187 class ImpactStrategy {
188 const ImpactStrategy();
189
190 /// Applies [impact] to [visitor] for the [impactUseCase] of [element].
191 void visitImpact(Element element,
192 WorldImpact impact,
193 WorldImpactVisitor visitor,
194 ImpactUseCase impactUseCase) {
195 // Apply unconditionally.
196 impact.apply(visitor);
197 }
198 }
199
200 /// Visitor used to process the uses of a [WorldImpact].
201 abstract class WorldImpactVisitor {
202 void visitStaticUse(StaticUse staticUse);
203 void visitDynamicUse(DynamicUse dynamicUse);
204 void visitTypeUse(TypeUse typeUse);
205 }
206
207 // TODO(johnniwinther): Remove these when we get anonymous local classes.
208 typedef void VisitUse<U>(U use);
209
210 class WorldImpactVisitorImpl implements WorldImpactVisitor {
211 final VisitUse<StaticUse> _visitStaticUse;
212 final VisitUse<DynamicUse> _visitDynamicUse;
213 final VisitUse<TypeUse> _visitTypeUse;
214
215 WorldImpactVisitorImpl(
216 {VisitUse<StaticUse> visitStaticUse,
217 VisitUse<DynamicUse> visitDynamicUse,
218 VisitUse<TypeUse> visitTypeUse})
219 : _visitStaticUse = visitStaticUse,
220 _visitDynamicUse = visitDynamicUse,
221 _visitTypeUse = visitTypeUse;
222
223 @override
224 void visitStaticUse(StaticUse use) {
225 if (_visitStaticUse != null) {
226 _visitStaticUse(use);
227 }
228 }
229
230 @override
231 void visitDynamicUse(DynamicUse use) {
232 if (_visitDynamicUse != null) {
233 _visitDynamicUse(use);
234 }
235 }
236
237 @override
238 void visitTypeUse(TypeUse use) {
239 if (_visitTypeUse != null) {
240 _visitTypeUse(use);
241 }
242 }
243 }
244
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/js_backend.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698