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

1.1       root        1: /* Process declarations and variables for C compiler.
1.1.1.5 ! root        2:    Copyright (C) 1988, 1992, 1993 Free Software Foundation, Inc.
1.1       root        3:    Hacked 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: /* Process declarations and symbol lookup for C front end.
                     23:    Also constructs types; the standard scalar types at initialization,
                     24:    and structure, union, array and enum types when they are declared.  */
                     25: 
                     26: /* ??? not all decl nodes are given the most useful possible
                     27:    line numbers.  For example, the CONST_DECLs for enum values.  */
                     28: 
                     29: #include "config.h"
1.1.1.4   root       30: #include <stdio.h>
1.1       root       31: #include "tree.h"
1.1.1.4   root       32: #include "rtl.h"
1.1       root       33: #include "flags.h"
                     34: #include "cp-tree.h"
                     35: #include "cp-decl.h"
1.1.1.5 ! root       36: #include "cp-lex.h"
1.1       root       37: 
                     38: extern tree grokdeclarator ();
                     39: static void grok_function_init ();
                     40: 
                     41: /* A list of virtual function tables we must make sure to write out.  */
                     42: tree pending_vtables;
                     43: 
                     44: /* A list of static class variables.  This is needed, because a
                     45:    static class variable can be declared inside the class without
                     46:    an initializer, and then initialized, staticly, outside the class.  */
                     47: tree pending_statics;
                     48: 
                     49: extern tree pending_addressable_inlines;
                     50: 
                     51: /* Used to help generate temporary names which are unique within
                     52:    a function.  Reset to 0 by start_function.  */
                     53: 
                     54: static int temp_name_counter;
                     55: 
                     56: /* Same, but not reset.  Local temp variables and global temp variables
                     57:    can have the same name.  */
                     58: static int global_temp_name_counter;
                     59: 
                     60: /* The (assembler) name of the first globally-visible object output.  */
                     61: extern char * first_global_object_name;
1.1.1.4   root       62: 
                     63: /* Flag used when debugging cp-spew.c */
                     64: 
                     65: extern int spew_debug;
1.1       root       66: 
                     67: /* C (and C++) language-specific option variables.  */
                     68: 
                     69: /* Nonzero means allow type mismatches in conditional expressions;
                     70:    just make their values `void'.   */
                     71: 
                     72: int flag_cond_mismatch;
                     73: 
                     74: /* Nonzero means give `double' the same size as `float'.  */
                     75: 
                     76: int flag_short_double;
                     77: 
                     78: /* Nonzero means don't recognize the keyword `asm'.  */
                     79: 
                     80: int flag_no_asm;
                     81: 
                     82: /* Nonzero means don't recognize the non-ANSI builtin functions.  */
                     83: 
                     84: int flag_no_builtin;
                     85: 
                     86: /* Nonzero means do some things the same way PCC does.  */
                     87: 
                     88: int flag_traditional;
                     89: 
                     90: /* Nonzero means to treat bitfields as unsigned unless they say `signed'.  */
                     91: 
                     92: int flag_signed_bitfields = 1;
                     93: 
                     94: /* Nonzero means handle `#ident' directives.  0 means ignore them.  */
                     95: 
                     96: int flag_no_ident = 0;
                     97: 
                     98: /* Nonzero means handle things in ANSI, instead of GNU fashion.  This
                     99:    flag should be tested for language behavior that's different between
                    100:    ANSI and GNU, but not so horrible as to merit a PEDANTIC label.  */
                    101: 
                    102: int flag_ansi = 0;
                    103: 
1.1.1.5 ! root      104: /* Nonzero means do emit exported implementations of functions even if
        !           105:    they can be inlined.  */
        !           106: 
        !           107: int flag_implement_inlines = 1;
        !           108: 
1.1       root      109: /* Nonzero means warn about implicit declarations.  */
                    110: 
                    111: int warn_implicit = 1;
                    112: 
                    113: /* Like `warn_return_type', but this is set by users, whereas
                    114:    `warn_return_type' is set by the compiler.  */
                    115: 
                    116: int explicit_warn_return_type;
                    117: 
                    118: /* Nonzero means give string constants the type `const char *'
                    119:    to get extra warnings from them.  These warnings will be too numerous
                    120:    to be useful, except in thoroughly ANSIfied programs.  */
                    121: 
                    122: int warn_write_strings;
                    123: 
                    124: /* Nonzero means warn about pointer casts that can drop a type qualifier
                    125:    from the pointer target type.  */
                    126: 
                    127: int warn_cast_qual;
                    128: 
1.1.1.5 ! root      129: /* Nonzero means warn that dbx info for template class methods isn't fully
        !           130:    supported yet.  */
        !           131: 
        !           132: int warn_template_debugging;
        !           133: 
1.1.1.4   root      134: /* Warn about traditional constructs whose meanings changed in ANSI C.  */
                    135: 
                    136: int warn_traditional;
                    137: 
1.1       root      138: /* Nonzero means warn about sizeof(function) or addition/subtraction
                    139:    of function pointers.  */
                    140: 
                    141: int warn_pointer_arith;
                    142: 
                    143: /* Nonzero means warn for non-prototype function decls
                    144:    or non-prototyped defs without previous prototype.  */
                    145: 
                    146: int warn_strict_prototypes;
                    147: 
                    148: /* Nonzero means warn for any function def without prototype decl.  */
                    149: 
                    150: int warn_missing_prototypes;
                    151: 
1.1.1.4   root      152: /* Nonzero means warn about multiple (redundant) decls for the same single
                    153:    variable or function.  */
                    154: 
                    155: int warn_redundant_decls;
                    156: 
1.1       root      157: /* Warn about *printf or *scanf format/argument anomalies. */
                    158: 
                    159: int warn_format;
                    160: 
1.1.1.4   root      161: /* Warn about a subscript that has type char.  */
                    162: 
                    163: int warn_char_subscripts = 0;
                    164: 
1.1       root      165: /* Warn if a type conversion is done that might have confusing results.  */
                    166: 
                    167: int warn_conversion;
                    168: 
                    169: /* Warn if adding () is suggested.  */
                    170: 
                    171: int warn_parentheses = 1;
                    172: 
                    173: /* Non-zero means warn in function declared in derived class has the
                    174:    same name as a virtual in the base class, but fails to match the
                    175:    type signature of any virtual function in the base class.  */
                    176: int warn_overloaded_virtual;
                    177: 
                    178: /* Non-zero means warn when converting between different enumeral types.  */
                    179: int warn_enum_clash;
                    180: 
1.1.1.4   root      181: /* Non-zero means warn when declaring a class that has a non virtual
                    182:    destructor, when it really ought to have a virtual one. */
                    183: int warn_nonvdtor = 1;
                    184: 
1.1       root      185: /* Nonzero means `$' can be in an identifier.
                    186:    See cccp.c for reasons why this breaks some obscure ANSI C programs.  */
                    187: 
                    188: #ifndef DOLLARS_IN_IDENTIFIERS
                    189: #define DOLLARS_IN_IDENTIFIERS 1
                    190: #endif
                    191: int dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
                    192: 
                    193: /* Nonzero for -no-strict-prototype switch: do not consider empty
                    194:    argument prototype to mean function takes no arguments.  */
                    195: 
                    196: int strict_prototype = 1;
                    197: int strict_prototypes_lang_c, strict_prototypes_lang_cplusplus = 1;
                    198: 
                    199: /* Nonzero means that labels can be used as first-class objects */
                    200: 
                    201: int flag_labels_ok;
                    202: 
                    203: /* Non-zero means to collect statistics which might be expensive
                    204:    and to print them when we are done.  */
                    205: int flag_detailed_statistics;
                    206: 
                    207: /* C++ specific flags.  */   
                    208: /* Nonzero for -fall-virtual: make every member function (except
                    209:    constructors) lay down in the virtual function table.  Calls
                    210:    can then either go through the virtual function table or not,
                    211:    depending.  */
                    212: 
                    213: int flag_all_virtual;
                    214: 
                    215: /* Zero means that `this' is a *const.  This gives nice behavior in the
1.1.1.2   root      216:    2.0 world.  1 gives 1.2-compatible behavior.  2 gives Spring behavior.
                    217:    -2 means we're constructing an object and it has fixed type.  */
