OLD | NEW |
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.serialization.task; | 5 library dart2js.serialization.task; |
6 | 6 |
| 7 import 'dart:async' show |
| 8 Future; |
7 import '../common/resolution.dart' show | 9 import '../common/resolution.dart' show |
8 ResolutionImpact, | 10 ResolutionImpact, |
9 ResolutionWorkItem; | 11 ResolutionWorkItem; |
10 import '../common/tasks.dart' show | 12 import '../common/tasks.dart' show |
11 CompilerTask; | 13 CompilerTask; |
12 import '../common/work.dart' show | 14 import '../common/work.dart' show |
13 ItemCompilationContext; | 15 ItemCompilationContext; |
14 import '../compiler.dart' show | 16 import '../compiler.dart' show |
15 Compiler; | 17 Compiler; |
16 import '../elements/elements.dart'; | 18 import '../elements/elements.dart'; |
17 import '../enqueue.dart' show | 19 import '../enqueue.dart' show |
18 ResolutionEnqueuer; | 20 ResolutionEnqueuer; |
19 import '../universe/world_impact.dart' show | 21 import '../universe/world_impact.dart' show |
20 WorldImpact; | 22 WorldImpact; |
21 | 23 |
22 /// A deserializer that can load a library element by reading it's information | 24 /// A deserializer that can load a library element by reading it's information |
23 /// from a serialized form. | 25 /// from a serialized form. |
24 abstract class LibraryDeserializer { | 26 abstract class LibraryDeserializer { |
25 /// Loads the [LibraryElement] associated with a library under [uri], or null | 27 /// Loads the [LibraryElement] associated with a library under [uri], or null |
26 /// if no serialized information is available for the given library. | 28 /// if no serialized information is available for the given library. |
27 LibraryElement readLibrary(Uri uri); | 29 Future<LibraryElement> readLibrary(Uri uri); |
28 } | 30 } |
29 | 31 |
30 /// Task that supports deserialization of elements. | 32 /// Task that supports deserialization of elements. |
31 class SerializationTask extends CompilerTask implements LibraryDeserializer { | 33 class SerializationTask extends CompilerTask implements LibraryDeserializer { |
32 SerializationTask(Compiler compiler) : super(compiler); | 34 SerializationTask(Compiler compiler) : super(compiler); |
33 | 35 |
34 DeserializerSystem deserializer; | 36 DeserializerSystem deserializer; |
35 | 37 |
36 String get name => 'Serialization'; | 38 String get name => 'Serialization'; |
37 | 39 |
38 /// If `true`, data must be retained to support serialization. | 40 /// If `true`, data must be retained to support serialization. |
39 // TODO(johnniwinther): Make this more precise in terms of what needs to be | 41 // TODO(johnniwinther): Make this more precise in terms of what needs to be |
40 // retained, for instance impacts, resolution data etc. | 42 // retained, for instance impacts, resolution data etc. |
41 bool supportSerialization = false; | 43 bool supportSerialization = false; |
42 | 44 |
43 /// Returns the [LibraryElement] for [resolvedUri] if available from | 45 /// Returns the [LibraryElement] for [resolvedUri] if available from |
44 /// serialization. | 46 /// serialization. |
45 LibraryElement readLibrary(Uri resolvedUri) { | 47 Future<LibraryElement> readLibrary(Uri resolvedUri) { |
46 if (deserializer == null) return null; | 48 if (deserializer == null) return new Future<LibraryElement>.value(); |
47 return deserializer.readLibrary(resolvedUri); | 49 return deserializer.readLibrary(resolvedUri); |
48 } | 50 } |
49 | 51 |
50 /// Returns `true` if [element] has been deserialized. | 52 /// Returns `true` if [element] has been deserialized. |
51 bool isDeserialized(Element element) { | 53 bool isDeserialized(Element element) { |
52 return deserializer != null && deserializer.isDeserialized(element); | 54 return deserializer != null && deserializer.isDeserialized(element); |
53 } | 55 } |
54 | 56 |
55 /// Creates the [ResolutionWorkItem] for the deserialized [element]. | 57 /// Creates the [ResolutionWorkItem] for the deserialized [element]. |
56 ResolutionWorkItem createResolutionWorkItem( | 58 ResolutionWorkItem createResolutionWorkItem( |
(...skipping 24 matching lines...) Expand all Loading... |
81 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { | 83 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { |
82 _isAnalyzed = true; | 84 _isAnalyzed = true; |
83 world.registerProcessedElement(element); | 85 world.registerProcessedElement(element); |
84 return worldImpact; | 86 return worldImpact; |
85 } | 87 } |
86 } | 88 } |
87 | 89 |
88 /// The interface for a system that supports deserialization of libraries and | 90 /// The interface for a system that supports deserialization of libraries and |
89 /// elements. | 91 /// elements. |
90 abstract class DeserializerSystem { | 92 abstract class DeserializerSystem { |
91 LibraryElement readLibrary(Uri resolvedUri); | 93 Future<LibraryElement> readLibrary(Uri resolvedUri); |
92 bool isDeserialized(Element element); | 94 bool isDeserialized(Element element); |
| 95 ResolvedAst getResolvedAst(Element element); |
93 ResolutionImpact getResolutionImpact(Element element); | 96 ResolutionImpact getResolutionImpact(Element element); |
94 WorldImpact computeWorldImpact(Element element); | 97 WorldImpact computeWorldImpact(Element element); |
95 } | 98 } |
OLD | NEW |