OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.values; | 5 library dart2js.constants.values; |
6 | 6 |
7 import '../core_types.dart'; | 7 import '../core_types.dart'; |
8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
9 import '../dart2jslib.dart' | 9 import '../dart2jslib.dart' |
10 show assertDebugMode; | 10 show assertDebugMode; |
(...skipping 21 matching lines...) Expand all Loading... |
32 R visitConstructed(ConstructedConstantValue constant, A arg); | 32 R visitConstructed(ConstructedConstantValue constant, A arg); |
33 R visitType(TypeConstantValue constant, A arg); | 33 R visitType(TypeConstantValue constant, A arg); |
34 R visitInterceptor(InterceptorConstantValue constant, A arg); | 34 R visitInterceptor(InterceptorConstantValue constant, A arg); |
35 R visitDummy(DummyConstantValue constant, A arg); | 35 R visitDummy(DummyConstantValue constant, A arg); |
36 R visitDeferred(DeferredConstantValue constant, A arg); | 36 R visitDeferred(DeferredConstantValue constant, A arg); |
37 } | 37 } |
38 | 38 |
39 abstract class ConstantValue { | 39 abstract class ConstantValue { |
40 const ConstantValue(); | 40 const ConstantValue(); |
41 | 41 |
| 42 /// `true` if this is a valid constant value. |
| 43 bool get isConstant => true; |
| 44 |
42 bool get isNull => false; | 45 bool get isNull => false; |
43 bool get isBool => false; | 46 bool get isBool => false; |
44 bool get isTrue => false; | 47 bool get isTrue => false; |
45 bool get isFalse => false; | 48 bool get isFalse => false; |
46 bool get isInt => false; | 49 bool get isInt => false; |
47 bool get isDouble => false; | 50 bool get isDouble => false; |
48 bool get isNum => false; | 51 bool get isNum => false; |
49 bool get isString => false; | 52 bool get isString => false; |
50 bool get isList => false; | 53 bool get isList => false; |
51 bool get isMap => false; | 54 bool get isMap => false; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 for (int i = 0 ; i < length ; i++) { | 478 for (int i = 0 ; i < length ; i++) { |
476 if (i > 0) sb.write(','); | 479 if (i > 0) sb.write(','); |
477 sb.write(entries[i].unparse()); | 480 sb.write(entries[i].unparse()); |
478 } | 481 } |
479 sb.write(']'); | 482 sb.write(']'); |
480 return sb.toString(); | 483 return sb.toString(); |
481 } | 484 } |
482 | 485 |
483 String toStructuredString() { | 486 String toStructuredString() { |
484 StringBuffer sb = new StringBuffer(); | 487 StringBuffer sb = new StringBuffer(); |
485 sb.write('ListConstant(['); | 488 sb.write('ListConstant('); |
| 489 _unparseTypeArguments(sb); |
| 490 sb.write('['); |
486 for (int i = 0 ; i < length ; i++) { | 491 for (int i = 0 ; i < length ; i++) { |
487 if (i > 0) sb.write(','); | 492 if (i > 0) sb.write(','); |
488 sb.write(entries[i].toStructuredString()); | 493 sb.write(entries[i].toStructuredString()); |
489 } | 494 } |
490 sb.write('])'); | 495 sb.write('])'); |
491 return sb.toString(); | 496 return sb.toString(); |
492 } | 497 } |
493 } | 498 } |
494 | 499 |
495 class MapConstantValue extends ObjectConstantValue { | 500 class MapConstantValue extends ObjectConstantValue { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 sb.write(keys[i].unparse()); | 549 sb.write(keys[i].unparse()); |
545 sb.write(':'); | 550 sb.write(':'); |
546 sb.write(values[i].unparse()); | 551 sb.write(values[i].unparse()); |
547 } | 552 } |
548 sb.write('}'); | 553 sb.write('}'); |
549 return sb.toString(); | 554 return sb.toString(); |
550 } | 555 } |
551 | 556 |
552 String toStructuredString() { | 557 String toStructuredString() { |
553 StringBuffer sb = new StringBuffer(); | 558 StringBuffer sb = new StringBuffer(); |
554 sb.write('MapConstant({'); | 559 sb.write('MapConstant('); |
| 560 _unparseTypeArguments(sb); |
| 561 sb.write('{'); |
555 for (int i = 0; i < length; i++) { | 562 for (int i = 0; i < length; i++) { |
556 if (i > 0) sb.write(','); | 563 if (i > 0) sb.write(','); |
557 sb.write(keys[i].toStructuredString()); | 564 sb.write(keys[i].toStructuredString()); |
558 sb.write(':'); | 565 sb.write(':'); |
559 sb.write(values[i].toStructuredString()); | 566 sb.write(values[i].toStructuredString()); |
560 } | 567 } |
561 sb.write('})'); | 568 sb.write('})'); |
562 return sb.toString(); | 569 return sb.toString(); |
563 } | 570 } |
564 } | 571 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; | 717 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; |
711 | 718 |
712 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); | 719 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); |
713 | 720 |
714 DartType getType(CoreTypes types) => referenced.getType(types); | 721 DartType getType(CoreTypes types) => referenced.getType(types); |
715 | 722 |
716 String unparse() => 'deferred(${referenced.unparse()})'; | 723 String unparse() => 'deferred(${referenced.unparse()})'; |
717 | 724 |
718 String toStructuredString() => 'DeferredConstant($referenced)'; | 725 String toStructuredString() => 'DeferredConstant($referenced)'; |
719 } | 726 } |
| 727 |
| 728 /// A constant value resulting from a non constant or erroneous constant |
| 729 /// expression. |
| 730 // TODO(johnniwinther): Expand this to contain the error kind. |
| 731 class NonConstantValue extends ConstantValue { |
| 732 bool get isConstant => false; |
| 733 |
| 734 @override |
| 735 accept(ConstantValueVisitor visitor, arg) { |
| 736 // TODO(johnniwinther): Should this be part of the visiting? |
| 737 } |
| 738 |
| 739 @override |
| 740 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 741 |
| 742 @override |
| 743 DartType getType(CoreTypes types) => const DynamicType(); |
| 744 |
| 745 @override |
| 746 String toStructuredString() => 'NonConstant'; |
| 747 |
| 748 @override |
| 749 String unparse() => '>>non-constant<<'; |
| 750 } |
OLD | NEW |