Annotation of gcc/cp-class.c, revision 1.1.1.2

1.1       root        1: /* Functions related to building classes and their related objects.
                      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: #ifdef DEBUG_CP_BINDING_LEVELS
                     33: #include "cp-decl.h"
                     34: #endif
                     35: 
                     36: #include "obstack.h"
                     37: #define obstack_chunk_alloc xmalloc
                     38: #define obstack_chunk_free free
                     39: 
                     40: extern int xmalloc ();
                     41: extern void free ();
                     42: 
                     43: extern struct obstack permanent_obstack;
                     44: 
                     45: /* in decl.c.  */
                     46: extern tree lookup_tag_current_binding_level ();
                     47: 
                     48: /* in method.c.  */
                     49: extern void do_inline_function_hair ();
                     50: 
                     51: /* Way of stacking class types.  */
                     52: static tree *current_class_base, *current_class_stack;
                     53: static int current_class_stacksize;
                     54: int current_class_depth;
                     55: 
                     56: struct class_level
                     57: {
                     58:   /* The previous class level.  */
                     59:   struct class_level *level_chain;
                     60: 
                     61:   /* The class instance variable, as a PARM_DECL.  */
                     62:   tree decl;
                     63:   /* The class instance variable, as an object.  */
                     64:   tree object;
                     65:   /* The virtual function table pointer
                     66:      for the class instance variable.  */
                     67:   tree vtable_decl;
                     68: 
                     69:   /* Name of the current class.  */
                     70:   tree name;
                     71:   /* Type of the current class.  */
                     72:   tree type;
                     73: 
                     74:   /* Flags for this class level.  */
                     75:   int this_is_variable;
                     76:   int memoized_lookups;
                     77:   int save_memoized;
                     78:   int unused;
                     79: };
                     80: 
                     81: tree current_class_decl, C_C_D;        /* PARM_DECL: the class instance variable */
                     82: tree current_vtable_decl;
                     83: 
                     84: /* The following two can be derived from the previous one */
                     85: tree current_class_name;       /* IDENTIFIER_NODE: name of current class */
                     86: tree current_class_type;       /* _TYPE: the type of the current class */
                     87: static tree prev_class_type;   /* _TYPE: the previous type that was a class */
                     88: 
                     89: static tree get_vtable_name (), get_vfield_name ();
                     90: tree the_null_vtable_entry;
                     91: 
1.1.1.2 ! root       92: /* Way of stacking language names.  */
1.1       root       93: tree *current_lang_base, *current_lang_stack;
                     94: static int current_lang_stacksize;
                     95: 
                     96: /* Names of languages we recognize.  */
                     97: tree lang_name_c, lang_name_cplusplus;
                     98: tree current_lang_name;
                     99: 
                    100: tree minus_one_node;
                    101: 
                    102: /* When layout out an aggregate type, the size of the
                    103:    basetypes (virtual and non-virtual) is passed to layout_record
                    104:    via this node.  */
                    105: static tree base_layout_decl;
                    106: 
                    107: /* Variables shared between cp-class.c and cp-call.c.  */
                    108: 
                    109: int n_vtables = 0;
                    110: int n_vtable_entries = 0;
                    111: int n_vtable_searches = 0;
                    112: int n_vtable_elems = 0;
                    113: int n_convert_harshness = 0;
                    114: int n_compute_conversion_costs = 0;
                    115: int n_build_method_call = 0;
                    116: int n_inner_fields_searched = 0;
                    117: 
                    118: #if 0
                    119: /* Make sure that the tag NAME is defined *in the current binding level*
                    120:    at least as a forward reference.
                    121:    CODE says which kind of tag NAME ought to be.
                    122: 
                    123:    Not used for C++.  Not maintained.  */
                    124: 
                    125: tree
                    126: start_struct (code, name)
                    127:      enum tree_code code;
                    128:      tree name;
                    129: {
                    130:   /* If there is already a tag defined at this binding level
                    131:      (as a forward reference), just return it.  */
                    132:   register tree ref = 0;
                    133: 
                    134:   if (name != 0)
                    135:     ref = lookup_tag (code, name, current_binding_level, 1);
                    136:   if (ref && TREE_CODE (ref) == code)
                    137:     {
                    138:       if (TYPE_FIELDS (ref))
                    139:        error ((code == UNION_TYPE ? "redefinition of `union %s'"
                    140:                : "redefinition of `struct %s'"),
                    141:               IDENTIFIER_POINTER (name));
                    142: 
                    143:       return ref;
                    144:     }
                    145: 
                    146:   /* Otherwise create a forward-reference just so the tag is in scope.  */
                    147: 
                    148:   ref = make_lang_type (code);
                    149:   /* Must re-synch this with xref_tag if you are going to use it.  */
                    150:   assert (0);
                    151:   pushtag (name, ref);
                    152:   return ref;
                    153: }
                    154: #endif
                    155: 
                    156: /* Virtual baseclass things.  */
                    157: tree
                    158: build_vbase_pointer (exp, type)
                    159:      tree exp, type;
                    160: {
                    161:   char *name;
                    162: 
                    163:   name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
                    164:   sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
                    165:   return build_component_ref (exp, get_identifier (name), 0, 0);
                    166: }
                    167: 
                    168: /* Build multi-level access to EXPR using hierarchy path PATH.
                    169:    CODE is PLUS_EXPR if we are going with the grain,
                    170:    and MINUS_EXPR if we are not (in which case, we cannot traverse
                    171:    virtual baseclass links).
                    172: 
                    173:    TYPE is the type we want this path to have on exit.
                    174: 
                    175:    ALIAS_THIS is non-zero if EXPR in an expression involving `this'.  */
                    176: tree
                    177: build_vbase_path (code, type, expr, path, alias_this)
                    178:      enum tree_code code;
                    179:      tree type;
                    180:      tree expr;
                    181:      tree path;
                    182:      int alias_this;
                    183: {
                    184:   register int changed = 0;
                    185:   tree last = NULL_TREE, last_virtual = NULL_TREE;
                    186:   int nonnull = 0;
                    187:   int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
                    188:   tree null_expr = 0, nonnull_expr;
                    189:   tree basetype;
                    190:   tree offset = integer_zero_node;
                    191: 
                    192:   if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
                    193:     expr = save_expr (expr);
                    194:   nonnull_expr = expr;
                    195: 
                    196:   if (BINFO_INHERITANCE_CHAIN (path))
                    197:     {
                    198:       tree reverse_path = NULL_TREE;
                    199: 
                    200:       while (path)
                    201:        {
                    202:          tree r = copy_node (path);
                    203:          BINFO_INHERITANCE_CHAIN (r) = reverse_path;
                    204:          reverse_path = r;
                    205:          path = BINFO_INHERITANCE_CHAIN (path);
                    206:        }
                    207:       path = reverse_path;
                    208:     }
                    209: 
                    210:   basetype = BINFO_TYPE (path);
                    211: 
                    212:   while (path)
                    213:     {
                    214:       if (TREE_VIA_VIRTUAL (path))
                    215:        {
                    216:          last_virtual = BINFO_TYPE (path);
                    217:          if (code == PLUS_EXPR)
                    218:            {
                    219:              changed = ! fixed_type_p;
                    220: 
                    221:              if (changed)
                    222:                {
                    223:                  extern tree flag_assume_nonnull_objects;
                    224:                  tree ind;
                    225: 
                    226:                  if (last)
                    227:                    nonnull_expr = convert_pointer_to (last, nonnull_expr);
                    228:                  ind = build_indirect_ref (nonnull_expr, 0);
                    229:                  nonnull_expr = build_vbase_pointer (ind, last_virtual);
                    230:                  if (nonnull == 0 && !flag_assume_nonnull_objects
                    231:                      && null_expr == NULL_TREE)
                    232:                    {
                    233:                      null_expr = build1 (NOP_EXPR, TYPE_POINTER_TO (last_virtual), integer_zero_node);
                    234:                      expr = build (COND_EXPR, TYPE_POINTER_TO (last_virtual),
                    235:                                    build (EQ_EXPR, integer_type_node, expr,
                    236:                                           integer_zero_node),
                    237:                                    null_expr, nonnull_expr);
                    238:                    }
                    239:                }
                    240:              /* else we'll figure out the offset below.  */
                    241: 
                    242:              /* Happens in the case of parse errors.  */
                    243:              if (nonnull_expr == error_mark_node)
                    244:                return error_mark_node;
                    245:            }
                    246:          else
                    247:            {
                    248:              error_with_aggr_type (last_virtual, "cannot cast up from virtual baseclass `%s'");
                    249:              return error_mark_node;
                    250:            }
                    251:        }
                    252:       last = path;
                    253:       path = BINFO_INHERITANCE_CHAIN (path);
                    254:     }
                    255:   /* LAST is now the last basetype assoc on the path.  */
                    256: 
                    257:   /* A pointer to a virtual base member of a non-null object
                    258:      is non-null.  Therefore, we only need to test for zeroness once.
1.1.1.2 ! root      259:      Make EXPR the canonical expression to deal with here.  */
1.1       root      260:   if (null_expr)
                    261:     {
                    262:       TREE_OPERAND (expr, 2) = nonnull_expr;
                    263:       TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr);
                    264:     }
                    265:   else
                    266:     expr = nonnull_expr;
                    267: 
                    268:   /* If we go through any virtual base pointers, make sure that
                    269:      casts to BASETYPE from the last virtual base class use
                    270:      the right value for BASETYPE.  */
                    271:   if (changed)
                    272:     {
                    273:       tree intype = TREE_TYPE (TREE_TYPE (expr));
                    274:       if (TYPE_MAIN_VARIANT (intype) == BINFO_TYPE (last))
                    275:        basetype = intype;
                    276:       else
                    277:        {
                    278:          tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
                    279:          basetype = last;
                    280:          offset = BINFO_OFFSET (binfo);
                    281:        }
                    282:     }
                    283:   else
                    284:     {
                    285:       if (last_virtual)
                    286:        {
                    287:          offset = BINFO_OFFSET (binfo_member (last_virtual,
                    288:                                               CLASSTYPE_VBASECLASSES (basetype)));
                    289:          offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
                    290:        }
                    291:       else
                    292:        offset = BINFO_OFFSET (last);
                    293: 
                    294:       code = PLUS_EXPR;
                    295:     }
                    296: 
                    297:   if (TREE_INT_CST_LOW (offset))
                    298:     {
                    299:       /* For multiple inheritance: if `this' can be set by any
                    300:         function, then it could be 0 on entry to any function.
                    301:         Preserve such zeroness here.  Otherwise, only in the
                    302:         case of constructors need we worry, and in those cases,
                    303:         it will be zero, or initialized to some legal value to
                    304:         which we may add.  */
1.1.1.2 ! root      305:       if (nonnull == 0 && (alias_this == 0 || flag_this_is_variable > 0))
1.1       root      306:        {
                    307:          if (null_expr)
                    308:            TREE_TYPE (null_expr) = type;
                    309:          else
                    310:            null_expr = build1 (NOP_EXPR, type, integer_zero_node);
                    311:          if (TREE_SIDE_EFFECTS (expr))
                    312:            expr = save_expr (expr);
                    313: 
                    314:          return build (COND_EXPR, type,
                    315:                        build (EQ_EXPR, integer_type_node, expr, integer_zero_node),
                    316:                        null_expr,
                    317:                        build (code, type, expr, offset));
                    318:        }
                    319:       else return build (code, type, expr, offset);
                    320:     }
                    321: 
                    322:   /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
                    323:      be used multiple times in initialization of multiple inheritance.  */
                    324:   if (null_expr)
                    325:     {
                    326:       TREE_TYPE (expr) = type;
                    327:       return expr;
                    328:     }
                    329:   else
                    330:     return build1 (NOP_EXPR, type, expr);
                    331: }
                    332: 
                    333: /* Virtual function things.  */
                    334: 
                    335: /* Virtual functions to be dealt with after laying out our
                    336:    base classes.  Usually this is used only when classes have virtual
                    337:    baseclasses, but it can happen also when classes have non-virtual
                    338:    baseclasses if the derived class overrides baseclass functions
                    339:    at different offsets.  */
                    340: static tree pending_hard_virtuals;
                    341: static int doing_hard_virtuals;
                    342: 
                    343: /* The names of the entries in the virtual table structure.  */
                    344: static tree delta_name, pfn_name;
                    345: 
                    346: /* Temporary binfo list to memoize lookups of the left-most non-virtual
                    347:    baseclass B in a lattice topped by T.  B can appear multiple times
                    348:    in the lattice.
                    349:    TREE_PURPOSE is B's TYPE_MAIN_VARIANT.
                    350:    TREE_VALUE is the path by which B is reached from T.
                    351:    TREE_TYPE is B's real type.
                    352: 
                    353:    If TREE_TYPE is NULL_TREE, it means that B was reached via
                    354:    a virtual baseclass.
                    355:    N.B.: This list consists of nodes on the temporary obstack.  */
                    356: static tree leftmost_baseclasses;
                    357: 
                    358: /* Build an entry in the virtual function table.
                    359:    DELTA is the offset for the `this' pointer.
                    360:    PFN is an ADDR_EXPR containing a pointer to the virtual function.
                    361:    Note that the index (DELTA2) in the virtual function table
                    362:    is always 0.  */
                    363: tree
                    364: build_vtable_entry (delta, pfn)
                    365:      tree delta, pfn;
                    366: {
                    367:   tree elems = tree_cons (NULL_TREE, delta,
                    368:                          tree_cons (NULL_TREE, integer_zero_node,
                    369:                                     build_tree_list (NULL_TREE, pfn)));
                    370:   tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
1.1.1.2 ! root      371: 
        !           372:   /* DELTA is constructed by `size_int', which means it may be an
        !           373:      unsigned quantity on some platforms.  Therefore, we cannot use
        !           374:      `int_fits_type_p', because when DELTA is really negative,
        !           375:      `force_fit_type' will make it look like a very large number.  */
        !           376: 
        !           377:   if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (short_integer_type_node))
        !           378:        < TREE_INT_CST_LOW (delta))
        !           379:       || (TREE_INT_CST_LOW (delta)
        !           380:          < TREE_INT_CST_LOW (TYPE_MIN_VALUE (short_integer_type_node))))
        !           381:     sorry ("object size exceeds built-in limit for virtual function table implementation");
