Annotation of gcc/cp-call.c, revision 1.1.1.5

1.1       root        1: /* Functions related to invoking methods and overloaded functions.
1.1.1.5 ! root        2:    Copyright (C) 1987, 1992, 1993 Free Software Foundation, Inc.
1.1       root        3:    Contributed by Michael Tiemann ([email protected])
                      4: 
                      5: This file is part of GNU CC.
                      6: 
                      7: GNU CC is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU General Public License as published by
                      9: the Free Software Foundation; either version 2, or (at your option)
                     10: any later version.
                     11: 
                     12: GNU CC is distributed in the hope that it will be useful,
                     13: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: GNU General Public License for more details.
                     16: 
                     17: You should have received a copy of the GNU General Public License
                     18: along with GNU CC; see the file COPYING.  If not, write to
                     19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     20: 
                     21: 
                     22: /* High-level class interface. */
                     23: 
                     24: #include "config.h"
                     25: #include "tree.h"
                     26: #include <stdio.h>
                     27: #include "cp-tree.h"
                     28: #include "flags.h"
                     29: 
                     30: #include "obstack.h"
                     31: #define obstack_chunk_alloc xmalloc
                     32: #define obstack_chunk_free free
                     33: 
1.1.1.2   root       34: extern void sorry ();
                     35: 
                     36: extern int inhibit_warnings;
                     37: extern int flag_assume_nonnull_objects;
                     38: extern tree ctor_label, dtor_label;
1.1       root       39: 
1.1.1.2   root       40: /* From cp-typeck.c:  */
                     41: extern tree unary_complex_lvalue ();
                     42: 
1.1       root       43: /* Compute the ease with which a conversion can be performed
                     44:    between an expected and the given type.  */
                     45: static int convert_harshness ();
                     46: 
                     47: #define EVIL_HARSHNESS(ARG) ((ARG) & 1)
1.1.1.5 ! root       48: #define ELLIPSIS_HARSHNESS(ARG) ((ARG) & 2)
        !            49: #define USER_HARSHNESS(ARG) ((ARG) & 4)
        !            50: #define CONTRAVARIANT_HARSHNESS(ARG) ((ARG) & 8)
        !            51: #define BASE_DERIVED_HARSHNESS(ARG) ((ARG) & 16)
        !            52: #define INT_TO_BD_HARSHNESS(ARG) (((ARG) << 5) | 16)
        !            53: #define INT_FROM_BD_HARSHNESS(ARG) ((ARG) >> 5)
        !            54: #define INT_TO_EASY_HARSHNESS(ARG) ((ARG) << 5)
        !            55: #define INT_FROM_EASY_HARSHNESS(ARG) ((ARG) >> 5)
        !            56: #define ONLY_EASY_HARSHNESS(ARG) (((ARG) & 31) == 0)
        !            57: #define CONST_HARSHNESS(ARG) ((ARG) & 2048)
1.1       root       58: 
                     59: /* Ordering function for overload resolution.  */
                     60: int
                     61: rank_for_overload (x, y)
                     62:      struct candidate *x, *y;
                     63: {
                     64:   if (y->evil - x->evil)
                     65:     return y->evil - x->evil;
                     66:   if (CONST_HARSHNESS (y->harshness[0]) ^ CONST_HARSHNESS (x->harshness[0]))
                     67:     return y->harshness[0] - x->harshness[0];
1.1.1.5 ! root       68:   if (y->ellipsis - x->ellipsis)
        !            69:     return y->ellipsis - x->ellipsis;
1.1       root       70:   if (y->user - x->user)
                     71:     return y->user - x->user;
                     72:   if (y->b_or_d - x->b_or_d)
                     73:     return y->b_or_d - x->b_or_d;
                     74:   return y->easy - x->easy;
                     75: }
                     76: 
                     77: /* TYPE is the type we wish to convert to.  PARM is the parameter
                     78:    we have to work with.  We use a somewhat arbitrary cost function
                     79:    to measure this conversion.  */
                     80: static int
                     81: convert_harshness (type, parmtype, parm)
                     82:      register tree type, parmtype;
                     83:      tree parm;
                     84: {
                     85:   register enum tree_code codel = TREE_CODE (type);
                     86:   register enum tree_code coder = TREE_CODE (parmtype);
                     87: 
                     88: #ifdef GATHER_STATISTICS
                     89:   n_convert_harshness++;
                     90: #endif
                     91: 
                     92:   if (TYPE_MAIN_VARIANT (parmtype) == TYPE_MAIN_VARIANT (type))
                     93:     return 0;
                     94: 
                     95:   if (coder == ERROR_MARK)
                     96:     return 1;
                     97: 
                     98:   if (codel == POINTER_TYPE
                     99:       && (coder == METHOD_TYPE || coder == FUNCTION_TYPE))
                    100:     {
                    101:       tree p1, p2;
                    102:       int harshness, new_harshness;
                    103: 
                    104:       /* Get to the METHOD_TYPE or FUNCTION_TYPE that this might be.  */
                    105:       type = TREE_TYPE (type);
                    106: 
                    107:       if (coder != TREE_CODE (type))
                    108:        return 1;
                    109: 
                    110:       harshness = 0;
                    111: 
                    112:       /* We allow the default conversion between function type
                    113:         and pointer-to-function type for free.  */
                    114:       if (type == parmtype)
                    115:        return 0;
                    116: 
                    117:       /* Compare return types.  */
                    118:       p1 = TREE_TYPE (type);
                    119:       p2 = TREE_TYPE (parmtype);
1.1.1.5 ! root      120:       new_harshness = convert_harshness (p1, p2, NULL_TREE);
1.1       root      121:       if (new_harshness & 1)
                    122:        return 1;
                    123: 
                    124:       if (BASE_DERIVED_HARSHNESS (new_harshness))
                    125:        {
                    126:          tree binfo;
                    127: 
                    128:          /* This only works for pointers.  */
                    129:          if (TREE_CODE (p1) != POINTER_TYPE
                    130:              && TREE_CODE (p1) != REFERENCE_TYPE)
                    131:            return 1;
                    132: 
                    133:          p1 = TREE_TYPE (p1);
                    134:          p2 = TREE_TYPE (p2);
                    135:          if (CONTRAVARIANT_HARSHNESS (new_harshness))
                    136:            binfo = get_binfo (p2, p1, 0);
                    137:          else
                    138:            binfo = get_binfo (p1, p2, 0);
                    139: 
                    140:          if (! BINFO_OFFSET_ZEROP (binfo))
                    141:            {
1.1.1.5 ! root      142:              static int explained = 0;
1.1       root      143:              if (CONTRAVARIANT_HARSHNESS (new_harshness))
                    144:                message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p2, p1);
                    145:              else
                    146:                message_2_types (sorry, "cannot cast `%d' to `%d' at function call site", p1, p2);
                    147: 
                    148:              if (! explained++)
                    149:                sorry ("(because pointer values change during conversion)");
                    150:              return 1;
                    151:            }
                    152:        }
                    153: 
                    154:       harshness |= new_harshness;
                    155: 
                    156:       p1 = TYPE_ARG_TYPES (type);
                    157:       p2 = TYPE_ARG_TYPES (parmtype);
1.1.1.5 ! root      158:       while (p1 && TREE_VALUE (p1) != void_type_node
        !           159:             && p2 && TREE_VALUE (p2) != void_type_node)
1.1       root      160:        {
1.1.1.5 ! root      161:          new_harshness = convert_harshness (TREE_VALUE (p1), TREE_VALUE (p2), NULL_TREE);
1.1       root      162:          if (EVIL_HARSHNESS (new_harshness))
                    163:            return 1;
                    164: 
                    165:          if (BASE_DERIVED_HARSHNESS (new_harshness))
                    166:            {
                    167:              /* This only works for pointers and references. */
                    168:              if (TREE_CODE (TREE_VALUE (p1)) != POINTER_TYPE
                    169:                  && TREE_CODE (TREE_VALUE (p1)) != REFERENCE_TYPE)
                    170:                return 1;
                    171:              new_harshness ^= CONTRAVARIANT_HARSHNESS (new_harshness);
                    172:              harshness |= new_harshness;
                    173:            }
                    174:          /* This trick allows use to accumulate easy type
                    175:             conversions without messing up the bits that encode
                    176:             info about more involved things.  */
                    177:          else if (ONLY_EASY_HARSHNESS (new_harshness))
                    178:            harshness += new_harshness;
                    179:          else
                    180:            harshness |= new_harshness;
                    181:          p1 = TREE_CHAIN (p1);
                    182:          p2 = TREE_CHAIN (p2);
                    183:        }
                    184:       if (p1 == p2)
                    185:        return harshness;
                    186:       if (p2)
1.1.1.5 ! root      187:        return p1 ? 1 : (harshness | ELLIPSIS_HARSHNESS (-1));
1.1       root      188:       if (p1)
                    189:        return harshness | (TREE_PURPOSE (p1) == NULL_TREE);
                    190:     }
                    191:   else if (codel == POINTER_TYPE && coder == OFFSET_TYPE)
                    192:     {
1.1.1.5 ! root      193:       /* XXX: Note this is set a few times, but it's never actually
        !           194:         used! (bpk) */
1.1       root      195:       int harshness;
                    196: 
                    197:       /* Get to the OFFSET_TYPE that this might be.  */
                    198:       type = TREE_TYPE (type);
                    199: 
                    200:       if (coder != TREE_CODE (type))
                    201:        return 1;
                    202: 
                    203:       harshness = 0;
                    204: 
                    205:       if (TYPE_OFFSET_BASETYPE (type) == TYPE_OFFSET_BASETYPE (parmtype))
                    206:        harshness = 0;
1.1.1.4   root      207:       else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (type),
1.1       root      208:                               TYPE_OFFSET_BASETYPE (parmtype)))
                    209:        harshness = INT_TO_BD_HARSHNESS (1);
1.1.1.4   root      210:       else if (UNIQUELY_DERIVED_FROM_P (TYPE_OFFSET_BASETYPE (parmtype),
1.1       root      211:                               TYPE_OFFSET_BASETYPE (type)))
                    212:        harshness = CONTRAVARIANT_HARSHNESS (-1);
                    213:       else
                    214:        return 1;