1.1       root      218: 
                    219: int flag_this_is_variable;
                    220: 
                    221: /* Nonzero means memoize our member lookups.  */
                    222: 
                    223: int flag_memoize_lookups; int flag_save_memoized_contexts;
                    224: 
                    225: /* 3 means write out only virtuals function tables `defined'
                    226:    in this implementation file.
                    227:    2 means write out only specific virtual function tables
                    228:    and give them (C) public visibility.
                    229:    1 means write out virtual function tables and give them
                    230:    (C) public visibility.
                    231:    0 means write out virtual function tables and give them
                    232:    (C) static visibility (default).
                    233:    -1 means declare virtual function tables extern.  */
                    234: 
                    235: int write_virtuals;
                    236: 
                    237: /* Nonzero means we should attempt to elide constructors when possible.  */
                    238: 
                    239: int flag_elide_constructors;
                    240: 
                    241: /* Same, but for inline functions: nonzero means write out debug info
                    242:    for inlines.  Zero means do not.  */
                    243: 
                    244: int flag_inline_debug;
                    245: 
                    246: /* Nonzero means recognize and handle exception handling constructs.
                    247:    2 means handle exceptions the way Spring wants them handled.  */
                    248: 
                    249: int flag_handle_exceptions;
                    250: 
                    251: /* Nonzero means recognize and handle exception handling constructs.
                    252:    Use ansi syntax and semantics.  WORK IN PROGRESS!
                    253:    2 means handle exceptions the way Spring wants them handled.  */
                    254: 
                    255: int flag_ansi_exceptions;
                    256: 
                    257: /* Nonzero means that member functions defined in class scope are
                    258:    inline by default.  */
                    259: 
                    260: int flag_default_inline = 1;
                    261: 
                    262: /* Controls whether enums and ints freely convert.
                    263:    1 means with complete freedom.
                    264:    0 means enums can convert to ints, but not vice-versa.  */
                    265: int flag_int_enum_equivalence;
                    266: 
                    267: /* Controls whether compiler is operating under LUCID's Cadillac
                    268:    system.  1 means yes, 0 means no.  */
                    269: int flag_cadillac;
                    270: 
                    271: /* Controls whether compiler generates code to build objects
                    272:    that can be collected when they become garbage.  */
                    273: int flag_gc;
                    274: 
                    275: /* Controls whether compiler generates 'dossiers' that give
                    276:    run-time type information.  */
                    277: int flag_dossier;
                    278: 
                    279: /* Nonzero if we wish to output cross-referencing information
                    280:    for the GNU class browser.  */
                    281: extern int flag_gnu_xref;
                    282: 
                    283: /* Nonzero if compiler can make `reasonable' assumptions about
                    284:    references and objects.  For example, the compiler must be
                    285:    conservative about the following and not assume that `a' is nonnull:
                    286: 
                    287:    obj &a = g ();
                    288:    a.f (2);
                    289: 
                    290:    In general, it is `reasonable' to assume that for many programs,
                    291:    and better code can be generated in that case.  */
                    292: 
                    293: int flag_assume_nonnull_objects;
                    294: 
                    295: /* Table of language-dependent -f options.
                    296:    STRING is the option name.  VARIABLE is the address of the variable.
                    297:    ON_VALUE is the value to store in VARIABLE
                    298:     if `-fSTRING' is seen as an option.
                    299:    (If `-fno-STRING' is seen as an option, the opposite value is stored.)  */
                    300: 
                    301: static struct { char *string; int *variable; int on_value;} lang_f_options[] =
                    302: {
                    303:   {"signed-char", &flag_signed_char, 1},
                    304:   {"unsigned-char", &flag_signed_char, 0},
                    305:   {"signed-bitfields", &flag_signed_bitfields, 1},
                    306:   {"unsigned-bitfields", &flag_signed_bitfields, 0},
                    307:   {"short-enums", &flag_short_enums, 1},
                    308:   {"short-double", &flag_short_double, 1},
                    309:   {"cond-mismatch", &flag_cond_mismatch, 1},
                    310:   {"asm", &flag_no_asm, 0},
                    311:   {"builtin", &flag_no_builtin, 0},
                    312:   {"ident", &flag_no_ident, 0},
                    313:   {"labels-ok", &flag_labels_ok, 1},
                    314:   {"stats", &flag_detailed_statistics, 1},
                    315:   {"this-is-variable", &flag_this_is_variable, 1},
                    316:   {"strict-prototype", &strict_prototypes_lang_cplusplus, 1},
                    317:   {"all-virtual", &flag_all_virtual, 1},
                    318:   {"memoize-lookups", &flag_memoize_lookups, 1},
                    319:   {"elide-constructors", &flag_elide_constructors, 1},
                    320:   {"inline-debug", &flag_inline_debug, 0},
                    321:   {"handle-exceptions", &flag_handle_exceptions, 1},
                    322:   {"ansi-exceptions", &flag_ansi_exceptions, 1},
                    323:   {"spring-exceptions", &flag_handle_exceptions, 2},
                    324:   {"default-inline", &flag_default_inline, 1},
                    325:   {"dollars-in-identifiers", &dollars_in_ident, 1},
                    326:   {"enum-int-equiv", &flag_int_enum_equivalence, 1},
                    327:   {"gc", &flag_gc, 1},
                    328:   {"dossier", &flag_dossier, 1},
                    329:   {"xref", &flag_gnu_xref, 1},
                    330:   {"nonnull-objects", &flag_assume_nonnull_objects, 1},
1.1.1.5 ! root      331:   {"implement-inlines", &flag_implement_inlines, 1},
1.1       root      332: };
                    333: 
                    334: /* Decode the string P as a language-specific option.
                    335:    Return 1 if it is recognized (and handle it);
                    336:    return 0 if not recognized.  */
                    337: 
                    338: int   
                    339: lang_decode_option (p)
                    340:      char *p;
                    341: {
                    342:   if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
                    343:     flag_traditional = 1, dollars_in_ident = 1, flag_writable_strings = 1,
                    344:     flag_this_is_variable = 1;
1.1.1.4   root      345:   /* The +e options are for cfront compatibility.  They come in as
                    346:      `-+eN', to kludge around gcc.c's argument handling.  */
                    347:   else if (p[0] == '-' && p[1] == '+' && p[2] == 'e')
1.1       root      348:     {
                    349:       int old_write_virtuals = write_virtuals;
1.1.1.4   root      350:       if (p[3] == '1')
1.1       root      351:        write_virtuals = 1;
1.1.1.4   root      352:       else if (p[3] == '0')
1.1       root      353:        write_virtuals = -1;
1.1.1.4   root      354:       else if (p[3] == '2')
1.1       root      355:        write_virtuals = 2;
                    356:       else error ("invalid +e option");
                    357:       if (old_write_virtuals != 0
                    358:          && write_virtuals != old_write_virtuals)
                    359:        error ("conflicting +e options given");
                    360:     }
                    361:   else if (p[0] == '-' && p[1] == 'f')
                    362:     {
                    363:       /* Some kind of -f option.
                    364:         P's value is the option sans `-f'.
                    365:         Search for it in the table of options.  */
                    366:       int found = 0, j;
                    367: 
                    368:       p += 2;
                    369:       /* Try special -f options.  */
                    370: 
                    371:       if (!strcmp (p, "save-memoized"))
                    372:        {
                    373:          flag_memoize_lookups = 1;
                    374:          flag_save_memoized_contexts = 1;
                    375:          found = 1;
                    376:        }
                    377:       if (!strcmp (p, "no-save-memoized"))
                    378:        {
                    379:          flag_memoize_lookups = 0;
                    380:          flag_save_memoized_contexts = 0;
                    381:          found = 1;
                    382:        }
                    383:       else if (! strncmp (p, "cadillac", 8))
                    384:        {
                    385:          flag_cadillac = atoi (p+9);
                    386:          found = 1;
                    387:        }
                    388:       else if (! strncmp (p, "no-cadillac", 11))
                    389:        {
                    390:          flag_cadillac = 0;
                    391:          found = 1;
                    392:        }
                    393:       else if (! strcmp (p, "gc"))
                    394:        {
                    395:          flag_gc = 1;
                    396:          /* This must come along for the ride.  */
                    397:          flag_dossier = 1;
                    398:          found = 1;
                    399:        }
                    400:       else if (! strcmp (p, "no-gc"))
                    401:        {
                    402:          flag_gc = 0;
                    403:          /* This must come along for the ride.  */
                    404:          flag_dossier = 0;
                    405:          found = 1;
                    406:        }
                    407:       else for (j = 0;
                    408:                !found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
                    409:                j++)
                    410:        {
                    411:          if (!strcmp (p, lang_f_options[j].string))
                    412:            {
                    413:              *lang_f_options[j].variable = lang_f_options[j].on_value;
                    414:              /* A goto here would be cleaner,
                    415:                 but breaks the vax pcc.  */
                    416:              found = 1;
                    417:            }
                    418:          if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
                    419:              && ! strcmp (p+3, lang_f_options[j].string))
                    420:            {
                    421:              *lang_f_options[j].variable = ! lang_f_options[j].on_value;
                    422:              found = 1;
                    423:            }
                    424:        }
                    425:       return found;
                    426:     }
                    427:   else if (p[0] == '-' && p[1] == 'W')
                    428:     {
                    429:       int setting = 1;
                    430: 
                    431:       /* The -W options control the warning behavior of the compiler.  */
                    432:       p += 2;
                    433: 
                    434:       if (p[0] == 'n' && p[1] == 'o' && p[2] == '-')
                    435:        setting = 0, p += 3;
                    436: 
                    437:       if (!strcmp (p, "implicit"))
                    438:        warn_implicit = setting;
                    439:       else if (!strcmp (p, "return-type"))
                    440:        explicit_warn_return_type = setting;
                    441:       else if (!strcmp (p, "write-strings"))
                    442:        warn_write_strings = setting;
                    443:       else if (!strcmp (p, "cast-qual"))
                    444:        warn_cast_qual = setting;
1.1.1.4   root      445:       else if (!strcmp (p, "traditional"))
                    446:        warn_traditional = setting;
                    447:       else if (!strcmp (p, "char-subscripts"))
                    448:        warn_char_subscripts = setting;
1.1       root      449:       else if (!strcmp (p, "pointer-arith"))
                    450:        warn_pointer_arith = setting;
                    451:       else if (!strcmp (p, "strict-prototypes"))
                    452:        warn_strict_prototypes = setting;
                    453:       else if (!strcmp (p, "missing-prototypes"))
                    454:        warn_missing_prototypes = setting;
1.1.1.4   root      455:       else if (!strcmp (p, "redundant-decls"))
                    456:        warn_redundant_decls = setting;
1.1       root      457:       else if (!strcmp (p, "format"))
                    458:        warn_format = setting;
                    459:       else if (!strcmp (p, "conversion"))
                    460:        warn_conversion = setting;
                    461:       else if (!strcmp (p, "parentheses"))
                    462:        warn_parentheses = setting;
                    463:       else if (!strcmp (p, "comment"))
                    464:        ;                       /* cpp handles this one.  */
                    465:       else if (!strcmp (p, "comments"))
                    466:        ;                       /* cpp handles this one.  */
                    467:       else if (!strcmp (p, "trigraphs"))
                    468:        ;                       /* cpp handles this one.  */
1.1.1.3   root      469:       else if (!strcmp (p, "import"))
                    470:        ;                       /* cpp handles this one.  */
1.1       root      471:       else if (!strcmp (p, "all"))
                    472:        {
                    473:          extra_warnings = setting;
                    474:          explicit_warn_return_type = setting;
                    475:          warn_unused = setting;
1.1.1.4   root      476:          warn_implicit = setting;
1.1       root      477:          warn_switch = setting;
1.1.1.5 ! root      478:          /* We save the value of warn_uninitialized, since if they put
        !           479:             -Wuninitialized on the command line, we need to generate a
        !           480:             warning about not using it without also specifying -O.  */
        !           481:          if (warn_uninitialized != 1)
        !           482:            warn_uninitialized = (setting ? 2 : 0);
        !           483:          warn_template_debugging = setting;
1.1       root      484: #if 0
                    485:          warn_enum_clash = setting;
                    486: #endif
                    487:        }
                    488: 
                    489:       else if (!strcmp (p, "overloaded-virtual"))
                    490:        warn_overloaded_virtual = setting;
                    491:       else if (!strcmp (p, "enum-clash"))
                    492:        warn_enum_clash = setting;
                    493:       else return 0;
                    494:     }
                    495:   else if (!strcmp (p, "-ansi"))
                    496:     flag_no_asm = 1, dollars_in_ident = 0, flag_ansi = 1;
1.1.1.4   root      497: #ifdef SPEW_DEBUG
                    498:   /* Undocumented, only ever used when you're invoking cc1plus by hand, since
                    499:      it's probably safe to assume no sane person would ever want to use this
                    500:      under normal circumstances.  */
                    501:   else if (!strcmp (p, "-spew-debug"))
                    502:     spew_debug = 1;
                    503: #endif
1.1       root      504:   else
                    505:     return 0;
                    506: 
                    507:   return 1;
                    508: }
                    509: 
                    510: /* Incorporate `const' and `volatile' qualifiers for member functions.
                    511:    FUNCTION is a TYPE_DECL or a FUNCTION_DECL.
                    512:    QUALS is a list of qualifiers.  */
                    513: tree
                    514: grok_method_quals (ctype, function, quals)
                    515:      tree ctype, function, quals;
                    516: {
                    517:   tree fntype = TREE_TYPE (function);
                    518:   tree raises = TYPE_RAISES_EXCEPTIONS (fntype);
                    519: 
                    520:   do
                    521:     {
                    522:       extern tree ridpointers[];
                    523: 
                    524:       if (TREE_VALUE (quals) == ridpointers[(int)RID_CONST])
                    525:        {
                    526:          if (TYPE_READONLY (ctype))
                    527:            error ("duplicate `%s' %s",
                    528:                   IDENTIFIER_POINTER (TREE_VALUE (quals)),
                    529:                   (TREE_CODE (function) == FUNCTION_DECL
                    530:                    ? "for member function" : "in type declaration"));
                    531:          ctype = build_type_variant (ctype, 1, TYPE_VOLATILE (ctype));
                    532:          build_pointer_type (ctype);
                    533:        }
                    534:       else if (TREE_VALUE (quals) == ridpointers[(int)RID_VOLATILE])
                    535:        {
                    536:          if (TYPE_VOLATILE (ctype))
                    537:            error ("duplicate `%s' %s",
                    538:                   IDENTIFIER_POINTER (TREE_VALUE (quals)),
                    539:                   (TREE_CODE (function) == FUNCTION_DECL
                    540:                    ? "for member function" : "in type declaration"));
                    541:          ctype = build_type_variant (ctype, TYPE_READONLY (ctype), 1);
                    542:          build_pointer_type (ctype);
                    543:        }
                    544:       else
1.1.1.3   root      545:        my_friendly_abort (20);
1.1       root      546:       quals = TREE_CHAIN (quals);
                    547:     }
                    548:   while (quals);
                    549:   fntype = build_cplus_method_type (ctype, TREE_TYPE (fntype),
                    550:                                    (TREE_CODE (fntype) == METHOD_TYPE
                    551:                                     ? TREE_CHAIN (TYPE_ARG_TYPES (fntype))
                    552:                                     : TYPE_ARG_TYPES (fntype)));
                    553:   if (raises)
                    554:     fntype = build_exception_variant (ctype, fntype, raises);
                    555: 
                    556:   TREE_TYPE (function) = fntype;
                    557:   return ctype;
                    558: }
                    559: 
1.1.1.4   root      560: /* This routine replaces cryptic DECL_NAMEs with readable DECL_NAMEs.
                    561:    It leaves DECL_ASSEMBLER_NAMEs with the correct value.  */
                    562: /* This does not yet work with user defined conversion operators
                    563:    It should.  */
                    564: static void
                    565: substitute_nice_name (decl)
                    566:      tree decl;
                    567: {
                    568:   if (DECL_NAME (decl) && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE)
                    569:     {
                    570:       char *n = decl_as_string (DECL_NAME (decl));
                    571:       if (n[strlen (n) - 1] == ' ')
                    572:        n[strlen (n) - 1] = 0;
                    573:       DECL_NAME (decl) = get_identifier (n);
                    574:     }
                    575: }
                    576: 
