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 EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem; | 9 import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem; |
10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 ResolvedAst getResolvedAst(ExecutableElement element) { | 79 ResolvedAst getResolvedAst(ExecutableElement element) { |
80 return deserializer != null ? deserializer.getResolvedAst(element) : null; | 80 return deserializer != null ? deserializer.getResolvedAst(element) : null; |
81 } | 81 } |
82 | 82 |
83 Serializer createSerializer(Iterable<LibraryElement> libraries) { | 83 Serializer createSerializer(Iterable<LibraryElement> libraries) { |
84 return measure(() { | 84 return measure(() { |
85 assert(supportSerialization); | 85 assert(supportSerialization); |
86 | 86 |
87 Serializer serializer = new Serializer(); | 87 Serializer serializer = new Serializer( |
| 88 shouldInclude: (e) => libraries.contains(e.library)); |
88 SerializerPlugin backendSerializer = | 89 SerializerPlugin backendSerializer = |
89 compiler.backend.serialization.serializer; | 90 compiler.backend.serialization.serializer; |
90 serializer.plugins.add(backendSerializer); | 91 serializer.plugins.add(backendSerializer); |
91 serializer.plugins.add(new ResolutionImpactSerializer( | 92 serializer.plugins.add(new ResolutionImpactSerializer( |
92 compiler.resolution, backendSerializer)); | 93 compiler.resolution, backendSerializer)); |
93 serializer.plugins.add(new ResolvedAstSerializerPlugin( | 94 serializer.plugins.add(new ResolvedAstSerializerPlugin( |
94 compiler.resolution, backendSerializer)); | 95 compiler.resolution, backendSerializer)); |
95 | 96 |
96 for (LibraryElement library in libraries) { | 97 for (LibraryElement library in libraries) { |
97 serializer.serialize(library); | 98 serializer.serialize(library); |
98 } | 99 } |
99 return serializer; | 100 return serializer; |
100 }); | 101 }); |
101 } | 102 } |
102 | 103 |
103 void serializeToSink( | 104 void serializeToSink( |
104 EventSink<String> sink, Iterable<LibraryElement> libraries) { | 105 EventSink<String> sink, Iterable<LibraryElement> libraries) { |
105 measure(() { | 106 measure(() { |
106 sink | 107 sink |
107 ..add(createSerializer(libraries) | 108 ..add(createSerializer(libraries) |
108 .toText(const JsonSerializationEncoder())) | 109 .toText(const JsonSerializationEncoder())) |
109 ..close(); | 110 ..close(); |
110 }); | 111 }); |
111 } | 112 } |
112 | 113 |
113 void deserializeFromText(String serializedData) { | 114 void deserializeFromText(Uri sourceUri, String serializedData) { |
114 measure(() { | 115 measure(() { |
115 if (deserializer == null) { | 116 if (deserializer == null) { |
116 deserializer = new DeserializerSystemImpl( | 117 deserializer = new DeserializerSystemImpl( |
117 compiler, compiler.backend.impactTransformer); | 118 compiler, compiler.backend.impactTransformer); |
118 } | 119 } |
119 DeserializerSystemImpl deserializerImpl = deserializer; | 120 DeserializerSystemImpl deserializerImpl = deserializer; |
120 DeserializationContext context = deserializerImpl.deserializationContext; | 121 DeserializationContext context = deserializerImpl.deserializationContext; |
121 Deserializer dataDeserializer = new Deserializer.fromText( | 122 Deserializer dataDeserializer = new Deserializer.fromText( |
122 context, serializedData, const JsonSerializationDecoder()); | 123 context, sourceUri, serializedData, const JsonSerializationDecoder()); |
123 context.deserializers.add(dataDeserializer); | 124 context.deserializers.add(dataDeserializer); |
124 }); | 125 }); |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 /// A [ResolutionWorkItem] for a deserialized element. | 129 /// A [ResolutionWorkItem] for a deserialized element. |
129 /// | 130 /// |
130 /// This will not resolve the element but only compute the [WorldImpact]. | 131 /// This will not resolve the element but only compute the [WorldImpact]. |
131 class DeserializedResolutionWorkItem implements ResolutionWorkItem { | 132 class DeserializedResolutionWorkItem implements ResolutionWorkItem { |
132 final Element element; | 133 final Element element; |
(...skipping 19 matching lines...) Expand all Loading... |
152 /// elements. | 153 /// elements. |
153 abstract class DeserializerSystem { | 154 abstract class DeserializerSystem { |
154 Future<LibraryElement> readLibrary(Uri resolvedUri); | 155 Future<LibraryElement> readLibrary(Uri resolvedUri); |
155 bool isDeserialized(Element element); | 156 bool isDeserialized(Element element); |
156 bool hasResolvedAst(ExecutableElement element); | 157 bool hasResolvedAst(ExecutableElement element); |
157 ResolvedAst getResolvedAst(ExecutableElement element); | 158 ResolvedAst getResolvedAst(ExecutableElement element); |
158 bool hasResolutionImpact(Element element); | 159 bool hasResolutionImpact(Element element); |
159 ResolutionImpact getResolutionImpact(Element element); | 160 ResolutionImpact getResolutionImpact(Element element); |
160 WorldImpact computeWorldImpact(Element element); | 161 WorldImpact computeWorldImpact(Element element); |
161 } | 162 } |
OLD | NEW |