~ubuntu-branches/ubuntu/quantal/aspectc++/quantal

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/src/CCOverloading.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "Puma/CClassInstance.h"
22
22
#include "Puma/CUnionInstance.h"
23
23
#include "Puma/CNamespaceInfo.h"
 
24
#include "Puma/CClassDatabase.h"
24
25
#include "Puma/CCOverloading.h"
25
26
#include "Puma/CFunctionInfo.h"
26
27
#include "Puma/CArgumentInfo.h"
34
35
#include "Puma/CCSemExpr.h"
35
36
#include "Puma/CTree.h"
36
37
 
 
38
#include <string.h>
 
39
 
37
40
namespace Puma {
38
41
 
39
42
 
215
218
      // non-conversion functions
216
219
      } else {
217
220
        seq = implicitThisConv (atype, atype, cf);
218
 
          ci->addConvSequence (seq);
 
221
        ci->addConvSequence (seq);
219
222
      }
220
223
    }
221
224
 
337
340
int CCOverloading::compareCandidates (CCandidateInfo *c1, CCandidateInfo *c2) const {
338
341
  unsigned num_ics1, num_ics2, first_ics;
339
342
  CFunctionInfo *f1, *f2;
340
 
  bool better;
 
343
  bool c1_better, c2_better;
341
344
 
342
 
  better = false;
 
345
  c1_better = c2_better = false;
343
346
  f1 = c1->Function ();
344
347
  f2 = c2->Function ();
345
348
  num_ics1 = c1->ConvSequences ();
362
365
  for (unsigned i = first_ics; i < num_ics1; i++) {
363
366
    switch (cvs.compareConvSeq (c1->ConvSequence (i), c2->ConvSequence (i))) {
364
367
      case 1:
365
 
        better = true;
 
368
        c1_better = true;
366
369
        break;
367
370
      case -1:
368
371
        // worse
369
 
        return -1;
 
372
        c2_better = true;
 
373
        break;
370
374
      default: 
371
375
        // case 0: not worse
372
376
        break;
373
377
    }
374
378
  }
375
 
  if (better)
 
379
  if (c1_better && ! c2_better)
376
380
    return 1;
 
381
  if (! c1_better && c2_better)
 
382
    return -1;
377
383
  
378
384
  // non-template functions are better than template functions
379
385
  if (! f1->FctInstance () && f2->FctInstance ())
384
390
  // a more specialized template function is better than a less 
385
391
  // specialized template function
386
392
  if (f1->FctInstance () && f2->FctInstance ()) {
387
 
    if (moreSpecialized (f1, f2))
388
 
      return 1;
389
 
    if (moreSpecialized (f2, f1))
390
 
      return -1;
 
393
    switch (moreSpecialized (f1, f2)) {
 
394
      case 1:
 
395
        // f1 more specialized
 
396
        return 1;
 
397
      case -1:
 
398
        // f2 more specialized
 
399
        return -1;
 
400
      default: 
 
401
        // case 0: equal specialized
 
402
        break;
 
403
    }
391
404
  }
392
405
  
393
406
  // context is initialization by user-defined conversion (�13.3.1.5)
506
519
        }
507
520
      }
508
521
      if (! hidden)
509
 
        addCandidate (new CCandidateInfo (fct));
 
522
        addCandidate (fct);
510
523
    }
511
524
  }
512
525
 
519
532
 
520
533
 
521
534
// collect converting constructors of cu (class or union)
522
 
void CCOverloading::collectConstructors (CRecord *cu) {
 
535
void CCOverloading::collectConstructors (CRecord *cu, bool default_constr) {
523
536
  CFunctionInfo *fct;
524
537
  cu = cu->DefObject ()->Record ();
525
538
  for (unsigned i = 0; i < cu->Functions (); i++) {
526
539
    fct = cu->Function (i);
527
540
    // non-default constructors are converting constructors
528
541
    // (i.e. constructors with parameters)
529
 
    if (fct->isConstructor () && fct->Arguments ())
530
 
      addCandidate (new CCandidateInfo (fct));
 
542
    if (fct->isConstructor () && (default_constr || fct->Arguments () > 0))
 
543
      addCandidate (fct);
531
544
  }
532
545
}
533
546
 
538
551
    info = nl.Object (i);
539
552
    if (! info->FunctionInfo ())
540
553
      continue;
541
 
    addCandidate (new CCandidateInfo (info->FunctionInfo ()));
 
554
    addCandidate (info->FunctionInfo ());
542
555
  }
