OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 const_expression; | 5 library dart2js.constants.expressions; |
6 | 6 |
7 import '../dart2jslib.dart' show assertDebugMode; | 7 import '../dart2jslib.dart' show assertDebugMode; |
8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
9 import '../elements/elements.dart' show | 9 import '../elements/elements.dart' show |
10 Element, | 10 Element, |
11 FunctionElement, | 11 FunctionElement, |
12 VariableElement; | 12 VariableElement; |
13 import '../universe/universe.dart' show Selector; | 13 import '../universe/universe.dart' show Selector; |
14 import 'values.dart'; | 14 import 'values.dart'; |
15 | 15 |
16 /// An expression that is a compile-time constant. | 16 /// An expression that is a compile-time constant. |
17 /// | 17 /// |
18 /// Whereas [Constant] represent a compile-time value, a [ConstExp] | 18 /// Whereas [ConstantValue] represent a compile-time value, a |
19 /// represents an expression for creating a constant. | 19 /// [ConstantExpression] represents an expression for creating a constant. |
20 /// | 20 /// |
21 /// There is no one-to-one mapping between [ConstExp] and [Constant], because | 21 /// There is no one-to-one mapping between [ConstantExpression] and |
22 /// different expressions can denote the same constant. For instance, | 22 /// [ConstantValue], because different expressions can denote the same constant. |
23 /// multiple `const` constructors may be used to create the same object, and | 23 /// For instance, multiple `const` constructors may be used to create the same |
24 /// different `const` variables may hold the same value. | 24 /// object, and different `const` variables may hold the same value. |
25 abstract class ConstExp { | 25 abstract class ConstantExpression { |
26 /// Returns the value of this constant expression. | 26 /// Returns the value of this constant expression. |
27 Constant get value; | 27 ConstantValue get value; |
28 | 28 |
29 // TODO(johnniwinther): Unify precedence handled between constants, front-end | 29 // TODO(johnniwinther): Unify precedence handled between constants, front-end |
30 // and back-end. | 30 // and back-end. |
31 int get precedence => 16; | 31 int get precedence => 16; |
32 | 32 |
33 accept(ConstExpVisitor visitor); | 33 accept(ConstantExpressionVisitor visitor); |
34 | 34 |
35 String getText() { | 35 String getText() { |
36 ConstExpPrinter printer = new ConstExpPrinter(); | 36 ConstExpPrinter printer = new ConstExpPrinter(); |
37 accept(printer); | 37 accept(printer); |
38 return printer.toString(); | 38 return printer.toString(); |
39 } | 39 } |
40 | 40 |
41 String toString() { | 41 String toString() { |
42 assertDebugMode('Use ConstExp.getText() instead of ConstExp.toString()'); | 42 assertDebugMode('Use ConstantExpression.getText() instead of ' |
| 43 'ConstantExpression.toString()'); |
43 return getText(); | 44 return getText(); |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
47 /// Boolean, int, double, string, or null constant. | 48 /// Boolean, int, double, string, or null constant. |
48 class PrimitiveConstExp extends ConstExp { | 49 class PrimitiveConstantExpression extends ConstantExpression { |
49 final PrimitiveConstant value; | 50 final PrimitiveConstantValue value; |
50 | 51 |
51 PrimitiveConstExp(this.value) { | 52 PrimitiveConstantExpression(this.value) { |
52 assert(value != null); | 53 assert(value != null); |
53 } | 54 } |
54 | 55 |
55 accept(ConstExpVisitor visitor) => visitor.visitPrimitive(this); | 56 accept(ConstantExpressionVisitor visitor) => visitor.visitPrimitive(this); |
56 } | 57 } |
57 | 58 |
58 /// Literal list constant. | 59 /// Literal list constant. |
59 class ListConstExp extends ConstExp { | 60 class ListConstantExpression extends ConstantExpression { |
60 final ListConstant value; | 61 final ListConstantValue value; |
61 final InterfaceType type; | 62 final InterfaceType type; |
62 final List<ConstExp> values; | 63 final List<ConstantExpression> values; |
63 | 64 |
64 ListConstExp(this.value, this.type, this.values); | 65 ListConstantExpression(this.value, this.type, this.values); |
65 | 66 |
66 accept(ConstExpVisitor visitor) => visitor.visitList(this); | 67 accept(ConstantExpressionVisitor visitor) => visitor.visitList(this); |
67 } | 68 } |
68 | 69 |
69 /// Literal map constant. | 70 /// Literal map constant. |
70 class MapConstExp extends ConstExp { | 71 class MapConstantExpression extends ConstantExpression { |
71 final MapConstant value; | 72 final MapConstantValue value; |
72 final InterfaceType type; | 73 final InterfaceType type; |
73 final List<ConstExp> keys; | 74 final List<ConstantExpression> keys; |
74 final List<ConstExp> values; | 75 final List<ConstantExpression> values; |
75 | 76 |
76 MapConstExp(this.value, this.type, this.keys, this.values); | 77 MapConstantExpression(this.value, this.type, this.keys, this.values); |
77 | 78 |
78 accept(ConstExpVisitor visitor) => visitor.visitMap(this); | 79 accept(ConstantExpressionVisitor visitor) => visitor.visitMap(this); |
79 } | 80 } |
80 | 81 |
81 /// Invocation of a const constructor. | 82 /// Invocation of a const constructor. |
82 class ConstructorConstExp extends ConstExp { | 83 class ConstructedConstantExpresssion extends ConstantExpression { |
83 final Constant value; | 84 final ConstantValue value; |
84 final InterfaceType type; | 85 final InterfaceType type; |
85 final FunctionElement target; | 86 final FunctionElement target; |
86 final Selector selector; | 87 final Selector selector; |
87 final List<ConstExp> arguments; | 88 final List<ConstantExpression> arguments; |
88 | 89 |
89 ConstructorConstExp(this.value, | 90 ConstructedConstantExpresssion(this.value, |
90 this.type, | 91 this.type, |
91 this.target, | 92 this.target, |
92 this.selector, | 93 this.selector, |
93 this.arguments) { | 94 this.arguments) { |
94 assert(type.element == target.enclosingClass); | 95 assert(type.element == target.enclosingClass); |
95 } | 96 } |
96 | 97 |
97 accept(ConstExpVisitor visitor) => visitor.visitConstructor(this); | 98 accept(ConstantExpressionVisitor visitor) => visitor.visitConstructor(this); |
98 } | 99 } |
99 | 100 |
100 /// String literal with juxtaposition and/or interpolations. | 101 /// String literal with juxtaposition and/or interpolations. |
101 // TODO(johnniwinther): Do we need this? | 102 // TODO(johnniwinther): Do we need this? |
102 class ConcatenateConstExp extends ConstExp { | 103 class ConcatenateConstantExpression extends ConstantExpression { |
103 final StringConstant value; | 104 final StringConstantValue value; |
104 final List<ConstExp> arguments; | 105 final List<ConstantExpression> arguments; |
105 | 106 |
106 ConcatenateConstExp(this.value, this.arguments); | 107 ConcatenateConstantExpression(this.value, this.arguments); |
107 | 108 |
108 accept(ConstExpVisitor visitor) => visitor.visitConcatenate(this); | 109 accept(ConstantExpressionVisitor visitor) => visitor.visitConcatenate(this); |
109 } | 110 } |
110 | 111 |
111 /// Symbol literal. | 112 /// Symbol literal. |
112 class SymbolConstExp extends ConstExp { | 113 class SymbolConstantExpression extends ConstantExpression { |
113 final ConstructedConstant value; | 114 final ConstructedConstantValue value; |
114 final String name; | 115 final String name; |
115 | 116 |
116 SymbolConstExp(this.value, this.name); | 117 SymbolConstantExpression(this.value, this.name); |
117 | 118 |
118 accept(ConstExpVisitor visitor) => visitor.visitSymbol(this); | 119 accept(ConstantExpressionVisitor visitor) => visitor.visitSymbol(this); |
119 } | 120 } |
120 | 121 |
121 /// Type literal. | 122 /// Type literal. |
122 class TypeConstExp extends ConstExp { | 123 class TypeConstantExpression extends ConstantExpression { |
123 final TypeConstant value; | 124 final TypeConstantValue value; |
124 /// Either [DynamicType] or a raw [GenericType]. | 125 /// Either [DynamicType] or a raw [GenericType]. |
125 final DartType type; | 126 final DartType type; |
126 | 127 |
127 TypeConstExp(this.value, this.type) { | 128 TypeConstantExpression(this.value, this.type) { |
128 assert(type is GenericType || type is DynamicType); | 129 assert(type is GenericType || type is DynamicType); |
129 } | 130 } |
130 | 131 |
131 accept(ConstExpVisitor visitor) => visitor.visitType(this); | 132 accept(ConstantExpressionVisitor visitor) => visitor.visitType(this); |
132 } | 133 } |
133 | 134 |
134 /// A constant local, top-level, or static variable. | 135 /// Reference to a constant local, top-level, or static variable. |
135 class VariableConstExp extends ConstExp { | 136 class VariableConstantExpression extends ConstantExpression { |
136 final Constant value; | 137 final ConstantValue value; |
137 final VariableElement element; | 138 final VariableElement element; |
138 | 139 |
139 VariableConstExp(this.value, this.element); | 140 VariableConstantExpression(this.value, this.element); |
140 | 141 |
141 accept(ConstExpVisitor visitor) => visitor.visitVariable(this); | 142 accept(ConstantExpressionVisitor visitor) => visitor.visitVariable(this); |
142 } | 143 } |
143 | 144 |
144 /// Reference to a top-level or static function. | 145 /// Reference to a top-level or static function. |
145 class FunctionConstExp extends ConstExp { | 146 class FunctionConstantExpression extends ConstantExpression { |
146 final FunctionConstant value; | 147 final FunctionConstantValue value; |
147 final FunctionElement element; | 148 final FunctionElement element; |
148 | 149 |
149 FunctionConstExp(this.value, this.element); | 150 FunctionConstantExpression(this.value, this.element); |
150 | 151 |
151 accept(ConstExpVisitor visitor) => visitor.visitFunction(this); | 152 accept(ConstantExpressionVisitor visitor) => visitor.visitFunction(this); |
152 } | 153 } |
153 | 154 |
154 /// A constant binary expression like `a * b` or `identical(a, b)`. | 155 /// A constant binary expression like `a * b` or `identical(a, b)`. |
155 class BinaryConstExp extends ConstExp { | 156 class BinaryConstantExpression extends ConstantExpression { |
156 final Constant value; | 157 final ConstantValue value; |
157 final ConstExp left; | 158 final ConstantExpression left; |
158 final String operator; | 159 final String operator; |
159 final ConstExp right; | 160 final ConstantExpression right; |
160 | 161 |
161 BinaryConstExp(this.value, this.left, this.operator, this.right) { | 162 BinaryConstantExpression(this.value, this.left, this.operator, this.right) { |
162 assert(PRECEDENCE_MAP[operator] != null); | 163 assert(PRECEDENCE_MAP[operator] != null); |
163 } | 164 } |
164 | 165 |
165 accept(ConstExpVisitor visitor) => visitor.visitBinary(this); | 166 accept(ConstantExpressionVisitor visitor) => visitor.visitBinary(this); |
166 | 167 |
167 int get precedence => PRECEDENCE_MAP[operator]; | 168 int get precedence => PRECEDENCE_MAP[operator]; |
168 | 169 |
169 static const Map<String, int> PRECEDENCE_MAP = const { | 170 static const Map<String, int> PRECEDENCE_MAP = const { |
170 'identical': 15, | 171 'identical': 15, |
171 '==': 6, | 172 '==': 6, |
172 '!=': 6, | 173 '!=': 6, |
173 '&&': 5, | 174 '&&': 5, |
174 '||': 4, | 175 '||': 4, |
175 '^': 9, | 176 '^': 9, |
176 '&': 10, | 177 '&': 10, |
177 '|': 8, | 178 '|': 8, |
178 '>>': 11, | 179 '>>': 11, |
179 '<<': 11, | 180 '<<': 11, |
180 '+': 12, | 181 '+': 12, |
181 '-': 12, | 182 '-': 12, |
182 '*': 13, | 183 '*': 13, |
183 '/': 13, | 184 '/': 13, |
184 '~/': 13, | 185 '~/': 13, |
185 '>': 7, | 186 '>': 7, |
186 '<': 7, | 187 '<': 7, |
187 '>=': 7, | 188 '>=': 7, |
188 '<=': 7, | 189 '<=': 7, |
189 '%': 13, | 190 '%': 13, |
190 }; | 191 }; |
191 } | 192 } |
192 | 193 |
193 /// A unary constant expression like `-a`. | 194 /// A unary constant expression like `-a`. |
194 class UnaryConstExp extends ConstExp { | 195 class UnaryConstantExpression extends ConstantExpression { |
195 final Constant value; | 196 final ConstantValue value; |
196 final String operator; | 197 final String operator; |
197 final ConstExp expression; | 198 final ConstantExpression expression; |
198 | 199 |
199 UnaryConstExp(this.value, this.operator, this.expression) { | 200 UnaryConstantExpression(this.value, this.operator, this.expression) { |
200 assert(PRECEDENCE_MAP[operator] != null); | 201 assert(PRECEDENCE_MAP[operator] != null); |
201 } | 202 } |
202 | 203 |
203 accept(ConstExpVisitor visitor) => visitor.visitUnary(this); | 204 accept(ConstantExpressionVisitor visitor) => visitor.visitUnary(this); |
204 | 205 |
205 int get precedence => PRECEDENCE_MAP[operator]; | 206 int get precedence => PRECEDENCE_MAP[operator]; |
206 | 207 |
207 static const Map<String, int> PRECEDENCE_MAP = const { | 208 static const Map<String, int> PRECEDENCE_MAP = const { |
208 '!': 14, | 209 '!': 14, |
209 '~': 14, | 210 '~': 14, |
210 '-': 14, | 211 '-': 14, |
211 }; | 212 }; |
212 } | 213 } |
213 | 214 |
214 /// A constant conditional expression like `a ? b : c`. | 215 /// A constant conditional expression like `a ? b : c`. |
215 class ConditionalConstExp extends ConstExp { | 216 class ConditionalConstantExpression extends ConstantExpression { |
216 final Constant value; | 217 final ConstantValue value; |
217 final ConstExp condition; | 218 final ConstantExpression condition; |
218 final ConstExp trueExp; | 219 final ConstantExpression trueExp; |
219 final ConstExp falseExp; | 220 final ConstantExpression falseExp; |
220 | 221 |
221 ConditionalConstExp(this.value, this.condition, this.trueExp, this.falseExp); | 222 ConditionalConstantExpression(this.value, |
| 223 this.condition, |
| 224 this.trueExp, |
| 225 this.falseExp); |
222 | 226 |
223 accept(ConstExpVisitor visitor) => visitor.visitConditional(this); | 227 accept(ConstantExpressionVisitor visitor) => visitor.visitConditional(this); |
224 | 228 |
225 int get precedence => 3; | 229 int get precedence => 3; |
226 } | 230 } |
227 | 231 |
228 abstract class ConstExpVisitor<T> { | 232 abstract class ConstantExpressionVisitor<T> { |
229 T visit(ConstExp constant) => constant.accept(this); | 233 T visit(ConstantExpression constant) => constant.accept(this); |
230 | 234 |
231 T visitPrimitive(PrimitiveConstExp exp); | 235 T visitPrimitive(PrimitiveConstantExpression exp); |
232 T visitList(ListConstExp exp); | 236 T visitList(ListConstantExpression exp); |
233 T visitMap(MapConstExp exp); | 237 T visitMap(MapConstantExpression exp); |
234 T visitConstructor(ConstructorConstExp exp); | 238 T visitConstructor(ConstructedConstantExpresssion exp); |
235 T visitConcatenate(ConcatenateConstExp exp); | 239 T visitConcatenate(ConcatenateConstantExpression exp); |
236 T visitSymbol(SymbolConstExp exp); | 240 T visitSymbol(SymbolConstantExpression exp); |
237 T visitType(TypeConstExp exp); | 241 T visitType(TypeConstantExpression exp); |
238 T visitVariable(VariableConstExp exp); | 242 T visitVariable(VariableConstantExpression exp); |
239 T visitFunction(FunctionConstExp exp); | 243 T visitFunction(FunctionConstantExpression exp); |
240 T visitBinary(BinaryConstExp exp); | 244 T visitBinary(BinaryConstantExpression exp); |
241 T visitUnary(UnaryConstExp exp); | 245 T visitUnary(UnaryConstantExpression exp); |
242 T visitConditional(ConditionalConstExp exp); | 246 T visitConditional(ConditionalConstantExpression exp); |
243 } | 247 } |
244 | 248 |
245 /// Represents the declaration of a constant [element] with value [expression]. | 249 /// Represents the declaration of a constant [element] with value [expression]. |
| 250 // TODO(johnniwinther): Where does this class belong? |
246 class ConstDeclaration { | 251 class ConstDeclaration { |
247 final VariableElement element; | 252 final VariableElement element; |
248 final ConstExp expression; | 253 final ConstantExpression expression; |
249 | 254 |
250 ConstDeclaration(this.element, this.expression); | 255 ConstDeclaration(this.element, this.expression); |
251 } | 256 } |
252 | 257 |
253 class ConstExpPrinter extends ConstExpVisitor { | 258 class ConstExpPrinter extends ConstantExpressionVisitor { |
254 final StringBuffer sb = new StringBuffer(); | 259 final StringBuffer sb = new StringBuffer(); |
255 | 260 |
256 write(ConstExp parent, ConstExp child, {bool leftAssociative: true}) { | 261 write(ConstantExpression parent, |
| 262 ConstantExpression child, |
| 263 {bool leftAssociative: true}) { |
257 if (child.precedence < parent.precedence || | 264 if (child.precedence < parent.precedence || |
258 !leftAssociative && child.precedence == parent.precedence) { | 265 !leftAssociative && child.precedence == parent.precedence) { |
259 sb.write('('); | 266 sb.write('('); |
260 child.accept(this); | 267 child.accept(this); |
261 sb.write(')'); | 268 sb.write(')'); |
262 } else { | 269 } else { |
263 child.accept(this); | 270 child.accept(this); |
264 } | 271 } |
265 } | 272 } |
266 | 273 |
267 writeTypeArguments(InterfaceType type) { | 274 writeTypeArguments(InterfaceType type) { |
268 if (type.treatAsRaw) return; | 275 if (type.treatAsRaw) return; |
269 sb.write('<'); | 276 sb.write('<'); |
270 bool needsComma = false; | 277 bool needsComma = false; |
271 for (DartType value in type.typeArguments) { | 278 for (DartType value in type.typeArguments) { |
272 if (needsComma) { | 279 if (needsComma) { |
273 sb.write(', '); | 280 sb.write(', '); |
274 } | 281 } |
275 sb.write(value); | 282 sb.write(value); |
276 needsComma = true; | 283 needsComma = true; |
277 } | 284 } |
278 sb.write('>'); | 285 sb.write('>'); |
279 } | 286 } |
280 | 287 |
281 visitPrimitive(PrimitiveConstExp exp) { | 288 visitPrimitive(PrimitiveConstantExpression exp) { |
282 sb.write(exp.value.unparse()); | 289 sb.write(exp.value.unparse()); |
283 } | 290 } |
284 | 291 |
285 visitList(ListConstExp exp) { | 292 visitList(ListConstantExpression exp) { |
286 sb.write('const '); | 293 sb.write('const '); |
287 writeTypeArguments(exp.type); | 294 writeTypeArguments(exp.type); |
288 sb.write('['); | 295 sb.write('['); |
289 bool needsComma = false; | 296 bool needsComma = false; |
290 for (ConstExp value in exp.values) { | 297 for (ConstantExpression value in exp.values) { |
291 if (needsComma) { | 298 if (needsComma) { |
292 sb.write(', '); | 299 sb.write(', '); |
293 } | 300 } |
294 visit(value); | 301 visit(value); |
295 needsComma = true; | 302 needsComma = true; |
296 } | 303 } |
297 sb.write(']'); | 304 sb.write(']'); |
298 } | 305 } |
299 | 306 |
300 visitMap(MapConstExp exp) { | 307 visitMap(MapConstantExpression exp) { |
301 sb.write('const '); | 308 sb.write('const '); |
302 writeTypeArguments(exp.type); | 309 writeTypeArguments(exp.type); |
303 sb.write('{'); | 310 sb.write('{'); |
304 for (int index = 0; index < exp.keys.length; index++) { | 311 for (int index = 0; index < exp.keys.length; index++) { |
305 if (index > 0) { | 312 if (index > 0) { |
306 sb.write(', '); | 313 sb.write(', '); |
307 } | 314 } |
308 visit(exp.keys[index]); | 315 visit(exp.keys[index]); |
309 sb.write(': '); | 316 sb.write(': '); |
310 visit(exp.values[index]); | 317 visit(exp.values[index]); |
311 } | 318 } |
312 sb.write('}'); | 319 sb.write('}'); |
313 } | 320 } |
314 | 321 |
315 visitConstructor(ConstructorConstExp exp) { | 322 visitConstructor(ConstructedConstantExpresssion exp) { |
316 sb.write('const '); | 323 sb.write('const '); |
317 sb.write(exp.target.enclosingClass.name); | 324 sb.write(exp.target.enclosingClass.name); |
318 if (exp.target.name != '') { | 325 if (exp.target.name != '') { |
319 sb.write('.'); | 326 sb.write('.'); |
320 sb.write(exp.target.name); | 327 sb.write(exp.target.name); |
321 } | 328 } |
322 writeTypeArguments(exp.type); | 329 writeTypeArguments(exp.type); |
323 sb.write('('); | 330 sb.write('('); |
324 bool needsComma = false; | 331 bool needsComma = false; |
325 | 332 |
(...skipping 10 matching lines...) Expand all Loading... |
336 sb.write(', '); | 343 sb.write(', '); |
337 } | 344 } |
338 sb.write(exp.selector.namedArguments[index]); | 345 sb.write(exp.selector.namedArguments[index]); |
339 sb.write(': '); | 346 sb.write(': '); |
340 visit(exp.arguments[namedOffset + index]); | 347 visit(exp.arguments[namedOffset + index]); |
341 needsComma = true; | 348 needsComma = true; |
342 } | 349 } |
343 sb.write(')'); | 350 sb.write(')'); |
344 } | 351 } |
345 | 352 |
346 visitConcatenate(ConcatenateConstExp exp) { | 353 visitConcatenate(ConcatenateConstantExpression exp) { |
347 sb.write(exp.value.unparse()); | 354 sb.write(exp.value.unparse()); |
348 } | 355 } |
349 | 356 |
350 visitSymbol(SymbolConstExp exp) { | 357 visitSymbol(SymbolConstantExpression exp) { |
351 sb.write('#'); | 358 sb.write('#'); |
352 sb.write(exp.name); | 359 sb.write(exp.name); |
353 } | 360 } |
354 | 361 |
355 visitType(TypeConstExp exp) { | 362 visitType(TypeConstantExpression exp) { |
356 sb.write(exp.type.name); | 363 sb.write(exp.type.name); |
357 } | 364 } |
358 | 365 |
359 visitVariable(VariableConstExp exp) { | 366 visitVariable(VariableConstantExpression exp) { |
360 if (exp.element.isStatic) { | 367 if (exp.element.isStatic) { |
361 sb.write(exp.element.enclosingClass.name); | 368 sb.write(exp.element.enclosingClass.name); |
362 sb.write('.'); | 369 sb.write('.'); |
363 } | 370 } |
364 sb.write(exp.element.name); | 371 sb.write(exp.element.name); |
365 } | 372 } |
366 | 373 |
367 visitFunction(FunctionConstExp exp) { | 374 visitFunction(FunctionConstantExpression exp) { |
368 if (exp.element.isStatic) { | 375 if (exp.element.isStatic) { |
369 sb.write(exp.element.enclosingClass.name); | 376 sb.write(exp.element.enclosingClass.name); |
370 sb.write('.'); | 377 sb.write('.'); |
371 } | 378 } |
372 sb.write(exp.element.name); | 379 sb.write(exp.element.name); |
373 } | 380 } |
374 | 381 |
375 visitBinary(BinaryConstExp exp) { | 382 visitBinary(BinaryConstantExpression exp) { |
376 if (exp.operator == 'identical') { | 383 if (exp.operator == 'identical') { |
377 sb.write('identical('); | 384 sb.write('identical('); |
378 visit(exp.left); | 385 visit(exp.left); |
379 sb.write(', '); | 386 sb.write(', '); |
380 visit(exp.right); | 387 visit(exp.right); |
381 sb.write(')'); | 388 sb.write(')'); |
382 } else { | 389 } else { |
383 write(exp, exp.left); | 390 write(exp, exp.left); |
384 sb.write(' '); | 391 sb.write(' '); |
385 sb.write(exp.operator); | 392 sb.write(exp.operator); |
386 sb.write(' '); | 393 sb.write(' '); |
387 write(exp, exp.right); | 394 write(exp, exp.right); |
388 } | 395 } |
389 } | 396 } |
390 | 397 |
391 visitUnary(UnaryConstExp exp) { | 398 visitUnary(UnaryConstantExpression exp) { |
392 sb.write(exp.operator); | 399 sb.write(exp.operator); |
393 write(exp, exp.expression); | 400 write(exp, exp.expression); |
394 } | 401 } |
395 | 402 |
396 visitConditional(ConditionalConstExp exp) { | 403 visitConditional(ConditionalConstantExpression exp) { |
397 write(exp, exp.condition, leftAssociative: false); | 404 write(exp, exp.condition, leftAssociative: false); |
398 sb.write(' ? '); | 405 sb.write(' ? '); |
399 write(exp, exp.trueExp); | 406 write(exp, exp.trueExp); |
400 sb.write(' : '); | 407 sb.write(' : '); |
401 write(exp, exp.falseExp); | 408 write(exp, exp.falseExp); |
402 } | 409 } |
403 | 410 |
404 String toString() => sb.toString(); | 411 String toString() => sb.toString(); |
405 } | 412 } |
OLD | NEW |