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

Side by Side Diff: pkg/compiler/lib/src/common/resolution.dart

Issue 2531303002: Decouple WorkItem from Compiler (Closed)
Patch Set: Created 4 years 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
OLDNEW
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.common.resolution; 5 library dart2js.common.resolution;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../compile_time_constants.dart'; 8 import '../compile_time_constants.dart';
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/expressions.dart' show ConstantExpression; 10 import '../constants/expressions.dart' show ConstantExpression;
(...skipping 23 matching lines...) Expand all
34 import '../patch_parser.dart'; 34 import '../patch_parser.dart';
35 import '../resolution/resolution.dart'; 35 import '../resolution/resolution.dart';
36 import '../tree/tree.dart' show Send, TypeAnnotation; 36 import '../tree/tree.dart' show Send, TypeAnnotation;
37 import '../universe/call_structure.dart' show CallStructure; 37 import '../universe/call_structure.dart' show CallStructure;
38 import '../universe/world_impact.dart' show WorldImpact; 38 import '../universe/world_impact.dart' show WorldImpact;
39 import '../universe/feature.dart'; 39 import '../universe/feature.dart';
40 import 'backend_api.dart'; 40 import 'backend_api.dart';
41 import 'work.dart' show WorkItem; 41 import 'work.dart' show WorkItem;
42 42
43 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. 43 /// [WorkItem] used exclusively by the [ResolutionEnqueuer].
44 class ResolutionWorkItem extends WorkItem { 44 abstract class ResolutionWorkItem implements WorkItem {
45 factory ResolutionWorkItem(Resolution resolution, AstElement element) =
46 _ResolutionWorkItem;
47 }
48
49 class _ResolutionWorkItem extends WorkItem implements ResolutionWorkItem {
45 bool _isAnalyzed = false; 50 bool _isAnalyzed = false;
51 final Resolution resolution;
46 52
47 ResolutionWorkItem(AstElement element) : super(element); 53 _ResolutionWorkItem(this.resolution, AstElement element) : super(element);
48 54
49 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { 55 WorldImpact run() {
50 WorldImpact impact = compiler.analyze(this, world); 56 assert(invariant(element, !_isAnalyzed,
57 message: 'Element ${element} has already been analyzed'));
58 WorldImpact impact = resolution.computeWorldImpact(element);
51 _isAnalyzed = true; 59 _isAnalyzed = true;
52 return impact; 60 return impact;
53 } 61 }
54
55 bool get isAnalyzed => _isAnalyzed;
56 } 62 }
57 63
58 class ResolutionImpact extends WorldImpact { 64 class ResolutionImpact extends WorldImpact {
59 const ResolutionImpact(); 65 const ResolutionImpact();
60 66
61 Iterable<Feature> get features => const <Feature>[]; 67 Iterable<Feature> get features => const <Feature>[];
62 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; 68 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[];
63 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; 69 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[];
64 Iterable<String> get constSymbolNames => const <String>[]; 70 Iterable<String> get constSymbolNames => const <String>[];
65 Iterable<ConstantExpression> get constantLiterals => 71 Iterable<ConstantExpression> get constantLiterals =>
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 209
204 void forgetElement(Element element); 210 void forgetElement(Element element);
205 211
206 /// Returns `true` if [value] is the top-level [proxy] annotation from the 212 /// Returns `true` if [value] is the top-level [proxy] annotation from the
207 /// core library. 213 /// core library.
208 bool isProxyConstant(ConstantValue value); 214 bool isProxyConstant(ConstantValue value);
209 } 215 }
210 216
211 /// A container of commonly used dependencies for tasks that involve parsing. 217 /// A container of commonly used dependencies for tasks that involve parsing.
212 abstract class ParsingContext { 218 abstract class ParsingContext {
213 factory ParsingContext( 219 factory ParsingContext(DiagnosticReporter reporter, ParserTask parser,
214 DiagnosticReporter reporter, 220 PatchParserTask patchParser, Backend backend) = _ParsingContext;
215 ParserTask parser,
216 PatchParserTask patchParser,
217 Backend backend) = _ParsingContext;
218 221
219 DiagnosticReporter get reporter; 222 DiagnosticReporter get reporter;
220 ParserTask get parser; 223 ParserTask get parser;
221 PatchParserTask get patchParser; 224 PatchParserTask get patchParser;
222 225
223 /// Use [patchParser] directly instead. 226 /// Use [patchParser] directly instead.
224 @deprecated 227 @deprecated
225 void parsePatchClass(ClassElement cls); 228 void parsePatchClass(ClassElement cls);
226 229
227 /// Use [parser] and measure directly instead. 230 /// Use [parser] and measure directly instead.
228 @deprecated 231 @deprecated
229 measure(f()); 232 measure(f());
230 233
231 /// Get the [ScannerOptions] to scan the given [element]. 234 /// Get the [ScannerOptions] to scan the given [element].
232 ScannerOptions getScannerOptionsFor(Element element); 235 ScannerOptions getScannerOptionsFor(Element element);
233 } 236 }
234 237
235 class _ParsingContext implements ParsingContext { 238 class _ParsingContext implements ParsingContext {
236 final DiagnosticReporter reporter; 239 final DiagnosticReporter reporter;
237 final ParserTask parser; 240 final ParserTask parser;
238 final PatchParserTask patchParser; 241 final PatchParserTask patchParser;
239 final Backend backend; 242 final Backend backend;
240 243
241 _ParsingContext(this.reporter, this.parser, 244 _ParsingContext(this.reporter, this.parser, this.patchParser, this.backend);
242 this.patchParser, this.backend);
243 245
244 @override 246 @override
245 measure(f()) => parser.measure(f); 247 measure(f()) => parser.measure(f);
246 248
247 @override 249 @override
248 void parsePatchClass(ClassElement cls) { 250 void parsePatchClass(ClassElement cls) {
249 patchParser.measure(() { 251 patchParser.measure(() {
250 if (cls.isPatch) { 252 if (cls.isPatch) {
251 patchParser.parsePatchClassNode(cls); 253 patchParser.parsePatchClassNode(cls);
252 } 254 }
253 }); 255 });
254 } 256 }
255 257
256 @override 258 @override
257 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( 259 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions(
258 canUseNative: backend.canLibraryUseNative(element.library)); 260 canUseNative: backend.canLibraryUseNative(element.library));
259 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698