| OLD | NEW |
| 1 // Copyright (c) 2015, 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 '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../common/resolution.dart'; | 8 import '../common/resolution.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| 11 import '../universe/call_structure.dart'; | 11 import '../universe/call_structure.dart'; |
| 12 import '../universe/selector.dart'; | 12 import '../universe/selector.dart'; |
| 13 import '../universe/world_impact.dart'; | 13 import '../universe/world_impact.dart'; |
| 14 import '../universe/use.dart'; | 14 import '../universe/use.dart'; |
| 15 import '../util/enumset.dart'; | 15 import '../util/enumset.dart'; |
| 16 | 16 |
| 17 import 'keys.dart'; | 17 import 'keys.dart'; |
| 18 import 'serialization.dart'; | 18 import 'serialization.dart'; |
| 19 import 'serialization_util.dart'; |
| 19 | 20 |
| 20 /// Visitor that serializes a [ResolutionImpact] object using an | 21 /// Visitor that serializes a [ResolutionImpact] object using an |
| 21 /// [ObjectEncoder]. | 22 /// [ObjectEncoder]. |
| 22 class ImpactSerializer implements WorldImpactVisitor { | 23 class ImpactSerializer implements WorldImpactVisitor { |
| 23 final ObjectEncoder objectEncoder; | 24 final ObjectEncoder objectEncoder; |
| 24 final ListEncoder staticUses; | 25 final ListEncoder staticUses; |
| 25 final ListEncoder dynamicUses; | 26 final ListEncoder dynamicUses; |
| 26 final ListEncoder typeUses; | 27 final ListEncoder typeUses; |
| 27 | 28 |
| 28 ImpactSerializer(ObjectEncoder objectEncoder) | 29 ImpactSerializer(ObjectEncoder objectEncoder) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 53 useEncoder.setType(Key.TYPE, use.type); | 54 useEncoder.setType(Key.TYPE, use.type); |
| 54 useEncoder.setBool(Key.IS_CONST, use.isConstant); | 55 useEncoder.setBool(Key.IS_CONST, use.isConstant); |
| 55 useEncoder.setBool(Key.IS_EMPTY, use.isEmpty); | 56 useEncoder.setBool(Key.IS_EMPTY, use.isEmpty); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 | 60 |
| 60 @override | 61 @override |
| 61 void visitDynamicUse(DynamicUse dynamicUse) { | 62 void visitDynamicUse(DynamicUse dynamicUse) { |
| 62 ObjectEncoder object = dynamicUses.createObject(); | 63 ObjectEncoder object = dynamicUses.createObject(); |
| 63 object.setEnum(Key.KIND, dynamicUse.selector.kind); | 64 serializeSelector(dynamicUse.selector, object); |
| 64 | |
| 65 object.setInt( | |
| 66 Key.ARGUMENTS, dynamicUse.selector.callStructure.argumentCount); | |
| 67 object.setStrings( | |
| 68 Key.NAMED_ARGUMENTS, dynamicUse.selector.callStructure.namedArguments); | |
| 69 | |
| 70 object.setString(Key.NAME, dynamicUse.selector.memberName.text); | |
| 71 object.setBool(Key.IS_SETTER, dynamicUse.selector.memberName.isSetter); | |
| 72 if (dynamicUse.selector.memberName.library != null) { | |
| 73 object.setElement(Key.LIBRARY, dynamicUse.selector.memberName.library); | |
| 74 } | |
| 75 } | 65 } |
| 76 | 66 |
| 77 @override | 67 @override |
| 78 void visitStaticUse(StaticUse staticUse) { | 68 void visitStaticUse(StaticUse staticUse) { |
| 79 if (staticUse.element.isGenerativeConstructor && | 69 if (staticUse.element.isGenerativeConstructor && |
| 80 staticUse.element.enclosingClass.isUnnamedMixinApplication) { | 70 staticUse.element.enclosingClass.isUnnamedMixinApplication) { |
| 81 // TODO(johnniwinther): Handle static use of forwarding constructors. | 71 // TODO(johnniwinther): Handle static use of forwarding constructors. |
| 82 return; | 72 return; |
| 83 } | 73 } |
| 84 ObjectEncoder object = staticUses.createObject(); | 74 ObjectEncoder object = staticUses.createObject(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 ObjectDecoder object = staticUseDecoder.getObject(index); | 119 ObjectDecoder object = staticUseDecoder.getObject(index); |
| 130 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); | 120 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); |
| 131 Element element = object.getElement(Key.ELEMENT); | 121 Element element = object.getElement(Key.ELEMENT); |
| 132 staticUses.add(new StaticUse.internal(element, kind)); | 122 staticUses.add(new StaticUse.internal(element, kind)); |
| 133 } | 123 } |
| 134 | 124 |
| 135 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES); | 125 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES); |
| 136 List<DynamicUse> dynamicUses = <DynamicUse>[]; | 126 List<DynamicUse> dynamicUses = <DynamicUse>[]; |
| 137 for (int index = 0; index < dynamicUseDecoder.length; index++) { | 127 for (int index = 0; index < dynamicUseDecoder.length; index++) { |
| 138 ObjectDecoder object = dynamicUseDecoder.getObject(index); | 128 ObjectDecoder object = dynamicUseDecoder.getObject(index); |
| 139 SelectorKind kind = object.getEnum(Key.KIND, SelectorKind.values); | 129 Selector selector = deserializeSelector(object); |
| 140 int argumentCount = object.getInt(Key.ARGUMENTS); | 130 dynamicUses.add(new DynamicUse(selector, null)); |
| 141 List<String> namedArguments = | |
| 142 object.getStrings(Key.NAMED_ARGUMENTS, isOptional: true); | |
| 143 String name = object.getString(Key.NAME); | |
| 144 bool isSetter = object.getBool(Key.IS_SETTER); | |
| 145 LibraryElement library = object.getElement(Key.LIBRARY, isOptional: true); | |
| 146 dynamicUses.add(new DynamicUse( | |
| 147 new Selector(kind, new Name(name, library, isSetter: isSetter), | |
| 148 new CallStructure(argumentCount, namedArguments)), | |
| 149 null)); | |
| 150 } | 131 } |
| 151 | 132 |
| 152 ListDecoder typeUseDecoder = objectDecoder.getList(Key.TYPE_USES); | 133 ListDecoder typeUseDecoder = objectDecoder.getList(Key.TYPE_USES); |
| 153 List<TypeUse> typeUses = <TypeUse>[]; | 134 List<TypeUse> typeUses = <TypeUse>[]; |
| 154 for (int index = 0; index < typeUseDecoder.length; index++) { | 135 for (int index = 0; index < typeUseDecoder.length; index++) { |
| 155 ObjectDecoder object = typeUseDecoder.getObject(index); | 136 ObjectDecoder object = typeUseDecoder.getObject(index); |
| 156 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values); | 137 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values); |
| 157 DartType type = object.getType(Key.TYPE); | 138 DartType type = object.getType(Key.TYPE); |
| 158 typeUses.add(new TypeUse.internal(type, kind)); | 139 typeUses.add(new TypeUse.internal(type, kind)); |
| 159 } | 140 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 constSymbolNames: constSymbolNames, | 182 constSymbolNames: constSymbolNames, |
| 202 constantLiterals: constantLiterals, | 183 constantLiterals: constantLiterals, |
| 203 dynamicUses: dynamicUses, | 184 dynamicUses: dynamicUses, |
| 204 features: features, | 185 features: features, |
| 205 listLiterals: listLiterals, | 186 listLiterals: listLiterals, |
| 206 mapLiterals: mapLiterals, | 187 mapLiterals: mapLiterals, |
| 207 staticUses: staticUses, | 188 staticUses: staticUses, |
| 208 typeUses: typeUses); | 189 typeUses: typeUses); |
| 209 } | 190 } |
| 210 } | 191 } |
| OLD | NEW |