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.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 '../constants/expressions.dart' show ConstantExpression; | 9 import '../constants/expressions.dart' show ConstantExpression; |
10 import '../core_types.dart' show CoreTypes; | 10 import '../core_types.dart' show CoreTypes; |
11 import '../dart_types.dart' show DartType, InterfaceType; | 11 import '../dart_types.dart' show DartType, InterfaceType; |
12 import '../elements/elements.dart' | 12 import '../elements/elements.dart' |
13 show | 13 show |
14 AstElement, | 14 AstElement, |
15 ClassElement, | 15 ClassElement, |
16 Element, | 16 Element, |
17 FunctionElement, | 17 FunctionElement, |
18 FunctionSignature, | 18 FunctionSignature, |
19 MetadataAnnotation, | 19 MetadataAnnotation, |
20 ResolvedAst, | 20 ResolvedAst, |
21 TypedefElement; | 21 TypedefElement; |
22 import '../enqueue.dart' show ResolutionEnqueuer; | 22 import '../enqueue.dart' show ResolutionEnqueuer; |
23 import '../options.dart' show ParserOptions; | 23 import '../options.dart' show ParserOptions; |
24 import '../parser/element_listener.dart' show ScannerOptions; | 24 import '../parser/element_listener.dart' show ScannerOptions; |
| 25 import '../parser/parser_task.dart'; |
| 26 import '../patch_parser.dart'; |
25 import '../tree/tree.dart' show TypeAnnotation; | 27 import '../tree/tree.dart' show TypeAnnotation; |
26 import '../universe/world_impact.dart' show WorldImpact; | 28 import '../universe/world_impact.dart' show WorldImpact; |
| 29 import 'backend_api.dart'; |
27 import 'work.dart' show ItemCompilationContext, WorkItem; | 30 import 'work.dart' show ItemCompilationContext, WorkItem; |
28 | 31 |
29 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. | 32 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. |
30 class ResolutionWorkItem extends WorkItem { | 33 class ResolutionWorkItem extends WorkItem { |
31 bool _isAnalyzed = false; | 34 bool _isAnalyzed = false; |
32 | 35 |
33 ResolutionWorkItem( | 36 ResolutionWorkItem( |
34 AstElement element, ItemCompilationContext compilationContext) | 37 AstElement element, ItemCompilationContext compilationContext) |
35 : super(element, compilationContext); | 38 : super(element, compilationContext); |
36 | 39 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 isEmpty == other.isEmpty; | 180 isEmpty == other.isEmpty; |
178 } | 181 } |
179 | 182 |
180 String toString() { | 183 String toString() { |
181 return 'ListLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)'; | 184 return 'ListLiteralUse($type,isConstant:$isConstant,isEmpty:$isEmpty)'; |
182 } | 185 } |
183 } | 186 } |
184 | 187 |
185 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. | 188 // TODO(johnniwinther): Rename to `Resolver` or `ResolverContext`. |
186 abstract class Resolution { | 189 abstract class Resolution { |
187 Parsing get parsing; | 190 ParsingContext get parsingContext; |
188 DiagnosticReporter get reporter; | 191 DiagnosticReporter get reporter; |
189 CoreTypes get coreTypes; | 192 CoreTypes get coreTypes; |
190 | 193 |
191 /// If set to `true` resolution caches will not be cleared. Use this only for | 194 /// If set to `true` resolution caches will not be cleared. Use this only for |
192 /// testing. | 195 /// testing. |
193 bool retainCachesForTesting; | 196 bool retainCachesForTesting; |
194 | 197 |
195 void resolveTypedef(TypedefElement typdef); | 198 void resolveTypedef(TypedefElement typdef); |
196 void resolveClass(ClassElement cls); | 199 void resolveClass(ClassElement cls); |
197 void registerClass(ClassElement cls); | 200 void registerClass(ClassElement cls); |
(...skipping 27 matching lines...) Expand all Loading... |
225 /// Removes the [WorldImpact] for [element] from the resolution cache. Later | 228 /// Removes the [WorldImpact] for [element] from the resolution cache. Later |
226 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact. | 229 /// calls to [getWorldImpact] or [computeWorldImpact] returns an empty impact. |
227 void uncacheWorldImpact(Element element); | 230 void uncacheWorldImpact(Element element); |
228 | 231 |
229 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. , | 232 /// Removes the [WorldImpact]s for all [Element]s in the resolution cache. , |
230 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty | 233 /// Later calls to [getWorldImpact] or [computeWorldImpact] returns an empty |
231 /// impact. | 234 /// impact. |
232 void emptyCache(); | 235 void emptyCache(); |
233 } | 236 } |
234 | 237 |
235 // TODO(johnniwinther): Rename to `Parser` or `ParsingContext`. | 238 /// A container of commonly used dependencies for tasks that involve parsing. |
236 abstract class Parsing { | 239 abstract class ParsingContext { |
| 240 factory ParsingContext( |
| 241 DiagnosticReporter reporter, |
| 242 ParserOptions parserOptions, |
| 243 ParserTask parser, |
| 244 PatchParserTask patchParser, |
| 245 Backend backend) = _ParsingContext; |
| 246 |
237 DiagnosticReporter get reporter; | 247 DiagnosticReporter get reporter; |
| 248 ParserOptions get parserOptions; |
| 249 ParserTask get parser; |
| 250 PatchParserTask get patchParser; |
| 251 |
| 252 /// Use [patchParser] directly instead. |
| 253 @deprecated |
238 void parsePatchClass(ClassElement cls); | 254 void parsePatchClass(ClassElement cls); |
| 255 |
| 256 /// Use [parser] and measure directly instead. |
| 257 @deprecated |
239 measure(f()); | 258 measure(f()); |
| 259 |
| 260 /// Get the [ScannerOptions] to scan the given [element]. |
240 ScannerOptions getScannerOptionsFor(Element element); | 261 ScannerOptions getScannerOptionsFor(Element element); |
241 ParserOptions get parserOptions; | |
242 } | 262 } |
| 263 |
| 264 class _ParsingContext implements ParsingContext { |
| 265 final DiagnosticReporter reporter; |
| 266 final ParserOptions parserOptions; |
| 267 final ParserTask parser; |
| 268 final PatchParserTask patchParser; |
| 269 final Backend backend; |
| 270 |
| 271 _ParsingContext(this.reporter, this.parserOptions, this.parser, |
| 272 this.patchParser, this.backend); |
| 273 |
| 274 @override |
| 275 measure(f()) => parser.measure(f); |
| 276 |
| 277 @override |
| 278 void parsePatchClass(ClassElement cls) { |
| 279 patchParser.measure(() { |
| 280 if (cls.isPatch) { |
| 281 patchParser.parsePatchClassNode(cls); |
| 282 } |
| 283 }); |
| 284 } |
| 285 |
| 286 @override |
| 287 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( |
| 288 canUseNative: backend.canLibraryUseNative(element.library)); |
| 289 } |
OLD | NEW |