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

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

unix.superglobalmegacorp.com

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