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

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

unix.superglobalmegacorp.com

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