1.1       root      577: /* Classes overload their constituent function names automatically.
                    578:    When a function name is declared in a record structure,
                    579:    its name is changed to it overloaded name.  Since names for
                    580:    constructors and destructors can conflict, we place a leading
                    581:    '$' for destructors.
                    582: 
                    583:    CNAME is the name of the class we are grokking for.
                    584: 
                    585:    FUNCTION is a FUNCTION_DECL.  It was created by `grokdeclarator'.
                    586: 
                    587:    FLAGS contains bits saying what's special about today's
                    588:    arguments.  1 == DESTRUCTOR.  2 == OPERATOR.
                    589: 
                    590:    If FUNCTION is a destructor, then we must add the `auto-delete' field
                    591:    as a second parameter.  There is some hair associated with the fact
                    592:    that we must "declare" this variable in the manner consistent with the
1.1.1.2   root      593:    way the rest of the arguments were declared.
1.1       root      594: 
                    595:    QUALS are the qualifiers for the this pointer.  */
                    596: 
                    597: void
                    598: grokclassfn (ctype, cname, function, flags, quals)
                    599:      tree ctype, cname, function;
                    600:      enum overload_flags flags;
                    601:      tree quals;
                    602: {
                    603:   tree fn_name = DECL_NAME (function);
                    604:   tree arg_types;
                    605:   tree parm;
                    606: 
                    607:   if (fn_name == NULL_TREE)
                    608:     {
                    609:       error ("name missing for member function");
                    610:       fn_name = get_identifier ("<anonymous>");
                    611:       DECL_NAME (function) = fn_name;
                    612:     }
                    613: 
                    614:   if (quals)
                    615:     ctype = grok_method_quals (ctype, function, quals);
                    616: 
                    617:   arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
                    618:   if (TREE_CODE (TREE_TYPE (function)) == METHOD_TYPE)
                    619:     {
                    620:       /* Must add the class instance variable up front.  */
                    621:       /* Right now we just make this a pointer.  But later
                    622:         we may wish to make it special.  */
                    623:       tree type = TREE_VALUE (arg_types);
                    624: 
                    625:       if (flags == DTOR_FLAG)
                    626:        type = TYPE_MAIN_VARIANT (type);
                    627:       else if (DECL_CONSTRUCTOR_P (function))
                    628:        {
                    629:          if (TYPE_USES_VIRTUAL_BASECLASSES (ctype))
                    630:            {
                    631:              DECL_CONSTRUCTOR_FOR_VBASE_P (function) = 1;
                    632:              /* In this case we need "in-charge" flag saying whether
                    633:                 this constructor is responsible for initialization
                    634:                 of virtual baseclasses or not.  */
                    635:              parm = build_decl (PARM_DECL, in_charge_identifier, integer_type_node);
                    636:              DECL_ARG_TYPE (parm) = integer_type_node;
1.1.1.4   root      637:              DECL_REGISTER (parm) = 1;
1.1       root      638:              TREE_CHAIN (parm) = last_function_parms;
                    639:              last_function_parms = parm;
                    640:            }
                    641:        }
                    642: 
                    643:       parm = build_decl (PARM_DECL, this_identifier, type);
1.1.1.4   root      644:       /* Mark the artificial `this' parameter as "artificial".  */
                    645:       DECL_SOURCE_LINE (parm) = 0;
1.1       root      646:       DECL_ARG_TYPE (parm) = type;
                    647:       /* We can make this a register, so long as we don't
1.1.1.2   root      648:         accidentally complain if someone tries to take its address.  */
1.1.1.4   root      649:       DECL_REGISTER (parm) = 1;
1.1.1.3   root      650: #if 0
                    651:       /* it is wrong to flag the object as readonly, when
                    652:         flag_this_is_variable is 0. */
1.1       root      653:       if (flags != DTOR_FLAG
1.1.1.2   root      654:          && (flag_this_is_variable <= 0 || TYPE_READONLY (type)))
1.1.1.3   root      655: #else
                    656:       if (flags != DTOR_FLAG && TYPE_READONLY (type))
                    657: #endif
1.1       root      658:        TREE_READONLY (parm) = 1;
                    659:       TREE_CHAIN (parm) = last_function_parms;
                    660:       last_function_parms = parm;
                    661:     }
                    662: 
                    663:   if (flags == DTOR_FLAG)
                    664:     {
                    665:       char *buf, *dbuf;
                    666:       tree const_integer_type = build_type_variant (integer_type_node, 1, 0);
                    667:       int len = sizeof (DESTRUCTOR_DECL_PREFIX)-1;
                    668: 
                    669:       arg_types = hash_tree_chain (const_integer_type, void_list_node);
                    670:       /* Build the overload name.  It will look like e.g. 7Example.  */
1.1.1.4   root      671:       if (IDENTIFIER_TYPE_VALUE (cname))
                    672:        dbuf = build_overload_name (IDENTIFIER_TYPE_VALUE (cname), 1, 1);
                    673:       else if (IDENTIFIER_LOCAL_VALUE (cname))
                    674:        dbuf = build_overload_name (TREE_TYPE (IDENTIFIER_LOCAL_VALUE (cname)), 1, 1);
                    675:       else
1.1.1.5 ! root      676: #if 0
1.1.1.4   root      677:        my_friendly_abort (346);
1.1.1.5 ! root      678: #else
        !           679:       /* Using ctype fixes the `X::Y::~Y()' crash.  The cname has no type when
        !           680:         it's defined out of the class definition, since poplevel_class wipes
        !           681:         it out.  */
        !           682:        dbuf = build_overload_name (ctype, 1, 1);
        !           683: #endif
1.1       root      684:       buf = (char *)alloca (strlen (dbuf) + sizeof (DESTRUCTOR_DECL_PREFIX));
                    685:       bcopy (DESTRUCTOR_DECL_PREFIX, buf, len);
                    686:       buf[len] = '\0';
                    687:       strcat (buf, dbuf);
                    688:       DECL_ASSEMBLER_NAME (function) = get_identifier (buf);
                    689:       parm = build_decl (PARM_DECL, in_charge_identifier, const_integer_type);
                    690:       TREE_USED (parm) = 1;
                    691:       TREE_READONLY (parm) = 1;
                    692:       DECL_ARG_TYPE (parm) = const_integer_type;
                    693:       /* This is the same chain as DECL_ARGUMENTS (...).  */
                    694:       TREE_CHAIN (last_function_parms) = parm;
                    695: 
                    696:       TREE_TYPE (function) = build_cplus_method_type (ctype, void_type_node, arg_types);
                    697:       TYPE_HAS_DESTRUCTOR (ctype) = 1;
                    698:     }
                    699:   else
                    700:     {
                    701:       tree these_arg_types;
                    702: 
                    703:       if (DECL_CONSTRUCTOR_FOR_VBASE_P (function))
                    704:        {
                    705:          arg_types = hash_tree_chain (integer_type_node, TREE_CHAIN (arg_types));
                    706:          TREE_TYPE (function)
                    707:            = build_cplus_method_type (ctype, TREE_TYPE (TREE_TYPE (function)), arg_types);
                    708:          arg_types = TYPE_ARG_TYPES (TREE_TYPE (function));
                    709:        }
                    710: 
                    711:       these_arg_types = arg_types;
                    712: 
                    713:       if (TREE_CODE (TREE_TYPE (function)) == FUNCTION_TYPE)
                    714:        /* Only true for static member functions.  */
                    715:        these_arg_types = hash_tree_chain (TYPE_POINTER_TO (ctype), arg_types);
                    716: 
                    717:       DECL_ASSEMBLER_NAME (function)
1.1.1.2   root      718:        = build_decl_overload (fn_name, these_arg_types,
1.1       root      719:                               1 + DECL_CONSTRUCTOR_P (function));
1.1.1.4   root      720: 
                    721: #if 0
                    722:       /* This code is going into the compiler, but currently, it makes
                    723:         libg++/src/Interger.cc not compile.  The problem is that the nice name
                    724:         winds up going into the symbol table, and conversion operations look
                    725:         for the manged name.  */
                    726:       substitute_nice_name (function);
                    727: #endif
                    728: 
1.1       root      729: #if 0
                    730:       if (flags == TYPENAME_FLAG)
                    731:        /* Not exactly an IDENTIFIER_TYPE_VALUE.  */
                    732:        TREE_TYPE (DECL_ASSEMBLER_NAME (function)) = TREE_TYPE (fn_name);
                    733: #endif
                    734:     }
                    735: 
                    736:   DECL_ARGUMENTS (function) = last_function_parms;
                    737:   /* First approximations.  */
                    738:   DECL_CONTEXT (function) = ctype;
                    739:   DECL_CLASS_CONTEXT (function) = ctype;
                    740: }
                    741: 
1.1.1.5 ! root      742: /* Generate errors possibly applicable for a given set of specifiers.  */
        !           743: void
        !           744: bad_specifiers (object, virtualp, quals, friendp, raises)
        !           745:      char *object;
        !           746:      int virtualp, quals, friendp, raises;
        !           747: {
        !           748:   if (virtualp)
        !           749:     error ("%s declared `virtual'", object);
        !           750:   if (quals)
        !           751:     error ("`const' and `volatile' function specifiers invalid in %s declaration");
        !           752:   if (friendp)
        !           753:     error ("invalid friend declaration");
        !           754:   if (raises)
        !           755:     error ("invalid raises declaration");
        !           756: }
        !           757: 
1.1       root      758: /* Sanity check: report error if this function FUNCTION is not
                    759:    really a member of the class (CTYPE) it is supposed to belong to.
                    760:    CNAME and FLAGS are the same here as they are for grokclassfn above.  */
                    761: 
                    762: void
1.1.1.5 ! root      763: check_classfn (ctype, cname, function)
1.1       root      764:      tree ctype, cname, function;
                    765: {
                    766:   tree fn_name = DECL_NAME (function);
                    767:   tree fndecl;
                    768:   int need_quotes = 0;
                    769:   char *err_name;
                    770:   tree method_vec = CLASSTYPE_METHOD_VEC (ctype);
                    771:   tree *methods = 0;
                    772:   tree *end = 0;
                    773: 
                    774:   if (method_vec != 0)
                    775:     {
                    776:       methods = &TREE_VEC_ELT (method_vec, 0);
                    777:       end = TREE_VEC_END (method_vec);
                    778: 
                    779:       /* First suss out ctors and dtors.  */
                    780:       if (*methods && fn_name == cname)
                    781:        goto got_it;
                    782: 
                    783:       while (++methods != end)
                    784:        {
                    785:          if (fn_name == DECL_NAME (*methods))
                    786:            {
                    787:            got_it:
                    788:              fndecl = *methods;
                    789:              while (fndecl)
                    790:                {
                    791:                  if (DECL_ASSEMBLER_NAME (function) == DECL_ASSEMBLER_NAME (fndecl))
                    792:                    return;
                    793:                  fndecl = DECL_CHAIN (fndecl);
                    794:                }
                    795:              break;            /* loser */
                    796:            }
                    797:        }
                    798:     }
                    799: 
1.1.1.2   root      800:   if (fn_name == ansi_opname[(int) TYPE_EXPR])
1.1       root      801:     {
                    802:       if (TYPE_HAS_CONVERSION (ctype))
                    803:        err_name = "such type conversion operator";
                    804:     }
                    805:   else if (IDENTIFIER_OPNAME_P (fn_name))
                    806:     {
                    807:       err_name = (char *)alloca (1024);
                    808:       sprintf (err_name, "`operator %s'", operator_name_string (fn_name));
                    809:     }
                    810:   else
                    811:     {
                    812:       err_name = IDENTIFIER_POINTER (fn_name);
                    813:       need_quotes = 1;
                    814:     }
                    815: 
                    816:   if (methods != end)
                    817:     if (need_quotes)
1.1.1.5 ! root      818:       error ("argument list for `%s' does not match any in class `%s'",
        !           819:             err_name, IDENTIFIER_POINTER (cname));
1.1       root      820:     else
1.1.1.5 ! root      821:       error ("argument list for %s does not match any in class `%s'",
        !           822:             err_name, IDENTIFIER_POINTER (cname));
1.1       root      823:   else
                    824:     {
                    825:       methods = 0;
                    826:       if (need_quotes)
1.1.1.5 ! root      827:        error ("no `%s' member function declared in class `%s'",
        !           828:               err_name, IDENTIFIER_POINTER (cname));
1.1       root      829:       else
1.1.1.5 ! root      830:        error ("no %s declared in class `%s'",
        !           831:               err_name, IDENTIFIER_POINTER (cname));
1.1       root      832:     }
                    833: 
                    834:   /* If we did not find the method in the class, add it to
                    835:      avoid spurious errors.  */
                    836:   add_method (ctype, methods, function);
                    837: }
                    838: 
                    839: /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
                    840:    of a structure component, returning a FIELD_DECL node.
                    841:    QUALS is a list of type qualifiers for this decl (such as for declaring
                    842:    const member functions).
                    843: 
                    844:    This is done during the parsing of the struct declaration.
                    845:    The FIELD_DECL nodes are chained together and the lot of them
                    846:    are ultimately passed to `build_struct' to make the RECORD_TYPE node.
                    847: 
                    848:    C++:
                    849: 
                    850:    If class A defines that certain functions in class B are friends, then
                    851:    the way I have set things up, it is B who is interested in permission
                    852:    granted by A.  However, it is in A's context that these declarations
                    853:    are parsed.  By returning a void_type_node, class A does not attempt
                    854:    to incorporate the declarations of the friends within its structure.
                    855: 
                    856:    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
                    857:    CHANGES TO CODE IN `start_method'.  */
                    858: 
                    859: tree
                    860: grokfield (declarator, declspecs, raises, init, asmspec_tree)
