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:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 .then((Script newScript) { | 223 .then((Script newScript) { |
224 script.file = newScript.file; | 224 script.file = newScript.file; |
225 _resolvedAstDeserializer.sourceFiles[script.resourceUri] = | 225 _resolvedAstDeserializer.sourceFiles[script.resourceUri] = |
226 newScript.file; | 226 newScript.file; |
227 }); | 227 }); |
228 }).then((_) => library); | 228 }).then((_) => library); |
229 } | 229 } |
230 return new Future<LibraryElement>.value(library); | 230 return new Future<LibraryElement>.value(library); |
231 } | 231 } |
232 | 232 |
| 233 // TODO(johnniwinther): Remove the need for this method. |
233 @override | 234 @override |
234 bool hasResolvedAst(ExecutableElement element) { | 235 bool hasResolvedAst(ExecutableElement element) { |
235 return _resolvedAstDeserializer.hasResolvedAst(element); | 236 return getResolvedAst(element) != null; |
236 } | 237 } |
237 | 238 |
238 @override | 239 @override |
239 ResolvedAst getResolvedAst(ExecutableElement element) { | 240 ResolvedAst getResolvedAst(ExecutableElement element) { |
240 return _resolvedAstDeserializer.getResolvedAst(element); | 241 return _resolvedAstDeserializer.getResolvedAst(element); |
241 } | 242 } |
242 | 243 |
243 @override | 244 @override |
244 bool hasResolutionImpact(Element element) { | 245 bool hasResolutionImpact(Element element) { |
245 if (element.isConstructor && | 246 if (element.isConstructor && |
(...skipping 22 matching lines...) Expand all Loading... |
268 }); | 269 }); |
269 } | 270 } |
270 return _resolutionImpactDeserializer.impactMap[element]; | 271 return _resolutionImpactDeserializer.impactMap[element]; |
271 } | 272 } |
272 | 273 |
273 @override | 274 @override |
274 WorldImpact computeWorldImpact(Element element) { | 275 WorldImpact computeWorldImpact(Element element) { |
275 ResolutionImpact resolutionImpact = getResolutionImpact(element); | 276 ResolutionImpact resolutionImpact = getResolutionImpact(element); |
276 assert(invariant(element, resolutionImpact != null, | 277 assert(invariant(element, resolutionImpact != null, |
277 message: 'No impact found for $element (${element.library})')); | 278 message: 'No impact found for $element (${element.library})')); |
| 279 if (element is ExecutableElement) { |
| 280 getResolvedAst(element); |
| 281 } |
278 return _impactTransformer.transformResolutionImpact(resolutionImpact); | 282 return _impactTransformer.transformResolutionImpact(resolutionImpact); |
279 } | 283 } |
280 | 284 |
281 @override | 285 @override |
282 bool isDeserialized(Element element) { | 286 bool isDeserialized(Element element) { |
283 return deserializedLibraries.contains(element.library); | 287 return deserializedLibraries.contains(element.library); |
284 } | 288 } |
285 } | 289 } |
286 | 290 |
287 const String RESOLVED_AST_TAG = 'resolvedAst'; | 291 const String RESOLVED_AST_TAG = 'resolvedAst'; |
(...skipping 19 matching lines...) Expand all Loading... |
307 nativeDataSerializer).serialize(); | 311 nativeDataSerializer).serialize(); |
308 } | 312 } |
309 } | 313 } |
310 } | 314 } |
311 | 315 |
312 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { | 316 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { |
313 final ParsingContext parsingContext; | 317 final ParsingContext parsingContext; |
314 final DeserializerPlugin nativeDataDeserializer; | 318 final DeserializerPlugin nativeDataDeserializer; |
315 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; | 319 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; |
316 | 320 |
317 Map<ExecutableElement, ResolvedAst> _resolvedAstMap = | |
318 <ExecutableElement, ResolvedAst>{}; | |
319 Map<MemberElement, ObjectDecoder> _decoderMap = | 321 Map<MemberElement, ObjectDecoder> _decoderMap = |
320 <MemberElement, ObjectDecoder>{}; | 322 <MemberElement, ObjectDecoder>{}; |
321 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; | 323 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; |
322 | 324 |
323 ResolvedAstDeserializerPlugin( | 325 ResolvedAstDeserializerPlugin( |
324 this.parsingContext, this.nativeDataDeserializer); | 326 this.parsingContext, this.nativeDataDeserializer); |
325 | 327 |
326 bool hasResolvedAst(ExecutableElement element) { | 328 bool hasResolvedAst(ExecutableElement element) { |
327 return _resolvedAstMap.containsKey(element) || | 329 return getResolvedAst(element) != null; |
328 _decoderMap.containsKey(element.memberContext); | |
329 } | 330 } |
330 | 331 |
331 ResolvedAst getResolvedAst(ExecutableElement element) { | 332 ResolvedAst getResolvedAst(ExecutableElement element) { |
332 ResolvedAst resolvedAst = _resolvedAstMap[element]; | 333 if (element.hasResolvedAst) { |
333 if (resolvedAst == null) { | 334 return element.resolvedAst; |
334 ObjectDecoder decoder = _decoderMap[element.memberContext]; | |
335 if (decoder != null) { | |
336 ResolvedAstDeserializer.deserialize( | |
337 element.memberContext, decoder, parsingContext, findToken, | |
338 nativeDataDeserializer, | |
339 _resolvedAstMap); | |
340 _decoderMap.remove(element); | |
341 resolvedAst = _resolvedAstMap[element]; | |
342 } | |
343 } | 335 } |
344 return resolvedAst; | 336 |
| 337 ObjectDecoder decoder = _decoderMap[element.memberContext]; |
| 338 if (decoder != null) { |
| 339 ResolvedAstDeserializer.deserialize( |
| 340 element.memberContext, decoder, parsingContext, findToken, |
| 341 nativeDataDeserializer); |
| 342 _decoderMap.remove(element); |
| 343 assert(invariant(element, element.hasResolvedAst, |
| 344 message: "ResolvedAst not computed for $element.")); |
| 345 return element.resolvedAst; |
| 346 } |
| 347 return null; |
345 } | 348 } |
346 | 349 |
347 Token findToken(Uri uri, int offset) { | 350 Token findToken(Uri uri, int offset) { |
348 Token beginToken = beginTokenMap.putIfAbsent(uri, () { | 351 Token beginToken = beginTokenMap.putIfAbsent(uri, () { |
349 SourceFile sourceFile = sourceFiles[uri]; | 352 SourceFile sourceFile = sourceFiles[uri]; |
350 if (sourceFile == null) { | 353 if (sourceFile == null) { |
351 throw 'No source file found for $uri in:\n ' | 354 throw 'No source file found for $uri in:\n ' |
352 '${sourceFiles.keys.join('\n ')}'; | 355 '${sourceFiles.keys.join('\n ')}'; |
353 } | 356 } |
354 return new Scanner(sourceFile).tokenize(); | 357 return new Scanner(sourceFile).tokenize(); |
355 }); | 358 }); |
356 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); | 359 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); |
357 } | 360 } |
358 | 361 |
359 @override | 362 @override |
360 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 363 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
361 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 364 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
362 if (decoder != null) { | 365 if (decoder != null) { |
363 _decoderMap[element] = decoder; | 366 _decoderMap[element] = decoder; |
364 } | 367 } |
365 } | 368 } |
366 } | 369 } |
367 | 370 |
OLD | NEW |