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_system; | 5 library dart2js.serialization_system; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import '../commandline_options.dart'; | 8 import '../commandline_options.dart'; |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/backend_api.dart'; | 10 import '../common/backend_api.dart'; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri); | 64 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri); |
65 if (library != null) { | 65 if (library != null) { |
66 deserializedLibraries.add(library); | 66 deserializedLibraries.add(library); |
67 return Future.forEach(library.compilationUnits, | 67 return Future.forEach(library.compilationUnits, |
68 (CompilationUnitElement compilationUnit) { | 68 (CompilationUnitElement compilationUnit) { |
69 ScriptZ script = compilationUnit.script; | 69 ScriptZ script = compilationUnit.script; |
70 return _compiler | 70 return _compiler |
71 .readScript(script.readableUri) | 71 .readScript(script.readableUri) |
72 .then((Script newScript) { | 72 .then((Script newScript) { |
73 script.file = newScript.file; | 73 script.file = newScript.file; |
74 _resolvedAstDeserializer.sourceFiles[script.resourceUri] = | 74 script.isSynthesized = newScript.isSynthesized; |
75 newScript.file; | 75 _resolvedAstDeserializer.scripts[script.resourceUri] = script; |
76 }); | 76 }); |
77 }).then((_) => library); | 77 }).then((_) => library); |
78 } | 78 } |
79 return new Future<LibraryElement>.value(library); | 79 return new Future<LibraryElement>.value(library); |
80 } | 80 } |
81 | 81 |
82 // TODO(johnniwinther): Remove the need for this method. | 82 // TODO(johnniwinther): Remove the need for this method. |
83 @override | 83 @override |
84 bool hasResolvedAst(ExecutableElement element) { | 84 bool hasResolvedAst(ExecutableElement element) { |
85 return getResolvedAst(element) != null; | 85 return getResolvedAst(element) != null; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 new ResolvedAstSerializer( | 193 new ResolvedAstSerializer( |
194 objectEncoder, resolvedAst, nativeDataSerializer) | 194 objectEncoder, resolvedAst, nativeDataSerializer) |
195 .serialize(); | 195 .serialize(); |
196 } | 196 } |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { | 200 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { |
201 final ParsingContext parsingContext; | 201 final ParsingContext parsingContext; |
202 final DeserializerPlugin nativeDataDeserializer; | 202 final DeserializerPlugin nativeDataDeserializer; |
203 final Map<Uri, SourceFile> sourceFiles = <Uri, SourceFile>{}; | 203 final Map<Uri, Script> scripts = <Uri, Script>{}; |
204 | 204 |
205 Map<MemberElement, ObjectDecoder> _decoderMap = | 205 Map<MemberElement, ObjectDecoder> _decoderMap = |
206 <MemberElement, ObjectDecoder>{}; | 206 <MemberElement, ObjectDecoder>{}; |
207 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; | 207 Map<Uri, Token> beginTokenMap = <Uri, Token>{}; |
208 | 208 |
209 ResolvedAstDeserializerPlugin( | 209 ResolvedAstDeserializerPlugin( |
210 this.parsingContext, this.nativeDataDeserializer); | 210 this.parsingContext, this.nativeDataDeserializer); |
211 | 211 |
212 bool hasResolvedAst(ExecutableElement element) { | 212 bool hasResolvedAst(ExecutableElement element) { |
213 return getResolvedAst(element) != null; | 213 return getResolvedAst(element) != null; |
(...skipping 11 matching lines...) Expand all Loading... |
225 _decoderMap.remove(element); | 225 _decoderMap.remove(element); |
226 assert(invariant(element, element.hasResolvedAst, | 226 assert(invariant(element, element.hasResolvedAst, |
227 message: "ResolvedAst not computed for $element.")); | 227 message: "ResolvedAst not computed for $element.")); |
228 return element.resolvedAst; | 228 return element.resolvedAst; |
229 } | 229 } |
230 return null; | 230 return null; |
231 } | 231 } |
232 | 232 |
233 Token findToken(Uri uri, int offset) { | 233 Token findToken(Uri uri, int offset) { |
234 Token beginToken = beginTokenMap.putIfAbsent(uri, () { | 234 Token beginToken = beginTokenMap.putIfAbsent(uri, () { |
235 SourceFile sourceFile = sourceFiles[uri]; | 235 Script script = scripts[uri]; |
236 if (sourceFile == null) { | 236 if (script == null) { |
237 throw 'No source file found for $uri in:\n ' | 237 parsingContext.reporter.internalError(NO_LOCATION_SPANNABLE, |
238 '${sourceFiles.keys.join('\n ')}'; | 238 'No source file found for $uri in:\n ${scripts.keys.join('\n ')}'); |
239 } | 239 } |
240 return new Scanner(sourceFile).tokenize(); | 240 if (script.isSynthesized) return null; |
| 241 return new Scanner(script.file).tokenize(); |
241 }); | 242 }); |
| 243 if (beginToken == null) return null; |
242 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); | 244 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); |
243 } | 245 } |
244 | 246 |
245 @override | 247 @override |
246 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 248 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
247 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 249 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
248 if (decoder != null) { | 250 if (decoder != null) { |
249 _decoderMap[element] = decoder; | 251 _decoderMap[element] = decoder; |
250 } | 252 } |
251 } | 253 } |
252 } | 254 } |
OLD | NEW |