543
556
}
544
557
 
545
558
 
546
 
void CCOverloading::addCandidate (CCandidateInfo *ci) { 
 
559
void CCOverloading::addCandidate (CFunctionInfo *fi) {
547
560
  for (unsigned i = Candidates (); i > 0; i--)
548
 
    if (Candidate (i-1)->Function () == ci->Function ()) {
549
 
      delete ci;
 
561
    if (Candidate (i-1)->Function () == fi)
550
562
      return;
551
 
    }
552
 
  _Candidates.append (ci); 
 
563
  _Candidates.append (new CCandidateInfo (fi)); 
553
564
}
554
565
 
555
566
 
575
586
}
576
587
 
577
588
 
578
 
bool CCOverloading::moreSpecialized (CFunctionInfo *f1, CFunctionInfo *f2) const {
579
 
  // !!! NOT YET IMPLEMENTED !!!
580
 
  return false;
 
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 ();
 
594
  
 
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 ());
 
599
  
 
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 ());
 
604
 
 
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 (); 
 
608
  
 
609
  // equal specialized
 
610
  if (f1_at_least_as_specialized && f2_at_least_as_specialized) 
 
611
    return 0;
 
612
  // f2 more specialized
 
613
  if (f2_at_least_as_specialized) 
 
614
    return -1;
 
615
  // f1 more specialized
 
616
  if (f1_at_least_as_specialized) 
 
617
    return 1;
 
618
  // equal specialized
 
619
  return 0;
581
620
}
582
621
 
583
622
 
587
626
 
588
627
 
589
628
// create built-in operators used as candidates for operator overloading
590
 
void CCOverloading::createBuiltinOperators (const char *opname, int oper, 
591
 
 CTree *arg0, CTree *arg1) { 
 
629
void CCOverloading::createBuiltinOperators (CClassDatabase *db,
 
630
  const char *opname, int oper, CTree *arg0, CTree *arg1) {
592
631
  unsigned len0, len1;
593
632
  CTypeInfo *t0, *t1;
594
633
  CRecord *record;
623
662
  // operator ||, operator &&, operator !
624
663
  // (these operators are always the same)
625
664
  if (oper == TOK_OR_OR || oper == TOK_AND_AND || oper == TOK_NOT)
626
 
    createLogOp (opname, t0, t1);
 
665
    createLogOp (db, oper, opname, t0, t1);
627
666
  else {
628
667
    // collect the types for the operands of the operators to be created
629
668
    Array<CTypeInfo*> types0; types0.append (t0);
656
695
        
657
696
        // operator ++
658
697
        if (oper == TOK_INCR)
659
 
          createIncrOp (opname, t0, t1);
 
698
          createIncrOp (db, oper, opname, t0, t1);
660
699
        // operator --
661
700
        else if (oper == TOK_DECR)
662
 
          createDecrOp (opname, t0, t1);
 
701
          createDecrOp (db, oper, opname, t0, t1);
663
702
        // operator *
664
703
        else if (oper == TOK_MUL)
665
 
          createMulOp (opname, t0, t1);
 
704
          createMulOp (db, oper, opname, t0, t1);
666
705
        // operator +
667
706
        else if (oper == TOK_PLUS)
668
 
          createPlusOp (opname, t0, t1);
 
707
          createPlusOp (db, oper, opname, t0, t1);
669
708
        // operator -
670
709
        else if (oper == TOK_MINUS)
671
 
          createMinusOp (opname, t0, t1);
 
710
          createMinusOp (db, oper, opname, t0, t1);
672
711
        // operator ~
673
712
        else if (oper == TOK_TILDE)
674
 
          createTildeOp (opname, t0, t1);
 
713
          createTildeOp (db, oper, opname, t0, t1);
675
714
        // operator ->*
676
715
        else if (oper == TOK_PTS_STAR) 
677
 
          createMembPtrOp (opname, t0, t1);
 
716
          createMembPtrOp (db, oper, opname, t0, t1);
678
717
        // operator []
679
718
        else if (oper == TOK_OPEN_SQUARE) // first token of []
680
 
          createIndexOp (opname, t0, t1);
 
719
          createIndexOp (db, oper, opname, t0, t1);
681
720
        // operator ?
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);
696
735
        // operator =
697
736
        else if (oper == TOK_ASSIGN)
698
 
          createAssOp (opname, t0, t1);
 
737
          createAssOp (db, oper, opname, t0, t1);
699
738
        // operator /
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);
711
750
      }