1.1.1.2   root      215:       /* Now test the OFFSET_TYPE's target compatibility.  */
1.1       root      216:       type = TREE_TYPE (type);
                    217:       parmtype = TREE_TYPE (parmtype);
                    218:     }
                    219: 
                    220:   if (coder == UNKNOWN_TYPE)
                    221:     {
                    222:       if (codel == FUNCTION_TYPE
                    223:          || codel == METHOD_TYPE
                    224:          || (codel == POINTER_TYPE
                    225:              && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
                    226:                  || TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)))
                    227:        return 0;
                    228:       return 1;
                    229:     }
                    230: 
                    231:   if (coder == VOID_TYPE)
                    232:     return 1;
                    233: 
                    234:   if (codel == ENUMERAL_TYPE || codel == INTEGER_TYPE)
                    235:     {
                    236:       /* Control equivalence of ints an enums.  */
                    237: 
                    238:       if (codel == ENUMERAL_TYPE
                    239:          && flag_int_enum_equivalence == 0)
                    240:        {
                    241:          /* Enums can be converted to ints, but not vice-versa.  */
                    242:          if (coder != ENUMERAL_TYPE
                    243:              || TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (parmtype))
                    244:            return 1;
                    245:        }
                    246: 
                    247:       /* else enums and ints (almost) freely interconvert.  */
                    248: 
                    249:       if (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE)
                    250:        {
                    251:          int easy = TREE_UNSIGNED (type) ^ TREE_UNSIGNED (parmtype);
                    252:          if (codel != coder)
                    253:            easy += 1;
                    254:          if (TYPE_MODE (type) != TYPE_MODE (parmtype))
                    255:            easy += 2;
                    256:          return INT_TO_EASY_HARSHNESS (easy);
                    257:        }
                    258:       else if (coder == REAL_TYPE)
                    259:        return INT_TO_EASY_HARSHNESS (4);
                    260:     }
                    261: 
                    262:   if (codel == REAL_TYPE)
                    263:     if (coder == REAL_TYPE)
                    264:       /* Shun converting between float and double if a choice exists.  */
                    265:       {
                    266:        if (TYPE_MODE (type) != TYPE_MODE (parmtype))
                    267:          return INT_TO_EASY_HARSHNESS (2);
                    268:        return 0;
                    269:       }
                    270:     else if (coder == INTEGER_TYPE || coder == ENUMERAL_TYPE)
                    271:       return INT_TO_EASY_HARSHNESS (4);
                    272: 
                    273:   /* convert arrays which have not previously been converted.  */
                    274:   if (codel == ARRAY_TYPE)
                    275:     codel = POINTER_TYPE;
                    276:   if (coder == ARRAY_TYPE)
                    277:     coder = POINTER_TYPE;
                    278: 
                    279:   /* Conversions among pointers */
                    280:   if (codel == POINTER_TYPE && coder == POINTER_TYPE)
                    281:     {
                    282:       register tree ttl = TYPE_MAIN_VARIANT (TREE_TYPE (type));
                    283:       register tree ttr = TYPE_MAIN_VARIANT (TREE_TYPE (parmtype));
                    284:       int penalty = 4 * (ttl != ttr);
                    285:       /* Anything converts to void *.  void * converts to anything.
                    286:         Since these may be `const void *' (etc.) use VOID_TYPE
                    287:         instead of void_type_node.
                    288:         Otherwise, the targets must be the same,
                    289:         except that we do allow (at some cost) conversion
                    290:         between signed and unsinged pointer types.  */
                    291: 
                    292:       if ((TREE_CODE (ttl) == METHOD_TYPE
                    293:           || TREE_CODE (ttl) == FUNCTION_TYPE)
                    294:          && TREE_CODE (ttl) == TREE_CODE (ttr))
                    295:        {
                    296:          if (comptypes (ttl, ttr, -1))
                    297:            return INT_TO_EASY_HARSHNESS (penalty);
                    298:          return 1;
                    299:        }
                    300: 
                    301:       if (!(TREE_CODE (ttl) == VOID_TYPE
                    302:            || TREE_CODE (ttr) == VOID_TYPE
                    303:            || (TREE_UNSIGNED (ttl) ^ TREE_UNSIGNED (ttr)
                    304:                && (ttl = unsigned_type (ttl),
                    305:                    ttr = unsigned_type (ttr),
                    306:                    penalty = 10, 0))
                    307:            || (comp_target_types (ttl, ttr, 0))))
                    308:        return 1;
                    309: 
                    310:       if (penalty == 10)
                    311:        return INT_TO_EASY_HARSHNESS (10);
                    312:       if (ttr == ttl)
                    313:        return INT_TO_BD_HARSHNESS (0);
                    314: 
1.1.1.2   root      315:       if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
1.1       root      316:        {
                    317:          int b_or_d = get_base_distance (ttl, ttr, 0, 0);
                    318:          if (b_or_d < 0)
                    319:            {
                    320:              b_or_d = get_base_distance (ttr, ttl, 0, 0);
                    321:              if (b_or_d < 0)
                    322:                return 1;
                    323:              return CONTRAVARIANT_HARSHNESS (-1);
                    324:            }
                    325:          return INT_TO_BD_HARSHNESS (b_or_d);
                    326:        }
                    327:       /* If converting from a `class*' to a `void*', make it
                    328:         less favorable than any inheritance relationship.  */
                    329:       if (TREE_CODE (ttl) == VOID_TYPE && IS_AGGR_TYPE (ttr))
                    330:        return INT_TO_BD_HARSHNESS (CLASSTYPE_MAX_DEPTH (ttr)+1);
                    331:       return INT_TO_EASY_HARSHNESS (penalty);
                    332:     }
                    333: 
                    334:   if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
                    335:     {
                    336:       /* This is not a bad match, but don't let it beat
                    337:         integer-enum combinations.  */
                    338:       if (parm && integer_zerop (parm))
                    339:        return INT_TO_EASY_HARSHNESS (4);
                    340:     }
                    341: 
                    342:   /* C++: one of the types must be a reference type.  */
                    343:   {
                    344:     tree ttl, ttr;
                    345:     register tree intype = TYPE_MAIN_VARIANT (parmtype);
                    346:     register enum tree_code form = TREE_CODE (intype);
                    347:     int penalty;
                    348: 
                    349:     if (codel == REFERENCE_TYPE || coder == REFERENCE_TYPE)
                    350:       {
                    351:        ttl = TYPE_MAIN_VARIANT (type);
                    352: 
                    353:        if (codel == REFERENCE_TYPE)
                    354:          {
1.1.1.4   root      355:            ttl = TREE_TYPE (ttl);
                    356: 
                    357:            /* When passing a non-const argument into a const reference,
                    358:               dig it a little, so a non-const reference is preferred over
                    359:               this one. (mrs) */
1.1.1.5 ! root      360:            if (parm && TREE_READONLY (ttl) && ! TREE_READONLY (parm))
1.1.1.4   root      361:              penalty = 2;
                    362:            else
                    363:              penalty = 0;
                    364: 
                    365:            ttl = TYPE_MAIN_VARIANT (ttl);
1.1       root      366: 
                    367:            if (form == OFFSET_TYPE)
                    368:              {
                    369:                intype = TREE_TYPE (intype);
                    370:                form = TREE_CODE (intype);
                    371:              }
                    372: 
                    373:            if (form == REFERENCE_TYPE)
                    374:              {
                    375:                intype = TYPE_MAIN_VARIANT (TREE_TYPE (intype));
                    376: 
                    377:                if (ttl == intype)
                    378:                  return 0;
                    379:                penalty = 2;
                    380:              }
                    381:            else
                    382:              {
                    383:                /* Can reference be built up?  */
1.1.1.4   root      384:                if (ttl == intype && penalty == 0) {
1.1.1.5 ! root      385:                  /* Because the READONLY bits and VOLATILE bits are not
        !           386:                     always in the type, this extra check is necessary.  The
        !           387:                     problem should be fixed someplace else, and this extra
        !           388:                     code removed.
1.1.1.4   root      389: 
                    390:                     Also, if type if a reference, the readonly bits could
                    391:                     either be in the outer type (with reference) or on the
                    392:                     inner type (the thing being referenced).  (mrs)  */
1.1.1.5 ! root      393:                  if (parm
        !           394:                      && ((TREE_READONLY (parm)
        !           395:                          && ! (TYPE_READONLY (type)
        !           396:                                || (TREE_CODE (type) == REFERENCE_TYPE
        !           397:                                    && TYPE_READONLY (TREE_TYPE (type)))))
        !           398:                          || (TREE_SIDE_EFFECTS (parm)
        !           399:                              && ! (TYPE_VOLATILE (type)
        !           400:                                    || (TREE_CODE (type) == REFERENCE_TYPE
        !           401:                                        && TYPE_VOLATILE (TREE_TYPE (type)))))))
        !           402:                     
1.1.1.4   root      403:                    penalty = 2;
                    404:                  else
                    405:                    return 0;
                    406:                }
1.1       root      407:                else
                    408:                  penalty = 2;
                    409:              }
                    410:          }
                    411:        else if (form == REFERENCE_TYPE)
                    412:          {
                    413:            if (parm)
                    414:              {
                    415:                tree tmp = convert_from_reference (parm);
                    416:                intype = TYPE_MAIN_VARIANT (TREE_TYPE (tmp));
                    417:              }
                    418:            else
                    419:              {
                    420:                intype = parmtype;
                    421:                do
                    422:                  {
                    423:                    intype = TREE_TYPE (intype);
                    424:                  }
                    425:                while (TREE_CODE (intype) == REFERENCE_TYPE);
                    426:                intype = TYPE_MAIN_VARIANT (intype);
                    427:              }
                    428: 
                    429:            if (ttl == intype)
                    430:              return 0;
                    431:            else
                    432:              penalty = 2;
                    433:          }
                    434: 
                    435:        if (TREE_UNSIGNED (ttl) ^ TREE_UNSIGNED (intype))
                    436:          {
                    437:            ttl = unsigned_type (ttl);
                    438:            intype = unsigned_type (intype);
                    439:            penalty += 2;
                    440:          }
                    441: 
                    442:        ttr = intype;
                    443: 
                    444:        /* If the initializer is not an lvalue, then it does not
                    445:           matter if we make life easier for the programmer
                    446:           by creating a temporary variable with which to
                    447:           hold the result.  */
                    448:        if (parm && (coder == INTEGER_TYPE
                    449:                     || coder == ENUMERAL_TYPE
                    450:                     || coder == REAL_TYPE)
                    451:            && ! lvalue_p (parm))
1.1.1.5 ! root      452:          return (convert_harshness (ttl, ttr, NULL_TREE)
1.1       root      453:                  | INT_TO_EASY_HARSHNESS (penalty));
                    454: 
                    455:        if (ttl == ttr)
                    456:          {
                    457:            if (penalty)
                    458:              return INT_TO_EASY_HARSHNESS (penalty);
                    459:            return INT_TO_BD_HARSHNESS (0);
                    460:          }
                    461: 
                    462:        /* Pointers to voids always convert for pointers.  But
                    463:           make them less natural than more specific matches.  */
                    464:        if (TREE_CODE (ttl) == POINTER_TYPE && TREE_CODE (ttr) == POINTER_TYPE)
                    465:          if (TREE_TYPE (ttl) == void_type_node
                    466:              || TREE_TYPE (ttr) == void_type_node)
                    467:            return INT_TO_EASY_HARSHNESS (penalty+1);
                    468: 
                    469:        if (parm && codel != REFERENCE_TYPE)
1.1.1.5 ! root      470:          return (convert_harshness (ttl, ttr, NULL_TREE)
1.1       root      471:                  | INT_TO_EASY_HARSHNESS (penalty));
                    472: 
                    473:        /* Here it does matter.  If this conversion is from
                    474:           derived to base, allow it.  Otherwise, types must
                    475:           be compatible in the strong sense.  */
1.1.1.2   root      476:        if (TREE_CODE (ttl) == RECORD_TYPE && TREE_CODE (ttr) == RECORD_TYPE)
1.1       root      477:          {
                    478:            int b_or_d = get_base_distance (ttl, ttr, 0, 0);
                    479:            if (b_or_d < 0)
                    480:              {
                    481:                b_or_d = get_base_distance (ttr, ttl, 0, 0);
                    482:                if (b_or_d < 0)
                    483:                  return 1;
                    484:                return CONTRAVARIANT_HARSHNESS (-1);
                    485:              }
                    486:            /* Say that this conversion is relatively painless.
                    487:               If it turns out that there is a user-defined X(X&)
                    488:               constructor, then that will be invoked, but that's
                    489:               preferable to dealing with other user-defined conversions
                    490:               that may produce surprising results.  */
                    491:            return INT_TO_BD_HARSHNESS (b_or_d);
                    492:          }
                    493: 
                    494:        if (comp_target_types (ttl, intype, 1))
                    495:          return INT_TO_EASY_HARSHNESS (penalty);
                    496:       }
                    497:   }
                    498:   if (codel == RECORD_TYPE && coder == RECORD_TYPE)
                    499:     {
                    500:       int b_or_d = get_base_distance (type, parmtype, 0, 0);
                    501:       if (b_or_d < 0)
                    502:        {
                    503:          b_or_d = get_base_distance (parmtype, type, 0, 0);
                    504:          if (b_or_d < 0)
                    505:            return 1;
                    506:          return CONTRAVARIANT_HARSHNESS (-1);
                    507:        }
                    508:       return INT_TO_BD_HARSHNESS (b_or_d);
                    509:     }
                    510:   return 1;
                    511: }
                    512: 
1.1.1.2   root      513: /* Algorithm: Start out with no strikes against.  For each argument
1.1       root      514:    which requires a (subjective) hard conversion (such as between
                    515:    floating point and integer), issue a strike.  If there are the same
                    516:    number of formal and actual parameters in the list, there will be at
                    517:    least on strike, otherwise an exact match would have been found.  If
                    518:    there are not the same number of arguments in the type lists, we are
                    519:    not dead yet: a `...' means that we can have more parms then were
                    520:    declared, and if we wind up in the default argument section of the
                    521:    list those can be used as well.  If an exact match could be found for
                    522:    one of those cases, return it immediately.  Otherwise, rank the fields
                    523:    so that fields with fewer strikes are tried first.
                    524: 
                    525:    Conversions between builtin and user-defined types are allowed, but
1.1.1.2   root      526:    no function involving such a conversion is preferred to one which
1.1       root      527:    does not require such a conversion.  Furthermore, such conversions
                    528:    must be unique.  */
                    529: 
                    530: void
                    531: compute_conversion_costs (function, tta_in, cp, arglen)
                    532:      tree function;
                    533:      tree tta_in;
                    534:      struct candidate *cp;
                    535:      int arglen;
                    536: {
                    537:   tree ttf_in = TYPE_ARG_TYPES (TREE_TYPE (function));
                    538:   tree ttf = ttf_in;
                    539:   tree tta = tta_in;
                    540: 
                    541:   /* Start out with no strikes against.  */
                    542:   int evil_strikes = 0;
1.1.1.5 ! root      543:   int ellipsis_strikes = 0;
1.1       root      544:   int user_strikes = 0;
                    545:   int b_or_d_strikes = 0;
                    546:   int easy_strikes = 0;
                    547: 
                    548:   int strike_index = 0, win, lose;
                    549: 
                    550: #ifdef GATHER_STATISTICS
                    551:   n_compute_conversion_costs++;
                    552: #endif
                    553: 
                    554:   cp->function = function;
                    555:   cp->arg = tta ? TREE_VALUE (tta) : NULL_TREE;
                    556:   cp->u.bad_arg = 0;           /* optimistic!  */
                    557: 
                    558:   bzero (cp->harshness, (arglen+1) * sizeof (short));
                    559: 
                    560:   while (ttf && tta)
                    561:     {
                    562:       int harshness;
                    563: 
                    564:       if (ttf == void_list_node)
                    565:        break;
                    566: 
                    567:       if (type_unknown_p (TREE_VALUE (tta)))
                    568:        {         
                    569:          /* Must perform some instantiation here.  */
                    570:          tree rhs = TREE_VALUE (tta);
                    571:          tree lhstype = TREE_VALUE (ttf);
                    572: 
                    573:          /* Keep quiet about possible contravariance violations.  */
                    574:          int old_inhibit_warnings = inhibit_warnings;
                    575:          inhibit_warnings = 1;
                    576: 
                    577:          /* @@ This is to undo what `grokdeclarator' does to
                    578:             parameter types.  It really should go through
                    579:             something more general.  */
                    580: 
                    581:          TREE_TYPE (tta) = unknown_type_node;
                    582:          rhs = instantiate_type (lhstype, rhs, 0);
                    583:          inhibit_warnings = old_inhibit_warnings;
                    584: 
                    585:          if (TREE_CODE (rhs) == ERROR_MARK)
                    586:            harshness = 1;
                    587:          else
                    588:            {
                    589:              harshness = convert_harshness (lhstype, TREE_TYPE (rhs), rhs);
                    590:              /* harshness |= 2; */
                    591:            }
                    592:        }
                    593:       else
                    594:        harshness = convert_harshness (TREE_VALUE (ttf), TREE_TYPE (TREE_VALUE (tta)), TREE_VALUE (tta));
                    595: 
                    596:       cp->harshness[strike_index] = harshness;
                    597:       if (EVIL_HARSHNESS (harshness)
                    598:          || CONTRAVARIANT_HARSHNESS (harshness))
                    599:        {
                    600:          cp->u.bad_arg = strike_index;
                    601:          evil_strikes = 1;
                    602:        }
1.1.1.5 ! root      603:      else if (ELLIPSIS_HARSHNESS (harshness))
        !           604:        {
        !           605:          ellipsis_strikes += 1;
        !           606:        }
1.1       root      607: #if 0
                    608:       /* This is never set by `convert_harshness'.  */
                    609:       else if (USER_HARSHNESS (harshness))
                    610:        {
                    611:          user_strikes += 1;
                    612:        }
                    613: #endif
                    614:       else if (BASE_DERIVED_HARSHNESS (harshness))
                    615:        {
                    616:          b_or_d_strikes += INT_FROM_BD_HARSHNESS (harshness);
                    617:        }
                    618:       else
                    619:        easy_strikes += INT_FROM_EASY_HARSHNESS (harshness);
                    620:       ttf = TREE_CHAIN (ttf);
                    621:       tta = TREE_CHAIN (tta);
                    622:       strike_index += 1;
                    623:     }
                    624: 
                    625:   if (tta)
                    626:     {
                    627:       /* ran out of formals, and parmlist is fixed size.  */
                    628:       if (ttf /* == void_type_node */)
                    629:        {
                    630:          cp->evil = 1;
                    631:          cp->u.bad_arg = -1;
                    632:          return;
                    633:        }
                    634:     }
                    635:   else if (ttf && ttf != void_list_node)
                    636:     {
                    637:       /* ran out of actuals, and no defaults.  */
                    638:       if (TREE_PURPOSE (ttf) == NULL_TREE)
                    639:        {
                    640:          cp->evil = 1;
                    641:          cp->u.bad_arg = -2;
                    642:          return;
                    643:        }
                    644:       /* Store index of first default.  */
                    645:       cp->harshness[arglen] = strike_index+1;
                    646:     }
                    647:   else cp->harshness[arglen] = 0;
                    648: 
                    649:   /* Argument list lengths work out, so don't need to check them again.  */
                    650:   if (evil_strikes)
                    651:     {
                    652:       /* We do not check for derived->base conversions here, since in
                    653:         no case would they give evil strike counts, unless such conversions
                    654:         are somehow ambiguous.  */
                    655: 
                    656:       /* See if any user-defined conversions apply.
                    657:          But make sure that we do not loop.  */
                    658:       static int dont_convert_types = 0;
                    659: 
                    660:       if (dont_convert_types)
                    661:        {
                    662:          cp->evil = 1;
                    663:          return;
                    664:        }
                    665: 
                    666:       win = 0;                 /* Only get one chance to win.  */
                    667:       ttf = TYPE_ARG_TYPES (TREE_TYPE (function));
                    668:       tta = tta_in;
                    669:       strike_index = 0;
                    670:       evil_strikes = 0;
                    671: 
                    672:       while (ttf && tta)
                    673:        {
                    674:          if (ttf == void_list_node)
                    675:            break;
                    676: 
                    677:          lose = cp->harshness[strike_index];
                    678:          if (EVIL_HARSHNESS (lose)
                    679:              || CONTRAVARIANT_HARSHNESS (lose))
                    680:            {
                    681:              tree actual_type = TREE_TYPE (TREE_VALUE (tta));
                    682:              tree formal_type = TREE_VALUE (ttf);
                    683: 
                    684:              dont_convert_types = 1;
                    685: 
                    686:              if (TREE_CODE (formal_type) == REFERENCE_TYPE)
                    687:                formal_type = TREE_TYPE (formal_type);
                    688:              if (TREE_CODE (actual_type) == REFERENCE_TYPE)
                    689:                actual_type = TREE_TYPE (actual_type);
                    690: 
                    691:              if (formal_type != error_mark_node
                    692:                  && actual_type != error_mark_node)
                    693:                {
                    694:                  formal_type = TYPE_MAIN_VARIANT (formal_type);
                    695:                  actual_type = TYPE_MAIN_VARIANT (actual_type);
                    696: 
                    697:                  if (TYPE_HAS_CONSTRUCTOR (formal_type))
                    698:                    {
                    699:                      /* If it has a constructor for this type, try to use it.  */
                    700:                      if (convert_to_aggr (formal_type, TREE_VALUE (tta), 0, 1)
                    701:                          != error_mark_node)
                    702:                        {
                    703:                          /* @@ There is no way to save this result yet.
                    704:                             @@ So success is NULL_TREE for now.  */
                    705:                          win++;
                    706:                        }
                    707:                    }
                    708:                  if (TYPE_LANG_SPECIFIC (actual_type) && TYPE_HAS_CONVERSION (actual_type))
                    709:                    {
                    710:                      if (TREE_CODE (formal_type) == INTEGER_TYPE
                    711:                          && TYPE_HAS_INT_CONVERSION (actual_type))
                    712:                        win++;
                    713:                      else if (TREE_CODE (formal_type) == REAL_TYPE
                    714:                               && TYPE_HAS_REAL_CONVERSION (actual_type))
                    715:                        win++;
                    716:                      else
                    717:                        {
                    718:                          tree conv = build_type_conversion (CALL_EXPR, TREE_VALUE (ttf), TREE_VALUE (tta), 0);
                    719:                          if (conv)
                    720:                            {
                    721:                              if (conv == error_mark_node)
                    722:                                win += 2;
                    723:                              else
                    724:                                win++;
                    725:                            }
                    726:                          else if (TREE_CODE (TREE_VALUE (ttf)) == REFERENCE_TYPE)
                    727:                            {
                    728:                              conv = build_type_conversion (CALL_EXPR, formal_type, TREE_VALUE (tta), 0);
                    729:                              if (conv)
                    730:                                {
                    731:                                  if (conv == error_mark_node)
                    732:                                    win += 2;
                    733:                                  else
                    734:                                    win++;
                    735:                                }
                    736:                            }
                    737:                        }
                    738:                    }
                    739:                }
                    740:              dont_convert_types = 0;
                    741: 
                    742:              if (win == 1)
                    743:                {
                    744:                  user_strikes += 1;
                    745:                  cp->harshness[strike_index] = USER_HARSHNESS (-1);
                    746:                  win = 0;
                    747:                }
                    748:              else
                    749:                {
                    750:                  if (cp->u.bad_arg > strike_index)
                    751:                    cp->u.bad_arg = strike_index;
                    752: 
                    753:                  evil_strikes = win ? 2 : 1;
                    754:                  break;
                    755:                }
                    756:            }
                    757: 
                    758:          ttf = TREE_CHAIN (ttf);
                    759:          tta = TREE_CHAIN (tta);
                    760:          strike_index += 1;
                    761:        }
                    762:     }
                    763: 
                    764:   /* Const member functions get a small penalty because defaulting
                    765:      to const is less useful than defaulting to non-const. */
1.1.1.4   root      766:   /* This is bogus, it does not correspond to anything in the ARM.
                    767:      This code will be fixed when this entire section is rewritten
                    768:      to conform to the ARM.  (mrs)  */
1.1       root      769:   if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
                    770:     {
                    771:       if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (ttf_in))))
                    772:        {
                    773:          cp->harshness[0] += INT_TO_EASY_HARSHNESS (1);
                    774:          ++easy_strikes;
                    775:        }
                    776:       else
                    777:        {
                    778:          /* Calling a non-const member function from a const member function
                    779:             is probably invalid, but for now we let it only draw a warning.
1.1.1.2   root      780:             We indicate that such a mismatch has occurred by setting the
1.1       root      781:             harshness to a maximum value.  */
                    782:          if (TREE_CODE (TREE_TYPE (TREE_VALUE (tta_in))) == POINTER_TYPE
                    783:              && (TYPE_READONLY (TREE_TYPE (TREE_TYPE (TREE_VALUE (tta_in))))))
                    784:            cp->harshness[0] |= CONST_HARSHNESS (-1);
                    785:        }
                    786:     }
                    787: 
                    788:   cp->evil = evil_strikes;
