| 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 10 matching lines...) Expand all Loading... |
| 21 import '../universe/world_impact.dart'; | 21 import '../universe/world_impact.dart'; |
| 22 import '../universe/use.dart'; | 22 import '../universe/use.dart'; |
| 23 import 'json_serializer.dart'; | 23 import 'json_serializer.dart'; |
| 24 import 'modelz.dart'; | 24 import 'modelz.dart'; |
| 25 import 'resolved_ast_serialization.dart'; | 25 import 'resolved_ast_serialization.dart'; |
| 26 import 'serialization.dart'; | 26 import 'serialization.dart'; |
| 27 import 'task.dart'; | 27 import 'task.dart'; |
| 28 | 28 |
| 29 class DeserializerSystemImpl extends DeserializerSystem { | 29 class DeserializerSystemImpl extends DeserializerSystem { |
| 30 final Compiler _compiler; | 30 final Compiler _compiler; |
| 31 final Resolution resolution; |
| 31 final DeserializationContext deserializationContext; | 32 final DeserializationContext deserializationContext; |
| 32 final List<LibraryElement> deserializedLibraries = <LibraryElement>[]; | 33 final List<LibraryElement> deserializedLibraries = <LibraryElement>[]; |
| 33 final ResolutionImpactDeserializer _resolutionImpactDeserializer; | 34 final ResolutionImpactDeserializer _resolutionImpactDeserializer; |
| 34 final ResolvedAstDeserializerPlugin _resolvedAstDeserializer; | 35 final ResolvedAstDeserializerPlugin _resolvedAstDeserializer; |
| 35 final ImpactTransformer _impactTransformer; | |
| 36 | 36 |
| 37 factory DeserializerSystemImpl( | 37 factory DeserializerSystemImpl(Compiler compiler) { |
| 38 Compiler compiler, ImpactTransformer impactTransformer) { | 38 DeserializationContext context = new DeserializationContext( |
| 39 DeserializationContext context = | 39 compiler.reporter, compiler.resolution, compiler.libraryLoader); |
| 40 new DeserializationContext( | |
| 41 compiler.reporter, compiler.resolution, compiler.libraryLoader); | |
| 42 DeserializerPlugin backendDeserializer = | 40 DeserializerPlugin backendDeserializer = |
| 43 compiler.backend.serialization.deserializer; | 41 compiler.backend.serialization.deserializer; |
| 44 context.plugins.add(backendDeserializer); | 42 context.plugins.add(backendDeserializer); |
| 45 ResolutionImpactDeserializer resolutionImpactDeserializer = | 43 ResolutionImpactDeserializer resolutionImpactDeserializer = |
| 46 new ResolutionImpactDeserializer(backendDeserializer); | 44 new ResolutionImpactDeserializer(backendDeserializer); |
| 47 context.plugins.add(resolutionImpactDeserializer); | 45 context.plugins.add(resolutionImpactDeserializer); |
| 48 ResolvedAstDeserializerPlugin resolvedAstDeserializer = | 46 ResolvedAstDeserializerPlugin resolvedAstDeserializer = |
| 49 new ResolvedAstDeserializerPlugin( | 47 new ResolvedAstDeserializerPlugin( |
| 50 compiler.parsingContext, backendDeserializer); | 48 compiler.parsingContext, backendDeserializer); |
| 51 context.plugins.add(resolvedAstDeserializer); | 49 context.plugins.add(resolvedAstDeserializer); |
| 52 return new DeserializerSystemImpl._(compiler, context, impactTransformer, | 50 return new DeserializerSystemImpl._(compiler, compiler.resolution, context, |
| 53 resolutionImpactDeserializer, resolvedAstDeserializer); | 51 resolutionImpactDeserializer, resolvedAstDeserializer); |
| 54 } | 52 } |
| 55 | 53 |
| 56 DeserializerSystemImpl._( | 54 DeserializerSystemImpl._( |
| 57 this._compiler, | 55 this._compiler, |
| 56 this.resolution, |
| 58 this.deserializationContext, | 57 this.deserializationContext, |
| 59 this._impactTransformer, | |
| 60 this._resolutionImpactDeserializer, | 58 this._resolutionImpactDeserializer, |
| 61 this._resolvedAstDeserializer); | 59 this._resolvedAstDeserializer); |
| 62 | 60 |
| 63 @override | 61 @override |
| 64 Future<LibraryElement> readLibrary(Uri resolvedUri) { | 62 Future<LibraryElement> readLibrary(Uri resolvedUri) { |
| 65 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri); | 63 LibraryElement library = deserializationContext.lookupLibrary(resolvedUri); |
| 66 if (library != null) { | 64 if (library != null) { |
| 67 deserializedLibraries.add(library); | 65 deserializedLibraries.add(library); |
| 68 return Future.forEach(library.compilationUnits, | 66 return Future.forEach(library.compilationUnits, |
| 69 (CompilationUnitElement compilationUnit) { | 67 (CompilationUnitElement compilationUnit) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 FieldElement field = element; | 133 FieldElement field = element; |
| 136 if (field.isTopLevel || field.isStatic) { | 134 if (field.isTopLevel || field.isStatic) { |
| 137 if (field.constant == null) { | 135 if (field.constant == null) { |
| 138 // TODO(johnniwinther): Find a cleaner way to do this. Maybe | 136 // TODO(johnniwinther): Find a cleaner way to do this. Maybe |
| 139 // `Feature.LAZY_FIELD` of the resolution impact should be used | 137 // `Feature.LAZY_FIELD` of the resolution impact should be used |
| 140 // instead. | 138 // instead. |
| 141 _compiler.backend.constants.registerLazyStatic(element); | 139 _compiler.backend.constants.registerLazyStatic(element); |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 } | 142 } |
| 145 return _impactTransformer.transformResolutionImpact(resolutionImpact); | 143 return resolution.transformResolutionImpact(element, resolutionImpact); |
| 146 } | 144 } |
| 147 | 145 |
| 148 @override | 146 @override |
| 149 bool isDeserialized(Element element) { | 147 bool isDeserialized(Element element) { |
| 150 return deserializedLibraries.contains(element.library); | 148 return deserializedLibraries.contains(element.library); |
| 151 } | 149 } |
| 152 } | 150 } |
| 153 | 151 |
| 154 const String WORLD_IMPACT_TAG = 'worldImpact'; | 152 const String WORLD_IMPACT_TAG = 'worldImpact'; |
| 155 | 153 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 ResolutionImpact getResolutionImpact(Element element) { | 195 ResolutionImpact getResolutionImpact(Element element) { |
| 198 return registerResolutionImpact(element, () { | 196 return registerResolutionImpact(element, () { |
| 199 ObjectDecoder decoder = _decoderMap[element]; | 197 ObjectDecoder decoder = _decoderMap[element]; |
| 200 if (decoder != null) { | 198 if (decoder != null) { |
| 201 _decoderMap.remove(element); | 199 _decoderMap.remove(element); |
| 202 return ImpactDeserializer.deserializeImpact( | 200 return ImpactDeserializer.deserializeImpact( |
| 203 element, decoder, nativeDataDeserializer); | 201 element, decoder, nativeDataDeserializer); |
| 204 } | 202 } |
| 205 return null; | 203 return null; |
| 206 }); | 204 }); |
| 207 | |
| 208 } | 205 } |
| 209 } | 206 } |
| 210 | 207 |
| 211 const String RESOLVED_AST_TAG = 'resolvedAst'; | 208 const String RESOLVED_AST_TAG = 'resolvedAst'; |
| 212 | 209 |
| 213 class ResolvedAstSerializerPlugin extends SerializerPlugin { | 210 class ResolvedAstSerializerPlugin extends SerializerPlugin { |
| 214 final Resolution resolution; | 211 final Resolution resolution; |
| 215 final SerializerPlugin nativeDataSerializer; | 212 final SerializerPlugin nativeDataSerializer; |
| 216 | 213 |
| 217 ResolvedAstSerializerPlugin(this.resolution, this.nativeDataSerializer); | 214 ResolvedAstSerializerPlugin(this.resolution, this.nativeDataSerializer); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 277 } |
| 281 | 278 |
| 282 @override | 279 @override |
| 283 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 280 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
| 284 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 281 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
| 285 if (decoder != null) { | 282 if (decoder != null) { |
| 286 _decoderMap[element] = decoder; | 283 _decoderMap[element] = decoder; |
| 287 } | 284 } |
| 288 } | 285 } |
| 289 } | 286 } |
| OLD | NEW |