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 Future; | 7 import 'dart:async' show EventSink, Future; |
8 import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem; | 8 import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem; |
9 import '../common/tasks.dart' show CompilerTask; | 9 import '../common/tasks.dart' show CompilerTask; |
10 import '../common/work.dart' show ItemCompilationContext; | 10 import '../common/work.dart' show ItemCompilationContext; |
11 import '../compiler.dart' show Compiler; | 11 import '../compiler.dart' show Compiler; |
12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
13 import '../enqueue.dart' show ResolutionEnqueuer; | 13 import '../enqueue.dart' show ResolutionEnqueuer; |
14 import '../universe/world_impact.dart' show WorldImpact; | 14 import '../universe/world_impact.dart' show WorldImpact; |
| 15 import 'json_serializer.dart'; |
| 16 import 'serialization.dart'; |
| 17 import 'system.dart'; |
15 | 18 |
16 /// A deserializer that can load a library element by reading it's information | 19 /// A deserializer that can load a library element by reading it's information |
17 /// from a serialized form. | 20 /// from a serialized form. |
18 abstract class LibraryDeserializer { | 21 abstract class LibraryDeserializer { |
19 /// Loads the [LibraryElement] associated with a library under [uri], or null | 22 /// Loads the [LibraryElement] associated with a library under [uri], or null |
20 /// if no serialized information is available for the given library. | 23 /// if no serialized information is available for the given library. |
21 Future<LibraryElement> readLibrary(Uri uri); | 24 Future<LibraryElement> readLibrary(Uri uri); |
22 } | 25 } |
23 | 26 |
24 /// Task that supports deserialization of elements. | 27 /// Task that supports deserialization of elements. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 element, context, deserializer.computeWorldImpact(element)); | 71 element, context, deserializer.computeWorldImpact(element)); |
69 } | 72 } |
70 | 73 |
71 bool hasResolvedAst(ExecutableElement element) { | 74 bool hasResolvedAst(ExecutableElement element) { |
72 return deserializer != null ? deserializer.hasResolvedAst(element) : false; | 75 return deserializer != null ? deserializer.hasResolvedAst(element) : false; |
73 } | 76 } |
74 | 77 |
75 ResolvedAst getResolvedAst(ExecutableElement element) { | 78 ResolvedAst getResolvedAst(ExecutableElement element) { |
76 return deserializer != null ? deserializer.getResolvedAst(element) : null; | 79 return deserializer != null ? deserializer.getResolvedAst(element) : null; |
77 } | 80 } |
| 81 |
| 82 Serializer createSerializer(Iterable<LibraryElement> libraries) { |
| 83 return measure(() { |
| 84 assert(supportSerialization); |
| 85 |
| 86 Serializer serializer = new Serializer(); |
| 87 SerializerPlugin backendSerializer = |
| 88 compiler.backend.serialization.serializer; |
| 89 serializer.plugins.add(backendSerializer); |
| 90 serializer.plugins.add(new ResolutionImpactSerializer( |
| 91 compiler.resolution, backendSerializer)); |
| 92 serializer.plugins.add(new ResolvedAstSerializerPlugin( |
| 93 compiler.resolution, backendSerializer)); |
| 94 |
| 95 for (LibraryElement library in libraries) { |
| 96 serializer.serialize(library); |
| 97 } |
| 98 return serializer; |
| 99 }); |
| 100 } |
| 101 |
| 102 void serializeToSink( |
| 103 EventSink<String> sink, Iterable<LibraryElement> libraries) { |
| 104 measure(() { |
| 105 sink |
| 106 ..add(createSerializer(libraries) |
| 107 .toText(const JsonSerializationEncoder())) |
| 108 ..close(); |
| 109 }); |
| 110 } |
| 111 |
| 112 void deserializeFromText(String serializedData) { |
| 113 measure(() { |
| 114 Deserializer dataDeserializer = new Deserializer.fromText( |
| 115 new DeserializationContext(), |
| 116 serializedData, |
| 117 const JsonSerializationDecoder()); |
| 118 dataDeserializer.plugins.add(compiler.backend.serialization.deserializer); |
| 119 deserializer = new DeserializerSystemImpl( |
| 120 compiler, dataDeserializer, compiler.backend.impactTransformer); |
| 121 }); |
| 122 } |
78 } | 123 } |
79 | 124 |
80 /// A [ResolutionWorkItem] for a deserialized element. | 125 /// A [ResolutionWorkItem] for a deserialized element. |
81 /// | 126 /// |
82 /// This will not resolve the element but only compute the [WorldImpact]. | 127 /// This will not resolve the element but only compute the [WorldImpact]. |
83 class DeserializedResolutionWorkItem implements ResolutionWorkItem { | 128 class DeserializedResolutionWorkItem implements ResolutionWorkItem { |
84 final Element element; | 129 final Element element; |
85 final ItemCompilationContext compilationContext; | 130 final ItemCompilationContext compilationContext; |
86 final WorldImpact worldImpact; | 131 final WorldImpact worldImpact; |
87 bool _isAnalyzed = false; | 132 bool _isAnalyzed = false; |
(...skipping 16 matching lines...) Expand all Loading... |
104 /// elements. | 149 /// elements. |
105 abstract class DeserializerSystem { | 150 abstract class DeserializerSystem { |
106 Future<LibraryElement> readLibrary(Uri resolvedUri); | 151 Future<LibraryElement> readLibrary(Uri resolvedUri); |
107 bool isDeserialized(Element element); | 152 bool isDeserialized(Element element); |
108 bool hasResolvedAst(ExecutableElement element); | 153 bool hasResolvedAst(ExecutableElement element); |
109 ResolvedAst getResolvedAst(ExecutableElement element); | 154 ResolvedAst getResolvedAst(ExecutableElement element); |
110 bool hasResolutionImpact(Element element); | 155 bool hasResolutionImpact(Element element); |
111 ResolutionImpact getResolutionImpact(Element element); | 156 ResolutionImpact getResolutionImpact(Element element); |
112 WorldImpact computeWorldImpact(Element element); | 157 WorldImpact computeWorldImpact(Element element); |
113 } | 158 } |
OLD | NEW |