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 23 matching lines...) Expand all Loading... |
34 IDENTICAL, | 34 IDENTICAL, |
35 INT, | 35 INT, |
36 INT_FROM_ENVIRONMENT, | 36 INT_FROM_ENVIRONMENT, |
37 LIST, | 37 LIST, |
38 MAP, | 38 MAP, |
39 NULL, | 39 NULL, |
40 STRING, | 40 STRING, |
41 STRING_FROM_ENVIRONMENT, | 41 STRING_FROM_ENVIRONMENT, |
42 STRING_LENGTH, | 42 STRING_LENGTH, |
43 SYMBOL, | 43 SYMBOL, |
| 44 SYNTHETIC, |
44 TYPE, | 45 TYPE, |
45 UNARY, | 46 UNARY, |
46 VARIABLE, | 47 VARIABLE, |
47 | 48 |
48 POSITIONAL_REFERENCE, | 49 POSITIONAL_REFERENCE, |
49 NAMED_REFERENCE, | 50 NAMED_REFERENCE, |
50 } | 51 } |
51 | 52 |
52 /// Environment used for evaluating constant expressions. | 53 /// Environment used for evaluating constant expressions. |
53 abstract class Environment { | 54 abstract class Environment { |
(...skipping 273 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.SYNTHETIC; |
| 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 |