| 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.impact; | 5 library dart2js.serialization.impact; |
| 6 | 6 |
| 7 import '../common.dart'; |
| 7 import '../common/resolution.dart'; | 8 import '../common/resolution.dart'; |
| 8 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 9 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| 10 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 11 import '../universe/selector.dart'; | 12 import '../universe/selector.dart'; |
| 12 import '../universe/use.dart'; | 13 import '../universe/use.dart'; |
| 13 import '../universe/world_impact.dart'; | 14 import '../universe/world_impact.dart'; |
| 14 import '../util/enumset.dart'; | 15 import '../util/enumset.dart'; |
| 15 import 'keys.dart'; | 16 import 'keys.dart'; |
| 16 import 'serialization.dart'; | 17 import 'serialization.dart'; |
| 17 import 'serialization_util.dart'; | 18 import 'serialization_util.dart'; |
| 18 | 19 |
| 19 /// Visitor that serializes a [ResolutionImpact] object using an | 20 /// Visitor that serializes a [ResolutionImpact] object using an |
| 20 /// [ObjectEncoder]. | 21 /// [ObjectEncoder]. |
| 21 class ImpactSerializer implements WorldImpactVisitor { | 22 class ImpactSerializer implements WorldImpactVisitor { |
| 23 final Element element; |
| 22 final ObjectEncoder objectEncoder; | 24 final ObjectEncoder objectEncoder; |
| 23 final ListEncoder staticUses; | 25 final ListEncoder staticUses; |
| 24 final ListEncoder dynamicUses; | 26 final ListEncoder dynamicUses; |
| 25 final ListEncoder typeUses; | 27 final ListEncoder typeUses; |
| 26 | 28 |
| 27 ImpactSerializer(ObjectEncoder objectEncoder) | 29 ImpactSerializer(this.element, ObjectEncoder objectEncoder) |
| 28 : this.objectEncoder = objectEncoder, | 30 : this.objectEncoder = objectEncoder, |
| 29 staticUses = objectEncoder.createList(Key.STATIC_USES), | 31 staticUses = objectEncoder.createList(Key.STATIC_USES), |
| 30 dynamicUses = objectEncoder.createList(Key.DYNAMIC_USES), | 32 dynamicUses = objectEncoder.createList(Key.DYNAMIC_USES), |
| 31 typeUses = objectEncoder.createList(Key.TYPE_USES); | 33 typeUses = objectEncoder.createList(Key.TYPE_USES); |
| 32 | 34 |
| 33 void serialize(ResolutionImpact resolutionImpact) { | 35 void serialize(ResolutionImpact resolutionImpact) { |
| 34 resolutionImpact.apply(this); | 36 resolutionImpact.apply(this); |
| 35 objectEncoder.setStrings(Key.SYMBOLS, resolutionImpact.constSymbolNames); | 37 objectEncoder.setStrings(Key.SYMBOLS, resolutionImpact.constSymbolNames); |
| 36 objectEncoder.setConstants( | 38 objectEncoder.setConstants( |
| 37 Key.CONSTANTS, resolutionImpact.constantLiterals); | 39 Key.CONSTANTS, resolutionImpact.constantLiterals); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 } | 59 } |
| 58 | 60 |
| 59 @override | 61 @override |
| 60 void visitDynamicUse(DynamicUse dynamicUse) { | 62 void visitDynamicUse(DynamicUse dynamicUse) { |
| 61 ObjectEncoder object = dynamicUses.createObject(); | 63 ObjectEncoder object = dynamicUses.createObject(); |
| 62 serializeSelector(dynamicUse.selector, object); | 64 serializeSelector(dynamicUse.selector, object); |
| 63 } | 65 } |
| 64 | 66 |
| 65 @override | 67 @override |
| 66 void visitStaticUse(StaticUse staticUse) { | 68 void visitStaticUse(StaticUse staticUse) { |
| 67 if (staticUse.element.isGenerativeConstructor && | |
| 68 staticUse.element.enclosingClass.isUnnamedMixinApplication) { | |
| 69 // TODO(johnniwinther): Handle static use of forwarding constructors. | |
| 70 return; | |
| 71 } | |
| 72 ObjectEncoder object = staticUses.createObject(); | 69 ObjectEncoder object = staticUses.createObject(); |
| 73 object.setEnum(Key.KIND, staticUse.kind); | 70 object.setEnum(Key.KIND, staticUse.kind); |
| 74 object.setElement(Key.ELEMENT, staticUse.element); | 71 serializeElementReference( |
| 72 element, Key.ELEMENT, Key.NAME, object, staticUse.element); |
| 75 } | 73 } |
| 76 | 74 |
| 77 @override | 75 @override |
| 78 void visitTypeUse(TypeUse typeUse) { | 76 void visitTypeUse(TypeUse typeUse) { |
| 79 ObjectEncoder object = typeUses.createObject(); | 77 ObjectEncoder object = typeUses.createObject(); |
| 80 object.setEnum(Key.KIND, typeUse.kind); | 78 object.setEnum(Key.KIND, typeUse.kind); |
| 81 object.setType(Key.TYPE, typeUse.type); | 79 object.setType(Key.TYPE, typeUse.type); |
| 82 } | 80 } |
| 83 } | 81 } |
| 84 | 82 |
| 85 /// A deserialized [WorldImpact] object. | 83 /// A deserialized [WorldImpact] object. |
| 86 class DeserializedResolutionImpact extends WorldImpact | 84 class DeserializedResolutionImpact extends WorldImpact |
| 87 implements ResolutionImpact { | 85 implements ResolutionImpact { |
| 88 final Iterable<String> constSymbolNames; | 86 final Iterable<String> constSymbolNames; |
| 89 final Iterable<ConstantExpression> constantLiterals; | 87 final Iterable<ConstantExpression> constantLiterals; |
| 90 final Iterable<DynamicUse> dynamicUses; | 88 final Iterable<DynamicUse> dynamicUses; |
| 91 final EnumSet<Feature> _features; | 89 final EnumSet<Feature> _features; |
| 92 final Iterable<ListLiteralUse> listLiterals; | 90 final Iterable<ListLiteralUse> listLiterals; |
| 93 final Iterable<MapLiteralUse> mapLiterals; | 91 final Iterable<MapLiteralUse> mapLiterals; |
| 94 final Iterable<StaticUse> staticUses; | 92 final Iterable<StaticUse> staticUses; |
| 95 final Iterable<TypeUse> typeUses; | 93 final Iterable<TypeUse> typeUses; |
| 96 | 94 |
| 97 DeserializedResolutionImpact( | 95 DeserializedResolutionImpact( |
| 98 {this.constSymbolNames, | 96 {this.constSymbolNames: const <String>[], |
| 99 this.constantLiterals, | 97 this.constantLiterals: const <ConstantExpression>[], |
| 100 this.dynamicUses, | 98 this.dynamicUses: const <DynamicUse>[], |
| 101 EnumSet<Feature> features, | 99 EnumSet<Feature> features, |
| 102 this.listLiterals, | 100 this.listLiterals: const <ListLiteralUse>[], |
| 103 this.mapLiterals, | 101 this.mapLiterals: const <MapLiteralUse>[], |
| 104 this.staticUses, | 102 this.staticUses: const <StaticUse>[], |
| 105 this.typeUses}) | 103 this.typeUses: const <TypeUse>[]}) |
| 106 : this._features = features; | 104 : this._features = features; |
| 107 | 105 |
| 108 Iterable<Feature> get features => _features.iterable(Feature.values); | 106 Iterable<Feature> get features { |
| 107 return _features != null |
| 108 ? _features.iterable(Feature.values) |
| 109 : const <Feature>[]; |
| 110 } |
| 109 } | 111 } |
| 110 | 112 |
| 111 class ImpactDeserializer { | 113 class ImpactDeserializer { |
| 112 /// Deserializes a [WorldImpact] from [objectDecoder]. | 114 /// Deserializes a [WorldImpact] from [objectDecoder]. |
| 113 static ResolutionImpact deserializeImpact(ObjectDecoder objectDecoder) { | 115 static ResolutionImpact deserializeImpact( |
| 116 Element element, ObjectDecoder objectDecoder) { |
| 114 ListDecoder staticUseDecoder = objectDecoder.getList(Key.STATIC_USES); | 117 ListDecoder staticUseDecoder = objectDecoder.getList(Key.STATIC_USES); |
| 115 List<StaticUse> staticUses = <StaticUse>[]; | 118 List<StaticUse> staticUses = <StaticUse>[]; |
| 116 for (int index = 0; index < staticUseDecoder.length; index++) { | 119 for (int index = 0; index < staticUseDecoder.length; index++) { |
| 117 ObjectDecoder object = staticUseDecoder.getObject(index); | 120 ObjectDecoder object = staticUseDecoder.getObject(index); |
| 118 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); | 121 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); |
| 119 Element element = object.getElement(Key.ELEMENT); | 122 Element usedElement = |
| 120 staticUses.add(new StaticUse.internal(element, kind)); | 123 deserializeElementReference(element, Key.ELEMENT, Key.NAME, object); |
| 124 staticUses.add(new StaticUse.internal(usedElement, kind)); |
| 121 } | 125 } |
| 122 | 126 |
| 123 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES); | 127 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES); |
| 124 List<DynamicUse> dynamicUses = <DynamicUse>[]; | 128 List<DynamicUse> dynamicUses = <DynamicUse>[]; |
| 125 for (int index = 0; index < dynamicUseDecoder.length; index++) { | 129 for (int index = 0; index < dynamicUseDecoder.length; index++) { |
| 126 ObjectDecoder object = dynamicUseDecoder.getObject(index); | 130 ObjectDecoder object = dynamicUseDecoder.getObject(index); |
| 127 Selector selector = deserializeSelector(object); | 131 Selector selector = deserializeSelector(object); |
| 128 dynamicUses.add(new DynamicUse(selector, null)); | 132 dynamicUses.add(new DynamicUse(selector, null)); |
| 129 } | 133 } |
| 130 | 134 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 constSymbolNames: constSymbolNames, | 184 constSymbolNames: constSymbolNames, |
| 181 constantLiterals: constantLiterals, | 185 constantLiterals: constantLiterals, |
| 182 dynamicUses: dynamicUses, | 186 dynamicUses: dynamicUses, |
| 183 features: features, | 187 features: features, |
| 184 listLiterals: listLiterals, | 188 listLiterals: listLiterals, |
| 185 mapLiterals: mapLiterals, | 189 mapLiterals: mapLiterals, |
| 186 staticUses: staticUses, | 190 staticUses: staticUses, |
| 187 typeUses: typeUses); | 191 typeUses: typeUses); |
| 188 } | 192 } |
| 189 } | 193 } |
| OLD | NEW |