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

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

Issue 1839243003: Serialize ResolutionImpact instead of WorldImpact. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. 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
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/serialization/keys.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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';
9 import '../constants/expressions.dart';
8 import '../elements/elements.dart'; 10 import '../elements/elements.dart';
9 import '../universe/call_structure.dart'; 11 import '../universe/call_structure.dart';
10 import '../universe/selector.dart'; 12 import '../universe/selector.dart';
11 import '../universe/world_impact.dart'; 13 import '../universe/world_impact.dart';
12 import '../universe/use.dart'; 14 import '../universe/use.dart';
15 import '../util/enumset.dart';
13 16
14 import 'keys.dart'; 17 import 'keys.dart';
15 import 'serialization.dart'; 18 import 'serialization.dart';
16 19
17 /// Visitor that serializes a [WorldImpact] object using an [ObjectEncoder]. 20 /// Visitor that serializes a [ResolutionImpact] object using an
21 /// [ObjectEncoder].
18 class ImpactSerializer implements WorldImpactVisitor { 22 class ImpactSerializer implements WorldImpactVisitor {
23 final ObjectEncoder objectEncoder;
19 final ListEncoder staticUses; 24 final ListEncoder staticUses;
20 final ListEncoder dynamicUses; 25 final ListEncoder dynamicUses;
21 final ListEncoder typeUses; 26 final ListEncoder typeUses;
22 27
23 ImpactSerializer(ObjectEncoder objectEncoder) 28 ImpactSerializer(ObjectEncoder objectEncoder)
24 : staticUses = objectEncoder.createList(Key.STATIC_USES), 29 : this.objectEncoder = objectEncoder,
30 staticUses = objectEncoder.createList(Key.STATIC_USES),
25 dynamicUses = objectEncoder.createList(Key.DYNAMIC_USES), 31 dynamicUses = objectEncoder.createList(Key.DYNAMIC_USES),
26 typeUses = objectEncoder.createList(Key.TYPE_USES); 32 typeUses = objectEncoder.createList(Key.TYPE_USES);
27 33
34 void serialize(ResolutionImpact resolutionImpact) {
35 resolutionImpact.apply(this);
36 objectEncoder.setStrings(Key.SYMBOLS, resolutionImpact.constSymbolNames);
37 objectEncoder.setConstants(
38 Key.CONSTANTS, resolutionImpact.constantLiterals);
39 objectEncoder.setEnums(Key.FEATURES, resolutionImpact.features);
40 if (resolutionImpact.listLiterals.isNotEmpty) {
41 ListEncoder encoder = objectEncoder.createList(Key.LISTS);
42 for (ListLiteralUse use in resolutionImpact.listLiterals) {
43 ObjectEncoder useEncoder = encoder.createObject();
44 useEncoder.setType(Key.TYPE, use.type);
45 useEncoder.setBool(Key.IS_CONST, use.isConstant);
46 useEncoder.setBool(Key.IS_EMPTY, use.isEmpty);
47 }
48 }
49 if (resolutionImpact.mapLiterals.isNotEmpty) {
50 ListEncoder encoder = objectEncoder.createList(Key.MAPS);
51 for (MapLiteralUse use in resolutionImpact.mapLiterals) {
52 ObjectEncoder useEncoder = encoder.createObject();
53 useEncoder.setType(Key.TYPE, use.type);
54 useEncoder.setBool(Key.IS_CONST, use.isConstant);
55 useEncoder.setBool(Key.IS_EMPTY, use.isEmpty);
56 }
57 }
58 }
59
28 @override 60 @override
29 void visitDynamicUse(DynamicUse dynamicUse) { 61 void visitDynamicUse(DynamicUse dynamicUse) {
30 ObjectEncoder object = dynamicUses.createObject(); 62 ObjectEncoder object = dynamicUses.createObject();
31 object.setEnum(Key.KIND, dynamicUse.selector.kind); 63 object.setEnum(Key.KIND, dynamicUse.selector.kind);
32 64
33 object.setInt(Key.ARGUMENTS, 65 object.setInt(Key.ARGUMENTS,
34 dynamicUse.selector.callStructure.argumentCount); 66 dynamicUse.selector.callStructure.argumentCount);
35 object.setStrings(Key.NAMED_ARGUMENTS, 67 object.setStrings(Key.NAMED_ARGUMENTS,
36 dynamicUse.selector.callStructure.namedArguments); 68 dynamicUse.selector.callStructure.namedArguments);
37 69
(...skipping 21 matching lines...) Expand all
59 91
60 @override 92 @override
61 void visitTypeUse(TypeUse typeUse) { 93 void visitTypeUse(TypeUse typeUse) {
62 ObjectEncoder object = typeUses.createObject(); 94 ObjectEncoder object = typeUses.createObject();
63 object.setEnum(Key.KIND, typeUse.kind); 95 object.setEnum(Key.KIND, typeUse.kind);
64 object.setType(Key.TYPE, typeUse.type); 96 object.setType(Key.TYPE, typeUse.type);
65 } 97 }
66 } 98 }
67 99
68 /// A deserialized [WorldImpact] object. 100 /// A deserialized [WorldImpact] object.
69 class DeserializedWorldImpact extends WorldImpact with WorldImpactBuilder {} 101 class DeserializedResolutionImpact extends WorldImpact
102 implements ResolutionImpact {
103 final Iterable<String> constSymbolNames;
104 final Iterable<ConstantExpression> constantLiterals;
105 final Iterable<DynamicUse> dynamicUses;
106 final EnumSet<Feature> _features;
107 final Iterable<ListLiteralUse> listLiterals;
108 final Iterable<MapLiteralUse> mapLiterals;
109 final Iterable<StaticUse> staticUses;
110 final Iterable<TypeUse> typeUses;
111
112 DeserializedResolutionImpact({
113 this.constSymbolNames,
114 this.constantLiterals,
115 this.dynamicUses,
116 EnumSet<Feature> features,
117 this.listLiterals,
118 this.mapLiterals,
119 this.staticUses,
120 this.typeUses})
121 : this._features = features;
122
123 Iterable<Feature> get features => _features.iterable(Feature.values);
124 }
70 125
71 class ImpactDeserializer { 126 class ImpactDeserializer {
72 /// Deserializes a [WorldImpact] from [objectDecoder]. 127 /// Deserializes a [WorldImpact] from [objectDecoder].
73 static WorldImpact deserializeImpact(ObjectDecoder objectDecoder) { 128 static ResolutionImpact deserializeImpact(ObjectDecoder objectDecoder) {
74 DeserializedWorldImpact worldImpact = new DeserializedWorldImpact(); 129 ListDecoder staticUseDecoder = objectDecoder.getList(Key.STATIC_USES);
75 ListDecoder staticUses = objectDecoder.getList(Key.STATIC_USES); 130 List<StaticUse> staticUses = <StaticUse>[];
76 for (int index = 0; index < staticUses.length; index++) { 131 for (int index = 0; index < staticUseDecoder.length; index++) {
77 ObjectDecoder object = staticUses.getObject(index); 132 ObjectDecoder object = staticUseDecoder.getObject(index);
78 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values); 133 StaticUseKind kind = object.getEnum(Key.KIND, StaticUseKind.values);
79 Element element = object.getElement(Key.ELEMENT); 134 Element element = object.getElement(Key.ELEMENT);
80 worldImpact.registerStaticUse(new StaticUse.internal(element, kind)); 135 staticUses.add(new StaticUse.internal(element, kind));
81 } 136 }
82 ListDecoder dynamicUses = objectDecoder.getList(Key.DYNAMIC_USES); 137
83 for (int index = 0; index < dynamicUses.length; index++) { 138 ListDecoder dynamicUseDecoder = objectDecoder.getList(Key.DYNAMIC_USES);
84 ObjectDecoder object = dynamicUses.getObject(index); 139 List<DynamicUse> dynamicUses = <DynamicUse>[];
140 for (int index = 0; index < dynamicUseDecoder.length; index++) {
141 ObjectDecoder object = dynamicUseDecoder.getObject(index);
85 SelectorKind kind = object.getEnum(Key.KIND, SelectorKind.values); 142 SelectorKind kind = object.getEnum(Key.KIND, SelectorKind.values);
86 int argumentCount = object.getInt(Key.ARGUMENTS); 143 int argumentCount = object.getInt(Key.ARGUMENTS);
87 List<String> namedArguments = 144 List<String> namedArguments =
88 object.getStrings(Key.NAMED_ARGUMENTS, isOptional: true); 145 object.getStrings(Key.NAMED_ARGUMENTS, isOptional: true);
89 String name = object.getString(Key.NAME); 146 String name = object.getString(Key.NAME);
90 bool isSetter = object.getBool(Key.IS_SETTER); 147 bool isSetter = object.getBool(Key.IS_SETTER);
91 LibraryElement library = object.getElement(Key.LIBRARY, isOptional: true); 148 LibraryElement library = object.getElement(Key.LIBRARY, isOptional: true);
92 worldImpact.registerDynamicUse( 149 dynamicUses.add(
93 new DynamicUse( 150 new DynamicUse(
94 new Selector( 151 new Selector(
95 kind, 152 kind,
96 new Name(name, library, isSetter: isSetter), 153 new Name(name, library, isSetter: isSetter),
97 new CallStructure(argumentCount, namedArguments)), 154 new CallStructure(argumentCount, namedArguments)),
98 null)); 155 null));
99 } 156 }
100 ListDecoder typeUses = objectDecoder.getList(Key.TYPE_USES); 157
101 for (int index = 0; index < typeUses.length; index++) { 158 ListDecoder typeUseDecoder = objectDecoder.getList(Key.TYPE_USES);
102 ObjectDecoder object = typeUses.getObject(index); 159 List<TypeUse> typeUses = <TypeUse>[];
160 for (int index = 0; index < typeUseDecoder.length; index++) {
161 ObjectDecoder object = typeUseDecoder.getObject(index);
103 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values); 162 TypeUseKind kind = object.getEnum(Key.KIND, TypeUseKind.values);
104 DartType type = object.getType(Key.TYPE); 163 DartType type = object.getType(Key.TYPE);
105 worldImpact.registerTypeUse(new TypeUse.internal(type, kind)); 164 typeUses.add(new TypeUse.internal(type, kind));
106 } 165 }
107 return worldImpact; 166
167 List<String> constSymbolNames =
168 objectDecoder.getStrings(Key.SYMBOLS, isOptional: true);
169
170 List<ConstantExpression> constantLiterals =
171 objectDecoder.getConstants(Key.CONSTANTS, isOptional: true);
172
173 EnumSet<Feature> features =
174 objectDecoder.getEnums(Key.FEATURES, isOptional: true);
175
176 ListDecoder listLiteralDecoder =
177 objectDecoder.getList(Key.LISTS, isOptional: true);
178 List<ListLiteralUse> listLiterals = const <ListLiteralUse>[];
179 if (listLiteralDecoder != null) {
180 listLiterals = <ListLiteralUse>[];
181 for (int i = 0; i < listLiteralDecoder.length; i++) {
182 ObjectDecoder useDecoder = listLiteralDecoder.getObject(i);
183 DartType type = useDecoder.getType(Key.TYPE);
184 bool isConstant = useDecoder.getBool(Key.IS_CONST);
185 bool isEmpty = useDecoder.getBool(Key.IS_EMPTY);
186 listLiterals.add(new ListLiteralUse(
187 type, isConstant: isConstant, isEmpty: isEmpty));
188 }
189 }
190
191 ListDecoder mapLiteralDecoder =
192 objectDecoder.getList(Key.LISTS, isOptional: true);
193 List<MapLiteralUse> mapLiterals = const <MapLiteralUse>[];
194 if (listLiteralDecoder != null) {
195 mapLiterals = <MapLiteralUse>[];
196 for (int i = 0; i < mapLiteralDecoder.length; i++) {
197 ObjectDecoder useDecoder = mapLiteralDecoder.getObject(i);
198 DartType type = useDecoder.getType(Key.TYPE);
199 bool isConstant = useDecoder.getBool(Key.IS_CONST);
200 bool isEmpty = useDecoder.getBool(Key.IS_EMPTY);
201 mapLiterals.add(new MapLiteralUse(
202 type, isConstant: isConstant, isEmpty: isEmpty));
203 }
204 }
205
206 return new DeserializedResolutionImpact(
207 constSymbolNames: constSymbolNames,
208 constantLiterals: constantLiterals,
209 dynamicUses: dynamicUses,
210 features: features,
211 listLiterals: listLiterals,
212 mapLiterals: mapLiterals,
213 staticUses: staticUses,
214 typeUses: typeUses);
108 } 215 }
109 } 216 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | pkg/compiler/lib/src/serialization/keys.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698