712
751
    }
713
752
  }
715
754
 
716
755
 
717
756
// operator ++
718
 
void CCOverloading::createIncrOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) { 
 
757
void CCOverloading::createIncrOp (CClassDatabase *db, int oper, 
 
758
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) { 
719
759
  CTypeInfo *t;
720
760
  
721
761
  if (t1) // unary operators do not have two operands
730
770
  //   T     operator++(VQ T&, int);
731
771
  if (t0->isArithmetic ()) {
732
772
    t = new CTypeAddress (t0->Duplicate ());
733
 
    createOperator (opname, t, t->Duplicate ());
734
 
    createOperator (opname, t0->UnqualType ()->Duplicate (), 
735
 
                    t->Duplicate (), &CTYPE_INT);
 
773
    createOperator (db, oper, opname, t->Duplicate (), t->Duplicate ());
 
774
    createOperator (db, oper, opname, t0->UnqualType ()->Duplicate (), 
 
775
                    t, &CTYPE_INT);
736
776
  }
737
777
 
738
778
  // 5. For every pair (T, VQ), where T is a cv-qualified or cv-unqualified 
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);
751
791
  }
752
792
}
753
793
 
754
794
 
755
795
// operator --
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) {
757
798
  CTypeInfo *t;
758
799
  
759
800
  if (t1) // unary operators do not have two operands
769
810
  //   T     operator--(VQ T&, int);
770
811
  if (t0->isArithmetic () && ! t0->UnqualType ()->is_bool ()) {
771
812
    t = new CTypeAddress (t0->Duplicate ());
772
 
    createOperator (opname, t, t->Duplicate ());
773
 
    createOperator (opname, t0->UnqualType ()->Duplicate (), 
774
 
                    t->Duplicate (), &CTYPE_INT);
 
813
    createOperator (db, oper, opname, t->Duplicate (), t->Duplicate ());
 
814
    createOperator (db, oper, opname, t0->UnqualType ()->Duplicate (), 
 
815
                    t, &CTYPE_INT);
775
816
  }
776
817
 
777
818
  // 5. For every pair (T, VQ), where T is a cv-qualified or cv-unqualified 
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);
790
831
  }
791
832
}
792
833
 
793
834
 
794
835
// operator *
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) {
796
838
  CTypeInfo *t;
797
839
  
798
840
  // 6. For every cv-qualified or cv-unqualified object type T, there exist 
803
845
  //   T& operator*(T*);
804
846
  if (! t1 && t0->isPointer ()) {
805
847
    t = new CTypeAddress (t0->PtrBaseType ()->Duplicate ());
806
 
    createOperator (opname, t, t0->Duplicate ());
 
848
    createOperator (db, oper, opname, t, t0->Duplicate ());
807
849
  }
808
850
 
809
851
  // 12. For every pair of promoted arithmetic types L and R, 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 ());
818
860
  }
819
861
}
820
862
 
821
863
 
822
864
// operator +
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;
825
868
  
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 ());
830
873
  }
831
874
 
832
875
  // 13. For every cv-qualified or cv-unqualified object type T there exist 
835
878
  //   T* operator+(ptrdiff_t, T*);
836
879
  if (t1 && t0->isObject () && t0->isPointer ()) {          
837
880
    t = CTypeInfo::CTYPE_PTRDIFF_T; // ptrdiff_t
838
 
    createOperator (opname, t0->Duplicate (), t0->Duplicate (), t);
839
 
    createOperator (opname, t0->Duplicate (), t, t0->Duplicate ());
 
881
    createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate (), t);
 
882
    createOperator (db, oper, opname, t0->Duplicate (), t, t0->Duplicate ());
840
883
  }                                          
841
884
 
842
885
  // 9. For every promoted arithmetic type T, there exist candidate operator 
844
887
  //   T operator+(T);
845
888
  if (! t1 && t0->isArithmetic ()) {
846
889
    t0 = cvs.arithmeticPromotion (t0);
847
 
    createOperator (opname, t0->Duplicate (), t0->Duplicate ()); 
 
890
    createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate ()); 
848
891
  }
849
892
 
850
893
  // 12. For every pair of promoted arithmetic types L and R, 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 ()); 
859
902
  }
860
903
}
861
904
 
862
905
 
863
906
// operator -
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;
866
910
  
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);
872
916
  }
873
917
 
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 ());
880
924
  }                        
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 ());
884
928
  }                        
