Index: pkg/compiler/lib/src/serialization/task.dart |
diff --git a/pkg/compiler/lib/src/serialization/task.dart b/pkg/compiler/lib/src/serialization/task.dart |
index 6ca46364572e9a320f28523e61f030321fc8ac84..d93581f4b8f4d3e6dd3786d787f3c79f28b9ef45 100644 |
--- a/pkg/compiler/lib/src/serialization/task.dart |
+++ b/pkg/compiler/lib/src/serialization/task.dart |
@@ -4,7 +4,7 @@ |
library dart2js.serialization.task; |
-import 'dart:async' show Future; |
+import 'dart:async' show EventSink, Future; |
import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem; |
import '../common/tasks.dart' show CompilerTask; |
import '../common/work.dart' show ItemCompilationContext; |
@@ -12,6 +12,9 @@ import '../compiler.dart' show Compiler; |
import '../elements/elements.dart'; |
import '../enqueue.dart' show ResolutionEnqueuer; |
import '../universe/world_impact.dart' show WorldImpact; |
+import 'json_serializer.dart'; |
+import 'serialization.dart'; |
+import 'system.dart'; |
/// A deserializer that can load a library element by reading it's information |
/// from a serialized form. |
@@ -25,7 +28,7 @@ abstract class LibraryDeserializer { |
class SerializationTask extends CompilerTask implements LibraryDeserializer { |
SerializationTask(Compiler compiler) : super(compiler); |
- DeserializerSystem deserializer; |
+ DeserializerSystem system; |
Siggi Cherem (dart-lang)
2016/05/14 01:10:31
I sort of prefer the old name here.
Johnni Winther
2016/05/17 12:37:33
Done.
|
String get name => 'Serialization'; |
@@ -35,45 +38,85 @@ class SerializationTask extends CompilerTask implements LibraryDeserializer { |
bool supportSerialization = false; |
/// If `true`, deserialized data is supported. |
- bool get supportsDeserialization => deserializer != null; |
+ bool get supportsDeserialization => system != null; |
/// Returns the [LibraryElement] for [resolvedUri] if available from |
/// serialization. |
Future<LibraryElement> readLibrary(Uri resolvedUri) { |
- if (deserializer == null) return new Future<LibraryElement>.value(); |
- return deserializer.readLibrary(resolvedUri); |
+ if (system == null) return new Future<LibraryElement>.value(); |
+ return system.readLibrary(resolvedUri); |
} |
/// Returns `true` if [element] has been deserialized. |
bool isDeserialized(Element element) { |
- return deserializer != null && deserializer.isDeserialized(element); |
+ return system != null && system.isDeserialized(element); |
} |
bool hasResolutionImpact(Element element) { |
- return deserializer != null && deserializer.hasResolutionImpact(element); |
+ return system != null && system.hasResolutionImpact(element); |
} |
ResolutionImpact getResolutionImpact(Element element) { |
- return deserializer != null |
- ? deserializer.getResolutionImpact(element) |
- : null; |
+ return system != null ? system.getResolutionImpact(element) : null; |
} |
/// Creates the [ResolutionWorkItem] for the deserialized [element]. |
ResolutionWorkItem createResolutionWorkItem( |
Element element, ItemCompilationContext context) { |
- assert(deserializer != null); |
+ assert(system != null); |
assert(isDeserialized(element)); |
return new DeserializedResolutionWorkItem( |
- element, context, deserializer.computeWorldImpact(element)); |
+ element, context, system.computeWorldImpact(element)); |
} |
bool hasResolvedAst(ExecutableElement element) { |
- return deserializer != null ? deserializer.hasResolvedAst(element) : false; |
+ return system != null ? system.hasResolvedAst(element) : false; |
} |
ResolvedAst getResolvedAst(ExecutableElement element) { |
- return deserializer != null ? deserializer.getResolvedAst(element) : null; |
+ return system != null ? system.getResolvedAst(element) : null; |
+ } |
+ |
+ Serializer createSerializer(Iterable<LibraryElement> libraries) { |
+ return measure(() { |
+ assert(supportSerialization); |
+ |
+ Serializer serializer = new Serializer(); |
+ SerializerPlugin backendSerializer = |
+ compiler.backend.serialization.serializer; |
+ serializer.plugins.add(backendSerializer); |
+ serializer.plugins.add(new ResolutionImpactSerializer( |
+ compiler.resolution, backendSerializer)); |
+ serializer.plugins.add(new ResolvedAstSerializerPlugin( |
+ compiler.resolution, backendSerializer)); |
+ |
+ for (LibraryElement library in libraries) { |
+ serializer.serialize(library); |
+ } |
+ return serializer; |
+ }); |
+ } |
+ |
+ void serializeToSink( |
+ EventSink<String> sink, Iterable<LibraryElement> libraries) { |
+ measure(() { |
+ sink |
+ ..add(createSerializer(libraries) |
+ .toText(const JsonSerializationEncoder())) |
+ ..close(); |
+ }); |
+ } |
+ |
+ void deserializeFromText(String serializedData) { |
+ measure(() { |
+ Deserializer deserializer = new Deserializer.fromText( |
+ new DeserializationContext(), |
+ serializedData, |
+ const JsonSerializationDecoder()); |
+ deserializer.plugins.add(compiler.backend.serialization.deserializer); |
+ system = new DeserializerSystemImpl( |
+ compiler, deserializer, compiler.backend.impactTransformer); |
+ }); |
} |
} |