1.1       root      382: 
                    383:   TREE_CONSTANT (entry) = 1;
                    384:   TREE_STATIC (entry) = 1;
                    385:   TREE_READONLY (entry) = 1;
                    386: 
                    387: #ifdef GATHER_STATISTICS
                    388:   n_vtable_entries += 1;
                    389: #endif
                    390: 
                    391:   return entry;
                    392: }
                    393: 
                    394: /* Given an object INSTANCE, return an expression which yields
                    395:    the virtual function corresponding to INDEX.  There are many special
                    396:    cases for INSTANCE which we take care of here, mainly to avoid
                    397:    creating extra tree nodes when we don't have to.  */
                    398: tree
                    399: build_vfn_ref (ptr_to_instptr, instance, index)
                    400:      tree *ptr_to_instptr, instance;
                    401:      tree index;
                    402: {
                    403:   extern int building_cleanup;
                    404:   tree vtbl, aref;
                    405:   tree basetype = TREE_TYPE (instance);
                    406: 
                    407:   if (TREE_CODE (basetype) == REFERENCE_TYPE)
                    408:     basetype = TREE_TYPE (basetype);
                    409: 
                    410:   if (instance == C_C_D)
                    411:     {
                    412:       if (current_vtable_decl == NULL_TREE
                    413:          || current_vtable_decl == error_mark_node
                    414:          || !DERIVED_FROM_P (DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type)), basetype))
                    415:        vtbl = build_indirect_ref (build_vfield_ref (instance, basetype));
                    416:       else
                    417:        vtbl = current_vtable_decl;
                    418:     }
                    419:   else
                    420:     {
                    421:       if (optimize)
                    422:        {
                    423:          /* Try to figure out what a reference refers to, and
                    424:             access its virtual function table directly.  */
                    425:          tree ref = NULL_TREE;
                    426: 
                    427:          if (TREE_CODE (instance) == INDIRECT_REF
                    428:              && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
                    429:            ref = TREE_OPERAND (instance, 0);
                    430:          else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
                    431:            ref = instance;
                    432: 
                    433:          if (ref && TREE_CODE (ref) == VAR_DECL
                    434:              && DECL_INITIAL (ref))
                    435:            {
                    436:              tree init = DECL_INITIAL (ref);
                    437: 
                    438:              while (TREE_CODE (init) == NOP_EXPR
                    439:                     || TREE_CODE (init) == NON_LVALUE_EXPR)
                    440:                init = TREE_OPERAND (init, 0);
                    441:              if (TREE_CODE (init) == ADDR_EXPR)
                    442:                {
                    443:                  init = TREE_OPERAND (init, 0);
                    444:                  if (IS_AGGR_TYPE (TREE_TYPE (init))
                    445:                      && (TREE_CODE (init) == PARM_DECL
                    446:                          || TREE_CODE (init) == VAR_DECL))
                    447:                    instance = init;
                    448:                }
                    449:            }
                    450:        }
                    451: 
                    452:       if (IS_AGGR_TYPE (TREE_TYPE (instance))
                    453:          && (TREE_CODE (instance) == RESULT_DECL
                    454:              || TREE_CODE (instance) == PARM_DECL
                    455:              || TREE_CODE (instance) == VAR_DECL))
                    456:        vtbl = TYPE_BINFO_VTABLE (basetype);
                    457:       else
                    458:        vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), 0);
                    459:     }
                    460:   assemble_external (vtbl);
                    461:   aref = build_array_ref (vtbl, index);
                    462:   if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF)
                    463:     TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
                    464: 
                    465:   *ptr_to_instptr = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
                    466:                           *ptr_to_instptr,
                    467:                           convert (integer_type_node, build_component_ref (aref, delta_name, 0, 0)));
                    468:   return build_component_ref (aref, pfn_name, 0, 0);
                    469: }
                    470: 
                    471: /* Build a virtual function for type TYPE.
1.1.1.2 ! root      472:    If BINFO is non-NULL, build the vtable starting with the initial
1.1       root      473:    approximation that it is the same as the one which is the head of
1.1.1.2 ! root      474:    the association list.  */
1.1       root      475: static tree
                    476: build_vtable (binfo, type)
                    477:      tree binfo, type;
                    478: {
                    479:   tree name = get_vtable_name (type);
                    480:   tree virtuals, decl;
                    481: 
                    482:   if (binfo)
                    483:     {
                    484:       virtuals = copy_list (BINFO_VIRTUALS (binfo));
                    485:       decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
                    486:     }
                    487:   else
                    488:     {
                    489:       virtuals = NULL_TREE;
                    490:       decl = build_decl (VAR_DECL, name, void_type_node);
                    491:     }
                    492: 
                    493: #ifdef GATHER_STATISTICS
                    494:   n_vtables += 1;
                    495:   n_vtable_elems += list_length (virtuals);
                    496: #endif
                    497: 
                    498:   if (write_virtuals >= 2)
                    499:     {
                    500:       if (CLASSTYPE_INTERFACE_UNKNOWN (type) == 0)
                    501:        {
                    502:          /* Where ever it is, it's public whether extern or
                    503:             defined in the file being compiled.  */
                    504:          TREE_PUBLIC (decl) = 1;
                    505:          TREE_EXTERNAL (decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type);
                    506:        }
                    507:     }
                    508:   else if (write_virtuals != 0)
                    509:     TREE_PUBLIC (decl) = 1;
                    510:   if (write_virtuals < 0)
                    511:     TREE_EXTERNAL (decl) = 1;
                    512: 
                    513:   IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl);
                    514:   /* Initialize the association list for this type, based
                    515:      on our first approximation.  */
                    516:   TYPE_BINFO_VTABLE (type) = decl;
                    517:   TYPE_BINFO_VIRTUALS (type) = virtuals;
                    518: 
                    519:   TREE_STATIC (decl) = 1;
                    520:   DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
                    521:                           DECL_ALIGN (decl));
                    522: 
                    523:   if (binfo && write_virtuals >= 0)
                    524:     DECL_VIRTUAL_P (decl) = 1;
                    525:   /* Remember which class this vtable is really for.  */
                    526:   DECL_VPARENT (decl) = type;
                    527:   DECL_CONTEXT (decl) = type;
                    528: 
                    529:   binfo = TYPE_BINFO (type);
                    530:   SET_BINFO_VTABLE_PATH_MARKED (binfo);
                    531:   SET_BINFO_NEW_VTABLE_MARKED (binfo);
                    532:   return decl;
                    533: }
                    534: 
                    535: /* Give TYPE a new virtual function table which is initialized
                    536:    with a skeleton-copy of its original initialization.  The only
                    537:    entry that changes is the `delta' entry, so we can really
                    538:    share a lot of structure.
                    539: 
                    540:    FOR_TYPE is the derived type which caused this table to
                    541:    be needed.
                    542: 
                    543:    BINFO is the type association which provided TYPE for FOR_TYPE.
                    544: 
                    545:    The way we update BASE_BINFO's vtable information is just to change the
                    546:    association information in FOR_TYPE's association list.  */
                    547: static void
                    548: prepare_fresh_vtable (binfo, base_binfo, for_type)
                    549:      tree binfo, base_binfo, for_type;
                    550: {
                    551:   tree basetype = BINFO_TYPE (binfo);
                    552:   tree orig_decl = BINFO_VTABLE (binfo);
                    553:   tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type);
                    554:   tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
                    555:   tree path;
                    556:   int result;
                    557: 
                    558:   /* Remember which class this vtable is really for.  */
                    559:   DECL_VPARENT (new_decl) = BINFO_TYPE (base_binfo);
                    560:   DECL_CONTEXT (new_decl) = for_type;
                    561: 
                    562:   TREE_STATIC (new_decl) = 1;
                    563:   BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
                    564:   DECL_VIRTUAL_P (new_decl) = 1;
                    565:   DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
                    566: 
                    567:   /* Make fresh virtual list, so we can smash it later.  */
                    568:   BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
                    569:   /* Install the value for `headof' if that's what we're doing.  */
                    570:   if (flag_dossier)
                    571:     TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo)))
                    572:       = build_vtable_entry (size_binop (MINUS_EXPR, integer_zero_node, BINFO_OFFSET (binfo)),
                    573:                            FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo)))));
                    574: 
                    575: #ifdef GATHER_STATISTICS
                    576:   n_vtables += 1;
                    577:   n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
                    578: #endif
                    579: 
                    580:   /* Set `new_decl's PUBLIC and EXTERNAL bits.  */
                    581:   if (write_virtuals >= 2)
                    582:     {
                    583:       if (CLASSTYPE_INTERFACE_UNKNOWN (for_type) == 0)
                    584:        {
                    585:          TREE_PUBLIC (new_decl) = CLASSTYPE_VTABLE_NEEDS_WRITING (for_type);
                    586:          TREE_EXTERNAL (new_decl) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (for_type);
                    587:        }
                    588:     }
                    589:   else if (write_virtuals > 0)
                    590:     TREE_PUBLIC (new_decl) = 1;
                    591:   else if (write_virtuals < 0)
                    592:     TREE_EXTERNAL (new_decl) = 1;
                    593: 
                    594:   if (TREE_VIA_VIRTUAL (binfo))
                    595:     assert (binfo == binfo_member (BINFO_TYPE (binfo),
                    596:                                   CLASSTYPE_VBASECLASSES (current_class_type)));
                    597:   SET_BINFO_NEW_VTABLE_MARKED (binfo);
                    598:   SET_BINFO_VTABLE_PATH_MARKED (binfo);
                    599: 
                    600:   /* Mark all types between FOR_TYPE and TYPE as having been
                    601:      touched, so that if we change virtual function table entries,
                    602:      new vtables will be initialized.  We may reach the virtual
                    603:      baseclass via ambiguous intervening baseclasses.  This
                    604:      loop makes sure we get through to the actual baseclass we marked.
                    605: 
                    606:      Also, update the vtable entries to reflect the overrides
                    607:      of the top-most class (short of the top type).  */
                    608: 
                    609:   do
                    610:     {
                    611:       result = get_base_distance (basetype, for_type, 0, &path);
                    612:       for_type = path;
                    613:       while (path)
                    614:        {
                    615:          tree path_binfo = path;
                    616:          tree path_type = BINFO_TYPE (path);
                    617: 
                    618:          if (TREE_VIA_VIRTUAL (path))
                    619:            path_binfo = binfo_member (path_type,
                    620:                                       CLASSTYPE_VBASECLASSES (current_class_type));
                    621: 
                    622:          SET_BINFO_VTABLE_PATH_MARKED (path_binfo);
                    623:          if (BINFO_INHERITANCE_CHAIN (path)
                    624:              && CLASSTYPE_VFIELD (path_type) != NULL_TREE
                    625:              && (DECL_NAME (CLASSTYPE_VFIELD (BINFO_TYPE (binfo)))
                    626:                  == DECL_NAME (CLASSTYPE_VFIELD (path_type)))
                    627:              /* This is the baseclass just before the original FOR_TYPE.  */
                    628:              && BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path)) == NULL_TREE)
                    629:            {
                    630:              tree old_virtuals = TREE_CHAIN (BINFO_VIRTUALS (binfo));
                    631:              tree new_virtuals = TREE_CHAIN (BINFO_VIRTUALS (path_binfo));
                    632:              if (flag_dossier)
                    633:                {
                    634:                  old_virtuals = TREE_CHAIN (old_virtuals);
                    635:                  new_virtuals = TREE_CHAIN (new_virtuals);
                    636:                }
                    637:              while (old_virtuals)
                    638:                {
                    639:                  TREE_VALUE (old_virtuals) = TREE_VALUE (new_virtuals);
                    640:                  old_virtuals = TREE_CHAIN (old_virtuals);
                    641:                  new_virtuals = TREE_CHAIN (new_virtuals);
                    642:                }
                    643:            }
                    644:          path = BINFO_INHERITANCE_CHAIN (path);
                    645:        }
                    646:     }
                    647:   while (result == -2);
                    648: }
                    649: 
                    650: /* Access the virtual function table entry that logically
                    651:    contains BASE_FNDECL.  VIRTUALS is the virtual function table's
                    652:    initializer.  */
                    653: static tree
                    654: get_vtable_entry (virtuals, base_fndecl)
                    655:      tree virtuals, base_fndecl;
                    656: {
                    657:   int i = (HOST_BITS_PER_INT >= BITS_PER_WORD
                    658: #ifdef VTABLE_USES_MASK
                    659:           && 0
                    660: #endif
                    661:           ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
                    662:              & (((unsigned)1<<(BITS_PER_WORD-1))-1))
                    663:           : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
                    664: 
                    665: #ifdef GATHER_STATISTICS
                    666:   n_vtable_searches += i;
                    667: #endif
                    668: 
                    669:   while (i > 0)
                    670:     {
                    671:       virtuals = TREE_CHAIN (virtuals);
                    672:       i -= 1;
                    673:     }
                    674:   return virtuals;
                    675: }
                    676: 
                    677: /* Put new entry ENTRY into virtual function table initializer
                    678:    VIRTUALS.  The virtual function table is for type CONTEXT.
                    679: 
                    680:    Also update DECL_VINDEX (FNDECL).  */
                    681: 
                    682: static void
                    683: modify_vtable_entry (old_entry_in_list, new_entry, fndecl, context)
                    684:      tree old_entry_in_list, new_entry, fndecl, context;
                    685: {
                    686:   tree base_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list));
                    687:   tree vindex;
                    688: 
                    689:   /* We can't put in the really right offset information
                    690:      here, since we have not yet laid out the class to
                    691:      take into account virtual base classes.  */
                    692:   TREE_VALUE (old_entry_in_list) = new_entry;
                    693:   vindex = DECL_VINDEX (TREE_OPERAND (base_pfn, 0));
                    694:   if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
                    695:     DECL_VINDEX (fndecl) = vindex;
                    696:   else
                    697:     {
                    698:       if (! tree_int_cst_equal (DECL_VINDEX (fndecl), vindex))
                    699:        {
                    700:          tree elts = CONSTRUCTOR_ELTS (new_entry);
                    701:          tree vfield = CLASSTYPE_VFIELD (context);
                    702: 
                    703:          if (! doing_hard_virtuals)
                    704:            {
                    705:              pending_hard_virtuals
                    706:                = tree_cons (fndecl, FNADDR_FROM_VTABLE_ENTRY (new_entry),
                    707:                             pending_hard_virtuals);
                    708:              TREE_TYPE (pending_hard_virtuals) = TREE_OPERAND (base_pfn, 0);
                    709:              return;
                    710:            }
                    711: 
                    712: #if 0
                    713:          abort ();
                    714: 
                    715:          /* Compute the relative offset of vtable we are really looking for.  */
                    716:          TREE_VALUE (elts) = size_binop (PLUS_EXPR,
                    717:                                          size_int (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (vfield))
                    718: /* ??? This may be wrong. */
                    719:                                                    / BITS_PER_UNIT),
                    720:                                          TREE_VALUE (elts));
                    721:          /* Say what index to use when we use that vtable.  */
                    722: #ifndef VTABLE_USES_MASK
                    723:          vindex = build_int_2 (TREE_INT_CST_LOW (vindex)
                    724:                                & ~((unsigned)1 << (BITS_PER_WORD -1)), 0);
                    725: #endif
                    726:          TREE_VALUE (TREE_CHAIN (elts)) = vindex;
                    727: #endif
                    728:        }
                    729:     }
                    730: }
                    731: 
                    732: /* Modify virtual function tables in lattice topped by T to
                    733:    place FNDECL in tables which previously held BASE_FNDECL.
                    734:    PFN is just FNDECL wrapped in an ADDR_EXPR, so that it
                    735:    is suitable for placement directly into an initializer.
                    736: 
                    737:    All distinct virtual function tables that this type uses
                    738:    must be updated.  */
                    739: static void
                    740: modify_vtable_entries (t, fndecl, base_fndecl, pfn)
                    741:      tree t;
                    742:      tree fndecl, base_fndecl, pfn;
                    743: {
                    744:   tree base_offset, offset;
                    745:   tree base_context = DECL_CLASS_CONTEXT (base_fndecl);
                    746:   tree context = DECL_CLASS_CONTEXT (fndecl);
                    747:   tree vfield = CLASSTYPE_VFIELD (t);
                    748:   tree vfields, vbases;
                    749: 
                    750:   DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
                    751: 
                    752:   offset = integer_zero_node;
                    753:   if (context != t && TYPE_USES_COMPLEX_INHERITANCE (t))
                    754:     {
                    755:       offset = virtual_offset (context, CLASSTYPE_VBASECLASSES (t), offset);
                    756:       if (offset == NULL_TREE)
                    757:        {
                    758:          tree binfo = binfo_value (context, t, 0);
                    759:          offset = BINFO_OFFSET (binfo);
                    760:        }
                    761:     }
                    762: 
                    763:   /* For each layer of base class (i.e., the first base class, and each
                    764:      virtual base class from that one), modify the virtual function table
                    765:      of the derived class to contain the new virtual function.
                    766:      A class has as many vfields as it has virtual base classes (total).  */
                    767:   for (vfields = CLASSTYPE_VFIELDS (t); vfields; vfields = TREE_CHAIN (vfields))
                    768:     {
                    769:       int normal = 1;
                    770:       tree binfo, this_offset;
                    771:       tree base, path;
                    772: 
                    773:       /* Find the right base class for this derived class, call it BASE.  */
                    774:       base = VF_BASETYPE_VALUE (vfields);
                    775: 
                    776:       if (base != base_context)
                    777:        {
                    778:          /* If BASE_FNDECL is not contained in the vtable accessed by
                    779:             the vslot, don't try to modify the vtable.
                    780:             
                    781:             Virtual functions from virtual baseclasses are not in derived
                    782:             virtual function tables.  This is an implementation decision;
                    783:             it keeps there from being a combinatorial exposion in the
                    784:             number of different vtables which must be maintained.  */
                    785: 
                    786:          if (! DERIVED_FROM_P (base, base_context))
                    787:            continue;
                    788: 
                    789:          /* BASE_FNDECL is defined in a class derived from
                    790:             the base class owning this VFIELD.  */
                    791:        }
                    792:       /* Get the path starting from the deepest base class CONTEXT
                    793:         of T (i.e., first defn of BASE_FNDECL).  */
                    794:       get_base_distance (base_context, t, 0, &path);
                    795: 
                    796:       /* Get our best approximation of what to use for constructing
                    797:         the virtual function table for T.  */
                    798:       do
                    799:        {
                    800:          /* Walk from base toward derived, stopping at the
                    801:             most derived baseclass that matters.  That baseclass
                    802:             is exactly the one which provides the vtable along
                    803:             the VFIELD spine, but no more.  */
                    804:          if (TREE_VIA_VIRTUAL (path))
                    805:            {
                    806:              base = path;
                    807:              binfo = binfo_member (BINFO_TYPE (base), CLASSTYPE_VBASECLASSES (t));
                    808:              break;
                    809:            }
                    810:          if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE
                    811:              || (BINFO_TYPE (BINFO_BASETYPE (BINFO_INHERITANCE_CHAIN (path), 0))
                    812:                  != BINFO_TYPE (path))
                    813:              || BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path)) == NULL_TREE)
                    814:            {
                    815:              base = path;
                    816:              binfo = base;
                    817:              break;
                    818:            }
                    819:          path = BINFO_INHERITANCE_CHAIN (path);
                    820:        }
                    821:       while (1);
                    822: 
                    823:       /* Find the right offset for the this pointer based on the base
                    824:         class we just found.  */
                    825:       base_offset = BINFO_OFFSET (binfo);
                    826:       this_offset = size_binop (MINUS_EXPR, offset, base_offset);
                    827: 
                    828:       /* Make sure we can modify the derived association with immunity.  */
                    829:       if (TREE_USED (TYPE_BINFO (t)))
                    830:        TYPE_BINFO (t) = copy_binfo (TYPE_BINFO (t));
                    831: 
                    832:       /* We call this case NORMAL iff this virtual function table
                    833:         pointer field has its storage reserved in this class.
                    834:         This is normally the case without virtual baseclasses
                    835:         or off-center multiple baseclasses.  */
                    836:       normal = (vfield != NULL_TREE
                    837:                && VF_BASETYPE_VALUE (vfields) == DECL_FCONTEXT (vfield)
                    838:                && (VF_BINFO_VALUE (vfields) == NULL_TREE
                    839:                    || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields))));
                    840: 
                    841:       if (normal && VF_BINFO_VALUE (vfields))
                    842:        /* Everything looks normal so far...check that we are really
                    843:           working from VFIELD's basetype, and not some other appearance
                    844:           of that basetype in the lattice.  */
                    845:        normal = (VF_BINFO_VALUE (vfields)
                    846:                  == get_binfo (VF_BASETYPE_VALUE (vfields), t, 0));
                    847: 
                    848:       if (normal)
                    849:        {
                    850:          /* In this case, it is *type*'s vtable we are modifying.
                    851:             We start with the approximation that it's vtable is that
                    852:             of the immediate base class.  */
                    853:          base_context = t;
                    854:          binfo = TYPE_BINFO (t);
                    855:          if (! BINFO_NEW_VTABLE_MARKED (binfo))
                    856:            build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
                    857:        }
                    858:       else
                    859:        {
                    860:          /* This is our very own copy of `basetype' to play with.
                    861:             Later, we will fill in all the virtual functions
                    862:             that override the virtual functions in these base classes
                    863:             which are not defined by the current type.  */
                    864:          if (! BINFO_NEW_VTABLE_MARKED (binfo))
                    865:            prepare_fresh_vtable (binfo, base, t);
                    866:        }
                    867: 
                    868:       modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (binfo), base_fndecl),
                    869:                           build_vtable_entry (this_offset, pfn),
                    870:                           fndecl, base_context);
                    871:     }
                    872:   for (vbases = CLASSTYPE_VBASECLASSES (t); vbases; vbases = TREE_CHAIN (vbases))
                    873:     {
                    874:       tree this_offset;
                    875:       tree base, path;
                    876: 
                    877:       if (! BINFO_VTABLE (vbases))
                    878:        /* There are only two ways that a type can fail to have
                    879:           virtual functions: neither it nor any of its base
                    880:           types define virtual functions (in which case
                    881:           no updating need be done), or virtual functions
                    882:           accessible to it come from virtual base classes
                    883:           (in which case we have or will get them modified
                    884:           in other passes of this loop).  */
                    885:        continue;
                    886: 
                    887:       base = BINFO_TYPE (vbases);
                    888:       path = NULL_TREE;
                    889: 
                    890:       if (base != base_context
                    891:          && get_base_distance (base_context, base, 0, &path) == -1)
                    892:        continue;
                    893: 
                    894:       if (path)
                    895:        this_offset = size_binop (MINUS_EXPR, offset, BINFO_OFFSET (path));
                    896:       else
                    897:        this_offset = offset;
                    898: 
                    899:       /* Doesn't matter if not actually from this virtual base class,
                    900:          but shouldn't come from deeper virtual baseclasses.  The enclosing
                    901:         loop should take care of such baseclasses.  */
                    902:       while (path)
                    903:        {
                    904:          if (TREE_VIA_VIRTUAL (path))
                    905:            goto skip;
                    906:          path = BINFO_INHERITANCE_CHAIN (path);
                    907:        }
                    908: 
                    909:       base_offset = BINFO_OFFSET (vbases);
                    910:       this_offset = size_binop (MINUS_EXPR, this_offset, base_offset);
                    911: 
                    912:       /* Make sure we can modify the derived association with immunity.  */
                    913:       if (TREE_USED (TYPE_BINFO (t)))
                    914:        TYPE_BINFO (t) = copy_binfo (TYPE_BINFO (t));
                    915: 
                    916:       /* This is our very own copy of `basetype' to play with.  */
                    917:       if (! BINFO_NEW_VTABLE_MARKED (vbases))
                    918:        {
                    919:          tree context_binfo = binfo_value (base_context, base, 0);
                    920:          prepare_fresh_vtable (vbases, context_binfo, t);
                    921:        }
                    922:       modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (vbases), base_fndecl),
                    923:                           build_vtable_entry (this_offset, pfn),
                    924:                           fndecl, base_context);
                    925:     skip: {}
                    926:     }
                    927: }
                    928: 
                    929: static tree
                    930: add_virtual_function (pending_virtuals, has_virtual, x, t)
                    931:      tree pending_virtuals;
                    932:      int *has_virtual;
                    933:      tree x;
                    934:      tree t; /* Structure type. */
                    935: {
                    936:   int debug_vbase = 1;
                    937: 
                    938:   /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
                    939:      convert to void *.  Make such a conversion here.  */
                    940:   tree vfn = build1 (ADDR_EXPR, ptr_type_node, x);
                    941:   TREE_CONSTANT (vfn) = 1;
                    942:   TREE_ADDRESSABLE (x) = CLASSTYPE_VTABLE_NEEDS_WRITING (current_class_type);
                    943: 
                    944:   /* If the virtual function is a redefinition of a prior one,
                    945:      figure out in which base class the new definition goes,
                    946:      and if necessary, make a fresh virtual function table
                    947:      to hold that entry.  */
                    948:   if (DECL_VINDEX (x) == error_mark_node)
                    949:     {
                    950:       tree entry = build_vtable_entry (integer_zero_node, vfn);
                    951: 
                    952:       if (flag_dossier && *has_virtual == 0)
                    953:        {
                    954:          /* CLASSTYPE_DOSSIER is only used as a Boolean (NULL or not). */
                    955:          CLASSTYPE_DOSSIER (t) = integer_one_node;
                    956:          *has_virtual = 1;
                    957:         }
                    958: 
                    959:       /* Build a new INT_CST for this DECL_VINDEX.  */
                    960: #ifdef VTABLE_USES_MASK
                    961:       SET_DECL_VINDEX (x, build_int_2 (++(*has_virtual), 0));
                    962: #else
                    963:       {
                    964:        static tree index_table[256];
                    965:        tree index;
                    966:        int i = ++(*has_virtual);
                    967: 
                    968:        if (i >= 256 || index_table[i] == 0)
                    969:          {
                    970:            index = build_int_2 (((unsigned)1 << (BITS_PER_WORD - 1)) | i, ~0);
                    971:            if (i < 256)
                    972:              index_table[i] = index;
                    973:          }
                    974:        else
                    975:          index = index_table[i];
                    976: 
                    977:        DECL_VINDEX (x) = index;
                    978:       }
                    979: #endif
                    980:       pending_virtuals = tree_cons (DECL_VINDEX (x), entry, pending_virtuals);
                    981:     }
                    982:   /* Happens if declared twice in class.  We will give error
                    983:      later.  */
                    984:   else if (TREE_CODE (DECL_VINDEX (x)) == INTEGER_CST)
                    985:     return pending_virtuals;
                    986:   else if (debug_vbase && TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
                    987:     {
                    988:       /* Need an entry in some other virtual function table.
                    989:          Deal with this after we have laid out our virtual base classes.  */
                    990:       pending_hard_virtuals = temp_tree_cons (x, vfn, pending_hard_virtuals);
                    991:     }
                    992:   else
                    993:     {
                    994:       /* Need an entry in some other virtual function table.
                    995:          We can do this now.  */
                    996:       tree base_fndecl_list = DECL_VINDEX (x), base_fndecls, prev = 0;
                    997:       tree vtable_context = DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type));
                    998:       tree true_base_fndecl = 0;
                    999: 
                   1000:       /* First assign DECL_VINDEX from the base vfn with which
                   1001:         we share our vtable.  */
                   1002:       base_fndecls = base_fndecl_list;
                   1003:       while (base_fndecls)
                   1004:        {
                   1005:          if (TREE_CHAIN (base_fndecls) == NULL_TREE
                   1006:              || DECL_FCONTEXT (CLASSTYPE_VFIELD (DECL_CLASS_CONTEXT (TREE_VALUE (base_fndecls)))) == vtable_context)
                   1007:            {
                   1008:              true_base_fndecl = TREE_VALUE (base_fndecls);
                   1009:              modify_vtable_entries (current_class_type, x,
                   1010:                                     true_base_fndecl, vfn);
                   1011:              if (prev)
                   1012:                TREE_CHAIN (prev) = TREE_CHAIN (base_fndecls);
                   1013:              else
                   1014:                base_fndecl_list = prev;
                   1015:              break;
                   1016:            }
                   1017:          prev = base_fndecls;
                   1018:          base_fndecls = TREE_CHAIN (base_fndecls);
                   1019:        }
                   1020: 
                   1021:       /* Now fill in the rest of the vtables.  */
                   1022:       base_fndecls = base_fndecl_list;
                   1023:       while (base_fndecls)
                   1024:        {
                   1025:          /* If we haven't found one we like, first one wins.  */
                   1026:          if (true_base_fndecl == 0)
                   1027:            true_base_fndecl = TREE_VALUE (base_fndecls);
                   1028: 
                   1029:          modify_vtable_entries (current_class_type, x,
                   1030:                                 TREE_VALUE (base_fndecls), vfn);
                   1031:          base_fndecls = TREE_CHAIN (base_fndecls);
                   1032:        }
                   1033: 
                   1034:       DECL_CONTEXT (x) = DECL_CONTEXT (true_base_fndecl);
                   1035:     }
                   1036:   return pending_virtuals;
                   1037: }
                   1038: 
                   1039: /* Obstack on which to build the vector of class methods.  */
                   1040: struct obstack class_obstack;
                   1041: extern struct obstack *current_obstack;
                   1042: 
                   1043: /* Add method METHOD to class TYPE.  This is used when a method
                   1044:    has been defined which did not initially appear in the class definition,
                   1045:    and helps cut down on spurious error messages.
                   1046: 
                   1047:    FIELDS is the entry in the METHOD_VEC vector entry of the class type where
                   1048:    the method should be added.  */
                   1049: void
                   1050: add_method (type, fields, method)
                   1051:      tree type, *fields, method;
                   1052: {
                   1053:   /* We must make a copy of METHOD here, since we must be sure that
                   1054:      we have exclusive title to this method's DECL_CHAIN.  */
                   1055:   tree decl;
                   1056: 
                   1057:   push_obstacks (&permanent_obstack, &permanent_obstack);
                   1058:   {
                   1059:     decl = copy_node (method);
                   1060:     if (DECL_RTL (decl) == 0
                   1061:         && (!processing_template_decl
                   1062:             || !uses_template_parms (decl)))
                   1063:       {
                   1064:        make_function_rtl (decl);
                   1065:        DECL_RTL (method) = DECL_RTL (decl);
                   1066:       }
                   1067:   }
                   1068: 
                   1069:   if (fields && *fields)
                   1070:     {
                   1071:       /* Take care not to hide destructor.  */
                   1072:       DECL_CHAIN (decl) = DECL_CHAIN (*fields);
                   1073:       DECL_CHAIN (*fields) = decl;
                   1074:     }
                   1075:   else if (CLASSTYPE_METHOD_VEC (type) == 0)
                   1076:     {
                   1077:       tree method_vec = make_node (TREE_VEC);
                   1078:       if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
                   1079:        {
                   1080:          TREE_VEC_ELT (method_vec, 0) = decl;
                   1081:          TREE_VEC_LENGTH (method_vec) = 1;
                   1082:        }
                   1083:       else
                   1084:        {
                   1085:          /* ??? Is it possible for there to have been enough room in the
                   1086:             current chunk for the tree_vec structure but not a tree_vec
                   1087:             plus a tree*?  Will this work in that case?  */
                   1088:          obstack_free (current_obstack, method_vec);
                   1089:          obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
                   1090:          TREE_VEC_ELT (method_vec, 1) = decl;
                   1091:          TREE_VEC_LENGTH (method_vec) = 2;
                   1092:          obstack_finish (current_obstack);
                   1093:        }
                   1094:       CLASSTYPE_METHOD_VEC (type) = method_vec;
                   1095:     }
                   1096:   else
                   1097:     {
                   1098:       tree method_vec = CLASSTYPE_METHOD_VEC (type);
                   1099:       int len = TREE_VEC_LENGTH (method_vec);
                   1100: 
                   1101:       /* Adding a new ctor or dtor.  This is easy because our
                   1102:          METHOD_VEC always has a slot for such entries.  */
                   1103:       if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
                   1104:        {
                   1105:          /* TREE_VEC_ELT (method_vec, 0) = decl; */
                   1106:          if (decl != TREE_VEC_ELT (method_vec, 0))
                   1107:            {
                   1108:              DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0);
                   1109:              TREE_VEC_ELT (method_vec, 0) = decl;
                   1110:            }
                   1111:        }
                   1112:       else
                   1113:        {
                   1114:          /* This is trickier.  We try to extend the TREE_VEC in-place,
                   1115:             but if that does not work, we copy all its data to a new
                   1116:             TREE_VEC that's large enough.  */
                   1117:          struct obstack *ob = &class_obstack;
                   1118:          tree *end = (tree *)obstack_next_free (ob);
                   1119: 
                   1120:          if (end != TREE_VEC_END (method_vec))
                   1121:            {
                   1122:              ob = current_obstack;
                   1123:              TREE_VEC_LENGTH (method_vec) += 1;
                   1124:              TREE_VEC_ELT (method_vec, len) = NULL_TREE;
                   1125:              method_vec = copy_node (method_vec);
                   1126:              TREE_VEC_LENGTH (method_vec) -= 1;
                   1127:            }
                   1128:          else
                   1129:            {
                   1130:              tree tmp_vec = (tree) obstack_base (ob);
                   1131:              if (obstack_room (ob) < sizeof (tree))
                   1132:                {
                   1133:                  obstack_blank (ob, sizeof (struct tree_common)
1.1.1.2 ! root     1134:                                 + tree_code_length[(int) TREE_VEC]
        !          1135:                                   * sizeof (char *)
1.1       root     1136:                                 + len * sizeof (tree));
                   1137:                  tmp_vec = (tree) obstack_base (ob);
                   1138:                  bcopy (method_vec, tmp_vec,
                   1139:                         (sizeof (struct tree_common)
1.1.1.2 ! root     1140:                          + tree_code_length[(int) TREE_VEC] * sizeof (char *)
1.1       root     1141:                          + (len-1) * sizeof (tree)));
                   1142:                  method_vec = tmp_vec;
                   1143:                }
                   1144:              else
                   1145:                obstack_blank (ob, sizeof (tree));
                   1146:            }
                   1147: 
                   1148:          obstack_finish (ob);
                   1149:          TREE_VEC_ELT (method_vec, len) = decl;
                   1150:          TREE_VEC_LENGTH (method_vec) = len + 1;
                   1151:          CLASSTYPE_METHOD_VEC (type) = method_vec;
                   1152: 
                   1153:          if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
                   1154:            {
                   1155:              /* ??? May be better to know whether these can be extended?  */
                   1156:              tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
                   1157: 
                   1158:              TREE_VEC_LENGTH (baselink_vec) += 1;
                   1159:              CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
                   1160:              TREE_VEC_LENGTH (baselink_vec) -= 1;
                   1161: 
                   1162:              TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
                   1163:            }
                   1164:        }
                   1165:     }
                   1166:   DECL_CONTEXT (decl) = type;
                   1167:   DECL_CLASS_CONTEXT (decl) = type;
                   1168: 
                   1169:   pop_obstacks ();
                   1170: }
                   1171: 
                   1172: /* Subroutines of finish_struct.  */
                   1173: 
                   1174: /* Look through the list of fields for this struct, deleting
                   1175:    duplicates as we go.  This must be recursive to handle
                   1176:    anonymous unions.
                   1177: 
                   1178:    FIELD is the field which may not appear anywhere in FIELDS.
                   1179:    FIELD_PTR, if non-null, is the starting point at which
                   1180:    chained deletions may take place.
                   1181:    The value returned is the first acceptable entry found
                   1182:    in FIELDS.
                   1183: 
                   1184:    Note that anonymous fields which are not of UNION_TYPE are
                   1185:    not duplicates, they are just anonymous fields.  This happens
                   1186:    when we have unnamed bitfields, for example.  */
                   1187: static tree
                   1188: delete_duplicate_fields_1 (field, field_ptr, fields)
                   1189:      tree field, *field_ptr, fields;
                   1190: {
                   1191:   tree x;
                   1192:   tree prev = field_ptr ? *field_ptr : 0;
                   1193:   if (DECL_NAME (field) == 0)
                   1194:     {
                   1195:       if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)
                   1196:        return fields;
                   1197: 
                   1198:       for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
                   1199:        fields = delete_duplicate_fields_1 (x, field_ptr, fields);
                   1200:       if (prev)
                   1201:        TREE_CHAIN (prev) = fields;
                   1202:       return fields;
                   1203:     }
                   1204:   else
                   1205:     {
                   1206:       for (x = fields; x; prev = x, x = TREE_CHAIN (x))
                   1207:        {
                   1208:          if (DECL_NAME (x) == 0)
                   1209:            {
                   1210:              if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE)
                   1211:                continue;
                   1212:              TYPE_FIELDS (TREE_TYPE (x))
                   1213:                = delete_duplicate_fields_1 (field, 0, TYPE_FIELDS (TREE_TYPE (x)));
                   1214:              if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
                   1215:                {
                   1216:                  if (prev == 0)
                   1217:                    fields = TREE_CHAIN (fields);
                   1218:                  else
                   1219:                    TREE_CHAIN (prev) = TREE_CHAIN (x);
                   1220:                }
                   1221:            }
                   1222:          else
                   1223:            {
                   1224:              if (DECL_NAME (field) == DECL_NAME (x))
                   1225:                {
                   1226:                  if (TREE_CODE (field) == CONST_DECL
                   1227:                      && TREE_CODE (x) == CONST_DECL)
                   1228:                    error_with_decl (x, "duplicate enum value `%s'");
                   1229:                  else if (TREE_CODE (field) == CONST_DECL
                   1230:                           || TREE_CODE (x) == CONST_DECL)
                   1231:                    error_with_decl (x, "duplicate field `%s' (as enum and non-enum)");
                   1232:                  else
                   1233:                    error_with_decl (x, "duplicate member `%s'");
                   1234:                  if (prev == 0)
                   1235:                    fields = TREE_CHAIN (fields);
                   1236:                  else
                   1237:                    TREE_CHAIN (prev) = TREE_CHAIN (x);
                   1238:                }
                   1239:            }
                   1240:        }
                   1241:     }
                   1242:   return fields;
                   1243: }
                   1244: 
                   1245: static void
                   1246: delete_duplicate_fields (fields)
                   1247:      tree fields;
                   1248: {
                   1249:   tree x;
                   1250:   for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
                   1251:     TREE_CHAIN (x) = delete_duplicate_fields_1 (x, &x, TREE_CHAIN (x));
                   1252: }
                   1253: 
                   1254: /* Change the visibility of T::FDECL to VISIBILITY.
                   1255:    Return 1 if change was legit, otherwise return 0.  */
                   1256: static int
                   1257: alter_visibility (t, fdecl, visibility)
                   1258:      tree t;
                   1259:      tree fdecl;
                   1260:      enum visibility_type visibility;
                   1261: {
                   1262:   tree elem = purpose_member (t, DECL_VISIBILITY (fdecl));
                   1263:   if (elem && TREE_VALUE (elem) != (tree)visibility)
                   1264:     {
                   1265:       if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
                   1266:        {
                   1267:          error_with_decl (TREE_TYPE (fdecl), "conflicting visibility specifications for method `%s', ignored");
                   1268:        }
                   1269:       else error ("conflicting visibility specifications for field `%s', ignored", IDENTIFIER_POINTER (DECL_NAME (fdecl)));
                   1270:     }
                   1271:   else if (TREE_PRIVATE (fdecl) && visibility != visibility_private)
                   1272:     error_with_decl (fdecl, "cannot make private %s non-private");
                   1273:   else if (TREE_PROTECTED (fdecl) && visibility == visibility_public)
                   1274:                    
                   1275:     error_with_decl (fdecl, "cannot make protected %s public");
                   1276:   else if (elem == NULL_TREE)
                   1277:     {
                   1278:       DECL_VISIBILITY (fdecl) = tree_cons (t, (tree)visibility,
                   1279:                                           DECL_VISIBILITY (fdecl));
                   1280:       return 1;
                   1281:     }
                   1282:   return 0;
                   1283: }
                   1284: 
                   1285: static tree
                   1286: get_vfield_offset (binfo)
                   1287:      tree binfo;
                   1288: {
                   1289:   return size_binop (PLUS_EXPR,
                   1290:                     DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
                   1291:                     BINFO_OFFSET (binfo));
                   1292: }
                   1293: 
                   1294: /* If FOR_TYPE needs to reinitialize virtual function table pointers
                   1295:    for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
                   1296:    Returns BASE_INIT_LIST appropriately modified.  */
                   1297: 
                   1298: static tree
                   1299: maybe_fixup_vptrs (for_type, binfo, base_init_list)
                   1300:      tree for_type, binfo, base_init_list;
                   1301: {
                   1302:   /* Now reinitialize any slots that don't fall under our virtual
                   1303:      function table pointer.  */
                   1304:   tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
                   1305:   while (vfields)
                   1306:     {
                   1307:       tree base_binfo = get_binfo (VF_BASETYPE_VALUE (vfields), for_type, 0);
                   1308:       if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (VF_BASETYPE_VALUE (vfields)))
                   1309:        {
                   1310:          tree base_offset = get_vfield_offset (base_binfo);
                   1311:          if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
                   1312:              && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
                   1313:            base_init_list = tree_cons (error_mark_node, base_binfo,
                   1314:                                        base_init_list);
                   1315:        }
                   1316:       vfields = TREE_CHAIN (vfields);
                   1317:     }
                   1318:   return base_init_list;
                   1319: }
                   1320: 
                   1321: /* If TYPE does not have a constructor, then the compiler must
                   1322:    manually deal with all of the initialization this type requires.
                   1323: 
                   1324:    If a base initializer exists only to fill in the virtual function
                   1325:    table pointer, then we mark that fact with the TREE_VIRTUAL bit.
                   1326:    This way, we avoid multiple initializations of the same field by
                   1327:    each virtual function table up the class hierarchy.
                   1328: 
                   1329:    Virtual base class pointers are not initialized here.  They are
                   1330:    initialized only at the "top level" of object creation.  If we
                   1331:    initialized them here, we would have to skip a lot of work.  */
                   1332: 
                   1333: static void
                   1334: build_class_init_list (type)
                   1335:      tree type;
                   1336: {
                   1337:   tree base_init_list = NULL_TREE;
                   1338:   tree member_init_list = NULL_TREE;
                   1339: 
                   1340:   /* Since we build member_init_list and base_init_list using
                   1341:      tree_cons, backwards fields the all through work.  */
                   1342:   tree x;
                   1343:   tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
                   1344:   int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
                   1345: 
                   1346:   for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x))
                   1347:     {
                   1348:       if (TREE_CODE (x) != FIELD_DECL)
                   1349:        continue;
                   1350: 
                   1351:       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x))
                   1352:          || DECL_INITIAL (x) != NULL_TREE)
                   1353:        member_init_list = tree_cons (x, type, member_init_list);
                   1354:     }
                   1355:   member_init_list = nreverse (member_init_list);
                   1356: 
                   1357:   /* We will end up doing this last.  Need special marker
                   1358:      to avoid infinite regress.  */
                   1359:   if (TYPE_VIRTUAL_P (type))
                   1360:     {
                   1361:       base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type));
                   1362:       if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0)
                   1363:        TREE_VALUE (base_init_list) = NULL_TREE;
                   1364:       TREE_ADDRESSABLE (base_init_list) = 1;
                   1365:     }
                   1366: 
                   1367:   /* Each base class which needs to have initialization
                   1368:      of some kind gets to make such requests known here.  */
                   1369:   for (i = n_baseclasses-1; i >= 0; i--)
                   1370:     {
                   1371:       tree child = TREE_VEC_ELT (binfos, i);
                   1372:       tree blist;
                   1373: 
                   1374:       /* Don't initialize virtual baseclasses this way.  */
                   1375:       if (TREE_VIA_VIRTUAL (child))
                   1376:        continue;
                   1377: 
                   1378:       if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (child)))
                   1379:        {
                   1380:          /* ...and the last shall come first...  */
                   1381:          base_init_list = maybe_fixup_vptrs (type, child, base_init_list);
                   1382:          base_init_list = tree_cons (NULL_TREE, child, base_init_list);
                   1383:          continue;
                   1384:        }
                   1385: 
                   1386:       if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (child))) == NULL_TREE)
                   1387:        /* Nothing to initialize.  */
                   1388:        continue;
                   1389: 
                   1390:       /* ...ditto...  */
                   1391:       base_init_list = maybe_fixup_vptrs (type, child, base_init_list);
                   1392: 
                   1393:       /* This is normally true for single inheritance.
                   1394:         The win is we can shrink the chain of initializations
                   1395:         to be done by only converting to the actual type
                   1396:         we are interested in.  */
                   1397:       if (TREE_VALUE (blist)
                   1398:          && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC
                   1399:          && tree_int_cst_equal (BINFO_OFFSET (child),
                   1400:                                 BINFO_OFFSET (TREE_VALUE (blist))))
                   1401:        {
                   1402:          if (base_init_list)
                   1403:            {
                   1404:              /* Does it do more than just fill in a
                   1405:                 virtual function table pointer?  */
                   1406:              if (! TREE_ADDRESSABLE (blist))
                   1407:                base_init_list = build_tree_list (blist, base_init_list);
                   1408:              /* Can we get by just with the virtual function table
                   1409:                 pointer that it fills in?  */
                   1410:              else if (TREE_ADDRESSABLE (base_init_list)
                   1411:                       && TREE_VALUE (base_init_list) == 0)
                   1412:                base_init_list = blist;
                   1413:              /* Maybe, but it is not obvious as the previous case.  */
                   1414:              else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type))
                   1415:                {
                   1416:                  tree last = tree_last (base_init_list);
                   1417:                  while (TREE_VALUE (last)
                   1418:                         && TREE_CODE (TREE_VALUE (last)) == TREE_LIST)
                   1419:                    last = tree_last (TREE_VALUE (last));
                   1420:                  if (TREE_VALUE (last) == 0)
                   1421:                    base_init_list = build_tree_list (blist, base_init_list);
                   1422:                }
                   1423:            }
                   1424:          else
                   1425:            base_init_list = blist;
                   1426:        }
                   1427:       else
                   1428:        {
                   1429:          /* The function expand_aggr_init knows how to do the
                   1430:             initialization of `basetype' without getting
                   1431:             an explicit `blist'.  */
                   1432:          if (base_init_list)
                   1433:            base_init_list = tree_cons (NULL_TREE, child, base_init_list);
                   1434:          else
                   1435:            base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (child));
                   1436:        }
                   1437:     }
                   1438: 
                   1439:   if (base_init_list)
                   1440:     if (member_init_list)
                   1441:       CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list);
                   1442:     else
                   1443:       CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
                   1444:   else if (member_init_list)
                   1445:     CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
                   1446: }
                   1447: 
                   1448: struct base_info
                   1449: {
                   1450:   int has_virtual;
                   1451:   int max_has_virtual;
                   1452:   int n_ancestors;
                   1453:   tree vfield;
                   1454:   tree vfields;
                   1455:   char needs_default_ctor;
                   1456:   char cant_have_default_ctor;
                   1457:   char needs_const_ctor;
                   1458:   char cant_have_const_ctor;
                   1459:   char members_need_dtors;
                   1460:   char needs_virtual_dtor;
                   1461: };
                   1462: 
                   1463: /* Record information about type T derived from its base classes.
                   1464:    Store most of that information in T itself, and place the
                   1465:    remaining information in the struct BASE_INFO.
                   1466: 
                   1467:    Propagate basetype offsets throughout the lattice.  Note that the
                   1468:    lattice topped by T is really a pair: it's a DAG that gives the
                   1469:    structure of the derivation hierarchy, and it's a list of the
                   1470:    virtual baseclasses that appear anywhere in the DAG.  When a vbase
                   1471:    type appears in the DAG, it's offset is 0, and it's children start
                   1472:    their offsets from that point.  When a vbase type appears in the list,
                   1473:    its offset is the offset it has in the hierarchy, and its children's
                   1474:    offsets include that offset in theirs.
                   1475: 
                   1476:    Returns the index of the first base class to have virtual functions,
                   1477:    or zero if no such base class.  */
                   1478: 
                   1479: static int
                   1480: finish_base_struct (t, b, binfos)
                   1481:      tree t;
                   1482:      struct base_info *b;
                   1483:      tree binfos;
                   1484: {
                   1485:   int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
                   1486:   int first_vfn_base_index = -1;
                   1487:   bzero (b, sizeof (struct base_info));
                   1488: 
                   1489:   for (i = 0; i < n_baseclasses; i++)
                   1490:     {
                   1491:       tree child = TREE_VEC_ELT (binfos, i);
                   1492:       tree basetype = BINFO_TYPE (child);
                   1493: 
                   1494:       /* If the type of basetype is incomplete, then
                   1495:         we already complained about that fact
                   1496:         (and we should have fixed it up as well).  */
                   1497:       if (TYPE_SIZE (basetype) == 0)
                   1498:        {
                   1499:          int j;
                   1500:          /* The base type is of incomplete type.  It is
                   1501:             probably best to pretend that it does not
                   1502:             exist.  */
                   1503:          if (i == n_baseclasses-1)
                   1504:            TREE_VEC_ELT (binfos, i) = NULL_TREE;
                   1505:          TREE_VEC_LENGTH (binfos) -= 1;
                   1506:          n_baseclasses -= 1;
                   1507:          for (j = i; j+1 < n_baseclasses; j++)
                   1508:            TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
                   1509:        }
                   1510: 
                   1511:       if (TYPE_WRAP_TYPE (t) == NULL_TREE)
                   1512:        TYPE_WRAP_TYPE (t) = TYPE_WRAP_TYPE (basetype);
                   1513:       else if (TYPE_WRAP_TYPE (basetype)
                   1514:               && TYPE_WRAP_TYPE (t) != TYPE_WRAP_TYPE (basetype))
                   1515:        /* Must have its own.  */
                   1516:        TYPE_WRAP_TYPE (t) = error_mark_node;
                   1517: 
                   1518:       if (TYPE_NEEDS_DESTRUCTOR (basetype))
                   1519:        b->members_need_dtors = 1;
                   1520:       if (TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
                   1521:        b->needs_default_ctor = 1;
                   1522:       else if (TYPE_HAS_CONSTRUCTOR (basetype))
                   1523:        b->cant_have_default_ctor = 1;
                   1524:       if (TYPE_GETS_CONST_INIT_REF (basetype))
                   1525:        b->needs_const_ctor = 1;
                   1526:       else if (TYPE_GETS_INIT_REF (basetype))
                   1527:        b->cant_have_const_ctor = 1;
                   1528: 
                   1529:       CLASSTYPE_ALTERS_VISIBILITIES_P (t)
                   1530:        |= CLASSTYPE_ALTERS_VISIBILITIES_P (basetype);
                   1531: 
                   1532:       b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
                   1533:       TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
                   1534:       TYPE_NEEDS_CONSTRUCTOR (t) |= TYPE_NEEDS_CONSTRUCTOR (basetype);
                   1535:       TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
                   1536:       TYPE_GETS_ASSIGNMENT (t) |= TYPE_GETS_ASSIGNMENT (basetype);
                   1537:       TYPE_GETS_INIT_REF (t) |= TYPE_GETS_INIT_REF (basetype);
                   1538: 
                   1539:       TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
                   1540:       TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
                   1541:       TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
                   1542: 
                   1543:       if (! TREE_VIA_VIRTUAL (child)
                   1544:          && ! BINFO_OFFSET_ZEROP (child)
                   1545:          && BINFO_BASETYPES (child))
                   1546:        {
                   1547:          tree child_binfos = BINFO_BASETYPES (child);
                   1548:          tree chain = NULL_TREE;
                   1549:          int j;
                   1550: 
                   1551:          /* Now unshare the structure beneath CHILD.  */
                   1552:          for (j = TREE_VEC_LENGTH (child_binfos)-1;
                   1553:               j >= 0; j--)
                   1554:            {
                   1555:              tree child_child = TREE_VEC_ELT (child_binfos, j);
                   1556:              if (! TREE_VIA_VIRTUAL (child_child))
                   1557:                TREE_VEC_ELT (child_binfos, j)
                   1558:                  = make_binfo (BINFO_OFFSET (child_child),
                   1559:                                BINFO_TYPE (child_child),
                   1560:                                BINFO_VTABLE (child_child),
                   1561:                                BINFO_VIRTUALS (child_child),
                   1562:                                chain);
                   1563:              chain = TREE_VEC_ELT (child_binfos, j);
                   1564:              TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (child_child);
                   1565:            }
                   1566: 
                   1567:          /* Completely unshare potentially shared data, and
                   1568:             update what is ours.  */
                   1569:          propagate_binfo_offsets (child, BINFO_OFFSET (child));
                   1570:        }
                   1571: 
                   1572:       if (! TREE_VIA_VIRTUAL (child))
                   1573:        CLASSTYPE_N_SUPERCLASSES (t) += 1;
                   1574: 
                   1575:       if (TYPE_VIRTUAL_P (basetype))
                   1576:        {
                   1577:          /* If there's going to be a destructor needed, make
                   1578:             sure it will be virtual.  */
                   1579:          b->needs_virtual_dtor = 1;
                   1580: 
                   1581:          /* Don't borrow virtuals from virtual baseclasses.  */
                   1582:          if (TREE_VIA_VIRTUAL (child))
                   1583:            continue;
                   1584: 
                   1585:          if (first_vfn_base_index < 0)
                   1586:            {
                   1587:              first_vfn_base_index = i;
                   1588: 
                   1589:              b->has_virtual = CLASSTYPE_VSIZE (basetype);
                   1590:              b->vfield = CLASSTYPE_VFIELD (basetype);
                   1591:              b->vfields = CLASSTYPE_VFIELDS (basetype);
                   1592:              CLASSTYPE_VFIELD (t) = b->vfield;
                   1593:            }
                   1594:          else
                   1595:            {
                   1596:              /* Only add unique vfields, and flatten them out as we go.  */
                   1597:              tree vfields = CLASSTYPE_VFIELDS (basetype);
                   1598:              while (vfields)
                   1599:                {
                   1600:                  if (VF_BINFO_VALUE (vfields) == NULL_TREE
                   1601:                      || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
                   1602:                    {
                   1603:                      tree value = VF_BASETYPE_VALUE (vfields);
                   1604:                      b->vfields = tree_cons (child, value, b->vfields);
                   1605:                      if (DECL_NAME (CLASSTYPE_VFIELD (value))
                   1606:                          == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
                   1607:                        VF_NORMAL_VALUE (b->vfields) = basetype;
                   1608:                      else
                   1609:                        VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
                   1610:                    }
                   1611:                  vfields = TREE_CHAIN (vfields);
                   1612:                }
                   1613: 
                   1614:              if (b->has_virtual == 0)
                   1615:                {
                   1616:                  first_vfn_base_index = i;
                   1617:                  b->has_virtual = CLASSTYPE_VSIZE (basetype);
                   1618:                  b->vfield = CLASSTYPE_VFIELD (basetype);
                   1619:                  CLASSTYPE_VFIELD (t) = b->vfield;
                   1620:                }
                   1621:            }
                   1622:        }
                   1623:     }
                   1624: 
                   1625:   {
                   1626:     tree vfields;
                   1627:     /* Find the base class with the largest number of virtual functions.  */
                   1628:     for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
                   1629:       {
                   1630:        if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
                   1631:          b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
                   1632:        if (VF_DERIVED_VALUE (vfields)
                   1633:            && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
                   1634:          b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
                   1635:       }
                   1636:   }
                   1637: 
                   1638:   if (b->vfield == 0)
                   1639:     /* If all virtual functions come only from virtual baseclasses.  */
                   1640:     return -1;
                   1641:   return first_vfn_base_index;
                   1642: }
                   1643: 
                   1644: static int
                   1645: typecode_p (type, code)
                   1646:      tree type;
                   1647:      enum tree_code code;
                   1648: {
                   1649:   return (TREE_CODE (type) == code
                   1650:          || (TREE_CODE (type) == REFERENCE_TYPE
                   1651:              && TREE_CODE (TREE_TYPE (type)) == code));
                   1652: }
                   1653: 
                   1654: extern tree constructor_name ();
                   1655: 
                   1656: /* Set memoizing fields and bits of T (and its variants) for later use.
                   1657:    MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables.  */
                   1658: static void
                   1659: finish_struct_bits (t, max_has_virtual)
                   1660:      tree t;
                   1661:      int max_has_virtual;
                   1662: {
                   1663:   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
                   1664:   tree method_vec = CLASSTYPE_METHOD_VEC (t);
                   1665: 
                   1666:   /* Fix up variants (if any).  */
                   1667:   tree variants = TYPE_NEXT_VARIANT (t);
                   1668:   while (variants)
                   1669:     {
                   1670:       /* These fields are in the _TYPE part of the node, not in
                   1671:         the TYPE_LANG_SPECIFIC component, so they are not shared.  */
                   1672:       TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
                   1673:       TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
                   1674:       TYPE_NEEDS_CONSTRUCTOR (variants) = TYPE_NEEDS_CONSTRUCTOR (t);
                   1675:       TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
                   1676:       TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
                   1677: 
                   1678:       TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
                   1679:       TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
                   1680:       TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
                   1681:       /* Copy whatever these are holding today.  */
                   1682:       TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
                   1683:       TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
                   1684:       variants = TYPE_NEXT_VARIANT (variants);
                   1685:     }
                   1686: 
                   1687:   if (n_baseclasses && max_has_virtual)
                   1688:     {
                   1689:       /* Done by `finish_struct' for classes without baseclasses.  */
                   1690:       int has_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
                   1691:       tree binfos = TYPE_BINFO_BASETYPES (t);
                   1692:       for (i = n_baseclasses-1; i >= 0; i--)
                   1693:        {
                   1694:          has_abstract_virtuals
                   1695:            |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
                   1696:          if (has_abstract_virtuals)
                   1697:            break;
                   1698:        }
                   1699:       if (has_abstract_virtuals)
                   1700:        CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
                   1701:     }
                   1702: 
                   1703:   if (n_baseclasses)
                   1704:     {
                   1705:       /* Notice whether this class has type conversion functions defined.
                   1706:         Also report whether joining two types yields an ambiguity in the
                   1707:         virtual function table, e.g.,
                   1708:         
                   1709:         struct A { virtual int f (); };
                   1710:         struct B { virtual int f (); };
                   1711:         struct C : A, B { / * no f (); * / };  / / error, ambiguous
                   1712:         */
                   1713:       tree binfo = TYPE_BINFO (t);
                   1714:       tree binfos = BINFO_BASETYPES (binfo);
                   1715:       int n_binfos = list_length (binfo);
                   1716:       tree vbases = CLASSTYPE_VBASECLASSES (t), basetype;
                   1717:       int n_vbases = list_length (vbases), j;
                   1718: 
                   1719:       build_mi_virtuals (n_binfos+n_vbases*n_baseclasses, max_has_virtual);
                   1720:       /* Fill in virtual function table with values which do not come
                   1721:         "normal"ly, i.e., those which come from virtual and/or
                   1722:         non-leftmost base classes.  */
                   1723:       for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
                   1724:        {
                   1725:          if (TREE_VIA_VIRTUAL (binfo))
                   1726:            /* Virtual functions from virtual baseclasses are done below.  */;
                   1727:          else if (CLASSTYPE_VSIZE (BINFO_TYPE (binfo)))
                   1728:            {
                   1729:              tree virtuals = TREE_CHAIN (BINFO_VIRTUALS (binfo));
                   1730:              if (flag_dossier)
                   1731:                virtuals = TREE_CHAIN (virtuals);
                   1732:              add_mi_virtuals (++i, virtuals);
                   1733:            }
                   1734:        }
                   1735:       for (; vbases; vbases = TREE_CHAIN (vbases))
                   1736:        {
                   1737:          basetype = BINFO_TYPE (vbases);
                   1738:          if (CLASSTYPE_VSIZE (basetype))
                   1739:            for (j = n_baseclasses-1; j >= 0; j--)
                   1740:              {
                   1741:                tree this_binfo = TREE_VEC_ELT (binfos, j);
                   1742:                if (DERIVED_FROM_P (basetype, this_binfo))
                   1743:                  {
                   1744:                    tree virtuals = TREE_CHAIN (BINFO_VIRTUALS (vbases));
                   1745:                    if (flag_dossier)
                   1746:                      virtuals = TREE_CHAIN (virtuals);
                   1747:                    add_mi_virtuals (++i, virtuals);
                   1748:                  }
                   1749:              }
                   1750:        }
                   1751:       for (i = n_baseclasses-1; i >= 0; i--)
                   1752:        {
                   1753:          basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
                   1754: 
                   1755:          if (TYPE_HAS_CONVERSION (basetype))
                   1756:            {
                   1757:              TYPE_HAS_CONVERSION (t) = 1;
                   1758:              TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype);
                   1759:              TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype);
                   1760:            }
                   1761:          if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
                   1762:            CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
                   1763:        }
                   1764:       report_ambiguous_mi_virtuals (n_binfos+n_vbases*n_baseclasses, t);
                   1765: #if 0
                   1766:       /* Now that we know what the virtual functiond table looks like,
                   1767:         fix up offsets in the presence of virtual base classes.  */
                   1768:       if (n_vbases)
                   1769:        fixup_vbase_offsets (t);
                   1770: #endif
                   1771:     }
                   1772: 
                   1773:   /* Need to test METHOD_VEC here in case all methods
                   1774:      (conversions and otherwise) are inherited.  */
                   1775:   if (TYPE_HAS_CONVERSION (t) && method_vec != NULL_TREE)
                   1776:     {
                   1777:       tree first_conversions[last_conversion_type];
                   1778:       tree last_conversions[last_conversion_type];
                   1779:       enum conversion_type conv_index;
                   1780:       tree *tmp;
                   1781:       int i;
                   1782: 
                   1783:       bzero (first_conversions, sizeof (first_conversions));
                   1784:       bzero (last_conversions, sizeof (last_conversions));
                   1785:       for (tmp = &TREE_VEC_ELT (method_vec, 1);
                   1786:           tmp != TREE_VEC_END (method_vec); tmp += 1)
                   1787:        {
                   1788:          /* ??? This should compare DECL_NAME (*tmp) == ansi_opname[TYPE_EXPR].  */
                   1789:          if (IDENTIFIER_TYPENAME_P (DECL_ASSEMBLER_NAME (*tmp)))
                   1790:            {
                   1791:              tree fntype = TREE_TYPE (*tmp);
                   1792:              tree return_type = TREE_TYPE (fntype);
                   1793:              assert (TREE_CODE (fntype) == METHOD_TYPE);
                   1794: 
                   1795:              if (typecode_p (return_type, POINTER_TYPE))
                   1796:                {
                   1797:                  if (TYPE_READONLY (TREE_TYPE (return_type)))
                   1798:                    conv_index = constptr_conv;
                   1799:                  else
                   1800:                    conv_index = ptr_conv;
                   1801:                }
                   1802:              else if (typecode_p (return_type, INTEGER_TYPE))
                   1803:                {
                   1804:                  TYPE_HAS_INT_CONVERSION (t) = 1;
                   1805:                  conv_index = int_conv;
                   1806:                }
                   1807:              else if (typecode_p (return_type, REAL_TYPE))
                   1808:                {
                   1809:                  TYPE_HAS_REAL_CONVERSION (t) = 1;
                   1810:                  conv_index = real_conv;
                   1811:                }
                   1812:              else
                   1813:                continue;
                   1814: 
                   1815:              if (first_conversions[(int) conv_index] == NULL_TREE)
                   1816:                first_conversions[(int) conv_index] = *tmp;
                   1817:              last_conversions[(int) conv_index] = *tmp;
                   1818:            }
                   1819:        }
                   1820: 
                   1821:       for (i = 0; i < (int) last_conversion_type; i++)
                   1822:        if (first_conversions[i] != last_conversions[i])
                   1823:          CLASSTYPE_CONVERSION (t, i) = error_mark_node;
                   1824:        else
                   1825:          CLASSTYPE_CONVERSION (t, i) = first_conversions[i];
                   1826:     }
                   1827: 
                   1828:   /* If this type has constructors, force its mode to be BLKmode,
                   1829:      and force its TREE_ADDRESSABLE bit to be nonzero.  */
                   1830:   if (TYPE_NEEDS_CONSTRUCTING (t) || TYPE_NEEDS_DESTRUCTOR (t))
                   1831:     {
                   1832:       tree variants = t;
                   1833: 
                   1834:       if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
                   1835:        DECL_MODE (TYPE_NAME (t)) = BLKmode;
                   1836:       while (variants)
                   1837:        {
                   1838:          TYPE_MODE (variants) = BLKmode;
                   1839:          TREE_ADDRESSABLE (variants) = 1;
                   1840:          variants = TYPE_NEXT_VARIANT (variants);
                   1841:        }
                   1842:     }
                   1843: }
                   1844: 
                   1845: /* Warn about duplicate methods in fn_fields.  Also compact method
                   1846:    lists so that lookup can be made faster.
                   1847: 
                   1848:    Algorithm: Outer loop builds lists by method name.  Inner loop
                   1849:    checks for redundant method names within a list.
                   1850: 
                   1851:    Data Structure: List of method lists.  The outer list is a
                   1852:    TREE_LIST, whose TREE_PURPOSE field is the field name and the
                   1853:    TREE_VALUE is the TREE_CHAIN of the FUNCTION_DECLs.  Friends are
                   1854:    chained in the same way as member functions, but they live in the
                   1855:    TREE_TYPE field of the outer list.  That allows them to be quicky
                   1856:    deleted, and requires no extra storage.
                   1857: 
                   1858:    If there are any constructors/destructors, they are moved to the
                   1859:    front of the list.  This makes pushclass more efficient.
                   1860: 
                   1861:    We also link each field which has shares a name with its baseclass
                   1862:    to the head of the list of fields for that base class.  This allows
                   1863:    us to reduce search time in places like `build_method_call' to
                   1864:    consider only reasonably likely functions.  */
                   1865: 
                   1866: static tree
                   1867: finish_struct_methods (t, fn_fields, nonprivate_method)
                   1868:      tree t;
                   1869:      tree fn_fields;
                   1870:      int nonprivate_method;
                   1871: {
                   1872:   tree method_vec;
                   1873:   tree name = constructor_name (t);
                   1874:   int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
                   1875: 
                   1876:   /* Now prepare to gather fn_fields into vector.  */
                   1877:   struct obstack *ambient_obstack = current_obstack;
                   1878:   current_obstack = &class_obstack;
                   1879:   method_vec = make_node (TREE_VEC);
                   1880:   /* Room has been saved for constructors and destructors.  */
                   1881:   current_obstack = ambient_obstack;
                   1882:   /* Now make this a live vector.  */
                   1883:   obstack_free (&class_obstack, method_vec);
                   1884:   obstack_blank (&class_obstack, sizeof (struct tree_vec));
                   1885: 
                   1886:   while (fn_fields)
                   1887:     {
                   1888:       /* NEXT Pointer, TEST Pointer, and BASE Pointer.  */
                   1889:       tree nextp, *testp;
                   1890:       tree fn_name = DECL_NAME (fn_fields);
                   1891:       if (fn_name == NULL_TREE)
                   1892:        fn_name = name;
                   1893: 
                   1894:       nextp = TREE_CHAIN (fn_fields);
                   1895:       TREE_CHAIN (fn_fields) = NULL_TREE;
                   1896:       /* Constructors are handled easily in search routines.
                   1897:         Besides, we know we won't find any, so do not bother looking.  */
                   1898:       if (fn_name == name && TREE_VEC_ELT (method_vec, 0) == 0)
                   1899:        TREE_VEC_ELT (method_vec, 0) = fn_fields;
                   1900:       else
                   1901:        {
                   1902:          testp = &TREE_VEC_ELT (method_vec, 0);
                   1903:          if (*testp == NULL_TREE)
                   1904:            testp++;
                   1905:          while ((int)testp < (int)obstack_next_free (&class_obstack)
                   1906:                 && DECL_NAME (*testp) != fn_name)
                   1907:            testp++;
                   1908:          if ((int)testp < (int)obstack_next_free (&class_obstack))
                   1909:            {
                   1910:              tree x, prev_x;
                   1911: 
                   1912:              for (x = *testp; x; x = DECL_CHAIN (x))
                   1913:                {
                   1914:                  if (DECL_ASSEMBLER_NAME (fn_fields) == DECL_ASSEMBLER_NAME (x))
                   1915:                    {
                   1916:                      /* We complain about multiple destructors on sight,
                   1917:                         so we do not repeat the warning here.  Friend-friend
                   1918:                         ambiguities are warned about outside this loop.  */
                   1919:                      if (! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn_fields)))
                   1920:                        error_with_file_and_line (DECL_SOURCE_FILE (fn_fields),
                   1921:                                                  DECL_SOURCE_LINE (fn_fields),
                   1922:                                                  "ambiguous method `%s' in structure",
                   1923:                                                  lang_printable_name (fn_fields));
                   1924:                      break;
                   1925:                    }
                   1926:                  prev_x = x;
                   1927:                }
                   1928:              if (x == 0)
                   1929:                if (*testp)
                   1930:                  DECL_CHAIN (prev_x) = fn_fields;
                   1931:                else
                   1932:                  *testp = fn_fields;
                   1933:            }
                   1934:          else
                   1935:            {
                   1936:              obstack_ptr_grow (&class_obstack, fn_fields);
                   1937:              method_vec = (tree)obstack_base (&class_obstack);
                   1938:            }
                   1939:        }
                   1940:       fn_fields = nextp;
                   1941:     }
                   1942: 
                   1943:   TREE_VEC_LENGTH (method_vec)
                   1944:     = (tree *)obstack_next_free (&class_obstack) - (&TREE_VEC_ELT (method_vec, 0));
                   1945:   obstack_finish (&class_obstack);
                   1946:   CLASSTYPE_METHOD_VEC (t) = method_vec;
                   1947: 
                   1948:   if (nonprivate_method == 0
                   1949:       && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
                   1950:       && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
                   1951:     {
                   1952:       tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
                   1953:       for (i = 0; i < n_baseclasses; i++)
                   1954:        if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i)))
                   1955:          {
                   1956:            nonprivate_method = 1;
                   1957:            break;
                   1958:          }
                   1959:       if (nonprivate_method == 0)
                   1960:        warning ("all class member functions are private");
                   1961:     }
                   1962: 
                   1963:   /* If there are constructors (and destructors), they are at the
                   1964:      front.  Place destructors at very front.  Also warn if all
                   1965:      constructors and/or destructors are private (in which case this
                   1966:      class is effectively unusable.  */
                   1967:   if (TYPE_HAS_DESTRUCTOR (t))
                   1968:     {
                   1969:       tree dtor, prev;
                   1970: 
                   1971:       for (dtor = TREE_VEC_ELT (method_vec, 0); dtor; prev = dtor, dtor = DECL_CHAIN (dtor))
                   1972:        {
                   1973:          if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor)))
                   1974:            {
                   1975:              if (TREE_PRIVATE (dtor)
                   1976:                  && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
                   1977:                  && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
                   1978:                warning_with_decl (TYPE_NAME (t), "class `%s' only defines a private destructor and has no friends");
                   1979:              break;
                   1980:            }
                   1981:        }
                   1982:       /* Wild parse errors can cause this to happen.  */
                   1983:       if (dtor == NULL_TREE)
                   1984:        TYPE_HAS_DESTRUCTOR (t) = 0;
                   1985:       else if (dtor != TREE_VEC_ELT (method_vec, 0))
                   1986:        {
                   1987:          DECL_CHAIN (prev) = DECL_CHAIN (dtor);
                   1988:          DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0);
                   1989:          TREE_VEC_ELT (method_vec, 0) = dtor;
                   1990:        }
                   1991:     }
                   1992: 
                   1993:   /* Now for each member function (except for constructors and
                   1994:      destructors), compute where member functions of the same
                   1995:      name reside in base classes.  */
                   1996:   if (n_baseclasses != 0
                   1997:       && TREE_VEC_LENGTH (method_vec) > 1)
                   1998:     {
                   1999:       int len = TREE_VEC_LENGTH (method_vec);
                   2000:       tree baselink_vec = make_tree_vec (len);
                   2001:       int any_links = 0;
                   2002:       tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
                   2003: 
                   2004:       for (i = 1; i < len; i++)
                   2005:        {
                   2006:          TREE_VEC_ELT (baselink_vec, i)
                   2007:            = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i)));
                   2008:          if (TREE_VEC_ELT (baselink_vec, i) != 0)
                   2009:            any_links = 1;
                   2010:        }
                   2011:       if (any_links != 0)
                   2012:        CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
                   2013:       else
                   2014:        obstack_free (current_obstack, baselink_vec);
                   2015:     }
                   2016: 
                   2017:   /* Now add the methods to the TYPE_METHODS of T, arranged in a chain.  */
                   2018:   {
                   2019:     tree x, last_x = NULL_TREE;
                   2020:     int limit = TREE_VEC_LENGTH (method_vec);
                   2021: 
                   2022:     for (i = 1; i < limit; i++)
                   2023:       {
                   2024:        for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x))
                   2025:          {
                   2026:            if (last_x != NULL_TREE)
                   2027:              TREE_CHAIN (last_x) = x;
                   2028:            last_x = x;
                   2029:          }
                   2030:       }
                   2031: 
                   2032:     /* Put ctors and dtors at the front of the list.  */
                   2033:     x = TREE_VEC_ELT (method_vec, 0);
                   2034:     if (x)
                   2035:       {
                   2036:        while (DECL_CHAIN (x))
                   2037:          {
                   2038:            TREE_CHAIN (x) = DECL_CHAIN (x);
                   2039:            x = DECL_CHAIN (x);
                   2040:          }
                   2041:        if (TREE_VEC_LENGTH (method_vec) > 1)
                   2042:          TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1);
                   2043:        else
                   2044:          TREE_CHAIN (x) = NULL_TREE;
                   2045:       }
                   2046:   }
                   2047: 
                   2048: #if 0
                   2049:   TYPE_METHODS (t) = TREE_VEC_ELT (method_vec, 0)
                   2050:     ? TREE_VEC_ELT (method_vec, 0) : TREE_VEC_ELT (method_vec, 1);
                   2051: #else
                   2052:   TYPE_METHODS (t) = method_vec;
                   2053: #endif
                   2054: 
                   2055:   return method_vec;
                   2056: }
                   2057: 
                   2058: /* Emit error when a duplicate definition of a type is seen.  Patch up. */
                   2059: 
                   2060: void
                   2061: duplicate_tag_error (t)
                   2062:      tree t;
                   2063: {
                   2064:   char *err_name;
                   2065:   tree name = TYPE_NAME (t);
                   2066:   if (TREE_CODE (name) == TYPE_DECL)
                   2067:     name = DECL_NAME (name);
                   2068:   err_name = IDENTIFIER_POINTER (name);
                   2069:   if (TREE_CODE (t) == UNION_TYPE)
                   2070:     error ("redefinition of `union %s'", err_name);
                   2071:   else if (TREE_CODE (t) == RECORD_TYPE)
                   2072:     error ("redefinition of `struct %s'", err_name);
                   2073:   else
                   2074:     error ("redefinition of tag %s", err_name);
                   2075: 
                   2076:   /* Pretend we haven't defined this type.  */
                   2077:   if (TYPE_LANG_SPECIFIC (t))
                   2078:     {
                   2079:       tree as_list = CLASSTYPE_AS_LIST (t);
                   2080:       tree binfo = TYPE_BINFO (t);
                   2081:       tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t);
                   2082:       int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
                   2083:       int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
                   2084: 
                   2085:       bzero (TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
                   2086:       BINFO_BASETYPES(binfo) = NULL_TREE;
                   2087: 
                   2088:       CLASSTYPE_AS_LIST (t) = as_list;
                   2089:       TYPE_BINFO (t) = binfo;
                   2090:       CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
                   2091:       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
                   2092:       CLASSTYPE_INTERFACE_UNKNOWN (t) = interface_unknown;
1.1.1.2 ! root     2093:       CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
1.1       root     2094:       TYPE_REDEFINED (t) = 1;
                   2095:     }
                   2096:   TYPE_SIZE (t) = NULL_TREE;
                   2097:   TYPE_MODE (t) = VOIDmode;
                   2098:   TYPE_FIELDS (t) = NULL_TREE;
                   2099:   TYPE_METHODS (t) = NULL_TREE;
                   2100:   TYPE_VFIELD (t) = NULL_TREE;
                   2101:   TYPE_CONTEXT (t) = NULL_TREE;
                   2102: }
                   2103: 
                   2104: /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
                   2105:    (or C++ class declaration).
                   2106: 
                   2107:    For C++, we must handle the building of derived classes.
                   2108:    Also, C++ allows static class members.  The way that this is
                   2109:    handled is to keep the field name where it is (as the DECL_NAME
                   2110:    of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
                   2111:    of the field.  layout_record and layout_union will know about this.
                   2112: 
                   2113:    More C++ hair: inline functions have text in their
                   2114:    DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
                   2115:    meaningful tree structure.  After the struct has been laid out, set
                   2116:    things up so that this can happen.
                   2117: 
                   2118:    And still more: virtual functions.  In the case of single inheritance,
                   2119:    when a new virtual function is seen which redefines a virtual function
                   2120:    from the base class, the new virtual function is placed into
                   2121:    the virtual function table at exactly the same address that
                   2122:    it had in the base class.  When this is extended to multiple
                   2123:    inheritance, the same thing happens, except that multiple virtual
                   2124:    function tables must be maintained.  The first virtual function
                   2125:    table is treated in exactly the same way as in the case of single
                   2126:    inheritance.  Additional virtual function tables have different
                   2127:    DELTAs, which tell how to adjust `this' to point to the right thing.
                   2128: 
                   2129:    LIST_OF_FIELDLISTS is just that.  The elements of the list are
                   2130:    TREE_LIST elements, whose TREE_PURPOSE field tells what visibility
                   2131:    the list has, and the TREE_VALUE slot gives the actual fields.
                   2132: 
                   2133:    EMPTY is non-zero if this structure has no declarations following it.
                   2134: 
                   2135:    If flag_all_virtual == 1, then we lay all functions into
                   2136:    the virtual function table, as though they were declared
                   2137:    virtual.  Constructors do not lay down in the virtual function table.
                   2138: 
                   2139:    If flag_all_virtual == 2, then we lay all functions into
                   2140:    the virtual function table, such that virtual functions
                   2141:    occupy a space by themselves, and then all functions
                   2142:    of the class occupy a space by themselves.  This is illustrated
                   2143:    in the following diagram:
                   2144: 
                   2145:    class A; class B : A;
                   2146: 
                   2147:        Class A's vtbl:                 Class B's vtbl:
                   2148:     --------------------------------------------------------------------
1.1.1.2 ! root     2149:    | A's virtual functions|            | B's virtual functions         |
1.1       root     2150:    |                     |             | (may inherit some from A).    |
                   2151:     --------------------------------------------------------------------
                   2152:    | All of A's functions |            | All of A's functions          |
                   2153:    | (such as a->A::f).          |             | (such as b->A::f)             |
                   2154:     --------------------------------------------------------------------
                   2155:                                        | B's new virtual functions     |
                   2156:                                        | (not defined in A.)           |
                   2157:                                         -------------------------------
                   2158:                                        | All of B's functions          |
                   2159:                                        | (such as b->B::f)             |
                   2160:                                         -------------------------------
                   2161: 
                   2162:    this allows the program to make references to any function, virtual
1.1.1.2 ! root     2163:    or otherwise in a type-consistent manner.  */
1.1       root     2164: 
                   2165: tree
                   2166: finish_struct (t, list_of_fieldlists, empty, warn_anon)
                   2167:      tree t;
                   2168:      tree list_of_fieldlists;
                   2169:      int empty;
                   2170:      int warn_anon;
                   2171: {
                   2172:   extern int interface_only, interface_unknown;
                   2173:   int old;
                   2174:   int round_up_size = 1;
                   2175:   /* Set non-zero to debug using default functions.
                   2176:      Not set by program.  */
                   2177:   static int debug_default_functions = 0;
                   2178: 
                   2179:   enum tree_code code = TREE_CODE (t);
                   2180:   register tree x, last_x, method_vec;
                   2181:   int needs_ctor = 0, needs_dtor = 0;
                   2182:   int members_need_dtors, needs_virtual_dtor;
                   2183:   tree name = TYPE_NAME (t), fields, fn_fields, tail;
                   2184:   enum visibility_type visibility;
                   2185:   int all_virtual;
                   2186:   int has_virtual;
                   2187:   int max_has_virtual;
                   2188:   tree pending_virtuals = NULL_TREE;
                   2189:   tree abstract_virtuals = NULL_TREE;
                   2190:   tree vfield;
                   2191:   tree vfields;
                   2192:   int needs_default_ctor;
                   2193:   int cant_have_default_ctor;
                   2194:   int needs_const_ctor;
                   2195:   int cant_have_const_ctor;
                   2196: 
                   2197:   /* The index of the first base class which has virtual
                   2198:      functions.  Only applied to non-virtual baseclasses.  */
                   2199:   int first_vfn_base_index;
                   2200: 
                   2201:   int n_baseclasses;
                   2202:   int any_default_members = 0;
                   2203:   char *err_name;
                   2204:   int const_sans_init = 0;
                   2205:   int ref_sans_init = 0;
                   2206:   int nonprivate_method = 0;
                   2207:   tree t_binfo = TYPE_BINFO (t);
                   2208: 
                   2209:   if (TREE_CODE (name) == TYPE_DECL)
                   2210:     {
                   2211:       extern int lineno;
                   2212: 
                   2213:       DECL_SOURCE_FILE (name) = input_filename;
                   2214:       DECL_SOURCE_LINE (name) = lineno;
                   2215:       name = DECL_NAME (name);
                   2216:     }
                   2217:   err_name = IDENTIFIER_POINTER (name);
                   2218: 
                   2219:   if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (name))
                   2220:     {
                   2221:       warning ("un-usable class ignored (anonymous classes and unions are useless)");
                   2222:       err_name = "(anon)";
                   2223:     }
                   2224: 
                   2225:   leftmost_baseclasses = NULL_TREE;
                   2226:   if (TYPE_SIZE (t))
                   2227:     {
                   2228:       if (TREE_CODE (t) == UNION_TYPE)
                   2229:        error ("redefinition of `union %s'", err_name);
                   2230:       else if (TREE_CODE (t) == RECORD_TYPE)
                   2231:        error ("redefinition of `struct %s'", err_name);
                   2232:       else
                   2233:        assert (0);
                   2234:       popclass (0);
                   2235:       return t;
                   2236:     }
                   2237: 
                   2238:   GNU_xref_decl (current_function_decl, t);
                   2239: 
                   2240:   /* If this type was previously laid out as a forward reference,
                   2241:      make sure we lay it out again.  */
                   2242: 
                   2243:   TYPE_SIZE (t) = 0;
                   2244:   CLASSTYPE_GOT_SEMICOLON (t) = 0;
                   2245:   CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
                   2246:   CLASSTYPE_INTERFACE_UNKNOWN (t) = interface_unknown;
                   2247: 
                   2248:   if (flag_dossier)
                   2249:     build_t_desc (t, 0);
                   2250: 
                   2251:   TYPE_BINFO (t) = NULL_TREE;
                   2252: 
                   2253:   old = suspend_momentary ();
                   2254: 
                   2255:   /* Install struct as DECL_FIELD_CONTEXT of each field decl.
                   2256:      Also process specified field sizes.
                   2257:      Set DECL_FRAME_SIZE to the specified size, or 0 if none specified.
                   2258:      The specified size is found in the DECL_INITIAL.
                   2259:      Store 0 there, except for ": 0" fields (so we can find them
                   2260:      and delete them, below).  */
                   2261: 
                   2262:   if (t_binfo && BINFO_BASETYPES (t_binfo))
                   2263:     n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
                   2264:   else
                   2265:     n_baseclasses = 0;
                   2266: 
                   2267:   if (n_baseclasses > 0)
                   2268:     {
                   2269:       struct base_info base_info;
                   2270: 
                   2271:       /* If using multiple inheritance, this may cause variants of our
                   2272:         basetypes to be used (instead of their canonical forms).  */
                   2273:       fields = layout_basetypes (t, BINFO_BASETYPES (t_binfo));
                   2274:       last_x = tree_last (fields);
                   2275: 
                   2276:       first_vfn_base_index = finish_base_struct (t, &base_info,
                   2277:                                                 BINFO_BASETYPES (t_binfo));
                   2278:       has_virtual = base_info.has_virtual;
                   2279:       max_has_virtual = base_info.max_has_virtual;
                   2280:       CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
                   2281:       vfield = base_info.vfield;
                   2282:       vfields = base_info.vfields;
                   2283:       needs_default_ctor = base_info.needs_default_ctor;
                   2284:       cant_have_default_ctor = base_info.cant_have_default_ctor;
                   2285:       needs_const_ctor = base_info.needs_const_ctor;
                   2286:       cant_have_const_ctor = base_info.cant_have_const_ctor;
                   2287:       members_need_dtors = base_info.members_need_dtors;
                   2288:       needs_virtual_dtor = base_info.needs_virtual_dtor;
                   2289:       n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
                   2290:     }
                   2291:   else
                   2292:     {
                   2293:       first_vfn_base_index = -1;
                   2294:       has_virtual = 0;
                   2295:       max_has_virtual = has_virtual;
                   2296:       vfield = NULL_TREE;
                   2297:       vfields = NULL_TREE;
                   2298:       fields = NULL_TREE;
                   2299:       last_x = NULL_TREE;
                   2300:       needs_default_ctor = 0;
                   2301:       cant_have_default_ctor = 0;
                   2302:       needs_const_ctor = 0;
                   2303:       cant_have_const_ctor = 0;
                   2304:       members_need_dtors = 0;
                   2305:       needs_virtual_dtor = 0;
                   2306:     }
                   2307: 
                   2308:   if (write_virtuals == 3 && ! CLASSTYPE_INTERFACE_UNKNOWN (t)
                   2309:       && current_lang_name == lang_name_cplusplus)
                   2310:     {
                   2311:       CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
                   2312:       CLASSTYPE_VTABLE_NEEDS_WRITING (t) = ! interface_only;
                   2313:     }
                   2314: 
                   2315:   /* The three of these are approximations which may later be
                   2316:      modified.  Needed at this point to make add_virtual_function
                   2317:      and modify_vtable_entries work.  */
                   2318:   TREE_CHAIN (t_binfo) = TYPE_BINFO (t);
                   2319:   TYPE_BINFO (t) = t_binfo;
                   2320:   CLASSTYPE_VFIELDS (t) = vfields;
                   2321:   CLASSTYPE_VFIELD (t) = vfield;
                   2322: 
                   2323:   fn_fields = NULL_TREE;
                   2324:   tail = NULL_TREE;
                   2325:   if (last_x && list_of_fieldlists)
                   2326:     TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
                   2327: 
                   2328: #ifdef SOS
                   2329:   if (flag_all_virtual == 2)
                   2330:     all_virtual = 2;
                   2331:   else
                   2332: #endif
                   2333:     {
                   2334:       if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t))
                   2335:        all_virtual = 1;
                   2336:       else
                   2337:        all_virtual = 0;
                   2338:     }
                   2339: 
                   2340:   if (CLASSTYPE_DECLARED_CLASS (t) == 0)
                   2341:     {
                   2342:       nonprivate_method = 1;
                   2343:       if (list_of_fieldlists
                   2344:          && TREE_PURPOSE (list_of_fieldlists) == (tree)visibility_default)
                   2345:        TREE_PURPOSE (list_of_fieldlists) = (tree)visibility_public;
                   2346:     }
                   2347:   else if (list_of_fieldlists
                   2348:           && TREE_PURPOSE (list_of_fieldlists) == (tree)visibility_default)
                   2349:     TREE_PURPOSE (list_of_fieldlists) = (tree)visibility_private;
                   2350: 
                   2351:   while (list_of_fieldlists)
                   2352:     {
                   2353:       visibility = (enum visibility_type)TREE_PURPOSE (list_of_fieldlists);
                   2354: 
                   2355:       for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x))
                   2356:        {
                   2357:          TREE_PRIVATE (x) = visibility == visibility_private;
                   2358:          TREE_PROTECTED (x) = visibility == visibility_protected;
                   2359:          GNU_xref_member (current_class_name, x);
                   2360: 
                   2361:           if (TREE_CODE (x) == TYPE_DECL
                   2362:               && TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE)
                   2363:             {
1.1.1.2 ! root     2364:              /* @@ Um.  This doesn't seem to be handled properly, at
        !          2365:                 least in my PT test cases.  Not sure if it's really
        !          2366:                 supposed to work for non-PT cases.  Let's find out.  */
1.1       root     2367:               static tree t, d;
                   2368:               d = DECL_NAME (x);
                   2369:               t = DECL_NAME (TYPE_NAME (TREE_TYPE (x)));
1.1.1.2 ! root     2370:              if (d == t) continue;
        !          2371:              assert (IDENTIFIER_TEMPLATE (t) != NULL_TREE);
1.1       root     2372:               t = DECL_NAME (TREE_PURPOSE (IDENTIFIER_TEMPLATE (t)));
                   2373:               assert (t == d);
                   2374:               continue;
                   2375:             }
                   2376: 
                   2377:          if (TREE_CODE (x) == FUNCTION_DECL)
                   2378:            {
                   2379:              /* Clear out this flag.
                   2380: 
                   2381:                 @@ Doug may figure out how to break
                   2382:                 @@ this with nested classes and friends.  */
                   2383:              DECL_IN_AGGR_P (x) = 0;
                   2384: 
                   2385:              nonprivate_method |= ! TREE_PRIVATE (x);
                   2386: 
                   2387:              /* If this was an evil function, don't keep it in class.  */
                   2388:              if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
                   2389:                continue;
                   2390: 
                   2391:              if (last_x) TREE_CHAIN (last_x) = TREE_CHAIN (x);
                   2392:              if (! fn_fields) fn_fields = x;
                   2393:              else TREE_CHAIN (tail) = x;
                   2394:              tail = x;
                   2395: 
                   2396: #if 0
                   2397:              /* ??? What if we have duplicate declarations
                   2398:                 in T's definition?  */
                   2399:              if (DECL_CLASS_CONTEXT (x))
                   2400:                continue;
                   2401: #endif
                   2402:              DECL_CLASS_CONTEXT (x) = t;
                   2403: 
                   2404:              DECL_FRAME_SIZE (x) = 0;
                   2405: 
                   2406:              /* The name of the field is the original field name
                   2407:                 Save this in auxiliary field for later overloading.  */
                   2408:              if (DECL_VINDEX (x)
                   2409:                  || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
                   2410:                {
                   2411:                  pending_virtuals = add_virtual_function (pending_virtuals,
                   2412:                                                           &has_virtual, x, t);
                   2413:                  if (DECL_ABSTRACT_VIRTUAL_P (x))
                   2414:                    abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
                   2415:                }
                   2416:              continue;
                   2417:            }
                   2418: 
                   2419:          /* Handle visibility declarations.  */
                   2420:          if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF)
                   2421:            {
                   2422:              tree fdecl = TREE_OPERAND (DECL_NAME (x), 1);
                   2423: 
                   2424:              if (last_x) TREE_CHAIN (last_x) = TREE_CHAIN (x);
                   2425:              /* Make type T see field decl FDECL with
                   2426:                 the visibility VISIBILITY.  */
                   2427:              if (TREE_CODE (fdecl) == TREE_LIST)
                   2428:                {
                   2429:                  fdecl = TREE_VALUE (fdecl);
                   2430:                  while (fdecl)
                   2431:                    {
                   2432:                      if (alter_visibility (t, fdecl, visibility) == 0)
                   2433:                        break;
                   2434:                      fdecl = DECL_CHAIN (fdecl);
                   2435:                    }
                   2436:                }
                   2437:              else alter_visibility (t, fdecl, visibility);
                   2438:              CLASSTYPE_ALTERS_VISIBILITIES_P (t) = 1;
                   2439:              continue;
                   2440:            }
                   2441: 
                   2442:          /* Perform error checking that did not get done in grokdeclarator.  */
                   2443:          if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE)
                   2444:            {
                   2445:              error_with_decl (x, "field `%s' invalidly declared function type");
                   2446:              TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
                   2447:            }
                   2448:          else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE)
                   2449:            {
                   2450:              error_with_decl (x, "field `%s' invalidly declared method type");
                   2451:              TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
                   2452:            }
                   2453:          else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
                   2454:            {
                   2455:              error_with_decl (x, "field `%s' invalidly declared offset type");
                   2456:              TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
                   2457:            }
                   2458:          /* If this is of reference type, check if it needs an init.  */
                   2459:          if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE
                   2460:              && DECL_INITIAL (x) == 0)
                   2461:            ref_sans_init = 1;
                   2462: 
                   2463:          /* When this goes into scope, it will be a non-local reference.  */
                   2464:          TREE_NONLOCAL (x) = 1;
                   2465: 
                   2466:          if (TREE_CODE (x) == FIELD_DECL)
                   2467:            {
                   2468:              /* Never let anything with uninheritable virtuals
                   2469:                 make it through without complaint.  */
                   2470:              if (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
                   2471:                  && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (x)))
                   2472:                abstract_virtuals_error (x, TREE_TYPE (x));
                   2473: 
                   2474:              if (TYPE_LANG_SPECIFIC (TREE_TYPE (x)))
                   2475:                {
                   2476:                  if (TYPE_HAS_DEFAULT_CONSTRUCTOR (TREE_TYPE (x)))
                   2477:                    needs_default_ctor = 1;
                   2478:                  if (TYPE_GETS_CONST_INIT_REF (TREE_TYPE (x)))
                   2479:                    needs_const_ctor = 1;
                   2480:                  else if (TYPE_GETS_INIT_REF (TREE_TYPE (x)))
                   2481:                    cant_have_const_ctor = 1;
                   2482:                }
                   2483:              else if (DECL_INITIAL (x) == NULL_TREE
                   2484:                       && (TYPE_HAS_CONSTRUCTOR (TREE_TYPE (x))
                   2485:                           || TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE))
                   2486:                cant_have_default_ctor = 1;
                   2487: 
                   2488:              /* If any field is const, the structure type is pseudo-const.  */
                   2489:              if (TREE_READONLY (x))
                   2490:                {
                   2491:                  C_TYPE_FIELDS_READONLY (t) = 1;
                   2492:                  if (DECL_INITIAL (x) == 0)
                   2493:                    const_sans_init = 1;
                   2494:                }
                   2495:              else 
                   2496:                {
                   2497:                  /* A field that is pseudo-const makes the structure likewise.  */
                   2498:                  tree t1 = TREE_TYPE (x);
                   2499:                  while (TREE_CODE (t1) == ARRAY_TYPE)
                   2500:                    t1 = TREE_TYPE (t1);
                   2501:                  if (IS_AGGR_TYPE (t1))
                   2502:                    {
                   2503:                      if (C_TYPE_FIELDS_READONLY (t1))
                   2504:                        C_TYPE_FIELDS_READONLY (t) = 1;
                   2505:                      if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1))
                   2506:                        const_sans_init = 1;
                   2507:                    }
                   2508:                }
                   2509:            }
                   2510:          else if (TREE_STATIC (x) && TREE_CODE (t) == UNION_TYPE)
                   2511:            /* Unions cannot have static members.  */
                   2512:            error_with_decl (x, "field `%s' declared static in union");
                   2513: 
                   2514:          if (! fields) fields = x;
                   2515:          DECL_FIELD_CONTEXT (x) = t;
                   2516:          DECL_CLASS_CONTEXT (x) = t;
                   2517:          DECL_FRAME_SIZE (x) = 0;
                   2518: 
                   2519:          /* We set DECL_BIT_FIELD tentatively in grokbitfield.
                   2520:             If the type and width are valid, we'll keep it set.
                   2521:             Otherwise, the flag is cleared.  */
                   2522:          if (DECL_BIT_FIELD (x))
                   2523:            {
                   2524:              DECL_BIT_FIELD (x) = 0;
                   2525:              /* Invalid bit-field size done by grokfield.  */
                   2526:              /* Detect invalid bit-field type.  */
                   2527:              if (DECL_INITIAL (x)
                   2528:                  && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
                   2529:                  && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
                   2530:                {
                   2531:                  error_with_decl (x, "bit-field `%s' has invalid type");
                   2532:                  DECL_INITIAL (x) = NULL;
                   2533:                }
                   2534:              if (DECL_INITIAL (x) && pedantic
                   2535:                  && TREE_TYPE (x) != integer_type_node
                   2536:                  && TREE_TYPE (x) != unsigned_type_node)
                   2537:                warning_with_decl (x, "bit-field `%s' type invalid in ANSI C");
                   2538: 
                   2539:              /* Detect and ignore out of range field width.  */
                   2540:              if (DECL_INITIAL (x))
                   2541:                {
                   2542:                  register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
                   2543: 
                   2544:                  if (width < 0)
                   2545:                    {
                   2546:                      DECL_INITIAL (x) = NULL;
                   2547:                      warning_with_decl (x, "negative width in bit-field `%s'");
                   2548:                    }
                   2549:                  else if (width == 0 && DECL_NAME (x) != 0)
                   2550:                    {
                   2551:                      error_with_decl (x, "zero width for bit-field `%s'");
                   2552:                      DECL_INITIAL (x) = NULL;
                   2553:                    }
                   2554:                  else if ((unsigned)width > TYPE_PRECISION (TREE_TYPE (x)))
                   2555:                    {
                   2556:                      DECL_INITIAL (x) = NULL;
                   2557:                      warning_with_decl (x, "width of `%s' exceeds its type");
                   2558:                    }
                   2559:                }
                   2560: 
                   2561:              /* Process valid field width.  */
                   2562:              if (DECL_INITIAL (x))
                   2563:                {
                   2564:                  register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
                   2565: 
                   2566:                  if (width == 0)
                   2567:                    {
                   2568: #ifdef EMPTY_FIELD_BOUNDARY
                   2569:                      /* field size 0 => mark following field as "aligned" */
                   2570:                      if (TREE_CHAIN (x))
                   2571:                        DECL_ALIGN (TREE_CHAIN (x))
                   2572:                          = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
                   2573:                      /* field of size 0 at the end => round up the size.  */
                   2574:                      else
                   2575:                        round_up_size = EMPTY_FIELD_BOUNDARY;
                   2576: #endif
                   2577: #ifdef PCC_BITFIELD_TYPE_MATTERS
                   2578:                      DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
                   2579:                                            TYPE_ALIGN (TREE_TYPE (x)));
                   2580: #endif
                   2581:                    }
                   2582:                  else
                   2583:                    {
                   2584:                      DECL_INITIAL (x) = NULL_TREE;
                   2585:                      DECL_FRAME_SIZE (x) = width;
                   2586:                      DECL_BIT_FIELD (x) = 1;
                   2587:                      /* Traditionally a bit field is unsigned
                   2588:                         even if declared signed.  */
                   2589:                      if (flag_traditional
                   2590:                          && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
                   2591:                        TREE_TYPE (x) = unsigned_type_node;
                   2592:                    }
                   2593:                }
                   2594:              else
                   2595:                /* Non-bit-fields are aligned for their type.  */
                   2596:                DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
                   2597:            }
                   2598:          else if (TREE_CODE (x) == FIELD_DECL)
                   2599:            {
                   2600:              tree type = TREE_TYPE (x);
                   2601:              if (TREE_CODE (type) == ARRAY_TYPE)
                   2602:                type = TREE_TYPE (type);
                   2603:              if (code == UNION_TYPE && IS_AGGR_TYPE (type))
                   2604:                {
                   2605:                  if (TYPE_NEEDS_CONSTRUCTING (type)
                   2606:                      || TYPE_NEEDS_DESTRUCTOR (type))
                   2607:                    error_with_decl (x, "member `%s' with constructor or destructor not allowed in union");
                   2608:                  TYPE_GETS_ASSIGNMENT (t) |= TYPE_GETS_ASSIGNMENT (type);
                   2609:                  TYPE_GETS_INIT_REF (t) |= TYPE_GETS_INIT_REF (type);
                   2610:                }
                   2611:              else if (code == RECORD_TYPE)
                   2612:                {
                   2613:                  /* Array of record type doesn't matter for this bit.  */
                   2614:                  TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
                   2615:                  if (IS_AGGR_TYPE (type))
                   2616:                    {
                   2617:                      needs_ctor |= TYPE_NEEDS_CONSTRUCTOR (type);
                   2618:                      needs_dtor |= TYPE_NEEDS_DESTRUCTOR (type);
                   2619:                      members_need_dtors |= TYPE_NEEDS_DESTRUCTOR (type);
                   2620:                      TYPE_GETS_CONST_INIT_REF (t) |= TYPE_GETS_CONST_INIT_REF (type);
                   2621:                      TYPE_GETS_ASSIGNMENT (t) |= TYPE_GETS_ASSIGNMENT (type);
                   2622:                      TYPE_GETS_INIT_REF (t) |= TYPE_GETS_INIT_REF (type);
                   2623:                    }
                   2624:                }
                   2625:              if (DECL_INITIAL (x) != NULL_TREE)
                   2626:                {
                   2627:                  /* `build_class_init_list' does not recognize non-FIELD_DECLs.  */
                   2628:                  if (code == UNION_TYPE && any_default_members != 0)
                   2629:                    error ("multiple fields in union initialized");
                   2630:                  any_default_members = 1;
                   2631:                }
                   2632:            }
                   2633:          last_x = x;
                   2634:        }
                   2635:       list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
                   2636:       /* link the tail while we have it! */
                   2637:       if (last_x)
                   2638:        {
                   2639:          TREE_CHAIN (last_x) = NULL_TREE;
                   2640: 
                   2641:          if (list_of_fieldlists
                   2642:              && TREE_VALUE (list_of_fieldlists)
                   2643:              && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
                   2644:            TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
                   2645:        }
                   2646:     }
                   2647: 
                   2648:   if (tail) TREE_CHAIN (tail) = NULL_TREE;
                   2649: 
                   2650:   /* If this type has any constant members which did not come
                   2651:      with their own initialization, mark that fact here.  It is
                   2652:      not an error here, since such types can be saved either by their
                   2653:      constructors, or by fortuitous initialization.  */
                   2654:   CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
                   2655:   CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
                   2656:   CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
                   2657: 
                   2658:   if (members_need_dtors && !TYPE_HAS_DESTRUCTOR (t))
                   2659:     {
                   2660:       /* Here we must cons up a destructor on the fly.  */
                   2661:       tree dtor = cons_up_default_function (t, name,
                   2662:                                            needs_virtual_dtor != 0);
                   2663: 
                   2664:       /* If we couldn't make it work, then pretend we didn't need it.  */
                   2665:       if (dtor == void_type_node)
                   2666:        TYPE_NEEDS_DESTRUCTOR (t) = 0;
                   2667:       else
                   2668:        {
                   2669:          if (! fn_fields) fn_fields = dtor;
                   2670:          else TREE_CHAIN (tail) = dtor;
                   2671:          tail = dtor;
                   2672: 
                   2673:          if (DECL_VINDEX (dtor) == NULL_TREE
                   2674:              && ! CLASSTYPE_DECLARED_EXCEPTION (t)
                   2675:              && (needs_virtual_dtor
                   2676:                  || pending_virtuals != NULL_TREE
                   2677:                  || pending_hard_virtuals != NULL_TREE))
                   2678:            DECL_VINDEX (dtor) = error_mark_node;
                   2679:          if (DECL_VINDEX (dtor))
                   2680:            pending_virtuals = add_virtual_function (pending_virtuals,
                   2681:                                                     &has_virtual, dtor, NULL);
                   2682:          nonprivate_method = 1;
                   2683:          TYPE_HAS_DESTRUCTOR (t) = 1;
                   2684:        }
                   2685:     }
                   2686: 
                   2687:   if (debug_default_functions)
                   2688:     {
                   2689:       if ((TYPE_NEEDS_CONSTRUCTOR (t) || TYPE_HAS_CONSTRUCTOR (t) || needs_ctor)
                   2690:          && ! TYPE_HAS_INIT_REF (t))
                   2691:        {
                   2692:          tree default_fn = cons_up_default_function (t, name, 4);
                   2693:          TREE_CHAIN (default_fn) = fn_fields;
                   2694:          fn_fields = default_fn;
                   2695:          TYPE_HAS_INIT_REF (t) = 1;
                   2696:          default_fn = cons_up_default_function (t, name, 3);
                   2697:          TREE_CHAIN (default_fn) = fn_fields;
                   2698:          fn_fields = default_fn;
                   2699:          nonprivate_method = 1;
                   2700:        }
                   2701: 
                   2702:       if (! TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
                   2703:          && needs_default_ctor && ! cant_have_default_ctor)
                   2704:        {
                   2705:          tree default_fn = cons_up_default_function (t, name, 2);
                   2706:          TREE_CHAIN (default_fn) = fn_fields;
                   2707:          fn_fields = default_fn;
                   2708:          TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 1;
                   2709:          nonprivate_method = 1;
                   2710:        }
                   2711:     }
                   2712: 
                   2713:   if (fn_fields)
                   2714:     {
                   2715:       method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
                   2716: 
                   2717:       if (TYPE_HAS_CONSTRUCTOR (t)
                   2718:          && ! CLASSTYPE_DECLARED_EXCEPTION (t)
                   2719:          && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
                   2720:          && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
                   2721:        {
                   2722:          int nonprivate_ctor = 0;
                   2723:          tree ctor;
                   2724: 
                   2725:          for (ctor = TREE_VEC_ELT (method_vec, 0); ctor;
                   2726:               ctor = DECL_CHAIN (ctor))
                   2727:            if (! TREE_PRIVATE (ctor))
                   2728:              {
                   2729:                nonprivate_ctor = 1;
                   2730:                break;
                   2731:              }
                   2732:          if (nonprivate_ctor == 0)
                   2733:            warning ("class `%s' only defines private constructors and has no friends",
                   2734:                     err_name);
                   2735:        }
                   2736:     }
                   2737:   else
                   2738:     {
                   2739:       method_vec = 0;
                   2740: 
1.1.1.2 ! root     2741:       /* Just in case these got accidentally
1.1       root     2742:         filled in by syntax errors.  */
                   2743:       TYPE_HAS_CONSTRUCTOR (t) = 0;
                   2744:       TYPE_HAS_DESTRUCTOR (t) = 0;
                   2745:     }
                   2746: 
                   2747:   if (vfield == 0
                   2748:       && (has_virtual
                   2749: #ifdef SOS
                   2750:          || TYPE_DYNAMIC (t)
                   2751: #endif
                   2752:          ))
                   2753:     {
                   2754:       /* We build this decl with ptr_type_node, and
                   2755:         change the type when we know what it should be.  */
                   2756:       vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t), ptr_type_node);
                   2757:       DECL_ASSEMBLER_NAME (vfield) = get_identifier ("$vf");
                   2758:       CLASSTYPE_VFIELD (t) = vfield;
                   2759:       DECL_VIRTUAL_P (vfield) = 1;
                   2760:       DECL_FIELD_CONTEXT (vfield) = t;
                   2761:       DECL_CLASS_CONTEXT (vfield) = t;
                   2762:       DECL_FCONTEXT (vfield) = t;
                   2763:       DECL_FRAME_SIZE (vfield) = 0;
                   2764:       DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
                   2765:       if (CLASSTYPE_DOSSIER (t))
                   2766:        {
                   2767:          /* vfield is always first entry in structure.  */
                   2768:          TREE_CHAIN (vfield) = fields;
                   2769:          fields = vfield;
                   2770:        }
                   2771:       else if (last_x)
                   2772:        {
                   2773:          assert (TREE_CHAIN (last_x) == 0);
                   2774:          TREE_CHAIN (last_x) = vfield;
                   2775:          last_x = vfield;
                   2776:        }
                   2777:       else fields = vfield;
                   2778:       vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
                   2779:     }
                   2780: 
                   2781:   /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
                   2782:      And they have already done their work.
                   2783: 
                   2784:      C++: maybe we will support default field initialization some day...  */
                   2785: 
                   2786:   /* Delete all zero-width bit-fields from the front of the fieldlist */
                   2787:   while (fields && DECL_BIT_FIELD (fields)
                   2788:         && DECL_INITIAL (fields))
                   2789:     fields = TREE_CHAIN (fields);
                   2790:   /* Delete all such fields from the rest of the fields.  */
                   2791:   for (x = fields; x;)
                   2792:     {
                   2793:       if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x))
                   2794:          && DECL_INITIAL (TREE_CHAIN (x)))
                   2795:        TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
                   2796:       else x = TREE_CHAIN (x);
                   2797:     }
                   2798:   /* Delete all duplicate fields from the fields */
                   2799:   delete_duplicate_fields (fields);
                   2800: 
                   2801:   /* Now we have the final fieldlist for the data fields.  Record it,
                   2802:      then lay out the structure or union (including the fields).  */
                   2803: 
                   2804:   TYPE_FIELDS (t) = fields;
                   2805: 
                   2806:   /* If there's a :0 field at the end, round the size to the
                   2807:      EMPTY_FIELD_BOUNDARY.  */
                   2808:   TYPE_ALIGN (t) = round_up_size;
                   2809: 
                   2810:   /* Pass layout information about base classes to layout_type, if any.  */
                   2811: 
                   2812:   if (n_baseclasses)
                   2813:     {
                   2814:       tree pseudo_basetype = TREE_TYPE (base_layout_decl);
                   2815: 
                   2816:       TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t);
                   2817:       TYPE_FIELDS (t) = base_layout_decl;
                   2818: 
                   2819:       TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t);
                   2820:       TYPE_MODE (pseudo_basetype) = TYPE_MODE (t);
                   2821:       TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t);
                   2822:       DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype);
                   2823:     }
                   2824: 
                   2825:   layout_type (t);
                   2826: 
                   2827:   if (n_baseclasses)
                   2828:     TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
                   2829: 
                   2830:   /* C++: do not let empty structures exist.  */
                   2831:   if (integer_zerop (TYPE_SIZE (t)))
                   2832:     TYPE_SIZE (t) = TYPE_SIZE (char_type_node);
                   2833: 
                   2834:   /* Set the TYPE_DECL for this type to contain the right
                   2835:      value for DECL_OFFSET, so that we can use it as part
                   2836:      of a COMPONENT_REF for multiple inheritance.  */
                   2837: 
                   2838:   if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
                   2839:     layout_decl (TYPE_NAME (t), 0);
                   2840: 
                   2841:   /* Now fix up any virtual base class types that we
                   2842:      left lying around.  We must get these done
                   2843:      before we try to lay out the virtual function table.  */
                   2844:   doing_hard_virtuals = 1;
                   2845:   pending_hard_virtuals = nreverse (pending_hard_virtuals);
                   2846: 
                   2847:   if (TYPE_USES_VIRTUAL_BASECLASSES (t))
                   2848:     {
                   2849:       tree vbases;
                   2850: 
                   2851:       max_has_virtual = layout_vbasetypes (t, max_has_virtual);
                   2852:       vbases = CLASSTYPE_VBASECLASSES (t);
                   2853:       CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
                   2854: 
                   2855:       /* This loop makes all the entries in the virtual function tables
                   2856:         of interest contain the "latest" version of the functions
                   2857:         we have defined.  */
                   2858: 
                   2859:       while (vbases)
                   2860:        {
                   2861:          tree virtuals = BINFO_VIRTUALS (vbases);
                   2862: 
                   2863:          if (virtuals)
                   2864:            {
                   2865:              /* Get past the `null' vtable entry...  */
                   2866:              virtuals = TREE_CHAIN (virtuals);
                   2867:              /* and the `dossier' vtable entry if we're doing dossiers.  */
                   2868:              if (flag_dossier)
                   2869:                virtuals = TREE_CHAIN (virtuals);
                   2870:            }
                   2871: 
                   2872:          while (virtuals != NULL_TREE)
                   2873:            {
                   2874:              tree pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals));
                   2875:              tree base_fndecl = TREE_OPERAND (pfn, 0);
                   2876:              tree decl = get_first_matching_virtual (TYPE_BINFO (t), base_fndecl,
                   2877:                                                      DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)));
                   2878:              tree context = DECL_CLASS_CONTEXT (decl);
                   2879:              if (decl != base_fndecl && context != t)
                   2880:                {
                   2881:                  tree base_context = DECL_CLASS_CONTEXT (base_fndecl);
                   2882:                  tree binfo = NULL_TREE, these_virtuals;
                   2883:                  unsigned i = (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
                   2884:                                & (((unsigned)1<<(BITS_PER_WORD-1))-1));
                   2885: 
                   2886:                  if (TYPE_USES_VIRTUAL_BASECLASSES (context))
                   2887:                    binfo = virtual_member (base_context,
                   2888:                                            CLASSTYPE_VBASECLASSES (context));
                   2889:                  if (binfo == NULL_TREE)
                   2890:                    binfo = binfo_value (base_context, context, 0);
                   2891:                  if (binfo != NULL_TREE)
                   2892:                    {
                   2893:                      these_virtuals = BINFO_VIRTUALS (binfo);
                   2894: 
                   2895:                      while (i-- > 0)
                   2896:                        these_virtuals = TREE_CHAIN (these_virtuals);
                   2897:                      pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (these_virtuals));
                   2898:                      modify_vtable_entries (t, decl, base_fndecl, pfn);
                   2899:                    }
                   2900:                }
                   2901:              virtuals = TREE_CHAIN (virtuals);
                   2902:            }
                   2903:          /* Update dossier info with offsets for virtual baseclasses.  */
                   2904:          if (flag_dossier && ! BINFO_NEW_VTABLE_MARKED (vbases))
                   2905:            prepare_fresh_vtable (vbases, vbases, t);
                   2906: 
                   2907:          vbases = TREE_CHAIN (vbases);
                   2908:        }
                   2909:     }
                   2910: 
                   2911:   while (pending_hard_virtuals)
                   2912:     {
                   2913:       /* Need an entry in some other virtual function table.  */
                   2914:       if (TREE_TYPE (pending_hard_virtuals))
                   2915:        {
                   2916:          /* This is how we modify entries when a vfn's index changes
                   2917:             between derived and base type.  */
                   2918:          modify_vtable_entries (t, TREE_PURPOSE (pending_hard_virtuals),
                   2919:                                 TREE_TYPE (pending_hard_virtuals),
                   2920:                                 TREE_VALUE (pending_hard_virtuals));
                   2921:        }
                   2922:       else
                   2923:        {
                   2924:          /* This is how we modify entries when a vfn comes from
                   2925:             a virtual baseclass.  */
                   2926:          tree base_fndecls = DECL_VINDEX (TREE_PURPOSE (pending_hard_virtuals));
                   2927:          assert (base_fndecls != error_mark_node);
                   2928:          while (base_fndecls)
                   2929:            {
                   2930:              modify_vtable_entries (t, TREE_PURPOSE (pending_hard_virtuals),
                   2931:                                     TREE_VALUE (base_fndecls),
                   2932:                                     TREE_VALUE (pending_hard_virtuals));
                   2933:              base_fndecls = TREE_CHAIN (base_fndecls);
                   2934:            }
                   2935:        }
                   2936:       pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
                   2937:     }
                   2938:   doing_hard_virtuals = 0;
                   2939: 
                   2940:   /* Under our model of GC, every C++ class gets its own virtual
                   2941:      function table, at least virtually.  */
                   2942:   if (pending_virtuals || CLASSTYPE_DOSSIER (t))
                   2943:     {
                   2944:       pending_virtuals = nreverse (pending_virtuals);
                   2945:       /* We must enter these virtuals into the table.  */
                   2946:       if (first_vfn_base_index < 0)
                   2947:        {
                   2948:          if (flag_dossier)
                   2949:            pending_virtuals = tree_cons (NULL_TREE,
                   2950:                                          build_vtable_entry (integer_zero_node,
                   2951:                                                              build_t_desc (t, 0)),
                   2952:                                          pending_virtuals);
                   2953:          pending_virtuals = tree_cons (NULL_TREE, the_null_vtable_entry,
                   2954:                                        pending_virtuals);
                   2955:          build_vtable (0, t);
                   2956:        }
                   2957:       else
                   2958:        {
                   2959:          /* Here we know enough to change the type of our virtual
                   2960:             function table, but we will wait until later this function.  */
                   2961: 
                   2962:          if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
                   2963:            build_vtable (binfo_value (TYPE_BINFO_BASETYPE (t, first_vfn_base_index), t, 0), t);
                   2964: 
                   2965:          /* Update the dossier pointer for this class.  */
                   2966:          if (flag_dossier)
                   2967:            TREE_VALUE (TREE_CHAIN (TYPE_BINFO_VIRTUALS (t)))
                   2968:              = build_vtable_entry (integer_zero_node, build_t_desc (t, 0));
                   2969:        }
                   2970: 
                   2971:       /* If this type has basetypes with constructors, then those
                   2972:         constructors might clobber the virtual function table.  But
                   2973:         they don't if the derived class shares the exact vtable of the base
                   2974:         class.  */
                   2975: 
                   2976:       CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
                   2977:     }
                   2978:   else if (first_vfn_base_index >= 0)
                   2979:     {
                   2980:       tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
                   2981:       tree basetype = BINFO_TYPE (binfo);
                   2982: 
                   2983:       /* This class contributes nothing new to the virtual function
                   2984:         table.  However, it may have declared functions which
                   2985:         went into the virtual function table "inherited" from the
                   2986:         base class.  If so, we grab a copy of those updated functions,
                   2987:         and pretend they are ours.  */
                   2988: 
                   2989: #ifdef SOS
                   2990:       /* Don't define this ahead of time if we have more
                   2991:         fields to add later.  */
                   2992:       if (all_virtual == 2 && fn_fields != NULL_TREE)
                   2993:        ;
                   2994:       else
                   2995: #endif
                   2996:        {
                   2997:          /* See if we should steal the virtual info from base class.  */
                   2998:          if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
                   2999:            TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
                   3000:          if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
                   3001:            TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
                   3002:        }
                   3003:       if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
                   3004:        CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
                   3005:     }
                   3006: 
                   3007:   if (has_virtual > max_has_virtual)
                   3008:     max_has_virtual = has_virtual;
                   3009:   if (max_has_virtual || first_vfn_base_index >= 0)
                   3010:     {
                   3011: #ifdef VTABLE_USES_MASK
                   3012:       if (max_has_virtual >= VINDEX_MAX)
                   3013:        {
                   3014:          error ("too many virtual functions for class `%s' (VINDEX_MAX < %d)",
                   3015:                 err_name, has_virtual);
                   3016:        }
                   3017: #endif
                   3018:       TYPE_VIRTUAL_P (t) = 1;
                   3019:       CLASSTYPE_VSIZE (t) = has_virtual;
                   3020:       if (first_vfn_base_index >= 0)
                   3021:        {
                   3022:          if (pending_virtuals)
                   3023:            TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
                   3024:                                                pending_virtuals);
                   3025:        }
                   3026:       else if (has_virtual)
                   3027:        {
                   3028:          TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
                   3029:          if (write_virtuals >= 0)
                   3030:            DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
                   3031:        }
                   3032:     }
                   3033: 
                   3034: #ifdef SOS
                   3035:   if (all_virtual == 2 && (max_has_virtual || method_vec))
                   3036:     {
                   3037:       /* Now that we know the size of the virtual table, lay out
                   3038:         the absolute table following it.  */
                   3039:       int i;
                   3040:       tree tmp;
                   3041:       tree pending_absolutes = NULL_TREE;
                   3042:       int has_absolute = has_virtual;
                   3043: 
                   3044:       /* Local variables for building a table filled with strings
                   3045:         containing the names of interesting things.  */
                   3046:       tree decl, init;
                   3047:       tree start = NULL_TREE, next = NULL_TREE;
                   3048:       tree *outer = &TREE_VEC_ELT (method_vec, 0);
                   3049: 
                   3050:       while (outer != TREE_VEC_END (method_vec))
                   3051:        {
                   3052:          tree inner;
                   3053:          for (inner = *outer; inner; inner = DECL_CHAIN (inner))
                   3054:            {
                   3055:              tree entry;
                   3056:              tree fn;
                   3057: 
                   3058:              /* Don't bother with functions which appear
                   3059:                 for visibility reasons.  */
                   3060:              if (DECL_FIELD_CONTEXT (inner) != t)
                   3061:                continue;
                   3062: 
                   3063:              /* Must lay this function into its absolute table as well.
                   3064:                 This forces an inline function to be written out.  */
                   3065:              fn = build1 (ADDR_EXPR, ptr_type_node, inner);
                   3066:              TREE_CONSTANT (fn) = 1;
                   3067:              DECL_DINDEX (inner) = build_int_2 (++has_absolute, 0);
                   3068:              entry = build_vtable_entry (integer_zero_node, fn);
                   3069:              pending_absolutes = tree_cons (DECL_DINDEX (inner), entry,
                   3070:                                             pending_absolutes);
                   3071:            }
                   3072:          outer++;
                   3073:        }
                   3074: 
                   3075:       TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
                   3076:                                          nreverse (pending_absolutes));
                   3077:       if (TYPE_DYNAMIC (t))
                   3078:        {
                   3079:          for (outer = &TREE_VEC_ELT (method_vec, 0);
                   3080:               outer != TREE_VEC_END (method_vec);
                   3081:               outer++)
                   3082:            {
                   3083:              tree inner;
                   3084:              for (inner = *outer; inner; inner = DECL_CHAIN (inner))
                   3085:                {
                   3086:                  tree str = make_node (STRING_CST);
                   3087:                  TREE_STRING_LENGTH (str) = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (inner));
                   3088:                  TREE_STRING_POINTER (str) = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (inner));
                   3089:                  TREE_CONSTANT (str) = 1;
                   3090:                  TREE_STATIC (str) = 1;
                   3091:                  TREE_TYPE (str)
                   3092:                    = build_cplus_array_type (char_type_node,
                   3093:                                              build_index_type (build_int_2 (TREE_STRING_LENGTH (str) - 1, 0)));
                   3094:              
                   3095:                  if (start)
                   3096:                    {
                   3097:                      TREE_CHAIN (next) = build_tree_list (NULL_TREE, str);
                   3098:                      next = TREE_CHAIN (next);
                   3099:                    }
                   3100:                  else
                   3101:                    {
                   3102:                      start = build_tree_list (NULL_TREE, str);
                   3103:                      next = start;
                   3104:                    }
                   3105:                }
                   3106:            }
                   3107: 
                   3108:          /* Lay out dynamic link table for SOS.  */
                   3109: 
                   3110:          decl = finish_table (get_linktable_name (t),
                   3111:                               string_type_node, start, 0);
                   3112:        }
                   3113:       has_virtual = has_absolute;
                   3114:       CLASSTYPE_VSIZE (t) = has_virtual;
                   3115:       if (has_virtual > max_has_virtual)
                   3116:        max_has_virtual = has_virtual;
                   3117:       if (vfield == 0)
                   3118:        {
                   3119:          /* We build this decl with ptr_type_node, and
                   3120:             change the type when we know what it should be.  */
                   3121:          vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t), ptr_type_node);
                   3122:          DECL_ASSEMBLER_NAME (vfield) = get_identifier ("$vf");
                   3123:          CLASSTYPE_VFIELD (t) = vfield;
                   3124:          DECL_VIRTUAL_P (vfield) = 1;
                   3125:          DECL_FIELD_CONTEXT (vfield) = t;
                   3126:          DECL_CLASS_CONTEXT (vfield) = t;
                   3127:          DECL_FCONTEXT (vfield) = t;
                   3128:          DECL_FRAME_SIZE (vfield) = 0;
                   3129:          y = tree_last (fields);
                   3130:          if (y)
                   3131:            TREE_CHAIN (y) = vfield;
                   3132:          else
                   3133:            fields = vfield;
                   3134:          vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
                   3135:        }
                   3136:     }
                   3137: #endif
                   3138: 
                   3139:   /* Now lay out the virtual function table.  */
                   3140:   if (has_virtual)
                   3141:     {
                   3142:       tree atype, itype;
                   3143: 
                   3144:       if (TREE_TYPE (vfield) == ptr_type_node)
                   3145:        {
                   3146:          /* We must create a pointer to this table because
                   3147:             the one inherited from base class does not exist.
                   3148:             We will fill in the type when we know what it
                   3149:             should really be.  Use `size_int' so values are memoized
                   3150:             in common cases.  */
                   3151:          itype = build_index_type (size_int (has_virtual));
                   3152:          atype = build_array_type (vtable_entry_type, itype);
                   3153:          layout_type (atype);
                   3154:          TREE_TYPE (vfield) = build_pointer_type (atype);
                   3155:        }
                   3156:       else
                   3157:        {
                   3158:          atype = TREE_TYPE (TREE_TYPE (vfield));
                   3159: 
                   3160:          if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))))
                   3161:            {
                   3162:              /* We must extend (or create) the boundaries on this array,
                   3163:                 because we picked up virtual functions from multiple
                   3164:                 base classes.  */
                   3165:              itype = build_index_type (size_int (has_virtual));
                   3166:              atype = build_array_type (vtable_entry_type, itype);
                   3167:              layout_type (atype);
                   3168:              vfield = copy_node (vfield);
                   3169:              TREE_TYPE (vfield) = build_pointer_type (atype);
                   3170:            }
                   3171:        }
                   3172: 
                   3173:       CLASSTYPE_VFIELD (t) = vfield;
                   3174:       if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
                   3175:        {
                   3176:          TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
                   3177:          layout_decl (TYPE_BINFO_VTABLE (t), 0);
                   3178:          DECL_ALIGN (TYPE_BINFO_VTABLE (t))
                   3179:            = MAX (TYPE_ALIGN (double_type_node),
                   3180:                   DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
                   3181:        }
                   3182:     }
                   3183:   else if (first_vfn_base_index >= 0)
                   3184:     CLASSTYPE_VFIELD (t) = vfield;
                   3185:   CLASSTYPE_VFIELDS (t) = vfields;
                   3186: 
                   3187:   /* Set all appropriate CLASSTYPE_... flags for this type
                   3188:      and its variants.  */
                   3189:   TYPE_NEEDS_CONSTRUCTOR (t) |= needs_ctor || TYPE_HAS_CONSTRUCTOR (t);
                   3190:   TYPE_NEEDS_CONSTRUCTING (t)
                   3191:     |= ((TYPE_NEEDS_CONSTRUCTOR (t)|TYPE_USES_VIRTUAL_BASECLASSES (t))
                   3192:        || has_virtual || any_default_members
                   3193:        || first_vfn_base_index >= 0);
                   3194:   TYPE_NEEDS_DESTRUCTOR (t) |= needs_dtor || TYPE_HAS_DESTRUCTOR (t);
                   3195:   finish_struct_bits (t, max_has_virtual);
                   3196: 
                   3197:   /* Promote each bit-field's type to int if it is narrower than that.
                   3198:      Also warn (or error) if static members are specified for a class
                   3199:      which takes a constructor.  */
                   3200:   for (x = fields; x; x = TREE_CHAIN (x))
                   3201:     {
                   3202:       if (DECL_BIT_FIELD (x)
                   3203:          && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE
                   3204:          && ((unsigned)TREE_INT_CST_LOW (DECL_SIZE (x))
                   3205:              < TYPE_PRECISION (integer_type_node)))
                   3206:        TREE_TYPE (x) = integer_type_node;
                   3207:     }
                   3208: 
                   3209:   /* Now add the tags, if any, to the list of TYPE_DECLs
                   3210:      defined for this type.  */
                   3211:   if (CLASSTYPE_TAGS (t))
                   3212:     {
                   3213:       x = CLASSTYPE_TAGS (t);
                   3214:       last_x = tree_last (TYPE_FIELDS (t));
                   3215:       while (x)
                   3216:        {
                   3217:          tree tag = build_lang_decl (TYPE_DECL, TREE_PURPOSE (x), TREE_VALUE (x));
                   3218:          DECL_CONTEXT (tag) = t;
                   3219:          DECL_CLASS_CONTEXT (tag) = t;
                   3220:          x = TREE_CHAIN (x);
                   3221:          last_x = chainon (last_x, tag);
                   3222:        }
                   3223:       if (TYPE_FIELDS (t) == 0)
                   3224:        TYPE_FIELDS (t) = last_x;
                   3225:       CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
                   3226:     }
                   3227: 
                   3228:   if (TYPE_HAS_CONSTRUCTOR (t))
                   3229:     {
                   3230:       tree vfields = CLASSTYPE_VFIELDS (t);
                   3231: 
                   3232:       while (vfields)
                   3233:        {
                   3234:          /* Mark the fact that constructor for T
                   3235:             could affect anybody inheriting from T
                   3236:             who wants to initialize vtables for VFIELDS's type.  */
                   3237:          if (VF_DERIVED_VALUE (vfields))
                   3238:            TREE_ADDRESSABLE (vfields) = 1;
                   3239:          vfields = TREE_CHAIN (vfields);
                   3240:        }
                   3241:       if (any_default_members != 0)
                   3242:        build_class_init_list (t);
                   3243:     }
                   3244:   else if (TYPE_NEEDS_CONSTRUCTING (t))
                   3245:     build_class_init_list (t);
                   3246: 
                   3247:   if (current_lang_name == lang_name_cplusplus)
                   3248:     {
                   3249:       if (! CLASSTYPE_DECLARED_EXCEPTION (t))
                   3250:        embrace_waiting_friends (t);
                   3251: 
                   3252:       /* Write out inline function definitions.  */
                   3253:       do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
                   3254:       CLASSTYPE_INLINE_FRIENDS (t) = 0;
                   3255:     }
                   3256: 
                   3257:   if (CLASSTYPE_VSIZE (t) != 0)
                   3258:     {
                   3259: #if 0
                   3260:       if (!TYPE_USES_COMPLEX_INHERITANCE (t))
                   3261:        TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
                   3262: #endif
                   3263: 
                   3264:       if ((flag_this_is_variable & 1) == 0)
                   3265:        {
                   3266:          tree vtbl_ptr = build_decl (VAR_DECL, get_identifier (VPTR_NAME),
                   3267:                                      TREE_TYPE (vfield));
                   3268:          TREE_REGDECL (vtbl_ptr) = 1;
                   3269:          CLASSTYPE_VTBL_PTR (t) = vtbl_ptr;
                   3270:        }
                   3271:       if (DECL_FIELD_CONTEXT (vfield) != t)
                   3272:        {
                   3273:          tree binfo = binfo_value (DECL_FIELD_CONTEXT (vfield), t, 0);
                   3274:          tree offset = BINFO_OFFSET (binfo);
                   3275: 
                   3276:          vfield = copy_node (vfield);
                   3277:          copy_lang_decl (vfield);
                   3278: 
                   3279:          if (! integer_zerop (offset))
                   3280:            offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
                   3281:          DECL_FIELD_CONTEXT (vfield) = t;
                   3282:          DECL_CLASS_CONTEXT (vfield) = t;
                   3283:          DECL_FIELD_BITPOS (vfield)
                   3284:            = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
                   3285:          CLASSTYPE_VFIELD (t) = vfield;
                   3286:        }
                   3287:       if (TYPE_HAS_DESTRUCTOR (t)
                   3288:          && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE)
                   3289:        warning ("class `%s' has virtual functions but non-virtual destructor",
                   3290:                 err_name);
                   3291:     }
                   3292: 
                   3293:   /* Make the rtl for any new vtables we have created, and unmark
                   3294:      the base types we marked.  */
                   3295:   unmark_finished_struct (t);
                   3296:   TYPE_BEING_DEFINED (t) = 0;
                   3297: 
                   3298:   if (flag_dossier && CLASSTYPE_VTABLE_NEEDS_WRITING (t))
                   3299:     {
                   3300:       tree variants;
                   3301:       tree tdecl;
                   3302: 
                   3303:       /* Now instantiate its type descriptors.  */
                   3304:       tdecl = TREE_OPERAND (build_t_desc (t, 1), 0);
                   3305:       variants = TYPE_POINTER_TO (t);
                   3306:       build_type_variant (variants, 1, 0);
                   3307:       while (variants)
                   3308:        {
                   3309:          build_t_desc (variants, 1);
                   3310:          variants = TYPE_NEXT_VARIANT (variants);
                   3311:        }
                   3312:       variants = build_reference_type (t);
                   3313:       build_type_variant (variants, 1, 0);
                   3314:       while (variants)
                   3315:        {
                   3316:          build_t_desc (variants, 1);
                   3317:          variants = TYPE_NEXT_VARIANT (variants);
                   3318:        }
                   3319:       DECL_VPARENT (tdecl) = t;
                   3320:       DECL_CONTEXT (tdecl) = t;
                   3321:     }
                   3322:   /* Still need to instantiate this C struct's type descriptor.  */
                   3323:   else if (flag_dossier && ! CLASSTYPE_DOSSIER (t))
                   3324:     build_t_desc (t, 1);
                   3325: 
                   3326:   if (TYPE_NAME (t) && DECL_NAME (TYPE_NAME (t)))
                   3327:     undo_template_name_overload (DECL_NAME (TYPE_NAME (t)), 1);
                   3328:   popclass (0);
                   3329: 
                   3330:   hack_incomplete_structures (t);
                   3331: 
                   3332:   resume_momentary (old);
                   3333: 
                   3334:   if (flag_cadillac)
                   3335:     cadillac_finish_struct (t);
                   3336: 
                   3337: #if 0
                   3338:   /* This has to be done after we have sorted out what to do with
                   3339:      the enclosing type.  */
                   3340:   /* Be smarter about nested classes here.  If a type is nested,
                   3341:      only output it if we would output the enclosing type.  */
                   3342:   if (DECL_CONTEXT (TYPE_NAME (t))
                   3343:       && TREE_CODE (DECL_CONTEXT (TYPE_NAME (t))) == RECORD_TYPE)
                   3344:     DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t));
                   3345: #endif
                   3346: 
                   3347:   /* If the type has methods, we want to think about cutting down
1.1.1.2 ! root     3348:      the amount of symbol table stuff we output.  The value stored in
1.1       root     3349:      the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
                   3350:      For example, if a member function is seen and we decide to
                   3351:      write out that member function, then we can change the value
                   3352:      of the DECL_IGNORED_P slot, and the type will be output when
                   3353:      that member function's debug info is written out.  */
                   3354:   if (CLASSTYPE_METHOD_VEC (t))
                   3355:     {
                   3356:       extern tree pending_vtables;
                   3357: 
                   3358:       /* Don't output full info about any type
                   3359:         which does not have its implementation defined here.  */
                   3360:       if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
                   3361:        DECL_IGNORED_P (TYPE_NAME (t))
                   3362:          = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
                   3363:       else if (CLASSTYPE_INTERFACE_ONLY (t))
                   3364:        DECL_IGNORED_P (TYPE_NAME (t)) = 1;
                   3365:       else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
                   3366:        /* Only a first approximation!  */
                   3367:        DECL_IGNORED_P (TYPE_NAME (t)) = 1;
                   3368:     }
                   3369:   else if (CLASSTYPE_INTERFACE_ONLY (t))
                   3370:     DECL_IGNORED_P (TYPE_NAME (t)) = 1;
                   3371: 
                   3372:   /* Finish debugging output for this type.  */
