| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.send_structure; | 5 library dart2js.send_structure; |
| 6 | 6 |
| 7 import 'access_semantics.dart'; | 7 import 'access_semantics.dart'; |
| 8 import 'operators.dart'; | 8 import 'operators.dart'; |
| 9 import 'semantic_visitor.dart'; | 9 import 'semantic_visitor.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 node, | 725 node, |
| 726 node.receiver, | 726 node.receiver, |
| 727 node.arguments.single, | 727 node.arguments.single, |
| 728 arg); | 728 arg); |
| 729 case AccessKind.SUPER_METHOD: | 729 case AccessKind.SUPER_METHOD: |
| 730 return visitor.visitSuperIndex( | 730 return visitor.visitSuperIndex( |
| 731 node, | 731 node, |
| 732 semantics.element, | 732 semantics.element, |
| 733 node.arguments.single, | 733 node.arguments.single, |
| 734 arg); | 734 arg); |
| 735 case AccessKind.UNRESOLVED: |
| 736 return visitor.errorUnresolvedSuperIndex( |
| 737 node, |
| 738 semantics.element, |
| 739 node.arguments.single, |
| 740 arg); |
| 735 default: | 741 default: |
| 736 // This is not a valid case. | 742 // This is not a valid case. |
| 737 break; | 743 break; |
| 738 } | 744 } |
| 739 throw new SpannableAssertionFailure(node, "Invalid index: ${semantics}"); | 745 throw new SpannableAssertionFailure(node, "Invalid index: ${semantics}"); |
| 740 } | 746 } |
| 741 } | 747 } |
| 742 | 748 |
| 743 /// The structure for a [Send] that is an equals test, i.e. of the form | 749 /// The structure for a [Send] that is an equals test, i.e. of the form |
| 744 /// `a == b`. | 750 /// `a == b`. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 arg); | 914 arg); |
| 909 default: | 915 default: |
| 910 // This is not a valid case. | 916 // This is not a valid case. |
| 911 break; | 917 break; |
| 912 } | 918 } |
| 913 throw new SpannableAssertionFailure( | 919 throw new SpannableAssertionFailure( |
| 914 node, "Invalid index set: ${semantics}"); | 920 node, "Invalid index set: ${semantics}"); |
| 915 } | 921 } |
| 916 } | 922 } |
| 917 | 923 |
| 924 /// The structure for a [Send] that is an prefix operation on an index |
| 925 /// expression, i.e. of the form `--a[b]`. |
| 926 class IndexPrefixStructure<R, A> implements SendStructure<R, A> { |
| 927 /// The target of the left operand. |
| 928 final AccessSemantics semantics; |
| 929 |
| 930 /// The `++` or `--` operator used in the operation. |
| 931 final IncDecOperator operator; |
| 932 |
| 933 // TODO(johnniwinther): Should we store this? |
| 934 /// The [Selector] for the `[]` invocation. |
| 935 final Selector getterSelector; |
| 936 |
| 937 // TODO(johnniwinther): Should we store this? |
| 938 /// The [Selector] for the `[]=` invocation. |
| 939 final Selector setterSelector; |
| 940 |
| 941 IndexPrefixStructure(this.semantics, |
| 942 this.operator, |
| 943 this.getterSelector, |
| 944 this.setterSelector); |
| 945 |
| 946 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 947 switch (semantics.kind) { |
| 948 case AccessKind.DYNAMIC_PROPERTY: |
| 949 return visitor.visitIndexPrefix( |
| 950 node, |
| 951 node.receiver, |
| 952 node.arguments.single, |
| 953 operator, |
| 954 arg); |
| 955 case AccessKind.UNRESOLVED: |
| 956 return visitor.errorUnresolvedSuperIndexPrefix( |
| 957 node, |
| 958 semantics.element, |
| 959 node.arguments.single, |
| 960 operator, |
| 961 arg); |
| 962 case AccessKind.COMPOUND: |
| 963 CompoundAccessSemantics compoundSemantics = semantics; |
| 964 switch (compoundSemantics.compoundAccessKind) { |
| 965 case CompoundAccessKind.SUPER_GETTER_SETTER: |
| 966 return visitor.visitSuperIndexPrefix( |
| 967 node, |
| 968 compoundSemantics.getter, |
| 969 compoundSemantics.setter, |
| 970 node.arguments.single, |
| 971 operator, |
| 972 arg); |
| 973 default: |
| 974 // This is not a valid case. |
| 975 break; |
| 976 } |
| 977 break; |
| 978 default: |
| 979 // This is not a valid case. |
| 980 break; |
| 981 } |
| 982 throw new SpannableAssertionFailure( |
| 983 node, "Invalid index prefix: ${semantics}"); |
| 984 } |
| 985 } |
| 986 |
| 987 /// The structure for a [Send] that is an postfix operation on an index |
| 988 /// expression, i.e. of the form `a[b]++`. |
| 989 class IndexPostfixStructure<R, A> implements SendStructure<R, A> { |
| 990 /// The target of the left operand. |
| 991 final AccessSemantics semantics; |
| 992 |
| 993 /// The `++` or `--` operator used in the operation. |
| 994 final IncDecOperator operator; |
| 995 |
| 996 // TODO(johnniwinther): Should we store this? |
| 997 /// The [Selector] for the `[]` invocation. |
| 998 final Selector getterSelector; |
| 999 |
| 1000 // TODO(johnniwinther): Should we store this? |
| 1001 /// The [Selector] for the `[]=` invocation. |
| 1002 final Selector setterSelector; |
| 1003 |
| 1004 IndexPostfixStructure(this.semantics, |
| 1005 this.operator, |
| 1006 this.getterSelector, |
| 1007 this.setterSelector); |
| 1008 |
| 1009 R dispatch(SemanticSendVisitor<R, A> visitor, Send node, A arg) { |
| 1010 switch (semantics.kind) { |
| 1011 case AccessKind.DYNAMIC_PROPERTY: |
| 1012 return visitor.visitIndexPostfix( |
| 1013 node, |
| 1014 node.receiver, |
| 1015 node.arguments.single, |
| 1016 operator, |
| 1017 arg); |
| 1018 case AccessKind.UNRESOLVED: |
| 1019 return visitor.errorUnresolvedSuperIndexPostfix( |
| 1020 node, |
| 1021 semantics.element, |
| 1022 node.arguments.single, |
| 1023 operator, |
| 1024 arg); |
| 1025 case AccessKind.COMPOUND: |
| 1026 CompoundAccessSemantics compoundSemantics = semantics; |
| 1027 switch (compoundSemantics.compoundAccessKind) { |
| 1028 case CompoundAccessKind.SUPER_GETTER_SETTER: |
| 1029 return visitor.visitSuperIndexPostfix( |
| 1030 node, |
| 1031 compoundSemantics.getter, |
| 1032 compoundSemantics.setter, |
| 1033 node.arguments.single, |
| 1034 operator, |
| 1035 arg); |
| 1036 default: |
| 1037 // This is not a valid case. |
| 1038 break; |
| 1039 } |
| 1040 break; |
| 1041 default: |
| 1042 // This is not a valid case. |
| 1043 break; |
| 1044 } |
| 1045 throw new SpannableAssertionFailure( |
| 1046 node, "Invalid index postfix: ${semantics}"); |
| 1047 } |
| 1048 } |
| 1049 |
| 918 /// The structure for a [Send] that is a compound assignment. For instance | 1050 /// The structure for a [Send] that is a compound assignment. For instance |
| 919 /// `a += b`. | 1051 /// `a += b`. |
| 920 class CompoundStructure<R, A> implements SendStructure<R, A> { | 1052 class CompoundStructure<R, A> implements SendStructure<R, A> { |
| 921 /// The target of the compound assignment, i.e. the left-hand side. | 1053 /// The target of the compound assignment, i.e. the left-hand side. |
| 922 final AccessSemantics semantics; | 1054 final AccessSemantics semantics; |
| 923 | 1055 |
| 924 /// The assignment operator used in the compound assignment. | 1056 /// The assignment operator used in the compound assignment. |
| 925 final AssignmentOperator operator; | 1057 final AssignmentOperator operator; |
| 926 | 1058 |
| 927 /// The [Selector] for the getter invocation. | 1059 /// The [Selector] for the getter invocation. |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1625 compoundSemantics.setter, | 1757 compoundSemantics.setter, |
| 1626 operator, | 1758 operator, |
| 1627 arg); | 1759 arg); |
| 1628 } | 1760 } |
| 1629 } | 1761 } |
| 1630 throw new SpannableAssertionFailure(node, | 1762 throw new SpannableAssertionFailure(node, |
| 1631 "Invalid compound assigment: ${semantics}"); | 1763 "Invalid compound assigment: ${semantics}"); |
| 1632 } | 1764 } |
| 1633 } | 1765 } |
| 1634 | 1766 |
| OLD | NEW |