1.1.1.5 ! root      861:      tree declarator, declspecs, raises, init, asmspec_tree;
1.1       root      862: {
                    863:   register tree value;
                    864:   char *asmspec = 0;
                    865: 
                    866:   /* Convert () initializers to = initializers.  */
                    867:   if (init == NULL_TREE && declarator != NULL_TREE
                    868:       && TREE_CODE (declarator) == CALL_EXPR
                    869:       && TREE_OPERAND (declarator, 0)
                    870:       && (TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE
                    871:          || TREE_CODE (TREE_OPERAND (declarator, 0)) == SCOPE_REF)
                    872:       && parmlist_is_exprlist (TREE_OPERAND (declarator, 1)))
                    873:     {
                    874:       init = TREE_OPERAND (declarator, 1);
                    875:       declarator = TREE_OPERAND (declarator, 0);
                    876:     }
                    877: 
1.1.1.4   root      878:   if (init
                    879:       && TREE_CODE (init) == TREE_LIST
                    880:       && TREE_VALUE (init) == error_mark_node
                    881:       && TREE_CHAIN (init) == NULL_TREE)
                    882:        init = NULL_TREE;
                    883: 
1.1       root      884:   value = grokdeclarator (declarator, declspecs, FIELD, init != 0, raises);
                    885:   if (! value)
                    886:     return NULL_TREE; /* friends went bad.  */
                    887: 
                    888:   /* Pass friendly classes back.  */
                    889:   if (TREE_CODE (value) == VOID_TYPE)
                    890:     return void_type_node;
                    891: 
                    892:   if (DECL_NAME (value) != NULL_TREE
                    893:       && IDENTIFIER_POINTER (DECL_NAME (value))[0] == '_'
                    894:       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (value)), "_vptr"))
                    895:     error_with_decl (value, "member `%s' conflicts with virtual function table field name");
                    896: 
                    897:   /* Stash away type declarations.  */
                    898:   if (TREE_CODE (value) == TYPE_DECL)
                    899:     {
1.1.1.4   root      900:       DECL_NONLOCAL (value) = 1;
1.1       root      901:       CLASSTYPE_LOCAL_TYPEDECLS (current_class_type) = 1;
1.1.1.5 ! root      902:       set_identifier_type_value (DECL_NAME (value), TREE_TYPE (value));
1.1       root      903:       pushdecl_class_level (value);
                    904:       return value;
                    905:     }
                    906: 
                    907:   if (DECL_IN_AGGR_P (value))
                    908:     {
1.1.1.4   root      909:       error_with_decl (value, "`%s' is already defined in the class %s",
                    910:                       TYPE_NAME_STRING (DECL_CONTEXT (value)));
1.1       root      911:       return void_type_node;
                    912:     }
                    913: 
                    914:   if (flag_cadillac)
                    915:     cadillac_start_decl (value);
                    916: 
                    917:   if (asmspec_tree)
                    918:     asmspec = TREE_STRING_POINTER (asmspec_tree);
                    919: 
                    920:   if (init != 0)
                    921:     {
                    922:       if (TREE_CODE (value) == FUNCTION_DECL)
                    923:        {
                    924:          grok_function_init (value, init);
                    925:          init = NULL_TREE;
                    926:        }
                    927:       else if (pedantic)
                    928:        {
                    929:          error ("fields cannot have initializers");
                    930:          init = NULL_TREE;
                    931:        }
                    932:       else
                    933:        {
                    934:          /* We allow initializers to become parameters to base initializers.  */
                    935:          if (TREE_CODE (init) == TREE_LIST)
                    936:            {
                    937:              if (TREE_CHAIN (init) == NULL_TREE)
                    938:                init = TREE_VALUE (init);
                    939:              else
1.1.1.5 ! root      940:                init = digest_init (TREE_TYPE (value), init, (tree *)0);
1.1       root      941:            }
                    942: 
                    943:          if (TREE_CODE (init) == CONST_DECL)
                    944:            init = DECL_INITIAL (init);
                    945:          else if (TREE_READONLY_DECL_P (init))
                    946:            init = decl_constant_value (init);
                    947:          else if (TREE_CODE (init) == CONSTRUCTOR)
1.1.1.5 ! root      948:            init = digest_init (TREE_TYPE (value), init, (tree *)0);
1.1.1.4   root      949:          my_friendly_assert (TREE_PERMANENT (init), 192);
1.1       root      950:          if (init == error_mark_node)
                    951:            /* We must make this look different than `error_mark_node'
                    952:               because `decl_const_value' would mis-interpret it
                    953:               as only meaning that this VAR_DECL is defined.  */
                    954:            init = build1 (NOP_EXPR, TREE_TYPE (value), init);
                    955:          else if (! TREE_CONSTANT (init))
                    956:            {
                    957:              /* We can allow references to things that are effectively
                    958:                 static, since references are initialized with the address.  */
                    959:              if (TREE_CODE (TREE_TYPE (value)) != REFERENCE_TYPE
                    960:                  || (TREE_STATIC (init) == 0
                    961:                      && (TREE_CODE_CLASS (TREE_CODE (init)) != 'd'
1.1.1.4   root      962:                          || DECL_EXTERNAL (init) == 0)))
1.1       root      963:                {
                    964:                  error ("field initializer is not constant");
                    965:                  init = error_mark_node;
                    966:                }
                    967:            }
                    968:        }
                    969:     }
                    970: 
                    971:   /* The corresponding pop_obstacks is in finish_decl.  */
                    972:   push_obstacks_nochange ();
                    973: 
                    974:   if (TREE_CODE (value) == VAR_DECL)
                    975:     {
                    976:       /* We cannot call pushdecl here, because that would
                    977:         fill in the value of our TREE_CHAIN.  Instead, we
                    978:         modify finish_decl to do the right thing, namely, to
                    979:         put this decl out straight away.  */
                    980:       if (TREE_STATIC (value))
                    981:        {
1.1.1.4   root      982:          /* current_class_type can be NULL_TREE in case of error.  */
                    983:          if (asmspec == 0 && current_class_type)
1.1       root      984:            {
                    985:              tree name;
                    986:              char *buf, *buf2;
                    987: 
                    988:              buf2 = build_overload_name (current_class_type, 1, 1);
                    989:              buf = (char *)alloca (IDENTIFIER_LENGTH (DECL_NAME (value))
                    990:                                    + sizeof (STATIC_NAME_FORMAT)
                    991:                                    + strlen (buf2));
                    992:              sprintf (buf, STATIC_NAME_FORMAT, buf2,
                    993:                       IDENTIFIER_POINTER (DECL_NAME (value)));
                    994:              name = get_identifier (buf);
                    995:              TREE_PUBLIC (value) = 1;
                    996:              DECL_INITIAL (value) = error_mark_node;
                    997:              DECL_ASSEMBLER_NAME (value) = name;
                    998:            }
                    999:          pending_statics = perm_tree_cons (NULL_TREE, value, pending_statics);
                   1000: 
                   1001:          /* Static consts need not be initialized in the class definition.  */
                   1002:          if (init != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (value)))
                   1003:            {
                   1004:              static int explanation = 0;
                   1005: 
                   1006:              error ("initializer invalid for static member with constructor");
                   1007:              if (explanation++ == 0)
                   1008:                error ("(you really want to initialize it separately)");
                   1009:              init = 0;
                   1010:            }
                   1011:          /* Force the compiler to know when an uninitialized static
                   1012:             const member is being used.  */
                   1013:          if (TYPE_READONLY (value) && init == 0)
                   1014:            TREE_USED (value) = 1;
                   1015:        }
                   1016:       DECL_INITIAL (value) = init;
                   1017:       DECL_IN_AGGR_P (value) = 1;
                   1018: 
                   1019:       finish_decl (value, init, asmspec_tree, 1);
                   1020:       pushdecl_class_level (value);
                   1021:       return value;
                   1022:     }
                   1023:   if (TREE_CODE (value) == FIELD_DECL)
                   1024:     {
                   1025:       if (asmspec)
                   1026:        DECL_ASSEMBLER_NAME (value) = get_identifier (asmspec);
                   1027:       if (DECL_INITIAL (value) == error_mark_node)
                   1028:        init = error_mark_node;
                   1029:       finish_decl (value, init, asmspec_tree, 1);
                   1030:       DECL_INITIAL (value) = init;
                   1031:       DECL_IN_AGGR_P (value) = 1;
                   1032:       return value;
                   1033:     }
                   1034:   if (TREE_CODE (value) == FUNCTION_DECL)
                   1035:     {
                   1036:       /* grokdeclarator defers setting this.  */
                   1037:       TREE_PUBLIC (value) = 1;
                   1038:       if (DECL_CHAIN (value) != NULL_TREE)
                   1039:        {
                   1040:          /* Need a fresh node here so that we don't get circularity
                   1041:             when we link these together.  */
                   1042:          value = copy_node (value);
                   1043:          /* When does this happen?  */
1.1.1.4   root     1044:          my_friendly_assert (init == NULL_TREE, 193);
1.1       root     1045:        }
                   1046:       finish_decl (value, init, asmspec_tree, 1);
                   1047: 
                   1048:       /* Pass friends back this way.  */
                   1049:       if (DECL_FRIEND_P (value))
                   1050:        return void_type_node;
                   1051: 
                   1052:       DECL_IN_AGGR_P (value) = 1;
                   1053:       return value;
                   1054:     }
1.1.1.3   root     1055:   my_friendly_abort (21);
1.1       root     1056:   /* NOTREACHED */
                   1057:   return NULL_TREE;
                   1058: }
                   1059: 
                   1060: /* Like `grokfield', but for bitfields.
                   1061:    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.  */
                   1062: 
                   1063: tree
                   1064: grokbitfield (declarator, declspecs, width)
                   1065:      tree declarator, declspecs, width;
                   1066: {
                   1067:   register tree value = grokdeclarator (declarator, declspecs, BITFIELD, 0, NULL_TREE);
                   1068: 
                   1069:   if (! value) return NULL_TREE; /* friends went bad.  */
                   1070: 
                   1071:   /* Pass friendly classes back.  */
                   1072:   if (TREE_CODE (value) == VOID_TYPE)
                   1073:     return void_type_node;
                   1074: 
                   1075:   if (TREE_CODE (value) == TYPE_DECL)
                   1076:     {
                   1077:       error_with_decl (value, "cannot declare `%s' to be a bitfield type");
                   1078:       return NULL_TREE;
                   1079:     }
                   1080: 
                   1081:   if (DECL_IN_AGGR_P (value))
                   1082:     {
1.1.1.4   root     1083:       error_with_decl (value, "`%s' is already defined in the class %s",
                   1084:                       TYPE_NAME_STRING (DECL_CONTEXT (value)));
1.1       root     1085:       return void_type_node;
                   1086:     }
                   1087: 
                   1088:   GNU_xref_member (current_class_name, value);
                   1089: 
                   1090:   if (TREE_STATIC (value))
                   1091:     {
                   1092:       error_with_decl (value, "static member `%s' cannot be a bitfield");
                   1093:       return NULL_TREE;
                   1094:     }
                   1095:   finish_decl (value, NULL_TREE, NULL_TREE, 0);
                   1096: 
1.1.1.4   root     1097:   if (width != error_mark_node)
1.1       root     1098:     {
1.1.1.4   root     1099:       /* detect invalid field size.  */
                   1100:       if (TREE_CODE (width) == CONST_DECL)
                   1101:        width = DECL_INITIAL (width);
                   1102:       else if (TREE_READONLY_DECL_P (width))
                   1103:        width = decl_constant_value (width);
                   1104:       if (TREE_CODE (width) != INTEGER_CST)
                   1105:        {
                   1106:          error_with_decl (value, "structure field `%s' width not an integer constant");
                   1107:          DECL_INITIAL (value) = NULL_TREE;
                   1108:        }
                   1109:       else
                   1110:        {
                   1111:          DECL_INITIAL (value) = width;
                   1112:          DECL_BIT_FIELD (value) = 1;
                   1113:        }
1.1       root     1114:     }
1.1.1.4   root     1115: 
1.1       root     1116:   DECL_IN_AGGR_P (value) = 1;
                   1117:   return value;
                   1118: }
                   1119: 
                   1120: /* Like GROKFIELD, except that the declarator has been
                   1121:    buried in DECLSPECS.  Find the declarator, and
                   1122:    return something that looks like it came from
                   1123:    GROKFIELD.  */
                   1124: tree
                   1125: groktypefield (declspecs, parmlist)
                   1126:      tree declspecs;
                   1127:      tree parmlist;
                   1128: {
                   1129:   tree spec = declspecs;
                   1130:   tree prev = NULL_TREE;
                   1131: 
                   1132:   tree type_id = NULL_TREE;
                   1133:   tree quals = NULL_TREE;
                   1134:   tree lengths = NULL_TREE;
                   1135:   tree decl = NULL_TREE;
                   1136: 
                   1137:   while (spec)
                   1138:     {
                   1139:       register tree id = TREE_VALUE (spec);
                   1140: 
                   1141:       if (TREE_CODE (spec) != TREE_LIST)
                   1142:        /* Certain parse errors slip through.  For example,
                   1143:           `int class ();' is not caught by the parser. Try
                   1144:           weakly to recover here.  */
                   1145:        return NULL_TREE;
                   1146: 
                   1147:       if (TREE_CODE (id) == TYPE_DECL
                   1148:          || (TREE_CODE (id) == IDENTIFIER_NODE && TREE_TYPE (id)))
                   1149:        {
                   1150:          /* We have a constructor/destructor or
                   1151:             conversion operator.  Use it.  */
                   1152:          if (prev)
                   1153:            TREE_CHAIN (prev) = TREE_CHAIN (spec);
                   1154:          else
                   1155:            declspecs = TREE_CHAIN (spec);
                   1156: 
                   1157:          type_id = id;
                   1158:          goto found;
                   1159:        }
                   1160:       prev = spec;
                   1161:       spec = TREE_CHAIN (spec);
                   1162:     }
                   1163: 
1.1.1.4   root     1164:   /* Nope, we have a conversion operator to a scalar type or something
                   1165:      else, that includes things like constructor declarations for
                   1166:      templates.  */
1.1       root     1167:   spec = declspecs;
                   1168:   while (spec)
                   1169:     {
                   1170:       tree id = TREE_VALUE (spec);
                   1171: 
                   1172:       if (TREE_CODE (id) == IDENTIFIER_NODE)
                   1173:        {
                   1174:          if (id == ridpointers[(int)RID_INT]
                   1175:              || id == ridpointers[(int)RID_DOUBLE]
1.1.1.4   root     1176:              || id == ridpointers[(int)RID_FLOAT]
                   1177:              || id == ridpointers[(int)RID_WCHAR])
1.1       root     1178:            {
                   1179:              if (type_id)
                   1180:                error ("extra `%s' ignored",
                   1181:                       IDENTIFIER_POINTER (id));
                   1182:              else
                   1183:                type_id = id;
                   1184:            }
                   1185:          else if (id == ridpointers[(int)RID_LONG]
                   1186:                   || id == ridpointers[(int)RID_SHORT]
                   1187:                   || id == ridpointers[(int)RID_CHAR])
                   1188:            {
                   1189:              lengths = tree_cons (NULL_TREE, id, lengths);
                   1190:            }
                   1191:          else if (id == ridpointers[(int)RID_VOID])
                   1192:            {
                   1193:              if (type_id)
                   1194:                error ("spurious `void' type ignored");
                   1195:              else
                   1196:                error ("conversion to `void' type invalid");
                   1197:            }
                   1198:          else if (id == ridpointers[(int)RID_AUTO]
                   1199:                   || id == ridpointers[(int)RID_REGISTER]
                   1200:                   || id == ridpointers[(int)RID_TYPEDEF]
                   1201:                   || id == ridpointers[(int)RID_CONST]
                   1202:                   || id == ridpointers[(int)RID_VOLATILE])
                   1203:            {
                   1204:              error ("type specifier `%s' used invalidly",
                   1205:                     IDENTIFIER_POINTER (id));
                   1206:            }
                   1207:          else if (id == ridpointers[(int)RID_FRIEND]
                   1208:                   || id == ridpointers[(int)RID_VIRTUAL]
                   1209:                   || id == ridpointers[(int)RID_INLINE]
                   1210:                   || id == ridpointers[(int)RID_UNSIGNED]
                   1211:                   || id == ridpointers[(int)RID_SIGNED]
                   1212:                   || id == ridpointers[(int)RID_STATIC]
                   1213:                   || id == ridpointers[(int)RID_EXTERN])
                   1214:            {
                   1215:              quals = tree_cons (NULL_TREE, id, quals);
                   1216:            }
                   1217:          else
                   1218:            {
                   1219:              /* Happens when we have a global typedef
                   1220:                 and a class-local member function with
                   1221:                 the same name.  */
                   1222:              type_id = id;
                   1223:              goto found;
                   1224:            }
                   1225:        }
                   1226:       else if (TREE_CODE (id) == RECORD_TYPE)
                   1227:        {
                   1228:          type_id = TYPE_NAME (id);
                   1229:          if (TREE_CODE (type_id) == TYPE_DECL)
                   1230:            type_id = DECL_NAME (type_id);
                   1231:          if (type_id == NULL_TREE)
                   1232:            error ("identifier for aggregate type conversion omitted");
                   1233:        }
1.1.1.4   root     1234:       else if (TREE_CODE_CLASS (TREE_CODE (id)) == 't')
1.1.1.5 ! root     1235:        error ("`operator' missing on conversion operator or tag missing from type");
1.1       root     1236:       else
1.1.1.5 ! root     1237:        my_friendly_abort (194);
1.1       root     1238:       spec = TREE_CHAIN (spec);
                   1239:     }
                   1240: 
                   1241:   if (type_id)
1.1.1.5 ! root     1242:     declspecs = chainon (lengths, quals);
1.1       root     1243:   else if (lengths)
                   1244:     {
                   1245:       if (TREE_CHAIN (lengths))
                   1246:        error ("multiple length specifiers");
                   1247:       type_id = ridpointers[(int)RID_INT];
                   1248:       declspecs = chainon (lengths, quals);
                   1249:     }
                   1250:   else if (quals)
                   1251:     {
                   1252:       error ("no type given, defaulting to `operator int ...'");
                   1253:       type_id = ridpointers[(int)RID_INT];
                   1254:       declspecs = quals;
                   1255:     }
1.1.1.5 ! root     1256:   else
        !          1257:     return NULL_TREE;
1.1.1.4   root     1258: 
1.1       root     1259:  found:
                   1260:   decl = grokdeclarator (build_parse_node (CALL_EXPR, type_id, parmlist, NULL_TREE),
                   1261:                         declspecs, FIELD, 0, NULL_TREE);
                   1262:   if (decl == NULL_TREE)
                   1263:     return NULL_TREE;
                   1264: 
                   1265:   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_CHAIN (decl) != NULL_TREE)
                   1266:     {
                   1267:       /* Need a fresh node here so that we don't get circularity
                   1268:         when we link these together.  */
                   1269:       decl = copy_node (decl);
                   1270:     }
                   1271: 
                   1272:   if (decl == void_type_node
                   1273:       || (TREE_CODE (decl) == FUNCTION_DECL
                   1274:          && TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE))
                   1275:     /* bunch of friends.  */
                   1276:     return decl;
                   1277: 
                   1278:   if (DECL_IN_AGGR_P (decl))
                   1279:     {
1.1.1.4   root     1280:       error_with_decl (decl, "`%s' already defined in the class ");
1.1       root     1281:       return void_type_node;
                   1282:     }
                   1283: 
                   1284:   finish_decl (decl, NULL_TREE, NULL_TREE, 0);
                   1285: 
                   1286:   /* If this declaration is common to another declaration
                   1287:      complain about such redundancy, and return NULL_TREE
                   1288:      so that we don't build a circular list.  */
                   1289:   if (DECL_CHAIN (decl))
                   1290:     {
1.1.1.4   root     1291:       error_with_decl (decl, "function `%s' declared twice in class %s",
                   1292:                       TYPE_NAME_STRING (DECL_CONTEXT (decl)));
1.1       root     1293:       return NULL_TREE;
                   1294:     }
                   1295:   DECL_IN_AGGR_P (decl) = 1;
                   1296:   return decl;
                   1297: }
                   1298: 
                   1299: /* The precedence rules of this grammar (or any other deterministic LALR
                   1300:    grammar, for that matter), place the CALL_EXPR somewhere where we
                   1301:    may not want it.  The solution is to grab the first CALL_EXPR we see,
                   1302:    pretend that that is the one that belongs to the parameter list of
                   1303:    the type conversion function, and leave everything else alone.
                   1304:    We pull it out in place.
                   1305: 
                   1306:    CALL_REQUIRED is non-zero if we should complain if a CALL_EXPR
                   1307:    does not appear in DECL.  */
                   1308: tree
                   1309: grokoptypename (decl, call_required)
                   1310:      tree decl;
                   1311:      int call_required;
                   1312: {
                   1313:   tree tmp, last;
                   1314: 
1.1.1.4   root     1315:   my_friendly_assert (TREE_CODE (decl) == TYPE_EXPR, 195);
1.1       root     1316: 
                   1317:   tmp = TREE_OPERAND (decl, 0);
                   1318:   last = NULL_TREE;
                   1319: 
                   1320:   while (tmp)
                   1321:     {
                   1322:       switch (TREE_CODE (tmp))
                   1323:        {
                   1324:        case CALL_EXPR:
                   1325:          {
                   1326:            tree parms = TREE_OPERAND (tmp, 1);
                   1327: 
                   1328:            if (last)
                   1329:              TREE_OPERAND (last, 0) = TREE_OPERAND (tmp, 0);
                   1330:            else
                   1331:              TREE_OPERAND (decl, 0) = TREE_OPERAND (tmp, 0);
                   1332:            if (parms
                   1333:                && TREE_CODE (TREE_VALUE (parms)) == TREE_LIST)
                   1334:              TREE_VALUE (parms)
                   1335:                = grokdeclarator (TREE_VALUE (TREE_VALUE (parms)),
                   1336:                                  TREE_PURPOSE (TREE_VALUE (parms)),
                   1337:                                  TYPENAME, 0, NULL_TREE);
                   1338:            if (parms)
                   1339:              {
                   1340:                if (TREE_VALUE (parms) != void_type_node)
                   1341:                  error ("operator <typename> requires empty parameter list");
                   1342:                else
                   1343:                  /* Canonicalize parameter lists.  */
                   1344:                  TREE_OPERAND (tmp, 1) = void_list_node;
                   1345:              }
                   1346: 
                   1347:            last = grokdeclarator (TREE_OPERAND (decl, 0),
                   1348:                                   TREE_TYPE (decl),
                   1349:                                   TYPENAME, 0, NULL_TREE);
                   1350:            TREE_OPERAND (tmp, 0) = build_typename_overload (last);
                   1351:            TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
                   1352:            return tmp;
                   1353:          }
                   1354: 
                   1355:        case INDIRECT_REF:
                   1356:        case ADDR_EXPR:
                   1357:        case ARRAY_REF:
                   1358:          break;
                   1359: 
                   1360:        case SCOPE_REF:
                   1361:          /* This is legal when declaring a conversion to
                   1362:             something of type pointer-to-member.  */
                   1363:          if (TREE_CODE (TREE_OPERAND (tmp, 1)) == INDIRECT_REF)
                   1364:            {
                   1365:              tmp = TREE_OPERAND (tmp, 1);
                   1366:            }
                   1367:          else
                   1368:            {
                   1369: #if 0
                   1370:              /* We may need to do this if grokdeclarator cannot handle this.  */
                   1371:              error ("type `member of class %s' invalid return type",
                   1372:                     TYPE_NAME_STRING (TREE_OPERAND (tmp, 0)));
                   1373:              TREE_OPERAND (tmp, 1) = build_parse_node (INDIRECT_REF, TREE_OPERAND (tmp, 1));
                   1374: #endif
                   1375:              tmp = TREE_OPERAND (tmp, 1);
                   1376:            }
                   1377:          break;
                   1378: 
                   1379:        default:
1.1.1.5 ! root     1380:          my_friendly_abort (196);
1.1       root     1381:        }
                   1382:       last = tmp;
                   1383:       tmp = TREE_OPERAND (tmp, 0);
                   1384:     }
                   1385: 
                   1386:   if (call_required)
                   1387:     error ("operator <typename> construct requires parameter list");
                   1388: 
                   1389:   last = grokdeclarator (TREE_OPERAND (decl, 0),
                   1390:                         TREE_TYPE (decl),
                   1391:                         TYPENAME, 0, NULL_TREE);
                   1392:   tmp = build_parse_node (CALL_EXPR, build_typename_overload (last),
                   1393:                          void_list_node, NULL_TREE);
                   1394:   TREE_TYPE (TREE_OPERAND (tmp, 0)) = last;
                   1395:   return tmp;
                   1396: }
                   1397: 
