578
bool CCOverloading::moreSpecialized (CFunctionInfo *f1, CFunctionInfo *f2) const {
579
// !!! NOT YET IMPLEMENTED !!!
589
int CCOverloading::moreSpecialized (CFunctionInfo *f1, CFunctionInfo *f2) const {
590
CTemplateInstance *inst1 = f1->TemplateInstance ();
591
CTemplateInstance *inst2 = f2->TemplateInstance ();
592
f1 = inst1->Template ()->ObjectInfo ()->FunctionInfo ();
593
f2 = inst2->Template ()->ObjectInfo ()->FunctionInfo ();
595
InstantiationCandidate cand1;
596
cand1.initialize (inst1->PointOfInstantiation (), f1, inst1->Template ());
597
for (unsigned i = 0; i < f2->Arguments (); i++)
598
cand1.addArgument (f2->Argument (i)->Tree ());
600
InstantiationCandidate cand2;
601
cand2.initialize (inst2->PointOfInstantiation (), f2, inst2->Template ());
602
for (unsigned i = 0; i < f1->Arguments (); i++)
603
cand2.addArgument (f1->Argument (i)->Tree ());
605
// perform argument deduction against the other function
606
bool f1_at_least_as_specialized = cand2.deduceArgumentsFromFctCall ();
607
bool f2_at_least_as_specialized = cand1.deduceArgumentsFromFctCall ();
610
if (f1_at_least_as_specialized && f2_at_least_as_specialized)
612
// f2 more specialized
613
if (f2_at_least_as_specialized)
615
// f1 more specialized
616
if (f1_at_least_as_specialized)
658
697
if (oper == TOK_INCR)
659
createIncrOp (opname, t0, t1);
698
createIncrOp (db, oper, opname, t0, t1);
661
700
else if (oper == TOK_DECR)
662
createDecrOp (opname, t0, t1);
701
createDecrOp (db, oper, opname, t0, t1);
664
703
else if (oper == TOK_MUL)
665
createMulOp (opname, t0, t1);
704
createMulOp (db, oper, opname, t0, t1);
667
706
else if (oper == TOK_PLUS)
668
createPlusOp (opname, t0, t1);
707
createPlusOp (db, oper, opname, t0, t1);
670
709
else if (oper == TOK_MINUS)
671
createMinusOp (opname, t0, t1);
710
createMinusOp (db, oper, opname, t0, t1);
673
712
else if (oper == TOK_TILDE)
674
createTildeOp (opname, t0, t1);
713
createTildeOp (db, oper, opname, t0, t1);
676
715
else if (oper == TOK_PTS_STAR)
677
createMembPtrOp (opname, t0, t1);
716
createMembPtrOp (db, oper, opname, t0, t1);
679
718
else if (oper == TOK_OPEN_SQUARE) // first token of []
680
createIndexOp (opname, t0, t1);
719
createIndexOp (db, oper, opname, t0, t1);
682
721
else if (oper == TOK_QUESTION) // cannot be overloaded! see �13.6.24
683
createIfThenOp (opname, t0, t1);
722
createIfThenOp (db, oper, opname, t0, t1);
684
723
// operator <, operator >, operator <=, operator >=
685
724
else if (oper == TOK_LESS || oper == TOK_GREATER ||
686
725
oper == TOK_LEQ || oper == TOK_GEQ)
687
createRelOp (opname, t0, t1);
726
createRelOp (db, oper, opname, t0, t1);
688
727
// operator %, operator &, operator ^, operator |, operator <<, operator >>
689
728
else if (oper == TOK_MODULO || oper == TOK_AND || oper == TOK_ROOF ||
690
729
oper == TOK_OR || oper == TOK_LSH || oper == TOK_RSH)
691
createBinOp (opname, t0, t1);
730
createBinOp (db, oper, opname, t0, t1);
692
731
// operator %=, operator &=, operator ^=, operator |=, operator <<=, operator >>=
693
732
else if (oper == TOK_MOD_EQ || oper == TOK_AND_EQ || oper == TOK_XOR_EQ ||
694
733
oper == TOK_IOR_EQ || oper == TOK_LSH_EQ || oper == TOK_RSH_EQ)
695
createEqAssOp (opname, t0, t1);
734
createEqAssOp (db, oper, opname, t0, t1);
697
736
else if (oper == TOK_ASSIGN)
698
createAssOp (opname, t0, t1);
737
createAssOp (db, oper, opname, t0, t1);
700
739
else if (oper == TOK_DIV)
701
createDivOp (opname, t0, t1);
740
createDivOp (db, oper, opname, t0, t1);
702
741
// operator ==, operator !=
703
742
else if (oper == TOK_EQL || oper == TOK_NEQ)
704
createEqOp (opname, t0, t1);
743
createEqOp (db, oper, opname, t0, t1);
705
744
// operator *=, operator /=
706
745
else if (oper == TOK_MUL_EQ || oper == TOK_DIV_EQ)
707
createMulAssOp (opname, t0, t1);
746
createMulAssOp (db, oper, opname, t0, t1);
708
747
// operator +=, operator -=
709
748
else if (oper == TOK_ADD_EQ || oper == TOK_SUB_EQ)
710
createAddAssOp (opname, t0, t1);
749
createAddAssOp (db, oper, opname, t0, t1);
746
786
t = new CTypeQualified (t, false, true, false);
747
787
t = new CTypeAddress (t);
748
788
t0 = t0->UnqualType ()->Duplicate ();
749
createOperator (opname, t, t->Duplicate ());
750
createOperator (opname, t0, t->Duplicate (), &CTYPE_INT);
789
createOperator (db, oper, opname, t->Duplicate (), t->Duplicate ());
790
createOperator (db, oper, opname, t0, t, &CTYPE_INT);
756
void CCOverloading::createDecrOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
796
void CCOverloading::createDecrOp (CClassDatabase *db, int oper,
797
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
759
800
if (t1) // unary operators do not have two operands
785
826
t = new CTypeQualified (t, false, true, false);
786
827
t = new CTypeAddress (t);
787
828
t0 = t0->UnqualType ()->Duplicate ();
788
createOperator (opname, t, t->Duplicate ());
789
createOperator (opname, t0, t->Duplicate (), &CTYPE_INT);
829
createOperator (db, oper, opname, t->Duplicate (), t->Duplicate ());
830
createOperator (db, oper, opname, t0, t, &CTYPE_INT);
795
void CCOverloading::createMulOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
836
void CCOverloading::createMulOp (CClassDatabase *db, int oper,
837
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
798
840
// 6. For every cv-qualified or cv-unqualified object type T, there exist
814
856
t0 = cvs.arithmeticPromotion (t0);
815
857
t1 = cvs.arithmeticPromotion (t1);
816
858
t = cvs.usualArithmeticConv (t0, t1);
817
createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
859
createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
823
void CCOverloading::createPlusOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
865
void CCOverloading::createPlusOp (CClassDatabase *db, int oper,
866
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
824
867
CTypeInfo *t = 0;
826
869
// 8. For every type T, there exist candidate operator functions of the form
827
870
// T* operator+(T*);
828
871
if (! t1 && t0->isPointer ()) {
829
createOperator (opname, t0->Duplicate (), t0->Duplicate ());
872
createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate ());
832
875
// 13. For every cv-qualified or cv-unqualified object type T there exist
855
898
t0 = cvs.arithmeticPromotion (t0);
856
899
t1 = cvs.arithmeticPromotion (t1);
857
900
t = cvs.usualArithmeticConv (t0, t1);
858
createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
901
createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
864
void CCOverloading::createMinusOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
907
void CCOverloading::createMinusOp (CClassDatabase *db, int oper,
908
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
865
909
CTypeInfo *t = 0;
867
911
// 13. For every cv-qualified or cv-unqualified object type T there exist
868
912
// candidate operator functions of the form
869
913
// T* operator-(T*, ptrdiff_t);
870
914
if (t1 && t0->isObject () && t0->isPointer ()) {
871
createOperator (opname, t0->Duplicate (), t0->Duplicate (), t);
915
createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate (), t);
874
918
// 14. For every T, where T is a pointer to object type, there exist candidate
876
920
// ptrdiff_t operator-(T, T);
877
921
if (t1 && t0->isPointer () && t0->PtrBaseType ()->isObject ()) {
878
922
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
879
createOperator (opname, t, t0->Duplicate (), t0->Duplicate ());
923
createOperator (db, oper, opname, t, t0->Duplicate (), t0->Duplicate ());
881
925
if (t1 && t1->isPointer () && t1->PtrBaseType ()->isObject ()) {
882
926
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
883
createOperator (opname, t, t1->Duplicate (), t1->Duplicate ());
927
createOperator (db, oper, opname, t, t1->Duplicate (), t1->Duplicate ());
886
930
// 9. For every promoted arithmetic type T, there exist candidate operator
971
1018
rt = new CTypeAddress (t0->PtrBaseType ()->Duplicate ());
972
1019
pt = t0->Duplicate ();
973
1020
t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
974
createOperator (opname, rt, pt, t);
975
createOperator (opname, rt->Duplicate (), t, pt->Duplicate ());
1021
createOperator (db, oper, opname, rt->Duplicate (), pt->Duplicate (), t);
1022
createOperator (db, oper, opname, rt, t, pt);
981
void CCOverloading::createIfThenOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1028
void CCOverloading::createIfThenOp (CClassDatabase *db, int oper,
1029
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
984
1032
if (! t1) // binary operators must have two operands
1002
1050
t0 = cvs.arithmeticPromotion (t0);
1003
1051
t1 = cvs.arithmeticPromotion (t1);
1004
1052
t = cvs.usualArithmeticConv (t0, t1);
1005
createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1053
createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1010
1058
// operator ||, operator &&, operator !
1011
void CCOverloading::createLogOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1059
void CCOverloading::createLogOp (CClassDatabase *db, int oper,
1060
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1012
1061
// 23. There also exist candidate operator functions of the form
1013
1062
// bool operator!(bool);
1014
1063
// bool operator&&(bool, bool);
1015
1064
// bool operator||(bool, bool);
1017
createOperator (opname, &CTYPE_BOOL, &CTYPE_BOOL);
1066
createOperator (db, oper, opname, &CTYPE_BOOL, &CTYPE_BOOL);
1019
createOperator (opname, &CTYPE_BOOL, &CTYPE_BOOL, &CTYPE_BOOL);
1068
createOperator (db, oper, opname, &CTYPE_BOOL, &CTYPE_BOOL, &CTYPE_BOOL);
1024
1073
// operator <, operator >, operator <=, operator >=
1025
void CCOverloading::createRelOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1074
void CCOverloading::createRelOp (CClassDatabase *db, int oper,
1075
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1026
1076
if (! t1) // binary operators must have two operands
1049
1099
if (t0->isArithmetic () && t1->isArithmetic ()) {
1050
1100
t0 = cvs.arithmeticPromotion (t0);
1051
1101
t1 = cvs.arithmeticPromotion (t1);
1052
createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ());
1102
createOperator (db, oper, opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ());
1057
1107
// operator %, operator &, operator ^, operator |, operator <<, operator >>
1058
void CCOverloading::createBinOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1108
void CCOverloading::createBinOp (CClassDatabase *db, int oper,
1109
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1061
1112
if (! t1) // binary operators must have two operands
1074
1125
t0 = cvs.integralPromotion (t0);
1075
1126
t1 = cvs.integralPromotion (t1);
1076
1127
if (*(opname+9) == '<' || *(opname+9) == '>') {
1077
createOperator (opname, t0->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1128
createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1079
1130
t = cvs.usualArithmeticConv (t0, t1);
1080
createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1131
createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ());
1086
1137
// operator %=, operator &=, operator ^=, operator |=, operator <<=, operator >>=
1087
void CCOverloading::createEqAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1138
void CCOverloading::createEqAssOp (CClassDatabase *db, int oper,
1139
const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1088
1140
if (! t1) // binary operators must have two operands
1252
1309
if (t0->isArithmetic () && t1->isArithmetic ()) {
1253
1310
t = new CTypeAddress (t0->Duplicate ());
1254
1311
t1 = cvs.arithmeticPromotion (t1);
1255
createOperator (opname, t, t->Duplicate (), t1->Duplicate ());
1312
createOperator (db, oper, opname, t, t->Duplicate (), t1->Duplicate ());
1260
void CCOverloading::createOperator (const char *name, CTypeInfo *rtype,
1261
CTypeInfo *t0, CTypeInfo *t1) {
1317
void CCOverloading::createOperator (CClassDatabase *db, int oper,
1318
const char *name, CTypeInfo *rtype, CTypeInfo *t0, CTypeInfo *t1) {
1262
1320
CFunctionInfo *info;
1266
1322
// add operator function to candidate set only if there is no
1267
1323
// other non-template non-member candidate with the same parameter
1282
1338
(t1 ? *t1 == *args->Entry (1) : true)) {
1283
1339
if (t0) CTypeInfo::Destroy (t0);
1284
1340
if (t1) CTypeInfo::Destroy (t1);
1341
if (rtype) CTypeInfo::Destroy (rtype);
1285
1342
return; // operator already exists
1291
rtype = &CTYPE_UNDEFINED;
1293
// parameter type list
1294
args = new CTypeList ((t0?1:0)+(t1?1:0));
1295
if (t0) args->AddEntry (t0);
1296
if (t1) args->AddEntry (t1);
1298
// operator function type
1299
type = new CTypeFunction (rtype, args, true);
1301
// operator function
1302
info = new CFunctionInfo;
1304
info->isOperator (true);
1305
info->ObjectInfo ()->TypeInfo (type);
1306
type->VirtualType ()->TypeFunction ()->FunctionInfo (info);
1308
// create function parameters
1309
if (t0) createParameter (info, t0);
1310
if (t1) createParameter (info, t1);
1312
addCandidate (new CCandidateInfo (info));
1316
void CCOverloading::createParameter (CFunctionInfo *finfo, CTypeInfo *type) const {
1317
CArgumentInfo *info;
1318
info = finfo->newArgument ();
1319
info->Name ("<noname>");
1320
info->Storage (CStorage::CLASS_AUTOMATIC);
1321
info->TypeInfo (type->Duplicate ());
1346
// get the built-in operator object from the class the and add it as a
1348
addCandidate (db->BuiltinOperator (name, oper, rtype, t0, t1));