1.1.1.2 ! root     3373:   rest_of_type_compilation (t, global_bindings_p ());
1.1       root     3374: 
                   3375:   return t;
                   3376: }
                   3377: 
                   3378: /* Return non-zero if the effective type of INSTANCE is static.
                   3379:    Used to determine whether the virtual function table is needed
                   3380:    or not.
                   3381: 
                   3382:    *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
1.1.1.2 ! root     3383:    of our knowledge of its type.  */
1.1       root     3384: int
                   3385: resolves_to_fixed_type_p (instance, nonnull)
                   3386:      tree instance;
                   3387:      int *nonnull;
                   3388: {
                   3389:   switch (TREE_CODE (instance))
                   3390:     {
                   3391:     case INDIRECT_REF:
                   3392:       /* Check that we are not going through a cast of some sort.  */
                   3393:       if (TREE_TYPE (instance)
                   3394:          == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
                   3395:        instance = TREE_OPERAND (instance, 0);
                   3396:       /* fall through...  */
                   3397:     case CALL_EXPR:
                   3398:       /* This is a call to a constructor, hence it's never zero.  */
                   3399:       if (TREE_HAS_CONSTRUCTOR (instance))
                   3400:        {
                   3401:          if (nonnull)
                   3402:            *nonnull = 1;
                   3403:          return 1;
                   3404:        }
                   3405:       return 0;
                   3406: 
                   3407:     case SAVE_EXPR:
                   3408:       /* This is a call to a constructor, hence it's never zero.  */
                   3409:       if (TREE_HAS_CONSTRUCTOR (instance))
                   3410:        {
                   3411:          if (nonnull)
                   3412:            *nonnull = 1;
                   3413:          return 1;
                   3414:        }
                   3415:       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3416: 
                   3417:     case RTL_EXPR:
                   3418:       /* This is a call to `new', hence it's never zero.  */
                   3419:       if (TREE_CALLS_NEW (instance))
                   3420:        {
                   3421:          if (nonnull)
                   3422:            *nonnull = 1;
                   3423:          return 1;
                   3424:        }
                   3425:       return 0;
                   3426: 
                   3427:     case PLUS_EXPR:
                   3428:     case MINUS_EXPR:
                   3429:       if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
                   3430:        /* Propagate nonnull.  */
                   3431:        resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3432:       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
                   3433:        return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3434:       return 0;
                   3435: 
                   3436:     case NOP_EXPR:
                   3437:     case CONVERT_EXPR:
                   3438:       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3439: 
                   3440:     case ADDR_EXPR:
                   3441:       if (nonnull)
                   3442:        *nonnull = 1;
                   3443:       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3444: 
                   3445:     case COMPONENT_REF:
                   3446:       return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
                   3447: 
                   3448:     case WITH_CLEANUP_EXPR:
                   3449:       if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
                   3450:        return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
                   3451:       /* fall through... */
                   3452:     case VAR_DECL:
                   3453:     case FIELD_DECL:
                   3454:       if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
                   3455:          && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
                   3456:        {
                   3457:          if (nonnull)
                   3458:            *nonnull = 1;
                   3459:          return 1;
                   3460:        }
                   3461:       /* fall through... */
                   3462:     case TARGET_EXPR:
                   3463:     case PARM_DECL:
                   3464:       if (IS_AGGR_TYPE (TREE_TYPE (instance)))
                   3465:        {
                   3466:          if (nonnull)
                   3467:            *nonnull = 1;
                   3468:          return 1;
                   3469:        }
                   3470:       else if (nonnull)
                   3471:        {
                   3472:          if (instance == current_class_decl
1.1.1.2 ! root     3473:              && flag_this_is_variable <= 0)
1.1       root     3474:            {
                   3475:              /* Some people still use `this = 0' inside destructors.  */
                   3476:              *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
                   3477:              /* In a constructor, we know our type.  */
1.1.1.2 ! root     3478:              if (flag_this_is_variable < 0)
1.1       root     3479:                return 1;
                   3480:            }
                   3481:          else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
1.1.1.2 ! root     3482:            /* Reference variables should be references to objects.  */
1.1       root     3483:            *nonnull = 1;
                   3484:        }
                   3485:       return 0;
                   3486: 
                   3487:     default:
                   3488:       return 0;
                   3489:     }
                   3490: }
                   3491: 
                   3492: void
                   3493: init_class_processing ()
                   3494: {
                   3495:   current_class_depth = 0;
                   3496:   current_class_stacksize = 10;
                   3497:   current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
                   3498:   current_class_stack = current_class_base;
                   3499: 
                   3500:   current_lang_stacksize = 10;
                   3501:   current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
                   3502:   current_lang_stack = current_lang_base;
                   3503: 
                   3504:   delta_name = get_identifier (VTABLE_DELTA_NAME);
                   3505:   pfn_name = get_identifier (VTABLE_PFN_NAME);
                   3506: 
                   3507:   /* Keep these values lying around.  */
                   3508:   minus_one_node = build_int_2 (-1, 0);
                   3509:   the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node);
                   3510:   base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
                   3511:   TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
                   3512: 
                   3513:   gcc_obstack_init (&class_obstack);
                   3514: }
                   3515: 
                   3516: /* Set current scope to NAME. CODE tells us if this is a
                   3517:    STRUCT, UNION, or ENUM environment.
                   3518: 
                   3519:    NAME may end up being NULL_TREE if this is an anonymous or
                   3520:    late-bound struct (as in "struct { ... } foo;")  */
                   3521: 
                   3522: /* Here's a subroutine we need because C lacks lambdas.  */
                   3523: static void
                   3524: unuse_fields (type)
                   3525:      tree type;
                   3526: {
                   3527:   tree fields;
                   3528: 
                   3529:   for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
                   3530:     {
                   3531:       if (TREE_CODE (fields) != FIELD_DECL)
                   3532:        continue;
                   3533: 
                   3534:       TREE_USED (fields) = 0;
                   3535:       if (DECL_NAME (fields) == NULL_TREE
                   3536:          && TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE)
                   3537:        unuse_fields (TREE_TYPE (fields));
                   3538:     }
                   3539: }
                   3540: 
                   3541: /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
                   3542:    appropriate values, found by looking up the type definition of
                   3543:    NAME (as a CODE).
                   3544: 
                   3545:    If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
                   3546:    which can be seen locally to the class.  They are shadowed by
                   3547:    any subsequent local declaration (including parameter names).
                   3548: 
                   3549:    If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
                   3550:    which have static meaning (i.e., static members, static
                   3551:    member functions, enum declarations, etc).
                   3552: 
                   3553:    If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
                   3554:    which can be seen locally to the class (as in 1), but
                   3555:    know that we are doing this for declaration purposes
                   3556:    (i.e. friend foo::bar (int)).
                   3557: 
                   3558:    So that we may avoid calls to lookup_name, we cache the _TYPE
                   3559:    nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
                   3560: 
                   3561:    For multiple inheritance, we perform a two-pass depth-first search
                   3562:    of the type lattice.  The first pass performs a pre-order search,
                   3563:    marking types after the type has had its fields installed in
                   3564:    the appropriate IDENTIFIER_CLASS_VALUE slot.  The second pass merely
                   3565:    unmarks the marked types.  If a field or member function name
                   3566:    appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
                   3567:    that name becomes `error_mark_node'.  */
                   3568: 
                   3569: void
                   3570: pushclass (type, modify)
                   3571:      tree type;
                   3572:      int modify;
                   3573: {
                   3574: #ifdef DEBUG_CP_BINDING_LEVELS
                   3575:   indent_to (stderr, debug_bindings_indentation);
                   3576:   fprintf (stderr, "pushclass");
                   3577:   debug_bindings_indentation += 4;
                   3578: #endif
                   3579: 
                   3580:   push_memoized_context (type, modify);
                   3581: 
                   3582:   current_class_depth++;
                   3583:   *current_class_stack++ = current_class_name;
                   3584:   *current_class_stack++ = current_class_type;
                   3585:   if (current_class_stack >= current_class_base + current_class_stacksize)
                   3586:     {
                   3587:       current_class_base =
                   3588:        (tree *)xrealloc (current_class_base,
                   3589:                          sizeof (tree) * (current_class_stacksize + 10));
                   3590:       current_class_stack = current_class_base + current_class_stacksize;
                   3591:       current_class_stacksize += 10;
                   3592:     }
                   3593: 
                   3594:   current_class_name = TYPE_NAME (type);
                   3595:   if (TREE_CODE (current_class_name) == TYPE_DECL)
                   3596:     current_class_name = DECL_NAME (current_class_name);
                   3597:   current_class_type = type;
                   3598: 
                   3599:   if (prev_class_type != NULL_TREE
                   3600:       && (type != prev_class_type
                   3601:          || TYPE_SIZE (prev_class_type) == NULL_TREE
                   3602:          /* ??? Is this necessary any more?  */
                   3603:          || IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (prev_class_type))))
                   3604:       && (current_class_depth == 1 || modify == 3))
                   3605:     {
                   3606:       /* Forcibly remove any old class remnants.  */
                   3607:       popclass (-1);
                   3608:       prev_class_type = 0;
                   3609:     }
                   3610: 
                   3611:   pushlevel_class ();
                   3612: 
                   3613:   if (modify)
                   3614:     {
                   3615:       tree tags;
                   3616:       tree this_fndecl = current_function_decl;
                   3617: 
                   3618:       if (current_function_decl
                   3619:          && DECL_CONTEXT (current_function_decl)
                   3620:          && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
                   3621:        current_function_decl = DECL_CONTEXT (current_function_decl);
                   3622:       else
                   3623:        current_function_decl = NULL_TREE;
                   3624: 
                   3625:       if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
                   3626:         {
                   3627:           extern void declare_uninstantiated_type_level ();
                   3628:           declare_uninstantiated_type_level ();
                   3629:          overload_template_name (current_class_name, 0);
                   3630:         }
                   3631:       else if (type != prev_class_type)
                   3632:        {
                   3633:          build_mi_matrix (type);
                   3634:          push_class_decls (type);
                   3635:          free_mi_matrix ();
                   3636:          prev_class_type = type;
                   3637:        }
                   3638:       else
                   3639:        unuse_fields (type);
                   3640: 
1.1.1.2 ! root     3641:       for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
1.1       root     3642:        {
                   3643:          TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1;
1.1.1.2 ! root     3644:          if (! TREE_PURPOSE (tags))
        !          3645:            continue;
1.1       root     3646:          pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags));
                   3647:          if (IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (tags)) == NULL_TREE
                   3648:              && TREE_CODE (TYPE_NAME (TREE_VALUE (tags))) == TYPE_DECL)
                   3649:            IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (tags))
                   3650:              = TYPE_NAME (TREE_VALUE (tags));
                   3651:        }
                   3652: 
                   3653:       current_function_decl = this_fndecl;
                   3654:     }
                   3655: 
                   3656:   if (flag_cadillac)
                   3657:     cadillac_push_class (type);
                   3658: 
                   3659: #ifdef DEBUG_CP_BINDING_LEVELS
                   3660:   debug_bindings_indentation -= 4;
                   3661: #endif
                   3662: }
                   3663:  
                   3664: /* Get out of the current class scope. If we were in a class scope
                   3665:    previously, that is the one popped to.  The flag MODIFY tells
                   3666:    whether the current scope declarations needs to be modified
                   3667:    as a result of popping to the previous scope.  */
                   3668: void
                   3669: popclass (modify)
                   3670:      int modify;
                   3671: {
                   3672: #ifdef DEBUG_CP_BINDING_LEVELS
                   3673:   indent_to (stderr, debug_bindings_indentation);
                   3674:   fprintf (stderr, "popclass");
                   3675:   debug_bindings_indentation += 4;
                   3676: #endif
                   3677: 
                   3678:   if (flag_cadillac)
                   3679:     cadillac_pop_class ();
                   3680: 
                   3681:   if (modify < 0)
                   3682:     {
                   3683:       /* Back this old class out completely.  */
                   3684:       tree tags = CLASSTYPE_TAGS (prev_class_type);
                   3685: 
                   3686:       pop_class_decls (prev_class_type);
                   3687:       while (tags)
                   3688:        {
                   3689:          TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
                   3690:          IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (tags)) = NULL_TREE;
                   3691:          tags = TREE_CHAIN (tags);
                   3692:        }
                   3693:       goto ret;
                   3694:     }
                   3695: 
                   3696:   if (modify)
                   3697:     {
                   3698:       /* Just remove from this class what didn't make
                   3699:         it into IDENTIFIER_CLASS_VALUE.  */
                   3700:       tree tags = CLASSTYPE_TAGS (current_class_type);
                   3701: 
                   3702:       while (tags)
                   3703:        {
                   3704:          TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
1.1.1.2 ! root     3705:          if (TREE_PURPOSE (tags))
        !          3706:            IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (tags)) = NULL_TREE;
1.1       root     3707:          tags = TREE_CHAIN (tags);
                   3708:        }
                   3709:     }
                   3710:   if (TREE_CODE (current_class_type) == UNINSTANTIATED_P_TYPE)
                   3711:     undo_template_name_overload (current_class_name, 0);
                   3712:   poplevel_class ();
                   3713: 
                   3714:   current_class_depth--;
                   3715:   current_class_type = *--current_class_stack;
                   3716:   current_class_name = *--current_class_stack;
                   3717: 
                   3718:   if (current_class_type)
                   3719:     {
                   3720:       if (CLASSTYPE_VTBL_PTR (current_class_type))
                   3721:        {
                   3722:          current_vtable_decl = lookup_name (DECL_NAME (CLASSTYPE_VTBL_PTR (current_class_type)), 0);
                   3723:          if (current_vtable_decl)
                   3724:            current_vtable_decl = build_indirect_ref (current_vtable_decl, 0);
                   3725:        }
                   3726:       current_class_decl = lookup_name (get_identifier (THIS_NAME), 0);
                   3727:       if (current_class_decl)
                   3728:        {
                   3729:          if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
                   3730:            {
                   3731:              tree temp;
                   3732:              /* Can't call build_indirect_ref here, because it has special
                   3733:                 logic to return C_C_D given this argument.  */
                   3734:              C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
                   3735:              temp = TREE_TYPE (TREE_TYPE (current_class_decl));
                   3736:              TREE_READONLY (C_C_D) = TYPE_READONLY (temp);
                   3737:              TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (temp);
                   3738:              TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (temp);
                   3739:            }
                   3740:          else
                   3741:            C_C_D = current_class_decl;
                   3742:        }
                   3743:       else C_C_D = NULL_TREE;
                   3744:     }
                   3745:   else
                   3746:     {
                   3747:       current_class_decl = NULL_TREE;
                   3748:       current_vtable_decl = NULL_TREE;
                   3749:       C_C_D = NULL_TREE;
                   3750:     }
                   3751: 
                   3752:   pop_memoized_context (modify);
                   3753: 
                   3754:  ret:
                   3755:   ;
                   3756: #ifdef DEBUG_CP_BINDING_LEVELS
                   3757:   debug_bindings_indentation -= 4;
                   3758: #endif
                   3759: }
                   3760: 
                   3761: /* Set global variables CURRENT_LANG_NAME to appropriate value
                   3762:    so that behavior of name-mangling machinery is correct.  */
                   3763: 
                   3764: void
                   3765: push_lang_context (name)
                   3766:      tree name;
                   3767: {
                   3768:   *current_lang_stack++ = current_lang_name;
                   3769:   if (current_lang_stack >= current_lang_base + current_lang_stacksize)
                   3770:     {
                   3771:       current_lang_base =
                   3772:        (tree *)xrealloc (current_lang_base,
                   3773:                          sizeof (tree) * (current_lang_stacksize + 10));
                   3774:       current_lang_stack = current_lang_base + current_lang_stacksize;
                   3775:       current_lang_stacksize += 10;
                   3776:     }
                   3777: 
                   3778:   if (name == lang_name_cplusplus)
                   3779:     {
                   3780:       strict_prototype = strict_prototypes_lang_cplusplus;
                   3781:       current_lang_name = name;
                   3782:     }
                   3783:   else if (name == lang_name_c)
                   3784:     {
                   3785:       strict_prototype = strict_prototypes_lang_c;
                   3786:       current_lang_name = name;
                   3787:     }
                   3788:   else
                   3789:     error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
                   3790: 
                   3791:   if (flag_cadillac)
                   3792:     cadillac_push_lang (name);
                   3793: }
                   3794:   
                   3795: /* Get out of the current language scope.  */
                   3796: void
                   3797: pop_lang_context ()
                   3798: {
                   3799:   if (flag_cadillac)
                   3800:     cadillac_pop_lang ();
                   3801: 
                   3802:   current_lang_name = *--current_lang_stack;
                   3803:   if (current_lang_name == lang_name_cplusplus)
                   3804:     strict_prototype = strict_prototypes_lang_cplusplus;
                   3805:   else if (current_lang_name == lang_name_c)
                   3806:     strict_prototype = strict_prototypes_lang_c;
                   3807: }
                   3808: 
                   3809: int
                   3810: root_lang_context_p ()
                   3811: {
                   3812:   return current_lang_stack == current_lang_base;
                   3813: }
                   3814: 
                   3815: /* Type instantiation routines.  */
                   3816: 
                   3817: /* This function will instantiate the type of the expression given
                   3818:    in RHS to match the type of LHSTYPE.  If LHSTYPE is NULL_TREE,
                   3819:    or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE.
                   3820: 
                   3821:    This function is used in build_modify_expr, convert_arguments,
                   3822:    build_c_cast, and compute_conversion_costs.  */
                   3823: tree
                   3824: instantiate_type (lhstype, rhs, complain)
                   3825:      tree lhstype, rhs;
                   3826:      int complain;
                   3827: {
                   3828:   if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
                   3829:     {
                   3830:       if (complain)
                   3831:        error ("not enough type information");
                   3832:       return error_mark_node;
                   3833:     }
                   3834: 
                   3835:   if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
                   3836:     return rhs;
                   3837: 
                   3838:   /* This should really only be used when attempting to distinguish
                   3839:      what sort of a pointer to function we have.  For now, any
1.1.1.2 ! root     3840:      arithmetic operation which is not supported on pointers
1.1       root     3841:      is rejected as an error.  */
                   3842: 
                   3843:   switch (TREE_CODE (rhs))
                   3844:     {
                   3845:     case TYPE_EXPR:
                   3846:     case CONVERT_EXPR:
                   3847:     case SAVE_EXPR:
                   3848:     case CONSTRUCTOR:
                   3849:     case BUFFER_REF:
                   3850:       assert (0);
                   3851:       return error_mark_node;
                   3852: 
                   3853:     case INDIRECT_REF:
                   3854:     case ARRAY_REF:
                   3855:       TREE_TYPE (rhs) = lhstype;
                   3856:       lhstype = build_pointer_type (lhstype);
                   3857:       TREE_OPERAND (rhs, 0)
                   3858:        = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
                   3859:       if (TREE_OPERAND (rhs, 0) == error_mark_node)
                   3860:        return error_mark_node;
                   3861: 
                   3862:       return rhs;
                   3863: 
                   3864:     case NOP_EXPR:
                   3865:       rhs = copy_node (TREE_OPERAND (rhs, 0));
                   3866:       TREE_TYPE (rhs) = unknown_type_node;
                   3867:       return instantiate_type (lhstype, rhs, complain);
                   3868: 
                   3869:     case COMPONENT_REF:
                   3870:       {
                   3871:        tree field = TREE_OPERAND (rhs, 1);
                   3872:        if (TREE_CODE (field) == TREE_LIST)
                   3873:          {
                   3874:            tree function = instantiate_type (lhstype, field, complain);
                   3875:            if (function == error_mark_node)
                   3876:              return error_mark_node;
                   3877:            assert (TREE_CODE (function) == FUNCTION_DECL);
                   3878:            if (DECL_VINDEX (function))
                   3879:              {
                   3880:                tree base = TREE_OPERAND (rhs, 0);
                   3881:                tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
                   3882:                if (base_ptr == error_mark_node)
                   3883:                  return error_mark_node;
                   3884:                base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
                   3885:                if (base_ptr == error_mark_node)
                   3886:                  return error_mark_node;
                   3887:                return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
                   3888:              }
                   3889:            return function;
                   3890:          }
                   3891: 
                   3892:        assert (TREE_CODE (field) == FIELD_DECL);
                   3893:        assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
                   3894:                  || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE));
                   3895: 
                   3896:        TREE_TYPE (rhs) = lhstype;
                   3897:        /* First look for an exact match  */
                   3898: 
                   3899:        while (field && TREE_TYPE (field) != lhstype)
                   3900:          field = TREE_CHAIN (field);
                   3901:        if (field)
                   3902:          {
                   3903:            TREE_OPERAND (rhs, 1) = field;
                   3904:            return rhs;
                   3905:          }
                   3906: 
                   3907:        /* No exact match found, look for a compatible function.  */
                   3908:        field = TREE_OPERAND (rhs, 1);
                   3909:        while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
                   3910:          field = TREE_CHAIN (field);
                   3911:        if (field)
                   3912:          {
                   3913:            TREE_OPERAND (rhs, 1) = field;
                   3914:            field = TREE_CHAIN (field);
                   3915:            while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
                   3916:              field = TREE_CHAIN (field);
                   3917:            if (field)
                   3918:              {
                   3919:                if (complain)
                   3920:                  error ("ambiguous overload for COMPONENT_REF requested");
                   3921:                return error_mark_node;
                   3922:              }
                   3923:          }
                   3924:        else
                   3925:          {
                   3926:            if (complain)
                   3927:              error ("no appropriate overload exists for COMPONENT_REF");
                   3928:            return error_mark_node;
                   3929:          }
                   3930:        return rhs;
                   3931:       }
                   3932: 
                   3933:     case TREE_LIST:
                   3934:       {
                   3935:        tree elem, baselink, name;
                   3936:        int globals = overloaded_globals_p (rhs);
                   3937: 
                   3938:        /* If there's only one function we know about, return that.  */
                   3939:        if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE)
                   3940:          return TREE_VALUE (rhs);
                   3941: 
                   3942:        /* First look for an exact match.  Search either overloaded
                   3943:           functions or member functions.  May have to undo what
                   3944:           `default_conversion' might do to lhstype.  */
                   3945: 
                   3946:        if (TREE_CODE (lhstype) == POINTER_TYPE)
                   3947:          if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
                   3948:              || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
                   3949:            lhstype = TREE_TYPE (lhstype);
                   3950:          else
                   3951:            {
                   3952:              if (complain)
                   3953:                error ("invalid type combination for overload");
                   3954:              return error_mark_node;
                   3955:            }
                   3956: 
                   3957:        if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0)
                   3958:          {
                   3959:            if (complain)
                   3960:              error ("cannot resolve overloaded function `%s' based on non-function type",
                   3961:                     IDENTIFIER_POINTER (TREE_PURPOSE (rhs)));
                   3962:            return error_mark_node;
                   3963:          }
                   3964: 
                   3965:        if (globals > 0)
                   3966:          {
                   3967:            assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL);
                   3968:            elem = rhs;
                   3969:            while (elem)
                   3970:              if (TREE_TYPE (TREE_VALUE (elem)) != lhstype)
                   3971:                elem = TREE_CHAIN (elem);
                   3972:              else
                   3973:                return TREE_VALUE (elem);
                   3974:            /* No exact match found, look for a compatible function.  */
                   3975:            elem = rhs;
                   3976:            while (elem && ! comp_target_types (lhstype, TREE_TYPE (TREE_VALUE (elem)), 1))
                   3977:              elem = TREE_CHAIN (elem);
                   3978:            if (elem)
                   3979:              {
                   3980:                tree save_elem = TREE_VALUE (elem);
                   3981:                elem = TREE_CHAIN (elem);
                   3982:                while (elem && ! comp_target_types (lhstype, TREE_TYPE (TREE_VALUE (elem)), 0))
                   3983:                  elem = TREE_CHAIN (elem);
                   3984:                if (elem)
                   3985:                  {
                   3986:                    if (complain)
                   3987:                      error ("ambiguous overload for overloaded function requested");
                   3988:                    return error_mark_node;
                   3989:                  }
                   3990:                return save_elem;
                   3991:              }
                   3992:            if (complain)
                   3993:              {
                   3994:                if (TREE_CHAIN (rhs))
                   3995:                  error ("no appropriate overload for overloaded function `%s' exists",
                   3996:                         IDENTIFIER_POINTER (TREE_PURPOSE (rhs)));
                   3997:                else
                   3998:                  error ("function `%s' has inappropriate type signature",
                   3999:                         IDENTIFIER_POINTER (TREE_PURPOSE (rhs)));
                   4000:              }
                   4001:            return error_mark_node;
                   4002:          }
                   4003: 
                   4004:        if (TREE_NONLOCAL_FLAG (rhs))
                   4005:          {
                   4006:            /* Got to get it as a baselink.  */
                   4007:            rhs = lookup_fnfields (TYPE_BINFO (current_class_type),
                   4008:                                   TREE_PURPOSE (rhs), 0);
                   4009:          }
                   4010:        else
                   4011:          {
                   4012:            assert (TREE_CHAIN (rhs) == NULL_TREE);
                   4013:            if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST)
                   4014:              rhs = TREE_VALUE (rhs);
                   4015:            assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL);
                   4016:          }
                   4017: 
                   4018:        for (baselink = rhs; baselink;
                   4019:             baselink = next_baselink (baselink))
                   4020:          {
                   4021:            elem = TREE_VALUE (baselink);
                   4022:            while (elem)
                   4023:              if (TREE_TYPE (elem) != lhstype)
                   4024:                elem = TREE_CHAIN (elem);
                   4025:              else
                   4026:                return elem;
                   4027:          }
                   4028: 
                   4029:        /* No exact match found, look for a compatible method.  */
                   4030:        for (baselink = rhs; baselink;
                   4031:             baselink = next_baselink (baselink))
                   4032:          {
                   4033:            elem = TREE_VALUE (baselink);
                   4034:            while (elem && ! comp_target_types (lhstype, TREE_TYPE (elem), 1))
                   4035:              elem = TREE_CHAIN (elem);
                   4036:            if (elem)
                   4037:              {
                   4038:                tree save_elem = elem;
                   4039:                elem = TREE_CHAIN (elem);
                   4040:                while (elem && ! comp_target_types (lhstype, TREE_TYPE (elem), 0))
                   4041:                  elem = TREE_CHAIN (elem);
                   4042:                if (elem)
                   4043:                  {
                   4044:                    if (complain)
                   4045:                      error ("ambiguous overload for overloaded method requested");
                   4046:                    return error_mark_node;
                   4047:                  }
                   4048:                return save_elem;
                   4049:              }
                   4050:            name = DECL_NAME (TREE_VALUE (rhs));
                   4051:            if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
                   4052:              {
                   4053:                /* Try to instantiate from non-member functions.  */
                   4054:                rhs = IDENTIFIER_GLOBAL_VALUE (name);
                   4055:                if (rhs && TREE_CODE (rhs) == TREE_LIST)
                   4056:                  {
                   4057:                    /* This code seems to be missing a `return'.  */
                   4058:                    abort ();
                   4059:                    instantiate_type (lhstype, rhs, complain);
                   4060:                  }
                   4061:              }
                   4062:          }
                   4063:        if (complain)
                   4064:          error ("no static member functions named `%s'",
                   4065:                 IDENTIFIER_POINTER (name));
                   4066:        return error_mark_node;
                   4067:       }
                   4068: 
                   4069:     case CALL_EXPR:
                   4070:       /* This is too hard for now.  */
                   4071:       assert (0);
                   4072:       return error_mark_node;
                   4073: 
                   4074:     case PLUS_EXPR:
                   4075:     case MINUS_EXPR:
                   4076:     case COMPOUND_EXPR:
                   4077:       TREE_OPERAND (rhs, 0) = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
                   4078:       if (TREE_OPERAND (rhs, 0) == error_mark_node)
                   4079:        return error_mark_node;
                   4080:       TREE_OPERAND (rhs, 1) = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
                   4081:       if (TREE_OPERAND (rhs, 1) == error_mark_node)
                   4082:        return error_mark_node;
                   4083: 
                   4084:       TREE_TYPE (rhs) = lhstype;
                   4085:       return rhs;
                   4086: 
                   4087:     case MULT_EXPR:
                   4088:     case TRUNC_DIV_EXPR:
                   4089:     case FLOOR_DIV_EXPR:
                   4090:     case CEIL_DIV_EXPR:
                   4091:     case ROUND_DIV_EXPR:
                   4092:     case RDIV_EXPR:
                   4093:     case TRUNC_MOD_EXPR:
                   4094:     case FLOOR_MOD_EXPR:
                   4095:     case CEIL_MOD_EXPR:
                   4096:     case ROUND_MOD_EXPR:
                   4097:     case FIX_ROUND_EXPR:
                   4098:     case FIX_FLOOR_EXPR:
                   4099:     case FIX_CEIL_EXPR:
                   4100:     case FIX_TRUNC_EXPR:
                   4101:     case FLOAT_EXPR:
                   4102:     case NEGATE_EXPR:
                   4103:     case ABS_EXPR:
                   4104:     case MAX_EXPR:
                   4105:     case MIN_EXPR:
                   4106:     case FFS_EXPR:
                   4107: 
                   4108:     case BIT_AND_EXPR:
                   4109:     case BIT_IOR_EXPR:
                   4110:     case BIT_XOR_EXPR:
                   4111:     case LSHIFT_EXPR:
                   4112:     case RSHIFT_EXPR:
                   4113:     case LROTATE_EXPR:
                   4114:     case RROTATE_EXPR:
                   4115: 
                   4116:     case PREINCREMENT_EXPR:
                   4117:     case PREDECREMENT_EXPR:
                   4118:     case POSTINCREMENT_EXPR:
                   4119:     case POSTDECREMENT_EXPR:
                   4120:       if (complain)
                   4121:        error ("illegal operation on uninstantiated type");
                   4122:       return error_mark_node;
                   4123: 
                   4124:     case TRUTH_AND_EXPR:
                   4125:     case TRUTH_OR_EXPR:
                   4126:     case LT_EXPR:
                   4127:     case LE_EXPR:
                   4128:     case GT_EXPR:
                   4129:     case GE_EXPR:
                   4130:     case EQ_EXPR:
                   4131:     case NE_EXPR:
                   4132:     case TRUTH_ANDIF_EXPR:
                   4133:     case TRUTH_ORIF_EXPR:
                   4134:     case TRUTH_NOT_EXPR:
                   4135:       if (complain)
                   4136:        error ("not enough type information");
                   4137:       return error_mark_node;
                   4138: 
                   4139:     case COND_EXPR:
                   4140:       if (type_unknown_p (TREE_OPERAND (rhs, 0)))
                   4141:        {
                   4142:          if (complain)
                   4143:            error ("not enough type information");
                   4144:          return error_mark_node;
                   4145:        }
                   4146:       TREE_OPERAND (rhs, 1) = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
                   4147:       if (TREE_OPERAND (rhs, 1) == error_mark_node)
                   4148:        return error_mark_node;
                   4149:       TREE_OPERAND (rhs, 2) = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain);
                   4150:       if (TREE_OPERAND (rhs, 2) == error_mark_node)
                   4151:        return error_mark_node;
                   4152: 
                   4153:       TREE_TYPE (rhs) = lhstype;
                   4154:       return rhs;
                   4155: 
                   4156:     case MODIFY_EXPR:
                   4157:       TREE_OPERAND (rhs, 1) = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
                   4158:       if (TREE_OPERAND (rhs, 1) == error_mark_node)
                   4159:        return error_mark_node;
                   4160: 
                   4161:       TREE_TYPE (rhs) = lhstype;
                   4162:       return rhs;
                   4163:       
                   4164:     case ADDR_EXPR:
                   4165:       if (TREE_CODE (lhstype) != POINTER_TYPE)
                   4166:        {
                   4167:          if (complain)
                   4168:            error ("type for resolving address of overloaded function must be pointer type");
                   4169:          return error_mark_node;
                   4170:        }
                   4171:       TREE_TYPE (rhs) = lhstype;
                   4172:       lhstype = TREE_TYPE (lhstype);
                   4173:       TREE_OPERAND (rhs, 0) = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
                   4174:       if (TREE_OPERAND (rhs, 0) == error_mark_node)
                   4175:        return error_mark_node;
                   4176: 
                   4177:       mark_addressable (TREE_OPERAND (rhs, 0));
                   4178:       return rhs;
                   4179: 
                   4180:     case ENTRY_VALUE_EXPR:
                   4181:       assert (0);
                   4182:       return error_mark_node;
                   4183: 
                   4184:     case ERROR_MARK:
                   4185:       return error_mark_node;
                   4186: 
                   4187:     default:
                   4188:       assert (0);
                   4189:       return error_mark_node;
                   4190:     }
                   4191: }
                   4192: 
                   4193: /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
                   4194:    for the given TYPE.  */
                   4195: static tree
                   4196: get_vtable_name (type)
                   4197:      tree type;
                   4198: {
                   4199:   tree type_id = build_typename_overload (type);
                   4200:   char *buf = (char *)alloca (sizeof (VTABLE_NAME_FORMAT)
                   4201:                              + IDENTIFIER_LENGTH (type_id) + 2);
                   4202:   char *ptr = IDENTIFIER_POINTER (type_id);
                   4203:   int i;
                   4204:   for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
                   4205:   while (ptr[i] >= '0' && ptr[i] <= '9')
                   4206:     i += 1;
                   4207:   sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
                   4208:   return get_identifier (buf);
                   4209: }
                   4210: 
                   4211: /* Return the name of the virtual function pointer field
                   4212:    (as an IDENTIFIER_NODE) for the given TYPE.  Note that
                   4213:    this may have to look back through base types to find the
                   4214:    ultimate field name.  (For single inheritance, these could
                   4215:    all be the same name.  Who knows for multiple inheritance).  */
                   4216: static tree
                   4217: get_vfield_name (type)
                   4218:      tree type;
                   4219: {
                   4220:   tree binfo = TYPE_BINFO (type);
                   4221:   char *buf;
                   4222: 
                   4223:   while (BINFO_BASETYPES (binfo)
                   4224:         && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
                   4225:         && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
                   4226:     binfo = BINFO_BASETYPE (binfo, 0);
                   4227: 
                   4228:   type = BINFO_TYPE (binfo);
                   4229:   buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT)
                   4230:                        + TYPE_NAME_LENGTH (type) + 2);
                   4231:   sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
                   4232:   return get_identifier (buf);
                   4233: }
                   4234: 
                   4235: void
                   4236: print_class_statistics ()
                   4237: {
                   4238: #ifdef GATHER_STATISTICS
                   4239:   fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
                   4240:   fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
                   4241:   fprintf (stderr, "build_method_call = %d (inner = %d)\n",
                   4242:           n_build_method_call, n_inner_fields_searched);
                   4243:   if (n_vtables)
                   4244:     {
                   4245:       fprintf (stderr, "vtables = %d; vtable searches = %d\n",
                   4246:               n_vtables, n_vtable_searches);
                   4247:       fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
                   4248:               n_vtable_entries, n_vtable_elems);
                   4249:     }
                   4250: #endif
                   4251: }

unix.superglobalmegacorp.com

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