1.1.1.2   root     1398: /* When a function is declared with an initializer,
1.1       root     1399:    do the right thing.  Currently, there are two possibilities:
                   1400: 
                   1401:    class B
                   1402:    {
                   1403:     public:
                   1404:      // initialization possibility #1.
                   1405:      virtual void f () = 0;
                   1406:      int g ();
                   1407:    };
                   1408:    
                   1409:    class D1 : B
                   1410:    {
                   1411:     public:
                   1412:      int d1;
                   1413:      // error, no f ();
                   1414:    };
                   1415:    
                   1416:    class D2 : B
                   1417:    {
                   1418:     public:
                   1419:      int d2;
                   1420:      void f ();
                   1421:    };
                   1422:    
                   1423:    class D3 : B
                   1424:    {
                   1425:     public:
                   1426:      int d3;
                   1427:      // initialization possibility #2
                   1428:      void f () = B::f;
                   1429:    };
                   1430: 
                   1431: */
                   1432: 
                   1433: static void
                   1434: grok_function_init (decl, init)
                   1435:      tree decl;
                   1436:      tree init;
                   1437: {
                   1438:   /* An initializer for a function tells how this function should
                   1439:      be inherited.  */
                   1440:   tree type = TREE_TYPE (decl);
                   1441:   extern tree abort_fndecl;
                   1442: 
                   1443:   if (TREE_CODE (type) == FUNCTION_TYPE)
                   1444:     error_with_decl (decl, "initializer specified for non-member function `%s'");
                   1445:   else if (DECL_VINDEX (decl) == NULL_TREE)
                   1446:     error_with_decl (decl, "initializer specified for non-virtual method `%s'");
                   1447:   else if (integer_zerop (init))
                   1448:     {
                   1449:       /* Mark this function as being "defined".  */
                   1450:       DECL_INITIAL (decl) = error_mark_node;
1.1.1.5 ! root     1451:       /* pure virtual destructors must be defined. */
        !          1452:       if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)))
        !          1453:        {
        !          1454:          /* Give this node rtl from `abort'.  */
        !          1455:          DECL_RTL (decl) = DECL_RTL (abort_fndecl);
        !          1456:        }
1.1       root     1457:       DECL_ABSTRACT_VIRTUAL_P (decl) = 1;
                   1458:     }
                   1459:   else if (TREE_CODE (init) == OFFSET_REF
                   1460:           && TREE_OPERAND (init, 0) == NULL_TREE
                   1461:           && TREE_CODE (TREE_TYPE (init)) == METHOD_TYPE)
                   1462:     {
                   1463:       tree basetype = DECL_CLASS_CONTEXT (init);
                   1464:       tree basefn = TREE_OPERAND (init, 1);
                   1465:       if (TREE_CODE (basefn) != FUNCTION_DECL)
                   1466:        error_with_decl (decl, "non-method initializer invalid for method `%s'");
                   1467:       else if (! BINFO_OFFSET_ZEROP (TYPE_BINFO (DECL_CLASS_CONTEXT (basefn))))
                   1468:        sorry ("base member function from other than first base class");
                   1469:       else
                   1470:        {
                   1471:          tree binfo = get_binfo (basetype, TYPE_METHOD_BASETYPE (type), 1);
                   1472:          if (binfo == error_mark_node)
                   1473:            ;
                   1474:          else if (binfo == 0)
                   1475:            error_not_base_type (TYPE_METHOD_BASETYPE (TREE_TYPE (init)),
                   1476:                                 TYPE_METHOD_BASETYPE (type));
                   1477:          else
                   1478:            {
                   1479:              /* Mark this function as being defined,
                   1480:                 and give it new rtl.  */
                   1481:              DECL_INITIAL (decl) = error_mark_node;
                   1482:              DECL_RTL (decl) = DECL_RTL (basefn);
                   1483:            }
                   1484:        }
                   1485:     }
                   1486:   else
                   1487:     error_with_decl (decl, "invalid initializer for virtual method `%s'");
                   1488: }
                   1489: 
                   1490: /* When we get a declaration of the form
                   1491: 
                   1492:    type cname::fname ...
                   1493: 
                   1494:    the node for `cname::fname' gets built here in a special way.
                   1495:    Namely, we push into `cname's scope.  When this declaration is
                   1496:    processed, we pop back out.  */
                   1497: tree
                   1498: build_push_scope (cname, name)
                   1499:      tree cname;
                   1500:      tree name;
                   1501: {
                   1502:   extern int current_class_depth;
                   1503:   tree ctype, rval;
                   1504: 
                   1505:   if (cname == error_mark_node)
                   1506:     return error_mark_node;
                   1507: 
                   1508:   ctype = IDENTIFIER_TYPE_VALUE (cname);
                   1509: 
                   1510:   if (ctype == NULL_TREE || ! IS_AGGR_TYPE (ctype))
                   1511:     {
                   1512:       error ("`%s' not defined as aggregate type", IDENTIFIER_POINTER (cname));
                   1513:       return name;
                   1514:     }
                   1515: 
                   1516:   rval = build_parse_node (SCOPE_REF, cname, name);
                   1517: 
                   1518:   /* Don't need to push the scope here, but we do need to return
                   1519:      a SCOPE_REF for something like
                   1520: 
                   1521:      class foo { typedef int bar (foo::*foo_fn)(void); };  */
                   1522:   if (ctype == current_class_type)
                   1523:     return rval;
                   1524: 
                   1525:   pushclass (ctype, 3);
                   1526:   TREE_COMPLEXITY (rval) = current_class_depth;
                   1527:   return rval;
                   1528: }
1.1.1.4   root     1529: 
                   1530: void cplus_decl_attributes (decl, attributes)
                   1531:      tree decl, attributes;
                   1532: {
                   1533:   if (decl)
                   1534:     decl_attributes (decl, attributes);
                   1535: }
