home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / cplus-decl2.c < prev    next >
C/C++ Source or Header  |  1991-06-04  |  77KB  |  2,509 lines

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