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

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

unix.superglobalmegacorp.com

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