1.1.1.5 ! root      789:   cp->ellipsis = ellipsis_strikes;
1.1       root      790:   cp->user = user_strikes;
                    791:   cp->b_or_d = b_or_d_strikes;
                    792:   cp->easy = easy_strikes;
                    793: }
                    794: 
                    795: /* When one of several possible overloaded functions and/or methods
                    796:    can be called, choose the best candidate for overloading.
                    797: 
                    798:    BASETYPE is the context from which we start method resolution
                    799:    or NULL if we are comparing overloaded functions.
1.1.1.2   root      800:    CANDIDATES is the array of candidates we have to choose from.
1.1       root      801:    N_CANDIDATES is the length of CANDIDATES.
                    802:    PARMS is a TREE_LIST of parameters to the function we'll ultimately
                    803:    choose.  It is modified in place when resolving methods.  It is not
                    804:    modified in place when resolving overloaded functions.
                    805:    LEN is the length of the parameter list.  */
                    806: 
                    807: static struct candidate *
                    808: ideal_candidate (basetype, candidates, n_candidates, parms, len)
                    809:      tree basetype;
                    810:      struct candidate *candidates;
                    811:      int n_candidates;
                    812:      tree parms;
                    813:      int len;
                    814: {
                    815:   struct candidate *cp = candidates + n_candidates;
                    816:   int index, i;
                    817:   tree ttf;
                    818: 
                    819:   qsort (candidates,           /* char *base */
                    820:         n_candidates,          /* int nel */
                    821:         sizeof (struct candidate), /* int width */
                    822:         rank_for_overload);    /* int (*compar)() */
                    823: 
                    824:   /* If the best candidate requires user-defined conversions,
                    825:      and its user-defined conversions are a strict subset
                    826:      of all other candidates requiring user-defined conversions,
                    827:      then it is, in fact, the best.  */
                    828:   for (i = -1; cp + i != candidates; i--)
                    829:     if (cp[i].user == 0)
                    830:       break;
                    831: 
                    832:   if (i < -1)
                    833:     {
                    834:       tree ttf0;
                    835: 
                    836:       /* Check that every other candidate requires those conversions
                    837:         as a strict subset of their conversions.  */
                    838:       if (cp[i].user == cp[-1].user)
                    839:        goto non_subset;
                    840: 
                    841:       /* Look at subset relationship more closely.  */
                    842:       while (i != -1)
                    843:        {
                    844:          for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[i].function)),
                    845:               ttf0 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function)),
                    846:               index = 0;
                    847:               index < len;
                    848:               ttf = TREE_CHAIN (ttf), ttf0 = TREE_CHAIN (ttf0), index++)
                    849:            if (USER_HARSHNESS (cp[i].harshness[index]))
                    850:              {
                    851:                /* If our "best" candidate also needs a conversion,
                    852:                   it must be the same one.  */
                    853:                if (USER_HARSHNESS (cp[-1].harshness[index])
                    854:                    && TREE_VALUE (ttf) != TREE_VALUE (ttf0))
                    855:                  goto non_subset;
                    856:              }
                    857:          i++;
                    858:        }
                    859:       /* The best was the best.  */
                    860:       return cp - 1;
                    861:     non_subset:
                    862:       /* Use other rules for determining "bestness".  */
                    863:       ;
                    864:     }
                    865: 
                    866:   /* If the best two candidates we find require user-defined
                    867:      conversions, we may need to report and error message.  */
                    868:   if (cp[-1].user && cp[-2].user
                    869:       && (cp[-1].b_or_d || cp[-2].b_or_d == 0))
                    870:     {
                    871:       /* If the best two methods found involved user-defined
                    872:         type conversions, then we must see whether one
                    873:         of them is exactly what we wanted.  If not, then
                    874:         we have an ambiguity.  */
                    875:       int best = 0;
                    876:       tree tta = parms;
1.1.1.5 ! root      877:       tree f1;
        !           878: #if 0
        !           879:       /* for LUCID */
        !           880:       tree p1;
        !           881: #endif
1.1       root      882: 
                    883:       /* Stash all of our parameters in safe places
                    884:         so that we can perform type conversions in place.  */
                    885:       while (tta)
                    886:        {
                    887:          TREE_PURPOSE (tta) = TREE_VALUE (tta);
                    888:          tta = TREE_CHAIN (tta);
                    889:        }
                    890: 
                    891:       i = 0;
                    892:       do
                    893:        {
                    894:          int exact_conversions = 0;
                    895: 
                    896:          i -= 1;
                    897:          tta = parms;
                    898:          if (DECL_STATIC_FUNCTION_P (cp[i].function))
                    899:            tta = TREE_CHAIN (tta);
1.1.1.3   root      900:          /* special note, we don't go through len parameters, because we
                    901:             may only need len-1 parameters because of a call to a static
                    902:             member. */
1.1       root      903:          for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[i].function)), index = 0;
1.1.1.3   root      904:               tta;
1.1       root      905:               tta = TREE_CHAIN (tta), ttf = TREE_CHAIN (ttf), index++)
                    906:            {
                    907:              if (USER_HARSHNESS (cp[i].harshness[index]))
                    908:                {
1.1.1.2   root      909:                  tree this_parm = build_type_conversion (CALL_EXPR, TREE_VALUE (ttf), TREE_PURPOSE (tta), 2);
                    910:                  if (basetype != NULL_TREE)
                    911:                    TREE_VALUE (tta) = this_parm;
                    912:                  if (this_parm)
1.1       root      913:                    {
1.1.1.2   root      914:                      if (TREE_CODE (this_parm) != CONVERT_EXPR
                    915:                          && (TREE_CODE (this_parm) != NOP_EXPR
                    916:                              || comp_target_types (TREE_TYPE (this_parm),
                    917:                                                    TREE_TYPE (TREE_OPERAND (this_parm, 0)), 1)))
1.1       root      918:                        exact_conversions += 1;
                    919:                    }
                    920:                  else if (PROMOTES_TO_AGGR_TYPE (TREE_VALUE (ttf), REFERENCE_TYPE))
                    921:                    {
                    922:                      /* To get here we had to have succeeded via
                    923:                         a constructor.  */
                    924:                      TREE_VALUE (tta) = TREE_PURPOSE (tta);
                    925:                      exact_conversions += 1;
                    926:                    }
                    927:                }
                    928:            }
                    929:          if (exact_conversions == cp[i].user)
                    930:            {
                    931:              if (best == 0)
                    932:                {
                    933:                  best = i;
                    934:                  f1 = cp[best].function;
1.1.1.5 ! root      935: #if 0
        !           936:                  /* For LUCID */
1.1       root      937:                  p1 = TYPE_ARG_TYPES (TREE_TYPE (f1));
1.1.1.5 ! root      938: #endif
1.1       root      939:                }
                    940:              else
                    941:                {
                    942:                  /* Don't complain if next best is from base class.  */
                    943:                  tree f2 = cp[i].function;
                    944: 
                    945:                  if (TREE_CODE (TREE_TYPE (f1)) == METHOD_TYPE
                    946:                      && TREE_CODE (TREE_TYPE (f2)) == METHOD_TYPE
                    947:                      && BASE_DERIVED_HARSHNESS (cp[i].harshness[0])
                    948:                      && cp[best].harshness[0] < cp[i].harshness[0])
                    949:                    {
                    950: #if 0
1.1.1.4   root      951:                      tree p2 = TYPE_ARG_TYPES (TREE_TYPE (f2));
1.1       root      952:                      /* For LUCID.  */
                    953:                      if (! compparms (TREE_CHAIN (p1), TREE_CHAIN (p2), 1))
                    954:                        goto ret0;
                    955:                      else
                    956: #endif
                    957:                        continue;
                    958:                    }
                    959:                  else
                    960:                    {
                    961:                      /* Ensure that there's nothing ambiguous about these
                    962:                         two fns.  */
1.1.1.4   root      963:                      int identical = 1;
1.1       root      964:                      for (index = 0; index < len; index++)
                    965:                        {
                    966:                          /* Type conversions must be piecewise equivalent.  */
                    967:                          if (USER_HARSHNESS (cp[best].harshness[index])
                    968:                              != USER_HARSHNESS (cp[i].harshness[index]))
                    969:                            goto ret0;
                    970:                          /* If there's anything we like better about the
                    971:                             other function, consider it ambiguous.  */
                    972:                          if (cp[i].harshness[index] < cp[best].harshness[index])
                    973:                            goto ret0;
1.1.1.4   root      974:                          /* If any single one it diffent, then the whole is
                    975:                             not identical.  */
                    976:                          if (cp[i].harshness[index] != cp[best].harshness[index])
                    977:                            identical = 0;
1.1       root      978:                        }
1.1.1.4   root      979: 
                    980:                      /* If we can't tell the difference between the two, it
                    981:                         is ambiguous.  */
                    982:                      if (identical)
                    983:                        goto ret0;
                    984: 
1.1       root      985:                      /* If we made it to here, it means we're satisfied that
                    986:                         BEST is still best.  */
                    987:                      continue;
                    988:                    }
                    989:                }
                    990:            }
                    991:        } while (cp + i != candidates);
                    992: 
                    993:       if (best)
                    994:        {
                    995:          int exact_conversions = cp[best].user;
                    996:          tta = parms;
                    997:          if (DECL_STATIC_FUNCTION_P (cp[best].function))
                    998:            tta = TREE_CHAIN (parms);
                    999:          for (ttf = TYPE_ARG_TYPES (TREE_TYPE (cp[best].function)), index = 0;
                   1000:               exact_conversions > 0;
                   1001:               tta = TREE_CHAIN (tta), ttf = TREE_CHAIN (ttf), index++)
                   1002:            {
                   1003:              if (USER_HARSHNESS (cp[best].harshness[index]))
                   1004:                {
                   1005:                  /* We must now fill in the slot we left behind.
                   1006:                     @@ This could be optimized to use the value previously
                   1007:                     @@ computed by build_type_conversion in some cases.  */
                   1008:                  if (basetype != NULL_TREE)
                   1009:                    TREE_VALUE (tta) = convert (TREE_VALUE (ttf), TREE_PURPOSE (tta));
                   1010:                  exact_conversions -= 1;
                   1011:                }
                   1012:              else TREE_VALUE (tta) = TREE_PURPOSE (tta);
                   1013:            }
                   1014:          return cp + best;
                   1015:        }
                   1016:       goto ret0;
                   1017:     }
                   1018:   /* If the best two candidates we find both use default parameters,
                   1019:      we may need to report and error.  Don't need to worry if next-best
                   1020:      candidate is forced to use user-defined conversion when best is not.  */
                   1021:   if (cp[-2].user == 0
                   1022:       && cp[-1].harshness[len] != 0 && cp[-2].harshness[len] != 0)
                   1023:     {
                   1024:       tree tt1 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function));
                   1025:       tree tt2 = TYPE_ARG_TYPES (TREE_TYPE (cp[-2].function));
                   1026:       unsigned i = cp[-1].harshness[len];
                   1027: 
                   1028:       if (cp[-2].harshness[len] < i)
                   1029:        i = cp[-2].harshness[len];
                   1030:       while (--i > 0)
                   1031:        {
                   1032:          if (TYPE_MAIN_VARIANT (TREE_VALUE (tt1))
                   1033:              != TYPE_MAIN_VARIANT (TREE_VALUE (tt2)))
                   1034:            /* These lists are not identical, so we can choose our best candidate.  */
                   1035:            return cp - 1;
                   1036:          tt1 = TREE_CHAIN (tt1);
                   1037:          tt2 = TREE_CHAIN (tt2);
                   1038:        }
                   1039:       /* To get here, both lists had the same parameters up to the defaults
                   1040:         which were used.  This is an ambiguous request.  */
                   1041:       goto ret0;
                   1042:     }
                   1043: 
                   1044:   /* Otherwise, return our best candidate.  Note that if we get candidates
                   1045:      from independent base classes, we have an ambiguity, even if one
                   1046:      argument list look a little better than another one.  */
                   1047:   if (cp[-1].b_or_d && basetype && TYPE_USES_MULTIPLE_INHERITANCE (basetype))
                   1048:     {
                   1049:       int i = n_candidates - 1, best = i;
                   1050:       tree base1 = NULL_TREE;
                   1051: 
                   1052:       if (TREE_CODE (TREE_TYPE (candidates[i].function)) == FUNCTION_TYPE)
                   1053:        return cp - 1;
                   1054: 
                   1055:       for (; i >= 0 && candidates[i].user == 0 && candidates[i].evil == 0; i--)
                   1056:        {
                   1057:          if (TREE_CODE (TREE_TYPE (candidates[i].function)) == METHOD_TYPE)
                   1058:            {
                   1059:              tree newbase = DECL_CLASS_CONTEXT (candidates[i].function);
                   1060: 
                   1061:              if (base1 != NULL_TREE)
                   1062:                {
1.1.1.3   root     1063:                  /* newbase could be a base or a parent of base1 */
1.1.1.4   root     1064:                  if (newbase != base1 && ! UNIQUELY_DERIVED_FROM_P (newbase, base1)
                   1065:                      && ! UNIQUELY_DERIVED_FROM_P (base1, newbase))
1.1       root     1066:                    {
1.1.1.2   root     1067:                      error_with_aggr_type (basetype, "ambiguous request for function from distinct base classes of type `%s'");
1.1.1.5 ! root     1068:                      error ("  first candidate is `%s'",
1.1       root     1069:                             fndecl_as_string (0, candidates[best].function, 1));
1.1.1.5 ! root     1070:                      error ("  second candidate is `%s'",
1.1       root     1071:                             fndecl_as_string (0, candidates[i].function, 1));
                   1072:                      cp[-1].evil = 1;
                   1073:                      return cp - 1;
                   1074:                    }
                   1075:                }
                   1076:              else
                   1077:                {
                   1078:                  best = i;
                   1079:                  base1 = newbase;
                   1080:                }
                   1081:            }
                   1082:          else return cp - 1;
                   1083:        }
                   1084:     }
                   1085: 
                   1086:   /* Don't accept a candidate as being ideal if it's indistinguishable
                   1087:      from another candidate.  */
                   1088:   if (rank_for_overload (cp-1, cp-2) == 0)
                   1089:     {
                   1090:       /* If the types are distinguishably different (like
                   1091:         `long' vs. `unsigned long'), that's ok.  But if they are arbitrarily
                   1092:         different, such as `int (*)(void)' vs. `void (*)(int)',
                   1093:         that's not ok.  */
                   1094:       tree p1 = TYPE_ARG_TYPES (TREE_TYPE (cp[-1].function));
                   1095:       tree p2 = TYPE_ARG_TYPES (TREE_TYPE (cp[-2].function));
                   1096:       while (p1 && p2)
                   1097:        {
                   1098:          if (TREE_CODE (TREE_VALUE (p1)) == POINTER_TYPE
                   1099:              && TREE_CODE (TREE_TYPE (TREE_VALUE (p1))) == FUNCTION_TYPE
                   1100:              && TREE_VALUE (p1) != TREE_VALUE (p2))
                   1101:            return 0;
                   1102:          p1 = TREE_CHAIN (p1);
                   1103:          p2 = TREE_CHAIN (p2);
                   1104:        }
                   1105:       if (p1 || p2)
                   1106:        return 0;
                   1107:     }
                   1108: 
                   1109:   return cp - 1;
                   1110: 
                   1111:  ret0:
                   1112:   /* In the case where there is no ideal candidate, restore
                   1113:      TREE_VALUE slots of PARMS from TREE_PURPOSE slots.  */
                   1114:   while (parms)
                   1115:     {
                   1116:       TREE_VALUE (parms) = TREE_PURPOSE (parms);
                   1117:       parms = TREE_CHAIN (parms);
                   1118:     }
                   1119:   return 0;
                   1120: }
                   1121: 
                   1122: /* Assume that if the class referred to is not in the
                   1123:    current class hierarchy, that it may be remote.
                   1124:    PARENT is assumed to be of aggregate type here.  */
                   1125: static int
                   1126: may_be_remote (parent)
                   1127:      tree parent;
                   1128: {
                   1129:   if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent) == 0)
                   1130:     return 0;
                   1131: 
                   1132:   if (current_class_type == NULL_TREE)
                   1133:     return 0;
                   1134:   if (parent == current_class_type)
                   1135:     return 0;
                   1136: 