1.1       root     1536: 
                   1537: /* CONSTRUCTOR_NAME:
                   1538:    Return the name for the constructor (or destructor) for the specified
                   1539:    class.  Argument can be RECORD_TYPE, TYPE_DECL, or IDENTIFIER_NODE.  */
                   1540: tree
                   1541: constructor_name (thing)
                   1542:      tree thing;
                   1543: {
                   1544:   tree t;
                   1545:   if (TREE_CODE (thing) == UNINSTANTIATED_P_TYPE)
                   1546:     return DECL_NAME (UPT_TEMPLATE (thing));
                   1547:   if (TREE_CODE (thing) == RECORD_TYPE || TREE_CODE (thing) == UNION_TYPE)
                   1548:     thing = TYPE_NAME (thing);
                   1549:   if (TREE_CODE (thing) == TYPE_DECL
                   1550:       || (TREE_CODE (thing) == TEMPLATE_DECL
                   1551:          && DECL_TEMPLATE_IS_CLASS (thing)))
                   1552:     thing = DECL_NAME (thing);
1.1.1.4   root     1553:   my_friendly_assert (TREE_CODE (thing) == IDENTIFIER_NODE, 197);
1.1       root     1554:   t = IDENTIFIER_TEMPLATE (thing);
                   1555:   if (!t)
                   1556:     return thing;
                   1557:   t = TREE_PURPOSE (t);
                   1558:   return DECL_NAME (t);
                   1559: }
                   1560: 
                   1561: /* Cache the value of this class's main virtual function table pointer
                   1562:    in a register variable.  This will save one indirection if a
                   1563:    more than one virtual function call is made this function.  */
                   1564: void
                   1565: setup_vtbl_ptr ()
                   1566: {
1.1.1.4   root     1567:   extern rtx base_init_insns;
1.1       root     1568: 
                   1569:   if (base_init_insns == 0
                   1570:       && DECL_CONSTRUCTOR_P (current_function_decl))
                   1571:     emit_base_init (current_class_type, 0);
                   1572: 
1.1.1.4   root     1573: #if 0
                   1574:   /* This has something a little wrong with it.
                   1575: 
                   1576:      On a sun4, code like:
                   1577: 
                   1578:         be L6
                   1579:         ld [%i0],%o1
                   1580: 
                   1581:      is generated, when the below is used when -O4 is given.  The delay
                   1582:      slot it filled with an instruction that is safe, when this isn't
                   1583:      used, like in:
                   1584: 
                   1585:         be L6
                   1586:         sethi %hi(LC1),%o0
                   1587:         ld [%i0],%o1
                   1588: 
                   1589:      on code like:
                   1590: 
                   1591:         struct A {
                   1592:           virtual void print() { printf("xxx"); }
                   1593:           void f();
                   1594:         };
                   1595: 
                   1596:         void A::f() {
                   1597:           if (this) {
                   1598:             print();
                   1599:           } else {
                   1600:             printf("0");
                   1601:           }
                   1602:         }
                   1603: 
                   1604:      And that is why this is disabled for now. (mrs)
                   1605:   */
                   1606: 
1.1       root     1607:   if ((flag_this_is_variable & 1) == 0
                   1608:       && optimize
                   1609:       && current_class_type
                   1610:       && CLASSTYPE_VSIZE (current_class_type)
                   1611:       && ! DECL_STATIC_FUNCTION_P (current_function_decl))
                   1612:     {
                   1613:       tree vfield = build_vfield_ref (C_C_D, current_class_type);
                   1614:       current_vtable_decl = CLASSTYPE_VTBL_PTR (current_class_type);
                   1615:       DECL_RTL (current_vtable_decl) = 0;
                   1616:       DECL_INITIAL (current_vtable_decl) = error_mark_node;
                   1617:       /* Have to cast the initializer, since it may have come from a
                   1618:         more base class then we ascribe CURRENT_VTABLE_DECL to be.  */
                   1619:       finish_decl (current_vtable_decl, convert_force (TREE_TYPE (current_vtable_decl), vfield), 0, 0);
                   1620:       current_vtable_decl = build_indirect_ref (current_vtable_decl, 0);
                   1621:     }
                   1622:   else
1.1.1.4   root     1623: #endif
1.1       root     1624:     current_vtable_decl = NULL_TREE;
                   1625: }
                   1626: 
                   1627: /* Record the existence of an addressable inline function.  */
                   1628: void
                   1629: mark_inline_for_output (decl)
                   1630:      tree decl;
                   1631: {
                   1632:   if (DECL_PENDING_INLINE_INFO (decl) != 0
                   1633:       && ! DECL_PENDING_INLINE_INFO (decl)->deja_vu)
                   1634:     {
                   1635:       struct pending_inline *t = pending_inlines;
1.1.1.4   root     1636:       my_friendly_assert (DECL_SAVED_INSNS (decl) == 0, 198);
1.1       root     1637:       while (t)
                   1638:        {
                   1639:          if (t == DECL_PENDING_INLINE_INFO (decl))
                   1640:            break;
                   1641:          t = t->next;
                   1642:        }
                   1643:       if (t == 0)
                   1644:        {
                   1645:          t = DECL_PENDING_INLINE_INFO (decl);
                   1646:          t->next = pending_inlines;
                   1647:          pending_inlines = t;
                   1648:        }
                   1649:       DECL_PENDING_INLINE_INFO (decl) = 0;
                   1650:     }
                   1651:   pending_addressable_inlines = perm_tree_cons (NULL_TREE, decl,
                   1652:                                                pending_addressable_inlines);
                   1653: }
                   1654: 
                   1655: void
                   1656: clear_temp_name ()
                   1657: {
                   1658:   temp_name_counter = 0;
                   1659: }
                   1660: 
                   1661: /* Hand off a unique name which can be used for variable we don't really
                   1662:    want to know about anyway, for example, the anonymous variables which
                   1663:    are needed to make references work.  Declare this thing so we can use it.
                   1664:    The variable created will be of type TYPE.
                   1665: 
                   1666:    STATICP is nonzero if this variable should be static.  */
                   1667: 
                   1668: tree
                   1669: get_temp_name (type, staticp)
                   1670:      tree type;
                   1671:      int staticp;
                   1672: {
                   1673:   char buf[sizeof (AUTO_TEMP_FORMAT) + 20];
                   1674:   tree decl;
                   1675:   int toplev = global_bindings_p ();
                   1676: 
                   1677:   push_obstacks_nochange ();
                   1678:   if (toplev || staticp)
                   1679:     {
                   1680:       end_temporary_allocation ();
                   1681:       sprintf (buf, AUTO_TEMP_FORMAT, global_temp_name_counter++);
                   1682:       decl = pushdecl_top_level (build_decl (VAR_DECL, get_identifier (buf), type));
                   1683:     }
                   1684:   else
                   1685:     {
                   1686:       sprintf (buf, AUTO_TEMP_FORMAT, temp_name_counter++);
                   1687:       decl = pushdecl (build_decl (VAR_DECL, get_identifier (buf), type));
                   1688:     }
                   1689:   TREE_USED (decl) = 1;
                   1690:   TREE_STATIC (decl) = staticp;
                   1691: 
                   1692:   /* If this is a local variable, then lay out its rtl now.
                   1693:      Otherwise, callers of this function are responsible for dealing
                   1694:      with this variable's rtl.  */
                   1695:   if (! toplev)
                   1696:     {
                   1697:       expand_decl (decl);
                   1698:       expand_decl_init (decl);
                   1699:     }
                   1700:   pop_obstacks ();
                   1701: 
                   1702:   return decl;
                   1703: }
                   1704: 
                   1705: /* Get a variable which we can use for multiple assignments.
                   1706:    It is not entered into current_binding_level, because
                   1707:    that breaks things when it comes time to do final cleanups
                   1708:    (which take place "outside" the binding contour of the function).  */
                   1709: tree
                   1710: get_temp_regvar (type, init)
                   1711:      tree type, init;
                   1712: {
                   1713:   static char buf[sizeof (AUTO_TEMP_FORMAT) + 20] = { '_' };
                   1714:   tree decl;
                   1715: 
                   1716:   sprintf (buf+1, AUTO_TEMP_FORMAT, temp_name_counter++);
                   1717:   decl = build_decl (VAR_DECL, get_identifier (buf), type);
                   1718:   TREE_USED (decl) = 1;
1.1.1.4   root     1719:   DECL_REGISTER (decl) = 1;
1.1       root     1720: 
                   1721:   if (init)
                   1722:     store_init_value (decl, init);
                   1723: 
                   1724:   /* We can expand these without fear, since they cannot need
                   1725:      constructors or destructors.  */
                   1726:   expand_decl (decl);
                   1727:   expand_decl_init (decl);
                   1728: 
                   1729:   if (type_needs_gc_entry (type))
                   1730:     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
                   1731: 
                   1732:   return decl;
                   1733: }
                   1734: 
                   1735: /* Make the macro TEMP_NAME_P available to units which do not
                   1736:    include c-tree.h.  */
                   1737: int
                   1738: temp_name_p (decl)
                   1739:      tree decl;
                   1740: {
                   1741:   return TEMP_NAME_P (decl);
                   1742: }
                   1743: 
                   1744: /* Finish off the processing of a UNION_TYPE structure.
                   1745:    If there are static members, then all members are
                   1746:    static, and must be laid out together.  If the
1.1.1.2   root     1747:    union is an anonymous union, we arrange for that
1.1.1.4   root     1748:    as well.  PUBLIC_P is nonzero if this union is
1.1       root     1749:    not declared static.  */
                   1750: void
                   1751: finish_anon_union (anon_union_decl)
                   1752:      tree anon_union_decl;
                   1753: {
                   1754:   tree type = TREE_TYPE (anon_union_decl);
1.1.1.2   root     1755:   tree field, main_decl = NULL_TREE;
1.1       root     1756:   tree elems = NULL_TREE;
                   1757:   int public_p = TREE_PUBLIC (anon_union_decl);
                   1758:   int static_p = TREE_STATIC (anon_union_decl);
1.1.1.4   root     1759:   int external_p = DECL_EXTERNAL (anon_union_decl);
1.1       root     1760: 
                   1761:   if ((field = TYPE_FIELDS (type)) == NULL_TREE)
                   1762:     return;
                   1763: 
                   1764:   if (public_p && (static_p || external_p))
                   1765:     error ("optimizer cannot handle global anonymous unions");
                   1766: 
                   1767:   while (field)
                   1768:     {
1.1.1.2   root     1769:       tree decl = build_decl (VAR_DECL, DECL_NAME (field), TREE_TYPE (field));
1.1       root     1770:       /* tell `pushdecl' that this is not tentative.  */
                   1771:       DECL_INITIAL (decl) = error_mark_node;
                   1772:       TREE_PUBLIC (decl) = public_p;
                   1773:       TREE_STATIC (decl) = static_p;
1.1.1.4   root     1774:       DECL_EXTERNAL (decl) = external_p;
1.1       root     1775:       decl = pushdecl (decl);
1.1.1.2   root     1776: 
                   1777:       /* Only write out one anon union element--choose the one that
                   1778:         can hold them all.  */
                   1779:       if (main_decl == NULL_TREE
                   1780:          && DECL_SIZE (decl) == DECL_SIZE (anon_union_decl))
                   1781:        {
                   1782:          main_decl = decl;
                   1783:        }
                   1784:       else
                   1785:        {
                   1786:          /* ??? This causes there to be no debug info written out
                   1787:             about this decl.  */
                   1788:          TREE_ASM_WRITTEN (decl) = 1;
                   1789:        }
                   1790: 
1.1       root     1791:       DECL_INITIAL (decl) = NULL_TREE;
                   1792:       /* If there's a cleanup to do, it belongs in the
                   1793:         TREE_PURPOSE of the following TREE_LIST.  */
                   1794:       elems = tree_cons (NULL_TREE, decl, elems);
                   1795:       TREE_TYPE (elems) = type;
                   1796:       field = TREE_CHAIN (field);
                   1797:     }
                   1798:   if (static_p)
1.1.1.2   root     1799:     {
                   1800:       make_decl_rtl (main_decl, 0, global_bindings_p ());
                   1801:       DECL_RTL (anon_union_decl) = DECL_RTL (main_decl);
                   1802:     }
1.1       root     1803: 
                   1804:   /* The following call assumes that there are never any cleanups
                   1805:      for anonymous unions--a reasonable assumption.  */
                   1806:   expand_anon_union_decl (anon_union_decl, NULL_TREE, elems);
                   1807: 
                   1808:   if (flag_cadillac)
1.1.1.2   root     1809:     cadillac_finish_anon_union (anon_union_decl);
1.1       root     1810: }
                   1811: 
                   1812: /* Finish and output a table which is generated by the compiler.
                   1813:    NAME is the name to give the table.
                   1814:    TYPE is the type of the table entry.
                   1815:    INIT is all the elements in the table.
                   1816:    PUBLICP is non-zero if this table should be given external visibility.  */
                   1817: tree
                   1818: finish_table (name, type, init, publicp)
                   1819:      tree name, type, init;
1.1.1.4   root     1820:      int publicp;
1.1       root     1821: {
                   1822:   tree itype, atype, decl;
                   1823:   static tree empty_table;
                   1824:   int is_empty = 0;
                   1825:   tree asmspec;
                   1826: 
                   1827:   itype = build_index_type (size_int (list_length (init) - 1));
                   1828:   atype = build_cplus_array_type (type, itype);
                   1829:   layout_type (atype);
                   1830: 
                   1831:   if (TREE_VALUE (init) == integer_zero_node
                   1832:       && TREE_CHAIN (init) == NULL_TREE)
                   1833:     {
                   1834:       if (empty_table == NULL_TREE)
                   1835:        {
                   1836:          empty_table = get_temp_name (atype, 1);
                   1837:          init = build (CONSTRUCTOR, atype, NULL_TREE, init);
                   1838:          TREE_CONSTANT (init) = 1;
                   1839:          TREE_STATIC (init) = 1;
                   1840:          DECL_INITIAL (empty_table) = init;
                   1841:          asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
                   1842:                                  IDENTIFIER_POINTER (DECL_NAME (empty_table)));
                   1843:          finish_decl (empty_table, init, asmspec, 0);
                   1844:        }
                   1845:       is_empty = 1;
                   1846:     }
                   1847: 
                   1848:   if (name == NULL_TREE)
                   1849:     {
                   1850:       if (is_empty)
                   1851:        return empty_table;
                   1852:       decl = get_temp_name (atype, 1);
                   1853:     }
                   1854:   else
                   1855:     {
                   1856:       decl = build_decl (VAR_DECL, name, atype);
                   1857:       decl = pushdecl (decl);
                   1858:       TREE_STATIC (decl) = 1;
                   1859:     }
                   1860: 
                   1861:   if (is_empty == 0)
                   1862:     {
                   1863:       TREE_PUBLIC (decl) = publicp;
                   1864:       init = build (CONSTRUCTOR, atype, NULL_TREE, init);
                   1865:       TREE_CONSTANT (init) = 1;
                   1866:       TREE_STATIC (init) = 1;
                   1867:       DECL_INITIAL (decl) = init;
                   1868:       asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (decl)),
                   1869:                              IDENTIFIER_POINTER (DECL_NAME (decl)));
                   1870:     }
                   1871:   else
                   1872:     {
                   1873:       /* This will cause DECL to point to EMPTY_TABLE in rtl-land.  */
1.1.1.4   root     1874:       DECL_EXTERNAL (decl) = 1;
1.1       root     1875:       TREE_STATIC (decl) = 0;
                   1876:       init = 0;
                   1877:       asmspec = build_string (IDENTIFIER_LENGTH (DECL_NAME (empty_table)),
                   1878:                              IDENTIFIER_POINTER (DECL_NAME (empty_table)));
                   1879:     }
                   1880: 
                   1881:   finish_decl (decl, init, asmspec, 0);
                   1882:   return decl;
                   1883: }
                   1884: 
                   1885: /* Finish processing a builtin type TYPE.  It's name is NAME,
                   1886:    its fields are in the array FIELDS.  LEN is the number of elements
                   1887:    in FIELDS.
                   1888: 
                   1889:    It is given the same alignment as ALIGN_TYPE.  */
                   1890: void
                   1891: finish_builtin_type (type, name, fields, len, align_type)
                   1892:      tree type;
                   1893:      char *name;
                   1894:      tree fields[];
