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

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

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments Created 5 years, 5 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Class hiarchy for semantic wrapping of serializable values.
6
7 library dart2js.serialization.values;
8
9 import '../constants/expressions.dart';
10 import '../dart_types.dart';
11 import '../elements/elements.dart';
12 import 'keys.dart';
13
14 /// Intermediate representation of a serializable value.
15 ///
16 /// Serializable values are
17 /// * [bool],
18 /// * [int],
19 /// * [double],
20 /// * [String],
21 /// * enum values,
22 /// * [ConstantExpression],
23 /// * [DartType],
24 /// * [Element],
25 /// * [Uri],
26 /// * lists of serializeable values,
27 /// * maps from arbitrary strings to serializable values; these are called
28 /// `Map` values, and
29 /// * maps from [Key] to serializable values; these are called `Object`
30 /// values.
31 ///
32 /// The distinction between map and object values is chosen to provide a more
33 /// robust and checkable implementation of the latter; since the keys are drawn
34 /// from a fixed typed set of values, consistency between serialization and
35 /// deserialization is easierly maintained.
36 abstract class Value {
37 accept(ValueVisitor visitor, arg);
38 }
39
40 class ElementValue implements Value {
41 final Element element;
42 final Value id;
43
44 ElementValue(this.element, this.id);
45
46 accept(ValueVisitor visitor, arg) => visitor.visitElement(this, arg);
47
48 String toString() => element.toString();
49 }
50
51 class TypeValue implements Value {
52 final DartType type;
53 final Value id;
54
55 TypeValue(this.type, this.id);
56
57 accept(ValueVisitor visitor, arg) => visitor.visitType(this, arg);
58
59 String toString() => type.toString();
60 }
61
62 class ConstantValue implements Value {
63 final ConstantExpression constant;
64 final Value id;
65
66 ConstantValue(this.constant, this.id);
67
68 accept(ValueVisitor visitor, arg) => visitor.visitConstant(this, arg);
69
70 String toString() => constant.getText();
71 }
72
73 abstract class PrimitiveValue implements Value {
74 get value;
75
76 String toString() => value.toString();
77 }
78
79 class BoolValue extends PrimitiveValue {
80 final bool value;
81
82 BoolValue(this.value);
83
84 accept(ValueVisitor visitor, arg) => visitor.visitBool(this, arg);
85 }
86
87 class IntValue extends PrimitiveValue {
88 final int value;
89
90 IntValue(this.value);
91
92 accept(ValueVisitor visitor, arg) => visitor.visitInt(this, arg);
93 }
94
95 class DoubleValue extends PrimitiveValue {
96 final double value;
97
98 DoubleValue(this.value);
99
100 accept(ValueVisitor visitor, arg) => visitor.visitDouble(this, arg);
101 }
102
103 class StringValue extends PrimitiveValue {
104 final String value;
105
106 StringValue(this.value);
107
108 accept(ValueVisitor visitor, arg) => visitor.visitString(this, arg);
109 }
110
111 class ObjectValue implements Value {
112 final Map<Key, Value> map;
113
114 ObjectValue(this.map);
115
116 accept(ValueVisitor visitor, arg) => visitor.visitObject(this, arg);
117
118 String toString() => map.toString();
119 }
120
121 class MapValue implements Value {
122 final Map<String, Value> map;
123
124 MapValue(this.map);
125
126 accept(ValueVisitor visitor, arg) => visitor.visitMap(this, arg);
127
128 String toString() => map.toString();
129 }
130
131 class ListValue implements Value {
132 final List<Value> values;
133
134 ListValue(this.values);
135
136 accept(ValueVisitor visitor, arg) => visitor.visitList(this, arg);
137
138 String toString() => values.toString();
139 }
140
141 class EnumValue implements Value {
142 final value;
143
144 EnumValue(this.value);
145
146 accept(ValueVisitor visitor, arg) => visitor.visitEnum(this, arg);
147
148 String toString() => value.toString();
149 }
150
151 class UriValue implements Value {
152 final Uri baseUri;
153 final Uri value;
154
155 UriValue(this.baseUri, this.value);
156
157 accept(ValueVisitor visitor, arg) => visitor.visitUri(this, arg);
158
159 String toString() => value.toString();
160 }
161
162 /// Visitor for the [Value] class hierarchy.
163 abstract class ValueVisitor<R, A> {
164 R visit(Value value, A arg);
165
166 R visitElement(ElementValue value, A arg);
167 R visitType(TypeValue value, A arg);
168 R visitConstant(ConstantValue value, A arg);
169 R visitBool(BoolValue value, A arg);
170 R visitInt(IntValue value, A arg);
171 R visitDouble(DoubleValue value, A arg);
172 R visitString(StringValue value, A arg);
173 R visitObject(ObjectValue value, A arg);
174 R visitMap(MapValue value, A arg);
175 R visitList(ListValue value, A arg);
176 R visitEnum(EnumValue value, A arg);
177 R visitUri(UriValue value, A arg);
178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698