1.1.1.4   root     1137:   if (UNIQUELY_DERIVED_FROM_P (parent, current_class_type))
1.1       root     1138:     return 0;
                   1139:   return 1;
                   1140: }
                   1141: 
                   1142: tree
                   1143: build_vfield_ref (datum, type)
                   1144:      tree datum, type;
                   1145: {
                   1146:   tree rval;
                   1147:   int old_assume_nonnull_objects = flag_assume_nonnull_objects;
                   1148: 
1.1.1.5 ! root     1149:   if (datum == error_mark_node)
        !          1150:     return error_mark_node;
        !          1151: 
1.1       root     1152:   /* Vtable references are always made from non-null objects.  */
                   1153:   flag_assume_nonnull_objects = 1;
                   1154:   if (TREE_CODE (TREE_TYPE (datum)) == REFERENCE_TYPE)
                   1155:     datum = convert_from_reference (datum);
                   1156: 
                   1157:   if (! TYPE_USES_COMPLEX_INHERITANCE (type))
                   1158:     rval = build (COMPONENT_REF, TREE_TYPE (CLASSTYPE_VFIELD (type)),
                   1159:                  datum, CLASSTYPE_VFIELD (type));
                   1160:   else
                   1161:     rval = build_component_ref (datum, DECL_NAME (CLASSTYPE_VFIELD (type)), 0, 0);
                   1162:   flag_assume_nonnull_objects = old_assume_nonnull_objects;
                   1163: 
                   1164:   return rval;
                   1165: }
                   1166: 
                   1167: /* Build a call to a member of an object.  I.e., one that overloads
                   1168:    operator ()(), or is a pointer-to-function or pointer-to-method.  */
                   1169: static tree
                   1170: build_field_call (basetype_path, instance_ptr, name, parms, err_name)
                   1171:      tree basetype_path;
                   1172:      tree instance_ptr, name, parms;
                   1173:      char *err_name;
                   1174: {
                   1175:   tree field, instance;
                   1176: 
                   1177:   if (instance_ptr == current_class_decl)
                   1178:     {
                   1179:       /* Check to see if we really have a reference to an instance variable
                   1180:         with `operator()()' overloaded.  */
                   1181:       field = IDENTIFIER_CLASS_VALUE (name);
                   1182: 
                   1183:       if (field == NULL_TREE)
                   1184:        {
                   1185:          error ("`this' has no member named `%s'", err_name);
                   1186:          return error_mark_node;
                   1187:        }
                   1188: 
                   1189:       if (TREE_CODE (field) == FIELD_DECL)
                   1190:        {
                   1191:          /* If it's a field, try overloading operator (),
                   1192:             or calling if the field is a pointer-to-function.  */
                   1193:          instance = build_component_ref_1 (C_C_D, field, 0);
                   1194:          if (instance == error_mark_node)
                   1195:            return error_mark_node;
                   1196: 
                   1197:          if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance))
                   1198:              && TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance)))
1.1.1.5 ! root     1199:            return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, instance, parms, NULL_TREE);
1.1       root     1200: 
                   1201:          if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
                   1202:            if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE)
                   1203:              return build_function_call (instance, parms);
                   1204:            else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == METHOD_TYPE)
                   1205:              return build_function_call (instance, tree_cons (NULL_TREE, current_class_decl, parms));
                   1206:        }
                   1207:       return NULL_TREE;
                   1208:     }
                   1209: 
                   1210:   /* Check to see if this is not really a reference to an instance variable
                   1211:      with `operator()()' overloaded.  */
1.1.1.4   root     1212:   field = lookup_field (basetype_path, name, 1, 0);
1.1       root     1213: 
                   1214:   /* This can happen if the reference was ambiguous
                   1215:      or for visibility violations.  */
                   1216:   if (field == error_mark_node)
                   1217:     return error_mark_node;
                   1218:   if (field)
                   1219:     {
                   1220:       tree basetype;
                   1221:       tree ftype = TREE_TYPE (field);
                   1222: 
                   1223:       if (TYPE_LANG_SPECIFIC (ftype) && TYPE_OVERLOADS_CALL_EXPR (ftype))
                   1224:        {
                   1225:          /* Make the next search for this field very short.  */
                   1226:          basetype = DECL_FIELD_CONTEXT (field);
                   1227:          instance_ptr = convert_pointer_to (basetype, instance_ptr);
                   1228: 
1.1.1.5 ! root     1229:          instance = build_indirect_ref (instance_ptr, NULL);
1.1       root     1230:          return build_opfncall (CALL_EXPR, LOOKUP_NORMAL,
                   1231:                                 build_component_ref_1 (instance, field, 0),
1.1.1.5 ! root     1232:                                 parms, NULL_TREE);
1.1       root     1233:        }
                   1234:       if (TREE_CODE (ftype) == POINTER_TYPE)
                   1235:        {
                   1236:          if (TREE_CODE (TREE_TYPE (ftype)) == FUNCTION_TYPE
                   1237:              || TREE_CODE (TREE_TYPE (ftype)) == METHOD_TYPE)
                   1238:            {
                   1239:              /* This is a member which is a pointer to function.  */
1.1.1.5 ! root     1240:              tree ref
        !          1241:                = build_component_ref_1 (build_indirect_ref (instance_ptr,
        !          1242:                                                             NULL),
        !          1243:                                         field, LOOKUP_COMPLAIN);
1.1       root     1244:              if (ref == error_mark_node)
                   1245:                return error_mark_node;
                   1246:              return build_function_call (ref, parms);
                   1247:            }
                   1248:        }
                   1249:       else if (TREE_CODE (ftype) == METHOD_TYPE)
                   1250:        {
                   1251:          error ("invalid call via pointer-to-member function");
                   1252:          return error_mark_node;
                   1253:        }
                   1254:       else
                   1255:        return NULL_TREE;
                   1256:     }
                   1257:   return NULL_TREE;
                   1258: }
                   1259: 
1.1.1.4   root     1260: tree
                   1261: find_scoped_type (type, inner_name, inner_types)
                   1262:      tree type, inner_name, inner_types;
                   1263: {
                   1264:   tree tags = CLASSTYPE_TAGS (type);
                   1265: 
                   1266:   while (tags)
                   1267:     {
                   1268:       /* The TREE_PURPOSE of an enum tag (which becomes a member of the
                   1269:         enclosing class) is set to the name for the enum type.  So, if
                   1270:         inner_name is `bar', and we strike `baz' for `enum bar { baz }',
                   1271:         then this test will be true.  */
                   1272:       if (TREE_PURPOSE (tags) == inner_name)
                   1273:        {
                   1274:          if (inner_types == NULL_TREE)
                   1275:            return DECL_NESTED_TYPENAME (TYPE_NAME (TREE_VALUE (tags)));
                   1276:          return resolve_scope_to_name (TREE_VALUE (tags), inner_types);
                   1277:        }
                   1278:       tags = TREE_CHAIN (tags);
                   1279:     }
                   1280: 
                   1281:   /* Look for a TYPE_DECL.  */
                   1282:   for (tags = TYPE_FIELDS (type); tags; tags = TREE_CHAIN (tags))
                   1283:     if (TREE_CODE (tags) == TYPE_DECL && DECL_NAME (tags) == inner_name)
                   1284:       {
                   1285:        /* Code by raeburn.  */
                   1286:        if (inner_types == NULL_TREE)
                   1287:          return DECL_NESTED_TYPENAME (tags);
                   1288:        return resolve_scope_to_name (TREE_TYPE (tags), inner_types);
                   1289:       }
                   1290: 
                   1291:   return NULL_TREE;
                   1292: }
                   1293: 
1.1       root     1294: /* Resolve an expression NAME1::NAME2::...::NAMEn to
                   1295:    the name that names the above nested type.  INNER_TYPES
                   1296:    is a chain of nested type names (held together by SCOPE_REFs);
                   1297:    OUTER_TYPE is the type we know to enclose INNER_TYPES.
                   1298:    Returns NULL_TREE if there is an error.  */
                   1299: tree
                   1300: resolve_scope_to_name (outer_type, inner_types)
                   1301:      tree outer_type, inner_types;
                   1302: {
1.1.1.4   root     1303:   register tree tmp;
1.1.1.5 ! root     1304:   tree inner_name;
1.1       root     1305: 
                   1306:   if (outer_type == NULL_TREE && current_class_type != NULL_TREE)
                   1307:     {
1.1.1.5 ! root     1308:       /* We first try to look for a nesting in our current class context,
        !          1309:          then try any enclosing classes.  */
        !          1310:       tree type = current_class_type;
        !          1311:       
        !          1312:       while (type && (TREE_CODE (type) == RECORD_TYPE
        !          1313:                      || TREE_CODE (type) == UNION_TYPE))
        !          1314:         {
        !          1315:           tree rval = resolve_scope_to_name (type, inner_types);
        !          1316: 
        !          1317:          if (rval != NULL_TREE)
        !          1318:            return rval;
        !          1319:          type = DECL_CONTEXT (TYPE_NAME (type));
        !          1320:        }
1.1       root     1321:     }
                   1322: 
                   1323:   if (TREE_CODE (inner_types) == SCOPE_REF)
                   1324:     {
                   1325:       inner_name = TREE_OPERAND (inner_types, 0);
                   1326:       inner_types = TREE_OPERAND (inner_types, 1);
                   1327:     }
                   1328:   else
                   1329:     {
                   1330:       inner_name = inner_types;
1.1.1.5 ! root     1331:       inner_types = NULL_TREE;
1.1       root     1332:     }
                   1333: 
                   1334:   if (outer_type == NULL_TREE)
                   1335:     {
                   1336:       /* If we have something that's already a type by itself,
                   1337:         use that.  */
                   1338:       if (IDENTIFIER_HAS_TYPE_VALUE (inner_name))
                   1339:        {
                   1340:          if (inner_types)
                   1341:            return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name),
                   1342:                                          inner_types);
                   1343:          return inner_name;
                   1344:        }
                   1345:       return NULL_TREE;
                   1346:     }
                   1347: 
                   1348:   if (! IS_AGGR_TYPE (outer_type))
                   1349:     return NULL_TREE;
                   1350: 
1.1.1.4   root     1351:   /* Look for member classes or enums.  */
                   1352:   tmp = find_scoped_type (outer_type, inner_name, inner_types);
1.1       root     1353: 
1.1.1.4   root     1354:   /* If it's not a type in this class, then go down into the
                   1355:      base classes and search there.  */
                   1356:   if (! tmp && TYPE_BINFO (outer_type))
1.1       root     1357:     {
1.1.1.4   root     1358:       tree binfos = TYPE_BINFO_BASETYPES (outer_type);
                   1359:       int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
                   1360: 
                   1361:       for (i = 0; i < n_baselinks; i++)
1.1       root     1362:        {
1.1.1.4   root     1363:          tree base_binfo = TREE_VEC_ELT (binfos, i);
                   1364:          tmp = find_scoped_type (BINFO_TYPE (base_binfo),
                   1365:                                  inner_name, inner_types);
                   1366:          if (tmp)
                   1367:            return tmp;
1.1       root     1368:        }
1.1.1.4   root     1369:       tmp = NULL_TREE;
1.1       root     1370:     }
                   1371: 
1.1.1.4   root     1372:   return tmp;
1.1       root     1373: }
                   1374: 
                   1375: /* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
                   1376:    This is how virtual function calls are avoided.  */
                   1377: tree
                   1378: build_scoped_method_call (exp, scopes, name, parms)
                   1379:      tree exp;
                   1380:      tree scopes;
                   1381:      tree name;
                   1382:      tree parms;
                   1383: {
                   1384:   /* Because this syntactic form does not allow
                   1385:      a pointer to a base class to be `stolen',
1.1.1.2   root     1386:      we need not protect the derived->base conversion
1.1       root     1387:      that happens here.
                   1388:      
                   1389:      @@ But we do have to check visibility privileges later.  */
                   1390:   tree basename = resolve_scope_to_name (NULL_TREE, scopes);
                   1391:   tree basetype, binfo, decl;
                   1392:   tree type = TREE_TYPE (exp);
                   1393: 
                   1394:   if (type == error_mark_node
                   1395:       || basename == NULL_TREE
                   1396:       || ! is_aggr_typedef (basename, 1))
                   1397:     return error_mark_node;
                   1398: 
                   1399:   if (! IS_AGGR_TYPE (type))
                   1400:     {
                   1401:       error ("base object of scoped method call is not of aggregate type");
                   1402:       return error_mark_node;
                   1403:     }
                   1404: 
                   1405:   basetype = IDENTIFIER_TYPE_VALUE (basename);
                   1406: 
                   1407:   if (binfo = binfo_or_else (basetype, type))
                   1408:     {
                   1409:       if (binfo == error_mark_node)
                   1410:        return error_mark_node;
                   1411:       if (TREE_CODE (exp) == INDIRECT_REF)
                   1412:        decl = build_indirect_ref (convert_pointer_to (binfo,
1.1.1.5 ! root     1413:                                                       build_unary_op (ADDR_EXPR, exp, 0)), NULL);
1.1       root     1414:       else
                   1415:        decl = build_scoped_ref (exp, scopes);
                   1416: 
                   1417:       /* Call to a destructor.  */
                   1418:       if (TREE_CODE (name) == BIT_NOT_EXPR)
                   1419:        {
                   1420:          /* Explicit call to destructor.  */
                   1421:          name = TREE_OPERAND (name, 0);
                   1422:          if (! is_aggr_typedef (name, 1))
                   1423:            return error_mark_node;
                   1424:          if (TREE_TYPE (decl) != IDENTIFIER_TYPE_VALUE (name))
                   1425:            {
                   1426:              error_with_aggr_type (TREE_TYPE (decl),
                   1427:                                    "qualified type `%s' does not match destructor type `%s'",
                   1428:                                    IDENTIFIER_POINTER (name));
                   1429:              return error_mark_node;
                   1430:            }
                   1431:          if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl)))
                   1432:            error_with_aggr_type (TREE_TYPE (decl), "type `%s' has no destructor");
                   1433:          return build_delete (TREE_TYPE (decl), decl, integer_two_node,
1.1.1.4   root     1434:                               LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR,
                   1435:                               0, 0);
