| 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 | 8 |
| 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 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 DeserializerSystem deserializer; | 35 DeserializerSystem deserializer; |
| 36 | 36 |
| 37 String get name => 'Serialization'; | 37 String get name => 'Serialization'; |
| 38 | 38 |
| 39 /// If `true`, data must be retained to support serialization. | 39 /// If `true`, data must be retained to support serialization. |
| 40 // TODO(johnniwinther): Make this more precise in terms of what needs to be | 40 // TODO(johnniwinther): Make this more precise in terms of what needs to be |
| 41 // retained, for instance impacts, resolution data etc. | 41 // retained, for instance impacts, resolution data etc. |
| 42 bool supportSerialization = false; | 42 bool supportSerialization = false; |
| 43 | 43 |
| 44 /// Set this flag to also deserialize [ResolvedAst]s and [ResolutionImpact]s |
| 45 /// in `resolveOnly` mode. Use this for testing only. |
| 46 bool deserializeCompilationDataForTesting = false; |
| 47 |
| 44 /// If `true`, deserialized data is supported. | 48 /// If `true`, deserialized data is supported. |
| 45 bool get supportsDeserialization => deserializer != null; | 49 bool get supportsDeserialization => deserializer != null; |
| 46 | 50 |
| 47 /// Returns the [LibraryElement] for [resolvedUri] if available from | 51 /// Returns the [LibraryElement] for [resolvedUri] if available from |
| 48 /// serialization. | 52 /// serialization. |
| 49 Future<LibraryElement> readLibrary(Uri resolvedUri) { | 53 Future<LibraryElement> readLibrary(Uri resolvedUri) { |
| 50 if (deserializer == null) return new Future<LibraryElement>.value(); | 54 if (deserializer == null) return new Future<LibraryElement>.value(); |
| 51 return deserializer.readLibrary(resolvedUri); | 55 return deserializer.readLibrary(resolvedUri); |
| 52 } | 56 } |
| 53 | 57 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 sink | 114 sink |
| 111 ..add(createSerializer(libraries) | 115 ..add(createSerializer(libraries) |
| 112 .toText(const JsonSerializationEncoder())) | 116 .toText(const JsonSerializationEncoder())) |
| 113 ..close(); | 117 ..close(); |
| 114 }); | 118 }); |
| 115 } | 119 } |
| 116 | 120 |
| 117 void deserializeFromText(Uri sourceUri, String serializedData) { | 121 void deserializeFromText(Uri sourceUri, String serializedData) { |
| 118 measure(() { | 122 measure(() { |
| 119 if (deserializer == null) { | 123 if (deserializer == null) { |
| 120 deserializer = new DeserializerSystemImpl(compiler); | 124 deserializer = new ResolutionDeserializerSystem(compiler, |
| 125 deserializeCompilationDataForTesting: |
| 126 deserializeCompilationDataForTesting); |
| 121 } | 127 } |
| 122 DeserializerSystemImpl deserializerImpl = deserializer; | 128 ResolutionDeserializerSystem deserializerImpl = deserializer; |
| 123 DeserializationContext context = deserializerImpl.deserializationContext; | 129 DeserializationContext context = deserializerImpl.deserializationContext; |
| 124 Deserializer dataDeserializer = new Deserializer.fromText( | 130 Deserializer dataDeserializer = new Deserializer.fromText( |
| 125 context, sourceUri, serializedData, const JsonSerializationDecoder()); | 131 context, sourceUri, serializedData, const JsonSerializationDecoder()); |
| 126 context.deserializers.add(dataDeserializer); | 132 context.deserializers.add(dataDeserializer); |
| 127 }); | 133 }); |
| 128 } | 134 } |
| 129 } | 135 } |
| 130 | 136 |
| 131 /// A [ResolutionWorkItem] for a deserialized element. | 137 /// A [ResolutionWorkItem] for a deserialized element. |
| 132 /// | 138 /// |
| (...skipping 22 matching lines...) Expand all Loading... |
| 155 /// elements. | 161 /// elements. |
| 156 abstract class DeserializerSystem { | 162 abstract class DeserializerSystem { |
| 157 Future<LibraryElement> readLibrary(Uri resolvedUri); | 163 Future<LibraryElement> readLibrary(Uri resolvedUri); |
| 158 bool isDeserialized(Element element); | 164 bool isDeserialized(Element element); |
| 159 bool hasResolvedAst(ExecutableElement element); | 165 bool hasResolvedAst(ExecutableElement element); |
| 160 ResolvedAst getResolvedAst(ExecutableElement element); | 166 ResolvedAst getResolvedAst(ExecutableElement element); |
| 161 bool hasResolutionImpact(Element element); | 167 bool hasResolutionImpact(Element element); |
| 162 ResolutionImpact getResolutionImpact(Element element); | 168 ResolutionImpact getResolutionImpact(Element element); |
| 163 WorldImpact computeWorldImpact(Element element); | 169 WorldImpact computeWorldImpact(Element element); |
| 164 } | 170 } |
| OLD | NEW |