home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / cplus-decl.c < prev    next >
C/C++ Source or Header  |  1991-06-04  |  307KB  |  9,746 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 <stdio.h>
  30. #include "config.h"
  31. #include "tree.h"
  32. #include "flags.h"
  33. #include "cplus-tree.h"
  34. #include "cplus-parse.h"
  35. #include <signal.h>
  36. #include "assert.h"
  37. #include "obstack.h"
  38.  
  39. #define obstack_chunk_alloc xmalloc
  40. #define obstack_chunk_free free
  41.  
  42. extern int xmalloc ();
  43. extern void free ();
  44.  
  45. /* Define this if C structs should have gratuitous typedefing
  46.    done just like C++ structs do.  */
  47. #define BREAK_C_TAGS
  48.  
  49. /* Stack of places to restore the search obstack back to.  */
  50.    
  51. /* Obstack used for remembering local class declarations (like
  52.    enums and static (const) members.  */
  53. #include "stack.h"
  54. static struct obstack decl_obstack;
  55. static struct stack_level *decl_stack;
  56.  
  57. #include "cplus-decl.h"
  58.  
  59. #undef NULL
  60. #define NULL 0
  61. #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
  62. #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
  63.  
  64. #ifndef CHAR_TYPE_SIZE
  65. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  66. #endif
  67.  
  68. #ifndef SHORT_TYPE_SIZE
  69. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  70. #endif
  71.  
  72. #ifndef INT_TYPE_SIZE
  73. #define INT_TYPE_SIZE BITS_PER_WORD
  74. #endif
  75.  
  76. #ifndef LONG_TYPE_SIZE
  77. #define LONG_TYPE_SIZE BITS_PER_WORD
  78. #endif
  79.  
  80. #ifndef LONG_LONG_TYPE_SIZE
  81. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  82. #endif
  83.  
  84. #ifndef WCHAR_TYPE_SIZE
  85. #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
  86. #endif
  87.  
  88. #ifndef WCHAR_UNSIGNED
  89. #define WCHAR_UNSIGNED 0
  90. #endif
  91.  
  92. #ifndef FLOAT_TYPE_SIZE
  93. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  94. #endif
  95.  
  96. #ifndef DOUBLE_TYPE_SIZE
  97. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  98. #endif
  99.  
  100. #ifndef LONG_DOUBLE_TYPE_SIZE
  101. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  102. #endif
  103.  
  104. static tree grokparms ();
  105. tree grokdeclarator ();
  106. tree pushdecl (), pushdecl_class_level ();
  107. void push_overloaded_decl ();
  108. void pop_implicit_try_blocks ();
  109.  
  110. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  111.   define_function (NAME, TYPE, CODE, (void (*)())&pushdecl, LIBNAME)
  112. #define auto_function(NAME, TYPE, CODE) \
  113.   define_function (NAME, TYPE, CODE, (void (*)())&push_overloaded_decl, 0)
  114.  
  115. /* static */ void grokclassfn ();
  116. /* static */ tree grokopexpr (), grokoptypename ();
  117.  
  118. static tree lookup_tag ();
  119. static tree lookup_tag_reverse ();
  120. static tree lookup_name_current_level ();
  121. static void globalize_nested_type ();
  122. static tree lookup_nested_type ();
  123. static char *redeclaration_error_message ();
  124. static int parmlist_is_exprlist ();
  125. static int parmlist_is_random ();
  126. void grok_ctor_properties ();
  127. static void grok_op_properties ();
  128. static void expand_static_init ();
  129. static void deactivate_exception_cleanups ();
  130. void adjust_type_value ();
  131.  
  132. tree finish_table ();
  133. static void GNU_end_scope();
  134.  
  135. /* a node which has tree code ERROR_MARK, and whose type is itself.
  136.    All erroneous expressions are replaced with this node.  All functions
  137.    that accept nodes as arguments should avoid generating error messages
  138.    if this node is one of the arguments, since it is undesirable to get
  139.    multiple error messages from one error in the input.  */
  140.  
  141. tree error_mark_node;
  142.  
  143. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  144. tree error_mark_list;
  145.  
  146. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  147.  
  148. tree short_integer_type_node;
  149. tree integer_type_node;
  150. tree long_integer_type_node;
  151. tree long_long_integer_type_node;
  152.  
  153. tree short_unsigned_type_node;
  154. tree unsigned_type_node;
  155. tree long_unsigned_type_node;
  156. tree long_long_unsigned_type_node;
  157.  
  158. tree unsigned_char_type_node;
  159. tree signed_char_type_node;
  160. tree char_type_node;
  161. tree wchar_type_node;
  162. tree signed_wchar_type_node;
  163. tree unsigned_wchar_type_node;
  164.  
  165. tree float_type_node;
  166. tree double_type_node;
  167. tree long_double_type_node;
  168.  
  169. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  170.  
  171. tree void_type_node, void_list_node;
  172. tree void_zero_node;
  173.  
  174. /* Nodes for types `void *' and `const void *'.  */
  175.  
  176. tree ptr_type_node, const_ptr_type_node;
  177.  
  178. /* Nodes for types `char *' and `const char *'.  */
  179.  
  180. tree string_type_node, const_string_type_node;
  181.  
  182. /* Type `char[256]' or something like it.
  183.    Used when an array of char is needed and the size is irrelevant.  */
  184.  
  185. tree char_array_type_node;
  186.  
  187. /* Type `int[256]' or something like it.
  188.    Used when an array of int needed and the size is irrelevant.  */
  189.  
  190. tree int_array_type_node;
  191.  
  192. /* Type `wchar_t[256]' or something like it.
  193.    Used when a wide string literal is created.  */
  194.  
  195. tree wchar_array_type_node;
  196.  
  197. /* type `int ()' -- used for implicit declaration of functions.  */
  198.  
  199. tree default_function_type;
  200.  
  201. /* function types `double (double)' and `double (double, double)', etc.  */
  202.  
  203. tree double_ftype_double, double_ftype_double_double;
  204. tree int_ftype_int, long_ftype_long;
  205.  
  206. /* Function type `void (void *, void *, int)' and similar ones.  */
  207.  
  208. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  209.  
  210. /* Function type `char *(char *, char *)' and similar ones */
  211. tree string_ftype_ptr_ptr, int_ftype_string_string;
  212.  
  213. /* Function type `int (const void *, const void *, size_t)' */
  214. tree int_ftype_cptr_cptr_sizet;
  215.  
  216. /* C++ extensions */
  217. tree vtable_entry_type;
  218. tree __t_desc_type_node, __i_desc_type_node, __m_desc_type_node;
  219. tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
  220. tree class_star_type_node;
  221. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  222. tree exception_type_node, unknown_type_node;
  223.  
  224. /* Function type `void * (long)', 'void (void *)' */
  225. tree ptr_ftype_long, void_ftype_ptr;
  226. tree ptr_ftype_ptr_int_int_ptr, void_ftype_ptr_int_int_ptr_int_int;
  227.  
  228. /* Used for virtual function tables.  */
  229. tree vtbl_mask;
  230.  
  231. /* Array type `(void *)[]' */
  232. tree vtbl_type_node;
  233.  
  234. #ifdef SOS
  235. /* SOS extensions.  */
  236. tree zlink_type, zret_type;
  237. tree zlink, zret;
  238. #endif
  239.  
  240. /* Static decls which do not have static initializers have no
  241.    initializers as far as GNU C is concerned.  EMPTY_INIT_NODE
  242.    is a static initializer which makes varasm code place the decl
  243.    in data rather than in bss space.  Such gymnastics are necessary
  244.    to avoid the problem that the linker will not include a library
  245.    file if all the library appears to contribute are bss variables.  */
  246.  
  247. tree empty_init_node;
  248.  
  249. /* In a destructor, the point at which all derived class destroying
  250.    has been done, just before any base class destroying will be done.  */
  251.  
  252. tree dtor_label;
  253.  
  254. /* In a constructor, the point at which we are ready to return
  255.    the pointer to the initialized object.  */
  256.  
  257. tree ctor_label;
  258.  
  259. /* A FUNCTION_DECL which can call `unhandled_exception'.
  260.    Not neccessarily the one that the user will declare,
  261.    but sufficient to be called by routines that want to abort the program.  */
  262.  
  263. tree unhandled_exception_fndecl;
  264.  
  265. /* A FUNCTION_DECL which can call `abort'.  Not neccessarily the
  266.    one that the user will declare, but sufficient to be called
  267.    by routines that want to abort the program.  */
  268.  
  269. tree abort_fndecl;
  270.  
  271. /* -- end of C++ */
  272.  
  273. /* Two expressions that are constants with value zero.
  274.    The first is of type `int', the second of type `void *'.  */
  275.  
  276. tree integer_zero_node;
  277. tree null_pointer_node;
  278.  
  279. /* A node for the integer constants 1, 2, and 3.  */
  280.  
  281. tree integer_one_node, integer_two_node, integer_three_node;
  282.  
  283. /* Nonzero if we have seen an invalid cross reference
  284.    to a struct, union, or enum, but not yet printed the message.  */
  285.  
  286. tree pending_invalid_xref;
  287. /* File and line to appear in the eventual error message.  */
  288. char *pending_invalid_xref_file;
  289. int pending_invalid_xref_line;
  290.  
  291. /* An identifier whose name is <value>.  This is used as the "name"
  292.    of the RESULT_DECLs for values of functions.  */
  293.  
  294. tree value_identifier;
  295.  
  296. /* If original DECL_RESULT of current function was a register,
  297.    but due to being an addressable named return value, would up
  298.    on the stack, this variable holds the named return value's
  299.    original location.  */
  300. struct rtx_def *original_result_rtx;
  301.  
  302. /* Sequence of insns which represents base initialization.  */
  303. struct rtx_def *base_init_insns;
  304.  
  305. /* C++: Keep these around to reduce calls to `get_identifier'.
  306.    Identifiers for `this' in member functions and the auto-delete
  307.    parameter for destructors.  */
  308. tree this_identifier, in_charge_identifier;
  309.  
  310. /* While defining an enum type, this is 1 plus the last enumerator
  311.    constant value.  */
  312.  
  313. static tree enum_next_value;
  314.  
  315. /* Parsing a function declarator leaves a list of parameter names
  316.    or a chain or parameter decls here.  */
  317.  
  318. tree last_function_parms;
  319.  
  320. /* Parsing a function declarator leaves here a chain of structure
  321.    and enum types declared in the parmlist.  */
  322.  
  323. static tree last_function_parm_tags;
  324.  
  325. /* After parsing the declarator that starts a function definition,
  326.    `start_function' puts here the list of parameter names or chain of decls.
  327.    `store_parm_decls' finds it here.  */
  328.  
  329. static tree current_function_parms;
  330.  
  331. /* Similar, for last_function_parm_tags.  */
  332. static tree current_function_parm_tags;
  333.  
  334. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  335.    that have names.  Here so we can clear out their names' definitions
  336.    at the end of the function.  */
  337.  
  338. static tree named_labels;
  339.  
  340. /* A list (chain of TREE_LIST nodes) of named label uses.
  341.    The TREE_PURPOSE field is the list of variables defined
  342.    the the label's scope defined at the point of use.
  343.    The TREE_VALUE field is the LABEL_DECL used.
  344.    The TREE_TYPE field holds `current_binding_level' at the
  345.    point of the label's use.
  346.  
  347.    Used only for jumps to as-yet undefined labels, since
  348.    jumps to defined labels can have their validity checked
  349.    by stmt.c.  */
  350.  
  351. static tree named_label_uses;
  352.  
  353. /* A list of objects which have constructors or destructors
  354.    which reside in the global scope.  The decl is stored in
  355.    the TREE_VALUE slot and the initializer is stored
  356.    in the TREE_PURPOSE slot.  */
  357. tree static_aggregates;
  358.  
  359. /* A list of functions which were declared inline, but later had their
  360.    address taken.  Used only for non-virtual member functions, since we can
  361.    find other functions easily enough.  */
  362. tree pending_addressable_inlines;
  363.  
  364. /* A list of overloaded functions which we should forget ever
  365.    existed, such as functions declared in a function's scope,
  366.    once we leave that function's scope.  */
  367. static tree overloads_to_forget;
  368.  
  369. /* The FUNCTION_DECL for the function currently being compiled,
  370.    or 0 if between functions.  */
  371. tree current_function_decl;
  372.  
  373. /* Set to 0 at beginning of a function definition, set to 1 if
  374.    a return statement that specifies a return value is seen.  */
  375.  
  376. int current_function_returns_value;
  377.  
  378. /* Set to 0 at beginning of a function definition, set to 1 if
  379.    a return statement with no argument is seen.  */
  380.  
  381. int current_function_returns_null;
  382.  
  383. /* Set to nonzero by `grokdeclarator' for a function
  384.    whose return type is defaulted, if warnings for this are desired.  */
  385.  
  386. static int warn_about_return_type;
  387.  
  388. /* Nonzero when starting a function delcared `extern inline'.  */
  389.  
  390. static int current_extern_inline;
  391.  
  392. /* Nonzero means give `double' the same size as `float'.  */
  393.  
  394. extern int flag_short_double;
  395.  
  396. /* C and C++ flags are in cplus-decl2.c.  */
  397. char *language_string = "GNU C++";
  398.  
  399. /* Set to 0 at beginning of a constructor, set to 1
  400.    if that function does an allocation before referencing its
  401.    instance variable.  */
  402. int current_function_assigns_this;
  403. int current_function_just_assigned_this;
  404.  
  405. /* Set to 0 at beginning of a function.  Set non-zero when
  406.    store_parm_decls is called.  Don't call store_parm_decls
  407.    if this flag is non-zero!  */
  408. int current_function_parms_stored;
  409.  
  410. /* Current end of entries in the gc obstack for stack pointer variables.  */
  411.  
  412. int current_function_obstack_index;
  413.  
  414. /* Flag saying whether we have used the obstack in this function or not.  */
  415.  
  416. int current_function_obstack_usage;
  417.  
  418. /* Allocate a level of searching.  */
  419. struct stack_level *
  420. push_decl_level (stack, obstack)
  421.      struct stack_level *stack;
  422.      struct obstack *obstack;
  423. {
  424.   struct stack_level tem;
  425.   tem.prev = stack;
  426.  
  427.   return push_stack_level (obstack, &tem, sizeof (tem));
  428. }
  429.  
  430. /* Discard a level of decl allocation.  */
  431.  
  432. static struct stack_level *
  433. pop_decl_level (stack)
  434.      struct stack_level *stack;
  435. {
  436.   tree *bp, *tp;
  437.   struct obstack *obstack = stack->obstack;
  438.   bp = stack->first;
  439.   tp = (tree *)obstack_next_free (obstack);
  440.   while (tp != bp)
  441.     {
  442.       --tp;
  443.       IDENTIFIER_CLASS_VALUE (DECL_NAME (*tp)) = NULL_TREE;
  444.     }
  445.   return pop_stack_level (stack);
  446. }
  447.  
  448. /* For each binding contour we allocate a binding_level structure
  449.  * which records the names defined in that contour.
  450.  * Contours include:
  451.  *  0) the global one
  452.  *  1) one for each function definition,
  453.  *     where internal declarations of the parameters appear.
  454.  *  2) one for each compound statement,
  455.  *     to record its declarations.
  456.  *
  457.  * The current meaning of a name can be found by searching the levels from
  458.  * the current one out to the global one.
  459.  *
  460.  * Off to the side, may be the class_binding_level.  This exists
  461.  * only to catch class-local declarations.  It is otherwise
  462.  * nonexistent.
  463.  * 
  464.  * Also there may be binding levels that catch cleanups that
  465.  * must be run when exceptions occur.
  466.  */
  467.  
  468. /* Note that the information in the `names' component of the global contour
  469.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  470.  
  471. struct binding_level
  472.   {
  473.     /* A chain of _DECL nodes for all variables, constants, functions,
  474.      * and typedef types.  These are in the reverse of the order supplied.
  475.      */
  476.     tree names;
  477.  
  478.     /* A list of structure, union and enum definitions,
  479.      * for looking up tag names.
  480.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  481.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  482.      * or ENUMERAL_TYPE node.
  483.      *
  484.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  485.      *
  486.      */
  487.     tree tags;
  488.  
  489.     /* For each level, a list of shadowed outer-level local definitions
  490.        to be restored when this level is popped.
  491.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  492.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  493.     tree shadowed;
  494.  
  495.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  496.     tree class_shadowed;
  497.  
  498.     /* For each level (except not the global one),
  499.        a chain of BLOCK nodes for all the levels
  500.        that were entered and exited one level down.  */
  501.     tree blocks;
  502.  
  503.     /* The binding level which this one is contained in (inherits from).  */
  504.     struct binding_level *level_chain;
  505.  
  506.     /* Number of decls in `names' that have incomplete 
  507.        structure or union types.  */
  508.     unsigned short n_incomplete;
  509.  
  510.     /* 1 for the level that holds the parameters of a function.
  511.        2 for the level that holds a class declaration.
  512.        3 for levels that hold parameter declarations.  */
  513.     unsigned parm_flag : 4;
  514.  
  515.     /* 1 means make a BLOCK for this level regardless of all else.
  516.        2 for temporary binding contours created by the compiler.  */
  517.     unsigned keep : 3;
  518.  
  519.     /* Nonzero if this level "doesn't exist" for tags.  */
  520.     unsigned tag_transparent : 1;
  521.  
  522.     /* Nonzero if this level can safely have additional
  523.        cleanup-needing variables added to it.  */
  524.     unsigned more_cleanups_ok : 1;
  525.     unsigned have_cleanups : 1;
  526.  
  527.     /* Nonzero if this level can safely have additional
  528.        exception-raising statements added to it.  */
  529.     unsigned more_exceptions_ok : 1;
  530.     unsigned have_exceptions : 1;
  531.  
  532.     /* Four bits left for this word.  */
  533.   };
  534.  
  535. #define NULL_BINDING_LEVEL (struct binding_level *) NULL
  536.   
  537. /* The binding level currently in effect.  */
  538.  
  539. static struct binding_level *current_binding_level;
  540.  
  541. /* The binding level of the current class, if any.  */
  542.  
  543. static struct binding_level *class_binding_level;
  544.  
  545. /* A chain of binding_level structures awaiting reuse.  */
  546.  
  547. static struct binding_level *free_binding_level;
  548.  
  549. /* The outermost binding level, for names of file scope.
  550.    This is created when the compiler is started and exists
  551.    through the entire run.  */
  552.  
  553. static struct binding_level *global_binding_level;
  554.  
  555. /* Binding level structures are initialized by copying this one.  */
  556.  
  557. static struct binding_level clear_binding_level;
  558.  
  559. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  560.  
  561. static int keep_next_level_flag;
  562.  
  563. #define PUSH_BINDING_LEVEL(NEWLEVEL, TAG_TRANSPARENT, KEEP) \
  564. do {                                    \
  565.   /* Add this level to the front of the chain (stack) of levels that    \
  566.      are active.  */                            \
  567.   *NEWLEVEL = clear_binding_level;                    \
  568.   if (class_binding_level)                        \
  569.     {                                    \
  570.       NEWLEVEL->level_chain = class_binding_level;            \
  571.       class_binding_level = 0;                        \
  572.     }                                    \
  573.   else                                    \
  574.     {                                    \
  575.       NEWLEVEL->level_chain = current_binding_level;            \
  576.     }                                    \
  577.   current_binding_level = NEWLEVEL;                    \
  578.   NEWLEVEL->tag_transparent = TAG_TRANSPARENT;                \
  579.   NEWLEVEL->more_cleanups_ok = 1;                    \
  580.   NEWLEVEL->more_exceptions_ok = 1;                    \
  581.   NEWLEVEL->keep = KEEP;                        \
  582. } while (0)
  583.  
  584. #define POP_BINDING_LEVEL \
  585. do {                                    \
  586.   /* Pop the current level, and free the structure for reuse.  */    \
  587.   {                                    \
  588.     register struct binding_level *level = current_binding_level;    \
  589.     current_binding_level = current_binding_level->level_chain;        \
  590.     level->level_chain = free_binding_level;                \
  591.     free_binding_level = level;                        \
  592.     if (current_binding_level->parm_flag == 2)                \
  593.       {                                    \
  594.     class_binding_level = current_binding_level;            \
  595.     do                                \
  596.       {                                \
  597.         current_binding_level = current_binding_level->level_chain;    \
  598.       }                                \
  599.     while (current_binding_level->parm_flag == 2);            \
  600.       }                                    \
  601.   }                                    \
  602. } while (0)
  603.  
  604. /* Nonzero if we are currently in the global binding level.  */
  605.  
  606. int
  607. global_bindings_p ()
  608. {
  609.   return current_binding_level == global_binding_level;
  610. }
  611.  
  612. void
  613. keep_next_level ()
  614. {
  615.   keep_next_level_flag = 1;
  616. }
  617.  
  618. /* Identify this binding level as a level of parameters.  */
  619.  
  620. void
  621. declare_parm_level ()
  622. {
  623.   current_binding_level->parm_flag = 1;
  624. }
  625.  
  626. /* Identify this binding level as a level of a default exception handler.  */
  627.  
  628. void
  629. declare_implicit_exception ()
  630. {
  631.   current_binding_level->parm_flag = 3;
  632. }
  633.  
  634. /* Nonzero if current binding contour contains expressions
  635.    that might raise exceptions.  */
  636.  
  637. int
  638. have_exceptions_p ()
  639. {
  640.   return current_binding_level->have_exceptions;
  641. }
  642.  
  643. /* Enter a new binding level.
  644.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  645.    not for that of tags.  */
  646.  
  647. void
  648. pushlevel (tag_transparent)
  649.      int tag_transparent;
  650. {
  651.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  652.  
  653.   /* If this is the top level of a function,
  654.      just make sure that NAMED_LABELS is 0.
  655.      They should have been set to 0 at the end of the previous function.  */
  656.  
  657.   if (current_binding_level == global_binding_level)
  658.     assert (named_labels == NULL_TREE);
  659.  
  660.   /* Reuse or create a struct for this binding level.  */
  661.  
  662.   if (free_binding_level)
  663.     {
  664.       newlevel = free_binding_level;
  665.       free_binding_level = free_binding_level->level_chain;
  666.     }
  667.   else
  668.     {
  669.       /* Create a new `struct binding_level'.  */
  670.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  671.     }
  672.   PUSH_BINDING_LEVEL (newlevel, tag_transparent, keep_next_level_flag);
  673.   GNU_xref_start_scope (newlevel);
  674.   keep_next_level_flag = 0;
  675. }
  676.  
  677. void
  678. pushlevel_temporary (tag_transparent)
  679.      int tag_transparent;
  680. {
  681.   pushlevel (tag_transparent);
  682.   current_binding_level->keep = 2;
  683.   clear_last_expr ();
  684. #if 0
  685.   /* Don't call push_momentary here!  It will cause cleanups
  686.      to be allocated on the momentary obstack, and they
  687.      will be overwritten by the next statement.  */
  688.   push_momentary ();
  689. #endif
  690.   expand_start_bindings (0);
  691. }
  692.  
  693. /* Exit a binding level.
  694.    Pop the level off, and restore the state of the identifier-decl mappings
  695.    that were in effect when this level was entered.
  696.  
  697.    If KEEP == 1, this level had explicit declarations, so
  698.    and create a "block" (a BLOCK node) for the level
  699.    to record its declarations and subblocks for symbol table output.
  700.  
  701.    If KEEP == 2, this level's subblocks go to the front,
  702.    not the back of the current binding level.  This happens,
  703.    for instance, when code for constructors and destructors
  704.    need to generate code at the end of a function which must
  705.    be moved up to the front of the function.
  706.  
  707.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  708.    so create a block as if KEEP were set and also clear out all
  709.    label names.
  710.  
  711.    If REVERSE is nonzero, reverse the order of decls before putting
  712.    them into the BLOCK.  */
  713.  
  714. tree
  715. poplevel (keep, reverse, functionbody)
  716.      int keep;
  717.      int reverse;
  718.      int functionbody;
  719. {
  720.   register tree link;
  721.   /* The chain of decls was accumulated in reverse order.
  722.      Put it into forward order, just for cleanliness.  */
  723.   tree decls;
  724.   int tmp = functionbody;
  725.   int implicit_try_block = current_binding_level->parm_flag == 3;
  726.   int real_functionbody = current_binding_level->keep == 2
  727.     ? ((functionbody = 0), tmp) : functionbody;
  728.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  729.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  730.   tree block = 0;
  731.   tree decl;
  732.  
  733.   GNU_xref_end_scope (current_binding_level,
  734.               current_binding_level->level_chain,
  735.               current_binding_level->parm_flag,
  736.               current_binding_level->keep,
  737.               current_binding_level->tag_transparent);
  738.  
  739.   if (current_binding_level->keep == 1)
  740.     keep = 1;
  741.  
  742.   /* This warning is turned off because it causes warnings for
  743.      declarations like `extern struct foo *x'.  */
  744. #if 0
  745.   /* Warn about incomplete structure types in this level.  */
  746.   for (link = tags; link; link = TREE_CHAIN (link))
  747.     if (TYPE_SIZE (TREE_VALUE (link)) == 0)
  748.       {
  749.     tree type = TREE_VALUE (link);
  750.     char *errmsg;
  751.     switch (TREE_CODE (type))
  752.       {
  753.       case RECORD_TYPE:
  754.         errmsg = "`struct %s' incomplete in scope ending here";
  755.         break;
  756.       case UNION_TYPE:
  757.         errmsg = "`union %s' incomplete in scope ending here";
  758.         break;
  759.       case ENUMERAL_TYPE:
  760.         errmsg = "`enum %s' incomplete in scope ending here";
  761.         break;
  762.       }
  763.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  764.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  765.     else
  766.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  767.       error (errmsg, TYPE_NAME_STRING (type));
  768.       }
  769. #endif /* 0 */
  770.  
  771.   /* Get the decls in the order they were written.
  772.      Usually current_binding_level->names is in reverse order.
  773.      But parameter decls were previously put in forward order.  */
  774.  
  775.   if (reverse)
  776.     current_binding_level->names
  777.       = decls = nreverse (current_binding_level->names);
  778.   else
  779.     decls = current_binding_level->names;
  780.  
  781.   /* Output any nested inline functions within this block
  782.      if they weren't already output.  */
  783.  
  784.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  785.     if (TREE_CODE (decl) == FUNCTION_DECL
  786.     && ! TREE_ASM_WRITTEN (decl)
  787.     && DECL_INITIAL (decl) != 0
  788.     && TREE_ADDRESSABLE (decl))
  789.       output_inline_function (decl);
  790.  
  791.   /* If there were any declarations or structure tags in that level,
  792.      or if this level is a function body,
  793.      create a BLOCK to record them for the life of this function.  */
  794.  
  795.   if (keep == 1 || functionbody > 0)
  796.     block = build_block (keep ? decls : 0, keep ? tags : 0,
  797.              subblocks, 0, 0);
  798.  
  799.   /* In each subblock, record that this is its superior.  */
  800.  
  801.   if (keep >= 0)
  802.     for (link = subblocks; link; link = TREE_CHAIN (link))
  803.       BLOCK_SUPERCONTEXT (link) = block;
  804.  
  805.   /* Clear out the meanings of the local variables of this level;
  806.      also record in each decl which block it belongs to.
  807.      We do this only for decls declared within the function,
  808.      since nested types have their own contexts.  */
  809.  
  810.   for (link = decls; link; link = TREE_CHAIN (link))
  811.     {
  812.       if (DECL_NAME (link) != 0)
  813.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  814.       if (TREE_CODE (link) != TYPE_DECL
  815.       || DECL_NESTED_TYPENAME (link) == DECL_NAME (link))
  816.     DECL_CONTEXT (link) = block;
  817.     }
  818.  
  819.   /* Restore all name-meanings of the outer levels
  820.      that were shadowed by this level.  */
  821.  
  822.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  823.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  824.   for (link = current_binding_level->class_shadowed;
  825.        link; link = TREE_CHAIN (link))
  826.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  827.  
  828.   /* If the level being exited is the top level of a function,
  829.      check over all the labels.  */
  830.  
  831.   if (functionbody)
  832.     {
  833.       /* Clear out the definitions of all label names,
  834.      since their scopes end here.  */
  835.  
  836.       for (link = named_labels; link; link = TREE_CHAIN (link))
  837.     {
  838.       if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
  839.         {
  840.           error ("label `%s' used somewhere above but not defined",
  841.              IDENTIFIER_POINTER (DECL_NAME (TREE_VALUE (link))));
  842.           /* Avoid crashing later.  */
  843.           define_label (input_filename, 1, DECL_NAME (TREE_VALUE (link)));
  844.         }
  845.       else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
  846.         warning_with_decl (TREE_VALUE (link), 
  847.                    "label `%s' defined but not used");
  848.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), 0);
  849.     }
  850.  
  851.       named_labels = 0;
  852.     }
  853.  
  854.   /* Any uses of undefined labels now operate under constraints
  855.      of next binding contour.  */
  856.   {
  857.     struct binding_level *level_chain;
  858.     level_chain = current_binding_level->level_chain;
  859.     if (level_chain)
  860.       {
  861.     tree labels;
  862.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  863.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  864.         {
  865.           TREE_TYPE (labels) = (tree)level_chain;
  866.           TREE_PURPOSE (labels) = level_chain->names;
  867.         }
  868.       }
  869.   }
  870.  
  871.   tmp = current_binding_level->keep;
  872.  
  873.   POP_BINDING_LEVEL;
  874.   if (functionbody > 0)
  875.     {
  876.       DECL_INITIAL (current_function_decl) = block;
  877.       /* If this is the top level block of a function,
  878.      the vars are the function's parameters.
  879.      Don't leave them in the BLOCK because they are
  880.      found in the FUNCTION_DECL instead.  */
  881.       BLOCK_VARS (block) = 0;
  882.     }
  883.   else if (block)
  884.     current_binding_level->blocks
  885.       = chainon (current_binding_level->blocks, block);
  886.   /* If we did not make a block for the level just exited,
  887.      any blocks made for inner levels
  888.      (since they cannot be recorded as subblocks in that level)
  889.      must be carried forward so they will later become subblocks
  890.      of something else.  */
  891.   else if (subblocks)
  892.     if (keep == 2)
  893.       current_binding_level->blocks = chainon (subblocks, current_binding_level->blocks);
  894.     else
  895.       current_binding_level->blocks
  896.         = chainon (current_binding_level->blocks, subblocks);
  897.  
  898.   /* Take care of compiler's internal binding structures.  */
  899.   if (tmp == 2 && !implicit_try_block)
  900.     {
  901. #if 0
  902.       /* We did not call push_momentary for this
  903.      binding contour, so there is nothing to pop.  */
  904.       pop_momentary ();
  905. #endif
  906.       expand_end_bindings (getdecls (), keep, 1);
  907.       block = poplevel (keep, reverse, real_functionbody);
  908.     }
  909.   if (block)
  910.     TREE_USED (block) = 1;
  911.   return block;
  912. }
  913.  
  914. /* Add BLOCK to the current list of blocks for this binding contour.  */
  915. void
  916. add_block_current_level (block)
  917.      tree block;
  918. {
  919.   current_binding_level->blocks
  920.     = chainon (current_binding_level->blocks, block);
  921. }
  922.  
  923. /* Do a pushlevel for class declarations.  */
  924. void
  925. pushlevel_class ()
  926. {
  927.   pushlevel (0);
  928.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  929.   class_binding_level = current_binding_level;
  930.   class_binding_level->parm_flag = 2;
  931.   do
  932.     {
  933.       current_binding_level = current_binding_level->level_chain;
  934.     }
  935.   while (current_binding_level->parm_flag == 2);
  936. }
  937.  
  938. /* ...and a poplevel for class declarations.  */
  939. tree
  940. poplevel_class ()
  941. {
  942.   register struct binding_level *level = class_binding_level;
  943.   tree block = 0;
  944.   tree shadowed;
  945.  
  946.   if (level == 0)
  947.     {
  948.       while (current_binding_level && class_binding_level == 0)
  949.     block = poplevel (0, 0, 0);
  950.       if (current_binding_level == 0)
  951.     fatal ("syntax error too serious");
  952.       level = class_binding_level;
  953.     }
  954.   decl_stack = pop_decl_level (decl_stack);
  955.   for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  956.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  957.  
  958.   GNU_xref_end_scope (class_binding_level,
  959.               class_binding_level->level_chain,
  960.               class_binding_level->parm_flag,
  961.               class_binding_level->keep,
  962.               class_binding_level->tag_transparent);
  963.  
  964.   class_binding_level = level->level_chain;
  965.  
  966.   level->level_chain = free_binding_level;
  967.   free_binding_level = level;
  968.   if (class_binding_level->parm_flag != 2)
  969.     class_binding_level = 0;
  970.   return block;
  971. }
  972.  
  973. /* For debugging.  */
  974. void
  975. print_binding_level (lvl)
  976.      struct binding_level *lvl;
  977. {
  978.   tree t;
  979.   int i = 0, len;
  980.   fprintf (stderr, " blocks=%x n_incomplete=%d parm_flag=%d keep=%d",
  981.        lvl->blocks, lvl->n_incomplete, lvl->parm_flag, lvl->keep);
  982.   if (lvl->tag_transparent)
  983.     fprintf (stderr, " tag-transparent");
  984.   if (lvl->more_cleanups_ok)
  985.     fprintf (stderr, " more-cleanups-ok");
  986.   if (lvl->have_cleanups)
  987.     fprintf (stderr, " have-cleanups");
  988.   if (lvl->more_exceptions_ok)
  989.     fprintf (stderr, " more-exceptions-ok");
  990.   if (lvl->have_exceptions)
  991.     fprintf (stderr, " have-exceptions");
  992.   fprintf (stderr, "\n names:\t");
  993.   /* We can probably fit 3 names to a line?  */
  994.   for (t = lvl->names; t; t = TREE_CHAIN (t))
  995.     {
  996.       /* Function decls tend to have longer names.  */
  997.       if (TREE_CODE (t) == FUNCTION_DECL)
  998.     len = 3;
  999.       else
  1000.     len = 2;
  1001.       i += len;
  1002.       if (i > 6)
  1003.     {
  1004.       fprintf (stderr, "\n\t");
  1005.       i = len;
  1006.     }
  1007.       print_node_brief (stderr, "", t, 0);
  1008.       if (TREE_CODE (t) == ERROR_MARK)
  1009.     break;
  1010.     }
  1011.   fprintf (stderr, "%s tags:\t", (i == 0 && lvl->names) ? "" : "\n");
  1012.   /* Print tags, two to a line.  */
  1013.   i = 0;
  1014.   for (t = lvl->tags; t; t = TREE_CHAIN (t))
  1015.     {
  1016.       if (TREE_PURPOSE (t) == NULL_TREE)
  1017.     len = 3;
  1018.       else if (TREE_PURPOSE (t) == DECL_NAME (TYPE_NAME (TREE_VALUE (t))))
  1019.     len = 2;
  1020.       else
  1021.     len = 4;
  1022.       i += len;
  1023.       if (i > 5)
  1024.     {
  1025.       fprintf (stderr, "\n\t");
  1026.       i = len;
  1027.     }
  1028.       if (TREE_PURPOSE (t) == NULL_TREE)
  1029.     {
  1030.       print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
  1031.       fprintf (stderr, ">");
  1032.     }
  1033.       else if (TREE_PURPOSE (t) == DECL_NAME (TYPE_NAME (TREE_VALUE (t))))
  1034.     print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1035.       else
  1036.     {
  1037.       print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
  1038.       print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1039.       fprintf (stderr, ">");
  1040.     }
  1041.     }
  1042.   if (i || !lvl->tags)
  1043.     fprintf (stderr, "\n");
  1044. }
  1045.  
  1046. void
  1047. print_other_binding_stack (stack)
  1048.      struct binding_level *stack;
  1049. {
  1050.   struct binding_level *level;
  1051.   for (level = stack; level != global_binding_level; level = level->level_chain)
  1052.     {
  1053.       fprintf (stderr, "binding level %x\n", level);
  1054.       print_binding_level (level);
  1055.     }
  1056. }
  1057.  
  1058. void
  1059. print_binding_stack ()
  1060. {
  1061.   struct binding_level *b;
  1062.   fprintf (stderr, "current_binding_level=%8x\n", current_binding_level);
  1063.   fprintf (stderr, "class_binding_level=  %8x\n", class_binding_level);
  1064.   fprintf (stderr, "global_binding_level= %8x\n", global_binding_level);
  1065.   if (class_binding_level)
  1066.     {
  1067.       for (b = class_binding_level; b; b = b->level_chain)
  1068.     if (b == current_binding_level)
  1069.       break;
  1070.       if (b)
  1071.     b = class_binding_level;
  1072.       else
  1073.     b = current_binding_level;
  1074.     }
  1075.   else
  1076.     b = current_binding_level;
  1077.   print_other_binding_stack (b);
  1078.   fprintf (stderr, "global:\n");
  1079.   print_binding_level (global_binding_level);
  1080. }
  1081.  
  1082. /* Subroutines for reverting temporarily to top-level for instantiation
  1083.    of templates and such.  We actually need to clear out the class- and
  1084.    local-value slots of all identifiers, so that only the global values
  1085.    are at all visible.  Simply setting current_binding_level to the global
  1086.    scope isn't enough, because more binding levels may be pushed.  */
  1087. struct saved_scope {
  1088.   struct binding_level *old_binding_level;
  1089.   tree old_bindings;
  1090.   struct saved_scope *prev;
  1091.   tree class_name, class_type, class_decl, function_decl;
  1092.   struct binding_level *class_bindings;
  1093. };
  1094. static struct saved_scope *current_saved_scope;
  1095. extern tree prev_class_type;
  1096.  
  1097. void
  1098. push_to_top_level ()
  1099. {
  1100.   struct saved_scope *s =
  1101.     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
  1102.   struct binding_level *b = current_binding_level;
  1103.   tree old_bindings = NULL_TREE;
  1104.  
  1105.   for (; b != global_binding_level; b = b->level_chain)
  1106.     {
  1107.       tree t;
  1108.       for (t = b->names; t; t = TREE_CHAIN (t))
  1109.     {
  1110.       tree binding, t1;
  1111.       tree id = DECL_NAME (t);
  1112.       for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
  1113.         if (TREE_VEC_ELT (t1, 0) == id)
  1114.           goto skip_it;
  1115.  
  1116.       binding = make_tree_vec (4);
  1117.       assert (id != 0);
  1118.       assert (TREE_CODE (id) == IDENTIFIER_NODE);
  1119.       TREE_VEC_ELT (binding, 0) = id;
  1120.       TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
  1121.       TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
  1122.       TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
  1123.       IDENTIFIER_LOCAL_VALUE (id) = 0;
  1124.       IDENTIFIER_CLASS_VALUE (id) = 0;
  1125.       adjust_type_value (id);
  1126.       TREE_CHAIN (binding) = old_bindings;
  1127.       old_bindings = binding;
  1128.     skip_it:
  1129.       ;
  1130.     }
  1131.     }
  1132.  
  1133.   s->old_binding_level = current_binding_level;
  1134.   current_binding_level = global_binding_level;
  1135.  
  1136.   s->class_name = current_class_name;
  1137.   s->class_type = current_class_type;
  1138.   s->class_decl = current_class_decl;
  1139.   s->function_decl = current_function_decl;
  1140.   s->class_bindings = class_binding_level;
  1141.   current_class_name = current_class_type = current_class_decl = 0;
  1142.   current_function_decl = 0;
  1143.   class_binding_level = 0;
  1144.  
  1145.   s->prev = current_saved_scope;
  1146.   s->old_bindings = old_bindings;
  1147.   current_saved_scope = s;
  1148. }
  1149.  
  1150. void
  1151. pop_from_top_level ()
  1152. {
  1153.   struct saved_scope *s = current_saved_scope;
  1154.   tree t;
  1155.  
  1156.   assert (s != 0);
  1157.   current_binding_level = s->old_binding_level;
  1158.   current_saved_scope = s->prev;
  1159.   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
  1160.     {
  1161.       tree id = TREE_VEC_ELT (t, 0);
  1162.       IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
  1163.       IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
  1164.       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
  1165.     }
  1166.   current_class_name = s->class_name;
  1167.   current_class_type = s->class_type;
  1168.   current_class_decl = s->class_decl;
  1169.   current_function_decl = s->function_decl;
  1170.   class_binding_level = s->class_bindings;
  1171.   free (s);
  1172. }
  1173.  
  1174. /* Push a definition of struct, union or enum tag "name".
  1175.    "type" should be the type node.
  1176.    We assume that the tag "name" is not already defined.
  1177.  
  1178.    Note that the definition may really be just a forward reference.
  1179.    In that case, the TYPE_SIZE will be zero.
  1180.  
  1181.    C++ gratuitously puts all these tags in the name space. */
  1182.  
  1183. /* Subroutine "set_nested_typename" builds the nested-typename of
  1184.    the type decl in question.  (Argument CLASSNAME can actually be
  1185.    a function as well, if that's the smallest containing scope.)  */
  1186.  
  1187. static void
  1188. set_nested_typename (decl, classname, name, type)
  1189.      tree decl, classname, name, type;
  1190. {
  1191.   assert (decl != 0);
  1192.   assert (TREE_CODE (decl) == TYPE_DECL);
  1193.   if (classname != 0)
  1194.     {
  1195.       char *buf;
  1196.       assert (TREE_CODE (classname) == IDENTIFIER_NODE);
  1197.       assert (TREE_CODE (name) == IDENTIFIER_NODE);
  1198.       buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
  1199.                  + IDENTIFIER_LENGTH (name));
  1200.       sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
  1201.            IDENTIFIER_POINTER (name));
  1202.       DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
  1203.       SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (decl), type);
  1204.     }
  1205.   else
  1206.     DECL_NESTED_TYPENAME (decl) = name;
  1207. }
  1208.  
  1209. void
  1210. pushtag (name, type)
  1211.      tree name, type;
  1212. {
  1213.   register struct binding_level *b;
  1214.  
  1215.   if (class_binding_level)
  1216.     b = class_binding_level;
  1217.   else
  1218.     {
  1219.       b = current_binding_level;
  1220.       while (b->tag_transparent) b = b->level_chain;
  1221.     }
  1222.  
  1223.   if (name)
  1224.     {
  1225.       /* Record the identifier as the type's name if it has none.  */
  1226.  
  1227.       if (TYPE_NAME (type) == 0)
  1228.         TYPE_NAME (type) = name;
  1229.  
  1230.       if (b == global_binding_level)
  1231.     b->tags = perm_tree_cons (name, type, b->tags);
  1232.       else
  1233.     b->tags = saveable_tree_cons (name, type, b->tags);
  1234.  
  1235.       /* Do C++ gratuitous typedefing.  */
  1236.       if (IDENTIFIER_TYPE_VALUE (name) != type
  1237. #ifndef BREAK_C_TAGS
  1238.       /* This *should* only happen in C++ language scope.
  1239.          But everybody else seems to think otherwise.  */
  1240.       && current_lang_name == lang_name_cplusplus
  1241. #endif
  1242.       && (TREE_CODE (type) != RECORD_TYPE
  1243.           || class_binding_level == 0
  1244.           || !CLASSTYPE_DECLARED_EXCEPTION (type)))
  1245.         {
  1246.           register tree d;
  1247.       if (current_class_type == 0
  1248.           || TYPE_SIZE (current_class_type) != NULL_TREE)
  1249.         {
  1250.           if (current_lang_name == lang_name_cplusplus)
  1251.         d = lookup_nested_type (type, current_class_type ? TYPE_NAME (current_class_type) : NULL_TREE);
  1252.           else
  1253.         d = NULL_TREE;
  1254.  
  1255.           if (d == NULL_TREE)
  1256.         {
  1257.           d = build_decl (TYPE_DECL, name, type);
  1258.           SET_IDENTIFIER_TYPE_VALUE (name, type);
  1259.         }
  1260.           else
  1261.         d = TYPE_NAME (d);
  1262.  
  1263.           /* If it is anonymous, then we are called from pushdecl,
  1264.          and we don't want to infinitely recurse.  Also, if the
  1265.          name is already in scope, we don't want to push it
  1266.          again--pushdecl is only for pushing new decls.  */
  1267.           if (! ANON_AGGRNAME_P (name) && lookup_name (name) != TYPE_NAME (type))
  1268.         d = pushdecl (d);
  1269.         }
  1270.       else
  1271.         {
  1272.           /* Make nested declarations go into class-level scope.  */
  1273.           d = build_decl (TYPE_DECL, name, type);
  1274.           SET_IDENTIFIER_TYPE_VALUE (name, type);
  1275.           d = pushdecl_class_level (d);
  1276.         }
  1277.       TYPE_NAME (type) = d;
  1278.  
  1279.       if ((current_class_type == NULL_TREE
  1280.            && current_function_decl == NULL_TREE)
  1281.           || current_lang_name != lang_name_cplusplus)
  1282.         /* Non-nested class.  */
  1283.         DECL_NESTED_TYPENAME (d) = name;
  1284.       else if (current_function_decl != NULL_TREE)
  1285.         {
  1286.           /* Function-nested class.  */
  1287.           set_nested_typename (d, DECL_NAME (current_function_decl),
  1288.                    name, type);
  1289.           /* This builds the links for classes nested in fn scope.  */
  1290.           DECL_CONTEXT (d) = current_function_decl;
  1291.         }
  1292.       else if (TYPE_SIZE (current_class_type) == NULL_TREE)
  1293.         {
  1294.           /* Class-nested class.  */
  1295.           set_nested_typename (d, DECL_NESTED_TYPENAME (TYPE_NAME (current_class_type)),
  1296.                    name, type);
  1297.           /* This builds the links for classes nested in type scope.  */
  1298.           DECL_CONTEXT (d) = current_class_type;
  1299.         }
  1300.         }
  1301.       if (b->parm_flag == 2)
  1302.     {
  1303.       TREE_NONLOCAL_FLAG (type) = 1;
  1304.       IDENTIFIER_CLASS_VALUE (name) = TYPE_NAME (type);
  1305.       CLASSTYPE_TAGS (current_class_type) = b->tags;
  1306.     }
  1307.     }
  1308. }
  1309.  
  1310. /* Subroutine of duplicate_decls: return truthvalue of whether
  1311.    or not types of these decls match.  */
  1312. static int
  1313. decls_match (newdecl, olddecl)
  1314.      tree newdecl, olddecl;
  1315. {
  1316.   int types_match;
  1317.  
  1318.   if (TREE_CODE (newdecl) == FUNCTION_DECL && TREE_CODE (olddecl) == FUNCTION_DECL)
  1319.     {
  1320.       tree f1 = TREE_TYPE (newdecl);
  1321.       tree f2 = TREE_TYPE (olddecl);
  1322.       tree p1 = TYPE_ARG_TYPES (f1);
  1323.       tree p2 = TYPE_ARG_TYPES (f2);
  1324.  
  1325.       /* When we parse a static member function definition,
  1326.      we put together a FUNCTION_DECL which thinks its type
  1327.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  1328.      proceed.  */
  1329.       if (TREE_CODE (f1) == METHOD_TYPE
  1330.       && DECL_STATIC_FUNCTION_P (olddecl))
  1331.     {
  1332.       tree n1;
  1333.       p1 = TREE_CHAIN (p1);
  1334.       n1 = build_function_type (TREE_TYPE (f1), p1);
  1335.       n1 = build_type_variant (n1, TYPE_READONLY (f1), TYPE_VOLATILE (f1));
  1336.       n1 = build_exception_variant (TYPE_METHOD_BASETYPE (f1), n1, TYPE_RAISES_EXCEPTIONS (f1));
  1337.       TREE_TYPE (newdecl) = n1;
  1338.       f1 = n1;
  1339.       DECL_STATIC_FUNCTION_P (newdecl) = 1;
  1340.     }
  1341.       /* Here we must take care of the case where new default
  1342.      parameters are specified.  Also, warn if an old
  1343.      declaration becomes ambiguous because default
  1344.      parameters may cause the two to be ambiguous.  */
  1345.       if (TREE_CODE (f1) != TREE_CODE (f2))
  1346.     {
  1347.       if (TREE_CODE (f1) == OFFSET_TYPE)
  1348.         compiler_error_with_decl (newdecl, "`%s' redeclared as member function");
  1349.       else
  1350.         compiler_error_with_decl (newdecl, "`%s' redeclared as non-member function");
  1351.       return 0;
  1352.     }
  1353.  
  1354.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (f1)),
  1355.              TYPE_MAIN_VARIANT (TREE_TYPE (f2)), 1))
  1356.     types_match = compparms (p1, p2, 1);
  1357.       else types_match = 0;
  1358.     }
  1359.   else
  1360.     {
  1361.       if (TREE_TYPE (newdecl) == error_mark_node)
  1362.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  1363.       else
  1364.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  1365.     }
  1366.  
  1367.   return types_match;
  1368. }
  1369.  
  1370. /* Handle when a new declaration NEWDECL has the same name as an old
  1371.    one OLDDECL in the same binding contour.  Prints an error message
  1372.    if appropriate.
  1373.  
  1374.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  1375.    Otherwise, return 0.  */
  1376.  
  1377. static int
  1378. duplicate_decls (newdecl, olddecl)
  1379.      register tree newdecl, olddecl;
  1380. {
  1381.   extern struct obstack permanent_obstack;
  1382.   int types_match;
  1383.   int new_is_definition;
  1384.  
  1385.   if (TREE_CODE (olddecl) == TREE_LIST
  1386.       && TREE_CODE (newdecl) == FUNCTION_DECL)
  1387.     {
  1388.       /* If a new decl finds a list of old decls, then
  1389.      we assume that the new decl has C linkage, and
  1390.      that the old decls have C++ linkage.  In this case,
  1391.      we must look through the list to see whether
  1392.      there is an ambiguity or not.  */
  1393.       tree olddecls = olddecl;
  1394.  
  1395.       /* If the overload list is empty, just install the decl.  */
  1396.       if (TREE_VALUE (olddecls) == NULL_TREE)
  1397.     {
  1398.       TREE_VALUE (olddecls) = newdecl;
  1399.       return 1;
  1400.     }
  1401.  
  1402.       while (olddecls)
  1403.     {
  1404.       if (decls_match (newdecl, TREE_VALUE (olddecls)))
  1405.         {
  1406.           if (TREE_CODE (newdecl) == VAR_DECL)
  1407.         ;
  1408.           else if (DECL_LANGUAGE (newdecl)
  1409.                != DECL_LANGUAGE (TREE_VALUE (olddecls)))
  1410.         {
  1411.           error_with_decl (newdecl, "declaration of `%s' with different language linkage");
  1412.           error_with_decl (TREE_VALUE (olddecls), "previous declaration here");
  1413.         }
  1414.           types_match = 1;
  1415.           break;
  1416.         }
  1417.       olddecls = TREE_CHAIN (olddecls);
  1418.     }
  1419.       if (olddecls)
  1420.     olddecl = TREE_VALUE (olddecl);
  1421.       else
  1422.     return 1;
  1423.     }
  1424.   else
  1425.     types_match = decls_match (newdecl, olddecl);
  1426.  
  1427.   if ((TREE_TYPE (newdecl) && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
  1428.       || (TREE_TYPE (olddecl) && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
  1429.     types_match = 0;
  1430.  
  1431.   /* If this decl has linkage, and the old one does too, maybe no error.  */
  1432.   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  1433.     {
  1434.       error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
  1435.       if (TREE_CODE (olddecl) == TREE_LIST)
  1436.     olddecl = TREE_VALUE (olddecl);
  1437.       error_with_decl (olddecl, "previous declaration of `%s'");
  1438.  
  1439.       /* New decl is completely inconsistent with the old one =>
  1440.      tell caller to replace the old one.  */
  1441.  
  1442.       return 0;
  1443.     }
  1444.  
  1445.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1446.     {
  1447.       /* Now that functions must hold information normally held
  1448.      by field decls, there is extra work to do so that
  1449.      declaration information does not get destroyed during
  1450.      definition.  */
  1451.       if (DECL_VINDEX (olddecl) && ! DECL_VINDEX (newdecl))
  1452.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  1453.       if (DECL_VCONTEXT (olddecl) && ! DECL_VCONTEXT (newdecl))
  1454.     DECL_VCONTEXT (newdecl) = DECL_VCONTEXT (olddecl);
  1455.       if (DECL_FIELD_CONTEXT (olddecl) && ! DECL_FIELD_CONTEXT (newdecl))
  1456.     DECL_FIELD_CONTEXT (newdecl) = DECL_FIELD_CONTEXT (olddecl);
  1457. #ifdef SOS
  1458.       if (DECL_DINDEX (olddecl) && ! DECL_DINDEX (newdecl))
  1459.     DECL_DINDEX (newdecl) = DECL_DINDEX (newdecl);
  1460. #endif
  1461.       if (DECL_PENDING_INLINE_INFO (newdecl) == 0)
  1462.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  1463.       DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
  1464.     }
  1465.  
  1466.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  1467.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl)
  1468.     /* If -traditional, avoid error for redeclaring fcn
  1469.        after implicit decl.  */
  1470.     ;
  1471.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1472.        && DECL_BUILT_IN (olddecl))
  1473.     {
  1474.       if (!types_match)
  1475.     error_with_decl (newdecl, "conflicting types for built-in function `%s'");
  1476.       else if (extra_warnings)
  1477.     warning_with_decl (newdecl, "built-in function `%s' redeclared");
  1478.     }
  1479.   else if (!types_match)
  1480.     {
  1481.       tree oldtype = TREE_TYPE (olddecl);
  1482.       tree newtype = TREE_TYPE (newdecl);
  1483.       int give_error = 0;
  1484.  
  1485.       /* Already complained about this, so don't do so again.  */
  1486.       if (current_class_type == NULL_TREE
  1487.       || IDENTIFIER_ERROR_LOCUS (DECL_NAME (newdecl)) != current_class_type)
  1488.     {
  1489.       give_error = 1;
  1490.       error_with_decl (newdecl, "conflicting types for `%s'");
  1491.     }
  1492.  
  1493.       /* Check for function type mismatch
  1494.      involving an empty arglist vs a nonempty one.  */
  1495.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1496.       && comptypes (TREE_TYPE (oldtype),
  1497.             TREE_TYPE (newtype), 1)
  1498.       && ((TYPE_ARG_TYPES (oldtype) == 0
  1499.            && DECL_INITIAL (olddecl) == 0)
  1500.           || (TYPE_ARG_TYPES (newtype) == 0
  1501.           && DECL_INITIAL (newdecl) == 0)))
  1502.     {
  1503.       /* Classify the problem further.  */
  1504.       register tree t = TYPE_ARG_TYPES (oldtype);
  1505.       if (t == 0)
  1506.         t = TYPE_ARG_TYPES (newtype);
  1507.       for (; t; t = TREE_CHAIN (t))
  1508.         {
  1509.           register tree type = TREE_VALUE (t);
  1510.  
  1511.           if (TREE_CHAIN (t) == 0 && type != void_type_node)
  1512.         {
  1513.           error ("A parameter list with an ellipsis can't match");
  1514.           error ("an empty parameter name list declaration.");
  1515.           break;
  1516.         }
  1517.  
  1518.           if (type == float_type_node
  1519.           || (TREE_CODE (type) == INTEGER_TYPE
  1520.               && (TYPE_PRECISION (type)
  1521.               < TYPE_PRECISION (integer_type_node))))
  1522.         {
  1523.           error ("An argument type that has a default promotion");
  1524.           error ("can't match an empty parameter name list declaration.");
  1525.           break;
  1526.         }
  1527.         }
  1528.     }
  1529.       if (give_error)
  1530.     error_with_decl (olddecl, "previous declaration of `%s'");
  1531.  
  1532.       /* There is one thing GNU C++ cannot tolerate: a constructor
  1533.      which takes the type of object being constructed.
  1534.      Farm that case out here.  */
  1535.       if (TREE_CODE (newdecl) == FUNCTION_DECL
  1536.       && DECL_CONSTRUCTOR_P (newdecl))
  1537.     {
  1538.       tree tmp = TREE_CHAIN (TYPE_ARG_TYPES (newtype));
  1539.  
  1540.       if (tmp != NULL_TREE
  1541.           && (TYPE_MAIN_VARIANT (TREE_VALUE (tmp))
  1542.           == TYPE_METHOD_BASETYPE (newtype)))
  1543.         {
  1544.           tree parm = TREE_CHAIN (DECL_ARGUMENTS (newdecl));
  1545.           tree argtypes
  1546.         = hash_tree_chain (build_reference_type (TREE_VALUE (tmp)),
  1547.                    TREE_CHAIN (tmp));
  1548.  
  1549.           DECL_ARG_TYPE (parm)
  1550.         = TREE_TYPE (parm)
  1551.           = TYPE_REFERENCE_TO (TREE_VALUE (tmp));
  1552.  
  1553.           TREE_TYPE (newdecl) = newtype
  1554.         = build_cplus_method_type (TYPE_METHOD_BASETYPE (newtype),
  1555.                        TREE_TYPE (newtype), argtypes);
  1556.           error ("constructor cannot take as argument the type being constructed");
  1557.           SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (newdecl), current_class_type);
  1558.         }
  1559.     }
  1560.     }
  1561.   else
  1562.     {
  1563.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  1564.       if (errmsg)
  1565.     {
  1566.       error_with_decl (newdecl, errmsg);
  1567.       if (DECL_LANG_SPECIFIC (olddecl)
  1568.           && DECL_COMPILER_GENERATED_P (olddecl))
  1569.         DECL_COMPILER_GENERATED_P (olddecl) = 0;
  1570.       else
  1571.         error_with_decl (olddecl,
  1572.                  "here is the previous declaration of `%s'");
  1573.     }
  1574.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1575.            && DECL_INITIAL (olddecl) != 0
  1576.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == 0
  1577.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != 0)
  1578.     {
  1579.       /* Prototype decl follows defn w/o prototype.  */
  1580.       warning_with_decl (newdecl, "prototype for `%s'");
  1581.       warning_with_decl (olddecl,
  1582.                  "follows non-prototype definition here");
  1583.     }
  1584.  
  1585.       /* These bits are logically part of the type.  */
  1586.       if (pedantic
  1587.       && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  1588.           || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
  1589.     error_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
  1590.     }
  1591.  
  1592.   /* Deal with C++: must preserve virtual function table size.  */
  1593.   if (TREE_CODE (olddecl) == TYPE_DECL)
  1594.     {
  1595.       if (TYPE_LANG_SPECIFIC (TREE_TYPE (newdecl))
  1596.           && TYPE_LANG_SPECIFIC (TREE_TYPE (olddecl)))
  1597.     {
  1598.       CLASSTYPE_VSIZE (TREE_TYPE (newdecl))
  1599.         = CLASSTYPE_VSIZE (TREE_TYPE (olddecl));
  1600.       CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (newdecl))
  1601.         = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (olddecl));
  1602.     }
  1603.     }
  1604.  
  1605.   new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
  1606.                && DECL_INITIAL (newdecl) != 0);
  1607.  
  1608.   /* Copy all the DECL_... slots specified in the new decl
  1609.      except for any that we copy here from the old type.  */
  1610.  
  1611.   if (types_match)
  1612.     {
  1613.       /* Automatically handles default parameters.  */
  1614.       tree oldtype = TREE_TYPE (olddecl);
  1615.       /* Merge the data types specified in the two decls.  */
  1616.       tree newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  1617.  
  1618.       if (TREE_CODE (newdecl) == VAR_DECL)
  1619.     DECL_EXTERNAL (newdecl) |= DECL_EXTERNAL (olddecl);
  1620.       /* Do this after calling `common_type' so that default
  1621.      parameters don't confuse us.  */
  1622.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  1623.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  1624.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  1625.     {
  1626.       tree ctype = NULL_TREE;
  1627.       if (TREE_CODE (newtype) == METHOD_TYPE)
  1628.         ctype = TYPE_METHOD_BASETYPE (newtype);
  1629.       else if (DECL_STATIC_FUNCTION_P (newdecl))
  1630.         ctype = DECL_STATIC_CONTEXT (newdecl);
  1631.       TREE_TYPE (newdecl) = build_exception_variant (ctype, newtype,
  1632.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  1633.       TREE_TYPE (olddecl) = build_exception_variant (ctype, newtype,
  1634.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  1635.  
  1636.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
  1637.         {
  1638.           error_with_decl (newdecl, "declaration of `%s' raises different exceptions...");
  1639.           error_with_decl (olddecl, "...from previous declaration here");
  1640.         }
  1641.     }
  1642.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  1643.  
  1644.       /* Lay the type out, unless already done.  */
  1645.       if (oldtype != TREE_TYPE (newdecl))
  1646.     {
  1647.       if (TREE_TYPE (newdecl) != error_mark_node)
  1648.         layout_type (TREE_TYPE (newdecl));
  1649.       if (TREE_CODE (newdecl) != FUNCTION_DECL
  1650.           && TREE_CODE (newdecl) != TYPE_DECL
  1651.           && TREE_CODE (newdecl) != CONST_DECL)
  1652.         layout_decl (newdecl, 0);
  1653.     }
  1654.       else
  1655.     {
  1656.       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
  1657.       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
  1658.     }
  1659.  
  1660.       /* Merge the type qualifiers.  */
  1661.       if (TREE_READONLY (newdecl))
  1662.     TREE_READONLY (olddecl) = 1;
  1663.       if (TREE_THIS_VOLATILE (newdecl))
  1664.     TREE_THIS_VOLATILE (olddecl) = 1;
  1665.  
  1666.       /* Merge the initialization information.  */
  1667.       if (DECL_INITIAL (newdecl) == 0)
  1668.     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1669.       /* Keep the old rtl since we can safely use it.  */
  1670.       DECL_RTL (newdecl) = DECL_RTL (olddecl);
  1671.     }
  1672.   /* If cannot merge, then use the new type and qualifiers,
  1673.      and don't preserve the old rtl.  */
  1674.   else
  1675.     {
  1676.       /* Clean out any memory we had of the old declaration.  */
  1677.       tree oldstatic = value_member (olddecl, static_aggregates);
  1678.       if (oldstatic)
  1679.     TREE_VALUE (oldstatic) = error_mark_node;
  1680.  
  1681.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  1682.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  1683.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  1684.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  1685.     }
  1686.  
  1687.   /* Merge the storage class information.  */
  1688.   if (TREE_EXTERNAL (newdecl))
  1689.     {
  1690.       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
  1691.       TREE_EXTERNAL (newdecl) = TREE_EXTERNAL (olddecl);
  1692.  
  1693.       /* For functions, static overrides non-static.  */
  1694.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1695.     {
  1696.       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
  1697.       /* This is since we don't automatically
  1698.          copy the attributes of NEWDECL into OLDDECL.  */
  1699.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1700.       /* If this clears `static', clear it in the identifier too.  */
  1701.       if (! TREE_PUBLIC (olddecl))
  1702.         TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
  1703.     }
  1704.       else
  1705.     TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  1706.     }
  1707.   else
  1708.     {
  1709.       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
  1710.       TREE_EXTERNAL (olddecl) = 0;
  1711.       /* A `const' which was not declared `extern' and is
  1712.      in static storage is invisible.  */
  1713.       if (TREE_CODE (newdecl) == VAR_DECL
  1714.       && TREE_READONLY (newdecl) && TREE_STATIC (newdecl)
  1715.       && ! DECL_EXTERNAL (newdecl))
  1716.     TREE_PUBLIC (newdecl) = 0;
  1717.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1718.     }
  1719.   /* If either decl says `inline', this fn is inline,
  1720.      unless its definition was passed already.  */
  1721.   TREE_INLINE (olddecl) |= TREE_INLINE (newdecl);
  1722.  
  1723.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1724.     {
  1725.       if (new_is_definition)
  1726.     /* If defining a function declared with other language
  1727.        linkage, use the previously declared language linkage.  */
  1728.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  1729.       else
  1730.     {
  1731.       /* If redeclaring a builtin function, and not a definition,
  1732.          it stays built in.  */
  1733.       if (DECL_BUILT_IN (olddecl))
  1734.         {
  1735.           DECL_BUILT_IN (newdecl) = 1;
  1736.           DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
  1737.         }
  1738.       else
  1739.         DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  1740.  
  1741.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  1742.       if (DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))
  1743.         /* Previously saved insns go together with
  1744.            the function's previous definition.  */
  1745.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1746. #if 0
  1747.       DECL_RESULT_TYPE (newdecl) = DECL_RESULT_TYPE (olddecl);
  1748. #endif
  1749.       DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  1750.     }
  1751.     }
  1752.  
  1753.   /* Now preserve various other info from the definition.  */
  1754.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  1755.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  1756.  
  1757.   /* Don't really know how much of the language-specific
  1758.      values we should copy from old to new.  */
  1759. #if 1
  1760.   if (DECL_LANG_SPECIFIC (olddecl))
  1761.     DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  1762. #endif
  1763.  
  1764.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1765.     {
  1766.       int function_size;
  1767.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  1768.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  1769.  
  1770.       function_size = sizeof (struct tree_decl);
  1771.  
  1772.       /* Don't lose track of having output OLDDECL as GDB symbol.  */
  1773.       DECL_BLOCK_SYMTAB_ADDRESS (newdecl)
  1774.     = DECL_BLOCK_SYMTAB_ADDRESS (olddecl);
  1775.  
  1776.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  1777.          (char *) olddecl + sizeof (struct tree_common),
  1778.          function_size - sizeof (struct tree_common));
  1779.  
  1780.       if ((char *)newdecl == obstack_next_free (&permanent_obstack)
  1781.       - (function_size + sizeof (struct lang_decl)))
  1782.     {
  1783.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  1784.       DECL_LANG_SPECIFIC (olddecl) = ol;
  1785.       bcopy (nl, ol, sizeof (struct lang_decl));
  1786.  
  1787.       obstack_free (&permanent_obstack, newdecl);
  1788.     }
  1789. #ifdef LANG_DECL_PERMANENT
  1790.       else if (LANG_DECL_PERMANENT (ol))
  1791.     {
  1792.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  1793.         {
  1794.           /* Save these lang_decls that would otherwise be lost.  */
  1795.           extern tree free_lang_decl_chain;
  1796.           tree free_lang_decl = (tree) ol;
  1797.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  1798.           free_lang_decl_chain = free_lang_decl;
  1799.         }
  1800.       else
  1801.         {
  1802.           /* Storage leak.  */
  1803.         }
  1804.     }
  1805. #else
  1806.       /* Storage leak.  */
  1807. #endif
  1808.     }
  1809.   else
  1810.     {
  1811.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  1812.          (char *) olddecl + sizeof (struct tree_common),
  1813.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  1814.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  1815.     }
  1816.  
  1817.   return 1;
  1818. }
  1819.  
  1820. void
  1821. adjust_type_value (id)
  1822.      tree id;
  1823. {
  1824.   tree t;
  1825.  
  1826.   if (current_binding_level != global_binding_level)
  1827.     {
  1828.       if (current_binding_level != class_binding_level)
  1829.     {
  1830.       t = IDENTIFIER_LOCAL_VALUE (id);
  1831.       if (t && TREE_CODE (t) == TYPE_DECL)
  1832.         {
  1833.         set_it:
  1834.           SET_IDENTIFIER_TYPE_VALUE (id, TREE_TYPE (t));
  1835.           return;
  1836.         }
  1837.     }
  1838.       else
  1839.     abort ();
  1840.  
  1841.       if (current_class_type)
  1842.     {
  1843.       t = IDENTIFIER_CLASS_VALUE (id);
  1844.       if (t && TREE_CODE (t) == TYPE_DECL)
  1845.         goto set_it;
  1846.     }
  1847.     }
  1848.  
  1849.   t = IDENTIFIER_GLOBAL_VALUE (id);
  1850.   if (t && TREE_CODE (t) == TYPE_DECL)
  1851.     goto set_it;
  1852.  
  1853.   SET_IDENTIFIER_TYPE_VALUE (id, NULL_TREE);
  1854. }
  1855.  
  1856. /* Record a decl-node X as belonging to the current lexical scope.
  1857.    Check for errors (such as an incompatible declaration for the same
  1858.    name already seen in the same scope).
  1859.  
  1860.    Returns either X or an old decl for the same name.
  1861.    If an old decl is returned, it may have been smashed
  1862.    to agree with what X says.  */
  1863.  
  1864. tree
  1865. pushdecl (x)
  1866.      tree x;
  1867. {
  1868.   static int nglobals; int len;
  1869.   register tree t;
  1870.   register tree name = DECL_NAME (x);
  1871.   register struct binding_level *b = current_binding_level;
  1872.  
  1873. #if 0
  1874.   len = list_length (global_binding_level->names);
  1875.   if (len < nglobals)
  1876.     abort ();
  1877.   else if (len > nglobals)
  1878.     nglobals = len;
  1879. #endif
  1880.  
  1881.   if (name)
  1882.     {
  1883.       char *file;
  1884.       int line;
  1885.  
  1886.       t = lookup_name_current_level (name);
  1887.       if (t != 0 && t == error_mark_node)
  1888.     /* error_mark_node is 0 for a while during initialization!  */
  1889.     {
  1890.       t = 0;
  1891.       error_with_decl (x, "`%s' used prior to declaration");
  1892.     }
  1893.  
  1894.       if (t != 0)
  1895.     {
  1896.       tree cntxt = t;
  1897.       if (TREE_CODE (t) == PARM_DECL)
  1898.         {
  1899.           if (DECL_CONTEXT (t) == NULL_TREE)
  1900.         fatal ("parse errors have confused me too much");
  1901.           cntxt = DECL_CONTEXT (t);
  1902.         }
  1903.       file = DECL_SOURCE_FILE (t);
  1904.       line = DECL_SOURCE_LINE (t);
  1905.     }
  1906.  
  1907.       if (t != 0 && TREE_CODE (t) != TREE_CODE (x))
  1908.     {
  1909.       if (TREE_CODE (t) == TYPE_DECL)
  1910.         {
  1911. #ifdef BREAK_C_TAGS
  1912.           ;
  1913. #else
  1914.           warning ("type declaration of %s shadowed",
  1915.                IDENTIFIER_POINTER (name));
  1916. #endif
  1917.         }
  1918.       else if (TREE_CODE (x) == TYPE_DECL)
  1919.         {
  1920. #ifdef BREAK_C_TAGS
  1921.           ;
  1922. #else
  1923.           warning ("type declaration of %s shadows previous declaration",
  1924.                IDENTIFIER_POINTER (name));
  1925. #endif
  1926.         }
  1927.       else if (duplicate_decls (x, t))
  1928.         return t;
  1929.     }
  1930.       else if (t != 0 && duplicate_decls (x, t))
  1931.     {
  1932.       /* If this decl is `static' and an `extern' was seen previously,
  1933.          that is erroneous.  But don't complain if -traditional,
  1934.          since traditional compilers don't complain.
  1935.  
  1936.          Note that this does not apply to the C++ case of declaring
  1937.          a variable `extern const' and then later `const'.  */
  1938.       if (!flag_traditional && TREE_PUBLIC (name)
  1939.           && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x) && ! TREE_INLINE (x))
  1940.         {
  1941.           /* Due to interference in memory reclamation (X may be
  1942.          obstack-deallocated at this point), we must guard against
  1943.          one really special case.  */
  1944.           if (current_function_decl == x)
  1945.         current_function_decl = t;
  1946.           if (IDENTIFIER_IMPLICIT_DECL (name))
  1947.         warning ("`%s' was declared implicitly `extern' and later `static'",
  1948.              lang_printable_name (t));
  1949.           else
  1950.         warning ("`%s' was declared `extern' and later `static'",
  1951.              lang_printable_name (t));
  1952.           warning_with_file_and_line (file, line,
  1953.                       "previous declaration of `%s'",
  1954.                       lang_printable_name (t));
  1955.         }
  1956.       return t;
  1957.     }
  1958.  
  1959.       /* If declaring a type as a typedef, and the type has no known
  1960.      typedef name, install this TYPE_DECL as its typedef name.
  1961.  
  1962.      C++: If it had an anonymous aggregate or enum name,
  1963.      give it a `better' one.  */
  1964.       if (TREE_CODE (x) == TYPE_DECL)
  1965.     {
  1966.       tree name = TYPE_NAME (TREE_TYPE (x));
  1967.  
  1968.       if (name == NULL_TREE
  1969.           || (TREE_CODE (name) != TYPE_DECL
  1970. #ifndef BREAK_C_TAGS
  1971.           && current_lang_name == lang_name_cplusplus
  1972. #endif
  1973.           ))
  1974.         {
  1975.           /* If these are different names, make two equivalent
  1976.          definitions.  */
  1977.           TYPE_NAME (TREE_TYPE (x)) = name = x;
  1978.         }
  1979.       else
  1980.         {
  1981.           tree tname = name;
  1982.           if (TREE_CODE (name) == TYPE_DECL)
  1983.         tname = DECL_NAME (name);
  1984.           if (ANON_AGGRNAME_P (tname))
  1985.         {
  1986.           /* do gratuitous C++ typedefing, and make sure that
  1987.              we access this type either through TREE_TYPE field
  1988.              or via the tags list.  */
  1989.           TYPE_NAME (TREE_TYPE (x)) = x;
  1990.           pushtag (tname, TREE_TYPE (x));
  1991.         }
  1992.         }
  1993.       assert (TREE_CODE (name) == TYPE_DECL);
  1994.       if (DECL_NAME (name) && !DECL_NESTED_TYPENAME (name))
  1995.         {
  1996.           set_nested_typename (x, current_class_name, DECL_NAME (name),
  1997.                    TREE_TYPE (x));
  1998.           SET_IDENTIFIER_TYPE_VALUE (TYPE_IDENTIFIER (TREE_TYPE (x)),
  1999.                      TREE_TYPE (x));
  2000.         }
  2001.     }
  2002.  
  2003.       /* Multiple external decls of the same identifier ought to match.  */
  2004.  
  2005.       if (TREE_EXTERNAL (x) && IDENTIFIER_GLOBAL_VALUE (name) != 0
  2006.       && (TREE_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  2007.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  2008.     {
  2009.       if (! comptypes (TREE_TYPE (x),
  2010.                TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name)), 1))
  2011.         {
  2012.           warning_with_decl (x,
  2013.                  "type mismatch with previous external decl");
  2014.           warning_with_decl (IDENTIFIER_GLOBAL_VALUE (name),
  2015.                  "previous external decl of `%s'");
  2016.         }
  2017.     }
  2018.  
  2019.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  2020.      take effect at top level no matter where they are.  */
  2021.       if (flag_traditional && TREE_EXTERNAL (x)
  2022.       && lookup_name (name) == 0)
  2023.     b = global_binding_level;
  2024.  
  2025.       /* This name is new in its binding level.
  2026.      Install the new declaration and return it.  */
  2027.       if (b == global_binding_level)
  2028.     {
  2029.       /* Install a global value.  */
  2030.  
  2031.       /* Rule for VAR_DECLs, but not for other kinds of _DECLs:
  2032.          A `const' which was not declared `extern' is invisible.  */
  2033.       if (TREE_CODE (x) == VAR_DECL
  2034.           && TREE_READONLY (x) && ! DECL_EXTERNAL (x))
  2035.         TREE_PUBLIC (x) = 0;
  2036.  
  2037.       /* If the first global decl has external linkage,
  2038.          warn if we later see static one.  */
  2039.       if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
  2040.         TREE_PUBLIC (name) = 1;
  2041.  
  2042.       IDENTIFIER_GLOBAL_VALUE (name) = x;
  2043.  
  2044.       /* Don't forget if the function was used via an implicit decl.  */
  2045.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2046.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  2047.         TREE_USED (x) = 1;
  2048.  
  2049.       /* Don't forget if its address was taken in that way.  */
  2050.       if (IDENTIFIER_IMPLICIT_DECL (name)
  2051.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  2052.         TREE_ADDRESSABLE (x) = 1;
  2053.  
  2054.       /* Warn about mismatches against previous implicit decl.  */
  2055.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  2056.           /* If this real decl matches the implicit, don't complain.  */
  2057.           && ! (TREE_CODE (x) == FUNCTION_DECL
  2058.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  2059.         warning ("`%s' was previously implicitly declared to return `int'",
  2060.              lang_printable_name (x));
  2061.  
  2062.       /* If this decl is `static' and an `extern' was seen previously,
  2063.          that is erroneous.  Don't do this for TYPE_DECLs.  */
  2064.       if (TREE_PUBLIC (name)
  2065.           && TREE_CODE (x) != TYPE_DECL
  2066.           && ! TREE_PUBLIC (x) && ! TREE_EXTERNAL (x))
  2067.         {
  2068.           if (IDENTIFIER_IMPLICIT_DECL (name))
  2069.         warning ("`%s' was declared implicitly `extern' and later `static'",
  2070.              lang_printable_name (x));
  2071.           else
  2072.         warning ("`%s' was declared `extern' and later `static'",
  2073.              lang_printable_name (x));
  2074.         }
  2075.     }
  2076.       else
  2077.     {
  2078.       /* Here to install a non-global value.  */
  2079.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  2080.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  2081.       IDENTIFIER_LOCAL_VALUE (name) = x;
  2082.  
  2083.       /* If this is an extern function declaration, see if we
  2084.          have a global definition for the function.  */
  2085.       if (oldlocal == 0
  2086.           && oldglobal != 0
  2087.           && TREE_CODE (x) == FUNCTION_DECL
  2088.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  2089.         {
  2090.           /* We have one.  Their types must agree.  */
  2091.           if (! comptypes (TREE_TYPE (x), TREE_TYPE (oldglobal), 1))
  2092.         warning_with_decl (x, "local declaration of `%s' doesn't match global one");
  2093.           /* If the global one is inline, make the local one inline.  */
  2094.           else if (TREE_INLINE (oldglobal)
  2095.                || DECL_BUILT_IN (oldglobal)
  2096.                || (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
  2097.                && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0))
  2098.         IDENTIFIER_LOCAL_VALUE (name) = oldglobal;
  2099.         }
  2100.       /* If we have a local external declaration,
  2101.          and no file-scope declaration has yet been seen,
  2102.          then if we later have a file-scope decl it must not be static.  */
  2103.       if (oldlocal == 0
  2104.           && oldglobal == 0
  2105.           && TREE_EXTERNAL (x)
  2106.           && TREE_PUBLIC (x))
  2107.         {
  2108.           TREE_PUBLIC (name) = 1;
  2109.         }
  2110.  
  2111.       if (TREE_INLINE (x))
  2112.         /* Inline decls shadow nothing.  */;
  2113.  
  2114.       /* Warn if shadowing an argument at the top level of the body.  */
  2115.       else if (oldlocal != 0 && !TREE_EXTERNAL (x)
  2116.           && TREE_CODE (oldlocal) == PARM_DECL
  2117.           && TREE_CODE (x) != PARM_DECL)
  2118.         {
  2119.           extern struct rtx_def *cleanup_label;
  2120.  
  2121.           /* Go to where the parms should be and see if we
  2122.          find them there.  */
  2123.           struct binding_level *b = current_binding_level->level_chain;
  2124.  
  2125.           if (cleanup_label)
  2126.         b = b->level_chain;
  2127.  
  2128.           if (b->parm_flag == 1)
  2129.         warning ("declaration of `%s' shadows a parameter",
  2130.              IDENTIFIER_POINTER (name));
  2131.         }
  2132.       /* Maybe warn if shadowing something else.  */
  2133.       else if (warn_shadow && !TREE_EXTERNAL (x))
  2134.         {
  2135.           char *warnstring = 0;
  2136.  
  2137.           if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
  2138.         warnstring = "declaration of `%s' shadows a parameter";
  2139.           else if (IDENTIFIER_CLASS_VALUE (name) != 0)
  2140.         warnstring = "declaration of `%s' shadows a member of `this'";
  2141.           else if (oldlocal != 0)
  2142.         warnstring = "declaration of `%s' shadows previous local";
  2143.           else if (oldglobal != 0)
  2144.         warnstring = "declaration of `%s' shadows global declaration";
  2145.  
  2146.           if (warnstring)
  2147.         warning (warnstring, IDENTIFIER_POINTER (name));
  2148.         }
  2149.  
  2150.       /* If storing a local value, there may already be one (inherited).
  2151.          If so, record it for restoration when this binding level ends.  */
  2152.       if (oldlocal != 0)
  2153.         b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  2154.     }
  2155.  
  2156.       /* Keep count of variables in this level with incomplete type.  */
  2157.       if (TREE_CODE (x) != TEMPLATE_DECL
  2158.       && TREE_CODE (x) != CPLUS_CATCH_DECL
  2159.       && TYPE_SIZE (TREE_TYPE (x)) == 0
  2160.       && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
  2161.     {
  2162.       if (++b->n_incomplete == 0)
  2163.         error ("too many incomplete variables at this point");
  2164.     }
  2165.     }
  2166.  
  2167.   if (TREE_CODE (x) == TYPE_DECL)
  2168.     {
  2169.       adjust_type_value (name);
  2170.       if (current_class_name)
  2171.     {
  2172.       if (!DECL_NESTED_TYPENAME (x))
  2173.         set_nested_typename (x, current_class_name, DECL_NAME (x),
  2174.                  TREE_TYPE (x));
  2175.       adjust_type_value (DECL_NESTED_TYPENAME (x));
  2176.     }
  2177.     }
  2178.  
  2179.   /* Put decls on list in reverse order.
  2180.      We will reverse them later if necessary.  */
  2181.   TREE_CHAIN (x) = b->names;
  2182.   b->names = x;
  2183.  
  2184.   return x;
  2185. }
  2186.  
  2187. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  2188.    if appropriate.  */
  2189. tree
  2190. pushdecl_top_level (x)
  2191.      tree x;
  2192. {
  2193.   register tree t;
  2194.   register struct binding_level *b = current_binding_level;
  2195.  
  2196.   current_binding_level = global_binding_level;
  2197.   t = pushdecl (x);
  2198.   current_binding_level = b;
  2199.   return t;
  2200. }
  2201.  
  2202. /* Make the declaration of X appear in CLASS scope.  */
  2203. tree
  2204. pushdecl_class_level (x)
  2205.      tree x;
  2206. {
  2207.   register tree name = DECL_NAME (x);
  2208.  
  2209.   if (name)
  2210.     {
  2211.       tree oldclass = IDENTIFIER_CLASS_VALUE (name);
  2212.       if (oldclass)
  2213.     class_binding_level->class_shadowed
  2214.       = tree_cons (name, oldclass, class_binding_level->class_shadowed);
  2215.       IDENTIFIER_CLASS_VALUE (name) = x;
  2216.       obstack_ptr_grow (&decl_obstack, x);
  2217.       if (TREE_CODE (x) == TYPE_DECL)
  2218.     set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
  2219.     }
  2220.   return x;
  2221. }
  2222.  
  2223. /* Tell caller how to interpret a TREE_LIST which contains
  2224.    chains of FUNCTION_DECLS.  */
  2225. int
  2226. overloaded_globals_p (list)
  2227.      tree list;
  2228. {
  2229.   assert (TREE_CODE (list) == TREE_LIST);
  2230.  
  2231.   /* Don't commit caller to seeing them as globals.  */
  2232.   if (TREE_NONLOCAL_FLAG (list))
  2233.     return -1;
  2234.   /* Do commit caller to seeing them as globals.  */
  2235.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  2236.     return 1;
  2237.   /* Do commit caller to not seeing them as globals.  */
  2238.   return 0;
  2239. }
  2240.  
  2241. /* DECL is a FUNCTION_DECL which may have other definitions already in place.
  2242.    We get around this by making IDENTIFIER_GLOBAL_VALUE (DECL_ORIGINAL_NAME (DECL))
  2243.    point to a list of all the things that want to be referenced by that name.
  2244.    It is then up to the users of that name to decide what to do with that
  2245.    list.  */
  2246. void
  2247. push_overloaded_decl (decl)
  2248.      tree decl;
  2249. {
  2250.   tree orig_name = DECL_ORIGINAL_NAME (decl);
  2251.   tree glob = IDENTIFIER_GLOBAL_VALUE (orig_name);
  2252.  
  2253.   DECL_OVERLOADED (decl) = 1;
  2254.   if (glob && TREE_CODE (glob) != TREE_LIST)
  2255.     {
  2256.       if (DECL_LANGUAGE (decl) == lang_c)
  2257.     {
  2258.       if (TREE_CODE (glob) == FUNCTION_DECL)
  2259.         {
  2260.           if (DECL_LANGUAGE (glob) == lang_c)
  2261.         {
  2262.           error_with_decl (decl, "C-language function `%s' overloaded here");
  2263.           error_with_decl (glob, "Previous C-language version of this function was `%s'");
  2264.         }
  2265.         }
  2266.       else abort ();
  2267.     }
  2268.       if (! flag_traditional
  2269.       && TREE_PERMANENT (glob) == 1
  2270.       && current_binding_level != global_binding_level)
  2271.     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  2272.       if (TREE_CODE (glob) == FUNCTION_DECL
  2273.       && DECL_LANGUAGE (glob) != DECL_LANGUAGE (decl)
  2274.       && comptypes (TREE_TYPE (glob), TREE_TYPE (decl), 1))
  2275.     {
  2276.       error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
  2277.       error_with_decl (glob, "conflicts with previous declaration here");
  2278.     }
  2279.       glob = tree_cons (DECL_NAME (glob), glob, NULL_TREE);
  2280.       glob = tree_cons (TREE_PURPOSE (glob), decl, glob);
  2281.       IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  2282.       TREE_TYPE (glob) = unknown_type_node;
  2283.       return;
  2284.     }
  2285.   if (glob)
  2286.     {
  2287.       tree tmp, name;
  2288.  
  2289.       if (TREE_VALUE (glob) == NULL_TREE)
  2290.     {
  2291.       TREE_VALUE (glob) = decl;
  2292.       return;
  2293.     }
  2294.       name = DECL_NAME (decl);
  2295.       for (tmp = glob; tmp; tmp = TREE_CHAIN (tmp))
  2296.     {
  2297.       if (TREE_CODE (TREE_VALUE (tmp)) == FUNCTION_DECL
  2298.           && DECL_LANGUAGE (TREE_VALUE (tmp)) != DECL_LANGUAGE (decl)
  2299.           && comptypes (TREE_TYPE (TREE_VALUE (tmp)), TREE_TYPE (decl), 1))
  2300.         {
  2301.           error_with_decl (decl, "conflicting language contexts for declaration of `%s';");
  2302.           error_with_decl (TREE_VALUE (tmp), "conflicts with previous declaration here");
  2303.         }
  2304.       if (DECL_NAME (TREE_VALUE (tmp)) == name)
  2305.         return;
  2306.     }
  2307.     }
  2308.  
  2309.   if (DECL_LANGUAGE (decl) == lang_c)
  2310.     {
  2311.       tree decls = glob;
  2312.       while (decls && DECL_LANGUAGE (TREE_VALUE (decls)) == lang_cplusplus)
  2313.     decls = TREE_CHAIN (decls);
  2314.       if (decls)
  2315.     {
  2316.       error_with_decl (decl, "C-language function `%s' overloaded here");
  2317.       error_with_decl (TREE_VALUE (decls), "Previous C-language version of this function was `%s'");
  2318.     }
  2319.     }
  2320.  
  2321.   if (! flag_traditional
  2322.       && (glob == 0 || TREE_PERMANENT (glob) == 1)
  2323.       && current_binding_level != global_binding_level)
  2324.     overloads_to_forget = tree_cons (orig_name, glob, overloads_to_forget);
  2325.   glob = tree_cons (orig_name, decl, glob);
  2326.   IDENTIFIER_GLOBAL_VALUE (orig_name) = glob;
  2327.   TREE_TYPE (glob) = unknown_type_node;
  2328. }
  2329.  
  2330. /* Generate an implicit declaration for identifier FUNCTIONID
  2331.    as a function of type int ().  Print a warning if appropriate.  */
  2332.  
  2333. tree
  2334. implicitly_declare (functionid)
  2335.      tree functionid;
  2336. {
  2337.   register tree decl;
  2338.   int temp = allocation_temporary_p ();
  2339.  
  2340.   /* Save the decl permanently so we can warn if definition follows.  */
  2341.   if (temp && (flag_traditional || !warn_implicit))
  2342.     end_temporary_allocation ();
  2343.  
  2344.   /* We used to reuse an old implicit decl here,
  2345.      but this loses with inline functions because it can clobber
  2346.      the saved decl chains.  */
  2347. /*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
  2348.     decl = IDENTIFIER_IMPLICIT_DECL (functionid);
  2349.   else  */
  2350.     decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  2351.  
  2352.   TREE_EXTERNAL (decl) = 1;
  2353.   TREE_PUBLIC (decl) = 1;
  2354.  
  2355.   /* ANSI standard says implicit declarations are in the innermost block.
  2356.      So we record the decl in the standard fashion.
  2357.      If flag_traditional is set, pushdecl does it top-level.  */
  2358.   pushdecl (decl);
  2359.   rest_of_decl_compilation (decl, 0, 0, 0);
  2360.  
  2361.   if (warn_implicit
  2362.       /* Only one warning per identifier.  */
  2363.       && IDENTIFIER_IMPLICIT_DECL (functionid) == 0)
  2364.     warning ("implicit declaration of function `%s'",
  2365.          IDENTIFIER_POINTER (functionid));
  2366.  
  2367.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  2368.  
  2369.   if (temp && (flag_traditional || ! warn_implicit))
  2370.     resume_temporary_allocation ();
  2371.  
  2372.   return decl;
  2373. }
  2374.  
  2375. /* Return zero if the declaration NEWDECL is valid
  2376.    when the declaration OLDDECL (assumed to be for the same name)
  2377.    has already been seen.
  2378.    Otherwise return an error message format string with a %s
  2379.    where the identifier should go.  */
  2380.  
  2381. static char *
  2382. redeclaration_error_message (newdecl, olddecl)
  2383.      tree newdecl, olddecl;
  2384. {
  2385.   if (TREE_CODE (newdecl) == TYPE_DECL)
  2386.     {
  2387.       /* Because C++ can put things into name space for free,
  2388.      constructs like "typedef struct foo { ... } foo"
  2389.      would look like an erroneous redeclaration.  */
  2390.       if (TREE_TYPE (olddecl) == TREE_TYPE (newdecl))
  2391.     return 0;
  2392.       else
  2393.     return "redefinition of `%s'";
  2394.     }
  2395.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2396.     {
  2397.       /* Declarations of functions can insist on internal linkage
  2398.      but they can't be inconsistent with internal linkage,
  2399.      so there can be no error on that account.
  2400.      However defining the same name twice is no good.  */
  2401.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
  2402.       /* However, defining once as extern inline and a second
  2403.          time in another way is ok.  */
  2404.       && !(TREE_INLINE (olddecl) && TREE_EXTERNAL (olddecl)
  2405.            && !(TREE_INLINE (newdecl) && TREE_EXTERNAL (newdecl))))
  2406.     {
  2407.       if (DECL_LANG_SPECIFIC (olddecl)
  2408.           && DECL_COMPILER_GENERATED_P (olddecl))
  2409.         return "`%s' not declared in class";
  2410.       else
  2411.         return "redefinition of `%s'";
  2412.     }
  2413.       return 0;
  2414.     }
  2415.   else if (current_binding_level == global_binding_level)
  2416.     {
  2417.       /* Objects declared at top level:  */
  2418.       /* If at least one is a reference, it's ok.  */
  2419.       if (TREE_EXTERNAL (newdecl) || TREE_EXTERNAL (olddecl))
  2420.     return 0;
  2421.       /* Reject two definitions.  */
  2422.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
  2423.     return "redefinition of `%s'";
  2424.       /* Now we have two tentative defs, or one tentative and one real def.  */
  2425.       /* Insist that the linkage match.  */
  2426.       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
  2427.     return "conflicting declarations of `%s'";
  2428.       return 0;
  2429.     }
  2430.   else
  2431.     {
  2432.       /* Objects declared with block scope:  */
  2433.       /* Reject two definitions, and reject a definition
  2434.      together with an external reference.  */
  2435.       if (!(TREE_EXTERNAL (newdecl) && TREE_EXTERNAL (olddecl)))
  2436.     return "redeclaration of `%s'";
  2437.       return 0;
  2438.     }
  2439. }
  2440.  
  2441. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  2442.    Create one if none exists so far for the current function.
  2443.    This function is called for both label definitions and label references.  */
  2444.  
  2445. tree
  2446. lookup_label (id)
  2447.      tree id;
  2448. {
  2449.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  2450.  
  2451.   if ((decl == 0
  2452.       || DECL_SOURCE_LINE (decl) == 0)
  2453.       && (named_label_uses == 0
  2454.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  2455.       || TREE_VALUE (named_label_uses) != decl))
  2456.     {
  2457.       named_label_uses
  2458.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  2459.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  2460.     }
  2461.  
  2462.   if (decl != 0)
  2463.     return decl;
  2464.  
  2465.   decl = build_decl (LABEL_DECL, id, void_type_node);
  2466.  
  2467.   /* A label not explicitly declared must be local to where it's ref'd.  */
  2468.   DECL_CONTEXT (decl) = current_function_decl;
  2469.  
  2470.   DECL_MODE (decl) = VOIDmode;
  2471.  
  2472.   /* Say where one reference is to the label,
  2473.      for the sake of the error if it is not defined.  */
  2474.   DECL_SOURCE_LINE (decl) = lineno;
  2475.   DECL_SOURCE_FILE (decl) = input_filename;
  2476.  
  2477.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  2478.  
  2479.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  2480.   TREE_VALUE (named_label_uses) = decl;
  2481.  
  2482.   return decl;
  2483. }
  2484.  
  2485. /* Define a label, specifying the location in the source file.
  2486.    Return the LABEL_DECL node for the label, if the definition is valid.
  2487.    Otherwise return 0.  */
  2488.  
  2489. tree
  2490. define_label (filename, line, name)
  2491.      char *filename;
  2492.      int line;
  2493.      tree name;
  2494. {
  2495.   tree decl = lookup_label (name);
  2496.  
  2497.   /* After labels, make any new cleanups go into their
  2498.      own new (temporary) binding contour.  */
  2499.   current_binding_level->more_cleanups_ok = 0;
  2500.  
  2501.   if (DECL_INITIAL (decl) != 0)
  2502.     {
  2503.       error_with_decl (decl, "duplicate label `%s'");
  2504.       return 0;
  2505.     }
  2506.   else
  2507.     {
  2508.       tree uses, prev;
  2509.  
  2510.       /* Mark label as having been defined.  */
  2511.       DECL_INITIAL (decl) = error_mark_node;
  2512.       /* Say where in the source.  */
  2513.       DECL_SOURCE_FILE (decl) = filename;
  2514.       DECL_SOURCE_LINE (decl) = line;
  2515.  
  2516.       for (prev = 0, uses = named_label_uses;
  2517.        uses;
  2518.        prev = uses, uses = TREE_CHAIN (uses))
  2519.     if (TREE_VALUE (uses) == decl)
  2520.       {
  2521.         struct binding_level *b = current_binding_level;
  2522.         while (1)
  2523.           {
  2524.         tree new_decls = b->names;
  2525.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  2526.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  2527.         while (new_decls != old_decls)
  2528.           {
  2529.             if (TREE_CODE (new_decls) == VAR_DECL
  2530.             /* Don't complain about crossing initialization
  2531.                of temporaries.  They can't be accessed,
  2532.                and they should be cleaned up
  2533.                by the time we get to the label.  */
  2534.             && ! TEMP_NAME_P (DECL_NAME (new_decls))
  2535.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  2536.                  && DECL_INITIAL (new_decls) != error_mark_node)
  2537.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  2538.               {
  2539.             if (IDENTIFIER_ERROR_LOCUS (decl) == NULL_TREE)
  2540.               error_with_decl (decl, "invalid jump to label `%s'");
  2541.             SET_IDENTIFIER_ERROR_LOCUS (decl, current_function_decl);
  2542.             error_with_decl (new_decls, "crosses initialization of `%s'");
  2543.               }
  2544.             new_decls = TREE_CHAIN (new_decls);
  2545.           }
  2546.         if ((tree)b == TREE_TYPE (uses))
  2547.           break;
  2548.         b = b->level_chain;
  2549.           }
  2550.  
  2551.         if (prev)
  2552.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  2553.         else
  2554.           named_label_uses = TREE_CHAIN (uses);
  2555.       }
  2556.       return decl;
  2557.     }
  2558. }
  2559.  
  2560. /* Same, but for CASE labels.  */
  2561. void
  2562. define_case_label (decl)
  2563.      tree decl;
  2564. {
  2565.   /* After labels, make any new cleanups go into their
  2566.      own new (temporary) binding contour.  */
  2567.  
  2568.   current_binding_level->more_cleanups_ok = 0;
  2569. }
  2570.  
  2571. /* Return the list of declarations of the current level.
  2572.    Note that this list is in reverse order unless/until
  2573.    you nreverse it; and when you do nreverse it, you must
  2574.    store the result back using `storedecls' or you will lose.  */
  2575.  
  2576. tree
  2577. getdecls ()
  2578. {
  2579.   return current_binding_level->names;
  2580. }
  2581.  
  2582. /* Return the list of type-tags (for structs, etc) of the current level.  */
  2583.  
  2584. tree
  2585. gettags ()
  2586. {
  2587.   return current_binding_level->tags;
  2588. }
  2589.  
  2590. /* Store the list of declarations of the current level.
  2591.    This is done for the parameter declarations of a function being defined,
  2592.    after they are modified in the light of any missing parameters.  */
  2593.  
  2594. static void
  2595. storedecls (decls)
  2596.      tree decls;
  2597. {
  2598.   current_binding_level->names = decls;
  2599. }
  2600.  
  2601. /* Similarly, store the list of tags of the current level.  */
  2602.  
  2603. static void
  2604. storetags (tags)
  2605.      tree tags;
  2606. {
  2607.   current_binding_level->tags = tags;
  2608. }
  2609.  
  2610. /* Given NAME, an IDENTIFIER_NODE,
  2611.    return the structure (or union or enum) definition for that name.
  2612.    Searches binding levels from BINDING_LEVEL up to the global level.
  2613.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  2614.    (but skips any tag-transparent contexts to find one that is
  2615.    meaningful for tags).
  2616.    FORM says which kind of type the caller wants;
  2617.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  2618.    If the wrong kind of type is found, and it's not a template, an error is
  2619.    reported.  */
  2620.  
  2621. static tree
  2622. lookup_tag (form, name, binding_level, thislevel_only)
  2623.      enum tree_code form;
  2624.      struct binding_level *binding_level;
  2625.      tree name;
  2626.      int thislevel_only;
  2627. {
  2628.   register struct binding_level *level;
  2629.  
  2630.   for (level = binding_level; level; level = level->level_chain)
  2631.     {
  2632.       register tree tail;
  2633.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2634.     {
  2635.       if (TREE_PURPOSE (tail) == name)
  2636.         {
  2637.           if (TREE_CODE (TREE_VALUE (tail)) != form
  2638.           && !(TREE_CODE (TREE_VALUE (tail)) == TEMPLATE_DECL
  2639.                && form == RECORD_TYPE))
  2640.         {
  2641.           /* Definition isn't the kind we were looking for.  */
  2642.           error ("`%s' defined as wrong kind of tag",
  2643.              IDENTIFIER_POINTER (name));
  2644.         }
  2645.           return TREE_VALUE (tail);
  2646.         }
  2647.     }
  2648.       if (thislevel_only && ! level->tag_transparent)
  2649.     return NULL_TREE;
  2650.       if (current_class_type && level->level_chain == global_binding_level)
  2651.     {
  2652.       /* Try looking in this class's tags before heading into
  2653.          global binding level.  */
  2654.       tree context = current_class_type;
  2655.       while (context)
  2656.         {
  2657.           tree these_tags = CLASSTYPE_TAGS (context);
  2658.           while (these_tags)
  2659.         {
  2660.           if (TREE_PURPOSE (these_tags) == name)
  2661.             {
  2662.               if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  2663.             {
  2664.               error ("`%s' defined as wrong kind of tag in class scope",
  2665.                  IDENTIFIER_POINTER (name));
  2666.             }
  2667.               return TREE_VALUE (tail);
  2668.             }
  2669.           these_tags = TREE_CHAIN (these_tags);
  2670.         }
  2671.           /* If this type is not yet complete, then don't
  2672.          look at its context.  */
  2673.           if (TYPE_SIZE (context) == NULL_TREE)
  2674.         break;
  2675.           /* Go to next enclosing type, if any.  */
  2676.           context = DECL_CONTEXT (TYPE_NAME (context));
  2677.         }
  2678.     }
  2679.     }
  2680.   return NULL_TREE;
  2681. }
  2682.  
  2683. void
  2684. set_current_level_tags_transparency (tags_transparent)
  2685. {
  2686.   current_binding_level->tag_transparent = tags_transparent;
  2687. }
  2688.  
  2689. /* Given a type, find the tag that was defined for it and return the tag name.
  2690.    Otherwise return 0.  However, the value can never be 0
  2691.    in the cases in which this is used.
  2692.  
  2693.    C++: If NAME is non-zero, this is the new name to install.  This is
  2694.    done when replacing anonymous tags with real tag names.  */
  2695.  
  2696. static tree
  2697. lookup_tag_reverse (type, name)
  2698.      tree type;
  2699.      tree name;
  2700. {
  2701.   register struct binding_level *level;
  2702.  
  2703.   for (level = current_binding_level; level; level = level->level_chain)
  2704.     {
  2705.       register tree tail;
  2706.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2707.     {
  2708.       if (TREE_VALUE (tail) == type)
  2709.         {
  2710.           if (name)
  2711.         TREE_PURPOSE (tail) = name;
  2712.           return TREE_PURPOSE (tail);
  2713.         }
  2714.     }
  2715.     }
  2716.   return NULL_TREE;
  2717. }
  2718.  
  2719. /* Given type TYPE which was not declared in C++ language context,
  2720.    attempt to find a name by which it is refered.  */
  2721. tree
  2722. typedecl_for_tag (tag)
  2723.      tree tag;
  2724. {
  2725.   struct binding_level *b = current_binding_level;
  2726.  
  2727.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  2728.     return TYPE_NAME (tag);
  2729.  
  2730.   while (b)
  2731.     {
  2732.       tree decls = b->names;
  2733.       while (decls)
  2734.     {
  2735.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  2736.         break;
  2737.       decls = TREE_CHAIN (decls);
  2738.     }
  2739.       if (decls)
  2740.     return decls;
  2741.       b = b->level_chain;
  2742.     }
  2743.   return NULL_TREE;
  2744. }
  2745.  
  2746. /* Called when we must retroactively globalize a type we previously
  2747.    thought needed to be nested.  This happenes, for example, when
  2748.    a `friend class' declaration is seen for an undefined type.  */
  2749.  
  2750. static void
  2751. globalize_nested_type (type)
  2752.      tree type;
  2753. {
  2754.   tree t, prev = NULL_TREE, d = TYPE_NAME (type);
  2755.   struct binding_level *b;
  2756.  
  2757.   assert (TREE_CODE (d) == TYPE_DECL);
  2758.   if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (d)) == d)
  2759.     return;
  2760.  
  2761.   SET_IDENTIFIER_TYPE_VALUE (DECL_NESTED_TYPENAME (d), NULL_TREE);
  2762.   DECL_NESTED_TYPENAME (d) = DECL_NAME (d);
  2763.   DECL_CONTEXT (d) = NULL_TREE;
  2764.   if (class_binding_level)
  2765.     b = class_binding_level;
  2766.   else
  2767.     b = current_binding_level;
  2768.   while (b != global_binding_level)
  2769.     {
  2770.       prev = NULL_TREE;
  2771.       if (b->parm_flag == 2)
  2772.     for (t = b->tags; t != NULL_TREE; prev = t, t = TREE_CHAIN (t))
  2773.       if (TREE_VALUE (t) == type)
  2774.         goto found;
  2775.       b = b->level_chain;
  2776.     }
  2777.   /* We failed to find this tag anywhere up the binding chains.  */
  2778.   abort ();
  2779.  
  2780.  found:
  2781.   /* Pull the tag out of the nested binding contour.  */
  2782.   if (prev)
  2783.     TREE_CHAIN (prev) = TREE_CHAIN (t);
  2784.   else
  2785.     b->tags = TREE_CHAIN (t);
  2786.   
  2787.   SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
  2788.   global_binding_level->tags
  2789.     = perm_tree_cons (TREE_PURPOSE (t), TREE_VALUE (t),
  2790.               global_binding_level->tags);
  2791.  
  2792.   /* Pull the tag out of the class's tags (if there).
  2793.      It won't show up if it appears e.g. in a parameter declaration
  2794.      or definition of a member function of this type.  */
  2795.   if (current_class_type != NULL_TREE)
  2796.     {
  2797.       for (t = CLASSTYPE_TAGS (current_class_type), prev = NULL_TREE;
  2798.        t != NULL_TREE;
  2799.        prev = t, t = TREE_CHAIN (t))
  2800.     if (TREE_VALUE (t) == type)
  2801.       break;
  2802.  
  2803.       if (t != NULL_TREE)
  2804.     {
  2805.       if (prev)
  2806.         TREE_CHAIN (prev) = TREE_CHAIN (t);
  2807.       else
  2808.         CLASSTYPE_TAGS (current_class_type) = TREE_CHAIN (t);
  2809.     }
  2810.     }
  2811.  
  2812.   pushdecl_top_level (d);
  2813. }
  2814.  
  2815. /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
  2816.    Return the type value, or NULL_TREE if not found.  */
  2817. static tree
  2818. lookup_nested_type (type, context)
  2819.      tree type;
  2820.      tree context;
  2821. {
  2822.   if (context == NULL_TREE)
  2823.     return NULL_TREE;
  2824.   if (TREE_CODE (context) == FUNCTION_DECL)
  2825.     return lookup_name (TYPE_IDENTIFIER (type));
  2826.   while (context)
  2827.     {
  2828.       tree ctype = TREE_TYPE (context);
  2829.       tree match = value_member (type, CLASSTYPE_TAGS (ctype));
  2830.       if (match)
  2831.     return TREE_VALUE (match);
  2832.       context = DECL_CONTEXT (context);
  2833.     }
  2834.   return NULL_TREE;
  2835. }
  2836.  
  2837. /* Look up NAME in the current binding level and its superiors
  2838.    in the namespace of variables, functions and typedefs.
  2839.    Return a ..._DECL node of some kind representing its definition,
  2840.    or return 0 if it is undefined.  */
  2841.  
  2842. tree
  2843. lookup_name (name)
  2844.      tree name;
  2845. {
  2846.   register tree val;
  2847.   if (current_binding_level != global_binding_level
  2848.       && IDENTIFIER_LOCAL_VALUE (name))
  2849.     val = IDENTIFIER_LOCAL_VALUE (name);
  2850.   /* In C++ class fields are between local and global scope,
  2851.      just before the global scope.  */
  2852.   else if (current_class_type)
  2853.     {
  2854.       if (IDENTIFIER_CLASS_VALUE (name))
  2855.     val = IDENTIFIER_CLASS_VALUE (name);
  2856.       else if (TYPE_SIZE (current_class_type) == 0
  2857.            && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  2858.     {
  2859.       /* Try to find values from base classes
  2860.          if we are presently defining a type.
  2861.          We are presently only interested in TYPE_DECLs.  */
  2862.       val = lookup_field (current_class_type, name, 0);
  2863.       if (val == error_mark_node)
  2864.         return val;
  2865.       if (val && TREE_CODE (val) != TYPE_DECL)
  2866.         val = NULL_TREE;
  2867.       else if (val == NULL_TREE)
  2868.         val = IDENTIFIER_GLOBAL_VALUE (name);
  2869.     }
  2870.       else
  2871.     val = IDENTIFIER_GLOBAL_VALUE (name);
  2872.     }
  2873.   else
  2874.     val = IDENTIFIER_GLOBAL_VALUE (name);
  2875.   if (val && TREE_TYPE (val) == error_mark_node)
  2876.     return error_mark_node;
  2877.   return val;
  2878. }
  2879.  
  2880. /* Similar to `lookup_name' but look only at current binding level.  */
  2881.  
  2882. static tree
  2883. lookup_name_current_level (name)
  2884.      tree name;
  2885. {
  2886.   register tree t;
  2887.  
  2888.   if (current_binding_level == global_binding_level)
  2889.     return IDENTIFIER_GLOBAL_VALUE (name);
  2890.  
  2891.   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
  2892.     return 0;
  2893.  
  2894.   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
  2895.     if (DECL_NAME (t) == name)
  2896.       break;
  2897.  
  2898.   return t;
  2899. }
  2900.  
  2901. static int sigsegv ()
  2902. {
  2903.   error ("Segmentation violation");
  2904.   signal (SIGSEGV, SIG_DFL);
  2905. }
  2906.  
  2907. /* Array for holding types considered "built-in".  These types
  2908.    are output in the module in which `main' is defined.  */
  2909. static tree *builtin_type_tdescs_arr;
  2910. static int builtin_type_tdescs_len, builtin_type_tdescs_max;
  2911.  
  2912. static void
  2913. record_builtin_type (rid_index, name, type)
  2914.      enum rid rid_index;
  2915.      char *name;
  2916.      tree type;
  2917. {
  2918.   tree tname;
  2919.  
  2920.   if (rid_index < RID_MAX)
  2921.     tname = ridpointers[(int) rid_index];
  2922.   else if (name)
  2923.     tname = get_identifier (name);
  2924.   else
  2925.     tname = 0;
  2926.  
  2927.   if (tname)
  2928.     {
  2929.       tree decl = pushdecl (build_decl (TYPE_DECL, tname, type));
  2930.       SET_IDENTIFIER_TYPE_VALUE (tname, NULL_TREE);
  2931.       if (rid_index < RID_MAX)
  2932.     IDENTIFIER_GLOBAL_VALUE (ridpointers[(int) rid_index]) = decl;
  2933.     }
  2934.  
  2935.   if (flag_dossier)
  2936.     {
  2937.       if (builtin_type_tdescs_len >= builtin_type_tdescs_max)
  2938.     {
  2939.       builtin_type_tdescs_max *= 2;
  2940.       builtin_type_tdescs_arr
  2941.         = (tree *)xrealloc (builtin_type_tdescs_arr,
  2942.                 builtin_type_tdescs_max);
  2943.     }
  2944.       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
  2945.       if (TREE_CODE (type) != POINTER_TYPE)
  2946.     {
  2947.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  2948.         = build_pointer_type (type);
  2949.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  2950.         = build_type_variant (TYPE_POINTER_TO (type), 1, 0);
  2951.     }
  2952.       if (TREE_CODE (type) != VOID_TYPE)
  2953.     {
  2954.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  2955.         = build_reference_type (type);
  2956.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  2957.         = build_type_variant (TYPE_REFERENCE_TO (type), 1, 0);
  2958.     }
  2959.     }
  2960. }
  2961.  
  2962. static void
  2963. output_builtin_tdesc_entries ()
  2964. {
  2965.   extern struct obstack permanent_obstack;
  2966.  
  2967.   /* If there's more than one main in this file, don't crash.  */
  2968.   if (builtin_type_tdescs_arr == 0)
  2969.     return;
  2970.  
  2971.   push_obstacks (&permanent_obstack, &permanent_obstack);
  2972.   while (builtin_type_tdescs_len > 0)
  2973.     {
  2974.       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
  2975.       tree tdesc = build_t_desc (type, 0);
  2976.       TREE_ASM_WRITTEN (tdesc) = 0;
  2977.       build_t_desc (type, 2);
  2978.     }
  2979.   free (builtin_type_tdescs_arr);
  2980.   builtin_type_tdescs_arr = 0;
  2981.   pop_obstacks ();
  2982. }
  2983.  
  2984. /* Create the predefined scalar types of C,
  2985.    and some nodes representing standard constants (0, 1, (void *)0).
  2986.    Initialize the global binding level.
  2987.    Make definitions for built-in primitive functions.  */
  2988.  
  2989. void
  2990. init_decl_processing ()
  2991. {
  2992.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  2993.   tree fields[20];
  2994.   /* Either char* or void*.  */
  2995.   tree traditional_ptr_type_node;
  2996.   /* Data type of memcpy.  */
  2997.   tree memcpy_ftype;
  2998.  
  2999.   /* Have to make these distinct before we try using them.  */
  3000.   lang_name_cplusplus = get_identifier ("C++");
  3001.   lang_name_c = get_identifier ("C");
  3002.   lang_name_objc = get_identifier ("Objective-C");
  3003.  
  3004.   /* Initially, C.  */
  3005.   current_lang_name = lang_name_c;
  3006.  
  3007.   current_function_decl = NULL_TREE;
  3008.   named_labels = NULL_TREE;
  3009.   named_label_uses = NULL_TREE;
  3010.   current_binding_level = NULL_BINDING_LEVEL;
  3011.   free_binding_level = NULL_BINDING_LEVEL;
  3012.  
  3013.   if (write_symbols == GDB_DEBUG)
  3014.     fatal ("GNU C++ does not support GDB symbol info, use -g");
  3015.  
  3016.   /* Handle signals.  */
  3017.   signal (SIGSEGV, sigsegv);
  3018.  
  3019.   gcc_obstack_init (&decl_obstack);
  3020.   if (flag_dossier)
  3021.     {
  3022.       builtin_type_tdescs_max = 100;
  3023.       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
  3024.     }
  3025.  
  3026.   /* Must lay these out before anything else gets laid out.  */
  3027.   error_mark_node = make_node (ERROR_MARK);
  3028.   TREE_PERMANENT (error_mark_node) = 1;
  3029.   TREE_TYPE (error_mark_node) = error_mark_node;
  3030.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  3031.   TREE_TYPE (error_mark_list) = error_mark_node;
  3032.  
  3033.   pushlevel (0);    /* make the binding_level structure for global names.  */
  3034.   global_binding_level = current_binding_level;
  3035.  
  3036.   value_identifier = get_identifier ("<value>");
  3037.   this_identifier = get_identifier (THIS_NAME);
  3038.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  3039.  
  3040.   /* Define `int' and `char' first so that dbx will output them first.  */
  3041.  
  3042.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  3043.   record_builtin_type (RID_INT, 0, integer_type_node);
  3044.  
  3045.   /* Define `char', which is like either `signed char' or `unsigned char'
  3046.      but not the same as either.  */
  3047.  
  3048.   char_type_node =
  3049.     (flag_signed_char
  3050.      ? make_signed_type (CHAR_TYPE_SIZE)
  3051.      : make_unsigned_type (CHAR_TYPE_SIZE));
  3052.   record_builtin_type (RID_CHAR, "char", char_type_node);
  3053.  
  3054.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  3055.   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
  3056.  
  3057.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  3058.   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
  3059.  
  3060.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  3061.   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
  3062.  
  3063.   /* `unsigned long' or `unsigned int' is the standard type for sizeof.
  3064.      Traditionally, use a signed type.  */
  3065.   if (INT_TYPE_SIZE != LONG_TYPE_SIZE)
  3066.     sizetype = flag_traditional ? long_integer_type_node : long_unsigned_type_node;
  3067.   else
  3068.     sizetype = flag_traditional ? integer_type_node : unsigned_type_node;
  3069.  
  3070.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  3071.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  3072.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  3073.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  3074.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  3075.  
  3076.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  3077.   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
  3078.  
  3079.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  3080.   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
  3081.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  3082.   record_builtin_type (RID_MAX, "unsigned short int", short_unsigned_type_node);
  3083.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  3084.   record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node);
  3085.  
  3086.   /* Define both `signed char' and `unsigned char'.  */
  3087.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  3088.   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
  3089.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  3090.   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
  3091.  
  3092.   float_type_node = make_node (REAL_TYPE);
  3093.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  3094.   record_builtin_type (RID_FLOAT, 0, float_type_node);
  3095.   layout_type (float_type_node);
  3096.  
  3097.   double_type_node = make_node (REAL_TYPE);
  3098.   if (flag_short_double)
  3099.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  3100.   else
  3101.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  3102.   record_builtin_type (RID_DOUBLE, 0, double_type_node);
  3103.   layout_type (double_type_node);
  3104.  
  3105.   long_double_type_node = make_node (REAL_TYPE);
  3106.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  3107.   record_builtin_type (RID_MAX, "long double", long_double_type_node);
  3108.   layout_type (long_double_type_node);
  3109.  
  3110.   signed_wchar_type_node = type_for_size (WCHAR_TYPE_SIZE, 0);
  3111.   unsigned_wchar_type_node = type_for_size (WCHAR_TYPE_SIZE, 1);
  3112.   wchar_type_node = type_for_size (WCHAR_TYPE_SIZE, WCHAR_UNSIGNED);
  3113.  
  3114.   integer_zero_node = build_int_2 (0, 0);
  3115.   TREE_TYPE (integer_zero_node) = integer_type_node;
  3116.   integer_one_node = build_int_2 (1, 0);
  3117.   TREE_TYPE (integer_one_node) = integer_type_node;
  3118.   integer_two_node = build_int_2 (2, 0);
  3119.   TREE_TYPE (integer_two_node) = integer_type_node;
  3120.   integer_three_node = build_int_2 (3, 0);
  3121.   TREE_TYPE (integer_three_node) = integer_type_node;
  3122.   empty_init_node = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
  3123.  
  3124.   size_zero_node = build_int_2 (0, 0);
  3125.   TREE_TYPE (size_zero_node) = sizetype;
  3126.   size_one_node = build_int_2 (1, 0);
  3127.   TREE_TYPE (size_one_node) = sizetype;
  3128.  
  3129.   void_type_node = make_node (VOID_TYPE);
  3130.   record_builtin_type (RID_VOID, 0, void_type_node);
  3131.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  3132.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  3133.   TREE_PARMLIST (void_list_node) = 1;
  3134.  
  3135.   null_pointer_node = build_int_2 (0, 0);
  3136.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  3137.   layout_type (TREE_TYPE (null_pointer_node));
  3138.  
  3139.   /* Used for expressions that do nothing, but are not errors.  */
  3140.   void_zero_node = build_int_2 (0, 0);
  3141.   TREE_TYPE (void_zero_node) = void_type_node;
  3142.  
  3143.   string_type_node = build_pointer_type (char_type_node);
  3144.   record_builtin_type (RID_MAX, 0, string_type_node);
  3145.  
  3146.   /* make a type for arrays of 256 characters.
  3147.      256 is picked randomly because we have a type for integers from 0 to 255.
  3148.      With luck nothing will ever really depend on the length of this
  3149.      array type.  */
  3150.   char_array_type_node
  3151.     = build_array_type (char_type_node, unsigned_char_type_node);
  3152.   /* Likewise for arrays of ints.  */
  3153.   int_array_type_node
  3154.     = build_array_type (integer_type_node, unsigned_char_type_node);
  3155.   /* This is for wide string constants.  */
  3156.   wchar_array_type_node
  3157.     = build_array_type (wchar_type_node, unsigned_char_type_node);
  3158.  
  3159.   /* This is just some anonymous class type.  Nobody should ever
  3160.      need to look inside this envelope.  */
  3161.   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
  3162.  
  3163.   default_function_type
  3164.     = build_function_type (integer_type_node, NULL_TREE);
  3165.   build_pointer_type (default_function_type);
  3166.  
  3167.   ptr_type_node = build_pointer_type (void_type_node);
  3168.   record_builtin_type (RID_MAX, 0, ptr_type_node);
  3169.   endlink = void_list_node;
  3170.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  3171.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  3172.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  3173.  
  3174.   double_ftype_double
  3175.     = build_function_type (double_type_node, double_endlink);
  3176.  
  3177.   double_ftype_double_double
  3178.     = build_function_type (double_type_node,
  3179.                tree_cons (NULL_TREE, double_type_node, double_endlink));
  3180.  
  3181.   int_ftype_int
  3182.     = build_function_type (integer_type_node, int_endlink);
  3183.  
  3184.   long_ftype_long
  3185.     = build_function_type (long_integer_type_node,
  3186.                tree_cons (NULL_TREE, long_integer_type_node, endlink));
  3187.  
  3188.   void_ftype_ptr_ptr_int
  3189.     = build_function_type (void_type_node,
  3190.                tree_cons (NULL_TREE, ptr_type_node,
  3191.                       tree_cons (NULL_TREE, ptr_type_node,
  3192.                          int_endlink)));
  3193.  
  3194.   int_ftype_cptr_cptr_sizet
  3195.     = build_function_type (integer_type_node,
  3196.                tree_cons (NULL_TREE, const_ptr_type_node,
  3197.                       tree_cons (NULL_TREE, const_ptr_type_node,
  3198.                          tree_cons (NULL_TREE,
  3199.                                 sizetype,
  3200.                                 endlink))));
  3201.  
  3202.   void_ftype_ptr_int_int
  3203.     = build_function_type (void_type_node,
  3204.                tree_cons (NULL_TREE, ptr_type_node,
  3205.                       tree_cons (NULL_TREE, integer_type_node,
  3206.                          int_endlink)));
  3207.  
  3208.   string_ftype_ptr_ptr        /* strcpy prototype */
  3209.     = build_function_type (string_type_node,
  3210.                tree_cons (NULL_TREE, string_type_node,
  3211.                       tree_cons (NULL_TREE,
  3212.                          const_string_type_node,
  3213.                          endlink)));
  3214.  
  3215.   int_ftype_string_string    /* strcmp prototype */
  3216.     = build_function_type (integer_type_node,
  3217.                tree_cons (NULL_TREE, const_string_type_node,
  3218.                       tree_cons (NULL_TREE,
  3219.                          const_string_type_node,
  3220.                          endlink)));
  3221.  
  3222.   traditional_ptr_type_node
  3223.     = (flag_traditional ? string_type_node : ptr_type_node);
  3224.  
  3225.   memcpy_ftype    /* memcpy prototype */
  3226.     = build_function_type (traditional_ptr_type_node,
  3227.                tree_cons (NULL_TREE, ptr_type_node,
  3228.                       tree_cons (NULL_TREE, const_ptr_type_node,
  3229.                          tree_cons (NULL_TREE,
  3230.                                 sizetype,
  3231.                                 endlink))));
  3232.  
  3233.   ptr_ftype_long /* builtin new prototype */
  3234.     = build_function_type (ptr_type_node, TYPE_ARG_TYPES (long_ftype_long));
  3235.  
  3236.   ptr_ftype_ptr_int_int_ptr /* builtin vec new prototype */
  3237.     = build_function_type (ptr_type_node,
  3238.                tree_cons (NULL_TREE, ptr_type_node,
  3239.                       tree_cons (NULL_TREE, integer_type_node,
  3240.                          tree_cons (NULL_TREE, integer_type_node,
  3241.                                 ptr_endlink))));
  3242.  
  3243.   void_ftype_ptr /* builtin deleted prototype */
  3244.     = build_function_type (void_type_node, ptr_endlink);
  3245.  
  3246.   void_ftype_ptr_int_int_ptr_int_int /* builtin vec delete prototype */
  3247.     = build_function_type (void_type_node,
  3248.        tree_cons (NULL_TREE, ptr_type_node,
  3249.           tree_cons (NULL_TREE, integer_type_node,
  3250.          tree_cons (NULL_TREE, integer_type_node,
  3251.                 TYPE_ARG_TYPES (void_ftype_ptr_int_int)))));
  3252.  
  3253. #ifdef VTABLE_USES_MASK
  3254.   /* This is primarily for virtual function definition.  We
  3255.      declare an array of `void *', which can later be
  3256.      converted to the appropriate function pointer type.
  3257.      To do pointers to members, we need a mask which can
  3258.      distinguish an index value into a virtual function table
  3259.      from an address.  */
  3260.   vtbl_mask = build_int_2 (~(VINDEX_MAX - 1), -1);
  3261. #endif
  3262.  
  3263.   vtbl_type_node
  3264.     = build_array_type (ptr_type_node, NULL_TREE);
  3265.   layout_type (vtbl_type_node);
  3266.   vtbl_type_node = build_type_variant (vtbl_type_node, 1, 0);
  3267.  
  3268.   builtin_function ("__builtin_constant_p",
  3269.             build_function_type (integer_type_node, endlink),
  3270.             BUILT_IN_CONSTANT_P, 0);
  3271.  
  3272.   builtin_function ("__builtin_alloca",
  3273.             build_function_type (ptr_type_node,
  3274.                      tree_cons (NULL_TREE,
  3275.                             sizetype,
  3276.                             endlink)),
  3277.             BUILT_IN_ALLOCA, "alloca");
  3278. #if 0
  3279.   builtin_function ("alloca",
  3280.             build_function_type (ptr_type_node,
  3281.                      tree_cons (NULL_TREE,
  3282.                             sizetype,
  3283.                             endlink)),
  3284.             BUILT_IN_ALLOCA, 0);
  3285. #endif
  3286.  
  3287.   builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, 0);
  3288.   builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, 0);
  3289.   builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, 0);
  3290.   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, 0);
  3291. #if 0
  3292.   /* This does not work well with libg++.  */
  3293.   builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, 0);
  3294.   builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, 0);
  3295.   builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, 0);
  3296. #endif
  3297.   builtin_function ("__builtin_saveregs", default_function_type,
  3298.             BUILT_IN_SAVEREGS, 0);
  3299. #ifdef EXPAND_BUILTIN_VARARGS
  3300.   builtin_function ("__builtin_varargs",
  3301.             build_function_type (ptr_type_node,
  3302.                      tree_cons (NULL_TREE,
  3303.                             integer_type_node,
  3304.                             endlink)),
  3305.             BUILT_IN_VARARGS, 0);
  3306. #endif
  3307.   builtin_function ("__builtin_classify_type", default_function_type,
  3308.             BUILT_IN_CLASSIFY_TYPE, 0);
  3309.   builtin_function ("__builtin_next_arg",
  3310.             build_function_type (ptr_type_node, endlink),
  3311.             BUILT_IN_NEXT_ARG, 0);
  3312.  
  3313.   /* Currently under experimentation.  */
  3314.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  3315.             BUILT_IN_MEMCPY, "memcpy");
  3316.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  3317.             BUILT_IN_MEMCMP, "memcmp");
  3318.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  3319.             BUILT_IN_STRCMP, "strcmp");
  3320.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  3321.             BUILT_IN_STRCPY, "strcpy");
  3322.  
  3323. #if 0
  3324. /* at least memcpy, on at least sun4, fails on a length of zero. */
  3325.   builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, 0);
  3326.   builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, 0);
  3327.   builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, 0);
  3328.   builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, 0);
  3329. #endif
  3330.  
  3331. #if 0
  3332.   /* Support for these has not been written in either expand_builtin
  3333.      or build_function_call.  */
  3334.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
  3335.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
  3336.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, 0);
  3337.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
  3338.   builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, 0);
  3339.   builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, 0);
  3340.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, 0);
  3341.   builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT, 0);
  3342.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, 0);
  3343.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, 0);
  3344. #endif
  3345.  
  3346.   /* C++ extensions */
  3347.  
  3348.   unknown_type_node = make_node (UNKNOWN_TYPE);
  3349.   pushdecl (build_decl (TYPE_DECL,
  3350.             get_identifier ("unknown type"),
  3351.             unknown_type_node));
  3352.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  3353.   TYPE_ALIGN (unknown_type_node) = 1;
  3354.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  3355.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  3356.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  3357.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result.  */
  3358.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  3359.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  3360.  
  3361.   /* Define these now, but use 0 as their DECL_FUNCTION_CODE.  This
  3362.      will install them in the global binding level, but cause them
  3363.      to be expanded normally.  */
  3364.   builtin_function ("__main", default_function_type, NOT_BUILT_IN, 0);
  3365.   pushdecl (lookup_name (get_identifier ("__main")));
  3366.  
  3367.   /* This is a hack that should go away when we deliver the
  3368.      real gc code.  */
  3369.   if (flag_gc)
  3370.     {
  3371.       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
  3372.       pushdecl (lookup_name (get_identifier ("__gc_main")));
  3373.     }
  3374.  
  3375.   /* Simplify life by making a "vtable_entry_type".  Give its
  3376.      fields names so that the debugger can use them.  */
  3377.  
  3378.   vtable_entry_type = make_lang_type (RECORD_TYPE);
  3379.   fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_DELTA_NAME), short_integer_type_node);
  3380.   fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_INDEX_NAME), short_integer_type_node);
  3381.   fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier (VTABLE_PFN_NAME), ptr_type_node);
  3382.   finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
  3383.                double_type_node);
  3384.  
  3385.   /* Make this part of an invisible union.  */
  3386.   fields[3] = copy_node (fields[2]);
  3387.   TREE_TYPE (fields[3]) = short_integer_type_node;
  3388.   DECL_NAME (fields[3]) = get_identifier (VTABLE_DELTA2_NAME);
  3389.   DECL_MODE (fields[3]) = TYPE_MODE (short_integer_type_node);
  3390.   DECL_SIZE (fields[3]) = TYPE_SIZE (short_integer_type_node);
  3391.   TREE_UNSIGNED (fields[3]) = 0;
  3392.   TREE_CHAIN (fields[2]) = fields[3];
  3393.   vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  3394.  
  3395.   if (flag_dossier)
  3396.     {
  3397.       /* Must build __t_desc type.  Currently, type descriptors look like this:
  3398.  
  3399.      struct __t_desc
  3400.      {
  3401.            const char *name;
  3402.        int size;
  3403.        int bits;
  3404.        struct __t_desc *points_to;
  3405.        struct __i_desc *ivars[];
  3406.        struct __m_desc *meths[];
  3407.        struct __t_desc *parents[];
  3408.        struct __t_desc *vbases[];
  3409.        int offsets[];
  3410.      };
  3411.  
  3412.      ...as per Linton's paper.  */
  3413.  
  3414.       __t_desc_type_node = make_lang_type (RECORD_TYPE);
  3415.       __i_desc_type_node = make_lang_type (RECORD_TYPE);
  3416.       __m_desc_type_node = make_lang_type (RECORD_TYPE);
  3417.       __t_desc_array_type = build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE);
  3418.       __i_desc_array_type = build_array_type (TYPE_POINTER_TO (__i_desc_type_node), NULL_TREE);
  3419.       __m_desc_array_type = build_array_type (TYPE_POINTER_TO (__m_desc_type_node), NULL_TREE);
  3420.  
  3421.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  3422.                      string_type_node);
  3423.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
  3424.                      unsigned_type_node);
  3425.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
  3426.                      unsigned_type_node);
  3427.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("points_to"),
  3428.                      TYPE_POINTER_TO (__t_desc_type_node));
  3429.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
  3430.                      build_pointer_type (__i_desc_array_type));
  3431.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
  3432.                      build_pointer_type (__m_desc_array_type));
  3433.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
  3434.                      build_pointer_type (__t_desc_array_type));
  3435.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
  3436.                      build_pointer_type (__t_desc_array_type));
  3437.       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
  3438.                      build_pointer_type (integer_type_node));
  3439.       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 8, integer_type_node);
  3440.  
  3441.       /* ivar descriptors look like this:
  3442.  
  3443.      struct __i_desc
  3444.      {
  3445.        const char *name;
  3446.        int offset;
  3447.        struct __t_desc *type;
  3448.      };
  3449.       */
  3450.  
  3451.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  3452.                      string_type_node);
  3453.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
  3454.                      integer_type_node);
  3455.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
  3456.                      TYPE_POINTER_TO (__t_desc_type_node));
  3457.       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2, integer_type_node);
  3458.  
  3459.       /* method descriptors look like this:
  3460.  
  3461.      struct __m_desc
  3462.      {
  3463.        const char *name;
  3464.        int vindex;
  3465.        struct __t_desc *vcontext;
  3466.        struct __t_desc *return_type;
  3467.        void (*address)();
  3468.        int parm_count;
  3469.        int required_parms;
  3470.        struct __t_desc *parm_types[];
  3471.      };
  3472.       */
  3473.  
  3474.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  3475.                      string_type_node);
  3476.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
  3477.                      integer_type_node);
  3478.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
  3479.                      TYPE_POINTER_TO (__t_desc_type_node));
  3480.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
  3481.                      TYPE_POINTER_TO (__t_desc_type_node));
  3482.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
  3483.                      build_pointer_type (default_function_type));
  3484.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
  3485.                      integer_type_node);
  3486.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
  3487.                      integer_type_node);
  3488.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
  3489.                      build_pointer_type (build_array_type (TYPE_POINTER_TO (__t_desc_type_node), NULL_TREE)));
  3490.       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7, integer_type_node);
  3491.     }
  3492.  
  3493. #ifdef SOS
  3494.   if (flag_all_virtual == 2)
  3495.     {
  3496.       tree ptr_ftype_default
  3497.         = build_function_type (ptr_type_node, NULL_TREE);
  3498.  
  3499.       builtin_function ("sosFindCode", ptr_ftype_default, NOT_BUILT_IN, 0);
  3500.       builtin_function ("sosLookup", ptr_ftype_default, NOT_BUILT_IN, 0);
  3501.       builtin_function ("sosImport", ptr_ftype_default, NOT_BUILT_IN, 0);
  3502.       builtin_function ("sosDynError", ptr_ftype_default, NOT_BUILT_IN, 0);
  3503.  
  3504.       zlink_type = make_lang_type (RECORD_TYPE);
  3505.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), string_type_node);
  3506.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("t"), char_type_node);
  3507.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), TYPE_POINTER_TO (default_function_type));
  3508.       finish_builtin_type (zlink_type, "__zlink", fields, 2, integer_type_node);
  3509.  
  3510.       zret_type = make_lang_type (RECORD_TYPE);
  3511.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("cn"), string_type_node);
  3512.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("ptr"), build_pointer_type (TYPE_POINTER_TO (default_function_type)));
  3513.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("n"), integer_type_node);
  3514.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("bcl"), string_type_node);
  3515.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("f"), char_type_node);
  3516.       finish_builtin_type (zret_type, "__zret", fields, 4, integer_type_node);
  3517.     }
  3518. #endif
  3519.  
  3520.   /* Now, C++.  */
  3521.   current_lang_name = lang_name_cplusplus;
  3522.   if (flag_dossier)
  3523.     {
  3524.       int i = builtin_type_tdescs_len;
  3525.       while (i > 0)
  3526.     {
  3527.       tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
  3528.       TREE_ASM_WRITTEN (tdesc) = 1;
  3529.       TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
  3530.     }
  3531.     }
  3532.  
  3533.   auto_function ("__builtin_new", ptr_ftype_long, NOT_BUILT_IN);
  3534.   auto_function ("__builtin_vec_new", ptr_ftype_ptr_int_int_ptr, NOT_BUILT_IN);
  3535.   auto_function ("__builtin_delete", void_ftype_ptr, NOT_BUILT_IN);
  3536.   auto_function ("__builtin_vec_delete", void_ftype_ptr_int_int_ptr_int_int, NOT_BUILT_IN);
  3537.  
  3538.   abort_fndecl
  3539.     = define_function ("abort",
  3540.                build_function_type (void_type_node, void_list_node),
  3541.                NOT_BUILT_IN, 0, 0);
  3542.  
  3543.   unhandled_exception_fndecl
  3544.     = define_function ("__unhandled_exception",
  3545.                build_function_type (void_type_node, NULL_TREE),
  3546.                NOT_BUILT_IN, 0, 0);
  3547.  
  3548.   /* Perform other language dependent initializations.  */
  3549.   init_class_processing ();
  3550.   init_init_processing ();
  3551.   init_search_processing ();
  3552.  
  3553.   if (flag_handle_exceptions)
  3554.     {
  3555.       init_exception_processing ();
  3556.       if (flag_handle_exceptions == 2)
  3557.     /* Too much trouble to inline all the trys needed for this.  */
  3558.     flag_this_is_variable = 2;
  3559.     }
  3560.   if (flag_gc)
  3561.     init_gc_processing ();
  3562.   if (flag_no_inline)
  3563.     flag_inline_functions = 0, flag_default_inline = 0;
  3564.   if (flag_cadillac)
  3565.     init_cadillac ();
  3566.  
  3567.   /* Warnings about failure to return values are too valuable to forego.  */
  3568.   warn_return_type = 1;
  3569. }
  3570.  
  3571. /* Make a definition for a builtin function named NAME and whose data type
  3572.    is TYPE.  TYPE should be a function type with argument types.
  3573.    FUNCTION_CODE tells later passes how to compile calls to this function.
  3574.    See tree.h for its possible values.
  3575.  
  3576.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  3577.    the name to be called if we can't opencode the function.  */
  3578.  
  3579. tree
  3580. define_function (name, type, function_code, pfn, library_name)
  3581.      char *name;
  3582.      tree type;
  3583.      enum built_in_function function_code;
  3584.      void (*pfn)();
  3585.      char *library_name;
  3586. {
  3587.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  3588.   TREE_EXTERNAL (decl) = 1;
  3589.   TREE_PUBLIC (decl) = 1;
  3590.   if (library_name)
  3591.     DECL_ASSEMBLER_NAME (decl) = library_name;
  3592.   make_function_rtl (decl);
  3593.   if (pfn) pfn (decl);
  3594.   if (function_code != NOT_BUILT_IN)
  3595.     {
  3596.       DECL_BUILT_IN (decl) = 1;
  3597.       DECL_SET_FUNCTION_CODE (decl, function_code);
  3598.     }
  3599.   return decl;
  3600. }
  3601.  
  3602. /* Called when a declaration is seen that contains no names to declare.
  3603.    If its type is a reference to a structure, union or enum inherited
  3604.    from a containing scope, shadow that tag name for the current scope
  3605.    with a forward reference.
  3606.    If its type defines a new named structure or union
  3607.    or defines an enum, it is valid but we need not do anything here.
  3608.    Otherwise, it is an error.
  3609.  
  3610.    C++: may have to grok the declspecs to learn about static,
  3611.    complain for anonymous unions.  */
  3612.  
  3613. void
  3614. shadow_tag (declspecs)
  3615.      tree declspecs;
  3616. {
  3617.   int found_tag = 0;
  3618.   int warned = 0;
  3619.   register tree link;
  3620.   register enum tree_code code, ok_code = ERROR_MARK;
  3621.   register tree t = NULL_TREE;
  3622.  
  3623.   for (link = declspecs; link; link = TREE_CHAIN (link))
  3624.     {
  3625.       register tree value = TREE_VALUE (link);
  3626.  
  3627.       code = TREE_CODE (value);
  3628.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  3629.     /* Used to test also that TYPE_SIZE (value) != 0.
  3630.        That caused warning for `struct foo;' at top level in the file.  */
  3631.     {
  3632.       register tree name = TYPE_NAME (value);
  3633.  
  3634.       if (name == NULL_TREE)
  3635.         name = lookup_tag_reverse (value, NULL_TREE);
  3636.  
  3637.       if (name && TREE_CODE (name) == TYPE_DECL)
  3638.         name = DECL_NAME (name);
  3639.  
  3640.       if (class_binding_level)
  3641.         t = lookup_tag (code, name, class_binding_level, 1);
  3642.       else
  3643.         t = lookup_tag (code, name, current_binding_level, 1);
  3644.  
  3645.       if (t == 0)
  3646.         {
  3647.           int temp = allocation_temporary_p ();
  3648.           if (temp)
  3649.         end_temporary_allocation ();
  3650.           if (IS_AGGR_TYPE_CODE (code))
  3651.         t = make_lang_type (code);
  3652.           else
  3653.         t = make_node (code);
  3654.           pushtag (name, t);
  3655.           if (temp)
  3656.         resume_temporary_allocation ();
  3657.           ok_code = code;
  3658.           break;
  3659.         }
  3660.       else if (name != 0 || code == ENUMERAL_TYPE)
  3661.         ok_code = code;
  3662.  
  3663.       if (ok_code != ERROR_MARK)
  3664.         found_tag++;
  3665.       else
  3666.         {
  3667.           if (!warned)
  3668.         warning ("useless keyword or type name in declaration");
  3669.           warned = 1;
  3670.         }
  3671.     }
  3672.     }
  3673.  
  3674.   /* This is where the variables in an anonymous union are
  3675.      declared.  An anonymous union declaration looks like:
  3676.      union { ... } ;
  3677.      because there is no declarator after the union, the parser
  3678.      sends that declaration here.  */
  3679.   if (ok_code == UNION_TYPE
  3680.       && t != NULL_TREE
  3681.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  3682.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  3683.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  3684.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))))
  3685.       && TYPE_FIELDS (t))
  3686.     {
  3687.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE);
  3688.       finish_anon_union (decl);
  3689.     }
  3690.   else if (ok_code == RECORD_TYPE
  3691.        && found_tag == 1
  3692.        && TYPE_LANG_SPECIFIC (t)
  3693.        && CLASSTYPE_DECLARED_EXCEPTION (t))
  3694.     {
  3695.       if (TYPE_SIZE (t))
  3696.     error_with_aggr_type (t, "redeclaration of exception `%s'");
  3697.       else
  3698.     {
  3699.       tree ename, decl;
  3700.       int temp = allocation_temporary_p ();
  3701.       int momentary = suspend_momentary ();
  3702.       if (temp)
  3703.         end_temporary_allocation ();
  3704.  
  3705.       pushclass (t, 0);
  3706.       finish_exception (t, NULL_TREE);
  3707.  
  3708.       ename = TYPE_NAME (t);
  3709.       if (TREE_CODE (ename) == TYPE_DECL)
  3710.         ename = DECL_NAME (ename);
  3711.       decl = build_lang_field_decl (VAR_DECL, ename, t);
  3712.       finish_exception_decl (current_class_name, decl);
  3713.       end_exception_decls ();
  3714.  
  3715.       if (temp)
  3716.         resume_temporary_allocation ();
  3717.       if (momentary)
  3718.         resume_momentary ();
  3719.     }
  3720.     }
  3721.   else if (!warned)
  3722.     {
  3723.       if (found_tag > 1)
  3724.     warning ("multiple types in one declaration");
  3725.       if (found_tag == 0)
  3726.     warning ("empty declaration");
  3727.     }
  3728. }
  3729.  
  3730. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  3731.  
  3732. tree
  3733. groktypename (typename)
  3734.      tree typename;
  3735. {
  3736.   if (TREE_CODE (typename) != TREE_LIST)
  3737.     return typename;
  3738.   return grokdeclarator (TREE_VALUE (typename),
  3739.              TREE_PURPOSE (typename),
  3740.              TYPENAME, 0, NULL_TREE);
  3741. }
  3742.  
  3743. /* Return a PARM_DECL node for a given pair of specs and declarator.  */
  3744.  
  3745. tree
  3746. groktypename_in_parm_context (typename)
  3747.      tree typename;
  3748. {
  3749.   if (TREE_CODE (typename) != TREE_LIST)
  3750.     return typename;
  3751.   return grokdeclarator (TREE_VALUE (typename),
  3752.              TREE_PURPOSE (typename),
  3753.              PARM, 0, NULL_TREE);
  3754. }
  3755.  
  3756. /* Decode a declarator in an ordinary declaration or data definition.
  3757.    This is called as soon as the type information and variable name
  3758.    have been parsed, before parsing the initializer if any.
  3759.    Here we create the ..._DECL node, fill in its type,
  3760.    and put it on the list of decls for the current context.
  3761.    The ..._DECL node is returned as the value.
  3762.  
  3763.    Exception: for arrays where the length is not specified,
  3764.    the type is left null, to be filled in by `finish_decl'.
  3765.  
  3766.    Function definitions do not come here; they go to start_function
  3767.    instead.  However, external and forward declarations of functions
  3768.    do go through here.  Structure field declarations are done by
  3769.    grokfield and not through here.  */
  3770.  
  3771. /* Set this to zero to debug not using the temporary obstack
  3772.    to parse initializers.  */
  3773. int debug_temp_inits = 1;
  3774.  
  3775. tree
  3776. start_decl (declarator, declspecs, initialized, raises)
  3777.      tree declspecs, declarator;
  3778.      int initialized;
  3779.      tree raises;
  3780. {
  3781.   register tree decl = grokdeclarator (declarator, declspecs,
  3782.                        NORMAL, initialized, raises);
  3783.   register tree type, tem;
  3784.   int init_written = initialized;
  3785.  
  3786.   if (decl == NULL_TREE) return decl;
  3787.  
  3788.   type = TREE_TYPE (decl);
  3789.  
  3790.   /* Don't lose if destructors must be executed at file-level.  */
  3791.   if (TREE_STATIC (decl)
  3792.       && TYPE_NEEDS_DESTRUCTOR (type)
  3793.       && TREE_PERMANENT (decl) == 0)
  3794.     {
  3795.       end_temporary_allocation ();
  3796.       decl = copy_node (decl);
  3797.       if (TREE_CODE (type) == ARRAY_TYPE)
  3798.     {
  3799.       tree itype = TYPE_DOMAIN (type);
  3800.       if (itype && ! TREE_PERMANENT (itype))
  3801.         {
  3802.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  3803.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  3804.           TREE_TYPE (decl) = type;
  3805.         }
  3806.     }
  3807.       resume_temporary_allocation ();
  3808.     }
  3809.  
  3810.   /* Interesting work for this is done in `finish_exception_decl'.  */
  3811.   if (TREE_CODE (type) == RECORD_TYPE
  3812.       && CLASSTYPE_DECLARED_EXCEPTION (type))
  3813.     return decl;
  3814.  
  3815.   if (DECL_CONTEXT (decl))
  3816.     {
  3817.       /* If it was not explicitly declared `extern',
  3818.      revoke any previous claims of TREE_EXTERNAL.  */
  3819.       if (DECL_EXTERNAL (decl) == 0)
  3820.     TREE_EXTERNAL (decl) = 0;
  3821.       if (DECL_LANG_SPECIFIC (decl))
  3822.     DECL_IN_AGGR_P (decl) = 0;
  3823.       pushclass (DECL_CONTEXT (decl), 2);
  3824.     }
  3825.  
  3826.   /* If this type of object needs a cleanup, and control may
  3827.      jump past it, make a new binding level so that it is cleaned
  3828.      up only when it is initialized first.  */
  3829.   if (TYPE_NEEDS_DESTRUCTOR (type)
  3830.       && current_binding_level->more_cleanups_ok == 0)
  3831.     pushlevel_temporary (1);
  3832.  
  3833.   if (initialized)
  3834.     /* Is it valid for this decl to have an initializer at all?
  3835.        If not, set INITIALIZED to zero, which will indirectly
  3836.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  3837.     switch (TREE_CODE (decl))
  3838.       {
  3839.       case TYPE_DECL:
  3840.     /* typedef foo = bar  means give foo the same type as bar.
  3841.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  3842.        Any other case of an initialization in a TYPE_DECL is an error.  */
  3843.     if (pedantic || list_length (declspecs) > 1)
  3844.       {
  3845.         error ("typedef `%s' is initialized",
  3846.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3847.         initialized = 0;
  3848.       }
  3849.     break;
  3850.  
  3851.       case FUNCTION_DECL:
  3852.     error ("function `%s' is initialized like a variable",
  3853.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3854.     initialized = 0;
  3855.     break;
  3856.  
  3857.       default:
  3858.     /* Don't allow initializations for incomplete types
  3859.        except for arrays which might be completed by the initialization.  */
  3860.     if (TYPE_SIZE (type) != 0)
  3861.       ;                     /* A complete type is ok.  */
  3862.     else if (TREE_CODE (type) != ARRAY_TYPE)
  3863.       {
  3864.         error ("variable `%s' has initializer but incomplete type",
  3865.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3866.         initialized = 0;
  3867.       }
  3868.     else if (TYPE_SIZE (TREE_TYPE (type)) == 0)
  3869.       {
  3870.         error ("elements of array `%s' have incomplete type",
  3871.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3872.         initialized = 0;
  3873.       }
  3874.       }
  3875.  
  3876.   if (!initialized && TREE_CODE (decl) != TYPE_DECL
  3877.       && IS_AGGR_TYPE (type) && ! TREE_EXTERNAL (decl))
  3878.     {
  3879.       if (TYPE_SIZE (type) == 0)
  3880.     {
  3881.       error ("aggregate `%s' has incomplete type and cannot be initialized",
  3882.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  3883.       /* Change the type so that assemble_variable will give
  3884.          DECL an rtl we can live with: (mem (const_int 0)).  */
  3885.       TREE_TYPE (decl) = error_mark_node;
  3886.       type = error_mark_node;
  3887.     }
  3888.       else
  3889.     {
  3890.       /* If any base type in the hierarchy of TYPE needs a constructor,
  3891.          then we set initialized to 1.  This way any nodes which are
  3892.          created for the purposes of initializing this aggregate
  3893.          will live as long as it does.  This is necessary for global
  3894.          aggregates which do not have their initializers processed until
  3895.          the end of the file.  */
  3896.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  3897.     }
  3898.     }
  3899.  
  3900.   if (initialized)
  3901.     {
  3902.       if (current_binding_level != global_binding_level
  3903.       && TREE_EXTERNAL (decl))
  3904.     warning ("declaration of `%s' has `extern' and is initialized",
  3905.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  3906.       TREE_EXTERNAL (decl) = 0;
  3907.       if (current_binding_level == global_binding_level)
  3908.     TREE_STATIC (decl) = 1;
  3909.  
  3910.       /* Tell `pushdecl' this is an initialized decl
  3911.      even though we don't yet have the initializer expression.
  3912.      Also tell `finish_decl' it may store the real initializer.  */
  3913.       DECL_INITIAL (decl) = error_mark_node;
  3914.     }
  3915.  
  3916.   /* Add this decl to the current binding level, but not if it
  3917.      comes from another scope, e.g. a static member variable.
  3918.      TEM may equal DECL or it may be a previous decl of the same name.  */
  3919.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  3920.       || TREE_CODE (type) == LANG_TYPE)
  3921.     tem = decl;
  3922.   else
  3923.     {
  3924.       tem = pushdecl (decl);
  3925.       if (TREE_CODE (tem) == TREE_LIST)
  3926.     {
  3927.       tree tem2 = value_member (decl, tem);
  3928.       if (tem2 != NULL_TREE)
  3929.         tem = TREE_VALUE (tem2);
  3930.       else
  3931.         {
  3932.           while (tem && ! decls_match (decl, TREE_VALUE (tem)))
  3933.         tem = TREE_CHAIN (tem);
  3934.           if (tem == NULL_TREE)
  3935.         tem = decl;
  3936.           else
  3937.         tem = TREE_VALUE (tem);
  3938.         }
  3939.     }
  3940.     }
  3941.  
  3942. #if 0
  3943.   /* We don't do this yet for GNU C++.  */
  3944.   /* For a local variable, define the RTL now.  */
  3945.   if (current_binding_level != global_binding_level
  3946.       /* But not if this is a duplicate decl
  3947.      and we preserved the rtl from the previous one
  3948.      (which may or may not happen).  */
  3949.       && DECL_RTL (tem) == 0)
  3950.     {
  3951.       if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
  3952.     expand_decl (tem);
  3953.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  3954.            && DECL_INITIAL (tem) != 0)
  3955.     expand_decl (tem);
  3956.     }
  3957. #endif
  3958.  
  3959.     if (TREE_CODE (decl) == FUNCTION_DECL && DECL_OVERLOADED (decl))
  3960.       /* @@ Also done in start_function.  */
  3961.       push_overloaded_decl (tem);
  3962.  
  3963.   if (init_written
  3964.       && ! (TREE_CODE (tem) == PARM_DECL
  3965.         || (TREE_READONLY (tem)
  3966.         && (TREE_CODE (tem) == VAR_DECL
  3967.             || TREE_CODE (tem) == FIELD_DECL))))
  3968.     {
  3969.       /* When parsing and digesting the initializer,
  3970.      use temporary storage.  Do this even if we will ignore the value.  */
  3971.       if (current_binding_level == global_binding_level && debug_temp_inits)
  3972.     {
  3973.       if (TYPE_NEEDS_CONSTRUCTING (type))
  3974.         /* In this case, the initializer must lay down in permanent
  3975.            storage, since it will be saved until `finish_file' is run.   */
  3976.         ;
  3977.       else
  3978.         temporary_allocation ();
  3979.     }
  3980.     }
  3981.  
  3982.   if (flag_cadillac)
  3983.     cadillac_start_decl (tem);
  3984.  
  3985.   return tem;
  3986. }
  3987.  
  3988. /* Handle initialization of references.
  3989.    These three arguments from from `finish_decl', and have the
  3990.    same meaning here that they do there.  */
  3991. static void
  3992. grok_reference_init (decl, type, init, cleanupp)
  3993.      tree decl, type, init;
  3994.      tree *cleanupp;
  3995. {
  3996.   char *errstr = 0;
  3997.   int is_reference;
  3998.   tree tmp;
  3999.   tree this_ptr_type, actual_init;
  4000.  
  4001.   if (init == NULL_TREE)
  4002.     {
  4003.       if (DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0)
  4004.     {
  4005.       error ("variable declared as reference not initialized");
  4006.       if (TREE_CODE (decl) == VAR_DECL)
  4007.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  4008.     }
  4009.       return;
  4010.     }
  4011.  
  4012.   if (TREE_CODE (init) == TREE_LIST)
  4013.     init = build_compound_expr (init);
  4014.   is_reference = TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE;
  4015.   tmp = is_reference ? convert_from_reference (init) : init;
  4016.  
  4017.   if (is_reference)
  4018.     {
  4019.       if (! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  4020.                TYPE_MAIN_VARIANT (TREE_TYPE (tmp)), 0))
  4021.     errstr = "initialization of `%s' from dissimilar reference type";
  4022.       else if (TYPE_READONLY (TREE_TYPE (type))
  4023.            >= TYPE_READONLY (TREE_TYPE (TREE_TYPE (init))))
  4024.     {
  4025.       is_reference = 0;
  4026.       init = tmp;
  4027.     }
  4028.     }
  4029.   else
  4030.     {
  4031.       if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  4032.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  4033.     {
  4034.       /* Note: default conversion is only called in very
  4035.          special cases.  */
  4036.       init = default_conversion (init);
  4037.     }
  4038.       if (TREE_CODE (TREE_TYPE (type)) == TREE_CODE (TREE_TYPE (init)))
  4039.     {
  4040.       init = convert (TREE_TYPE (type), init);
  4041.     }
  4042.       else if (init != error_mark_node
  4043.            && ! comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (type)),
  4044.                    TYPE_MAIN_VARIANT (TREE_TYPE (init)), 0))
  4045.     errstr = "invalid type conversion for reference";
  4046.     }
  4047.  
  4048.   if (errstr)
  4049.     {
  4050.       /* Things did not go smoothly; look for type conversion.  */
  4051.       if (IS_AGGR_TYPE (TREE_TYPE (tmp)))
  4052.     {
  4053.       tmp = build_type_conversion (CONVERT_EXPR, type, init, 0);
  4054.       if (tmp != NULL_TREE)
  4055.         {
  4056.           init = tmp;
  4057.           if (tmp == error_mark_node)
  4058.         errstr = "ambiguous pointer conversion";
  4059.           else
  4060.         errstr = 0;
  4061.           is_reference = 1;
  4062.         }
  4063.       else
  4064.         {
  4065.           tmp = build_type_conversion (CONVERT_EXPR, TREE_TYPE (type), init, 0);
  4066.           if (tmp != NULL_TREE)
  4067.         {
  4068.           init = tmp;
  4069.           if (tmp == error_mark_node)
  4070.             errstr = "ambiguous pointer conversion";
  4071.           else
  4072.             errstr = 0;
  4073.           is_reference = 0;
  4074.         }
  4075.         }
  4076.     }
  4077.     }
  4078.  
  4079.   if (errstr)
  4080.     {
  4081.       error_with_decl (decl, errstr);
  4082.       if (TREE_CODE (decl) == VAR_DECL)
  4083.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  4084.       return;
  4085.     }
  4086.  
  4087.   /* In the case of initialization, it is permissable
  4088.      to assign one reference to another.  */
  4089.   this_ptr_type = build_pointer_type (TREE_TYPE (type));
  4090.  
  4091.   if (is_reference)
  4092.     {
  4093.       if (TREE_SIDE_EFFECTS (init))
  4094.     DECL_INITIAL (decl) = save_expr (init);
  4095.       else
  4096.     DECL_INITIAL (decl) = init;
  4097.     }
  4098.   else if (lvalue_p (init))
  4099.     {
  4100.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), build_unary_op (ADDR_EXPR, init, 0));
  4101.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  4102.       if (DECL_INITIAL (decl) == current_class_decl)
  4103.     DECL_INITIAL (decl) = copy_node (current_class_decl);
  4104.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  4105.     }
  4106.   else if ((actual_init = unary_complex_lvalue (ADDR_EXPR, init)))
  4107.     {
  4108.       /* The initializer for this decl goes into its
  4109.      DECL_REFERENCE_SLOT.  Make sure that we can handle
  4110.      multiple evaluations without ill effect.  */
  4111.       if (TREE_CODE (actual_init) == ADDR_EXPR
  4112.       && TREE_CODE (TREE_OPERAND (actual_init, 0)) == TARGET_EXPR)
  4113.     actual_init = save_expr (actual_init);
  4114.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), actual_init);
  4115.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  4116.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  4117.     }
  4118.   else if (TYPE_READONLY (TREE_TYPE (type)))
  4119.     /* Section 8.4.3 allows us to make a temporary for
  4120.        the initialization of const&.  */
  4121.     {
  4122.       tree target_type = TREE_TYPE (type);
  4123.       tree tmp_addr;
  4124.       tmp = get_temp_name (target_type,
  4125.                current_binding_level == global_binding_level);
  4126.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  4127.       TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  4128.       DECL_INITIAL (decl) = convert_pointer_to (TREE_TYPE (this_ptr_type), tmp_addr);
  4129.       TREE_TYPE (DECL_INITIAL (decl)) = type;
  4130.       if (TYPE_NEEDS_CONSTRUCTING (target_type))
  4131.     {
  4132.       if (current_binding_level == global_binding_level)
  4133.         {
  4134.           /* lay this variable out now.  Otherwise `output_addressed_constants'
  4135.          gets confused by its initializer.  */
  4136.           make_decl_rtl (tmp, 0, 1);
  4137.           static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  4138.         }
  4139.       else
  4140.         {
  4141.           init = build_method_call (tmp, TYPE_IDENTIFIER (target_type), build_tree_list (NULL_TREE, init), NULL_TREE, LOOKUP_NORMAL);
  4142.           DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init, DECL_INITIAL (decl));
  4143.           *cleanupp = maybe_build_cleanup (tmp);
  4144.         }
  4145.     }
  4146.       else
  4147.     {
  4148.       DECL_INITIAL (tmp) = init;
  4149.       TREE_STATIC (tmp) = current_binding_level == global_binding_level;
  4150.       finish_decl (tmp, init, 0);
  4151.     }
  4152.     }
  4153.   else
  4154.     {
  4155.       error_with_decl (decl, "type mismatch in initialization of `%s' (use `const')");
  4156.       DECL_INITIAL (decl) = error_mark_node;
  4157.     }
  4158.  
  4159.   /* ?? Can this be optimized in some cases to
  4160.      hand back the DECL_INITIAL slot??  */
  4161.   if (TYPE_SIZE (TREE_TYPE (type)))
  4162.     SET_DECL_REFERENCE_SLOT (decl, convert_from_reference (decl));
  4163.  
  4164.   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
  4165.     {
  4166.       expand_static_init (decl, DECL_INITIAL (decl));
  4167.       DECL_INITIAL (decl) = 0;
  4168.     }
  4169. }
  4170.  
  4171. /* Finish processing of a declaration;
  4172.    install its line number and initial value.
  4173.    If the length of an array type is not known before,
  4174.    it must be determined now, from the initial value, or it is an error.
  4175.  
  4176.    For C++, `finish_decl' must be fairly evasive:  it must keep initializers
  4177.    for aggregates that have constructors alive on the permanent obstack,
  4178.    so that the global initializing functions can be written at the end.
  4179.  
  4180.    INIT0 holds the value of an initializer that should be allowed to escape
  4181.    the normal rules.
  4182.  
  4183.    For functions that take defualt parameters, DECL points to its
  4184.    "maximal" instantiation.  finish_decl must then also declared its
  4185.    subsequently lower and lower forms of instantiation, checking for
  4186.    ambiguity as it goes.  This can be sped up later.  */
  4187.  
  4188. void
  4189. finish_decl (decl, init, asmspec_tree)
  4190.      tree decl, init;
  4191.      tree asmspec_tree;
  4192. {
  4193.   register tree type;
  4194.   tree cleanup = NULL_TREE, ttype;
  4195.   int was_incomplete;
  4196.   int temporary = allocation_temporary_p ();
  4197.   char *asmspec = 0;
  4198.   int was_readonly = 0;
  4199.  
  4200.   /* If this is 0, then we did not change obstacks.  */
  4201.   if (! decl)
  4202.     {
  4203.       if (init)
  4204.     error ("assignment (not initialization) in declaration");
  4205.       return;
  4206.     }
  4207.  
  4208.   if (asmspec_tree)
  4209.     {
  4210.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  4211.       /* Zero out old RTL, since we will rewrite it.  */
  4212.       DECL_RTL (decl) = 0;
  4213.     }
  4214.  
  4215.   /* If the type of the thing we are declaring either has
  4216.      a constructor, or has a virtual function table pointer,
  4217.      AND its initialization was accepted by `start_decl',
  4218.      then we stayed on the permanent obstack through the
  4219.      declaration, otherwise, changed obstacks as GCC would.  */
  4220.  
  4221.   type = TREE_TYPE (decl);
  4222.  
  4223.   was_incomplete = (DECL_SIZE (decl) == 0);
  4224.  
  4225.   /* Take care of TYPE_DECLs up front.  */
  4226.   if (TREE_CODE (decl) == TYPE_DECL)
  4227.     {
  4228.       if (init && DECL_INITIAL (decl))
  4229.     {
  4230.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  4231.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  4232.       DECL_INITIAL (decl) = init = 0;
  4233.     }
  4234.       if (IS_AGGR_TYPE (type))
  4235.     {
  4236. #ifndef BREAK_C_TAGS
  4237.       if (current_lang_name == lang_name_cplusplus)
  4238. #endif
  4239.         {
  4240.           if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  4241.         warning ("shadowing previous type declaration of `%s'",
  4242.              IDENTIFIER_POINTER (DECL_NAME (decl)));
  4243.           SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (decl), type);
  4244.         }
  4245.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  4246.     }
  4247.       GNU_xref_decl (current_function_decl, decl);
  4248.       rest_of_decl_compilation (decl, 0,
  4249.                 current_binding_level == global_binding_level, 0);
  4250.       goto finish_end;
  4251.     }
  4252.   if (IS_AGGR_TYPE (type) && CLASSTYPE_DECLARED_EXCEPTION (type))
  4253.     {
  4254.       finish_exception_decl (NULL_TREE, decl);
  4255.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  4256.       goto finish_end;
  4257.     }
  4258.   if (TREE_CODE (decl) != FUNCTION_DECL)
  4259.     {
  4260.       ttype = target_type (type);
  4261.       if (TYPE_NAME (ttype)
  4262.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  4263.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
  4264.     {
  4265.       tree old_id = TYPE_IDENTIFIER (ttype);
  4266.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  4267.       newname[0] = '_';
  4268.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  4269.          IDENTIFIER_LENGTH (old_id) + 1);
  4270.       old_id = get_identifier (newname);
  4271.       lookup_tag_reverse (ttype, old_id);
  4272.       TYPE_IDENTIFIER (ttype) = old_id;
  4273.     }
  4274.     }
  4275.  
  4276.   if (! TREE_EXTERNAL (decl) && TREE_READONLY (decl)
  4277.       && TYPE_NEEDS_CONSTRUCTING (type))
  4278.     {
  4279.  
  4280.       /* Currently, GNU C++ puts constants in text space, making them
  4281.      impossible to initialize.  In the future, one would hope for
  4282.      an operating system which understood the difference between
  4283.      initialization and the running of a program.  */
  4284.       was_readonly = 1;
  4285.       TREE_READONLY (decl) = 0;
  4286.     }
  4287.  
  4288.   if (TREE_CODE (decl) == FIELD_DECL)
  4289.     {
  4290.       if (init && init != error_mark_node)
  4291.     assert (TREE_PERMANENT (init));
  4292.  
  4293.       if (asmspec)
  4294.     {
  4295.       /* This must override the asm specifier which was placed
  4296.          by grokclassfn.  Lay this out fresh.
  4297.          
  4298.          @@ Should emit an error if this redefines an asm-specified
  4299.          @@ name, or if we have already used the function's name.  */
  4300.       DECL_RTL (TREE_TYPE (decl)) = 0;
  4301.       DECL_ASSEMBLER_NAME (decl) = asmspec;
  4302.       make_decl_rtl (decl, asmspec, 0);
  4303.     }
  4304.     }
  4305.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  4306.   else if (init != 0 && DECL_INITIAL (decl) == 0)
  4307.     init = 0;
  4308.   else if (TREE_EXTERNAL (decl))
  4309.     ;
  4310.   else if (TREE_CODE (type) == REFERENCE_TYPE)
  4311.     {
  4312.       grok_reference_init (decl, type, init, &cleanup);
  4313.       init = 0;
  4314.     }
  4315.  
  4316.   GNU_xref_decl (current_function_decl, decl);
  4317.  
  4318.   if (TREE_CODE (decl) == FIELD_DECL || TREE_EXTERNAL (decl))
  4319.     ;
  4320.   else if (TREE_CODE (decl) == CONST_DECL)
  4321.     {
  4322.       assert (TREE_CODE (decl) != REFERENCE_TYPE);
  4323.  
  4324.       DECL_INITIAL (decl) = init;
  4325.  
  4326.       /* This will keep us from needing to worry about our obstacks.  */
  4327.       assert (init != 0);
  4328.       init = 0;
  4329.     }
  4330.   else if (init)
  4331.     {
  4332.       if (TYPE_NEEDS_CONSTRUCTING (type))
  4333.     {
  4334.       if (TREE_CODE (type) == ARRAY_TYPE)
  4335.         init = digest_init (type, init, 0);
  4336.       else if (TREE_CODE (init) == CONSTRUCTOR
  4337.            && CONSTRUCTOR_ELTS (init) != NULL_TREE)
  4338.         {
  4339.           error_with_decl (decl, "`%s' must be initialized by constructor, not by `{...}'");
  4340.           init = error_mark_node;
  4341.         }
  4342. #if 0
  4343.       /* fix this in `build_functional_cast' instead.
  4344.          Here's the trigger code:
  4345.  
  4346.         struct ostream
  4347.         {
  4348.           ostream ();
  4349.           ostream (int, char *);
  4350.           ostream (char *);
  4351.           operator char *();
  4352.           ostream (void *);
  4353.           operator void *();
  4354.           operator << (int);
  4355.         };
  4356.         int buf_size = 1024;
  4357.         static char buf[buf_size];
  4358.         const char *debug(int i) {
  4359.           char *b = &buf[0];
  4360.           ostream o = ostream(buf_size, b);
  4361.           o << i;
  4362.           return buf;
  4363.         }
  4364.         */
  4365.  
  4366.       else if (TREE_CODE (init) == TARGET_EXPR
  4367.            && TREE_CODE (TREE_OPERAND (init, 1) == NEW_EXPR))
  4368.         {
  4369.           /* User wrote something like `foo x = foo (args)'  */
  4370.           assert (TREE_CODE (TREE_OPERAND (init, 0)) == VAR_DECL);
  4371.           assert (DECL_NAME (TREE_OPERAND (init, 0)) == NULL_TREE);
  4372.  
  4373.           /* User wrote exactly `foo x = foo (args)'  */
  4374.           if (TYPE_MAIN_VARIANT (type) == TREE_TYPE (init))
  4375.         {
  4376.           init = build (CALL_EXPR, TREE_TYPE (init),
  4377.                 TREE_OPERAND (TREE_OPERAND (init, 1), 0),
  4378.                 TREE_OPERAND (TREE_OPERAND (init, 1), 1), 0);
  4379.           TREE_SIDE_EFFECTS (init) = 1;
  4380.         }
  4381.         }
  4382. #endif
  4383.  
  4384.       /* We must hide the initializer so that expand_decl
  4385.          won't try to do something it does not understand.  */
  4386.       if (current_binding_level == global_binding_level)
  4387.         {
  4388.           tree value = digest_init (type, empty_init_node, 0);
  4389.           DECL_INITIAL (decl) = value;
  4390.         }
  4391.       else
  4392.         DECL_INITIAL (decl) = error_mark_node;
  4393.     }
  4394.       else
  4395.     {
  4396.       if (TREE_CODE (init) != TREE_VEC)
  4397.         init = store_init_value (decl, init);
  4398.  
  4399.       if (init)
  4400.         /* Don't let anyone try to initialize this variable
  4401.            until we are ready to do so.  */
  4402.         DECL_INITIAL (decl) = error_mark_node;
  4403.     }
  4404.     }
  4405.   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  4406.        && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
  4407.     {
  4408.       tree ctype = type;
  4409.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  4410.     ctype = TREE_TYPE (ctype);
  4411.       if (! TYPE_NEEDS_CONSTRUCTOR (ctype))
  4412.     {
  4413.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  4414.         error_with_decl (decl, "structure `%s' with uninitialized const members");
  4415.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  4416.         error_with_decl (decl, "structure `%s' with uninitialized reference members");
  4417.     }
  4418.  
  4419.       if (TREE_CODE (decl) == VAR_DECL
  4420.       && !TYPE_NEEDS_CONSTRUCTING (type)
  4421.       && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  4422.     error_with_decl (decl, "uninitialized const `%s'");
  4423.  
  4424.       /* Initialize variables in need of static initialization
  4425.      with `empty_init_node' to keep assemble_variable from putting them
  4426.      in the wrong program space.  */
  4427.       if (TREE_STATIC (decl)
  4428.       && TREE_CODE (decl) == VAR_DECL
  4429.       && TYPE_NEEDS_CONSTRUCTING (type)
  4430.       && (DECL_INITIAL (decl) == 0
  4431.           || DECL_INITIAL (decl) == error_mark_node))
  4432.     {
  4433.       tree value = digest_init (type, empty_init_node, 0);
  4434.       DECL_INITIAL (decl) = value;
  4435.     }
  4436.     }
  4437.   else if (TREE_CODE (decl) == VAR_DECL
  4438.        && TREE_CODE (type) != REFERENCE_TYPE
  4439.        && TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  4440.        && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  4441.     {
  4442.       if (! TREE_STATIC (decl))
  4443.     error_with_decl (decl, "uninitialized const `%s'");
  4444.     }
  4445.  
  4446.   /* For top-level declaration, the initial value was read in
  4447.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  4448.      must go in the permanent obstack; but don't discard the
  4449.      temporary data yet.  */
  4450.  
  4451.   if (current_binding_level == global_binding_level && temporary)
  4452.     end_temporary_allocation ();
  4453.  
  4454.   /* Deduce size of array from initialization, if not already known.  */
  4455.  
  4456.   if (TREE_CODE (type) == ARRAY_TYPE
  4457.       && TYPE_DOMAIN (type) == 0
  4458.       && TREE_CODE (decl) != TYPE_DECL)
  4459.     {
  4460.       int do_default
  4461.     = (TREE_STATIC (decl)
  4462.        /* Even if pedantic, an external linkage array
  4463.           may have incomplete type at first.  */
  4464.        ? pedantic && !TREE_PUBLIC (decl)
  4465.        : !TREE_EXTERNAL (decl));
  4466.       tree initializer = init ? init : DECL_INITIAL (decl);
  4467.       int failure = complete_array_type (type, initializer, do_default);
  4468.  
  4469.       if (failure == 1)
  4470.     error_with_decl (decl, "initializer fails to determine size of `%s'");
  4471.  
  4472.       if (failure == 2)
  4473.     {
  4474.       if (do_default)
  4475.         error_with_decl (decl, "array size missing in `%s'");
  4476.       else if (!pedantic && TREE_STATIC (decl))
  4477.         TREE_EXTERNAL (decl) = 1;
  4478.     }
  4479.  
  4480.       if (pedantic && TYPE_DOMAIN (type) != 0
  4481.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  4482.                   integer_zero_node))
  4483.     error_with_decl (decl, "zero-size array `%s'");
  4484.  
  4485.       layout_decl (decl, 0);
  4486.     }
  4487.  
  4488.   if (TREE_CODE (decl) == VAR_DECL)
  4489.     {
  4490.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == 0)
  4491.     {
  4492.       /* A static variable with an incomplete type:
  4493.          that is an error if it is initialized or `static'.
  4494.          Otherwise, let it through, but if it is not `extern'
  4495.          then it may cause an error message later.  */
  4496.       if (! (TREE_PUBLIC (decl) && DECL_INITIAL (decl) == 0))
  4497.         error_with_decl (decl, "storage size of `%s' isn't known");
  4498.       init = 0;
  4499.     }
  4500.       else if (!TREE_EXTERNAL (decl) && DECL_SIZE (decl) == 0)
  4501.     {
  4502.       /* An automatic variable with an incomplete type:
  4503.          that is an error.  */
  4504.       error_with_decl (decl, "storage size of `%s' isn't known");
  4505.       TREE_TYPE (decl) = error_mark_node;
  4506.     }
  4507.       else if (!TREE_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  4508.     /* Let debugger know it should output info for this type.  */
  4509.     CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  4510.  
  4511.       if ((TREE_EXTERNAL (decl) || TREE_STATIC (decl))
  4512.       && DECL_SIZE (decl) != 0 && ! TREE_CONSTANT (DECL_SIZE (decl)))
  4513.     error_with_decl (decl, "storage size of `%s' isn't constant");
  4514.  
  4515.       if (TYPE_NEEDS_DESTRUCTOR (type))
  4516.     {
  4517.       int yes = suspend_momentary ();
  4518.       cleanup = maybe_build_cleanup (decl);
  4519.       resume_momentary (yes);
  4520.     }
  4521.     }
  4522.   /* PARM_DECLs get cleanups, too.  */
  4523.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  4524.     {
  4525.       if (temporary)
  4526.     end_temporary_allocation ();
  4527.       cleanup = maybe_build_cleanup (decl);
  4528.       if (temporary)
  4529.     resume_temporary_allocation ();
  4530.     }
  4531.  
  4532.   /* Output the assembler code and/or RTL code for variables and functions,
  4533.      unless the type is an undefined structure or union.
  4534.      If not, it will get done when the type is completed.  */
  4535.  
  4536.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  4537.       || TREE_CODE (decl) == RESULT_DECL)
  4538.     {
  4539.       int toplev = current_binding_level == global_binding_level;
  4540.       int was_temp
  4541.     = ((flag_traditional
  4542.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  4543.        && allocation_temporary_p ());
  4544.  
  4545.       if (was_temp)
  4546.     end_temporary_allocation ();
  4547.  
  4548.       /* If we are in need of a cleanup, get out of any implicit
  4549.      handlers that have been established so far.  */
  4550.       if (cleanup && current_binding_level->parm_flag == 3)
  4551.     {
  4552.       pop_implicit_try_blocks (decl);
  4553.       current_binding_level->more_exceptions_ok = 0;
  4554.     }
  4555.  
  4556.       if (TREE_CODE (decl) == VAR_DECL
  4557.       && current_binding_level != global_binding_level
  4558.       && ! TREE_STATIC (decl)
  4559.       && type_needs_gc_entry (type))
  4560.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  4561.  
  4562.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  4563.     make_decl_rtl (decl, 0, toplev);
  4564.       else if (TREE_CODE (decl) == VAR_DECL
  4565.            && TREE_READONLY (decl)
  4566.            && DECL_INITIAL (decl) != 0
  4567.            && DECL_INITIAL (decl) != error_mark_node
  4568.            && DECL_INITIAL (decl) != empty_init_node)
  4569.     {
  4570.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  4571.  
  4572.       if (asmspec)
  4573.         DECL_ASSEMBLER_NAME (decl) = asmspec;
  4574.  
  4575.       if (! toplev
  4576.           && TREE_STATIC (decl)
  4577.           && ! TREE_SIDE_EFFECTS (decl)
  4578.           && ! TREE_PUBLIC (decl)
  4579.           && ! TREE_EXTERNAL (decl)
  4580.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  4581.           && DECL_MODE (decl) != BLKmode)
  4582.         {
  4583.           /* If this variable is really a constant, then fill its DECL_RTL
  4584.          slot with something which won't take up storage.
  4585.          If something later should take its address, we can always give
  4586.          it legitimate RTL at that time.  */
  4587.           DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
  4588.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  4589.           TREE_ASM_WRITTEN (decl) = 1;
  4590.         }
  4591.       else if (toplev)
  4592.         {
  4593.           /* Keep GCC from complaining that this variable
  4594.          is defined but never used.  */
  4595.           TREE_INLINE (decl) = 1;
  4596.           make_decl_rtl (decl, asmspec, toplev);
  4597.         }
  4598.       else
  4599.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  4600.     }
  4601.       else if (TREE_CODE (decl) == VAR_DECL
  4602.            && DECL_LANG_SPECIFIC (decl)
  4603.            && DECL_IN_AGGR_P (decl))
  4604.     {
  4605.       if (TREE_STATIC (decl))
  4606.         if (init == 0 && TYPE_NEEDS_CONSTRUCTING (type))
  4607.           {
  4608.         TREE_EXTERNAL (decl) = 1;
  4609.         make_decl_rtl (decl, asmspec, 1);
  4610.           }
  4611.         else
  4612.           rest_of_decl_compilation (decl, asmspec, toplev, 0);
  4613.       else
  4614.         /* Just a constant field.  Should not need any rtl.  */
  4615.         goto finish_end0;
  4616.     }
  4617.       else
  4618.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  4619.  
  4620.       if (was_temp)
  4621.     resume_temporary_allocation ();
  4622.  
  4623.       if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  4624.     abstract_virtuals_error (decl, type);
  4625.       else if (TREE_CODE (type) == FUNCTION_TYPE
  4626.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  4627.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  4628.     abstract_virtuals_error (decl, TREE_TYPE (type));
  4629.  
  4630.       if (TREE_CODE (decl) == FUNCTION_DECL)
  4631.     {
  4632.       /* C++: Handle overloaded functions with default parameters.  */
  4633.       if (DECL_OVERLOADED (decl))
  4634.         {
  4635.           tree parmtypes = TYPE_ARG_TYPES (type);
  4636.           tree prev = NULL_TREE;
  4637.           char *original_name = IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (decl));
  4638.           struct lang_decl *tmp_lang_decl = DECL_LANG_SPECIFIC (decl);
  4639.           /* All variants will share an uncollectable lang_decl.  */
  4640.           copy_decl_lang_specific (decl);
  4641.  
  4642.           while (parmtypes && parmtypes != void_list_node)
  4643.         {
  4644.           if (TREE_PURPOSE (parmtypes))
  4645.             {
  4646.               tree fnname, fndecl;
  4647.               tree *argp = prev
  4648.             ? & TREE_CHAIN (prev)
  4649.               : & TYPE_ARG_TYPES (type);
  4650.  
  4651.               *argp = NULL_TREE;
  4652.               fnname = build_decl_overload (original_name, TYPE_ARG_TYPES (type), 0);
  4653.               *argp = parmtypes;
  4654.               fndecl = build_decl (FUNCTION_DECL, fnname, type);
  4655.               TREE_EXTERNAL (fndecl) = TREE_EXTERNAL (decl);
  4656.               TREE_PUBLIC (fndecl) = TREE_PUBLIC (decl);
  4657.               TREE_INLINE (fndecl) = TREE_INLINE (decl);
  4658.               /* Keep G++ from thinking this function is unused.
  4659.              It is only used to speed up search in name space.  */
  4660.               TREE_USED (fndecl) = 1;
  4661.               TREE_ASM_WRITTEN (fndecl) = 1;
  4662.               DECL_INITIAL (fndecl) = NULL_TREE;
  4663.               DECL_LANG_SPECIFIC (fndecl) = DECL_LANG_SPECIFIC (decl);
  4664.               fndecl = pushdecl (fndecl);
  4665.               DECL_INITIAL (fndecl) = error_mark_node;
  4666.               DECL_RTL (fndecl) = DECL_RTL (decl);
  4667.             }
  4668.           prev = parmtypes;
  4669.           parmtypes = TREE_CHAIN (parmtypes);
  4670.         }
  4671.           DECL_LANG_SPECIFIC (decl) = tmp_lang_decl;
  4672.         }
  4673.     }
  4674.       else if (TREE_EXTERNAL (decl))
  4675.     ;
  4676.       else if (TREE_STATIC (decl))
  4677.     {
  4678.       /* Cleanups for static variables are handled by `finish_file'.  */
  4679.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE)
  4680.         expand_static_init (decl, init);
  4681.  
  4682.       /* Make entry in appropriate vector.  */
  4683.       if (flag_gc && type_needs_gc_entry (type))
  4684.         build_static_gc_entry (decl, type);
  4685.     }
  4686.       else if (current_binding_level != global_binding_level)
  4687.     {
  4688.       /* This is a declared decl which must live until the
  4689.          end of the binding contour.  It may need a cleanup.  */
  4690.  
  4691.       /* Recompute the RTL of a local array now
  4692.          if it used to be an incomplete type.  */
  4693.       if (was_incomplete && ! TREE_STATIC (decl))
  4694.         {
  4695.           /* If we used it already as memory, it must stay in memory.  */
  4696.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  4697.           /* If it's still incomplete now, no init will save it.  */
  4698.           if (DECL_SIZE (decl) == 0)
  4699.         DECL_INITIAL (decl) = 0;
  4700.           expand_decl (decl);
  4701.         }
  4702.       else if (! TREE_ASM_WRITTEN (decl)
  4703.            && (TYPE_SIZE (type) != 0 || TREE_CODE (type) == ARRAY_TYPE))
  4704.         {
  4705.           /* Do this here, because we did not expand this decl's
  4706.          rtl in start_decl.  */
  4707.           if (DECL_RTL (decl) == 0)
  4708.         expand_decl (decl);
  4709.           else if (cleanup)
  4710.         {
  4711.           expand_decl_cleanup (NULL_TREE, cleanup);
  4712.           /* Cleanup used up here.  */
  4713.           cleanup = 0;
  4714.         }
  4715.         }
  4716.  
  4717.       if (DECL_SIZE (decl))
  4718.         {
  4719.           /* Compute and store the initial value.  */
  4720.           expand_decl_init (decl);
  4721.  
  4722.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  4723.         {
  4724.           emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  4725.           expand_aggr_init (decl, init, 0);
  4726.         }
  4727.  
  4728.           /* Set this to 0 so we can tell whether an aggregate
  4729.          which was initialized was ever used.  */
  4730.           if (TYPE_NEEDS_CONSTRUCTING (type))
  4731.         TREE_USED (decl) = 0;
  4732.  
  4733.           /* Store the cleanup, if there was one.  */
  4734.           if (cleanup)
  4735.         {
  4736.           if (! expand_decl_cleanup (decl, cleanup))
  4737.             error_with_decl (decl, "parser lost in parsing declaration of `%s'");
  4738.         }
  4739.         }
  4740.     }
  4741.     finish_end0:
  4742.  
  4743.       /* Undo call to `pushclass' that was done in `start_decl'
  4744.      due to initialization of qualified member variable.
  4745.      I.e., Foo::x = 10;  */
  4746.       if (TREE_CODE (decl) == VAR_DECL && DECL_CONTEXT (decl))
  4747.     popclass (1);
  4748.     }
  4749.  
  4750.  finish_end:
  4751.  
  4752.   /* Resume permanent allocation, if not within a function.  */
  4753.   if (temporary && current_binding_level == global_binding_level)
  4754.     {
  4755.       permanent_allocation ();
  4756. #if 0
  4757.       /* @@ I don't know whether this is true for GNU C++.  */
  4758.       /* We need to remember that this array HAD an initialization,
  4759.      but discard the actual nodes, since they are temporary anyway.  */
  4760.       if (DECL_INITIAL (decl) != 0)
  4761.     DECL_INITIAL (decl) = error_mark_node;
  4762. #endif
  4763.     }
  4764.   if (was_readonly)
  4765.     TREE_READONLY (decl) = 1;
  4766.  
  4767.   if (flag_cadillac)
  4768.     cadillac_finish_decl (decl);
  4769. }
  4770.  
  4771. static void
  4772. expand_static_init (decl, init)
  4773.      tree decl;
  4774.      tree init;
  4775. {
  4776.   tree oldstatic = value_member (decl, static_aggregates);
  4777.   if (oldstatic)
  4778.     {
  4779.       if (TREE_PURPOSE (oldstatic))
  4780.     error_with_decl (decl, "multiple initializations given for `%s'");
  4781.     }
  4782.   else if (current_binding_level != global_binding_level)
  4783.     {
  4784.       /* Emit code to perform this initialization but once.  */
  4785.       tree temp = get_temp_name (integer_type_node, 1);
  4786.       rest_of_decl_compilation (temp, NULL_TREE, 0, 0);
  4787.       expand_start_cond (build_binary_op (EQ_EXPR, temp, integer_zero_node), 0);
  4788.       expand_assignment (temp, integer_one_node, 0, 0);
  4789.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  4790.     {
  4791.       expand_aggr_init (decl, init, 0);
  4792.       do_pending_stack_adjust ();
  4793.     }
  4794.       else
  4795.     expand_assignment (decl, init, 0, 0);
  4796.       expand_end_cond ();
  4797.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  4798.     {
  4799.       int temporary = allocation_temporary_p ();
  4800.       if (temporary)
  4801.         end_temporary_allocation ();
  4802.       static_aggregates = tree_cons (temp, decl, static_aggregates);
  4803.       TREE_STATIC (static_aggregates) = 1;
  4804.       if (temporary)
  4805.         resume_temporary_allocation ();
  4806.     }
  4807.     }
  4808.   else
  4809.     {
  4810.       /* This code takes into account memory allocation
  4811.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  4812.      does not hold for this object, then we must make permanent
  4813.      the storage currently in the temporary obstack.  */
  4814.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  4815.     preserve_initializer ();
  4816.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  4817.     }
  4818. }
  4819.  
  4820. /* Make TYPE a complete type based on INITIAL_VALUE.
  4821.    Return 0 if successful, 1 if INITIAL_VALUE can't be decyphered,
  4822.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  4823.  
  4824. int
  4825. complete_array_type (type, initial_value, do_default)
  4826.      tree type;
  4827.      tree initial_value;
  4828.      int do_default;
  4829. {
  4830.   register tree maxindex = NULL_TREE;
  4831.   int value = 0;
  4832.   int temporary = (TREE_PERMANENT (type) && allocation_temporary_p ());
  4833.  
  4834.   /* Don't put temporary nodes in permanent type.  */
  4835.   if (temporary)
  4836.     end_temporary_allocation ();
  4837.  
  4838.   if (initial_value)
  4839.     {
  4840.       /* Note MAXINDEX  is really the maximum index,
  4841.      one less than the size.  */
  4842.       if (TREE_CODE (initial_value) == STRING_CST)
  4843.     maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) - 1, 0);
  4844.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  4845.     {
  4846.       register int nelts
  4847.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  4848.       maxindex = build_int_2 (nelts - 1, 0);
  4849.     }
  4850.       else
  4851.     {
  4852.       /* Make an error message unless that happened already.  */
  4853.       if (initial_value != error_mark_node)
  4854.         value = 1;
  4855.  
  4856.       /* Prevent further error messages.  */
  4857.       maxindex = build_int_2 (1, 0);
  4858.     }
  4859.     }
  4860.  
  4861.   if (!maxindex)
  4862.     {
  4863.       if (do_default)
  4864.     maxindex = build_int_2 (1, 0);
  4865.       value = 2;
  4866.     }
  4867.  
  4868.   if (maxindex)
  4869.     {
  4870.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  4871.       if (!TREE_TYPE (maxindex))
  4872.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  4873.     }
  4874.  
  4875.   /* Lay out the type now that we can get the real answer.  */
  4876.  
  4877.   layout_type (type);
  4878.  
  4879.   if (temporary)
  4880.     resume_temporary_allocation ();
  4881.  
  4882.   return value;
  4883. }
  4884.  
  4885. /* Return zero if something is declared to be a member of type
  4886.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  4887.    message to print in that case.  Otherwise, quietly return 1.  */
  4888. static int
  4889. member_function_or_else (ctype, cur_type, string)
  4890.      tree ctype, cur_type;
  4891.      char *string;
  4892. {
  4893.   if (ctype && ctype != cur_type)
  4894.     {
  4895.       error (string, TYPE_NAME_STRING (ctype));
  4896.       return 0;
  4897.     }
  4898.   return 1;
  4899. }
  4900.  
  4901. /* Subroutine of `grokdeclarator'.  */
  4902.  
  4903. /* CTYPE is class type, or null if non-class.
  4904.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  4905.    or METHOD_TYPE.
  4906.    DECLARATOR is the function's name.
  4907.    VIRTUALP is truthvalue of whether the function is virtual or not.
  4908.    FLAGS are to be passed through to `grokclassfn'.
  4909.    QUALS are qualifiers indicating whether the function is `const'
  4910.    or `volatile'.
  4911.    RAISES is a list of exceptions that this function can raise.
  4912.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  4913.    not look, and -1 if we should not call `grokclassfn' at all.  */
  4914. static tree
  4915. grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, check)
  4916.      tree ctype, type;
  4917.      tree declarator;
  4918.      int virtualp;
  4919.      enum overload_flags flags;
  4920.      tree quals, raises;
  4921.      int check;
  4922. {
  4923.   tree cname, decl;
  4924.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  4925.  
  4926.   if (ctype)
  4927.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  4928.       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
  4929.   else
  4930.     cname = NULL_TREE;
  4931.  
  4932.   if (raises)
  4933.     {
  4934.       type = build_exception_variant (ctype, type, raises);
  4935.       raises = TYPE_RAISES_EXCEPTIONS (type);
  4936.     }
  4937.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  4938.   if (staticp)
  4939.     {
  4940.       DECL_STATIC_FUNCTION_P (decl) = 1;
  4941.       DECL_STATIC_CONTEXT (decl) = ctype;
  4942.     }
  4943.   TREE_EXTERNAL (decl) = 1;
  4944.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  4945.     {
  4946.       /* Dont have DECL_ORIGINAL_NAME yet, so we cannot pretty print it.  */
  4947.       error ("functions cannot have method qualifiers");
  4948.       quals = NULL_TREE;
  4949.     }
  4950.  
  4951.   /* Caller will do the rest of this.  */
  4952.   if (check < 0)
  4953.     return decl;
  4954.  
  4955.   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
  4956.     {
  4957.       tree tmp;
  4958.       /* Just handle constructors here.  We could do this
  4959.      inside the following if stmt, but I think
  4960.      that the code is more legible by breaking this
  4961.      case out.  See comments below for what each of
  4962.      the following calls is supposed to do.  */
  4963.       DECL_CONSTRUCTOR_P (decl) = 1;
  4964.  
  4965.       grokclassfn (ctype, declarator, decl, flags, check, quals);
  4966.       grok_ctor_properties (ctype, decl);
  4967.       if (check == 0)
  4968.     {
  4969.       tmp = lookup_name (DECL_NAME (decl));
  4970.       if (tmp == 0)
  4971.         IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl)) = decl;
  4972.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  4973.         error_with_decl (decl, "inconsistant declarations for `%s'");
  4974.       else
  4975.         {
  4976.           duplicate_decls (decl, tmp);
  4977.           decl = tmp;
  4978.         }
  4979.       make_decl_rtl (decl, NULL_TREE, 1);
  4980.     }
  4981.     }
  4982.   else
  4983.     {
  4984.       tree tmp;
  4985.       int i, n_baseclasses;
  4986.  
  4987.       /* Function gets the ugly name, field gets the nice one.
  4988.      This call may change the type of the function (because
  4989.      of default parameters)!
  4990.      
  4991.      Wrappers get field names which will not conflict
  4992.      with constructors and destructors.  */
  4993.       if (ctype != NULL_TREE)
  4994.     grokclassfn (ctype, cname, decl, flags, check, quals);
  4995.  
  4996.       if (OPERATOR_NAME_P (DECL_NAME (decl)))
  4997.     {
  4998.       DECL_OPERATOR (decl) = 1;
  4999.       grok_op_properties (decl);
  5000.     }
  5001.  
  5002.       if (ctype == NULL_TREE || check)
  5003.     return decl;
  5004.  
  5005.       /* Now install the declaration of this function so that
  5006.      others may find it (esp. its DECL_FRIENDLIST).
  5007.      Pretend we are at top level, we will get true
  5008.      reference later, perhaps.  */
  5009.       tmp = lookup_name (DECL_NAME (decl));
  5010.       if (tmp == 0)
  5011.     IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl)) = decl;
  5012.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  5013.     error_with_decl (decl, "inconsistant declarations for `%s'");
  5014.       else
  5015.     {
  5016.       duplicate_decls (decl, tmp);
  5017.       decl = tmp;
  5018.     }
  5019.       make_decl_rtl (decl, NULL_TREE, 1);
  5020.  
  5021.       /* If this declaration supersedes the declaration of
  5022.      a method declared virtual in the base class, then
  5023.      mark this field as being virtual as well.  */
  5024.       for (i = 0, n_baseclasses = CLASSTYPE_N_BASECLASSES (ctype);
  5025.        i < n_baseclasses; i++)
  5026.     {
  5027.       tree basetype = CLASSTYPE_BASECLASS (ctype, i);
  5028.       if (TYPE_VIRTUAL_P (basetype) || flag_all_virtual == 1)
  5029.         {
  5030.           tmp = get_first_matching_virtual (basetype, decl,
  5031.                         flags == DTOR_FLAG);
  5032.           if (tmp)
  5033.         {
  5034.           /* The TMP we really want is the one from the deepest
  5035.              baseclass on this path, taking care not to
  5036.              duplicate if we have already found it (via another
  5037.              path to its virtual baseclass.  */
  5038.           if (staticp)
  5039.             {
  5040.               error_with_decl (decl, "method `%s' may not be declared static");
  5041.               error_with_decl (tmp, "(since `%s' declared virtual in base class.)");
  5042.               break;
  5043.             }
  5044.           virtualp = 1;
  5045.  
  5046.           if ((TYPE_USES_VIRTUAL_BASECLASSES (basetype)
  5047.                || TYPE_USES_MULTIPLE_INHERITANCE (ctype))
  5048.               && TYPE_MAIN_VARIANT (basetype) != DECL_VCONTEXT (tmp))
  5049.             tmp = get_first_matching_virtual (DECL_VCONTEXT (tmp),
  5050.                               decl, flags == DTOR_FLAG);
  5051.           if (value_member (tmp, DECL_VINDEX (decl)) == NULL_TREE)
  5052.             {
  5053.               /* The argument types may have changed... */
  5054.               tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  5055.               tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  5056.  
  5057.               argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  5058.                           TREE_CHAIN (argtypes));
  5059.               /* But the return type has not.  */
  5060.               type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  5061.               if (raises)
  5062.             {
  5063.               type = build_exception_variant (ctype, type, raises);
  5064.               raises == TYPE_RAISES_EXCEPTIONS (type);
  5065.             }
  5066.               TREE_TYPE (decl) = type;
  5067.               SET_DECL_VINDEX (decl, tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl)));
  5068.             }
  5069.         }
  5070.         }
  5071.     }
  5072.       if (virtualp)
  5073.     {
  5074.       DECL_VIRTUAL_P (decl) = 1;
  5075.       IDENTIFIER_VIRTUAL_P (declarator) = 1;
  5076.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  5077.           && (write_virtuals == 2
  5078.           || (write_virtuals == 3
  5079.               && ! CLASSTYPE_INTERFACE_UNKNOWN (ctype))))
  5080.         TREE_PUBLIC (decl) = 1;
  5081.     }
  5082.     }
  5083.   return decl;
  5084. }
  5085.  
  5086. static tree
  5087. grokvardecl (ctype, type, declarator, specbits, initialized)
  5088.      tree ctype, type;
  5089.      tree declarator;
  5090.      int specbits;
  5091. {
  5092.   tree decl;
  5093.  
  5094.   if (TREE_CODE (type) == OFFSET_TYPE)
  5095.     {
  5096.       /* If you declare a static member so that it
  5097.      can be initialized, the code will reach here.  */
  5098.       tree field = lookup_field (TYPE_OFFSET_BASETYPE (type),
  5099.                  declarator, 0);
  5100.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  5101.     {
  5102.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  5103.       error ("`%s' is not a static member of class `%s'",
  5104.          IDENTIFIER_POINTER (declarator),
  5105.          TYPE_NAME_STRING (basetype));
  5106.       type = TREE_TYPE (type);
  5107.       decl = build_decl (VAR_DECL, declarator, type);
  5108.       DECL_CONTEXT (decl) = basetype;
  5109.     }
  5110.       else
  5111.     {
  5112.       decl = field;
  5113.       if (initialized && DECL_INITIAL (decl)
  5114.           /* Complain about multiply-initialized
  5115.          member variables, but don't be faked
  5116.          out if initializer is faked up from `empty_init_node'.  */
  5117.           && (TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  5118.           || CONSTRUCTOR_ELTS (DECL_INITIAL (decl)) != NULL_TREE))
  5119.         error_with_aggr_type (DECL_CONTEXT (decl),
  5120.                   "multiple initializations of static member `%s::%s'",
  5121.                   IDENTIFIER_POINTER (DECL_NAME (decl)));
  5122.     }
  5123.     }
  5124.   else decl = build_decl (VAR_DECL, declarator, type);
  5125.  
  5126.   if (specbits & (1 << (int) RID_EXTERN))
  5127.     {
  5128.       DECL_EXTERNAL (decl) = 1;
  5129.       TREE_EXTERNAL (decl) = !initialized;
  5130.     }
  5131.  
  5132.   /* In class context, static means one per class,
  5133.      public visibility, and static storage.  */
  5134.   if (DECL_FIELD_CONTEXT (decl) != 0
  5135.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  5136.     {
  5137.       TREE_PUBLIC (decl) = 1;
  5138.       TREE_STATIC (decl) = 1;
  5139.     }
  5140.   /* At top level, either `static' or no s.c. makes a definition
  5141.      (perhaps tentative), and absence of `static' makes it public.  */
  5142.   else if (current_binding_level == global_binding_level)
  5143.     {
  5144.       TREE_PUBLIC (decl) = !(specbits & (1 << (int) RID_STATIC));
  5145.       TREE_STATIC (decl) = ! TREE_EXTERNAL (decl);
  5146.     }
  5147.   /* Not at top level, only `static' makes a static definition.  */
  5148.   else
  5149.     {
  5150.       TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
  5151.       TREE_PUBLIC (decl) = TREE_EXTERNAL (decl);
  5152.     }
  5153.   return decl;
  5154. }
  5155.  
  5156. /* Given declspecs and a declarator,
  5157.    determine the name and type of the object declared
  5158.    and construct a ..._DECL node for it.
  5159.    (In one case we can return a ..._TYPE node instead.
  5160.     For invalid input we sometimes return 0.)
  5161.  
  5162.    DECLSPECS is a chain of tree_list nodes whose value fields
  5163.     are the storage classes and type specifiers.
  5164.  
  5165.    DECL_CONTEXT says which syntactic context this declaration is in:
  5166.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  5167.      FUNCDEF for a function definition.  Like NORMAL but a few different
  5168.       error messages in each case.  Return value may be zero meaning
  5169.       this definition is too screwy to try to parse.
  5170.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  5171.       handle member functions (which have FIELD context).
  5172.       Return value may be zero meaning this definition is too screwy to
  5173.       try to parse.
  5174.      PARM for a parameter declaration (either within a function prototype
  5175.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  5176.      TYPENAME if for a typename (in a cast or sizeof).
  5177.       Don't make a DECL node; just return the ..._TYPE node.
  5178.      FIELD for a struct or union field; make a FIELD_DECL.
  5179.      BITFIELD for a field with specified width.
  5180.    INITIALIZED is 1 if the decl has an initializer.
  5181.  
  5182.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  5183.    It may also be so in the PARM case, for a prototype where the
  5184.    argument type is specified but not the name.
  5185.  
  5186.    This function is where the complicated C meanings of `static'
  5187.    and `extern' are intrepreted.
  5188.  
  5189.    For C++, if there is any monkey business to do, the function which
  5190.    calls this one must do it, i.e., prepending instance variables,
  5191.    renaming overloaded function names, etc.
  5192.  
  5193.    Note that for this C++, it is an error to define a method within a class
  5194.    which does not belong to that class.
  5195.  
  5196.    Execpt in the case where SCOPE_REFs are implicitly known (such as
  5197.    methods within a class being redundantly qualified),
  5198.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  5199.    (class_name::decl_name).  The caller must also deal with this.
  5200.  
  5201.    If a constructor or destructor is seen, and the context is FIELD,
  5202.    then the type gains the attribtue TREE_HAS_x.  If such a declaration
  5203.    is erroneous, NULL_TREE is returned.
  5204.  
  5205.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  5206.    function, these are the qualifiers to give to the `this' pointer.
  5207.  
  5208.    May return void_type_node if the declarator turned out to be a friend.
  5209.    See grokfield for details.  */
  5210.  
  5211. enum return_types { return_normal, return_ctor, return_dtor, return_conversion, };
  5212.  
  5213. tree
  5214. grokdeclarator (declarator, declspecs, decl_context, initialized, raises)
  5215.      tree declspecs;
  5216.      tree declarator;
  5217.      enum decl_context decl_context;
  5218.      int initialized;
  5219.      tree raises;
  5220. {
  5221.   extern int current_class_depth;
  5222.  
  5223.   int specbits = 0;
  5224.   int nclasses = 0;
  5225.   tree spec;
  5226.   tree type = NULL_TREE;
  5227.   int longlong = 0;
  5228.   int constp;
  5229.   int volatilep;
  5230.   int virtualp, friendp, inlinep, staticp;
  5231.   int explicit_int = 0;
  5232.   int explicit_char = 0;
  5233.   tree typedef_decl = 0;
  5234.   char *name;
  5235.   tree typedef_type = 0;
  5236.   int funcdef_flag = 0;
  5237.   int resume_temporary = 0;
  5238.   enum tree_code innermost_code = ERROR_MARK;
  5239.   int bitfield = 0;
  5240.   int variable_size = 0;
  5241.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  5242.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  5243.   tree init = 0;
  5244.  
  5245.   /* Keep track of what sort of function is being processed
  5246.      so that we can warn about default return values, or explicit
  5247.      return values which do not match prescribed defaults.  */
  5248.   enum return_types return_type = return_normal;
  5249.  
  5250.   tree dname = NULL_TREE;
  5251.   tree ctype = current_class_type;
  5252.   tree ctor_return_type = NULL_TREE;
  5253.   enum overload_flags flags = NO_SPECIAL;
  5254.   int seen_scope_ref = 0;
  5255.   tree quals = 0;
  5256.  
  5257.   if (decl_context == FUNCDEF)
  5258.     funcdef_flag = 1, decl_context = NORMAL;
  5259.   else if (decl_context == MEMFUNCDEF)
  5260.     funcdef_flag = -1, decl_context = FIELD;
  5261.   else if (decl_context == BITFIELD)
  5262.     bitfield = 1, decl_context = FIELD;
  5263.  
  5264.   if (flag_traditional && allocation_temporary_p ())
  5265.     {
  5266.       resume_temporary = 1;
  5267.       end_temporary_allocation ();
  5268.     }
  5269.  
  5270.   /* Look inside a declarator for the name being declared
  5271.      and get it as a string, for an error message.  */
  5272.   {
  5273.     tree type, last = 0;
  5274.     register tree decl = declarator;
  5275.     name = 0;
  5276.  
  5277.     /* If we see something of the form `aggr_type xyzzy (a, b, c)'
  5278.        it is either an old-style function declaration or a call to
  5279.        a constructor.  The following conditional makes recognizes this
  5280.        case as being a call to a constructor.  Too bad if it is not.  */
  5281.  
  5282.     /* For Doug Lea, also grok `aggr_type xyzzy (a, b, c)[10][10][10]'.  */
  5283.     while (decl && TREE_CODE (decl) == ARRAY_REF)
  5284.       {
  5285.     last = decl;
  5286.     decl = TREE_OPERAND (decl, 0);
  5287.       }
  5288.  
  5289.     if (current_lang_name == lang_name_cplusplus
  5290.         && decl && declspecs
  5291.         && TREE_CODE (decl) == CALL_EXPR
  5292.         && TREE_OPERAND (decl, 0)
  5293.         && (TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  5294.         || TREE_CODE (TREE_OPERAND (decl, 0)) == SCOPE_REF))
  5295.       {
  5296.         type = TREE_CODE (TREE_VALUE (declspecs)) == IDENTIFIER_NODE
  5297.           ? lookup_name (TREE_VALUE (declspecs)) :
  5298.         (IS_AGGR_TYPE (TREE_VALUE (declspecs))
  5299.          ? TYPE_NAME (TREE_VALUE (declspecs)) : NULL_TREE);
  5300.  
  5301.         if (type && TREE_CODE (type) == TYPE_DECL
  5302.             && IS_AGGR_TYPE (TREE_TYPE (type))
  5303.             && parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  5304.           {
  5305.             if (decl_context == FIELD
  5306.                 && TREE_CHAIN (TREE_OPERAND (decl, 1)))
  5307.               {
  5308.                 /* That was an initializer list.  */
  5309.                 sorry ("initializer lists for field declarations");
  5310.                 decl = TREE_OPERAND (decl, 0);
  5311.         if (last)
  5312.           {
  5313.             TREE_OPERAND (last, 0) = decl;
  5314.             decl = declarator;
  5315.           }
  5316.                 declarator = decl;
  5317.                 init = error_mark_node;
  5318.                 goto bot;
  5319.               }
  5320.             else
  5321.               {
  5322.         tree init = TREE_OPERAND (decl, 1);
  5323.         if (last)
  5324.           {
  5325.             TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  5326.             if (pedantic && init)
  5327.               error ("arrays cannot take initializers");
  5328.           }
  5329.         else
  5330.           declarator = TREE_OPERAND (declarator, 0);
  5331.                 decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  5332.                 finish_decl (decl, init, NULL_TREE);
  5333.                 return 0;
  5334.               }
  5335.           }
  5336.  
  5337.         if (parmlist_is_random (TREE_OPERAND (decl, 1)))
  5338.           {
  5339.         decl = TREE_OPERAND (decl, 0);
  5340.         if (TREE_CODE (decl) == SCOPE_REF)
  5341.           {
  5342.         if (TREE_COMPLEXITY (decl))
  5343.           abort ();
  5344.         decl = TREE_OPERAND (decl, 1);
  5345.           }
  5346.         if (TREE_CODE (decl) == IDENTIFIER_NODE)
  5347.           name = IDENTIFIER_POINTER (decl);
  5348.         if (name)
  5349.           error ("bad parameter list specification for function `%s'",
  5350.              name);
  5351.         else
  5352.           error ("bad parameter list specification for function");
  5353.             return 0;
  5354.           }
  5355.       bot:
  5356.         ;
  5357.       }
  5358.     else
  5359.       /* It didn't look like we thought it would, leave the ARRAY_REFs on.  */
  5360.       decl = declarator;
  5361.  
  5362.     while (decl)
  5363.       switch (TREE_CODE (decl))
  5364.         {
  5365.     case WRAPPER_EXPR:      /* for C++ wrappers.  */
  5366.       if (current_lang_name != lang_name_cplusplus)
  5367.         error ("wrapper declared in \"%s\" language context",
  5368.            IDENTIFIER_POINTER (current_lang_name));
  5369.  
  5370.       ctype = NULL_TREE;
  5371.       assert (flags == NO_SPECIAL);
  5372.       flags = WRAPPER_FLAG;
  5373.       decl = TREE_OPERAND (decl, 0);
  5374.       break;
  5375.  
  5376.     case ANTI_WRAPPER_EXPR: /* for C++ wrappers.  */
  5377.       if (current_lang_name != lang_name_cplusplus)
  5378.         error ("anti-wrapper declared in \"%s\" language context",
  5379.            IDENTIFIER_POINTER (current_lang_name));
  5380.  
  5381.       ctype = NULL_TREE;
  5382.       assert (flags == NO_SPECIAL);
  5383.       flags = ANTI_WRAPPER_FLAG;
  5384.       decl = TREE_OPERAND (decl, 0);
  5385.       break;
  5386.  
  5387.     case COND_EXPR:
  5388.       if (current_lang_name != lang_name_cplusplus)
  5389.         error ("wrapper predicate declared in \"%s\" language context",
  5390.            IDENTIFIER_POINTER (current_lang_name));
  5391.  
  5392.       ctype = NULL_TREE;
  5393.       assert (flags == WRAPPER_FLAG);
  5394.       flags = WRAPPER_PRED_FLAG;
  5395.       decl = TREE_OPERAND (decl, 0);
  5396.       break;
  5397.  
  5398.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  5399.       {
  5400.         tree name = TREE_OPERAND (decl, 0);
  5401.         tree rename = NULL_TREE;
  5402.  
  5403.         if (current_lang_name != lang_name_cplusplus)
  5404.           error ("destructor declared in \"%s\" language context",
  5405.              IDENTIFIER_POINTER (current_lang_name));
  5406.  
  5407.         assert (flags == NO_SPECIAL);
  5408.         flags = DTOR_FLAG;
  5409.         return_type = return_dtor;
  5410.         assert (TREE_CODE (name) == IDENTIFIER_NODE);
  5411.         if (ctype == NULL_TREE)
  5412.           {
  5413.         if (current_class_type == NULL_TREE)
  5414.           {
  5415.             error ("destructors must be member functions");
  5416.             flags = NO_SPECIAL;
  5417.           }
  5418.         else
  5419.           {
  5420.             tree t = constructor_name (current_class_name);
  5421.             if (t != name)
  5422.               rename = t;
  5423.           }
  5424.           }
  5425.         else
  5426.           {
  5427.         tree t = constructor_name (ctype);
  5428.         if (t != name)
  5429.           rename = t;
  5430.           }
  5431.  
  5432.         if (rename)
  5433.           {
  5434.         error ("destructor `%s' must match class name `%s'",
  5435.                IDENTIFIER_POINTER (name),
  5436.                IDENTIFIER_POINTER (rename));
  5437.         TREE_OPERAND (decl, 0) = rename;
  5438.           }
  5439.         decl = name;
  5440.       }
  5441.       break;
  5442.  
  5443.     case ADDR_EXPR:         /* C++ reference declaration */
  5444.       /* fall through */
  5445.     case ARRAY_REF:
  5446.     case INDIRECT_REF:
  5447.       ctype = NULL_TREE;
  5448.       innermost_code = TREE_CODE (decl);
  5449.       decl = TREE_OPERAND (decl, 0);
  5450.       break;
  5451.  
  5452.     case CALL_EXPR:
  5453.       innermost_code = TREE_CODE (decl);
  5454.       decl = TREE_OPERAND (decl, 0);
  5455.       if (decl_context == FIELD && ctype == NULL_TREE)
  5456.         ctype = current_class_type;
  5457.       if (ctype != NULL_TREE
  5458.           && decl != NULL_TREE && flags != DTOR_FLAG
  5459.           /* && TREE_CODE (decl) == IDENTIFIER_NODE */
  5460.           && decl == constructor_name (ctype))
  5461.         {
  5462.           return_type = return_ctor;
  5463.           ctor_return_type = ctype;
  5464.         }
  5465.       ctype = NULL_TREE;
  5466.       break;
  5467.  
  5468.     case IDENTIFIER_NODE:
  5469.       dname = decl;
  5470.       name = IDENTIFIER_POINTER (decl);
  5471.       decl = 0;
  5472.       break;
  5473.  
  5474.     case RECORD_TYPE:
  5475.     case UNION_TYPE:
  5476.     case ENUMERAL_TYPE:
  5477.       /* Parse error puts this typespec where
  5478.          a declarator should go.  */
  5479.       error ("declarator name missing");
  5480.       dname = TYPE_NAME (decl);
  5481.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  5482.         dname = DECL_NAME (dname);
  5483.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  5484.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  5485.       decl = 0;
  5486.       break;
  5487.  
  5488.     case OP_IDENTIFIER:
  5489.       if (current_lang_name != lang_name_cplusplus)
  5490.         error ("operator declared in \"%s\" language context",
  5491.            IDENTIFIER_POINTER (current_lang_name));
  5492.  
  5493.       /* C++ operators: if these are member functions, then
  5494.          they overload the same way normal methods do.  However,
  5495.          if they are declared outside of a classes scope, then
  5496.          they are implicitly treated like `friends', i.e.,
  5497.          they do not take any unseen arguments.  */
  5498.       assert (flags == NO_SPECIAL);
  5499.       flags = OP_FLAG;
  5500.       name = "operator name";
  5501.       decl = 0;
  5502.       break;
  5503.  
  5504.     case TYPE_EXPR:
  5505.       if (current_lang_name != lang_name_cplusplus)
  5506.         error ("type conversion operator declared in \"%s\" language context",
  5507.            IDENTIFIER_POINTER (current_lang_name));
  5508.  
  5509.       ctype = NULL_TREE;
  5510.       assert (flags == NO_SPECIAL);
  5511.       flags = TYPENAME_FLAG;
  5512.       name = "operator <typename>";
  5513.       /* Go to the absdcl.  */
  5514.       decl = TREE_OPERAND (decl, 0);
  5515.       return_type = return_conversion;
  5516.       break;
  5517.  
  5518.       /* C++ extension */
  5519.     case SCOPE_REF:
  5520.       if (current_lang_name != lang_name_cplusplus)
  5521.         error ("member function declared in \"%s\" language context",
  5522.            IDENTIFIER_POINTER (current_lang_name));
  5523.       if (seen_scope_ref == 1)
  5524.         error ("multiple `::' terms in declarator invalid");
  5525.       seen_scope_ref += 1;
  5526.       {
  5527.         /* Perform error checking, and convert class names to types.
  5528.            We may call grokdeclarator multiple times for the same
  5529.            tree structure, so only do the conversion once.  In this
  5530.            case, we have exactly what we want for `ctype'.  */
  5531.         tree cname = TREE_OPERAND (decl, 0);
  5532.         if (cname == NULL_TREE)
  5533.           ctype = NULL_TREE;
  5534.         /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
  5535.         else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname)))
  5536.           ctype = cname;
  5537.         else if (! is_aggr_typedef (cname, 1))
  5538.           {
  5539.         TREE_OPERAND (decl, 0) = 0;
  5540.           }
  5541.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  5542.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  5543.         else if (TREE_OPERAND (decl, 1)
  5544.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  5545.           {
  5546.         TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
  5547.           }
  5548.         else if (ctype == NULL_TREE)
  5549.           {
  5550.         ctype = IDENTIFIER_TYPE_VALUE (cname);
  5551.         TREE_OPERAND (decl, 0) = ctype;
  5552.           }
  5553.         else if (TREE_COMPLEXITY (decl) == current_class_depth)
  5554.           TREE_OPERAND (decl, 0) = ctype;
  5555.         else
  5556.           {
  5557.         tree new_type = get_base_type (IDENTIFIER_TYPE_VALUE (cname), ctype, 0);
  5558.         if (new_type == NULL_TREE)
  5559.           {
  5560.             error ("type `%s' is not derived from type `%s'",
  5561.                IDENTIFIER_POINTER (cname),
  5562.                TYPE_NAME_STRING (ctype));
  5563.             TREE_OPERAND (decl, 0) = 0;
  5564.           }
  5565.         else
  5566.           {
  5567.             ctype = new_type;
  5568.             TREE_OPERAND (decl, 0) = ctype;
  5569.           }
  5570.           }
  5571.  
  5572.         decl = TREE_OPERAND (decl, 1);
  5573.         if (ctype != NULL_TREE && constructor_name (ctype) == decl)
  5574.           {
  5575.         return_type = return_ctor;
  5576.         ctor_return_type = ctype;
  5577.           }
  5578.       }
  5579.       break;
  5580.  
  5581.     case ERROR_MARK:
  5582.       decl = NULL_TREE;
  5583.       break;
  5584.  
  5585.     default:
  5586.       assert (0);
  5587.     }
  5588.     if (name == 0)
  5589.       name = "type name";
  5590.   }
  5591.  
  5592.   /* A function definition's declarator must have the form of
  5593.      a function declarator.  */
  5594.  
  5595.   if (funcdef_flag && innermost_code != CALL_EXPR)
  5596.     return 0;
  5597.  
  5598.   /* Anything declared one level down from the top level
  5599.      must be one of the parameters of a function
  5600.      (because the body is at least two levels down).  */
  5601.  
  5602.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  5603.      by not allowing C++ class definitions to specify their parameters
  5604.      with xdecls (must be spec.d in the parmlist).
  5605.  
  5606.      Since we now wait to push a class scope until we are sure that
  5607.      we are in a legitimate method context, we must set oldcname
  5608.      explicitly (since current_class_name is not yet alive).  */
  5609.  
  5610.   if (decl_context == NORMAL
  5611.       && current_binding_level->level_chain == global_binding_level)
  5612.     decl_context = PARM;
  5613.  
  5614.   /* Look through the decl specs and record which ones appear.
  5615.      Some typespecs are defined as built-in typenames.
  5616.      Others, the ones that are modifiers of other types,
  5617.      are represented by bits in SPECBITS: set the bits for
  5618.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  5619.  
  5620.      If there is a typedef name or a type, store the type in TYPE.
  5621.      This includes builtin typedefs such as `int'.
  5622.  
  5623.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  5624.      come from a user typedef.
  5625.  
  5626.      Set LONGLONG if `long' is mentioned twice.
  5627.  
  5628.      For C++, constructors and destructors have their own fast treatment.  */
  5629.  
  5630.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  5631.     {
  5632.       register int i;
  5633.       register tree id = TREE_VALUE (spec);
  5634.  
  5635.       /* Certain parse errors slip through.  For example,
  5636.      `int class;' is not caught by the parser. Try
  5637.      weakly to recover here.  */
  5638.       if (TREE_CODE (spec) != TREE_LIST)
  5639.     return 0;
  5640.  
  5641.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  5642.     {
  5643.       if (id == ridpointers[(int) RID_INT])
  5644.         {
  5645.           if (type)
  5646.         error ("extraneous `int' ignored");
  5647.           else
  5648.         {
  5649.           explicit_int = 1;
  5650.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  5651.         }
  5652.           goto found;
  5653.         }
  5654.       if (id == ridpointers[(int) RID_CHAR])
  5655.         {
  5656.           if (type)
  5657.         error ("extraneous `char' ignored");
  5658.           else
  5659.         {
  5660.           explicit_char = 1;
  5661.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  5662.         }
  5663.           goto found;
  5664.         }
  5665.       /* C++ aggregate types.  */
  5666.       if (IDENTIFIER_HAS_TYPE_VALUE (id))
  5667.         {
  5668.           if (type)
  5669.         error ("multiple declarations `%s' and `%s'",
  5670.                IDENTIFIER_POINTER (type),
  5671.                IDENTIFIER_POINTER (id));
  5672.           else
  5673.         type = IDENTIFIER_TYPE_VALUE (id);
  5674.           goto found;
  5675.         }
  5676.  
  5677.       for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  5678.         {
  5679.           if (ridpointers[i] == id)
  5680.         {
  5681.           if (i == (int) RID_LONG && specbits & (1<<i))
  5682.             {
  5683.               if (pedantic)
  5684.             warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  5685.             else if (longlong)
  5686.               warning ("`long long long' is too long for GCC");
  5687.               else
  5688.             longlong = 1;
  5689.             }
  5690.           else if (specbits & (1 << i))
  5691.             warning ("duplicate `%s'", IDENTIFIER_POINTER (id));
  5692.           specbits |= 1 << i;
  5693.           goto found;
  5694.         }
  5695.         }
  5696.     }
  5697.       if (type)
  5698.     error ("two or more data types in declaration of `%s'", name);
  5699.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  5700.     {
  5701.       register tree t = lookup_name (id);
  5702.       if (!t || TREE_CODE (t) != TYPE_DECL)
  5703.         error ("`%s' fails to be a typedef or built in type",
  5704.            IDENTIFIER_POINTER (id));
  5705.       else
  5706.         {
  5707.           type = TREE_TYPE (t);
  5708.           typedef_decl = t;
  5709.         }
  5710.     }
  5711.       else if (TREE_CODE (id) != ERROR_MARK)
  5712.     /* Can't change CLASS nodes into RECORD nodes here!  */
  5713.     type = id;
  5714.  
  5715.     found: {}
  5716.     }
  5717.  
  5718.   typedef_type = type;
  5719.  
  5720.   /* No type at all: default to `int', and set EXPLICIT_INT
  5721.      because it was not a user-defined typedef.  */
  5722.  
  5723.   if (type == 0)
  5724.     {
  5725.       explicit_int = -1;
  5726.       if (return_type == return_dtor)
  5727.     type = void_type_node;
  5728.       else if (return_type == return_ctor)
  5729.     type = TYPE_POINTER_TO (ctor_return_type);
  5730.       else
  5731.     {
  5732.       if (funcdef_flag && warn_return_type
  5733.           && return_type == return_normal
  5734.           && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  5735.                 | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
  5736.         warn_about_return_type = 1;
  5737.       /* Save warning until we know what is really going on.  */
  5738.       type = integer_type_node;
  5739.     }
  5740.     }
  5741.   else if (return_type == return_dtor)
  5742.     {
  5743.       error ("return type specification for destructor invalid");
  5744.       type = void_type_node;
  5745.     }
  5746.   else if (return_type == return_ctor)
  5747.     {
  5748.       warning ("return type specification for constructor invalid");
  5749.       type = TYPE_POINTER_TO (ctor_return_type);
  5750.     }
  5751.   else if (IS_AGGR_TYPE (type)
  5752.        && ! TYPE_BEING_DEFINED (type)
  5753.        && TYPE_SIZE (type) == NULL_TREE
  5754.        && ! ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))
  5755.        && current_function_decl == NULL_TREE)
  5756.     {
  5757.       /* xref_tag will make friend class declarations look like
  5758.      nested class declarations.  Retroactively change that
  5759.      if the type has not yet been defined.
  5760.  
  5761.      ??? ANSI C++ doesn't say what to do in this case yet.  */
  5762.       globalize_nested_type (type);
  5763.     }
  5764.  
  5765.   ctype = NULL_TREE;
  5766.  
  5767.   /* Now process the modifiers that were specified
  5768.      and check for invalid combinations.  */
  5769.  
  5770.   /* Long double is a special combination.  */
  5771.  
  5772.   if ((specbits & 1 << (int) RID_LONG) && type == double_type_node)
  5773.     {
  5774.       specbits &= ~ (1 << (int) RID_LONG);
  5775.       type = long_double_type_node;
  5776.     }
  5777.  
  5778.   /* Check all other uses of type modifiers.  */
  5779.  
  5780.   if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  5781.           | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
  5782.     {
  5783.       int ok = 0;
  5784.  
  5785.       if (TREE_CODE (type) == REAL_TYPE)
  5786.     error ("short, signed or unsigned invalid for `%s'", name);
  5787.       else if (TREE_CODE (type) != INTEGER_TYPE)
  5788.     error ("long, short, signed or unsigned invalid for `%s'", name);
  5789.       else if ((specbits & 1 << (int) RID_LONG)
  5790.            && (specbits & 1 << (int) RID_SHORT))
  5791.     error ("long and short specified together for `%s'", name);
  5792.       else if (((specbits & 1 << (int) RID_LONG)
  5793.         || (specbits & 1 << (int) RID_SHORT))
  5794.            && explicit_char)
  5795.     error ("long or short specified with char for `%s'", name);
  5796.       else if (((specbits & 1 << (int) RID_LONG)
  5797.         || (specbits & 1 << (int) RID_SHORT))
  5798.            && TREE_CODE (type) == REAL_TYPE)
  5799.     error ("long or short specified with floating type for `%s'", name);
  5800.       else if ((specbits & 1 << (int) RID_SIGNED)
  5801.            && (specbits & 1 << (int) RID_UNSIGNED))
  5802.     error ("signed and unsigned given together for `%s'", name);
  5803.       else
  5804.     {
  5805.       ok = 1;
  5806.       if (!explicit_int && !explicit_char && pedantic)
  5807.         {
  5808.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  5809.                name);
  5810.           if (flag_pedantic_errors)
  5811.         ok = 0;
  5812.         }
  5813.     }
  5814.  
  5815.       /* Discard the type modifiers if they are invalid.  */
  5816.       if (! ok)
  5817.     {
  5818.       specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  5819.             | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
  5820.       longlong = 0;
  5821.     }
  5822.     }
  5823.  
  5824.   /* Decide whether an integer type is signed or not.
  5825.      Optionally treat bitfields as signed by default.  */
  5826.   if (specbits & 1 << (int) RID_UNSIGNED
  5827.       /* Traditionally, all bitfields are unsigned.  */
  5828.       || (bitfield && flag_traditional)
  5829.       || (bitfield && ! flag_signed_bitfields
  5830.       && (explicit_int || explicit_char
  5831.           /* A typedef for plain `int' without `signed'
  5832.          can be controlled just like plain `int'.  */
  5833.           || ! (typedef_decl != 0
  5834.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  5835.       && TREE_CODE (type) != ENUMERAL_TYPE
  5836.       && !(specbits & 1 << (int) RID_SIGNED)))
  5837.     {
  5838.       if (longlong)
  5839.     type = long_long_unsigned_type_node;
  5840.       else if (specbits & 1 << (int) RID_LONG)
  5841.     type = long_unsigned_type_node;
  5842.       else if (specbits & 1 << (int) RID_SHORT)
  5843.     type = short_unsigned_type_node;
  5844.       else if (type == char_type_node)
  5845.     type = unsigned_char_type_node;
  5846.       else
  5847.     type = unsigned_type_node;
  5848.     }
  5849.   else if ((specbits & 1 << (int) RID_SIGNED)
  5850.        && type == char_type_node)
  5851.     type = signed_char_type_node;
  5852.   else if (longlong)
  5853.     type = long_long_integer_type_node;
  5854.   else if (specbits & 1 << (int) RID_LONG)
  5855.     type = long_integer_type_node;
  5856.   else if (specbits & 1 << (int) RID_SHORT)
  5857.     type = short_integer_type_node;
  5858.  
  5859.   /* Set CONSTP if this declaration is `const', whether by
  5860.      explicit specification or via a typedef.
  5861.      Likewise for VOLATILEP.  */
  5862.  
  5863.   constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
  5864.   volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
  5865.   staticp = 0;
  5866.   inlinep = !! (specbits & (1 << (int) RID_INLINE));
  5867.   if (constp > 1)
  5868.     warning ("duplicate `const'");
  5869.   if (volatilep > 1)
  5870.     warning ("duplicate `volatile'");
  5871.   virtualp = specbits & (1 << (int) RID_VIRTUAL);
  5872.   if (specbits & (1 << (int) RID_STATIC))
  5873.     staticp = 1 + (decl_context == FIELD);
  5874.  
  5875.   if (virtualp && staticp == 2)
  5876.     {
  5877.       error ("member `%s' cannot be declared both virtual and static", name);
  5878.       staticp = 0;
  5879.     }
  5880.   friendp = specbits & (1 << (int) RID_FRIEND);
  5881.   specbits &= ~ ((1 << (int) RID_VIRTUAL) | (1 << (int) RID_FRIEND));
  5882.  
  5883.   /* Warn if two storage classes are given. Default to `auto'.  */
  5884.  
  5885.   if (specbits)
  5886.     {
  5887.       if (specbits & 1 << (int) RID_STATIC) nclasses++;
  5888.       if (specbits & 1 << (int) RID_EXTERN) nclasses++;
  5889.       if (decl_context == PARM && nclasses > 0)
  5890.     error ("storage class specifiers invalid in parameter declarations");
  5891.       if (specbits & 1 << (int) RID_TYPEDEF)
  5892.     {
  5893.       if (decl_context == PARM)
  5894.         error ("typedef declaration invalid in parameter declaration");
  5895.       nclasses++;
  5896.     }
  5897.       if (specbits & 1 << (int) RID_AUTO) nclasses++;
  5898.       if (specbits & 1 << (int) RID_REGISTER) nclasses++;
  5899.     }
  5900.  
  5901.   /* Give error if `virtual' is used outside of class declaration.  */
  5902.   if (virtualp && current_class_name == NULL_TREE)
  5903.     {
  5904.       error ("virtual outside class declaration");
  5905.       virtualp = 0;
  5906.     }
  5907.  
  5908.   /* Warn about storage classes that are invalid for certain
  5909.      kinds of declarations (parameters, typenames, etc.).  */
  5910.  
  5911.   if (nclasses > 1)
  5912.     error ("multiple storage classes in declaration of `%s'", name);
  5913.   else if (decl_context != NORMAL && nclasses > 0)
  5914.     {
  5915.       if (decl_context == PARM
  5916.       && ((specbits & (1 << (int) RID_REGISTER)) | (1 << (int) RID_AUTO)))
  5917.     ;
  5918.       else if (decl_context == FIELD
  5919.            && (specbits
  5920.            & (/* C++ allows static class elements  */
  5921.               (1 << (int) RID_STATIC)
  5922.               /* ...and inlines  */
  5923.               | (1 << (int) RID_INLINE)
  5924.               /* ...and signed and unsigned elements.  */
  5925.               | (1 << (int) RID_SIGNED)
  5926.               | (1 << (int) RID_UNSIGNED))))
  5927.     ;
  5928.       else if (decl_context == FIELD && (specbits & (1 << (int) RID_TYPEDEF)))
  5929.     {
  5930.       /* A typedef which was made in a class's scope.  */
  5931.       tree loc_typedecl;
  5932.       register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  5933.       register int *pi;
  5934.  
  5935.       /* keep `grokdeclarator' from thinking we are in PARM context.  */
  5936.       pushlevel (0);
  5937.       loc_typedecl = start_decl (declarator, declspecs, initialized, NULL_TREE);
  5938.  
  5939.       pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  5940.       while (i > 0)
  5941.         pi[--i] = 0;
  5942.       DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  5943.       poplevel (0, 0, 0);
  5944.  
  5945. #if 0
  5946.       if (TREE_CODE (TREE_TYPE (loc_typedecl)) == ENUMERAL_TYPE)
  5947.         {
  5948.           tree ref = lookup_tag (ENUMERAL_TYPE, DECL_NAME (loc_typedecl), current_binding_level, 0);
  5949.           if (! ref)
  5950.         pushtag (DECL_NAME (loc_typedecl), TREE_TYPE (loc_typedecl));
  5951.         }
  5952. #endif
  5953.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)))
  5954.         error_with_decl (loc_typedecl,
  5955.                  "typedef of `%s' in class scope hides previous declaration");
  5956. #if 0
  5957.       /* Must push this into scope via `pushdecl_class_level'.  */
  5958.       IDENTIFIER_CLASS_VALUE (DECL_NAME (loc_typedecl)) = loc_typedecl;
  5959. #endif
  5960.       return loc_typedecl;
  5961.     }
  5962.       else
  5963.     {
  5964.       error ((decl_context == FIELD
  5965.           ? "storage class specified for structure field `%s'"
  5966.           : (decl_context == PARM
  5967.              ? "storage class specified for parameter `%s'"
  5968.              : "storage class specified for typename")),
  5969.          name);
  5970.       specbits &= ~ ((1 << (int) RID_REGISTER) | (1 << (int) RID_AUTO)
  5971.              | (1 << (int) RID_EXTERN));
  5972.     }
  5973.     }
  5974.   else if (specbits & 1 << (int) RID_EXTERN && initialized)
  5975.     {
  5976.       /* `extern' with initialization is invalid if not at top level.  */
  5977.       if (current_binding_level == global_binding_level)
  5978.     warning ("`%s' initialized and declared `extern'", name);
  5979.       else
  5980.     error ("`%s' has both `extern' and initializer", name);
  5981.     }
  5982.   else if (current_binding_level == global_binding_level)
  5983.     {
  5984.       if (specbits & (1 << (int) RID_AUTO))
  5985.     error ("top-level declaration of `%s' specifies `auto'", name);
  5986. #if 0
  5987.       if (specbits & (1 << (int) RID_REGISTER))
  5988.     error ("top-level declaration of `%s' specifies `register'", name);
  5989. #endif
  5990. #if 0
  5991.       /* I'm not sure under what circumstances we should turn
  5992.      on the extern bit, and under what circumstances we should
  5993.      warn if other bits are turned on.  */
  5994.       if (decl_context == NORMAL
  5995.       && (specbits & (1 << (int) RID_EXTERN)) == 0
  5996.       && ! root_lang_context_p ())
  5997.     {
  5998.       specbits |= (1 << (int) RID_EXTERN);
  5999.     }
  6000. #endif
  6001.     }
  6002.  
  6003.   /* Now figure out the structure of the declarator proper.
  6004.      Descend through it, creating more complex types, until we reach
  6005.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  6006.  
  6007.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  6008.     {
  6009.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  6010.      an INDIRECT_REF (for *...),
  6011.      a CALL_EXPR (for ...(...)),
  6012.      an identifier (for the name being declared)
  6013.      or a null pointer (for the place in an absolute declarator
  6014.      where the name was omitted).
  6015.      For the last two cases, we have just exited the loop.
  6016.  
  6017.      For C++ it could also be
  6018.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  6019.      sensible names to types, and those are the values we use to
  6020.      qualify the member name.
  6021.      an ADDR_EXPR (for &...),
  6022.      a BIT_NOT_EXPR (for destructors)
  6023.      a TYPE_EXPR (for operator typenames)
  6024.      a WRAPPER_EXPR (for wrappers)
  6025.      an ANTI_WRAPPER_EXPR (for averting wrappers)
  6026.  
  6027.      At this point, TYPE is the type of elements of an array,
  6028.      or for a function to return, or for a pointer to point to.
  6029.      After this sequence of ifs, TYPE is the type of the
  6030.      array or function or pointer, and DECLARATOR has had its
  6031.      outermost layer removed.  */
  6032.  
  6033.       if (TREE_CODE (type) == ERROR_MARK
  6034.       && TREE_CODE (declarator) != OP_IDENTIFIER)
  6035.     {
  6036.       if (TREE_CODE (declarator) == SCOPE_REF)
  6037.         declarator = TREE_OPERAND (declarator, 1);
  6038.       else
  6039.         declarator = TREE_OPERAND (declarator, 0);
  6040.       continue;
  6041.     }
  6042.       if (quals != NULL_TREE
  6043.       && (declarator == NULL_TREE
  6044.           || TREE_CODE (declarator) != SCOPE_REF))
  6045.     {
  6046.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  6047.         ctype = TYPE_METHOD_BASETYPE (type);
  6048.       if (ctype != NULL_TREE)
  6049.         {
  6050.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  6051.           ctype = grok_method_quals (ctype, dummy, quals);
  6052.           type = TREE_TYPE (dummy);
  6053.           quals = NULL_TREE;
  6054.         }
  6055.     }
  6056.       switch (TREE_CODE (declarator))
  6057.     {
  6058.     case ARRAY_REF:
  6059.       {
  6060.         register tree itype = NULL_TREE;
  6061.         register tree size = TREE_OPERAND (declarator, 1);
  6062.  
  6063.         declarator = TREE_OPERAND (declarator, 0);
  6064.  
  6065.         /* Check for some types that there cannot be arrays of.  */
  6066.  
  6067.         if (type == void_type_node)
  6068.           {
  6069.         error ("declaration of `%s' as array of voids", name);
  6070.         type = error_mark_node;
  6071.           }
  6072.  
  6073.         if (TREE_CODE (type) == FUNCTION_TYPE)
  6074.           {
  6075.         error ("declaration of `%s' as array of functions", name);
  6076.         type = error_mark_node;
  6077.           }
  6078.  
  6079.         if (size == error_mark_node)
  6080.           type = error_mark_node;
  6081.  
  6082.         if (type == error_mark_node)
  6083.           continue;
  6084.  
  6085.         if (size)
  6086.           {
  6087.         /* Must suspend_momentary here because the index
  6088.            type may need to live until the end of the function.
  6089.            For example, it is used in the declaration of a
  6090.            variable which requires destructing at the end of
  6091.            the function; then build_vec_delete will need this
  6092.            value.  */
  6093.         int yes = suspend_momentary ();
  6094.         /* might be a cast */
  6095.         if (TREE_CODE (size) == NOP_EXPR
  6096.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  6097.           size = TREE_OPERAND (size, 0);
  6098.  
  6099.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  6100.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  6101.           {
  6102.             error ("size of array `%s' has non-integer type", name);
  6103.             size = integer_one_node;
  6104.           }
  6105.         if (TREE_READONLY_DECL_P (size))
  6106.           size = decl_constant_value (size);
  6107.         if (pedantic && integer_zerop (size))
  6108.           warning ("ANSI C forbids zero-size array `%s'", name);
  6109.         if (TREE_CONSTANT (size))
  6110.           {
  6111.             if (INT_CST_LT (size, integer_zero_node))
  6112.               {
  6113.             error ("size of array `%s' is negative", name);
  6114.             size = integer_one_node;
  6115.               }
  6116.             itype = build_index_type (size_binop (MINUS_EXPR, size,
  6117.                               integer_one_node));
  6118.           }
  6119.         else
  6120.           {
  6121.             if (pedantic)
  6122.               warning ("ANSI C forbids variable-size array `%s'", name);
  6123.             itype = build_binary_op (MINUS_EXPR, size, integer_one_node);
  6124.             itype = build_index_type (itype);
  6125.           }
  6126.         resume_momentary (yes);
  6127.           }
  6128.  
  6129.         /* Build the array type itself.
  6130.            Merge any constancy or volatility into the target type.  */
  6131.  
  6132.         if (constp || volatilep)
  6133.           type = build_type_variant (type, constp, volatilep);
  6134.  
  6135. #if 0   /* don't clear these; leave them set so that the array type
  6136.        or the variable is itself const or volatile.  */
  6137.         constp = 0;
  6138.         volatilep = 0;
  6139. #endif
  6140.  
  6141.         type = build_cplus_array_type (type, itype);
  6142.         ctype = NULL_TREE;
  6143.       }
  6144.       break;
  6145.  
  6146.     case CALL_EXPR:
  6147.       {
  6148.         tree arg_types;
  6149.  
  6150.         /* Declaring a function type.
  6151.            Make sure we have a valid type for the function to return.  */
  6152.         /* Is this an error?  Should they be merged into TYPE here?  */
  6153.         if (pedantic && (constp || volatilep))
  6154.           warning ("function declared to return const or volatile result");
  6155.  
  6156.         /* Warn about some types functions can't return.  */
  6157.  
  6158.         if (TREE_CODE (type) == FUNCTION_TYPE)
  6159.           {
  6160.         error ("`%s' declared as function returning a function", name);
  6161.         type = integer_type_node;
  6162.           }
  6163.         if (TREE_CODE (type) == ARRAY_TYPE)
  6164.           {
  6165.         error ("`%s' declared as function returning an array", name);
  6166.         type = integer_type_node;
  6167.           }
  6168.  
  6169.         if (ctype == NULL_TREE
  6170.         && decl_context == FIELD
  6171.         && (friendp == 0 || dname == current_class_name))
  6172.           ctype = current_class_type;
  6173.  
  6174.         if (ctype && flags == TYPENAME_FLAG)
  6175.           TYPE_HAS_CONVERSION (ctype) = 1;
  6176.         if (ctype && constructor_name (ctype) == dname)
  6177.           {
  6178.         /* We are within a class's scope. If our declarator name
  6179.            is the same as the class name, and we are defining
  6180.            a function, then it is a constructor/destructor, and
  6181.            therefore returns a void type.  */
  6182.  
  6183.         if (flags == DTOR_FLAG)
  6184.           {
  6185.             if (staticp == 2)
  6186.               error ("destructor cannot be static member function");
  6187.             if (decl_context == FIELD)
  6188.               {
  6189.             if (! member_function_or_else (ctype, current_class_type,
  6190.                                "destructor for alien class `%s' cannot be a member"))
  6191.               return NULL_TREE;
  6192.             if (TYPE_HAS_DESTRUCTOR (ctype))
  6193.               error_with_aggr_type (ctype, "class `%s' already has destructor defined");
  6194.               }
  6195.           }
  6196.         else if (flags == WRAPPER_FLAG || flags == ANTI_WRAPPER_FLAG)
  6197.           {
  6198.             if (staticp == 2)
  6199.               error ("wrapper cannot be static member function");
  6200.             if (decl_context == FIELD)
  6201.               {
  6202.             if (! member_function_or_else (ctype, current_class_type,
  6203.                                "wrapper for alien class `%s' cannot be member"))
  6204.               return NULL_TREE;
  6205.             TYPE_WRAP_TYPE (ctype) = TYPE_MAIN_VARIANT (ctype);
  6206.               }
  6207.           }
  6208.         else if (flags == WRAPPER_PRED_FLAG)
  6209.           {
  6210.             if (staticp == 2)
  6211.               error ("wrapper predicate cannot be static member function");
  6212.             if (TREE_CODE (type) != INTEGER_TYPE)
  6213.               {
  6214.             error ("wrapper predicated must return an integer type");
  6215.             type = integer_type_node;
  6216.               }
  6217.             if (decl_context == FIELD)
  6218.               {
  6219.             if (! member_function_or_else (ctype, current_class_type,
  6220.                                "wrapper predicate for alien class `%s' cannot be member"))
  6221.               return NULL_TREE;
  6222.             TYPE_HAS_WRAPPER_PRED (ctype) = 1;
  6223.               }
  6224.           }
  6225.         else            /* its a constructor. */
  6226.           {
  6227.             if (staticp == 2)
  6228.               error ("constructor cannot be static member function");
  6229.             if (virtualp || friendp)
  6230.               {
  6231.             error ("constructors cannot be declared virtual or friend");
  6232.             virtualp = 0;
  6233.             friendp = 0;
  6234.               }
  6235.             if (specbits & ~((1 << (int) RID_INLINE)|(1 << (int) RID_STATIC)))
  6236.               error ("return value type specifier for %s ignored",
  6237.                  flags == DTOR_FLAG ? "destructor" : "constructor");
  6238.             type = TYPE_POINTER_TO (ctype);
  6239.             if (decl_context == FIELD)
  6240.               {
  6241.             if (! member_function_or_else (ctype, current_class_type,
  6242.                                "constructor for alien class `%s' cannot be member"))
  6243.               return NULL_TREE;
  6244.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  6245.             assert (return_type == return_ctor);
  6246.               }
  6247.           }
  6248.         if (decl_context == FIELD)
  6249.           staticp = 0;
  6250.           }
  6251.         else if (friendp && virtualp)
  6252.           {
  6253.         /* Cannot be both friend and virtual.  */
  6254.         error ("virtual functions cannot be friends");
  6255.         specbits ^= (1 << (int) RID_FRIEND);
  6256.           }
  6257.  
  6258.         if (decl_context == NORMAL && friendp)
  6259.           error ("friend declaration not in class definition");
  6260.  
  6261.         /* Picky up type qualifiers which should be applied to `this'.  */
  6262.         quals = TREE_OPERAND (declarator, 2);
  6263.  
  6264.         /* Traditionally, declaring return type float means double.  */
  6265.  
  6266.         if (flag_traditional && type == float_type_node)
  6267.           type = double_type_node;
  6268.  
  6269.         /* Construct the function type and go to the next
  6270.            inner layer of declarator.  */
  6271.  
  6272.         {
  6273.           int funcdef_p;
  6274.           tree inner_parms = TREE_OPERAND (declarator, 1);
  6275.           tree inner_decl = TREE_OPERAND (declarator, 0);
  6276.  
  6277.           declarator = TREE_OPERAND (declarator, 0);
  6278.  
  6279.           if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  6280.         inner_decl = TREE_OPERAND (inner_decl, 1);
  6281.  
  6282.           /* Say it's a definition only for the CALL_EXPR
  6283.          closest to the identifier.  */
  6284.           funcdef_p =
  6285.         (inner_decl &&
  6286.          (TREE_CODE (inner_decl) == IDENTIFIER_NODE
  6287.           || TREE_CODE (inner_decl) == OP_IDENTIFIER
  6288.           || TREE_CODE (inner_decl) == TYPE_EXPR)) ? funcdef_flag : 0;
  6289.  
  6290.           arg_types = grokparms (inner_parms, funcdef_p);
  6291.         }
  6292.  
  6293.         if (declarator)
  6294.           {
  6295.         /* Get past destructors, wrappers, etc.
  6296.            We know we have one because FLAGS will be non-zero.
  6297.  
  6298.            Complain about improper parameter lists here.  */
  6299.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  6300.           {
  6301.             declarator = TREE_OPERAND (declarator, 0);
  6302.  
  6303.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  6304.               arg_types = void_list_node;
  6305.             else if (arg_types == NULL_TREE
  6306.                  || arg_types != void_list_node)
  6307.               {
  6308.             error ("destructors cannot be specified with parameters");
  6309.             arg_types = void_list_node;
  6310.               }
  6311.           }
  6312.         else if (TREE_CODE (declarator) == WRAPPER_EXPR)
  6313.           {
  6314.             /* Report misuse of wrappers and their associates.
  6315.                Note that because wrappers may be invoked
  6316.                quite a bit implicitly, if we give an error
  6317.                message, we make an effort to fix that error
  6318.                so that spurious errors do not show up.  */
  6319.             if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
  6320.               {
  6321.             /* First parameter must be a pointer to a member function.
  6322.                Rest of parameters must all be default parameters.  */
  6323.             if (arg_types == NULL_TREE
  6324.                 || arg_types == void_list_node
  6325.                 || TREE_CODE (TREE_VALUE (arg_types)) != POINTER_TYPE
  6326.                 || TREE_CODE (TREE_TYPE (TREE_VALUE (arg_types))) != METHOD_TYPE)
  6327.               {
  6328.                 error ("wrapper predicate takes a pointer-to-member-function as first argument");
  6329.                 arg_types = NULL_TREE;
  6330.               }
  6331.             else if (TREE_CHAIN (arg_types)
  6332.                  && TREE_CHAIN (arg_types) != void_list_node
  6333.                  && TREE_PURPOSE (TREE_CHAIN (arg_types)) == NULL_TREE)
  6334.               {
  6335.                 error ("all arguments past first must be default for wrapper predicate");
  6336.                 TREE_CHAIN (arg_types) = NULL_TREE;
  6337.               }
  6338.             declarator = wrapper_pred_name;
  6339.               }
  6340.             else
  6341.               {
  6342.             /* First parameter must be an int.
  6343.                Second parameter must be a pointer to a member function.  */
  6344.             if (arg_types == NULL_TREE || TREE_CHAIN (arg_types) == NULL_TREE)
  6345.               {
  6346.                 error ("wrappers must have at least two arguments (int, pointer-to-member-function)");
  6347.                 arg_types = NULL_TREE;
  6348.               }
  6349.             else
  6350.               {
  6351.                 if (TREE_CODE (TREE_VALUE (arg_types)) != INTEGER_TYPE)
  6352.                   {
  6353.                 error ("first argument to wrapper must be an integer");
  6354.                 TREE_VALUE (arg_types) = integer_type_node;
  6355.                   }
  6356.                 if (TREE_CODE (TREE_VALUE (TREE_CHAIN (arg_types))) != POINTER_TYPE
  6357.                 || TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (arg_types)))) != METHOD_TYPE)
  6358.                   {
  6359.                 error ("second argument to wrapper must be a pointer-to-member-function type");
  6360.                 TREE_CHAIN (arg_types) = NULL_TREE;
  6361.                   }
  6362.               }
  6363.             declarator = wrapper_name;
  6364.               }
  6365.           }
  6366.         else if (TREE_CODE (declarator) == ANTI_WRAPPER_EXPR)
  6367.           declarator = anti_wrapper_name;
  6368.           }
  6369.  
  6370.         type = build_function_type (type, flag_traditional ? 0 : arg_types);
  6371.       }
  6372.       break;
  6373.  
  6374.     case ADDR_EXPR:
  6375.     case INDIRECT_REF:
  6376.       /* Filter out pointers-to-references and references-to-references.
  6377.          We can get these if a TYPE_DECL is used.  */
  6378.  
  6379.       if (TREE_CODE (type) == REFERENCE_TYPE)
  6380.         {
  6381.           error ("cannot declare %s to references",
  6382.              TREE_CODE (declarator) == ADDR_EXPR
  6383.              ? "references" : "pointers");
  6384.           declarator = TREE_OPERAND (declarator, 0);
  6385.           continue;
  6386.         }
  6387.  
  6388.       /* Merge any constancy or volatility into the target type
  6389.          for the pointer.  */
  6390.  
  6391.       if (constp || volatilep)
  6392.         {
  6393.           type = build_type_variant (type, constp, volatilep);
  6394.           if (IS_AGGR_TYPE (type))
  6395.         build_pointer_type (type);
  6396.         }
  6397.       constp = 0;
  6398.       volatilep = 0;
  6399.  
  6400.       if (TREE_CODE (declarator) == ADDR_EXPR)
  6401.         if (TREE_CODE (type) == FUNCTION_TYPE)
  6402.           {
  6403.         error ("cannot declare references to functions; use pointer to function instead");
  6404.         type = build_pointer_type (type);
  6405.           }
  6406.         else
  6407.           {
  6408.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  6409.           error ("invalid type: `void &'");
  6410.         else
  6411.           type = build_reference_type (type);
  6412.           }
  6413.       else
  6414.         type = build_pointer_type (type);
  6415.  
  6416.       /* Process a list of type modifier keywords (such as
  6417.          const or volatile) that were given inside the `*' or `&'.  */
  6418.  
  6419.       if (TREE_TYPE (declarator))
  6420.         {
  6421.           register tree typemodlist;
  6422.           int erred = 0;
  6423.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  6424.            typemodlist = TREE_CHAIN (typemodlist))
  6425.         {
  6426.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  6427.             constp++;
  6428.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  6429.             volatilep++;
  6430.           else if (!erred)
  6431.             {
  6432.               erred = 1;
  6433.               error ("invalid type modifier within %s declarator",
  6434.                  TREE_CODE (declarator) == ADDR_EXPR
  6435.                  ? "reference" : "pointer");
  6436.             }
  6437.         }
  6438.           if (constp > 1)
  6439.         warning ("duplicate `const'");
  6440.           if (volatilep > 1)
  6441.         warning ("duplicate `volatile'");
  6442.         }
  6443.       declarator = TREE_OPERAND (declarator, 0);
  6444.       ctype = NULL_TREE;
  6445.       break;
  6446.  
  6447.     case SCOPE_REF:
  6448.       {
  6449.         /* We have converted type names to NULL_TREE if the
  6450.            name was bogus, or to a _TYPE node, if not.
  6451.  
  6452.            The variable CTYPE holds the type we will ultimately
  6453.            resolve to.  The code here just needs to build
  6454.            up appropriate member types.  */
  6455.         tree sname = TREE_OPERAND (declarator, 1);
  6456.  
  6457.         if (TREE_COMPLEXITY (declarator) == 0)
  6458.           /* This needs to be here, in case we are called
  6459.          multiple times.  */ ;
  6460.         else if (TREE_COMPLEXITY (declarator) == current_class_depth)
  6461.           {
  6462.         TREE_COMPLEXITY (declarator) -= 1;
  6463.         popclass (1);
  6464.           }
  6465.         else
  6466.           abort ();
  6467.  
  6468.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  6469.           {
  6470.         /* We had a reference to a global decl, or
  6471.            perhaps we were given a non-aggregate typedef,
  6472.            in which case we cleared this out, and should just
  6473.            keep going as though it wasn't there.  */
  6474.         declarator = sname;
  6475.         continue;
  6476.           }
  6477.         ctype = TREE_OPERAND (declarator, 0);
  6478.  
  6479.         if (sname == NULL_TREE)
  6480.           goto done_scoping;
  6481.  
  6482.         /* Destructors can have their visibilities changed as well.  */
  6483.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  6484.           sname = TREE_OPERAND (sname, 0);
  6485.  
  6486.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  6487.           {
  6488.         /* This is the `standard' use of the scoping operator:
  6489.            basetype :: member .  */
  6490.  
  6491.         if (ctype == current_class_type || friendp)
  6492.           if (TREE_CODE (type) == FUNCTION_TYPE)
  6493.             type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6494.           else
  6495.             type = build_member_type (ctype, type);
  6496.         else if (TYPE_SIZE (ctype) != 0
  6497.             || (specbits & (1<<(int)RID_TYPEDEF)))
  6498.           {
  6499.             tree t;
  6500.             /* have to move this code elsewhere in this function.
  6501.                this code is used for i.e., typedef int A::M; M *pm; */
  6502.  
  6503.             if (decl_context == FIELD)
  6504.               {
  6505.             t = lookup_field (ctype, sname, 0);
  6506.             if (t)
  6507.               {
  6508.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  6509.                 DECL_INITIAL (t) = init;
  6510.                 return t;
  6511.               }
  6512.             /* No such field, try member functions.  */
  6513.             t = lookup_fnfields (CLASSTYPE_AS_LIST (ctype), sname, 0);
  6514.             if (t)
  6515.               {
  6516.                 if (flags == DTOR_FLAG)
  6517.                   t = TREE_VALUE (t);
  6518.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  6519.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  6520.                   {
  6521.                 /* Don't include destructor with constructors.  */
  6522.                 t = DECL_CHAIN (TREE_VALUE (t));
  6523.                 if (t == NULL_TREE)
  6524.                   error ("class `%s' does not have any constructors", IDENTIFIER_POINTER (sname));
  6525.                 t = build_tree_list (NULL_TREE, t);
  6526.                   }
  6527.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  6528.                 DECL_INITIAL (t) = init;
  6529.                 return t;
  6530.               }
  6531.  
  6532.             if (flags == TYPENAME_FLAG)
  6533.               error_with_aggr_type (ctype, "type conversion is not a member of structure `%s'");
  6534.             else
  6535.               error ("field `%s' is not a member of structure `%s'",
  6536.                  IDENTIFIER_POINTER (sname),
  6537.                  TYPE_NAME_STRING (ctype));
  6538.               }
  6539.             if (TREE_CODE (type) == FUNCTION_TYPE)
  6540.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6541.             else
  6542.               type = build_member_type (ctype, type);
  6543.           }
  6544.         else
  6545.           sorry ("structure `%s' not yet defined",
  6546.              TYPE_NAME_STRING (ctype));
  6547.         declarator = sname;
  6548.           }
  6549.         else if (TREE_CODE (sname) == TYPE_EXPR)
  6550.           {
  6551.         /* A TYPE_EXPR will change types out from under us.
  6552.            So do the TYPE_EXPR now, and make this SCOPE_REF
  6553.            inner to the TYPE_EXPR's CALL_EXPR.
  6554.  
  6555.            This does not work if we don't get a CALL_EXPR back.
  6556.            I did not think about error recovery, hence the
  6557.            assert (0).  */
  6558.  
  6559.         /* Get the CALL_EXPR.  */
  6560.         sname = grokoptypename (sname, 0);
  6561.         assert (TREE_CODE (sname) == CALL_EXPR);
  6562.         type = TREE_TYPE (TREE_OPERAND (sname, 0));
  6563.         /* Scope the CALL_EXPR's name.  */
  6564.         TREE_OPERAND (declarator, 1) = TREE_OPERAND (sname, 0);
  6565.         /* Put the SCOPE_EXPR in the CALL_EXPR's innermost position.  */
  6566.         TREE_OPERAND (sname, 0) = declarator;
  6567.         /* Now work from the CALL_EXPR.  */
  6568.         declarator = sname;
  6569.         continue;
  6570.           }
  6571.         else if (TREE_CODE (sname) == SCOPE_REF)
  6572.           abort ();
  6573.         else
  6574.           {
  6575.           done_scoping:
  6576.         declarator = TREE_OPERAND (declarator, 1);
  6577.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  6578.           /* In this case, we will deal with it later.  */
  6579.           ;
  6580.         else
  6581.           {
  6582.             if (TREE_CODE (type) == FUNCTION_TYPE)
  6583.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6584.             else
  6585.               type = build_member_type (ctype, type);
  6586.           }
  6587.           }
  6588.       }
  6589.       break;
  6590.  
  6591.     case OP_IDENTIFIER:
  6592.       /* This is exceptional, in that we must finalize a 
  6593.          member type before calling grokopexpr, if we want
  6594.          to use the declared type information to resolve
  6595.          ambiguities.  Do not get fooled by friends,
  6596.          which do not have a member type built for them
  6597.          unless they were explicitly scoped (in which case that
  6598.          will have been taken care of in the SCOPE_REF case).  */
  6599.       if (TREE_CODE (type) != FUNCTION_TYPE
  6600.           && TREE_CODE (type) != METHOD_TYPE)
  6601.         {
  6602.           error ("operator name missing at this point in file");
  6603.           if (ctype)
  6604.         type = build_cplus_method_type (ctype, type, NULL_TREE);
  6605.           else
  6606.         type = build_function_type (type, NULL_TREE);
  6607.         }
  6608.       if (TREE_CODE (TREE_OPERAND (declarator, 0)) == NEW_EXPR)
  6609.         {
  6610.           int was_method = ctype || TREE_CODE (type) == METHOD_TYPE;
  6611.           type = coerce_new_type (ctype, type);
  6612.           if (was_method)
  6613.         staticp = 2;
  6614.         }
  6615.       else if (TREE_CODE (TREE_OPERAND (declarator, 0)) == DELETE_EXPR)
  6616.         {
  6617.           int was_method = ctype || TREE_CODE (type) == METHOD_TYPE;
  6618.           type = coerce_delete_type (ctype, type);
  6619.           if (was_method)
  6620.         staticp = 2;
  6621.         }
  6622.       else if (TREE_CODE (type) == FUNCTION_TYPE
  6623.            && ctype != 0
  6624.            && (friendp == 0 || staticp < 2))
  6625.         type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6626.       {
  6627.         tree tmp = declarator;
  6628.         declarator = grokopexpr (&tmp, ctype, type, 0,
  6629.                      staticp == 2 ? 2 : 1);
  6630.       }
  6631.       if (declarator == NULL_TREE)
  6632.         return NULL_TREE;
  6633.       name = IDENTIFIER_POINTER (declarator);
  6634.       break;
  6635.  
  6636.     case BIT_NOT_EXPR:
  6637.       declarator = TREE_OPERAND (declarator, 0);
  6638.       break;
  6639.  
  6640.     case TYPE_EXPR:
  6641.       declarator = grokoptypename (declarator, 0);
  6642.       if (explicit_int != -1)
  6643.         if (comp_target_types (type, TREE_TYPE (TREE_OPERAND (declarator, 0)), 1) == 0)
  6644.           error ("type conversion function declared to return incongruent type");
  6645.         else
  6646.           warning ("return type specified for type conversion function");
  6647.       type = TREE_TYPE (TREE_OPERAND (declarator, 0));
  6648.       break;
  6649.  
  6650.     case WRAPPER_EXPR:
  6651.       if (TREE_CODE (TREE_OPERAND (declarator, 0)) == COND_EXPR)
  6652.         declarator = wrapper_pred_name;
  6653.       else
  6654.         declarator = wrapper_name;
  6655.       break;
  6656.  
  6657.     case ANTI_WRAPPER_EXPR:
  6658.       declarator = anti_wrapper_name;
  6659.       break;
  6660.  
  6661.     case RECORD_TYPE:
  6662.     case UNION_TYPE:
  6663.     case ENUMERAL_TYPE:
  6664.       declarator = 0;
  6665.       break;
  6666.  
  6667.     case ERROR_MARK:
  6668.       declarator = 0;
  6669.       break;
  6670.  
  6671.     default:
  6672.       assert (0);
  6673.     }
  6674.     }
  6675.  
  6676.   /* Now TYPE has the actual type.  */
  6677.  
  6678.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  6679.  
  6680.   if (specbits & (1 << (int) RID_TYPEDEF))
  6681.     {
  6682.       tree decl;
  6683.  
  6684.       /* Note that the grammar rejects storage classes
  6685.      in typenames, fields or parameters.  */
  6686.       if (constp || volatilep)
  6687.     type = build_type_variant (type, constp, volatilep);
  6688.  
  6689.       /* If the user declares "struct {...} foo" then `foo' will have
  6690.      an anonymous name.  Fill that name in now.  Nothing can
  6691.      refer to it, so nothing needs know about the name change.
  6692.      The TYPE_NAME field was filled in by build_struct_xref.  */
  6693.       if (TYPE_NAME (type)
  6694. #ifndef BREAK_C_TAGS
  6695.       && current_lang_name == lang_name_cplusplus
  6696. #endif
  6697.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  6698.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
  6699.     {
  6700.       /* replace the anonymous name with the real name everywhere.  */
  6701.       lookup_tag_reverse (type, declarator);
  6702.       TYPE_IDENTIFIER (type) = declarator;
  6703.  
  6704.       /* Replace names of default constructors and/or destructors.  */
  6705.       if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_METHOD_VEC (type))
  6706.         {
  6707.           tree method_vec = CLASSTYPE_METHOD_VEC (type);
  6708.           tree fndecl = TREE_VEC_ELT (method_vec, 0);
  6709.           while (fndecl)
  6710.         {
  6711.           DECL_ORIGINAL_NAME (fndecl) = declarator;
  6712.           fndecl = DECL_CHAIN  (fndecl);
  6713.         }
  6714.         }
  6715.     }
  6716.  
  6717.       decl = build_decl (TYPE_DECL, declarator, type);
  6718.       if (quals)
  6719.     {
  6720.       if (ctype == NULL_TREE)
  6721.         {
  6722.           assert (TREE_CODE (type) == METHOD_TYPE);
  6723.           ctype = TYPE_METHOD_BASETYPE (type);
  6724.         }
  6725.       grok_method_quals (ctype, decl, quals);
  6726.     }
  6727.  
  6728.       if (specbits & (1 << (int) RID_SIGNED))
  6729.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  6730.  
  6731.       if (resume_temporary)
  6732.     resume_temporary_allocation ();
  6733.       return decl;
  6734.     }
  6735.  
  6736.   /* Detect the case of an array type of unspecified size
  6737.      which came, as such, direct from a typedef name.
  6738.      We must copy the type, so that each identifier gets
  6739.      a distinct type, so that each identifier's size can be
  6740.      controlled separately by its own initializer.  */
  6741.  
  6742.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  6743.       && TYPE_DOMAIN (type) == 0)
  6744.     {
  6745.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  6746.     }
  6747.  
  6748.   /* If this is a type name (such as, in a cast or sizeof),
  6749.      compute the type and return it now.  */
  6750.  
  6751.   if (decl_context == TYPENAME)
  6752.     {
  6753.       /* Note that the grammar rejects storage classes
  6754.      in typenames, fields or parameters.  */
  6755.       if (constp || volatilep)
  6756.     type = build_type_variant (type, constp, volatilep);
  6757.  
  6758.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  6759.       if (friendp)
  6760.     {
  6761.       /* A friendly class?  */
  6762.       make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  6763.       type = void_type_node;
  6764.     }
  6765.       else if (quals)
  6766.     {
  6767.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  6768.       if (ctype == NULL_TREE)
  6769.         {
  6770.           assert (TREE_CODE (type) == METHOD_TYPE);
  6771.           ctype = TYPE_METHOD_BASETYPE (type);
  6772.         }
  6773.       grok_method_quals (ctype, dummy, quals);
  6774.       type = TREE_TYPE (dummy);
  6775.     }
  6776.  
  6777.       if (resume_temporary)
  6778.     resume_temporary_allocation ();
  6779.       return type;
  6780.     }
  6781.  
  6782.   /* `void' at top level (not within pointer)
  6783.      is allowed only in typedefs or type names.
  6784.      We don't complain about parms either, but that is because
  6785.      a better error message can be made later.  */
  6786.  
  6787.   if (type == void_type_node && decl_context != PARM)
  6788.     {
  6789.       if (declarator != NULL_TREE
  6790.       && TREE_CODE (declarator) == IDENTIFIER_NODE)
  6791.     error ("variable or field `%s' declared void", name);
  6792.       else
  6793.     error ("variable or field declared void");
  6794.       type = integer_type_node;
  6795.     }
  6796.  
  6797.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  6798.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  6799.  
  6800.   {
  6801.     register tree decl;
  6802.  
  6803.     if (decl_context == PARM)
  6804.       {
  6805.     if (ctype)
  6806.       error ("cannot use `::' in parameter declaration");
  6807.     if (virtualp)
  6808.       error ("parameter declared `virtual'");
  6809.     if (quals)
  6810.       error ("`const' and `volatile' function specifiers invalid in parameter declaration");
  6811.     if (friendp)
  6812.       error ("invalid friend declaration");
  6813.     if (raises)
  6814.       error ("invalid raises declaration");
  6815.  
  6816.     /* A parameter declared as an array of T is really a pointer to T.
  6817.        One declared as a function is really a pointer to a function.
  6818.        One declared as a member is really a pointer to member.  */
  6819.  
  6820.     if (TREE_CODE (type) == ARRAY_TYPE)
  6821.       {
  6822.         /* Transfer const-ness of array into that of type pointed to.  */
  6823.         type = build_pointer_type
  6824.             (build_type_variant (TREE_TYPE (type), constp, volatilep));
  6825.         volatilep = constp = 0;
  6826.       }
  6827.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  6828.       type = build_pointer_type (type);
  6829.     else if (TREE_CODE (type) == OFFSET_TYPE)
  6830.       type = build_pointer_type (type);
  6831.  
  6832.     decl = build_decl (PARM_DECL, declarator, type);
  6833.  
  6834.     /* Compute the type actually passed in the parmlist,
  6835.        for the case where there is no prototype.
  6836.        (For example, shorts and chars are passed as ints.)
  6837.        When there is a prototype, this is overridden later.  */
  6838.  
  6839.     DECL_ARG_TYPE (decl) = type;
  6840.     if (type == float_type_node)
  6841.       DECL_ARG_TYPE (decl) = double_type_node;
  6842.     else if (TREE_CODE (type) == INTEGER_TYPE
  6843.          && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  6844.       DECL_ARG_TYPE (decl) = integer_type_node;
  6845.       }
  6846.     else if (decl_context == FIELD)
  6847.       {
  6848.     if (type == error_mark_node)
  6849.       {
  6850.         /* Happens when declaring arrays of sizes which
  6851.            are error_mark_node, for example.  */
  6852.         decl = NULL_TREE;
  6853.       }
  6854.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  6855.       {
  6856.         if (current_lang_name == lang_name_c)
  6857.           {
  6858.         error ("field `%s' declared as a function in %s language context",
  6859.                name, IDENTIFIER_POINTER (current_lang_name));
  6860.         type = build_pointer_type (type);
  6861.           }
  6862.         else
  6863.           {
  6864.         if (friendp == 0)
  6865.           {
  6866.             if (ctype == NULL_TREE)
  6867.               ctype = current_class_type;
  6868.             if (staticp < 2)
  6869.               type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  6870.           }
  6871.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  6872.         TREE_INLINE (decl) = inlinep;
  6873.         if (specbits & (1 << (int) RID_EXTERN))
  6874.           TREE_PUBLIC (decl) = 1;
  6875.           }
  6876.       }
  6877.     else if (TREE_CODE (type) == METHOD_TYPE)
  6878.       {
  6879.         decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0);
  6880.         TREE_INLINE (decl) = inlinep;
  6881.         if (specbits & (1 << (int) RID_EXTERN))
  6882.           TREE_PUBLIC (decl) = 1;
  6883.       }
  6884.     else if (TREE_CODE (type) == RECORD_TYPE
  6885.          && CLASSTYPE_DECLARED_EXCEPTION (type))
  6886.       {
  6887.         /* Handle a class-local exception declaration.  */
  6888.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6889.         if (ctype == NULL_TREE)
  6890.           ctype = current_class_type;
  6891.         finish_exception_decl (TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  6892.                    ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype), decl);
  6893.         return void_type_node;
  6894.       }
  6895.     else if (TYPE_SIZE (type) == 0 && !staticp
  6896.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  6897.       {
  6898.         if (declarator)
  6899.           error ("field `%s' has incomplete type",
  6900.              IDENTIFIER_POINTER (declarator));
  6901.         else
  6902.           error ("field has incomplete type");
  6903.         type = error_mark_node;
  6904.         decl = NULL_TREE;
  6905.       }
  6906.     else
  6907.       {
  6908.         if (friendp)
  6909.           {
  6910.         if (declarator)
  6911.           error ("`%s' is neither function nor method; cannot be declared friend",
  6912.              IDENTIFIER_POINTER (declarator));
  6913.         else
  6914.           {
  6915.             error ("invalid friend declaration");
  6916.             return void_type_node;
  6917.           }
  6918.         friendp = 0;
  6919.           }
  6920.         decl = NULL_TREE;
  6921.       }
  6922.  
  6923.     if (friendp)
  6924.       {
  6925.         /* Friends are treated specially.  */
  6926.         if (ctype == current_class_type)
  6927.           warning ("member functions are implicitly friends of their class");
  6928.         else if (DECL_NAME (decl))
  6929.           return do_friend (ctype, declarator, decl, last_function_parms, flags, quals);
  6930.         else return void_type_node;
  6931.       }
  6932.  
  6933.     /* Structure field.  It may not be a function, except for C++ */
  6934.  
  6935.     if (decl == 0)
  6936.       {
  6937.         if (virtualp)
  6938.           error ("field declared `virtual'");
  6939.         if (quals)
  6940.           error ("`const' and `volatile' function specifiers invalid in field declaration");
  6941.         if (friendp)
  6942.           error ("invalid friend declaration");
  6943.         if (raises)
  6944.           error ("invalid raises declaration");
  6945.  
  6946.         if (staticp || (constp && initialized))
  6947.           {
  6948.         /* C++ allows static class members.
  6949.            All other work for this is done by grokfield.
  6950.            This VAR_DECL is built by build_lang_field_decl.
  6951.            All other VAR_DECLs are built by build_decl.  */
  6952.         if (current_lang_name == lang_name_c)
  6953.           {
  6954.             if (staticp)
  6955.               error ("field `%s' declared static in %s language context",
  6956.                  name, IDENTIFIER_POINTER (current_lang_name));
  6957.             else
  6958.               error ("field `%s' declared with initializer in %s language context",
  6959.                  name, IDENTIFIER_POINTER (current_lang_name));
  6960.           }
  6961.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  6962.         if (staticp)
  6963.           TREE_STATIC (decl) = 1;
  6964.         /* In class context, static means public visibility.  */
  6965.         TREE_PUBLIC (decl) = 1;
  6966.           }
  6967.         else
  6968.           decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  6969.       }
  6970.       }
  6971.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  6972.       {
  6973.     int was_overloaded = 0;
  6974.     tree original_name = declarator;
  6975.  
  6976.     if (! declarator) return NULL_TREE;
  6977.  
  6978.     if (specbits & ((1 << (int) RID_AUTO) | (1 << (int) RID_REGISTER)))
  6979.       error ("invalid storage class for function `%s'", name);
  6980.     /* Function declaration not at top level.
  6981.        Storage classes other than `extern' are not allowed
  6982.        and `extern' makes no difference.  */
  6983.     if (current_binding_level != global_binding_level
  6984.         && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
  6985.         && pedantic)
  6986.       warning ("invalid storage class for function `%s'", name);
  6987.  
  6988.     if (ctype == NULL_TREE)
  6989.       {
  6990.         if (virtualp)
  6991.           {
  6992.         error ("virtual non-class function `%s'", name);
  6993.         virtualp = 0;
  6994.           }
  6995. #ifdef NO_AUTO_OVERLOAD
  6996.         if (is_overloaded (declarator))
  6997.           {
  6998.         /* Plain overloading: will not be grok'd by grokclassfn.  */
  6999.         if (current_lang_name == lang_name_cplusplus)
  7000.           declarator = build_decl_overload (name, TYPE_ARG_TYPES (type), 0);
  7001.         was_overloaded = 1;
  7002.           }
  7003. #else
  7004.         if (current_lang_name == lang_name_cplusplus
  7005.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  7006.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  7007.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  7008.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  7009.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  7010.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  7011.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  7012.           {
  7013.         /* Plain overloading: will not be grok'd by grokclassfn.  */
  7014.         declarator = build_decl_overload (name, TYPE_ARG_TYPES (type), 0);
  7015.         was_overloaded = 1;
  7016.           }
  7017. #endif
  7018.       }
  7019.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  7020.       type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type));
  7021.  
  7022.     decl = grokfndecl (ctype, type, declarator, virtualp, flags, quals, raises, friendp ? 2 : 1);
  7023.     /* Record presence of `static'.  In C++, `inline' is like `static'.  */
  7024.     TREE_PUBLIC (decl) = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)));
  7025.     /* Provide additional information about this function's
  7026.        linkage, in case it's a static inline in a #pragma
  7027.        implementation section.  */
  7028.     if (staticp)
  7029.       TREE_PRIVATE (decl) = 1;
  7030.     /* Record presence of `inline', if it is reasonable.  */
  7031.     if (inlinep)
  7032.       {
  7033.         tree last = tree_last (TYPE_ARG_TYPES (type));
  7034.  
  7035.         if (! was_overloaded
  7036.         && ! ctype
  7037.         && ! strcmp (IDENTIFIER_POINTER (original_name), "main"))
  7038.           warning ("cannot inline function `main'");
  7039.         else if (last && last != void_list_node)
  7040.           warning ("inline declaration ignored for function with `...'");
  7041.         else
  7042.           /* Assume that otherwise the function can be inlined.  */
  7043.           TREE_INLINE (decl) = 1;
  7044.  
  7045.         if (specbits & (1 << (int) RID_EXTERN))
  7046.           current_extern_inline = 1;
  7047.       }
  7048.     if (was_overloaded)
  7049.       {
  7050.         DECL_OVERLOADED (decl) = 1;
  7051.         DECL_ORIGINAL_NAME (decl) = original_name;
  7052.       }
  7053.       }
  7054.     else
  7055.       {
  7056.     /* It's a variable.  */
  7057.  
  7058.     if (virtualp)
  7059.       error ("variable declared `virtual'");
  7060.     if (inlinep)
  7061.       warning ("variable declared `inline'");
  7062.     if (quals)
  7063.       error ("`const' and `volatile' function specifiers invalid in field declaration");
  7064.     if (friendp)
  7065.       error ("invalid friend declaration");
  7066.     if (raises)
  7067.       error ("invalid raises declaration");
  7068.  
  7069.     /* An uninitialized decl with `extern' is a reference.  */
  7070.     decl = grokvardecl (ctype, type, declarator, specbits, initialized);
  7071.       }
  7072.  
  7073.     /* Record `register' declaration for warnings on &
  7074.        and in case doing stupid register allocation.  */
  7075.  
  7076.     if (specbits & (1 << (int) RID_REGISTER))
  7077.       TREE_REGDECL (decl) = 1;
  7078.  
  7079.     /* Record constancy and volatility.  */
  7080.  
  7081.     if (constp)
  7082.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  7083.     if (volatilep)
  7084.       {
  7085.     TREE_SIDE_EFFECTS (decl) = 1;
  7086.     TREE_THIS_VOLATILE (decl) = 1;
  7087.       }
  7088.  
  7089.     if (resume_temporary)
  7090.       resume_temporary_allocation ();
  7091.  
  7092.     return decl;
  7093.   }
  7094. }
  7095.  
  7096. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  7097.    An empty exprlist is a parmlist.  An exprlist which
  7098.    contains only identifiers at the global level
  7099.    is a parmlist.  Otherwise, it is an exprlist. */
  7100. static int
  7101. parmlist_is_exprlist (exprs)
  7102.      tree exprs;
  7103. {
  7104.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  7105.     return 0;
  7106.  
  7107.   if (current_binding_level == global_binding_level)
  7108.     {
  7109.       /* At the global level, if these are all identifiers,
  7110.      then it is a parmlist.  */
  7111.       while (exprs)
  7112.     {
  7113.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  7114.         return 1;
  7115.       exprs = TREE_CHAIN (exprs);
  7116.     }
  7117.       return 0;
  7118.     }
  7119.   return 1;
  7120. }
  7121.  
  7122. /* Make sure that the this list of PARMS has a chance of being
  7123.    grokked by `grokparms'.
  7124.  
  7125.    @@ This is really weak, but the grammar does not allow us
  7126.    @@ to easily reject things that this has to catch as syntax errors.  */
  7127. static int
  7128. parmlist_is_random (parms)
  7129.      tree parms;
  7130. {
  7131.   if (parms == NULL_TREE)
  7132.     return 0;
  7133.  
  7134.   if (TREE_CODE (parms) != TREE_LIST)
  7135.     return 1;
  7136.  
  7137.   while (parms)
  7138.     {
  7139.       if (parms == void_list_node)
  7140.     return 0;
  7141.  
  7142.       if (TREE_CODE (TREE_VALUE (parms)) != TREE_LIST)
  7143.     return 1;
  7144.       /* Don't get faked out by overloaded functions, which
  7145.      masquerade as TREE_LISTs!  */
  7146.       if (TREE_TYPE (TREE_VALUE (parms)) == unknown_type_node)
  7147.     return 1;
  7148.       parms = TREE_CHAIN (parms);
  7149.     }
  7150.   return 0;
  7151. }
  7152.  
  7153. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  7154.    be complete.
  7155.  
  7156.    C++: also subroutine of `start_function'.  */
  7157. static void
  7158. require_complete_types_for_parms (parms)
  7159.      tree parms;
  7160. {
  7161.   while (parms)
  7162.     {
  7163.       tree type = TREE_TYPE (parms);
  7164.       if (TYPE_SIZE (type) == 0)
  7165.     {
  7166.       if (DECL_NAME (parms))
  7167.         error ("parameter `%s' has incomplete type",
  7168.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  7169.       else
  7170.         error ("parameter has incomplete type");
  7171.       TREE_TYPE (parms) = error_mark_node;
  7172.     }
  7173. #if 0
  7174.       /* If the arg types are incomplete in a declaration,
  7175.      they must include undefined tags.
  7176.      These tags can never be defined in the scope of the declaration,
  7177.      so the types can never be completed,
  7178.      and no call can be compiled successfully.  */
  7179.       /* This is not the right behavior for C++, but not having
  7180.      it is also probably wrong.  */
  7181.       else
  7182.     {
  7183.       /* Now warn if is a pointer to an incomplete type.  */
  7184.       while (TREE_CODE (type) == POINTER_TYPE
  7185.          || TREE_CODE (type) == REFERENCE_TYPE)
  7186.         type = TREE_TYPE (type);
  7187.       type = TYPE_MAIN_VARIANT (type);
  7188.       if (TYPE_SIZE (type) == 0)
  7189.         {
  7190.           if (DECL_NAME (parm) != 0)
  7191.         warning ("parameter `%s' points to incomplete type",
  7192.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  7193.           else
  7194.         warning ("parameter points to incomplete type");
  7195.         }
  7196.     }
  7197. #endif
  7198.       parms = TREE_CHAIN (parms);
  7199.     }
  7200. }
  7201.  
  7202. /* Decode the list of parameter types for a function type.
  7203.    Given the list of things declared inside the parens,
  7204.    return a list of types.
  7205.  
  7206.    The list we receive can have three kinds of elements:
  7207.    an IDENTIFIER_NODE for names given without types,
  7208.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  7209.    or void_type_node, to mark the end of an argument list
  7210.    when additional arguments are not permitted (... was not used).
  7211.  
  7212.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  7213.    a mere declaration.  A nonempty identifier-list gets an error message
  7214.    when FUNCDEF_FLAG is zero.
  7215.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  7216.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  7217.  
  7218.    If all elements of the input list contain types,
  7219.    we return a list of the types.
  7220.    If all elements contain no type (except perhaps a void_type_node
  7221.    at the end), we return a null list.
  7222.    If some have types and some do not, it is an error, and we
  7223.    return a null list.
  7224.  
  7225.    Also set last_function_parms to either
  7226.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  7227.    A list of names is converted to a chain of PARM_DECLs
  7228.    by store_parm_decls so that ultimately it is always a chain of decls.
  7229.  
  7230.    Note that in C++, paramters can take default values.  These default
  7231.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  7232.    an error to specify default values which are followed by parameters
  7233.    that have no defualt values, or an ELLIPSES.  For simplicities sake,
  7234.    only parameters which are specified with their types can take on
  7235.    default values.  */
  7236.  
  7237. static tree
  7238. grokparms (first_parm, funcdef_flag)
  7239.      tree first_parm;
  7240.      int funcdef_flag;
  7241. {
  7242.   tree result = NULL_TREE;
  7243.   tree decls = NULL_TREE;
  7244.  
  7245.   if (first_parm != 0
  7246.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  7247.     {
  7248.       if (! funcdef_flag)
  7249.     warning ("parameter names (without types) in function declaration");
  7250.       last_function_parms = first_parm;
  7251.       return 0;
  7252.     }
  7253.   else
  7254.     {
  7255.       /* Types were specified.  This is a list of declarators
  7256.      each represented as a TREE_LIST node.  */
  7257.       register tree parm, chain;
  7258.       int any_init = 0, any_error = 0, saw_void = 0;
  7259.  
  7260.       if (first_parm != NULL_TREE)
  7261.     {
  7262.       tree last_result = NULL_TREE;
  7263.       tree last_decl = NULL_TREE;
  7264.  
  7265.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  7266.         {
  7267.           tree type, list_node = parm;
  7268.           register tree decl = TREE_VALUE (parm);
  7269.           tree init = TREE_PURPOSE (parm);
  7270.  
  7271.           chain = TREE_CHAIN (parm);
  7272.           /* @@ weak defense against parse errors.  */
  7273.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  7274.         {
  7275.           /* Give various messages as the need arises.  */
  7276.           if (TREE_CODE (decl) == STRING_CST)
  7277.             error ("invalid string constant `%s'",
  7278.                TREE_STRING_POINTER (decl));
  7279.           else if (TREE_CODE (decl) == INTEGER_CST)
  7280.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  7281.           continue;
  7282.         }
  7283.  
  7284.           if (decl != void_type_node)
  7285.         {
  7286.           /* @@ May need to fetch out a `raises' here.  */
  7287.           decl = grokdeclarator (TREE_VALUE (decl),
  7288.                      TREE_PURPOSE (decl),
  7289.                      PARM, 0, NULL_TREE);
  7290.           if (! decl) continue;
  7291.           type = TREE_TYPE (decl);
  7292.           if (type == void_type_node)
  7293.             decl = void_type_node;
  7294.           else if (TREE_CODE (type) == METHOD_TYPE)
  7295.             {
  7296.               if (DECL_NAME (decl))
  7297.             /* Cannot use `error_with_decl' here because
  7298.                we don't have DECL_CONTEXT set up yet.  */
  7299.             error ("parameter `%s' invalidly declared method type",
  7300.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  7301.               else
  7302.             error ("parameter invalidly declared method type");
  7303.               type = build_pointer_type (type);
  7304.               TREE_TYPE (decl) = type;
  7305.             }
  7306.           else if (TREE_CODE (type) == OFFSET_TYPE)
  7307.             {
  7308.               if (DECL_NAME (decl))
  7309.             error ("parameter `%s' invalidly declared offset type",
  7310.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  7311.               else
  7312.             error ("parameter invalidly declared offset type");
  7313.               type = build_pointer_type (type);
  7314.               TREE_TYPE (decl) = type;
  7315.             }
  7316.         }
  7317.  
  7318.           if (decl == void_type_node)
  7319.         {
  7320.           if (result == NULL_TREE)
  7321.             {
  7322.               result = void_list_node;
  7323.               last_result = result;
  7324.             }
  7325.           else
  7326.             {
  7327.               TREE_CHAIN (last_result) = void_list_node;
  7328.               last_result = void_list_node;
  7329.             }
  7330.           saw_void = 1;
  7331.           if (chain
  7332.               && (chain != void_list_node || TREE_CHAIN (chain)))
  7333.             error ("`void' in parameter list must be entire list");
  7334.           break;
  7335.         }
  7336.  
  7337.           /* Since there is a prototype, args are passed in their own types.  */
  7338.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  7339. #ifdef PROMOTE_PROTOTYPES
  7340.           if (TREE_CODE (type) == INTEGER_TYPE
  7341.           && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  7342.         DECL_ARG_TYPE (decl) = integer_type_node;
  7343. #endif
  7344.           if (!any_error)
  7345.         {
  7346.           if (init)
  7347.             {
  7348.               any_init++;
  7349.               if (TREE_CODE (init) == SAVE_EXPR)
  7350.             PARM_DECL_EXPR (init) = 1;
  7351.               else
  7352.             init = require_instantiated_type (type, init, integer_zero_node);
  7353.             }
  7354.           else if (any_init)
  7355.             {
  7356.               error ("all trailing parameters must have default arguments");
  7357.               any_error = 1;
  7358.             }
  7359.         }
  7360.           else
  7361.         init = NULL_TREE;
  7362.  
  7363.           if (decls == NULL_TREE)
  7364.         {
  7365.           decls = decl;
  7366.           last_decl = decls;
  7367.         }
  7368.           else
  7369.         {
  7370.           TREE_CHAIN (last_decl) = decl;
  7371.           last_decl = decl;
  7372.         }
  7373.           if (TREE_PERMANENT (list_node))
  7374.         {
  7375.           TREE_PURPOSE (list_node) = init;
  7376.           TREE_VALUE (list_node) = type;
  7377.           TREE_CHAIN (list_node) = 0;
  7378.         }
  7379.           else
  7380.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  7381.           if (result == NULL_TREE)
  7382.         {
  7383.           result = list_node;
  7384.           last_result = result;
  7385.         }
  7386.           else
  7387.         {
  7388.           TREE_CHAIN (last_result) = list_node;
  7389.           last_result = list_node;
  7390.         }
  7391.         }
  7392.       if (last_result)
  7393.         TREE_CHAIN (last_result) = NULL_TREE;
  7394.       /* If there are no parameters, and the function does not end
  7395.          with `...', then last_decl will be NULL_TREE.  */
  7396.       if (last_decl != NULL_TREE)
  7397.         TREE_CHAIN (last_decl) = NULL_TREE;
  7398.     }
  7399.     }
  7400.  
  7401.   last_function_parms = decls;
  7402.  
  7403.   /* In a fcn definition, arg types must be complete.  */
  7404.   if (funcdef_flag > 0)
  7405.     require_complete_types_for_parms (last_function_parms);
  7406.  
  7407.   return result;
  7408. }
  7409.  
  7410. /* These memoizing functions keep track of special properties which
  7411.    a class may have.  `grok_ctor_properties' notices whether a class
  7412.    has a constructor of the for X(X&), and also complains
  7413.    if the class has a constructor of the form X(X).
  7414.    `grok_op_properties' takes notice of the various forms of
  7415.    operator= which are defined, as well as what sorts of type conversion
  7416.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  7417. void
  7418. grok_ctor_properties (ctype, decl)
  7419.      tree ctype, decl;
  7420. {
  7421.   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
  7422.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  7423.  
  7424.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  7425.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  7426.     {
  7427.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  7428.       || TREE_CHAIN (parmtypes) == void_list_node
  7429.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  7430.     {
  7431.       TYPE_HAS_INIT_REF (ctype) = 1;
  7432.       TYPE_GETS_INIT_REF (ctype) = 1;
  7433.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  7434.         TYPE_GETS_CONST_INIT_REF (ctype) = 1;
  7435.     }
  7436.       else
  7437.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  7438.     }
  7439.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  7440.     {
  7441.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  7442.       && TREE_CHAIN (parmtypes) == void_list_node)
  7443.     error ("invalid constructor; you probably meant `%s (%s&)'",
  7444.            TYPE_NAME_STRING (ctype),
  7445.            TYPE_NAME_STRING (ctype));
  7446.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  7447.       TYPE_GETS_INIT_AGGR (ctype) = 1;
  7448.     }
  7449.   else if (TREE_CODE (parmtype) == VOID_TYPE
  7450.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  7451.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  7452. }
  7453.  
  7454. static void
  7455. grok_op_properties (decl)
  7456.      tree decl;
  7457. {
  7458.   char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
  7459.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  7460.  
  7461.   if (DECL_STATIC_FUNCTION_P (decl))
  7462.     {
  7463.       if (! strncmp (name, OPERATOR_NEW_FORMAT, OPERATOR_NEW_LENGTH))
  7464.     {
  7465.       /* Take care of function decl if we had syntax errors.  */
  7466.       if (argtypes == NULL_TREE)
  7467.         TREE_TYPE (decl) = build_function_type (ptr_type_node,
  7468.                             hash_tree_chain (integer_type_node, void_list_node));
  7469.     }
  7470.       else if (! strncmp (name, OPERATOR_DELETE_FORMAT, OPERATOR_DELETE_LENGTH))
  7471.     {
  7472.       if (argtypes == NULL_TREE)
  7473.         TREE_TYPE (decl) = build_function_type (void_type_node,
  7474.                             hash_tree_chain (ptr_type_node, void_list_node));
  7475.     }
  7476.       else
  7477.     error_with_decl (decl, "`%s' cannot be a static member function");
  7478.     }
  7479.   else if (! strncmp (name, OPERATOR_MODIFY_FORMAT, OPERATOR_MODIFY_LENGTH))
  7480.     {
  7481.       tree parmtypes = TREE_CHAIN (argtypes);
  7482.       tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  7483.  
  7484.       if (TREE_CODE (parmtype) == REFERENCE_TYPE
  7485.       && TREE_TYPE (parmtype) == current_class_type)
  7486.     {
  7487.       TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  7488.       TYPE_GETS_ASSIGN_REF (current_class_type) = 1;
  7489.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  7490.         TYPE_GETS_CONST_INIT_REF (current_class_type) = 1;
  7491.     }
  7492.     }
  7493. }
  7494.  
  7495. /* Get the struct, enum or union (CODE says which) with tag NAME.
  7496.    Define the tag as a forward-reference if it is not defined.
  7497.  
  7498.    C++: If a class derivation is given, process it here, and report
  7499.    an error if multiple derivation declarations are not identical.
  7500.  
  7501.    If we are compiling for SOS, then
  7502.      if CODE_TYPE_NODE is a TREE_LIST, then we have a dynamic class
  7503.      declaration.  The name associated with the class is the tree
  7504.      purpose, and the real CODE is in the tree value slot.  */
  7505. tree
  7506. xref_tag (code_type_node, name, binfo)
  7507.      tree code_type_node;
  7508.      tree name, binfo;
  7509. {
  7510.   enum tag_types tag_code;
  7511.   enum tree_code code;
  7512.   int temp = 0;
  7513.   int i, len;
  7514.   register tree ref;
  7515.   struct binding_level *b
  7516.     = (class_binding_level ? class_binding_level : current_binding_level);
  7517. #ifdef SOS
  7518.   tree dynamic_name = error_mark_node;
  7519.   if (TREE_CODE (code_type_node) == TREE_LIST)
  7520.     {
  7521.       dynamic_name = TREE_PURPOSE (code_type_node);
  7522.       code_type_node = TREE_VALUE (code_type_node);
  7523.     }
  7524. #endif
  7525.  
  7526.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  7527.   switch (tag_code)
  7528.     {
  7529.     case record_type:
  7530.     case class_type:
  7531.     case exception_type:
  7532.       code = RECORD_TYPE;
  7533.       len = list_length (binfo);
  7534.       break;
  7535.     case union_type:
  7536.       code = UNION_TYPE;
  7537.       if (binfo)
  7538.     {
  7539.       error ("derived union `%s' invalid", IDENTIFIER_POINTER (name));
  7540.       binfo = NULL_TREE;
  7541.     }
  7542.       len = 0;
  7543.       break;
  7544.     case enum_type:
  7545.       code = ENUMERAL_TYPE;
  7546.       break;
  7547.     default:
  7548.       abort ();
  7549.     }
  7550.  
  7551.   /* If a cross reference is requested, look up the type
  7552.      already defined for this tag and return it.  */
  7553.   ref = lookup_tag (code, name, b, 0);
  7554.  
  7555.   if (! ref)
  7556.     {
  7557.       /* Try finding it as a type declaration.  If that wins, use it.  */
  7558.       ref = lookup_name (name);
  7559.       if (ref && TREE_CODE (ref) == TYPE_DECL
  7560.          && TREE_CODE (TREE_TYPE (ref)) == code)
  7561.     ref = TREE_TYPE (ref);
  7562.       else
  7563.     ref = NULL_TREE;
  7564.     }
  7565.  
  7566.   if (! ref)
  7567.     {
  7568.       /* If no such tag is yet defined, create a forward-reference node
  7569.      and record it as the "definition".
  7570.      When a real declaration of this type is found,
  7571.      the forward-reference will be altered into a real type.  */
  7572.  
  7573.       /* In C++, since these migrate into the global scope, we must
  7574.      build them on the permanent obstack.  */
  7575.       if (temp == 0)
  7576.     temp = allocation_temporary_p ();
  7577.       if (temp)
  7578.     end_temporary_allocation ();
  7579.  
  7580.       if (code == ENUMERAL_TYPE)
  7581.     {
  7582.       ref = make_node (ENUMERAL_TYPE);
  7583.  
  7584.       /* Give the type a default layout like unsigned int
  7585.          to avoid crashing if it does not get defined.  */
  7586.       TYPE_MODE (ref) = SImode;
  7587.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  7588.       TREE_UNSIGNED (ref) = 1;
  7589.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  7590.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  7591.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  7592.  
  7593.       /* Enable us to recognize when a type is created in class context.
  7594.          To do nested classes correctly, this should probably be cleared
  7595.          out when we leave this classes scope.  Currently this in only
  7596.          done in `start_enum'.  */
  7597.  
  7598.       pushtag (name, ref);
  7599.       if (flag_cadillac)
  7600.         cadillac_start_enum (ref);
  7601.     }
  7602.       else if (tag_code == exception_type)
  7603.     {
  7604.       ref = make_lang_type (code);
  7605.       /* Enable us to recognize when an exception type is created in
  7606.          class context.  To do nested classes correctly, this should
  7607.          probably be cleared out when we leave this class's scope.  */
  7608.       CLASSTYPE_DECLARED_EXCEPTION (ref) = 1;
  7609.       pushtag (name, ref);
  7610.       if (flag_cadillac)
  7611.         cadillac_start_struct (ref);
  7612.     }
  7613.       else
  7614.     {
  7615.       extern tree pending_vtables;
  7616.       struct binding_level *old_b = class_binding_level;
  7617.       int needs_writing;
  7618.  
  7619.       ref = make_lang_type (code);
  7620.  
  7621.       if (len > 0)
  7622.         {
  7623.           TYPE_BASETYPES (ref) = make_tree_vec (len);
  7624.           CLASSTYPE_VIAS (ref) = (unsigned char *) xmalloc (len);
  7625.         }
  7626.  
  7627.       /* Record how to set the visibility of this class's
  7628.          virtual functions.  If write_virtuals == 2 or 3, then
  7629.          inline virtuals are ``extern inline''.  */
  7630.       switch (write_virtuals)
  7631.         {
  7632.         case 0:
  7633.         case 1:
  7634.           needs_writing = 1;
  7635.           break;
  7636.         case 2:
  7637.           needs_writing = !! value_member (name, pending_vtables);
  7638.           break;
  7639.         case 3:
  7640.           needs_writing
  7641.         = ! (CLASSTYPE_INTERFACE_ONLY (ref) || CLASSTYPE_INTERFACE_UNKNOWN (ref));
  7642.           break;
  7643.         default:
  7644.           needs_writing = 0;
  7645.         }
  7646.  
  7647.       CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = needs_writing;
  7648.  
  7649. #ifdef NONNESTED_CLASSES
  7650.       /* Class types don't nest the way enums do.  */
  7651.       class_binding_level = 0;
  7652. #endif
  7653.       pushtag (name, ref);
  7654.       class_binding_level = old_b;
  7655.  
  7656.       if (flag_cadillac)
  7657.         cadillac_start_struct (ref);
  7658.     }
  7659.     }
  7660.   else
  7661.     {
  7662.       if (IS_AGGR_TYPE_CODE (code))
  7663.     {
  7664.       if (IS_AGGR_TYPE (ref)
  7665.           && ((tag_code == exception_type)
  7666.           != (CLASSTYPE_DECLARED_EXCEPTION (ref) == 1)))
  7667.         {
  7668.           error ("type `%s' is both exception and aggregate type",
  7669.              IDENTIFIER_POINTER (name));
  7670.           CLASSTYPE_DECLARED_EXCEPTION (ref) = (tag_code == exception_type);
  7671.         }
  7672.     }
  7673.       if (binfo)
  7674.     {
  7675.       tree tt1 = binfo;
  7676.       tree tt2 = TYPE_BASETYPES (ref);
  7677.  
  7678.       if (TYPE_BASETYPES (ref))
  7679.         for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
  7680.           if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (TREE_VEC_ELT (tt2, i)))
  7681.         {
  7682.           error ("redeclaration of derivation chain of type `%s'",
  7683.              IDENTIFIER_POINTER (name));
  7684.           break;
  7685.         }
  7686.  
  7687.       if (tt1 != NULL_TREE)
  7688.         {
  7689.           free (CLASSTYPE_VIAS (ref));
  7690.           TYPE_BASETYPES (ref) = make_tree_vec (len);
  7691.           CLASSTYPE_OFFSET (ref) = integer_zero_node;
  7692.           CLASSTYPE_ASSOC (ref) = NULL_TREE;
  7693.           CLASSTYPE_VIAS (ref) = (unsigned char *) xmalloc (len);
  7694.         }
  7695.       else
  7696.         {
  7697.           /* The user told us something we already knew.  */
  7698.           goto just_return;
  7699.         }
  7700.     }
  7701. #ifdef SOS
  7702.       else if (TREE_CODE (ref) != ENUMERAL_TYPE
  7703.            && (dynamic_name != error_mark_node) != TYPE_DYNAMIC (ref))
  7704.     error ("type `%s' declared both dynamic and non-dynamic",
  7705.            IDENTIFIER_POINTER (name));
  7706. #endif
  7707.     }
  7708.  
  7709.   if (binfo)
  7710.     {
  7711.       CLASSTYPE_MARKED (ref) = 1;
  7712.       for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
  7713.     {
  7714.       /* The base of a derived struct is public.  */
  7715.       int via_public = (tag_code != class_type
  7716.                 || TREE_PURPOSE (binfo) == (tree)visibility_public
  7717.                 || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual);
  7718.       int via_virtual = (TREE_PURPOSE (binfo) == (tree)visibility_private_virtual
  7719.                  || TREE_PURPOSE (binfo) == (tree)visibility_public_virtual
  7720.                  || TREE_PURPOSE (binfo) == (tree)visibility_default_virtual);
  7721.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  7722.  
  7723.       GNU_xref_hier (IDENTIFIER_POINTER (name),
  7724.              IDENTIFIER_POINTER (TREE_VALUE (binfo)),
  7725.              via_public, via_virtual, 0);
  7726.  
  7727.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  7728.         basetype = TREE_TYPE (basetype);
  7729.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  7730.         {
  7731.           error ("base type `%s' fails to be a struct or class type",
  7732.              IDENTIFIER_POINTER (TREE_VALUE (binfo)));
  7733.           continue;
  7734.         }
  7735. #if 0
  7736.       else if (TYPE_SIZE (basetype) == 0)
  7737.         {
  7738.           error_with_aggr_type (basetype, "base class `%s' has incomplete type");
  7739.           continue;
  7740.         }
  7741. #endif
  7742.       else
  7743.         {
  7744. #ifdef SOS
  7745.           if (dynamic_name == error_mark_node && TYPE_DYNAMIC (basetype))
  7746.         error_with_aggr_type (ref, "non-dynamic type `%s' cannot derive from dynamic type `%s'", TYPE_NAME_STRING (basetype));
  7747. #endif
  7748.           if (CLASSTYPE_MARKED (basetype))
  7749.         {
  7750.           if (basetype == ref)
  7751.             error_with_aggr_type (basetype, "recursive type `%s' undefined");
  7752.           else
  7753.             error_with_aggr_type (basetype, "duplicate base type `%s' invalid");
  7754.           continue;
  7755.         }
  7756.           CLASSTYPE_BASECLASS (ref, i) = basetype;
  7757.           CLASSTYPE_MARKED (basetype) = 1;
  7758. #if 0
  7759. /* XYZZY TEST VIRTUAL BASECLASSES */
  7760. if (CLASSTYPE_N_BASECLASSES (basetype) == 0
  7761.     && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  7762.     && via_virtual == 0)
  7763.   {
  7764.     warning ("making type `%s' a virtual baseclass",
  7765.          TYPE_NAME_STRING (basetype));
  7766.     via_virtual = 1;
  7767.   }
  7768. #endif
  7769.           SET_CLASSTYPE_VIAS (ref, i, via_public, via_virtual);
  7770.           if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  7771.         {
  7772.           TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  7773.           TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  7774.         }
  7775.  
  7776.           TYPE_GETS_ASSIGNMENT (ref) |= TYPE_GETS_ASSIGNMENT (basetype);
  7777.           TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  7778.           TYPE_HAS_WRAPPER_PRED (ref) |= TYPE_HAS_WRAPPER_PRED (basetype);
  7779.           TREE_GETS_NEW (ref) |= TREE_GETS_NEW (basetype);
  7780.           TREE_GETS_DELETE (ref) |= TREE_GETS_DELETE (basetype);
  7781.           CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  7782.           i += 1;
  7783.         }
  7784.     }
  7785.       /* Set `i' to the true number of baseclasses this type really has.  */
  7786.  
  7787.       if (i > 1)
  7788.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  7789.       else if (i == 1)
  7790.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  7791.       = TYPE_USES_MULTIPLE_INHERITANCE (CLASSTYPE_BASECLASS (ref, 0));
  7792.       if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
  7793.     TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  7794.  
  7795.       while (--i >= 0)
  7796.     CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (ref, i)) = 0;
  7797.       CLASSTYPE_MARKED (ref) = 0;
  7798.     }
  7799.  
  7800.  just_return:
  7801.  
  7802. #ifdef SOS
  7803.   if (dynamic_name != error_mark_node)
  7804.     {
  7805.       if (temp == 0)
  7806.     temp = allocation_temporary_p ();
  7807.       if (temp)
  7808.     end_temporary_allocation ();
  7809.  
  7810.       if (dynamic_name)
  7811.     CLASSTYPE_DYNAMIC_FILENAME (ref) = combine_strings (dynamic_name);
  7812.       else
  7813.     CLASSTYPE_DYNAMIC_FILENAME (ref) = NULL_TREE;
  7814.       TYPE_DYNAMIC (ref) = 1;
  7815.       CLASSTYPE_TYPENAME_AS_STRING (ref) = combine_strings (build_string (IDENTIFIER_LENGTH (name), IDENTIFIER_POINTER (name)));
  7816.  
  7817.     }
  7818. #endif
  7819.  
  7820.   /* Until the type is defined, tentatively accept whatever
  7821.      structure tag the user hands us.  */
  7822.   if (TYPE_SIZE (ref) == NULL_TREE
  7823.       && ref != current_class_type
  7824.       && IS_AGGR_TYPE_CODE (code))
  7825.     {
  7826.       if (tag_code == class_type)
  7827.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  7828.       else if (tag_code == record_type)
  7829.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  7830.     }
  7831.  
  7832.   if (temp)
  7833.     resume_temporary_allocation ();
  7834.  
  7835.   return ref;
  7836. }
  7837.  
  7838. /* Begin compiling the definition of an enumeration type.
  7839.    NAME is its name (or null if anonymous).
  7840.    Returns the type object, as yet incomplete.
  7841.    Also records info about it so that build_enumerator
  7842.    may be used to declare the individual values as they are read.  */
  7843.  
  7844. tree
  7845. start_enum (name)
  7846.      tree name;
  7847. {
  7848.   register tree enumtype = 0;
  7849.   struct binding_level *b
  7850.     = (class_binding_level ? class_binding_level : current_binding_level);
  7851.  
  7852.   /* If this is the real definition for a previous forward reference,
  7853.      fill in the contents in the same object that used to be the
  7854.      forward reference.  */
  7855.  
  7856.   if (name != 0)
  7857.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  7858.  
  7859.   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
  7860.     {
  7861.       enumtype = make_node (ENUMERAL_TYPE);
  7862.       pushtag (name, enumtype);
  7863.     }
  7864.  
  7865.   if (TYPE_VALUES (enumtype) != 0)
  7866.     {
  7867.       /* This enum is a named one that has been declared already.  */
  7868.       error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
  7869.  
  7870.       /* Completely replace its old definition.
  7871.      The old enumerators remain defined, however.  */
  7872.       TYPE_VALUES (enumtype) = 0;
  7873.     }
  7874.  
  7875.   /* Initially, set up this enum as like `int'
  7876.      so that we can create the enumerators' declarations and values.
  7877.      Later on, the precision of the type may be changed and
  7878.      it may be laid out again.  */
  7879.  
  7880.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  7881.   TYPE_SIZE (enumtype) = 0;
  7882.   fixup_unsigned_type (enumtype);
  7883.  
  7884.   /* We copy this value because enumerated type constants
  7885.      are really of the type of the enumerator, not integer_type_node.  */
  7886.   enum_next_value = copy_node (integer_zero_node);
  7887.  
  7888.   GNU_xref_decl (current_function_decl, enumtype);
  7889.   return enumtype;
  7890. }
  7891.  
  7892. /* After processing and defining all the values of an enumeration type,
  7893.    install their decls in the enumeration type and finish it off.
  7894.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  7895.    Returns ENUMTYPE.  */
  7896.  
  7897. tree
  7898. finish_enum (enumtype, values)
  7899.      register tree enumtype, values;
  7900. {
  7901.   register tree pair;
  7902.   register long maxvalue = 0;
  7903.   register long minvalue = 0;
  7904.   register int i;
  7905.  
  7906.   TYPE_VALUES (enumtype) = values;
  7907.  
  7908.   /* Calculate the maximum value of any enumerator in this type.  */
  7909.  
  7910.   if (values)
  7911.     {
  7912.       /* Speed up the main loop by performing some precalculations */
  7913.  
  7914.       int value = TREE_INT_CST_LOW (TREE_VALUE (values));
  7915.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  7916.       minvalue = maxvalue = value;
  7917.       
  7918.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  7919.     {
  7920.       value = TREE_INT_CST_LOW (TREE_VALUE (pair));
  7921.       if (value > maxvalue)
  7922.         maxvalue = value;
  7923.       else if (value < minvalue)
  7924.         minvalue = value;
  7925.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  7926.     }
  7927.     }
  7928.  
  7929.   if (flag_short_enums)
  7930.     {
  7931.       /* Determine the precision this type needs, lay it out, and define it.  */
  7932.  
  7933.       for (i = maxvalue; i; i >>= 1)
  7934.     TYPE_PRECISION (enumtype)++;
  7935.  
  7936.       if (!TYPE_PRECISION (enumtype))
  7937.     TYPE_PRECISION (enumtype) = 1;
  7938.  
  7939.       /* Cancel the laying out previously done for the enum type,
  7940.      so that fixup_unsigned_type will do it over.  */
  7941.       TYPE_SIZE (enumtype) = 0;
  7942.  
  7943.       fixup_unsigned_type (enumtype);
  7944.     }
  7945.  
  7946.   TREE_INT_CST_LOW (TYPE_MAX_VALUE (enumtype)) = maxvalue;
  7947.  
  7948.   /* An enum can have some negative values; then it is signed.  */
  7949.   if (minvalue < 0)
  7950.     {
  7951.       TREE_INT_CST_LOW (TYPE_MIN_VALUE (enumtype)) = minvalue;
  7952.       TREE_INT_CST_HIGH (TYPE_MIN_VALUE (enumtype)) = -1;
  7953.       TREE_UNSIGNED (enumtype) = 0;
  7954.     }
  7955.   if (flag_cadillac)
  7956.     cadillac_finish_enum (enumtype);
  7957.  
  7958.   return enumtype;
  7959. }
  7960.  
  7961. /* Build and install a CONST_DECL for one value of the
  7962.    current enumeration type (one that was begun with start_enum).
  7963.    Return a tree-list containing the name and its value.
  7964.    Assignment of sequential values by default is handled here.  */
  7965.  
  7966. tree
  7967. build_enumerator (name, value)
  7968.      tree name, value;
  7969. {
  7970.   tree decl, result;
  7971.   /* Change this to zero if we find VALUE is not shareable.  */
  7972.   int shareable = 1;
  7973.  
  7974.   /* Validate and default VALUE.  */
  7975.   if (value != 0)
  7976.     {
  7977.       if (TREE_READONLY_DECL_P (value))
  7978.     {
  7979.       value = decl_constant_value (value);
  7980.       shareable = 0;
  7981.     }
  7982.  
  7983.       if (TREE_CODE (value) != INTEGER_CST)
  7984.     {
  7985.       error ("enumerator value for `%s' not integer constant",
  7986.          IDENTIFIER_POINTER (name));
  7987.       value = 0;
  7988.     }
  7989.     }
  7990.   /* The order of things is reversed here so that we
  7991.      can check for possible sharing of enum values,
  7992.      to keep that from happening.  */
  7993.   /* Default based on previous value.  */
  7994.   if (value == 0)
  7995.     value = enum_next_value;
  7996.  
  7997.   /* Remove no-op casts from the value.  */
  7998.   while (value != 0 && TREE_CODE (value) == NOP_EXPR)
  7999.     {
  8000.       value = TREE_OPERAND (value, 0);
  8001.       shareable = 0;
  8002.     }
  8003.  
  8004.   /* Make up for hacks in cplus-lex.c.  */
  8005.   if (value == integer_zero_node)
  8006.     value = build_int_2 (0, 0);
  8007.   else if (value == integer_one_node)
  8008.     value = build_int_2 (1, 0);
  8009.   else if (TREE_CODE (value) == INTEGER_CST
  8010.        && (shareable == 0
  8011.            || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
  8012.     {
  8013.       value = copy_node (value);
  8014.       TREE_TYPE (value) = integer_type_node;
  8015.     }
  8016.  
  8017.   result = saveable_tree_cons (name, value, NULL_TREE);
  8018.  
  8019.   /* C++ associates enums with global, function, or class declarations.  */
  8020.   if (current_class_type == NULL_TREE || current_function_decl != NULL_TREE)
  8021.     {
  8022.       /* Create a declaration for the enum value name.  */
  8023.  
  8024.       decl = build_decl (CONST_DECL, name, integer_type_node);
  8025.       DECL_INITIAL (decl) = value;
  8026.  
  8027.       pushdecl (decl);
  8028.       GNU_xref_decl (current_function_decl, decl);
  8029.     }
  8030.  
  8031.   /* Set basis for default for next value.  */
  8032.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  8033.                            integer_one_node, PLUS_EXPR);
  8034.   if (enum_next_value == integer_one_node)
  8035.     enum_next_value = copy_node (enum_next_value);
  8036.  
  8037.   return result;
  8038. }
  8039.  
  8040. tree
  8041. grok_enum_decls (type, decl)
  8042.      tree type, decl;
  8043. {
  8044.   struct binding_level *b = class_binding_level;
  8045.   tree tag = NULL_TREE;
  8046.   tree values;
  8047.  
  8048.   while (b)
  8049.     {
  8050.       tag = value_member (type, b->tags);
  8051.       if (tag)
  8052.     break;
  8053.       b = b->level_chain;
  8054.     }
  8055.  
  8056.   if (b == 0)
  8057.     {
  8058.       tree name = TYPE_NAME (type);
  8059.       if (TREE_CODE (name) == TYPE_DECL)
  8060.     name = DECL_NAME (name);
  8061.       error ("class-local enum declaration `%s' is not in scope here",
  8062.          IDENTIFIER_POINTER (name));
  8063.     }
  8064.   else if (b != class_binding_level)
  8065.     {
  8066.       warning ("class-local declaration for enumeral type `%s' found",
  8067.            IDENTIFIER_POINTER (TREE_PURPOSE (tag)));
  8068.       warning ("(probably missing '}' before that enum declaration)");
  8069.       return decl;
  8070.     }
  8071.   else if (TREE_ADDRESSABLE (tag))
  8072.     return decl;
  8073.   else
  8074.     TREE_ADDRESSABLE (tag) = 1;
  8075.  
  8076.   values = TYPE_VALUES (type);
  8077.   while (values)
  8078.     {
  8079.       /* Create a declaration for the enum value name.  */
  8080.       tree next = build_lang_field_decl (CONST_DECL, TREE_PURPOSE (values), type);
  8081.       DECL_INITIAL (next) = TREE_VALUE (values);
  8082.       TREE_CHAIN (next) = decl;
  8083.       decl = next;
  8084.       pushdecl_class_level (decl);
  8085.       values = TREE_CHAIN (values);
  8086.     }
  8087.   return decl;
  8088. }
  8089.  
  8090. /* Create the FUNCTION_DECL for a function definition.
  8091.    DECLSPECS and DECLARATOR are the parts of the declaration;
  8092.    they describe the function's name and the type it returns,
  8093.    but twisted together in a fashion that parallels the syntax of C.
  8094.  
  8095.    This function creates a binding context for the function body
  8096.    as well as setting up the FUNCTION_DECL in current_function_decl.
  8097.  
  8098.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  8099.    (it defines a datum instead), we return 0, which tells
  8100.    yyparse to report a parse error.
  8101.  
  8102.    For C++, we must first check whether that datum makes any sense.
  8103.    For example, "class A local_a(1,2);" means that variable local
  8104.    a is an aggregate of type A, which should have a constructor
  8105.    applied to it with the argument list [1, 2].
  8106.  
  8107.    @@ There is currently no way to retrieve the storage
  8108.    @@ allocated to FUNCTION (or all of its parms) if we return
  8109.    @@ something we had previously.  */
  8110.  
  8111. int
  8112. start_function (declspecs, declarator, raises, pre_parsed_p)
  8113.      tree declarator, declspecs, raises;
  8114.      int pre_parsed_p;
  8115. {
  8116.   extern int interface_only, interface_unknown;
  8117.   extern tree EHS_decl;
  8118.   tree decl1, olddecl;
  8119.   tree ctype = NULL_TREE;
  8120.   tree fntype;
  8121.   tree restype;
  8122.  
  8123.   if (flag_handle_exceptions && EHS_decl == NULL_TREE)
  8124.     init_exception_processing_1 ();
  8125.  
  8126.   /* Sanity check.  */
  8127.   assert (TREE_VALUE (void_list_node) == void_type_node);
  8128.   assert (TREE_CHAIN (void_list_node) == NULL_TREE);
  8129.  
  8130.   /* Assume, until we see it does. */
  8131.   current_function_returns_value = 0;
  8132.   current_function_returns_null = 0;
  8133.   warn_about_return_type = 0;
  8134.   current_extern_inline = 0;
  8135.   current_function_assigns_this = 0;
  8136.   current_function_just_assigned_this = 0;
  8137.   current_function_parms_stored = 0;
  8138.   original_result_rtx = 0;
  8139.   current_function_obstack_index = 0;
  8140.   current_function_obstack_usage = 0;
  8141.  
  8142.   clear_temp_name ();
  8143.  
  8144.   if (pre_parsed_p)
  8145.     {
  8146.       decl1 = declarator;
  8147.       last_function_parms = DECL_ARGUMENTS (decl1);
  8148.       last_function_parm_tags = 0;
  8149.       fntype = TREE_TYPE (decl1);
  8150.       if (TREE_CODE (fntype) == METHOD_TYPE)
  8151.     ctype = TYPE_METHOD_BASETYPE (fntype);
  8152.  
  8153.       if ( !(DECL_VIRTUAL_P (decl1)
  8154.          && write_virtuals >= 2
  8155.          && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)))
  8156.     current_extern_inline = TREE_PUBLIC (decl1);
  8157.  
  8158.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  8159.  
  8160.       /* In a fcn definition, arg types must be complete.  */
  8161.       require_complete_types_for_parms (last_function_parms);
  8162.     }
  8163.   else
  8164.     {
  8165.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises);
  8166.       /* If the declarator is not suitable for a function definition,
  8167.      cause a syntax error.  */
  8168.       if (decl1 == 0 || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  8169.  
  8170.       fntype = TREE_TYPE (decl1);
  8171.  
  8172.       restype = TREE_TYPE (fntype);
  8173.       if (IS_AGGR_TYPE (restype)
  8174.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  8175.     {
  8176.       error_with_aggr_type (restype, "semicolon missing after declaration of `%s'");
  8177.       shadow_tag (build_tree_list (NULL_TREE, restype));
  8178.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  8179.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  8180.         fntype = build_function_type (integer_type_node,
  8181.                       TYPE_ARG_TYPES (fntype));
  8182.       else
  8183.         fntype = build_cplus_method_type (TYPE_METHOD_BASETYPE (fntype),
  8184.                           integer_type_node,
  8185.                           TYPE_ARG_TYPES (fntype));
  8186.       TREE_TYPE (decl1) = fntype;
  8187.     }
  8188.  
  8189.       if (TREE_CODE (fntype) == METHOD_TYPE)
  8190.     ctype = TYPE_METHOD_BASETYPE (fntype);
  8191.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  8192.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main"))
  8193.     {
  8194.       /* If this doesn't return an integer type, complain.  */
  8195.       if (TREE_CODE (TREE_TYPE (fntype)) != INTEGER_TYPE)
  8196.         {
  8197. #if 0
  8198.           error ("return type for `main' must be integer type");
  8199. #else
  8200.           warning ("return type for `main' changed to integer type");
  8201. #endif
  8202.           TREE_TYPE (decl1) = fntype = default_function_type;
  8203.         }
  8204.       warn_about_return_type = 0;
  8205.     }
  8206.     }
  8207.  
  8208.   /* Warn if function was previously implicitly declared
  8209.      (but not if we warned then).  */
  8210.   if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != 0)
  8211.     warning_with_decl (IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)),
  8212.                "`%s' implicitly declared before its definition");
  8213.  
  8214.   current_function_decl = decl1;
  8215.  
  8216.   if (flag_cadillac)
  8217.     cadillac_start_function (decl1);
  8218.   else
  8219.     announce_function (decl1);
  8220.  
  8221.   if (TYPE_SIZE (TREE_TYPE (fntype)) == 0)
  8222.     {
  8223.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  8224.     error_with_aggr_type (TREE_TYPE (fntype),
  8225.                   "return-type `%s' is an incomplete type");
  8226.       else
  8227.     error ("return-type is an incomplete type");
  8228.  
  8229.       /* Make it return void instead.  */
  8230.       if (ctype)
  8231.     TREE_TYPE (decl1)
  8232.       = build_cplus_method_type (ctype,
  8233.                      void_type_node,
  8234.                      FUNCTION_ARG_CHAIN (decl1));
  8235.       else
  8236.     TREE_TYPE (decl1)
  8237.       = build_function_type (void_type_node,
  8238.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  8239.     }
  8240.  
  8241.   if (warn_about_return_type)
  8242.     warning ("return-type defaults to `int'");
  8243.  
  8244.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  8245.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  8246.   DECL_INITIAL (decl1) = error_mark_node;
  8247.  
  8248. #ifdef NO_AUTO_OVERLOAD
  8249.   /* If this definition isn't a prototype and we had a prototype declaration
  8250.      before, copy the arg type info from that prototype.  */
  8251.   olddecl = lookup_name_current_level (DECL_NAME (decl1));
  8252.   if (olddecl != 0
  8253.       && TREE_CODE (olddecl) != TREE_LIST
  8254.       && TREE_TYPE (TREE_TYPE (decl1)) == TREE_TYPE (TREE_TYPE (olddecl))
  8255.       && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
  8256.     {
  8257.       fntype = TREE_TYPE (olddecl);
  8258.       TREE_TYPE (decl1) = fntype;
  8259.     }
  8260. #endif
  8261.  
  8262.   /* Didn't get anything from C.  */
  8263.   olddecl = 0;
  8264.  
  8265.   /* This is a definition, not a reference.
  8266.      So normally clear TREE_EXTERNAL.
  8267.      However, `extern inline' acts like a declaration
  8268.      except for defining how to inline.  So set TREE_EXTERNAL in that case.  */
  8269.   TREE_EXTERNAL (current_function_decl) = current_extern_inline;
  8270.  
  8271.   /* This function exists in static storage.
  8272.      (This does not mean `static' in the C sense!)  */
  8273.   TREE_STATIC (decl1) = 1;
  8274.  
  8275.   /* If this inline function belongs to the implementation, make it public.  */
  8276.   if (TREE_INLINE (decl1) && !TREE_PRIVATE (decl1) && interface_unknown == 0)
  8277.     {
  8278.       TREE_PUBLIC (decl1) = ! interface_only;
  8279.       TREE_EXTERNAL (decl1) = interface_only;
  8280.     }
  8281.  
  8282.   /* Now see if this is the implementation of a function
  8283.      declared with "C" linkage.  */
  8284.   if (ctype == NULL_TREE && current_lang_name == lang_name_cplusplus)
  8285.     {
  8286.       olddecl = lookup_name_current_level (DECL_ORIGINAL_NAME (decl1));
  8287.       if (olddecl && TREE_CODE (olddecl) != FUNCTION_DECL)
  8288.     olddecl = NULL_TREE;
  8289.       if (olddecl
  8290.       && DECL_ORIGINAL_NAME (decl1) != DECL_ORIGINAL_NAME (olddecl))
  8291.     {
  8292.       /* Collision between user and internal naming scheme.  */
  8293.       olddecl = lookup_name_current_level (DECL_NAME (decl1));
  8294.       if (olddecl == NULL_TREE)
  8295.         olddecl = decl1;
  8296.     }
  8297.       if (olddecl && olddecl != decl1
  8298.       && DECL_ORIGINAL_NAME (decl1) == DECL_ORIGINAL_NAME (olddecl))
  8299.     {
  8300.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  8301.           && (decls_match (decl1, olddecl)
  8302.           || comp_target_parms (TYPE_ARG_TYPES (TREE_TYPE (decl1)),
  8303.                     TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 1)))
  8304.         {
  8305.           olddecl = DECL_MAIN_VARIANT (olddecl);
  8306.           DECL_NAME (decl1) = DECL_NAME (olddecl);
  8307.           DECL_PRINT_NAME (decl1) = DECL_PRINT_NAME (olddecl);
  8308.           DECL_OVERLOADED (decl1) = DECL_OVERLOADED (olddecl);
  8309.           if (DECL_INITIAL (olddecl))
  8310.         redeclaration_error_message (decl1, olddecl);
  8311.           if (! duplicate_decls (decl1, olddecl))
  8312.         abort ();
  8313.           decl1 = olddecl;
  8314.         }
  8315.       else
  8316.         olddecl = NULL_TREE;
  8317.     }
  8318.     }
  8319.  
  8320.   /* Record the decl so that the function name is defined.
  8321.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  8322.      use the old decl.  */
  8323.  
  8324.   if (olddecl)
  8325.     current_function_decl = olddecl;
  8326.   else if (pre_parsed_p == 0)
  8327.     {
  8328.       current_function_decl = pushdecl (decl1);
  8329.       if (TREE_CODE (current_function_decl) == TREE_LIST)
  8330.     {
  8331.       /* @@ revert to modified original declaration.  */
  8332.       decl1 = DECL_MAIN_VARIANT (decl1);
  8333.       current_function_decl = decl1;
  8334.     }
  8335.       else
  8336.     {
  8337.       decl1 = current_function_decl;
  8338.       DECL_MAIN_VARIANT (decl1) = decl1;
  8339.     }
  8340.       fntype = TREE_TYPE (decl1);
  8341.     }
  8342.   else
  8343.     current_function_decl = decl1;
  8344.  
  8345.   if (DECL_OVERLOADED (decl1))
  8346.     push_overloaded_decl (decl1);
  8347.  
  8348.   if (ctype != 0 && DECL_STATIC_FUNCTION_P (decl1))
  8349.     {
  8350.       if (TREE_CODE (fntype) == METHOD_TYPE)
  8351.     TREE_TYPE (decl1) = fntype
  8352.       = build_function_type (TREE_TYPE (fntype),
  8353.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  8354.       last_function_parms = TREE_CHAIN (last_function_parms);
  8355.       DECL_ARGUMENTS (decl1) = last_function_parms;
  8356.       ctype = 0;
  8357.     }
  8358.   restype = TREE_TYPE (fntype);
  8359.  
  8360.   pushlevel (0);
  8361.   current_binding_level->parm_flag = 1;
  8362.  
  8363.   /* Save the parm names or decls from this function's declarator
  8364.      where store_parm_decls will find them.  */
  8365.   current_function_parms = last_function_parms;
  8366.   current_function_parm_tags = last_function_parm_tags;
  8367.  
  8368.   GNU_xref_function (decl1, current_function_parms);
  8369.  
  8370.   make_function_rtl (decl1);
  8371.  
  8372.   if (ctype)
  8373.     {
  8374.       pushclass (ctype, 1);
  8375.       /* We know that this was set up by `grokclassfn'.
  8376.      We do not wait until `store_parm_decls', since evil
  8377.      parse errors may never get us to that point.  Here
  8378.      we keep the consistency between `current_class_type'
  8379.      and `current_class_decl'.  */
  8380.       current_class_decl = last_function_parms;
  8381.       assert (TREE_CODE (current_class_decl) == PARM_DECL);
  8382.       if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
  8383.     {
  8384.       tree variant = TREE_TYPE (TREE_TYPE (current_class_decl));
  8385.       if (CLASSTYPE_INST_VAR (ctype) == NULL_TREE)
  8386.         {
  8387.           /* Can't call build_indirect_ref here, because it has special
  8388.          logic to return C_C_D given this argument.  */
  8389.           C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
  8390.           CLASSTYPE_INST_VAR (ctype) = C_C_D;
  8391.         }
  8392.       else
  8393.         {
  8394.           C_C_D = CLASSTYPE_INST_VAR (ctype);
  8395.           /* `current_class_decl' is different for every
  8396.          function we compile.  */
  8397.           TREE_OPERAND (C_C_D, 0) = current_class_decl;
  8398.         }
  8399.       TREE_READONLY (C_C_D) = TYPE_READONLY (variant);
  8400.       TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (variant);
  8401.       TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (variant);
  8402.     }
  8403.       else
  8404.     C_C_D = current_class_decl;
  8405.     }
  8406.   else
  8407.     {
  8408.       if (DECL_STATIC_FUNCTION_P (decl1))
  8409.     pushclass (DECL_STATIC_CONTEXT (decl1), 2);
  8410.       else
  8411.     push_memoized_context (0, 1);
  8412.     }
  8413.  
  8414.   /* Promote the value to int before returning it.  */
  8415.   if (TREE_CODE (restype) == INTEGER_TYPE
  8416.       && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
  8417.     restype = integer_type_node;
  8418. #if 0
  8419.   DECL_RESULT_TYPE (decl1) = restype;
  8420. #endif
  8421.   DECL_RESULT (decl1) = build_decl (RESULT_DECL, value_identifier, restype);
  8422.  
  8423.   if (DESTRUCTOR_NAME_P (DECL_NAME (decl1)))
  8424.     {
  8425.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  8426.       ctor_label = NULL_TREE;
  8427.     }
  8428.   else
  8429.     {
  8430.       dtor_label = NULL_TREE;
  8431.       if (DECL_CONSTRUCTOR_P (decl1))
  8432.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  8433.     }
  8434.  
  8435.   /* Allocate further tree nodes temporarily during compilation
  8436.      of this function only.  */
  8437.   temporary_allocation ();
  8438.  
  8439.   /* If this fcn was already referenced via a block-scope `extern' decl
  8440.      (or an implicit decl), propagate certain information about the usage.  */
  8441.   if (TREE_ADDRESSABLE (DECL_NAME (decl1)))
  8442.     TREE_ADDRESSABLE (decl1) = 1;
  8443.       
  8444.   return 1;
  8445. }
  8446.  
  8447. /* Store the parameter declarations into the current function declaration.
  8448.    This is called after parsing the parameter declarations, before
  8449.    digesting the body of the function.
  8450.  
  8451.    Also install to binding contour return value identifier, if any.  */
  8452.  
  8453. void
  8454. store_parm_decls ()
  8455. {
  8456.   register tree fndecl = current_function_decl;
  8457.   register tree parm;
  8458.   int parms_have_cleanups = 0;
  8459.   tree eh_decl;
  8460.  
  8461.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  8462.   tree specparms = current_function_parms;
  8463.  
  8464.   /* This is a list of types declared among parms in a prototype.  */
  8465.   tree parmtags = current_function_parm_tags;
  8466.  
  8467.   /* This is a chain of any other decls that came in among the parm
  8468.      declarations.  If a parm is declared with  enum {foo, bar} x;
  8469.      then CONST_DECLs for foo and bar are put here.  */
  8470.   tree nonparms = 0;
  8471.  
  8472.   if (current_binding_level == global_binding_level)
  8473.     fatal ("parse errors have confused me too much");
  8474.  
  8475.   /* Initialize RTL machinery.  */
  8476.   init_function_start (fndecl, input_filename, lineno);
  8477.  
  8478.   /* Create a binding level for the parms.  */
  8479.   expand_start_bindings (0);
  8480.  
  8481.   /* Prepare to catch raises, if appropriate.  */
  8482.   if (flag_handle_exceptions)
  8483.     {
  8484.       /* Get this cleanup to be run last, since it
  8485.      is a call to `longjmp'.  */
  8486.       setup_exception_throw_decl ();
  8487.       eh_decl = current_binding_level->names;
  8488.       current_binding_level->names = TREE_CHAIN (current_binding_level->names);
  8489.     }
  8490.   if (flag_handle_exceptions)
  8491.     expand_start_try (integer_one_node, 0, 1);
  8492.  
  8493.   if (specparms != 0)
  8494.     {
  8495.       /* This case is when the function was defined with an ANSI prototype.
  8496.      The parms already have decls, so we need not do anything here
  8497.      except record them as in effect
  8498.      and complain if any redundant old-style parm decls were written.  */
  8499.  
  8500.       register tree next;
  8501.  
  8502.       for (parm = nreverse (specparms); parm; parm = next)
  8503.     {
  8504.       tree cleanup = maybe_build_cleanup (parm);
  8505.       next = TREE_CHAIN (parm);
  8506.       if (DECL_NAME (parm) == 0)
  8507.         {
  8508. #if 0
  8509.           error_with_decl (parm, "parameter name omitted");
  8510. #else
  8511.           /* for C++, this is not an error.  */
  8512.           pushdecl (parm);
  8513. #endif
  8514.         }
  8515.       else if (TREE_TYPE (parm) == void_type_node)
  8516.         error_with_decl (parm, "parameter `%s' declared void");
  8517.       else
  8518.         {
  8519.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  8520.          A parameter is assumed not to have any side effects.
  8521.          If this should change for any reason, then this
  8522.          will have to wrap the bashed reference type in a save_expr.
  8523.          
  8524.          Also, if the parameter type is declared to be an X
  8525.          and there is an X(X&) constructor, we cannot lay it
  8526.          into the stack (any more), so we make this parameter
  8527.          look like it is really of reference type.  Functions
  8528.          which pass parameters to this function will know to
  8529.          create a temporary in their frame, and pass a reference
  8530.          to that.  */
  8531.  
  8532.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  8533.           && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  8534.         SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  8535.  
  8536.           pushdecl (parm);
  8537.         }
  8538.  
  8539.       if (cleanup)
  8540.         {
  8541.           expand_decl (parm);
  8542.           expand_decl_cleanup (parm, cleanup);
  8543.           parms_have_cleanups = 1;
  8544.         }
  8545.     }
  8546.  
  8547.       /* Get the decls in their original chain order
  8548.      and record in the function.  */
  8549.       DECL_ARGUMENTS (fndecl) = getdecls ();
  8550.  
  8551.       storetags (chainon (parmtags, gettags ()));
  8552.     }
  8553.   else
  8554.     DECL_ARGUMENTS (fndecl) = 0;
  8555.  
  8556.   /* Now store the final chain of decls for the arguments
  8557.      as the decl-chain of the current lexical scope.
  8558.      Put the enumerators in as well, at the front so that
  8559.      DECL_ARGUMENTS is not modified.  */
  8560.  
  8561.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  8562.  
  8563.   /* Initialize the RTL code for the function.  */
  8564.   DECL_SAVED_INSNS (fndecl) = 0;
  8565.   expand_function_start (fndecl, parms_have_cleanups);
  8566.  
  8567.   if (flag_handle_exceptions)
  8568.     {
  8569.       /* Make the throw decl visibile at this level, just
  8570.      not in the way of the parameters.  */
  8571.       pushdecl (eh_decl);
  8572.       expand_decl_init (eh_decl);
  8573.     }
  8574.  
  8575.   /* Create a binding contour which can be used to catch
  8576.      cleanup-generated temporaries.  Also, if the return value needs or
  8577.      has initialization, deal with that now.  */
  8578.   if (parms_have_cleanups)
  8579.     {
  8580.       pushlevel (0);
  8581.       expand_start_bindings (0);
  8582.     }
  8583.  
  8584.   current_function_parms_stored = 1;
  8585.  
  8586.   /* If this function is `main', emit a call to `__main'
  8587.      to run global initializers, etc.  */
  8588.   if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  8589.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0)
  8590.     {
  8591.       expand_expr (build_function_call (lookup_name (get_identifier ("__main")), NULL_TREE),
  8592.            0, VOIDmode, 0);
  8593.       if (flag_gc)
  8594.     expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main")), NULL_TREE),
  8595.              0, VOIDmode, 0);
  8596.  
  8597.       if (flag_dossier)
  8598.     output_builtin_tdesc_entries ();
  8599.     }
  8600. }
  8601.  
  8602. /* Bind a name and initialization to the return value of
  8603.    the current function.  */
  8604. void
  8605. store_return_init (return_id, init)
  8606.      tree return_id, init;
  8607. {
  8608.   tree decl = DECL_RESULT (current_function_decl);
  8609.   if (return_id != NULL_TREE)
  8610.     {
  8611.       if (DECL_NAME (decl) == value_identifier)
  8612.     DECL_NAME (decl) = return_id;
  8613.       else
  8614.     error ("return identifier `%s' already in place",
  8615.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  8616.     }
  8617.  
  8618.   /* Can't let this happen for constructors.  */
  8619.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  8620.     {
  8621.       error ("can't redefine default return value for constructors");
  8622.       return;
  8623.     }
  8624.  
  8625.   /* If we have a named return value, put that in our scope as well.  */
  8626.   if (DECL_NAME (decl) != value_identifier)
  8627.     {
  8628.       /* If this named return value comes in a register,
  8629.      put it in a pseudo-register.  */
  8630.       if (TREE_REGDECL (decl))
  8631.     {
  8632.       original_result_rtx = DECL_RTL (decl);
  8633.       DECL_RTL (decl) = (struct rtx_def *)gen_reg_rtx (DECL_MODE (decl));
  8634.     }
  8635.  
  8636.       /* Let `finish_decl' know that this initializer is ok.  */
  8637.       DECL_INITIAL (decl) = init;
  8638.       pushdecl (decl);
  8639.       finish_decl (decl, init, 0);
  8640.     }
  8641. }
  8642.  
  8643. /* Generate code for default X(X&) constructor.  */
  8644. static void
  8645. build_default_constructor (fndecl)
  8646.      tree fndecl;
  8647. {
  8648.   int i = CLASSTYPE_N_BASECLASSES (current_class_type);
  8649.   tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl));
  8650.   tree fields = TYPE_FIELDS (current_class_type);
  8651.   if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8652.     parm = TREE_CHAIN (parm);
  8653.   parm = DECL_REFERENCE_SLOT (parm);
  8654.  
  8655.   while (--i >= 0)
  8656.     {
  8657.       tree basetype = CLASSTYPE_BASECLASS (current_class_type, i);
  8658.       if (TYPE_GETS_INIT_REF (basetype))
  8659.     {
  8660.       tree name = TYPE_NAME (basetype);
  8661.       if (TREE_CODE (name) == TYPE_DECL)
  8662.         name = DECL_NAME (name);
  8663.       current_base_init_list = tree_cons (name, parm, current_base_init_list);
  8664.     }
  8665.     }
  8666.   for (fields = TYPE_FIELDS (current_class_type); fields;
  8667.        fields = TREE_CHAIN (fields))
  8668.     {
  8669.       tree name, init;
  8670.       if (TREE_STATIC (fields))
  8671.     continue;
  8672.       if (TREE_CODE (fields) != FIELD_DECL)
  8673.     continue;
  8674.       if (DECL_NAME (fields))
  8675.     {
  8676.       if (VFIELD_NAME_P (DECL_NAME (fields)))
  8677.         continue;
  8678.       if (VBASE_NAME_P (DECL_NAME (fields)))
  8679.         continue;
  8680.  
  8681.       /* True for duplicate members.  */
  8682.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (fields)) != fields)
  8683.         continue;
  8684.     }
  8685.  
  8686.       init = build (COMPONENT_REF, TREE_TYPE (fields), parm, fields);
  8687.  
  8688.       if (TREE_ANON_UNION_ELEM (fields))
  8689.     name = build (COMPONENT_REF, TREE_TYPE (fields), C_C_D, fields);
  8690.       else
  8691.     {
  8692.       name = DECL_NAME (fields);
  8693.       init = build_tree_list (NULL_TREE, init);
  8694.     }
  8695.  
  8696.       current_member_init_list
  8697.     = tree_cons (name, init, current_member_init_list);
  8698.     }
  8699. }
  8700.  
  8701.  
  8702. /* Finish up a function declaration and compile that function
  8703.    all the way to assembler language output.  The free the storage
  8704.    for the function definition.
  8705.  
  8706.    This is called after parsing the body of the function definition.
  8707.    LINENO is the current line number.
  8708.  
  8709.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  8710.    (and expand_end_bindings) must be made to take care of the binding
  8711.    contour for the base initializers.  This is only relevant for
  8712.    constructors.  */
  8713.  
  8714. void
  8715. finish_function (lineno, call_poplevel)
  8716.      int lineno;
  8717.      int call_poplevel;
  8718. {
  8719.   register tree fndecl = current_function_decl;
  8720.   tree fntype = TREE_TYPE (fndecl), ctype = NULL_TREE;
  8721.   tree parmdecl;
  8722.   struct rtx_def *head, *last_parm_insn, *mark;
  8723.   extern struct rtx_def *get_last_insn ();
  8724.   extern struct rtx_def *cleanup_label, *return_label;
  8725.   extern int sets_exception_throw_decl;
  8726.   /* Label to use if this function is supposed to return a value.  */
  8727.   tree no_return_label = 0;
  8728.  
  8729. /*  TREE_READONLY (fndecl) = 1;
  8730.     This caused &foo to be of type ptr-to-const-function
  8731.     which then got a warning when stored in a ptr-to-function variable.  */
  8732.  
  8733.   /* This happens on strange parse errors.  */
  8734.   if (! current_function_parms_stored)
  8735.     {
  8736.       call_poplevel = 0;
  8737.       store_parm_decls ();
  8738.     }
  8739.  
  8740.   if (flag_minimal_debug
  8741.       && write_symbols == DBX_DEBUG
  8742.       && (TREE_CODE (fntype) != METHOD_TYPE
  8743.       || ! CLASSTYPE_ASM_WRITTEN (TYPE_METHOD_BASETYPE (fntype))))
  8744.     {
  8745.       tree ttype = target_type (fntype);
  8746.       if (IS_AGGR_TYPE (ttype))
  8747.     /* Let debugger know it should output info for this type.  */
  8748.     CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  8749.  
  8750.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  8751.     {
  8752.       ttype = target_type (TREE_TYPE (parmdecl));
  8753.       if (IS_AGGR_TYPE (ttype))
  8754.         /* Let debugger know it should output info for this type.  */
  8755.         CLASSTYPE_ASM_WRITTEN (ttype) = 1;
  8756.     }
  8757.     }
  8758.  
  8759.   /* Clean house because we will need to reorder insns here.  */
  8760.   do_pending_stack_adjust ();
  8761.  
  8762.   if (dtor_label)
  8763.     {
  8764.       tree cond = integer_one_node;
  8765.       tree exprstmt, vfields;
  8766.       tree in_charge_node = lookup_name (in_charge_identifier);
  8767.       int ok_to_optimize_dtor = 0;
  8768.  
  8769.       if (current_function_assigns_this)
  8770.     cond = build (NE_EXPR, integer_type_node,
  8771.               current_class_decl, integer_zero_node);
  8772.       else
  8773.     {
  8774.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  8775.  
  8776.       /* If this destructor is empty, then we don't need to check
  8777.          whether `this' is NULL in some cases.  */
  8778.       mark = get_last_insn ();
  8779.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  8780.  
  8781.       if ((flag_this_is_variable & 1) == 0)
  8782.         ok_to_optimize_dtor = 1;
  8783.       else if (mark == last_parm_insn)
  8784.         ok_to_optimize_dtor
  8785.           = (n_baseclasses == 0
  8786.          || (n_baseclasses == 1
  8787.              && TYPE_HAS_DESTRUCTOR (CLASSTYPE_BASECLASS (current_class_type, 0))));
  8788.     }
  8789.  
  8790.       /* These initializations might go inline.  Protect
  8791.      the binding level of the parms.  */
  8792.       pushlevel (0);
  8793.  
  8794.       if (current_function_assigns_this)
  8795.     {
  8796.       current_function_assigns_this = 0;
  8797.       current_function_just_assigned_this = 0;
  8798.     }
  8799.  
  8800.       /* Generate the code to call destructor on base class.
  8801.      If this destructor belongs to a class with virtual
  8802.      functions, then set the virtual function table
  8803.      pointer to represent the type of our base class.  */
  8804.  
  8805.       /* This side-effect makes call to `build_delete' generate the
  8806.      code we have to have at the end of this destructor.  */
  8807.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  8808.  
  8809.       /* These are two cases where we cannot delegate deletion.  */
  8810.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  8811.       || TREE_GETS_DELETE (current_class_type))
  8812.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  8813.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  8814.       else
  8815.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  8816.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  8817.  
  8818.       /* If we did not assign to this, then `this' is non-zero at
  8819.      the end of a destructor.  As a special optimization, don't
  8820.      emit test if this is an empty destructor.  If it does nothing,
  8821.      it does nothing.  If it calls a base destructor, the base
  8822.      destructor will perform the test.  */
  8823.  
  8824.       if (exprstmt != error_mark_node
  8825.       && (TREE_CODE (exprstmt) != NOP_EXPR
  8826.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  8827.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  8828.     {
  8829.       expand_label (dtor_label);
  8830.       if (cond != integer_one_node)
  8831.         expand_start_cond (cond, 0);
  8832.       expand_expr_stmt (exprstmt);
  8833.  
  8834.       /* Run destructor on all virtual baseclasses.  */
  8835.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8836.         {
  8837.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  8838.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  8839.                     in_charge_node, integer_two_node), 0);
  8840.           while (vbases)
  8841.         {
  8842.           if (TYPE_NEEDS_DESTRUCTOR (TREE_VALUE (vbases)))
  8843.             {
  8844.               tree ptr = convert_pointer_to_vbase (TREE_TYPE (vbases), current_class_decl);
  8845.               expand_expr_stmt (build_delete (TYPE_POINTER_TO (TREE_VALUE (vbases)),
  8846.                               ptr, integer_zero_node,
  8847.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
  8848.             }
  8849.           vbases = TREE_CHAIN (vbases);
  8850.         }
  8851.           expand_end_cond ();
  8852.         }
  8853.  
  8854.       do_pending_stack_adjust ();
  8855.       if (cond != integer_one_node)
  8856.         expand_end_cond ();
  8857.     }
  8858.  
  8859.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  8860.  
  8861.       /* At the end, call delete if that's what's requested.  */
  8862.       if (TREE_GETS_DELETE (current_class_type))
  8863.     /* This NOP_EXPR means we are in a static call context.  */
  8864.     exprstmt = build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
  8865.                       get_identifier (OPERATOR_DELETE_FORMAT),
  8866.                       /* ??? This was integer_zero_node.  */
  8867.                       build_tree_list (NULL_TREE, current_class_decl),
  8868.                       NULL_TREE, LOOKUP_NORMAL);
  8869.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8870.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0);
  8871.       else
  8872.     exprstmt = 0;
  8873.  
  8874.       if (exprstmt)
  8875.     {
  8876.       cond = build (BIT_AND_EXPR, integer_type_node,
  8877.             in_charge_node, integer_one_node);
  8878.       expand_start_cond (cond, 0);
  8879.       expand_expr_stmt (exprstmt);
  8880.       expand_end_cond ();
  8881.     }
  8882.  
  8883.       /* End of destructor.  */
  8884.       poplevel (2, 0, 0);
  8885.  
  8886.       /* Back to the top of destructor.  */
  8887.       /* Dont execute destructor code if `this' is NULL.  */
  8888.       mark = get_last_insn ();
  8889.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  8890.       if (last_parm_insn == 0) last_parm_insn = mark;
  8891.       else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
  8892.  
  8893.       /* Make all virtual function table pointers point to CURRENT_CLASS_TYPE's
  8894.      virtual function tables.  */
  8895.       if (CLASSTYPE_VFIELDS (current_class_type))
  8896.     {
  8897.       for (vfields = CLASSTYPE_VFIELDS (current_class_type);
  8898.            TREE_CHAIN (vfields);
  8899.            vfields = TREE_CHAIN (vfields))
  8900.         expand_expr_stmt (build_virtual_init (current_class_type,
  8901.                           TREE_VALUE (vfields),
  8902.                           current_class_decl));
  8903.       expand_expr_stmt (build_virtual_init (current_class_type,
  8904.                         current_class_type,
  8905.                         current_class_decl));
  8906.     }
  8907.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  8908.     expand_expr_stmt (build_vbase_vtables_init (current_class_type,
  8909.                             current_class_type,
  8910.                             C_C_D, current_class_decl, 0));
  8911.       if (! ok_to_optimize_dtor)
  8912.     {
  8913.       cond = build_binary_op (NE_EXPR, current_class_decl, integer_zero_node);
  8914.       expand_start_cond (cond, 0);
  8915.     }
  8916.       if (mark != get_last_insn ())
  8917.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  8918.       if (! ok_to_optimize_dtor)
  8919.       expand_end_cond ();
  8920.     }
  8921.   else if (current_function_assigns_this)
  8922.     {
  8923.       /* Does not need to call emit_base_init, because
  8924.      that is done (if needed) just after assignment to this
  8925.      is seen.  */
  8926.  
  8927.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  8928.     {
  8929.       expand_label (ctor_label);
  8930.       ctor_label = NULL_TREE;
  8931.  
  8932.       if (call_poplevel)
  8933.         {
  8934.           tree decls = getdecls ();
  8935.           if (flag_handle_exceptions == 2)
  8936.         deactivate_exception_cleanups ();
  8937.           expand_end_bindings (decls, decls != 0, 0);
  8938.           poplevel (decls != 0, 0, 0);
  8939.         }
  8940.       c_expand_return (current_class_decl);
  8941.     }
  8942.       else if (DECL_RESULT (current_function_decl))
  8943.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  8944.  
  8945.       current_function_assigns_this = 0;
  8946.       current_function_just_assigned_this = 0;
  8947.       base_init_insns = 0;
  8948.     }
  8949.   else if (DECL_CONSTRUCTOR_P (fndecl))
  8950.     {
  8951.       tree allocated_this;
  8952.       tree cond, thenclause;
  8953.       /* Allow constructor for a type to get a new instance of the object
  8954.      using `build_new'.  */
  8955.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  8956.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  8957.  
  8958.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  8959.  
  8960.       if (flag_this_is_variable)
  8961.     {
  8962.       cond = build_binary_op (EQ_EXPR, current_class_decl, integer_zero_node);
  8963.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  8964.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  8965.       if (flag_handle_exceptions == 2)
  8966.         {
  8967.           tree cleanup, cleanup_deallocate;
  8968.  
  8969.           allocated_this = build_decl (VAR_DECL, NULL_TREE, ptr_type_node);
  8970.           TREE_REGDECL (allocated_this) = 1;
  8971.           DECL_INITIAL (allocated_this) = error_mark_node;
  8972.           expand_decl (allocated_this);
  8973.           expand_decl_init (allocated_this);
  8974.           /* How we cleanup `this' if an exception was raised before
  8975.          we are ready to bail out.  */
  8976.           cleanup = TREE_GETS_DELETE (current_class_type)
  8977.         ? build_opfncall (DELETE_EXPR, LOOKUP_NORMAL, allocated_this)
  8978.           : build_delete (TREE_TYPE (allocated_this), allocated_this, integer_three_node, LOOKUP_NORMAL|LOOKUP_HAS_IN_CHARGE, 1);
  8979.           cleanup_deallocate
  8980.         = build_modify_expr (current_class_decl, NOP_EXPR, integer_zero_node);
  8981.           cleanup = tree_cons (NULL_TREE, cleanup,
  8982.                    build_tree_list (NULL_TREE, cleanup_deallocate));
  8983.  
  8984.           expand_decl_cleanup (allocated_this,
  8985.                    build (COND_EXPR, integer_type_node,
  8986.                       build (NE_EXPR, integer_type_node,
  8987.                          allocated_this, integer_zero_node),
  8988.                       build_compound_expr (cleanup),
  8989.                       integer_zero_node));
  8990.         }
  8991.     }
  8992.       else if (TREE_GETS_NEW (current_class_type))
  8993.     /* Just check visibility here.  */
  8994.     build_method_call (build1 (NOP_EXPR, TYPE_POINTER_TO (current_class_type), error_mark_node),
  8995.                get_identifier (OPERATOR_NEW_FORMAT),
  8996.                build_tree_list (NULL_TREE, integer_zero_node),
  8997.                NULL_TREE, LOOKUP_NORMAL);
  8998.  
  8999.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  9000.  
  9001.       /* must keep the first insn safe.  */
  9002.       head = (struct rtx_def *)get_insns ();
  9003.  
  9004.       /* this note will come up to the top with us.  */
  9005.       mark = get_last_insn ();
  9006.  
  9007.       if (flag_this_is_variable)
  9008.     {
  9009.       expand_start_cond (cond, 0);
  9010.       expand_expr_stmt (thenclause);
  9011.       if (flag_handle_exceptions == 2)
  9012.         expand_assignment (allocated_this, current_class_decl, 0, 0);
  9013.       expand_end_cond ();
  9014.     }
  9015.  
  9016.       if (DECL_COMPILER_GENERATED_P (fndecl)
  9017.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  9018.     build_default_constructor (fndecl);
  9019.  
  9020.       /* Emit insns from `emit_base_init' which sets up virtual
  9021.      function table pointer(s).  */
  9022.       emit_insns (base_init_insns);
  9023.       base_init_insns = 0;
  9024.  
  9025.       /* This is where the body of the constructor begins.
  9026.      If there were no insns in this function body, then the
  9027.      last_parm_insn is also the last insn.
  9028.  
  9029.      If optimization is enabled, last_parm_insn may move, so
  9030.      we don't hold on to it (across emit_base_init).  */
  9031.       last_parm_insn = (struct rtx_def *)get_first_nonparm_insn ();
  9032.       if (last_parm_insn == 0) last_parm_insn = mark;
  9033.       else last_parm_insn = (struct rtx_def *) previous_insn (last_parm_insn);
  9034.  
  9035.       if (mark != get_last_insn ())
  9036.     reorder_insns (next_insn (mark), get_last_insn (), last_parm_insn);
  9037.  
  9038.       /* This is where the body of the constructor ends.  */
  9039.       expand_label (ctor_label);
  9040.       ctor_label = NULL_TREE;
  9041.       if (flag_handle_exceptions == 2)
  9042.     {
  9043.       expand_assignment (allocated_this, integer_zero_node, 0, 0);
  9044.       deactivate_exception_cleanups ();
  9045.     }
  9046.  
  9047.       pop_implicit_try_blocks (NULL_TREE);
  9048.  
  9049.       if (call_poplevel)
  9050.     {
  9051.       expand_end_bindings (getdecls (), 1, 0);
  9052.       poplevel (1, 1, 0);
  9053.     }
  9054.  
  9055.       c_expand_return (current_class_decl);
  9056.  
  9057.       current_function_assigns_this = 0;
  9058.       current_function_just_assigned_this = 0;
  9059.     }
  9060.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  9061.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
  9062.     {
  9063.       /* Make it so that `main' always returns 0 by default.  */
  9064. #ifdef VMS
  9065.       c_expand_return (integer_one_node);
  9066. #else
  9067.       c_expand_return (integer_zero_node);
  9068. #endif
  9069.     }
  9070.   else if (DECL_RESULT (current_function_decl))
  9071.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  9072.  
  9073.   if (flag_gc)
  9074.     expand_gc_prologue_and_epilogue ();
  9075.  
  9076.   /* That's the end of the vtable decl's life.  Need to mark it such
  9077.      if doing stupid register allocation.
  9078.  
  9079.      Note that current_vtable_decl is really an INDIRECT_REF
  9080.      on top of a VAR_DECL here.  */
  9081.   if (obey_regdecls && current_vtable_decl)
  9082.     use_variable (DECL_RTL (TREE_OPERAND (current_vtable_decl, 0)));
  9083.  
  9084.   /* If this function is supposed to return a value, ensure that
  9085.      we do not fall into the cleanups by mistake.  The end of our
  9086.      function will look like this:
  9087.  
  9088.     user code (may have return stmt somewhere)
  9089.     goto no_return_label
  9090.     cleanup_label:
  9091.     cleanups
  9092.     goto return_label
  9093.     no_return_label:
  9094.     NOTE_INSN_FUNCTION_END
  9095.     return_label:
  9096.     things for return
  9097.  
  9098.      If the user omits a return stmt in the USER CODE section, we
  9099.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  9100.      Otherwise, we won't.  */
  9101.   if (no_return_label)
  9102.     {
  9103.       DECL_CONTEXT (no_return_label) = fndecl;
  9104.       DECL_INITIAL (no_return_label) = error_mark_node;
  9105.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  9106.       DECL_SOURCE_LINE (no_return_label) = lineno;
  9107.       expand_goto (no_return_label);
  9108.     }
  9109.  
  9110.   if (cleanup_label)
  9111.     {
  9112.       /* remove the binding contour which is used
  9113.      to catch cleanup-generated temporaries.  */
  9114.       expand_end_bindings (0, 0, 0);
  9115.       poplevel (0, 0, 0);
  9116.     }
  9117.  
  9118.   /* Must mark the RESULT_DECL as being in this function.  */
  9119.  
  9120.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  9121.  
  9122.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  9123.   if (flag_traditional && current_function_calls_setjmp)
  9124.     setjmp_protect (DECL_INITIAL (fndecl));
  9125.  
  9126.   if (cleanup_label)
  9127.     {
  9128.       /* Emit label at beginning of cleanup code for parmeters.  */
  9129.       emit_label (cleanup_label);
  9130.       /* After this point we zero out CLEANUP_LABEL so that all
  9131.      other `returns' go to RETURN_LABEL.  */
  9132.       cleanup_label = 0;
  9133.     }
  9134.  
  9135. #if 1
  9136.   /* Cheap hack to get better code from GNU C++.  Remove when cse is fixed.  */
  9137.   if (exception_throw_decl && sets_exception_throw_decl == 0)
  9138.     expand_assignment (exception_throw_decl, integer_zero_node, 0, 0);
  9139. #endif
  9140.  
  9141.   if (flag_handle_exceptions)
  9142.     {
  9143.       expand_end_try ();
  9144.       expand_start_except (0, 0);
  9145.       expand_end_except ();
  9146.     }
  9147.   expand_end_bindings (0, 0, 0);
  9148.  
  9149.   /* Get return value into reigster if that's where it's supposed to be.  */
  9150.   if (original_result_rtx)
  9151.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  9152.  
  9153.   /* Finish building code that will trigger warnings if users forget
  9154.      to make their functions return values.  */
  9155.   if (no_return_label)
  9156.     {
  9157.       expand_null_return ();
  9158.       expand_label (no_return_label);
  9159.     }
  9160.  
  9161.   /* reset scope for C++: if we were in the scope of a class,
  9162.      then when we finish this function, we are not longer so.
  9163.      This cannot be done until we know for sure that no more
  9164.      class members will ever be referenced in this function
  9165.      (i.e., calls to destructors).  */
  9166.   if (current_class_name)
  9167.     {
  9168.       ctype = current_class_type;
  9169.       popclass (1);
  9170.     }
  9171.   else
  9172.     pop_memoized_context (1);
  9173.  
  9174.   /* Forget about all overloaded functions defined in
  9175.      this scope which go away.  */
  9176.   while (overloads_to_forget)
  9177.     {
  9178.       IDENTIFIER_GLOBAL_VALUE (TREE_PURPOSE (overloads_to_forget))
  9179.     = TREE_VALUE (overloads_to_forget);
  9180.       overloads_to_forget = TREE_CHAIN (overloads_to_forget);
  9181.     }
  9182.  
  9183.   /* Generate rtl for function exit.  */
  9184.   expand_function_end (input_filename, lineno);
  9185.  
  9186.   /* This must come after expand_function_end because cleanups might
  9187.      have declarations (from inline functions) that need to go into
  9188.      this function's blocks.  */
  9189.   assert (current_binding_level->parm_flag == 1);
  9190.   poplevel (1, 0, 1);
  9191.  
  9192.   /* So we can tell if jump_optimize sets it to 1.  */
  9193.   current_function_returns_null = 0;
  9194.  
  9195.   /* ??? Compensate for Sun brain damage in dealing with data segments
  9196.      of PIC code.  */
  9197.   if (flag_pic
  9198.       && (DECL_CONSTRUCTOR_P (fndecl)
  9199.       || DESTRUCTOR_NAME_P (DECL_NAME (fndecl)))
  9200.       && CLASSTYPE_NEEDS_VIRTUAL_REINIT (TYPE_METHOD_BASETYPE (fntype)))
  9201.     TREE_INLINE (fndecl) = 0;
  9202.  
  9203.   if (TREE_EXTERNAL (fndecl) && ! TREE_PUBLIC (fndecl)
  9204.       /* This function is just along for the ride.  If we can make
  9205.      it inline, that's great.  Otherwise, just punt it.  */
  9206.       && (TREE_INLINE (fndecl) == 0
  9207.       || function_cannot_inline_p (fndecl)))
  9208.     {
  9209.       extern int rtl_dump_and_exit;
  9210.       int old_rtl_dump_and_exit = rtl_dump_and_exit;
  9211.  
  9212.       /* This throws away the code for FNDECL.  */
  9213.       rtl_dump_and_exit = 1;
  9214.       rest_of_compilation (fndecl);
  9215.       rtl_dump_and_exit = old_rtl_dump_and_exit;
  9216.     }
  9217.   else
  9218.     /* Run the optimizers and output the assembler code for this function.  */
  9219.     rest_of_compilation (fndecl);
  9220.  
  9221.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  9222.     CLASSTYPE_ASM_WRITTEN (ctype) = 1;
  9223.  
  9224.   /* Since we don't normally go through c_expand_return for constructors,
  9225.      this normally gets the wrong value.
  9226.      Also, named return values have their return codes emitted after
  9227.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  9228.   if (DECL_CONSTRUCTOR_P (fndecl)
  9229.       || DECL_NAME (DECL_RESULT (fndecl)) != value_identifier)
  9230.     current_function_returns_null = 0;
  9231.  
  9232.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  9233.     warning ("`volatile' function does return");
  9234.   else if (warn_return_type && current_function_returns_null
  9235.        && TREE_TYPE (fntype) != void_type_node)
  9236.     /* If this function returns non-void and control can drop through,
  9237.        complain.  */
  9238.     warning ("control reaches end of non-void function");
  9239.   /* With just -W, complain only if function returns both with
  9240.      and without a value.  */
  9241.   else if (extra_warnings
  9242.        && current_function_returns_value && current_function_returns_null)
  9243.     warning ("this function may return with or without a value");
  9244.  
  9245.   /* Free all the tree nodes making up this function.  */
  9246.   /* Switch back to allocating nodes permanently
  9247.      until we start another function.  */
  9248.   permanent_allocation ();
  9249.  
  9250.   if (flag_cadillac)
  9251.     cadillac_finish_function (fndecl);
  9252.  
  9253.   if (DECL_SAVED_INSNS (fndecl) == 0)
  9254.     {
  9255.       /* Stop pointing to the local nodes about to be freed.  */
  9256.       /* But DECL_INITIAL must remain nonzero so we know this
  9257.      was an actual function definition.  */
  9258.       DECL_INITIAL (fndecl) = error_mark_node;
  9259.       if (! DECL_CONSTRUCTOR_P (fndecl)
  9260.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  9261.     DECL_ARGUMENTS (fndecl) = 0;
  9262.     }
  9263.  
  9264.   /* Let the error reporting routines know that we're outside a function.  */
  9265.   current_function_decl = NULL_TREE;
  9266.   named_label_uses = NULL_TREE;
  9267.   clear_anon_parm_name ();
  9268. }
  9269.  
  9270. /* Create the FUNCTION_DECL for a function definition.
  9271.    LINE1 is the line number that the definition absolutely begins on.
  9272.    LINE2 is the line number that the name of the function appears on.
  9273.    DECLSPECS and DECLARATOR are the parts of the declaration;
  9274.    they describe the function's name and the type it returns,
  9275.    but twisted together in a fashion that parallels the syntax of C.
  9276.  
  9277.    This function creates a binding context for the function body
  9278.    as well as setting up the FUNCTION_DECL in current_function_decl.
  9279.  
  9280.    Returns a FUNCTION_DECL on success.
  9281.  
  9282.    If the DECLARATOR is not suitable for a function (it defines a datum
  9283.    instead), we return 0, which tells yyparse to report a parse error.
  9284.  
  9285.    May return void_type_node indicating that this method is actually
  9286.    a friend.  See grokfield for more details.
  9287.  
  9288.    Came here with a `.pushlevel' .
  9289.  
  9290.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  9291.    CHANGES TO CODE IN `grokfield'.  */
  9292. tree
  9293. start_method (declspecs, declarator, raises)
  9294.      tree declarator, declspecs, raises;
  9295. {
  9296.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises);
  9297.  
  9298.   /* Something too ugly to handle.  */
  9299.   if (fndecl == 0)
  9300.     return 0;
  9301.  
  9302.   /* Pass friends other than inline friend functions back.  */
  9303.   if (fndecl == void_type_node)
  9304.     return void_type_node;
  9305.  
  9306.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  9307.     /* Not a function, tell parser to report parse error.  */
  9308.     return 0;
  9309.  
  9310.   if (DECL_IN_AGGR_P (fndecl))
  9311.     {
  9312.       if (IDENTIFIER_ERROR_LOCUS (DECL_NAME (fndecl)) != current_class_type)
  9313.     error_with_decl (fndecl, "`%s' is already defined in aggregate scope");
  9314.       return void_type_node;
  9315.     }
  9316.  
  9317.   if (flag_default_inline)
  9318.     TREE_INLINE (fndecl) = 1;
  9319.  
  9320.   /* We read in the parameters on the maybepermanent_obstack,
  9321.      but we won't be getting back to them until after we
  9322.      may have clobbered them.  So the call to preserve_data
  9323.      will keep them safe.  */
  9324.   preserve_data ();
  9325.  
  9326.   if (! DECL_FRIEND_P (fndecl))
  9327.     {
  9328.       if (DECL_CHAIN (fndecl) != NULL_TREE)
  9329.     {
  9330.       /* Need a fresh node here so that we don't get circularity
  9331.          when we link these together.  If FNDECL was a friend, then
  9332.          `pushdecl' does the right thing, which is nothing wrt its
  9333.          current value of DECL_CHAIN.  */
  9334.       fndecl = copy_node (fndecl);
  9335.     }
  9336.  
  9337.       if (DECL_CONSTRUCTOR_P (fndecl))
  9338.     grok_ctor_properties (current_class_type, fndecl);
  9339.       else if (OPERATOR_NAME_P (DECL_NAME (fndecl)))
  9340.     {
  9341.       DECL_OPERATOR (fndecl) = 1;
  9342.       grok_op_properties (fndecl);
  9343.     }
  9344.     }
  9345.  
  9346.   finish_decl (fndecl, NULL, NULL);
  9347.  
  9348.   /* Make a place for the parms */
  9349.   pushlevel (0);
  9350.   current_binding_level->parm_flag = 1;
  9351.   
  9352.   DECL_IN_AGGR_P (fndecl) = 1;
  9353.   return fndecl;
  9354. }
  9355.  
  9356. /* Go through the motions of finishing a function definition.
  9357.    We don't compile this method until after the whole class has
  9358.    been processed.
  9359.  
  9360.    FINISH_METHOD must return something that looks as though it
  9361.    came from GROKFIELD (since we are defining a method, after all).
  9362.  
  9363.    This is called after parsing the body of the function definition.
  9364.    STMTS is the chain of statements that makes up the function body.
  9365.  
  9366.    DECL is the ..._DECL that `start_method' provided.  */
  9367.  
  9368. tree
  9369. finish_method (decl)
  9370.      tree decl;
  9371. {
  9372.   register tree fndecl = decl;
  9373.   tree old_initial;
  9374.  
  9375.   register tree link;
  9376.  
  9377.   if (decl == void_type_node)
  9378.     return decl;
  9379.  
  9380.   old_initial = DECL_INITIAL (fndecl);
  9381.  
  9382.   /* Undo the level for the parms (from start_method).
  9383.      This is like poplevel, but it causes nothing to be
  9384.      saved.  Saving information here confuses symbol-table
  9385.      output routines.  Besides, this information will
  9386.      be correctly output when this method is actually
  9387.      compiled.  */
  9388.  
  9389.   /* Clear out the meanings of the local variables of this level;
  9390.      also record in each decl which block it belongs to.  */
  9391.  
  9392.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  9393.     {
  9394.       if (DECL_NAME (link) != 0)
  9395.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  9396.       DECL_CONTEXT (link) = 0;
  9397.     }
  9398.  
  9399.   /* Restore all name-meanings of the outer levels
  9400.      that were shadowed by this level.  */
  9401.  
  9402.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  9403.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  9404.   for (link = current_binding_level->class_shadowed;
  9405.        link;
  9406.        link = TREE_CHAIN (link))
  9407.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  9408.  
  9409.   GNU_xref_end_scope (current_binding_level,
  9410.               current_binding_level->level_chain,
  9411.               current_binding_level->parm_flag,
  9412.               current_binding_level->keep,
  9413.               current_binding_level->tag_transparent);
  9414.  
  9415.   POP_BINDING_LEVEL;
  9416.  
  9417.   DECL_INITIAL (fndecl) = old_initial;
  9418.   if (DECL_FRIEND_P (fndecl))
  9419.     {
  9420.       if (current_lang_name == lang_name_cplusplus)
  9421.     CLASSTYPE_INLINE_FRIENDS (current_class_type)
  9422.       = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  9423.       return void_type_node;
  9424.     }
  9425.   return decl;
  9426. }
  9427.  
  9428. /* Called when a new struct TYPE is defined.
  9429.    If this structure or union completes the type of any previous
  9430.    variable declaration, lay it out and output its rtl.  */
  9431.  
  9432. void
  9433. hack_incomplete_structures (type)
  9434.      tree type;
  9435. {
  9436.   tree decl;
  9437.  
  9438.   if (current_binding_level->n_incomplete == 0)
  9439.     return;
  9440.  
  9441.   if (!type) /* Don't do this for class templates.  */
  9442.     return;
  9443.  
  9444.   for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  9445.     if (TREE_TYPE (decl) == type
  9446.     || (TREE_TYPE (decl)
  9447.         && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  9448.         && TREE_TYPE (TREE_TYPE (decl)) == type))
  9449.       {
  9450.     if (TREE_CODE (decl) == TYPE_DECL)
  9451.       layout_type (TREE_TYPE (decl));
  9452.     else
  9453.       {
  9454.         int toplevel = global_binding_level == current_binding_level;
  9455.         layout_decl (decl, 0);
  9456.         rest_of_decl_compilation (decl, 0, toplevel, 0);
  9457.         if (! toplevel)
  9458.           {
  9459.         expand_decl (decl);
  9460.         expand_decl_cleanup (decl, maybe_build_cleanup (decl));
  9461.         expand_decl_init (decl);
  9462.           }
  9463.       }
  9464.     --current_binding_level->n_incomplete;
  9465.     assert (current_binding_level->n_incomplete >= 0);
  9466.       }
  9467. }
  9468.  
  9469. /* Nonzero if presently building a cleanup.  Needed because
  9470.    SAVE_EXPRs are not the right things to use inside of cleanups.
  9471.    They are only ever evaluated once, where the cleanup
  9472.    might be evaluated several times.  In this case, a later evaluation
  9473.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  9474.    not be valid for an earlier cleanup.  */
  9475.  
  9476. int building_cleanup;
  9477.  
  9478. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  9479.    We don't build cleanups if just going for syntax checking, since
  9480.    fixup_cleanups does not know how to not handle them.
  9481.  
  9482.    Don't build these on the momentary obstack; they must live
  9483.    the life of the binding contour.  */
  9484. tree
  9485. maybe_build_cleanup (decl)
  9486.      tree decl;
  9487. {
  9488.   tree type = TREE_TYPE (decl);
  9489.   if (TYPE_NEEDS_DESTRUCTOR (type))
  9490.     {
  9491.       int temp, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
  9492.       tree rval;
  9493.       int old_building_cleanup = building_cleanup;
  9494.       building_cleanup = 1;
  9495.  
  9496.       if (TREE_CODE (decl) == PARM_DECL)
  9497.     {
  9498.       temp = allocation_temporary_p ();
  9499.       end_temporary_allocation ();
  9500.     }
  9501.       else
  9502.     temp = suspend_momentary ();
  9503.  
  9504.       if (TREE_CODE (type) == ARRAY_TYPE)
  9505.     rval = decl;
  9506.       else
  9507.     {
  9508.       mark_addressable (decl);
  9509.       rval = build_unary_op (ADDR_EXPR, decl, 0);
  9510.     }
  9511.  
  9512.       /* Optimize for space over speed here.  */
  9513.       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
  9514.       || flag_expensive_optimizations)
  9515.     flags |= LOOKUP_NONVIRTUAL;
  9516.  
  9517.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node,
  9518.                flags, 0);
  9519.  
  9520.       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
  9521.       && ! TYPE_HAS_DESTRUCTOR (type))
  9522.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  9523.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  9524.  
  9525.       current_binding_level->have_cleanups = 1;
  9526.       current_binding_level->more_exceptions_ok = 0;
  9527.  
  9528.       if (TREE_CODE (decl) == PARM_DECL)
  9529.     {
  9530.       if (temp)
  9531.         resume_temporary_allocation ();
  9532.     }
  9533.       else
  9534.     resume_momentary (temp);
  9535.  
  9536.       building_cleanup = old_building_cleanup;
  9537.  
  9538.       return rval;
  9539.     }
  9540.   return 0;
  9541. }
  9542.  
  9543. tree
  9544. cleanup_after_call (expr)
  9545.      tree expr;
  9546. {
  9547.   tree type = TREE_TYPE (expr);
  9548.   tree decl = get_temp_name (type, 0);
  9549.   tree rval = build (WITH_CLEANUP_EXPR, type,
  9550.              build (INIT_EXPR, type, decl, expr), 0,
  9551.              maybe_build_cleanup (decl));
  9552.   return rval;
  9553. }
  9554.  
  9555. /* Expand a C++ expression at the statement level.
  9556.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  9557.    The C++ type checker should get all of these out when
  9558.    expressions are combined with other, type-providing, expressions,
  9559.    leaving only orphan expressions, such as:
  9560.  
  9561.    &class::bar;        / / takes its address, but does nothing with it.
  9562.  
  9563.    */
  9564. void
  9565. cplus_expand_expr_stmt (exp)
  9566.      tree exp;
  9567. {
  9568.   if (TREE_TYPE (exp) == unknown_type_node)
  9569.     {
  9570.       if (TREE_CODE (exp) == ADDR_EXPR)
  9571.     {
  9572.       if (TREE_CODE (TREE_OPERAND (exp, 0)) == OP_IDENTIFIER)
  9573.         error ("unresolved reference to user-defined operator");
  9574.       else
  9575.         error ("address of overloaded function with no contextual type information");
  9576.     }
  9577.       else if (TREE_CODE (exp) == TREE_LIST)
  9578.     error ("address of overloaded function with no contextual type information");
  9579.       else if (TREE_CODE (exp) == OP_IDENTIFIER)
  9580.     error ("unresolved reference to user-defined operator");
  9581.       else if (TREE_CODE (exp) == COMPONENT_REF)
  9582.     warning ("useless reference to a member function name, did you forget the ()?");
  9583.     }
  9584.   else
  9585.     {
  9586.       int remove_implicit_immediately = 0;
  9587.  
  9588.       if (TREE_CODE (exp) == CALL_EXPR
  9589.       && TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (exp)))
  9590.     exp = cleanup_after_call (exp);
  9591.       else if (TREE_CODE (exp) == FUNCTION_DECL)
  9592.     warning_with_decl (exp, "reference, not call, to function `%s'");
  9593.       if (TREE_RAISES (exp))
  9594.     {
  9595.       assert (flag_handle_exceptions);
  9596.       if (flag_handle_exceptions == 2)
  9597.         {
  9598.           if (! current_binding_level->more_exceptions_ok)
  9599.         {
  9600.           extern struct nesting *nesting_stack, *block_stack;
  9601.  
  9602.           remove_implicit_immediately
  9603.             = (nesting_stack != block_stack);
  9604.           cplus_expand_start_try (1);
  9605.         }
  9606.           current_binding_level->have_exceptions = 1;
  9607.         }
  9608.     }
  9609.       expand_expr_stmt (exp);
  9610.       if (remove_implicit_immediately)
  9611.     pop_implicit_try_blocks (NULL_TREE);
  9612.     }
  9613.  
  9614.   /* Clean up any pending cleanups.  This happens when a function call
  9615.      returns a cleanup-needing value that nobody uses.  */
  9616.   expand_cleanups_to (NULL_TREE);
  9617. }
  9618.  
  9619. /* When a stmt has been parsed, this function is called.
  9620.  
  9621.    Currently, this function only does something within a
  9622.    constructor's scope: if a stmt has just assigned to this,
  9623.    and we are in a derived class, we call `emit_base_init'.  */
  9624.  
  9625. void
  9626. finish_stmt ()
  9627. {
  9628.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  9629.  
  9630.   
  9631.   if (current_function_assigns_this
  9632.       || ! current_function_just_assigned_this)
  9633.     return;
  9634.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  9635.     {
  9636.       /* Constructors must wait until we are out of control
  9637.      zones before calling base constructors.  */
  9638.       if (cond_stack || loop_stack || case_stack)
  9639.     return;
  9640.       emit_insns (base_init_insns);
  9641.       check_base_init (current_class_type);
  9642.     }
  9643.   current_function_assigns_this = 1;
  9644.  
  9645.   if (flag_cadillac)
  9646.     cadillac_finish_stmt ();
  9647. }
  9648.  
  9649. void
  9650. pop_implicit_try_blocks (decl)
  9651.      tree decl;
  9652. {
  9653.   if (decl)
  9654.     {
  9655.       assert (current_binding_level->parm_flag == 3);
  9656.       current_binding_level->names = TREE_CHAIN (decl);
  9657.     }
  9658.  
  9659.   while (current_binding_level->parm_flag == 3)
  9660.     {
  9661.       tree name = get_identifier ("(compiler error)");
  9662.       tree orig_ex_type = current_exception_type;
  9663.       tree orig_ex_decl = current_exception_decl;
  9664.       tree orig_ex_obj = current_exception_object;
  9665.       tree decl = cplus_expand_end_try (2), decls;
  9666.       tree current_exception_ptr;
  9667.  
  9668.       /* @@ It would be nice to make all these point
  9669.      to exactly the same handler.  */
  9670.       /* Start hidden EXCEPT.  */
  9671.       cplus_expand_start_except (name, decl);
  9672.       /* reraise ALL.  */
  9673.       cplus_expand_reraise (NULL_TREE);
  9674.       current_exception_type = orig_ex_type;
  9675.       current_exception_decl = orig_ex_decl;
  9676.       current_exception_object = orig_ex_obj;
  9677.       /* This will reraise for us.  */
  9678.       cplus_expand_end_except (error_mark_node);
  9679.     }
  9680.  
  9681.   if (decl)
  9682.     {
  9683.       TREE_CHAIN (decl) = current_binding_level->names;
  9684.       current_binding_level->names = decl;
  9685.     }
  9686. }
  9687.  
  9688. static void
  9689. GNU_end_scope (lvl)
  9690.    struct binding_level *lvl;
  9691. {
  9692.    GNU_xref_end_scope (lvl, lvl->level_chain, lvl->parm_flag, lvl->keep,
  9693.                lvl->tag_transparent);
  9694. };
  9695.  
  9696. /* Push a cleanup onto the current binding contour that will cause
  9697.    ADDR to be cleaned up, in the case that an exception propagates
  9698.    through its binding contour.  */
  9699.  
  9700. void
  9701. push_exception_cleanup (addr)
  9702.      tree addr;
  9703. {
  9704.   tree decl = build_decl (VAR_DECL, get_identifier (EXCEPTION_CLEANUP_NAME), ptr_type_node);
  9705.   tree cleanup;
  9706.  
  9707.   decl = pushdecl (decl);
  9708.   TREE_REGDECL (decl) = 1;
  9709.   store_init_value (decl, addr);
  9710.   expand_decl (decl);
  9711.   expand_decl_init (decl);
  9712.  
  9713.   cleanup = build (COND_EXPR, integer_type_node,
  9714.            build (NE_EXPR, integer_type_node,
  9715.               decl, integer_zero_node),
  9716.            build_delete (TREE_TYPE (addr), decl,
  9717.                  lookup_name (in_charge_identifier),
  9718.                  LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0),
  9719.            integer_zero_node);
  9720.   expand_decl_cleanup (decl, cleanup);
  9721. }
  9722.  
  9723. /* For each binding contour, emit code that deactivates the
  9724.    exception cleanups.  All other cleanups are left as they were.  */
  9725.  
  9726. static void
  9727. deactivate_exception_cleanups ()
  9728. {
  9729.   struct binding_level *b = current_binding_level;
  9730.   tree xyzzy = get_identifier (EXCEPTION_CLEANUP_NAME);
  9731.   while (b != class_binding_level)
  9732.     {
  9733.       if (b->parm_flag == 3)
  9734.     {
  9735.       tree decls = b->names;
  9736.       while (decls)
  9737.         {
  9738.           if (DECL_NAME (decls) == xyzzy)
  9739.         expand_assignment (decls, integer_zero_node, 0, 0);
  9740.           decls = TREE_CHAIN (decls);
  9741.         }
  9742.     }
  9743.       b = b->level_chain;
  9744.     }
  9745. }
  9746.