1.1       root     1436:        }
                   1437: 
                   1438:       /* Call to a method.  */
                   1439:       return build_method_call (decl, name, parms, NULL_TREE,
                   1440:                                LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
                   1441:     }
                   1442:   return error_mark_node;
                   1443: }
                   1444: 
                   1445: /* Build something of the form ptr->method (args)
                   1446:    or object.method (args).  This can also build
                   1447:    calls to constructors, and find friends.
                   1448: 
                   1449:    Member functions always take their class variable
                   1450:    as a pointer.
                   1451: 
                   1452:    INSTANCE is a class instance.
                   1453: 
                   1454:    NAME is the NAME field of the struct, union, or class
                   1455:    whose type is that of INSTANCE.
                   1456: 
                   1457:    PARMS help to figure out what that NAME really refers to.
                   1458: 
                   1459:    BASETYPE_PATH, if non-NULL, tells which basetypes of INSTANCE
                   1460:    we should be traversed before starting our search.  We need
                   1461:    this information to get protected accesses correct.
                   1462: 
                   1463:    FLAGS is the logical disjunction of zero or more LOOKUP_
                   1464:    flags.  See cp-tree.h for more info.
                   1465: 
                   1466:    If this is all OK, calls build_function_call with the resolved
                   1467:    member function.
                   1468: 
                   1469:    This function must also handle being called to perform
                   1470:    initialization, promotion/coercion of arguments, and
                   1471:    instantiation of default parameters.
                   1472: 
                   1473:    Note that NAME may refer to an instance variable name.  If
                   1474:    `operator()()' is defined for the type of that field, then we return
                   1475:    that result.  */
                   1476: tree
                   1477: build_method_call (instance, name, parms, basetype_path, flags)
                   1478:      tree instance, name, parms, basetype_path;
                   1479:      int flags;
                   1480: {
                   1481:   register tree function, fntype, value_type;
                   1482:   register tree basetype, save_basetype;
                   1483:   register tree baselink, result, method_name, parmtypes, parm;
                   1484:   tree last;
                   1485:   int pass;
                   1486:   enum visibility_type visibility;
                   1487: 
                   1488:   /* Range of cases for vtable optimization.  */
1.1.1.5 ! root     1489:   enum vtable_needs { not_needed, maybe_needed, unneeded, needed };
1.1       root     1490:   enum vtable_needs need_vtbl = not_needed;
                   1491: 
                   1492:   char *err_name;
                   1493:   char *name_kind;
                   1494:   int ever_seen = 0;
                   1495:   tree instance_ptr = NULL_TREE;
                   1496:   int all_virtual = flag_all_virtual;
                   1497:   int static_call_context = 0;
1.1.1.5 ! root     1498:   tree saw_private = NULL_TREE;
        !          1499:   tree saw_protected = NULL_TREE;
1.1       root     1500: 
                   1501:   /* Keep track of `const' and `volatile' objects.  */
                   1502:   int constp, volatilep;
                   1503: 
                   1504: #ifdef GATHER_STATISTICS
                   1505:   n_build_method_call++;
                   1506: #endif
                   1507: 
                   1508:   if (instance == error_mark_node
                   1509:       || name == error_mark_node
                   1510:       || parms == error_mark_node
1.1.1.5 ! root     1511:       || (instance != NULL_TREE && TREE_TYPE (instance) == error_mark_node))
1.1       root     1512:     return error_mark_node;
                   1513: 
1.1.1.4   root     1514:   /* This is the logic that magically deletes the second argument to
                   1515:      operator delete, if it is not needed. */
                   1516:   if (name == ansi_opname[(int) DELETE_EXPR] && list_length (parms)==2)
                   1517:     {
                   1518:       tree save_last = TREE_CHAIN (parms);
                   1519:       tree result;
                   1520:       /* get rid of unneeded argument */
                   1521:       TREE_CHAIN (parms) = NULL_TREE;
                   1522:       result = build_method_call (instance, name, parms, basetype_path,
                   1523:                                  (LOOKUP_SPECULATIVELY|flags)
                   1524:                                  &~LOOKUP_COMPLAIN);
                   1525:       /* If it works, return it. */
                   1526:       if (result && result != error_mark_node)
                   1527:        return build_method_call (instance, name, parms, basetype_path, flags);
                   1528:       /* If it doesn't work, two argument delete must work */
                   1529:       TREE_CHAIN (parms) = save_last;
                   1530:     }
                   1531: 
1.1       root     1532: #if 0
                   1533:   /* C++ 2.1 does not allow this, but ANSI probably will.  */
                   1534:   if (TREE_CODE (name) == BIT_NOT_EXPR)
                   1535:     {
                   1536:       error ("invalid call to destructor, use qualified name `%s::~%s'",
                   1537:             IDENTIFIER_POINTER (name), IDENTIFIER_POINTER (name));
                   1538:       return error_mark_node;
                   1539:     }
                   1540: #else
                   1541:   if (TREE_CODE (name) == BIT_NOT_EXPR)
                   1542:     {
                   1543:       flags |= LOOKUP_DESTRUCTOR;
                   1544:       name = TREE_OPERAND (name, 0);
                   1545:       if (! is_aggr_typedef (name, 1))
                   1546:        return error_mark_node;
                   1547:       if (parms)
                   1548:        error ("destructors take no parameters");
                   1549:       basetype = IDENTIFIER_TYPE_VALUE (name);
                   1550:       if (! TYPE_HAS_DESTRUCTOR (basetype))
                   1551:        {
                   1552: #if 0 /* ARM says tp->~T() without T::~T() is valid.  */
                   1553:          error_with_aggr_type (basetype, "type `%s' has no destructor");
                   1554: #endif
                   1555:          /* A destructive destructor wouldn't be a bad idea, but let's
                   1556:             not bother for now.  */
                   1557:          return build_c_cast (void_type_node, instance);
                   1558:        }
                   1559:       instance = default_conversion (instance);
                   1560:       if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
                   1561:        instance_ptr = instance;
                   1562:       else
                   1563:        instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
1.1.1.5 ! root     1564:       return build_delete (build_pointer_type (basetype),
        !          1565:                           instance_ptr, integer_two_node,
1.1       root     1566:                           LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0, 0);
                   1567:     }
                   1568: #endif
                   1569: 
                   1570:   /* Initialize name for error reporting.  */
                   1571:   if (IDENTIFIER_TYPENAME_P (name))
                   1572:     err_name = "type conversion operator";
                   1573:   else if (IDENTIFIER_OPNAME_P (name))
                   1574:     {
                   1575:       char *p = operator_name_string (name);
                   1576:       err_name = (char *)alloca (strlen (p) + 10);
                   1577:       sprintf (err_name, "operator %s", p);
                   1578:     }
                   1579:   else if (TREE_CODE (name) == SCOPE_REF)
                   1580:     err_name = IDENTIFIER_POINTER (TREE_OPERAND (name, 1));
                   1581:   else
                   1582:     err_name = IDENTIFIER_POINTER (name);
                   1583: 
                   1584:   if (IDENTIFIER_OPNAME_P (name))
                   1585:     GNU_xref_call (current_function_decl,  IDENTIFIER_POINTER (name));
                   1586:   else
                   1587:     GNU_xref_call (current_function_decl, err_name);
                   1588: 
                   1589:   if (instance == NULL_TREE)
                   1590:     {
                   1591:       basetype = NULL_TREE;
                   1592:       /* Check cases where this is really a call to raise
                   1593:         an exception.  */
                   1594:       if (current_class_type && TREE_CODE (name) == IDENTIFIER_NODE)
                   1595:        {
                   1596:          basetype = purpose_member (name, CLASSTYPE_TAGS (current_class_type));
                   1597:          if (basetype)
                   1598:            basetype = TREE_VALUE (basetype);
                   1599:        }
                   1600:       else if (TREE_CODE (name) == SCOPE_REF
                   1601:               && TREE_CODE (TREE_OPERAND (name, 0)) == IDENTIFIER_NODE)
                   1602:        {
                   1603:          if (! is_aggr_typedef (TREE_OPERAND (name, 0), 1))
                   1604:            return error_mark_node;
                   1605:          basetype = purpose_member (TREE_OPERAND (name, 1),
                   1606:                                     CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name, 0))));
                   1607:          if (basetype)
                   1608:            basetype = TREE_VALUE (basetype);
                   1609:        }
                   1610: 
                   1611:       if (basetype != NULL_TREE)
                   1612:        ;
                   1613:       /* call to a constructor... */
                   1614:       else if (IDENTIFIER_HAS_TYPE_VALUE (name))
                   1615:        {
                   1616:          basetype = IDENTIFIER_TYPE_VALUE (name);
                   1617:          name = constructor_name (basetype);
                   1618:        }
                   1619:       else
                   1620:        {
                   1621:          tree typedef_name = lookup_name (name, 1);
                   1622:          if (typedef_name && TREE_CODE (typedef_name) == TYPE_DECL)
                   1623:            {
1.1.1.2   root     1624:              /* Canonicalize the typedef name.  */
1.1       root     1625:              basetype = TREE_TYPE (typedef_name);
                   1626:              name = TYPE_IDENTIFIER (basetype);
                   1627:            }
                   1628:          else
                   1629:            {
                   1630:              error ("no constructor named `%s' in visible scope",
                   1631:                     IDENTIFIER_POINTER (name));
                   1632:              return error_mark_node;
                   1633:            }
                   1634:        }
                   1635: 
                   1636:       if (! IS_AGGR_TYPE (basetype))
                   1637:        {
                   1638:        non_aggr_error:
                   1639:          if ((flags & LOOKUP_COMPLAIN) && TREE_CODE (basetype) != ERROR_MARK)
                   1640:            error ("request for member `%s' in something not a structure or union", err_name);
                   1641: 
                   1642:          return error_mark_node;
                   1643:        }
                   1644:     }
                   1645:   else if (instance == C_C_D || instance == current_class_decl)
                   1646:     {
                   1647:       /* When doing initialization, we side-effect the TREE_TYPE of
                   1648:         C_C_D, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE.  */
                   1649:       basetype = TREE_TYPE (C_C_D);
                   1650: 
                   1651:       /* Anything manifestly `this' in constructors and destructors
                   1652:         has a known type, so virtual function tables are not needed.  */
                   1653:       if (TYPE_VIRTUAL_P (basetype)
1.1.1.4   root     1654:          && !(flags & LOOKUP_NONVIRTUAL))
1.1       root     1655:        need_vtbl = (dtor_label || ctor_label)
                   1656:          ? unneeded : maybe_needed;
                   1657: 
                   1658:       instance = C_C_D;
                   1659:       instance_ptr = current_class_decl;
                   1660:       result = build_field_call (TYPE_BINFO (current_class_type),
                   1661:                                 instance_ptr, name, parms, err_name);
                   1662: 
                   1663:       if (result)
                   1664:        return result;
                   1665:     }
                   1666:   else if (TREE_CODE (instance) == RESULT_DECL)
                   1667:     {
                   1668:       basetype = TREE_TYPE (instance);
                   1669:       /* Should we ever have to make a virtual function reference
                   1670:         from a RESULT_DECL, know that it must be of fixed type
                   1671:         within the scope of this function.  */
1.1.1.4   root     1672:       if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype))
1.1       root     1673:        need_vtbl = maybe_needed;
                   1674:       instance_ptr = build1 (ADDR_EXPR, TYPE_POINTER_TO (basetype), instance);
                   1675:     }
                   1676:   else if (instance == current_exception_object)
                   1677:     {
                   1678:       instance_ptr = build1 (ADDR_EXPR, TYPE_POINTER_TO (current_exception_type),
                   1679:                            TREE_OPERAND (current_exception_object, 0));
                   1680:       mark_addressable (TREE_OPERAND (current_exception_object, 0));
                   1681:       result = build_field_call (TYPE_BINFO (current_exception_type),
                   1682:                                 instance_ptr, name, parms, err_name);
                   1683:       if (result)
                   1684:        return result;
                   1685:       error ("exception member `%s' cannot be invoked", err_name);
                   1686:       return error_mark_node;
                   1687:     }
                   1688:   else
                   1689:     {
                   1690:       /* The MAIN_VARIANT of the type that `instance_ptr' winds up being.  */
                   1691:       tree inst_ptr_basetype;
                   1692: 
                   1693:       static_call_context = (TREE_CODE (instance) == NOP_EXPR
                   1694:                             && TREE_OPERAND (instance, 0) == error_mark_node);
                   1695: 
                   1696:       /* the base type of an instance variable is pointer to class */
                   1697:       basetype = TREE_TYPE (instance);
                   1698: 
                   1699:       if (TREE_CODE (basetype) == REFERENCE_TYPE)
                   1700:        {
                   1701:          basetype = TYPE_MAIN_VARIANT (TREE_TYPE (basetype));
                   1702:          if (! IS_AGGR_TYPE (basetype))
                   1703:            goto non_aggr_error;
                   1704:          /* Call to convert not needed because we are remaining
                   1705:             within the same type.  */
                   1706:          instance_ptr = build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), instance);
                   1707:          inst_ptr_basetype = basetype;
                   1708:        }
                   1709:       else
                   1710:        {
                   1711:          if (TREE_CODE (basetype) == POINTER_TYPE)
                   1712:            {
                   1713:              basetype = TREE_TYPE (basetype);
                   1714:              instance_ptr = instance;
                   1715:            }
                   1716: 
                   1717:          if (! IS_AGGR_TYPE (basetype))
                   1718:            goto non_aggr_error;
                   1719: 
                   1720:          if (! instance_ptr)
                   1721:            {
                   1722:              if ((lvalue_p (instance)
                   1723:                   && (instance_ptr = build_unary_op (ADDR_EXPR, instance, 0)))
                   1724:                  || (instance_ptr = unary_complex_lvalue (ADDR_EXPR, instance)))
                   1725:                {
                   1726:                  if (instance_ptr == error_mark_node)
                   1727:                    return error_mark_node;
                   1728:                }
                   1729:              else if (TREE_CODE (instance) == NOP_EXPR
                   1730:                       || TREE_CODE (instance) == CONSTRUCTOR)
                   1731:                {
                   1732:                  /* A cast is not an lvalue.  Initialize a fresh temp
                   1733:                     with the value we are casting from, and proceed with
                   1734:                     that temporary.  We can't cast to a reference type,
                   1735:                     so that simplifies the initialization to something
                   1736:                     we can manage.  */
                   1737:                  tree temp = get_temp_name (TREE_TYPE (instance), 0);
                   1738:                  if (IS_AGGR_TYPE (TREE_TYPE (instance)))
                   1739:                    expand_aggr_init (temp, instance, 0);
                   1740:                  else
                   1741:                    {
                   1742:                      store_init_value (temp, instance);
                   1743:                      expand_decl_init (temp);
                   1744:                    }
                   1745:                  instance = temp;
                   1746:                  instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
                   1747:                }
                   1748:              else
                   1749:                {
1.1.1.4   root     1750:                  if (TREE_CODE (instance) != CALL_EXPR)
                   1751:                    my_friendly_abort (125);
1.1       root     1752:                  if (TYPE_NEEDS_CONSTRUCTOR (basetype))
                   1753:                    instance = build_cplus_new (basetype, instance, 0);
                   1754:                  else
                   1755:                    {
                   1756:                      instance = get_temp_name (basetype, 0);
                   1757:                      TREE_ADDRESSABLE (instance) = 1;
                   1758:                    }
                   1759:                  instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
                   1760:                }
                   1761:              /* @@ Should we call comp_target_types here?  */
                   1762:              inst_ptr_basetype = TREE_TYPE (TREE_TYPE (instance_ptr));
                   1763:              if (TYPE_MAIN_VARIANT (basetype) == TYPE_MAIN_VARIANT (inst_ptr_basetype))
                   1764:                basetype = inst_ptr_basetype;
                   1765:              else
1.1.1.2   root     1766:                {
                   1767:                  instance_ptr = convert (TYPE_POINTER_TO (basetype), instance_ptr);
                   1768:                  if (instance_ptr == error_mark_node)
                   1769:                    return error_mark_node;
                   1770:                }
1.1       root     1771:            }
                   1772:          else
                   1773:            inst_ptr_basetype = TREE_TYPE (TREE_TYPE (instance_ptr));
                   1774:        }
                   1775: 
                   1776:       if (basetype_path == NULL_TREE)
                   1777:        basetype_path = TYPE_BINFO (inst_ptr_basetype);
                   1778: 
                   1779:       result = build_field_call (basetype_path, instance_ptr, name, parms, err_name);
                   1780:       if (result)
                   1781:        return result;
                   1782: 
