Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: pkg/compiler/lib/src/serialization/impact_serialization.dart

Issue 1873573004: Serialize TreeElements (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(Key.ARGUMENTS,
66 dynamicUse.selector.callStructure.argumentCount);
67 object.setStrings(Key.NAMED_ARGUMENTS,
68 dynamicUse.selector.callStructure.namedArguments);
69
70 object.setString(Key.NAME,
71 dynamicUse.selector.memberName.text);
72 object.setBool(Key.IS_SETTER,
73 dynamicUse.selector.memberName.isSetter);
74 if (dynamicUse.selector.memberName.library != null) {
75 object.setElement(Key.LIBRARY,
76 dynamicUse.selector.memberName.library);
77 }
78 } 65 }
79 66
80 @override 67 @override
81 void visitStaticUse(StaticUse staticUse) { 68 void visitStaticUse(StaticUse staticUse) {
82 if (staticUse.element.isGenerativeConstructor && 69 if (staticUse.element.isGenerativeConstructor &&
83 staticUse.element.enclosingClass.isUnnamedMixinApplication) { 70 staticUse.element.enclosingClass.isUnnamedMixinApplication) {
84 // TODO(johnniwinther): Handle static use of forwarding constructors. 71 // TODO(johnniwinther): Handle static use of forwarding constructors.
85 return; 72 return;
86 } 73 }
87 ObjectEncoder object = staticUses.createObject(); 74 ObjectEncoder object = staticUses.createObject();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 ObjectDecoder object = staticUseDecoder.getObject(index); 119 ObjectDecoder object = staticUseDecoder.getObject(index);
133 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); 120 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values);
134 Element element = object.getElement(Key.ELEMENT); 121 Element element = object.getElement(Key.ELEMENT);
135 staticUses.add(new StaticUse.internal(element, kind)); 122 staticUses.add(new StaticUse.internal(element, kind));
136 } 123 }
137 124
138 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES); 125 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES);
139 List<DynamicUse> dynamicUses = <DynamicUse>[]; 126 List<DynamicUse> dynamicUses = <DynamicUse>[];
140 for (int index = 0; index < dynamicUseDecoder.length; index++) { 127 for (int index = 0; index < dynamicUseDecoder.length; index++) {
141 ObjectDecoder object = dynamicUseDecoder.getObject(index); 128 ObjectDecoder object = dynamicUseDecoder.getObject(index);
142 SelectorKind kind = object.getEnum(Key.KIND, SelectorKind.values); 129 Selector selector = deserializeSelector(object);
143 int argumentCount = object.getInt(Key.ARGUMENTS); 130 dynamicUses.add(new DynamicUse(selector, null));
144 List<String> namedArguments =
145 object.getStrings(Key.NAMED_ARGUMENTS, isOptional: true);
146 String name = object.getString(Key.NAME);
147 bool isSetter = object.getBool(Key.IS_SETTER);
148 LibraryElement library = object.getElement(Key.LIBRARY, isOptional: true);
149 dynamicUses.add(
150 new DynamicUse(
151 new Selector(
152 kind,
153 new Name(name, library, isSetter: isSetter),
154 new CallStructure(argumentCount, namedArguments)),
155 null));
156 } 131 }
157 132
158 ListDecoder typeUseDecoder = objectDecoder.getList(Key.TYPE_USES); 133 ListDecoder typeUseDecoder = objectDecoder.getList(Key.TYPE_USES);
159 List<TypeUse> typeUses = <TypeUse>[]; 134 List<TypeUse> typeUses = <TypeUse>[];
160 for (int index = 0; index < typeUseDecoder.length; index++) { 135 for (int index = 0; index < typeUseDecoder.length; index++) {
161 ObjectDecoder object = typeUseDecoder.getObject(index); 136 ObjectDecoder object = typeUseDecoder.getObject(index);
162 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values); 137 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values);
163 DartType type = object.getType(Key.TYPE); 138 DartType type = object.getType(Key.TYPE);
164 typeUses.add(new TypeUse.internal(type, kind)); 139 typeUses.add(new TypeUse.internal(type, kind));
165 } 140 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 constSymbolNames: constSymbolNames, 182 constSymbolNames: constSymbolNames,
208 constantLiterals: constantLiterals, 183 constantLiterals: constantLiterals,
209 dynamicUses: dynamicUses, 184 dynamicUses: dynamicUses,
210 features: features, 185 features: features,
211 listLiterals: listLiterals, 186 listLiterals: listLiterals,
212 mapLiterals: mapLiterals, 187 mapLiterals: mapLiterals,
213 staticUses: staticUses, 188 staticUses: staticUses,
214 typeUses: typeUses); 189 typeUses: typeUses);
215 } 190 }
216 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698