~ubuntu-branches/ubuntu/jaunty/aspectc++/jaunty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-07-07 14:41:02 UTC
  • mfrom: (1.1.3 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707144102-lzml7t07f3sl00r5
Tags: 1.0pre4~svn.20080711-1
* new upstream snapshot.
* include all upstream documentation. Clarifying emails regarding
  licensing has been included into debian/copyright.
* reformat description following recomendations of
  http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
  (Closes: #480316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
// �8.5.14 initialization
124
124
CCConvSeq *CCConversions::implicitConversions (CTypeInfo *ptype, 
125
125
 CTypeInfo *atype, CTree *arg_expr, CTree *base, bool user_def) {
 
126
  if (! atype || ! ptype)
 
127
    return 0;
 
128
    
126
129
  // argument passing is a copy-initialization
127
130
  if (atype->isAddress ())
128
131
    atype = atype->BaseType ();
159
162
      if (param->isPointer () &&
160
163
          (param->BaseType ()->UnqualType ()->is_void () ||
161
164
           (arg_expr->NodeName () == CT_String::NodeId () && 
162
 
            param->BaseType ()->UnqualType ()->is_char ()) ||
 
165
            param->BaseType ()->UnqualType ()->is_char ()) ||
163
166
           (arg_expr->NodeName () == CT_WideString::NodeId () && 
164
 
            param->BaseType ()->UnqualType ()->is_wchar_t ()))) {
 
167
            param->BaseType ()->UnqualType ()->is_wchar_t ()))) {
165
168
        // convert to "pointer to char" resp. to "pointer to wchar_t"
166
169
        seq->addConversion (new CCArrayToPointerConv (param, arg, arg_expr, base));
167
170
        arg = arg->BaseType ()->UnqualType ();
309
312
          seq = new CCUserDefinedConvSeq;
310
313
          // 1. initial standard conversion sequence
311
314
          seq->addConversion (new CCDerivedToBaseConv (param, arg, arg_expr, base));
312
 
          // 2. user-defined conversion
 
315
          // 2. user-defined conversion
313
316
          seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
314
 
          // 3. second standard conversion sequence
315
 
          seq2 = new CCStandardConvSeq;
 
317
          // 3. second standard conversion sequence
 
318
          seq2 = new CCStandardConvSeq;
316
319
          seq2->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
317
 
          seq->addConversion (seq2);
 
320
          seq->addConversion (seq2);
318
321
        }
319
322
      // �13.3.1.4 initialization of class type with a (non-)class type
320
323
      } else {
321
324
        if (c1) {
322
325
          // candidates are conversion functions of c1 and its base 
323
 
          // classes that are visible in c1 and yield a type whose 
324
 
          // cv-unqualified version is the same type as c2 or is a 
325
 
          // derived class thereof (including functions returning 
326
 
          // "reference to c2" => treated as "c2")
327
 
          ovl.collectConvFunctions (c1);
 
326
          // classes that are visible in c1 and yield a type whose 
 
327
          // cv-unqualified version is the same type as c2 or is a 
 
328
          // derived class thereof (including functions returning 
 
329
          // "reference to c2" => treated as "c2")
 
330
          ovl.collectConvFunctions (c1);
328
331
          ovl.ObjectType (arg);
329
 
          for (unsigned i = ovl.Candidates (); i > 0; i--) {
330
 
            ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
331
 
            if (! (*param->UnqualType () == *ctype->VirtualType () ||
332
 
                   (ctype->isClass () && baseClass (param, ctype)))) 
333
 
              ovl.removeCandidate (i-1);
334
 
          }
 
332
          for (unsigned i = ovl.Candidates (); i > 0; i--) {
 
333
            ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
 
334
            if (! (*param->UnqualType () == *ctype->VirtualType () ||
 
335
                   (ctype->isClass () && baseClass (param, ctype)))) 
 
336
              ovl.removeCandidate (i-1);
 
337
          }
335
338
        }
336
339
        // candidates are converting constructors of c2
337
340
        ovl.collectConstructors (c2);
340
343
        if (isValidConversion (arg_expr, ptype, atype, ovl)) {
341
344
          seq = new CCUserDefinedConvSeq;
342
345
          // 1. initial standard conversion sequence (need not to 
343
 
          // be correct, not relevant to the algorithm at all)
 
346
          // be correct, not relevant to the algorithm at all)
344
347
          seq->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
345
 
          // 2. user-defined conversion
346
 
          seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
347
 
          // 3. second standard conversion sequence
348
 
          seq2 = new CCStandardConvSeq;
 
348
          // 2. user-defined conversion
 
349
          seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
 
350
          // 3. second standard conversion sequence
 
351
          seq2 = new CCStandardConvSeq;
349
352
          if (! ovl.Function ()->isConstructor () &&
350
 
              baseClass (param, ovl.Function ()->ConversionType ()))
351
 
            seq2->addConversion (new CCDerivedToBaseConv (param, 
352
 
                                 ovl.Function ()->ConversionType (), arg_expr, base));
 
353
              baseClass (param, ovl.Function ()->ConversionType ()))
 
354
            seq2->addConversion (new CCDerivedToBaseConv (param, 
 
355
                                 ovl.Function ()->ConversionType (), arg_expr, base));
353
356
          else 
354
357
            seq2->addConversion (new CCIdentityConv (param, 
355
 
                                 ovl.Function ()->ConversionType (), arg_expr, base));
356
 
          seq->addConversion (seq2);
 
358
                                 ovl.Function ()->ConversionType (), arg_expr, base));
 