1.1.1.4   root     1783:       if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype))
1.1       root     1784:        {
                   1785:          if (TREE_SIDE_EFFECTS (instance_ptr))
                   1786:            {
                   1787:              /* This action is needed because the instance is needed
                   1788:                 for providing the base of the virtual function table.
                   1789:                 Without using a SAVE_EXPR, the function we are building
                   1790:                 may be called twice, or side effects on the instance
                   1791:                 variable (such as a post-increment), may happen twice.  */
                   1792:              instance_ptr = save_expr (instance_ptr);
1.1.1.5 ! root     1793:              instance = build_indirect_ref (instance_ptr, NULL);
1.1       root     1794:            }
                   1795:          else if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
                   1796:            {
                   1797:              /* This happens when called for operator new ().  */
1.1.1.5 ! root     1798:              instance = build_indirect_ref (instance, NULL);
1.1       root     1799:            }
                   1800: 
                   1801:          need_vtbl = maybe_needed;
                   1802:        }
                   1803:     }
                   1804: 
                   1805:   if (TYPE_SIZE (basetype) == 0)
                   1806:     {
                   1807:       /* This is worth complaining about, I think.  */
                   1808:       error_with_aggr_type (basetype, "cannot lookup method in incomplete type `%s'");
                   1809:       return error_mark_node;
                   1810:     }
                   1811: 
                   1812:   save_basetype = basetype;
                   1813: 
                   1814: #if 0
                   1815:   if (all_virtual == 1
                   1816:       && (! strncmp (IDENTIFIER_POINTER (name), OPERATOR_METHOD_FORMAT,
                   1817:                     OPERATOR_METHOD_LENGTH)
                   1818:          || instance_ptr == NULL_TREE
1.1.1.5 ! root     1819:          || (TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype) == 0)))
1.1       root     1820:     all_virtual = 0;
                   1821: #endif
                   1822: 
                   1823:   last = NULL_TREE;
1.1.1.5 ! root     1824:   for (parmtypes = NULL_TREE, parm = parms; parm; parm = TREE_CHAIN (parm))
1.1       root     1825:     {
                   1826:       tree t = TREE_TYPE (TREE_VALUE (parm));
                   1827:       if (TREE_CODE (t) == OFFSET_TYPE)
                   1828:        {
                   1829:          /* Convert OFFSET_TYPE entities to their normal selves.  */
                   1830:          TREE_VALUE (parm) = resolve_offset_ref (TREE_VALUE (parm));
                   1831:          t = TREE_TYPE (TREE_VALUE (parm));
                   1832:        }
                   1833:       if (TREE_CODE (t) == ARRAY_TYPE)
                   1834:        {
                   1835:          /* Perform the conversion from ARRAY_TYPE to POINTER_TYPE in place.
                   1836:             This eliminates needless calls to `compute_conversion_costs'.  */
                   1837:          TREE_VALUE (parm) = default_conversion (TREE_VALUE (parm));
                   1838:          t = TREE_TYPE (TREE_VALUE (parm));
                   1839:        }
                   1840:       if (t == error_mark_node)
                   1841:        return error_mark_node;
                   1842:       last = build_tree_list (NULL_TREE, t);
                   1843:       parmtypes = chainon (parmtypes, last);
                   1844:     }
                   1845: 
                   1846:   if (instance)
                   1847:     {
                   1848:       constp = TREE_READONLY (instance);
                   1849:       volatilep = TREE_THIS_VOLATILE (instance);
                   1850:       parms = tree_cons (NULL_TREE, instance_ptr, parms);
                   1851:     }
                   1852:   else
                   1853:     {
                   1854:       /* Raw constructors are always in charge.  */
                   1855:       if (TYPE_USES_VIRTUAL_BASECLASSES (basetype)
                   1856:          && ! (flags & LOOKUP_HAS_IN_CHARGE))
                   1857:        {
                   1858:          flags |= LOOKUP_HAS_IN_CHARGE;
                   1859:          parms = tree_cons (NULL_TREE, integer_one_node, parms);
                   1860:          parmtypes = tree_cons (NULL_TREE, integer_type_node, parmtypes);
                   1861:        }
                   1862: 
1.1.1.2   root     1863:       if (flag_this_is_variable > 0)
1.1       root     1864:        {
                   1865:          constp = 0;
                   1866:          volatilep = 0;
                   1867:          parms = tree_cons (NULL_TREE, build1 (NOP_EXPR, TYPE_POINTER_TO (basetype), integer_zero_node), parms);
                   1868:        }
                   1869:       else
                   1870:        {
                   1871:          constp = 0;
                   1872:          volatilep = 0;
                   1873:          instance_ptr = build_new (NULL_TREE, basetype, void_type_node, 0);
                   1874:          if (instance_ptr == error_mark_node)
                   1875:            return error_mark_node;
                   1876:          instance_ptr = save_expr (instance_ptr);
                   1877:          TREE_CALLS_NEW (instance_ptr) = 1;
1.1.1.5 ! root     1878:          instance = build_indirect_ref (instance_ptr, NULL);
1.1.1.4   root     1879: 
                   1880:          /* If it's a default argument initialized from a ctor, what we get
                   1881:             from instance_ptr will match the arglist for the FUNCTION_DECL
                   1882:             of the constructor.  */
                   1883:          if (parms && TREE_CODE (TREE_VALUE (parms)) == CALL_EXPR
                   1884:              && TREE_OPERAND (TREE_VALUE (parms), 1)
                   1885:              && TREE_CALLS_NEW (TREE_VALUE (TREE_OPERAND (TREE_VALUE (parms), 1))))
                   1886:            parms = build_tree_list (NULL_TREE, instance_ptr);
                   1887:          else
                   1888:            parms = tree_cons (NULL_TREE, instance_ptr, parms);
1.1       root     1889:        }
                   1890:     }
                   1891:   parmtypes = tree_cons (NULL_TREE,
                   1892:                         build_pointer_type (build_type_variant (basetype, constp, volatilep)),
                   1893:                         parmtypes);
                   1894:   if (last == NULL_TREE)
                   1895:     last = parmtypes;
                   1896: 
                   1897:   /* Look up function name in the structure type definition.  */
                   1898: 
1.1.1.4   root     1899:   if ((IDENTIFIER_HAS_TYPE_VALUE (name)
                   1900:        && IS_AGGR_TYPE (IDENTIFIER_TYPE_VALUE (name)))
                   1901:       || name == constructor_name (basetype))
1.1       root     1902:     {
1.1.1.4   root     1903:       tree tmp = NULL_TREE;
                   1904:       if (IDENTIFIER_TYPE_VALUE (name) == basetype
1.1       root     1905:          || name == constructor_name (basetype))
1.1.1.4   root     1906:        tmp = TYPE_BINFO (basetype);
                   1907:       else
                   1908:        tmp = get_binfo (IDENTIFIER_TYPE_VALUE (name), basetype, 0);
                   1909:       
1.1.1.5 ! root     1910:       if (tmp != NULL_TREE)
1.1.1.4   root     1911:        {
                   1912:          name_kind = "constructor";
                   1913:          
                   1914:          if (TYPE_USES_VIRTUAL_BASECLASSES (basetype)
                   1915:              && ! (flags & LOOKUP_HAS_IN_CHARGE))
                   1916:            {
                   1917:              /* Constructors called for initialization
                   1918:                 only are never in charge.  */
                   1919:              tree tmplist;
                   1920:              
                   1921:              flags |= LOOKUP_HAS_IN_CHARGE;
                   1922:              tmplist = tree_cons (NULL_TREE, integer_zero_node,
                   1923:                                   TREE_CHAIN (parms));
                   1924:              TREE_CHAIN (parms) = tmplist;
                   1925:              tmplist = tree_cons (NULL_TREE, integer_type_node, TREE_CHAIN (parmtypes));
                   1926:              TREE_CHAIN (parmtypes) = tmplist;
                   1927:            }
                   1928:          basetype = BINFO_TYPE (tmp);
1.1       root     1929:        }
1.1.1.4   root     1930:       else
                   1931:        name_kind = "method";
1.1       root     1932:     }
1.1.1.4   root     1933:   else name_kind = "method";
                   1934:   
                   1935:   if (basetype_path == NULL_TREE)
                   1936:     basetype_path = TYPE_BINFO (basetype);
                   1937:   result = lookup_fnfields (basetype_path, name,
                   1938:                            (flags & LOOKUP_COMPLAIN));
                   1939:   if (result == error_mark_node)
                   1940:     return error_mark_node;
                   1941: 
1.1       root     1942: 
                   1943:   /* Now, go look for this method name.  We do not find destructors here.
                   1944: 
                   1945:      Putting `void_list_node' on the end of the parmtypes
                   1946:      fakes out `build_decl_overload' into doing the right thing.  */
                   1947:   TREE_CHAIN (last) = void_list_node;
1.1.1.2   root     1948:   method_name = build_decl_overload (name, parmtypes,
1.1       root     1949:                                     1 + (name == constructor_name (save_basetype)));
                   1950:   TREE_CHAIN (last) = NULL_TREE;
                   1951: 
                   1952:   for (pass = 0; pass < 2; pass++)
                   1953:     {
                   1954:       struct candidate *candidates;
                   1955:       struct candidate *cp;
                   1956:       int len;
1.1.1.5 ! root     1957:       unsigned best = 1;
1.1       root     1958: 
                   1959:       /* This increments every time we go up the type hierarchy.
1.1.1.4   root     1960:         The idea is to prefer a function of the derived class if possible. */
                   1961:       int b_or_d = 0;
1.1       root     1962: 
                   1963:       baselink = result;
                   1964: 
                   1965:       if (pass > 0)
                   1966:        {
1.1.1.4   root     1967:          candidates
                   1968:            = (struct candidate *) alloca ((ever_seen+1)
                   1969:                                           * sizeof (struct candidate));
1.1       root     1970:          cp = candidates;
                   1971:          len = list_length (parms);
                   1972: 
                   1973:          /* First see if a global function has a shot at it.  */
                   1974:          if (flags & LOOKUP_GLOBAL)
                   1975:            {
                   1976:              tree friend_parms;
                   1977:              tree parm = TREE_VALUE (parms);
                   1978: 
                   1979:              if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE)
                   1980:                friend_parms = parms;
                   1981:              else if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
                   1982:                {
1.1.1.3   root     1983:                  tree new_type;
1.1       root     1984:                  parm = build_indirect_ref (parm, "friendifying parms (compiler error)");
1.1.1.3   root     1985:                  new_type = build_reference_type (TREE_TYPE (parm));
                   1986:                  /* It is possible that this should go down a layer. */
                   1987:                  new_type = build_type_variant (new_type,
                   1988:                                                 TREE_READONLY (parm),
                   1989:                                                 TREE_THIS_VOLATILE (parm));
                   1990:                  parm = convert (new_type, parm);
1.1       root     1991:                  friend_parms = tree_cons (NULL_TREE, parm, TREE_CHAIN (parms));
                   1992:                }
                   1993:              else
1.1.1.5 ! root     1994:                my_friendly_abort (167);
1.1       root     1995: 
                   1996:              cp->harshness
                   1997:                = (unsigned short *)alloca ((len+1) * sizeof (short));
                   1998:              result = build_overload_call (name, friend_parms, 0, cp);
                   1999:              /* If it turns out to be the one we were actually looking for
                   2000:                 (it was probably a friend function), the return the
                   2001:                 good result.  */
                   2002:              if (TREE_CODE (result) == CALL_EXPR)
                   2003:                return result;
                   2004: 
                   2005:              while (cp->evil == 0)
                   2006:                {
                   2007:                  /* non-standard uses: set the field to 0 to indicate
                   2008:                     we are using a non-member function.  */
                   2009:                  cp->u.field = 0;
                   2010:                  if (cp->harshness[len] == 0
                   2011:                      && cp->harshness[len] == 0
                   2012:                      && cp->user == 0 && cp->b_or_d == 0
                   2013:                      && cp->easy < best)
                   2014:                    best = cp->easy;
                   2015:                  cp += 1;
                   2016:                }
                   2017:            }
                   2018:        }
                   2019: 
                   2020:       while (baselink)
                   2021:        {
                   2022:          /* We have a hit (of sorts). If the parameter list is
                   2023:             "error_mark_node", or some variant thereof, it won't
                   2024:             match any methods.  Since we have verified that the is
                   2025:             some method vaguely matching this one (in name at least),
                   2026:             silently return.
                   2027:             
                   2028:             Don't stop for friends, however.  */
                   2029:          tree basetypes = TREE_PURPOSE (baselink);
                   2030: 
                   2031:          function = TREE_VALUE (baselink);
                   2032:          if (TREE_CODE (basetypes) == TREE_LIST)
                   2033:            basetypes = TREE_VALUE (basetypes);
                   2034:          basetype = BINFO_TYPE (basetypes);
                   2035: 
1.1.1.2   root     2036:          /* Cast the instance variable to the appropriate type.  */
1.1       root     2037:          TREE_VALUE (parmtypes) = TYPE_POINTER_TO (basetype);
                   2038: 
                   2039:          if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (function)))
                   2040:            function = DECL_CHAIN (function);
                   2041: 
                   2042:          for (; function; function = DECL_CHAIN (function))
                   2043:            {
                   2044: #ifdef GATHER_STATISTICS
                   2045:              n_inner_fields_searched++;
                   2046: #endif
                   2047:              ever_seen++;
                   2048: 
                   2049:              /* Not looking for friends here.  */
                   2050:              if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE
                   2051:                  && ! DECL_STATIC_FUNCTION_P (function))
                   2052:                continue;
                   2053: 
                   2054:              if (pass == 0
                   2055:                  && DECL_ASSEMBLER_NAME (function) == method_name)
                   2056:                {
                   2057:                  if (flags & LOOKUP_PROTECT)
                   2058:                    {
                   2059:                      visibility = compute_visibility (basetypes, function);
                   2060:                      if (visibility == visibility_protected
                   2061:                          && flags & LOOKUP_PROTECTED_OK)
                   2062:                        visibility = visibility_public;
                   2063:                    }
                   2064: 
                   2065:                  if ((flags & LOOKUP_PROTECT) == 0
                   2066:                      || visibility == visibility_public)
                   2067:                    goto found_and_ok;
                   2068:                  else if (visibility == visibility_private)
                   2069:                    saw_private = function;
                   2070:                  else if (visibility == visibility_protected)
                   2071:                    saw_protected = function;
                   2072:                  /* If we fail on the exact match, we have
                   2073:                     an immediate failure.  */
                   2074:                  goto found;
                   2075:                }
                   2076:              if (pass > 0)
                   2077:                {
                   2078:                  tree these_parms = parms;
                   2079: 
                   2080: #ifdef GATHER_STATISTICS
                   2081:                  n_inner_fields_searched++;
                   2082: #endif
                   2083:                  cp->harshness
                   2084:                    = (unsigned short *)alloca ((len+1) * sizeof (short));
                   2085:                  if (DECL_STATIC_FUNCTION_P (function))
                   2086:                    these_parms = TREE_CHAIN (these_parms);
                   2087:                  compute_conversion_costs (function, these_parms, cp, len);
                   2088:                  cp->b_or_d += b_or_d;
                   2089:                  if (cp->evil == 0)
                   2090:                    {
                   2091:                      cp->u.field = function;
                   2092:                      cp->function = function;
                   2093:                      if (flags & LOOKUP_PROTECT)
                   2094:                        {
                   2095:                          enum visibility_type this_v;
                   2096:                          this_v = compute_visibility (basetypes, function);
                   2097:                          if (this_v == visibility_protected
                   2098:                              && (flags & LOOKUP_PROTECTED_OK))
                   2099:                            this_v = visibility_public;
                   2100:                          if (this_v != visibility_public)
                   2101:                            {
                   2102:                              if (this_v == visibility_private)
                   2103:                                saw_private = function;
                   2104:                              else
                   2105:                                saw_protected = function;
                   2106:                              continue;
                   2107:                            }
                   2108:                        }
                   2109: 
                   2110:                      /* No "two-level" conversions.  */
                   2111:                      if (flags & LOOKUP_NO_CONVERSION && cp->user != 0)
                   2112:                        continue;
                   2113: 
                   2114:                      /* If we used default parameters, we must
                   2115:                         check to see whether anyone else might
                   2116:                         use them also, and report a possible
                   2117:                         ambiguity.  */
                   2118:                      if (! TYPE_USES_MULTIPLE_INHERITANCE (save_basetype)
                   2119:                          && cp->harshness[len] == 0
                   2120:                          && CONST_HARSHNESS (cp->harshness[0]) == 0
                   2121:                          && cp->user == 0 && cp->b_or_d == 0
                   2122:                          && cp->easy < best)
                   2123:                        {
                   2124:                          if (! DECL_STATIC_FUNCTION_P (function))
                   2125:                            TREE_VALUE (parms) = cp->arg;
1.1.1.5 ! root     2126:                          if (best == 1)
1.1       root     2127:                            goto found_and_maybe_warn;
                   2128:                        }
                   2129:                      cp++;
                   2130:                    }
                   2131:                }
                   2132:            }
                   2133:          /* Now we have run through one link's member functions.
                   2134:             arrange to head-insert this link's links.  */
                   2135:          baselink = next_baselink (baselink);
                   2136:          b_or_d += 1;
                   2137:        }
                   2138:       if (pass == 0)
                   2139:        {
                   2140:          /* No exact match could be found.  Now try to find match
                   2141:             using default conversions.  */
                   2142:          if ((flags & LOOKUP_GLOBAL) && IDENTIFIER_GLOBAL_VALUE (name))
                   2143:            if (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == FUNCTION_DECL)
                   2144:              ever_seen += 1;
                   2145:            else if (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (name)) == TREE_LIST)
                   2146:              ever_seen += list_length (IDENTIFIER_GLOBAL_VALUE (name));
                   2147: 
                   2148:          if (ever_seen == 0)
                   2149:            {
1.1.1.4   root     2150:              if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN))
                   2151:                  == LOOKUP_SPECULATIVELY)
                   2152:                return NULL_TREE;
