734
740
// operator functions of the form
735
741
// T*VQ& operator++(T*VQ&);
736
742
// T* operator++(T*VQ&, int);
737
if (t0->isObject ()) {
738
t = new CTypePointer (t0->UnqualType ()->Duplicate ());
743
if (t0->isObject () && t0->isPointer ()) {
744
t = t0->UnqualType ()->Duplicate ();
739
745
if (t0->isVolatile ())
740
746
t = new CTypeQualified (t, false, true, false);
741
747
t = new CTypeAddress (t);
742
t0 = new CTypePointer (t0->UnqualType ()->Duplicate ());
748
t0 = t0->UnqualType ()->Duplicate ();
743
749
createOperator (opname, t, t->Duplicate ());
744
750
createOperator (opname, t0, t->Duplicate (), &CTYPE_INT);
773
779
// operator functions of the form
774
780
// T*VQ& operator--(T*VQ&);
775
781
// T* operator--(T*VQ&, int);
776
if (t0->isObject ()) {
777
t = new CTypePointer (t0->UnqualType ()->Duplicate ());
782
if (t0->isObject () && t0->isPointer ()) {
783
t = t0->UnqualType ()->Duplicate ();
778
784
if (t0->isVolatile ())
779
785
t = new CTypeQualified (t, false, true, false);
780
786
t = new CTypeAddress (t);
781
t0 = new CTypePointer (t0->UnqualType ()->Duplicate ());
787
t0 = t0->UnqualType ()->Duplicate ();
782
788
createOperator (opname, t, t->Duplicate ());
783
789
createOperator (opname, t0, t->Duplicate (), &CTYPE_INT);
795
801
// 7. For every function type T, there exist candidate operator functions
797
803
// T& operator*(T*);
799
createOperator (opname, new CTypeAddress (t0->Duplicate ()),
800
new CTypePointer (t0->Duplicate ()));
804
if (! t1 && t0->isPointer ()) {
805
t = new CTypeAddress (t0->PtrBaseType ()->Duplicate ());
806
createOperator (opname, t, t0->Duplicate ());
803
809
// 12. For every pair of promoted arithmetic types L and R, there exist
820
826
// 8. For every type T, there exist candidate operator functions of the form
821
827
// T* operator+(T*);
823
t = new CTypePointer (t0->Duplicate ());
824
createOperator (opname, t, t->Duplicate ());
828
if (! t1 && t0->isPointer ()) {
829
createOperator (opname, t0->Duplicate (), t0->Duplicate ());
827
832
// 13. For every cv-qualified or cv-unqualified object type T there exist
828
833
// candidate operator functions of the form
829
834
// T* operator+(T*, ptrdiff_t);
830
835
// T* operator+(ptrdiff_t, T*);
831
if (! t1 && t0->isObject ()) { /* ptrdiff_t */
832
createOperator (opname, t->Duplicate (), t->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T);
833
createOperator (opname, t->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T, t->Duplicate ());
836
if (t1 && t0->isObject () && t0->isPointer ()) {
837
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
838
createOperator (opname, t0->Duplicate (), t0->Duplicate (), t);
839
createOperator (opname, t0->Duplicate (), t, t0->Duplicate ());
836
842
// 9. For every promoted arithmetic type T, there exist candidate operator
837
843
// functions of the form
858
864
void CCOverloading::createMinusOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
861
867
// 13. For every cv-qualified or cv-unqualified object type T there exist
862
868
// candidate operator functions of the form
863
869
// T* operator-(T*, ptrdiff_t);
864
if (! t1 && t0->isObject ()) {
865
t = new CTypePointer (t0->Duplicate ()); /* ptrdiff_t */
866
createOperator (opname, t, t->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T);
870
if (t1 && t0->isObject () && t0->isPointer ()) {
871
createOperator (opname, t0->Duplicate (), t0->Duplicate (), t);
869
874
// 14. For every T, where T is a pointer to object type, there exist candidate
870
875
// operator functions of the form
871
876
// ptrdiff_t operator-(T, T);
872
if (! t1 && t0->isPointer () && t0->VirtualType ()->BaseType ()->isObject ()) {
873
createOperator (opname, CTypeInfo::CTYPE_PTRDIFF_T, t0->Duplicate (),
874
t0->Duplicate ()); /* ptrdiff_t */
877
if (t1 && t0->isPointer () && t0->PtrBaseType ()->isObject ()) {
878
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
879
createOperator (opname, t, t0->Duplicate (), t0->Duplicate ());
881
if (t1 && t1->isPointer () && t1->PtrBaseType ()->isObject ()) {
882
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
883
createOperator (opname, t, t1->Duplicate (), t1->Duplicate ());
877
886
// 9. For every promoted arithmetic type T, there exist candidate operator
899
908
void CCOverloading::createTildeOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
900
if (t1) // check operands
909
if (t1) // unary operators do not have two operands
903
912
// 10. For every promoted integral type T, there exist candidate operator
916
925
CRecord *c0, *c1;
927
if (! t1) // binary operators must have two operands
921
930
// 11. For every quintuple (C1, C2, T, CV1, CV2), where C2 is a class type,
951
960
void CCOverloading::createIndexOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
961
CTypeInfo *rt, *pt, *t;
963
if (! t1) // binary operators must have two operands
957
966
// 13. For every cv-qualified or cv-unqualified object type T there exist
958
967
// candidate operator functions of the form
959
968
// T& operator[](T*, ptrdiff_t);
960
969
// T& operator[](ptrdiff_t, T*);
961
if (t0->isObject ()) {
962
rt = new CTypeAddress (t0->Duplicate ());
963
pt = new CTypePointer (t0->Duplicate ());
964
createOperator (opname, rt, pt, CTypeInfo::CTYPE_PTRDIFF_T); /* ptrdiff_t */
965
createOperator (opname, rt->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T,
966
pt->Duplicate ()); /* ptrdiff_t */
970
if (t0->isObject () && t0->isPointer ()) {
971
rt = new CTypeAddress (t0->PtrBaseType ()->Duplicate ());
972
pt = t0->Duplicate ();
973
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
974
createOperator (opname, rt, pt, t);
975
createOperator (opname, rt->Duplicate (), t, pt->Duplicate ());
972
981
void CCOverloading::createIfThenOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
984
if (! t1) // binary operators must have two operands
975
987
// 25. For every type T, where T is a pointer or pointer-to-member type, there exist
976
988
// candidate operator functions of the form
977
989
// T operator?(bool, T, T); // first operand skipped!!!
978
if (! t1 && (t0->isMemberPointer () || t0->isPointer ())) {
990
if (t0->isMemberPointer () || t0->isPointer ()) {
979
991
createOperator (opname, t0->Duplicate (), t0->Duplicate (), t0->Duplicate ());
993
if (t1->isMemberPointer () || t1->isPointer ()) {
994
createOperator (opname, t1->Duplicate (), t1->Duplicate (), t1->Duplicate ());
982
997
// 24. For every pair of promoted arithmetic types L and R, there exist candidate
983
998
// operator functions of the form (where LR is the result of the usual arithmetic
984
999
// conversions between types L and R)
985
1000
// LR operator?(bool, L, R); // first operand skipped!!!
986
if (t1 && t0->isArithmetic () && t1->isArithmetic ()) {
1001
if (t0->isArithmetic () && t1->isArithmetic ()) {
987
1002
t0 = cvs.arithmeticPromotion (t0);
988
1003
t1 = cvs.arithmeticPromotion (t1);
989
1004
t = cvs.usualArithmeticConv (t0, t1);
1009
1024
// operator <, operator >, operator <=, operator >=
1010
1025
void CCOverloading::createRelOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1026
if (! t1) // binary operators must have two operands
1011
1029
// 15. For every pointer or enumeration type T, there exist candidate operator
1012
1030
// functions of the form
1013
1031
// bool operator<(T, T);
1014
1032
// bool operator>(T, T);
1015
1033
// bool operator<=(T, T);
1016
1034
// bool operator>=(T, T);
1017
if (! t1 && (t0->isPointer () || t0->isEnum ())) {
1035
if (t0->isPointer () || t0->isEnum ()) {
1018
1036
createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
1038
if (t1->isPointer () || t1->isEnum ()) {
1039
createOperator (opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
1021
1042
// 12. For every pair of promoted arithmetic types L and R, there exist
1022
1043
// candidate operator functions of the form (where LR is the result of the
1025
1046
// bool operator>(L, R);
1026
1047
// bool operator<=(L, R);
1027
1048
// bool operator>=(L, R);
1028
if (t1 && t0->isArithmetic () && t1->isArithmetic ()) {
1049
if (t0->isArithmetic () && t1->isArithmetic ()) {
1029
1050
t0 = cvs.arithmeticPromotion (t0);
1030
1051
t1 = cvs.arithmeticPromotion (t1);
1031
1052
createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ());
1037
1058
void CCOverloading::createBinOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1061
if (! t1) // binary operators must have two operands
1043
1064
// 17. For every pair of promoted integral types L and R, there exist candidate
1065
1086
// operator %=, operator &=, operator ^=, operator |=, operator <<=, operator >>=
1066
1087
void CCOverloading::createEqAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1088
if (! t1) // binary operators must have two operands
1070
1091
// 22. For every triple (L, VQ, R), where L is an integral type, VQ is either
1088
1109
void CCOverloading::createAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1112
if (! t1) // binary operators must have two operands
1091
1115
if (t0->isConst ())
1094
1118
// 19. For every pair (T, VQ), where T is any type and VQ is either volatile or
1095
1119
// empty, there exist candidate operator functions of the form
1096
1120
// T*VQ& operator=(T*VQ&, T*);
1098
t = new CTypePointer (t0->UnqualType ()->Duplicate ());
1121
if (t0->isPointer ()) {
1122
t = t0->UnqualType ()->Duplicate ();
1099
1123
if (t0->isVolatile ())
1100
1124
t = new CTypeQualified (t, false, true, false);
1101
1125
t = new CTypeAddress (t);
1102
createOperator (opname, t, t->Duplicate (),
1103
new CTypePointer (t0->UnqualType ()->Duplicate ()));
1126
createOperator (opname, t, t->Duplicate (), t0->UnqualType ()->Duplicate ());
1106
1129
// 20. For every pair (T, VQ), where T is an enumeration or pointer to member type
1107
1130
// and VQ is either volatile or empty, there exist candidate operator functions
1109
1132
// VQ T& operator=(VQ T&, T);
1110
if (! t1 && (t0->isMemberPointer () || t0->isEnum ())) {
1133
if (t0->isMemberPointer () || t0->isEnum ()) {
1111
1134
t = new CTypeAddress (t0->Duplicate ());
1112
1135
t0 = t0->UnqualType ()->Duplicate ();
1113
1136
createOperator (opname, t, t->Duplicate (), t0);
1117
1140
// volatile or empty, and R is a promoted arithmetic type, there exist candidate
1118
1141
// operator functions of the form
1119
1142
// VQ L& operator=(VQ L&, R);
1120
if (t1 && t0->isArithmetic () && t1->isArithmetic ()) {
1143
if (t0->isArithmetic () && t1->isArithmetic ()) {
1121
1144
t = new CTypeAddress (t0->Duplicate ());
1122
1145
t1 = cvs.arithmeticPromotion (t1);
1123
1146
createOperator (opname, t, t->Duplicate (), t1->Duplicate ());
1129
1152
void CCOverloading::createDivOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1155
if (! t1) // binary operators must have two operands
1135
1158
// 12. For every pair of promoted arithmetic types L and R, there exist
1148
1171
// operator ==, operator !=
1149
1172
void CCOverloading::createEqOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1173
if (! t1) // binary operators must have two operands
1150
1176
// 15. For every pointer or enumeration type T, there exist candidate operator
1151
1177
// functions of the form
1152
1178
// bool operator==(T, T);
1155
1181
// functions of the form
1156
1182
// bool operator==(T, T);
1157
1183
// bool operator!=(T, T);
1158
if (! t1 && (t0->isMemberPointer () || t0->isPointer () || t0->isEnum ())) {
1184
if (t0->isMemberPointer () || t0->isPointer () || t0->isEnum ()) {
1159
1185
createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
1187
if (t1->isMemberPointer () || t1->isPointer () || t1->isEnum ()) {
1188
createOperator (opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
1162
1191
// 12. For every pair of promoted arithmetic types L and R, there exist
1163
1192
// candidate operator functions of the form (where LR is the result of the
1164
1193
// usual arithmetic conversions between types L and R)
1165
1194
// bool operator==(L, R);
1166
1195
// bool operator!=(L, R);
1167
if (t1 && t0->isArithmetic () && t1->isArithmetic ()) {
1196
if (t0->isArithmetic () && t1->isArithmetic ()) {
1168
1197
t0 = cvs.arithmeticPromotion (t0);
1169
1198
t1 = cvs.arithmeticPromotion (t1);
1170
1199
createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ());
1176
1205
void CCOverloading::createMulAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1208
if (! t1) // binary operators must have two operands
1182
1211
// 18. For every triple (L, VQ, R), where L is an arithmetic type, VQ is either
1205
1237
// T*VQ& operator+=(T*VQ&, ptrdiff_t);
1206
1238
// T*VQ& operator-=(T*VQ&, ptrdiff_t);
1207
if (! t1 && t0->isObject ()) {
1208
t = new CTypePointer (t0->UnqualType ()->Duplicate ());
1239
if (t0->isObject () && t0->isPointer ()) {
1240
t = t0->UnqualType ()->Duplicate ();
1209
1241
if (t0->isVolatile ())
1210
1242
t = new CTypeQualified (t, false, true, false);
1211
1243
t = new CTypeAddress (t); /* ptrdiff_t */
1217
1249
// operator functions of the form
1218
1250
// VQ L& operator+=(VQ L&, R);
1219
1251
// VQ L& operator-=(VQ L&, R);
1220
if (t1 && t0->isArithmetic () && t1->isArithmetic ()) {
1252
if (t0->isArithmetic () && t1->isArithmetic ()) {
1221
1253
t = new CTypeAddress (t0->Duplicate ());
1222
1254
t1 = cvs.arithmeticPromotion (t1);
1223
1255
createOperator (opname, t, t->Duplicate (), t1->Duplicate ());