OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_helper; | 5 library dart2js.serialization_helper; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:io'; | 8 import 'dart:io'; |
8 import 'dart:async'; | 9 |
9 import 'package:async_helper/async_helper.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
10 import 'package:expect/expect.dart'; | |
11 import 'package:compiler/compiler_new.dart'; | |
12 import 'package:compiler/src/common.dart'; | 11 import 'package:compiler/src/common.dart'; |
13 import 'package:compiler/src/commandline_options.dart'; | |
14 import 'package:compiler/src/common/backend_api.dart'; | 12 import 'package:compiler/src/common/backend_api.dart'; |
15 import 'package:compiler/src/common/names.dart'; | 13 import 'package:compiler/src/common/names.dart'; |
16 import 'package:compiler/src/common/resolution.dart'; | 14 import 'package:compiler/src/common/resolution.dart'; |
17 import 'package:compiler/src/compiler.dart'; | 15 import 'package:compiler/src/compiler.dart'; |
18 import 'package:compiler/src/elements/elements.dart'; | 16 import 'package:compiler/src/elements/elements.dart'; |
19 import 'package:compiler/src/filenames.dart'; | |
20 import 'package:compiler/src/io/source_file.dart'; | 17 import 'package:compiler/src/io/source_file.dart'; |
21 import 'package:compiler/src/scanner/scanner.dart'; | 18 import 'package:compiler/src/scanner/scanner.dart'; |
22 import 'package:compiler/src/serialization/element_serialization.dart'; | 19 import 'package:compiler/src/script.dart'; |
23 import 'package:compiler/src/serialization/impact_serialization.dart'; | 20 import 'package:compiler/src/serialization/impact_serialization.dart'; |
24 import 'package:compiler/src/serialization/json_serializer.dart'; | 21 import 'package:compiler/src/serialization/json_serializer.dart'; |
25 import 'package:compiler/src/serialization/resolved_ast_serialization.dart'; | 22 import 'package:compiler/src/serialization/resolved_ast_serialization.dart'; |
26 import 'package:compiler/src/serialization/serialization.dart'; | 23 import 'package:compiler/src/serialization/serialization.dart'; |
27 import 'package:compiler/src/serialization/modelz.dart'; | |
28 import 'package:compiler/src/serialization/task.dart'; | 24 import 'package:compiler/src/serialization/task.dart'; |
29 import 'package:compiler/src/tokens/token.dart'; | 25 import 'package:compiler/src/tokens/token.dart'; |
30 import 'package:compiler/src/script.dart'; | |
31 import 'package:compiler/src/universe/world_impact.dart'; | 26 import 'package:compiler/src/universe/world_impact.dart'; |
| 27 |
32 import 'memory_compiler.dart'; | 28 import 'memory_compiler.dart'; |
33 | 29 |
34 class Arguments { | 30 class Arguments { |
35 final String filename; | 31 final String filename; |
36 final bool loadSerializedData; | 32 final bool loadSerializedData; |
37 final bool saveSerializedData; | 33 final bool saveSerializedData; |
38 final String serializedDataFileName; | 34 final String serializedDataFileName; |
39 final bool verbose; | 35 final bool verbose; |
40 | 36 |
41 const Arguments({ | 37 const Arguments({ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 final bool _deserializeResolvedAst; | 170 final bool _deserializeResolvedAst; |
175 | 171 |
176 _DeserializerSystem( | 172 _DeserializerSystem( |
177 Compiler compiler, | 173 Compiler compiler, |
178 this._deserializer, | 174 this._deserializer, |
179 this._impactTransformer, | 175 this._impactTransformer, |
180 {bool deserializeResolvedAst: false}) | 176 {bool deserializeResolvedAst: false}) |
181 : this._compiler = compiler, | 177 : this._compiler = compiler, |
182 this._deserializeResolvedAst = deserializeResolvedAst, | 178 this._deserializeResolvedAst = deserializeResolvedAst, |
183 this._resolvedAstDeserializer = deserializeResolvedAst | 179 this._resolvedAstDeserializer = deserializeResolvedAst |
184 ? new ResolvedAstDeserializerPlugin(compiler.parsing) : null { | 180 ? new ResolvedAstDeserializerPlugin(compiler.parsingContext) : null { |
185 _deserializer.plugins.add(_resolutionImpactDeserializer); | 181 _deserializer.plugins.add(_resolutionImpactDeserializer); |
186 if (_deserializeResolvedAst) { | 182 if (_deserializeResolvedAst) { |
187 _deserializer.plugins.add(_resolvedAstDeserializer); | 183 _deserializer.plugins.add(_resolvedAstDeserializer); |
188 } | 184 } |
189 } | 185 } |
190 | 186 |
191 @override | 187 @override |
192 Future<LibraryElement> readLibrary(Uri resolvedUri) { | 188 Future<LibraryElement> readLibrary(Uri resolvedUri) { |
193 LibraryElement library = _deserializer.lookupLibrary(resolvedUri); | 189 LibraryElement library = _deserializer.lookupLibrary(resolvedUri); |
194 if (library != null) { | 190 if (library != null) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 assert(invariant(element, resolution.hasResolvedAst(element), | 257 assert(invariant(element, resolution.hasResolvedAst(element), |
262 message: "Element $element must have a resolved ast")); | 258 message: "Element $element must have a resolved ast")); |
263 ResolvedAst resolvedAst = resolution.getResolvedAst(element); | 259 ResolvedAst resolvedAst = resolution.getResolvedAst(element); |
264 ObjectEncoder objectEncoder = createEncoder(RESOLVED_AST_TAG); | 260 ObjectEncoder objectEncoder = createEncoder(RESOLVED_AST_TAG); |
265 new ResolvedAstSerializer(objectEncoder, resolvedAst).serialize(); | 261 new ResolvedAstSerializer(objectEncoder, resolvedAst).serialize(); |
266 } | 262 } |
267 } | 263 } |
268 } | 264 } |
269 | 265 |
270 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { | 266 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { |
271 final Parsing parsing; | 267 final ParsingContext parsingContext; |
272 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; | 268 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; |
273 | 269 |
274 Map<Element, ResolvedAst> _resolvedAstMap = <Element, ResolvedAst>{}; | 270 Map<Element, ResolvedAst> _resolvedAstMap = <Element, ResolvedAst>{}; |
275 Map<Element, ObjectDecoder> _decoderMap = <Element, ObjectDecoder>{}; | 271 Map<Element, ObjectDecoder> _decoderMap = <Element, ObjectDecoder>{}; |
276 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; | 272 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; |
277 | 273 |
278 ResolvedAstDeserializerPlugin(this.parsing); | 274 ResolvedAstDeserializerPlugin(this.parsingContext); |
279 | 275 |
280 bool hasResolvedAst(Element element) { | 276 bool hasResolvedAst(Element element) { |
281 return _resolvedAstMap.containsKey(element) || | 277 return _resolvedAstMap.containsKey(element) || |
282 _decoderMap.containsKey(element); | 278 _decoderMap.containsKey(element); |
283 } | 279 } |
284 | 280 |
285 ResolvedAst getResolvedAst(Element element) { | 281 ResolvedAst getResolvedAst(Element element) { |
286 ResolvedAst resolvedAst = _resolvedAstMap[element]; | 282 ResolvedAst resolvedAst = _resolvedAstMap[element]; |
287 if (resolvedAst == null) { | 283 if (resolvedAst == null) { |
288 ObjectDecoder decoder = _decoderMap[element]; | 284 ObjectDecoder decoder = _decoderMap[element]; |
289 if (decoder != null) { | 285 if (decoder != null) { |
290 resolvedAst = _resolvedAstMap[element] = | 286 resolvedAst = _resolvedAstMap[element] = |
291 ResolvedAstDeserializer.deserialize( | 287 ResolvedAstDeserializer.deserialize( |
292 element, decoder, parsing, findToken); | 288 element, decoder, parsingContext, findToken); |
293 _decoderMap.remove(element); | 289 _decoderMap.remove(element); |
294 } | 290 } |
295 } | 291 } |
296 return resolvedAst; | 292 return resolvedAst; |
297 } | 293 } |
298 | 294 |
299 Token findToken(Uri uri, int offset) { | 295 Token findToken(Uri uri, int offset) { |
300 Token beginToken = beginTokenMap.putIfAbsent(uri, () { | 296 Token beginToken = beginTokenMap.putIfAbsent(uri, () { |
301 SourceFile sourceFile = sourceFiles[uri]; | 297 SourceFile sourceFile = sourceFiles[uri]; |
302 if (sourceFile == null) { | 298 if (sourceFile == null) { |
303 throw 'No source file found for $uri in:\n ' | 299 throw 'No source file found for $uri in:\n ' |
304 '${sourceFiles.keys.join('\n ')}'; | 300 '${sourceFiles.keys.join('\n ')}'; |
305 } | 301 } |
306 return new Scanner(sourceFile).tokenize(); | 302 return new Scanner(sourceFile).tokenize(); |
307 }); | 303 }); |
308 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); | 304 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); |
309 } | 305 } |
310 | 306 |
311 @override | 307 @override |
312 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 308 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
313 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 309 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
314 if (decoder != null) { | 310 if (decoder != null) { |
315 _decoderMap[element] = decoder; | 311 _decoderMap[element] = decoder; |
316 } | 312 } |
317 } | 313 } |
318 } | 314 } |
319 | 315 |
OLD | NEW |