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 14 matching lines...) Expand all Loading... |
25 R visitNull(NullConstantValue constant, A arg); | 25 R visitNull(NullConstantValue constant, A arg); |
26 R visitInt(IntConstantValue constant, A arg); | 26 R visitInt(IntConstantValue constant, A arg); |
27 R visitDouble(DoubleConstantValue constant, A arg); | 27 R visitDouble(DoubleConstantValue constant, A arg); |
28 R visitBool(BoolConstantValue constant, A arg); | 28 R visitBool(BoolConstantValue constant, A arg); |
29 R visitString(StringConstantValue constant, A arg); | 29 R visitString(StringConstantValue constant, A arg); |
30 R visitList(ListConstantValue constant, A arg); | 30 R visitList(ListConstantValue constant, A arg); |
31 R visitMap(MapConstantValue constant, A arg); | 31 R visitMap(MapConstantValue constant, A arg); |
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 visitSynthetic(SyntheticConstantValue 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. | 42 /// `true` if this is a valid constant value. |
43 bool get isConstant => true; | 43 bool get isConstant => true; |
44 | 44 |
45 bool get isNull => false; | 45 bool get isNull => false; |
(...skipping 27 matching lines...) Expand all Loading... |
73 List<ConstantValue> getDependencies(); | 73 List<ConstantValue> getDependencies(); |
74 | 74 |
75 accept(ConstantValueVisitor visitor, arg); | 75 accept(ConstantValueVisitor visitor, arg); |
76 | 76 |
77 /// The value of this constant in Dart syntax, if possible. | 77 /// The value of this constant in Dart syntax, if possible. |
78 /// | 78 /// |
79 /// For [ConstructedConstantValue]s there is no way to create a valid const | 79 /// For [ConstructedConstantValue]s there is no way to create a valid const |
80 /// expression from the value so the unparse of these is best effort. | 80 /// expression from the value so the unparse of these is best effort. |
81 /// | 81 /// |
82 /// For the synthetic constants, [DeferredConstantValue], | 82 /// For the synthetic constants, [DeferredConstantValue], |
83 /// [DummyConstantValue], [InterceptorConstantValue] the unparse is | 83 /// [SyntheticConstantValue], [InterceptorConstantValue] the unparse is |
84 /// descriptive only. | 84 /// descriptive only. |
85 String unparse(); | 85 String unparse(); |
86 | 86 |
87 /// Returns a structured representation of this constant suited for debugging. | 87 /// Returns a structured representation of this constant suited for debugging. |
88 String toStructuredString(); | 88 String toStructuredString(); |
89 | 89 |
90 String toString() { | 90 String toString() { |
91 assertDebugMode("Use Constant.unparse() or Constant.toStructuredString() " | 91 assertDebugMode("Use Constant.unparse() or Constant.toStructuredString() " |
92 "instead of Constant.toString()."); | 92 "instead of Constant.toString()."); |
93 return toStructuredString(); | 93 return toStructuredString(); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 | 596 |
597 String unparse() { | 597 String unparse() { |
598 return 'interceptor($dispatchedType)'; | 598 return 'interceptor($dispatchedType)'; |
599 } | 599 } |
600 | 600 |
601 String toStructuredString() { | 601 String toStructuredString() { |
602 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; | 602 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 // TODO(johnniwinther): Remove this class. | 606 class SyntheticConstantValue extends ConstantValue { |
607 class DummyConstantValue extends ConstantValue { | 607 final payload; |
608 final ti.TypeMask typeMask; | 608 final kind; |
609 | 609 |
610 DummyConstantValue(this.typeMask); | 610 SyntheticConstantValue(this.kind, this.payload); |
611 | 611 |
612 bool get isDummy => true; | 612 bool get isDummy => true; |
613 | 613 |
614 bool operator ==(other) { | 614 bool operator ==(other) { |
615 return other is DummyConstantValue | 615 return other is SyntheticConstantValue |
616 && typeMask == other.typeMask; | 616 && payload == other.payload; |
617 } | 617 } |
618 | 618 |
619 get hashCode => typeMask.hashCode; | 619 get hashCode => payload.hashCode * 17 + kind.hashCode; |
620 | 620 |
621 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 621 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
622 | 622 |
623 accept(ConstantValueVisitor visitor, arg) => visitor.visitDummy(this, arg); | 623 accept(ConstantValueVisitor visitor, arg) { |
| 624 return visitor.visitSynthetic(this, arg); |
| 625 } |
624 | 626 |
625 DartType getType(CoreTypes types) => const DynamicType(); | 627 DartType getType(CoreTypes types) => const DynamicType(); |
626 | 628 |
627 String unparse() => 'dummy($typeMask)'; | 629 String unparse() => 'synthetic($kind, $payload)'; |
628 | 630 |
629 String toStructuredString() => 'DummyConstant($typeMask)'; | 631 String toStructuredString() => 'SyntheticConstant($kind, $payload)'; |
630 } | 632 } |
631 | 633 |
632 class ConstructedConstantValue extends ObjectConstantValue { | 634 class ConstructedConstantValue extends ObjectConstantValue { |
633 final Map<FieldElement, ConstantValue> fields; | 635 final Map<FieldElement, ConstantValue> fields; |
634 final int hashCode; | 636 final int hashCode; |
635 | 637 |
636 ConstructedConstantValue(InterfaceType type, | 638 ConstructedConstantValue(InterfaceType type, |
637 Map<FieldElement, ConstantValue> fields) | 639 Map<FieldElement, ConstantValue> fields) |
638 : this.fields = fields, | 640 : this.fields = fields, |
639 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), | 641 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 744 |
743 @override | 745 @override |
744 DartType getType(CoreTypes types) => const DynamicType(); | 746 DartType getType(CoreTypes types) => const DynamicType(); |
745 | 747 |
746 @override | 748 @override |
747 String toStructuredString() => 'NonConstant'; | 749 String toStructuredString() => 'NonConstant'; |
748 | 750 |
749 @override | 751 @override |
750 String unparse() => '>>non-constant<<'; | 752 String unparse() => '>>non-constant<<'; |
751 } | 753 } |
OLD | NEW |