| 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 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/resolution.dart'; | 10 import '../common/resolution.dart'; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 bool hasResolutionImpact(Element element) => true; | 81 bool hasResolutionImpact(Element element) => true; |
| 82 | 82 |
| 83 @override | 83 @override |
| 84 ResolutionImpact getResolutionImpact(Element element) { | 84 ResolutionImpact getResolutionImpact(Element element) { |
| 85 return const ResolutionImpact(); | 85 return const ResolutionImpact(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 @override | 88 @override |
| 89 WorldImpact computeWorldImpact(Element element) { | 89 WorldImpact computeWorldImpact(Element element) { |
| 90 ResolutionImpact resolutionImpact = getResolutionImpact(element); | 90 ResolutionImpact resolutionImpact = getResolutionImpact(element); |
| 91 assert(invariant(element, resolutionImpact != null, | 91 assert(resolutionImpact != null, |
| 92 message: 'No impact found for $element (${element.library})')); | 92 failedAt(element, 'No impact found for $element (${element.library})')); |
| 93 if (element is ExecutableElement) { | 93 if (element is ExecutableElement) { |
| 94 getResolvedAst(element); | 94 getResolvedAst(element); |
| 95 } | 95 } |
| 96 if (element.isField && !element.isConst) { | 96 if (element.isField && !element.isConst) { |
| 97 FieldElement field = element; | 97 FieldElement field = element; |
| 98 if (field.isTopLevel || field.isStatic) { | 98 if (field.isTopLevel || field.isStatic) { |
| 99 if (field.constant == null) { | 99 if (field.constant == null) { |
| 100 // TODO(johnniwinther): Find a cleaner way to do this. Maybe | 100 // TODO(johnniwinther): Find a cleaner way to do this. Maybe |
| 101 // `Feature.LAZY_FIELD` of the resolution impact should be used | 101 // `Feature.LAZY_FIELD` of the resolution impact should be used |
| 102 // instead. | 102 // instead. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 | 154 |
| 155 @override | 155 @override |
| 156 ResolutionImpact getResolutionImpact(Element element) { | 156 ResolutionImpact getResolutionImpact(Element element) { |
| 157 if (element.isConstructor && | 157 if (element.isConstructor && |
| 158 element.enclosingClass.isUnnamedMixinApplication) { | 158 element.enclosingClass.isUnnamedMixinApplication) { |
| 159 ConstructorElement constructor = element; | 159 ConstructorElement constructor = element; |
| 160 ClassElement superclass = constructor.enclosingClass.superclass; | 160 ClassElement superclass = constructor.enclosingClass.superclass; |
| 161 ConstructorElement superclassConstructor = | 161 ConstructorElement superclassConstructor = |
| 162 superclass.lookupConstructor(constructor.name); | 162 superclass.lookupConstructor(constructor.name); |
| 163 assert(invariant(element, superclassConstructor != null, | 163 assert( |
| 164 message: "Superclass constructor '${constructor.name}' called from " | 164 superclassConstructor != null, |
| 165 failedAt( |
| 166 element, |
| 167 "Superclass constructor '${constructor.name}' called from " |
| 165 "${element} not found in ${superclass}.")); | 168 "${element} not found in ${superclass}.")); |
| 166 // TODO(johnniwinther): Compute callStructure. Currently not used. | 169 // TODO(johnniwinther): Compute callStructure. Currently not used. |
| 167 CallStructure callStructure; | 170 CallStructure callStructure; |
| 168 return _resolutionImpactDeserializer.registerResolutionImpact(constructor, | 171 return _resolutionImpactDeserializer.registerResolutionImpact(constructor, |
| 169 () { | 172 () { |
| 170 List<TypeUse> typeUses = <TypeUse>[]; | 173 List<TypeUse> typeUses = <TypeUse>[]; |
| 171 void addCheckedModeCheck(ResolutionDartType type) { | 174 void addCheckedModeCheck(ResolutionDartType type) { |
| 172 if (!type.isDynamic) { | 175 if (!type.isDynamic) { |
| 173 typeUses.add(new TypeUse.checkedModeCheck(type)); | 176 typeUses.add(new TypeUse.checkedModeCheck(type)); |
| 174 } | 177 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 const String RESOLVED_AST_TAG = 'resolvedAst'; | 254 const String RESOLVED_AST_TAG = 'resolvedAst'; |
| 252 | 255 |
| 253 class ResolvedAstSerializerPlugin extends SerializerPlugin { | 256 class ResolvedAstSerializerPlugin extends SerializerPlugin { |
| 254 final Resolution resolution; | 257 final Resolution resolution; |
| 255 final SerializerPlugin nativeDataSerializer; | 258 final SerializerPlugin nativeDataSerializer; |
| 256 | 259 |
| 257 ResolvedAstSerializerPlugin(this.resolution, this.nativeDataSerializer); | 260 ResolvedAstSerializerPlugin(this.resolution, this.nativeDataSerializer); |
| 258 | 261 |
| 259 @override | 262 @override |
| 260 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { | 263 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { |
| 261 assert(invariant(element, element.isDeclaration, | 264 assert(element.isDeclaration, |
| 262 message: "Element $element must be the declaration")); | 265 failedAt(element, "Element $element must be the declaration")); |
| 263 if (element.isError) return; | 266 if (element.isError) return; |
| 264 if (element is MemberElement) { | 267 if (element is MemberElement) { |
| 265 assert(invariant(element, resolution.hasResolvedAst(element), | 268 assert(resolution.hasResolvedAst(element), |
| 266 message: "Element $element must have a resolved ast")); | 269 failedAt(element, "Element $element must have a resolved ast")); |
| 267 ResolvedAst resolvedAst = resolution.getResolvedAst(element); | 270 ResolvedAst resolvedAst = resolution.getResolvedAst(element); |
| 268 ObjectEncoder objectEncoder = createEncoder(RESOLVED_AST_TAG); | 271 ObjectEncoder objectEncoder = createEncoder(RESOLVED_AST_TAG); |
| 269 new ResolvedAstSerializer( | 272 new ResolvedAstSerializer( |
| 270 objectEncoder, resolvedAst, nativeDataSerializer) | 273 objectEncoder, resolvedAst, nativeDataSerializer) |
| 271 .serialize(); | 274 .serialize(); |
| 272 } | 275 } |
| 273 } | 276 } |
| 274 } | 277 } |
| 275 | 278 |
| 276 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { | 279 class ResolvedAstDeserializerPlugin extends DeserializerPlugin { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 292 ResolvedAst getResolvedAst(ExecutableElement element) { | 295 ResolvedAst getResolvedAst(ExecutableElement element) { |
| 293 if (element.hasResolvedAst) { | 296 if (element.hasResolvedAst) { |
| 294 return element.resolvedAst; | 297 return element.resolvedAst; |
| 295 } | 298 } |
| 296 | 299 |
| 297 ObjectDecoder decoder = _decoderMap[element.memberContext]; | 300 ObjectDecoder decoder = _decoderMap[element.memberContext]; |
| 298 if (decoder != null) { | 301 if (decoder != null) { |
| 299 ResolvedAstDeserializer.deserialize(element.memberContext, decoder, | 302 ResolvedAstDeserializer.deserialize(element.memberContext, decoder, |
| 300 parsingContext, findToken, nativeDataDeserializer); | 303 parsingContext, findToken, nativeDataDeserializer); |
| 301 _decoderMap.remove(element); | 304 _decoderMap.remove(element); |
| 302 assert(invariant(element, element.hasResolvedAst, | 305 assert(element.hasResolvedAst, |
| 303 message: "ResolvedAst not computed for $element.")); | 306 failedAt(element, "ResolvedAst not computed for $element.")); |
| 304 return element.resolvedAst; | 307 return element.resolvedAst; |
| 305 } | 308 } |
| 306 return null; | 309 return null; |
| 307 } | 310 } |
| 308 | 311 |
| 309 Token findToken(Uri uri, int offset) { | 312 Token findToken(Uri uri, int offset) { |
| 310 Token beginToken = beginTokenMap.putIfAbsent(uri, () { | 313 Token beginToken = beginTokenMap.putIfAbsent(uri, () { |
| 311 Script script = scripts[uri]; | 314 Script script = scripts[uri]; |
| 312 if (script == null) { | 315 if (script == null) { |
| 313 parsingContext.reporter.internalError(NO_LOCATION_SPANNABLE, | 316 parsingContext.reporter.internalError(NO_LOCATION_SPANNABLE, |
| 314 'No source file found for $uri in:\n ${scripts.keys.join('\n ')}'); | 317 'No source file found for $uri in:\n ${scripts.keys.join('\n ')}'); |
| 315 } | 318 } |
| 316 if (script.isSynthesized) return null; | 319 if (script.isSynthesized) return null; |
| 317 return parsingContext.scanner.scanFile(script.file); | 320 return parsingContext.scanner.scanFile(script.file); |
| 318 }); | 321 }); |
| 319 if (beginToken == null) return null; | 322 if (beginToken == null) return null; |
| 320 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); | 323 return ResolvedAstDeserializer.findTokenInStream(beginToken, offset); |
| 321 } | 324 } |
| 322 | 325 |
| 323 @override | 326 @override |
| 324 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 327 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
| 325 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); | 328 ObjectDecoder decoder = getDecoder(RESOLVED_AST_TAG); |
| 326 if (decoder != null) { | 329 if (decoder != null) { |
| 327 _decoderMap[element] = decoder; | 330 _decoderMap[element] = decoder; |
| 328 } | 331 } |
| 329 } | 332 } |
| 330 } | 333 } |
| OLD | NEW |