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

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

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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) 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.constants; 5 library dart2js.serialization.constants;
6 6
7 import '../constants/constructors.dart'; 7 import '../constants/constructors.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../elements/resolution_types.dart'; 9 import '../elements/resolution_types.dart';
10 import '../elements/elements.dart' show FieldElement; 10 import '../elements/elements.dart' show FieldElement;
11 import '../resolution/operators.dart'; 11 import '../resolution/operators.dart';
12 import '../universe/call_structure.dart' show CallStructure; 12 import '../universe/call_structure.dart' show CallStructure;
13 import 'keys.dart'; 13 import 'keys.dart';
14 import 'serialization.dart'; 14 import 'serialization.dart';
15 15
16 /// Visitor that serializes a [ConstantExpression] by encoding it into an 16 /// Visitor that serializes a [ConstantExpression] by encoding it into an
17 /// [ObjectEncoder]. 17 /// [ObjectEncoder].
18 /// 18 ///
19 /// This class is called from the [Serializer] when a [ConstantExpression] needs 19 /// This class is called from the [Serializer] when a [ConstantExpression] needs
20 /// serialization. The [ObjectEncoder] ensures that any [Element], [DartType], 20 /// serialization. The [ObjectEncoder] ensures that any [Element],
21 /// and other [ConstantExpression] that the serialized [ConstantExpression] 21 /// [ResolutionDartType], and other [ConstantExpression] that the serialized
22 /// depends upon are also serialized. 22 /// [ConstantExpression] depends upon are also serialized.
23 class ConstantSerializer 23 class ConstantSerializer
24 extends ConstantExpressionVisitor<dynamic, ObjectEncoder> { 24 extends ConstantExpressionVisitor<dynamic, ObjectEncoder> {
25 const ConstantSerializer(); 25 const ConstantSerializer();
26 26
27 @override 27 @override
28 void visitBinary(BinaryConstantExpression exp, ObjectEncoder encoder) { 28 void visitBinary(BinaryConstantExpression exp, ObjectEncoder encoder) {
29 encoder.setEnum(Key.OPERATOR, exp.operator.kind); 29 encoder.setEnum(Key.OPERATOR, exp.operator.kind);
30 encoder.setConstant(Key.LEFT, exp.left); 30 encoder.setConstant(Key.LEFT, exp.left);
31 encoder.setConstant(Key.RIGHT, exp.right); 31 encoder.setConstant(Key.RIGHT, exp.right);
32 } 32 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 /// Utility class for deserializing [ConstantExpression]s. 177 /// Utility class for deserializing [ConstantExpression]s.
178 /// 178 ///
179 /// This is used by the [Deserializer]. 179 /// This is used by the [Deserializer].
180 class ConstantDeserializer { 180 class ConstantDeserializer {
181 /// Deserializes a [ConstantExpression] from an [ObjectDecoder]. 181 /// Deserializes a [ConstantExpression] from an [ObjectDecoder].
182 /// 182 ///
183 /// The class is called from the [Deserializer] when a [ConstantExpression] 183 /// The class is called from the [Deserializer] when a [ConstantExpression]
184 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], 184 /// needs deserialization. The [ObjectDecoder] ensures that any [Element],
185 /// [DartType], and other [ConstantExpression] that the deserialized 185 /// [ResolutionDartType], and other [ConstantExpression] that the deserialized
186 /// [ConstantExpression] depends upon are available. 186 /// [ConstantExpression] depends upon are available.
187 static ConstantExpression deserialize(ObjectDecoder decoder) { 187 static ConstantExpression deserialize(ObjectDecoder decoder) {
188 ConstantExpressionKind kind = 188 ConstantExpressionKind kind =
189 decoder.getEnum(Key.KIND, ConstantExpressionKind.values); 189 decoder.getEnum(Key.KIND, ConstantExpressionKind.values);
190 switch (kind) { 190 switch (kind) {
191 case ConstantExpressionKind.BINARY: 191 case ConstantExpressionKind.BINARY:
192 BinaryOperator operator = BinaryOperator 192 BinaryOperator operator = BinaryOperator
193 .fromKind(decoder.getEnum(Key.OPERATOR, BinaryOperatorKind.values)); 193 .fromKind(decoder.getEnum(Key.OPERATOR, BinaryOperatorKind.values));
194 return new BinaryConstantExpression(decoder.getConstant(Key.LEFT), 194 return new BinaryConstantExpression(decoder.getConstant(Key.LEFT),
195 operator, decoder.getConstant(Key.RIGHT)); 195 operator, decoder.getConstant(Key.RIGHT));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 throw new UnsupportedError("Unexpected constant kind: ${kind} in $decoder"); 275 throw new UnsupportedError("Unexpected constant kind: ${kind} in $decoder");
276 } 276 }
277 } 277 }
278 278
279 /// Visitor that serializes a [ConstantConstructor] by encoding it into an 279 /// Visitor that serializes a [ConstantConstructor] by encoding it into an
280 /// [ObjectEncoder]. 280 /// [ObjectEncoder].
281 /// 281 ///
282 /// This class is called from the [ConstructorSerializer] when the [Serializer] 282 /// This class is called from the [ConstructorSerializer] when the [Serializer]
283 /// is serializing constant constructor. The [ObjectEncoder] ensures that any 283 /// is serializing constant constructor. The [ObjectEncoder] ensures that any
284 /// [Element], [DartType], and [ConstantExpression] that the serialized 284 /// [Element], [ResolutionDartType], and [ConstantExpression] that the
285 /// [ConstantConstructor] depends upon are also serialized. 285 /// serialized [ConstantConstructor] depends upon are also serialized.
286 class ConstantConstructorSerializer 286 class ConstantConstructorSerializer
287 extends ConstantConstructorVisitor<dynamic, ObjectEncoder> { 287 extends ConstantConstructorVisitor<dynamic, ObjectEncoder> {
288 const ConstantConstructorSerializer(); 288 const ConstantConstructorSerializer();
289 289
290 @override 290 @override
291 void visit(ConstantConstructor constantConstructor, ObjectEncoder encoder) { 291 void visit(ConstantConstructor constantConstructor, ObjectEncoder encoder) {
292 encoder.setEnum(Key.KIND, constantConstructor.kind); 292 encoder.setEnum(Key.KIND, constantConstructor.kind);
293 constantConstructor.accept(this, encoder); 293 constantConstructor.accept(this, encoder);
294 } 294 }
295 295
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 335
336 /// Utility class for deserializing [ConstantConstructor]s. 336 /// Utility class for deserializing [ConstantConstructor]s.
337 /// 337 ///
338 /// This is used by the [ConstructorElementZ]. 338 /// This is used by the [ConstructorElementZ].
339 class ConstantConstructorDeserializer { 339 class ConstantConstructorDeserializer {
340 /// Deserializes a [ConstantConstructor] from an [ObjectDecoder]. 340 /// Deserializes a [ConstantConstructor] from an [ObjectDecoder].
341 /// 341 ///
342 /// The class is called from the [Deserializer] when a constant constructor 342 /// The class is called from the [Deserializer] when a constant constructor
343 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], 343 /// needs deserialization. The [ObjectDecoder] ensures that any [Element],
344 /// [DartType], and [ConstantExpression] that the deserialized 344 /// [ResolutionDartType], and [ConstantExpression] that the deserialized
345 /// [ConstantConstructor] depends upon are available. 345 /// [ConstantConstructor] depends upon are available.
346 static ConstantConstructor deserialize(ObjectDecoder decoder) { 346 static ConstantConstructor deserialize(ObjectDecoder decoder) {
347 ConstantConstructorKind kind = 347 ConstantConstructorKind kind =
348 decoder.getEnum(Key.KIND, ConstantConstructorKind.values); 348 decoder.getEnum(Key.KIND, ConstantConstructorKind.values);
349 349
350 DartType readType() { 350 ResolutionDartType readType() {
351 return decoder.getType(Key.TYPE); 351 return decoder.getType(Key.TYPE);
352 } 352 }
353 353
354 Map<dynamic /*int|String*/, ConstantExpression> readDefaults() { 354 Map<dynamic /*int|String*/, ConstantExpression> readDefaults() {
355 Map<dynamic, ConstantExpression> defaultValues = 355 Map<dynamic, ConstantExpression> defaultValues =
356 <dynamic, ConstantExpression>{}; 356 <dynamic, ConstantExpression>{};
357 if (decoder.containsKey(Key.DEFAULTS)) { 357 if (decoder.containsKey(Key.DEFAULTS)) {
358 MapDecoder defaultsMap = decoder.getMap(Key.DEFAULTS); 358 MapDecoder defaultsMap = decoder.getMap(Key.DEFAULTS);
359 defaultsMap.forEachKey((String key) { 359 defaultsMap.forEachKey((String key) {
360 int index = int.parse(key, onError: (_) => null); 360 int index = int.parse(key, onError: (_) => null);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 readFields(), readConstructorInvocation()); 393 readFields(), readConstructorInvocation());
394 case ConstantConstructorKind.REDIRECTING_GENERATIVE: 394 case ConstantConstructorKind.REDIRECTING_GENERATIVE:
395 return new RedirectingGenerativeConstantConstructor( 395 return new RedirectingGenerativeConstantConstructor(
396 readDefaults(), readConstructorInvocation()); 396 readDefaults(), readConstructorInvocation());
397 case ConstantConstructorKind.REDIRECTING_FACTORY: 397 case ConstantConstructorKind.REDIRECTING_FACTORY:
398 return new RedirectingFactoryConstantConstructor( 398 return new RedirectingFactoryConstantConstructor(
399 readConstructorInvocation()); 399 readConstructorInvocation());
400 } 400 }
401 } 401 }
402 } 402 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/typedefs.dart ('k') | pkg/compiler/lib/src/serialization/element_serialization.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698