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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 _resolvedAstDeserializer.sourceFiles[script.resourceUri] = | 204 _resolvedAstDeserializer.sourceFiles[script.resourceUri] = |
205 newScript.file; | 205 newScript.file; |
206 }); | 206 }); |
207 }).then((_) => library); | 207 }).then((_) => library); |
208 } | 208 } |
209 } | 209 } |
210 return new Future<LibraryElement>.value(library); | 210 return new Future<LibraryElement>.value(library); |
211 } | 211 } |
212 | 212 |
213 @override | 213 @override |
214 bool hasResolvedAst(Element element) { | 214 bool hasResolvedAst(ExecutableElement element) { |
215 if (_resolvedAstDeserializer != null) { | 215 if (_resolvedAstDeserializer != null) { |
216 return _resolvedAstDeserializer.hasResolvedAst(element); | 216 return _resolvedAstDeserializer.hasResolvedAst(element); |
217 } | 217 } |
218 return false; | 218 return false; |
219 } | 219 } |
220 | 220 |
221 @override | 221 @override |
222 ResolvedAst getResolvedAst(Element element) { | 222 ResolvedAst getResolvedAst(ExecutableElement element) { |
223 if (_resolvedAstDeserializer != null) { | 223 if (_resolvedAstDeserializer != null) { |
224 return _resolvedAstDeserializer.getResolvedAst(element); | 224 return _resolvedAstDeserializer.getResolvedAst(element); |
225 } | 225 } |
226 return null; | 226 return null; |
227 } | 227 } |
228 | 228 |
229 @override | 229 @override |
230 bool hasResolutionImpact(Element element) { | 230 bool hasResolutionImpact(Element element) { |
231 if (element.isConstructor && | 231 if (element.isConstructor && |
232 element.enclosingClass.isUnnamedMixinApplication) { | 232 element.enclosingClass.isUnnamedMixinApplication) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 backend.serialization.serializer).serialize(); | 293 backend.serialization.serializer).serialize(); |
294 } | 294 } |
295 } | 295 } |
296 } | 296 } |
297 | 297 |
298 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { | 298 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { |
299 final ParsingContext parsingContext; | 299 final ParsingContext parsingContext; |
300 final Backend backend; | 300 final Backend backend; |
301 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; | 301 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; |
302 | 302 |
303 Map<Element, ResolvedAst> _resolvedAstMap = <Element, ResolvedAst>{}; | 303 Map<ExecutableElement, ResolvedAst> _resolvedAstMap = |
304 Map<Element, ObjectDecoder> _decoderMap = <Element, ObjectDecoder>{}; | 304 <ExecutableElement, ResolvedAst>{}; |
| 305 Map<MemberElement, ObjectDecoder> _decoderMap = |
| 306 <MemberElement, ObjectDecoder>{}; |
305 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; | 307 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; |
306 | 308 |
307 ResolvedAstDeserializerPlugin(this.parsingContext, this.backend); | 309 ResolvedAstDeserializerPlugin(this.parsingContext, this.backend); |
308 | 310 |
309 bool hasResolvedAst(Element element) { | 311 bool hasResolvedAst(ExecutableElement element) { |
310 return _resolvedAstMap.containsKey(element) || | 312 return _resolvedAstMap.containsKey(element) || |
311 _decoderMap.containsKey(element); | 313 _decoderMap.containsKey(element.memberContext); |
312 } | 314 } |
313 | 315 |
314 ResolvedAst getResolvedAst(Element element) { | 316 ResolvedAst getResolvedAst(ExecutableElement element) { |
315 ResolvedAst resolvedAst = _resolvedAstMap[element]; | 317 ResolvedAst resolvedAst = _resolvedAstMap[element]; |
316 if (resolvedAst == null) { | 318 if (resolvedAst == null) { |
317 ObjectDecoder decoder = _decoderMap[element]; | 319 ObjectDecoder decoder = _decoderMap[element.memberContext]; |
318 if (decoder != null) { | 320 if (decoder != null) { |
319 resolvedAst = _resolvedAstMap[element] = | 321 ResolvedAstDeserializer.deserialize( |
320 ResolvedAstDeserializer.deserialize( | 322 element.memberContext, decoder, parsingContext, findToken, |
321 element, decoder, parsingContext, findToken, | 323 backend.serialization.deserializer, |
322 backend.serialization.deserializer); | 324 _resolvedAstMap); |
323 _decoderMap.remove(element); | 325 _decoderMap.remove(element); |
| 326 resolvedAst = _resolvedAstMap[element]; |
324 } | 327 } |
325 } | 328 } |
326 return resolvedAst; | 329 return resolvedAst; |
327 } | 330 } |
328 | 331 |
329 Token findToken(Uri uri, int offset) { | 332 Token findToken(Uri uri, int offset) { |
330 Token beginToken = beginTokenMap.putIfAbsent(uri, () { | 333 Token beginToken = beginTokenMap.putIfAbsent(uri, () { |
331 SourceFile sourceFile = sourceFiles[uri]; | 334 SourceFile sourceFile = sourceFiles[uri]; |
332 if (sourceFile == null) { | 335 if (sourceFile == null) { |
333 throw 'No source file found for $uri in:\n ' | 336 throw 'No source file found for $uri in:\n ' |
334 '${sourceFiles.keys.join('\n ')}'; | 337 '${sourceFiles.keys.join('\n ')}'; |
335 } | 338 } |
336 return new Scanner(sourceFile).tokenize(); | 339 return new Scanner(sourceFile).tokenize(); |
337 }); | 340 }); |
338 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); | 341 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); |
339 } | 342 } |
340 | 343 |
341 @override | 344 @override |
342 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 345 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
343 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 346 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
344 if (decoder != null) { | 347 if (decoder != null) { |
345 _decoderMap[element] = decoder; | 348 _decoderMap[element] = decoder; |
346 } | 349 } |
347 } | 350 } |
348 } | 351 } |
349 | 352 |
OLD | NEW |