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 dart2js.constants.expressions; | 5 library dart2js.constants.expressions; |
6 | 6 |
7 import '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
9 import '../dart2jslib.dart' show assertDebugMode, Compiler; | 9 import '../dart2jslib.dart' show assertDebugMode, Compiler; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 enum ConstantExpressionKind { | 23 enum ConstantExpressionKind { |
24 BINARY, | 24 BINARY, |
25 BOOL, | 25 BOOL, |
26 BOOL_FROM_ENVIRONMENT, | 26 BOOL_FROM_ENVIRONMENT, |
27 CONCATENATE, | 27 CONCATENATE, |
28 CONDITIONAL, | 28 CONDITIONAL, |
29 CONSTRUCTED, | 29 CONSTRUCTED, |
30 DEFERRED, | 30 DEFERRED, |
31 DOUBLE, | 31 DOUBLE, |
| 32 DUMMY, |
32 ERRONEOUS, | 33 ERRONEOUS, |
33 FUNCTION, | 34 FUNCTION, |
34 IDENTICAL, | 35 IDENTICAL, |
35 INT, | 36 INT, |
36 INT_FROM_ENVIRONMENT, | 37 INT_FROM_ENVIRONMENT, |
37 LIST, | 38 LIST, |
38 MAP, | 39 MAP, |
39 NULL, | 40 NULL, |
40 STRING, | 41 STRING, |
41 STRING_FROM_ENVIRONMENT, | 42 STRING_FROM_ENVIRONMENT, |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 return new NonConstantValue(); | 328 return new NonConstantValue(); |
328 } | 329 } |
329 | 330 |
330 @override | 331 @override |
331 int _computeHashCode() => 13; | 332 int _computeHashCode() => 13; |
332 | 333 |
333 @override | 334 @override |
334 bool _equals(ErroneousConstantExpression other) => true; | 335 bool _equals(ErroneousConstantExpression other) => true; |
335 } | 336 } |
336 | 337 |
| 338 // TODO(johnniwinther): Avoid the need for this class. |
| 339 class SyntheticConstantExpression extends ConstantExpression { |
| 340 final SyntheticConstantValue value; |
| 341 |
| 342 SyntheticConstantExpression(this.value); |
| 343 |
| 344 @override |
| 345 ConstantValue evaluate(Environment environment, |
| 346 ConstantSystem constantSystem) { |
| 347 return value; |
| 348 } |
| 349 |
| 350 @override |
| 351 int _computeHashCode() => 13 * value.hashCode; |
| 352 |
| 353 accept(ConstantExpressionVisitor visitor, [context]) { |
| 354 throw "unsupported"; |
| 355 } |
| 356 |
| 357 @override |
| 358 bool _equals(SyntheticConstantExpression other) { |
| 359 return value == other.value; |
| 360 } |
| 361 |
| 362 ConstantExpressionKind get kind => ConstantExpressionKind.DUMMY; |
| 363 } |
| 364 |
| 365 |
| 366 |
337 /// A boolean, int, double, string, or null constant. | 367 /// A boolean, int, double, string, or null constant. |
338 abstract class PrimitiveConstantExpression extends ConstantExpression { | 368 abstract class PrimitiveConstantExpression extends ConstantExpression { |
339 /// The primitive value of this contant expression. | 369 /// The primitive value of this contant expression. |
340 get primitiveValue; | 370 get primitiveValue; |
341 } | 371 } |
342 | 372 |
343 /// Boolean literal constant. | 373 /// Boolean literal constant. |
344 class BoolConstantExpression extends PrimitiveConstantExpression { | 374 class BoolConstantExpression extends PrimitiveConstantExpression { |
345 final bool primitiveValue; | 375 final bool primitiveValue; |
346 | 376 |
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 visit(exp.name); | 1804 visit(exp.name); |
1775 if (exp.defaultValue != null) { | 1805 if (exp.defaultValue != null) { |
1776 sb.write(', defaultValue: '); | 1806 sb.write(', defaultValue: '); |
1777 visit(exp.defaultValue); | 1807 visit(exp.defaultValue); |
1778 } | 1808 } |
1779 sb.write(')'); | 1809 sb.write(')'); |
1780 } | 1810 } |
1781 | 1811 |
1782 String toString() => sb.toString(); | 1812 String toString() => sb.toString(); |
1783 } | 1813 } |
OLD | NEW |