359
          seq->addConversion (seq2);
357
360
        }
358
361
      }
359
362
    }
436
439
      ovl.collectConvFunctions (c);
437
440
      for (unsigned i = ovl.Candidates (); i > 0; i--) {
438
441
        ctype = ovl.Candidate (i-1)->Function ()->ConversionType ();
439
 
        if (! ctype->isAddress () || 
440
 
            ! referenceCompatible (param, ctype->UnqualType ()->BaseType ()))
 
442
        if (! ctype->isAddress () || 
 
443
            ! referenceCompatible (param, ctype->UnqualType ()->BaseType ()))
441
444
          ovl.removeCandidate (i-1);
442
445
      }
443
446
      // select the best conversion function
450
453
        // 2. user-defined conversion
451
454
        seq->addConversion (new CCUserDefinedConv (param, arg, ovl.Function (), arg_expr, base));
452
455
        // 3. second standard conversion sequence
453
 
        seq2 = new CCStandardConvSeq;
454
 
        ctype = ovl.Function ()->ConversionType ();
 
456
        seq2 = new CCStandardConvSeq;
 
457
        ctype = ovl.Function ()->ConversionType ();
455
458
        if (param->isClass () && ctype->isClass () && baseClass (param, ctype))
456
459
          seq2->addConversion (new CCDerivedToBaseConv (param, ctype, arg_expr, base));
457
460
        else
458
461
          seq2->addConversion (new CCIdentityConv (param, ctype, arg_expr, base));
459
 
        seq2->isReferenceBinding (true);
 
462
        seq2->isReferenceBinding (true);
460
463
        seq->addConversion (seq2);
461
464
        conv = true;
462
465
      }
469
472
          referenceCompatible (param, arg)) {
470
473
        seq = new CCStandardConvSeq;
471
474
        // �13.3.3.1.4.2 not really clear which kind of conversion
472
 
        // this is; is it right to distinguish like above?
 
475
        // this is; is it right to distinguish like above?
473
476
        if ((param->isClass () && arg->isClass () && baseClass (param, arg)))
474
477
          seq->addConversion (new CCDerivedToBaseConv (param, arg, arg_expr, base));
475
478
        else
476
479
          seq->addConversion (new CCIdentityConv (param, arg, arg_expr, base));
477
480
      // �13.3.3.1.4.2 reference not bound directly to argument expression
478
481
      } else if (! (referenceRelated (param, arg) && 
479
 
                    ! equalOrMoreQualified (param, arg))) {
 
482
                    ! equalOrMoreQualified (param, arg))) {
480
483
        // 1. create temporary of underlying parameter type
481
 
        // 2. non-reference copy-initialization of temporary
 
484
        // 2. non-reference copy-initialization of temporary
482
485
        // 3. temporary is bound to reference
483
 
        seq = implicitConversions (param, arg, arg_expr, base, user_def);
 
486
        seq = implicitConversions (param, arg, arg_expr, base, user_def);
484
487
      }
485
488
    }
486
489
  }
561
564
    while (true) {
562
565
      if ((p1->isMemberPointer () && ! p2->isMemberPointer ()) ||
563
566
          (p2->isMemberPointer () && ! p1->isMemberPointer ()))
564
 
        break;
 
567
        break;
565
568
      if (p1->isMemberPointer () && 
566
569
          p1->TypeMemberPointer ()->Record () &&
567
 
          p2->TypeMemberPointer ()->Record () &&
 
570
          p2->TypeMemberPointer ()->Record () &&
568
571
          ! (*p1->TypeMemberPointer ()->Record () ==
569
572
             *p2->TypeMemberPointer ()->Record ()))
570
573
        break;
572
575
      p2 = p2->BaseType ();
573
576
      if ((p1->UnqualType ()->isPointer () && ! p2->UnqualType ()->isPointer ()) ||
574
577
          (p2->UnqualType ()->isPointer () && ! p1->UnqualType ()->isPointer ()))
575
 
        break;
 
578
        break;
576
579
 
577
580
      if (p1->isQualified () && ! p2->isQualified ())
578
581
        break;
579
582
      if (p1->isQualified ()) { // => p2->isQualified ()
580
583
        if ((p1->isVolatile () && ! p2->isVolatile ()) ||
581
 
            (p1->isConst () && ! p2->isConst ()))
582
 
          break;
583
 
        if (((p1->isVolatile ()?1:0)+(p1->isConst ()?2:0)) !=
584
 
            ((p2->isVolatile ()?1:0)+(p2->isConst ()?2:0)) &&
585
 
            ! all_const)
586
 
          break;
 
584
            (p1->isConst () && ! p2->isConst ()))
 
585
          break;
 
586
        if (((p1->isVolatile ()?1:0)+(p1->isConst ()?2:0)) !=
 
587
            ((p2->isVolatile ()?1:0)+(p2->isConst ()?2:0)) &&
 
588
            ! all_const)
 
589
          break;
587
590
      } else if (p2->isQualified () && ! all_const)
