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

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

unix.superglobalmegacorp.com

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