1.1.1.4   root     1895:      int len;
1.1       root     1896:      tree align_type;
                   1897: {
                   1898:   register int i;
                   1899: 
                   1900:   TYPE_FIELDS (type) = fields[0];
                   1901:   for (i = 0; i < len; i++)
                   1902:     {
                   1903:       layout_type (TREE_TYPE (fields[i]));
                   1904:       DECL_FIELD_CONTEXT (fields[i]) = type;
                   1905:       TREE_CHAIN (fields[i]) = fields[i+1];
                   1906:     }
                   1907:   DECL_FIELD_CONTEXT (fields[i]) = type;
                   1908:   DECL_CLASS_CONTEXT (fields[i]) = type;
                   1909:   TYPE_ALIGN (type) = TYPE_ALIGN (align_type);
                   1910:   layout_type (type);
1.1.1.2   root     1911: #if 0 /* not yet, should get fixed properly later */
                   1912:   TYPE_NAME (type) = make_type_decl (get_identifier (name), type);
                   1913: #else
1.1       root     1914:   TYPE_NAME (type) = build_decl (TYPE_DECL, get_identifier (name), type);
1.1.1.2   root     1915: #endif
1.1       root     1916:   layout_decl (TYPE_NAME (type), 0);
                   1917: }
                   1918: 
1.1.1.2   root     1919: /* Auxiliary functions to make type signatures for
1.1       root     1920:    `operator new' and `operator delete' correspond to
                   1921:    what compiler will be expecting.  */
                   1922: 
                   1923: extern tree sizetype;
                   1924: 
                   1925: tree
1.1.1.5 ! root     1926: coerce_new_type (type)
1.1       root     1927:      tree type;
                   1928: {
                   1929:   int e1 = 0, e2 = 0;
                   1930: 
                   1931:   if (TREE_CODE (type) == METHOD_TYPE)
                   1932:     type = build_function_type (TREE_TYPE (type), TREE_CHAIN (TYPE_ARG_TYPES (type)));
                   1933:   if (TREE_TYPE (type) != ptr_type_node)
                   1934:     e1 = 1, error ("`operator new' must return type `void *'");
                   1935: 
                   1936:   /* Technically the type must be `size_t', but we may not know
                   1937:      what that is.  */
                   1938:   if (TYPE_ARG_TYPES (type) == NULL_TREE)
                   1939:     e1 = 1, error ("`operator new' takes type `size_t' parameter");
                   1940:   else if (TREE_CODE (TREE_VALUE (TYPE_ARG_TYPES (type))) != INTEGER_TYPE
                   1941:           || TYPE_PRECISION (TREE_VALUE (TYPE_ARG_TYPES (type))) != TYPE_PRECISION (sizetype))
                   1942:     e2 = 1, error ("`operator new' takes type `size_t' as first parameter");
                   1943:   if (e2)
                   1944:     type = build_function_type (ptr_type_node, tree_cons (NULL_TREE, sizetype, TREE_CHAIN (TYPE_ARG_TYPES (type))));
                   1945:   else if (e1)
                   1946:     type = build_function_type (ptr_type_node, TYPE_ARG_TYPES (type));
                   1947:   return type;
                   1948: }
                   1949: 
                   1950: tree
1.1.1.5 ! root     1951: coerce_delete_type (type)
1.1       root     1952:      tree type;
                   1953: {
                   1954:   int e1 = 0, e2 = 0, e3 = 0;
                   1955:   tree arg_types = TYPE_ARG_TYPES (type);
                   1956: 
                   1957:   if (TREE_CODE (type) == METHOD_TYPE)
                   1958:     {
                   1959:       type = build_function_type (TREE_TYPE (type), TREE_CHAIN (arg_types));
                   1960:       arg_types = TREE_CHAIN (arg_types);
                   1961:     }
                   1962:   if (TREE_TYPE (type) != void_type_node)
                   1963:     e1 = 1, error ("`operator delete' must return type `void'");
                   1964:   if (arg_types == NULL_TREE
                   1965:       || TREE_VALUE (arg_types) != ptr_type_node)
                   1966:     e2 = 1, error ("`operator delete' takes type `void *' as first parameter");
                   1967: 
                   1968:   if (arg_types
                   1969:       && TREE_CHAIN (arg_types)
                   1970:       && TREE_CHAIN (arg_types) != void_list_node)
                   1971:     {
                   1972:       /* Again, technically this argument must be `size_t', but again
                   1973:         we may not know what that is.  */
                   1974:       tree t2 = TREE_VALUE (TREE_CHAIN (arg_types));
                   1975:       if (TREE_CODE (t2) != INTEGER_TYPE
                   1976:          || TYPE_PRECISION (t2) != TYPE_PRECISION (sizetype))
                   1977:        e3 = 1, error ("second argument to `operator delete' must be of type `size_t'");
                   1978:       else if (TREE_CHAIN (TREE_CHAIN (arg_types)) != void_list_node)
                   1979:        {
                   1980:          e3 = 1;
                   1981:          if (TREE_CHAIN (TREE_CHAIN (arg_types)))
                   1982:            error ("too many arguments in declaration of `operator delete'");
                   1983:          else
                   1984:            error ("`...' invalid in specification of `operator delete'");
                   1985:        }
                   1986:     }
                   1987:   if (e3)
                   1988:     arg_types = tree_cons (NULL_TREE, ptr_type_node, build_tree_list (NULL_TREE, sizetype));
                   1989:   else if (e3 |= e2)
                   1990:     {
                   1991:       if (arg_types == NULL_TREE)
                   1992:        arg_types = void_list_node;
                   1993:       else
                   1994:        arg_types = tree_cons (NULL_TREE, ptr_type_node, TREE_CHAIN (arg_types));
                   1995:     }
                   1996:   else e3 |= e1;
                   1997: 
                   1998:   if (e3)
                   1999:     type = build_function_type (void_type_node, arg_types);
                   2000: 
                   2001:   return type;
                   2002: }
                   2003: 
                   2004: static void
                   2005: write_vtable_entries (decl)
                   2006:      tree decl;
                   2007: {
                   2008:   tree entries = TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)));
                   2009: 
                   2010:   if (flag_dossier)
                   2011:     entries = TREE_CHAIN (entries);
                   2012: 
                   2013:   for (; entries; entries = TREE_CHAIN (entries))
                   2014:     {
                   2015:       tree fnaddr = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (entries));
                   2016:       tree fn = TREE_OPERAND (fnaddr, 0);
1.1.1.4   root     2017:       if (! DECL_EXTERNAL (fn) && ! TREE_ASM_WRITTEN (fn)
1.1.1.3   root     2018:          && DECL_SAVED_INSNS (fn))
1.1       root     2019:        {
                   2020:          if (TREE_PUBLIC (DECL_CLASS_CONTEXT (fn)))
                   2021:            TREE_PUBLIC (fn) = 1;
                   2022:          TREE_ADDRESSABLE (fn) = 1;
                   2023:          output_inline_function (fn);
                   2024:        }
                   2025:       else
                   2026:        assemble_external (fn);
                   2027:     }
                   2028: }
                   2029: 
1.1.1.5 ! root     2030: /* Note even though prev is never used in here, walk_vtables
        !          2031:    expects this to have two arguments, so concede.  */
1.1       root     2032: static void
                   2033: finish_vtable_typedecl (prev, vars)
                   2034:      tree prev, vars;
                   2035: {
                   2036:   tree decl = TYPE_BINFO_VTABLE (TREE_TYPE (vars));
                   2037: 
                   2038:   /* If we are controlled by `+e2', obey.  */
                   2039:   if (write_virtuals == 2)
                   2040:     {
                   2041:       tree binfo = value_member (DECL_NAME (vars), pending_vtables);
                   2042:       if (binfo)
                   2043:        TREE_PURPOSE (binfo) = void_type_node;
                   2044:       else
                   2045:        decl = NULL_TREE;
                   2046:     }
                   2047:   /* If this type has inline virtual functions, then
                   2048:      write those functions out now.  */
                   2049:   if (decl && write_virtuals >= 0
1.1.1.4   root     2050:       && ! DECL_EXTERNAL (decl) && (TREE_PUBLIC (decl) || TREE_USED (decl)))
1.1       root     2051:     write_vtable_entries (decl);
                   2052: }
                   2053: 
                   2054: static void
                   2055: finish_vtable_vardecl (prev, vars)
                   2056:      tree prev, vars;
                   2057: {
1.1.1.3   root     2058:   if (write_virtuals >= 0
1.1.1.4   root     2059:       && ! DECL_EXTERNAL (vars) && (TREE_PUBLIC (vars) || TREE_USED (vars)))
1.1       root     2060:     {
                   2061:       extern tree the_null_vtable_entry;
                   2062: 
                   2063:       /* Stuff this virtual function table's size into
                   2064:         `pfn' slot of `the_null_vtable_entry'.  */
                   2065:       tree nelts = array_type_nelts (TREE_TYPE (vars));
                   2066:       SET_FNADDR_FROM_VTABLE_ENTRY (the_null_vtable_entry, nelts);
                   2067:       /* Kick out the dossier before writing out the vtable.  */
                   2068:       if (flag_dossier)
                   2069:        rest_of_decl_compilation (TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (CONSTRUCTOR_ELTS (DECL_INITIAL (vars))))), 0), 0, 1, 1);
                   2070: 
                   2071:       /* Write it out.  */
                   2072:       write_vtable_entries (vars);
                   2073:       if (TREE_TYPE (DECL_INITIAL (vars)) == 0)
                   2074:        store_init_value (vars, DECL_INITIAL (vars));
                   2075:       rest_of_decl_compilation (vars, 0, 1, 1);
                   2076:     }
                   2077:   /* We know that PREV must be non-zero here.  */
                   2078:   TREE_CHAIN (prev) = TREE_CHAIN (vars);
                   2079: }
                   2080: 
                   2081: void
                   2082: walk_vtables (typedecl_fn, vardecl_fn)
                   2083:      register void (*typedecl_fn)();
                   2084:      register void (*vardecl_fn)();
                   2085: {
                   2086:   tree prev, vars;
                   2087: 
                   2088:   for (prev = 0, vars = getdecls (); vars; vars = TREE_CHAIN (vars))
                   2089:     {
                   2090:       if (TREE_CODE (vars) == TYPE_DECL
                   2091:          && TYPE_LANG_SPECIFIC (TREE_TYPE (vars))
                   2092:          && CLASSTYPE_VSIZE (TREE_TYPE (vars)))
                   2093:        {
                   2094:          if (typedecl_fn) (*typedecl_fn) (prev, vars);
                   2095:        }
                   2096:       else if (TREE_CODE (vars) == VAR_DECL && DECL_VIRTUAL_P (vars))
                   2097:        {
                   2098:          if (vardecl_fn) (*vardecl_fn) (prev, vars);
                   2099:        }
                   2100:       else
                   2101:        prev = vars;
                   2102:     }
                   2103: }
                   2104: 
                   2105: extern int parse_time, varconst_time;
                   2106: 
                   2107: #define TIMEVAR(VAR, BODY)    \
                   2108: do { int otime = get_run_time (); BODY; VAR += get_run_time () - otime; } while (0)
                   2109: 
                   2110: /* This routine is called from the last rule in yyparse ().
                   2111:    Its job is to create all the code needed to initialize and
                   2112:    destroy the global aggregates.  We do the destruction
                   2113:    first, since that way we only need to reverse the decls once.  */
                   2114: 
                   2115: void
                   2116: finish_file ()
                   2117: {
                   2118:   extern int lineno;
                   2119:   int start_time, this_time;
                   2120: 
                   2121:   char *buf;
                   2122:   char *p;
                   2123:   tree fnname;
                   2124:   tree vars = static_aggregates;
                   2125:   int needs_cleaning = 0, needs_messing_up = 0;
                   2126: 
                   2127:   if (main_input_filename == 0)
                   2128:     main_input_filename = input_filename;
                   2129:   if (!first_global_object_name)
                   2130:     first_global_object_name = main_input_filename;
                   2131: 
                   2132:   buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT)
                   2133:                         + strlen (first_global_object_name));
                   2134: 
                   2135:   if (flag_detailed_statistics)
                   2136:     dump_tree_statistics ();
                   2137: 
                   2138:   /* Bad parse errors.  Just forget about it.  */