1.1       root     2153:              if (flags & LOOKUP_GLOBAL)
1.1.1.5 ! root     2154:                error ("no global or non-hidden member function `%s' defined", err_name);
1.1       root     2155:              else
1.1.1.5 ! root     2156:                error_with_aggr_type (save_basetype, "no non-hidden member function `%s::%s' defined", err_name);
1.1       root     2157:              return error_mark_node;
                   2158:            }
                   2159:          continue;
                   2160:        }
                   2161: 
                   2162:       if (cp - candidates != 0)
                   2163:        {
                   2164:          /* Rank from worst to best.  Then cp will point to best one.
                   2165:             Private fields have their bits flipped.  For unsigned
                   2166:             numbers, this should make them look very large.
                   2167:             If the best alternate has a (signed) negative value,
                   2168:             then all we ever saw were private members.  */
                   2169:          if (cp - candidates > 1)
                   2170:            {
                   2171:              cp = ideal_candidate (save_basetype, candidates,
                   2172:                                    cp - candidates, parms, len);
1.1.1.5 ! root     2173:              if (cp == (struct candidate *)0)
1.1       root     2174:                {
                   2175:                  error ("ambiguous type conversion requested for %s `%s'",
                   2176:                         name_kind, err_name);
                   2177:                  return error_mark_node;
                   2178:                }
                   2179:              if (cp->evil)
                   2180:                return error_mark_node;
                   2181:            }
                   2182:          else if (cp[-1].evil == 2)
                   2183:            {
                   2184:              error ("ambiguous type conversion requested for %s `%s'",
                   2185:                     name_kind, err_name);
                   2186:              return error_mark_node;
                   2187:            }
                   2188:          else cp--;
                   2189: 
                   2190:          /* The global function was the best, so use it.  */
                   2191:          if (cp->u.field == 0)
                   2192:            {
                   2193:              /* We must convert the instance pointer into a reference type.
                   2194:                 Global overloaded functions can only either take
                   2195:                 aggregate objects (which come for free from references)
                   2196:                 or reference data types anyway.  */
                   2197:              TREE_VALUE (parms) = copy_node (instance_ptr);
                   2198:              TREE_TYPE (TREE_VALUE (parms)) = build_reference_type (TREE_TYPE (TREE_TYPE (instance_ptr)));
                   2199:              return build_function_call (cp->function, parms);
                   2200:            }
                   2201: 
                   2202:          function = cp->function;
                   2203:          if (! DECL_STATIC_FUNCTION_P (function))
                   2204:            TREE_VALUE (parms) = cp->arg;
                   2205:          goto found_and_maybe_warn;
                   2206:        }
                   2207: 
                   2208:       if ((flags & ~LOOKUP_GLOBAL) & (LOOKUP_COMPLAIN|LOOKUP_SPECULATIVELY))
                   2209:        {
                   2210:          char *tag_name, *buf;
                   2211: 
                   2212:          if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN))
                   2213:              == LOOKUP_SPECULATIVELY)
                   2214:            return NULL_TREE;
                   2215: 
                   2216:          if (DECL_STATIC_FUNCTION_P (cp->function))
                   2217:            parms = TREE_CHAIN (parms);
                   2218:          if (ever_seen)
                   2219:            {
1.1.1.4   root     2220:              if (((HOST_WIDE_INT)saw_protected|(HOST_WIDE_INT)saw_private) == 0)
1.1       root     2221:                {
                   2222:                  if (flags & LOOKUP_SPECULATIVELY)
                   2223:                    return NULL_TREE;
                   2224:                  if (static_call_context && TREE_CODE (TREE_TYPE (cp->function)) == METHOD_TYPE)
                   2225:                    error_with_aggr_type (TREE_TYPE (TREE_TYPE (instance_ptr)),
                   2226:                                          "object missing in call to `%s::%s'",
                   2227:                                          err_name);
                   2228:                  else
                   2229:                    report_type_mismatch (cp, parms, name_kind, err_name);
                   2230:                }
                   2231:              else
                   2232:                {
                   2233:                  char buf[80];
                   2234:                  char *msg;
                   2235:                  tree seen = saw_private;
                   2236: 
                   2237:                  if (saw_private)
1.1.1.5 ! root     2238:                    {
        !          2239:                      if (saw_protected)
        !          2240:                        msg = "%s `%%s' (and the like) are private or protected";
        !          2241:                      else
        !          2242:                        msg = "the %s `%%s' is private";
        !          2243:                    }
1.1       root     2244:                  else
                   2245:                    {
1.1.1.5 ! root     2246:                      msg = "the %s `%%s' is protected";
1.1       root     2247:                      seen = saw_protected;
                   2248:                    }
                   2249:                  sprintf (buf, msg, name_kind);
                   2250:                  error_with_decl (seen, buf);
                   2251:                  error ("within this context");
                   2252:                }
                   2253:              return error_mark_node;
                   2254:            }
                   2255: 
                   2256:          if ((flags & (LOOKUP_SPECULATIVELY|LOOKUP_COMPLAIN))
                   2257:              == LOOKUP_COMPLAIN)
                   2258:            {
                   2259:              if (TREE_CODE (save_basetype) == RECORD_TYPE)
                   2260:                tag_name = "structure";
                   2261:              else
                   2262:                tag_name = "union";
                   2263: 
1.1.1.4   root     2264:              buf = (char *)alloca (30 + strlen (err_name));
                   2265:              strcpy (buf, "%s has no method named `%s'");
1.1       root     2266:              error (buf, tag_name, err_name);
                   2267:              return error_mark_node;
                   2268:            }
                   2269:          return NULL_TREE;
                   2270:        }
                   2271:       continue;
                   2272: 
                   2273:     found_and_maybe_warn:
                   2274:       if (CONST_HARSHNESS (cp->harshness[0]))
                   2275:        {
                   2276:          if (flags & LOOKUP_COMPLAIN)
                   2277:            {
                   2278:              error_with_decl (cp->function, "non-const member function `%s'");
                   2279:              error ("called for const object at this point in file");
                   2280:            }
                   2281:          /* Not good enough for a match.  */
1.1.1.5 ! root     2282:          else
        !          2283:            return error_mark_node;
1.1       root     2284:        }
                   2285:       goto found_and_ok;
                   2286:     }
                   2287:   /* Silently return error_mark_node.  */
                   2288:   return error_mark_node;
                   2289: 
                   2290:  found:
                   2291:   if (visibility == visibility_private)
                   2292:     {
                   2293:       if (flags & LOOKUP_COMPLAIN)
1.1.1.5 ! root     2294:        {
        !          2295:          error_with_file_and_line (DECL_SOURCE_FILE (function),
        !          2296:                                    DECL_SOURCE_LINE (function),
        !          2297:                                    TREE_PRIVATE (function)
        !          2298:                                    ? "%s `%s' is private"
        !          2299:                                    : "%s `%s' is from private base class",
        !          2300:                                    name_kind,
        !          2301:                                    lang_printable_name (function));
        !          2302:          error ("within this context");
        !          2303:        }
1.1       root     2304:       return error_mark_node;
                   2305:     }
                   2306:   else if (visibility == visibility_protected)
                   2307:     {
                   2308:       if (flags & LOOKUP_COMPLAIN)
1.1.1.5 ! root     2309:        {
        !          2310:          error_with_file_and_line (DECL_SOURCE_FILE (function),
        !          2311:                                    DECL_SOURCE_LINE (function),
        !          2312:                                    TREE_PROTECTED (function)
        !          2313:                                    ? "%s `%s' is protected"
        !          2314:                                    : "%s `%s' has protected visibility from this point",
        !          2315:                                    name_kind,
        !          2316:                                    lang_printable_name (function));
        !          2317:          error ("within this context");
        !          2318:        }
1.1       root     2319:       return error_mark_node;
                   2320:     }
1.1.1.3   root     2321:   my_friendly_abort (1);
1.1       root     2322: 
                   2323:  found_and_ok:
                   2324: 
                   2325:   /* From here on down, BASETYPE is the type that INSTANCE_PTR's
                   2326:      type (if it exists) is a pointer to.  */
                   2327:   function = DECL_MAIN_VARIANT (function);
                   2328:   /* Declare external function if necessary. */
                   2329:   assemble_external (function);
                   2330: 
                   2331:   fntype = TREE_TYPE (function);
                   2332:   if (TREE_CODE (fntype) == POINTER_TYPE)
                   2333:     fntype = TREE_TYPE (fntype);
                   2334:   basetype = DECL_CLASS_CONTEXT (function);
                   2335: 
                   2336:   /* If we are referencing a virtual function from an object
                   2337:      of effectively static type, then there is no need
                   2338:      to go through the virtual function table.  */
                   2339:   if (need_vtbl == maybe_needed)
                   2340:     {
                   2341:       int fixed_type = resolves_to_fixed_type_p (instance, 0);
                   2342: 
                   2343:       if (all_virtual == 1
                   2344:          && DECL_VINDEX (function)
                   2345:          && may_be_remote (basetype))
                   2346:        need_vtbl = needed;
                   2347:       else if (DECL_VINDEX (function))
                   2348:        need_vtbl = fixed_type ? unneeded : needed;
                   2349:       else
                   2350:        need_vtbl = not_needed;
                   2351:     }
                   2352: 
1.1.1.5 ! root     2353:   if (TREE_CODE (fntype) == METHOD_TYPE && static_call_context
        !          2354:       && !DECL_CONSTRUCTOR_P (function))
1.1       root     2355:     {
                   2356:       /* Let's be nice to the user for now, and give reasonable
                   2357:         default behavior.  */
                   2358:       instance_ptr = current_class_decl;
                   2359:       if (instance_ptr)
                   2360:        {
                   2361:          if (basetype != current_class_type)
                   2362:            {
                   2363:              tree binfo = get_binfo (basetype, current_class_type, 1);
1.1.1.5 ! root     2364:              if (binfo == NULL_TREE)
1.1       root     2365:                {
                   2366:                  error_not_base_type (function, current_class_type);
                   2367:                  return error_mark_node;
                   2368:                }
                   2369:              else if (basetype == error_mark_node)
                   2370:                return error_mark_node;
                   2371:            }
                   2372:        }
1.1.1.4   root     2373:       else if (! TREE_STATIC (function))
1.1       root     2374:        {
                   2375:          error_with_aggr_type (basetype, "cannot call member function `%s::%s' without object",
                   2376:                                err_name);
                   2377:          return error_mark_node;
                   2378:        }
                   2379:     }
                   2380: 
                   2381:   value_type = TREE_TYPE (fntype) ? TREE_TYPE (fntype) : void_type_node;
                   2382: 
                   2383:   if (TYPE_SIZE (value_type) == 0)
                   2384:     {
                   2385:       if (flags & LOOKUP_COMPLAIN)
                   2386:        incomplete_type_error (0, value_type);
                   2387:       return error_mark_node;
                   2388:     }
                   2389: 
                   2390:   /* We do not pass FUNCTION into `convert_arguments', because by
                   2391:      now everything should be ok.  If not, then we have a serious error.  */
                   2392:   if (DECL_STATIC_FUNCTION_P (function))
                   2393:     parms = convert_arguments (NULL_TREE, TYPE_ARG_TYPES (fntype),
                   2394:                               TREE_CHAIN (parms), NULL_TREE, LOOKUP_NORMAL);
                   2395:   else if (need_vtbl == unneeded)
                   2396:     {
                   2397:       int sub_flags = DECL_CONSTRUCTOR_P (function) ? flags : LOOKUP_NORMAL;
                   2398:       basetype = TREE_TYPE (instance);
                   2399:       if (TYPE_METHOD_BASETYPE (TREE_TYPE (function)) != TYPE_MAIN_VARIANT (basetype)
                   2400:          && TYPE_USES_COMPLEX_INHERITANCE (basetype))
                   2401:        {
                   2402:          basetype = DECL_CLASS_CONTEXT (function);
                   2403:          instance_ptr = convert_pointer_to (basetype, instance_ptr);
1.1.1.5 ! root     2404:          instance = build_indirect_ref (instance_ptr, NULL);
1.1       root     2405:        }
                   2406:       parms = tree_cons (NULL_TREE, instance_ptr,
                   2407:                         convert_arguments (NULL_TREE, TREE_CHAIN (TYPE_ARG_TYPES (fntype)), TREE_CHAIN (parms), NULL_TREE, sub_flags));
                   2408:     }
                   2409:   else
                   2410:     {
                   2411:       if ((flags & LOOKUP_NONVIRTUAL) == 0)
                   2412:        basetype = DECL_CONTEXT (function);
                   2413: 
                   2414:       /* First parm could be integer_zerop with casts like
                   2415:         ((Object*)0)->Object::IsA()  */
                   2416:       if (!integer_zerop (TREE_VALUE (parms)))
                   2417:        {
                   2418:          instance_ptr = convert_pointer_to (build_type_variant (basetype, constp, volatilep),
                   2419:                                             TREE_VALUE (parms));
                   2420:          if (TREE_CODE (instance_ptr) == COND_EXPR)
                   2421:            {
                   2422:              instance_ptr = save_expr (instance_ptr);
1.1.1.5 ! root     2423:              instance = build_indirect_ref (instance_ptr, NULL);
1.1       root     2424:            }
                   2425:          else if (TREE_CODE (instance_ptr) == NOP_EXPR
                   2426:                   && TREE_CODE (TREE_OPERAND (instance_ptr, 0)) == ADDR_EXPR
                   2427:                   && TREE_OPERAND (TREE_OPERAND (instance_ptr, 0), 0) == instance)
                   2428:            ;
1.1.1.4   root     2429:          /* The call to `convert_pointer_to' may return error_mark_node.  */
                   2430:          else if (TREE_CODE (instance_ptr) == ERROR_MARK)
                   2431:            return instance_ptr;
1.1       root     2432:          else if (instance == NULL_TREE
                   2433:                   || TREE_CODE (instance) != INDIRECT_REF
                   2434:                   || TREE_OPERAND (instance, 0) != instance_ptr)
1.1.1.5 ! root     2435:            instance = build_indirect_ref (instance_ptr, NULL);
1.1       root     2436:        }
                   2437:       parms = tree_cons (NULL_TREE, instance_ptr,
                   2438:                         convert_arguments (NULL_TREE, TREE_CHAIN (TYPE_ARG_TYPES (fntype)), TREE_CHAIN (parms), NULL_TREE, LOOKUP_NORMAL));
                   2439:     }
                   2440: 
                   2441: #if 0
                   2442:   /* Constructors do not overload method calls.  */
                   2443:   else if (TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype)
                   2444:           && name != TYPE_IDENTIFIER (basetype)
                   2445:           && (TREE_CODE (function) != FUNCTION_DECL
                   2446:               || strncmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)),
                   2447:                           OPERATOR_METHOD_FORMAT,
                   2448:                           OPERATOR_METHOD_LENGTH))
                   2449: #if 0
                   2450:           && (may_be_remote (basetype)
                   2451:               || (C_C_D ? TREE_TYPE (instance) != current_class_type : 1))
                   2452: #else
                   2453:           /* This change by Larry Ketcham.  */
                   2454:           && (may_be_remote (basetype) || instance != C_C_D)
                   2455: #endif
                   2456:           )
                   2457:     {
                   2458:       tree fn_as_int;
                   2459: 
                   2460:       parms = TREE_CHAIN (parms);
                   2461: 
                   2462:       if (!all_virtual && TREE_CODE (function) == FUNCTION_DECL)
                   2463:        fn_as_int = build_unary_op (ADDR_EXPR, function, 0);
                   2464:       else
                   2465:        fn_as_int = convert (TREE_TYPE (default_conversion (function)), DECL_VINDEX (function));
                   2466:       if (all_virtual == 1)
                   2467:        fn_as_int = convert (integer_type_node, fn_as_int);
                   2468: 
                   2469:       result = build_opfncall (METHOD_CALL_EXPR, LOOKUP_NORMAL, instance, fn_as_int, parms);
                   2470: 
                   2471:       if (result == NULL_TREE)
                   2472:        {
                   2473:          compiler_error ("could not overload `operator->()(...)'");
                   2474:          return error_mark_node;
                   2475:        }
                   2476:       else if (result == error_mark_node)
                   2477:        return error_mark_node;
                   2478: 
                   2479: #if 0
                   2480:       /* Do this if we want the result of operator->() to inherit
                   2481:         the type of the function it is subbing for.  */
                   2482:       TREE_TYPE (result) = value_type;
                   2483: #endif
                   2484: 
                   2485:       return result;
                   2486:     }
                   2487: #endif
                   2488: 
                   2489:   if (need_vtbl == needed)
                   2490:     {
                   2491:       function = build_vfn_ref (&TREE_VALUE (parms), instance, DECL_VINDEX (function));
                   2492:       TREE_TYPE (function) = build_pointer_type (fntype);
                   2493:     }
                   2494: 
