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

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

Issue 2123073003: remove dependency on compiler from resolution (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: respond to comments Created 4 years, 5 months 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/common/backend_api.dart ('k') | pkg/compiler/lib/src/compiler.dart » ('j') | 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) 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 '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../compile_time_constants.dart';
9 import '../constants/expressions.dart' show ConstantExpression; 10 import '../constants/expressions.dart' show ConstantExpression;
11 import '../constants/values.dart' show ConstantValue;
10 import '../core_types.dart' show CoreClasses, CoreTypes; 12 import '../core_types.dart' show CoreClasses, CoreTypes;
11 import '../dart_types.dart' show DartType, InterfaceType, Types; 13 import '../dart_types.dart' show DartType, InterfaceType, Types;
12 import '../elements/elements.dart' 14 import '../elements/elements.dart'
13 show 15 show
14 AstElement, 16 AstElement,
15 ClassElement, 17 ClassElement,
18 ConstructorElement,
16 Element, 19 Element,
17 ExecutableElement, 20 ExecutableElement,
18 FunctionElement, 21 FunctionElement,
19 FunctionSignature, 22 FunctionSignature,
20 LibraryElement, 23 LibraryElement,
21 MetadataAnnotation, 24 MetadataAnnotation,
25 MethodElement,
22 ResolvedAst, 26 ResolvedAst,
23 TypedefElement; 27 TypedefElement;
24 import '../enqueue.dart' show ResolutionEnqueuer; 28 import '../enqueue.dart' show ResolutionEnqueuer;
25 import '../options.dart' show ParserOptions; 29 import '../id_generator.dart';
30 import '../mirrors_used.dart';
31 import '../options.dart' show CompilerOptions, ParserOptions;
26 import '../parser/element_listener.dart' show ScannerOptions; 32 import '../parser/element_listener.dart' show ScannerOptions;
27 import '../parser/parser_task.dart'; 33 import '../parser/parser_task.dart';
28 import '../patch_parser.dart'; 34 import '../patch_parser.dart';
29 import '../tree/tree.dart' show TypeAnnotation; 35 import '../resolution/resolution.dart';
36 import '../tree/tree.dart' show Send, TypeAnnotation;
37 import '../universe/call_structure.dart' show CallStructure;
30 import '../universe/world_impact.dart' show WorldImpact; 38 import '../universe/world_impact.dart' show WorldImpact;
31 import 'backend_api.dart'; 39 import 'backend_api.dart';
32 import 'work.dart' show ItemCompilationContext, WorkItem; 40 import 'work.dart' show ItemCompilationContext, WorkItem;
33 41
34 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. 42 /// [WorkItem] used exclusively by the [ResolutionEnqueuer].
35 class ResolutionWorkItem extends WorkItem { 43 class ResolutionWorkItem extends WorkItem {
36 bool _isAnalyzed = false; 44 bool _isAnalyzed = false;
37 45
38 ResolutionWorkItem( 46 ResolutionWorkItem(
39 AstElement element, ItemCompilationContext compilationContext) 47 AstElement element, ItemCompilationContext compilationContext)
40 : super(element, compilationContext); 48 : super(element, compilationContext);
41 49
42 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { 50 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) {
43 WorldImpact impact = compiler.analyze(this, world); 51 WorldImpact impact = compiler.analyze(this, world);
44 _isAnalyzed = true; 52 _isAnalyzed = true;
45 return impact; 53 return impact;
46 } 54 }
47 55
48 bool get isAnalyzed => _isAnalyzed; 56 bool get isAnalyzed => _isAnalyzed;
49 } 57 }
50 58
51 class ResolutionImpact extends WorldImpact { 59 class ResolutionImpact extends WorldImpact {
52 const ResolutionImpact(); 60 const ResolutionImpact();
53 61
54 Iterable<Feature> get features => const <Feature>[]; 62 Iterable<Feature> get features => const <Feature>[];
55 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; 63 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[];
56 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; 64 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[];
57 Iterable<String> get constSymbolNames => const <String>[]; 65 Iterable<String> get constSymbolNames => const <String>[];
58 Iterable<ConstantExpression> get constantLiterals { 66 Iterable<ConstantExpression> get constantLiterals =>
59 return const <ConstantExpression>[]; 67 const <ConstantExpression>[];
60 }
61 68
62 Iterable<dynamic> get nativeData => const <dynamic>[]; 69 Iterable<dynamic> get nativeData => const <dynamic>[];
63 } 70 }
64 71
65 /// A language feature seen during resolution. 72 /// A language feature seen during resolution.
66 // TODO(johnniwinther): Should mirror usage be part of this? 73 // TODO(johnniwinther): Should mirror usage be part of this?
67 enum Feature { 74 enum Feature {
68 /// Invocation of a generative construction on an abstract class. 75 /// Invocation of a generative construction on an abstract class.
69 ABSTRACT_CLASS_INSTANTIATION, 76 ABSTRACT_CLASS_INSTANTIATION,
70 77
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 /// Interface defining target-specific behavior for resolution. 206 /// Interface defining target-specific behavior for resolution.
200 abstract class Target { 207 abstract class Target {
201 /// Returns `true` if [library] is a target specific library whose members 208 /// Returns `true` if [library] is a target specific library whose members
202 /// have special treatment, such as being allowed to extends blacklisted 209 /// have special treatment, such as being allowed to extends blacklisted
203 /// classes or members being eagerly resolved. 210 /// classes or members being eagerly resolved.
204 bool isTargetSpecificLibrary(LibraryElement element); 211 bool isTargetSpecificLibrary(LibraryElement element);
205 212
206 /// Resolve target specific information for [element] and register it with 213 /// Resolve target specific information for [element] and register it with
207 /// [registry]. 214 /// [registry].
208 void resolveNativeElement(Element element, NativeRegistry registry) {} 215 void resolveNativeElement(Element element, NativeRegistry registry) {}
216
217 /// Processes [element] for resolution and returns the [MethodElement] that
218 /// defines the implementation of [element].
219 MethodElement resolveExternalFunction(MethodElement element) => element;
220
221 /// Called when resolving a call to a foreign function. If a non-null value
222 /// is returned, this is stored as native data for [node] in the resolved
223 /// AST.
224 dynamic resolveForeignCall(Send node, Element element,
225 CallStructure callStructure, ForeignResolver resolver) {
226 return null;
227 }
228
229 /// Returns the default superclass for the given [element] in this target.
230 ClassElement defaultSuperclass(ClassElement element);
231
232 /// Returns `true` if [element] is a native element, that is, that the
233 /// corresponding entity already exists in the target language.
234 bool isNative(Element element) => false;
235
236 /// Returns `true` if [element] is a foreign element, that is, that the
237 /// backend has specialized handling for the element.
238 bool isForeign(Element element) => false;
239
240 /// Returns `true` if this target supports async/await.
241 bool get supportsAsyncAwait => true;
209 } 242 }
210 243
211 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. 244 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`.
212 abstract class Resolution implements Frontend { 245 abstract class Resolution implements Frontend {
213 ParsingContext get parsingContext; 246 ParsingContext get parsingContext;
214 DiagnosticReporter get reporter; 247 DiagnosticReporter get reporter;
215 CoreClasses get coreClasses; 248 CoreClasses get coreClasses;
216 CoreTypes get coreTypes; 249 CoreTypes get coreTypes;
217 Types get types; 250 Types get types;
218 Target get target; 251 Target get target;
252 ResolverTask get resolver;
253 ResolutionEnqueuer get enqueuer;
254 CompilerOptions get options;
255 IdGenerator get idGenerator;
256 ConstantEnvironment get constants;
257 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask;
258
259 // TODO(het): Move all elements into common/elements.dart
260 LibraryElement get coreLibrary;
261 FunctionElement get identicalFunction;
262 ClassElement get mirrorSystemClass;
263 FunctionElement get mirrorSystemGetNameFunction;
264 ConstructorElement get mirrorsUsedConstructor;
265 ConstructorElement get symbolConstructor;
266
267 // TODO(het): This is only referenced in a test...
268 /// The constant for the [proxy] variable defined in dart:core.
269 ConstantValue get proxyConstant;
219 270
220 /// If set to `true` resolution caches will not be cleared. Use this only for 271 /// If set to `true` resolution caches will not be cleared. Use this only for
221 /// testing. 272 /// testing.
222 bool retainCachesForTesting; 273 bool retainCachesForTesting;
223 274
224 void resolveTypedef(TypedefElement typdef); 275 void resolveTypedef(TypedefElement typdef);
225 void resolveClass(ClassElement cls); 276 void resolveClass(ClassElement cls);
226 void registerClass(ClassElement cls); 277 void registerClass(ClassElement cls);
227 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation); 278 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation);
228 FunctionSignature resolveSignature(FunctionElement function); 279 FunctionSignature resolveSignature(FunctionElement function);
229 DartType resolveTypeAnnotation(Element element, TypeAnnotation node); 280 DartType resolveTypeAnnotation(Element element, TypeAnnotation node);
230 281
231 /// Returns `true` if [element] has been resolved. 282 /// Returns `true` if [element] has been resolved.
232 // TODO(johnniwinther): Normalize semantics between normal and deserialized 283 // TODO(johnniwinther): Normalize semantics between normal and deserialized
233 // elements; deserialized elements are always resolved but the method will 284 // elements; deserialized elements are always resolved but the method will
234 // return `false`. 285 // return `false`.
235 bool hasBeenResolved(Element element); 286 bool hasBeenResolved(Element element);
236 287
237 /// Resolve [element] if it has not already been resolved. 288 /// Resolve [element] if it has not already been resolved.
238 void ensureResolved(Element element); 289 void ensureResolved(Element element);
239 290
291 /// Called whenever a class has been resolved.
292 void onClassResolved(ClassElement element);
293
294 /// Registers that [element] has a compile time error.
295 ///
296 /// The error itself is given in [message].
297 void registerCompileTimeError(Element element, DiagnosticMessage message);
298
240 ResolutionWorkItem createWorkItem( 299 ResolutionWorkItem createWorkItem(
241 Element element, ItemCompilationContext compilationContext); 300 Element element, ItemCompilationContext compilationContext);
242 301
243 /// Returns `true` if [element] as a fully computed [ResolvedAst]. 302 /// Returns `true` if [element] as a fully computed [ResolvedAst].
244 bool hasResolvedAst(ExecutableElement element); 303 bool hasResolvedAst(ExecutableElement element);
245 304
246 /// Returns the `ResolvedAst` for the [element]. 305 /// Returns the `ResolvedAst` for the [element].
247 ResolvedAst getResolvedAst(ExecutableElement element); 306 ResolvedAst getResolvedAst(ExecutableElement element);
248 307
249 /// Returns `true` if the [ResolutionImpact] for [element] is cached. 308 /// Returns `true` if the [ResolutionImpact] for [element] is cached.
(...skipping 17 matching lines...) Expand all
267 /// Removes the [WorldImpact] for [element] from the resolution cache. Later 326 /// Removes the [WorldImpact] for [element] from the resolution cache. Later
268 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact. 327 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact.
269 void uncacheWorldImpact(Element element); 328 void uncacheWorldImpact(Element element);
270 329
271 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. , 330 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. ,
272 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty 331 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty
273 /// impact. 332 /// impact.
274 void emptyCache(); 333 void emptyCache();
275 334
276 void forgetElement(Element element); 335 void forgetElement(Element element);
336
337 /// Returns `true` if [value] is the top-level [proxy] annotation from the
338 /// core library.
339 bool isProxyConstant(ConstantValue value);
277 } 340 }
278 341
279 /// A container of commonly used dependencies for tasks that involve parsing. 342 /// A container of commonly used dependencies for tasks that involve parsing.
280 abstract class ParsingContext { 343 abstract class ParsingContext {
281 factory ParsingContext( 344 factory ParsingContext(
282 DiagnosticReporter reporter, 345 DiagnosticReporter reporter,
283 ParserOptions parserOptions, 346 ParserOptions parserOptions,
284 ParserTask parser, 347 ParserTask parser,
285 PatchParserTask patchParser, 348 PatchParserTask patchParser,
286 Backend backend) = _ParsingContext; 349 Backend backend) = _ParsingContext;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (cls.isPatch) { 384 if (cls.isPatch) {
322 patchParser.parsePatchClassNode(cls); 385 patchParser.parsePatchClassNode(cls);
323 } 386 }
324 }); 387 });
325 } 388 }
326 389
327 @override 390 @override
328 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( 391 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions(
329 canUseNative: backend.canLibraryUseNative(element.library)); 392 canUseNative: backend.canLibraryUseNative(element.library));
330 } 393 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/common/backend_api.dart ('k') | pkg/compiler/lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698