1.1.1.2   root     2139:   if (! global_bindings_p () || current_class_type)
1.1       root     2140:     return;
                   2141: 
                   2142:   start_time = get_run_time ();
                   2143: 
                   2144:   /* Push into C language context, because that's all
                   2145:      we'll need here.  */
                   2146:   push_lang_context (lang_name_c);
                   2147: 
                   2148:   /* Set up the name of the file-level functions we may need.  */
                   2149:   /* Use a global object (which is already required to be unique over
                   2150:      the program) rather than the file name (which imposes extra
                   2151:      constraints).  -- [email protected], 10 Jan 1990.  */
                   2152:   sprintf (buf, FILE_FUNCTION_FORMAT, first_global_object_name);
                   2153: 
                   2154:   /* Don't need to pull wierd characters out of global names.  */
                   2155:   if (first_global_object_name == main_input_filename)
                   2156:     {
                   2157:       for (p = buf+11; *p; p++)
                   2158:        if (! ((*p >= '0' && *p <= '9')
                   2159: #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
                   2160: #ifndef ASM_IDENTIFY_GCC       /* this is required if `.' is invalid -- k. raeburn */
                   2161:               || *p == '.'
                   2162: #endif
                   2163: #endif
                   2164: #ifndef NO_DOLLAR_IN_LABEL     /* this for `$'; unlikely, but... -- kr */
                   2165:               || *p == '$'
                   2166: #endif
1.1.1.5 ! root     2167: #ifndef NO_DOT_IN_LABEL                /* this for `.'; unlikely, but... */
        !          2168:               || *p == '.'
        !          2169: #endif
1.1       root     2170:               || (*p >= 'A' && *p <= 'Z')
                   2171:               || (*p >= 'a' && *p <= 'z')))
                   2172:          *p = '_';
                   2173:     }
                   2174: 
                   2175:   /* See if we really need the hassle.  */
                   2176:   while (vars && needs_cleaning == 0)
                   2177:     {
                   2178:       tree decl = TREE_VALUE (vars);
                   2179:       tree type = TREE_TYPE (decl);
                   2180:       if (TYPE_NEEDS_DESTRUCTOR (type))
                   2181:        {
                   2182:          needs_cleaning = 1;
                   2183:          needs_messing_up = 1;
                   2184:          break;
                   2185:        }
                   2186:       else
                   2187:        needs_messing_up |= TYPE_NEEDS_CONSTRUCTING (type);
                   2188:       vars = TREE_CHAIN (vars);
                   2189:     }
                   2190:   if (needs_cleaning == 0)
                   2191:     goto mess_up;
                   2192: 
                   2193:   /* Otherwise, GDB can get confused, because in only knows
                   2194:      about source for LINENO-1 lines.  */
                   2195:   lineno -= 1;
                   2196: 
                   2197:   fnname = get_identifier (buf);
                   2198:   start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
                   2199:   fnname = DECL_ASSEMBLER_NAME (current_function_decl);
                   2200:   store_parm_decls ();
                   2201: 
                   2202:   pushlevel (0);
                   2203:   clear_last_expr ();
                   2204:   push_momentary ();
                   2205:   expand_start_bindings (0);
                   2206: 
                   2207:   /* These must be done in backward order to destroy,
                   2208:      in which they happen to be!  */
                   2209:   while (vars)
                   2210:     {
                   2211:       tree decl = TREE_VALUE (vars);
                   2212:       tree type = TREE_TYPE (decl);
                   2213:       tree temp = TREE_PURPOSE (vars);
                   2214: 
                   2215:       if (TYPE_NEEDS_DESTRUCTOR (type))
                   2216:        {
                   2217:          if (TREE_STATIC (vars))
1.1.1.5 ! root     2218:            expand_start_cond (build_binary_op (NE_EXPR, temp, integer_zero_node, 1), 0);
1.1       root     2219:          if (TREE_CODE (type) == ARRAY_TYPE)
                   2220:            temp = decl;
                   2221:          else
                   2222:            {
                   2223:              mark_addressable (decl);
                   2224:              temp = build1 (ADDR_EXPR, TYPE_POINTER_TO (type), decl);
                   2225:            }
                   2226:          temp = build_delete (TREE_TYPE (temp), temp,
                   2227:                               integer_two_node, LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0, 0);
                   2228:          expand_expr_stmt (temp);
                   2229: 
                   2230:          if (TREE_STATIC (vars))
                   2231:            expand_end_cond ();
                   2232:        }
                   2233:       vars = TREE_CHAIN (vars);
                   2234:     }
                   2235: 
                   2236:   expand_end_bindings (getdecls (), 1, 0);
1.1.1.4   root     2237:   poplevel (1, 0, 0);
1.1       root     2238:   pop_momentary ();
                   2239: 
                   2240:   finish_function (lineno, 0);
                   2241: 
                   2242:   assemble_destructor (IDENTIFIER_POINTER (fnname));
                   2243: 
                   2244:   /* if it needed cleaning, then it will need messing up: drop through  */
                   2245: 
                   2246:  mess_up:
                   2247:   /* Must do this while we think we are at the top level.  */
                   2248:   vars = nreverse (static_aggregates);
                   2249:   if (vars != NULL_TREE)
                   2250:     {
                   2251:       buf[FILE_FUNCTION_PREFIX_LEN] = 'I';
                   2252: 
                   2253:       fnname = get_identifier (buf);
                   2254:       start_function (void_list_node, build_parse_node (CALL_EXPR, fnname, void_list_node, NULL_TREE), 0, 0);
                   2255:       fnname = DECL_ASSEMBLER_NAME (current_function_decl);
                   2256:       store_parm_decls ();
                   2257: 
                   2258:       pushlevel (0);
                   2259:       clear_last_expr ();
                   2260:       push_momentary ();
                   2261:       expand_start_bindings (0);
                   2262: 
                   2263:       while (vars)
                   2264:        {
                   2265:          tree decl = TREE_VALUE (vars);
                   2266:          tree init = TREE_PURPOSE (vars);
                   2267: 
                   2268:          /* If this was a static attribute within some function's scope,
                   2269:             then don't initialize it here.  Also, don't bother
                   2270:             with initializers that contain errors.  */
                   2271:          if (TREE_STATIC (vars)
                   2272:              || (init && TREE_CODE (init) == TREE_LIST
                   2273:                  && value_member (error_mark_node, init)))
                   2274:            {
                   2275:              vars = TREE_CHAIN (vars);
                   2276:              continue;
                   2277:            }
                   2278: 
                   2279:          if (TREE_CODE (decl) == VAR_DECL)
                   2280:            {
                   2281:              /* Set these global variables so that GDB at least puts
                   2282:                 us near the declaration which required the initialization.  */
                   2283:              input_filename = DECL_SOURCE_FILE (decl);
                   2284:              lineno = DECL_SOURCE_LINE (decl);
                   2285:              emit_note (input_filename, lineno);
                   2286: 
                   2287:              if (init)
                   2288:                {
                   2289:                  if (TREE_CODE (init) == VAR_DECL)
                   2290:                    {
                   2291:                      /* This behavior results when there are
                   2292:                         multiple declarations of an aggregate,
                   2293:                         the last of which defines it.  */
                   2294:                      if (DECL_RTL (init) == DECL_RTL (decl))
                   2295:                        {
1.1.1.4   root     2296:                          my_friendly_assert (DECL_INITIAL (decl) == error_mark_node
1.1       root     2297:                                  || (TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
1.1.1.4   root     2298:                                      && CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) == NULL_TREE),
                   2299:                                              199);
1.1       root     2300:                          init = DECL_INITIAL (init);
                   2301:                          if (TREE_CODE (init) == CONSTRUCTOR
                   2302:                              && CONSTRUCTOR_ELTS (init) == NULL_TREE)
                   2303:                            init = NULL_TREE;
                   2304:                        }
                   2305: #if 0
                   2306:                      else if (TREE_TYPE (decl) == TREE_TYPE (init))
                   2307:                        {
                   2308: #if 1
1.1.1.5 ! root     2309:                          my_friendly_abort (200);
1.1       root     2310: #else
                   2311:                          /* point to real decl's rtl anyway.  */
                   2312:                          DECL_RTL (init) = DECL_RTL (decl);
1.1.1.4   root     2313:                          my_friendly_assert (DECL_INITIAL (decl) == error_mark_node,
                   2314:                                              201);
1.1       root     2315:                          init = DECL_INITIAL (init);
                   2316: #endif                         /* 1 */
                   2317:                        }
                   2318: #endif                         /* 0 */
                   2319:                    }
                   2320:                }
                   2321:              if (IS_AGGR_TYPE (TREE_TYPE (decl))
                   2322:                  || init == 0
                   2323:                  || TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1.1.1.4   root     2324:                {
                   2325:                  /* Set this up so is_friend() works properly on _GLOBAL_ fns.  */
                   2326:                  tree old_dcc = DECL_CLASS_CONTEXT (current_function_decl);
                   2327:                  if (old_dcc == NULL_TREE)
                   2328:                    DECL_CLASS_CONTEXT (current_function_decl) = TREE_TYPE (decl);
                   2329:                  expand_aggr_init (decl, init, 0);
                   2330:                  DECL_CLASS_CONTEXT (current_function_decl) = old_dcc;
                   2331:                }
1.1       root     2332:              else if (TREE_CODE (init) == TREE_VEC)
                   2333:                {
                   2334:                  expand_expr (expand_vec_init (decl, TREE_VEC_ELT (init, 0),
                   2335:                                                TREE_VEC_ELT (init, 1),
                   2336:                                                TREE_VEC_ELT (init, 2), 0),
                   2337:                               const0_rtx, VOIDmode, 0);
                   2338:                  free_temp_slots ();
                   2339:                }
                   2340:              else
                   2341:                expand_assignment (decl, init, 0, 0);
                   2342:            }
                   2343:          else if (TREE_CODE (decl) == SAVE_EXPR)
                   2344:            {
                   2345:              if (! PARM_DECL_EXPR (decl))
                   2346:                {
                   2347:                  /* a `new' expression at top level.  */
                   2348:                  expand_expr (decl, const0_rtx, VOIDmode, 0);
                   2349:                  free_temp_slots ();
                   2350:                  expand_aggr_init (build_indirect_ref (decl, 0), init, 0);
                   2351:                }
                   2352:            }
                   2353:          else if (decl == error_mark_node)
                   2354:            ;
1.1.1.3   root     2355:          else my_friendly_abort (22);
1.1       root     2356:          vars = TREE_CHAIN (vars);
                   2357:        }
                   2358: 
                   2359:       expand_end_bindings (getdecls (), 1, 0);
1.1.1.4   root     2360:       poplevel (1, 0, 0);
1.1       root     2361:       pop_momentary ();
                   2362: 
                   2363:       finish_function (lineno, 0);
                   2364:       assemble_constructor (IDENTIFIER_POINTER (fnname));
                   2365:     }
                   2366: 
                   2367:   /* Done with C language context needs.  */
                   2368:   pop_lang_context ();
                   2369: 
                   2370:   /* Now write out any static class variables (which may have since
                   2371:      learned how to be initialized).  */
                   2372:   while (pending_statics)
                   2373:     {
                   2374:       tree decl = TREE_VALUE (pending_statics);
                   2375:       if (TREE_USED (decl) == 1
                   2376:          || TREE_READONLY (decl) == 0
                   2377:          || DECL_INITIAL (decl) == 0)
                   2378:        rest_of_decl_compilation (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), 1, 1);
                   2379:       pending_statics = TREE_CHAIN (pending_statics);
                   2380:     }
                   2381: 
                   2382:   this_time = get_run_time ();
                   2383:   parse_time -= this_time - start_time;
                   2384:   varconst_time += this_time - start_time;
                   2385: 
                   2386:   /* Now write out inline functions which had their addresses taken
                   2387:      and which were not declared virtual and which were not declared
                   2388:      `extern inline'.  */
                   2389:   while (pending_addressable_inlines)
                   2390:     {
                   2391:       tree decl = TREE_VALUE (pending_addressable_inlines);
                   2392:       if (! TREE_ASM_WRITTEN (decl)
1.1.1.4   root     2393:          && ! DECL_EXTERNAL (decl)
1.1       root     2394:          && DECL_SAVED_INSNS (decl))
                   2395:        output_inline_function (decl);
                   2396:       pending_addressable_inlines = TREE_CHAIN (pending_addressable_inlines);
                   2397:     }
                   2398: 
                   2399:   start_time = get_run_time ();
                   2400: 
                   2401:   /* Now delete from the chain of variables all virtual function tables.
                   2402:      We output them all ourselves, because each will be treated specially.  */
                   2403: 
1.1.1.4   root     2404: #if 1
                   2405:   /* The reason for pushing garbage onto the global_binding_level is to
                   2406:      ensure that we can slice out _DECLs which pertain to virtual function
                   2407:      tables.  If the last thing pushed onto the global_binding_level was a
                   2408:      virtual function table, then slicing it out would slice away all the
                   2409:      decls (i.e., we lose the head of the chain).
                   2410: 
                   2411:      There are several ways of getting the same effect, from changing the
                   2412:      way that iterators over the chain treat the elements that pertain to
                   2413:      virtual function tables, moving the implementation of this code to
                   2414:      cp-decl.c (where we can manipulate global_binding_level directly),
                   2415:      popping the garbage after pushing it and slicing away the vtable
                   2416:      stuff, or just leaving it alone. */
                   2417: 
1.1       root     2418:   /* Make last thing in global scope not be a virtual function table.  */
1.1.1.2   root     2419: #if 0 /* not yet, should get fixed properly later */
                   2420:   vars = make_type_decl (get_identifier (" @%$#@!"), integer_type_node);
                   2421: #else
1.1       root     2422:   vars = build_decl (TYPE_DECL, get_identifier (" @%$#@!"), integer_type_node);
1.1.1.2   root     2423: #endif
1.1.1.4   root     2424:   DECL_IGNORED_P (vars) = 1;
                   2425:   DECL_SOURCE_LINE (vars) = 0;
1.1       root     2426:   pushdecl (vars);
1.1.1.4   root     2427: #endif
1.1       root     2428: 
                   2429:   walk_vtables (finish_vtable_typedecl, finish_vtable_vardecl);
                   2430: 
                   2431:   if (write_virtuals == 2)
                   2432:     {
                   2433:       /* Now complain about an virtual function tables promised
                   2434:         but not delivered.  */
                   2435:       while (pending_vtables)
                   2436:        {
                   2437:          if (TREE_PURPOSE (pending_vtables) == NULL_TREE)
                   2438:            error ("virtual function table for `%s' not defined",
                   2439:                   IDENTIFIER_POINTER (TREE_VALUE (pending_vtables)));
                   2440:          pending_vtables = TREE_CHAIN (pending_vtables);
                   2441:        }
                   2442:     }
                   2443: 
                   2444:   permanent_allocation ();
                   2445:   this_time = get_run_time ();
                   2446:   parse_time -= this_time - start_time;
                   2447:   varconst_time += this_time - start_time;
                   2448: 
                   2449:   if (flag_detailed_statistics)
                   2450:     dump_time_statistics ();
                   2451: }

unix.superglobalmegacorp.com

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