1.1.1.5 ! root     2495:   if (TREE_CODE (function) == FUNCTION_DECL)
        !          2496:     GNU_xref_call (current_function_decl,
        !          2497:                   IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function)));
1.1       root     2498: 
                   2499:   if (TREE_CODE (function) == FUNCTION_DECL)
                   2500:     {
1.1.1.4   root     2501:       if (DECL_INLINE (function))
1.1       root     2502:        function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
                   2503:       else
                   2504:        {
1.1.1.2   root     2505:          assemble_external (function);
1.1       root     2506:          TREE_USED (function) = 1;
                   2507:          function = default_conversion (function);
                   2508:        }
                   2509:     }
                   2510:   else
                   2511:     function = default_conversion (function);
                   2512: 
                   2513:   result =
                   2514:     build_nt (CALL_EXPR, function, parms, NULL_TREE);
                   2515: 
                   2516:   TREE_TYPE (result) = value_type;
                   2517:   TREE_SIDE_EFFECTS (result) = 1;
                   2518:   TREE_RAISES (result)
                   2519:     = TYPE_RAISES_EXCEPTIONS (fntype) || (parms && TREE_RAISES (parms));
                   2520:   return result;
                   2521: }
                   2522: 
                   2523: /* Similar to `build_method_call', but for overloaded non-member functions.
                   2524:    The name of this function comes through NAME.  The name depends
                   2525:    on PARMS.
                   2526: 
                   2527:    Note that this function must handle simple `C' promotions,
                   2528:    as well as variable numbers of arguments (...), and
                   2529:    default arguments to boot.
                   2530: 
                   2531:    If the overloading is successful, we return a tree node which
                   2532:    contains the call to the function.
                   2533: 
                   2534:    If overloading produces candidates which are probable, but not definite,
                   2535:    we hold these candidates.  If FINAL_CP is non-zero, then we are free
                   2536:    to assume that final_cp points to enough storage for all candidates that
                   2537:    this function might generate.  The `harshness' array is preallocated for
                   2538:    the first candidate, but not for subsequent ones.
                   2539: 
                   2540:    Note that the DECL_RTL of FUNCTION must be made to agree with this
                   2541:    function's new name.  */
                   2542: 
                   2543: tree
                   2544: build_overload_call_real (fnname, parms, complain, final_cp, buildxxx)
                   2545:      tree fnname, parms;
                   2546:      int complain;
                   2547:      struct candidate *final_cp;
                   2548:      int buildxxx;
                   2549: {
                   2550:   /* must check for overloading here */
                   2551:   tree overload_name, functions, function, parm;
                   2552:   tree parmtypes = NULL_TREE, last = NULL_TREE;
                   2553:   register tree outer;
                   2554:   int length;
                   2555:   int parmlength = list_length (parms);
                   2556: 
                   2557:   struct candidate *candidates, *cp;
                   2558: 
                   2559:   if (final_cp)
                   2560:     {
                   2561:       final_cp[0].evil = 0;
                   2562:       final_cp[0].user = 0;
                   2563:       final_cp[0].b_or_d = 0;
                   2564:       final_cp[0].easy = 0;
                   2565:       final_cp[0].function = 0;
                   2566:       /* end marker.  */
                   2567:       final_cp[1].evil = 1;
                   2568:     }
                   2569: 
                   2570:   for (parm = parms; parm; parm = TREE_CHAIN (parm))
                   2571:     {
                   2572:       register tree t = TREE_TYPE (TREE_VALUE (parm));
                   2573: 
                   2574:       if (t == error_mark_node)
1.1.1.3   root     2575:        {
                   2576:          if (final_cp)
                   2577:            final_cp->evil = 1;
                   2578:          return error_mark_node;
                   2579:        }
1.1       root     2580:       if (TREE_CODE (t) == ARRAY_TYPE || TREE_CODE (t) == OFFSET_TYPE)
                   2581:        {
                   2582:          /* Perform the conversion from ARRAY_TYPE to POINTER_TYPE in place.
                   2583:             Also convert OFFSET_TYPE entities to their normal selves.
                   2584:             This eliminates needless calls to `compute_conversion_costs'.  */
                   2585:          TREE_VALUE (parm) = default_conversion (TREE_VALUE (parm));
                   2586:          t = TREE_TYPE (TREE_VALUE (parm));
                   2587:        }
                   2588:       last = build_tree_list (NULL_TREE, t);
                   2589:       parmtypes = chainon (parmtypes, last);
                   2590:     }
                   2591:   if (last)
                   2592:     TREE_CHAIN (last) = void_list_node;
                   2593:   else
                   2594:     parmtypes = void_list_node;
1.1.1.2   root     2595:   overload_name = build_decl_overload (fnname, parmtypes, 0);
1.1       root     2596: 
                   2597:   /* Now check to see whether or not we can win.
                   2598:      Note that if we are called from `build_method_call',
                   2599:      then we cannot have a mis-match, because we would have
                   2600:      already found such a winning case.  */
                   2601: 
                   2602:   if (IDENTIFIER_GLOBAL_VALUE (overload_name))
                   2603:     if (TREE_CODE (IDENTIFIER_GLOBAL_VALUE (overload_name)) != TREE_LIST)
                   2604:       return build_function_call (DECL_MAIN_VARIANT (IDENTIFIER_GLOBAL_VALUE (overload_name)), parms);
                   2605: 
                   2606:   functions = IDENTIFIER_GLOBAL_VALUE (fnname);
                   2607: 
                   2608:   if (functions == NULL_TREE)
                   2609:     {
                   2610:       if (complain)
                   2611:        error ("only member functions apply");
                   2612:       if (final_cp)
                   2613:        final_cp->evil = 1;
                   2614:       return error_mark_node;
                   2615:     }
                   2616: 
                   2617:   if (TREE_CODE (functions) == FUNCTION_DECL)
                   2618:     {
                   2619:       functions = DECL_MAIN_VARIANT (functions);
                   2620:       if (final_cp)
                   2621:        {
                   2622:          /* We are just curious whether this is a viable alternative or not.  */
                   2623:          compute_conversion_costs (functions, parms, final_cp, parmlength);
                   2624:          return functions;
                   2625:        }
                   2626:       else
                   2627:        return build_function_call (functions, parms);
                   2628:     }
                   2629: 
                   2630:   if (TREE_VALUE (functions) == NULL_TREE)
                   2631:     {
                   2632:       if (complain)
                   2633:        error ("function `%s' declared overloaded, but no instances of that function declared",
                   2634:               IDENTIFIER_POINTER (TREE_PURPOSE (functions)));
1.1.1.3   root     2635:       if (final_cp)
                   2636:        final_cp->evil = 1;
1.1       root     2637:       return error_mark_node;
                   2638:     }
                   2639: 
                   2640:   if (TREE_CODE (TREE_VALUE (functions)) == TREE_LIST)
                   2641:     {
                   2642:       register tree outer;
                   2643:       length = 0;
                   2644: 
                   2645:       /* The list-of-lists should only occur for class things.  */
1.1.1.4   root     2646:       my_friendly_assert (functions == IDENTIFIER_CLASS_VALUE (fnname), 168);
1.1       root     2647: 
                   2648:       for (outer = functions; outer; outer = TREE_CHAIN (outer))
                   2649:        {
                   2650:          /* member functions.  */
                   2651:          length += decl_list_length (TREE_VALUE (TREE_VALUE (outer)));
                   2652:          /* friend functions.  */
                   2653:          length += list_length (TREE_TYPE (TREE_VALUE (outer)));
                   2654:        }
                   2655:     }
                   2656:   else
                   2657:     {
                   2658:       length = list_length (functions);
                   2659:     }
                   2660: 
                   2661:   if (final_cp)
                   2662:     candidates = final_cp;
                   2663:   else
                   2664:     candidates = (struct candidate *)alloca ((length+1) * sizeof (struct candidate));
                   2665: 
                   2666:   cp = candidates;
                   2667: 
1.1.1.4   root     2668:   my_friendly_assert (TREE_CODE (TREE_VALUE (functions)) != TREE_LIST, 169);
1.1       root     2669:   /* OUTER is the list of FUNCTION_DECLS, in a TREE_LIST.  */
                   2670: 
                   2671:   for (outer = functions; outer; outer = TREE_CHAIN (outer))
                   2672:     {
                   2673:       int template_cost = 0;
                   2674:       function = TREE_VALUE (outer);
                   2675:       if (TREE_CODE (function) != FUNCTION_DECL
                   2676:          && ! (TREE_CODE (function) == TEMPLATE_DECL
                   2677:                && ! DECL_TEMPLATE_IS_CLASS (function)
                   2678:                && TREE_CODE (DECL_TEMPLATE_RESULT (function)) == FUNCTION_DECL))
                   2679:        {
                   2680:          enum tree_code code = TREE_CODE (function);
                   2681:          if (code == TEMPLATE_DECL)
                   2682:            code = TREE_CODE (DECL_TEMPLATE_RESULT (function));
                   2683:          if (code == CONST_DECL)
                   2684:            error_with_decl (function, "enumeral value `%s' conflicts with function of same name");
                   2685:          else if (code == VAR_DECL)
                   2686:            if (TREE_STATIC (function))
                   2687:              error_with_decl (function, "variable `%s' conflicts with function of same name");
                   2688:            else
                   2689:              error_with_decl (function, "constant field `%s' conflicts with function of same name");
                   2690:          else if (code == TYPE_DECL)
                   2691:            continue;
1.1.1.3   root     2692:          else my_friendly_abort (2);
1.1       root     2693:          error ("at this point in file");
                   2694:          continue;
                   2695:        }
                   2696:       if (TREE_CODE (function) == TEMPLATE_DECL)
                   2697:        {
                   2698:          int ntparms = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (function));
                   2699:          tree *targs = (tree *) alloca (sizeof (tree) * ntparms);
                   2700:          int i;
                   2701: 
                   2702:          i = type_unification (DECL_TEMPLATE_PARMS (function), targs,
                   2703:                                TYPE_ARG_TYPES (TREE_TYPE (function)),
                   2704:                                parms, &template_cost);
                   2705:          if (i == 0)
                   2706:            function = instantiate_template (function, targs);
                   2707:        }
                   2708:       if (TREE_CODE (function) == TEMPLATE_DECL)
                   2709:        /* Unconverted template -- failed match.  */
                   2710:        cp->evil = 1, cp->function = function, cp->u.bad_arg = -4;
                   2711:       else
                   2712:        {
                   2713:          function = DECL_MAIN_VARIANT (function);
                   2714: 
                   2715:          /* Can't use alloca here, since result might be
                   2716:             passed to calling function.  */
                   2717:          cp->harshness
                   2718:            = (unsigned short *)oballoc ((parmlength+1) * sizeof (short));
                   2719:          compute_conversion_costs (function, parms, cp, parmlength);
                   2720:          /* Should really add another field...  */
                   2721:          cp->easy = cp->easy * 128 + template_cost;
                   2722:          if (cp[0].evil == 0)
                   2723:            {
                   2724:              cp[1].evil = 1;
                   2725:              if (final_cp
                   2726:                  && cp[0].user == 0 && cp[0].b_or_d == 0
                   2727:                  && template_cost == 0
                   2728:                  && cp[0].easy <= 1)
                   2729:                {
                   2730:                  final_cp[0].easy = cp[0].easy;
                   2731:                  return function;
                   2732:                }
                   2733:              cp++;
                   2734:            }
                   2735:        }
                   2736:     }
                   2737: 
                   2738:   if (cp - candidates)
                   2739:     {
                   2740:       tree rval = error_mark_node;
                   2741: 
                   2742:       /* Leave marker.  */
                   2743:       cp[0].evil = 1;
                   2744:       if (cp - candidates > 1)
                   2745:        {
                   2746:          struct candidate *best_cp
                   2747:            = ideal_candidate (NULL_TREE, candidates,
                   2748:                               cp - candidates, parms, parmlength);
1.1.1.5 ! root     2749:          if (best_cp == (struct candidate *)0)
1.1       root     2750:            {
                   2751:              if (complain)
                   2752:                error ("call of overloaded `%s' is ambiguous", IDENTIFIER_POINTER (fnname));
                   2753:              return error_mark_node;
                   2754:            }
                   2755:          else
                   2756:            rval = best_cp->function;
                   2757:        }
                   2758:       else
                   2759:        {
                   2760:          cp -= 1;
                   2761:          if (cp->evil > 1)
                   2762:            {
                   2763:              if (complain)
                   2764:                error ("type conversion ambiguous");
                   2765:            }
                   2766:          else
                   2767:            rval = cp->function;
                   2768:        }
                   2769: 
                   2770:       if (final_cp)
                   2771:        return rval;
                   2772: 
                   2773:       return buildxxx ? build_function_call_maybe (rval, parms)
                   2774:         : build_function_call (rval, parms);
                   2775:     }
                   2776:   else if (complain)
                   2777:     {
                   2778:       tree name;
                   2779:       char *err_name;
1.1.1.4   root     2780: 
1.1       root     2781:       /* Initialize name for error reporting.  */
                   2782:       if (TREE_CODE (functions) == TREE_LIST)
                   2783:        name = TREE_PURPOSE (functions);
1.1.1.4   root     2784:       else if (TREE_CODE (functions) == ADDR_EXPR)
                   2785:       /* Since the implicit `operator new' and `operator delete' functions
                   2786:         are set up to have IDENTIFIER_GLOBAL_VALUEs that are unary ADDR_EXPRs
                   2787:         by default_conversion(), we must compensate for that here by
                   2788:         using the name of the ADDR_EXPR's operand.  */
                   2789:        name = DECL_NAME (TREE_OPERAND (functions, 0));
1.1       root     2790:       else
                   2791:        name = DECL_NAME (functions);
                   2792: 
                   2793:       if (IDENTIFIER_OPNAME_P (name))
                   2794:        {
                   2795:          char *opname = operator_name_string (name);
                   2796:          err_name = (char *)alloca (strlen (opname) + 12);
                   2797:          sprintf (err_name, "operator %s", opname);
                   2798:        }
                   2799:       else
                   2800:        err_name = IDENTIFIER_POINTER (name);
                   2801: 
                   2802:       report_type_mismatch (cp, parms, "function", err_name);
                   2803:     }
                   2804:   return error_mark_node;
                   2805: }
                   2806: 
                   2807: tree
                   2808: build_overload_call (fnname, parms, complain, final_cp)
                   2809:      tree fnname, parms;
                   2810:      int complain;
                   2811:      struct candidate *final_cp;
                   2812: {
                   2813:   return build_overload_call_real (fnname, parms, complain, final_cp, 0);
                   2814: }
                   2815: 
                   2816: tree
                   2817: build_overload_call_maybe (fnname, parms, complain, final_cp)
                   2818:      tree fnname, parms;
                   2819:      int complain;
                   2820:      struct candidate *final_cp;
                   2821: {
                   2822:   return build_overload_call_real (fnname, parms, complain, final_cp, 1);
                   2823: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.