885
929
 
886
930
  // 9. For every promoted arithmetic type T, there exist candidate operator 
888
932
  //   T operator-(T);
889
933
  if (! t1 && t0->isArithmetic ()) {
890
934
    t0 = cvs.arithmeticPromotion (t0);
891
 
    createOperator (opname, t0->Duplicate (), t0->Duplicate ()); 
 
935
    createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate ()); 
892
936
  }
893
937
 
894
938
  // 12. For every pair of promoted arithmetic types L and R, there exist 
899
943
    t0 = cvs.arithmeticPromotion (t0);
900
944
    t1 = cvs.arithmeticPromotion (t1);
901
945
    t = cvs.usualArithmeticConv (t0, t1);
902
 
    createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ()); 
 
946
    createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ()); 
903
947
  }
904
948
}
905
949
 
906
950
 
907
951
// operator ~
908
 
void CCOverloading::createTildeOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
952
void CCOverloading::createTildeOp (CClassDatabase *db, int oper,
 
953
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
909
954
  if (t1) // unary operators do not have two operands
910
955
    return;
911
956
 
914
959
  //   T operator~(T);
915
960
  if (t0->isInteger ()) {
916
961
    t0 = cvs.integralPromotion (t0);
917
 
    createOperator (opname, t0->Duplicate (), t0->Duplicate ());
 
962
    createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate ());
918
963
  }
919
964
}
920
965
 
921
966
 
922
967
// operator ->*
923
 
void CCOverloading::createMembPtrOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
968
void CCOverloading::createMembPtrOp (CClassDatabase *db, int oper,
 
969
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
924
970
  CTypeInfo *t;
925
971
  CRecord *c0, *c1;
926
972
  
950
996
        }
951
997
      }
952
998
      t = new CTypeAddress (t);
953
 
      createOperator (opname, t, t0->Duplicate (), t1->Duplicate ());
 
999
      createOperator (db, oper, opname, t, t0->Duplicate (), t1->Duplicate ());
954
1000
    }
955
1001
  } 
956
1002
}
957
1003
 
958
1004
 
959
1005
// operator []
960
 
void CCOverloading::createIndexOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1006
void CCOverloading::createIndexOp (CClassDatabase *db, int oper,
 
1007
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
961
1008
  CTypeInfo *rt, *pt, *t;
962
1009
  
963
1010
  if (! t1) // binary operators must have two operands
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);
976
1023
  }
977
1024
}
978
1025
 
979
1026
 
980
1027
// operator ?
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) {
982
1030
  CTypeInfo *t;
983
1031
 
984
1032
  if (! t1) // binary operators must have two operands
988
1036
  // candidate operator functions of the form
989
1037
  //   T operator?(bool, T, T);   // first operand skipped!!!
990
1038
  if (t0->isMemberPointer () || t0->isPointer ()) {
991
 
    createOperator (opname, t0->Duplicate (), t0->Duplicate (), t0->Duplicate ());
 
1039
    createOperator (db, oper, opname, t0->Duplicate (), t0->Duplicate (), t0->Duplicate ());
992
1040
  }
993
1041
  if (t1->isMemberPointer () || t1->isPointer ()) {
994
 
    createOperator (opname, t1->Duplicate (), t1->Duplicate (), t1->Duplicate ());
 
1042
    createOperator (db, oper, opname, t1->Duplicate (), t1->Duplicate (), t1->Duplicate ());
995
1043
  }
996
1044
 
997
1045
  // 24. For every pair of promoted arithmetic types L and R, there exist candidate 
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 ()); 
1006
1054
  }
1007
1055
}
1008
1056
 
1009
1057
 
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);
1016
1065
  if (! t1) {
1017
 
    createOperator (opname, &CTYPE_BOOL, &CTYPE_BOOL);
 
1066
    createOperator (db, oper, opname, &CTYPE_BOOL, &CTYPE_BOOL);
1018
1067
  } else {
1019
 
    createOperator (opname, &CTYPE_BOOL, &CTYPE_BOOL, &CTYPE_BOOL);
 
1068
    createOperator (db, oper, opname, &CTYPE_BOOL, &CTYPE_BOOL, &CTYPE_BOOL);
1020
1069
  }
1021
1070
}
1022
1071
 
1023
1072
 
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
1027
1077
    return;
1028
1078
 
1033
1083
  //   bool operator<=(T, T);
1034
1084
  //   bool operator>=(T, T);  