588
591
        break;
589
592
      if (! p2->isQualified () || ! p2->isConst ())
591
594
 
592
595
      if (! p1->UnqualType ()->isPointer ()) {
593
596
        if (*p1->UnqualType () == *p2->UnqualType ())
594
 
          // types are similar
595
 
          return true;
596
 
        break;
 
597
          // types are similar
 
598
          return true;
 
599
        break;
597
600
      }
598
601
      
599
602
      if (p1->isQualified ())
672
675
    c1 = seq1->Conversion (seq1->Conversions ()-1);
673
676
    c2 = seq2->Conversion (seq2->Conversions ()-1);
674
677
    if (c1->isQualificationConv () || c2->isQualificationConv ()) {
675
 
      v1 = similarTypes (c1->ToType (), c2->ToType ());
676
 
      v2 = similarTypes (c2->ToType (), c1->ToType ());
 
678
      v1 = similarTypes (c2->ToType (), c1->ToType ());  // c1 similar to c2?
 
679
      v2 = similarTypes (c1->ToType (), c2->ToType ());  // c2 similar to c1?
677
680
      if (v1 && ! v2)
678
681
        return 1;
679
682
      if (v2 && ! v1)
690
693
      c2 = seq2->Conversion (0);
691
694
      if (*c1->ToType ()->UnqualType () == 
692
695
          *c2->ToType ()->UnqualType ()) {
693
 
        v1 = equalOrMoreQualified (c1->ToType (), c2->ToType ());
694
 
        v2 = equalOrMoreQualified (c2->ToType (), c1->ToType ());
695
 
        if (! v1 && v2)
696
 
          return 1;
697
 
        if (! v2 && v1)
698
 
          return -1;
 
696
        v1 = equalOrMoreQualified (c1->ToType (), c2->ToType ());
 
697
        v2 = equalOrMoreQualified (c2->ToType (), c1->ToType ());
 
698
        if (! v1 && v2)
 
699
          return 1;
 
700
        if (! v2 && v1)
 
701
          return -1;
699
702
      }
700
703
    }
701
704
  } else if (seq1->isUserDefinedConvSeq ()) { // => seq2->isUserDefinedConvSeq ()
726
729
      promo = true;
727
730
    else if (c->isFloatingPointConv () || c->isIntegralConv () ||
728
731
             c->isFloatingIntegralConv () || c->isPointerConv () ||
729
 
             c->isPointerToMemberConv () || c->isBooleanConv () ||
730
 
             c->isDerivedToBaseConv ())
 
732
             c->isPointerToMemberConv () || c->isBooleanConv () ||
 
733
             c->isDerivedToBaseConv ())
731
734
      conv = true;
732
735
  }
733
736
 
887
890
      for (unsigned k = j; k < num_conv2; k++) {
888
891
        // subsequence of seq2 is longer than subsequence of seq1
889
892
        if ((num_conv2-k) > (num_conv1-i))
890
 
          continue;
891
 
        
892
 
        // subsequence of seq2 is shorter than subsequence of seq1
893
 
        // so it cannot be a proper subsequence of seq2
 
893
          continue;
 
894
        
 
895
        // subsequence of seq2 is shorter than subsequence of seq1
 
896
        // so it cannot be a proper subsequence of seq2
894
897
        if ((num_conv2-k) < (num_conv1-i))
895
 
          return false;
896
 
          
 
898
          return false;
 
899
          
897
900
        // compare seq1 with the remainder of seq2; must be equal
898
901
        for (unsigned l = k; l < num_conv2; l++) {
899
902
          c2 = seq2->Conversion (l);
900
 
        
901
 
          // not the same type of conversion 
902
 
          if (c1->Id () != c2->Id ())
903
 
            return false;
904
 
        
905
 
          // same type of conversions; but also same parameter
906
 
          // and argument types?
 
903
        
 
904
          // not the same type of conversion 
 
905
          if (c1->Id () != c2->Id ())
 
906
            return false;
 
907
        
 
908
          // same type of conversions; but also same parameter
 
909
          // and argument types?
907
910
          if (*c1->FromType () != *c2->FromType () ||
908
 
              *c1->ToType () != *c2->ToType ())
909
 
            return false;
910
 
        }       
911
 
        return true;
 
911
              *c1->ToType () != *c2->ToType ())
 
912
            return false;
 
913
        }        
 
914
        return true;
912
915
      }
913
916
      return false;
914
917
    }