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

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: fix tests 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
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 AstElement, ClassElement, ConstructorElement, Element, ExecutableElemen t, FunctionElement, FunctionSignature, LibraryElement, MetadataAnnotation, Metho dElement, ResolvedAst, TypedefElement;
Johnni Winther 2016/07/08 08:05:39 Bad dartfmt!
Harry Terkelsen 2016/07/18 17:35:58 Done.
14 AstElement,
15 ClassElement,
16 Element,
17 ExecutableElement,
18 FunctionElement,
19 FunctionSignature,
20 LibraryElement,
21 MetadataAnnotation,
22 ResolvedAst,
23 TypedefElement;
24 import '../enqueue.dart' show ResolutionEnqueuer; 16 import '../enqueue.dart' show ResolutionEnqueuer;
25 import '../options.dart' show ParserOptions; 17 import '../id_generator.dart';
18 import '../mirrors_used.dart';
19 import '../options.dart' show CompilerOptions, ParserOptions;
26 import '../parser/element_listener.dart' show ScannerOptions; 20 import '../parser/element_listener.dart' show ScannerOptions;
27 import '../parser/parser_task.dart'; 21 import '../parser/parser_task.dart';
28 import '../patch_parser.dart'; 22 import '../patch_parser.dart';
29 import '../tree/tree.dart' show TypeAnnotation; 23 import '../resolution/resolution.dart';
24 import '../tree/tree.dart' show Send, TypeAnnotation;
25 import '../universe/call_structure.dart' show CallStructure;
30 import '../universe/world_impact.dart' show WorldImpact; 26 import '../universe/world_impact.dart' show WorldImpact;
31 import 'backend_api.dart'; 27 import 'backend_api.dart';
32 import 'work.dart' show ItemCompilationContext, WorkItem; 28 import 'work.dart' show ItemCompilationContext, WorkItem;
33 29
34 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. 30 /// [WorkItem] used exclusively by the [ResolutionEnqueuer].
35 class ResolutionWorkItem extends WorkItem { 31 class ResolutionWorkItem extends WorkItem {
36 bool _isAnalyzed = false; 32 bool _isAnalyzed = false;
37 33
38 ResolutionWorkItem( 34 ResolutionWorkItem(
39 AstElement element, ItemCompilationContext compilationContext) 35 AstElement element, ItemCompilationContext compilationContext)
40 : super(element, compilationContext); 36 : super(element, compilationContext);
41 37
42 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { 38 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) {
43 WorldImpact impact = compiler.analyze(this, world); 39 WorldImpact impact = compiler.analyze(this, world);
44 _isAnalyzed = true; 40 _isAnalyzed = true;
45 return impact; 41 return impact;
46 } 42 }
47 43
48 bool get isAnalyzed => _isAnalyzed; 44 bool get isAnalyzed => _isAnalyzed;
49 } 45 }
50 46
51 class ResolutionImpact extends WorldImpact { 47 class ResolutionImpact extends WorldImpact {
52 const ResolutionImpact(); 48 const ResolutionImpact();
53 49
54 Iterable<Feature> get features => const <Feature>[]; 50 Iterable<Feature> get features => const <Feature>[];
55 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[]; 51 Iterable<MapLiteralUse> get mapLiterals => const <MapLiteralUse>[];
56 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[]; 52 Iterable<ListLiteralUse> get listLiterals => const <ListLiteralUse>[];
57 Iterable<String> get constSymbolNames => const <String>[]; 53 Iterable<String> get constSymbolNames => const <String>[];
58 Iterable<ConstantExpression> get constantLiterals { 54 Iterable<ConstantExpression> get constantLiterals =>
59 return const <ConstantExpression>[]; 55 const <ConstantExpression>[];
60 }
61 56
62 Iterable<dynamic> get nativeData => const <dynamic>[]; 57 Iterable<dynamic> get nativeData => const <dynamic>[];
63 } 58 }
64 59
65 /// A language feature seen during resolution. 60 /// A language feature seen during resolution.
66 // TODO(johnniwinther): Should mirror usage be part of this? 61 // TODO(johnniwinther): Should mirror usage be part of this?
67 enum Feature { 62 enum Feature {
68 /// Invocation of a generative construction on an abstract class. 63 /// Invocation of a generative construction on an abstract class.
69 ABSTRACT_CLASS_INSTANTIATION, 64 ABSTRACT_CLASS_INSTANTIATION,
70 65
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 /// Interface defining target-specific behavior for resolution. 194 /// Interface defining target-specific behavior for resolution.
200 abstract class Target { 195 abstract class Target {
201 /// Returns `true` if [library] is a target specific library whose members 196 /// Returns `true` if [library] is a target specific library whose members
202 /// have special treatment, such as being allowed to extends blacklisted 197 /// have special treatment, such as being allowed to extends blacklisted
203 /// classes or members being eagerly resolved. 198 /// classes or members being eagerly resolved.
204 bool isTargetSpecificLibrary(LibraryElement element); 199 bool isTargetSpecificLibrary(LibraryElement element);
205 200
206 /// Resolve target specific information for [element] and register it with 201 /// Resolve target specific information for [element] and register it with
207 /// [registry]. 202 /// [registry].
208 void resolveNativeElement(Element element, NativeRegistry registry) {} 203 void resolveNativeElement(Element element, NativeRegistry registry) {}
204
205 /// Processes [element] for resolution and returns the [MethodElement] that
206 /// defines the implementation of [element].
207 MethodElement resolveExternalFunction(MethodElement element) => element;
208
209 /// Called when resolving a call to a foreign function. If a non-null value
210 /// is returned, this is stored as native data for [node] in the resolved
211 /// AST.
212 dynamic resolveForeignCall(Send node, Element element,
213 CallStructure callStructure, ForeignResolver resolver) {
214 return null;
215 }
216
217 /// Returns the default superclass for the given [element] in this target.
218 ClassElement defaultSuperclass(ClassElement element);
219
220 /// Returns `true` if [element] is a native element, that is, that the
221 /// corresponding entity already exists in the target language.
222 bool isNative(Element element) => false;
223
224 /// Returns `true` if [element] is a foreign element, that is, that the
225 /// backend has specialized handling for the element.
226 bool isForeign(Element element) => false;
209 } 227 }
210 228
211 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. 229 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`.
212 abstract class Resolution implements Frontend { 230 abstract class Resolution implements Frontend {
213 ParsingContext get parsingContext; 231 ParsingContext get parsingContext;
214 DiagnosticReporter get reporter; 232 DiagnosticReporter get reporter;
215 CoreClasses get coreClasses; 233 CoreClasses get coreClasses;
216 CoreTypes get coreTypes; 234 CoreTypes get coreTypes;
217 Types get types; 235 Types get types;
218 Target get target; 236 Target get target;
237 ResolverTask get resolver;
238 ResolutionEnqueuer get enqueuer;
239 CompilerOptions get options;
240 IdGenerator get idGenerator;
241 ConstantEnvironment get constants;
242 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask;
243
244 // TODO(het): Move all elements into common/elements.dart
245 LibraryElement get coreLibrary;
246 FunctionElement get identicalFunction;
247 ClassElement get mirrorSystemClass;
248 FunctionElement get mirrorSystemGetNameFunction;
249 ConstructorElement get mirrorsUsedConstructor;
250 ConstructorElement get symbolConstructor;
251
252 // TODO(het): This is only referenced in a test...
253 /// The constant for the [proxy] variable defined in dart:core.
254 ConstantValue get proxyConstant;
219 255
220 /// If set to `true` resolution caches will not be cleared. Use this only for 256 /// If set to `true` resolution caches will not be cleared. Use this only for
221 /// testing. 257 /// testing.
222 bool retainCachesForTesting; 258 bool retainCachesForTesting;
223 259
224 void resolveTypedef(TypedefElement typdef); 260 void resolveTypedef(TypedefElement typdef);
225 void resolveClass(ClassElement cls); 261 void resolveClass(ClassElement cls);
226 void registerClass(ClassElement cls); 262 void registerClass(ClassElement cls);
227 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation); 263 void resolveMetadataAnnotation(MetadataAnnotation metadataAnnotation);
228 FunctionSignature resolveSignature(FunctionElement function); 264 FunctionSignature resolveSignature(FunctionElement function);
229 DartType resolveTypeAnnotation(Element element, TypeAnnotation node); 265 DartType resolveTypeAnnotation(Element element, TypeAnnotation node);
230 266
231 /// Returns `true` if [element] has been resolved. 267 /// Returns `true` if [element] has been resolved.
232 // TODO(johnniwinther): Normalize semantics between normal and deserialized 268 // TODO(johnniwinther): Normalize semantics between normal and deserialized
233 // elements; deserialized elements are always resolved but the method will 269 // elements; deserialized elements are always resolved but the method will
234 // return `false`. 270 // return `false`.
235 bool hasBeenResolved(Element element); 271 bool hasBeenResolved(Element element);
236 272
237 /// Resolve [element] if it has not already been resolved. 273 /// Resolve [element] if it has not already been resolved.
238 void ensureResolved(Element element); 274 void ensureResolved(Element element);
239 275
276 /// Called whenever a class has been resolved.
277 void onClassResolved(ClassElement element);
278
279 /// Registers that [element] has a compile time error.
280 ///
281 /// The error itself is given in [message].
282 void registerCompiletimeError(Element element, DiagnosticMessage message);
Johnni Winther 2016/07/08 08:05:39 Compilertime -> CompileTime?
Harry Terkelsen 2016/07/18 17:35:58 Done.
283
240 ResolutionWorkItem createWorkItem( 284 ResolutionWorkItem createWorkItem(
241 Element element, ItemCompilationContext compilationContext); 285 Element element, ItemCompilationContext compilationContext);
242 286
243 /// Returns `true` if [element] as a fully computed [ResolvedAst]. 287 /// Returns `true` if [element] as a fully computed [ResolvedAst].
244 bool hasResolvedAst(ExecutableElement element); 288 bool hasResolvedAst(ExecutableElement element);
245 289
246 /// Returns the `ResolvedAst` for the [element]. 290 /// Returns the `ResolvedAst` for the [element].
247 ResolvedAst getResolvedAst(ExecutableElement element); 291 ResolvedAst getResolvedAst(ExecutableElement element);
248 292
249 /// Returns `true` if the [ResolutionImpact] for [element] is cached. 293 /// 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 311 /// Removes the [WorldImpact] for [element] from the resolution cache. Later
268 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact. 312 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact.
269 void uncacheWorldImpact(Element element); 313 void uncacheWorldImpact(Element element);
270 314
271 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. , 315 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. ,
272 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty 316 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty
273 /// impact. 317 /// impact.
274 void emptyCache(); 318 void emptyCache();
275 319
276 void forgetElement(Element element); 320 void forgetElement(Element element);
321
322 /// Returns `true` if [value] is the top-level [proxy] annotation from the
323 /// core library.
324 bool isProxyConstant(ConstantValue value);
277 } 325 }
278 326
279 /// A container of commonly used dependencies for tasks that involve parsing. 327 /// A container of commonly used dependencies for tasks that involve parsing.
280 abstract class ParsingContext { 328 abstract class ParsingContext {
281 factory ParsingContext( 329 factory ParsingContext(
282 DiagnosticReporter reporter, 330 DiagnosticReporter reporter,
283 ParserOptions parserOptions, 331 ParserOptions parserOptions,
284 ParserTask parser, 332 ParserTask parser,
285 PatchParserTask patchParser, 333 PatchParserTask patchParser,
286 Backend backend) = _ParsingContext; 334 Backend backend) = _ParsingContext;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (cls.isPatch) { 369 if (cls.isPatch) {
322 patchParser.parsePatchClassNode(cls); 370 patchParser.parsePatchClassNode(cls);
323 } 371 }
324 }); 372 });
325 } 373 }
326 374
327 @override 375 @override
328 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( 376 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions(
329 canUseNative: backend.canLibraryUseNative(element.library)); 377 canUseNative: backend.canLibraryUseNative(element.library));
330 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698