1035
1085
  if (t0->isPointer () || t0->isEnum ()) {
1036
 
    createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
 
1086
    createOperator (db, oper, opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
1037
1087
  } 
1038
1088
  if (t1->isPointer () || t1->isEnum ()) {
1039
 
    createOperator (opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
 
1089
    createOperator (db, oper, opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
1040
1090
  } 
1041
1091
  
1042
1092
  // 12. For every pair of promoted arithmetic types L and R, there exist 
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 ()); 
1053
1103
  }
1054
1104
}
1055
1105
 
1056
1106
 
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) {
1059
1110
  CTypeInfo *t;
1060
1111
  
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 ()); 
1078
1129
    } else {
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 ()); 
1081
1132
    }
1082
1133
  }
1083
1134
}
1084
1135
 
1085
1136
 
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
1089
1141
    return;
1090
1142
 
1100
1152
  if (t0->isInteger () && t1->isInteger () && ! t0->isConst ()) {
1101
1153
    t1 = cvs.integralPromotion (t1);
1102
1154
    t0 = new CTypeAddress (t0->Duplicate ());
1103
 
    createOperator (opname, t0, t0->Duplicate (), t1->Duplicate ()); 
 
1155
    createOperator (db, oper, opname, t0, t0->Duplicate (), t1->Duplicate ()); 
1104
1156
  }
1105
1157
}
1106
1158
 
1107
1159
 
1108
1160
// operator =
1109
 
void CCOverloading::createAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1161
void CCOverloading::createAssOp (CClassDatabase *db, int oper,
 
1162
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1110
1163
  CTypeInfo *t;
1111
1164
  
1112
1165
  if (! t1) // binary operators must have two operands
1123
1176
    if (t0->isVolatile ())
1124
1177
      t = new CTypeQualified (t, false, true, false);
1125
1178
    t = new CTypeAddress (t);
1126
 
    createOperator (opname, t, t->Duplicate (), t0->UnqualType ()->Duplicate ());
 
1179
    createOperator (db, oper, opname, t, t->Duplicate (), t0->UnqualType ()->Duplicate ());
1127
1180
  }
1128
1181
 
1129
1182
  // 20. For every pair (T, VQ), where T is an enumeration or pointer to member type 
1133
1186
  if (t0->isMemberPointer () || t0->isEnum ()) {
1134
1187
    t = new CTypeAddress (t0->Duplicate ());
1135
1188
    t0 = t0->UnqualType ()->Duplicate ();
1136
 
    createOperator (opname, t, t->Duplicate (), t0);
 
1189
    createOperator (db, oper, opname, t, t->Duplicate (), t0);
1137
1190
  }
1138
1191
 
1139
1192
  // 18. For every triple (L, VQ, R), where L is an arithmetic type, VQ is either 
1143
1196
  if (t0->isArithmetic () && t1->isArithmetic ()) {
1144
1197
    t = new CTypeAddress (t0->Duplicate ());
1145
1198
    t1 = cvs.arithmeticPromotion (t1);
1146
 
    createOperator (opname, t, t->Duplicate (), t1->Duplicate ()); 
 
1199
    createOperator (db, oper, opname, t, t->Duplicate (), t1->Duplicate ()); 
1147
1200
  }
1148
1201
}
1149
1202
 
1150
1203
 
1151
1204
// operator /
1152
 
void CCOverloading::createDivOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1205
void CCOverloading::createDivOp (CClassDatabase *db, int oper,
 
1206
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1153
1207
  CTypeInfo *t;
1154
1208
  
1155
1209
  if (! t1) // binary operators must have two operands
1163
1217
    t0 = cvs.arithmeticPromotion (t0);
1164
1218
    t1 = cvs.arithmeticPromotion (t1);
1165
1219
    t = cvs.usualArithmeticConv (t0, t1);
1166
 
    createOperator (opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ()); 
 
1220
    createOperator (db, oper, opname, t->Duplicate (), t0->Duplicate (), t1->Duplicate ()); 
1167
1221
  }
1168
1222
}
1169
1223
 
1170
1224
 
1171
1225
// operator ==, operator !=
1172
 
