home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / cp / decl.c < prev    next >
C/C++ Source or Header  |  1996-12-21  |  409KB  |  13,081 lines

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988, 1992, 1993, 1994, 1995 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, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. /* Process declarations and symbol lookup for C front end.
  24.    Also constructs types; the standard scalar types at initialization,
  25.    and structure, union, array and enum types when they are declared.  */
  26.  
  27. /* ??? not all decl nodes are given the most useful possible
  28.    line numbers.  For example, the CONST_DECLs for enum values.  */
  29.  
  30. #include <stdio.h>
  31. #include "config.h"
  32. #include "tree.h"
  33. #include "rtl.h"
  34. #include "flags.h"
  35. #include "cp-tree.h"
  36. #include "decl.h"
  37. #include "lex.h"
  38. #include <sys/types.h>
  39. #include <signal.h>
  40. #include "obstack.h"
  41.  
  42. #if defined (_WIN32) && defined (NEXT_PDO)
  43. extern char* exportNamesForDLL;
  44. #endif
  45.  
  46. #define obstack_chunk_alloc xmalloc
  47. #define obstack_chunk_free free
  48.  
  49. extern tree builtin_return_address_fndecl;
  50.  
  51. extern struct obstack permanent_obstack;
  52.  
  53. extern int current_class_depth;
  54.  
  55. extern tree cleanups_this_call;
  56.  
  57. extern tree static_ctors, static_dtors;
  58.  
  59. /* Stack of places to restore the search obstack back to.  */
  60.    
  61. /* Obstack used for remembering local class declarations (like
  62.    enums and static (const) members.  */
  63. #include "stack.h"
  64. static struct obstack decl_obstack;
  65. static struct stack_level *decl_stack;
  66.  
  67. #ifndef CHAR_TYPE_SIZE
  68. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  69. #endif
  70.  
  71. #ifndef SHORT_TYPE_SIZE
  72. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  73. #endif
  74.  
  75. #ifndef INT_TYPE_SIZE
  76. #define INT_TYPE_SIZE BITS_PER_WORD
  77. #endif
  78.  
  79. #ifndef LONG_TYPE_SIZE
  80. #define LONG_TYPE_SIZE BITS_PER_WORD
  81. #endif
  82.  
  83. #ifndef LONG_LONG_TYPE_SIZE
  84. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  85. #endif
  86.  
  87. #ifndef WCHAR_UNSIGNED
  88. #define WCHAR_UNSIGNED 0
  89. #endif
  90.  
  91. #ifndef FLOAT_TYPE_SIZE
  92. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  93. #endif
  94.  
  95. #ifndef DOUBLE_TYPE_SIZE
  96. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  97. #endif
  98.  
  99. #ifndef LONG_DOUBLE_TYPE_SIZE
  100. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  101. #endif
  102.  
  103. #ifndef BOOL_TYPE_SIZE
  104. #ifdef SLOW_BYTE_ACCESS
  105. #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (BITS_PER_WORD) : (BITS_PER_UNIT))
  106. #else
  107. #define BOOL_TYPE_SIZE BITS_PER_UNIT
  108. #endif
  109. #endif
  110.  
  111. /* We let tm.h override the types used here, to handle trivial differences
  112.    such as the choice of unsigned int or long unsigned int for size_t.
  113.    When machines start needing nontrivial differences in the size type,
  114.    it would be best to do something here to figure out automatically
  115.    from other information what type to use.  */
  116.  
  117. #ifndef SIZE_TYPE
  118. #define SIZE_TYPE "long unsigned int"
  119. #endif
  120.  
  121. #ifndef PTRDIFF_TYPE
  122. #define PTRDIFF_TYPE "long int"
  123. #endif
  124.  
  125. #ifndef WCHAR_TYPE
  126. #define WCHAR_TYPE "int"
  127. #endif
  128.  
  129. #ifndef OBJCPLUS
  130. static
  131. #endif
  132. tree grokparms                    PROTO((tree, int));
  133. static tree lookup_nested_type            PROTO((tree, tree));
  134. static char *redeclaration_error_message    PROTO((tree, tree));
  135. static void grok_op_properties            PROTO((tree, int, int));
  136.  
  137. tree define_function        
  138.     PROTO((char *, tree, enum built_in_function, void (*)(), char *));
  139.  
  140. /* a node which has tree code ERROR_MARK, and whose type is itself.
  141.    All erroneous expressions are replaced with this node.  All functions
  142.    that accept nodes as arguments should avoid generating error messages
  143.    if this node is one of the arguments, since it is undesirable to get
  144.    multiple error messages from one error in the input.  */
  145.  
  146. tree error_mark_node;
  147.  
  148. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  149. tree error_mark_list;
  150.  
  151. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  152.  
  153. tree short_integer_type_node;
  154. tree integer_type_node;
  155. tree long_integer_type_node;
  156. tree long_long_integer_type_node;
  157.  
  158. tree short_unsigned_type_node;
  159. tree unsigned_type_node;
  160. tree long_unsigned_type_node;
  161. tree long_long_unsigned_type_node;
  162.  
  163. tree ptrdiff_type_node;
  164.  
  165. tree unsigned_char_type_node;
  166. tree signed_char_type_node;
  167. tree char_type_node;
  168. tree wchar_type_node;
  169. tree signed_wchar_type_node;
  170. tree unsigned_wchar_type_node;
  171.  
  172. tree wchar_decl_node;
  173.  
  174. tree float_type_node;
  175. tree double_type_node;
  176. tree long_double_type_node;
  177.  
  178. tree intQI_type_node;
  179. tree intHI_type_node;
  180. tree intSI_type_node;
  181. tree intDI_type_node;
  182.  
  183. tree unsigned_intQI_type_node;
  184. tree unsigned_intHI_type_node;
  185. tree unsigned_intSI_type_node;
  186. tree unsigned_intDI_type_node;
  187.  
  188. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  189.  
  190. tree void_type_node, void_list_node;
  191. tree void_zero_node;
  192.  
  193. /* Nodes for types `void *' and `const void *'.  */
  194.  
  195. tree ptr_type_node, const_ptr_type_node;
  196.  
  197. /* Nodes for types `char *' and `const char *'.  */
  198.  
  199. tree string_type_node, const_string_type_node;
  200.  
  201. /* Type `char[256]' or something like it.
  202.    Used when an array of char is needed and the size is irrelevant.  */
  203.  
  204. tree char_array_type_node;
  205.  
  206. /* Type `int[256]' or something like it.
  207.    Used when an array of int needed and the size is irrelevant.  */
  208.  
  209. tree int_array_type_node;
  210.  
  211. /* Type `wchar_t[256]' or something like it.
  212.    Used when a wide string literal is created.  */
  213.  
  214. tree wchar_array_type_node;
  215.  
  216. /* The bool data type, and constants */
  217. tree boolean_type_node, boolean_true_node, boolean_false_node;
  218.  
  219. /* type `int ()' -- used for implicit declaration of functions.  */
  220.  
  221. tree default_function_type;
  222.  
  223. /* function types `double (double)' and `double (double, double)', etc.  */
  224.  
  225. tree double_ftype_double, double_ftype_double_double;
  226. tree int_ftype_int, long_ftype_long;
  227.  
  228. /* Function type `void (void *, void *, int)' and similar ones.  */
  229.  
  230. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  231.  
  232. /* Function type `char *(char *, char *)' and similar ones */
  233. tree string_ftype_ptr_ptr, int_ftype_string_string;
  234.  
  235. /* Function type `size_t (const char *)' */
  236. tree sizet_ftype_string;
  237.  
  238. /* Function type `int (const void *, const void *, size_t)' */
  239. tree int_ftype_cptr_cptr_sizet;
  240.  
  241. /* C++ extensions */
  242. tree vtable_entry_type;
  243. tree delta_type_node;
  244. #if 0
  245. /* Old rtti stuff. */
  246. tree __baselist_desc_type_node;
  247. tree __i_desc_type_node, __m_desc_type_node;
  248. tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
  249. #endif
  250. tree __t_desc_type_node, __tp_desc_type_node;
  251. tree __access_mode_type_node;
  252. tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
  253. tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
  254. tree __ptmf_desc_type_node, __ptmd_desc_type_node;
  255. #if 0
  256. /* Not needed yet?  May be needed one day?  */
  257. tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
  258. tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
  259. tree __ptmf_desc_array_type, __ptmd_desc_array_type;
  260. #endif
  261.  
  262. tree class_star_type_node;
  263. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  264. tree unknown_type_node;
  265. tree opaque_type_node, signature_type_node;
  266. tree sigtable_entry_type;
  267. tree maybe_gc_cleanup;
  268.  
  269. /* Array type `vtable_entry_type[]' */
  270. tree vtbl_type_node;
  271.  
  272. /* In a destructor, the point at which all derived class destroying
  273.    has been done, just before any base class destroying will be done.  */
  274.  
  275. tree dtor_label;
  276.  
  277. /* In a constructor, the point at which we are ready to return
  278.    the pointer to the initialized object.  */
  279.  
  280. tree ctor_label;
  281.  
  282. /* A FUNCTION_DECL which can call `abort'.  Not necessarily the
  283.    one that the user will declare, but sufficient to be called
  284.    by routines that want to abort the program.  */
  285.  
  286. tree abort_fndecl;
  287.  
  288. extern rtx cleanup_label, return_label;
  289.  
  290. /* If original DECL_RESULT of current function was a register,
  291.    but due to being an addressable named return value, would up
  292.    on the stack, this variable holds the named return value's
  293.    original location.  */
  294. rtx original_result_rtx;
  295.  
  296. /* Sequence of insns which represents base initialization.  */
  297. tree base_init_expr;
  298.  
  299. /* C++: Keep these around to reduce calls to `get_identifier'.
  300.    Identifiers for `this' in member functions and the auto-delete
  301.    parameter for destructors.  */
  302. tree this_identifier, in_charge_identifier;
  303. /* Used in pointer to member functions, in vtables, and in sigtables. */
  304. tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
  305. tree pfn_or_delta2_identifier, tag_identifier;
  306. tree vb_off_identifier, vt_off_identifier;
  307.  
  308. /* A list (chain of TREE_LIST nodes) of named label uses.
  309.    The TREE_PURPOSE field is the list of variables defined
  310.    the the label's scope defined at the point of use.
  311.    The TREE_VALUE field is the LABEL_DECL used.
  312.    The TREE_TYPE field holds `current_binding_level' at the
  313.    point of the label's use.
  314.  
  315.    Used only for jumps to as-yet undefined labels, since
  316.    jumps to defined labels can have their validity checked
  317.    by stmt.c.  */
  318.  
  319. static tree named_label_uses;
  320.  
  321. /* A list of objects which have constructors or destructors
  322.    which reside in the global scope.  The decl is stored in
  323.    the TREE_VALUE slot and the initializer is stored
  324.    in the TREE_PURPOSE slot.  */
  325. tree static_aggregates;
  326.  
  327. /* -- end of C++ */
  328.  
  329. /* Two expressions that are constants with value zero.
  330.    The first is of type `int', the second of type `void *'.  */
  331.  
  332. tree integer_zero_node;
  333. tree null_pointer_node;
  334.  
  335. /* A node for the integer constants 1, 2, and 3.  */
  336.  
  337. tree integer_one_node, integer_two_node, integer_three_node;
  338.  
  339. /* Nonzero if we have seen an invalid cross reference
  340.    to a struct, union, or enum, but not yet printed the message.  */
  341.  
  342. tree pending_invalid_xref;
  343. /* File and line to appear in the eventual error message.  */
  344. char *pending_invalid_xref_file;
  345. int pending_invalid_xref_line;
  346.  
  347. /* While defining an enum type, this is 1 plus the last enumerator
  348.    constant value.  */
  349.  
  350. static tree enum_next_value;
  351.  
  352. /* Nonzero means that there was overflow computing enum_next_value.  */
  353.  
  354. static int enum_overflow;
  355.  
  356. /* Parsing a function declarator leaves a list of parameter names
  357.    or a chain or parameter decls here.  */
  358.  
  359. tree last_function_parms;
  360.  
  361. /* Parsing a function declarator leaves here a chain of structure
  362.    and enum types declared in the parmlist.  */
  363.  
  364. static tree last_function_parm_tags;
  365.  
  366. /* After parsing the declarator that starts a function definition,
  367.    `start_function' puts here the list of parameter names or chain of decls.
  368.    `store_parm_decls' finds it here.  */
  369.  
  370. static tree current_function_parms;
  371.  
  372. /* Similar, for last_function_parm_tags.  */
  373. static tree current_function_parm_tags;
  374.  
  375. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  376.    that have names.  Here so we can clear out their names' definitions
  377.    at the end of the function.  */
  378.  
  379. static tree named_labels;
  380.  
  381. /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
  382.  
  383. static tree shadowed_labels;
  384.  
  385. #if 0 /* Not needed by C++ */
  386. /* Nonzero when store_parm_decls is called indicates a varargs function.
  387.    Value not meaningful after store_parm_decls.  */
  388.  
  389. static int c_function_varargs;
  390. #endif
  391.  
  392. /* The FUNCTION_DECL for the function currently being compiled,
  393.    or 0 if between functions.  */
  394. tree current_function_decl;
  395.  
  396. /* Set to 0 at beginning of a function definition, set to 1 if
  397.    a return statement that specifies a return value is seen.  */
  398.  
  399. int current_function_returns_value;
  400.  
  401. /* Set to 0 at beginning of a function definition, set to 1 if
  402.    a return statement with no argument is seen.  */
  403.  
  404. int current_function_returns_null;
  405.  
  406. /* Set to 0 at beginning of a function definition, and whenever
  407.    a label (case or named) is defined.  Set to value of expression
  408.    returned from function when that value can be transformed into
  409.    a named return value.  */
  410.  
  411. tree current_function_return_value;
  412.  
  413. /* Set to nonzero by `grokdeclarator' for a function
  414.    whose return type is defaulted, if warnings for this are desired.  */
  415.  
  416. static int warn_about_return_type;
  417.  
  418. /* Nonzero means give `double' the same size as `float'.  */
  419.  
  420. extern int flag_short_double;
  421.  
  422. /* Nonzero means don't recognize any builtin functions.  */
  423.  
  424. extern int flag_no_builtin;
  425.  
  426. /* Nonzero means don't recognize the non-ANSI builtin functions.
  427.    -ansi sets this.  */
  428.  
  429. extern int flag_no_nonansi_builtin;
  430.  
  431. /* Nonzero means enable obscure ANSI features and disable GNU extensions
  432.    that might cause ANSI-compliant code to be miscompiled.  */
  433.  
  434. extern int flag_ansi;
  435.  
  436. /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
  437.    objects. */
  438. extern int flag_huge_objects;
  439.  
  440. /* Nonzero if we want to conserve space in the .o files.  We do this
  441.    by putting uninitialized data and runtime initialized data into
  442.    .common instead of .data at the expense of not flagging multiple
  443.    definitions.  */
  444. extern int flag_conserve_space;
  445.  
  446. /* Pointers to the base and current top of the language name stack.  */
  447.  
  448. extern tree *current_lang_base, *current_lang_stack;
  449.  
  450. /* C and C++ flags are in decl2.c.  */
  451.  
  452. /* Set to 0 at beginning of a constructor, set to 1
  453.    if that function does an allocation before referencing its
  454.    instance variable.  */
  455. int current_function_assigns_this;
  456. int current_function_just_assigned_this;
  457.  
  458. /* Set to 0 at beginning of a function.  Set non-zero when
  459.    store_parm_decls is called.  Don't call store_parm_decls
  460.    if this flag is non-zero!  */
  461. int current_function_parms_stored;
  462.  
  463. /* Current end of entries in the gc obstack for stack pointer variables.  */
  464.  
  465. int current_function_obstack_index;
  466.  
  467. /* Flag saying whether we have used the obstack in this function or not.  */
  468.  
  469. int current_function_obstack_usage;
  470.  
  471. /* Flag used when debugging spew.c */
  472.  
  473. extern int spew_debug;
  474.  
  475. /* This is a copy of the class_shadowed list of the previous class binding
  476.    contour when at global scope.  It's used to reset IDENTIFIER_CLASS_VALUEs
  477.    when entering another class scope (i.e. a cache miss).  */
  478. extern tree previous_class_values;
  479.  
  480.  
  481. /* Allocate a level of searching.  */
  482. struct stack_level *
  483. push_decl_level (stack, obstack)
  484.      struct stack_level *stack;
  485.      struct obstack *obstack;
  486. {
  487.   struct stack_level tem;
  488.   tem.prev = stack;
  489.  
  490.   return push_stack_level (obstack, (char *)&tem, sizeof (tem));
  491. }
  492.  
  493. /* For each binding contour we allocate a binding_level structure
  494.  * which records the names defined in that contour.
  495.  * Contours include:
  496.  *  0) the global one
  497.  *  1) one for each function definition,
  498.  *     where internal declarations of the parameters appear.
  499.  *  2) one for each compound statement,
  500.  *     to record its declarations.
  501.  *
  502.  * The current meaning of a name can be found by searching the levels from
  503.  * the current one out to the global one.
  504.  *
  505.  * Off to the side, may be the class_binding_level.  This exists
  506.  * only to catch class-local declarations.  It is otherwise
  507.  * nonexistent.
  508.  * 
  509.  * Also there may be binding levels that catch cleanups that
  510.  * must be run when exceptions occur.
  511.  */
  512.  
  513. /* Note that the information in the `names' component of the global contour
  514.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  515.  
  516. struct binding_level
  517.   {
  518.     /* A chain of _DECL nodes for all variables, constants, functions,
  519.      * and typedef types.  These are in the reverse of the order supplied.
  520.      */
  521.     tree names;
  522.  
  523.     /* A list of structure, union and enum definitions,
  524.      * for looking up tag names.
  525.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  526.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  527.      * or ENUMERAL_TYPE node.
  528.      *
  529.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  530.      *
  531.      */
  532.     tree tags;
  533.  
  534.     /* For each level, a list of shadowed outer-level local definitions
  535.        to be restored when this level is popped.
  536.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  537.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  538.     tree shadowed;
  539.  
  540.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  541.     tree class_shadowed;
  542.  
  543.     /* Same, for IDENTIFIER_TYPE_VALUE.  */
  544.     tree type_shadowed;
  545.  
  546.     /* For each level (except not the global one),
  547.        a chain of BLOCK nodes for all the levels
  548.        that were entered and exited one level down.  */
  549.     tree blocks;
  550.  
  551.     /* The BLOCK node for this level, if one has been preallocated.
  552.        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
  553.     tree this_block;
  554.  
  555.     /* The binding level which this one is contained in (inherits from).  */
  556.     struct binding_level *level_chain;
  557.  
  558.     /* List of decls in `names' that have incomplete
  559.        structure or union types.  */
  560.     tree incomplete;
  561.  
  562.     /* List of VAR_DECLS saved from a previous for statement.
  563.        These would be dead in ANSI-conforming code, but might
  564.        be referenced in traditional code. */
  565.     tree dead_vars_from_for;
  566.  
  567.     /* 1 for the level that holds the parameters of a function.
  568.        2 for the level that holds a class declaration.
  569.        3 for levels that hold parameter declarations.  */
  570.     unsigned parm_flag : 4;
  571.  
  572.     /* 1 means make a BLOCK for this level regardless of all else.
  573.        2 for temporary binding contours created by the compiler.  */
  574.     unsigned keep : 3;
  575.  
  576.     /* Nonzero if this level "doesn't exist" for tags.  */
  577.     unsigned tag_transparent : 1;
  578.  
  579.     /* Nonzero if this level can safely have additional
  580.        cleanup-needing variables added to it.  */
  581.     unsigned more_cleanups_ok : 1;
  582.     unsigned have_cleanups : 1;
  583.  
  584.     /* Nonzero if we should accept any name as an identifier in
  585.        this scope.  This happens in some template definitions.  */
  586.     unsigned accept_any : 1;
  587.  
  588.     /* Nonzero if this level is for completing a template class definition
  589.        inside a binding level that temporarily binds the parameters.  This
  590.        means that definitions here should not be popped off when unwinding
  591.        this binding level.  (Not actually implemented this way,
  592.        unfortunately.)  */
  593.     unsigned pseudo_global : 1;
  594.  
  595.     /* This is set for a namespace binding level.  */
  596.     unsigned namespace_p : 1;
  597.  
  598.     /* True if this level is that of a for-statement. */
  599.     unsigned is_for_scope : 1;
  600.  
  601.     /* One bit left for this word.  */
  602.  
  603. #if defined(DEBUG_CP_BINDING_LEVELS)
  604.     /* Binding depth at which this level began.  */
  605.     unsigned binding_depth;
  606. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  607.   };
  608.  
  609. #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
  610.   
  611. /* The (non-class) binding level currently in effect.  */
  612.  
  613. static struct binding_level *current_binding_level;
  614.  
  615. /* The binding level of the current class, if any.  */
  616.  
  617. static struct binding_level *class_binding_level;
  618.  
  619. /* The current (class or non-class) binding level currently in effect.  */
  620.  
  621. #define inner_binding_level \
  622.   (class_binding_level ? class_binding_level : current_binding_level)
  623.  
  624. /* A chain of binding_level structures awaiting reuse.  */
  625.  
  626. static struct binding_level *free_binding_level;
  627.  
  628. /* The outermost binding level, for names of file scope.
  629.    This is created when the compiler is started and exists
  630.    through the entire run.  */
  631.  
  632. static struct binding_level *global_binding_level;
  633.  
  634. /* Binding level structures are initialized by copying this one.  */
  635.  
  636. static struct binding_level clear_binding_level;
  637.  
  638. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  639.  
  640. static int keep_next_level_flag;
  641.  
  642. #if defined(DEBUG_CP_BINDING_LEVELS)
  643. static int binding_depth = 0;
  644. static int is_class_level = 0;
  645.  
  646. static void
  647. indent ()
  648. {
  649.   register unsigned i;
  650.  
  651.   for (i = 0; i < binding_depth*2; i++)
  652.     putc (' ', stderr);
  653. }
  654. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  655.  
  656. static tree pushdecl_with_scope    PROTO((tree, struct binding_level *));
  657.  
  658. static void
  659. push_binding_level (newlevel, tag_transparent, keep)
  660.      struct binding_level *newlevel;
  661.      int tag_transparent, keep;
  662. {
  663.   /* Add this level to the front of the chain (stack) of levels that
  664.      are active.  */
  665.   *newlevel = clear_binding_level;
  666.   if (class_binding_level)
  667.     {
  668.       newlevel->level_chain = class_binding_level;
  669.       class_binding_level = (struct binding_level *)0;
  670.     }
  671.   else
  672.     {
  673.       newlevel->level_chain = current_binding_level;
  674.     }
  675.   current_binding_level = newlevel;
  676.   newlevel->tag_transparent = tag_transparent;
  677.   newlevel->more_cleanups_ok = 1;
  678.   newlevel->keep = keep;
  679. #if defined(DEBUG_CP_BINDING_LEVELS)
  680.   newlevel->binding_depth = binding_depth;
  681.   indent ();
  682.   fprintf (stderr, "push %s level 0x%08x line %d\n",
  683.        (is_class_level) ? "class" : "block", newlevel, lineno);
  684.   is_class_level = 0;
  685.   binding_depth++;
  686. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  687. }
  688.  
  689. static void
  690. pop_binding_level ()
  691. {
  692.   if (class_binding_level)
  693.     current_binding_level = class_binding_level;
  694.  
  695.   if (global_binding_level)
  696.     {
  697.       /* cannot pop a level, if there are none left to pop. */
  698.       if (current_binding_level == global_binding_level)
  699.     my_friendly_abort (123);
  700.     }
  701.   /* Pop the current level, and free the structure for reuse.  */
  702. #if defined(DEBUG_CP_BINDING_LEVELS)
  703.   binding_depth--;
  704.   indent ();
  705.   fprintf (stderr, "pop  %s level 0x%08x line %d\n",
  706.       (is_class_level) ? "class" : "block",
  707.       current_binding_level, lineno);
  708.   if (is_class_level != (current_binding_level == class_binding_level))
  709. #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
  710.     abort ();
  711. #else
  712.   {
  713.     indent ();
  714.     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
  715.   }
  716. #endif
  717.   is_class_level = 0;
  718. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  719.   {
  720.     register struct binding_level *level = current_binding_level;
  721.     current_binding_level = current_binding_level->level_chain;
  722.     level->level_chain = free_binding_level;
  723. #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
  724.     if (level->binding_depth != binding_depth)
  725.       abort ();
  726. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  727.       free_binding_level = level;
  728.  
  729.     class_binding_level = current_binding_level;
  730.     if (class_binding_level->parm_flag != 2)
  731.       class_binding_level = 0;
  732.     while (current_binding_level->parm_flag == 2)
  733.       current_binding_level = current_binding_level->level_chain;
  734.   }
  735. }
  736.  
  737. static void
  738. suspend_binding_level ()
  739. {
  740.   if (class_binding_level)
  741.     current_binding_level = class_binding_level;
  742.  
  743.   if (global_binding_level)
  744.     {
  745.       /* cannot suspend a level, if there are none left to suspend. */
  746.       if (current_binding_level == global_binding_level)
  747.     my_friendly_abort (123);
  748.     }
  749.   /* Suspend the current level.  */
  750. #if defined(DEBUG_CP_BINDING_LEVELS)
  751.   binding_depth--;
  752.   indent ();
  753.   fprintf (stderr, "suspend  %s level 0x%08x line %d\n",
  754.       (is_class_level) ? "class" : "block",
  755.       current_binding_level, lineno);
  756.   if (is_class_level != (current_binding_level == class_binding_level))
  757. #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
  758.     abort ();
  759. #else
  760.   {
  761.     indent ();
  762.     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
  763.   }
  764. #endif
  765.   is_class_level = 0;
  766. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  767.   {
  768.     register struct binding_level *level = current_binding_level;
  769.     current_binding_level = current_binding_level->level_chain;
  770. #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
  771.     if (level->binding_depth != binding_depth)
  772.       abort ();
  773. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  774.  
  775.     class_binding_level = current_binding_level;
  776.     if (class_binding_level->parm_flag != 2)
  777.       class_binding_level = 0;
  778.     while (current_binding_level->parm_flag == 2)
  779.       current_binding_level = current_binding_level->level_chain;
  780.   }
  781. }
  782.  
  783. void
  784. resume_binding_level (b)
  785.      struct binding_level *b;
  786. {
  787.   if (class_binding_level)
  788.     {
  789. #if 1
  790.       /* These are here because we cannot deal with shadows yet. */
  791.       sorry ("cannot resume a namespace inside class");
  792.       return;
  793. #else
  794.       b->level_chain = class_binding_level;
  795.       class_binding_level = (struct binding_level *)0;
  796. #endif
  797.     }
  798.   else
  799.     {
  800. #if 1
  801.       /* These are here because we cannot deal with shadows yet. */
  802.       if (b->level_chain != current_binding_level)
  803.     {
  804.       sorry ("cannot resume a namespace inside a different namespace");
  805.       return;
  806.     }
  807. #endif
  808.       b->level_chain = current_binding_level;
  809.     }
  810.   current_binding_level = b;
  811. #if defined(DEBUG_CP_BINDING_LEVELS)
  812.   b->binding_depth = binding_depth;
  813.   indent ();
  814.   fprintf (stderr, "resume %s level 0x%08x line %d\n",
  815.        (is_class_level) ? "class" : "block", b, lineno);
  816.   is_class_level = 0;
  817.   binding_depth++;
  818. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  819. }
  820.  
  821. /* Nonzero if we are currently in the global binding level.  */
  822.  
  823. int
  824. global_bindings_p ()
  825. {
  826.   return current_binding_level == global_binding_level;
  827. }
  828.  
  829. /* Nonzero if we are currently in a toplevel binding level.  This
  830.    means either the global binding level or a namespace in a toplevel
  831.    binding level.  */
  832.  
  833. int
  834. toplevel_bindings_p ()
  835. {
  836.   struct binding_level *b = current_binding_level;
  837.  
  838.   while (1)
  839.     {
  840.       if (b == global_binding_level)
  841.     return 1;
  842.       if (! b->namespace_p)
  843.     return 0;
  844.       b=b->level_chain;
  845.     }
  846. }
  847.  
  848. /* Nonzero if this is a namespace scope.  */
  849.  
  850. int
  851. namespace_bindings_p ()
  852. {
  853.   return current_binding_level->namespace_p;
  854. }
  855.  
  856. void
  857. keep_next_level ()
  858. {
  859.   keep_next_level_flag = 1;
  860. }
  861.  
  862. /* Nonzero if the current level needs to have a BLOCK made.  */
  863.  
  864. int
  865. kept_level_p ()
  866. {
  867.   return (current_binding_level->blocks != NULL_TREE
  868.       || current_binding_level->keep
  869.       || current_binding_level->names != NULL_TREE
  870.       || (current_binding_level->tags != NULL_TREE
  871.           && !current_binding_level->tag_transparent));
  872. }
  873.  
  874. /* Identify this binding level as a level of parameters.  */
  875.  
  876. void
  877. declare_parm_level ()
  878. {
  879.   current_binding_level->parm_flag = 1;
  880. }
  881.  
  882. void
  883. declare_uninstantiated_type_level ()
  884. {
  885.   current_binding_level->accept_any = 1;
  886. }
  887.  
  888. int
  889. uninstantiated_type_level_p ()
  890. {
  891.   return current_binding_level->accept_any;
  892. }
  893.  
  894. void
  895. declare_pseudo_global_level ()
  896. {
  897.   current_binding_level->pseudo_global = 1;
  898. }
  899.  
  900. void
  901. declare_namespace_level ()
  902. {
  903.   current_binding_level->namespace_p = 1;
  904. }
  905.  
  906. int
  907. pseudo_global_level_p ()
  908. {
  909.   return current_binding_level->pseudo_global;
  910. }
  911.  
  912. void
  913. set_class_shadows (shadows)
  914.      tree shadows;
  915. {
  916.   class_binding_level->class_shadowed = shadows;
  917. }
  918.  
  919. /* Enter a new binding level.
  920.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  921.    not for that of tags.  */
  922.  
  923. void
  924. pushlevel (tag_transparent)
  925.      int tag_transparent;
  926. {
  927.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  928.  
  929.   /* If this is the top level of a function,
  930.      just make sure that NAMED_LABELS is 0.
  931.      They should have been set to 0 at the end of the previous function.  */
  932.  
  933.   if (current_binding_level == global_binding_level)
  934.     my_friendly_assert (named_labels == NULL_TREE, 134);
  935.  
  936.   /* Reuse or create a struct for this binding level.  */
  937.  
  938. #if defined(DEBUG_CP_BINDING_LEVELS)
  939.   if (0)
  940. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  941.   if (free_binding_level)
  942. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  943.     {
  944.       newlevel = free_binding_level;
  945.       free_binding_level = free_binding_level->level_chain;
  946.     }
  947.   else
  948.     {
  949.       /* Create a new `struct binding_level'.  */
  950.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  951.     }
  952.   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
  953.   GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
  954.   keep_next_level_flag = 0;
  955. }
  956.  
  957. int
  958. note_level_for_for ()
  959. {
  960.   current_binding_level->is_for_scope = 1;
  961. }
  962.  
  963. void
  964. pushlevel_temporary (tag_transparent)
  965.      int tag_transparent;
  966. {
  967.   pushlevel (tag_transparent);
  968.   current_binding_level->keep = 2;
  969.   clear_last_expr ();
  970.  
  971.   /* Note we don't call push_momentary() here.  Otherwise, it would cause
  972.      cleanups to be allocated on the momentary obstack, and they will be
  973.      overwritten by the next statement.  */
  974.  
  975.   expand_start_bindings (0);
  976. }
  977.  
  978. /* Exit a binding level.
  979.    Pop the level off, and restore the state of the identifier-decl mappings
  980.    that were in effect when this level was entered.
  981.  
  982.    If KEEP == 1, this level had explicit declarations, so
  983.    and create a "block" (a BLOCK node) for the level
  984.    to record its declarations and subblocks for symbol table output.
  985.  
  986.    If KEEP == 2, this level's subblocks go to the front,
  987.    not the back of the current binding level.  This happens,
  988.    for instance, when code for constructors and destructors
  989.    need to generate code at the end of a function which must
  990.    be moved up to the front of the function.
  991.  
  992.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  993.    so create a block as if KEEP were set and also clear out all
  994.    label names.
  995.  
  996.    If REVERSE is nonzero, reverse the order of decls before putting
  997.    them into the BLOCK.  */
  998.  
  999. tree
  1000. poplevel (keep, reverse, functionbody)
  1001.      int keep;
  1002.      int reverse;
  1003.      int functionbody;
  1004. {
  1005.   register tree link;
  1006.   /* The chain of decls was accumulated in reverse order.
  1007.      Put it into forward order, just for cleanliness.  */
  1008.   tree decls;
  1009.   int tmp = functionbody;
  1010.   int implicit_try_block = current_binding_level->parm_flag == 3;
  1011.   int real_functionbody = current_binding_level->keep == 2
  1012.     ? ((functionbody = 0), tmp) : functionbody;
  1013.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  1014.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  1015.   tree block = NULL_TREE;
  1016.   tree decl;
  1017.   int block_previously_created;
  1018.  
  1019.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  1020.               (HOST_WIDE_INT) current_binding_level->level_chain,
  1021.               current_binding_level->parm_flag,
  1022.               current_binding_level->keep,
  1023.               current_binding_level->tag_transparent);
  1024.  
  1025.   if (current_binding_level->keep == 1)
  1026.     keep = 1;
  1027.  
  1028.   /* This warning is turned off because it causes warnings for
  1029.      declarations like `extern struct foo *x'.  */
  1030. #if 0
  1031.   /* Warn about incomplete structure types in this level.  */
  1032.   for (link = tags; link; link = TREE_CHAIN (link))
  1033.     if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
  1034.       {
  1035.     tree type = TREE_VALUE (link);
  1036.     char *errmsg;
  1037.     switch (TREE_CODE (type))
  1038.       {
  1039.       case RECORD_TYPE:
  1040.         errmsg = "`struct %s' incomplete in scope ending here";
  1041.         break;
  1042.       case UNION_TYPE:
  1043.         errmsg = "`union %s' incomplete in scope ending here";
  1044.         break;
  1045.       case ENUMERAL_TYPE:
  1046.         errmsg = "`enum %s' incomplete in scope ending here";
  1047.         break;
  1048.       }
  1049.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  1050.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  1051.     else
  1052.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  1053.       error (errmsg, TYPE_NAME_STRING (type));
  1054.       }
  1055. #endif /* 0 */
  1056.  
  1057.   /* Get the decls in the order they were written.
  1058.      Usually current_binding_level->names is in reverse order.
  1059.      But parameter decls were previously put in forward order.  */
  1060.  
  1061.   if (reverse)
  1062.     current_binding_level->names
  1063.       = decls = nreverse (current_binding_level->names);
  1064.   else
  1065.     decls = current_binding_level->names;
  1066.  
  1067.   /* Output any nested inline functions within this block
  1068.      if they weren't already output.  */
  1069.  
  1070.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  1071.     if (TREE_CODE (decl) == FUNCTION_DECL
  1072.     && ! TREE_ASM_WRITTEN (decl)
  1073.     && DECL_INITIAL (decl) != NULL_TREE
  1074.     && TREE_ADDRESSABLE (decl)
  1075.     && decl_function_context (decl) == current_function_decl)
  1076.       {
  1077.     /* If this decl was copied from a file-scope decl
  1078.        on account of a block-scope extern decl,
  1079.        propagate TREE_ADDRESSABLE to the file-scope decl.  */
  1080.     if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
  1081.       TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
  1082.     else
  1083.       {
  1084.         push_function_context ();
  1085.         output_inline_function (decl);
  1086.         pop_function_context ();
  1087.       }
  1088.       }
  1089.  
  1090.   /* If there were any declarations or structure tags in that level,
  1091.      or if this level is a function body,
  1092.      create a BLOCK to record them for the life of this function.  */
  1093.  
  1094.   block = NULL_TREE;
  1095.   block_previously_created = (current_binding_level->this_block != NULL_TREE);
  1096.   if (block_previously_created)
  1097.     block = current_binding_level->this_block;
  1098.   else if (keep == 1 || functionbody)
  1099.     block = make_node (BLOCK);
  1100.   if (block != NULL_TREE)
  1101.     {
  1102.       BLOCK_VARS (block) = decls;
  1103.       BLOCK_TYPE_TAGS (block) = tags;
  1104.       BLOCK_SUBBLOCKS (block) = subblocks;
  1105.       /* If we created the block earlier on, and we are just diddling it now,
  1106.      then it already should have a proper BLOCK_END_NOTE value associated
  1107.      with it, so avoid trashing that.  Otherwise, for a new block, install
  1108.      a new BLOCK_END_NOTE value.  */
  1109.       if (! block_previously_created)
  1110.     remember_end_note (block);
  1111.     }
  1112.  
  1113.   /* In each subblock, record that this is its superior.  */
  1114.  
  1115.   if (keep >= 0)
  1116.     for (link = subblocks; link; link = TREE_CHAIN (link))
  1117.       BLOCK_SUPERCONTEXT (link) = block;
  1118.  
  1119.   /* Clear out the meanings of the local variables of this level.  */
  1120.  
  1121.   for (link = current_binding_level->dead_vars_from_for;
  1122.        link != NULL_TREE; link = TREE_CHAIN (link))
  1123.     {
  1124.       if (DECL_DEAD_FOR_LOCAL (link))
  1125.     {
  1126.       tree id = DECL_NAME (link);
  1127.       if (IDENTIFIER_LOCAL_VALUE (id) == link)
  1128.         IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link);
  1129.     }
  1130.     }
  1131.  
  1132.   if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
  1133.     {
  1134.       for (link = decls; link; link = TREE_CHAIN (link))
  1135.     {
  1136.       if (TREE_CODE (link) == VAR_DECL)
  1137.         DECL_DEAD_FOR_LOCAL (link) = 1;
  1138.     }
  1139.     }
  1140.   else
  1141.     {
  1142.       for (link = decls; link; link = TREE_CHAIN (link))
  1143.     {
  1144.       if (DECL_NAME (link) != NULL_TREE)
  1145.         {
  1146.           /* If the ident. was used or addressed via a local extern decl,
  1147.          don't forget that fact.  */
  1148.           if (DECL_EXTERNAL (link))
  1149.         {
  1150.           if (TREE_USED (link))
  1151.             TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  1152.           if (TREE_ADDRESSABLE (link))
  1153.             TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  1154.         }
  1155.           IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
  1156.         }
  1157.     }
  1158.     }
  1159.  
  1160.   /* Restore all name-meanings of the outer levels
  1161.      that were shadowed by this level.  */
  1162.  
  1163.   if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
  1164.     {
  1165.       struct binding_level *outer = current_binding_level->level_chain;
  1166.       for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1167.     {
  1168.       tree id = TREE_PURPOSE (link);
  1169.       tree decl = IDENTIFIER_LOCAL_VALUE (id);
  1170.       if (DECL_DEAD_FOR_LOCAL (decl))
  1171.         DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link);
  1172.       else
  1173.         IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link);
  1174.     }
  1175.  
  1176.       /* Save declarations made in a 'for' statement so we can support pre-ANSI
  1177.      'for' scoping semantics. */
  1178.  
  1179.       /* We append the current names of for-variables to those from previous
  1180.      declarations, so that when we get around to do an poplevel
  1181.      on the OUTER level, we restore the any shadowed readl bindings.
  1182.      Note that the new names are put first on the combined list,
  1183.      so they get to be restored first.  This is important if there are
  1184.      two for-loops using the same for-variable in the same block.
  1185.      The binding we really want restored is whatever binding was shadowed
  1186.      by the *first* for-variable, not the binding shadowed by the
  1187.      second for-variable (which would be the first for-variable). */
  1188.       outer->dead_vars_from_for
  1189.     = chainon (current_binding_level->names, outer->dead_vars_from_for);
  1190.     }
  1191.   else
  1192.     {
  1193.       for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1194.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1195.     }
  1196.   for (link = current_binding_level->class_shadowed;
  1197.        link; link = TREE_CHAIN (link))
  1198.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1199.   for (link = current_binding_level->type_shadowed;
  1200.        link; link = TREE_CHAIN (link))
  1201.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1202.  
  1203.   /* If the level being exited is the top level of a function,
  1204.      check over all the labels.  */
  1205.  
  1206.   if (functionbody)
  1207.     {
  1208.       /* If this is the top level block of a function,
  1209.          the vars are the function's parameters.
  1210.          Don't leave them in the BLOCK because they are
  1211.          found in the FUNCTION_DECL instead.  */
  1212.  
  1213.       BLOCK_VARS (block) = 0;
  1214.  
  1215.       /* Clear out the definitions of all label names,
  1216.      since their scopes end here.  */
  1217.  
  1218.       for (link = named_labels; link; link = TREE_CHAIN (link))
  1219.     {
  1220.       register tree label = TREE_VALUE (link);
  1221.  
  1222.       if (DECL_INITIAL (label) == NULL_TREE)
  1223.         {
  1224.           cp_error_at ("label `%D' used but not defined", label);
  1225.           /* Avoid crashing later.  */
  1226.           define_label (input_filename, 1, DECL_NAME (label));
  1227.         }
  1228.       else if (warn_unused && !TREE_USED (label))
  1229.         cp_warning_at ("label `%D' defined but not used", label);
  1230.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
  1231.  
  1232.           /* Put the labels into the "variables" of the
  1233.              top-level block, so debugger can see them.  */
  1234.           TREE_CHAIN (label) = BLOCK_VARS (block);
  1235.           BLOCK_VARS (block) = label;
  1236.     }
  1237.  
  1238.       named_labels = NULL_TREE;
  1239.     }
  1240.  
  1241.   /* Any uses of undefined labels now operate under constraints
  1242.      of next binding contour.  */
  1243.   {
  1244.     struct binding_level *level_chain;
  1245.     level_chain = current_binding_level->level_chain;
  1246.     if (level_chain)
  1247.       {
  1248.     tree labels;
  1249.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  1250.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  1251.         {
  1252.           TREE_TYPE (labels) = (tree)level_chain;
  1253.           TREE_PURPOSE (labels) = level_chain->names;
  1254.         }
  1255.       }
  1256.   }
  1257.  
  1258.   tmp = current_binding_level->keep;
  1259.  
  1260.   pop_binding_level ();
  1261.   if (functionbody)
  1262.     DECL_INITIAL (current_function_decl) = block;
  1263.   else if (block)
  1264.     {
  1265.       if (!block_previously_created)
  1266.         current_binding_level->blocks
  1267.           = chainon (current_binding_level->blocks, block);
  1268.     }
  1269.   /* If we did not make a block for the level just exited,
  1270.      any blocks made for inner levels
  1271.      (since they cannot be recorded as subblocks in that level)
  1272.      must be carried forward so they will later become subblocks
  1273.      of something else.  */
  1274.   else if (subblocks)
  1275.     {
  1276.       if (keep == 2)
  1277.     current_binding_level->blocks
  1278.       = chainon (subblocks, current_binding_level->blocks);
  1279.       else
  1280.     current_binding_level->blocks
  1281.       = chainon (current_binding_level->blocks, subblocks);
  1282.     }
  1283.  
  1284.   /* Take care of compiler's internal binding structures.  */
  1285.   if (tmp == 2)
  1286.     {
  1287. #if 0
  1288.       /* We did not call push_momentary for this
  1289.      binding contour, so there is nothing to pop.  */
  1290.       pop_momentary ();
  1291. #endif
  1292.       expand_end_bindings (getdecls (), keep, 1);
  1293.       /* Each and every BLOCK node created here in `poplevel' is important
  1294.      (e.g. for proper debugging information) so if we created one
  1295.      earlier, mark it as "used".  */
  1296.       if (block)
  1297.     TREE_USED (block) = 1;
  1298.       block = poplevel (keep, reverse, real_functionbody);
  1299.     }
  1300.  
  1301.   /* Each and every BLOCK node created here in `poplevel' is important
  1302.      (e.g. for proper debugging information) so if we created one
  1303.      earlier, mark it as "used".  */
  1304.   if (block)
  1305.     TREE_USED (block) = 1;
  1306.   return block;
  1307. }
  1308.  
  1309. /* Resume a binding level for a namespace.  */
  1310. void
  1311. resume_level (b)
  1312.      struct binding_level *b;
  1313. {
  1314.   tree decls, link;
  1315.  
  1316.   resume_binding_level (b);
  1317.  
  1318.   /* Resume the variable caches.  */
  1319.   decls = current_binding_level->names;
  1320.  
  1321.   /* Restore the meanings of the local variables of this level.  */
  1322.  
  1323.   for (link = decls; link; link = TREE_CHAIN (link))
  1324.     {
  1325.       if (DECL_NAME (link) != NULL_TREE)
  1326.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link;
  1327.  
  1328.       /* If this is a TYPE_DECL, push it into the type value slot.  */
  1329.       if (TREE_CODE (link) == TYPE_DECL)
  1330.     SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link));
  1331.     }
  1332. }
  1333.  
  1334. /* Delete the node BLOCK from the current binding level.
  1335.    This is used for the block inside a stmt expr ({...})
  1336.    so that the block can be reinserted where appropriate.  */
  1337.  
  1338. void
  1339. delete_block (block)
  1340.      tree block;
  1341. {
  1342.   tree t;
  1343.   if (current_binding_level->blocks == block)
  1344.     current_binding_level->blocks = TREE_CHAIN (block);
  1345.   for (t = current_binding_level->blocks; t;)
  1346.     {
  1347.       if (TREE_CHAIN (t) == block)
  1348.     TREE_CHAIN (t) = TREE_CHAIN (block);
  1349.       else
  1350.     t = TREE_CHAIN (t);
  1351.     }
  1352.   TREE_CHAIN (block) = NULL_TREE;
  1353.   /* Clear TREE_USED which is always set by poplevel.
  1354.      The flag is set again if insert_block is called.  */
  1355.   TREE_USED (block) = 0;
  1356. }
  1357.  
  1358. /* Insert BLOCK at the end of the list of subblocks of the
  1359.    current binding level.  This is used when a BIND_EXPR is expanded,
  1360.    to handle the BLOCK node inside the BIND_EXPR.  */
  1361.  
  1362. void
  1363. insert_block (block)
  1364.      tree block;
  1365. {
  1366.   TREE_USED (block) = 1;
  1367.   current_binding_level->blocks
  1368.     = chainon (current_binding_level->blocks, block);
  1369. }
  1370.  
  1371. /* Add BLOCK to the current list of blocks for this binding contour.  */
  1372. void
  1373. add_block_current_level (block)
  1374.      tree block;
  1375. {
  1376.   current_binding_level->blocks
  1377.     = chainon (current_binding_level->blocks, block);
  1378. }
  1379.  
  1380. /* Set the BLOCK node for the innermost scope
  1381.    (the one we are currently in).  */
  1382.  
  1383. void
  1384. set_block (block)
  1385.     register tree block;
  1386. {
  1387.   current_binding_level->this_block = block;
  1388. }
  1389.  
  1390. /* Do a pushlevel for class declarations.  */
  1391. void
  1392. pushlevel_class ()
  1393. {
  1394.   register struct binding_level *newlevel;
  1395.  
  1396.   /* Reuse or create a struct for this binding level.  */
  1397. #if defined(DEBUG_CP_BINDING_LEVELS)
  1398.   if (0)
  1399. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1400.   if (free_binding_level)
  1401. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1402.     {
  1403.       newlevel = free_binding_level;
  1404.       free_binding_level = free_binding_level->level_chain;
  1405.     }
  1406.   else
  1407.     {
  1408.       /* Create a new `struct binding_level'.  */
  1409.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  1410.     }
  1411.  
  1412. #if defined(DEBUG_CP_BINDING_LEVELS)
  1413.   is_class_level = 1;
  1414. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1415.  
  1416.   push_binding_level (newlevel, 0, 0);
  1417.  
  1418.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  1419.   class_binding_level = current_binding_level;
  1420.   class_binding_level->parm_flag = 2;
  1421.   /* We have just pushed into a new binding level.  Now, fake out the rest
  1422.      of the compiler.  Set the `current_binding_level' back to point to
  1423.      the most closely containing non-class binding level.  */
  1424.   do
  1425.     {
  1426.       current_binding_level = current_binding_level->level_chain;
  1427.     }
  1428.   while (current_binding_level->parm_flag == 2);
  1429. }
  1430.  
  1431. /* ...and a poplevel for class declarations.  FORCE is used to force
  1432.    clearing out of CLASS_VALUEs after a class definition.  */
  1433. tree
  1434. poplevel_class (force)
  1435.      int force;
  1436. {
  1437.   register struct binding_level *level = class_binding_level;
  1438.   tree block = NULL_TREE;
  1439.   tree shadowed;
  1440.  
  1441.   my_friendly_assert (level != 0, 354);
  1442.   
  1443.   decl_stack = pop_stack_level (decl_stack);
  1444.   for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1445.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1446.   /* If we're leaving a toplevel class, don't bother to do the setting
  1447.      of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
  1448.      shouldn't even be used when current_class_type isn't set, and second,
  1449.      if we don't touch it here, we're able to use the cache effect if the
  1450.      next time we're entering a class scope, it is the same class.  */
  1451.   if (current_class_depth != 1 || force)
  1452.     for (shadowed = level->class_shadowed;
  1453.      shadowed;
  1454.      shadowed = TREE_CHAIN (shadowed))
  1455.       IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1456.   else
  1457.     /* Remember to save what IDENTIFIER's were bound in this scope so we
  1458.        can recover from cache misses.  */
  1459.     previous_class_values = class_binding_level->class_shadowed;
  1460.   for (shadowed = level->type_shadowed;
  1461.        shadowed;
  1462.        shadowed = TREE_CHAIN (shadowed))
  1463.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1464.  
  1465.   GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
  1466.               (HOST_WIDE_INT) class_binding_level->level_chain,
  1467.               class_binding_level->parm_flag,
  1468.               class_binding_level->keep,
  1469.               class_binding_level->tag_transparent);
  1470.  
  1471.   if (class_binding_level->parm_flag != 2)
  1472.     class_binding_level = (struct binding_level *)0;
  1473.  
  1474.   /* Now, pop out of the the binding level which we created up in the
  1475.      `pushlevel_class' routine.  */
  1476. #if defined(DEBUG_CP_BINDING_LEVELS)
  1477.   is_class_level = 1;
  1478. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1479.  
  1480.   pop_binding_level ();
  1481.  
  1482.   return block;
  1483. }
  1484.  
  1485. /* For debugging.  */
  1486. int no_print_functions = 0;
  1487. int no_print_builtins = 0;
  1488.  
  1489. void
  1490. print_binding_level (lvl)
  1491.      struct binding_level *lvl;
  1492. {
  1493.   tree t;
  1494.   int i = 0, len;
  1495.   fprintf (stderr, " blocks=");
  1496.   fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
  1497.   fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
  1498.        list_length (lvl->incomplete), lvl->parm_flag, lvl->keep);
  1499.   if (lvl->tag_transparent)
  1500.     fprintf (stderr, " tag-transparent");
  1501.   if (lvl->more_cleanups_ok)
  1502.     fprintf (stderr, " more-cleanups-ok");
  1503.   if (lvl->have_cleanups)
  1504.     fprintf (stderr, " have-cleanups");
  1505.   fprintf (stderr, "\n");
  1506.   if (lvl->names)
  1507.     {
  1508.       fprintf (stderr, " names:\t");
  1509.       /* We can probably fit 3 names to a line?  */
  1510.       for (t = lvl->names; t; t = TREE_CHAIN (t))
  1511.     {
  1512.       if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 
  1513.         continue;
  1514.       if (no_print_builtins
  1515.           && (TREE_CODE(t) == TYPE_DECL)
  1516.           && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
  1517.         continue;
  1518.  
  1519.       /* Function decls tend to have longer names.  */
  1520.       if (TREE_CODE (t) == FUNCTION_DECL)
  1521.         len = 3;
  1522.       else
  1523.         len = 2;
  1524.       i += len;
  1525.       if (i > 6)
  1526.         {
  1527.           fprintf (stderr, "\n\t");
  1528.           i = len;
  1529.         }
  1530.       print_node_brief (stderr, "", t, 0);
  1531.       if (TREE_CODE (t) == ERROR_MARK)
  1532.         break;
  1533.     }
  1534.       if (i)
  1535.         fprintf (stderr, "\n");
  1536.     }
  1537.   if (lvl->tags)
  1538.     {
  1539.       fprintf (stderr, " tags:\t");
  1540.       i = 0;
  1541.       for (t = lvl->tags; t; t = TREE_CHAIN (t))
  1542.     {
  1543.       if (TREE_PURPOSE (t) == NULL_TREE)
  1544.         len = 3;
  1545.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1546.         len = 2;
  1547.       else
  1548.         len = 4;
  1549.       i += len;
  1550.       if (i > 5)
  1551.         {
  1552.           fprintf (stderr, "\n\t");
  1553.           i = len;
  1554.         }
  1555.       if (TREE_PURPOSE (t) == NULL_TREE)
  1556.         {
  1557.           print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
  1558.           fprintf (stderr, ">");
  1559.         }
  1560.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1561.         print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1562.       else
  1563.         {
  1564.           print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
  1565.           print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1566.           fprintf (stderr, ">");
  1567.         }
  1568.     }
  1569.       if (i)
  1570.     fprintf (stderr, "\n");
  1571.     }
  1572.   if (lvl->shadowed)
  1573.     {
  1574.       fprintf (stderr, " shadowed:");
  1575.       for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
  1576.     {
  1577.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1578.     }
  1579.       fprintf (stderr, "\n");
  1580.     }
  1581.   if (lvl->class_shadowed)
  1582.     {
  1583.       fprintf (stderr, " class-shadowed:");
  1584.       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
  1585.     {
  1586.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1587.     }
  1588.       fprintf (stderr, "\n");
  1589.     }
  1590.   if (lvl->type_shadowed)
  1591.     {
  1592.       fprintf (stderr, " type-shadowed:");
  1593.       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
  1594.         {
  1595. #if 0
  1596.           fprintf (stderr, "\n\t");
  1597.           print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
  1598.           if (TREE_VALUE (t))
  1599.             print_node_brief (stderr, " ", TREE_VALUE (t), 0);
  1600.           else
  1601.             fprintf (stderr, " (none)");
  1602.           fprintf (stderr, ">");
  1603. #else
  1604.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1605. #endif
  1606.         }
  1607.       fprintf (stderr, "\n");
  1608.     }
  1609. }
  1610.  
  1611. void
  1612. print_other_binding_stack (stack)
  1613.      struct binding_level *stack;
  1614. {
  1615.   struct binding_level *level;
  1616.   for (level = stack; level != global_binding_level; level = level->level_chain)
  1617.     {
  1618.       fprintf (stderr, "binding level ");
  1619.       fprintf (stderr, HOST_PTR_PRINTF, level);
  1620.       fprintf (stderr, "\n");
  1621.       print_binding_level (level);
  1622.     }
  1623. }
  1624.  
  1625. void
  1626. print_binding_stack ()
  1627. {
  1628.   struct binding_level *b;
  1629.   fprintf (stderr, "current_binding_level=");
  1630.   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
  1631.   fprintf (stderr, "\nclass_binding_level=");
  1632.   fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
  1633.   fprintf (stderr, "\nglobal_binding_level=");
  1634.   fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
  1635.   fprintf (stderr, "\n");
  1636.   if (class_binding_level)
  1637.     {
  1638.       for (b = class_binding_level; b; b = b->level_chain)
  1639.     if (b == current_binding_level)
  1640.       break;
  1641.       if (b)
  1642.     b = class_binding_level;
  1643.       else
  1644.     b = current_binding_level;
  1645.     }
  1646.   else
  1647.     b = current_binding_level;
  1648.   print_other_binding_stack (b);
  1649.   fprintf (stderr, "global:\n");
  1650.   print_binding_level (global_binding_level);
  1651. }
  1652.  
  1653. extern char * first_global_object_name;
  1654.  
  1655. /* Get a unique name for each call to this routine for unnamed namespaces.
  1656.    Mostly copied from get_file_function_name.  */
  1657. static tree
  1658. get_unique_name ()
  1659. {
  1660.   static int temp_name_counter = 0;
  1661.   char *buf;
  1662.   register char *p;
  1663.  
  1664.   if (first_global_object_name)
  1665.     p = first_global_object_name;
  1666.   else if (main_input_filename)
  1667.     p = main_input_filename;
  1668.   else
  1669.     p = input_filename;
  1670.  
  1671. #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
  1672.  
  1673.   buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p));
  1674.  
  1675.   sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++);
  1676.  
  1677.   /* Don't need to pull weird characters out of global names.  */
  1678.   if (p != first_global_object_name)
  1679.     {
  1680.       for (p = buf+11; *p; p++)
  1681.     if (! ((*p >= '0' && *p <= '9')
  1682. #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
  1683. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  1684.            || *p == '.'
  1685. #endif
  1686. #endif
  1687. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  1688.            || *p == '$'
  1689. #endif
  1690. #ifndef NO_DOT_IN_LABEL        /* this for `.'; unlikely, but... */
  1691.            || *p == '.'
  1692. #endif
  1693.            || (*p >= 'A' && *p <= 'Z')
  1694.            || (*p >= 'a' && *p <= 'z')))
  1695.       *p = '_';
  1696.     }
  1697.  
  1698.   return get_identifier (buf);
  1699. }
  1700.  
  1701. /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE, then we
  1702.    select a name that is unique to this compilation unit.  */
  1703. void
  1704. push_namespace (name)
  1705.      tree name;
  1706. {
  1707.   extern tree current_namespace;
  1708.   tree old_id = get_namespace_id ();
  1709.   char *buf;
  1710.   tree d = make_node (NAMESPACE_DECL);
  1711.  
  1712.   if (! name)
  1713.     {
  1714.       /* Create a truly ugly name! */
  1715.       name = get_unique_name ();
  1716.     }
  1717.  
  1718.   DECL_NAME (d) = name;
  1719.   DECL_ASSEMBLER_NAME (d) = name;
  1720.   /* pushdecl wants to check the size of it to see if it is incomplete... */
  1721.   TREE_TYPE (d) = void_type_node;
  1722.   /* Mark them as external, so redeclaration_error_message doesn't think
  1723.      they are duplicates. */
  1724.   DECL_EXTERNAL (d) = 1;
  1725.   d = pushdecl (d);
  1726.  
  1727.   if (NAMESPACE_LEVEL (d) == 0)
  1728.     {
  1729.       /* This is new for this compilation unit.  */
  1730.       pushlevel (0);
  1731.       declare_namespace_level ();
  1732.       NAMESPACE_LEVEL (d) = (tree)current_binding_level;
  1733.     }
  1734.   else
  1735.     {
  1736.       resume_level ((struct binding_level*)NAMESPACE_LEVEL (d));
  1737.     }
  1738.  
  1739.   /* This code is just is bit old now... */ 
  1740.   current_namespace = tree_cons (NULL_TREE, name, current_namespace);
  1741.   buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
  1742.              + IDENTIFIER_LENGTH (name));
  1743.   sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
  1744.        IDENTIFIER_POINTER (name));
  1745.   TREE_PURPOSE (current_namespace) = get_identifier (buf);
  1746. }
  1747.  
  1748. /* Pop from the scope of the current namespace.  */
  1749. void
  1750. pop_namespace ()
  1751. {
  1752.   extern tree current_namespace;
  1753.   tree decls, link;
  1754.   current_namespace = TREE_CHAIN (current_namespace);
  1755.  
  1756.   /* Just in case we get out of sync. */
  1757.   if (! namespace_bindings_p ())
  1758.     poplevel (0, 0, 0);
  1759.  
  1760.   decls = current_binding_level->names;
  1761.  
  1762.   /* Clear out the meanings of the local variables of this level.  */
  1763.  
  1764.   for (link = decls; link; link = TREE_CHAIN (link))
  1765.     {
  1766.       if (DECL_NAME (link) != NULL_TREE)
  1767.     {
  1768.       /* If the ident. was used or addressed via a local extern decl,
  1769.          don't forget that fact.  */
  1770.       if (DECL_EXTERNAL (link))
  1771.         {
  1772.           if (TREE_USED (link))
  1773.         TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  1774.           if (TREE_ADDRESSABLE (link))
  1775.         TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  1776.         }
  1777.       IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
  1778.     }
  1779.     }
  1780.  
  1781.   /* Restore all name-meanings of the outer levels
  1782.      that were shadowed by this level.  */
  1783.  
  1784.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1785.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1786.   for (link = current_binding_level->class_shadowed;
  1787.        link; link = TREE_CHAIN (link))
  1788.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1789.   for (link = current_binding_level->type_shadowed;
  1790.        link; link = TREE_CHAIN (link))
  1791.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1792.  
  1793.   /* suspend a level.  */
  1794.   suspend_binding_level ();
  1795. }
  1796.  
  1797. /* Subroutines for reverting temporarily to top-level for instantiation
  1798.    of templates and such.  We actually need to clear out the class- and
  1799.    local-value slots of all identifiers, so that only the global values
  1800.    are at all visible.  Simply setting current_binding_level to the global
  1801.    scope isn't enough, because more binding levels may be pushed.  */
  1802. struct saved_scope {
  1803.   struct binding_level *old_binding_level;
  1804.   tree old_bindings;
  1805.   struct saved_scope *prev;
  1806.   tree class_name, class_type, function_decl;
  1807.   tree base_init_list, member_init_list;
  1808.   struct binding_level *class_bindings;
  1809.   tree previous_class_type;
  1810.   tree *lang_base, *lang_stack, lang_name;
  1811.   int lang_stacksize;
  1812.   tree named_labels;
  1813. };
  1814. static struct saved_scope *current_saved_scope;
  1815. extern tree prev_class_type;
  1816.  
  1817. void
  1818. push_to_top_level ()
  1819. {
  1820.   extern int current_lang_stacksize;
  1821.   struct saved_scope *s =
  1822.     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
  1823.   struct binding_level *b = current_binding_level;
  1824.   tree old_bindings = NULL_TREE;
  1825.  
  1826.   /* Have to include global_binding_level, because class-level decls
  1827.      aren't listed anywhere useful.  */
  1828.   for (; b; b = b->level_chain)
  1829.     {
  1830.       tree t;
  1831.  
  1832.       if (b == global_binding_level)
  1833.     continue;
  1834.       
  1835.       for (t = b->names; t; t = TREE_CHAIN (t))
  1836.     {
  1837.       tree binding, t1, t2 = t;
  1838.       tree id = DECL_ASSEMBLER_NAME (t2);
  1839.  
  1840.       if (!id
  1841.           || (!IDENTIFIER_LOCAL_VALUE (id)
  1842.           && !IDENTIFIER_CLASS_VALUE (id)))
  1843.         continue;
  1844.  
  1845.       for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
  1846.         if (TREE_VEC_ELT (t1, 0) == id)
  1847.           goto skip_it;
  1848.         
  1849.       binding = make_tree_vec (4);
  1850.       if (id)
  1851.         {
  1852.           my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
  1853.           TREE_VEC_ELT (binding, 0) = id;
  1854.           TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
  1855.           TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
  1856.           TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
  1857.           IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
  1858.           IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
  1859.         }
  1860.       TREE_CHAIN (binding) = old_bindings;
  1861.       old_bindings = binding;
  1862.     skip_it:
  1863.       ;
  1864.     }
  1865.       /* Unwind type-value slots back to top level.  */
  1866.       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  1867.     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
  1868.     }
  1869.   /* Clear out class-level bindings cache.  */
  1870.   if (current_binding_level == global_binding_level
  1871.       && previous_class_type != NULL_TREE)
  1872.     {
  1873.       popclass (-1);
  1874.       previous_class_type = NULL_TREE;
  1875.     }
  1876.  
  1877.   s->old_binding_level = current_binding_level;
  1878.   current_binding_level = global_binding_level;
  1879.  
  1880.   s->class_name = current_class_name;
  1881.   s->class_type = current_class_type;
  1882.   s->function_decl = current_function_decl;
  1883.   s->base_init_list = current_base_init_list;
  1884.   s->member_init_list = current_member_init_list;
  1885.   s->class_bindings = class_binding_level;
  1886.   s->previous_class_type = previous_class_type;
  1887.   s->lang_stack = current_lang_stack;
  1888.   s->lang_base = current_lang_base;
  1889.   s->lang_stacksize = current_lang_stacksize;
  1890.   s->lang_name = current_lang_name;
  1891.   s->named_labels = named_labels;
  1892.   current_class_name = current_class_type = NULL_TREE;
  1893.   current_function_decl = NULL_TREE;
  1894.   class_binding_level = (struct binding_level *)0;
  1895.   previous_class_type = NULL_TREE;
  1896.   current_lang_stacksize = 10;
  1897.   current_lang_stack = current_lang_base
  1898.     = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
  1899.   current_lang_name = lang_name_cplusplus;
  1900.   strict_prototype = strict_prototypes_lang_cplusplus;
  1901.   named_labels = NULL_TREE;
  1902.  
  1903.   s->prev = current_saved_scope;
  1904.   s->old_bindings = old_bindings;
  1905.   current_saved_scope = s;
  1906. }
  1907.  
  1908. void
  1909. pop_from_top_level ()
  1910. {
  1911.   extern int current_lang_stacksize;
  1912.   struct saved_scope *s = current_saved_scope;
  1913.   tree t;
  1914.  
  1915.   if (previous_class_type)
  1916.     previous_class_type = NULL_TREE;
  1917.  
  1918.   current_binding_level = s->old_binding_level;
  1919.   current_saved_scope = s->prev;
  1920.   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
  1921.     {
  1922.       tree id = TREE_VEC_ELT (t, 0);
  1923.       if (id)
  1924.     {
  1925.       IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
  1926.       IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
  1927.       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
  1928.     }
  1929.     }
  1930.   current_class_name = s->class_name;
  1931.   current_class_type = s->class_type;
  1932.   current_base_init_list = s->base_init_list;
  1933.   current_member_init_list = s->member_init_list;
  1934.   current_function_decl = s->function_decl;
  1935.   class_binding_level = s->class_bindings;
  1936.   previous_class_type = s->previous_class_type;
  1937.   free (current_lang_base);
  1938.   current_lang_base = s->lang_base;
  1939.   current_lang_stack = s->lang_stack;
  1940.   current_lang_name = s->lang_name;
  1941.   current_lang_stacksize = s->lang_stacksize;
  1942.   if (current_lang_name == lang_name_cplusplus)
  1943.     strict_prototype = strict_prototypes_lang_cplusplus;
  1944.   else if (current_lang_name == lang_name_c)
  1945.     strict_prototype = strict_prototypes_lang_c;
  1946.   named_labels = s->named_labels;
  1947.  
  1948.   free (s);
  1949. }
  1950.  
  1951. /* Push a definition of struct, union or enum tag "name".
  1952.    into binding_level "b".   "type" should be the type node, 
  1953.    We assume that the tag "name" is not already defined.
  1954.  
  1955.    Note that the definition may really be just a forward reference.
  1956.    In that case, the TYPE_SIZE will be a NULL_TREE.
  1957.  
  1958.    C++ gratuitously puts all these tags in the name space. */
  1959.  
  1960. /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
  1961.    record the shadowed value for this binding contour.  TYPE is
  1962.    the type that ID maps to.  */
  1963.  
  1964. static void
  1965. set_identifier_type_value_with_scope (id, type, b)
  1966.      tree id;
  1967.      tree type;
  1968.      struct binding_level *b;
  1969. {
  1970.   if (b != global_binding_level)
  1971.     {
  1972.       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
  1973.       b->type_shadowed
  1974.     = tree_cons (id, old_type_value, b->type_shadowed);
  1975.     }
  1976.   SET_IDENTIFIER_TYPE_VALUE (id, type);
  1977. }
  1978.  
  1979. /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
  1980.  
  1981. void
  1982. set_identifier_type_value (id, type)
  1983.      tree id;
  1984.      tree type;
  1985. {
  1986.   set_identifier_type_value_with_scope (id, type, inner_binding_level);
  1987. }
  1988.  
  1989. /* Subroutine "set_nested_typename" builds the nested-typename of
  1990.    the type decl in question.  (Argument CLASSNAME can actually be
  1991.    a function as well, if that's the smallest containing scope.)  */
  1992.  
  1993. static void
  1994. set_nested_typename (decl, classname, name, type)
  1995.      tree decl, classname, name, type;
  1996. {
  1997.   char *buf;
  1998.   my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
  1999.  
  2000.   /* No need to do this for anonymous names, since they're unique.  */
  2001.   if (ANON_AGGRNAME_P (name))
  2002.     {
  2003.       DECL_NESTED_TYPENAME (decl) = name;
  2004.       return;
  2005.     }
  2006.  
  2007.   if (classname == NULL_TREE)
  2008.     classname = get_identifier ("");
  2009.  
  2010.   my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
  2011.   my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
  2012.   buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
  2013.              + IDENTIFIER_LENGTH (name));
  2014.   sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
  2015.        IDENTIFIER_POINTER (name));
  2016.   DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
  2017.   TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
  2018.  
  2019.   /* Create an extra decl so that the nested name will have a type value
  2020.      where appropriate.  */
  2021.   {
  2022.     tree nested, type_decl;
  2023.     nested = DECL_NESTED_TYPENAME (decl);
  2024.     type_decl = build_decl (TYPE_DECL, nested, type);
  2025.     DECL_NESTED_TYPENAME (type_decl) = nested;
  2026.     SET_DECL_ARTIFICIAL (type_decl);
  2027.     /* Mark the TYPE_DECL node created just above as a gratuitous one so that
  2028.        dwarfout.c will know not to generate a TAG_typedef DIE for it, and
  2029.        sdbout.c won't try to output a .def for "::foo".  */
  2030.     DECL_IGNORED_P (type_decl) = 1;
  2031.  
  2032.     /* Remove this when local classes are fixed.  */
  2033.     SET_IDENTIFIER_TYPE_VALUE (nested, type);
  2034.  
  2035.     pushdecl_nonclass_level (type_decl);
  2036.   }
  2037. }
  2038.  
  2039. /* Pop off extraneous binding levels left over due to syntax errors.
  2040.  
  2041.    We don't pop past namespaces, as they might be valid.  */
  2042. void
  2043. pop_everything ()
  2044. {
  2045. #ifdef DEBUG_CP_BINDING_LEVELS
  2046.   fprintf (stderr, "XXX entering pop_everything ()\n");
  2047. #endif
  2048.   while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
  2049.     {
  2050.       if (class_binding_level)
  2051.     pop_nested_class (1);
  2052.       else
  2053.     poplevel (0, 0, 0);
  2054.     }
  2055. #ifdef DEBUG_CP_BINDING_LEVELS
  2056.   fprintf (stderr, "XXX leaving pop_everything ()\n");
  2057. #endif
  2058. }
  2059.  
  2060. #if 0 /* not yet, should get fixed properly later */
  2061. /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
  2062.    Other routines shouldn't use build_decl directly; they'll produce
  2063.    incorrect results with `-g' unless they duplicate this code.
  2064.  
  2065.    This is currently needed mainly for dbxout.c, but we can make
  2066.    use of it in method.c later as well.  */
  2067. tree
  2068. make_type_decl (name, type)
  2069.      tree name, type;
  2070. {
  2071.   tree decl, id;
  2072.   decl = build_decl (TYPE_DECL, name, type);
  2073.   if (TYPE_NAME (type) == name)
  2074.     /* Class/union/enum definition, or a redundant typedef for same.  */
  2075.     {
  2076.       id = get_identifier (build_overload_name (type, 1, 1));
  2077.       DECL_ASSEMBLER_NAME (decl) = id;
  2078.     }
  2079.   else if (TYPE_NAME (type) != NULL_TREE)
  2080.     /* Explicit typedef, or implicit typedef for template expansion.  */
  2081.     DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
  2082.   else
  2083.     {
  2084.       /* XXX: Typedef for unnamed struct; some other situations.
  2085.      TYPE_NAME is null; what's right here?  */
  2086.     }
  2087.   return decl;
  2088. }
  2089. #endif
  2090.  
  2091. /* Push a tag name NAME for struct/class/union/enum type TYPE.
  2092.    Normally put into into the inner-most non-tag-transparent scope,
  2093.    but if GLOBALIZE is true, put it in the inner-most non-class scope.
  2094.    The latter is needed for implicit declarations. */
  2095.  
  2096. void
  2097. pushtag (name, type, globalize)
  2098.      tree name, type;
  2099.      int globalize;
  2100. {
  2101.   register struct binding_level *b;
  2102.   tree context = 0;
  2103.   tree c_decl = 0;
  2104.  
  2105.   b = inner_binding_level;
  2106.   while (b->tag_transparent
  2107.      || (globalize && b->parm_flag == 2))
  2108.     b = b->level_chain;
  2109.  
  2110.   if (toplevel_bindings_p ())
  2111.     b->tags = perm_tree_cons (name, type, b->tags);
  2112.   else
  2113.     b->tags = saveable_tree_cons (name, type, b->tags);
  2114.  
  2115.   if (name)
  2116.     {
  2117.       context = type ? TYPE_CONTEXT (type) : NULL_TREE;
  2118.       if (! context && ! globalize)
  2119.         context = current_scope ();
  2120.       if (context)
  2121.     c_decl = TREE_CODE (context) == FUNCTION_DECL
  2122.       ? context : TYPE_MAIN_DECL (context);
  2123.  
  2124. #if 0
  2125.       /* Record the identifier as the type's name if it has none.  */
  2126.       if (TYPE_NAME (type) == NULL_TREE)
  2127.         TYPE_NAME (type) = name;
  2128. #endif
  2129.       
  2130.       /* Do C++ gratuitous typedefing.  */
  2131.       if (IDENTIFIER_TYPE_VALUE (name) != type)
  2132.         {
  2133.           register tree d;
  2134.       int newdecl = 0;
  2135.       
  2136.       if (b->parm_flag != 2
  2137.           || TYPE_SIZE (current_class_type) != NULL_TREE)
  2138.         {
  2139.           d = lookup_nested_type (type, c_decl);
  2140.  
  2141.           if (d == NULL_TREE)
  2142.         {
  2143.           newdecl = 1;
  2144. #if 0 /* not yet, should get fixed properly later */
  2145.           d = make_type_decl (name, type);
  2146. #else
  2147.           d = build_decl (TYPE_DECL, name, type);
  2148.           DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d));
  2149. #endif
  2150.           SET_DECL_ARTIFICIAL (d);
  2151. #ifdef DWARF_DEBUGGING_INFO
  2152.           if (write_symbols == DWARF_DEBUG)
  2153.             {
  2154.               /* Mark the TYPE_DECL node we created just above as an
  2155.              gratuitous one.  We need to do this so that dwarfout.c
  2156.              will understand that it is not supposed to output a
  2157.              TAG_typedef DIE  for it. */
  2158.               DECL_IGNORED_P (d) = 1;
  2159.             }
  2160. #endif /* DWARF_DEBUGGING_INFO */
  2161.           set_identifier_type_value_with_scope (name, type, b);
  2162.         }
  2163.           else
  2164.         d = TYPE_NAME (d);
  2165.  
  2166.           TYPE_NAME (type) = d;
  2167.  
  2168.           /* If it is anonymous, then we are called from pushdecl,
  2169.          and we don't want to infinitely recurse.  */
  2170.           if (! ANON_AGGRNAME_P (name))
  2171.         {
  2172.           if (b->parm_flag == 2)
  2173.             d = pushdecl_class_level (d);
  2174.           else
  2175.             d = pushdecl_with_scope (d, b);
  2176.         }
  2177.         }
  2178.       else
  2179.         {
  2180.           /* Make nested declarations go into class-level scope.  */
  2181.           newdecl = 1;
  2182.           d = build_decl (TYPE_DECL, name, type);
  2183.           SET_DECL_ARTIFICIAL (d);
  2184. #ifdef DWARF_DEBUGGING_INFO
  2185.           if (write_symbols == DWARF_DEBUG)
  2186.         {
  2187.           /* Mark the TYPE_DECL node we created just above as an
  2188.              gratuitous one.  We need to do this so that dwarfout.c
  2189.              will understand that it is not supposed to output a
  2190.              TAG_typedef DIE  for it. */
  2191.           DECL_IGNORED_P (d) = 1;
  2192.         }
  2193. #endif /* DWARF_DEBUGGING_INFO */
  2194.  
  2195.           TYPE_MAIN_DECL (type) = d;
  2196.  
  2197.           /* Make sure we're in this type's scope when we push the
  2198.          decl for a template, otherwise class_binding_level will
  2199.          be NULL and we'll end up dying inside of
  2200.          push_class_level_binding.  */
  2201.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  2202.         pushclass (type, 0);
  2203.           d = pushdecl_class_level (d);
  2204.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  2205.         popclass (0);
  2206.         }
  2207.       if (newdecl)
  2208.         {
  2209.           if (write_symbols != DWARF_DEBUG)
  2210.         {
  2211.           if (ANON_AGGRNAME_P (name))
  2212.             DECL_IGNORED_P (d) = 1;
  2213.         }
  2214.  
  2215.           if (context == NULL_TREE)
  2216.         /* Non-nested class.  */
  2217.         set_nested_typename (d, NULL_TREE, name, type);
  2218.           else if (context && TREE_CODE (context) == FUNCTION_DECL)
  2219.         /* Function-nested class.  */
  2220.         set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
  2221.                      name, type);
  2222.           else /* if (context && IS_AGGR_TYPE (context)) */
  2223.         /* Class-nested class.  */
  2224.         set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
  2225.                      name, type);
  2226.  
  2227.           DECL_CONTEXT (d) = context;
  2228.           TYPE_CONTEXT (type) = DECL_CONTEXT (d);
  2229.           DECL_ASSEMBLER_NAME (d)
  2230.         = get_identifier (build_overload_name (type, 1, 1));
  2231.         }
  2232.         }
  2233.       if (b->parm_flag == 2)
  2234.     {
  2235.       TREE_NONLOCAL_FLAG (type) = 1;
  2236.       if (TYPE_SIZE (current_class_type) == NULL_TREE)
  2237.         CLASSTYPE_TAGS (current_class_type) = b->tags;
  2238.     }
  2239.     }
  2240.  
  2241.   if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  2242.     /* Use the canonical TYPE_DECL for this node.  */
  2243.     TYPE_STUB_DECL (type) = TYPE_NAME (type);
  2244.   else
  2245.     {
  2246.       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
  2247.      will be the tagged type we just added to the current
  2248.      binding level.  This fake NULL-named TYPE_DECL node helps
  2249.      dwarfout.c to know when it needs to output a
  2250.      representation of a tagged type, and it also gives us a
  2251.      convenient place to record the "scope start" address for
  2252.      the tagged type.  */
  2253.  
  2254. #if 0 /* not yet, should get fixed properly later */
  2255.       tree d = make_type_decl (NULL_TREE, type);
  2256. #else
  2257.       tree d = build_decl (TYPE_DECL, NULL_TREE, type);
  2258. #endif
  2259.       TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
  2260.     }
  2261. }
  2262.  
  2263. /* Counter used to create anonymous type names.  */
  2264. static int anon_cnt = 0;
  2265.  
  2266. /* Return an IDENTIFIER which can be used as a name for
  2267.    anonymous structs and unions.  */
  2268. tree
  2269. make_anon_name ()
  2270. {
  2271.   char buf[32];
  2272.  
  2273.   sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
  2274.   return get_identifier (buf);
  2275. }
  2276.  
  2277. /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
  2278.    This keeps dbxout from getting confused.  */
  2279. void
  2280. clear_anon_tags ()
  2281. {
  2282.   register struct binding_level *b;
  2283.   register tree tags;
  2284.   static int last_cnt = 0;
  2285.  
  2286.   /* Fast out if no new anon names were declared.  */
  2287.   if (last_cnt == anon_cnt)
  2288.     return;
  2289.  
  2290.   b = current_binding_level;
  2291.   while (b->tag_transparent)
  2292.     b = b->level_chain;
  2293.   tags = b->tags;
  2294.   while (tags)
  2295.     {
  2296.       /* A NULL purpose means we have already processed all tags
  2297.      from here to the end of the list.  */
  2298.       if (TREE_PURPOSE (tags) == NULL_TREE)
  2299.     break;
  2300.       if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
  2301.     TREE_PURPOSE (tags) = NULL_TREE;
  2302.       tags = TREE_CHAIN (tags);
  2303.     }
  2304.   last_cnt = anon_cnt;
  2305. }
  2306.  
  2307. /* Subroutine of duplicate_decls: return truthvalue of whether
  2308.    or not types of these decls match.
  2309.  
  2310.    For C++, we must compare the parameter list so that `int' can match
  2311.    `int&' in a parameter position, but `int&' is not confused with
  2312.    `const int&'.  */
  2313. int
  2314. decls_match (newdecl, olddecl)
  2315.      tree newdecl, olddecl;
  2316. {
  2317.   int types_match;
  2318.  
  2319.   if (TREE_CODE (newdecl) == FUNCTION_DECL
  2320.       && TREE_CODE (olddecl) == FUNCTION_DECL)
  2321.     {
  2322.       tree f1 = TREE_TYPE (newdecl);
  2323.       tree f2 = TREE_TYPE (olddecl);
  2324.       tree p1 = TYPE_ARG_TYPES (f1);
  2325.       tree p2 = TYPE_ARG_TYPES (f2);
  2326.  
  2327.       /* When we parse a static member function definition,
  2328.      we put together a FUNCTION_DECL which thinks its type
  2329.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  2330.      proceed.  */
  2331.       if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
  2332.     revert_static_member_fn (&newdecl, &f1, &p1);
  2333.       else if (TREE_CODE (f2) == METHOD_TYPE
  2334.            && DECL_STATIC_FUNCTION_P (newdecl))
  2335.     revert_static_member_fn (&olddecl, &f2, &p2);
  2336.  
  2337.       /* Here we must take care of the case where new default
  2338.      parameters are specified.  Also, warn if an old
  2339.      declaration becomes ambiguous because default
  2340.      parameters may cause the two to be ambiguous.  */
  2341.       if (TREE_CODE (f1) != TREE_CODE (f2))
  2342.     {
  2343.       if (TREE_CODE (f1) == OFFSET_TYPE)
  2344.         cp_compiler_error ("`%D' redeclared as member function", newdecl);
  2345.       else
  2346.         cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
  2347.       return 0;
  2348.     }
  2349.  
  2350.       if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
  2351.     {
  2352.       if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
  2353.           && p2 == NULL_TREE)
  2354.         {
  2355.           types_match = self_promoting_args_p (p1);
  2356.           if (p1 == void_list_node)
  2357.         TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  2358.         }
  2359.       else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
  2360.            && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
  2361.         {
  2362.           types_match = self_promoting_args_p (p2);
  2363.           TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  2364.         }
  2365.       else
  2366.         types_match = compparms (p1, p2, 3);
  2367.     }
  2368.       else
  2369.     types_match = 0;
  2370.     }
  2371.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL
  2372.        && TREE_CODE (olddecl) == TEMPLATE_DECL)
  2373.     {
  2374.     tree newargs = DECL_TEMPLATE_PARMS (newdecl);
  2375.     tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
  2376.     int i, len = TREE_VEC_LENGTH (newargs);
  2377.  
  2378.     if (TREE_VEC_LENGTH (oldargs) != len)
  2379.       return 0;
  2380.     
  2381.     for (i = 0; i < len; i++)
  2382.       {
  2383.         tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
  2384.         tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
  2385.         if (TREE_CODE (newarg) != TREE_CODE (oldarg))
  2386.           return 0;
  2387.         else if (TREE_CODE (newarg) == TYPE_DECL)
  2388.           /* continue */;
  2389.         else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
  2390.           return 0;
  2391.       }
  2392.  
  2393.     if (DECL_TEMPLATE_IS_CLASS (newdecl)
  2394.         != DECL_TEMPLATE_IS_CLASS (olddecl))
  2395.       types_match = 0;
  2396.     else if (DECL_TEMPLATE_IS_CLASS (newdecl))
  2397.       types_match = 1;
  2398.     else
  2399.       types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
  2400.                      DECL_TEMPLATE_RESULT (newdecl));
  2401.     }
  2402.   else
  2403.     {
  2404.       if (TREE_TYPE (newdecl) == error_mark_node)
  2405.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  2406.       else if (TREE_TYPE (olddecl) == NULL_TREE)
  2407.     types_match = TREE_TYPE (newdecl) == NULL_TREE;
  2408.       else if (TREE_TYPE (newdecl) == NULL_TREE)
  2409.     types_match = 0;
  2410.       else
  2411.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  2412.     }
  2413.  
  2414.   return types_match;
  2415. }
  2416.  
  2417. /* If NEWDECL is `static' and an `extern' was seen previously,
  2418.    warn about it.  (OLDDECL may be NULL_TREE; NAME contains
  2419.    information about previous usage as an `extern'.)
  2420.  
  2421.    Note that this does not apply to the C++ case of declaring
  2422.    a variable `extern const' and then later `const'.
  2423.  
  2424.    Don't complain if -traditional, since traditional compilers
  2425.    don't complain.
  2426.  
  2427.    Don't complain about built-in functions, since they are beyond
  2428.    the user's control.  */
  2429.  
  2430. static void
  2431. warn_extern_redeclared_static (newdecl, olddecl)
  2432.      tree newdecl, olddecl;
  2433. {
  2434.   tree name;
  2435.  
  2436.   static char *explicit_extern_static_warning
  2437.     = "`%D' was declared `extern' and later `static'";
  2438.   static char *implicit_extern_static_warning
  2439.     = "`%D' was declared implicitly `extern' and later `static'";
  2440.  
  2441.   if (flag_traditional
  2442. #ifdef OBJCPLUS
  2443.       || DECL_ARTIFICIAL (olddecl)
  2444. #endif
  2445.       || TREE_CODE (newdecl) == TYPE_DECL)
  2446.     return;
  2447.  
  2448.   name = DECL_ASSEMBLER_NAME (newdecl);
  2449.   if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl))
  2450.     {
  2451.       /* It's okay to redeclare an ANSI built-in function as static,
  2452.      or to declare a non-ANSI built-in function as anything.  */
  2453.       if (! (TREE_CODE (newdecl) == FUNCTION_DECL
  2454.          && olddecl != NULL_TREE
  2455.          && TREE_CODE (olddecl) == FUNCTION_DECL
  2456.          && (DECL_BUILT_IN (olddecl)
  2457.          || DECL_BUILT_IN_NONANSI (olddecl))))
  2458.     {
  2459.       cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
  2460.               ? implicit_extern_static_warning
  2461.               : explicit_extern_static_warning, newdecl);
  2462.       if (olddecl != NULL_TREE)
  2463.         cp_pedwarn_at ("previous declaration of `%D'", olddecl);
  2464.     }
  2465.     }
  2466. }
  2467.  
  2468. /* Handle when a new declaration NEWDECL has the same name as an old
  2469.    one OLDDECL in the same binding contour.  Prints an error message
  2470.    if appropriate.
  2471.  
  2472.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  2473.    Otherwise, return 0.  */
  2474.  
  2475. int
  2476. duplicate_decls (newdecl, olddecl)
  2477.      register tree newdecl, olddecl;
  2478. {
  2479.   extern struct obstack permanent_obstack;
  2480.   unsigned olddecl_uid = DECL_UID (olddecl);
  2481.   int olddecl_friend = 0, types_match = 0;
  2482.   int new_defines_function;
  2483.   tree previous_c_decl = NULL_TREE;
  2484.  
  2485.   if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
  2486.     DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl);
  2487.  
  2488.   types_match = decls_match (newdecl, olddecl);
  2489.  
  2490.   if (TREE_CODE (olddecl) != TREE_LIST)
  2491.     olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
  2492.  
  2493.   /* If either the type of the new decl or the type of the old decl is an
  2494.      error_mark_node, then that implies that we have already issued an
  2495.      error (earlier) for some bogus type specification, and in that case,
  2496.      it is rather pointless to harass the user with yet more error message
  2497.      about the same declaration, so well just pretent the types match here.  */
  2498.   if ((TREE_TYPE (newdecl)
  2499.        && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
  2500.       || (TREE_TYPE (olddecl)
  2501.       && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
  2502.     types_match = 1;
  2503.  
  2504.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  2505.       && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
  2506.     /* If -traditional, avoid error for redeclaring fcn
  2507.        after implicit decl.  */
  2508.     ;
  2509.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2510.        && DECL_ARTIFICIAL (olddecl)
  2511.        && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
  2512.     {
  2513.       /* If you declare a built-in or predefined function name as static,
  2514.      the old definition is overridden, but optionally warn this was a
  2515.      bad choice of name.  Ditto for overloads.  */
  2516.       if (! DECL_PUBLIC (newdecl)
  2517.       || (TREE_CODE (newdecl) == FUNCTION_DECL
  2518.           && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
  2519.     {
  2520.       if (warn_shadow)
  2521.         cp_warning ("shadowing %s function `%#D'",
  2522.             DECL_BUILT_IN (olddecl) ? "built-in" : "library",
  2523.             olddecl);
  2524.       /* Discard the old built-in function.  */
  2525.       return 0;
  2526.     }
  2527.       else if (! types_match)
  2528.     {
  2529.       if (TREE_CODE (newdecl) != FUNCTION_DECL)
  2530.         {
  2531.           /* If the built-in is not ansi, then programs can override
  2532.          it even globally without an error.  */
  2533.           if (! DECL_BUILT_IN (olddecl))
  2534.         cp_warning ("library function `%#D' redeclared as non-function `%#D'",
  2535.                 olddecl, newdecl);
  2536.           else
  2537.         {
  2538.           cp_error ("declaration of `%#D'", newdecl);
  2539.           cp_error ("conflicts with built-in declaration `%#D'",
  2540.                 olddecl);
  2541.         }
  2542.           return 0;
  2543.         }
  2544.  
  2545.       cp_warning ("declaration of `%#D'", newdecl);
  2546.       cp_warning ("conflicts with built-in declaration `%#D'",
  2547.               olddecl);
  2548.     }
  2549.     }
  2550.   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  2551.     {
  2552.       if ((TREE_CODE (newdecl) == FUNCTION_DECL
  2553.        && TREE_CODE (olddecl) == TEMPLATE_DECL
  2554.        && ! DECL_TEMPLATE_IS_CLASS (olddecl))
  2555.       || (TREE_CODE (olddecl) == FUNCTION_DECL
  2556.           && TREE_CODE (newdecl) == TEMPLATE_DECL
  2557.           && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
  2558.     return 0;
  2559.       
  2560.       cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
  2561.       if (TREE_CODE (olddecl) == TREE_LIST)
  2562.     olddecl = TREE_VALUE (olddecl);
  2563.       cp_error_at ("previous declaration of `%#D'", olddecl);
  2564.  
  2565.       /* New decl is completely inconsistent with the old one =>
  2566.      tell caller to replace the old one.  */
  2567.  
  2568.       return 0;
  2569.     }
  2570.   else if (!types_match)
  2571.     {
  2572.       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2573.     {
  2574.       /* The name of a class template may not be declared to refer to
  2575.          any other template, class, function, object, namespace, value,
  2576.          or type in the same scope. */
  2577.       if (DECL_TEMPLATE_IS_CLASS (olddecl)
  2578.           || DECL_TEMPLATE_IS_CLASS (newdecl))
  2579.         {
  2580.           cp_error ("declaration of template `%#D'", newdecl);
  2581.           cp_error_at ("conflicts with previous declaration `%#D'",
  2582.                olddecl);
  2583.         }
  2584.       return 0;
  2585.     }
  2586.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2587.     {
  2588.       if (DECL_LANGUAGE (newdecl) == lang_c
  2589.           && DECL_LANGUAGE (olddecl) == lang_c)
  2590.         {
  2591.           cp_error ("declaration of C function `%#D' conflicts with",
  2592.             newdecl);
  2593.           cp_error_at ("previous declaration `%#D' here", olddecl);
  2594.         }
  2595.       else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
  2596.                   TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3))
  2597.         {
  2598.           cp_error ("new declaration `%#D'", newdecl);
  2599.           cp_error_at ("ambiguates old declaration `%#D'", olddecl);
  2600.         }
  2601.       else
  2602.         return 0;
  2603.     }
  2604.  
  2605.       /* Already complained about this, so don't do so again.  */
  2606.       else if (current_class_type == NULL_TREE
  2607.       || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  2608.     {
  2609.       cp_error ("conflicting types for `%#D'", newdecl);
  2610.       cp_error_at ("previous declaration as `%#D'", olddecl);
  2611.     }
  2612.     }
  2613.   else
  2614.     {
  2615.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  2616.       if (errmsg)
  2617.     {
  2618.       cp_error (errmsg, newdecl);
  2619.       if (DECL_NAME (olddecl) != NULL_TREE)
  2620.         cp_error_at ((DECL_INITIAL (olddecl)
  2621.               && current_binding_level == global_binding_level)
  2622.              ? "`%#D' previously defined here"
  2623.              : "`%#D' previously declared here", olddecl);
  2624.     }
  2625.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2626.            && DECL_INITIAL (olddecl) != NULL_TREE
  2627.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
  2628.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
  2629.     {
  2630.       /* Prototype decl follows defn w/o prototype.  */
  2631.       cp_warning_at ("prototype for `%#D'", newdecl);
  2632.       cp_warning_at ("follows non-prototype definition here", olddecl);
  2633.     }
  2634.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2635.            && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
  2636.     {
  2637.       /* extern "C" int foo ();
  2638.          int foo () { bar (); }
  2639.          is OK.  */
  2640.       if (current_lang_stack == current_lang_base)
  2641.         DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2642.       else
  2643.         {
  2644.           cp_error_at ("previous declaration of `%#D' with %L linkage",
  2645.                olddecl, DECL_LANGUAGE (olddecl));
  2646.           cp_error ("conflicts with new declaration with %L linkage",
  2647.             DECL_LANGUAGE (newdecl));
  2648.         }
  2649.     }
  2650.  
  2651.       if (TREE_CODE (olddecl) == FUNCTION_DECL)
  2652.     {
  2653.       tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
  2654.       tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
  2655.       int i = 1;
  2656.  
  2657.       if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
  2658.         t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
  2659.     
  2660.       for (; t1 && t1 != void_list_node;
  2661.            t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
  2662.         if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  2663.           {
  2664.         if (1 == simple_cst_equal (TREE_PURPOSE (t1),
  2665.                        TREE_PURPOSE (t2)))
  2666.           {
  2667.             if (pedantic)
  2668.               {
  2669.             cp_pedwarn ("default argument given for parameter %d of `%#D'",
  2670.                     i, newdecl);
  2671.             cp_pedwarn_at ("after previous specification in `%#D'",
  2672.                        olddecl);
  2673.               }
  2674.           }
  2675.         else
  2676.           {
  2677.             cp_error ("default argument given for parameter %d of `%#D'",
  2678.                   i, newdecl);
  2679.             cp_error_at ("conflicts with previous specification in `%#D'",
  2680.                  olddecl);
  2681.           }
  2682.           }
  2683.  
  2684.       if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl))
  2685.         {
  2686. #if 0 /* I think this will be correct, but it's really annoying.  We should
  2687.      fix the compiler to find vtables by indirection so it isn't
  2688.      necessary.  (jason 8/25/95) */
  2689.           if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2690.         {
  2691.           cp_pedwarn ("virtual function `%#D' redeclared inline",
  2692.                   newdecl);
  2693.           cp_pedwarn_at ("previous non-inline declaration here",
  2694.                  olddecl);
  2695.         }
  2696.           else
  2697. #endif
  2698.           if (TREE_ADDRESSABLE (olddecl))
  2699.         {
  2700.           cp_pedwarn ("`%#D' was used before it was declared inline",
  2701.                   newdecl);
  2702.           cp_pedwarn_at ("previous non-inline declaration here",
  2703.                  olddecl);
  2704.         }
  2705.         }
  2706.     }
  2707.       /* These bits are logically part of the type for non-functions.  */
  2708.       else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  2709.            || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
  2710.     {
  2711.       cp_pedwarn ("type qualifiers for `%#D'", newdecl);
  2712.       cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl);
  2713.     }
  2714.     }
  2715.  
  2716.   /* If new decl is `static' and an `extern' was seen previously,
  2717.      warn about it.  */
  2718.   warn_extern_redeclared_static (newdecl, olddecl);
  2719.  
  2720.   /* We have committed to returning 1 at this point. */
  2721.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2722.     {
  2723.       /* Now that functions must hold information normally held
  2724.      by field decls, there is extra work to do so that
  2725.      declaration information does not get destroyed during
  2726.      definition.  */
  2727.       if (DECL_VINDEX (olddecl))
  2728.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  2729.       if (DECL_CONTEXT (olddecl))
  2730.     DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
  2731.       if (DECL_CLASS_CONTEXT (olddecl))
  2732.     DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
  2733.       if (DECL_CHAIN (newdecl) == NULL_TREE)
  2734.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2735.       if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
  2736.     DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
  2737.       if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
  2738.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  2739.       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
  2740.       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
  2741.       DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl);
  2742.     }
  2743.  
  2744.   /* Deal with C++: must preserve virtual function table size.  */
  2745.   if (TREE_CODE (olddecl) == TYPE_DECL)
  2746.     {
  2747.       register tree newtype = TREE_TYPE (newdecl);
  2748.       register tree oldtype = TREE_TYPE (olddecl);
  2749.  
  2750.       DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl);
  2751.  
  2752.       if (newtype != error_mark_node && oldtype != error_mark_node
  2753.       && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
  2754.     {
  2755.       CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
  2756.       CLASSTYPE_FRIEND_CLASSES (newtype)
  2757.         = CLASSTYPE_FRIEND_CLASSES (oldtype);
  2758.     }
  2759. #if 0
  2760.       /* why assert here?  Just because debugging information is
  2761.      messed up? (mrs) */
  2762.       /* it happens on something like:
  2763.          typedef struct Thing {
  2764.                     Thing();
  2765.                 int     x;
  2766.         } Thing;
  2767.       */
  2768.       my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
  2769.               139);
  2770. #endif
  2771.     }
  2772.  
  2773.   /* Special handling ensues if new decl is a function definition.  */
  2774.   new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
  2775.               && DECL_INITIAL (newdecl) != NULL_TREE);
  2776.  
  2777.   /* Optionally warn about more than one declaration for the same name,
  2778.      but don't warn about a function declaration followed by a definition.  */
  2779.   if (warn_redundant_decls
  2780.       && ! DECL_ARTIFICIAL (olddecl)
  2781.       && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
  2782.       /* Don't warn about extern decl followed by (tentative) definition.  */
  2783.       && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
  2784.     {
  2785.       cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
  2786.       cp_warning_at ("previous declaration of `%D'", olddecl);
  2787.     }
  2788.  
  2789.   /* Copy all the DECL_... slots specified in the new decl
  2790.      except for any that we copy here from the old type.  */
  2791.  
  2792.   if (types_match)
  2793.     {
  2794.       /* Automatically handles default parameters.  */
  2795.       tree oldtype = TREE_TYPE (olddecl);
  2796.       tree newtype;
  2797.  
  2798.       /* Make sure we put the new type in the same obstack as the old one.  */
  2799.       if (oldtype)
  2800.     push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
  2801.       else
  2802.     {
  2803.       push_obstacks_nochange ();
  2804.       end_temporary_allocation ();
  2805.     }
  2806.  
  2807.       /* Merge the data types specified in the two decls.  */
  2808.       newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  2809.  
  2810.       if (TREE_CODE (newdecl) == VAR_DECL)
  2811.     DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
  2812.       /* Do this after calling `common_type' so that default
  2813.      parameters don't confuse us.  */
  2814.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  2815.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  2816.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  2817.     {
  2818.       tree ctype = NULL_TREE;
  2819.       ctype = DECL_CLASS_CONTEXT (newdecl);
  2820.       TREE_TYPE (newdecl) = build_exception_variant (newtype,
  2821.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  2822.       TREE_TYPE (olddecl) = build_exception_variant (newtype,
  2823.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  2824.  
  2825.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  2826.         {
  2827.           cp_error ("declaration of `%D' throws different exceptions...",
  2828.             newdecl);
  2829.           cp_error_at ("...from previous declaration here", olddecl);
  2830.         }
  2831.     }
  2832.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  2833.  
  2834.       /* Lay the type out, unless already done.  */
  2835.       if (oldtype != TREE_TYPE (newdecl)
  2836.       && TREE_TYPE (newdecl) != error_mark_node)
  2837.     layout_type (TREE_TYPE (newdecl));
  2838.  
  2839.       if (TREE_CODE (newdecl) == VAR_DECL
  2840.       || TREE_CODE (newdecl) == PARM_DECL
  2841.       || TREE_CODE (newdecl) == RESULT_DECL
  2842.       || TREE_CODE (newdecl) == FIELD_DECL
  2843.       || TREE_CODE (newdecl) == TYPE_DECL)
  2844.     layout_decl (newdecl, 0);
  2845.  
  2846.       /* Merge the type qualifiers.  */
  2847.       if (TREE_READONLY (newdecl))
  2848.     TREE_READONLY (olddecl) = 1;
  2849.       if (TREE_THIS_VOLATILE (newdecl))
  2850.     TREE_THIS_VOLATILE (olddecl) = 1;
  2851.  
  2852.       /* Merge the initialization information.  */
  2853.       if (DECL_INITIAL (newdecl) == NULL_TREE
  2854.       && DECL_INITIAL (olddecl) != NULL_TREE)
  2855.     {
  2856.       DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2857.       DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
  2858.       DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
  2859.     }
  2860.  
  2861.       /* Merge the section attribute.
  2862.          We want to issue an error if the sections conflict but that must be
  2863.      done later in decl_attributes since we are called before attributes
  2864.      are assigned.  */
  2865.       if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
  2866.     DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
  2867.  
  2868.       /* Keep the old rtl since we can safely use it, unless it's the
  2869.      call to abort() used for abstract virtuals.  */
  2870.       if ((DECL_LANG_SPECIFIC (olddecl)
  2871.        && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2872.       || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
  2873.     DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2874.  
  2875.       pop_obstacks ();
  2876.     }
  2877.   /* If cannot merge, then use the new type and qualifiers,
  2878.      and don't preserve the old rtl.  */
  2879.   else
  2880.     {
  2881.       /* Clean out any memory we had of the old declaration.  */
  2882.       tree oldstatic = value_member (olddecl, static_aggregates);
  2883.       if (oldstatic)
  2884.     TREE_VALUE (oldstatic) = error_mark_node;
  2885.  
  2886.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  2887.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  2888.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  2889.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  2890.     }
  2891.  
  2892.   /* Merge the storage class information.  */
  2893.   DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
  2894.   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  2895.   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
  2896.   if (! DECL_EXTERNAL (olddecl))
  2897.     DECL_EXTERNAL (newdecl) = 0;
  2898.  
  2899.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2900.     {
  2901.       DECL_C_STATIC (newdecl) = DECL_C_STATIC (olddecl);
  2902.       DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
  2903.       DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
  2904.     }
  2905.  
  2906.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2907.     {
  2908.       DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl);
  2909.  
  2910.       /* If either decl says `inline', this fn is inline, unless its
  2911.          definition was passed already.  */
  2912.       if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
  2913.     DECL_INLINE (olddecl) = 1;
  2914.       DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
  2915.  
  2916.       if (! types_match)
  2917.     {
  2918.       DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
  2919.       DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
  2920.       DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
  2921.       DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
  2922.       DECL_RTL (olddecl) = DECL_RTL (newdecl);
  2923.     }
  2924.       if (new_defines_function)
  2925.     /* If defining a function declared with other language
  2926.        linkage, use the previously declared language linkage.  */
  2927.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2928.       else
  2929.     {
  2930.       /* If redeclaring a builtin function, and not a definition,
  2931.          it stays built in.  */
  2932.       if (DECL_BUILT_IN (olddecl))
  2933.         {
  2934.           DECL_BUILT_IN (newdecl) = 1;
  2935.           DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
  2936.           /* If we're keeping the built-in definition, keep the rtl,
  2937.          regardless of declaration matches.  */
  2938.           DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2939.         }
  2940.       else
  2941.         DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  2942.  
  2943.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  2944.       if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
  2945.         /* Previously saved insns go together with
  2946.            the function's previous definition.  */
  2947.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2948.       /* Don't clear out the arguments if we're redefining a function.  */
  2949.       if (DECL_ARGUMENTS (olddecl))
  2950.         DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  2951.     }
  2952.       if (DECL_LANG_SPECIFIC (olddecl))
  2953.     DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
  2954.     }
  2955.  
  2956. #if defined (_WIN32) && defined (NEXT_PDO)
  2957.     /* If this decl had DECL_DLLIMPORT set, then copy that */
  2958.     DECL_DLLIMPORT(newdecl) = DECL_DLLIMPORT(olddecl);
  2959. #endif /* _WIN32 */
  2960.  
  2961.   if (TREE_CODE (newdecl) == NAMESPACE_DECL)
  2962.     {
  2963.       NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
  2964.     }
  2965.  
  2966.   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2967.     {
  2968.       if (DECL_TEMPLATE_INFO (olddecl)->length)
  2969.     DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
  2970.       DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
  2971.       DECL_TEMPLATE_INSTANTIATIONS (newdecl)
  2972.     = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
  2973.       if (DECL_CHAIN (newdecl) == NULL_TREE)
  2974.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2975.     }
  2976.   
  2977.   /* Now preserve various other info from the definition.  */
  2978.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  2979.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  2980.   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
  2981.   DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
  2982.  
  2983.   /* Don't really know how much of the language-specific
  2984.      values we should copy from old to new.  */
  2985.   if (DECL_LANG_SPECIFIC (olddecl))
  2986.     {
  2987.       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  2988.       DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
  2989.       DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
  2990.     }
  2991.  
  2992.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2993.     {
  2994.       int function_size;
  2995.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  2996.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  2997.  
  2998.       function_size = sizeof (struct tree_decl);
  2999.  
  3000.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  3001.          (char *) olddecl + sizeof (struct tree_common),
  3002.          function_size - sizeof (struct tree_common));
  3003.  
  3004.       /* Can we safely free the storage used by newdecl?  */
  3005.  
  3006. #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
  3007.           & ~ obstack_alignment_mask (&permanent_obstack))
  3008.  
  3009.       if ((char *)newdecl + ROUND (function_size)
  3010.       + ROUND (sizeof (struct lang_decl))
  3011.       == obstack_next_free (&permanent_obstack))
  3012.     {
  3013.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  3014.       DECL_LANG_SPECIFIC (olddecl) = ol;
  3015.       bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
  3016.  
  3017.       obstack_free (&permanent_obstack, newdecl);
  3018.     }
  3019.       else if (LANG_DECL_PERMANENT (ol))
  3020.     {
  3021.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  3022.         {
  3023.           /* Save these lang_decls that would otherwise be lost.  */
  3024.           extern tree free_lang_decl_chain;
  3025.           tree free_lang_decl = (tree) ol;
  3026.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  3027.           free_lang_decl_chain = free_lang_decl;
  3028.         }
  3029.       else
  3030.         {
  3031.           /* Storage leak.  */
  3032.         }
  3033.     }
  3034.     }
  3035.   else
  3036.     {
  3037.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  3038.          (char *) olddecl + sizeof (struct tree_common),
  3039.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  3040.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  3041.     }
  3042.  
  3043.   DECL_UID (olddecl) = olddecl_uid;
  3044.   if (olddecl_friend)
  3045.     DECL_FRIEND_P (olddecl) = 1;
  3046.  
  3047.   return 1;
  3048. }
  3049.  
  3050. /* Record a decl-node X as belonging to the current lexical scope.
  3051.    Check for errors (such as an incompatible declaration for the same
  3052.    name already seen in the same scope).
  3053.  
  3054.    Returns either X or an old decl for the same name.
  3055.    If an old decl is returned, it may have been smashed
  3056.    to agree with what X says.  */
  3057.  
  3058. tree
  3059. pushdecl (x)
  3060.      tree x;
  3061. {
  3062.   register tree t;
  3063. #if 0 /* not yet, should get fixed properly later */
  3064.   register tree name;
  3065. #else
  3066.   register tree name = DECL_ASSEMBLER_NAME (x);
  3067. #endif
  3068.   register struct binding_level *b = current_binding_level;
  3069.  
  3070. #if 0
  3071.   static int nglobals; int len;
  3072.  
  3073.   len = list_length (global_binding_level->names);
  3074.   if (len < nglobals)
  3075.     my_friendly_abort (8);
  3076.   else if (len > nglobals)
  3077.     nglobals = len;
  3078. #endif
  3079.  
  3080.   if (x != current_function_decl
  3081.       /* Don't change DECL_CONTEXT of virtual methods.  */
  3082.       && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
  3083.       && ! DECL_CONTEXT (x))
  3084.     DECL_CONTEXT (x) = current_function_decl;
  3085.   /* A local declaration for a function doesn't constitute nesting.  */
  3086.   if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
  3087.     DECL_CONTEXT (x) = 0;
  3088.  
  3089. #if 0 /* not yet, should get fixed properly later */
  3090.   /* For functions and class static data, we currently look up the encoded
  3091.      form of the name.  For types, we want the real name.  The former will
  3092.      probably be changed soon, according to MDT.  */
  3093.   if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
  3094.     name = DECL_ASSEMBLER_NAME (x);
  3095.   else
  3096.     name = DECL_NAME (x);
  3097. #else
  3098.   /* Type are looked up using the DECL_NAME, as that is what the rest of the
  3099.      compiler wants to use. */
  3100.   if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL
  3101.       || TREE_CODE (x) == NAMESPACE_DECL)
  3102.     name = DECL_NAME (x);
  3103. #endif
  3104.  
  3105.   if (name)
  3106.     {
  3107.       char *file;
  3108.       int line;
  3109.  
  3110.       t = lookup_name_current_level (name);
  3111.       if (t == error_mark_node)
  3112.     {
  3113.       /* error_mark_node is 0 for a while during initialization!  */
  3114.       t = NULL_TREE;
  3115.       cp_error_at ("`%#D' used prior to declaration", x);
  3116.     }
  3117.  
  3118.       else if (t != NULL_TREE)
  3119.     {
  3120.       file = DECL_SOURCE_FILE (t);
  3121.       line = DECL_SOURCE_LINE (t);
  3122.       if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x))
  3123.         ; /* This is OK. */
  3124.       else if (TREE_CODE (t) == PARM_DECL)
  3125.         {
  3126.           if (DECL_CONTEXT (t) == NULL_TREE)
  3127.         fatal ("parse errors have confused me too much");
  3128.         }
  3129.       else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
  3130.            || (TREE_CODE (x) == TEMPLATE_DECL
  3131.            && ! DECL_TEMPLATE_IS_CLASS (x)))
  3132.           && is_overloaded_fn (t))
  3133.         /* don't do anything just yet */;
  3134.       else if (t == wchar_decl_node)
  3135.         {
  3136.           if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
  3137.         cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
  3138.  
  3139.           /* Throw away the redeclaration.  */
  3140.           return t;
  3141.         }
  3142.       else if (TREE_CODE (t) != TREE_CODE (x))
  3143.         {
  3144.           if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
  3145.           || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
  3146.         {
  3147.           /* We do nothing special here, because C++ does such nasty
  3148.              things with TYPE_DECLs.  Instead, just let the TYPE_DECL
  3149.              get shadowed, and know that if we need to find a TYPE_DECL
  3150.              for a given name, we can look in the IDENTIFIER_TYPE_VALUE
  3151.              slot of the identifier.  */
  3152.           ;
  3153.         }
  3154.           else if (duplicate_decls (x, t))
  3155.         return t;
  3156.         }
  3157.       else if (duplicate_decls (x, t))
  3158.         {
  3159. #if 0
  3160.           /* This is turned off until I have time to do it right (bpk).  */
  3161.  
  3162.           /* Also warn if they did a prototype with `static' on it, but
  3163.          then later left the `static' off.  */
  3164.           if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
  3165.         {
  3166.           if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
  3167.             return t;
  3168.  
  3169.           if (extra_warnings)
  3170.             {
  3171.               cp_warning ("`static' missing from declaration of `%D'",
  3172.                   t);
  3173.               warning_with_file_and_line (file, line,
  3174.                           "previous declaration of `%s'",
  3175.                           decl_as_string (t, 0));
  3176.             }
  3177.  
  3178.           /* Now fix things so it'll do what they expect.  */
  3179.           if (current_function_decl)
  3180.             TREE_PUBLIC (current_function_decl) = 0;
  3181.         }
  3182.           /* Due to interference in memory reclamation (X may be
  3183.          obstack-deallocated at this point), we must guard against
  3184.          one really special case.  [jason: This should be handled
  3185.          by start_function]  */
  3186.           if (current_function_decl == x)
  3187.         current_function_decl = t;
  3188. #endif
  3189.           if (TREE_CODE (t) == TYPE_DECL)
  3190.         SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
  3191.           else if (TREE_CODE (t) == FUNCTION_DECL)
  3192.         check_default_args (t);
  3193.  
  3194.           return t;
  3195.         }
  3196.     }
  3197.  
  3198.       if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
  3199.     {
  3200.       t = push_overloaded_decl (x, 1);
  3201.       if (t != x || DECL_LANGUAGE (x) == lang_c)
  3202.         return t;
  3203.     }
  3204.       else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
  3205.     return push_overloaded_decl (x, 0);
  3206.  
  3207.       /* If declaring a type as a typedef, and the type has no known
  3208.      typedef name, install this TYPE_DECL as its typedef name.  */
  3209.       if (TREE_CODE (x) == TYPE_DECL)
  3210.     {
  3211.       tree type = TREE_TYPE (x);
  3212.       tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
  3213.  
  3214.       if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
  3215.         {
  3216.           /* If these are different names, and we're at the global
  3217.          binding level, make two equivalent definitions.  */
  3218.               name = x;
  3219.               if (global_bindings_p ())
  3220.                 TYPE_NAME (type) = x;
  3221.         }
  3222.       else
  3223.         {
  3224.           tree tname = DECL_NAME (name);
  3225.  
  3226.           /* This is a disgusting kludge for dealing with UPTs.  */
  3227.           if (global_bindings_p () && ANON_AGGRNAME_P (tname))
  3228.         {
  3229.             /* do gratuitous C++ typedefing, and make sure that
  3230.                we access this type either through TREE_TYPE field
  3231.                or via the tags list.  */
  3232.           TYPE_NAME (TREE_TYPE (x)) = x;
  3233.           pushtag (tname, TREE_TYPE (x), 0);
  3234.         }
  3235.         }
  3236.       my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
  3237.  
  3238.       /* Don't set nested_typename on template type parms, for instance.
  3239.          Any artificial decls that need DECL_NESTED_TYPENAME will have it
  3240.          set in pushtag.  */
  3241.       if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
  3242.         set_nested_typename (x, current_class_name, DECL_NAME (x), type);
  3243.  
  3244.       if (type != error_mark_node
  3245.           && TYPE_NAME (type)
  3246.           && TYPE_IDENTIFIER (type))
  3247.             set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
  3248.     }
  3249.  
  3250.       /* Multiple external decls of the same identifier ought to match.
  3251.  
  3252.      We get warnings about inline functions where they are defined.
  3253.      We get warnings about other functions from push_overloaded_decl.
  3254.      
  3255.      Avoid duplicate warnings where they are used.  */
  3256.       if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
  3257.     {
  3258.       tree decl;
  3259.  
  3260.       if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
  3261.           && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  3262.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  3263.         decl = IDENTIFIER_GLOBAL_VALUE (name);
  3264.       else
  3265.         decl = NULL_TREE;
  3266.  
  3267.       if (decl
  3268.           /* If different sort of thing, we already gave an error.  */
  3269.           && TREE_CODE (decl) == TREE_CODE (x)
  3270.           && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
  3271.         {
  3272.           cp_pedwarn ("type mismatch with previous external decl", x);
  3273.           cp_pedwarn_at ("previous external decl of `%#D'", decl);
  3274.         }
  3275.     }
  3276.  
  3277.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  3278.      take effect at top level no matter where they are.  */
  3279.       if (flag_traditional && DECL_EXTERNAL (x)
  3280.       && lookup_name (name, 0) == NULL_TREE)
  3281.     b = global_binding_level;
  3282.  
  3283.       /* This name is new in its binding level.
  3284.      Install the new declaration and return it.  */
  3285.       if (b == global_binding_level)
  3286.     {
  3287.       /* Install a global value.  */
  3288.  
  3289.       /* If the first global decl has external linkage,
  3290.          warn if we later see static one.  */
  3291.       if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
  3292.         TREE_PUBLIC (name) = 1;
  3293.  
  3294.       /* Don't install an artificial TYPE_DECL if we already have
  3295.          another _DECL with that name.  */
  3296.       if (TREE_CODE (x) != TYPE_DECL
  3297.           || t == NULL_TREE
  3298.           || ! DECL_ARTIFICIAL (x))
  3299.         IDENTIFIER_GLOBAL_VALUE (name) = x;
  3300.  
  3301.       /* Don't forget if the function was used via an implicit decl.  */
  3302.       if (IDENTIFIER_IMPLICIT_DECL (name)
  3303.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  3304.         TREE_USED (x) = 1;
  3305.  
  3306.       /* Don't forget if its address was taken in that way.  */
  3307.       if (IDENTIFIER_IMPLICIT_DECL (name)
  3308.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  3309.         TREE_ADDRESSABLE (x) = 1;
  3310.  
  3311.       /* Warn about mismatches against previous implicit decl.  */
  3312.       if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
  3313.           /* If this real decl matches the implicit, don't complain.  */
  3314.           && ! (TREE_CODE (x) == FUNCTION_DECL
  3315.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  3316.         cp_warning
  3317.           ("`%D' was previously implicitly declared to return `int'", x);
  3318.  
  3319.       /* If new decl is `static' and an `extern' was seen previously,
  3320.          warn about it.  */
  3321.       if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
  3322.         warn_extern_redeclared_static (x, t);
  3323.     }
  3324.       else
  3325.     {
  3326.       /* Here to install a non-global value.  */
  3327.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  3328.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  3329.  
  3330.       /* Don't install an artificial TYPE_DECL if we already have
  3331.          another _DECL with that name.  */
  3332.       if (TREE_CODE (x) != TYPE_DECL
  3333.           || t == NULL_TREE
  3334.           || ! DECL_ARTIFICIAL (x))
  3335.         {
  3336.           b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  3337.           IDENTIFIER_LOCAL_VALUE (name) = x;
  3338.         }
  3339.  
  3340.       /* If this is a TYPE_DECL, push it into the type value slot.  */
  3341.       if (TREE_CODE (x) == TYPE_DECL)
  3342.         set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
  3343.  
  3344.       /* Clear out any TYPE_DECL shadowed by a namespace so that
  3345.          we won't think this is a type.  The C struct hack doesn't
  3346.          go through namespaces.  */
  3347.       if (TREE_CODE (x) == NAMESPACE_DECL)
  3348.         set_identifier_type_value_with_scope (name, NULL_TREE, b);
  3349.  
  3350.       /* If this is an extern function declaration, see if we
  3351.          have a global definition or declaration for the function.  */
  3352.       if (oldlocal == NULL_TREE
  3353.           && DECL_EXTERNAL (x)
  3354.           && oldglobal != NULL_TREE
  3355.           && TREE_CODE (x) == FUNCTION_DECL
  3356.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  3357.         {
  3358.           /* We have one.  Their types must agree.  */
  3359.           if (decls_match (x, oldglobal))
  3360.         /* OK */;
  3361.           else
  3362.         {
  3363.           cp_warning ("extern declaration of `%#D' doesn't match", x);
  3364.           cp_warning_at ("global declaration `%#D'", oldglobal);
  3365.         }
  3366.         }
  3367.       /* If we have a local external declaration,
  3368.          and no file-scope declaration has yet been seen,
  3369.          then if we later have a file-scope decl it must not be static.  */
  3370.       if (oldlocal == NULL_TREE
  3371.           && oldglobal == NULL_TREE
  3372.           && DECL_EXTERNAL (x)
  3373.           && TREE_PUBLIC (x))
  3374.         {
  3375.           TREE_PUBLIC (name) = 1;
  3376.         }
  3377.  
  3378.       if (DECL_FROM_INLINE (x))
  3379.         /* Inline decls shadow nothing.  */;
  3380.  
  3381.       /* Warn if shadowing an argument at the top level of the body.  */
  3382.       else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
  3383.           && TREE_CODE (oldlocal) == PARM_DECL
  3384.           && TREE_CODE (x) != PARM_DECL)
  3385.         {
  3386.           /* Go to where the parms should be and see if we
  3387.          find them there.  */
  3388.           struct binding_level *b = current_binding_level->level_chain;
  3389.  
  3390.           if (cleanup_label)
  3391.         b = b->level_chain;
  3392.  
  3393.           /* ARM $8.3 */
  3394.           if (b->parm_flag == 1)
  3395.         cp_error ("declaration of `%#D' shadows a parameter", name);
  3396.         }
  3397.       else if (oldlocal != NULL_TREE && b->is_for_scope
  3398.            && !DECL_DEAD_FOR_LOCAL (oldlocal))
  3399.         {
  3400.           warning ("variable `%s' shadows local",
  3401.                IDENTIFIER_POINTER (name));
  3402.           cp_warning_at ("  this is the shadowed declaration", oldlocal);
  3403.         }           
  3404.       /* Maybe warn if shadowing something else.  */
  3405.       else if (warn_shadow && !DECL_EXTERNAL (x)
  3406.            /* No shadow warnings for internally generated vars.  */
  3407.            && ! DECL_ARTIFICIAL (x)
  3408.            /* No shadow warnings for vars made for inlining.  */
  3409.            && ! DECL_FROM_INLINE (x))
  3410.         {
  3411.           char *warnstring = NULL;
  3412.  
  3413.           if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
  3414.         warnstring = "declaration of `%s' shadows a parameter";
  3415.           else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
  3416.                && current_class_decl
  3417.                && !TREE_STATIC (name))
  3418.         warnstring = "declaration of `%s' shadows a member of `this'";
  3419.           else if (oldlocal != NULL_TREE)
  3420.         warnstring = "declaration of `%s' shadows previous local";
  3421.           else if (oldglobal != NULL_TREE)
  3422.         warnstring = "declaration of `%s' shadows global declaration";
  3423.  
  3424.           if (warnstring)
  3425.         warning (warnstring, IDENTIFIER_POINTER (name));
  3426.         }
  3427.     }
  3428.  
  3429.       if (TREE_CODE (x) == FUNCTION_DECL)
  3430.     check_default_args (x);
  3431.  
  3432.       /* Keep count of variables in this level with incomplete type.  */
  3433.       if (TREE_CODE (x) == VAR_DECL
  3434.       && TREE_TYPE (x) != error_mark_node
  3435.       && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
  3436.            && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
  3437.           /* RTTI TD entries are created while defining the type_info.  */
  3438.           || (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
  3439.           && TYPE_BEING_DEFINED (TREE_TYPE (x)))))
  3440.     b->incomplete = tree_cons (NULL_TREE, x, b->incomplete);
  3441.     }
  3442.  
  3443.   /* Put decls on list in reverse order.
  3444.      We will reverse them later if necessary.  */
  3445.   TREE_CHAIN (x) = b->names;
  3446.   b->names = x;
  3447.   if (! (b != global_binding_level || TREE_PERMANENT (x)))
  3448.     my_friendly_abort (124);
  3449.  
  3450.   return x;
  3451. }
  3452.  
  3453. /* Same as pushdecl, but define X in binding-level LEVEL. */
  3454.  
  3455. static tree
  3456. pushdecl_with_scope (x, level)
  3457.      tree x;
  3458.      struct binding_level *level;
  3459. {
  3460.   register struct binding_level *b = current_binding_level;
  3461.  
  3462.   current_binding_level = level;
  3463.   x = pushdecl (x);
  3464.   current_binding_level = b;
  3465.   return x;
  3466. }
  3467.  
  3468. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  3469.    if appropriate.  */
  3470. tree
  3471. pushdecl_top_level (x)
  3472.      tree x;
  3473. {
  3474.   register struct binding_level *b = inner_binding_level;
  3475.   register tree t = pushdecl_with_scope (x, global_binding_level);
  3476.  
  3477.   /* Now, the type_shadowed stack may screw us.  Munge it so it does
  3478.      what we want.  */
  3479.   if (TREE_CODE (x) == TYPE_DECL)
  3480.     {
  3481.       tree name = DECL_NAME (x);
  3482.       tree newval;
  3483.       tree *ptr = (tree *)0;
  3484.       for (; b != global_binding_level; b = b->level_chain)
  3485.         {
  3486.           tree shadowed = b->type_shadowed;
  3487.           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
  3488.             if (TREE_PURPOSE (shadowed) == name)
  3489.               {
  3490.         ptr = &TREE_VALUE (shadowed);
  3491.         /* Can't break out of the loop here because sometimes
  3492.            a binding level will have duplicate bindings for
  3493.            PT names.  It's gross, but I haven't time to fix it.  */
  3494.               }
  3495.         }
  3496.       newval = TREE_TYPE (x);
  3497.       if (ptr == (tree *)0)
  3498.         {
  3499.           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
  3500.              up here if this is changed to an assertion.  --KR  */
  3501.       SET_IDENTIFIER_TYPE_VALUE (name, newval);
  3502.     }
  3503.       else
  3504.         {
  3505. #if 0
  3506.       /* Disabled this 11/10/92, since there are many cases which
  3507.          behave just fine when *ptr doesn't satisfy either of these.
  3508.          For example, nested classes declared as friends of their enclosing
  3509.          class will not meet this criteria.  (bpk) */
  3510.       my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
  3511. #endif
  3512.       *ptr = newval;
  3513.         }
  3514.     }
  3515.   return t;
  3516. }
  3517.  
  3518. /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
  3519.    if appropriate.  */
  3520. void
  3521. push_overloaded_decl_top_level (x, forget)
  3522.      tree x;
  3523.      int forget;
  3524. {
  3525.   struct binding_level *b = current_binding_level;
  3526.  
  3527.   current_binding_level = global_binding_level;
  3528.   push_overloaded_decl (x, forget);
  3529.   current_binding_level = b;
  3530. }
  3531.  
  3532. /* Make the declaration of X appear in CLASS scope.  */
  3533. tree
  3534. pushdecl_class_level (x)
  3535.      tree x;
  3536. {
  3537.   /* Don't use DECL_ASSEMBLER_NAME here!  Everything that looks in class
  3538.      scope looks for the pre-mangled name.  */
  3539.   register tree name = DECL_NAME (x);
  3540.  
  3541.   if (name)
  3542.     {
  3543.       if (TYPE_BEING_DEFINED (current_class_type))
  3544.     {
  3545.       /* Check for inconsistent use of this name in the class body.
  3546.          Types, enums, and static vars are checked here; other
  3547.          members are checked in finish_struct.  */
  3548.       tree icv = IDENTIFIER_CLASS_VALUE (name);
  3549.  
  3550.       if (icv
  3551.           /* Don't complain about inherited names.  */
  3552.           && id_in_current_class (name)
  3553.           /* Or shadowed tags.  */
  3554.           && !(TREE_CODE (icv) == TYPE_DECL
  3555.            && DECL_CONTEXT (icv) == current_class_type))
  3556.         {
  3557.           cp_error ("declaration of identifier `%D' as `%#D'", name, x);
  3558.           cp_error_at ("conflicts with previous use in class as `%#D'",
  3559.                icv);
  3560.         }
  3561.     }
  3562.  
  3563.       push_class_level_binding (name, x);
  3564.       if (TREE_CODE (x) == TYPE_DECL)
  3565.     {
  3566.       set_identifier_type_value (name, TREE_TYPE (x));
  3567.  
  3568.       /* Don't set nested_typename on template type parms, for instance.
  3569.          Any artificial decls that need DECL_NESTED_TYPENAME will have it
  3570.          set in pushtag.  */
  3571.       if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
  3572.         set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
  3573.     }
  3574.     }
  3575.   return x;
  3576. }
  3577.  
  3578. /* This function is used to push the mangled decls for nested types into
  3579.    the appropriate scope.  Previously pushdecl_top_level was used, but that
  3580.    is incorrect for members of local classes.  */
  3581. tree
  3582. pushdecl_nonclass_level (x)
  3583.      tree x;
  3584. {
  3585.   struct binding_level *b = current_binding_level;
  3586.  
  3587. #if 0
  3588.   /* Get out of class scope -- this isn't necessary, because class scope
  3589.      doesn't make it into current_binding_level.  */
  3590.   while (b->parm_flag == 2)
  3591.     b = b->level_chain;
  3592. #else
  3593.   my_friendly_assert (b->parm_flag != 2, 180);
  3594. #endif
  3595.  
  3596.   /* Get out of template binding levels */
  3597.   while (b->pseudo_global)
  3598.     b = b->level_chain;
  3599.  
  3600.   pushdecl_with_scope (x, b);
  3601. }
  3602.  
  3603. /* Make the declaration(s) of X appear in CLASS scope
  3604.    under the name NAME.  */
  3605. void
  3606. push_class_level_binding (name, x)
  3607.      tree name;
  3608.      tree x;
  3609. {
  3610.   if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
  3611.       && purpose_member (name, class_binding_level->class_shadowed))
  3612.     return;
  3613.  
  3614.   maybe_push_cache_obstack ();
  3615.   class_binding_level->class_shadowed
  3616.       = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
  3617.            class_binding_level->class_shadowed);
  3618.   pop_obstacks ();
  3619.   IDENTIFIER_CLASS_VALUE (name) = x;
  3620.   obstack_ptr_grow (&decl_obstack, x);
  3621. }
  3622.  
  3623. /* Tell caller how to interpret a TREE_LIST which contains
  3624.    chains of FUNCTION_DECLS.  */
  3625. int
  3626. overloaded_globals_p (list)
  3627.      tree list;
  3628. {
  3629.   my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
  3630.  
  3631.   /* Don't commit caller to seeing them as globals.  */
  3632.   if (TREE_NONLOCAL_FLAG (list))
  3633.     return -1;
  3634.   /* Do commit caller to seeing them as globals.  */
  3635.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  3636.     return 1;
  3637.   /* Do commit caller to not seeing them as globals.  */
  3638.   return 0;
  3639. }
  3640.  
  3641. /* DECL is a FUNCTION_DECL which may have other definitions already in
  3642.    place.  We get around this by making the value of the identifier point
  3643.    to a list of all the things that want to be referenced by that name.  It
  3644.    is then up to the users of that name to decide what to do with that
  3645.    list.
  3646.  
  3647.    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
  3648.    slot.  It is dealt with the same way.
  3649.  
  3650.    The value returned may be a previous declaration if we guessed wrong
  3651.    about what language DECL should belong to (C or C++).  Otherwise,
  3652.    it's always DECL (and never something that's not a _DECL).  */
  3653. tree
  3654. push_overloaded_decl (decl, forgettable)
  3655.      tree decl;
  3656.      int forgettable;
  3657. {
  3658.   tree orig_name = DECL_NAME (decl);
  3659.   tree old;
  3660.   int doing_global = (global_bindings_p () || ! forgettable
  3661.               || flag_traditional || pseudo_global_level_p ());
  3662.  
  3663.   if (doing_global)
  3664.     {
  3665.       old = IDENTIFIER_GLOBAL_VALUE (orig_name);
  3666.       if (old && TREE_CODE (old) == FUNCTION_DECL
  3667.       && DECL_ARTIFICIAL (old)
  3668.       && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
  3669.     {
  3670.       if (duplicate_decls (decl, old))
  3671.         return old;
  3672.       old = NULL_TREE;
  3673.     }
  3674.     }
  3675.   else
  3676.     {
  3677.       old = IDENTIFIER_LOCAL_VALUE (orig_name);
  3678.  
  3679.       if (! purpose_member (orig_name, current_binding_level->shadowed))
  3680.     {
  3681.       current_binding_level->shadowed
  3682.         = tree_cons (orig_name, old, current_binding_level->shadowed);
  3683.       old = NULL_TREE;
  3684.     }
  3685.     }
  3686.  
  3687.   if (old)
  3688.     {
  3689. #if 0
  3690.       /* We cache the value of builtin functions as ADDR_EXPRs
  3691.      in the name space.  Convert it to some kind of _DECL after
  3692.      remembering what to forget.  */
  3693.       if (TREE_CODE (old) == ADDR_EXPR)
  3694.     old = TREE_OPERAND (old, 0);
  3695.       else
  3696. #endif
  3697.       if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
  3698.     {
  3699.       tree t = TREE_TYPE (old);
  3700.       if (IS_AGGR_TYPE (t) && warn_shadow)
  3701.         cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
  3702.       old = NULL_TREE;
  3703.     }
  3704.       else if (is_overloaded_fn (old))
  3705.         {
  3706.           tree tmp;
  3707.       
  3708.       for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
  3709.         if (decl == tmp || duplicate_decls (decl, tmp))
  3710.           return tmp;
  3711.     }
  3712.       else
  3713.     {
  3714.       cp_error_at ("previous non-function declaration `%#D'", old);
  3715.       cp_error ("conflicts with function declaration `%#D'", decl);
  3716.       return decl;
  3717.     }
  3718.     }
  3719.  
  3720.   if (old || TREE_CODE (decl) == TEMPLATE_DECL)
  3721.     {
  3722.       if (old && is_overloaded_fn (old))
  3723.     DECL_CHAIN (decl) = get_first_fn (old);
  3724.       else
  3725.     DECL_CHAIN (decl) = NULL_TREE;
  3726.       old = tree_cons (orig_name, decl, NULL_TREE);
  3727.       TREE_TYPE (old) = unknown_type_node;
  3728.     }
  3729.   else
  3730.     /* orig_name is not ambiguous.  */
  3731.     old = decl;
  3732.  
  3733.   if (doing_global)
  3734.     IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
  3735.   else
  3736.     IDENTIFIER_LOCAL_VALUE (orig_name) = old;
  3737.  
  3738.   return decl;
  3739. }
  3740.  
  3741. /* Generate an implicit declaration for identifier FUNCTIONID
  3742.    as a function of type int ().  Print a warning if appropriate.  */
  3743.  
  3744. tree
  3745. implicitly_declare (functionid)
  3746.      tree functionid;
  3747. {
  3748.   register tree decl;
  3749.   int temp = allocation_temporary_p ();
  3750.  
  3751.   push_obstacks_nochange ();
  3752.  
  3753.   /* Save the decl permanently so we can warn if definition follows.
  3754.      In ANSI C, warn_implicit is usually false, so the saves little space.
  3755.      But in C++, it's usually true, hence the extra code.  */
  3756.   if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ()))
  3757.     end_temporary_allocation ();
  3758.  
  3759.   /* We used to reuse an old implicit decl here,
  3760.      but this loses with inline functions because it can clobber
  3761.      the saved decl chains.  */
  3762.   decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  3763.  
  3764.   DECL_EXTERNAL (decl) = 1;
  3765.   TREE_PUBLIC (decl) = 1;
  3766.  
  3767.   /* ANSI standard says implicit declarations are in the innermost block.
  3768.      So we record the decl in the standard fashion.
  3769.      If flag_traditional is set, pushdecl does it top-level.  */
  3770.   pushdecl (decl);
  3771.   rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
  3772.  
  3773.   if (warn_implicit
  3774.       /* Only one warning per identifier.  */
  3775.       && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
  3776.     {
  3777.       cp_pedwarn ("implicit declaration of function `%#D'", decl);
  3778.     }
  3779.  
  3780.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  3781.  
  3782.   pop_obstacks ();
  3783.  
  3784.   return decl;
  3785. }
  3786.  
  3787. /* Return zero if the declaration NEWDECL is valid
  3788.    when the declaration OLDDECL (assumed to be for the same name)
  3789.    has already been seen.
  3790.    Otherwise return an error message format string with a %s
  3791.    where the identifier should go.  */
  3792.  
  3793. static char *
  3794. redeclaration_error_message (newdecl, olddecl)
  3795.      tree newdecl, olddecl;
  3796. {
  3797.   if (TREE_CODE (newdecl) == TYPE_DECL)
  3798.     {
  3799.       /* Because C++ can put things into name space for free,
  3800.      constructs like "typedef struct foo { ... } foo"
  3801.      would look like an erroneous redeclaration.  */
  3802.       if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  3803.     return 0;
  3804.       else
  3805.     return "redefinition of `%#D'";
  3806.     }
  3807.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  3808.     {
  3809.       /* If this is a pure function, its olddecl will actually be
  3810.      the original initialization to `0' (which we force to call
  3811.      abort()).  Don't complain about redefinition in this case.  */
  3812.       if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
  3813.     return 0;
  3814.  
  3815.       /* We'll complain about linkage mismatches in
  3816.          warn_extern_redeclared_static.  */
  3817.  
  3818.       /* defining the same name twice is no good.  */
  3819.       if (DECL_INITIAL (olddecl) != NULL_TREE
  3820.       && DECL_INITIAL (newdecl) != NULL_TREE)
  3821.     {
  3822.       if (DECL_NAME (olddecl) == NULL_TREE)
  3823.         return "`%#D' not declared in class";
  3824.       else
  3825.         return "redefinition of `%#D'";
  3826.     }
  3827.       return 0;
  3828.     }
  3829.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  3830.     {
  3831.       if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
  3832.     return "redefinition of `%#D'";
  3833.       return 0;
  3834.     }
  3835.   else if (current_binding_level == global_binding_level)
  3836.     {
  3837.       /* Objects declared at top level:  */
  3838.       /* If at least one is a reference, it's ok.  */
  3839.       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
  3840.     return 0;
  3841.       /* Reject two definitions.  */
  3842.       return "redefinition of `%#D'";
  3843.     }
  3844.   else
  3845.     {
  3846.       /* Objects declared with block scope:  */
  3847.       /* Reject two definitions, and reject a definition
  3848.      together with an external reference.  */
  3849.       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
  3850.     return "redeclaration of `%#D'";
  3851.       return 0;
  3852.     }
  3853. }
  3854.  
  3855. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  3856.    Create one if none exists so far for the current function.
  3857.    This function is called for both label definitions and label references.  */
  3858.  
  3859. tree
  3860. lookup_label (id)
  3861.      tree id;
  3862. {
  3863.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  3864.  
  3865.   if (current_function_decl == NULL_TREE)
  3866.     {
  3867.       error ("label `%s' referenced outside of any function",
  3868.          IDENTIFIER_POINTER (id));
  3869.       return NULL_TREE;
  3870.     }
  3871.  
  3872.   if ((decl == NULL_TREE
  3873.       || DECL_SOURCE_LINE (decl) == 0)
  3874.       && (named_label_uses == NULL_TREE
  3875.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  3876.       || TREE_VALUE (named_label_uses) != decl))
  3877.     {
  3878.       named_label_uses
  3879.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  3880.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  3881.     }
  3882.  
  3883.   /* Use a label already defined or ref'd with this name.  */
  3884.   if (decl != NULL_TREE)
  3885.     {
  3886.       /* But not if it is inherited and wasn't declared to be inheritable.  */
  3887.       if (DECL_CONTEXT (decl) != current_function_decl
  3888.       && ! C_DECLARED_LABEL_FLAG (decl))
  3889.     return shadow_label (id);
  3890.       return decl;
  3891.     }
  3892.  
  3893.   decl = build_decl (LABEL_DECL, id, void_type_node);
  3894.  
  3895.   /* A label not explicitly declared must be local to where it's ref'd.  */
  3896.   DECL_CONTEXT (decl) = current_function_decl;
  3897.  
  3898.   DECL_MODE (decl) = VOIDmode;
  3899.  
  3900.   /* Say where one reference is to the label,
  3901.      for the sake of the error if it is not defined.  */
  3902.   DECL_SOURCE_LINE (decl) = lineno;
  3903.   DECL_SOURCE_FILE (decl) = input_filename;
  3904.  
  3905.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  3906.  
  3907.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  3908.   TREE_VALUE (named_label_uses) = decl;
  3909.  
  3910.   return decl;
  3911. }
  3912.  
  3913. /* Make a label named NAME in the current function,
  3914.    shadowing silently any that may be inherited from containing functions
  3915.    or containing scopes.
  3916.  
  3917.    Note that valid use, if the label being shadowed
  3918.    comes from another scope in the same function,
  3919.    requires calling declare_nonlocal_label right away.  */
  3920.  
  3921. tree
  3922. shadow_label (name)
  3923.      tree name;
  3924. {
  3925.   register tree decl = IDENTIFIER_LABEL_VALUE (name);
  3926.  
  3927.   if (decl != NULL_TREE)
  3928.     {
  3929.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3930.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3931.       SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
  3932.     }
  3933.  
  3934.   return lookup_label (name);
  3935. }
  3936.  
  3937. /* Define a label, specifying the location in the source file.
  3938.    Return the LABEL_DECL node for the label, if the definition is valid.
  3939.    Otherwise return 0.  */
  3940.  
  3941. tree
  3942. define_label (filename, line, name)
  3943.      char *filename;
  3944.      int line;
  3945.      tree name;
  3946. {
  3947.   tree decl = lookup_label (name);
  3948.  
  3949.   /* After labels, make any new cleanups go into their
  3950.      own new (temporary) binding contour.  */
  3951.   current_binding_level->more_cleanups_ok = 0;
  3952.  
  3953.   /* If label with this name is known from an outer context, shadow it.  */
  3954.   if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
  3955.     {
  3956.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3957.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3958.       decl = lookup_label (name);
  3959.     }
  3960.  
  3961.   if (name == get_identifier ("wchar_t"))
  3962.     cp_pedwarn ("label named wchar_t");
  3963.  
  3964.   if (DECL_INITIAL (decl) != NULL_TREE)
  3965.     {
  3966.       cp_error ("duplicate label `%D'", decl);
  3967.       return 0;
  3968.     }
  3969.   else
  3970.     {
  3971.       tree uses, prev;
  3972.       int identified = 0;
  3973.  
  3974.       /* Mark label as having been defined.  */
  3975.       DECL_INITIAL (decl) = error_mark_node;
  3976.       /* Say where in the source.  */
  3977.       DECL_SOURCE_FILE (decl) = filename;
  3978.       DECL_SOURCE_LINE (decl) = line;
  3979.  
  3980.       for (prev = NULL_TREE, uses = named_label_uses;
  3981.        uses;
  3982.        prev = uses, uses = TREE_CHAIN (uses))
  3983.     if (TREE_VALUE (uses) == decl)
  3984.       {
  3985.         struct binding_level *b = current_binding_level;
  3986.         while (b)
  3987.           {
  3988.         tree new_decls = b->names;
  3989.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  3990.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  3991.         while (new_decls != old_decls)
  3992.           {
  3993.             if (TREE_CODE (new_decls) == VAR_DECL
  3994.             /* Don't complain about crossing initialization
  3995.                of internal entities.  They can't be accessed,
  3996.                and they should be cleaned up
  3997.                by the time we get to the label.  */
  3998.             && ! DECL_ARTIFICIAL (new_decls)
  3999.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  4000.                  && DECL_INITIAL (new_decls) != error_mark_node)
  4001.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  4002.               {
  4003.             if (! identified)
  4004.               cp_error ("jump to label `%D'", decl);
  4005.             identified = 1;
  4006.             cp_error_at ("  crosses initialization of `%#D'",
  4007.                      new_decls);
  4008.               }
  4009.             new_decls = TREE_CHAIN (new_decls);
  4010.           }
  4011.         if ((tree)b == TREE_TYPE (uses))
  4012.           break;
  4013.         b = b->level_chain;
  4014.           }
  4015.  
  4016.         if (prev)
  4017.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  4018.         else
  4019.           named_label_uses = TREE_CHAIN (uses);
  4020.       }
  4021.       current_function_return_value = NULL_TREE;
  4022.       return decl;
  4023.     }
  4024. }
  4025.  
  4026. struct cp_switch
  4027. {
  4028.   struct binding_level *level;
  4029.   struct cp_switch *next;
  4030. };
  4031.  
  4032. static struct cp_switch *switch_stack;
  4033.  
  4034. void
  4035. push_switch ()
  4036. {
  4037.   struct cp_switch *p
  4038.     = (struct cp_switch *) oballoc (sizeof (struct cp_switch));
  4039.   p->level = current_binding_level;
  4040.   p->next = switch_stack;
  4041.   switch_stack = p;
  4042. }
  4043.  
  4044. void
  4045. pop_switch ()
  4046. {
  4047.   switch_stack = switch_stack->next;
  4048. }
  4049.  
  4050. /* Same, but for CASE labels.  If DECL is NULL_TREE, it's the default.  */
  4051. /* XXX Note decl is never actually used. (bpk) */
  4052. void
  4053. define_case_label (decl)
  4054.      tree decl;
  4055. {
  4056.   tree cleanup = last_cleanup_this_contour ();
  4057.   struct binding_level *b = current_binding_level;
  4058.   int identified = 0;
  4059.  
  4060.   if (cleanup)
  4061.     {
  4062.       static int explained = 0;
  4063.       cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
  4064.       warning ("where case label appears here");
  4065.       if (!explained)
  4066.     {
  4067.       warning ("(enclose actions of previous case statements requiring");
  4068.       warning ("destructors in their own binding contours.)");
  4069.       explained = 1;
  4070.     }
  4071.     }
  4072.  
  4073.   for (; b && b != switch_stack->level; b = b->level_chain)
  4074.     {
  4075.       tree new_decls = b->names;
  4076.       for (; new_decls; new_decls = TREE_CHAIN (new_decls))
  4077.     {
  4078.       if (TREE_CODE (new_decls) == VAR_DECL
  4079.           /* Don't complain about crossing initialization
  4080.          of internal entities.  They can't be accessed,
  4081.          and they should be cleaned up
  4082.          by the time we get to the label.  */
  4083.           && ! DECL_ARTIFICIAL (new_decls)
  4084.           && ((DECL_INITIAL (new_decls) != NULL_TREE
  4085.            && DECL_INITIAL (new_decls) != error_mark_node)
  4086.           || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  4087.         {
  4088.           if (! identified)
  4089.         error ("jump to case label");
  4090.           identified = 1;
  4091.           cp_error_at ("  crosses initialization of `%#D'",
  4092.                new_decls);
  4093.         }
  4094.     }
  4095.     }
  4096.  
  4097.   /* After labels, make any new cleanups go into their
  4098.      own new (temporary) binding contour.  */
  4099.  
  4100.   current_binding_level->more_cleanups_ok = 0;
  4101.   current_function_return_value = NULL_TREE;
  4102. }
  4103.  
  4104. /* Return the list of declarations of the current level.
  4105.    Note that this list is in reverse order unless/until
  4106.    you nreverse it; and when you do nreverse it, you must
  4107.    store the result back using `storedecls' or you will lose.  */
  4108.  
  4109. tree
  4110. getdecls ()
  4111. {
  4112.   return current_binding_level->names;
  4113. }
  4114.  
  4115. /* Return the list of type-tags (for structs, etc) of the current level.  */
  4116.  
  4117. tree
  4118. gettags ()
  4119. {
  4120.   return current_binding_level->tags;
  4121. }
  4122.  
  4123. /* Store the list of declarations of the current level.
  4124.    This is done for the parameter declarations of a function being defined,
  4125.    after they are modified in the light of any missing parameters.  */
  4126.  
  4127. static void
  4128. storedecls (decls)
  4129.      tree decls;
  4130. {
  4131.   current_binding_level->names = decls;
  4132. }
  4133.  
  4134. /* Similarly, store the list of tags of the current level.  */
  4135.  
  4136. static void
  4137. storetags (tags)
  4138.      tree tags;
  4139. {
  4140.   current_binding_level->tags = tags;
  4141. }
  4142.  
  4143. /* Given NAME, an IDENTIFIER_NODE,
  4144.    return the structure (or union or enum) definition for that name.
  4145.    Searches binding levels from BINDING_LEVEL up to the global level.
  4146.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  4147.    (but skips any tag-transparent contexts to find one that is
  4148.    meaningful for tags).
  4149.    FORM says which kind of type the caller wants;
  4150.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  4151.    If the wrong kind of type is found, and it's not a template, an error is
  4152.    reported.  */
  4153.  
  4154. static tree
  4155. lookup_tag (form, name, binding_level, thislevel_only)
  4156.      enum tree_code form;
  4157.      struct binding_level *binding_level;
  4158.      tree name;
  4159.      int thislevel_only;
  4160. {
  4161.   register struct binding_level *level;
  4162.  
  4163.   for (level = binding_level; level; level = level->level_chain)
  4164.     {
  4165.       register tree tail;
  4166.       if (ANON_AGGRNAME_P (name))
  4167.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4168.       {
  4169.         /* There's no need for error checking here, because
  4170.            anon names are unique throughout the compilation.  */
  4171.         if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
  4172.           return TREE_VALUE (tail);
  4173.       }
  4174.       else
  4175.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4176.       {
  4177.         if (TREE_PURPOSE (tail) == name)
  4178.           {
  4179.         enum tree_code code = TREE_CODE (TREE_VALUE (tail));
  4180.         /* Should tighten this up; it'll probably permit
  4181.            UNION_TYPE and a struct template, for example.  */
  4182.         if (code != form
  4183.             && !(form != ENUMERAL_TYPE
  4184.              && (code == TEMPLATE_DECL
  4185.                  || code == UNINSTANTIATED_P_TYPE)))
  4186.                
  4187.           {
  4188.             /* Definition isn't the kind we were looking for.  */
  4189.             cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
  4190.                   form);
  4191.           }
  4192.         return TREE_VALUE (tail);
  4193.           }
  4194.       }
  4195.       if (thislevel_only && ! level->tag_transparent)
  4196.     return NULL_TREE;
  4197.       if (current_class_type != NULL_TREE && level->level_chain == global_binding_level)
  4198.     {
  4199.       /* Try looking in this class's tags before heading into
  4200.          global binding level.  */
  4201.       tree context = current_class_type;
  4202.       while (context)
  4203.         {
  4204.           switch (TREE_CODE_CLASS (TREE_CODE (context)))
  4205.         {
  4206.         tree these_tags;
  4207.         case 't':
  4208.             these_tags = CLASSTYPE_TAGS (context);
  4209.             if (ANON_AGGRNAME_P (name))
  4210.               while (these_tags)
  4211.             {
  4212.               if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
  4213.                   == name)
  4214.                 return TREE_VALUE (tail);
  4215.               these_tags = TREE_CHAIN (these_tags);
  4216.             }
  4217.             else
  4218.               while (these_tags)
  4219.             {
  4220.               if (TREE_PURPOSE (these_tags) == name)
  4221.                 {
  4222.                   if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  4223.                 {
  4224.                   cp_error ("`%#D' redeclared as %C in class scope",
  4225.                         TREE_VALUE (tail), form);
  4226.                 }
  4227.                   return TREE_VALUE (tail);
  4228.                 }
  4229.               these_tags = TREE_CHAIN (these_tags);
  4230.             }
  4231.             /* If this type is not yet complete, then don't
  4232.                look at its context.  */
  4233.             if (TYPE_SIZE (context) == NULL_TREE)
  4234.               goto no_context;
  4235.             /* Go to next enclosing type, if any.  */
  4236.             context = DECL_CONTEXT (TYPE_NAME (context));
  4237.             break;
  4238.             case 'd':
  4239.             context = DECL_CONTEXT (context);
  4240.             break;
  4241.             default:
  4242.             my_friendly_abort (10);
  4243.         }
  4244.           continue;
  4245.           no_context:
  4246.           break;
  4247.         }
  4248.     }
  4249.     }
  4250.   return NULL_TREE;
  4251. }
  4252.  
  4253. void
  4254. set_current_level_tags_transparency (tags_transparent)
  4255.      int tags_transparent;
  4256. {
  4257.   current_binding_level->tag_transparent = tags_transparent;
  4258. }
  4259.  
  4260. /* Given a type, find the tag that was defined for it and return the tag name.
  4261.    Otherwise return 0.  However, the value can never be 0
  4262.    in the cases in which this is used.
  4263.  
  4264.    C++: If NAME is non-zero, this is the new name to install.  This is
  4265.    done when replacing anonymous tags with real tag names.  */
  4266.  
  4267. static tree
  4268. lookup_tag_reverse (type, name)
  4269.      tree type;
  4270.      tree name;
  4271. {
  4272.   register struct binding_level *level;
  4273.  
  4274.   for (level = current_binding_level; level; level = level->level_chain)
  4275.     {
  4276.       register tree tail;
  4277.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4278.     {
  4279.       if (TREE_VALUE (tail) == type)
  4280.         {
  4281.           if (name)
  4282.         TREE_PURPOSE (tail) = name;
  4283.           return TREE_PURPOSE (tail);
  4284.         }
  4285.     }
  4286.     }
  4287.   return NULL_TREE;
  4288. }
  4289.  
  4290. /* Given type TYPE which was not declared in C++ language context,
  4291.    attempt to find a name by which it is referred.  */
  4292. tree
  4293. typedecl_for_tag (tag)
  4294.      tree tag;
  4295. {
  4296.   struct binding_level *b = current_binding_level;
  4297.  
  4298.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  4299.     return TYPE_NAME (tag);
  4300.  
  4301.   while (b)
  4302.     {
  4303.       tree decls = b->names;
  4304.       while (decls)
  4305.     {
  4306.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  4307.         break;
  4308.       decls = TREE_CHAIN (decls);
  4309.     }
  4310.       if (decls)
  4311.     return decls;
  4312.       b = b->level_chain;
  4313.     }
  4314.   return NULL_TREE;
  4315. }
  4316.  
  4317. /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
  4318.    Return the type value, or NULL_TREE if not found.  */
  4319. static tree
  4320. lookup_nested_type (type, context)
  4321.      tree type;
  4322.      tree context;
  4323. {
  4324.   if (context == NULL_TREE)
  4325.     return NULL_TREE;
  4326.   while (context)
  4327.     {
  4328.       switch (TREE_CODE (context))
  4329.     {
  4330.     case TYPE_DECL:
  4331.       {
  4332.         tree ctype = TREE_TYPE (context);
  4333.         tree match = value_member (type, CLASSTYPE_TAGS (ctype));
  4334.         if (match)
  4335.           return TREE_VALUE (match);
  4336.         context = DECL_CONTEXT (context);
  4337.  
  4338.         /* When we have a nested class whose member functions have
  4339.            local types (e.g., a set of enums), we'll arrive here
  4340.            with the DECL_CONTEXT as the actual RECORD_TYPE node for
  4341.            the enclosing class.  Instead, we want to make sure we
  4342.            come back in here with the TYPE_DECL, not the RECORD_TYPE.  */
  4343.         if (context && TREE_CODE (context) == RECORD_TYPE)
  4344.           context = TREE_CHAIN (context);
  4345.       }
  4346.       break;
  4347.     case FUNCTION_DECL:
  4348.       if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
  4349.         return lookup_name (TYPE_IDENTIFIER (type), 1);
  4350.       return NULL_TREE;
  4351.     default:
  4352.       my_friendly_abort (12);
  4353.     }
  4354.     }
  4355.   return NULL_TREE;
  4356. }
  4357.  
  4358. /* Look up NAME in the NAMESPACE.  */
  4359. tree
  4360. lookup_namespace_name (namespace, name)
  4361.      tree namespace, name;
  4362. {
  4363.   struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace);
  4364.   tree x;
  4365.  
  4366.   for (x = NULL_TREE; b && !x; b = b->level_chain)
  4367.     {
  4368.       for (x = b->names; x; x = TREE_CHAIN (x))
  4369.     if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
  4370.       break;
  4371.       /* Must find directly in the namespace.  */
  4372.       break;
  4373.     }
  4374.   return x;
  4375. }
  4376.  
  4377. /* Look up NAME in the current binding level and its superiors in the
  4378.    namespace of variables, functions and typedefs.  Return a ..._DECL
  4379.    node of some kind representing its definition if there is only one
  4380.    such declaration, or return a TREE_LIST with all the overloaded
  4381.    definitions if there are many, or return 0 if it is undefined.
  4382.  
  4383.    If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
  4384.    If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
  4385.    Otherwise we prefer non-TYPE_DECLs.  */
  4386.  
  4387. tree
  4388. lookup_name_real (name, prefer_type, nonclass)
  4389.      tree name;
  4390.      int prefer_type, nonclass;
  4391. {
  4392.   register tree val;
  4393.   int yylex = 0;
  4394.   tree from_obj = NULL_TREE;
  4395.  
  4396.   if (prefer_type == -2)
  4397.     {
  4398.       extern int looking_for_typename;
  4399.       tree type;
  4400.  
  4401.       yylex = 1;
  4402.       prefer_type = looking_for_typename;
  4403.  
  4404.       if (got_scope)
  4405.     type = got_scope;
  4406.       else if (got_object != error_mark_node)
  4407.     type = got_object;
  4408.       
  4409.       if (type)
  4410.     {
  4411.       if (type == error_mark_node)
  4412.         return error_mark_node;
  4413.       else if (type == void_type_node)
  4414.         val = IDENTIFIER_GLOBAL_VALUE (name);
  4415.       else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
  4416.            /* TFIXME -- don't do this for UPTs in new model.  */
  4417.            || TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  4418.         {
  4419.           if (prefer_type > 0)
  4420.         val = create_nested_upt (type, name);
  4421.           else
  4422.         val = NULL_TREE;
  4423.         }
  4424.       else if (TREE_CODE (type) == NAMESPACE_DECL)
  4425.         {
  4426.           val = lookup_namespace_name (type, name);
  4427.         }
  4428.       else if (! IS_AGGR_TYPE (type))
  4429.         /* Someone else will give an error about this if needed. */
  4430.         val = NULL_TREE;
  4431.       else if (TYPE_BEING_DEFINED (type))
  4432.         {
  4433.           val = IDENTIFIER_CLASS_VALUE (name);
  4434.           if (val && DECL_CONTEXT (val) != type)
  4435.         {
  4436.           struct binding_level *b = class_binding_level;
  4437.           for (val = NULL_TREE; b; b = b->level_chain)
  4438.             {
  4439.               tree t = purpose_member (name, b->class_shadowed);
  4440.               if (t && TREE_VALUE (t)
  4441.               && DECL_CONTEXT (TREE_VALUE (t)) == type)
  4442.             {
  4443.               val = TREE_VALUE (t);
  4444.               break;
  4445.             }
  4446.             }
  4447.         }
  4448.           if (val == NULL_TREE
  4449.           && CLASSTYPE_LOCAL_TYPEDECLS (type))
  4450.         val = lookup_field (type, name, 0, 1);
  4451.         }
  4452.       else if (type == current_class_type)
  4453.         val = IDENTIFIER_CLASS_VALUE (name);
  4454.       else
  4455.         val = lookup_field (type, name, 0, prefer_type);
  4456.     }
  4457.       else
  4458.     val = NULL_TREE;
  4459.  
  4460.       if (got_scope)
  4461.     goto done;
  4462.  
  4463.       /* This special lookup only applies to types.  */
  4464.       else if (got_object && val && TREE_CODE (val) == TYPE_DECL)
  4465.     from_obj = val;
  4466.     }
  4467.     
  4468.   if (current_binding_level != global_binding_level
  4469.       && IDENTIFIER_LOCAL_VALUE (name))
  4470.     val = IDENTIFIER_LOCAL_VALUE (name);
  4471.   /* In C++ class fields are between local and global scope,
  4472.      just before the global scope.  */
  4473.   else if (current_class_type != NULL_TREE && ! nonclass)
  4474.     {
  4475.       val = IDENTIFIER_CLASS_VALUE (name);
  4476.       if (val == NULL_TREE
  4477.       && TYPE_BEING_DEFINED (current_class_type)
  4478.       && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  4479.     /* Try to find values from base classes if we are presently
  4480.        defining a type.  We are presently only interested in
  4481.        TYPE_DECLs.  */
  4482.     val = lookup_field (current_class_type, name, 0, 1);
  4483.  
  4484.       /* yylex() calls this with -2, since we should never start digging for
  4485.      the nested name at the point where we haven't even, for example,
  4486.      created the COMPONENT_REF or anything like that.  */
  4487.       if (val == NULL_TREE)
  4488.     val = lookup_nested_field (name, ! yylex);
  4489.  
  4490.       if (val == NULL_TREE)
  4491.     val = IDENTIFIER_GLOBAL_VALUE (name);
  4492.     }
  4493.   else
  4494.     val = IDENTIFIER_GLOBAL_VALUE (name);
  4495.  
  4496.  done:
  4497.   if (val)
  4498.     {
  4499.       if (from_obj && from_obj != val)
  4500.     cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope",
  4501.           got_object);
  4502.  
  4503.       if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
  4504.       || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
  4505.     ;
  4506.       else if (IDENTIFIER_HAS_TYPE_VALUE (name))
  4507.     val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
  4508.       else if (TREE_TYPE (val) == error_mark_node)
  4509.     val = error_mark_node;
  4510.     }
  4511.   else if (from_obj)
  4512.     val = from_obj;
  4513.  
  4514.   return val;
  4515. }
  4516.  
  4517. tree
  4518. lookup_name_nonclass (name)
  4519.      tree name;
  4520. {
  4521.   return lookup_name_real (name, 0, 1);
  4522. }
  4523.  
  4524. tree
  4525. lookup_name (name, prefer_type)
  4526.      tree name;
  4527.      int prefer_type;
  4528. {
  4529.   return lookup_name_real (name, prefer_type, 0);
  4530. }
  4531.  
  4532. /* Similar to `lookup_name' but look only at current binding level.  */
  4533.  
  4534. tree
  4535. lookup_name_current_level (name)
  4536.      tree name;
  4537. {
  4538.   register tree t = NULL_TREE;
  4539.  
  4540.   if (current_binding_level == global_binding_level)
  4541.     {
  4542.       t = IDENTIFIER_GLOBAL_VALUE (name);
  4543.  
  4544.       /* extern "C" function() */
  4545.       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
  4546.     t = TREE_VALUE (t);
  4547.     }
  4548.   else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
  4549.     {
  4550.       struct binding_level *b = current_binding_level;
  4551.       while (1)
  4552.     {
  4553.       for (t = b->names; t; t = TREE_CHAIN (t))
  4554.         if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name)
  4555.           goto out;
  4556.       if (b->keep == 2)
  4557.         b = b->level_chain;
  4558.       else
  4559.         break;
  4560.     }
  4561.     out:
  4562.       ;
  4563.     }
  4564.  
  4565.   return t;
  4566. }
  4567.  
  4568. /* Arrange for the user to get a source line number, even when the
  4569.    compiler is going down in flames, so that she at least has a
  4570.    chance of working around problems in the compiler.  We used to
  4571.    call error(), but that let the segmentation fault continue
  4572.    through; now, it's much more passive by asking them to send the
  4573.    maintainers mail about the problem.  */
  4574.  
  4575. static void
  4576. signal_catch (sig)
  4577.      int sig;
  4578. {
  4579.   signal (SIGSEGV, SIG_DFL);
  4580. #ifdef SIGIOT
  4581.   signal (SIGIOT, SIG_DFL);
  4582. #endif
  4583. #ifdef SIGILL
  4584.   signal (SIGILL, SIG_DFL);
  4585. #endif
  4586. #ifdef SIGABRT
  4587.   signal (SIGABRT, SIG_DFL);
  4588. #endif
  4589. #ifdef SIGBUS
  4590.   signal (SIGBUS, SIG_DFL);
  4591. #endif
  4592.   my_friendly_abort (0);
  4593. }
  4594.  
  4595. /* Array for holding types considered "built-in".  These types
  4596.    are output in the module in which `main' is defined.  */
  4597. static tree *builtin_type_tdescs_arr;
  4598. static int builtin_type_tdescs_len, builtin_type_tdescs_max;
  4599.  
  4600. /* Push the declarations of builtin types into the namespace.
  4601.    RID_INDEX, if < RID_MAX is the index of the builtin type
  4602.    in the array RID_POINTERS.  NAME is the name used when looking
  4603.    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
  4604.  
  4605. static void
  4606. record_builtin_type (rid_index, name, type)
  4607.      enum rid rid_index;
  4608.      char *name;
  4609.      tree type;
  4610. {
  4611.   tree rname = NULL_TREE, tname = NULL_TREE;
  4612.   tree tdecl;
  4613.  
  4614.   if ((int) rid_index < (int) RID_MAX)
  4615.     rname = ridpointers[(int) rid_index];
  4616.   if (name)
  4617.     tname = get_identifier (name);
  4618.  
  4619.   TYPE_BUILT_IN (type) = 1;
  4620.   
  4621.   if (tname)
  4622.     {
  4623. #if 0 /* not yet, should get fixed properly later */
  4624.       tdecl = pushdecl (make_type_decl (tname, type));
  4625. #else
  4626.       tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
  4627. #endif
  4628.       set_identifier_type_value (tname, NULL_TREE);
  4629.       if ((int) rid_index < (int) RID_MAX)
  4630.     IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
  4631.     }
  4632.   if (rname != NULL_TREE)
  4633.     {
  4634.       if (tname != NULL_TREE)
  4635.     {
  4636.       set_identifier_type_value (rname, NULL_TREE);
  4637.       IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
  4638.     }
  4639.       else
  4640.     {
  4641. #if 0 /* not yet, should get fixed properly later */
  4642.       tdecl = pushdecl (make_type_decl (rname, type));
  4643. #else
  4644.       tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
  4645. #endif
  4646.       set_identifier_type_value (rname, NULL_TREE);
  4647.     }
  4648.     }
  4649.  
  4650.   if (flag_rtti)
  4651.     {
  4652.       if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
  4653.     {
  4654.       builtin_type_tdescs_max *= 2;
  4655.       builtin_type_tdescs_arr
  4656.         = (tree *)xrealloc (builtin_type_tdescs_arr,
  4657.                 builtin_type_tdescs_max * sizeof (tree));
  4658.     }
  4659.       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
  4660.       if (TREE_CODE (type) != POINTER_TYPE)
  4661.     {
  4662.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4663.         = build_pointer_type (type);
  4664.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4665.         = build_pointer_type (build_type_variant (type, 1, 0));
  4666.     }
  4667.       if (TREE_CODE (type) != VOID_TYPE)
  4668.     {
  4669.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4670.         = build_reference_type (type);
  4671.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4672.         = build_reference_type (build_type_variant (type, 1, 0));
  4673.     }
  4674.     }
  4675. }
  4676.  
  4677. static void
  4678. output_builtin_tdesc_entries ()
  4679. {
  4680.   extern struct obstack permanent_obstack;
  4681.  
  4682.   /* If there's more than one main in this file, don't crash.  */
  4683.   if (builtin_type_tdescs_arr == 0)
  4684.     return;
  4685.  
  4686.   push_obstacks (&permanent_obstack, &permanent_obstack);
  4687.   while (builtin_type_tdescs_len > 0)
  4688.     {
  4689.       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
  4690.       tree tdesc = build_t_desc (type, 0);
  4691.       TREE_ASM_WRITTEN (tdesc) = 0;
  4692.       build_t_desc (type, 2);
  4693.     }
  4694.   free (builtin_type_tdescs_arr);
  4695.   builtin_type_tdescs_arr = 0;
  4696.   pop_obstacks ();
  4697. }
  4698.  
  4699. /* Push overloaded decl, in global scope, with one argument so it
  4700.    can be used as a callback from define_function.  */
  4701. static void
  4702. push_overloaded_decl_1 (x)
  4703.      tree x;
  4704. {
  4705.   push_overloaded_decl (x, 0);
  4706. }
  4707.  
  4708. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  4709.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  4710.  
  4711. #ifdef __GNUC__
  4712. __inline
  4713. #endif
  4714. tree auto_function (name, type, code)
  4715.      tree name, type;
  4716.      enum built_in_function code;
  4717. {
  4718.   return define_function
  4719.     (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1,
  4720.      IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type),
  4721.                           0)));
  4722. }
  4723.  
  4724. /* Create the predefined scalar types of C,
  4725.    and some nodes representing standard constants (0, 1, (void *)0).
  4726.    Initialize the global binding level.
  4727.    Make definitions for built-in primitive functions.  */
  4728.  
  4729. void
  4730. init_decl_processing ()
  4731. {
  4732.   tree decl;
  4733.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  4734.   tree fields[20];
  4735.   /* Either char* or void*.  */
  4736.   tree traditional_ptr_type_node;
  4737.   /* Data type of memcpy.  */
  4738.   tree memcpy_ftype;
  4739. #if 0 /* Not yet.  */
  4740.   /* Data type of strncpy.  */
  4741.   tree strncpy_ftype;
  4742. #endif
  4743.   int wchar_type_size;
  4744.   tree temp;
  4745.   tree array_domain_type;
  4746.   extern int flag_strict_prototype;
  4747.  
  4748.   /* Have to make these distinct before we try using them.  */
  4749.   lang_name_cplusplus = get_identifier ("C++");
  4750.   lang_name_c = get_identifier ("C");
  4751. #ifdef OBJCPLUS
  4752.   lang_name_objc = get_identifier ("Objective-C");
  4753. #endif
  4754.  
  4755.   if (flag_strict_prototype == 2)
  4756.     {
  4757.       if (pedantic)
  4758.     strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
  4759.     }
  4760.   else
  4761.     strict_prototypes_lang_c = flag_strict_prototype;
  4762.  
  4763.   /* Initially, C.  */
  4764.   current_lang_name = lang_name_c;
  4765.  
  4766.   current_function_decl = NULL_TREE;
  4767.   named_labels = NULL_TREE;
  4768.   named_label_uses = NULL_TREE;
  4769.   current_binding_level = NULL_BINDING_LEVEL;
  4770.   free_binding_level = NULL_BINDING_LEVEL;
  4771.  
  4772.   /* Because most segmentation signals can be traced back into user
  4773.      code, catch them and at least give the user a chance of working
  4774.      around compiler bugs. */
  4775.   signal (SIGSEGV, signal_catch);
  4776.  
  4777.   /* We will also catch aborts in the back-end through signal_catch and
  4778.      give the user a chance to see where the error might be, and to defeat
  4779.      aborts in the back-end when there have been errors previously in their
  4780.      code. */
  4781. #ifdef SIGIOT
  4782.   signal (SIGIOT, signal_catch);
  4783. #endif
  4784. #ifdef SIGILL
  4785.   signal (SIGILL, signal_catch);
  4786. #endif
  4787. #ifdef SIGABRT
  4788.   signal (SIGABRT, signal_catch);
  4789. #endif
  4790. #ifdef SIGBUS
  4791.   signal (SIGBUS, signal_catch);
  4792. #endif
  4793.  
  4794.   gcc_obstack_init (&decl_obstack);
  4795.   if (flag_rtti)
  4796.     {
  4797.       builtin_type_tdescs_max = 100;
  4798.       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
  4799.     }
  4800.  
  4801.   /* Must lay these out before anything else gets laid out.  */
  4802.   error_mark_node = make_node (ERROR_MARK);
  4803.   TREE_PERMANENT (error_mark_node) = 1;
  4804.   TREE_TYPE (error_mark_node) = error_mark_node;
  4805.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  4806.   TREE_TYPE (error_mark_list) = error_mark_node;
  4807.  
  4808.   /* Make the binding_level structure for global names.  */
  4809.   pushlevel (0);
  4810.   global_binding_level = current_binding_level;
  4811.  
  4812.   this_identifier = get_identifier (THIS_NAME);
  4813.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  4814.   pfn_identifier = get_identifier (VTABLE_PFN_NAME);
  4815.   index_identifier = get_identifier (VTABLE_INDEX_NAME);
  4816.   delta_identifier = get_identifier (VTABLE_DELTA_NAME);
  4817.   delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
  4818.   pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
  4819.   if (flag_handle_signatures)
  4820.     {
  4821.       tag_identifier = get_identifier (SIGTABLE_TAG_NAME);
  4822.       vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME);
  4823.       vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME);
  4824.     }
  4825.  
  4826.   /* Define `int' and `char' first so that dbx will output them first.  */
  4827.  
  4828.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  4829.   record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
  4830.  
  4831.   /* Define `char', which is like either `signed char' or `unsigned char'
  4832.      but not the same as either.  */
  4833.  
  4834.   char_type_node =
  4835.     (flag_signed_char
  4836.      ? make_signed_type (CHAR_TYPE_SIZE)
  4837.      : make_unsigned_type (CHAR_TYPE_SIZE));
  4838.   record_builtin_type (RID_CHAR, "char", char_type_node);
  4839.  
  4840.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  4841.   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
  4842.  
  4843.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  4844.   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
  4845.  
  4846.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  4847.   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
  4848.   record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
  4849.  
  4850.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  4851.   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
  4852.  
  4853.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  4854.   record_builtin_type (RID_MAX, "long long unsigned int",
  4855.                long_long_unsigned_type_node);
  4856.   record_builtin_type (RID_MAX, "long long unsigned",
  4857.                long_long_unsigned_type_node);
  4858.  
  4859.   /* `unsigned long' is the standard type for sizeof.
  4860.      Traditionally, use a signed type.
  4861.      Note that stddef.h uses `unsigned long',
  4862.      and this must agree, even of long and int are the same size.  */
  4863.   sizetype
  4864.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
  4865.   if (flag_traditional && TREE_UNSIGNED (sizetype))
  4866.     sizetype = signed_type (sizetype);
  4867.  
  4868.   ptrdiff_type_node
  4869.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
  4870.  
  4871.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  4872.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  4873.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  4874.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  4875.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  4876.   TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
  4877.   TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
  4878.  
  4879.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  4880.   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
  4881.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  4882.   record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
  4883.   record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
  4884.  
  4885.   /* Define both `signed char' and `unsigned char'.  */
  4886.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  4887.   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
  4888.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  4889.   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
  4890.  
  4891.   /* These are types that type_for_size and type_for_mode use.  */
  4892.   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
  4893.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
  4894.   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
  4895.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
  4896.   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
  4897.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
  4898.   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
  4899.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
  4900.   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
  4901.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
  4902.   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
  4903.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
  4904.   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
  4905.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
  4906.   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
  4907.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
  4908.  
  4909.   float_type_node = make_node (REAL_TYPE);
  4910.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  4911.   record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
  4912.   layout_type (float_type_node);
  4913.  
  4914.   double_type_node = make_node (REAL_TYPE);
  4915.   if (flag_short_double)
  4916.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  4917.   else
  4918.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  4919.   record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
  4920.   layout_type (double_type_node);
  4921.  
  4922.   long_double_type_node = make_node (REAL_TYPE);
  4923.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  4924.   record_builtin_type (RID_MAX, "long double", long_double_type_node);
  4925.   layout_type (long_double_type_node);
  4926.  
  4927.   integer_zero_node = build_int_2 (0, 0);
  4928.   TREE_TYPE (integer_zero_node) = integer_type_node;
  4929.   integer_one_node = build_int_2 (1, 0);
  4930.   TREE_TYPE (integer_one_node) = integer_type_node;
  4931.   integer_two_node = build_int_2 (2, 0);
  4932.   TREE_TYPE (integer_two_node) = integer_type_node;
  4933.   integer_three_node = build_int_2 (3, 0);
  4934.   TREE_TYPE (integer_three_node) = integer_type_node;
  4935.  
  4936.   boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
  4937.   TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
  4938.   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
  4939.   boolean_false_node = build_int_2 (0, 0);
  4940.   TREE_TYPE (boolean_false_node) = boolean_type_node;
  4941.   boolean_true_node = build_int_2 (1, 0);
  4942.   TREE_TYPE (boolean_true_node) = boolean_type_node;
  4943.  
  4944.   /* These are needed by stor-layout.c.  */
  4945.   size_zero_node = size_int (0);
  4946.   size_one_node = size_int (1);
  4947.  
  4948.   void_type_node = make_node (VOID_TYPE);
  4949.   record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
  4950.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  4951.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  4952.   TREE_PARMLIST (void_list_node) = 1;
  4953.  
  4954.   null_pointer_node = build_int_2 (0, 0);
  4955.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  4956.   layout_type (TREE_TYPE (null_pointer_node));
  4957.  
  4958.   /* Used for expressions that do nothing, but are not errors.  */
  4959.   void_zero_node = build_int_2 (0, 0);
  4960.   TREE_TYPE (void_zero_node) = void_type_node;
  4961.  
  4962.   string_type_node = build_pointer_type (char_type_node);
  4963.   const_string_type_node =
  4964.     build_pointer_type (build_type_variant (char_type_node, 1, 0));
  4965.   record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
  4966.  
  4967.   /* Make a type to be the domain of a few array types
  4968.      whose domains don't really matter.
  4969.      200 is small enough that it always fits in size_t
  4970.      and large enough that it can hold most function names for the
  4971.      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
  4972.   array_domain_type = build_index_type (build_int_2 (200, 0));
  4973.  
  4974.   /* make a type for arrays of characters.
  4975.      With luck nothing will ever really depend on the length of this
  4976.      array type.  */
  4977.   char_array_type_node
  4978.     = build_array_type (char_type_node, array_domain_type);
  4979.   /* Likewise for arrays of ints.  */
  4980.   int_array_type_node
  4981.     = build_array_type (integer_type_node, array_domain_type);
  4982.  
  4983.   /* This is just some anonymous class type.  Nobody should ever
  4984.      need to look inside this envelope.  */
  4985.   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
  4986.  
  4987.   default_function_type
  4988.     = build_function_type (integer_type_node, NULL_TREE);
  4989.   build_pointer_type (default_function_type);
  4990.  
  4991.   ptr_type_node = build_pointer_type (void_type_node);
  4992.   const_ptr_type_node =
  4993.     build_pointer_type (build_type_variant (void_type_node, 1, 0));
  4994.   record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
  4995.   endlink = void_list_node;
  4996.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  4997.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  4998.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  4999.  
  5000.   double_ftype_double
  5001.     = build_function_type (double_type_node, double_endlink);
  5002.  
  5003.   double_ftype_double_double
  5004.     = build_function_type (double_type_node,
  5005.                tree_cons (NULL_TREE, double_type_node,
  5006.                       double_endlink));
  5007.  
  5008.   int_ftype_int
  5009.     = build_function_type (integer_type_node, int_endlink);
  5010.  
  5011.   long_ftype_long
  5012.     = build_function_type (long_integer_type_node,
  5013.                tree_cons (NULL_TREE, long_integer_type_node,
  5014.                       endlink));
  5015.  
  5016.   void_ftype_ptr_ptr_int
  5017.     = build_function_type (void_type_node,
  5018.                tree_cons (NULL_TREE, ptr_type_node,
  5019.                       tree_cons (NULL_TREE, ptr_type_node,
  5020.                          int_endlink)));
  5021.  
  5022.   int_ftype_cptr_cptr_sizet
  5023.     = build_function_type (integer_type_node,
  5024.                tree_cons (NULL_TREE, const_ptr_type_node,
  5025.                       tree_cons (NULL_TREE, const_ptr_type_node,
  5026.                          tree_cons (NULL_TREE,
  5027.                                 sizetype,
  5028.                                 endlink))));
  5029.  
  5030.   void_ftype_ptr_int_int
  5031.     = build_function_type (void_type_node,
  5032.                tree_cons (NULL_TREE, ptr_type_node,
  5033.                       tree_cons (NULL_TREE, integer_type_node,
  5034.                          int_endlink)));
  5035.  
  5036.   string_ftype_ptr_ptr        /* strcpy prototype */
  5037.     = build_function_type (string_type_node,
  5038.                tree_cons (NULL_TREE, string_type_node,
  5039.                       tree_cons (NULL_TREE,
  5040.                          const_string_type_node,
  5041.                          endlink)));
  5042.  
  5043. #if 0
  5044.   /* Not yet.  */
  5045.   strncpy_ftype            /* strncpy prototype */
  5046.     = build_function_type (string_type_node,
  5047.                tree_cons (NULL_TREE, string_type_node,
  5048.                       tree_cons (NULL_TREE, const_string_type_node,
  5049.                          tree_cons (NULL_TREE,
  5050.                                 sizetype,
  5051.                                 endlink))));
  5052. #endif
  5053.  
  5054.   int_ftype_string_string    /* strcmp prototype */
  5055.     = build_function_type (integer_type_node,
  5056.                tree_cons (NULL_TREE, const_string_type_node,
  5057.                       tree_cons (NULL_TREE,
  5058.                          const_string_type_node,
  5059.                          endlink)));
  5060.  
  5061.   sizet_ftype_string        /* strlen prototype */
  5062.     = build_function_type (sizetype,
  5063.                tree_cons (NULL_TREE, const_string_type_node,
  5064.                       endlink));
  5065.  
  5066.   traditional_ptr_type_node
  5067.     = (flag_traditional ? string_type_node : ptr_type_node);
  5068.  
  5069.   memcpy_ftype    /* memcpy prototype */
  5070.     = build_function_type (traditional_ptr_type_node,
  5071.                tree_cons (NULL_TREE, ptr_type_node,
  5072.                       tree_cons (NULL_TREE, const_ptr_type_node,
  5073.                          tree_cons (NULL_TREE,
  5074.                                 sizetype,
  5075.                                 endlink))));
  5076.  
  5077.   if (flag_huge_objects)
  5078.     delta_type_node = long_integer_type_node;
  5079.   else
  5080.     delta_type_node = short_integer_type_node;
  5081.  
  5082.   builtin_function ("__builtin_constant_p", int_ftype_int,
  5083.             BUILT_IN_CONSTANT_P, NULL_PTR);
  5084.  
  5085.   builtin_return_address_fndecl =
  5086.   builtin_function ("__builtin_return_address",
  5087.             build_function_type (ptr_type_node, 
  5088.                      tree_cons (NULL_TREE,
  5089.                             unsigned_type_node,
  5090.                             endlink)),
  5091.             BUILT_IN_RETURN_ADDRESS, NULL_PTR);
  5092.  
  5093.   builtin_function ("__builtin_frame_address",
  5094.             build_function_type (ptr_type_node, 
  5095.                      tree_cons (NULL_TREE,
  5096.                             unsigned_type_node,
  5097.                             endlink)),
  5098.             BUILT_IN_FRAME_ADDRESS, NULL_PTR);
  5099.  
  5100.  
  5101.   builtin_function ("__builtin_alloca",
  5102.             build_function_type (ptr_type_node,
  5103.                      tree_cons (NULL_TREE,
  5104.                             sizetype,
  5105.                             endlink)),
  5106.             BUILT_IN_ALLOCA, "alloca");
  5107.   /* Define alloca, ffs as builtins.
  5108.      Declare _exit just to mark it as volatile.  */
  5109.   if (! flag_no_builtin && !flag_no_nonansi_builtin)
  5110.     {
  5111.       temp = builtin_function ("alloca",
  5112.                    build_function_type (ptr_type_node,
  5113.                             tree_cons (NULL_TREE,
  5114.                                    sizetype,
  5115.                                    endlink)),
  5116.                    BUILT_IN_ALLOCA, NULL_PTR);
  5117.       /* Suppress error if redefined as a non-function.  */
  5118.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5119.       temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
  5120.       /* Suppress error if redefined as a non-function.  */
  5121.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5122.       temp = builtin_function ("_exit", build_function_type (void_type_node,
  5123.                                  int_endlink),
  5124.                    NOT_BUILT_IN, NULL_PTR);
  5125.       TREE_THIS_VOLATILE (temp) = 1;
  5126.       TREE_SIDE_EFFECTS (temp) = 1;
  5127.       /* Suppress error if redefined as a non-function.  */
  5128.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5129.     }
  5130.  
  5131.   builtin_function ("__builtin_abs", int_ftype_int,
  5132.             BUILT_IN_ABS, NULL_PTR);
  5133.   builtin_function ("__builtin_fabs", double_ftype_double,
  5134.             BUILT_IN_FABS, NULL_PTR);
  5135.   builtin_function ("__builtin_labs", long_ftype_long,
  5136.             BUILT_IN_LABS, NULL_PTR);
  5137.   builtin_function ("__builtin_ffs", int_ftype_int,
  5138.             BUILT_IN_FFS, NULL_PTR);
  5139.   builtin_function ("__builtin_fsqrt", double_ftype_double,
  5140.             BUILT_IN_FSQRT, NULL_PTR);
  5141.   builtin_function ("__builtin_sin", double_ftype_double, 
  5142.             BUILT_IN_SIN, "sin");
  5143.   builtin_function ("__builtin_cos", double_ftype_double, 
  5144.             BUILT_IN_COS, "cos");
  5145.   builtin_function ("__builtin_saveregs",
  5146.             build_function_type (ptr_type_node, NULL_TREE),
  5147.             BUILT_IN_SAVEREGS, NULL_PTR);
  5148. /* EXPAND_BUILTIN_VARARGS is obsolete.  */
  5149. #if 0
  5150.   builtin_function ("__builtin_varargs",
  5151.             build_function_type (ptr_type_node,
  5152.                      tree_cons (NULL_TREE,
  5153.                             integer_type_node,
  5154.                             endlink)),
  5155.             BUILT_IN_VARARGS, NULL_PTR);
  5156. #endif
  5157.   builtin_function ("__builtin_classify_type", default_function_type,
  5158.             BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
  5159.   builtin_function ("__builtin_next_arg",
  5160.             build_function_type (ptr_type_node, NULL_TREE),
  5161.             BUILT_IN_NEXT_ARG, NULL_PTR);
  5162.   builtin_function ("__builtin_args_info",
  5163.             build_function_type (integer_type_node,
  5164.                      tree_cons (NULL_TREE,
  5165.                             integer_type_node,
  5166.                             endlink)),
  5167.             BUILT_IN_ARGS_INFO, NULL_PTR);
  5168.  
  5169.   /* Untyped call and return.  */
  5170.   builtin_function ("__builtin_apply_args",
  5171.             build_function_type (ptr_type_node, NULL_TREE),
  5172.             BUILT_IN_APPLY_ARGS, NULL_PTR);
  5173.  
  5174.   temp = tree_cons (NULL_TREE,
  5175.             build_pointer_type (build_function_type (void_type_node,
  5176.                                  NULL_TREE)),
  5177.             tree_cons (NULL_TREE,
  5178.                    ptr_type_node,
  5179.                    tree_cons (NULL_TREE,
  5180.                       sizetype,
  5181.                       endlink)));
  5182.   builtin_function ("__builtin_apply",
  5183.             build_function_type (ptr_type_node, temp),
  5184.             BUILT_IN_APPLY, NULL_PTR);
  5185.   builtin_function ("__builtin_return",
  5186.             build_function_type (void_type_node,
  5187.                      tree_cons (NULL_TREE,
  5188.                             ptr_type_node,
  5189.                             endlink)),
  5190.             BUILT_IN_RETURN, NULL_PTR);
  5191.  
  5192.   /* Currently under experimentation.  */
  5193.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  5194.             BUILT_IN_MEMCPY, "memcpy");
  5195.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  5196.             BUILT_IN_MEMCMP, "memcmp");
  5197.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  5198.             BUILT_IN_STRCMP, "strcmp");
  5199.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  5200.             BUILT_IN_STRCPY, "strcpy");
  5201. #if 0
  5202.   /* Not yet.  */
  5203.   builtin_function ("__builtin_strncpy", strncpy_ftype,
  5204.             BUILT_IN_STRNCPY, "strncpy");
  5205. #endif
  5206.   builtin_function ("__builtin_strlen", sizet_ftype_string,
  5207.             BUILT_IN_STRLEN, "strlen");
  5208.  
  5209.   if (!flag_no_builtin)
  5210.     {
  5211. #if 0 /* These do not work well with libg++.  */
  5212.       builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
  5213.       builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
  5214.       builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
  5215. #endif
  5216.       builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
  5217.       builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
  5218.             NULL_PTR);
  5219.       builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
  5220.       builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
  5221.             NULL_PTR);
  5222. #if 0
  5223.       /* Not yet.  */
  5224.       builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
  5225. #endif
  5226.       builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
  5227.       builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
  5228.       builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
  5229.  
  5230.       /* Declare these functions volatile
  5231.      to avoid spurious "control drops through" warnings.  */
  5232.       temp = builtin_function ("abort",
  5233.                    build_function_type (void_type_node, endlink),
  5234.                    NOT_BUILT_IN, NULL_PTR);
  5235.       TREE_THIS_VOLATILE (temp) = 1;
  5236.       TREE_SIDE_EFFECTS (temp) = 1;
  5237.       /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
  5238.          them...  */
  5239.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5240.       temp = builtin_function ("exit", build_function_type (void_type_node,
  5241.                                 int_endlink),
  5242.                    NOT_BUILT_IN, NULL_PTR);
  5243.       TREE_THIS_VOLATILE (temp) = 1;
  5244.       TREE_SIDE_EFFECTS (temp) = 1;
  5245.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5246.     }
  5247.  
  5248. #if 0
  5249.   /* Support for these has not been written in either expand_builtin
  5250.      or build_function_call.  */
  5251.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
  5252.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
  5253.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
  5254.             0);
  5255.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
  5256.   builtin_function ("__builtin_fmod", double_ftype_double_double,
  5257.             BUILT_IN_FMOD, 0);
  5258.   builtin_function ("__builtin_frem", double_ftype_double_double,
  5259.             BUILT_IN_FREM, 0);
  5260.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
  5261.             0);
  5262.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
  5263.             0);
  5264.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
  5265.             0);
  5266. #endif
  5267.  
  5268.   /* C++ extensions */
  5269.  
  5270.   unknown_type_node = make_node (UNKNOWN_TYPE);
  5271. #if 0 /* not yet, should get fixed properly later */
  5272.   pushdecl (make_type_decl (get_identifier ("unknown type"),
  5273.                unknown_type_node));
  5274. #else
  5275.   decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
  5276.             unknown_type_node));
  5277.   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
  5278.   DECL_IGNORED_P (decl) = 1;
  5279.   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
  5280. #endif
  5281.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  5282.   TYPE_ALIGN (unknown_type_node) = 1;
  5283.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  5284.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  5285.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  5286.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
  5287.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  5288.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  5289.  
  5290.   /* This is for handling opaque types in signatures.  */
  5291.   opaque_type_node = copy_node (ptr_type_node);
  5292.   TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
  5293.   record_builtin_type (RID_MAX, 0, opaque_type_node);
  5294.  
  5295.   /* This is special for C++ so functions can be overloaded. */
  5296.   wchar_type_node
  5297.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
  5298.   wchar_type_size = TYPE_PRECISION (wchar_type_node);
  5299.   signed_wchar_type_node = make_signed_type (wchar_type_size);
  5300.   unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
  5301.   wchar_type_node
  5302.     = TREE_UNSIGNED (wchar_type_node)
  5303.       ? unsigned_wchar_type_node
  5304.       : signed_wchar_type_node;
  5305.   record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
  5306.  
  5307.   /* Artificial declaration of wchar_t -- can be bashed */
  5308.   wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
  5309.                 wchar_type_node);
  5310.   pushdecl (wchar_decl_node);
  5311.  
  5312.   /* This is for wide string constants.  */
  5313.   wchar_array_type_node
  5314.     = build_array_type (wchar_type_node, array_domain_type);
  5315.  
  5316.   /* This is a hack that should go away when we deliver the
  5317.      real gc code.  */
  5318.   if (flag_gc)
  5319.     {
  5320.       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
  5321.       pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
  5322.     }
  5323.  
  5324.   if (flag_vtable_thunks)
  5325.     {
  5326.       /* Make sure we get a unique function type, so we can give
  5327.      its pointer type a name.  (This wins for gdb.) */
  5328.       tree vfunc_type = make_node (FUNCTION_TYPE);
  5329.       TREE_TYPE (vfunc_type) = integer_type_node;
  5330.       TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
  5331.       layout_type (vfunc_type);
  5332.  
  5333.       vtable_entry_type = build_pointer_type (vfunc_type);
  5334.     }
  5335.   else
  5336.     {
  5337.       vtable_entry_type = make_lang_type (RECORD_TYPE);
  5338.       fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  5339.                      delta_type_node);
  5340.       fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  5341.                      delta_type_node);
  5342.       fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
  5343.                      ptr_type_node);
  5344.       finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
  5345.                double_type_node);
  5346.  
  5347.       /* Make this part of an invisible union.  */
  5348.       fields[3] = copy_node (fields[2]);
  5349.       TREE_TYPE (fields[3]) = delta_type_node;
  5350.       DECL_NAME (fields[3]) = delta2_identifier;
  5351.       DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
  5352.       DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
  5353.       TREE_UNSIGNED (fields[3]) = 0;
  5354.       TREE_CHAIN (fields[2]) = fields[3];
  5355.       vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  5356.     }
  5357.   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
  5358.  
  5359.   vtbl_type_node
  5360.     = build_array_type (vtable_entry_type, NULL_TREE);
  5361.   layout_type (vtbl_type_node);
  5362.   vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
  5363.   record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
  5364.  
  5365.   /* Simplify life by making a "sigtable_entry_type".  Give its
  5366.      fields names so that the debugger can use them.  */
  5367.  
  5368.   if (flag_handle_signatures)
  5369.     {
  5370.       sigtable_entry_type = make_lang_type (RECORD_TYPE);
  5371.       fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier,
  5372.                      delta_type_node);
  5373.       fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier,
  5374.                      delta_type_node);
  5375.       fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  5376.                      delta_type_node);
  5377.       fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier,
  5378.                      delta_type_node);
  5379.       fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
  5380.                      ptr_type_node);
  5381.  
  5382.       /* Set the alignment to the max of the alignment of ptr_type_node and
  5383.      delta_type_node.  Double alignment wastes a word on the Sparc.  */
  5384.       finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4,
  5385.                (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node))
  5386.                ? ptr_type_node
  5387.                : delta_type_node);
  5388.  
  5389.       /* Make this part of an invisible union.  */
  5390.       fields[5] = copy_node (fields[4]);
  5391.       TREE_TYPE (fields[5]) = delta_type_node;
  5392.       DECL_NAME (fields[5]) = vt_off_identifier;
  5393.       DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node);
  5394.       DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node);
  5395.       TREE_UNSIGNED (fields[5]) = 0;
  5396.       TREE_CHAIN (fields[4]) = fields[5];
  5397.  
  5398.       sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
  5399.       record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
  5400.     }
  5401.  
  5402. #if 0
  5403.   if (flag_rtti)
  5404.     {
  5405.       /* Must build __t_desc type.  Currently, type descriptors look like this:
  5406.  
  5407.      struct __t_desc
  5408.      {
  5409.            const char *name;
  5410.        int size;
  5411.        int bits;
  5412.        struct __t_desc *points_to;
  5413.        int ivars_count, meths_count;
  5414.        struct __i_desc *ivars[];
  5415.        struct __m_desc *meths[];
  5416.        struct __t_desc *parents[];
  5417.        struct __t_desc *vbases[];
  5418.        int offsets[];
  5419.      };
  5420.  
  5421.      ...as per Linton's paper.  */
  5422.  
  5423.       __t_desc_type_node = make_lang_type (RECORD_TYPE);
  5424.       __i_desc_type_node = make_lang_type (RECORD_TYPE);
  5425.       __m_desc_type_node = make_lang_type (RECORD_TYPE);
  5426.       __t_desc_array_type =
  5427.     build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE);
  5428.       __i_desc_array_type =
  5429.     build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE);
  5430.       __m_desc_array_type =
  5431.     build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE);
  5432.  
  5433.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5434.                      string_type_node);
  5435.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
  5436.                      unsigned_type_node);
  5437.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
  5438.                      unsigned_type_node);
  5439.       fields[3] = build_lang_field_decl (FIELD_DECL,
  5440.                      get_identifier ("points_to"),
  5441.                      build_pointer_type (__t_desc_type_node));
  5442.       fields[4] = build_lang_field_decl (FIELD_DECL,
  5443.                      get_identifier ("ivars_count"),
  5444.                      integer_type_node);
  5445.       fields[5] = build_lang_field_decl (FIELD_DECL,
  5446.                      get_identifier ("meths_count"),
  5447.                      integer_type_node);
  5448.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
  5449.                      build_pointer_type (__i_desc_array_type));
  5450.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
  5451.                      build_pointer_type (__m_desc_array_type));
  5452.       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
  5453.                      build_pointer_type (__t_desc_array_type));
  5454.       fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
  5455.                      build_pointer_type (__t_desc_array_type));
  5456.       fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
  5457.                      build_pointer_type (integer_type_node));
  5458.       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
  5459.  
  5460.       /* ivar descriptors look like this:
  5461.  
  5462.      struct __i_desc
  5463.      {
  5464.        const char *name;
  5465.        int offset;
  5466.        struct __t_desc *type;
  5467.      };
  5468.       */
  5469.  
  5470.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5471.                      string_type_node);
  5472.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
  5473.                      integer_type_node);
  5474.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
  5475.                      build_pointer_type (__t_desc_type_node));
  5476.       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
  5477.                integer_type_node);
  5478.  
  5479.       /* method descriptors look like this:
  5480.  
  5481.      struct __m_desc
  5482.      {
  5483.        const char *name;
  5484.        int vindex;
  5485.        struct __t_desc *vcontext;
  5486.        struct __t_desc *return_type;
  5487.        void (*address)();
  5488.        short parm_count;
  5489.        short required_parms;
  5490.        struct __t_desc *parm_types[];
  5491.      };
  5492.       */
  5493.  
  5494.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5495.                      string_type_node);
  5496.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
  5497.                      integer_type_node);
  5498.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
  5499.                      build_pointer_type (__t_desc_type_node));
  5500.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
  5501.                      build_pointer_type (__t_desc_type_node));
  5502.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
  5503.                      build_pointer_type (default_function_type));
  5504.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
  5505.                      short_integer_type_node);
  5506.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
  5507.                      short_integer_type_node);
  5508.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
  5509.                      build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE)));
  5510.       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
  5511.                integer_type_node);
  5512.     }
  5513.  
  5514.   if (flag_rtti)
  5515.     {
  5516.       int i = builtin_type_tdescs_len;
  5517.       while (i > 0)
  5518.     {
  5519.       tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
  5520.       TREE_ASM_WRITTEN (tdesc) = 1;
  5521.       TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
  5522.     }
  5523.     }
  5524. #endif /*flag_rtti*/
  5525.  
  5526.   /* Now, C++.  */
  5527.   current_lang_name = lang_name_cplusplus;
  5528.  
  5529.   auto_function (ansi_opname[(int) NEW_EXPR],
  5530.          build_function_type (ptr_type_node,
  5531.                       tree_cons (NULL_TREE, sizetype,
  5532.                          void_list_node)),
  5533.          NOT_BUILT_IN);
  5534.   auto_function (ansi_opname[(int) VEC_NEW_EXPR],
  5535.          build_function_type (ptr_type_node,
  5536.                       tree_cons (NULL_TREE, sizetype,
  5537.                          void_list_node)),
  5538.          NOT_BUILT_IN);
  5539.   auto_function (ansi_opname[(int) DELETE_EXPR],
  5540.          build_function_type (void_type_node,
  5541.                       tree_cons (NULL_TREE, ptr_type_node,
  5542.                          void_list_node)),
  5543.          NOT_BUILT_IN);
  5544.   auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
  5545.          build_function_type (void_type_node,
  5546.                       tree_cons (NULL_TREE, ptr_type_node,
  5547.                          void_list_node)),
  5548.          NOT_BUILT_IN);
  5549.  
  5550.   abort_fndecl
  5551.     = define_function ("__pure_virtual",
  5552.                build_function_type (void_type_node, void_list_node),
  5553.                NOT_BUILT_IN, 0, 0);
  5554.  
  5555.   /* Perform other language dependent initializations.  */
  5556.   init_class_processing ();
  5557.   init_init_processing ();
  5558.   init_search_processing ();
  5559.  
  5560.   if (flag_handle_exceptions)
  5561.     init_exception_processing ();
  5562.   if (flag_gc)
  5563.     init_gc_processing ();
  5564.   if (flag_no_inline)
  5565.     {
  5566.       flag_inline_functions = 0;
  5567. #if 0
  5568.       /* This causes unnecessary emission of inline functions.  */
  5569.       flag_default_inline = 0;
  5570. #endif
  5571.     }
  5572.   if (flag_cadillac)
  5573.     init_cadillac ();
  5574.  
  5575.   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
  5576.   declare_function_name ();
  5577.  
  5578.   /* Prepare to check format strings against argument lists.  */
  5579.   init_function_format_info ();
  5580. }
  5581.  
  5582. /* initialize type descriptor type node of various rtti type. */
  5583.  
  5584. int
  5585. init_type_desc()
  5586. {
  5587.   tree tdecl;
  5588.  
  5589.   tdecl = lookup_name (get_identifier ("type_info"), 0);
  5590.   if (tdecl == NULL_TREE)
  5591.     return 0;
  5592.   __t_desc_type_node = TREE_TYPE(tdecl);
  5593.   __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
  5594.  
  5595. #if 0
  5596.   tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
  5597.   if (tdecl == NULL_TREE)
  5598.     return 0;
  5599.   __baselist_desc_type_node = TREE_TYPE (tdecl);
  5600. #endif
  5601.  
  5602.   tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
  5603.   if (tdecl == NULL_TREE)
  5604.     return 0;
  5605.   __bltn_desc_type_node = TREE_TYPE (tdecl);
  5606.  
  5607.   tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
  5608.   if (tdecl == NULL_TREE)
  5609.     return 0;
  5610.   __user_desc_type_node = TREE_TYPE (tdecl);
  5611.  
  5612.   tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
  5613.   if (tdecl == NULL_TREE)
  5614.     return 0;
  5615.   __class_desc_type_node = TREE_TYPE (tdecl);
  5616.  
  5617.   tdecl = lookup_field (__class_desc_type_node, 
  5618.     get_identifier ("access_mode"), 0, 0);
  5619.   if (tdecl == NULL_TREE)
  5620.     return 0;
  5621.   __access_mode_type_node = TREE_TYPE (tdecl);
  5622.  
  5623.   tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
  5624.   if (tdecl == NULL_TREE)
  5625.     return 0;
  5626.   __attr_desc_type_node = TREE_TYPE (tdecl);
  5627.  
  5628.   tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
  5629.   if (tdecl == NULL_TREE)
  5630.     return 0;
  5631.   __ptr_desc_type_node = TREE_TYPE (tdecl);
  5632.  
  5633.   tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
  5634.   if (tdecl == NULL_TREE)
  5635.     return 0;
  5636.   __func_desc_type_node = TREE_TYPE (tdecl);
  5637.  
  5638.   tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
  5639.   if (tdecl == NULL_TREE)
  5640.     return 0;
  5641.   __ptmf_desc_type_node = TREE_TYPE (tdecl);
  5642.  
  5643.   tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
  5644.   if (tdecl == NULL_TREE)
  5645.     return 0;
  5646.   __ptmd_desc_type_node = TREE_TYPE (tdecl);
  5647.  
  5648.   return 1;
  5649. }
  5650. /* Make a definition for a builtin function named NAME and whose data type
  5651.    is TYPE.  TYPE should be a function type with argument types.
  5652.    FUNCTION_CODE tells later passes how to compile calls to this function.
  5653.    See tree.h for its possible values.
  5654.  
  5655.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  5656.    the name to be called if we can't opencode the function.  */
  5657.  
  5658. tree
  5659. define_function (name, type, function_code, pfn, library_name)
  5660.      char *name;
  5661.      tree type;
  5662.      enum built_in_function function_code;
  5663.      void (*pfn)();
  5664.      char *library_name;
  5665. {
  5666.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  5667.   DECL_EXTERNAL (decl) = 1;
  5668.   TREE_PUBLIC (decl) = 1;
  5669.   DECL_ARTIFICIAL (decl) = 1;
  5670.  
  5671.   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
  5672.      we cannot change DECL_ASSEMBLER_NAME until we have installed this
  5673.      function in the namespace.  */
  5674.   if (pfn) (*pfn) (decl);
  5675.   if (library_name)
  5676.     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
  5677.   make_function_rtl (decl);
  5678.   if (function_code != NOT_BUILT_IN)
  5679.     {
  5680.       DECL_BUILT_IN (decl) = 1;
  5681.       DECL_FUNCTION_CODE (decl) = function_code;
  5682.     }
  5683.   return decl;
  5684. }
  5685.  
  5686. /* Called when a declaration is seen that contains no names to declare.
  5687.    If its type is a reference to a structure, union or enum inherited
  5688.    from a containing scope, shadow that tag name for the current scope
  5689.    with a forward reference.
  5690.    If its type defines a new named structure or union
  5691.    or defines an enum, it is valid but we need not do anything here.
  5692.    Otherwise, it is an error.
  5693.  
  5694.    C++: may have to grok the declspecs to learn about static,
  5695.    complain for anonymous unions.  */
  5696.  
  5697. void
  5698. shadow_tag (declspecs)
  5699.      tree declspecs;
  5700. {
  5701.   int found_tag = 0;
  5702.   tree ob_modifier = NULL_TREE;
  5703.   register tree link;
  5704.   register enum tree_code code, ok_code = ERROR_MARK;
  5705.   register tree t = NULL_TREE;
  5706.  
  5707.   for (link = declspecs; link; link = TREE_CHAIN (link))
  5708.     {
  5709.       register tree value = TREE_VALUE (link);
  5710.  
  5711.       code = TREE_CODE (value);
  5712.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  5713.     {
  5714.       my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
  5715.  
  5716.       if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
  5717.         cp_error ("forward declaration of `%#T'", value);
  5718.  
  5719.       t = value;
  5720.       ok_code = code;
  5721.       found_tag++;
  5722.     }
  5723.       else if (value == ridpointers[(int) RID_STATIC]
  5724.            || value == ridpointers[(int) RID_EXTERN]
  5725.            || value == ridpointers[(int) RID_AUTO]
  5726.            || value == ridpointers[(int) RID_REGISTER]
  5727.            || value == ridpointers[(int) RID_INLINE]
  5728.            || value == ridpointers[(int) RID_VIRTUAL]
  5729.            || value == ridpointers[(int) RID_EXPLICIT])
  5730.     ob_modifier = value;
  5731.     }
  5732.  
  5733.   /* This is where the variables in an anonymous union are
  5734.      declared.  An anonymous union declaration looks like:
  5735.      union { ... } ;
  5736.      because there is no declarator after the union, the parser
  5737.      sends that declaration here.  */
  5738.   if (ok_code == UNION_TYPE
  5739.       && t != NULL_TREE
  5740.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  5741.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  5742.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  5743.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
  5744.     {
  5745.       /* ANSI C++ June 5 1992 WP 9.5.3.  Anonymous unions may not have
  5746.      function members.  */
  5747.       if (TYPE_FIELDS (t))
  5748.     {
  5749.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
  5750.                       NULL_TREE, NULL_TREE);
  5751.       finish_anon_union (decl);
  5752.     }
  5753.       else
  5754.     error ("anonymous union cannot have a function member");
  5755.     }
  5756.   else
  5757.     {
  5758.       /* Anonymous unions are objects, that's why we only check for
  5759.      inappropriate specifiers in this branch.  */
  5760.  
  5761.       if (ob_modifier)
  5762.     {
  5763.       if (ob_modifier == ridpointers[(int) RID_INLINE]
  5764.           || ob_modifier == ridpointers[(int) RID_VIRTUAL])
  5765.         cp_error ("`%D' can only be specified for functions", ob_modifier);
  5766.       else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
  5767.         cp_error ("`%D' can only be specified for constructors",
  5768.               ob_modifier);
  5769.       else
  5770.         cp_error ("`%D' can only be specified for objects and functions",
  5771.               ob_modifier);
  5772.     }
  5773.  
  5774.       if (found_tag == 0)
  5775.     pedwarn ("abstract declarator used as declaration");
  5776.       else if (found_tag > 1)
  5777.     pedwarn ("multiple types in one declaration");
  5778.     }
  5779. }
  5780.  
  5781. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  5782.  
  5783. tree
  5784. groktypename (typename)
  5785.      tree typename;
  5786. {
  5787.   if (TREE_CODE (typename) != TREE_LIST)
  5788.     return typename;
  5789.   return grokdeclarator (TREE_VALUE (typename),
  5790.              TREE_PURPOSE (typename),
  5791.              TYPENAME, 0, NULL_TREE, NULL_TREE);
  5792. }
  5793.  
  5794. #ifdef OBJCPLUS
  5795. /* Return a PARM_DECL node for a given pair of specs and declarator.  */
  5796.  
  5797. tree
  5798. groktypename_in_parm_context (typename)
  5799.      tree typename;
  5800. {
  5801.   if (TREE_CODE (typename) != TREE_LIST)
  5802.     return typename;
  5803.   return grokdeclarator (TREE_VALUE (typename),
  5804.                          TREE_PURPOSE (typename),
  5805.                          PARM, 0, NULL_TREE, NULL_TREE);
  5806. }
  5807. #endif /* OBJCPLUS */
  5808.  
  5809. /* Decode a declarator in an ordinary declaration or data definition.
  5810.    This is called as soon as the type information and variable name
  5811.    have been parsed, before parsing the initializer if any.
  5812.    Here we create the ..._DECL node, fill in its type,
  5813.    and put it on the list of decls for the current context.
  5814.    The ..._DECL node is returned as the value.
  5815.  
  5816.    Exception: for arrays where the length is not specified,
  5817.    the type is left null, to be filled in by `cp_finish_decl'.
  5818.  
  5819.    Function definitions do not come here; they go to start_function
  5820.    instead.  However, external and forward declarations of functions
  5821.    do go through here.  Structure field declarations are done by
  5822.    grokfield and not through here.  */
  5823.  
  5824. /* Set this to zero to debug not using the temporary obstack
  5825.    to parse initializers.  */
  5826. int debug_temp_inits = 1;
  5827.  
  5828. tree
  5829. start_decl (declarator, declspecs, initialized, raises)
  5830.      tree declarator, declspecs;
  5831.      int initialized;
  5832.      tree raises;
  5833. {
  5834.   register tree decl;
  5835.   register tree type, tem;
  5836.   tree context;
  5837.   extern int have_extern_spec;
  5838.   extern int used_extern_spec;
  5839.  
  5840.   int init_written = initialized;
  5841.  
  5842.   /* This should only be done once on the top most decl. */
  5843.   if (have_extern_spec && !used_extern_spec)
  5844.     {
  5845.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
  5846.                   declspecs);
  5847.       used_extern_spec = 1;
  5848.     }
  5849.  
  5850.   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises,
  5851.              NULL_TREE);
  5852.   if (decl == NULL_TREE || decl == void_type_node)
  5853.     return NULL_TREE;
  5854.  
  5855.   type = TREE_TYPE (decl);
  5856.  
  5857.   /* Don't lose if destructors must be executed at file-level.  */
  5858.   if (TREE_STATIC (decl)
  5859.       && TYPE_NEEDS_DESTRUCTOR (type)
  5860.       && !TREE_PERMANENT (decl))
  5861.     {
  5862.       push_obstacks (&permanent_obstack, &permanent_obstack);
  5863.       decl = copy_node (decl);
  5864.       if (TREE_CODE (type) == ARRAY_TYPE)
  5865.     {
  5866.       tree itype = TYPE_DOMAIN (type);
  5867.       if (itype && ! TREE_PERMANENT (itype))
  5868.         {
  5869.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  5870.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  5871.           TREE_TYPE (decl) = type;
  5872.         }
  5873.     }
  5874.       pop_obstacks ();
  5875.     }
  5876.  
  5877.   /* Corresponding pop_obstacks is done in `cp_finish_decl'.  */
  5878.   push_obstacks_nochange ();
  5879.  
  5880.   context
  5881.     = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
  5882.       ? DECL_CLASS_CONTEXT (decl)
  5883.       : DECL_CONTEXT (decl);
  5884.  
  5885.   if (processing_template_decl)
  5886.     {
  5887.       tree d;
  5888.       if (TREE_CODE (decl) == FUNCTION_DECL)
  5889.         {
  5890.           /* Declarator is a call_expr; extract arguments from it, since
  5891.              grokdeclarator didn't do it.  */
  5892.           tree args;
  5893.           args = copy_to_permanent (last_function_parms);
  5894.           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
  5895.             {
  5896.           tree t = TREE_TYPE (decl);
  5897.           
  5898.               t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
  5899.           if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
  5900.         {
  5901.           t = build_pointer_type (t); /* base type of `this' */
  5902. #if 1
  5903.           /* I suspect this is wrong. */
  5904.           t = build_type_variant (t, flag_this_is_variable <= 0,
  5905.                       0); /* type of `this' */
  5906. #else
  5907.           t = build_type_variant (t, 0, 0); /* type of `this' */
  5908. #endif
  5909.           t = build (PARM_DECL, t, this_identifier);
  5910.           TREE_CHAIN (t) = args;
  5911.           args = t;
  5912.         }
  5913.         }
  5914.           DECL_ARGUMENTS (decl) = args;
  5915.         }
  5916.       d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
  5917.       TREE_PUBLIC (d) = TREE_PUBLIC (decl);
  5918.       TREE_STATIC (d) = TREE_STATIC (decl);
  5919.       DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
  5920.                && !(context && !DECL_THIS_EXTERN (decl)));
  5921.       DECL_TEMPLATE_RESULT (d) = decl;
  5922.       decl = d;
  5923.     }
  5924.  
  5925.   /* If this type of object needs a cleanup, and control may
  5926.      jump past it, make a new binding level so that it is cleaned
  5927.      up only when it is initialized first.  */
  5928.   if (TYPE_NEEDS_DESTRUCTOR (type)
  5929.       && current_binding_level->more_cleanups_ok == 0)
  5930.     pushlevel_temporary (1);
  5931.  
  5932.   if (initialized)
  5933.     /* Is it valid for this decl to have an initializer at all?
  5934.        If not, set INITIALIZED to zero, which will indirectly
  5935.        tell `cp_finish_decl' to ignore the initializer once it is parsed.  */
  5936.     switch (TREE_CODE (decl))
  5937.       {
  5938.       case TYPE_DECL:
  5939.     /* typedef foo = bar  means give foo the same type as bar.
  5940.        We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
  5941.        Any other case of an initialization in a TYPE_DECL is an error.  */
  5942.     if (pedantic || list_length (declspecs) > 1)
  5943.       {
  5944.         cp_error ("typedef `%D' is initialized", decl);
  5945.         initialized = 0;
  5946.       }
  5947.     break;
  5948.  
  5949.       case FUNCTION_DECL:
  5950.     cp_error ("function `%#D' is initialized like a variable", decl);
  5951.     initialized = 0;
  5952.     break;
  5953.  
  5954.       default:
  5955.     /* Don't allow initializations for incomplete types except for
  5956.        arrays which might be completed by the initialization.  */
  5957.     if (type == error_mark_node)
  5958.       ;            /* Don't complain again.  */
  5959.     else if (TYPE_SIZE (type) != NULL_TREE)
  5960.       ;                     /* A complete type is ok.  */
  5961.     else if (TREE_CODE (type) != ARRAY_TYPE)
  5962.       {
  5963.         cp_error ("variable `%#D' has initializer but incomplete type",
  5964.               decl);
  5965.         initialized = 0;
  5966.       }
  5967.     else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
  5968.       {
  5969.         cp_error ("elements of array `%#D' have incomplete type", decl);
  5970.         initialized = 0;
  5971.       }
  5972.       }
  5973.  
  5974.   if (!initialized
  5975.       && TREE_CODE (decl) != TYPE_DECL
  5976.       && TREE_CODE (decl) != TEMPLATE_DECL
  5977.       && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
  5978.     {
  5979.       if (TYPE_SIZE (type) == NULL_TREE)
  5980.     {
  5981.       cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
  5982.          decl);
  5983.       /* Change the type so that assemble_variable will give
  5984.          DECL an rtl we can live with: (mem (const_int 0)).  */
  5985.       TREE_TYPE (decl) = error_mark_node;
  5986.       type = error_mark_node;
  5987.     }
  5988.       else
  5989.     {
  5990.       /* If any base type in the hierarchy of TYPE needs a constructor,
  5991.          then we set initialized to 1.  This way any nodes which are
  5992.          created for the purposes of initializing this aggregate
  5993.          will live as long as it does.  This is necessary for global
  5994.          aggregates which do not have their initializers processed until
  5995.          the end of the file.  */
  5996.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  5997.     }
  5998.     }
  5999.  
  6000.   if (initialized)
  6001.     {
  6002.       if (! toplevel_bindings_p ()
  6003.       && DECL_EXTERNAL (decl))
  6004.     cp_warning ("declaration of `%#D' has `extern' and is initialized",
  6005.             decl);
  6006.       DECL_EXTERNAL (decl) = 0;
  6007.       if ( toplevel_bindings_p ())
  6008.     TREE_STATIC (decl) = 1;
  6009.  
  6010.       /* Tell `pushdecl' this is an initialized decl
  6011.      even though we don't yet have the initializer expression.
  6012.      Also tell `cp_finish_decl' it may store the real initializer.  */
  6013.       DECL_INITIAL (decl) = error_mark_node;
  6014.     }
  6015.  
  6016.   if (context && TYPE_SIZE (context) != NULL_TREE)
  6017.     {
  6018.       if (TREE_CODE (decl) == VAR_DECL)
  6019.     {
  6020.       tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
  6021.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  6022.         cp_error ("`%#D' is not a static member of `%#T'", decl, context);
  6023.       else if (duplicate_decls (decl, field))
  6024.         decl = field;
  6025.     }
  6026.       else
  6027.     {
  6028.       tree field = check_classfn (context, NULL_TREE, decl);
  6029.       if (field && duplicate_decls (decl, field))
  6030.         decl = field;
  6031.     }
  6032.  
  6033.       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
  6034.       if (DECL_LANG_SPECIFIC (decl))
  6035.     DECL_IN_AGGR_P (decl) = 0;
  6036.       if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context))
  6037.     SET_DECL_TEMPLATE_SPECIALIZATION (decl);
  6038.  
  6039.       /* Stupid stupid stupid stupid  (jason 7/21/95) */
  6040.       if (pedantic && DECL_EXTERNAL (decl)
  6041.       && ! DECL_TEMPLATE_SPECIALIZATION (decl))
  6042.     cp_pedwarn ("declaration of `%#D' outside of class is not definition",
  6043.             decl);
  6044.  
  6045.       pushclass (context, 2);
  6046.     }
  6047.  
  6048.   /* Add this decl to the current binding level, but not if it
  6049.      comes from another scope, e.g. a static member variable.
  6050.      TEM may equal DECL or it may be a previous decl of the same name.  */
  6051.   
  6052.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  6053.       || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
  6054.       || TREE_CODE (type) == LANG_TYPE)
  6055.     tem = decl;
  6056.   else
  6057.     tem = pushdecl (decl);
  6058.          
  6059.   /* Tell the back-end to use or not use .common as appropriate.  If we say
  6060.      -fconserve-space, we want this to save space, at the expense of wrong
  6061.      semantics.  If we say -fno-conserve-space, we want this to produce
  6062.      errors about redefs; to do this we force variables into the data
  6063.      segment.  Common storage is okay for non-public uninitialized data;
  6064.      the linker can't match it with storage from other files, and we may
  6065.      save some disk space.  */
  6066.   DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
  6067.  
  6068. #if 0
  6069.   /* We don't do this yet for GNU C++.  */
  6070.   /* For a local variable, define the RTL now.  */
  6071.   if (! toplevel_bindings_p ()
  6072.       /* But not if this is a duplicate decl
  6073.      and we preserved the rtl from the previous one
  6074.      (which may or may not happen).  */
  6075.       && DECL_RTL (tem) == NULL_RTX)
  6076.     {
  6077.       if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
  6078.     expand_decl (tem);
  6079.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  6080.            && DECL_INITIAL (tem) != NULL_TREE)
  6081.     expand_decl (tem);
  6082.     }
  6083. #endif
  6084.  
  6085.   if (TREE_CODE (decl) == TEMPLATE_DECL)
  6086.     {
  6087.       tree result = DECL_TEMPLATE_RESULT (decl);
  6088.       if (DECL_CONTEXT (result) != NULL_TREE)
  6089.     {
  6090.           tree type;
  6091.           type = DECL_CONTEXT (result);
  6092.  
  6093.       if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
  6094.         {
  6095.           cp_error ("declaration of `%D' in non-template type `%T'",
  6096.             decl, type);
  6097.           return NULL_TREE;
  6098.         }
  6099.  
  6100.       if (TREE_CODE (result) == FUNCTION_DECL)
  6101.         return tem;
  6102.       else if (TREE_CODE (result) == VAR_DECL)
  6103.         {
  6104. #if 0
  6105.               tree tmpl = UPT_TEMPLATE (type);
  6106.           
  6107.           fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
  6108.           print_node_brief (stderr, "", DECL_NAME (tem), 0);
  6109.           fprintf (stderr, " to class %s\n",
  6110.                IDENTIFIER_POINTER (DECL_NAME (tmpl)));
  6111.               DECL_TEMPLATE_MEMBERS (tmpl)
  6112.                 = perm_tree_cons (DECL_NAME (tem), tem,
  6113.                   DECL_TEMPLATE_MEMBERS (tmpl));
  6114.           return tem;
  6115. #else
  6116.           sorry ("static data member templates");
  6117.           return NULL_TREE;
  6118. #endif
  6119.         }
  6120.       else
  6121.         my_friendly_abort (13);
  6122.         }
  6123.       else if (TREE_CODE (result) == FUNCTION_DECL)
  6124.         /*tem = push_overloaded_decl (tem, 0)*/;
  6125.       else if (TREE_CODE (result) == VAR_DECL)
  6126.     {
  6127.       cp_error ("data template `%#D' must be member of a class template",
  6128.             result);
  6129.       return NULL_TREE;
  6130.     }
  6131.       else if (TREE_CODE (result) == TYPE_DECL)
  6132.     {
  6133.       cp_error ("invalid template `%#D'", result);
  6134.       return NULL_TREE;
  6135.     }
  6136.       else
  6137.     my_friendly_abort (14);
  6138.     }
  6139.  
  6140.   if (init_written
  6141.       && ! (TREE_CODE (tem) == PARM_DECL
  6142.         || (TREE_READONLY (tem)
  6143.         && (TREE_CODE (tem) == VAR_DECL
  6144.             || TREE_CODE (tem) == FIELD_DECL))))
  6145.     {
  6146.       /* When parsing and digesting the initializer,
  6147.      use temporary storage.  Do this even if we will ignore the value.  */
  6148.       if (toplevel_bindings_p () && debug_temp_inits)
  6149.     {
  6150.       if (TYPE_NEEDS_CONSTRUCTING (type)
  6151.           || TREE_CODE (type) == REFERENCE_TYPE)
  6152.         /* In this case, the initializer must lay down in permanent
  6153.            storage, since it will be saved until `finish_file' is run.   */
  6154.         ;
  6155.       else
  6156.         temporary_allocation ();
  6157.     }
  6158.     }
  6159.  
  6160.   if (flag_cadillac)
  6161.     cadillac_start_decl (tem);
  6162.  
  6163.   return tem;
  6164. }
  6165.  
  6166. #if 0                /* unused */
  6167. static void
  6168. make_temporary_for_reference (decl, ctor_call, init, cleanupp)
  6169.      tree decl, ctor_call, init;
  6170.      tree *cleanupp;
  6171. {
  6172.   tree type = TREE_TYPE (decl);
  6173.   tree target_type = TREE_TYPE (type);
  6174.   tree tmp, tmp_addr;
  6175.  
  6176.   if (ctor_call)
  6177.     {
  6178.       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
  6179.       if (TREE_CODE (tmp_addr) == NOP_EXPR)
  6180.     tmp_addr = TREE_OPERAND (tmp_addr, 0);
  6181.       my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
  6182.       tmp = TREE_OPERAND (tmp_addr, 0);
  6183.     }
  6184.   else
  6185.     {
  6186.       tmp = get_temp_name (target_type, toplevel_bindings_p ());
  6187.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  6188.     }
  6189.  
  6190.   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  6191.   DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr);
  6192.   TREE_TYPE (DECL_INITIAL (decl)) = type;
  6193.   if (TYPE_NEEDS_CONSTRUCTING (target_type))
  6194.     {
  6195.       if (toplevel_bindings_p ())
  6196.     {
  6197.       /* lay this variable out now.  Otherwise `output_addressed_constants'
  6198.          gets confused by its initializer.  */
  6199.       make_decl_rtl (tmp, NULL_PTR, 1);
  6200.       static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  6201.     }
  6202.       else
  6203.     {
  6204.       if (ctor_call != NULL_TREE)
  6205.         init = ctor_call;
  6206.       else
  6207.         init = build_method_call (tmp, constructor_name_full (target_type),
  6208.                       build_tree_list (NULL_TREE, init),
  6209.                       NULL_TREE, LOOKUP_NORMAL);
  6210.       DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
  6211.                        DECL_INITIAL (decl));
  6212.       *cleanupp = maybe_build_cleanup (tmp);
  6213.     }
  6214.     }
  6215.   else
  6216.     {
  6217.       DECL_INITIAL (tmp) = init;
  6218.       TREE_STATIC (tmp) = toplevel_bindings_p ();
  6219.       cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
  6220.     }
  6221.   if (TREE_STATIC (tmp))
  6222.     preserve_initializer ();
  6223. }
  6224. #endif
  6225.  
  6226. /* Handle initialization of references.
  6227.    These three arguments from from `cp_finish_decl', and have the
  6228.    same meaning here that they do there.  */
  6229. /* quotes on semantics can be found in ARM 8.4.3. */
  6230. static void
  6231. grok_reference_init (decl, type, init, cleanupp)
  6232.      tree decl, type, init;
  6233.      tree *cleanupp;
  6234. {
  6235.   tree tmp;
  6236.  
  6237.   if (init == NULL_TREE)
  6238.     {
  6239.       if ((DECL_LANG_SPECIFIC (decl) == 0
  6240.        || DECL_IN_AGGR_P (decl) == 0)
  6241.       && ! DECL_THIS_EXTERN (decl))
  6242.     {
  6243.       cp_error ("`%D' declared as reference but not initialized", decl);
  6244.       if (TREE_CODE (decl) == VAR_DECL)
  6245.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  6246.     }
  6247.       return;
  6248.     }
  6249.  
  6250.   if (init == error_mark_node)
  6251.     return;
  6252.  
  6253.   if (TREE_CODE (type) == REFERENCE_TYPE
  6254.       && TREE_CODE (init) == CONSTRUCTOR)
  6255.     {
  6256.       cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
  6257.       return;
  6258.     }
  6259.  
  6260.   if (TREE_CODE (init) == TREE_LIST)
  6261.     init = build_compound_expr (init);
  6262.  
  6263.   if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
  6264.     init = convert_from_reference (init);
  6265.  
  6266.   if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  6267.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  6268.     {
  6269.       /* Note: default conversion is only called in very special cases.  */
  6270.       init = default_conversion (init);
  6271.     }
  6272.  
  6273.   tmp = convert_to_reference
  6274.     (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
  6275.  
  6276.   if (tmp == error_mark_node)
  6277.     goto fail;
  6278.   else if (tmp != NULL_TREE)
  6279.     {
  6280.       tree subtype = TREE_TYPE (type);
  6281.       init = tmp;
  6282.  
  6283.       /* Associate the cleanup with the reference so that we
  6284.      don't get burned by "aggressive" cleanup policy.  */
  6285.       if (TYPE_NEEDS_DESTRUCTOR (subtype))
  6286.     {
  6287.       if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
  6288.         {
  6289.           *cleanupp = TREE_OPERAND (init, 2);
  6290.           TREE_OPERAND (init, 2) = error_mark_node;
  6291.         }
  6292.       else
  6293.         {
  6294.           if (TREE_CODE (tmp) == ADDR_EXPR)
  6295.         tmp = TREE_OPERAND (tmp, 0);
  6296.           if (TREE_CODE (tmp) == TARGET_EXPR)
  6297.         {
  6298.           *cleanupp = build_delete
  6299.             (build_pointer_type (subtype),
  6300.              build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
  6301.              integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
  6302.           TREE_OPERAND (tmp, 2) = error_mark_node;
  6303.         }
  6304.         }
  6305.     }
  6306.  
  6307.       DECL_INITIAL (decl) = save_expr (init);
  6308.     }
  6309.   else
  6310.     {
  6311.       cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
  6312.       goto fail;
  6313.     }
  6314.  
  6315.   /* ?? Can this be optimized in some cases to
  6316.      hand back the DECL_INITIAL slot??  */
  6317.   if (TYPE_SIZE (TREE_TYPE (type)))
  6318.     {
  6319.       init = convert_from_reference (decl);
  6320.       if (TREE_PERMANENT (decl))
  6321.     init = copy_to_permanent (init);
  6322.       SET_DECL_REFERENCE_SLOT (decl, init);
  6323.     }
  6324.  
  6325.   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
  6326.     {
  6327.       expand_static_init (decl, DECL_INITIAL (decl));
  6328.       DECL_INITIAL (decl) = NULL_TREE;
  6329.     }
  6330.   return;
  6331.  
  6332.  fail:
  6333.   if (TREE_CODE (decl) == VAR_DECL)
  6334.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  6335.   return;
  6336. }
  6337.  
  6338. /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
  6339.    mucking with forces it does not comprehend (i.e. initialization with a
  6340.    constructor).  If we are at global scope and won't go into COMMON, fill
  6341.    it in with a dummy CONSTRUCTOR to force the variable into .data;
  6342.    otherwise we can use error_mark_node.  */
  6343.  
  6344. static tree
  6345. obscure_complex_init (decl, init)
  6346.      tree decl, init;
  6347. {
  6348.   if (! flag_no_inline && TREE_STATIC (decl))
  6349.     {
  6350.       if (extract_init (decl, init))
  6351.     return NULL_TREE;
  6352.     }
  6353.  
  6354.   if (toplevel_bindings_p () && ! DECL_COMMON (decl))
  6355.     DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
  6356.                  NULL_TREE);
  6357.   else
  6358.     DECL_INITIAL (decl) = error_mark_node;
  6359.  
  6360.   return init;
  6361. }
  6362.  
  6363. /* Finish processing of a declaration;
  6364.    install its line number and initial value.
  6365.    If the length of an array type is not known before,
  6366.    it must be determined now, from the initial value, or it is an error.
  6367.  
  6368.    Call `pop_obstacks' iff NEED_POP is nonzero.
  6369.  
  6370.    For C++, `cp_finish_decl' must be fairly evasive:  it must keep initializers
  6371.    for aggregates that have constructors alive on the permanent obstack,
  6372.    so that the global initializing functions can be written at the end.
  6373.  
  6374.    INIT0 holds the value of an initializer that should be allowed to escape
  6375.    the normal rules.
  6376.  
  6377.    FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
  6378.    if the (init) syntax was used.
  6379.  
  6380.    For functions that take default parameters, DECL points to its
  6381.    "maximal" instantiation.  `cp_finish_decl' must then also declared its
  6382.    subsequently lower and lower forms of instantiation, checking for
  6383.    ambiguity as it goes.  This can be sped up later.  */
  6384.  
  6385. void
  6386. cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
  6387.      tree decl, init;
  6388.      tree asmspec_tree;
  6389.      int need_pop;
  6390.      int flags;
  6391. {
  6392.   register tree type;
  6393.   tree cleanup = NULL_TREE, ttype;
  6394.   int was_incomplete;
  6395.   int temporary = allocation_temporary_p ();
  6396.   char *asmspec = NULL;
  6397.   int was_readonly = 0;
  6398.  
  6399.   /* If this is 0, then we did not change obstacks.  */
  6400.   if (! decl)
  6401.     {
  6402.       if (init)
  6403.     error ("assignment (not initialization) in declaration");
  6404.       return;
  6405.     }
  6406.  
  6407.   /* If a name was specified, get the string.  */
  6408.   if (asmspec_tree)
  6409.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  6410.  
  6411.   /* If the type of the thing we are declaring either has
  6412.      a constructor, or has a virtual function table pointer,
  6413.      AND its initialization was accepted by `start_decl',
  6414.      then we stayed on the permanent obstack through the
  6415.      declaration, otherwise, changed obstacks as GCC would.  */
  6416.  
  6417.   type = TREE_TYPE (decl);
  6418.  
  6419.   if (type == error_mark_node)
  6420.     {
  6421.       if (toplevel_bindings_p () && temporary)
  6422.     end_temporary_allocation ();
  6423.  
  6424.       return;
  6425.     }
  6426.  
  6427.   was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
  6428.  
  6429.   /* Take care of TYPE_DECLs up front.  */
  6430.   if (TREE_CODE (decl) == TYPE_DECL)
  6431.     {
  6432.       if (init && DECL_INITIAL (decl))
  6433.     {
  6434.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  6435.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  6436.       DECL_INITIAL (decl) = init = NULL_TREE;
  6437.     }
  6438.       if (type != error_mark_node
  6439.       && IS_AGGR_TYPE (type) && DECL_NAME (decl))
  6440.     {
  6441.       if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  6442.         cp_warning ("shadowing previous type declaration of `%#D'", decl);
  6443.       set_identifier_type_value (DECL_NAME (decl), type);
  6444.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  6445.     }
  6446.       GNU_xref_decl (current_function_decl, decl);
  6447.       rest_of_decl_compilation (decl, NULL_PTR,
  6448.                 DECL_CONTEXT (decl) == NULL_TREE, 0);
  6449.       goto finish_end;
  6450.     }
  6451.   if (TREE_CODE (decl) != FUNCTION_DECL)
  6452.     {
  6453.       ttype = target_type (type);
  6454. #if 0 /* WTF?  -KR
  6455.      Leave this out until we can figure out why it was
  6456.      needed/desirable in the first place.  Then put a comment
  6457.      here explaining why.  Or just delete the code if no ill
  6458.      effects arise.  */
  6459.       if (TYPE_NAME (ttype)
  6460.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  6461.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
  6462.     {
  6463.       tree old_id = TYPE_IDENTIFIER (ttype);
  6464.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  6465.       /* Need to preserve template data for UPT nodes.  */
  6466.       tree old_template = IDENTIFIER_TEMPLATE (old_id);
  6467.       newname[0] = '_';
  6468.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  6469.          IDENTIFIER_LENGTH (old_id) + 1);
  6470.       old_id = get_identifier (newname);
  6471.       lookup_tag_reverse (ttype, old_id);
  6472.       TYPE_IDENTIFIER (ttype) = old_id;
  6473.       IDENTIFIER_TEMPLATE (old_id) = old_template;
  6474.     }
  6475. #endif
  6476.     }
  6477.  
  6478.   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
  6479.       && TYPE_NEEDS_CONSTRUCTING (type))
  6480.     {
  6481.  
  6482.       /* Currently, GNU C++ puts constants in text space, making them
  6483.      impossible to initialize.  In the future, one would hope for
  6484.      an operating system which understood the difference between
  6485.      initialization and the running of a program.  */
  6486.       was_readonly = 1;
  6487.       TREE_READONLY (decl) = 0;
  6488.     }
  6489.  
  6490.   if (TREE_CODE (decl) == FIELD_DECL)
  6491.     {
  6492.       if (init && init != error_mark_node)
  6493.     my_friendly_assert (TREE_PERMANENT (init), 147);
  6494.  
  6495.       if (asmspec)
  6496.     {
  6497.       /* This must override the asm specifier which was placed
  6498.          by grokclassfn.  Lay this out fresh.  */
  6499.       DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
  6500.       DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  6501.       make_decl_rtl (decl, asmspec, 0);
  6502.     }
  6503.     }
  6504.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  6505.   else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
  6506.     init = NULL_TREE;
  6507.   else if (DECL_EXTERNAL (decl))
  6508.     ;
  6509.   else if (TREE_CODE (type) == REFERENCE_TYPE
  6510.        || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
  6511.     {
  6512.       if (TREE_STATIC (decl))
  6513.     make_decl_rtl (decl, NULL_PTR,
  6514.                toplevel_bindings_p ()
  6515.                || pseudo_global_level_p ());
  6516.       grok_reference_init (decl, type, init, &cleanup);
  6517.       init = NULL_TREE;
  6518.     }
  6519.  
  6520.   GNU_xref_decl (current_function_decl, decl);
  6521.  
  6522.   if (TREE_CODE (decl) == FIELD_DECL)
  6523.     ;
  6524.   else if (TREE_CODE (decl) == CONST_DECL)
  6525.     {
  6526.       my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
  6527.  
  6528.       DECL_INITIAL (decl) = init;
  6529.  
  6530.       /* This will keep us from needing to worry about our obstacks.  */
  6531.       my_friendly_assert (init != NULL_TREE, 149);
  6532.       init = NULL_TREE;
  6533.     }
  6534.   else if (init)
  6535.     {
  6536.       if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
  6537.     {
  6538.       if (TREE_CODE (type) == ARRAY_TYPE)
  6539.         init = digest_init (type, init, (tree *) 0);
  6540.       else if (TREE_CODE (init) == CONSTRUCTOR)
  6541.         {
  6542.           if (TYPE_NON_AGGREGATE_CLASS (type))
  6543.         {
  6544.           cp_error ("`%D' must be initialized by constructor, not by `{...}'",
  6545.                 decl);
  6546.           init = error_mark_node;
  6547.         }
  6548.           else
  6549.         goto dont_use_constructor;
  6550.         }
  6551.     }
  6552.       else
  6553.     {
  6554.     dont_use_constructor:
  6555.       if (TREE_CODE (init) != TREE_VEC)
  6556.         init = store_init_value (decl, init);
  6557.     }
  6558.  
  6559.       if (init)
  6560.     /* We must hide the initializer so that expand_decl
  6561.        won't try to do something it does not understand.  */
  6562.     init = obscure_complex_init (decl, init);
  6563.     }
  6564.   else if (DECL_EXTERNAL (decl))
  6565.     ;
  6566.   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  6567.        && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
  6568.     {
  6569.       tree ctype = type;
  6570.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  6571.     ctype = TREE_TYPE (ctype);
  6572.       if (! TYPE_NEEDS_CONSTRUCTING (ctype))
  6573.     {
  6574.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  6575.         cp_error ("structure `%D' with uninitialized const members", decl);
  6576.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  6577.         cp_error ("structure `%D' with uninitialized reference members",
  6578.               decl);
  6579.     }
  6580.  
  6581.       if (TREE_CODE (decl) == VAR_DECL
  6582.       && !DECL_INITIAL (decl)
  6583.       && !TYPE_NEEDS_CONSTRUCTING (type)
  6584.       && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  6585.     cp_error ("uninitialized const `%D'", decl);
  6586.  
  6587.       if (TYPE_SIZE (type) != NULL_TREE
  6588.       && TYPE_NEEDS_CONSTRUCTING (type))
  6589.     init = obscure_complex_init (decl, NULL_TREE);
  6590.     }
  6591.   else if (TREE_CODE (decl) == VAR_DECL
  6592.        && TREE_CODE (type) != REFERENCE_TYPE
  6593.        && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  6594.     {
  6595.       /* ``Unless explicitly declared extern, a const object does not have
  6596.      external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
  6597.      However, if it's `const int foo = 1; const int foo;', don't complain
  6598.      about the second decl, since it does have an initializer before.
  6599.      We deliberately don't complain about arrays, because they're
  6600.      supposed to be initialized by a constructor.  */
  6601.       if (! DECL_INITIAL (decl)
  6602.       && TREE_CODE (type) != ARRAY_TYPE
  6603.       && (!pedantic || !current_class_type))
  6604.     cp_error ("uninitialized const `%#D'", decl);
  6605.     }
  6606.  
  6607.   /* For top-level declaration, the initial value was read in
  6608.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  6609.      must go in the permanent obstack; but don't discard the
  6610.      temporary data yet.  */
  6611.  
  6612.   if (toplevel_bindings_p () && temporary)
  6613.     end_temporary_allocation ();
  6614.  
  6615.   /* Deduce size of array from initialization, if not already known.  */
  6616.  
  6617.   if (TREE_CODE (type) == ARRAY_TYPE
  6618.       && TYPE_DOMAIN (type) == NULL_TREE
  6619.       && TREE_CODE (decl) != TYPE_DECL)
  6620.     {
  6621.       int do_default
  6622.     = (TREE_STATIC (decl)
  6623.        /* Even if pedantic, an external linkage array
  6624.           may have incomplete type at first.  */
  6625.        ? pedantic && ! DECL_EXTERNAL (decl)
  6626.        : !DECL_EXTERNAL (decl));
  6627.       tree initializer = init ? init : DECL_INITIAL (decl);
  6628.       int failure = complete_array_type (type, initializer, do_default);
  6629.  
  6630.       if (failure == 1)
  6631.     cp_error ("initializer fails to determine size of `%D'", decl);
  6632.  
  6633.       if (failure == 2)
  6634.     {
  6635.       if (do_default)
  6636.         cp_error ("array size missing in `%D'", decl);
  6637.       /* If a `static' var's size isn't known, make it extern as
  6638.          well as static, so it does not get allocated.  If it's not
  6639.          `static', then don't mark it extern; finish_incomplete_decl
  6640.          will give it a default size and it will get allocated.  */
  6641.       else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
  6642.         DECL_EXTERNAL (decl) = 1;
  6643.     }
  6644.  
  6645.       if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
  6646.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  6647.                   integer_zero_node))
  6648.     cp_error ("zero-size array `%D'", decl);
  6649.  
  6650.       layout_decl (decl, 0);
  6651.     }
  6652.  
  6653.   if (TREE_CODE (decl) == VAR_DECL)
  6654.     {
  6655.       if (DECL_SIZE (decl) == NULL_TREE
  6656.       && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
  6657.     layout_decl (decl, 0);
  6658.  
  6659.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
  6660.     {
  6661.       /* A static variable with an incomplete type:
  6662.          that is an error if it is initialized.
  6663.          Otherwise, let it through, but if it is not `extern'
  6664.          then it may cause an error message later.  */
  6665.       if (DECL_INITIAL (decl) != NULL_TREE)
  6666.         cp_error ("storage size of `%D' isn't known", decl);
  6667.       init = NULL_TREE;
  6668.     }
  6669.       else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
  6670.     {
  6671.       /* An automatic variable with an incomplete type: that is an error.
  6672.          Don't talk about array types here, since we took care of that
  6673.          message in grokdeclarator.  */
  6674.       cp_error ("storage size of `%D' isn't known", decl);
  6675.       TREE_TYPE (decl) = error_mark_node;
  6676.     }
  6677.       else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  6678.     /* Let debugger know it should output info for this type.  */
  6679.     note_debug_info_needed (ttype);
  6680.  
  6681.       if (TREE_STATIC (decl) && DECL_CONTEXT (decl)
  6682.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
  6683.     note_debug_info_needed (DECL_CONTEXT (decl));
  6684.  
  6685.       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
  6686.       && DECL_SIZE (decl) != NULL_TREE
  6687.       && ! TREE_CONSTANT (DECL_SIZE (decl)))
  6688.     {
  6689.       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
  6690.         constant_expression_warning (DECL_SIZE (decl));
  6691.       else
  6692.         cp_error ("storage size of `%D' isn't constant", decl);
  6693.     }
  6694.  
  6695.       if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
  6696.     {
  6697.       int yes = suspend_momentary ();
  6698.  
  6699.       /* If INIT comes from a functional cast, use the cleanup
  6700.          we built for that.  Otherwise, make our own cleanup.  */
  6701.       if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
  6702.           && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
  6703.         {
  6704.           cleanup = TREE_OPERAND (init, 2);
  6705.           init = TREE_OPERAND (init, 0);
  6706.           current_binding_level->have_cleanups = 1;
  6707.         }
  6708.       else
  6709.         cleanup = maybe_build_cleanup (decl);
  6710.       resume_momentary (yes);
  6711.     }
  6712.     }
  6713.   /* PARM_DECLs get cleanups, too.  */
  6714.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  6715.     {
  6716.       if (temporary)
  6717.     end_temporary_allocation ();
  6718.       cleanup = maybe_build_cleanup (decl);
  6719.       if (temporary)
  6720.     resume_temporary_allocation ();
  6721.     }
  6722.  
  6723.   /* Output the assembler code and/or RTL code for variables and functions,
  6724.      unless the type is an undefined structure or union.
  6725.      If not, it will get done when the type is completed.  */
  6726.  
  6727.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  6728.       || TREE_CODE (decl) == RESULT_DECL)
  6729.     {
  6730.       /* ??? FIXME: What about nested classes?  */
  6731.       int toplev = toplevel_bindings_p () || pseudo_global_level_p ();
  6732.       int was_temp
  6733.     = ((flag_traditional
  6734.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  6735.        && allocation_temporary_p ());
  6736.  
  6737.       if (was_temp)
  6738.     end_temporary_allocation ();
  6739.  
  6740.       if (TREE_CODE (decl) == VAR_DECL
  6741.       && ! toplevel_bindings_p ()
  6742.       && ! TREE_STATIC (decl)
  6743.       && type_needs_gc_entry (type))
  6744.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  6745.  
  6746.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  6747.     make_decl_rtl (decl, NULL_PTR, toplev);
  6748.       else if (TREE_CODE (decl) == VAR_DECL
  6749.            && TREE_READONLY (decl)
  6750.            && DECL_INITIAL (decl) != NULL_TREE
  6751.            && DECL_INITIAL (decl) != error_mark_node
  6752.            && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
  6753.     {
  6754.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  6755.  
  6756.       if (asmspec)
  6757.         DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  6758.  
  6759.       if (! toplev
  6760.           && TREE_STATIC (decl)
  6761.           && ! TREE_SIDE_EFFECTS (decl)
  6762.           && ! TREE_PUBLIC (decl)
  6763.           && ! DECL_EXTERNAL (decl)
  6764.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  6765.           && DECL_MODE (decl) != BLKmode)
  6766.         {
  6767.           /* If this variable is really a constant, then fill its DECL_RTL
  6768.          slot with something which won't take up storage.
  6769.          If something later should take its address, we can always give
  6770.          it legitimate RTL at that time.  */
  6771.           DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  6772.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  6773.           TREE_ASM_WRITTEN (decl) = 1;
  6774.         }
  6775.       else if (toplev && ! TREE_PUBLIC (decl))
  6776.         {
  6777.           /* If this is a static const, change its apparent linkage
  6778.              if it belongs to a #pragma interface.  */
  6779.           if (!interface_unknown)
  6780.         {
  6781.           TREE_PUBLIC (decl) = 1;
  6782.           DECL_EXTERNAL (decl) = interface_only;
  6783.         }
  6784.           make_decl_rtl (decl, asmspec, toplev);
  6785.         }
  6786.       else
  6787.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6788.     }
  6789.       else if (TREE_CODE (decl) == VAR_DECL
  6790.            && DECL_LANG_SPECIFIC (decl)
  6791.            && DECL_IN_AGGR_P (decl))
  6792.     {
  6793.       if (TREE_STATIC (decl))
  6794.         {
  6795.           if (init == NULL_TREE
  6796. #ifdef DEFAULT_STATIC_DEFS
  6797.           /* If this code is dead, then users must
  6798.              explicitly declare static member variables
  6799.              outside the class def'n as well.  */
  6800.           && TYPE_NEEDS_CONSTRUCTING (type)
  6801. #endif
  6802.           )
  6803.         {
  6804.           DECL_EXTERNAL (decl) = 1;
  6805.           make_decl_rtl (decl, asmspec, 1);
  6806.         }
  6807.           else
  6808.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6809.         }
  6810.       else
  6811.         /* Just a constant field.  Should not need any rtl.  */
  6812.         goto finish_end0;
  6813.     }
  6814.       else
  6815.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6816.  
  6817.       if (was_temp)
  6818.     resume_temporary_allocation ();
  6819.  
  6820.       if (type != error_mark_node
  6821.       && TYPE_LANG_SPECIFIC (type)
  6822.       && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  6823.     abstract_virtuals_error (decl, type);
  6824.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6825.         || TREE_CODE (type) == METHOD_TYPE)
  6826.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6827.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  6828.     abstract_virtuals_error (decl, TREE_TYPE (type));
  6829.  
  6830.       if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
  6831.     signature_error (decl, type);
  6832.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6833.         || TREE_CODE (type) == METHOD_TYPE)
  6834.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6835.            && IS_SIGNATURE (TREE_TYPE (type)))
  6836.     signature_error (decl, TREE_TYPE (type));
  6837.  
  6838.       if (TREE_CODE (decl) == FUNCTION_DECL)
  6839.     ;
  6840.       else if (DECL_EXTERNAL (decl))
  6841.     ;
  6842.       else if (TREE_STATIC (decl) && type != error_mark_node)
  6843.     {
  6844.       /* Cleanups for static variables are handled by `finish_file'.  */
  6845.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
  6846.           || TYPE_NEEDS_DESTRUCTOR (type))
  6847.         expand_static_init (decl, init);
  6848.  
  6849.       /* Make entry in appropriate vector.  */
  6850.       if (flag_gc && type_needs_gc_entry (type))
  6851.         build_static_gc_entry (decl, type);
  6852.     }
  6853.       else if (! toplev)
  6854.     {
  6855.       tree old_cleanups = cleanups_this_call;
  6856.       /* This is a declared decl which must live until the
  6857.          end of the binding contour.  It may need a cleanup.  */
  6858.  
  6859.       /* Recompute the RTL of a local array now
  6860.          if it used to be an incomplete type.  */
  6861.       if (was_incomplete && ! TREE_STATIC (decl))
  6862.         {
  6863.           /* If we used it already as memory, it must stay in memory.  */
  6864.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  6865.           /* If it's still incomplete now, no init will save it.  */
  6866.           if (DECL_SIZE (decl) == NULL_TREE)
  6867.         DECL_INITIAL (decl) = NULL_TREE;
  6868.           expand_decl (decl);
  6869.         }
  6870.       else if (! TREE_ASM_WRITTEN (decl)
  6871.            && (TYPE_SIZE (type) != NULL_TREE
  6872.                || TREE_CODE (type) == ARRAY_TYPE))
  6873.         {
  6874.           /* Do this here, because we did not expand this decl's
  6875.          rtl in start_decl.  */
  6876.           if (DECL_RTL (decl) == NULL_RTX)
  6877.         expand_decl (decl);
  6878.           else if (cleanup)
  6879.         {
  6880.           /* XXX: Why don't we use decl here?  */
  6881.           /* Ans: Because it was already expanded? */
  6882.           if (! cp_expand_decl_cleanup (NULL_TREE, cleanup))
  6883.             cp_error ("parser lost in parsing declaration of `%D'",
  6884.                   decl);
  6885.           /* Cleanup used up here.  */
  6886.           cleanup = NULL_TREE;
  6887.         }
  6888.         }
  6889.  
  6890.       if (DECL_SIZE (decl) && type != error_mark_node)
  6891.         {
  6892.           /* Compute and store the initial value.  */
  6893.           expand_decl_init (decl);
  6894.  
  6895.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  6896.         {
  6897.           emit_line_note (DECL_SOURCE_FILE (decl),
  6898.                   DECL_SOURCE_LINE (decl));
  6899.           expand_aggr_init (decl, init, 0, flags);
  6900.         }
  6901.  
  6902.           /* Set this to 0 so we can tell whether an aggregate which
  6903.          was initialized was ever used.  Don't do this if it has a
  6904.          destructor, so we don't complain about the 'resource
  6905.          allocation is initialization' idiom.  */
  6906.           if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE)
  6907.         TREE_USED (decl) = 0;
  6908.  
  6909.           /* Store the cleanup, if there was one.  */
  6910.           if (cleanup)
  6911.         {
  6912.           if (! cp_expand_decl_cleanup (decl, cleanup))
  6913.             cp_error ("parser lost in parsing declaration of `%D'",
  6914.                   decl);
  6915.         }
  6916.         }
  6917.       /* Cleanup any temporaries needed for the initial value.  */
  6918.       expand_cleanups_to (old_cleanups);
  6919.     }
  6920.     finish_end0:
  6921.  
  6922.       /* Undo call to `pushclass' that was done in `start_decl'
  6923.      due to initialization of qualified member variable.
  6924.      I.e., Foo::x = 10;  */
  6925.       {
  6926.     tree context = DECL_REAL_CONTEXT (decl);
  6927.     if (context
  6928.         && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
  6929.         && (TREE_CODE (decl) == VAR_DECL
  6930.         /* We also have a pushclass done that we need to undo here
  6931.            if we're at top level and declare a method.  */
  6932.         || (TREE_CODE (decl) == FUNCTION_DECL
  6933.             /* If size hasn't been set, we're still defining it,
  6934.                and therefore inside the class body; don't pop
  6935.                the binding level..  */
  6936.             && TYPE_SIZE (context) != NULL_TREE
  6937.             /* The binding level gets popped elsewhere for a
  6938.                friend declaration inside another class.  */
  6939.             /*
  6940.             && TYPE_IDENTIFIER (context) == current_class_name
  6941.             */
  6942.             && context == current_class_type
  6943.             )))
  6944.       popclass (1);
  6945.       }
  6946.     }
  6947.  
  6948.  finish_end:
  6949.  
  6950.   /* If requested, warn about definitions of large data objects.  */
  6951.  
  6952.   if (warn_larger_than
  6953.       && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
  6954.       && !DECL_EXTERNAL (decl))
  6955.     {
  6956.       register tree decl_size = DECL_SIZE (decl);
  6957.  
  6958.       if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
  6959.     {
  6960.       unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
  6961.  
  6962.       if (units > larger_than_size)
  6963.         warning_with_decl (decl, "size of `%s' is %u bytes", units);
  6964.     }
  6965.     }
  6966.  
  6967.   if (need_pop)
  6968.     {
  6969.       /* Resume permanent allocation, if not within a function.  */
  6970.       /* The corresponding push_obstacks_nochange is in start_decl,
  6971.      start_method, groktypename, and in grokfield.  */
  6972.       pop_obstacks ();
  6973.     }
  6974.  
  6975.   if (was_readonly)
  6976.     TREE_READONLY (decl) = 1;
  6977.  
  6978.   if (flag_cadillac)
  6979.     cadillac_finish_decl (decl);
  6980. }
  6981.  
  6982. /* This is here for a midend callback from c-common.c */
  6983. void
  6984. finish_decl (decl, init, asmspec_tree)
  6985.      tree decl, init;
  6986.      tree asmspec_tree;
  6987. {
  6988.   cp_finish_decl (decl, init, asmspec_tree, 1, 0);
  6989. }
  6990.  
  6991. void
  6992. expand_static_init (decl, init)
  6993.      tree decl;
  6994.      tree init;
  6995. {
  6996.   tree oldstatic = value_member (decl, static_aggregates);
  6997.   tree old_cleanups;
  6998.  
  6999.   if (oldstatic)
  7000.     {
  7001.       if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
  7002.     cp_error ("multiple initializations given for `%D'", decl);
  7003.     }
  7004.   else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
  7005.     {
  7006.       /* Emit code to perform this initialization but once.  */
  7007.       tree temp;
  7008.  
  7009.       /* Remember this information until end of file. */
  7010.       push_obstacks (&permanent_obstack, &permanent_obstack);
  7011.  
  7012.       /* Emit code to perform this initialization but once.  */
  7013.       temp = get_temp_name (integer_type_node, 1);
  7014.       rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
  7015.       expand_start_cond (build_binary_op (EQ_EXPR, temp,
  7016.                       integer_zero_node, 1), 0);
  7017.       old_cleanups = cleanups_this_call;
  7018.       expand_assignment (temp, integer_one_node, 0, 0);
  7019.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
  7020.       || (init && TREE_CODE (init) == TREE_LIST))
  7021.     {
  7022.       expand_aggr_init (decl, init, 0, 0);
  7023.       do_pending_stack_adjust ();
  7024.     }
  7025.       else if (init)
  7026.     expand_assignment (decl, init, 0, 0);
  7027.  
  7028.       /* Cleanup any temporaries needed for the initial value.  */
  7029.       expand_cleanups_to (old_cleanups);
  7030.       expand_end_cond ();
  7031.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  7032.     {
  7033.       static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
  7034.       TREE_STATIC (static_aggregates) = 1;
  7035.     }
  7036.  
  7037.       /* Resume old (possibly temporary) allocation. */
  7038.       pop_obstacks ();
  7039.     }
  7040.   else
  7041.     {
  7042.       /* This code takes into account memory allocation
  7043.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  7044.      does not hold for this object, then we must make permanent
  7045.      the storage currently in the temporary obstack.  */
  7046.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  7047.     preserve_initializer ();
  7048.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  7049.     }
  7050. }
  7051.  
  7052. /* Make TYPE a complete type based on INITIAL_VALUE.
  7053.    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
  7054.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  7055.  
  7056. int
  7057. complete_array_type (type, initial_value, do_default)
  7058.      tree type, initial_value;
  7059.      int do_default;
  7060. {
  7061.   register tree maxindex = NULL_TREE;
  7062.   int value = 0;
  7063.  
  7064.   if (initial_value)
  7065.     {
  7066.       /* Note MAXINDEX  is really the maximum index,
  7067.      one less than the size.  */
  7068.       if (TREE_CODE (initial_value) == STRING_CST)
  7069.     {
  7070.       int eltsize
  7071.         = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
  7072.       maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
  7073.                    / eltsize) - 1, 0);
  7074.     }
  7075.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  7076.     {
  7077.       tree elts = CONSTRUCTOR_ELTS (initial_value);
  7078.       maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
  7079.       for (; elts; elts = TREE_CHAIN (elts))
  7080.         {
  7081.           if (TREE_PURPOSE (elts))
  7082.         maxindex = TREE_PURPOSE (elts);
  7083.           else
  7084.         maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
  7085.         }
  7086.       maxindex = copy_node (maxindex);
  7087.     }
  7088.       else
  7089.     {
  7090.       /* Make an error message unless that happened already.  */
  7091.       if (initial_value != error_mark_node)
  7092.         value = 1;
  7093.  
  7094.       /* Prevent further error messages.  */
  7095.       maxindex = build_int_2 (0, 0);
  7096.     }
  7097.     }
  7098.  
  7099.   if (!maxindex)
  7100.     {
  7101.       if (do_default)
  7102.     maxindex = build_int_2 (0, 0);
  7103.       value = 2;
  7104.     }
  7105.  
  7106.   if (maxindex)
  7107.     {
  7108.       tree itype;
  7109.  
  7110.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  7111.       if (! TREE_TYPE (maxindex))
  7112.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  7113.       if (initial_value)
  7114.         itype = TREE_TYPE (initial_value);
  7115.       else
  7116.     itype = NULL;
  7117.       if (itype && !TYPE_DOMAIN (itype))
  7118.     TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
  7119.       /* The type of the main variant should never be used for arrays
  7120.      of different sizes.  It should only ever be completed with the
  7121.      size of the array.  */
  7122.       if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
  7123.     TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type);
  7124.     }
  7125.  
  7126.   /* Lay out the type now that we can get the real answer.  */
  7127.  
  7128.   layout_type (type);
  7129.  
  7130.   return value;
  7131. }
  7132.  
  7133. /* Return zero if something is declared to be a member of type
  7134.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  7135.    message to print in that case.  Otherwise, quietly return 1.  */
  7136. static int
  7137. member_function_or_else (ctype, cur_type, string)
  7138.      tree ctype, cur_type;
  7139.      char *string;
  7140. {
  7141.   if (ctype && ctype != cur_type)
  7142.     {
  7143.       error (string, TYPE_NAME_STRING (ctype));
  7144.       return 0;
  7145.     }
  7146.   return 1;
  7147. }
  7148.  
  7149. /* Subroutine of `grokdeclarator'.  */
  7150.  
  7151. /* Generate errors possibly applicable for a given set of specifiers.
  7152.    This is for ARM $7.1.2.  */
  7153. static void
  7154. bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
  7155.      tree object;
  7156.      char *type;
  7157.      int virtualp, quals, friendp, raises, inlinep;
  7158. {
  7159.   if (virtualp)
  7160.     cp_error ("`%D' declared as a `virtual' %s", object, type);
  7161.   if (inlinep)
  7162.     cp_error ("`%D' declared as an `inline' %s", object, type);
  7163.   if (quals)
  7164.     cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
  7165.           object, type);
  7166.   if (friendp)
  7167.     cp_error_at ("invalid friend declaration", object);
  7168.   if (raises)
  7169.     cp_error_at ("invalid exception specifications", object);
  7170. }
  7171.  
  7172. /* CTYPE is class type, or null if non-class.
  7173.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  7174.    or METHOD_TYPE.
  7175.    DECLARATOR is the function's name.
  7176.    VIRTUALP is truthvalue of whether the function is virtual or not.
  7177.    FLAGS are to be passed through to `grokclassfn'.
  7178.    QUALS are qualifiers indicating whether the function is `const'
  7179.    or `volatile'.
  7180.    RAISES is a list of exceptions that this function can raise.
  7181.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  7182.    not look, and -1 if we should not call `grokclassfn' at all.  */
  7183. static tree
  7184. grokfndecl (ctype, type, declarator, virtualp, flags, quals,
  7185.         raises, attrlist, check, publicp, inlinep)
  7186.      tree ctype, type;
  7187.      tree declarator;
  7188.      int virtualp;
  7189.      enum overload_flags flags;
  7190.      tree quals, raises, attrlist;
  7191.      int check, publicp, inlinep;
  7192. {
  7193.   tree cname, decl;
  7194.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  7195.  
  7196.   if (ctype)
  7197.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  7198.       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
  7199.   else
  7200.     cname = NULL_TREE;
  7201.  
  7202.   if (raises)
  7203.     {
  7204.       type = build_exception_variant (type, raises);
  7205.       raises = TYPE_RAISES_EXCEPTIONS (type);
  7206.     }
  7207.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  7208.   /* propagate volatile out from type to decl */
  7209.   if (TYPE_VOLATILE (type))
  7210.       TREE_THIS_VOLATILE (decl) = 1;
  7211.  
  7212.   /* Should probably propagate const out from type to decl I bet (mrs).  */
  7213.   if (staticp)
  7214.     {
  7215.       DECL_STATIC_FUNCTION_P (decl) = 1;
  7216.       DECL_CONTEXT (decl) = ctype;
  7217.       DECL_CLASS_CONTEXT (decl) = ctype;
  7218.     }
  7219.  
  7220.   /* All function decls start out public; we'll fix their linkage later (at
  7221.      definition or EOF) if appropriate.  */
  7222.   TREE_PUBLIC (decl) = 1;
  7223.  
  7224.   if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  7225.     {
  7226.       if (inlinep)
  7227.     error ("cannot declare `main' to be inline");
  7228.       else if (! publicp)
  7229.     error ("cannot declare `main' to be static");
  7230.       inlinep = 0;
  7231.       publicp = 1;
  7232.     }
  7233.       
  7234.   if (! publicp)
  7235.     DECL_C_STATIC (decl) = 1;
  7236.  
  7237.   if (inlinep)
  7238.     DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1;
  7239.  
  7240.   DECL_EXTERNAL (decl) = 1;
  7241.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  7242.     {
  7243.       cp_error ("%smember function `%D' cannot have `%T' method qualifier",
  7244.         (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
  7245.       quals = NULL_TREE;
  7246.     }
  7247.  
  7248.   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
  7249.     grok_op_properties (decl, virtualp, check < 0);
  7250.  
  7251.   /* Caller will do the rest of this.  */
  7252.   if (check < 0)
  7253.     return decl;
  7254.  
  7255.   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
  7256.     {
  7257.       tree tmp;
  7258.       /* Just handle constructors here.  We could do this
  7259.      inside the following if stmt, but I think
  7260.      that the code is more legible by breaking this
  7261.      case out.  See comments below for what each of
  7262.      the following calls is supposed to do.  */
  7263.       DECL_CONSTRUCTOR_P (decl) = 1;
  7264.  
  7265.       grokclassfn (ctype, declarator, decl, flags, quals);
  7266.       if (check)
  7267.     check_classfn (ctype, declarator, decl);
  7268.       if (! grok_ctor_properties (ctype, decl))
  7269.     return NULL_TREE;
  7270.  
  7271.       if (check == 0 && ! current_function_decl)
  7272.     {
  7273.       /* FIXME: this should only need to look at
  7274.              IDENTIFIER_GLOBAL_VALUE.  */
  7275.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  7276.       if (tmp == NULL_TREE)
  7277.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  7278.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  7279.         cp_error ("inconsistent declarations for `%D'", decl);
  7280.       else
  7281.         {
  7282.           duplicate_decls (decl, tmp);
  7283.           decl = tmp;
  7284.           /* avoid creating circularities.  */
  7285.           DECL_CHAIN (decl) = NULL_TREE;
  7286.         }
  7287.       make_decl_rtl (decl, NULL_PTR, 1);
  7288.     }
  7289.     }
  7290.   else
  7291.     {
  7292.       tree tmp;
  7293.  
  7294.       /* Function gets the ugly name, field gets the nice one.
  7295.      This call may change the type of the function (because
  7296.      of default parameters)!  */
  7297.       if (ctype != NULL_TREE)
  7298.     grokclassfn (ctype, cname, decl, flags, quals);
  7299.  
  7300.       if (ctype != NULL_TREE && check)
  7301.     check_classfn (ctype, cname, decl);
  7302.  
  7303.       if (ctype == NULL_TREE || check)
  7304.     return decl;
  7305.  
  7306.       /* Now install the declaration of this function so that others may
  7307.      find it (esp. its DECL_FRIENDLIST).  Don't do this for local class
  7308.      methods, though.  */
  7309.       if (! current_function_decl)
  7310.     {
  7311.       /* FIXME: this should only need to look at
  7312.              IDENTIFIER_GLOBAL_VALUE.  */
  7313.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  7314.       if (tmp == NULL_TREE)
  7315.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  7316.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  7317.         cp_error ("inconsistent declarations for `%D'", decl);
  7318.       else
  7319.         {
  7320.           duplicate_decls (decl, tmp);
  7321.           decl = tmp;
  7322.           /* avoid creating circularities.  */
  7323.           DECL_CHAIN (decl) = NULL_TREE;
  7324.         }
  7325.  
  7326.       if (attrlist)
  7327.         cplus_decl_attributes (decl, TREE_PURPOSE (attrlist),
  7328.                    TREE_VALUE (attrlist));
  7329.       make_decl_rtl (decl, NULL_PTR, 1);
  7330.     }
  7331.  
  7332.       /* If this declaration supersedes the declaration of
  7333.      a method declared virtual in the base class, then
  7334.      mark this field as being virtual as well.  */
  7335.       {
  7336.     tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
  7337.     int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  7338.  
  7339.     for (i = 0; i < n_baselinks; i++)
  7340.       {
  7341.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  7342.         if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
  7343.         || flag_all_virtual == 1)
  7344.           {
  7345.         tmp = get_matching_virtual (base_binfo, decl,
  7346.                         flags == DTOR_FLAG);
  7347.         if (tmp)
  7348.           {
  7349.             /* If this function overrides some virtual in some base
  7350.                class, then the function itself is also necessarily
  7351.                virtual, even if the user didn't explicitly say so.  */
  7352.             DECL_VIRTUAL_P (decl) = 1;
  7353.  
  7354.             /* The TMP we really want is the one from the deepest
  7355.                baseclass on this path, taking care not to
  7356.                duplicate if we have already found it (via another
  7357.                path to its virtual baseclass.  */
  7358.             if (staticp)
  7359.               {
  7360.             cp_error ("method `%D' may not be declared static",
  7361.                   decl);
  7362.             cp_error_at ("(since `%D' declared virtual in base class.)",
  7363.                      tmp);
  7364.             break;
  7365.               }
  7366.             virtualp = 1;
  7367.  
  7368.             {
  7369.               /* The argument types may have changed... */
  7370.               tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  7371.               tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  7372.  
  7373.               argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  7374.                           TREE_CHAIN (argtypes));
  7375.               /* But the return type has not.  */
  7376.               type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  7377.               if (raises)
  7378.             {
  7379.               type = build_exception_variant (type, raises);
  7380.               raises = TYPE_RAISES_EXCEPTIONS (type);
  7381.             }
  7382.               TREE_TYPE (decl) = type;
  7383.               DECL_VINDEX (decl)
  7384.             = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
  7385.             }
  7386.             break;
  7387.           }
  7388.           }
  7389.       }
  7390.       }
  7391.       if (virtualp)
  7392.     {
  7393.       if (DECL_VINDEX (decl) == NULL_TREE)
  7394.         DECL_VINDEX (decl) = error_mark_node;
  7395.       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
  7396.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  7397.           /* If this function is derived from a template, don't
  7398.          make it public.  This shouldn't be here, but there's
  7399.          no good way to override the interface pragmas for one
  7400.          function or class only.  Bletch.  */
  7401.           && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
  7402.           && (write_virtuals == 2
  7403.           || (write_virtuals == 3
  7404.               && CLASSTYPE_INTERFACE_KNOWN (ctype))))
  7405.         TREE_PUBLIC (decl) = 1;
  7406.     }
  7407.     }
  7408.   return decl;
  7409. }
  7410.  
  7411. static tree
  7412. grokvardecl (type, declarator, specbits, initialized, constp)
  7413.      tree type;
  7414.      tree declarator;
  7415.      RID_BIT_TYPE specbits;
  7416.      int initialized;
  7417.      int constp;
  7418. {
  7419.   tree decl;
  7420.  
  7421.   if (TREE_CODE (type) == OFFSET_TYPE)
  7422.     {
  7423.       /* If you declare a static member so that it
  7424.      can be initialized, the code will reach here.  */
  7425.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  7426.       type = TREE_TYPE (type);
  7427.       decl = build_lang_field_decl (VAR_DECL, declarator, type);
  7428.       DECL_CONTEXT (decl) = basetype;
  7429.       DECL_CLASS_CONTEXT (decl) = basetype;
  7430.       DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
  7431.     }
  7432.   else
  7433.     decl = build_decl (VAR_DECL, declarator, type);
  7434.  
  7435.   DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
  7436.  
  7437.   if (RIDBIT_SETP (RID_EXTERN, specbits))
  7438.     {
  7439.       DECL_THIS_EXTERN (decl) = 1;
  7440.       DECL_EXTERNAL (decl) = !initialized;
  7441.     }
  7442.  
  7443.   /* In class context, static means one per class,
  7444.      public access, and static storage.  */
  7445.   if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
  7446.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  7447.     {
  7448.       TREE_PUBLIC (decl) = 1;
  7449.       TREE_STATIC (decl) = 1;
  7450.       DECL_EXTERNAL (decl) = 0;
  7451.     }
  7452.   /* At top level, either `static' or no s.c. makes a definition
  7453.      (perhaps tentative), and absence of `static' makes it public.  */
  7454.   else if (toplevel_bindings_p ())
  7455.     {
  7456.       TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
  7457.                 && (DECL_THIS_EXTERN (decl) || ! constp));
  7458.       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
  7459.     }
  7460.   /* Not at top level, only `static' makes a static definition.  */
  7461.   else
  7462.     {
  7463.       TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
  7464.       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
  7465.     }
  7466.   return decl;
  7467. }
  7468.  
  7469. /* Create a canonical pointer to member function type. */
  7470.  
  7471. tree
  7472. build_ptrmemfunc_type (type)
  7473.      tree type;
  7474. {
  7475.   tree fields[4];
  7476.   tree t;
  7477.   tree u;
  7478.  
  7479.   /* If a canonical type already exists for this type, use it.  We use
  7480.      this method instead of type_hash_canon, because it only does a
  7481.      simple equality check on the list of field members.  */
  7482.  
  7483.   if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
  7484.     return t;
  7485.  
  7486.   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
  7487.  
  7488.   u = make_lang_type (UNION_TYPE);
  7489.   IS_AGGR_TYPE (u) = 0;
  7490.   fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
  7491.   fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
  7492.                      delta_type_node);
  7493.   finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
  7494.   TYPE_NAME (u) = NULL_TREE;
  7495.  
  7496.   t = make_lang_type (RECORD_TYPE);
  7497.  
  7498.   /* Let the front-end know this is a pointer to member function. */
  7499.   TYPE_PTRMEMFUNC_FLAG (t) = 1;
  7500.   /* and not really an aggregate.  */
  7501.   IS_AGGR_TYPE (t) = 0;
  7502.  
  7503.   fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  7504.                      delta_type_node);
  7505.   fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  7506.                      delta_type_node);
  7507.   fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
  7508.   finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
  7509.  
  7510.   pop_obstacks ();
  7511.  
  7512.   /* Zap out the name so that the back-end will give us the debugging
  7513.      information for this anonymous RECORD_TYPE.  */
  7514.   TYPE_NAME (t) = NULL_TREE;
  7515.  
  7516.   TYPE_SET_PTRMEMFUNC_TYPE (type, t);
  7517.  
  7518.   /* Seems to be wanted. */
  7519.   CLASSTYPE_GOT_SEMICOLON (t) = 1;
  7520.   return t;
  7521. }
  7522.  
  7523. /* Given declspecs and a declarator,
  7524.    determine the name and type of the object declared
  7525.    and construct a ..._DECL node for it.
  7526.    (In one case we can return a ..._TYPE node instead.
  7527.     For invalid input we sometimes return 0.)
  7528.  
  7529.    DECLSPECS is a chain of tree_list nodes whose value fields
  7530.     are the storage classes and type specifiers.
  7531.  
  7532.    DECL_CONTEXT says which syntactic context this declaration is in:
  7533.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  7534.      FUNCDEF for a function definition.  Like NORMAL but a few different
  7535.       error messages in each case.  Return value may be zero meaning
  7536.       this definition is too screwy to try to parse.
  7537.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  7538.       handle member functions (which have FIELD context).
  7539.       Return value may be zero meaning this definition is too screwy to
  7540.       try to parse.
  7541.      PARM for a parameter declaration (either within a function prototype
  7542.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  7543.      CATCHPARM for a parameter declaration before a catch clause.
  7544.      TYPENAME if for a typename (in a cast or sizeof).
  7545.       Don't make a DECL node; just return the ..._TYPE node.
  7546.      FIELD for a struct or union field; make a FIELD_DECL.
  7547.      BITFIELD for a field with specified width.
  7548.    INITIALIZED is 1 if the decl has an initializer.
  7549.  
  7550.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  7551.    It may also be so in the PARM case, for a prototype where the
  7552.    argument type is specified but not the name.
  7553.  
  7554.    This function is where the complicated C meanings of `static'
  7555.    and `extern' are interpreted.
  7556.  
  7557.    For C++, if there is any monkey business to do, the function which
  7558.    calls this one must do it, i.e., prepending instance variables,
  7559.    renaming overloaded function names, etc.
  7560.  
  7561.    Note that for this C++, it is an error to define a method within a class
  7562.    which does not belong to that class.
  7563.  
  7564.    Except in the case where SCOPE_REFs are implicitly known (such as
  7565.    methods within a class being redundantly qualified),
  7566.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  7567.    (class_name::decl_name).  The caller must also deal with this.
  7568.  
  7569.    If a constructor or destructor is seen, and the context is FIELD,
  7570.    then the type gains the attribute TREE_HAS_x.  If such a declaration
  7571.    is erroneous, NULL_TREE is returned.
  7572.  
  7573.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  7574.    function, these are the qualifiers to give to the `this' pointer.
  7575.  
  7576.    May return void_type_node if the declarator turned out to be a friend.
  7577.    See grokfield for details.  */
  7578.  
  7579. enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
  7580.  
  7581. tree
  7582. grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist)
  7583.      tree declspecs;
  7584.      tree declarator;
  7585.      enum decl_context decl_context;
  7586.      int initialized;
  7587.      tree raises, attrlist;
  7588. {
  7589.   RID_BIT_TYPE specbits;
  7590.   int nclasses = 0;
  7591.   tree spec;
  7592.   tree type = NULL_TREE;
  7593.   int longlong = 0;
  7594.   int constp;
  7595.   int volatilep;
  7596.   int virtualp, explicitp, friendp, inlinep, staticp;
  7597.   int explicit_int = 0;
  7598.   int explicit_char = 0;
  7599.   int opaque_typedef = 0;
  7600.   tree typedef_decl = NULL_TREE;
  7601.   char *name;
  7602.   tree typedef_type = NULL_TREE;
  7603.   int funcdef_flag = 0;
  7604.   enum tree_code innermost_code = ERROR_MARK;
  7605.   int bitfield = 0;
  7606.   int size_varies = 0;
  7607.   tree decl_machine_attr = NULL_TREE;
  7608. #if defined (_WIN32) && defined (NEXT_PDO)
  7609.   int stdcallp;     // Needed to support the __stdcall keyword used by Microsoft
  7610. #endif
  7611.  
  7612.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  7613.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  7614.   tree init = NULL_TREE;
  7615.  
  7616.   /* Keep track of what sort of function is being processed
  7617.      so that we can warn about default return values, or explicit
  7618.      return values which do not match prescribed defaults.  */
  7619.   enum return_types return_type = return_normal;
  7620.  
  7621.   tree dname = NULL_TREE;
  7622.   tree ctype = current_class_type;
  7623.   tree ctor_return_type = NULL_TREE;
  7624.   enum overload_flags flags = NO_SPECIAL;
  7625.   tree quals = NULL_TREE;
  7626.  
  7627.   RIDBIT_RESET_ALL (specbits);
  7628.   if (decl_context == FUNCDEF)
  7629.     funcdef_flag = 1, decl_context = NORMAL;
  7630.   else if (decl_context == MEMFUNCDEF)
  7631.     funcdef_flag = -1, decl_context = FIELD;
  7632.   else if (decl_context == BITFIELD)
  7633.     bitfield = 1, decl_context = FIELD;
  7634.  
  7635.   if (flag_traditional && allocation_temporary_p ())
  7636.     end_temporary_allocation ();
  7637.  
  7638.   /* Look inside a declarator for the name being declared
  7639.      and get it as a string, for an error message.  */
  7640.   {
  7641.     tree last = NULL_TREE;
  7642.     register tree decl = declarator;
  7643.     name = NULL;
  7644.  
  7645.     while (decl)
  7646.       switch (TREE_CODE (decl))
  7647.         {
  7648.     case COND_EXPR:
  7649.       ctype = NULL_TREE;
  7650.       decl = TREE_OPERAND (decl, 0);
  7651.       break;
  7652.  
  7653.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  7654.       {
  7655.         tree name = TREE_OPERAND (decl, 0);
  7656.         tree rename = NULL_TREE;
  7657.  
  7658.         my_friendly_assert (flags == NO_SPECIAL, 152);
  7659.         flags = DTOR_FLAG;
  7660.         return_type = return_dtor;
  7661.         my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
  7662.         if (ctype == NULL_TREE)
  7663.           {
  7664.         if (current_class_type == NULL_TREE)
  7665.           {
  7666.             error ("destructors must be member functions");
  7667.             flags = NO_SPECIAL;
  7668.           }
  7669.         else
  7670.           {
  7671.             tree t = constructor_name (current_class_name);
  7672.             if (t != name)
  7673.               rename = t;
  7674.           }
  7675.           }
  7676.         else
  7677.           {
  7678.         tree t = constructor_name (ctype);
  7679.         if (t != name)
  7680.           rename = t;
  7681.           }
  7682.  
  7683.         if (rename)
  7684.           {
  7685.         error ("destructor `%s' must match class name `%s'",
  7686.                IDENTIFIER_POINTER (name),
  7687.                IDENTIFIER_POINTER (rename));
  7688.         TREE_OPERAND (decl, 0) = rename;
  7689.           }
  7690.         decl = name;
  7691.       }
  7692.       break;
  7693.  
  7694.     case ADDR_EXPR:         /* C++ reference declaration */
  7695.       /* fall through */
  7696.     case ARRAY_REF:
  7697.     case INDIRECT_REF:
  7698.       ctype = NULL_TREE;
  7699.       innermost_code = TREE_CODE (decl);
  7700.       last = decl;
  7701.       decl = TREE_OPERAND (decl, 0);
  7702.       break;
  7703.  
  7704.     case CALL_EXPR:
  7705.       if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  7706.         {
  7707.           /* This is actually a variable declaration using constructor
  7708.          syntax.  We need to call start_decl and cp_finish_decl so we
  7709.          can get the variable initialized...  */
  7710.  
  7711.           if (last)
  7712.         /* We need to insinuate ourselves into the declarator in place
  7713.            of the CALL_EXPR.  */
  7714.         TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  7715.           else
  7716.         declarator = TREE_OPERAND (decl, 0);
  7717.  
  7718.           init = TREE_OPERAND (decl, 1);
  7719.  
  7720.           decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  7721.           finish_decl (decl, init, NULL_TREE);
  7722.           return 0;
  7723.         }
  7724.       innermost_code = TREE_CODE (decl);
  7725.       if (decl_context == FIELD && ctype == NULL_TREE)
  7726.         ctype = current_class_type;
  7727.       if (ctype
  7728.           && TREE_OPERAND (decl, 0) == constructor_name_full (ctype))
  7729.         TREE_OPERAND (decl, 0) = constructor_name (ctype);
  7730.       decl = TREE_OPERAND (decl, 0);
  7731.       if (ctype != NULL_TREE
  7732.           && decl != NULL_TREE && flags != DTOR_FLAG
  7733.           && decl == constructor_name (ctype))
  7734.         {
  7735.           return_type = return_ctor;
  7736.           ctor_return_type = ctype;
  7737.         }
  7738.       ctype = NULL_TREE;
  7739.       break;
  7740.  
  7741.     case IDENTIFIER_NODE:
  7742.       dname = decl;
  7743.       decl = NULL_TREE;
  7744.  
  7745.       if (! IDENTIFIER_OPNAME_P (dname)
  7746.           /* Linux headers use '__op'.  Arrgh.  */
  7747.           || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
  7748.         name = IDENTIFIER_POINTER (dname);
  7749.       else
  7750.         {
  7751.           if (IDENTIFIER_TYPENAME_P (dname))
  7752.         {
  7753.           my_friendly_assert (flags == NO_SPECIAL, 154);
  7754.           flags = TYPENAME_FLAG;
  7755.           ctor_return_type = TREE_TYPE (dname);
  7756.           return_type = return_conversion;
  7757.         }
  7758.           name = operator_name_string (dname);
  7759.         }
  7760.       break;
  7761.  
  7762.     case RECORD_TYPE:
  7763.     case UNION_TYPE:
  7764.     case ENUMERAL_TYPE:
  7765.       /* Parse error puts this typespec where
  7766.          a declarator should go.  */
  7767.       error ("declarator name missing");
  7768.       dname = TYPE_NAME (decl);
  7769.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  7770.         dname = DECL_NAME (dname);
  7771.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  7772.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  7773.       decl = NULL_TREE;
  7774.       break;
  7775.  
  7776.       /* C++ extension */
  7777.     case SCOPE_REF:
  7778.       {
  7779.         /* Perform error checking, and convert class names to types.
  7780.            We may call grokdeclarator multiple times for the same
  7781.            tree structure, so only do the conversion once.  In this
  7782.            case, we have exactly what we want for `ctype'.  */
  7783.         tree cname = TREE_OPERAND (decl, 0);
  7784.         if (cname == NULL_TREE)
  7785.           ctype = NULL_TREE;
  7786.         /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
  7787.         else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
  7788.              || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
  7789.           ctype = cname;
  7790.         else if (! is_aggr_typedef (cname, 1))
  7791.           {
  7792.         TREE_OPERAND (decl, 0) = NULL_TREE;
  7793.           }
  7794.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  7795.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  7796.         else if (TREE_OPERAND (decl, 1)
  7797.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  7798.           {
  7799.         TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
  7800.           }
  7801.         else if (ctype == NULL_TREE)
  7802.           {
  7803.         ctype = IDENTIFIER_TYPE_VALUE (cname);
  7804.         TREE_OPERAND (decl, 0) = ctype;
  7805.           }
  7806.         else if (TREE_COMPLEXITY (decl) == current_class_depth)
  7807.           TREE_OPERAND (decl, 0) = ctype;
  7808.         else
  7809.           {
  7810.         if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
  7811.                            ctype))
  7812.           {
  7813.             cp_error ("type `%T' is not derived from type `%T'",
  7814.                   IDENTIFIER_TYPE_VALUE (cname), ctype);
  7815.             TREE_OPERAND (decl, 0) = NULL_TREE;
  7816.           }
  7817.         else
  7818.           {
  7819.             ctype = IDENTIFIER_TYPE_VALUE (cname);
  7820.             TREE_OPERAND (decl, 0) = ctype;
  7821.           }
  7822.           }
  7823.  
  7824.         if (ctype
  7825.         && TREE_OPERAND (decl, 1) == constructor_name_full (ctype))
  7826.           TREE_OPERAND (decl, 1) = constructor_name (ctype);
  7827.         decl = TREE_OPERAND (decl, 1);
  7828.         if (ctype)
  7829.           {
  7830.         if (TREE_CODE (decl) == IDENTIFIER_NODE
  7831.             && constructor_name (ctype) == decl)
  7832.           {
  7833.             return_type = return_ctor;
  7834.             ctor_return_type = ctype;
  7835.           }
  7836.         else if (TREE_CODE (decl) == BIT_NOT_EXPR
  7837.              && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  7838.              && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
  7839.                  || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
  7840.           {
  7841.             return_type = return_dtor;
  7842.             ctor_return_type = ctype;
  7843.             flags = DTOR_FLAG;
  7844.             decl = TREE_OPERAND (decl, 0) = constructor_name (ctype);
  7845.           }
  7846.           }
  7847.       }
  7848.       break;
  7849.  
  7850.     case ERROR_MARK:
  7851.       decl = NULL_TREE;
  7852.       break;
  7853.  
  7854.     default:
  7855.       return 0; /* We used to do a 155 abort here.  */
  7856.     }
  7857.     if (name == NULL)
  7858.       name = "type name";
  7859.   }
  7860.  
  7861.   /* A function definition's declarator must have the form of
  7862.      a function declarator.  */
  7863.  
  7864.   if (funcdef_flag && innermost_code != CALL_EXPR)
  7865.     return 0;
  7866.  
  7867.   if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
  7868.       && innermost_code != CALL_EXPR
  7869.       && ! (ctype && declspecs == NULL_TREE))
  7870.     {
  7871.       cp_error ("declaration of `%D' as non-function", dname);
  7872.       return void_type_node;
  7873.     }
  7874.  
  7875.   /* Anything declared one level down from the top level
  7876.      must be one of the parameters of a function
  7877.      (because the body is at least two levels down).  */
  7878.  
  7879.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  7880.      by not allowing C++ class definitions to specify their parameters
  7881.      with xdecls (must be spec.d in the parmlist).
  7882.  
  7883.      Since we now wait to push a class scope until we are sure that
  7884.      we are in a legitimate method context, we must set oldcname
  7885.      explicitly (since current_class_name is not yet alive).
  7886.  
  7887.      We also want to avoid calling this a PARM if it is in a namespace.  */
  7888.  
  7889.   if (decl_context == NORMAL && ! namespace_bindings_p ())
  7890.     {
  7891.       struct binding_level *b = current_binding_level;
  7892.       current_binding_level = b->level_chain;
  7893.       if (current_binding_level != 0 && toplevel_bindings_p ())
  7894.     decl_context = PARM;
  7895.       current_binding_level = b;
  7896.     }
  7897.  
  7898.   /* Look through the decl specs and record which ones appear.
  7899.      Some typespecs are defined as built-in typenames.
  7900.      Others, the ones that are modifiers of other types,
  7901.      are represented by bits in SPECBITS: set the bits for
  7902.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  7903.  
  7904.      If there is a typedef name or a type, store the type in TYPE.
  7905.      This includes builtin typedefs such as `int'.
  7906.  
  7907.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  7908.      come from a user typedef.
  7909.  
  7910.      Set LONGLONG if `long' is mentioned twice.
  7911.  
  7912.      For C++, constructors and destructors have their own fast treatment.  */
  7913.  
  7914.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  7915.     {
  7916.       register int i;
  7917.       register tree id;
  7918.  
  7919.       /* Certain parse errors slip through.  For example,
  7920.      `int class;' is not caught by the parser. Try
  7921.      weakly to recover here.  */
  7922.       if (TREE_CODE (spec) != TREE_LIST)
  7923.     return 0;
  7924.  
  7925.       id = TREE_VALUE (spec);
  7926.  
  7927.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  7928.     {
  7929.       if (id == ridpointers[(int) RID_INT]
  7930.           || id == ridpointers[(int) RID_CHAR]
  7931.           || id == ridpointers[(int) RID_BOOL]
  7932.           || id == ridpointers[(int) RID_WCHAR])
  7933.         {
  7934.           if (type)
  7935.         {
  7936.           if (id == ridpointers[(int) RID_BOOL])
  7937.             error ("`bool' is now a keyword");
  7938.           else
  7939.             cp_error ("extraneous `%T' ignored", id);
  7940.         }
  7941.           else
  7942.         {
  7943.           if (id == ridpointers[(int) RID_INT])
  7944.             explicit_int = 1;
  7945.           else if (id == ridpointers[(int) RID_CHAR])
  7946.             explicit_char = 1;
  7947.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7948.         }
  7949.           goto found;
  7950.         }
  7951.       /* C++ aggregate types. */
  7952.       if (IDENTIFIER_HAS_TYPE_VALUE (id))
  7953.         {
  7954.           if (type)
  7955.         cp_error ("multiple declarations `%T' and `%T'", type, id);
  7956.           else
  7957.         type = IDENTIFIER_TYPE_VALUE (id);
  7958.           goto found;
  7959.         }
  7960.  
  7961.       for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
  7962.         {
  7963.           if (ridpointers[i] == id)
  7964.         {
  7965.           if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
  7966.             {
  7967.               if (pedantic && ! in_system_header)
  7968.             pedwarn ("ANSI C++ does not support `long long'");
  7969.               else if (longlong)
  7970.             error ("`long long long' is too long for GCC");
  7971.               else
  7972.             longlong = 1;
  7973.             }
  7974.           else if (RIDBIT_SETP (i, specbits))
  7975.             pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  7976.           RIDBIT_SET (i, specbits);
  7977.           goto found;
  7978.         }
  7979.         }
  7980.     }
  7981.       if (type)
  7982.     error ("two or more data types in declaration of `%s'", name);
  7983.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  7984.     {
  7985.       register tree t = lookup_name (id, 1);
  7986.       if (!t || TREE_CODE (t) != TYPE_DECL)
  7987.         error ("`%s' fails to be a typedef or built in type",
  7988.            IDENTIFIER_POINTER (id));
  7989.       else
  7990.         {
  7991.           type = TREE_TYPE (t);
  7992.           decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
  7993.           typedef_decl = t;
  7994.         }
  7995.     }
  7996.       else if (TREE_CODE (id) != ERROR_MARK)
  7997.     /* Can't change CLASS nodes into RECORD nodes here!  */
  7998.     type = id;
  7999.  
  8000.     found: ;
  8001.     }
  8002.  
  8003. #if defined (_WIN32) && defined (NEXT_PDO)
  8004.   if (RIDBIT_SETP (RID_DLLIMPORT, specbits))
  8005.     {
  8006.       /* If this is a variable that is being dllimported, then
  8007.      it's really a pointer to a variable where the address 
  8008.      of the variable is what is pointed to.  */
  8009. /*        if( TREE_CODE (declarator) != CALL_EXPR )
  8010.             declarator = build1 (INDIRECT_REF, NULL_TREE, declarator);*/
  8011.     }
  8012. #endif /* _WIN32 */
  8013.  
  8014.   typedef_type = type;
  8015.  
  8016.   /* No type at all: default to `int', and set EXPLICIT_INT
  8017.      because it was not a user-defined typedef.
  8018.      Except when we have a `typedef' inside a signature, in
  8019.      which case the type defaults to `unknown type' and is
  8020.      instantiated when assigning to a signature pointer or ref.  */
  8021.  
  8022.   if (type == NULL_TREE
  8023.       && (RIDBIT_SETP (RID_SIGNED, specbits)
  8024.       || RIDBIT_SETP (RID_UNSIGNED, specbits)
  8025.       || RIDBIT_SETP (RID_LONG, specbits)
  8026.       || RIDBIT_SETP (RID_SHORT, specbits)))
  8027.     {
  8028.       /* These imply 'int'.  */
  8029.       type = integer_type_node;
  8030.       explicit_int = 1;
  8031.     }
  8032.  
  8033.   if (type == NULL_TREE)
  8034.     {
  8035.       explicit_int = -1;
  8036.       if (return_type == return_dtor)
  8037.     type = void_type_node;
  8038.       else if (return_type == return_ctor)
  8039.     type = build_pointer_type (ctor_return_type);
  8040.       else if (return_type == return_conversion)
  8041.     type = ctor_return_type;
  8042.       else if (current_class_type
  8043.            && IS_SIGNATURE (current_class_type)
  8044.            && (RIDBIT_SETP (RID_TYPEDEF, specbits)
  8045.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8046.            && (decl_context == FIELD || decl_context == NORMAL))
  8047.     {
  8048.       explicit_int = 0;
  8049.       opaque_typedef = 1;
  8050.       type = copy_node (opaque_type_node);
  8051.     }
  8052.       /* access declaration */
  8053.       else if (decl_context == FIELD && declarator
  8054.            && TREE_CODE (declarator) == SCOPE_REF)
  8055.     type = void_type_node;
  8056.       else
  8057.     {
  8058.       if (funcdef_flag)
  8059.         {
  8060.           if (warn_return_type
  8061.           && return_type == return_normal)
  8062.         /* Save warning until we know what is really going on.  */
  8063.         warn_about_return_type = 1;
  8064.         }
  8065.       else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8066.         pedwarn ("ANSI C++ forbids typedef which does not specify a type");
  8067.       else if (declspecs == NULL_TREE &&
  8068.            (innermost_code != CALL_EXPR || pedantic))
  8069.         cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
  8070.             dname);
  8071.       type = integer_type_node;
  8072.     }
  8073.     }
  8074.   else if (return_type == return_dtor)
  8075.     {
  8076.       error ("return type specification for destructor invalid");
  8077.       type = void_type_node;
  8078.     }
  8079.   else if (return_type == return_ctor)
  8080.     {
  8081.       error ("return type specification for constructor invalid");
  8082.       type = build_pointer_type (ctor_return_type);
  8083.     }
  8084.   else if (return_type == return_conversion)
  8085.     {
  8086.       if (comptypes (type, ctor_return_type, 1) == 0)
  8087.     cp_error ("operator `%T' declared to return `%T'",
  8088.           ctor_return_type, type);
  8089.       else
  8090.     cp_pedwarn ("return type specified for `operator %T'",
  8091.             ctor_return_type);
  8092.  
  8093.       type = ctor_return_type;
  8094.     }
  8095.   /* Catch typedefs that only specify a type, like 'typedef int;'.  */
  8096.   else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
  8097.     {
  8098.       /* Template "this is a type" syntax; just ignore for now.  */
  8099.       if (processing_template_defn)
  8100.     return void_type_node;
  8101.     }
  8102.  
  8103.   ctype = NULL_TREE;
  8104.  
  8105.   /* Now process the modifiers that were specified
  8106.      and check for invalid combinations.  */
  8107.  
  8108.   /* Long double is a special combination.  */
  8109.  
  8110.   if (RIDBIT_SETP (RID_LONG, specbits)
  8111.       && TYPE_MAIN_VARIANT (type) == double_type_node)
  8112.     {
  8113.       RIDBIT_RESET (RID_LONG, specbits);
  8114.       type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
  8115.                  TYPE_VOLATILE (type));
  8116.     }
  8117.  
  8118.   /* Check all other uses of type modifiers.  */
  8119.  
  8120.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  8121.       || RIDBIT_SETP (RID_SIGNED, specbits)
  8122.       || RIDBIT_SETP (RID_LONG, specbits)
  8123.       || RIDBIT_SETP (RID_SHORT, specbits))
  8124.     {
  8125.       int ok = 0;
  8126.  
  8127.       if (TREE_CODE (type) == REAL_TYPE)
  8128.     error ("short, signed or unsigned invalid for `%s'", name);
  8129.       else if (TREE_CODE (type) != INTEGER_TYPE)
  8130.     error ("long, short, signed or unsigned invalid for `%s'", name);
  8131.       else if (RIDBIT_SETP (RID_LONG, specbits)
  8132.            && RIDBIT_SETP (RID_SHORT, specbits))
  8133.     error ("long and short specified together for `%s'", name);
  8134.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  8135.         || RIDBIT_SETP (RID_SHORT, specbits))
  8136.            && explicit_char)
  8137.     error ("long or short specified with char for `%s'", name);
  8138.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  8139.         || RIDBIT_SETP (RID_SHORT, specbits))
  8140.            && TREE_CODE (type) == REAL_TYPE)
  8141.     error ("long or short specified with floating type for `%s'", name);
  8142.       else if (RIDBIT_SETP (RID_SIGNED, specbits)
  8143.            && RIDBIT_SETP (RID_UNSIGNED, specbits))
  8144.     error ("signed and unsigned given together for `%s'", name);
  8145.       else
  8146.     {
  8147.       ok = 1;
  8148.       if (!explicit_int && !explicit_char && pedantic)
  8149.         {
  8150.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  8151.                name);
  8152.           if (flag_pedantic_errors)
  8153.         ok = 0;
  8154.         }
  8155.     }
  8156.  
  8157.       /* Discard the type modifiers if they are invalid.  */
  8158.       if (! ok)
  8159.     {
  8160.       RIDBIT_RESET (RID_UNSIGNED, specbits);
  8161.       RIDBIT_RESET (RID_SIGNED, specbits);
  8162.       RIDBIT_RESET (RID_LONG, specbits);
  8163.       RIDBIT_RESET (RID_SHORT, specbits);
  8164.       longlong = 0;
  8165.     }
  8166.     }
  8167.  
  8168.   /* Decide whether an integer type is signed or not.
  8169.      Optionally treat bitfields as signed by default.  */
  8170.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  8171.       /* Traditionally, all bitfields are unsigned.  */
  8172.       || (bitfield && flag_traditional)
  8173.       || (bitfield && ! flag_signed_bitfields
  8174.       && (explicit_int || explicit_char
  8175.           /* A typedef for plain `int' without `signed'
  8176.          can be controlled just like plain `int'.  */
  8177.           || ! (typedef_decl != NULL_TREE
  8178.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  8179.       && TREE_CODE (type) != ENUMERAL_TYPE
  8180.       && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
  8181.     {
  8182.       if (longlong)
  8183.     type = long_long_unsigned_type_node;
  8184.       else if (RIDBIT_SETP (RID_LONG, specbits))
  8185.     type = long_unsigned_type_node;
  8186.       else if (RIDBIT_SETP (RID_SHORT, specbits))
  8187.     type = short_unsigned_type_node;
  8188.       else if (type == char_type_node)
  8189.     type = unsigned_char_type_node;
  8190.       else if (typedef_decl)
  8191.     type = unsigned_type (type);
  8192.       else
  8193.     type = unsigned_type_node;
  8194.     }
  8195.   else if (RIDBIT_SETP (RID_SIGNED, specbits)
  8196.        && type == char_type_node)
  8197.     type = signed_char_type_node;
  8198.   else if (longlong)
  8199.     type = long_long_integer_type_node;
  8200.   else if (RIDBIT_SETP (RID_LONG, specbits))
  8201.     type = long_integer_type_node;
  8202.   else if (RIDBIT_SETP (RID_SHORT, specbits))
  8203.     type = short_integer_type_node;
  8204.  
  8205.   /* Set CONSTP if this declaration is `const', whether by
  8206.      explicit specification or via a typedef.
  8207.      Likewise for VOLATILEP.  */
  8208.  
  8209.   constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
  8210.   volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
  8211.   staticp = 0;
  8212.   inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
  8213. #if defined (_WIN32) && defined (NEXT_PDO)
  8214.   /* TYPE_STDCALL checks the stdcall_flag in the tree structure which indicates
  8215.      that this function uses the stdcall calling convention where the callee
  8216.      pops the arguments off the stack on return, the caller does nothing. */
  8217.   stdcallp = !! (RIDBIT_SETP (RID_STDCALL, specbits))/* + TYPE_STDCALL (type)*/;
  8218. #endif
  8219.  
  8220. #if 0
  8221.   /* This sort of redundancy is blessed in a footnote to the Sep 94 WP.  */
  8222.   if (constp > 1)
  8223.     warning ("duplicate `const'");
  8224.   if (volatilep > 1)
  8225.     warning ("duplicate `volatile'");
  8226. #endif
  8227.   virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
  8228.   RIDBIT_RESET (RID_VIRTUAL, specbits);
  8229.   explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
  8230.   RIDBIT_RESET (RID_EXPLICIT, specbits);
  8231.  
  8232.   if (RIDBIT_SETP (RID_STATIC, specbits))
  8233.     staticp = 1 + (decl_context == FIELD);
  8234.  
  8235.   if (virtualp && staticp == 2)
  8236.     {
  8237.       cp_error ("member `%D' cannot be declared both virtual and static",
  8238.         dname);
  8239.       staticp = 0;
  8240.     }
  8241.   friendp = RIDBIT_SETP (RID_FRIEND, specbits);
  8242.   RIDBIT_RESET (RID_FRIEND, specbits);
  8243.  
  8244.   if (RIDBIT_SETP (RID_MUTABLE, specbits))
  8245.     {
  8246.       if (decl_context == PARM)
  8247.     {
  8248.       error ("non-member `%s' cannot be declared `mutable'", name);
  8249.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8250.     }
  8251.       else if (friendp || decl_context == TYPENAME)
  8252.     {
  8253.       error ("non-object member `%s' cannot be declared `mutable'", name);
  8254.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8255.     }
  8256. #if 0
  8257.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8258.     {
  8259.       error ("non-object member `%s' cannot be declared `mutable'", name);
  8260.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8261.     }
  8262.       /* Because local typedefs are parsed twice, we don't want this
  8263.      message here. */
  8264.       else if (decl_context != FIELD)
  8265.     {
  8266.       error ("non-member `%s' cannot be declared `mutable'", name);
  8267.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8268.     }
  8269. #endif
  8270.     }
  8271.  
  8272.   /* Warn if two storage classes are given. Default to `auto'.  */
  8273.  
  8274.   if (RIDBIT_ANY_SET (specbits))
  8275.     {
  8276.       if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
  8277.       if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
  8278.       if (decl_context == PARM && nclasses > 0)
  8279.     error ("storage class specifiers invalid in parameter declarations");
  8280.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8281.     {
  8282.       if (decl_context == PARM)
  8283.         error ("typedef declaration invalid in parameter declaration");
  8284.       nclasses++;
  8285.     }
  8286.       if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
  8287.       if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
  8288.     }
  8289.  
  8290.   /* Give error if `virtual' is used outside of class declaration.  */
  8291.   if (virtualp
  8292.       && (current_class_name == NULL_TREE || decl_context != FIELD))
  8293.     {
  8294.       error ("virtual outside class declaration");
  8295.       virtualp = 0;
  8296.     }
  8297.   if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
  8298.     {
  8299.       error ("only members can be declared mutable");
  8300.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8301.     }
  8302.  
  8303.   /* Static anonymous unions are dealt with here.  */
  8304.   if (staticp && decl_context == TYPENAME
  8305.       && TREE_CODE (declspecs) == TREE_LIST
  8306.       && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
  8307.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
  8308.     decl_context = FIELD;
  8309.  
  8310.   /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
  8311.      is used in a signature member function declaration.  */
  8312.  
  8313.   if (decl_context == FIELD 
  8314.       && current_class_type != NULL_TREE
  8315.       && IS_SIGNATURE (current_class_type)
  8316.       && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
  8317.       && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8318.     {
  8319.       if (constp)
  8320.     {
  8321.       error ("`const' specified for signature member function `%s'", name);
  8322.       constp = 0;
  8323.     }
  8324.       if (volatilep)
  8325.     {
  8326.       error ("`volatile' specified for signature member function `%s'",
  8327.          name);
  8328.       volatilep = 0;
  8329.     }
  8330.       if (inlinep)
  8331.     {
  8332.       error ("`inline' specified for signature member function `%s'", name);
  8333.       /* Later, we'll make signature member functions inline.  */
  8334.       inlinep = 0;
  8335.     }
  8336.       if (friendp)
  8337.     {
  8338.       error ("`friend' declaration in signature definition");
  8339.       friendp = 0;
  8340.     }
  8341.       if (virtualp)
  8342.     {
  8343.       error ("`virtual' specified for signature member function `%s'",
  8344.          name);
  8345.       /* Later, we'll make signature member functions virtual.  */
  8346.       virtualp = 0;
  8347.     }
  8348.     }
  8349.  
  8350.   /* Warn about storage classes that are invalid for certain
  8351.      kinds of declarations (parameters, typenames, etc.).  */
  8352.  
  8353.   if (nclasses > 1)
  8354.     error ("multiple storage classes in declaration of `%s'", name);
  8355.   else if (decl_context != NORMAL && nclasses > 0)
  8356.     {
  8357.       if ((decl_context == PARM || decl_context == CATCHPARM)
  8358.       && (RIDBIT_SETP (RID_REGISTER, specbits)
  8359.           || RIDBIT_SETP (RID_AUTO, specbits)))
  8360.     ;
  8361.       else if (decl_context == FIELD
  8362.            && RIDBIT_SETP (RID_TYPEDEF, specbits))
  8363.     {
  8364.       /* Processing a typedef declaration nested within a class type
  8365.          definition.  */
  8366.       register tree scanner;
  8367.       register tree previous_declspec;
  8368.         tree loc_typedecl;
  8369.   
  8370.       if (initialized)
  8371.         error ("typedef declaration includes an initializer");
  8372.   
  8373.       /* To process a class-local typedef declaration, we descend down
  8374.          the chain of declspecs looking for the `typedef' spec.  When
  8375.          we find it, we replace it with `static', and then recursively
  8376.          call `grokdeclarator' with the original declarator and with
  8377.          the newly adjusted declspecs.  This call should return a
  8378.          FIELD_DECL node with the TREE_TYPE (and other parts) set
  8379.          appropriately.  We can then just change the TREE_CODE on that
  8380.          from FIELD_DECL to TYPE_DECL and we're done.  */
  8381.  
  8382.       for (previous_declspec = NULL_TREE, scanner = declspecs;
  8383.            scanner;
  8384.            previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
  8385.           {
  8386.           if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
  8387.         break;
  8388.           }
  8389.  
  8390.       if (previous_declspec)
  8391.         TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
  8392.       else
  8393.         declspecs = TREE_CHAIN (scanner);
  8394.  
  8395.       declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
  8396.                  declspecs);
  8397.  
  8398.       /* In the recursive call to grokdeclarator we need to know
  8399.          whether we are working on a signature-local typedef.  */
  8400.       if (IS_SIGNATURE (current_class_type))
  8401.         SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
  8402.   
  8403.       loc_typedecl =
  8404.         grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
  8405.  
  8406.       if (previous_declspec)
  8407.         TREE_CHAIN (previous_declspec) = scanner;
  8408.   
  8409.       if (loc_typedecl != error_mark_node)
  8410.           {
  8411.           register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  8412.           register int *pi;
  8413.   
  8414.           TREE_SET_CODE (loc_typedecl, TYPE_DECL);
  8415.           /* This is the same field as DECL_ARGUMENTS, which is set for
  8416.          function typedefs by the above grokdeclarator.  */
  8417.           DECL_NESTED_TYPENAME (loc_typedecl) = 0;
  8418.   
  8419.           pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  8420.           while (i > 0)
  8421.             pi[--i] = 0;
  8422.           DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  8423.         }
  8424.   
  8425.       if (IS_SIGNATURE (current_class_type))
  8426.         {
  8427.           SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
  8428.           if (loc_typedecl != error_mark_node && opaque_typedef)
  8429.         SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
  8430.         }
  8431.  
  8432.         return loc_typedecl;
  8433.     }
  8434.       else if (decl_context == FIELD
  8435.            && (! IS_SIGNATURE (current_class_type)
  8436.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8437.             /* C++ allows static class elements  */
  8438.             && RIDBIT_SETP (RID_STATIC, specbits))
  8439.      /* C++ also allows inlines and signed and unsigned elements,
  8440.         but in those cases we don't come in here.  */
  8441.     ;
  8442.       else
  8443.     {
  8444.       if (decl_context == FIELD)
  8445.         {
  8446.           tree tmp = NULL_TREE;
  8447.           register int op = 0;
  8448.  
  8449.           if (declarator)
  8450.         {
  8451.           tmp = TREE_OPERAND (declarator, 0);
  8452.           op = IDENTIFIER_OPNAME_P (tmp);
  8453.         }
  8454.           error ("storage class specified for %s `%s'",
  8455.              IS_SIGNATURE (current_class_type)
  8456.              ? (op
  8457.             ? "signature member operator"
  8458.             : "signature member function")
  8459.              : (op ? "member operator" : "field"),
  8460.              op ? operator_name_string (tmp) : name);
  8461.         }
  8462.       else
  8463.         error (((decl_context == PARM || decl_context == CATCHPARM)
  8464.             ? "storage class specified for parameter `%s'"
  8465.             : "storage class specified for typename"), name);
  8466.       RIDBIT_RESET (RID_REGISTER, specbits);
  8467.       RIDBIT_RESET (RID_AUTO, specbits);
  8468.       RIDBIT_RESET (RID_EXTERN, specbits);
  8469.  
  8470.       if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
  8471.         {
  8472.           RIDBIT_RESET (RID_STATIC, specbits);
  8473.           staticp = 0;
  8474.         }
  8475.     }
  8476.     }
  8477.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
  8478.     {
  8479.       if (toplevel_bindings_p ())
  8480.     {
  8481.       /* It's common practice (and completely valid) to have a const
  8482.          be initialized and declared extern.  */
  8483.       if (! constp)
  8484.         warning ("`%s' initialized and declared `extern'", name);
  8485.     }
  8486.       else
  8487.     error ("`%s' has both `extern' and initializer", name);
  8488.     }
  8489.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
  8490.        && ! toplevel_bindings_p ())
  8491.     error ("nested function `%s' declared `extern'", name);
  8492.   else if (toplevel_bindings_p ())
  8493.     {
  8494.       if (RIDBIT_SETP (RID_AUTO, specbits))
  8495.     error ("top-level declaration of `%s' specifies `auto'", name);
  8496. #if 0
  8497.       if (RIDBIT_SETP (RID_REGISTER, specbits))
  8498.     error ("top-level declaration of `%s' specifies `register'", name);
  8499. #endif
  8500. #if 0
  8501.       /* I'm not sure under what circumstances we should turn
  8502.      on the extern bit, and under what circumstances we should
  8503.      warn if other bits are turned on.  */
  8504.       if (decl_context == NORMAL
  8505.       && RIDBIT_NOSETP (RID_EXTERN, specbits)
  8506.       && ! root_lang_context_p ())
  8507.     {
  8508.       RIDBIT_SET (RID_EXTERN, specbits);
  8509.     }
  8510. #endif
  8511.     }
  8512.  
  8513.   /* Now figure out the structure of the declarator proper.
  8514.      Descend through it, creating more complex types, until we reach
  8515.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  8516.  
  8517.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  8518.     {
  8519.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  8520.      an INDIRECT_REF (for *...),
  8521.      a CALL_EXPR (for ...(...)),
  8522.      an identifier (for the name being declared)
  8523.      or a null pointer (for the place in an absolute declarator
  8524.      where the name was omitted).
  8525.      For the last two cases, we have just exited the loop.
  8526.  
  8527.      For C++ it could also be
  8528.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  8529.      sensible names to types, and those are the values we use to
  8530.      qualify the member name.
  8531.      an ADDR_EXPR (for &...),
  8532.      a BIT_NOT_EXPR (for destructors)
  8533.  
  8534.      At this point, TYPE is the type of elements of an array,
  8535.      or for a function to return, or for a pointer to point to.
  8536.      After this sequence of ifs, TYPE is the type of the
  8537.      array or function or pointer, and DECLARATOR has had its
  8538.      outermost layer removed.  */
  8539.  
  8540.       if (TREE_CODE (type) == ERROR_MARK)
  8541.     {
  8542.       if (TREE_CODE (declarator) == SCOPE_REF)
  8543.         declarator = TREE_OPERAND (declarator, 1);
  8544.       else
  8545.         declarator = TREE_OPERAND (declarator, 0);
  8546.       continue;
  8547.     }
  8548.       if (quals != NULL_TREE
  8549.       && (declarator == NULL_TREE
  8550.           || TREE_CODE (declarator) != SCOPE_REF))
  8551.     {
  8552.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  8553.         ctype = TYPE_METHOD_BASETYPE (type);
  8554.       if (ctype != NULL_TREE)
  8555.         {
  8556. #if 0 /* not yet, should get fixed properly later */
  8557.           tree dummy = make_type_decl (NULL_TREE, type);
  8558. #else
  8559.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  8560. #endif
  8561.           ctype = grok_method_quals (ctype, dummy, quals);
  8562.           type = TREE_TYPE (dummy);
  8563.           quals = NULL_TREE;
  8564.         }
  8565.     }
  8566.       switch (TREE_CODE (declarator))
  8567.     {
  8568.     case ARRAY_REF:
  8569.       {
  8570.         register tree itype = NULL_TREE;
  8571.         register tree size = TREE_OPERAND (declarator, 1);
  8572.         /* The index is a signed object `sizetype' bits wide.  */
  8573.         tree index_type = signed_type (sizetype);
  8574.  
  8575.         declarator = TREE_OPERAND (declarator, 0);
  8576.  
  8577.         /* Check for some types that there cannot be arrays of.  */
  8578.  
  8579.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8580.           {
  8581.         cp_error ("declaration of `%D' as array of voids", dname);
  8582.         type = error_mark_node;
  8583.           }
  8584.  
  8585.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8586.           {
  8587.         cp_error ("declaration of `%D' as array of functions", dname);
  8588.         type = error_mark_node;
  8589.           }
  8590.  
  8591.         /* ARM $8.4.3: Since you can't have a pointer to a reference,
  8592.            you can't have arrays of references.  If we allowed them,
  8593.            then we'd be saying x[i] is valid for an array x, but
  8594.            then you'd have to ask: what does `*(x + i)' mean?  */
  8595.         if (TREE_CODE (type) == REFERENCE_TYPE)
  8596.           {
  8597.         if (decl_context == TYPENAME)
  8598.           cp_error ("cannot make arrays of references");
  8599.         else
  8600.           cp_error ("declaration of `%D' as array of references",
  8601.                 dname);
  8602.         type = error_mark_node;
  8603.           }
  8604.  
  8605.         if (TREE_CODE (type) == OFFSET_TYPE)
  8606.           {
  8607.           cp_error ("declaration of `%D' as array of data members",
  8608.                 dname);
  8609.         type = error_mark_node;
  8610.           }
  8611.  
  8612.         if (TREE_CODE (type) == METHOD_TYPE)
  8613.           {
  8614.         cp_error ("declaration of `%D' as array of function members",
  8615.               dname);
  8616.         type = error_mark_node;
  8617.           }
  8618.  
  8619.         if (size == error_mark_node)
  8620.           type = error_mark_node;
  8621.  
  8622.         if (type == error_mark_node)
  8623.           continue;
  8624.  
  8625.         if (size)
  8626.           {
  8627.         /* Must suspend_momentary here because the index
  8628.            type may need to live until the end of the function.
  8629.            For example, it is used in the declaration of a
  8630.            variable which requires destructing at the end of
  8631.            the function; then build_vec_delete will need this
  8632.            value.  */
  8633.         int yes = suspend_momentary ();
  8634.         /* might be a cast */
  8635.         if (TREE_CODE (size) == NOP_EXPR
  8636.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  8637.           size = TREE_OPERAND (size, 0);
  8638.  
  8639.         /* If this is a template parameter, it'll be constant, but
  8640.            we don't know what the value is yet.  */
  8641.         if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
  8642.           goto dont_grok_size;
  8643.  
  8644.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  8645.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  8646.           {
  8647.             cp_error ("size of array `%D' has non-integer type",
  8648.                   dname);
  8649.             size = integer_one_node;
  8650.           }
  8651.         if (TREE_READONLY_DECL_P (size))
  8652.           size = decl_constant_value (size);
  8653.         if (pedantic && integer_zerop (size))
  8654.           cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
  8655.         if (TREE_CONSTANT (size))
  8656.           {
  8657.             int old_flag_pedantic_errors = flag_pedantic_errors;
  8658.             int old_pedantic = pedantic;
  8659.             pedantic = flag_pedantic_errors = 1;
  8660.             /* Always give overflow errors on array subscripts.  */
  8661.             constant_expression_warning (size);
  8662.             pedantic = old_pedantic;
  8663.             flag_pedantic_errors = old_flag_pedantic_errors;
  8664.             if (INT_CST_LT (size, integer_zero_node))
  8665.               {
  8666.             cp_error ("size of array `%D' is negative", dname);
  8667.             size = integer_one_node;
  8668.               }
  8669.           }
  8670.         else
  8671.           {
  8672.             if (pedantic)
  8673.               {
  8674.             if (dname)
  8675.               cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
  8676.                       dname);
  8677.             else
  8678.               cp_pedwarn ("ANSI C++ forbids variable-size array");
  8679.               }
  8680.             /* Make sure the array size remains visibly nonconstant
  8681.                even if it is (eg) a const variable with known value. */
  8682.             size_varies = 1;
  8683.           }
  8684.  
  8685.           dont_grok_size:
  8686.         itype =
  8687.           fold (build_binary_op (MINUS_EXPR,
  8688.                      convert (index_type, size),
  8689.                      convert (index_type,
  8690.                           integer_one_node), 1));
  8691.         if (! TREE_CONSTANT (itype))
  8692.           itype = variable_size (itype);
  8693.         itype = build_index_type (itype);
  8694.         resume_momentary (yes);
  8695.           }
  8696.  
  8697.       /* Build the array type itself, then merge any constancy or
  8698.          volatility into the target type.  We must do it in this order
  8699.          to ensure that the TYPE_MAIN_VARIANT field of the array type
  8700.          is set correctly.  */
  8701.  
  8702.         type = build_cplus_array_type (type, itype);
  8703.         if (constp || volatilep)
  8704.           type = cp_build_type_variant (type, constp, volatilep);
  8705.  
  8706.         ctype = NULL_TREE;
  8707.       }
  8708.       break;
  8709.  
  8710.     case CALL_EXPR:
  8711.       {
  8712.         tree arg_types;
  8713.         int funcdecl_p;
  8714.         tree inner_parms = TREE_OPERAND (declarator, 1);
  8715.         tree inner_decl = TREE_OPERAND (declarator, 0);
  8716.  
  8717.         /* Declaring a function type.
  8718.            Make sure we have a valid type for the function to return.  */
  8719. #if 0
  8720.         /* Is this an error?  Should they be merged into TYPE here?  */
  8721.         if (pedantic && (constp || volatilep))
  8722.           pedwarn ("function declared to return const or volatile result");
  8723. #else
  8724.         /* Merge any constancy or volatility into the function return
  8725.                type.  */
  8726.  
  8727.         if (constp || volatilep)
  8728.           {
  8729.         type = cp_build_type_variant (type, constp, volatilep);
  8730.         if (IS_AGGR_TYPE (type))
  8731.           build_pointer_type (type);
  8732.         constp = 0;
  8733.         volatilep = 0;
  8734.           }
  8735. #endif
  8736.  
  8737.         /* Warn about some types functions can't return.  */
  8738.  
  8739.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8740.           {
  8741.         error ("`%s' declared as function returning a function", name);
  8742.         type = integer_type_node;
  8743.           }
  8744.         if (TREE_CODE (type) == ARRAY_TYPE)
  8745.           {
  8746.         error ("`%s' declared as function returning an array", name);
  8747.         type = integer_type_node;
  8748.           }
  8749.  
  8750.         if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  8751.           inner_decl = TREE_OPERAND (inner_decl, 1);
  8752.  
  8753.         /* Pick up type qualifiers which should be applied to `this'.  */
  8754.         quals = TREE_OPERAND (declarator, 2);
  8755.  
  8756.         /* Say it's a definition only for the CALL_EXPR
  8757.            closest to the identifier.  */
  8758.         funcdecl_p =
  8759.           inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
  8760.                  || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
  8761.  
  8762.         if (ctype == NULL_TREE
  8763.         && decl_context == FIELD
  8764.         && funcdecl_p
  8765.         && (friendp == 0 || dname == current_class_name))
  8766.           ctype = current_class_type;
  8767.  
  8768.         if (ctype && return_type == return_conversion)
  8769.           TYPE_HAS_CONVERSION (ctype) = 1;
  8770.         if (ctype && constructor_name (ctype) == dname)
  8771.           {
  8772.         /* We are within a class's scope. If our declarator name
  8773.            is the same as the class name, and we are defining
  8774.            a function, then it is a constructor/destructor, and
  8775.            therefore returns a void type.  */
  8776.  
  8777.         if (flags == DTOR_FLAG)
  8778.           {
  8779.             /* ANSI C++ June 5 1992 WP 12.4.1.  A destructor may
  8780.                not be declared const or volatile.  A destructor
  8781.                may not be static.  */
  8782.             if (staticp == 2)
  8783.               error ("destructor cannot be static member function");
  8784.             if (quals)
  8785.               {
  8786.             error ("destructors cannot be declared `const' or `volatile'");
  8787.             return void_type_node;
  8788.               }
  8789.             if (decl_context == FIELD)
  8790.               {
  8791.             if (! member_function_or_else (ctype, current_class_type,
  8792.                                "destructor for alien class `%s' cannot be a member"))
  8793.               return void_type_node;
  8794.               }
  8795.           }
  8796.         else            /* it's a constructor. */
  8797.           {
  8798.             if (explicitp == 1)
  8799.               explicitp = 2;
  8800.             /* ANSI C++ June 5 1992 WP 12.1.2.  A constructor may
  8801.                not be declared const or volatile.  A constructor may
  8802.                not be virtual.  A constructor may not be static.  */
  8803.             if (staticp == 2)
  8804.               error ("constructor cannot be static member function");
  8805.             if (virtualp)
  8806.               {
  8807.             pedwarn ("constructors cannot be declared virtual");
  8808.             virtualp = 0;
  8809.               }
  8810.             if (quals)
  8811.               {
  8812.             error ("constructors cannot be declared `const' or `volatile'");
  8813.             return void_type_node;
  8814.                }
  8815.             {
  8816.               RID_BIT_TYPE tmp_bits;
  8817.               bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
  8818.               RIDBIT_RESET (RID_INLINE, tmp_bits);
  8819.               RIDBIT_RESET (RID_STATIC, tmp_bits);
  8820.               if (RIDBIT_ANY_SET (tmp_bits))
  8821.             error ("return value type specifier for constructor ignored");
  8822.             }
  8823.             type = build_pointer_type (ctype);
  8824.             if (decl_context == FIELD &&
  8825.             IS_SIGNATURE (current_class_type))
  8826.               {
  8827.             error ("constructor not allowed in signature");
  8828.             return void_type_node;
  8829.               }              
  8830.             else if (decl_context == FIELD)
  8831.               {
  8832.             if (! member_function_or_else (ctype, current_class_type,
  8833.                                "constructor for alien class `%s' cannot be member"))
  8834.               return void_type_node;
  8835.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  8836.             if (return_type != return_ctor)
  8837.               return NULL_TREE;
  8838.               }
  8839.           }
  8840.         if (decl_context == FIELD)
  8841.           staticp = 0;
  8842.           }
  8843.         else if (friendp)
  8844.           {
  8845.         if (initialized)
  8846.           error ("can't initialize friend function `%s'", name);
  8847.         if (virtualp)
  8848.           {
  8849.             /* Cannot be both friend and virtual.  */
  8850.             error ("virtual functions cannot be friends");
  8851.             RIDBIT_RESET (RID_FRIEND, specbits);
  8852.             friendp = 0;
  8853.           }
  8854.         if (decl_context == NORMAL)
  8855.           error ("friend declaration not in class definition");
  8856.         if (current_function_decl && funcdef_flag)
  8857.           cp_error ("can't define friend function `%s' in a local class definition",
  8858.                 name);
  8859.           }
  8860.  
  8861.         /* Traditionally, declaring return type float means double.  */
  8862.  
  8863.         if (flag_traditional
  8864.         && TYPE_MAIN_VARIANT (type) == float_type_node)
  8865.           {
  8866.         type = build_type_variant (double_type_node,
  8867.                        TYPE_READONLY (type),
  8868.                        TYPE_VOLATILE (type));
  8869.           }
  8870.  
  8871.         /* Construct the function type and go to the next
  8872.            inner layer of declarator.  */
  8873.  
  8874.         declarator = TREE_OPERAND (declarator, 0);
  8875.  
  8876.         /* FIXME: This is where default args should be fully
  8877.            processed.  */
  8878.  
  8879.         arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
  8880.  
  8881.         if (declarator)
  8882.           {
  8883.         /* Get past destructors, etc.
  8884.            We know we have one because FLAGS will be non-zero.
  8885.  
  8886.            Complain about improper parameter lists here.  */
  8887.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  8888.           {
  8889.             declarator = TREE_OPERAND (declarator, 0);
  8890.  
  8891.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  8892.               arg_types = void_list_node;
  8893.             else if (arg_types == NULL_TREE
  8894.                  || arg_types != void_list_node)
  8895.               {
  8896.             error ("destructors cannot be specified with parameters");
  8897.             arg_types = void_list_node;
  8898.               }
  8899.           }
  8900.           }
  8901.  
  8902.         /* ANSI seems to say that `const int foo ();'
  8903.            does not make the function foo const.  */
  8904.         type = build_function_type (type,
  8905.                     flag_traditional ? 0 : arg_types);
  8906. #ifdef _WIN32
  8907.         /* If this function uses the stdcall calling conventions, mark the 
  8908.         tree as such by setting the stdcall_flag to 1. */
  8909.         if( stdcallp )
  8910.         {
  8911.         type = build_type_copy( type );
  8912.         TYPE_STDCALL( type ) = 1;
  8913.         }
  8914. #endif /* _WIN32 */
  8915.  
  8916.       }
  8917.       break;
  8918.  
  8919.     case ADDR_EXPR:
  8920.     case INDIRECT_REF:
  8921.       /* Filter out pointers-to-references and references-to-references.
  8922.          We can get these if a TYPE_DECL is used.  */
  8923.  
  8924.       if (TREE_CODE (type) == REFERENCE_TYPE)
  8925.         {
  8926.           error ("cannot declare %s to references",
  8927.              TREE_CODE (declarator) == ADDR_EXPR
  8928.              ? "references" : "pointers");
  8929.           declarator = TREE_OPERAND (declarator, 0);
  8930.           continue;
  8931.         }
  8932.  
  8933.       if (TREE_CODE (type) == OFFSET_TYPE
  8934.           && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE
  8935.           || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE))
  8936.         {
  8937.           cp_error ("cannot declare pointer to `%#T' member",
  8938.             TREE_TYPE (type));
  8939.           type = TREE_TYPE (type);
  8940.         }
  8941.  
  8942.       /* Merge any constancy or volatility into the target type
  8943.          for the pointer.  */
  8944.  
  8945.       if (constp || volatilep)
  8946.         {
  8947.           /* A const or volatile signature pointer/reference is
  8948.          pointing to a const or volatile object, i.e., the
  8949.          `optr' is const or volatile, respectively, not the
  8950.          signature pointer/reference itself.  */
  8951.           if (! IS_SIGNATURE (type))
  8952.         {
  8953.           type = cp_build_type_variant (type, constp, volatilep);
  8954.           if (IS_AGGR_TYPE (type))
  8955.             build_pointer_type (type);
  8956.           constp = 0;
  8957.           volatilep = 0;
  8958.         }
  8959.         }
  8960.  
  8961.       if (IS_SIGNATURE (type))
  8962.         {
  8963.           if (TREE_CODE (declarator) == ADDR_EXPR)
  8964.         {
  8965.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8966.               && TYPE_SIZE (type))
  8967.             cp_warning ("empty signature `%T' used in signature reference declaration",
  8968.                 type);
  8969. #if 0
  8970.           type = build_signature_reference_type (type,
  8971.                              constp, volatilep);
  8972. #else
  8973.           sorry ("signature reference");
  8974.           return NULL_TREE;
  8975. #endif
  8976.         }
  8977.           else
  8978.         {
  8979.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8980.               && TYPE_SIZE (type))
  8981.             cp_warning ("empty signature `%T' used in signature pointer declaration",
  8982.                 type);
  8983.           type = build_signature_pointer_type (type,
  8984.                                constp, volatilep);
  8985.         }
  8986.           constp = 0;
  8987.           volatilep = 0;
  8988.         }
  8989.       else if (TREE_CODE (declarator) == ADDR_EXPR)
  8990.         {
  8991.           if (TREE_CODE (type) == FUNCTION_TYPE)
  8992.         {
  8993.           error ("cannot declare references to functions; use pointer to function instead");
  8994.           type = build_pointer_type (type);
  8995.         }
  8996.           else
  8997.         {
  8998.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8999.             error ("invalid type: `void &'");
  9000.           else
  9001.             type = build_reference_type (type);
  9002.         }
  9003.         }
  9004.       else if (TREE_CODE (type) == METHOD_TYPE)
  9005.         {
  9006.           type = build_ptrmemfunc_type (build_pointer_type (type));
  9007.         }
  9008.       else
  9009.         type = build_pointer_type (type);
  9010.  
  9011.       /* Process a list of type modifier keywords (such as
  9012.          const or volatile) that were given inside the `*' or `&'.  */
  9013.  
  9014.       if (TREE_TYPE (declarator))
  9015.         {
  9016.           register tree typemodlist;
  9017.           int erred = 0;
  9018.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  9019.            typemodlist = TREE_CHAIN (typemodlist))
  9020.         {
  9021.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  9022.             constp++;
  9023.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  9024.             volatilep++;
  9025. #ifdef _WIN32
  9026.           /* We had a problem under NT with the __stdcall keyword where calling 
  9027.              a __stdcall function indirectly wouldn't use the correct calling 
  9028.              convention.  This was added so that when the pointer to the function
  9029.              is declared it is marked as using the stdcall conventions. */
  9030.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_STDCALL])
  9031.           {
  9032.               stdcallp++;
  9033.                 type = build_type_copy( TREE_TYPE( type ) );
  9034.                 type = build_pointer_type( type );
  9035.                 TYPE_STDCALL( TREE_TYPE( type ) ) = 1;
  9036.           }
  9037. #endif /* _WIN32 */
  9038.           else if (!erred)
  9039.             {
  9040.               erred = 1;
  9041.               error ("invalid type modifier within %s declarator",
  9042.                  TREE_CODE (declarator) == ADDR_EXPR
  9043.                  ? "reference" : "pointer");
  9044.             }
  9045.         }
  9046.           if (constp > 1)
  9047.         pedwarn ("duplicate `const'");
  9048.           if (volatilep > 1)
  9049.         pedwarn ("duplicate `volatile'");
  9050. #ifdef _WIN32
  9051.           if (stdcallp > 1)
  9052.         pedwarn ("duplicate `stdcall'");
  9053. #endif /* _WIN32 */
  9054.           if (TREE_CODE (declarator) == ADDR_EXPR
  9055.           && (constp || volatilep))
  9056.         {
  9057.           if (constp)
  9058.             pedwarn ("discarding `const' applied to a reference");
  9059.           if (volatilep)
  9060.             pedwarn ("discarding `volatile' applied to a reference");
  9061.           constp = volatilep = 0;
  9062.         }
  9063.         }
  9064.       declarator = TREE_OPERAND (declarator, 0);
  9065.       ctype = NULL_TREE;
  9066.       break;
  9067.  
  9068.     case SCOPE_REF:
  9069.       {
  9070.         /* We have converted type names to NULL_TREE if the
  9071.            name was bogus, or to a _TYPE node, if not.
  9072.  
  9073.            The variable CTYPE holds the type we will ultimately
  9074.            resolve to.  The code here just needs to build
  9075.            up appropriate member types.  */
  9076.         tree sname = TREE_OPERAND (declarator, 1);
  9077.         /* Destructors can have their visibilities changed as well.  */
  9078.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  9079.           sname = TREE_OPERAND (sname, 0);
  9080.  
  9081.         if (TREE_COMPLEXITY (declarator) == 0)
  9082.           /* This needs to be here, in case we are called
  9083.          multiple times.  */ ;
  9084.         else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
  9085.           /* don't fall out into global scope. Hides real bug? --eichin */ ;
  9086.         else if (TREE_COMPLEXITY (declarator) == current_class_depth)
  9087.           {
  9088.         /* This pop_nested_class corresponds to the
  9089.                    push_nested_class used to push into class scope for
  9090.                    parsing the argument list of a function decl, in
  9091.                    qualified_id.  */
  9092.         pop_nested_class (1);
  9093.         TREE_COMPLEXITY (declarator) = current_class_depth;
  9094.           }
  9095.         else
  9096.           my_friendly_abort (16);
  9097.  
  9098.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  9099.           {
  9100.         /* We had a reference to a global decl, or
  9101.            perhaps we were given a non-aggregate typedef,
  9102.            in which case we cleared this out, and should just
  9103.            keep going as though it wasn't there.  */
  9104.         declarator = sname;
  9105.         continue;
  9106.           }
  9107.         ctype = TREE_OPERAND (declarator, 0);
  9108.  
  9109.         if (sname == NULL_TREE)
  9110.           goto done_scoping;
  9111.  
  9112.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  9113.           {
  9114.         /* This is the `standard' use of the scoping operator:
  9115.            basetype :: member .  */
  9116.  
  9117.         if (ctype == current_class_type)
  9118.           {
  9119.             /* class A {
  9120.                  void A::f ();
  9121.                };
  9122.  
  9123.                Is this ill-formed?  */
  9124.  
  9125.             if (pedantic)
  9126.               cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
  9127.                   ctype, name);
  9128.           }
  9129.         else if (TREE_CODE (type) == FUNCTION_TYPE)
  9130.           {
  9131.             if (current_class_type == NULL_TREE
  9132.             || friendp)
  9133.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9134.                               TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9135.             else
  9136.               {
  9137.             cp_error ("cannot declare member function `%T::%s' within `%T'",
  9138.                   ctype, name, current_class_type);
  9139.             return void_type_node;
  9140.               }
  9141.           }
  9142.         else if (TYPE_SIZE (ctype) != NULL_TREE
  9143.              || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
  9144.           {
  9145.             tree t;
  9146.             /* have to move this code elsewhere in this function.
  9147.                this code is used for i.e., typedef int A::M; M *pm;
  9148.  
  9149.                It is?  How? jason 10/2/94 */
  9150.  
  9151.             if (explicit_int == -1 && decl_context == FIELD
  9152.             && funcdef_flag == 0)
  9153.               {
  9154.             /* The code in here should only be used to build
  9155.                stuff that will be grokked as access decls.  */
  9156.             t = lookup_field (ctype, sname, 0, 0);
  9157.             if (t)
  9158.               {
  9159.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  9160.                 DECL_INITIAL (t) = init;
  9161.                 return t;
  9162.               }
  9163.             /* No such field, try member functions.  */
  9164.             t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
  9165.             if (t)
  9166.               {
  9167.                 if (flags == DTOR_FLAG)
  9168.                   t = TREE_VALUE (t);
  9169.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  9170.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  9171.                   {
  9172.                 /* Don't include destructor with constructors.  */
  9173.                 t = DECL_CHAIN (TREE_VALUE (t));
  9174.                 if (t == NULL_TREE)
  9175.                   cp_error ("`%T' does not have any constructors",
  9176.                         ctype);
  9177.                 t = build_tree_list (NULL_TREE, t);
  9178.                   }
  9179.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  9180.                 DECL_INITIAL (t) = init;
  9181.                 return t;
  9182.               }
  9183.  
  9184.             cp_error
  9185.               ("field `%D' is not a member of structure `%T'",
  9186.                sname, ctype);
  9187.               }
  9188.  
  9189.             if (current_class_type)
  9190.               {
  9191.             cp_error ("cannot declare member `%T::%s' within `%T'",
  9192.                   ctype, name, current_class_type);
  9193.             return void_type_node;
  9194.               }
  9195.             type = build_offset_type (ctype, type);
  9196.           }
  9197.         else if (uses_template_parms (ctype))
  9198.           {
  9199.                     enum tree_code c;
  9200.                     if (TREE_CODE (type) == FUNCTION_TYPE)
  9201.               {
  9202.             type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9203.                             TREE_TYPE (type),
  9204.                             TYPE_ARG_TYPES (type));
  9205.             c = FUNCTION_DECL;
  9206.               }
  9207.             }
  9208.         else
  9209.           {
  9210.             cp_error ("structure `%T' not yet defined", ctype);
  9211.             return error_mark_node;
  9212.           }
  9213.  
  9214.         declarator = sname;
  9215.           }
  9216.         else if (TREE_CODE (sname) == SCOPE_REF)
  9217.           my_friendly_abort (17);
  9218.         else
  9219.           {
  9220.           done_scoping:
  9221.         declarator = TREE_OPERAND (declarator, 1);
  9222.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  9223.           /* In this case, we will deal with it later.  */
  9224.           ;
  9225.         else
  9226.           {
  9227.             if (TREE_CODE (type) == FUNCTION_TYPE)
  9228.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9229.             else
  9230.               type = build_offset_type (ctype, type);
  9231.           }
  9232.           }
  9233.       }
  9234.       break;
  9235.  
  9236.     case BIT_NOT_EXPR:
  9237.       declarator = TREE_OPERAND (declarator, 0);
  9238.       break;
  9239.  
  9240.     case RECORD_TYPE:
  9241.     case UNION_TYPE:
  9242.     case ENUMERAL_TYPE:
  9243.       declarator = NULL_TREE;
  9244.       break;
  9245.  
  9246.     case ERROR_MARK:
  9247.       declarator = NULL_TREE;
  9248.       break;
  9249.  
  9250.     default:
  9251.       my_friendly_abort (158);
  9252.     }
  9253.     }
  9254.  
  9255.   if (explicitp == 1)
  9256.     {
  9257.       error ("only constructors can be declared `explicit'");
  9258.       explicitp = 0;
  9259.     }
  9260.  
  9261.   /* Now TYPE has the actual type.  */
  9262.  
  9263.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  9264.  
  9265.   if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9266.     {
  9267.       if (constp)
  9268.     {
  9269.       error ("const `%s' cannot be declared `mutable'", name);
  9270.       RIDBIT_RESET (RID_MUTABLE, specbits);
  9271.     }
  9272.       else if (staticp)
  9273.     {
  9274.       error ("static `%s' cannot be declared `mutable'", name);
  9275.       RIDBIT_RESET (RID_MUTABLE, specbits);
  9276.     }
  9277.     }
  9278.  
  9279.   if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  9280.     {
  9281.       tree decl;
  9282.  
  9283.       /* Note that the grammar rejects storage classes
  9284.      in typenames, fields or parameters.  */
  9285.       if (constp || volatilep)
  9286.     type = cp_build_type_variant (type, constp, volatilep);
  9287.  
  9288.       /* If the user declares "struct {...} foo" then `foo' will have
  9289.      an anonymous name.  Fill that name in now.  Nothing can
  9290.      refer to it, so nothing needs know about the name change.
  9291.      The TYPE_NAME field was filled in by build_struct_xref.  */
  9292.       if (type != error_mark_node
  9293.       && TYPE_NAME (type)
  9294.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  9295.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
  9296.     {
  9297.       /* replace the anonymous name with the real name everywhere.  */
  9298.       lookup_tag_reverse (type, declarator);
  9299.       TYPE_IDENTIFIER (type) = declarator;
  9300.  
  9301.       if (TYPE_LANG_SPECIFIC (type))
  9302.         TYPE_WAS_ANONYMOUS (type) = 1;
  9303.  
  9304.       {
  9305.         tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
  9306.  
  9307.         if (!c)
  9308.           set_nested_typename (d, 0, declarator, type);
  9309.         else if (TREE_CODE (c) == FUNCTION_DECL)
  9310.           set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
  9311.                    declarator, type);
  9312.         else
  9313.           set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
  9314.  
  9315.         DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
  9316.         DECL_ASSEMBLER_NAME (d)
  9317.           = get_identifier (build_overload_name (type, 1, 1));
  9318.       }
  9319.     }
  9320.  
  9321. #if 0 /* not yet, should get fixed properly later */
  9322.       decl = make_type_decl (declarator, type);
  9323. #else
  9324.       decl = build_decl (TYPE_DECL, declarator, type);
  9325. #endif
  9326.       if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
  9327.     {
  9328.       cp_error_at ("typedef name may not be class-qualified", decl);
  9329.       return NULL_TREE;
  9330.     }
  9331.       else if (quals)
  9332.     {
  9333.       if (ctype == NULL_TREE)
  9334.         {
  9335.           if (TREE_CODE (type) != METHOD_TYPE)
  9336.         cp_error_at ("invalid type qualifier for non-method type", decl);
  9337.           else
  9338.         ctype = TYPE_METHOD_BASETYPE (type);
  9339.         }
  9340.       if (ctype != NULL_TREE)
  9341.         grok_method_quals (ctype, decl, quals);
  9342.     }
  9343.  
  9344.       if (RIDBIT_SETP (RID_SIGNED, specbits)
  9345.       || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  9346.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  9347.  
  9348.       if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9349.     {
  9350.       error ("non-object member `%s' cannot be declared mutable", name);
  9351.     }
  9352.  
  9353. #ifdef _WIN32
  9354.       /* If this function uses the stdcall calling conventions, mark the 
  9355.          tree as such by setting the stdcall_flag to 1. */
  9356.       if( stdcallp )
  9357.           TYPE_STDCALL( type ) = 1;
  9358. #endif /* _WIN32 */
  9359.  
  9360.       return decl;
  9361.     }
  9362.  
  9363.   /* Detect the case of an array type of unspecified size
  9364.      which came, as such, direct from a typedef name.
  9365.      We must copy the type, so that each identifier gets
  9366.      a distinct type, so that each identifier's size can be
  9367.      controlled separately by its own initializer.  */
  9368.  
  9369.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  9370.       && TYPE_DOMAIN (type) == NULL_TREE)
  9371.     {
  9372.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  9373.     }
  9374.  
  9375.   /* If this is a type name (such as, in a cast or sizeof),
  9376.      compute the type and return it now.  */
  9377.  
  9378.   if (decl_context == TYPENAME)
  9379.     {
  9380.       /* Note that the grammar rejects storage classes
  9381.      in typenames, fields or parameters.  */
  9382.       if (constp || volatilep)
  9383.     if (IS_SIGNATURE (type))
  9384.       error ("`const' or `volatile' specified with signature type");
  9385.     else  
  9386.       type = cp_build_type_variant (type, constp, volatilep);
  9387.  
  9388.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  9389.       if (friendp)
  9390.     {
  9391.       if (volatilep)
  9392.         {
  9393.           cp_error ("`volatile' specified for friend class declaration");
  9394.           volatilep = 0;
  9395.         }
  9396.       if (inlinep)
  9397.         {
  9398.           cp_error ("`inline' specified for friend class declaration");
  9399.           inlinep = 0;
  9400.         }
  9401.  
  9402.       /* Only try to do this stuff if we didn't already give up.  */
  9403.       if (type != integer_type_node)
  9404.         {
  9405.           /* A friendly class?  */
  9406.           if (current_class_type)
  9407.         make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  9408.           else
  9409.         error ("trying to make class `%s' a friend of global scope",
  9410.                TYPE_NAME_STRING (type));
  9411.           type = void_type_node;
  9412.         }
  9413.     }
  9414.       else if (quals)
  9415.     {
  9416. #if 0 /* not yet, should get fixed properly later */
  9417.       tree dummy = make_type_decl (declarator, type);
  9418. #else
  9419.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  9420. #endif
  9421.       if (ctype == NULL_TREE)
  9422.         {
  9423.           my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
  9424.           ctype = TYPE_METHOD_BASETYPE (type);
  9425.         }
  9426.       grok_method_quals (ctype, dummy, quals);
  9427.       type = TREE_TYPE (dummy);
  9428.     }
  9429.  
  9430.       return type;
  9431.     }
  9432.   else if (declarator == NULL_TREE && decl_context != PARM
  9433.        && decl_context != CATCHPARM
  9434.        && TREE_CODE (type) != UNION_TYPE
  9435.        && ! bitfield)
  9436.     {
  9437.       cp_error ("abstract declarator `%T' used as declaration", type);
  9438.       declarator = make_anon_name ();
  9439.     }
  9440.  
  9441.   /* `void' at top level (not within pointer)
  9442.      is allowed only in typedefs or type names.
  9443.      We don't complain about parms either, but that is because
  9444.      a better error message can be made later.  */
  9445.  
  9446.   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
  9447.     {
  9448.       if (! declarator)
  9449.     error ("unnamed variable or field declared void");
  9450.       else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
  9451.     {
  9452.       if (IDENTIFIER_OPNAME_P (declarator))
  9453. #if 0                /* How could this happen? */
  9454.         error ("operator `%s' declared void",
  9455.            operator_name_string (declarator));
  9456. #else
  9457.         my_friendly_abort (356);
  9458. #endif
  9459.       else
  9460.         error ("variable or field `%s' declared void", name);
  9461.     }
  9462.       else
  9463.     error ("variable or field declared void");
  9464.       type = integer_type_node;
  9465.     }
  9466.  
  9467.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  9468.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  9469.  
  9470.   {
  9471.     register tree decl;
  9472.  
  9473.     if (decl_context == PARM)
  9474.       {
  9475.     if (ctype)
  9476.       error ("cannot use `::' in parameter declaration");
  9477.  
  9478.     /* A parameter declared as an array of T is really a pointer to T.
  9479.        One declared as a function is really a pointer to a function.
  9480.        One declared as a member is really a pointer to member.  */
  9481.  
  9482.     if (TREE_CODE (type) == ARRAY_TYPE)
  9483.       {
  9484.         /* Transfer const-ness of array into that of type pointed to. */
  9485.         type = build_pointer_type
  9486.           (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
  9487.         volatilep = constp = 0;
  9488.       }
  9489.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  9490.       type = build_pointer_type (type);
  9491.     else if (TREE_CODE (type) == OFFSET_TYPE)
  9492.       type = build_pointer_type (type);
  9493.     else if (type == void_type_node && declarator)
  9494.       {
  9495.         error ("declaration of `%s' as void", name);
  9496.         return NULL_TREE;
  9497.       }
  9498.  
  9499.     decl = build_decl (PARM_DECL, declarator, type);
  9500.  
  9501.     bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
  9502.             inlinep, friendp, raises != NULL_TREE);
  9503.     if (current_class_type
  9504.         && IS_SIGNATURE (current_class_type))
  9505.       {
  9506.         if (inlinep)
  9507.           error ("parameter of signature member function declared `inline'");
  9508.         if (RIDBIT_SETP (RID_AUTO, specbits))
  9509.           error ("parameter of signature member function declared `auto'");
  9510.         if (RIDBIT_SETP (RID_REGISTER, specbits))
  9511.           error ("parameter of signature member function declared `register'");
  9512.       }
  9513.  
  9514.     /* Compute the type actually passed in the parmlist,
  9515.        for the case where there is no prototype.
  9516.        (For example, shorts and chars are passed as ints.)
  9517.        When there is a prototype, this is overridden later.  */
  9518.  
  9519.     DECL_ARG_TYPE (decl) = type_promotes_to (type);
  9520.       }
  9521.     else if (decl_context == FIELD)
  9522.       {
  9523.     if (type == error_mark_node)
  9524.       {
  9525.         /* Happens when declaring arrays of sizes which
  9526.            are error_mark_node, for example.  */
  9527.         decl = NULL_TREE;
  9528.       }
  9529.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  9530.       {
  9531.         int publicp = 0;
  9532.  
  9533.         if (friendp == 0)
  9534.           {
  9535.         if (ctype == NULL_TREE)
  9536.           ctype = current_class_type;
  9537.  
  9538.         if (ctype == NULL_TREE)
  9539.           {
  9540.             cp_error ("can't make `%D' into a method -- not in a class",
  9541.                   declarator);
  9542.             return void_type_node;
  9543.           }
  9544.  
  9545.         /* ``A union may [ ... ] not [ have ] virtual functions.''
  9546.            ARM 9.5 */
  9547.         if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
  9548.           {
  9549.             cp_error ("function `%D' declared virtual inside a union",
  9550.                   declarator);
  9551.             return void_type_node;
  9552.           }
  9553.  
  9554.         if (declarator == ansi_opname[(int) NEW_EXPR]
  9555.             || declarator == ansi_opname[(int) VEC_NEW_EXPR]
  9556.             || declarator == ansi_opname[(int) DELETE_EXPR]
  9557.             || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
  9558.           {
  9559.             if (virtualp)
  9560.               {
  9561.             cp_error ("`%D' cannot be declared virtual, since it is always static",
  9562.                   declarator);
  9563.             virtualp = 0;
  9564.               }
  9565.           }
  9566.         else if (staticp < 2)
  9567.           type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9568.                           TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9569.           }
  9570.  
  9571.         /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
  9572.         publicp = (! friendp
  9573.                || RIDBIT_SETP (RID_EXTERN, specbits)
  9574.                || ! (funcdef_flag < 0 || inlinep));
  9575.         decl = grokfndecl (ctype, type, declarator,
  9576.                    virtualp, flags, quals, raises, attrlist,
  9577.                    friendp ? -1 : 0, publicp, inlinep);
  9578.         if (decl == NULL_TREE)
  9579.           return NULL_TREE;
  9580.         decl = build_decl_attribute_variant (decl, decl_machine_attr);
  9581.  
  9582. #ifdef _WIN32 
  9583.     if( stdcallp )
  9584.         DECL_STDCALL( decl ) = stdcallp;
  9585. #endif /* _WIN32 */
  9586.  
  9587.         if (explicitp == 2)
  9588.           DECL_NONCONVERTING_P (decl) = 1;
  9589.       }
  9590.     else if (TREE_CODE (type) == METHOD_TYPE)
  9591.       {
  9592.         /* We only get here for friend declarations of
  9593.            members of other classes.  */
  9594.         /* All method decls are public, so tell grokfndecl to set
  9595.            TREE_PUBLIC, also.  */
  9596.         decl = grokfndecl (ctype, type, declarator,
  9597.                    virtualp, flags, quals, raises, attrlist,
  9598.                    friendp ? -1 : 0, 1, 0);
  9599.         if (decl == NULL_TREE)
  9600.           return NULL_TREE;
  9601.       }
  9602.     else if (TYPE_SIZE (type) == NULL_TREE && !staticp
  9603.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  9604.       {
  9605.         if (declarator)
  9606.           cp_error ("field `%D' has incomplete type", declarator);
  9607.         else
  9608.           cp_error ("name `%T' has incomplete type", type);
  9609.  
  9610.         /* If we're instantiating a template, tell them which
  9611.            instantiation made the field's type be incomplete.  */
  9612.         if (current_class_type
  9613.         && TYPE_NAME (current_class_type)
  9614.         && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
  9615.         && declspecs && TREE_VALUE (declspecs)
  9616.         && TREE_TYPE (TREE_VALUE (declspecs)) == type)
  9617.           cp_error ("  in instantiation of template `%T'",
  9618.             current_class_type);
  9619.  
  9620.         type = error_mark_node;
  9621.         decl = NULL_TREE;
  9622.       }
  9623.     else
  9624.       {
  9625.         if (friendp)
  9626.           {
  9627.         error ("`%s' is neither function nor method; cannot be declared friend",
  9628.                IDENTIFIER_POINTER (declarator));
  9629.         friendp = 0;
  9630.           }
  9631.         decl = NULL_TREE;
  9632.       }
  9633.  
  9634.     if (friendp)
  9635.       {
  9636.         /* Friends are treated specially.  */
  9637.         if (ctype == current_class_type)
  9638.           warning ("member functions are implicitly friends of their class");
  9639.         else
  9640.           {
  9641.         tree t = NULL_TREE;
  9642.         if (decl && DECL_NAME (decl))
  9643.           t = do_friend (ctype, declarator, decl,
  9644.                  last_function_parms, flags, quals);
  9645.         if (t && funcdef_flag)
  9646.           return t;
  9647.         
  9648.         return void_type_node;
  9649.           }
  9650.       }
  9651.  
  9652.     /* Structure field.  It may not be a function, except for C++ */
  9653.  
  9654.     if (decl == NULL_TREE)
  9655.       {
  9656.         if (initialized)
  9657.           {
  9658.         /* Motion 10 at San Diego: If a static const integral data
  9659.            member is initialized with an integral constant
  9660.            expression, the initializer may appear either in the
  9661.            declaration (within the class), or in the definition,
  9662.            but not both.  If it appears in the class, the member is
  9663.            a member constant.  The file-scope definition is always
  9664.            required.  */
  9665.         if (staticp)
  9666.           {
  9667.             if (pedantic)
  9668.               {
  9669.             if (! constp)
  9670.               cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  9671.                       declarator);
  9672.  
  9673.             else if (! INTEGRAL_TYPE_P (type))
  9674.               cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
  9675.               }
  9676.           }
  9677.  
  9678.         /* Note that initialization of const members is prohibited
  9679.            by the draft ANSI standard, though it appears to be in
  9680.            common practice.  12.6.2: The argument list is used to
  9681.            initialize the named nonstatic member....  This (or an
  9682.            initializer list) is the only way to initialize
  9683.            nonstatic const and reference members.  */
  9684.         else if (pedantic || ! constp)
  9685.           cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
  9686.                   constp ? "const member" : "member", declarator);
  9687.           }
  9688.  
  9689.         if (staticp || (constp && initialized))
  9690.           {
  9691.         /* ANSI C++ Apr '95 wp 9.2 */
  9692.         if (staticp && declarator == current_class_name)
  9693.           cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
  9694.                   declarator);
  9695.  
  9696.         /* C++ allows static class members.
  9697.            All other work for this is done by grokfield.
  9698.            This VAR_DECL is built by build_lang_field_decl.
  9699.            All other VAR_DECLs are built by build_decl.  */
  9700.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  9701.         TREE_STATIC (decl) = 1;
  9702.         /* In class context, 'static' means public access.  */
  9703.         TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
  9704.           }
  9705.         else
  9706.           {
  9707.         decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  9708.         if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9709.           {
  9710.             DECL_MUTABLE_P (decl) = 1;
  9711.             RIDBIT_RESET (RID_MUTABLE, specbits);
  9712.           }
  9713.           }
  9714.  
  9715.         bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
  9716.                 inlinep, friendp, raises != NULL_TREE);
  9717.       }
  9718.       }
  9719.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  9720.       {
  9721.     tree original_name = declarator;
  9722.     int publicp = 0;
  9723.  
  9724.     if (! declarator)
  9725.       return NULL_TREE;
  9726.  
  9727.     if (RIDBIT_SETP (RID_AUTO, specbits))
  9728.       error ("storage class `auto' invalid for function `%s'", name);
  9729.     else if (RIDBIT_SETP (RID_REGISTER, specbits))
  9730.       error ("storage class `register' invalid for function `%s'", name);
  9731.  
  9732.     /* Function declaration not at top level.
  9733.        Storage classes other than `extern' are not allowed
  9734.        and `extern' makes no difference.  */
  9735.     if (! toplevel_bindings_p ()
  9736.         && ! processing_template_decl
  9737.         && (RIDBIT_SETP (RID_STATIC, specbits)
  9738.         || RIDBIT_SETP (RID_INLINE, specbits))
  9739.         && pedantic)
  9740.       {
  9741.         if (RIDBIT_SETP (RID_STATIC, specbits))
  9742.           pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
  9743.         else
  9744.           pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
  9745.       }
  9746.     
  9747.     if (ctype == NULL_TREE)
  9748.       {
  9749.         if (virtualp)
  9750.           {
  9751.         error ("virtual non-class function `%s'", name);
  9752.         virtualp = 0;
  9753.           }
  9754.  
  9755.         if (current_lang_name == lang_name_cplusplus
  9756.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  9757.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  9758.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  9759.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  9760.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  9761.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  9762.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  9763.           /* Plain overloading: will not be grok'd by grokclassfn.  */
  9764.           declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
  9765.       }
  9766.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  9767.       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9768.                       TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9769.  
  9770.     /* Record presence of `static'.  In C++, `inline' implies `static'.  */
  9771.     publicp = (ctype != NULL_TREE
  9772.            || RIDBIT_SETP (RID_EXTERN, specbits)
  9773.            || (!RIDBIT_SETP (RID_STATIC, specbits)
  9774.                && !RIDBIT_SETP (RID_INLINE, specbits)));
  9775.  
  9776.     decl = grokfndecl (ctype, type, original_name,
  9777.                virtualp, flags, quals, raises, attrlist,
  9778.                processing_template_decl ? 0 : friendp ? 2 : 1,
  9779.                publicp, inlinep);
  9780.     if (decl == NULL_TREE)
  9781.       return NULL_TREE;
  9782.  
  9783.     if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
  9784.       DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
  9785.  
  9786.     if (staticp == 1)
  9787.       {
  9788.         int illegal_static = 0;
  9789.  
  9790.         /* Don't allow a static member function in a class, and forbid
  9791.            declaring main to be static.  */
  9792.         if (TREE_CODE (type) == METHOD_TYPE)
  9793.           {
  9794.         cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
  9795.         illegal_static = 1;
  9796.           }
  9797.         else if (current_function_decl)
  9798.           {
  9799.         /* FIXME need arm citation */
  9800.         error ("cannot declare static function inside another function");
  9801.         illegal_static = 1;
  9802.           }
  9803.  
  9804.         if (illegal_static)
  9805.           {
  9806.         staticp = 0;
  9807.         RIDBIT_RESET (RID_STATIC, specbits);
  9808.           }
  9809.       }
  9810.       }
  9811.     else
  9812.       {
  9813.     /* It's a variable.  */
  9814.  
  9815.     if (decl_context == CATCHPARM)
  9816.       {
  9817.         if (ctype)
  9818.           {
  9819.         ctype = NULL_TREE;
  9820.         error ("cannot use `::' in parameter declaration");
  9821.           }
  9822.  
  9823.         /* A parameter declared as an array of T is really a pointer to T.
  9824.            One declared as a function is really a pointer to a function.
  9825.            One declared as a member is really a pointer to member.  */
  9826.  
  9827.         if (TREE_CODE (type) == ARRAY_TYPE)
  9828.           {
  9829.         /* Transfer const-ness of array into that of type pointed to. */
  9830.         type = build_pointer_type
  9831.           (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
  9832.         volatilep = constp = 0;
  9833.           }
  9834.         else if (TREE_CODE (type) == FUNCTION_TYPE)
  9835.           type = build_pointer_type (type);
  9836.         else if (TREE_CODE (type) == OFFSET_TYPE)
  9837.           type = build_pointer_type (type);
  9838.       }
  9839.  
  9840.     /* An uninitialized decl with `extern' is a reference.  */
  9841.     decl = grokvardecl (type, declarator, specbits, initialized, constp);
  9842.     bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
  9843.             inlinep, friendp, raises != NULL_TREE);
  9844.  
  9845.     if (ctype)
  9846.       {
  9847.         DECL_CONTEXT (decl) = ctype;
  9848.         if (staticp == 1)
  9849.           {
  9850.             cp_pedwarn ("static member `%D' re-declared as static", decl);
  9851.             staticp = 0;
  9852.         RIDBIT_RESET (RID_STATIC, specbits);
  9853.           }
  9854.         if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
  9855.           {
  9856.         cp_error ("static member `%D' declared `register'", decl);
  9857.         RIDBIT_RESET (RID_REGISTER, specbits);
  9858.           }
  9859.         if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
  9860.           {
  9861.             cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
  9862.                 decl);
  9863.         RIDBIT_RESET (RID_EXTERN, specbits);
  9864.           }
  9865.       }
  9866.       }
  9867.  
  9868.     if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9869.       {
  9870.     error ("`%s' cannot be declared mutable", name);
  9871.       }
  9872.  
  9873.     /* Record `register' declaration for warnings on &
  9874.        and in case doing stupid register allocation.  */
  9875.  
  9876.     if (RIDBIT_SETP (RID_REGISTER, specbits))
  9877.       DECL_REGISTER (decl) = 1;
  9878.  
  9879.     if (RIDBIT_SETP (RID_EXTERN, specbits))
  9880.       DECL_THIS_EXTERN (decl) = 1;
  9881.  
  9882.     if (RIDBIT_SETP (RID_STATIC, specbits))
  9883.       DECL_THIS_STATIC (decl) = 1;
  9884.  
  9885.     /* Record constancy and volatility.  */
  9886.  
  9887.     if (constp)
  9888.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  9889.     if (volatilep)
  9890.       {
  9891.     TREE_SIDE_EFFECTS (decl) = 1;
  9892.     TREE_THIS_VOLATILE (decl) = 1;
  9893.       }
  9894.  
  9895. #if defined (_WIN32) && defined (NEXT_PDO)
  9896.     /* If this function is a stdcall function, set the stdcall_flag using the TYPE_STDCALL
  9897.        macro */
  9898.     if (stdcallp)
  9899.       TYPE_STDCALL (decl) = 1;
  9900.     if (RIDBIT_SETP(RID_DLLIMPORT, specbits))
  9901.     {
  9902.         DECL_EXTERNAL (decl) = 1;
  9903.  
  9904.         {
  9905.             char* newName = (char*)malloc( 
  9906.                 strlen( IDENTIFIER_POINTER(DECL_NAME(decl)) ) + 7 ); // to allow for '_imp__' and \0
  9907.  
  9908.             sprintf( newName, "_imp__%s", IDENTIFIER_POINTER(DECL_NAME(decl)) );
  9909.             DECL_ASSEMBLER_NAME(decl) = get_identifier( newName );
  9910.             DECL_DLLIMPORT(decl) = 1;
  9911.         }
  9912.     }
  9913.     else if (RIDBIT_SETP(RID_DLLEXPORT, specbits))
  9914.     {
  9915.         char prependCharacter = '_';
  9916.         char* tail = "";
  9917.         int length = 0;
  9918.  
  9919.         if( TREE_CODE (decl) != FUNCTION_DECL )
  9920.             tail = ",data";
  9921.         if( exportNamesForDLL )
  9922.             length = strlen( exportNamesForDLL );
  9923.         length += strlen( " -export:" );
  9924.         length += strlen (IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl))) + 1;            // Include the '_' here
  9925.         if( strncmp( IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl)), "objc_class_name", 15 ) == 0 )
  9926.         {
  9927.             prependCharacter = '.';
  9928.             tail = "";
  9929.         }
  9930.         length += strlen( tail );
  9931.         if( exportNamesForDLL )
  9932.             exportNamesForDLL = (char*)realloc( (void*)exportNamesForDLL, length + 1 );
  9933.         else
  9934.           {
  9935.             exportNamesForDLL = (char*)malloc( length + 1 );
  9936.             *exportNamesForDLL = '\0';
  9937.           }
  9938.         sprintf( exportNamesForDLL, "%s%s%c%s%s", exportNamesForDLL, 
  9939.             " -export:", prependCharacter, IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl)), tail );
  9940.     }
  9941. #endif /* _WIN32 */
  9942.  
  9943.     return decl;
  9944.   }
  9945. }
  9946.  
  9947. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  9948.    An empty exprlist is a parmlist.  An exprlist which
  9949.    contains only identifiers at the global level
  9950.    is a parmlist.  Otherwise, it is an exprlist.  */
  9951. int
  9952. parmlist_is_exprlist (exprs)
  9953.      tree exprs;
  9954. {
  9955.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  9956.     return 0;
  9957.  
  9958.   if (toplevel_bindings_p ())
  9959.     {
  9960.       /* At the global level, if these are all identifiers,
  9961.      then it is a parmlist.  */
  9962.       while (exprs)
  9963.     {
  9964.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  9965.         return 1;
  9966.       exprs = TREE_CHAIN (exprs);
  9967.     }
  9968.       return 0;
  9969.     }
  9970.   return 1;
  9971. }
  9972.  
  9973. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  9974.    be complete.
  9975.  
  9976.    C++: also subroutine of `start_function'.  */
  9977. static void
  9978. require_complete_types_for_parms (parms)
  9979.      tree parms;
  9980. {
  9981.   while (parms)
  9982.     {
  9983.       tree type = TREE_TYPE (parms);
  9984.       if (TYPE_SIZE (type) == NULL_TREE)
  9985.     {
  9986.       if (DECL_NAME (parms))
  9987.         error ("parameter `%s' has incomplete type",
  9988.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  9989.       else
  9990.         error ("parameter has incomplete type");
  9991.       TREE_TYPE (parms) = error_mark_node;
  9992.     }
  9993. #if 0
  9994.       /* If the arg types are incomplete in a declaration,
  9995.      they must include undefined tags.
  9996.      These tags can never be defined in the scope of the declaration,
  9997.      so the types can never be completed,
  9998.      and no call can be compiled successfully.  */
  9999.       /* This is not the right behavior for C++, but not having
  10000.      it is also probably wrong.  */
  10001.       else
  10002.     {
  10003.       /* Now warn if is a pointer to an incomplete type.  */
  10004.       while (TREE_CODE (type) == POINTER_TYPE
  10005.          || TREE_CODE (type) == REFERENCE_TYPE)
  10006.         type = TREE_TYPE (type);
  10007.       type = TYPE_MAIN_VARIANT (type);
  10008.       if (TYPE_SIZE (type) == NULL_TREE)
  10009.         {
  10010.           if (DECL_NAME (parm) != NULL_TREE)
  10011.         warning ("parameter `%s' points to incomplete type",
  10012.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  10013.           else
  10014.         warning ("parameter points to incomplete type");
  10015.         }
  10016.     }
  10017. #endif
  10018.       parms = TREE_CHAIN (parms);
  10019.     }
  10020. }
  10021.  
  10022. /* Decode the list of parameter types for a function type.
  10023.    Given the list of things declared inside the parens,
  10024.    return a list of types.
  10025.  
  10026.    The list we receive can have three kinds of elements:
  10027.    an IDENTIFIER_NODE for names given without types,
  10028.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  10029.    or void_type_node, to mark the end of an argument list
  10030.    when additional arguments are not permitted (... was not used).
  10031.  
  10032.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  10033.    a mere declaration.  A nonempty identifier-list gets an error message
  10034.    when FUNCDEF_FLAG is zero.
  10035.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  10036.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  10037.  
  10038.    If all elements of the input list contain types,
  10039.    we return a list of the types.
  10040.    If all elements contain no type (except perhaps a void_type_node
  10041.    at the end), we return a null list.
  10042.    If some have types and some do not, it is an error, and we
  10043.    return a null list.
  10044.  
  10045.    Also set last_function_parms to either
  10046.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  10047.    A list of names is converted to a chain of PARM_DECLs
  10048.    by store_parm_decls so that ultimately it is always a chain of decls.
  10049.  
  10050.    Note that in C++, parameters can take default values.  These default
  10051.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  10052.    an error to specify default values which are followed by parameters
  10053.    that have no default values, or an ELLIPSES.  For simplicities sake,
  10054.    only parameters which are specified with their types can take on
  10055.    default values.  */
  10056.  
  10057. #ifdef OBJCPLUS
  10058. tree
  10059. #else
  10060. static tree
  10061. #endif
  10062. grokparms (first_parm, funcdef_flag)
  10063.      tree first_parm;
  10064.      int funcdef_flag;
  10065. {
  10066.   tree result = NULL_TREE;
  10067.   tree decls = NULL_TREE;
  10068.  
  10069.   if (first_parm != NULL_TREE
  10070.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  10071.     {
  10072.       if (! funcdef_flag)
  10073.     pedwarn ("parameter names (without types) in function declaration");
  10074.       last_function_parms = first_parm;
  10075.       return NULL_TREE;
  10076.     }
  10077.   else if (first_parm != NULL_TREE
  10078.        && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
  10079.        && TREE_VALUE (first_parm) != void_type_node)
  10080. #ifdef OBJCPLUS
  10081. /* snaroff (3/30/96): this is a total "COPOUT" fix for a problem briefly
  10082.    described below. Nevertheless, it appears to work. Without it, we
  10083.    would die anyway. A more elegant fix would require sifting through
  10084.    subtle changes between grokparms for C++ and grokparms for ANSI-C.
  10085.    I don't have the time right now
  10086.  */
  10087.     return first_parm;
  10088. #else
  10089.     my_friendly_abort (145);
  10090. #endif
  10091.   else
  10092.     {
  10093.       /* Types were specified.  This is a list of declarators
  10094.      each represented as a TREE_LIST node.  */
  10095.       register tree parm, chain;
  10096.       int any_init = 0, any_error = 0, saw_void = 0;
  10097.  
  10098.       if (first_parm != NULL_TREE)
  10099.     {
  10100.       tree last_result = NULL_TREE;
  10101.       tree last_decl = NULL_TREE;
  10102.  
  10103.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  10104.         {
  10105.           tree type, list_node = parm;
  10106.           register tree decl = TREE_VALUE (parm);
  10107.           tree init = TREE_PURPOSE (parm);
  10108.  
  10109.           chain = TREE_CHAIN (parm);
  10110.           /* @@ weak defense against parse errors.  */
  10111.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  10112.         {
  10113.           /* Give various messages as the need arises.  */
  10114.           if (TREE_CODE (decl) == STRING_CST)
  10115.             error ("invalid string constant `%s'",
  10116.                TREE_STRING_POINTER (decl));
  10117.           else if (TREE_CODE (decl) == INTEGER_CST)
  10118.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  10119.           continue;
  10120.         }
  10121.  
  10122.           if (decl != void_type_node)
  10123.         {
  10124.           /* @@ May need to fetch out a `raises' here.  */
  10125.           decl = grokdeclarator (TREE_VALUE (decl),
  10126.                      TREE_PURPOSE (decl),
  10127.                      PARM, init != NULL_TREE,
  10128.                      NULL_TREE, NULL_TREE);
  10129.           if (! decl)
  10130.             continue;
  10131.           type = TREE_TYPE (decl);
  10132.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  10133.             decl = void_type_node;
  10134.           else if (TREE_CODE (type) == METHOD_TYPE)
  10135.             {
  10136.               if (DECL_NAME (decl))
  10137.             /* Cannot use `error_with_decl' here because
  10138.                we don't have DECL_CONTEXT set up yet.  */
  10139.             error ("parameter `%s' invalidly declared method type",
  10140.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  10141.               else
  10142.             error ("parameter invalidly declared method type");
  10143.               type = build_pointer_type (type);
  10144.               TREE_TYPE (decl) = type;
  10145.             }
  10146.           else if (TREE_CODE (type) == OFFSET_TYPE)
  10147.             {
  10148.               if (DECL_NAME (decl))
  10149.             error ("parameter `%s' invalidly declared offset type",
  10150.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  10151.               else
  10152.             error ("parameter invalidly declared offset type");
  10153.               type = build_pointer_type (type);
  10154.               TREE_TYPE (decl) = type;
  10155.             }
  10156.                   else if (TREE_CODE (type) == RECORD_TYPE
  10157.                            && TYPE_LANG_SPECIFIC (type)
  10158.                            && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  10159.                     {
  10160.                       abstract_virtuals_error (decl, type);
  10161.                       any_error = 1;  /* seems like a good idea */
  10162.                     }
  10163.                   else if (TREE_CODE (type) == RECORD_TYPE
  10164.                            && TYPE_LANG_SPECIFIC (type)
  10165.                            && IS_SIGNATURE (type))
  10166.                     {
  10167.                       signature_error (decl, type);
  10168.                       any_error = 1;  /* seems like a good idea */
  10169.                     }
  10170.         }
  10171.  
  10172.           if (decl == void_type_node)
  10173.         {
  10174.           if (result == NULL_TREE)
  10175.             {
  10176.               result = void_list_node;
  10177.               last_result = result;
  10178.             }
  10179.           else
  10180.             {
  10181.               TREE_CHAIN (last_result) = void_list_node;
  10182.               last_result = void_list_node;
  10183.             }
  10184.           saw_void = 1;
  10185.           if (chain
  10186.               && (chain != void_list_node || TREE_CHAIN (chain)))
  10187.             error ("`void' in parameter list must be entire list");
  10188.           break;
  10189.         }
  10190.  
  10191.           /* Since there is a prototype, args are passed in their own types.  */
  10192.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  10193. #ifdef PROMOTE_PROTOTYPES
  10194.           if ((TREE_CODE (type) == INTEGER_TYPE
  10195.            || TREE_CODE (type) == ENUMERAL_TYPE)
  10196.           && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  10197.         DECL_ARG_TYPE (decl) = integer_type_node;
  10198. #endif
  10199.           if (!any_error)
  10200.         {
  10201.           if (init)
  10202.             {
  10203.               any_init++;
  10204.               if (TREE_CODE (init) == SAVE_EXPR)
  10205.             PARM_DECL_EXPR (init) = 1;
  10206.               else if (TREE_CODE (init) == VAR_DECL
  10207.                    || TREE_CODE (init) == PARM_DECL)
  10208.             {
  10209.               if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
  10210.                 {
  10211.                   /* ``Local variables may not be used in default
  10212.                  argument expressions.'' dpANSI C++ 8.2.6 */
  10213.                   /* If extern int i; within a function is not
  10214.                  considered a local variable, then this code is
  10215.                  wrong. */
  10216.                   cp_error ("local variable `%D' may not be used as a default argument", init);
  10217.                   any_error = 1;
  10218.                 }
  10219.               else if (TREE_READONLY_DECL_P (init))
  10220.                 init = decl_constant_value (init);
  10221.             }
  10222.               else
  10223.             init = require_instantiated_type (type, init, integer_zero_node);
  10224.         }
  10225. #if 0 /* This is too early to check; trailing parms might be merged in by
  10226.      duplicate_decls.  */
  10227.           else if (any_init)
  10228.             {
  10229.               error ("all trailing parameters must have default arguments");
  10230.               any_error = 1;
  10231.             }
  10232. #endif
  10233.         }
  10234.           else
  10235.         init = NULL_TREE;
  10236.  
  10237.           if (decls == NULL_TREE)
  10238.         {
  10239.           decls = decl;
  10240.           last_decl = decls;
  10241.         }
  10242.           else
  10243.         {
  10244.           TREE_CHAIN (last_decl) = decl;
  10245.           last_decl = decl;
  10246.         }
  10247. /* snaroff (3/30/96): add_instance_method/comp_proto_with_proto and
  10248.    really_start_method assume the parm list is immutable. This enables
  10249.    obcp-act.c to call this routine multiple times. Without this,
  10250.    we crash with "error(145)"...see beginning of this method.
  10251.  */
  10252.           if (TREE_PERMANENT (list_node))
  10253.         {
  10254.           TREE_PURPOSE (list_node) = init;
  10255.           TREE_VALUE (list_node) = type;
  10256.           TREE_CHAIN (list_node) = NULL_TREE;
  10257.         }
  10258.           else
  10259.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  10260.           if (result == NULL_TREE)
  10261.         {
  10262.           result = list_node;
  10263.           last_result = result;
  10264.         }
  10265.           else
  10266.         {
  10267.           TREE_CHAIN (last_result) = list_node;
  10268.           last_result = list_node;
  10269.         }
  10270.         }
  10271.       if (last_result)
  10272.         TREE_CHAIN (last_result) = NULL_TREE;
  10273.       /* If there are no parameters, and the function does not end
  10274.          with `...', then last_decl will be NULL_TREE.  */
  10275.       if (last_decl != NULL_TREE)
  10276.         TREE_CHAIN (last_decl) = NULL_TREE;
  10277.     }
  10278.     }
  10279.  
  10280.   last_function_parms = decls;
  10281.  
  10282.   /* In a fcn definition, arg types must be complete.  */
  10283.   if (funcdef_flag > 0)
  10284.     require_complete_types_for_parms (last_function_parms);
  10285.  
  10286.   return result;
  10287. }
  10288.  
  10289. /* These memoizing functions keep track of special properties which
  10290.    a class may have.  `grok_ctor_properties' notices whether a class
  10291.    has a constructor of the form X(X&), and also complains
  10292.    if the class has a constructor of the form X(X).
  10293.    `grok_op_properties' takes notice of the various forms of
  10294.    operator= which are defined, as well as what sorts of type conversion
  10295.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  10296. int
  10297. grok_ctor_properties (ctype, decl)
  10298.      tree ctype, decl;
  10299. {
  10300.   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
  10301.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  10302.  
  10303.   /* When a type has virtual baseclasses, a magical first int argument is
  10304.      added to any ctor so we can tell if the class has been initialized
  10305.      yet.  This could screw things up in this function, so we deliberately
  10306.      ignore the leading int if we're in that situation.  */
  10307.   if (parmtypes
  10308.       && TREE_VALUE (parmtypes) == integer_type_node
  10309.       && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
  10310.     {
  10311.       parmtypes = TREE_CHAIN (parmtypes);
  10312.       parmtype = TREE_VALUE (parmtypes);
  10313.     }
  10314.  
  10315.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  10316.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  10317.     {
  10318.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  10319.       || TREE_CHAIN (parmtypes) == void_list_node
  10320.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  10321.     {
  10322.       TYPE_HAS_INIT_REF (ctype) = 1;
  10323.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  10324.         TYPE_HAS_CONST_INIT_REF (ctype) = 1;
  10325.     }
  10326.       else
  10327.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  10328.     }
  10329.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  10330.     {
  10331.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  10332.       && TREE_CHAIN (parmtypes) == void_list_node)
  10333.     {
  10334.       cp_error ("invalid constructor; you probably meant `%T (%T&)'",
  10335.             ctype, ctype);
  10336.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  10337.  
  10338.       return 0;
  10339.     }
  10340.       else
  10341.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  10342.     }
  10343.   else if (TREE_CODE (parmtype) == VOID_TYPE
  10344.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  10345.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  10346.  
  10347.   return 1;
  10348. }
  10349.  
  10350. /* An operator with this name can be either unary or binary.  */
  10351. static int
  10352. ambi_op_p (name)
  10353.      tree name;
  10354. {
  10355.   return (name == ansi_opname [(int) INDIRECT_REF]
  10356.       || name == ansi_opname [(int) ADDR_EXPR]
  10357.       || name == ansi_opname [(int) NEGATE_EXPR]
  10358.       || name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10359.       || name == ansi_opname[(int) POSTDECREMENT_EXPR]
  10360.       || name == ansi_opname [(int) CONVERT_EXPR]);
  10361. }
  10362.  
  10363. /* An operator with this name can only be unary.  */
  10364. static int
  10365. unary_op_p (name)
  10366.      tree name;
  10367. {
  10368.   return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
  10369.       || name == ansi_opname [(int) BIT_NOT_EXPR]
  10370.       || name == ansi_opname [(int) COMPONENT_REF]
  10371.       || OPERATOR_TYPENAME_P (name));
  10372. }
  10373.  
  10374. /* Do a little sanity-checking on how they declared their operator.  */
  10375. static void
  10376. grok_op_properties (decl, virtualp, friendp)
  10377.      tree decl;
  10378.      int virtualp, friendp;
  10379. {
  10380.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  10381.   int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
  10382.   tree name = DECL_NAME (decl);
  10383.  
  10384.   if (current_class_type == NULL_TREE)
  10385.     friendp = 1;
  10386.  
  10387.   if (! friendp)
  10388.     {
  10389.       if (name == ansi_opname[(int) MODIFY_EXPR])
  10390.     TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
  10391.       else if (name == ansi_opname[(int) CALL_EXPR])
  10392.     TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
  10393.       else if (name == ansi_opname[(int) ARRAY_REF])
  10394.     TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
  10395.       else if (name == ansi_opname[(int) COMPONENT_REF]
  10396.            || name == ansi_opname[(int) MEMBER_REF])
  10397.     TYPE_OVERLOADS_ARROW (current_class_type) = 1;
  10398.       else if (name == ansi_opname[(int) NEW_EXPR])
  10399.     TYPE_GETS_NEW (current_class_type) |= 1;
  10400.       else if (name == ansi_opname[(int) DELETE_EXPR])
  10401.     TYPE_GETS_DELETE (current_class_type) |= 1;
  10402.       else if (name == ansi_opname[(int) VEC_NEW_EXPR])
  10403.     TYPE_GETS_NEW (current_class_type) |= 2;
  10404.       else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
  10405.     TYPE_GETS_DELETE (current_class_type) |= 2;
  10406.     }
  10407.  
  10408.   if (name == ansi_opname[(int) NEW_EXPR]
  10409.       || name == ansi_opname[(int) VEC_NEW_EXPR])
  10410.     {
  10411.       /* When the compiler encounters the definition of A::operator new, it
  10412.      doesn't look at the class declaration to find out if it's static.  */
  10413.       if (methodp)
  10414.     revert_static_member_fn (&decl, NULL, NULL);
  10415.      
  10416.       /* Take care of function decl if we had syntax errors.  */
  10417.       if (argtypes == NULL_TREE)
  10418.     TREE_TYPE (decl) =
  10419.       build_function_type (ptr_type_node,
  10420.                    hash_tree_chain (integer_type_node,
  10421.                         void_list_node));
  10422.       else
  10423.     TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
  10424.     }
  10425.   else if (name == ansi_opname[(int) DELETE_EXPR]
  10426.        || name == ansi_opname[(int) VEC_DELETE_EXPR])
  10427.     {
  10428.       if (methodp)
  10429.     revert_static_member_fn (&decl, NULL, NULL);
  10430.      
  10431.       if (argtypes == NULL_TREE)
  10432.     TREE_TYPE (decl) =
  10433.       build_function_type (void_type_node,
  10434.                    hash_tree_chain (ptr_type_node,
  10435.                         void_list_node));
  10436.       else
  10437.     {
  10438.       TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
  10439.  
  10440.       if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
  10441.           && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
  10442.           != void_list_node))
  10443.         TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
  10444.     }
  10445.     }
  10446.   else
  10447.     {
  10448.       /* An operator function must either be a non-static member function
  10449.      or have at least one parameter of a class, a reference to a class,
  10450.      an enumeration, or a reference to an enumeration.  13.4.0.6 */
  10451.       if (! methodp || DECL_STATIC_FUNCTION_P (decl))
  10452.     {
  10453.       if (OPERATOR_TYPENAME_P (name)
  10454.           || name == ansi_opname[(int) CALL_EXPR]
  10455.           || name == ansi_opname[(int) MODIFY_EXPR]
  10456.           || name == ansi_opname[(int) COMPONENT_REF]
  10457.           || name == ansi_opname[(int) ARRAY_REF])
  10458.         cp_error ("`%D' must be a nonstatic member function", decl);
  10459.       else
  10460.         {
  10461.           tree p = argtypes;
  10462.  
  10463.           if (DECL_STATIC_FUNCTION_P (decl))
  10464.         cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
  10465.  
  10466.           if (p)
  10467.         for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
  10468.           {
  10469.             tree arg = TREE_VALUE (p);
  10470.             if (TREE_CODE (arg) == REFERENCE_TYPE)
  10471.               arg = TREE_TYPE (arg);
  10472.  
  10473.             /* This lets bad template code slip through.  */
  10474.             if (IS_AGGR_TYPE (arg)
  10475.             || TREE_CODE (arg) == ENUMERAL_TYPE
  10476.             || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
  10477.               goto foundaggr;
  10478.           }
  10479.           cp_error
  10480.         ("`%D' must have an argument of class or enumerated type",
  10481.          decl);
  10482.         foundaggr:
  10483.           ;
  10484.         }
  10485.     }
  10486.       
  10487.       if (name == ansi_opname[(int) CALL_EXPR]
  10488.       || name == ansi_opname[(int) METHOD_CALL_EXPR])
  10489.     return;            /* no restrictions on args */
  10490.  
  10491.       if (IDENTIFIER_TYPENAME_P (name))
  10492.     {
  10493.       tree t = TREE_TYPE (name);
  10494.       if (TREE_CODE (t) == VOID_TYPE)
  10495.         pedwarn ("void is not a valid type conversion operator");
  10496.       else if (! friendp)
  10497.         {
  10498.           int ref = (TREE_CODE (t) == REFERENCE_TYPE);
  10499.           char *what = 0;
  10500.           if (ref)
  10501.         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
  10502.  
  10503.           if (t == current_class_type)
  10504.         what = "the same type";
  10505.           else if (IS_AGGR_TYPE (t)
  10506.                && DERIVED_FROM_P (t, current_class_type))
  10507.         what = "a base class";
  10508.  
  10509.           if (what)
  10510.         warning ("conversion to %s%s will never use a type conversion operator",
  10511.              ref ? "a reference to " : "", what);
  10512.         }
  10513.     }
  10514.  
  10515.       if (name == ansi_opname[(int) MODIFY_EXPR])
  10516.     {
  10517.       tree parmtype;
  10518.  
  10519.       if (list_length (argtypes) != 3 && methodp)
  10520.         {
  10521.           cp_error ("`%D' must take exactly one argument", decl);
  10522.           return;
  10523.         }
  10524.       parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
  10525.  
  10526.       if (copy_assignment_arg_p (parmtype, virtualp)
  10527.           && ! friendp)
  10528.         {
  10529.           TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  10530.           if (TREE_CODE (parmtype) != REFERENCE_TYPE
  10531.           || TYPE_READONLY (TREE_TYPE (parmtype)))
  10532.         TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
  10533. #if 0 /* Too soon; done in grok_function_init */
  10534.           if (DECL_ABSTRACT_VIRTUAL_P (decl))
  10535.         TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
  10536. #endif
  10537.         }
  10538.     }
  10539.       else if (name == ansi_opname[(int) COND_EXPR])
  10540.     {
  10541.       /* 13.4.0.3 */
  10542.       pedwarn ("ANSI C++ prohibits overloading operator ?:");
  10543.       if (list_length (argtypes) != 4)
  10544.         cp_error ("`%D' must take exactly three arguments", decl);
  10545.     }      
  10546.       else if (ambi_op_p (name))
  10547.     {
  10548.       if (list_length (argtypes) == 2)
  10549.         /* prefix */;
  10550.       else if (list_length (argtypes) == 3)
  10551.         {
  10552.           if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10553.            || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  10554.           && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
  10555.         {
  10556.           if (methodp)
  10557.             cp_error ("postfix `%D' must take `int' as its argument",
  10558.                   decl);
  10559.           else
  10560.             cp_error
  10561.               ("postfix `%D' must take `int' as its second argument",
  10562.                decl);
  10563.         }
  10564.         }
  10565.       else
  10566.         {
  10567.           if (methodp)
  10568.         cp_error ("`%D' must take either zero or one argument", decl);
  10569.           else
  10570.         cp_error ("`%D' must take either one or two arguments", decl);
  10571.         }
  10572.     }
  10573.       else if (unary_op_p (name))
  10574.     {
  10575.       if (list_length (argtypes) != 2)
  10576.         {
  10577.           if (methodp)
  10578.         cp_error ("`%D' must take `void'", decl);
  10579.           else
  10580.         cp_error ("`%D' must take exactly one argument", decl);
  10581.         }
  10582.     }
  10583.       else /* if (binary_op_p (name)) */
  10584.     {
  10585.       if (list_length (argtypes) != 3)
  10586.         {
  10587.           if (methodp)
  10588.         cp_error ("`%D' must take exactly one argument", decl);
  10589.           else
  10590.         cp_error ("`%D' must take exactly two arguments", decl);
  10591.         }
  10592.     }
  10593.  
  10594.       /* 13.4.0.8 */
  10595.       if (argtypes)
  10596.     for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
  10597.       if (TREE_PURPOSE (argtypes))
  10598.         {
  10599.           TREE_PURPOSE (argtypes) = NULL_TREE;
  10600.           if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10601.           || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  10602.         {
  10603.           if (pedantic)
  10604.             cp_pedwarn ("`%D' cannot have default arguments", decl);
  10605.         }
  10606.           else
  10607.         cp_error ("`%D' cannot have default arguments", decl);
  10608.         }
  10609.     }
  10610. }
  10611.  
  10612. /* Get the struct, enum or union (CODE says which) with tag NAME.
  10613.    Define the tag as a forward-reference if it is not defined.
  10614.  
  10615.    C++: If a class derivation is given, process it here, and report
  10616.    an error if multiple derivation declarations are not identical.
  10617.  
  10618.    If this is a definition, come in through xref_tag and only look in
  10619.    the current frame for the name (since C++ allows new names in any
  10620.    scope.)  */
  10621.  
  10622. tree
  10623. xref_tag (code_type_node, name, binfo, globalize)
  10624.      tree code_type_node;
  10625.      tree name, binfo;
  10626.      int globalize;
  10627. {
  10628.   enum tag_types tag_code;
  10629.   enum tree_code code;
  10630.   int temp = 0;
  10631.   int i;
  10632.   register tree ref, t;
  10633.   struct binding_level *b = inner_binding_level;
  10634.  
  10635.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  10636.   switch (tag_code)
  10637.     {
  10638.     case record_type:
  10639.     case class_type:
  10640.     case signature_type:
  10641.       code = RECORD_TYPE;
  10642.       break;
  10643.     case union_type:
  10644.       code = UNION_TYPE;
  10645.       break;
  10646.     case enum_type:
  10647.       code = ENUMERAL_TYPE;
  10648.       break;
  10649.     default:
  10650.       my_friendly_abort (18);
  10651.     }
  10652.  
  10653.   /* If a cross reference is requested, look up the type
  10654.      already defined for this tag and return it.  */
  10655.   t = IDENTIFIER_TYPE_VALUE (name);
  10656.   if (t && TREE_CODE (t) != code)
  10657.     t = NULL_TREE;
  10658.  
  10659.   if (! globalize)
  10660.     {
  10661.       /* If we know we are defining this tag, only look it up in this scope
  10662.        * and don't try to find it as a type. */
  10663.       if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name))
  10664.     ref = t;
  10665.       else
  10666.           ref = lookup_tag (code, name, b, 1);
  10667.     }
  10668.   else
  10669.     {
  10670.       if (t)
  10671.     ref = t;
  10672.       else
  10673.         ref = lookup_tag (code, name, b, 0);
  10674.  
  10675.       if (! ref)
  10676.     {
  10677.       /* Try finding it as a type declaration.  If that wins, use it.  */
  10678.       ref = lookup_name (name, 1);
  10679.       if (ref && TREE_CODE (ref) == TYPE_DECL
  10680.           && TREE_CODE (TREE_TYPE (ref)) == code)
  10681.         ref = TREE_TYPE (ref);
  10682.       else
  10683.         ref = NULL_TREE;
  10684.     }
  10685.     }
  10686.  
  10687.   push_obstacks_nochange ();
  10688.  
  10689.   if (! ref)
  10690.     {
  10691.       /* If no such tag is yet defined, create a forward-reference node
  10692.      and record it as the "definition".
  10693.      When a real declaration of this type is found,
  10694.      the forward-reference will be altered into a real type.  */
  10695.  
  10696.       /* In C++, since these migrate into the global scope, we must
  10697.      build them on the permanent obstack.  */
  10698.  
  10699.       temp = allocation_temporary_p ();
  10700.       if (temp)
  10701.     end_temporary_allocation ();
  10702.  
  10703.       if (code == ENUMERAL_TYPE)
  10704.     {
  10705.       ref = make_node (ENUMERAL_TYPE);
  10706.  
  10707.       /* Give the type a default layout like unsigned int
  10708.          to avoid crashing if it does not get defined.  */
  10709.       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
  10710.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  10711.       TREE_UNSIGNED (ref) = 1;
  10712.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  10713.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  10714.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  10715.  
  10716.       /* Enable us to recognize when a type is created in class context.
  10717.          To do nested classes correctly, this should probably be cleared
  10718.          out when we leave this classes scope.  Currently this in only
  10719.          done in `start_enum'.  */
  10720.  
  10721.       pushtag (name, ref, globalize);
  10722.       if (flag_cadillac)
  10723.         cadillac_start_enum (ref);
  10724.     }
  10725.       else
  10726.     {
  10727.       struct binding_level *old_b = class_binding_level;
  10728.  
  10729.       ref = make_lang_type (code);
  10730.  
  10731.       if (tag_code == signature_type)
  10732.         {
  10733.           SET_SIGNATURE (ref);
  10734.           /* Since a signature type will be turned into the type
  10735.          of signature tables, it's not only an interface.  */
  10736.           CLASSTYPE_INTERFACE_ONLY (ref) = 0;
  10737.           SET_CLASSTYPE_INTERFACE_KNOWN (ref);
  10738.           /* A signature doesn't have a vtable.  */
  10739.           CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
  10740.         }
  10741.  
  10742. #ifdef NONNESTED_CLASSES
  10743.       /* Class types don't nest the way enums do.  */
  10744.       class_binding_level = (struct binding_level *)0;
  10745. #endif
  10746.       pushtag (name, ref, globalize);
  10747.       class_binding_level = old_b;
  10748.  
  10749.       if (flag_cadillac)
  10750.         cadillac_start_struct (ref);
  10751.     }
  10752.     }
  10753.   else
  10754.     {
  10755.       /* If it no longer looks like a nested type, make sure it's
  10756.      in global scope.  */
  10757.       if (b == global_binding_level && !class_binding_level
  10758.       && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
  10759.     IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
  10760.  
  10761. #if 0
  10762.       if (binfo)
  10763.     {
  10764.       tree tt1 = binfo;
  10765.       tree tt2 = TYPE_BINFO_BASETYPES (ref);
  10766.  
  10767.       if (TYPE_BINFO_BASETYPES (ref))
  10768.         for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
  10769.           if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
  10770.         {
  10771.           cp_error ("redeclaration of derivation chain of type `%#T'",
  10772.                 ref);
  10773.           break;
  10774.         }
  10775.  
  10776.       if (tt1 == NULL_TREE)
  10777.         /* The user told us something we already knew.  */
  10778.         goto just_return;
  10779.  
  10780.       /* In C++, since these migrate into the global scope, we must
  10781.          build them on the permanent obstack.  */
  10782.       end_temporary_allocation ();
  10783.     }
  10784. #endif
  10785.     }
  10786.  
  10787.   if (binfo)
  10788.     xref_basetypes (code_type_node, name, ref, binfo);
  10789.  
  10790.  just_return:
  10791.  
  10792.   /* Until the type is defined, tentatively accept whatever
  10793.      structure tag the user hands us.  */
  10794.   if (TYPE_SIZE (ref) == NULL_TREE
  10795.       && ref != current_class_type
  10796.       /* Have to check this, in case we have contradictory tag info.  */
  10797.       && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
  10798.     {
  10799.       if (tag_code == class_type)
  10800.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  10801.       else if (tag_code == record_type || tag_code == signature_type)
  10802.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  10803.     }
  10804.  
  10805.   pop_obstacks ();
  10806.  
  10807.   return ref;
  10808. }
  10809.  
  10810. void
  10811. xref_basetypes (code_type_node, name, ref, binfo)
  10812.      tree code_type_node;
  10813.      tree name, ref;
  10814.      tree binfo;
  10815. {
  10816.   /* In the declaration `A : X, Y, ... Z' we mark all the types
  10817.      (A, X, Y, ..., Z) so we can check for duplicates.  */
  10818.   tree binfos;
  10819.   int i, len;
  10820.   enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  10821.  
  10822.   if (tag_code == union_type)
  10823.     {
  10824.       cp_error ("derived union `%T' invalid", ref);
  10825.       return;
  10826.     }
  10827.  
  10828.   len = list_length (binfo);
  10829.   push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref));
  10830.  
  10831.   SET_CLASSTYPE_MARKED (ref);
  10832.   BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
  10833.  
  10834.   for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
  10835.     {
  10836.       /* The base of a derived struct is public by default.  */
  10837.       int via_public
  10838.     = (TREE_PURPOSE (binfo) == (tree)access_public
  10839.        || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10840.        || (tag_code != class_type
  10841.            && (TREE_PURPOSE (binfo) == (tree)access_default
  10842.            || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
  10843.       int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
  10844.       int via_virtual
  10845.     = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
  10846.        || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10847.        || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
  10848.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  10849.       tree base_binfo;
  10850.  
  10851.       GNU_xref_hier (IDENTIFIER_POINTER (name),
  10852.              IDENTIFIER_POINTER (TREE_VALUE (binfo)),
  10853.              via_public, via_virtual, 0);
  10854.  
  10855.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  10856.     basetype = TREE_TYPE (basetype);
  10857.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  10858.     {
  10859.       cp_error ("base type `%T' fails to be a struct or class type",
  10860.             TREE_VALUE (binfo));
  10861.       continue;
  10862.     }
  10863. #if 1
  10864.       /* This code replaces similar code in layout_basetypes.  */
  10865.       else if (TYPE_INCOMPLETE (basetype))
  10866.     {
  10867.       cp_error ("base class `%T' has incomplete type", basetype);
  10868.       continue;
  10869.     }
  10870. #endif
  10871.       else
  10872.     {
  10873.       if (CLASSTYPE_MARKED (basetype))
  10874.         {
  10875.           if (basetype == ref)
  10876.         cp_error ("recursive type `%T' undefined", basetype);
  10877.           else
  10878.         cp_error ("duplicate base type `%T' invalid", basetype);
  10879.           continue;
  10880.         }
  10881.  
  10882.       /* Note that the BINFO records which describe individual
  10883.          inheritances are *not* shared in the lattice!  They
  10884.          cannot be shared because a given baseclass may be
  10885.          inherited with different `accessibility' by different
  10886.          derived classes.  (Each BINFO record describing an
  10887.          individual inheritance contains flags which say what
  10888.          the `accessibility' of that particular inheritance is.)  */
  10889.   
  10890.       base_binfo = make_binfo (integer_zero_node, basetype,
  10891.                    TYPE_BINFO_VTABLE (basetype),
  10892.                    TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
  10893.  
  10894.       TREE_VEC_ELT (binfos, i) = base_binfo;
  10895.       TREE_VIA_PUBLIC (base_binfo) = via_public;
  10896.       TREE_VIA_PROTECTED (base_binfo) = via_protected;
  10897.       TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
  10898.       BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
  10899.  
  10900.       SET_CLASSTYPE_MARKED (basetype);
  10901. #if 0
  10902.       /* XYZZY TEST VIRTUAL BASECLASSES */
  10903.       if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
  10904.           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  10905.           && via_virtual == 0)
  10906.         {
  10907.           warning ("making type `%s' a virtual baseclass",
  10908.                TYPE_NAME_STRING (basetype));
  10909.           via_virtual = 1;
  10910.         }
  10911. #endif
  10912.       /* We are free to modify these bits because they are meaningless
  10913.          at top level, and BASETYPE is a top-level type.  */
  10914.       if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  10915.         {
  10916.           TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  10917.           TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10918.         }
  10919.  
  10920.       TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  10921.       TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
  10922.       TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
  10923.       CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  10924.       i += 1;
  10925.     }
  10926.     }
  10927.   if (i)
  10928.     TREE_VEC_LENGTH (binfos) = i;
  10929.   else
  10930.     BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
  10931.  
  10932.   if (i > 1)
  10933.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  10934.   else if (i == 1)
  10935.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  10936.       = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
  10937.   if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
  10938.     TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10939.  
  10940.   /* Unmark all the types.  */
  10941.   while (--i >= 0)
  10942.     CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
  10943.   CLEAR_CLASSTYPE_MARKED (ref);
  10944.  
  10945.   pop_obstacks ();
  10946. }
  10947.   
  10948.  
  10949. static tree current_local_enum = NULL_TREE;
  10950.  
  10951. /* Begin compiling the definition of an enumeration type.
  10952.    NAME is its name (or null if anonymous).
  10953.    Returns the type object, as yet incomplete.
  10954.    Also records info about it so that build_enumerator
  10955.    may be used to declare the individual values as they are read.  */
  10956.  
  10957. tree
  10958. start_enum (name)
  10959.      tree name;
  10960. {
  10961.   register tree enumtype = NULL_TREE;
  10962.   struct binding_level *b = inner_binding_level;
  10963.  
  10964.   /* If this is the real definition for a previous forward reference,
  10965.      fill in the contents in the same object that used to be the
  10966.      forward reference.  */
  10967.  
  10968.   if (name != NULL_TREE)
  10969.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  10970.  
  10971.   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
  10972.     cp_error ("multiple definition of enum `%T'", enumtype);
  10973.   else
  10974.     {
  10975.       enumtype = make_node (ENUMERAL_TYPE);
  10976.       pushtag (name, enumtype, 0);
  10977.     }
  10978.  
  10979.   if (current_class_type)
  10980.     TREE_ADDRESSABLE (b->tags) = 1;
  10981.   current_local_enum = NULL_TREE;
  10982.  
  10983. #if 0 /* This stuff gets cleared in finish_enum anyway.  */
  10984.   if (TYPE_VALUES (enumtype) != NULL_TREE)
  10985.     /* Completely replace its old definition.
  10986.        The old enumerators remain defined, however.  */
  10987.     TYPE_VALUES (enumtype) = NULL_TREE;
  10988.  
  10989.   /* Initially, set up this enum as like `int'
  10990.      so that we can create the enumerators' declarations and values.
  10991.      Later on, the precision of the type may be changed and
  10992.      it may be laid out again.  */
  10993.  
  10994.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  10995.   TYPE_SIZE (enumtype) = NULL_TREE;
  10996.   fixup_signed_type (enumtype);
  10997. #endif
  10998.  
  10999.   /* We copy this value because enumerated type constants
  11000.      are really of the type of the enumerator, not integer_type_node.  */
  11001.   enum_next_value = copy_node (integer_zero_node);
  11002.   enum_overflow = 0;
  11003.  
  11004.   GNU_xref_decl (current_function_decl, enumtype);
  11005.   return enumtype;
  11006. }
  11007.  
  11008. /* After processing and defining all the values of an enumeration type,
  11009.    install their decls in the enumeration type and finish it off.
  11010.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  11011.    Returns ENUMTYPE.  */
  11012.  
  11013. tree
  11014. finish_enum (enumtype, values)
  11015.      register tree enumtype, values;
  11016. {
  11017.   register tree minnode, maxnode;
  11018.   /* Calculate the maximum value of any enumerator in this type.  */
  11019.  
  11020.   if (values)
  11021.     {
  11022.       register tree pair;
  11023.       register tree value = DECL_INITIAL (TREE_VALUE (values));
  11024.       
  11025.       /* Speed up the main loop by performing some precalculations */
  11026.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  11027.       TREE_TYPE (value) = enumtype;
  11028.       TREE_VALUE (values) = value;
  11029.       minnode = maxnode = value;
  11030.       
  11031.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  11032.     {
  11033.       value = DECL_INITIAL (TREE_VALUE (pair));
  11034.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  11035.       TREE_TYPE (value) = enumtype;
  11036.       TREE_VALUE (pair) = value;
  11037.       if (tree_int_cst_lt (maxnode, value))
  11038.         maxnode = value;
  11039.       else if (tree_int_cst_lt (value, minnode))
  11040.         minnode = value;
  11041.     }
  11042.     }
  11043.   else
  11044.     maxnode = minnode = integer_zero_node;
  11045.  
  11046.   TYPE_VALUES (enumtype) = values;
  11047.  
  11048.   {
  11049.     int unsignedp = tree_int_cst_sgn (minnode) >= 0;
  11050.     int lowprec = min_precision (minnode, unsignedp);
  11051.     int highprec = min_precision (maxnode, unsignedp);
  11052.     int precision = MAX (lowprec, highprec);
  11053.  
  11054.     TYPE_SIZE (enumtype) = NULL_TREE;
  11055.  
  11056.     /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'.  */
  11057.  
  11058.     TYPE_PRECISION (enumtype) = precision;
  11059.     if (unsignedp)
  11060.       fixup_unsigned_type (enumtype);
  11061.     else
  11062.       fixup_signed_type (enumtype);
  11063.  
  11064.     if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node))
  11065.       /* Use the width of the narrowest normal C type which is wide enough.  */
  11066.       TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size
  11067.                           (precision, 1));
  11068.     else
  11069.       TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  11070.  
  11071.     TYPE_SIZE (enumtype) = 0;
  11072.     layout_type (enumtype);
  11073.   }
  11074.  
  11075.   if (flag_cadillac)
  11076.     cadillac_finish_enum (enumtype);
  11077.  
  11078.   {
  11079.     register tree tem;
  11080.     
  11081.     /* Fix up all variant types of this enum type.  */
  11082.     for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
  11083.      tem = TYPE_NEXT_VARIANT (tem))
  11084.       {
  11085.     TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
  11086.     TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
  11087.     TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
  11088.     TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
  11089.     TYPE_MODE (tem) = TYPE_MODE (enumtype);
  11090.     TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
  11091.     TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
  11092.     TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
  11093.       }
  11094.   }
  11095.  
  11096.   /* Finish debugging output for this type.  */
  11097. #if 0
  11098.   /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
  11099.      information should *not* be generated?  I think not.  */
  11100.   if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
  11101. #endif
  11102.     rest_of_type_compilation (enumtype, global_bindings_p ());
  11103.  
  11104.   return enumtype;
  11105. }
  11106.  
  11107. /* Build and install a CONST_DECL for one value of the
  11108.    current enumeration type (one that was begun with start_enum).
  11109.    Return a tree-list containing the name and its value.
  11110.    Assignment of sequential values by default is handled here.  */
  11111.  
  11112. tree
  11113. build_enumerator (name, value)
  11114.      tree name, value;
  11115. {
  11116.   tree decl, result;
  11117.   /* Change this to zero if we find VALUE is not shareable.  */
  11118.   int shareable = 1;
  11119.  
  11120.   /* Remove no-op casts from the value.  */
  11121.   if (value)
  11122.     STRIP_TYPE_NOPS (value);
  11123.  
  11124.   /* Validate and default VALUE.  */
  11125.   if (value != NULL_TREE)
  11126.     {
  11127.       if (TREE_READONLY_DECL_P (value))
  11128.     {
  11129.       value = decl_constant_value (value);
  11130.       shareable = 0;
  11131.     }
  11132.  
  11133.       if (TREE_CODE (value) == INTEGER_CST)
  11134.     {
  11135.       value = default_conversion (value);
  11136.       constant_expression_warning (value);
  11137.     }
  11138.       else
  11139.     {
  11140.       cp_error ("enumerator value for `%D' not integer constant", name);
  11141.       value = NULL_TREE;
  11142.     }
  11143.     }
  11144.  
  11145.   /* The order of things is reversed here so that we
  11146.      can check for possible sharing of enum values,
  11147.      to keep that from happening.  */
  11148.   /* Default based on previous value.  */
  11149.   if (value == NULL_TREE)
  11150.     {
  11151.       value = enum_next_value;
  11152.       if (enum_overflow)
  11153.     cp_error ("overflow in enumeration values at `%D'", name);
  11154.     }
  11155.  
  11156.   /* Remove no-op casts from the value.  */
  11157.   if (value)
  11158.     STRIP_TYPE_NOPS (value);
  11159.  
  11160.   /* Make up for hacks in lex.c.  */
  11161.   if (value == integer_zero_node)
  11162.     value = build_int_2 (0, 0);
  11163.   else if (value == integer_one_node)
  11164.     value = build_int_2 (1, 0);
  11165.   else if (TREE_CODE (value) == INTEGER_CST
  11166.        && (shareable == 0
  11167.            || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
  11168.     {
  11169.       value = copy_node (value);
  11170.       TREE_TYPE (value) = integer_type_node;
  11171.     }
  11172.  
  11173.   /* C++ associates enums with global, function, or class declarations.  */
  11174.  
  11175.   decl = current_scope ();
  11176.   if (decl && decl == current_class_type)
  11177.     {
  11178.       /* This enum declaration is local to the class, so we must put
  11179.      it in that class's list of decls.  */
  11180.       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
  11181.       DECL_INITIAL (decl) = value;
  11182.       TREE_READONLY (decl) = 1;
  11183.       pushdecl_class_level (decl);
  11184.       TREE_CHAIN (decl) = current_local_enum;
  11185.       current_local_enum = decl;
  11186.     }
  11187.   else
  11188.     {
  11189.       /* It's a global enum, or it's local to a function.  (Note local to
  11190.      a function could mean local to a class method.  */
  11191.       decl = build_decl (CONST_DECL, name, integer_type_node);
  11192.       DECL_INITIAL (decl) = value;
  11193.  
  11194.       pushdecl (decl);
  11195.       GNU_xref_decl (current_function_decl, decl);
  11196.     }
  11197.  
  11198.   /* Set basis for default for next value.  */
  11199.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  11200.                            integer_one_node, PLUS_EXPR);
  11201.   enum_overflow = tree_int_cst_lt (enum_next_value, value);
  11202.   
  11203.   if (enum_next_value == integer_one_node)
  11204.     enum_next_value = copy_node (enum_next_value);
  11205.  
  11206.   result = saveable_tree_cons (name, decl, NULL_TREE);
  11207.   return result;
  11208. }
  11209.  
  11210. tree
  11211. grok_enum_decls (type, decl)
  11212.      tree type, decl;
  11213. {
  11214.   tree d = current_local_enum;
  11215.   
  11216.   if (d == NULL_TREE)
  11217.     return decl;
  11218.   
  11219.   while (1)
  11220.     {
  11221.       TREE_TYPE (d) = type;
  11222.       if (TREE_CHAIN (d) == NULL_TREE)
  11223.     {
  11224.       TREE_CHAIN (d) = decl;
  11225.       break;
  11226.     }
  11227.       d = TREE_CHAIN (d);
  11228.     }
  11229.  
  11230.   decl = current_local_enum;
  11231.   current_local_enum = NULL_TREE;
  11232.   
  11233.   return decl;
  11234. }
  11235.  
  11236. /* Create the FUNCTION_DECL for a function definition.
  11237.    DECLSPECS and DECLARATOR are the parts of the declaration;
  11238.    they describe the function's name and the type it returns,
  11239.    but twisted together in a fashion that parallels the syntax of C.
  11240.  
  11241.    This function creates a binding context for the function body
  11242.    as well as setting up the FUNCTION_DECL in current_function_decl.
  11243.  
  11244.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  11245.    (it defines a datum instead), we return 0, which tells
  11246.    yyparse to report a parse error.
  11247.  
  11248.    For C++, we must first check whether that datum makes any sense.
  11249.    For example, "class A local_a(1,2);" means that variable local_a
  11250.    is an aggregate of type A, which should have a constructor
  11251.    applied to it with the argument list [1, 2].
  11252.  
  11253.    @@ There is currently no way to retrieve the storage
  11254.    @@ allocated to FUNCTION (or all of its parms) if we return
  11255.    @@ something we had previously.  */
  11256.  
  11257. int
  11258. start_function (declspecs, declarator, raises, attrs, pre_parsed_p)
  11259.      tree declspecs, declarator, raises, attrs;
  11260.      int pre_parsed_p;
  11261. {
  11262.   tree decl1, olddecl;
  11263.   tree ctype = NULL_TREE;
  11264.   tree fntype;
  11265.   tree restype;
  11266.   extern int have_extern_spec;
  11267.   extern int used_extern_spec;
  11268.   int doing_friend = 0;
  11269.  
  11270.   /* Sanity check.  */
  11271.   my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
  11272.   my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
  11273.  
  11274.   /* Assume, until we see it does. */
  11275.   current_function_returns_value = 0;
  11276.   current_function_returns_null = 0;
  11277.   warn_about_return_type = 0;
  11278.   named_labels = 0;
  11279.   shadowed_labels = 0;
  11280.   current_function_assigns_this = 0;
  11281.   current_function_just_assigned_this = 0;
  11282.   current_function_parms_stored = 0;
  11283.   original_result_rtx = NULL_RTX;
  11284.   current_function_obstack_index = 0;
  11285.   current_function_obstack_usage = 0;
  11286.   base_init_expr = NULL_TREE;
  11287.   protect_list = NULL_TREE;
  11288.   current_base_init_list = NULL_TREE;
  11289.   current_member_init_list = NULL_TREE;
  11290.   ctor_label = dtor_label = NULL_TREE;
  11291.  
  11292.   clear_temp_name ();
  11293.  
  11294.   /* This should only be done once on the top most decl. */
  11295.   if (have_extern_spec && !used_extern_spec)
  11296.     {
  11297.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
  11298.       used_extern_spec = 1;
  11299.     }
  11300.  
  11301.   if (pre_parsed_p)
  11302.     {
  11303.       decl1 = declarator;
  11304.  
  11305.       if (! DECL_ARGUMENTS (decl1)
  11306.       && !DECL_STATIC_FUNCTION_P (decl1)
  11307.       && DECL_CONTEXT (decl1)
  11308.       && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
  11309.       && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
  11310.     {
  11311.       cp_error ("redeclaration of `%#D'", decl1);
  11312.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
  11313.         cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
  11314.       else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
  11315.         cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
  11316.     }
  11317.  
  11318.       /* This can happen if a template class is instantiated as part of the
  11319.      specialization of a member function which is defined in the class
  11320.      template.  We should just use the specialization, but for now give an
  11321.      error.  */
  11322.       if (DECL_INITIAL (decl1) != NULL_TREE)
  11323.     {
  11324.       cp_error_at ("specialization of `%#D' not supported", decl1);
  11325.       cp_error ("when defined in the class template body", decl1);
  11326.     }
  11327.  
  11328.       last_function_parms = DECL_ARGUMENTS (decl1);
  11329.       last_function_parm_tags = NULL_TREE;
  11330.       fntype = TREE_TYPE (decl1);
  11331.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11332.     ctype = TYPE_METHOD_BASETYPE (fntype);
  11333.  
  11334.       /* ANSI C++ June 5 1992 WP 11.4.5.  A friend function defined in a
  11335.      class is in the (lexical) scope of the class in which it is
  11336.      defined.  */
  11337.       if (!ctype && DECL_FRIEND_P (decl1))
  11338.     {
  11339.       ctype = DECL_CLASS_CONTEXT (decl1);
  11340.  
  11341.       /* CTYPE could be null here if we're dealing with a template;
  11342.          for example, `inline friend float foo()' inside a template
  11343.          will have no CTYPE set.  */
  11344.       if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
  11345.         ctype = NULL_TREE;
  11346.       else
  11347.         doing_friend = 1;
  11348.     }
  11349.  
  11350.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  11351.  
  11352.       /* In a fcn definition, arg types must be complete.  */
  11353.       require_complete_types_for_parms (last_function_parms);
  11354.  
  11355.       /* In case some arg types were completed since the declaration was
  11356.          parsed, fix up the decls.  */
  11357.       {
  11358.     tree t = last_function_parms;
  11359.     for (; t; t = TREE_CHAIN (t))
  11360.       layout_decl (t, 0);
  11361.       }
  11362.     }
  11363.   else
  11364.     {
  11365.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises,
  11366.                   NULL_TREE);
  11367.       /* If the declarator is not suitable for a function definition,
  11368.      cause a syntax error.  */
  11369.       if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  11370.  
  11371.       fntype = TREE_TYPE (decl1);
  11372.  
  11373.       restype = TREE_TYPE (fntype);
  11374.       if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
  11375.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  11376.     {
  11377.       cp_error ("semicolon missing after declaration of `%#T'", restype);
  11378.       shadow_tag (build_tree_list (NULL_TREE, restype));
  11379.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  11380.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  11381.         fntype = build_function_type (integer_type_node,
  11382.                       TYPE_ARG_TYPES (fntype));
  11383.       else
  11384.         fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
  11385.                           integer_type_node,
  11386.                           TYPE_ARG_TYPES (fntype));
  11387.       TREE_TYPE (decl1) = fntype;
  11388.     }
  11389.  
  11390.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11391.     ctype = TYPE_METHOD_BASETYPE (fntype);
  11392.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  11393.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
  11394.            && DECL_CONTEXT (decl1) == NULL_TREE)
  11395.     {
  11396.       /* If this doesn't return integer_type, complain.  */
  11397.       if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
  11398.         {
  11399.           if (pedantic || warn_return_type)
  11400.         pedwarn ("return type for `main' changed to integer type");
  11401.           TREE_TYPE (decl1) = fntype = default_function_type;
  11402.         }
  11403.       warn_about_return_type = 0;
  11404.     }
  11405.     }
  11406.  
  11407.   /* Warn if function was previously implicitly declared
  11408.      (but not if we warned then).  */
  11409.   if (! warn_implicit
  11410.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
  11411.     cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
  11412.  
  11413.   current_function_decl = decl1;
  11414.  
  11415.   if (flag_cadillac)
  11416.     cadillac_start_function (decl1);
  11417.   else
  11418.     announce_function (decl1);
  11419.  
  11420.   if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
  11421.     {
  11422.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  11423.     error_with_aggr_type (TREE_TYPE (fntype),
  11424.                   "return-type `%s' is an incomplete type");
  11425.       else
  11426.     error ("return-type is an incomplete type");
  11427.  
  11428.       /* Make it return void instead, but don't change the
  11429.      type of the DECL_RESULT, in case we have a named return value.  */
  11430.       if (ctype)
  11431.     TREE_TYPE (decl1)
  11432.       = build_cplus_method_type (build_type_variant (ctype,
  11433.                              TREE_READONLY (decl1),
  11434.                              TREE_SIDE_EFFECTS (decl1)),
  11435.                      void_type_node,
  11436.                      FUNCTION_ARG_CHAIN (decl1));
  11437.       else
  11438.     TREE_TYPE (decl1)
  11439.       = build_function_type (void_type_node,
  11440.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  11441.       DECL_RESULT (decl1)
  11442.     = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype)));
  11443.       TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype));
  11444.       TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype));
  11445.     }
  11446.  
  11447.   if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype))
  11448.       && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype)))
  11449.     abstract_virtuals_error (decl1, TREE_TYPE (fntype));
  11450.  
  11451.   if (warn_about_return_type)
  11452.     warning ("return-type defaults to `int'");
  11453.  
  11454.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  11455.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  11456.   DECL_INITIAL (decl1) = error_mark_node;
  11457.  
  11458.   /* Didn't get anything from C.  */
  11459.   olddecl = NULL_TREE;
  11460.  
  11461.   /* This function exists in static storage.
  11462.      (This does not mean `static' in the C sense!)  */
  11463.   TREE_STATIC (decl1) = 1;
  11464.  
  11465.   /* Record the decl so that the function name is defined.
  11466.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  11467.      use the old decl.  */
  11468.  
  11469.   if (pre_parsed_p == 0)
  11470.     {
  11471.       current_function_decl = decl1 = pushdecl (decl1);
  11472.       DECL_MAIN_VARIANT (decl1) = decl1;
  11473.       fntype = TREE_TYPE (decl1);
  11474.     }
  11475.   else
  11476.     current_function_decl = decl1;
  11477.  
  11478.   if (DECL_INTERFACE_KNOWN (decl1))
  11479.     {
  11480.       if (DECL_NOT_REALLY_EXTERN (decl1))
  11481.     DECL_EXTERNAL (decl1) = 0;
  11482.     }
  11483.   /* If this function belongs to an interface, it is public.
  11484.      If it belongs to someone else's interface, it is also external.
  11485.      It doesn't matter whether it's inline or not.  */
  11486.   else if (interface_unknown == 0)
  11487.     {
  11488.       if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
  11489.     DECL_EXTERNAL (decl1)
  11490.       = (interface_only
  11491.          || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines));
  11492.       else
  11493.     DECL_EXTERNAL (decl1) = 0;
  11494.       DECL_NOT_REALLY_EXTERN (decl1) = 0;
  11495.       DECL_INTERFACE_KNOWN (decl1) = 1;
  11496.     }
  11497.   else
  11498.     {
  11499.       /* This is a definition, not a reference.
  11500.      So clear DECL_EXTERNAL.  */
  11501.       DECL_EXTERNAL (decl1) = 0;
  11502.  
  11503.       if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1))
  11504.     DECL_DEFER_OUTPUT (decl1) = 1;
  11505.       else
  11506.     {
  11507.       DECL_INTERFACE_KNOWN (decl1) = 1;
  11508.       if (DECL_C_STATIC (decl1))
  11509.         TREE_PUBLIC (decl1) = 0;
  11510.     }
  11511.     }
  11512.  
  11513.   if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
  11514.     {
  11515.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11516.     TREE_TYPE (decl1) = fntype
  11517.       = build_function_type (TREE_TYPE (fntype),
  11518.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  11519.       last_function_parms = TREE_CHAIN (last_function_parms);
  11520.       DECL_ARGUMENTS (decl1) = last_function_parms;
  11521.       ctype = NULL_TREE;
  11522.     }
  11523.   restype = TREE_TYPE (fntype);
  11524.  
  11525.   if (ctype)
  11526.     {
  11527.       push_nested_class (ctype, 1);
  11528.  
  11529.       /* If we're compiling a friend function, neither of the variables
  11530.      current_class_decl nor current_class_type will have values.  */
  11531.       if (! doing_friend)
  11532.     {
  11533.       /* We know that this was set up by `grokclassfn'.
  11534.          We do not wait until `store_parm_decls', since evil
  11535.          parse errors may never get us to that point.  Here
  11536.          we keep the consistency between `current_class_type'
  11537.          and `current_class_decl'.  */
  11538.       tree t = last_function_parms;
  11539.  
  11540.       my_friendly_assert (t != NULL_TREE
  11541.                   && TREE_CODE (t) == PARM_DECL, 162);
  11542.  
  11543.       if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
  11544.         {
  11545.           int i = suspend_momentary ();
  11546.  
  11547.           /* Fool build_indirect_ref.  */
  11548.           current_class_decl = NULL_TREE;
  11549.           C_C_D = build_indirect_ref (t, NULL_PTR);
  11550.           current_class_decl = t;
  11551.           resume_momentary (i);
  11552.         }
  11553.       else
  11554.         /* We're having a signature pointer here.  */
  11555.         C_C_D = current_class_decl = t;
  11556.  
  11557.     }
  11558.     }
  11559.   else
  11560.     {
  11561.       if (DECL_STATIC_FUNCTION_P (decl1))
  11562.     push_nested_class (DECL_CONTEXT (decl1), 2);
  11563.       else
  11564.     push_memoized_context (0, 1);
  11565.       current_class_decl = C_C_D = NULL_TREE;
  11566.     }
  11567.  
  11568.   pushlevel (0);
  11569.   current_binding_level->parm_flag = 1;
  11570.  
  11571.   /* Save the parm names or decls from this function's declarator
  11572.      where store_parm_decls will find them.  */
  11573.   current_function_parms = last_function_parms;
  11574.   current_function_parm_tags = last_function_parm_tags;
  11575.  
  11576.   GNU_xref_function (decl1, current_function_parms);
  11577.  
  11578.   if (attrs)
  11579.     cplus_decl_attributes (decl1, NULL_TREE, attrs);
  11580.   make_function_rtl (decl1);
  11581.  
  11582.   /* Allocate further tree nodes temporarily during compilation
  11583.      of this function only.  Tiemann moved up here from bottom of fn.  */
  11584.   temporary_allocation ();
  11585.  
  11586.   /* Promote the value to int before returning it.  */
  11587.   if (C_PROMOTING_INTEGER_TYPE_P (restype))
  11588.     {
  11589.       /* It retains unsignedness if traditional or if it isn't
  11590.      really getting wider.  */
  11591.       if (TREE_UNSIGNED (restype)
  11592.       && (flag_traditional
  11593.           || TYPE_PRECISION (restype)
  11594.            == TYPE_PRECISION (integer_type_node)))
  11595.     restype = unsigned_type_node;
  11596.       else
  11597.     restype = integer_type_node;
  11598.     }
  11599.   if (DECL_RESULT (decl1) == NULL_TREE)
  11600.     {
  11601.       DECL_RESULT (decl1)
  11602.     = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
  11603.       TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype);
  11604.       TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype);
  11605.     }
  11606.  
  11607.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))
  11608.       && DECL_LANGUAGE (decl1) == lang_cplusplus)
  11609.     {
  11610.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11611.       ctor_label = NULL_TREE;
  11612.     }
  11613.   else
  11614.     {
  11615.       dtor_label = NULL_TREE;
  11616.       if (DECL_CONSTRUCTOR_P (decl1))
  11617.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11618.     }
  11619.  
  11620.   /* If this fcn was already referenced via a block-scope `extern' decl
  11621.      (or an implicit decl), propagate certain information about the usage.  */
  11622.   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
  11623.     TREE_ADDRESSABLE (decl1) = 1;
  11624.  
  11625.   return 1;
  11626. }
  11627.  
  11628. void
  11629. expand_start_early_try_stmts ()
  11630. {
  11631.   rtx insns;
  11632.   start_sequence ();
  11633.   expand_start_try_stmts ();
  11634.   insns = get_insns ();
  11635.   end_sequence ();
  11636.   store_in_parms (insns);
  11637. }
  11638.  
  11639. void
  11640. store_in_parms (insns)
  11641.      rtx insns;
  11642. {
  11643.   rtx last_parm_insn;
  11644.  
  11645.   last_parm_insn = get_first_nonparm_insn ();
  11646.   if (last_parm_insn == NULL_RTX)
  11647.     emit_insns (insns);
  11648.   else
  11649.     emit_insns_before (insns, previous_insn (last_parm_insn));
  11650. }
  11651.  
  11652. /* Store the parameter declarations into the current function declaration.
  11653.    This is called after parsing the parameter declarations, before
  11654.    digesting the body of the function.
  11655.  
  11656.    Also install to binding contour return value identifier, if any.  */
  11657.  
  11658. void
  11659. store_parm_decls ()
  11660. {
  11661.   register tree fndecl = current_function_decl;
  11662.   register tree parm;
  11663.   int parms_have_cleanups = 0;
  11664.  
  11665.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  11666.   tree specparms = current_function_parms;
  11667.  
  11668.   /* This is a list of types declared among parms in a prototype.  */
  11669.   tree parmtags = current_function_parm_tags;
  11670.  
  11671.   /* This is a chain of any other decls that came in among the parm
  11672.      declarations.  If a parm is declared with  enum {foo, bar} x;
  11673.      then CONST_DECLs for foo and bar are put here.  */
  11674.   tree nonparms = NULL_TREE;
  11675.  
  11676.   if (toplevel_bindings_p ())
  11677.     fatal ("parse errors have confused me too much");
  11678.  
  11679.   /* Initialize RTL machinery.  */
  11680.   init_function_start (fndecl, input_filename, lineno);
  11681.  
  11682.   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
  11683.   declare_function_name ();
  11684.  
  11685.   /* Create a binding level for the parms.  */
  11686.   expand_start_bindings (0);
  11687.  
  11688.   if (specparms != NULL_TREE)
  11689.     {
  11690.       /* This case is when the function was defined with an ANSI prototype.
  11691.      The parms already have decls, so we need not do anything here
  11692.      except record them as in effect
  11693.      and complain if any redundant old-style parm decls were written.  */
  11694.  
  11695.       register tree next;
  11696.  
  11697.       /* Must clear this because it might contain TYPE_DECLs declared
  11698.      at class level.  */
  11699.       storedecls (NULL_TREE);
  11700.       for (parm = nreverse (specparms); parm; parm = next)
  11701.     {
  11702.       next = TREE_CHAIN (parm);
  11703.       if (TREE_CODE (parm) == PARM_DECL)
  11704.         {
  11705.           tree cleanup = maybe_build_cleanup (parm);
  11706.           if (DECL_NAME (parm) == NULL_TREE)
  11707.         {
  11708. #if 0
  11709.           cp_error_at ("parameter name omitted", parm);
  11710. #else
  11711.           /* for C++, this is not an error.  */
  11712.           pushdecl (parm);
  11713. #endif
  11714.         }
  11715.           else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  11716.         cp_error ("parameter `%D' declared void", parm);
  11717.           else
  11718.         {
  11719.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  11720.              A parameter is assumed not to have any side effects.
  11721.              If this should change for any reason, then this
  11722.              will have to wrap the bashed reference type in a save_expr.
  11723.              
  11724.              Also, if the parameter type is declared to be an X
  11725.              and there is an X(X&) constructor, we cannot lay it
  11726.              into the stack (any more), so we make this parameter
  11727.              look like it is really of reference type.  Functions
  11728.              which pass parameters to this function will know to
  11729.              create a temporary in their frame, and pass a reference
  11730.              to that.  */
  11731.  
  11732.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  11733.               && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  11734.             SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  11735.  
  11736.           pushdecl (parm);
  11737.         }
  11738.           if (cleanup)
  11739.         {
  11740.           expand_decl (parm);
  11741.           if (! cp_expand_decl_cleanup (parm, cleanup))
  11742.             cp_error ("parser lost in parsing declaration of `%D'",
  11743.                   parm);
  11744.           parms_have_cleanups = 1;
  11745.         }
  11746.         }
  11747.       else
  11748.         {
  11749.           /* If we find an enum constant or a type tag,
  11750.          put it aside for the moment.  */
  11751.           TREE_CHAIN (parm) = NULL_TREE;
  11752.           nonparms = chainon (nonparms, parm);
  11753.         }
  11754.     }
  11755.  
  11756.       /* Get the decls in their original chain order
  11757.      and record in the function.  This is all and only the
  11758.      PARM_DECLs that were pushed into scope by the loop above.  */
  11759.       DECL_ARGUMENTS (fndecl) = getdecls ();
  11760.  
  11761.       storetags (chainon (parmtags, gettags ()));
  11762.     }
  11763.   else
  11764.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  11765.  
  11766.   /* Now store the final chain of decls for the arguments
  11767.      as the decl-chain of the current lexical scope.
  11768.      Put the enumerators in as well, at the front so that
  11769.      DECL_ARGUMENTS is not modified.  */
  11770.  
  11771.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  11772.  
  11773.   /* Initialize the RTL code for the function.  */
  11774.   DECL_SAVED_INSNS (fndecl) = NULL_RTX;
  11775.   expand_function_start (fndecl, parms_have_cleanups);
  11776.  
  11777.   /* Create a binding contour which can be used to catch
  11778.      cleanup-generated temporaries.  Also, if the return value needs or
  11779.      has initialization, deal with that now.  */
  11780.   if (parms_have_cleanups)
  11781.     {
  11782.       pushlevel (0);
  11783.       expand_start_bindings (0);
  11784.     }
  11785.  
  11786.   current_function_parms_stored = 1;
  11787.  
  11788.   if (flag_gc)
  11789.     {
  11790.       maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
  11791.       if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
  11792.     cp_error ("parser lost in parsing declaration of `%D'", fndecl);
  11793.     }
  11794.  
  11795.   /* If this function is `main', emit a call to `__main'
  11796.      to run global initializers, etc.  */
  11797.   if (DECL_NAME (fndecl)
  11798.       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  11799. #ifdef _WIN32
  11800.       && (strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  11801.       || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "WinMain") == 0)
  11802. #else
  11803.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  11804. #endif /* _WIN32 */
  11805.       && DECL_CONTEXT (fndecl) == NULL_TREE)
  11806.     {
  11807.       expand_main_function ();
  11808.  
  11809.       if (flag_gc)
  11810.     expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
  11811.              0, VOIDmode, 0);
  11812. #if 0
  11813.       /* done at a different time */
  11814.       if (flag_rtti)
  11815.     output_builtin_tdesc_entries ();
  11816. #endif
  11817.     }
  11818.  
  11819.   /* Take care of exception handling things. */
  11820.   if (flag_handle_exceptions)
  11821.     {
  11822.       rtx insns;
  11823.       start_sequence ();
  11824.  
  11825.       /* Mark the start of a stack unwinder if we need one.  */
  11826.       start_eh_unwinder ();
  11827.  
  11828.       /* Do the starting of the exception specifications, if we have any.  */
  11829.       if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
  11830.     expand_start_eh_spec ();
  11831.  
  11832.       insns = get_insns ();
  11833.       end_sequence ();
  11834.  
  11835.       if (insns)
  11836.     store_in_parms (insns);
  11837.     }
  11838. }
  11839.  
  11840. /* Bind a name and initialization to the return value of
  11841.    the current function.  */
  11842. void
  11843. store_return_init (return_id, init)
  11844.      tree return_id, init;
  11845. {
  11846.   tree decl = DECL_RESULT (current_function_decl);
  11847.  
  11848.   if (pedantic)
  11849.     /* Give this error as many times as there are occurrences,
  11850.        so that users can use Emacs compilation buffers to find
  11851.        and fix all such places.  */
  11852.     pedwarn ("ANSI C++ does not permit named return values");
  11853.  
  11854.   if (return_id != NULL_TREE)
  11855.     {
  11856.       if (DECL_NAME (decl) == NULL_TREE)
  11857.     {
  11858.       DECL_NAME (decl) = return_id;
  11859.       DECL_ASSEMBLER_NAME (decl) = return_id;
  11860.     }
  11861.       else
  11862.     error ("return identifier `%s' already in place",
  11863.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  11864.     }
  11865.  
  11866.   /* Can't let this happen for constructors.  */
  11867.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  11868.     {
  11869.       error ("can't redefine default return value for constructors");
  11870.       return;
  11871.     }
  11872.  
  11873.   /* If we have a named return value, put that in our scope as well.  */
  11874.   if (DECL_NAME (decl) != NULL_TREE)
  11875.     {
  11876.       /* If this named return value comes in a register,
  11877.      put it in a pseudo-register.  */
  11878.       if (DECL_REGISTER (decl))
  11879.     {
  11880.       original_result_rtx = DECL_RTL (decl);
  11881.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  11882.     }
  11883.  
  11884.       /* Let `cp_finish_decl' know that this initializer is ok.  */
  11885.       DECL_INITIAL (decl) = init;
  11886.       pushdecl (decl);
  11887.       cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
  11888.     }
  11889. }
  11890.  
  11891.  
  11892. /* Finish up a function declaration and compile that function
  11893.    all the way to assembler language output.  The free the storage
  11894.    for the function definition.
  11895.  
  11896.    This is called after parsing the body of the function definition.
  11897.    LINENO is the current line number.
  11898.  
  11899.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  11900.    (and expand_end_bindings) must be made to take care of the binding
  11901.    contour for the base initializers.  This is only relevant for
  11902.    constructors.  */
  11903.  
  11904. void
  11905. finish_function (lineno, call_poplevel, nested)
  11906.      int lineno;
  11907.      int call_poplevel;
  11908.      int nested;
  11909. {
  11910.   register tree fndecl = current_function_decl;
  11911.   tree fntype, ctype = NULL_TREE;
  11912.   rtx last_parm_insn, insns;
  11913.   /* Label to use if this function is supposed to return a value.  */
  11914.   tree no_return_label = NULL_TREE;
  11915.   tree decls = NULL_TREE;
  11916.  
  11917.   /* When we get some parse errors, we can end up without a
  11918.      current_function_decl, so cope.  */
  11919.   if (fndecl == NULL_TREE)
  11920.     return;
  11921.  
  11922.   fntype = TREE_TYPE (fndecl);
  11923.  
  11924. /*  TREE_READONLY (fndecl) = 1;
  11925.     This caused &foo to be of type ptr-to-const-function
  11926.     which then got a warning when stored in a ptr-to-function variable.  */
  11927.  
  11928.   /* This happens on strange parse errors.  */
  11929.   if (! current_function_parms_stored)
  11930.     {
  11931.       call_poplevel = 0;
  11932.       store_parm_decls ();
  11933.     }
  11934.  
  11935.   if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
  11936.     {
  11937.       tree ttype = target_type (fntype);
  11938.       tree parmdecl;
  11939.  
  11940.       if (IS_AGGR_TYPE (ttype))
  11941.     /* Let debugger know it should output info for this type.  */
  11942.     note_debug_info_needed (ttype);
  11943.  
  11944.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  11945.     {
  11946.       ttype = target_type (TREE_TYPE (parmdecl));
  11947.       if (IS_AGGR_TYPE (ttype))
  11948.         /* Let debugger know it should output info for this type.  */
  11949.         note_debug_info_needed (ttype);
  11950.     }
  11951.     }
  11952.  
  11953.   /* Clean house because we will need to reorder insns here.  */
  11954.   do_pending_stack_adjust ();
  11955.  
  11956.   if (dtor_label)
  11957.     {
  11958.       tree binfo = TYPE_BINFO (current_class_type);
  11959.       tree cond = integer_one_node;
  11960.       tree exprstmt, vfields;
  11961.       tree in_charge_node = lookup_name (in_charge_identifier, 0);
  11962.       tree virtual_size;
  11963.       int ok_to_optimize_dtor = 0;
  11964.  
  11965.       if (current_function_assigns_this)
  11966.     cond = build (NE_EXPR, boolean_type_node,
  11967.               current_class_decl, integer_zero_node);
  11968.       else
  11969.     {
  11970.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  11971.  
  11972.       /* If this destructor is empty, then we don't need to check
  11973.          whether `this' is NULL in some cases.  */
  11974.       if ((flag_this_is_variable & 1) == 0)
  11975.         ok_to_optimize_dtor = 1;
  11976.       else if (get_last_insn () == get_first_nonparm_insn ())
  11977.         ok_to_optimize_dtor
  11978.           = (n_baseclasses == 0
  11979.          || (n_baseclasses == 1
  11980.              && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
  11981.     }
  11982.  
  11983.       /* These initializations might go inline.  Protect
  11984.      the binding level of the parms.  */
  11985.       pushlevel (0);
  11986.       expand_start_bindings (0);
  11987.  
  11988.       if (current_function_assigns_this)
  11989.     {
  11990.       current_function_assigns_this = 0;
  11991.       current_function_just_assigned_this = 0;
  11992.     }
  11993.  
  11994.       /* Generate the code to call destructor on base class.
  11995.      If this destructor belongs to a class with virtual
  11996.      functions, then set the virtual function table
  11997.      pointer to represent the type of our base class.  */
  11998.  
  11999.       /* This side-effect makes call to `build_delete' generate the
  12000.      code we have to have at the end of this destructor.  */
  12001.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  12002.  
  12003.       /* These are two cases where we cannot delegate deletion.  */
  12004.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  12005.       || TYPE_GETS_REG_DELETE (current_class_type))
  12006.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  12007.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  12008.       else
  12009.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  12010.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  12011.  
  12012.       /* If we did not assign to this, then `this' is non-zero at
  12013.      the end of a destructor.  As a special optimization, don't
  12014.      emit test if this is an empty destructor.  If it does nothing,
  12015.      it does nothing.  If it calls a base destructor, the base
  12016.      destructor will perform the test.  */
  12017.  
  12018.       if (exprstmt != error_mark_node
  12019.       && (TREE_CODE (exprstmt) != NOP_EXPR
  12020.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  12021.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  12022.     {
  12023.       expand_label (dtor_label);
  12024.       if (cond != integer_one_node)
  12025.         expand_start_cond (cond, 0);
  12026.       if (exprstmt != void_zero_node)
  12027.         /* Don't call `expand_expr_stmt' if we're not going to do
  12028.            anything, since -Wall will give a diagnostic.  */
  12029.         expand_expr_stmt (exprstmt);
  12030.  
  12031.       /* Run destructor on all virtual baseclasses.  */
  12032.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12033.         {
  12034.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  12035.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  12036.                     in_charge_node, integer_two_node), 0);
  12037.           while (vbases)
  12038.         {
  12039.           if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
  12040.             {
  12041.               tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl);
  12042.               expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)),
  12043.                               ptr, integer_zero_node,
  12044.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
  12045.             }
  12046.           vbases = TREE_CHAIN (vbases);
  12047.         }
  12048.           expand_end_cond ();
  12049.         }
  12050.  
  12051.       do_pending_stack_adjust ();
  12052.       if (cond != integer_one_node)
  12053.         expand_end_cond ();
  12054.     }
  12055.  
  12056.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  12057.  
  12058.       virtual_size = c_sizeof (current_class_type);
  12059.  
  12060.       /* At the end, call delete if that's what's requested.  */
  12061.       if (TYPE_GETS_REG_DELETE (current_class_type))
  12062.     /* This NOP_EXPR means we are in a static call context.  */
  12063.     exprstmt =
  12064.       build_method_call
  12065.         (build_indirect_ref
  12066.          (build1 (NOP_EXPR, build_pointer_type (current_class_type),
  12067.               error_mark_node),
  12068.           NULL_PTR),
  12069.          ansi_opname[(int) DELETE_EXPR],
  12070.          tree_cons (NULL_TREE, current_class_decl,
  12071.             build_tree_list (NULL_TREE, virtual_size)),
  12072.          NULL_TREE, LOOKUP_NORMAL);
  12073.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12074.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
  12075.                    virtual_size);
  12076.       else
  12077.     exprstmt = NULL_TREE;
  12078.  
  12079.       if (exprstmt)
  12080.     {
  12081.       cond = build (BIT_AND_EXPR, integer_type_node,
  12082.             in_charge_node, integer_one_node);
  12083.       expand_start_cond (cond, 0);
  12084.       expand_expr_stmt (exprstmt);
  12085.       expand_end_cond ();
  12086.     }
  12087.  
  12088.       /* End of destructor.  */
  12089.       expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
  12090.       poplevel (2, 0, 0); /* XXX change to 1 */
  12091.  
  12092.       /* Back to the top of destructor.  */
  12093.       /* Dont execute destructor code if `this' is NULL.  */
  12094.  
  12095.       start_sequence ();
  12096.  
  12097.       /* Make all virtual function table pointers in non-virtual base
  12098.      classes point to CURRENT_CLASS_TYPE's virtual function
  12099.      tables.  */
  12100.       expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
  12101.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12102.     expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
  12103.       if (! ok_to_optimize_dtor)
  12104.     {
  12105.       cond = build_binary_op (NE_EXPR,
  12106.                   current_class_decl, integer_zero_node, 1);
  12107.       expand_start_cond (cond, 0);
  12108.     }
  12109.  
  12110.       insns = get_insns ();
  12111.       end_sequence ();
  12112.  
  12113.       last_parm_insn = get_first_nonparm_insn ();
  12114.       if (last_parm_insn == NULL_RTX)
  12115.     last_parm_insn = get_last_insn ();
  12116.       else
  12117.     last_parm_insn = previous_insn (last_parm_insn);
  12118.  
  12119.       emit_insns_after (insns, last_parm_insn);
  12120.  
  12121.       if (! ok_to_optimize_dtor)
  12122.     expand_end_cond ();
  12123.     }
  12124.   else if (current_function_assigns_this)
  12125.     {
  12126.       /* Does not need to call emit_base_init, because
  12127.      that is done (if needed) just after assignment to this
  12128.      is seen.  */
  12129.  
  12130.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  12131.     {
  12132.       end_protect_partials ();
  12133.       expand_label (ctor_label);
  12134.       ctor_label = NULL_TREE;
  12135.  
  12136.       if (call_poplevel)
  12137.         {
  12138.           decls = getdecls ();
  12139.           expand_end_bindings (decls, decls != NULL_TREE, 0);
  12140.           poplevel (decls != NULL_TREE, 0, 0);
  12141.         }
  12142.       c_expand_return (current_class_decl);
  12143.     }
  12144.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (
  12145.             DECL_RESULT (current_function_decl))) != void_type_node
  12146.            && return_label != NULL_RTX)
  12147.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  12148.  
  12149.       current_function_assigns_this = 0;
  12150.       current_function_just_assigned_this = 0;
  12151.       base_init_expr = NULL_TREE;
  12152.     }
  12153.   else if (DECL_CONSTRUCTOR_P (fndecl))
  12154.     {
  12155.       tree allocated_this;
  12156.       tree cond, thenclause;
  12157.       /* Allow constructor for a type to get a new instance of the object
  12158.      using `build_new'.  */
  12159.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  12160.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  12161.  
  12162.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  12163.  
  12164.       if (flag_this_is_variable > 0)
  12165.     {
  12166.       cond = build_binary_op (EQ_EXPR,
  12167.                   current_class_decl, integer_zero_node, 1);
  12168.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  12169.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  12170.     }
  12171.  
  12172.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  12173.  
  12174.       start_sequence ();
  12175.  
  12176.       if (flag_this_is_variable > 0)
  12177.     {
  12178.       expand_start_cond (cond, 0);
  12179.       expand_expr_stmt (thenclause);
  12180.       expand_end_cond ();
  12181.     }
  12182.  
  12183. #if 0
  12184.       if (DECL_NAME (fndecl) == NULL_TREE
  12185.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  12186.     build_default_constructor (fndecl);
  12187. #endif
  12188.  
  12189.       /* Emit insns from `emit_base_init' which sets up virtual
  12190.      function table pointer(s).  */
  12191.       if (base_init_expr)
  12192.     {
  12193.       expand_expr_stmt (base_init_expr);
  12194.       base_init_expr = NULL_TREE;
  12195.     }
  12196.  
  12197.       insns = get_insns ();
  12198.       end_sequence ();
  12199.  
  12200.       /* This is where the body of the constructor begins.
  12201.      If there were no insns in this function body, then the
  12202.      last_parm_insn is also the last insn.
  12203.  
  12204.      If optimization is enabled, last_parm_insn may move, so
  12205.      we don't hold on to it (across emit_base_init).  */
  12206.       last_parm_insn = get_first_nonparm_insn ();
  12207.       if (last_parm_insn == NULL_RTX)
  12208.     last_parm_insn = get_last_insn ();
  12209.       else
  12210.     last_parm_insn = previous_insn (last_parm_insn);
  12211.  
  12212.       emit_insns_after (insns, last_parm_insn);
  12213.  
  12214.       end_protect_partials ();
  12215.  
  12216.       /* This is where the body of the constructor ends.  */
  12217.       expand_label (ctor_label);
  12218.       ctor_label = NULL_TREE;
  12219.  
  12220.       if (call_poplevel)
  12221.     {
  12222.       decls = getdecls ();
  12223.       expand_end_bindings (decls, decls != NULL_TREE, 0);
  12224.       poplevel (decls != NULL_TREE, 1, 0);
  12225.     }
  12226.  
  12227.       c_expand_return (current_class_decl);
  12228.  
  12229.       current_function_assigns_this = 0;
  12230.       current_function_just_assigned_this = 0;
  12231.     }
  12232.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  12233.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
  12234.        && DECL_CONTEXT (fndecl) == NULL_TREE)
  12235.     {
  12236.       /* Make it so that `main' always returns 0 by default.  */
  12237. #ifdef VMS
  12238.       c_expand_return (integer_one_node);
  12239. #else
  12240.       c_expand_return (integer_zero_node);
  12241. #endif
  12242.     }
  12243.   else if (return_label != NULL_RTX
  12244.        && current_function_return_value == NULL_TREE
  12245.        && ! DECL_NAME (DECL_RESULT (current_function_decl)))
  12246.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  12247.  
  12248.   if (flag_gc)
  12249.     expand_gc_prologue_and_epilogue ();
  12250.  
  12251.   /* If this function is supposed to return a value, ensure that
  12252.      we do not fall into the cleanups by mistake.  The end of our
  12253.      function will look like this:
  12254.  
  12255.     user code (may have return stmt somewhere)
  12256.     goto no_return_label
  12257.     cleanup_label:
  12258.     cleanups
  12259.     goto return_label
  12260.     no_return_label:
  12261.     NOTE_INSN_FUNCTION_END
  12262.     return_label:
  12263.     things for return
  12264.  
  12265.      If the user omits a return stmt in the USER CODE section, we
  12266.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  12267.      Otherwise, we won't.  */
  12268.   if (no_return_label)
  12269.     {
  12270.       DECL_CONTEXT (no_return_label) = fndecl;
  12271.       DECL_INITIAL (no_return_label) = error_mark_node;
  12272.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  12273.       DECL_SOURCE_LINE (no_return_label) = lineno;
  12274.       expand_goto (no_return_label);
  12275.     }
  12276.  
  12277.   if (cleanup_label)
  12278.     {
  12279.       /* remove the binding contour which is used
  12280.      to catch cleanup-generated temporaries.  */
  12281.       expand_end_bindings (0, 0, 0);
  12282.       poplevel (0, 0, 0);
  12283.     }
  12284.  
  12285.   if (cleanup_label)
  12286.     /* Emit label at beginning of cleanup code for parameters.  */
  12287.     emit_label (cleanup_label);
  12288.  
  12289.   /* Get return value into register if that's where it's supposed to be.  */
  12290.   if (original_result_rtx)
  12291.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  12292.  
  12293.   /* Finish building code that will trigger warnings if users forget
  12294.      to make their functions return values.  */
  12295.   if (no_return_label || cleanup_label)
  12296.     emit_jump (return_label);
  12297.   if (no_return_label)
  12298.     {
  12299.       /* We don't need to call `expand_*_return' here because we
  12300.      don't need any cleanups here--this path of code is only
  12301.      for error checking purposes.  */
  12302.       expand_label (no_return_label);
  12303.     }
  12304.  
  12305.   /* Generate rtl for function exit.  */
  12306.   expand_function_end (input_filename, lineno, 1);
  12307.  
  12308.   if (flag_handle_exceptions)
  12309.     expand_exception_blocks ();
  12310.  
  12311.   /* This must come after expand_function_end because cleanups might
  12312.      have declarations (from inline functions) that need to go into
  12313.      this function's blocks.  */
  12314.   if (current_binding_level->parm_flag != 1)
  12315.     my_friendly_abort (122);
  12316.   poplevel (1, 0, 1);
  12317.  
  12318.   /* reset scope for C++: if we were in the scope of a class,
  12319.      then when we finish this function, we are not longer so.
  12320.      This cannot be done until we know for sure that no more
  12321.      class members will ever be referenced in this function
  12322.      (i.e., calls to destructors).  */
  12323.   if (current_class_name)
  12324.     {
  12325.       ctype = current_class_type;
  12326.       pop_nested_class (1);
  12327.     }
  12328.   else
  12329.     pop_memoized_context (1);
  12330.  
  12331.   /* Must mark the RESULT_DECL as being in this function.  */
  12332.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  12333.  
  12334.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  12335.   if (flag_traditional && current_function_calls_setjmp)
  12336.     setjmp_protect (DECL_INITIAL (fndecl));
  12337.  
  12338.   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
  12339.      to the FUNCTION_DECL node itself.  */
  12340.   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
  12341.  
  12342.   /* So we can tell if jump_optimize sets it to 1.  */
  12343.   can_reach_end = 0;
  12344.  
  12345.   /* Run the optimizers and output the assembler code for this function.  */
  12346.   rest_of_compilation (fndecl);
  12347.  
  12348.   if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl))
  12349.     {
  12350.       /* Set DECL_EXTERNAL so that assemble_external will be called as
  12351.          necessary.  We'll clear it again in finish_file.  */
  12352.       if (! DECL_EXTERNAL (fndecl))
  12353.     DECL_NOT_REALLY_EXTERN (fndecl) = 1;
  12354.       DECL_EXTERNAL (fndecl) = 1;
  12355.       mark_inline_for_output (fndecl);
  12356.     }
  12357.  
  12358.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  12359.     note_debug_info_needed (ctype);
  12360.  
  12361.   current_function_returns_null |= can_reach_end;
  12362.  
  12363.   /* Since we don't normally go through c_expand_return for constructors,
  12364.      this normally gets the wrong value.
  12365.      Also, named return values have their return codes emitted after
  12366.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  12367.   if (DECL_CONSTRUCTOR_P (fndecl)
  12368.       || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
  12369.     current_function_returns_null = 0;
  12370.  
  12371.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  12372.     cp_warning ("`noreturn' function `%D' does return", fndecl);
  12373.   else if ((warn_return_type || pedantic)
  12374.        && current_function_returns_null
  12375.        && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
  12376.     {
  12377.       /* If this function returns non-void and control can drop through,
  12378.      complain.  */
  12379.       cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
  12380.     }
  12381.   /* With just -W, complain only if function returns both with
  12382.      and without a value.  */
  12383.   else if (extra_warnings
  12384.        && current_function_returns_value && current_function_returns_null)
  12385.     warning ("this function may return with or without a value");
  12386.  
  12387.   /* Free all the tree nodes making up this function.  */
  12388.   /* Switch back to allocating nodes permanently
  12389.      until we start another function.  */
  12390.   if (! nested)
  12391.     permanent_allocation (1);
  12392.  
  12393.   if (flag_cadillac)
  12394.     cadillac_finish_function (fndecl);
  12395.  
  12396.   if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
  12397.     {
  12398.       /* Stop pointing to the local nodes about to be freed.  */
  12399.       /* But DECL_INITIAL must remain nonzero so we know this
  12400.      was an actual function definition.  */
  12401.       DECL_INITIAL (fndecl) = error_mark_node;
  12402.       if (! DECL_CONSTRUCTOR_P (fndecl)
  12403.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  12404.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  12405.     }
  12406.  
  12407.   if (DECL_STATIC_CONSTRUCTOR (fndecl))
  12408.     static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
  12409.   if (DECL_STATIC_DESTRUCTOR (fndecl))
  12410.     static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
  12411.  
  12412.   if (! nested)
  12413.     {
  12414.       /* Let the error reporting routines know that we're outside a
  12415.          function.  For a nested function, this value is used in
  12416.          pop_cp_function_context and then reset via pop_function_context.  */
  12417.       current_function_decl = NULL_TREE;
  12418.     }
  12419.  
  12420.   named_label_uses = NULL_TREE;
  12421.   current_class_decl = NULL_TREE;
  12422. }
  12423.  
  12424. /* Create the FUNCTION_DECL for a function definition.
  12425.    LINE1 is the line number that the definition absolutely begins on.
  12426.    LINE2 is the line number that the name of the function appears on.
  12427.    DECLSPECS and DECLARATOR are the parts of the declaration;
  12428.    they describe the return type and the name of the function,
  12429.    but twisted together in a fashion that parallels the syntax of C.
  12430.  
  12431.    This function creates a binding context for the function body
  12432.    as well as setting up the FUNCTION_DECL in current_function_decl.
  12433.  
  12434.    Returns a FUNCTION_DECL on success.
  12435.  
  12436.    If the DECLARATOR is not suitable for a function (it defines a datum
  12437.    instead), we return 0, which tells yyparse to report a parse error.
  12438.  
  12439.    May return void_type_node indicating that this method is actually
  12440.    a friend.  See grokfield for more details.
  12441.  
  12442.    Came here with a `.pushlevel' .
  12443.  
  12444.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  12445.    CHANGES TO CODE IN `grokfield'.  */
  12446. tree
  12447. start_method (declspecs, declarator, raises)
  12448.      tree declarator, declspecs, raises;
  12449. {
  12450.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises,
  12451.                 NULL_TREE);
  12452.  
  12453.   /* Something too ugly to handle.  */
  12454.   if (fndecl == NULL_TREE)
  12455.     return NULL_TREE;
  12456.  
  12457.   /* Pass friends other than inline friend functions back.  */
  12458.   if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
  12459.     return fndecl;
  12460.  
  12461.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  12462.     /* Not a function, tell parser to report parse error.  */
  12463.     return NULL_TREE;
  12464.  
  12465.   if (IS_SIGNATURE (current_class_type))
  12466.     {
  12467.       IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
  12468.       /* In case we need this info later.  */
  12469.       HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
  12470.     }
  12471.  
  12472.   if (DECL_IN_AGGR_P (fndecl))
  12473.     {
  12474.       if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
  12475.     {
  12476.       if (DECL_CONTEXT (fndecl))
  12477.         cp_error ("`%D' is already defined in class %s", fndecl,
  12478.                  TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
  12479.     }
  12480.       return void_type_node;
  12481.     }
  12482.  
  12483.   DECL_THIS_INLINE (fndecl) = 1;
  12484.  
  12485.   if (flag_default_inline)
  12486.     DECL_INLINE (fndecl) = 1;
  12487.  
  12488.   if (processing_template_defn)
  12489.     {
  12490.       SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
  12491.       repo_template_used (fndecl);
  12492.     }
  12493.  
  12494.   /* We read in the parameters on the maybepermanent_obstack,
  12495.      but we won't be getting back to them until after we
  12496.      may have clobbered them.  So the call to preserve_data
  12497.      will keep them safe.  */
  12498.   preserve_data ();
  12499.  
  12500.   if (! DECL_FRIEND_P (fndecl))
  12501.     {
  12502.       if (DECL_CHAIN (fndecl) != NULL_TREE)
  12503.     {
  12504.       /* Need a fresh node here so that we don't get circularity
  12505.          when we link these together.  If FNDECL was a friend, then
  12506.          `pushdecl' does the right thing, which is nothing wrt its
  12507.          current value of DECL_CHAIN.  */
  12508.       fndecl = copy_node (fndecl);
  12509.     }
  12510.       if (TREE_CHAIN (fndecl))
  12511.     {
  12512.       fndecl = copy_node (fndecl);
  12513.       TREE_CHAIN (fndecl) = NULL_TREE;
  12514.     }
  12515.  
  12516.       if (DECL_CONSTRUCTOR_P (fndecl))
  12517.     {
  12518.       if (! grok_ctor_properties (current_class_type, fndecl))
  12519.         return void_type_node;
  12520.     }
  12521.       else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
  12522.     grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
  12523.     }
  12524.  
  12525.   cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
  12526.  
  12527.   /* Make a place for the parms */
  12528.   pushlevel (0);
  12529.   current_binding_level->parm_flag = 1;
  12530.   
  12531.   DECL_IN_AGGR_P (fndecl) = 1;
  12532.   return fndecl;
  12533. }
  12534.  
  12535. /* Go through the motions of finishing a function definition.
  12536.    We don't compile this method until after the whole class has
  12537.    been processed.
  12538.  
  12539.    FINISH_METHOD must return something that looks as though it
  12540.    came from GROKFIELD (since we are defining a method, after all).
  12541.  
  12542.    This is called after parsing the body of the function definition.
  12543.    STMTS is the chain of statements that makes up the function body.
  12544.  
  12545.    DECL is the ..._DECL that `start_method' provided.  */
  12546.  
  12547. tree
  12548. finish_method (decl)
  12549.      tree decl;
  12550. {
  12551.   register tree fndecl = decl;
  12552.   tree old_initial;
  12553.  
  12554.   register tree link;
  12555.  
  12556.   if (TYPE_MAIN_VARIANT (decl) == void_type_node)
  12557.     return decl;
  12558.  
  12559.   old_initial = DECL_INITIAL (fndecl);
  12560.  
  12561.   /* Undo the level for the parms (from start_method).
  12562.      This is like poplevel, but it causes nothing to be
  12563.      saved.  Saving information here confuses symbol-table
  12564.      output routines.  Besides, this information will
  12565.      be correctly output when this method is actually
  12566.      compiled.  */
  12567.  
  12568.   /* Clear out the meanings of the local variables of this level;
  12569.      also record in each decl which block it belongs to.  */
  12570.  
  12571.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  12572.     {
  12573.       if (DECL_NAME (link) != NULL_TREE)
  12574.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  12575.       my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
  12576.       DECL_CONTEXT (link) = NULL_TREE;
  12577.     }
  12578.  
  12579.   /* Restore all name-meanings of the outer levels
  12580.      that were shadowed by this level.  */
  12581.  
  12582.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  12583.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12584.   for (link = current_binding_level->class_shadowed;
  12585.        link; link = TREE_CHAIN (link))
  12586.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12587.   for (link = current_binding_level->type_shadowed;
  12588.        link; link = TREE_CHAIN (link))
  12589.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12590.  
  12591.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  12592.               (HOST_WIDE_INT) current_binding_level->level_chain,
  12593.               current_binding_level->parm_flag,
  12594.               current_binding_level->keep,
  12595.               current_binding_level->tag_transparent);
  12596.  
  12597.   poplevel (0, 0, 0);
  12598.  
  12599.   DECL_INITIAL (fndecl) = old_initial;
  12600.  
  12601.   /* We used to check if the context of FNDECL was different from
  12602.      current_class_type as another way to get inside here.  This didn't work
  12603.      for String.cc in libg++.  */
  12604.   if (DECL_FRIEND_P (fndecl))
  12605.     {
  12606.       CLASSTYPE_INLINE_FRIENDS (current_class_type)
  12607.     = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  12608.       decl = void_type_node;
  12609.     }
  12610.  
  12611.   return decl;
  12612. }
  12613.  
  12614. /* Called when a new struct TYPE is defined.
  12615.    If this structure or union completes the type of any previous
  12616.    variable declaration, lay it out and output its rtl.  */
  12617.  
  12618. void
  12619. hack_incomplete_structures (type)
  12620.      tree type;
  12621. {
  12622.   tree *list;
  12623.  
  12624.   if (current_binding_level->incomplete == NULL_TREE)
  12625.     return;
  12626.  
  12627.   if (!type) /* Don't do this for class templates.  */
  12628.     return;
  12629.  
  12630.   for (list = ¤t_binding_level->incomplete; *list; )
  12631.     {
  12632.       tree decl = TREE_VALUE (*list);
  12633.       if (decl && TREE_TYPE (decl) == type
  12634.       || (TREE_TYPE (decl)
  12635.           && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  12636.           && TREE_TYPE (TREE_TYPE (decl)) == type))
  12637.     {
  12638.       int toplevel = toplevel_bindings_p ();
  12639.       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  12640.           && TREE_TYPE (TREE_TYPE (decl)) == type)
  12641.         layout_type (TREE_TYPE (decl));
  12642.       layout_decl (decl, 0);
  12643.       rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
  12644.       if (! toplevel)
  12645.         {
  12646.           tree cleanup;
  12647.           expand_decl (decl);
  12648.           cleanup = maybe_build_cleanup (decl);
  12649.           expand_decl_init (decl);
  12650.           if (! cp_expand_decl_cleanup (decl, cleanup))
  12651.         cp_error ("parser lost in parsing declaration of `%D'",
  12652.               decl);
  12653.         }
  12654.       *list = TREE_CHAIN (*list);
  12655.     }
  12656.       else
  12657.     list = &TREE_CHAIN (*list);
  12658.     }
  12659. }
  12660.  
  12661. /* Nonzero if presently building a cleanup.  Needed because
  12662.    SAVE_EXPRs are not the right things to use inside of cleanups.
  12663.    They are only ever evaluated once, where the cleanup
  12664.    might be evaluated several times.  In this case, a later evaluation
  12665.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  12666.    not be valid for an earlier cleanup.  */
  12667.  
  12668. int building_cleanup;
  12669.  
  12670. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  12671.    We don't build cleanups if just going for syntax checking, since
  12672.    fixup_cleanups does not know how to not handle them.
  12673.  
  12674.    Don't build these on the momentary obstack; they must live
  12675.    the life of the binding contour.  */
  12676. tree
  12677. maybe_build_cleanup (decl)
  12678.      tree decl;
  12679. {
  12680.   tree type = TREE_TYPE (decl);
  12681.   if (TYPE_NEEDS_DESTRUCTOR (type))
  12682.     {
  12683.       int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
  12684.       tree rval;
  12685.       int old_building_cleanup = building_cleanup;
  12686.       building_cleanup = 1;
  12687.  
  12688.       if (TREE_CODE (decl) != PARM_DECL)
  12689.     temp = suspend_momentary ();
  12690.  
  12691.       if (TREE_CODE (type) == ARRAY_TYPE)
  12692.     rval = decl;
  12693.       else
  12694.     {
  12695.       mark_addressable (decl);
  12696.       rval = build_unary_op (ADDR_EXPR, decl, 0);
  12697.     }
  12698.  
  12699.       /* Optimize for space over speed here.  */
  12700.       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
  12701.       || flag_expensive_optimizations)
  12702.     flags |= LOOKUP_NONVIRTUAL;
  12703.  
  12704.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
  12705.  
  12706.       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
  12707.       && ! TYPE_HAS_DESTRUCTOR (type))
  12708.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  12709.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  12710.  
  12711.       if (TREE_CODE (decl) != PARM_DECL)
  12712.     resume_momentary (temp);
  12713.  
  12714.       building_cleanup = old_building_cleanup;
  12715.  
  12716.       return rval;
  12717.     }
  12718.   return 0;
  12719. }
  12720.  
  12721. /* Expand a C++ expression at the statement level.
  12722.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  12723.    The C++ type checker should get all of these out when
  12724.    expressions are combined with other, type-providing, expressions,
  12725.    leaving only orphan expressions, such as:
  12726.  
  12727.    &class::bar;        / / takes its address, but does nothing with it.
  12728.  
  12729.    */
  12730. void
  12731. cplus_expand_expr_stmt (exp)
  12732.      tree exp;
  12733. {
  12734.   if (TREE_TYPE (exp) == unknown_type_node)
  12735.     {
  12736.       if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
  12737.     error ("address of overloaded function with no contextual type information");
  12738.       else if (TREE_CODE (exp) == COMPONENT_REF)
  12739.     warning ("useless reference to a member function name, did you forget the ()?");
  12740.     }
  12741.   else
  12742.     {
  12743.       int remove_implicit_immediately = 0;
  12744.  
  12745.       if (TREE_CODE (exp) == FUNCTION_DECL)
  12746.     {
  12747.       cp_warning ("reference, not call, to function `%D'", exp);
  12748.       warning ("at this point in file");
  12749.     }
  12750.  
  12751. #if 0
  12752.       /* We should do this eventually, but right now this causes regex.o from
  12753.      libg++ to miscompile, and tString to core dump.  */
  12754.       exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
  12755. #endif
  12756.       expand_expr_stmt (break_out_cleanups (exp));
  12757.     }
  12758.  
  12759.   /* Clean up any pending cleanups.  This happens when a function call
  12760.      returns a cleanup-needing value that nobody uses.  */
  12761.   expand_cleanups_to (NULL_TREE);
  12762. }
  12763.  
  12764. /* When a stmt has been parsed, this function is called.
  12765.  
  12766.    Currently, this function only does something within a
  12767.    constructor's scope: if a stmt has just assigned to this,
  12768.    and we are in a derived class, we call `emit_base_init'.  */
  12769.  
  12770. void
  12771. finish_stmt ()
  12772. {
  12773.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  12774.  
  12775.   
  12776.   if (current_function_assigns_this
  12777.       || ! current_function_just_assigned_this)
  12778.     return;
  12779.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  12780.     {
  12781.       /* Constructors must wait until we are out of control
  12782.      zones before calling base constructors.  */
  12783.       if (cond_stack || loop_stack || case_stack)
  12784.     return;
  12785.       expand_expr_stmt (base_init_expr);
  12786.       check_base_init (current_class_type);
  12787.     }
  12788.   current_function_assigns_this = 1;
  12789.  
  12790.   if (flag_cadillac)
  12791.     cadillac_finish_stmt ();
  12792. }
  12793.  
  12794. /* Change a static member function definition into a FUNCTION_TYPE, instead
  12795.    of the METHOD_TYPE that we create when it's originally parsed.
  12796.  
  12797.    WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
  12798.    (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
  12799.    other decls.  Either pass the addresses of local variables or NULL.  */
  12800.  
  12801. void
  12802. revert_static_member_fn (decl, fn, argtypes)
  12803.      tree *decl, *fn, *argtypes;
  12804. {
  12805.   tree tmp;
  12806.   tree function = fn ? *fn : TREE_TYPE (*decl);
  12807.   tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
  12808.  
  12809.   if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args))))
  12810.     cp_error ("static member function `%#D' declared const", *decl);
  12811.   if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args))))
  12812.     cp_error ("static member function `%#D' declared volatile", *decl);
  12813.  
  12814.   args = TREE_CHAIN (args);
  12815.   tmp = build_function_type (TREE_TYPE (function), args);
  12816.   tmp = build_type_variant (tmp, TYPE_READONLY (function),
  12817.                 TYPE_VOLATILE (function));
  12818.   tmp = build_exception_variant (tmp,
  12819.                  TYPE_RAISES_EXCEPTIONS (function));
  12820.   TREE_TYPE (*decl) = tmp;
  12821.   if (DECL_ARGUMENTS (*decl))
  12822.     DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl));
  12823.   DECL_STATIC_FUNCTION_P (*decl) = 1;
  12824.   if (fn)
  12825.     *fn = tmp;
  12826.   if (argtypes)
  12827.     *argtypes = args;
  12828. }
  12829.  
  12830. int
  12831. id_in_current_class (id)
  12832.      tree id;
  12833. {
  12834.   return !!purpose_member (id, class_binding_level->class_shadowed);
  12835. }
  12836.  
  12837. struct cp_function
  12838. {
  12839.   int returns_value;
  12840.   int returns_null;
  12841.   int warn_about_return_type;
  12842.   int assigns_this;
  12843.   int just_assigned_this;
  12844.   int parms_stored;
  12845.   int temp_name_counter;
  12846.   tree named_labels;
  12847.   tree shadowed_labels;
  12848.   tree ctor_label;
  12849.   tree dtor_label;
  12850.   tree protect_list;
  12851.   tree base_init_list;
  12852.   tree member_init_list;
  12853.   tree base_init_expr;
  12854.   tree class_decl;
  12855.   tree C_C_D;
  12856.   rtx result_rtx;
  12857.   struct cp_function *next;
  12858.   struct binding_level *binding_level;
  12859. };
  12860.  
  12861. struct cp_function *cp_function_chain;
  12862.  
  12863. extern int temp_name_counter;
  12864.  
  12865. /* Save and reinitialize the variables
  12866.    used during compilation of a C++ function.  */
  12867.  
  12868. void
  12869. push_cp_function_context (context)
  12870.      tree context;
  12871. {
  12872.   struct cp_function *p
  12873.     = (struct cp_function *) xmalloc (sizeof (struct cp_function));
  12874.  
  12875.   push_function_context_to (context);
  12876.  
  12877.   p->next = cp_function_chain;
  12878.   cp_function_chain = p;
  12879.  
  12880.   p->named_labels = named_labels;
  12881.   p->shadowed_labels = shadowed_labels;
  12882.   p->returns_value = current_function_returns_value;
  12883.   p->returns_null = current_function_returns_null;
  12884.   p->warn_about_return_type = warn_about_return_type;
  12885.   p->binding_level = current_binding_level;
  12886.   p->ctor_label = ctor_label;
  12887.   p->dtor_label = dtor_label;
  12888.   p->assigns_this = current_function_assigns_this;
  12889.   p->just_assigned_this = current_function_just_assigned_this;
  12890.   p->parms_stored = current_function_parms_stored;
  12891.   p->result_rtx = original_result_rtx;
  12892.   p->base_init_expr = base_init_expr;
  12893.   p->protect_list = protect_list;
  12894.   p->temp_name_counter = temp_name_counter;
  12895.   p->base_init_list = current_base_init_list;
  12896.   p->member_init_list = current_member_init_list;
  12897.   p->class_decl = current_class_decl;
  12898.   p->C_C_D = C_C_D;
  12899. }
  12900.  
  12901. /* Restore the variables used during compilation of a C++ function.  */
  12902.  
  12903. void
  12904. pop_cp_function_context (context)
  12905.      tree context;
  12906. {
  12907.   struct cp_function *p = cp_function_chain;
  12908.   tree link;
  12909.  
  12910.   /* Bring back all the labels that were shadowed.  */
  12911.   for (link = shadowed_labels; link; link = TREE_CHAIN (link))
  12912.     if (DECL_NAME (TREE_VALUE (link)) != 0)
  12913.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
  12914.                   TREE_VALUE (link));
  12915.  
  12916. #if 0
  12917.   if (DECL_SAVED_INSNS (current_function_decl) == 0)
  12918.     {
  12919.       /* Stop pointing to the local nodes about to be freed.  */
  12920.       /* But DECL_INITIAL must remain nonzero so we know this
  12921.      was an actual function definition.  */
  12922.       DECL_INITIAL (current_function_decl) = error_mark_node;
  12923.       DECL_ARGUMENTS (current_function_decl) = 0;
  12924.     }
  12925. #endif
  12926.  
  12927.   pop_function_context_from (context);
  12928.  
  12929.   cp_function_chain = p->next;
  12930.  
  12931.   named_labels = p->named_labels;
  12932.   shadowed_labels = p->shadowed_labels;
  12933.   current_function_returns_value = p->returns_value;
  12934.   current_function_returns_null = p->returns_null;
  12935.   warn_about_return_type = p->warn_about_return_type;
  12936.   current_binding_level = p->binding_level;
  12937.   ctor_label = p->ctor_label;
  12938.   dtor_label = p->dtor_label;
  12939.   protect_list = p->protect_list;
  12940.   current_function_assigns_this = p->assigns_this;
  12941.   current_function_just_assigned_this = p->just_assigned_this;
  12942.   current_function_parms_stored = p->parms_stored;
  12943.   original_result_rtx = p->result_rtx;
  12944.   base_init_expr = p->base_init_expr;
  12945.   temp_name_counter = p->temp_name_counter;
  12946.   current_base_init_list = p->base_init_list;
  12947.   current_member_init_list = p->member_init_list;
  12948.   current_class_decl = p->class_decl;
  12949.   C_C_D = p->C_C_D;
  12950.  
  12951.   free (p);
  12952. }
  12953.  
  12954. /* FSF LOCAL dje prefix attributes */
  12955. /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
  12956.    lists.  SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
  12957.  
  12958.    The head of the declspec list is stored in DECLSPECS.
  12959.    The head of the attribute list is stored in PREFIX_ATTRIBUTES.
  12960.  
  12961.    Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
  12962.    the list elements.  We drop the containing TREE_LIST nodes and link the
  12963.    resulting attributes together the way decl_attributes expects them.  */
  12964.  
  12965. void
  12966. split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
  12967.      tree specs_attrs;
  12968.      tree *declspecs, *prefix_attributes;
  12969. {
  12970.   tree t, s, a, next, specs, attrs;
  12971.  
  12972.   /* This can happen in c++ (eg: decl: typespec initdecls ';').  */
  12973.   if (specs_attrs != NULL_TREE
  12974.       && TREE_CODE (specs_attrs) != TREE_LIST)
  12975.     {
  12976.       *declspecs = specs_attrs;
  12977.       *prefix_attributes = NULL_TREE;
  12978.       return;
  12979.     }
  12980.  
  12981.   /* Remember to keep the lists in the same order, element-wise.  */
  12982.  
  12983.   specs = s = NULL_TREE;
  12984.   attrs = a = NULL_TREE;
  12985.   for (t = specs_attrs; t; t = next)
  12986.     {
  12987.       next = TREE_CHAIN (t);
  12988.       /* Declspecs have a non-NULL TREE_VALUE.  */
  12989.       if (TREE_VALUE (t) != NULL_TREE)
  12990.     {
  12991.       if (specs == NULL_TREE)
  12992.         specs = s = t;
  12993.       else
  12994.         {
  12995.           TREE_CHAIN (s) = t;
  12996.           s = t;
  12997.         }
  12998.     }
  12999.       else
  13000.     {
  13001.       if (attrs == NULL_TREE)
  13002.         attrs = a = TREE_PURPOSE (t);
  13003.       else
  13004.         {
  13005.           TREE_CHAIN (a) = TREE_PURPOSE (t);
  13006.           a = TREE_PURPOSE (t);
  13007.         }
  13008.     }
  13009.     }
  13010.  
  13011.   /* Terminate the lists.  */
  13012.   if (s != NULL_TREE)
  13013.     TREE_CHAIN (s) = NULL_TREE;
  13014.   if (a != NULL_TREE)
  13015.     TREE_CHAIN (a) = NULL_TREE;
  13016.  
  13017.   /* All done.  */
  13018.   *declspecs = specs;
  13019.   *prefix_attributes = attrs;
  13020. }
  13021.  
  13022. /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
  13023.    This function is used by the parser when a rule will accept attributes
  13024.    in a particular position, but we don't want to support that just yet.
  13025.  
  13026.    A warning is issued for every ignored attribute.  */
  13027.  
  13028. tree
  13029. strip_attrs (specs_attrs)
  13030.      tree specs_attrs;
  13031. {
  13032.   tree specs, attrs;
  13033.  
  13034.   split_specs_attrs (specs_attrs, &specs, &attrs);
  13035.  
  13036.   while (attrs)
  13037.     {
  13038.       warning ("`%s' attribute ignored",
  13039.            IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
  13040.       attrs = TREE_CHAIN (attrs);
  13041.     }
  13042.  
  13043.   return specs;
  13044. }
  13045. /* END FSF LOCAL */
  13046.  
  13047. #ifdef NEXT_SEMANTICS
  13048.  
  13049. #ifdef OBJCPLUS
  13050. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  13051.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  13052. #endif
  13053.  
  13054. int
  13055. call_destructor_dynamically (dfndecl)
  13056.      tree dfndecl;
  13057. {
  13058.   tree parms;
  13059.   tree call;
  13060.   tree atexit_decl;
  13061.   tree atexit_type;
  13062.   tree fnct_type = build_pointer_type (default_function_type);
  13063.  
  13064.   extern tree default_function_type;
  13065.   extern tree void_type_node;
  13066.  
  13067.   atexit_type = build_function_type (void_type_node, 
  13068.                      tree_cons (0, fnct_type, 0));
  13069.   atexit_decl =(tree) builtin_function ("atexit", 
  13070.                     atexit_type,
  13071.                     NOT_BUILT_IN, 0);
  13072.   parms = (tree) build_tree_list (NULL_TREE, 
  13073.                 build1 (ADDR_EXPR, 
  13074.                     fnct_type,
  13075.                     dfndecl));
  13076.   
  13077.   call = build_function_call (atexit_decl, parms);
  13078.   expand_call (call, 0, 0);
  13079. }
  13080. #endif
  13081.