void CCOverloading::createEqOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1226
void CCOverloading::createEqOp (CClassDatabase *db, int oper,
 
1227
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1173
1228
  if (! t1) // binary operators must have two operands
1174
1229
    return;
1175
1230
 
1182
1237
  //   bool operator==(T, T);
1183
1238
  //   bool operator!=(T, T);
1184
1239
  if (t0->isMemberPointer () || t0->isPointer () || t0->isEnum ()) {
1185
 
    createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
 
1240
    createOperator (db, oper, opname, &CTYPE_BOOL, t0->Duplicate (), t0->Duplicate ());
1186
1241
  } 
1187
1242
  if (t1->isMemberPointer () || t1->isPointer () || t1->isEnum ()) {
1188
 
    createOperator (opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
 
1243
    createOperator (db, oper, opname, &CTYPE_BOOL, t1->Duplicate (), t1->Duplicate ());
1189
1244
  } 
1190
1245
 
1191
1246
  // 12. For every pair of promoted arithmetic types L and R, there exist 
1196
1251
  if (t0->isArithmetic () && t1->isArithmetic ()) {
1197
1252
    t0 = cvs.arithmeticPromotion (t0);
1198
1253
    t1 = cvs.arithmeticPromotion (t1);
1199
 
    createOperator (opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ()); 
 
1254
    createOperator (db, oper, opname, &CTYPE_BOOL, t0->Duplicate (), t1->Duplicate ()); 
1200
1255
  }
1201
1256
}
1202
1257
 
1203
1258
 
1204
1259
// operator *=, operator /=
1205
 
void CCOverloading::createMulAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1260
void CCOverloading::createMulAssOp (CClassDatabase *db, int oper,
 
1261
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1206
1262
  CTypeInfo *t;
1207
1263
 
1208
1264
  if (! t1) // binary operators must have two operands
1216
1272
  if (! t0->isConst () && t0->isArithmetic () && t1->isArithmetic ()) {
1217
1273
    t = new CTypeAddress (t0->Duplicate ());
1218
1274
    t1 = cvs.arithmeticPromotion (t1);
1219
 
    createOperator (opname, t, t->Duplicate (), t1->Duplicate ()); 
 
1275
    createOperator (db, oper, opname, t, t->Duplicate (), t1->Duplicate ()); 
1220
1276
  }
1221
1277
}
1222
1278
 
1223
1279
 
1224
1280
// operator +=, operator -=
1225
 
void CCOverloading::createAddAssOp (const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
 
1281
void CCOverloading::createAddAssOp (CClassDatabase *db, int oper,
 
1282
  const char *opname, CTypeInfo *t0, CTypeInfo *t1) {
1226
1283
  CTypeInfo *t;
1227
1284
  
1228
1285
  if (! t1) // binary operators must have two operands
1241
1298
    if (t0->isVolatile ())
1242
1299
      t = new CTypeQualified (t, false, true, false);
1243
1300
    t = new CTypeAddress (t);                  /* ptrdiff_t */
1244
 
    createOperator (opname, t, t->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T);
 
1301
    createOperator (db, oper, opname, t, t->Duplicate (), CTypeInfo::CTYPE_PTRDIFF_T);
1245
1302
  }
1246
1303
 
1247
1304
  // 18. For every triple (L, VQ, R), where L is an arithmetic type, VQ is either 
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 ()); 
1256
1313
  }
1257
1314
}
1258
1315
 
1259
1316
 
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) {
 
1319
  CTypeList *args;
1262
1320
  CFunctionInfo *info;
1263
 
  CTypeList *args;
1264
 
  CTypeInfo *type;
1265
1321
  
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
1286
1343
          }
1287
1344
  }
1288
1345
 
1289
 
  // return type
1290
 
  if (! rtype)
1291
 
    rtype = &CTYPE_UNDEFINED;
1292
 
 
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);
1297
 
  
1298
 
  // operator function type
1299
 
  type = new CTypeFunction (rtype, args, true);
1300
 
 
1301
 
  // operator function
1302
 
  info = new CFunctionInfo;
1303
 
  info->Name (name);
1304
 
  info->isOperator (true);
1305
 
  info->ObjectInfo ()->TypeInfo (type);
1306
 
  type->VirtualType ()->TypeFunction ()->FunctionInfo (info);
1307
 
 
1308
 
  // create function parameters
1309
 
  if (t0) createParameter (info, t0);
1310
 
  if (t1) createParameter (info, t1);
1311
 
 
1312
 
  addCandidate (new CCandidateInfo (info));
1313
 
}
1314
 
 
1315
 
 
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
 
1347
  // candidate
 
1348
  addCandidate (db->BuiltinOperator (name, oper, rtype, t0, t1));
1322
1349
}
1323
1350
 
1324
1351