home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / obcp / decl.c < prev    next >
C/C++ Source or Header  |  1996-12-12  |  409KB  |  13,072 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. tree grokparms                PROTO((tree, int));
  130. static tree lookup_nested_type            PROTO((tree, tree));
  131. static char *redeclaration_error_message    PROTO((tree, tree));
  132. static void grok_op_properties            PROTO((tree, int, int));
  133.  
  134. tree define_function        
  135.     PROTO((char *, tree, enum built_in_function, void (*)(), char *));
  136.  
  137. /* a node which has tree code ERROR_MARK, and whose type is itself.
  138.    All erroneous expressions are replaced with this node.  All functions
  139.    that accept nodes as arguments should avoid generating error messages
  140.    if this node is one of the arguments, since it is undesirable to get
  141.    multiple error messages from one error in the input.  */
  142.  
  143. tree error_mark_node;
  144.  
  145. /* Erroneous argument lists can use this *IFF* they do not modify it.  */
  146. tree error_mark_list;
  147.  
  148. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  149.  
  150. tree short_integer_type_node;
  151. tree integer_type_node;
  152. tree long_integer_type_node;
  153. tree long_long_integer_type_node;
  154.  
  155. tree short_unsigned_type_node;
  156. tree unsigned_type_node;
  157. tree long_unsigned_type_node;
  158. tree long_long_unsigned_type_node;
  159.  
  160. tree ptrdiff_type_node;
  161.  
  162. tree unsigned_char_type_node;
  163. tree signed_char_type_node;
  164. tree char_type_node;
  165. tree wchar_type_node;
  166. tree signed_wchar_type_node;
  167. tree unsigned_wchar_type_node;
  168.  
  169. tree wchar_decl_node;
  170.  
  171. tree float_type_node;
  172. tree double_type_node;
  173. tree long_double_type_node;
  174.  
  175. tree intQI_type_node;
  176. tree intHI_type_node;
  177. tree intSI_type_node;
  178. tree intDI_type_node;
  179.  
  180. tree unsigned_intQI_type_node;
  181. tree unsigned_intHI_type_node;
  182. tree unsigned_intSI_type_node;
  183. tree unsigned_intDI_type_node;
  184.  
  185. /* a VOID_TYPE node, and the same, packaged in a TREE_LIST.  */
  186.  
  187. tree void_type_node, void_list_node;
  188. tree void_zero_node;
  189.  
  190. /* Nodes for types `void *' and `const void *'.  */
  191.  
  192. tree ptr_type_node, const_ptr_type_node;
  193.  
  194. /* Nodes for types `char *' and `const char *'.  */
  195.  
  196. tree string_type_node, const_string_type_node;
  197.  
  198. /* Type `char[256]' or something like it.
  199.    Used when an array of char is needed and the size is irrelevant.  */
  200.  
  201. tree char_array_type_node;
  202.  
  203. /* Type `int[256]' or something like it.
  204.    Used when an array of int needed and the size is irrelevant.  */
  205.  
  206. tree int_array_type_node;
  207.  
  208. /* Type `wchar_t[256]' or something like it.
  209.    Used when a wide string literal is created.  */
  210.  
  211. tree wchar_array_type_node;
  212.  
  213. /* The bool data type, and constants */
  214. tree boolean_type_node, boolean_true_node, boolean_false_node;
  215.  
  216. /* type `int ()' -- used for implicit declaration of functions.  */
  217.  
  218. tree default_function_type;
  219.  
  220. /* function types `double (double)' and `double (double, double)', etc.  */
  221.  
  222. tree double_ftype_double, double_ftype_double_double;
  223. tree int_ftype_int, long_ftype_long;
  224.  
  225. /* Function type `void (void *, void *, int)' and similar ones.  */
  226.  
  227. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  228.  
  229. /* Function type `char *(char *, char *)' and similar ones */
  230. tree string_ftype_ptr_ptr, int_ftype_string_string;
  231.  
  232. /* Function type `size_t (const char *)' */
  233. tree sizet_ftype_string;
  234.  
  235. /* Function type `int (const void *, const void *, size_t)' */
  236. tree int_ftype_cptr_cptr_sizet;
  237.  
  238. /* C++ extensions */
  239. tree vtable_entry_type;
  240. tree delta_type_node;
  241. #if 0
  242. /* Old rtti stuff. */
  243. tree __baselist_desc_type_node;
  244. tree __i_desc_type_node, __m_desc_type_node;
  245. tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type;
  246. #endif
  247. tree __t_desc_type_node, __tp_desc_type_node;
  248. tree __access_mode_type_node;
  249. tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node;
  250. tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node;
  251. tree __ptmf_desc_type_node, __ptmd_desc_type_node;
  252. #if 0
  253. /* Not needed yet?  May be needed one day?  */
  254. tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type;
  255. tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type;
  256. tree __ptmf_desc_array_type, __ptmd_desc_array_type;
  257. #endif
  258.  
  259. tree class_star_type_node;
  260. tree class_type_node, record_type_node, union_type_node, enum_type_node;
  261. tree unknown_type_node;
  262. tree opaque_type_node, signature_type_node;
  263. tree sigtable_entry_type;
  264. tree maybe_gc_cleanup;
  265.  
  266. /* Array type `vtable_entry_type[]' */
  267. tree vtbl_type_node;
  268.  
  269. /* In a destructor, the point at which all derived class destroying
  270.    has been done, just before any base class destroying will be done.  */
  271.  
  272. tree dtor_label;
  273.  
  274. /* In a constructor, the point at which we are ready to return
  275.    the pointer to the initialized object.  */
  276.  
  277. tree ctor_label;
  278.  
  279. /* A FUNCTION_DECL which can call `abort'.  Not necessarily the
  280.    one that the user will declare, but sufficient to be called
  281.    by routines that want to abort the program.  */
  282.  
  283. tree abort_fndecl;
  284.  
  285. extern rtx cleanup_label, return_label;
  286.  
  287. /* If original DECL_RESULT of current function was a register,
  288.    but due to being an addressable named return value, would up
  289.    on the stack, this variable holds the named return value's
  290.    original location.  */
  291. rtx original_result_rtx;
  292.  
  293. /* Sequence of insns which represents base initialization.  */
  294. tree base_init_expr;
  295.  
  296. /* C++: Keep these around to reduce calls to `get_identifier'.
  297.    Identifiers for `this' in member functions and the auto-delete
  298.    parameter for destructors.  */
  299. tree this_identifier, in_charge_identifier;
  300. /* Used in pointer to member functions, in vtables, and in sigtables. */
  301. tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier;
  302. tree pfn_or_delta2_identifier, tag_identifier;
  303. tree vb_off_identifier, vt_off_identifier;
  304.  
  305. /* A list (chain of TREE_LIST nodes) of named label uses.
  306.    The TREE_PURPOSE field is the list of variables defined
  307.    the the label's scope defined at the point of use.
  308.    The TREE_VALUE field is the LABEL_DECL used.
  309.    The TREE_TYPE field holds `current_binding_level' at the
  310.    point of the label's use.
  311.  
  312.    Used only for jumps to as-yet undefined labels, since
  313.    jumps to defined labels can have their validity checked
  314.    by stmt.c.  */
  315.  
  316. static tree named_label_uses;
  317.  
  318. /* A list of objects which have constructors or destructors
  319.    which reside in the global scope.  The decl is stored in
  320.    the TREE_VALUE slot and the initializer is stored
  321.    in the TREE_PURPOSE slot.  */
  322. tree static_aggregates;
  323.  
  324. /* -- end of C++ */
  325.  
  326. /* Two expressions that are constants with value zero.
  327.    The first is of type `int', the second of type `void *'.  */
  328.  
  329. tree integer_zero_node;
  330. tree null_pointer_node;
  331.  
  332. /* A node for the integer constants 1, 2, and 3.  */
  333.  
  334. tree integer_one_node, integer_two_node, integer_three_node;
  335.  
  336. /* Nonzero if we have seen an invalid cross reference
  337.    to a struct, union, or enum, but not yet printed the message.  */
  338.  
  339. tree pending_invalid_xref;
  340. /* File and line to appear in the eventual error message.  */
  341. char *pending_invalid_xref_file;
  342. int pending_invalid_xref_line;
  343.  
  344. /* While defining an enum type, this is 1 plus the last enumerator
  345.    constant value.  */
  346.  
  347. static tree enum_next_value;
  348.  
  349. /* Nonzero means that there was overflow computing enum_next_value.  */
  350.  
  351. static int enum_overflow;
  352.  
  353. /* Parsing a function declarator leaves a list of parameter names
  354.    or a chain or parameter decls here.  */
  355.  
  356. tree last_function_parms;
  357.  
  358. /* Parsing a function declarator leaves here a chain of structure
  359.    and enum types declared in the parmlist.  */
  360.  
  361. static tree last_function_parm_tags;
  362.  
  363. /* After parsing the declarator that starts a function definition,
  364.    `start_function' puts here the list of parameter names or chain of decls.
  365.    `store_parm_decls' finds it here.  */
  366.  
  367. static tree current_function_parms;
  368.  
  369. /* Similar, for last_function_parm_tags.  */
  370. static tree current_function_parm_tags;
  371.  
  372. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  373.    that have names.  Here so we can clear out their names' definitions
  374.    at the end of the function.  */
  375.  
  376. static tree named_labels;
  377.  
  378. /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
  379.  
  380. static tree shadowed_labels;
  381.  
  382. #if 0 /* Not needed by C++ */
  383. /* Nonzero when store_parm_decls is called indicates a varargs function.
  384.    Value not meaningful after store_parm_decls.  */
  385.  
  386. static int c_function_varargs;
  387. #endif
  388.  
  389. /* The FUNCTION_DECL for the function currently being compiled,
  390.    or 0 if between functions.  */
  391. tree current_function_decl;
  392.  
  393. /* Set to 0 at beginning of a function definition, set to 1 if
  394.    a return statement that specifies a return value is seen.  */
  395.  
  396. int current_function_returns_value;
  397.  
  398. /* Set to 0 at beginning of a function definition, set to 1 if
  399.    a return statement with no argument is seen.  */
  400.  
  401. int current_function_returns_null;
  402.  
  403. /* Set to 0 at beginning of a function definition, and whenever
  404.    a label (case or named) is defined.  Set to value of expression
  405.    returned from function when that value can be transformed into
  406.    a named return value.  */
  407.  
  408. tree current_function_return_value;
  409.  
  410. /* Set to nonzero by `grokdeclarator' for a function
  411.    whose return type is defaulted, if warnings for this are desired.  */
  412.  
  413. static int warn_about_return_type;
  414.  
  415. /* Nonzero means give `double' the same size as `float'.  */
  416.  
  417. extern int flag_short_double;
  418.  
  419. /* Nonzero means don't recognize any builtin functions.  */
  420.  
  421. extern int flag_no_builtin;
  422.  
  423. /* Nonzero means don't recognize the non-ANSI builtin functions.
  424.    -ansi sets this.  */
  425.  
  426. extern int flag_no_nonansi_builtin;
  427.  
  428. /* Nonzero means enable obscure ANSI features and disable GNU extensions
  429.    that might cause ANSI-compliant code to be miscompiled.  */
  430.  
  431. extern int flag_ansi;
  432.  
  433. /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes)
  434.    objects. */
  435. extern int flag_huge_objects;
  436.  
  437. /* Nonzero if we want to conserve space in the .o files.  We do this
  438.    by putting uninitialized data and runtime initialized data into
  439.    .common instead of .data at the expense of not flagging multiple
  440.    definitions.  */
  441. extern int flag_conserve_space;
  442.  
  443. /* Pointers to the base and current top of the language name stack.  */
  444.  
  445. extern tree *current_lang_base, *current_lang_stack;
  446.  
  447. /* C and C++ flags are in decl2.c.  */
  448.  
  449. /* Set to 0 at beginning of a constructor, set to 1
  450.    if that function does an allocation before referencing its
  451.    instance variable.  */
  452. int current_function_assigns_this;
  453. int current_function_just_assigned_this;
  454.  
  455. /* Set to 0 at beginning of a function.  Set non-zero when
  456.    store_parm_decls is called.  Don't call store_parm_decls
  457.    if this flag is non-zero!  */
  458. int current_function_parms_stored;
  459.  
  460. /* Current end of entries in the gc obstack for stack pointer variables.  */
  461.  
  462. int current_function_obstack_index;
  463.  
  464. /* Flag saying whether we have used the obstack in this function or not.  */
  465.  
  466. int current_function_obstack_usage;
  467.  
  468. /* Flag used when debugging spew.c */
  469.  
  470. extern int spew_debug;
  471.  
  472. /* This is a copy of the class_shadowed list of the previous class binding
  473.    contour when at global scope.  It's used to reset IDENTIFIER_CLASS_VALUEs
  474.    when entering another class scope (i.e. a cache miss).  */
  475. extern tree previous_class_values;
  476.  
  477.  
  478. /* Allocate a level of searching.  */
  479. struct stack_level *
  480. push_decl_level (stack, obstack)
  481.      struct stack_level *stack;
  482.      struct obstack *obstack;
  483. {
  484.   struct stack_level tem;
  485.   tem.prev = stack;
  486.  
  487.   return push_stack_level (obstack, (char *)&tem, sizeof (tem));
  488. }
  489.  
  490. /* For each binding contour we allocate a binding_level structure
  491.  * which records the names defined in that contour.
  492.  * Contours include:
  493.  *  0) the global one
  494.  *  1) one for each function definition,
  495.  *     where internal declarations of the parameters appear.
  496.  *  2) one for each compound statement,
  497.  *     to record its declarations.
  498.  *
  499.  * The current meaning of a name can be found by searching the levels from
  500.  * the current one out to the global one.
  501.  *
  502.  * Off to the side, may be the class_binding_level.  This exists
  503.  * only to catch class-local declarations.  It is otherwise
  504.  * nonexistent.
  505.  * 
  506.  * Also there may be binding levels that catch cleanups that
  507.  * must be run when exceptions occur.
  508.  */
  509.  
  510. /* Note that the information in the `names' component of the global contour
  511.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  512.  
  513. struct binding_level
  514.   {
  515.     /* A chain of _DECL nodes for all variables, constants, functions,
  516.      * and typedef types.  These are in the reverse of the order supplied.
  517.      */
  518.     tree names;
  519.  
  520.     /* A list of structure, union and enum definitions,
  521.      * for looking up tag names.
  522.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  523.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  524.      * or ENUMERAL_TYPE node.
  525.      *
  526.      * C++: the TREE_VALUE nodes can be simple types for component_bindings.
  527.      *
  528.      */
  529.     tree tags;
  530.  
  531.     /* For each level, a list of shadowed outer-level local definitions
  532.        to be restored when this level is popped.
  533.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  534.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  535.     tree shadowed;
  536.  
  537.     /* Same, for IDENTIFIER_CLASS_VALUE.  */
  538.     tree class_shadowed;
  539.  
  540.     /* Same, for IDENTIFIER_TYPE_VALUE.  */
  541.     tree type_shadowed;
  542.  
  543.     /* For each level (except not the global one),
  544.        a chain of BLOCK nodes for all the levels
  545.        that were entered and exited one level down.  */
  546.     tree blocks;
  547.  
  548.     /* The BLOCK node for this level, if one has been preallocated.
  549.        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
  550.     tree this_block;
  551.  
  552.     /* The binding level which this one is contained in (inherits from).  */
  553.     struct binding_level *level_chain;
  554.  
  555.     /* List of decls in `names' that have incomplete
  556.        structure or union types.  */
  557.     tree incomplete;
  558.  
  559.     /* List of VAR_DECLS saved from a previous for statement.
  560.        These would be dead in ANSI-conforming code, but might
  561.        be referenced in traditional code. */
  562.     tree dead_vars_from_for;
  563.  
  564.     /* 1 for the level that holds the parameters of a function.
  565.        2 for the level that holds a class declaration.
  566.        3 for levels that hold parameter declarations.  */
  567.     unsigned parm_flag : 4;
  568.  
  569.     /* 1 means make a BLOCK for this level regardless of all else.
  570.        2 for temporary binding contours created by the compiler.  */
  571.     unsigned keep : 3;
  572.  
  573.     /* Nonzero if this level "doesn't exist" for tags.  */
  574.     unsigned tag_transparent : 1;
  575.  
  576.     /* Nonzero if this level can safely have additional
  577.        cleanup-needing variables added to it.  */
  578.     unsigned more_cleanups_ok : 1;
  579.     unsigned have_cleanups : 1;
  580.  
  581.     /* Nonzero if we should accept any name as an identifier in
  582.        this scope.  This happens in some template definitions.  */
  583.     unsigned accept_any : 1;
  584.  
  585.     /* Nonzero if this level is for completing a template class definition
  586.        inside a binding level that temporarily binds the parameters.  This
  587.        means that definitions here should not be popped off when unwinding
  588.        this binding level.  (Not actually implemented this way,
  589.        unfortunately.)  */
  590.     unsigned pseudo_global : 1;
  591.  
  592.     /* This is set for a namespace binding level.  */
  593.     unsigned namespace_p : 1;
  594.  
  595.     /* True if this level is that of a for-statement. */
  596.     unsigned is_for_scope : 1;
  597.  
  598.     /* One bit left for this word.  */
  599.  
  600. #if defined(DEBUG_CP_BINDING_LEVELS)
  601.     /* Binding depth at which this level began.  */
  602.     unsigned binding_depth;
  603. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  604.   };
  605.  
  606. #define NULL_BINDING_LEVEL ((struct binding_level *) NULL)
  607.   
  608. /* The (non-class) binding level currently in effect.  */
  609.  
  610. static struct binding_level *current_binding_level;
  611.  
  612. /* The binding level of the current class, if any.  */
  613.  
  614. static struct binding_level *class_binding_level;
  615.  
  616. /* The current (class or non-class) binding level currently in effect.  */
  617.  
  618. #define inner_binding_level \
  619.   (class_binding_level ? class_binding_level : current_binding_level)
  620.  
  621. /* A chain of binding_level structures awaiting reuse.  */
  622.  
  623. static struct binding_level *free_binding_level;
  624.  
  625. /* The outermost binding level, for names of file scope.
  626.    This is created when the compiler is started and exists
  627.    through the entire run.  */
  628.  
  629. static struct binding_level *global_binding_level;
  630.  
  631. /* Binding level structures are initialized by copying this one.  */
  632.  
  633. static struct binding_level clear_binding_level;
  634.  
  635. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  636.  
  637. static int keep_next_level_flag;
  638.  
  639. #if defined(DEBUG_CP_BINDING_LEVELS)
  640. static int binding_depth = 0;
  641. static int is_class_level = 0;
  642.  
  643. static void
  644. indent ()
  645. {
  646.   register unsigned i;
  647.  
  648.   for (i = 0; i < binding_depth*2; i++)
  649.     putc (' ', stderr);
  650. }
  651. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  652.  
  653. static tree pushdecl_with_scope    PROTO((tree, struct binding_level *));
  654.  
  655. static void
  656. push_binding_level (newlevel, tag_transparent, keep)
  657.      struct binding_level *newlevel;
  658.      int tag_transparent, keep;
  659. {
  660.   /* Add this level to the front of the chain (stack) of levels that
  661.      are active.  */
  662.   *newlevel = clear_binding_level;
  663.   if (class_binding_level)
  664.     {
  665.       newlevel->level_chain = class_binding_level;
  666.       class_binding_level = (struct binding_level *)0;
  667.     }
  668.   else
  669.     {
  670.       newlevel->level_chain = current_binding_level;
  671.     }
  672.   current_binding_level = newlevel;
  673.   newlevel->tag_transparent = tag_transparent;
  674.   newlevel->more_cleanups_ok = 1;
  675.   newlevel->keep = keep;
  676. #if defined(DEBUG_CP_BINDING_LEVELS)
  677.   newlevel->binding_depth = binding_depth;
  678.   indent ();
  679.   fprintf (stderr, "push %s level 0x%08x line %d\n",
  680.        (is_class_level) ? "class" : "block", newlevel, lineno);
  681.   is_class_level = 0;
  682.   binding_depth++;
  683. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  684. }
  685.  
  686. static void
  687. pop_binding_level ()
  688. {
  689.   if (class_binding_level)
  690.     current_binding_level = class_binding_level;
  691.  
  692.   if (global_binding_level)
  693.     {
  694.       /* cannot pop a level, if there are none left to pop. */
  695.       if (current_binding_level == global_binding_level)
  696.     my_friendly_abort (123);
  697.     }
  698.   /* Pop the current level, and free the structure for reuse.  */
  699. #if defined(DEBUG_CP_BINDING_LEVELS)
  700.   binding_depth--;
  701.   indent ();
  702.   fprintf (stderr, "pop  %s level 0x%08x line %d\n",
  703.       (is_class_level) ? "class" : "block",
  704.       current_binding_level, lineno);
  705.   if (is_class_level != (current_binding_level == class_binding_level))
  706. #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
  707.     abort ();
  708. #else
  709.   {
  710.     indent ();
  711.     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
  712.   }
  713. #endif
  714.   is_class_level = 0;
  715. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  716.   {
  717.     register struct binding_level *level = current_binding_level;
  718.     current_binding_level = current_binding_level->level_chain;
  719.     level->level_chain = free_binding_level;
  720. #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
  721.     if (level->binding_depth != binding_depth)
  722.       abort ();
  723. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  724.       free_binding_level = level;
  725.  
  726.     class_binding_level = current_binding_level;
  727.     if (class_binding_level->parm_flag != 2)
  728.       class_binding_level = 0;
  729.     while (current_binding_level->parm_flag == 2)
  730.       current_binding_level = current_binding_level->level_chain;
  731.   }
  732. }
  733.  
  734. static void
  735. suspend_binding_level ()
  736. {
  737.   if (class_binding_level)
  738.     current_binding_level = class_binding_level;
  739.  
  740.   if (global_binding_level)
  741.     {
  742.       /* cannot suspend a level, if there are none left to suspend. */
  743.       if (current_binding_level == global_binding_level)
  744.     my_friendly_abort (123);
  745.     }
  746.   /* Suspend the current level.  */
  747. #if defined(DEBUG_CP_BINDING_LEVELS)
  748.   binding_depth--;
  749.   indent ();
  750.   fprintf (stderr, "suspend  %s level 0x%08x line %d\n",
  751.       (is_class_level) ? "class" : "block",
  752.       current_binding_level, lineno);
  753.   if (is_class_level != (current_binding_level == class_binding_level))
  754. #if 0 /* XXX Don't abort when we're watching how things are being managed.  */
  755.     abort ();
  756. #else
  757.   {
  758.     indent ();
  759.     fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n");
  760.   }
  761. #endif
  762.   is_class_level = 0;
  763. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  764.   {
  765.     register struct binding_level *level = current_binding_level;
  766.     current_binding_level = current_binding_level->level_chain;
  767. #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */
  768.     if (level->binding_depth != binding_depth)
  769.       abort ();
  770. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  771.  
  772.     class_binding_level = current_binding_level;
  773.     if (class_binding_level->parm_flag != 2)
  774.       class_binding_level = 0;
  775.     while (current_binding_level->parm_flag == 2)
  776.       current_binding_level = current_binding_level->level_chain;
  777.   }
  778. }
  779.  
  780. void
  781. resume_binding_level (b)
  782.      struct binding_level *b;
  783. {
  784.   if (class_binding_level)
  785.     {
  786. #if 1
  787.       /* These are here because we cannot deal with shadows yet. */
  788.       sorry ("cannot resume a namespace inside class");
  789.       return;
  790. #else
  791.       b->level_chain = class_binding_level;
  792.       class_binding_level = (struct binding_level *)0;
  793. #endif
  794.     }
  795.   else
  796.     {
  797. #if 1
  798.       /* These are here because we cannot deal with shadows yet. */
  799.       if (b->level_chain != current_binding_level)
  800.     {
  801.       sorry ("cannot resume a namespace inside a different namespace");
  802.       return;
  803.     }
  804. #endif
  805.       b->level_chain = current_binding_level;
  806.     }
  807.   current_binding_level = b;
  808. #if defined(DEBUG_CP_BINDING_LEVELS)
  809.   b->binding_depth = binding_depth;
  810.   indent ();
  811.   fprintf (stderr, "resume %s level 0x%08x line %d\n",
  812.        (is_class_level) ? "class" : "block", b, lineno);
  813.   is_class_level = 0;
  814.   binding_depth++;
  815. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  816. }
  817.  
  818. /* Nonzero if we are currently in the global binding level.  */
  819.  
  820. int
  821. global_bindings_p ()
  822. {
  823.   return current_binding_level == global_binding_level;
  824. }
  825.  
  826. /* Nonzero if we are currently in a toplevel binding level.  This
  827.    means either the global binding level or a namespace in a toplevel
  828.    binding level.  */
  829.  
  830. int
  831. toplevel_bindings_p ()
  832. {
  833.   struct binding_level *b = current_binding_level;
  834.  
  835.   while (1)
  836.     {
  837.       if (b == global_binding_level)
  838.     return 1;
  839.       if (! b->namespace_p)
  840.     return 0;
  841.       b=b->level_chain;
  842.     }
  843. }
  844.  
  845. /* Nonzero if this is a namespace scope.  */
  846.  
  847. int
  848. namespace_bindings_p ()
  849. {
  850.   return current_binding_level->namespace_p;
  851. }
  852.  
  853. void
  854. keep_next_level ()
  855. {
  856.   keep_next_level_flag = 1;
  857. }
  858.  
  859. /* Nonzero if the current level needs to have a BLOCK made.  */
  860.  
  861. int
  862. kept_level_p ()
  863. {
  864.   return (current_binding_level->blocks != NULL_TREE
  865.       || current_binding_level->keep
  866.       || current_binding_level->names != NULL_TREE
  867.       || (current_binding_level->tags != NULL_TREE
  868.           && !current_binding_level->tag_transparent));
  869. }
  870.  
  871. /* Identify this binding level as a level of parameters.  */
  872.  
  873. void
  874. declare_parm_level ()
  875. {
  876.   current_binding_level->parm_flag = 1;
  877. }
  878.  
  879. void
  880. declare_uninstantiated_type_level ()
  881. {
  882.   current_binding_level->accept_any = 1;
  883. }
  884.  
  885. int
  886. uninstantiated_type_level_p ()
  887. {
  888.   return current_binding_level->accept_any;
  889. }
  890.  
  891. void
  892. declare_pseudo_global_level ()
  893. {
  894.   current_binding_level->pseudo_global = 1;
  895. }
  896.  
  897. void
  898. declare_namespace_level ()
  899. {
  900.   current_binding_level->namespace_p = 1;
  901. }
  902.  
  903. int
  904. pseudo_global_level_p ()
  905. {
  906.   return current_binding_level->pseudo_global;
  907. }
  908.  
  909. void
  910. set_class_shadows (shadows)
  911.      tree shadows;
  912. {
  913.   class_binding_level->class_shadowed = shadows;
  914. }
  915.  
  916. /* Enter a new binding level.
  917.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  918.    not for that of tags.  */
  919.  
  920. void
  921. pushlevel (tag_transparent)
  922.      int tag_transparent;
  923. {
  924.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  925.  
  926.   /* If this is the top level of a function,
  927.      just make sure that NAMED_LABELS is 0.
  928.      They should have been set to 0 at the end of the previous function.  */
  929.  
  930.   if (current_binding_level == global_binding_level)
  931.     my_friendly_assert (named_labels == NULL_TREE, 134);
  932.  
  933.   /* Reuse or create a struct for this binding level.  */
  934.  
  935. #if defined(DEBUG_CP_BINDING_LEVELS)
  936.   if (0)
  937. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  938.   if (free_binding_level)
  939. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  940.     {
  941.       newlevel = free_binding_level;
  942.       free_binding_level = free_binding_level->level_chain;
  943.     }
  944.   else
  945.     {
  946.       /* Create a new `struct binding_level'.  */
  947.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  948.     }
  949.   push_binding_level (newlevel, tag_transparent, keep_next_level_flag);
  950.   GNU_xref_start_scope ((HOST_WIDE_INT) newlevel);
  951.   keep_next_level_flag = 0;
  952. }
  953.  
  954. int
  955. note_level_for_for ()
  956. {
  957.   current_binding_level->is_for_scope = 1;
  958. }
  959.  
  960. void
  961. pushlevel_temporary (tag_transparent)
  962.      int tag_transparent;
  963. {
  964.   pushlevel (tag_transparent);
  965.   current_binding_level->keep = 2;
  966.   clear_last_expr ();
  967.  
  968.   /* Note we don't call push_momentary() here.  Otherwise, it would cause
  969.      cleanups to be allocated on the momentary obstack, and they will be
  970.      overwritten by the next statement.  */
  971.  
  972.   expand_start_bindings (0);
  973. }
  974.  
  975. /* Exit a binding level.
  976.    Pop the level off, and restore the state of the identifier-decl mappings
  977.    that were in effect when this level was entered.
  978.  
  979.    If KEEP == 1, this level had explicit declarations, so
  980.    and create a "block" (a BLOCK node) for the level
  981.    to record its declarations and subblocks for symbol table output.
  982.  
  983.    If KEEP == 2, this level's subblocks go to the front,
  984.    not the back of the current binding level.  This happens,
  985.    for instance, when code for constructors and destructors
  986.    need to generate code at the end of a function which must
  987.    be moved up to the front of the function.
  988.  
  989.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  990.    so create a block as if KEEP were set and also clear out all
  991.    label names.
  992.  
  993.    If REVERSE is nonzero, reverse the order of decls before putting
  994.    them into the BLOCK.  */
  995.  
  996. tree
  997. poplevel (keep, reverse, functionbody)
  998.      int keep;
  999.      int reverse;
  1000.      int functionbody;
  1001. {
  1002.   register tree link;
  1003.   /* The chain of decls was accumulated in reverse order.
  1004.      Put it into forward order, just for cleanliness.  */
  1005.   tree decls;
  1006.   int tmp = functionbody;
  1007.   int implicit_try_block = current_binding_level->parm_flag == 3;
  1008.   int real_functionbody = current_binding_level->keep == 2
  1009.     ? ((functionbody = 0), tmp) : functionbody;
  1010.   tree tags = functionbody >= 0 ? current_binding_level->tags : 0;
  1011.   tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
  1012.   tree block = NULL_TREE;
  1013.   tree decl;
  1014.   int block_previously_created;
  1015.  
  1016.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  1017.               (HOST_WIDE_INT) current_binding_level->level_chain,
  1018.               current_binding_level->parm_flag,
  1019.               current_binding_level->keep,
  1020.               current_binding_level->tag_transparent);
  1021.  
  1022.   if (current_binding_level->keep == 1)
  1023.     keep = 1;
  1024.  
  1025.   /* This warning is turned off because it causes warnings for
  1026.      declarations like `extern struct foo *x'.  */
  1027. #if 0
  1028.   /* Warn about incomplete structure types in this level.  */
  1029.   for (link = tags; link; link = TREE_CHAIN (link))
  1030.     if (TYPE_SIZE (TREE_VALUE (link)) == NULL_TREE)
  1031.       {
  1032.     tree type = TREE_VALUE (link);
  1033.     char *errmsg;
  1034.     switch (TREE_CODE (type))
  1035.       {
  1036.       case RECORD_TYPE:
  1037.         errmsg = "`struct %s' incomplete in scope ending here";
  1038.         break;
  1039.       case UNION_TYPE:
  1040.         errmsg = "`union %s' incomplete in scope ending here";
  1041.         break;
  1042.       case ENUMERAL_TYPE:
  1043.         errmsg = "`enum %s' incomplete in scope ending here";
  1044.         break;
  1045.       }
  1046.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  1047.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  1048.     else
  1049.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  1050.       error (errmsg, TYPE_NAME_STRING (type));
  1051.       }
  1052. #endif /* 0 */
  1053.  
  1054.   /* Get the decls in the order they were written.
  1055.      Usually current_binding_level->names is in reverse order.
  1056.      But parameter decls were previously put in forward order.  */
  1057.  
  1058.   if (reverse)
  1059.     current_binding_level->names
  1060.       = decls = nreverse (current_binding_level->names);
  1061.   else
  1062.     decls = current_binding_level->names;
  1063.  
  1064.   /* Output any nested inline functions within this block
  1065.      if they weren't already output.  */
  1066.  
  1067.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  1068.     if (TREE_CODE (decl) == FUNCTION_DECL
  1069.     && ! TREE_ASM_WRITTEN (decl)
  1070.     && DECL_INITIAL (decl) != NULL_TREE
  1071.     && TREE_ADDRESSABLE (decl)
  1072.     && decl_function_context (decl) == current_function_decl)
  1073.       {
  1074.     /* If this decl was copied from a file-scope decl
  1075.        on account of a block-scope extern decl,
  1076.        propagate TREE_ADDRESSABLE to the file-scope decl.  */
  1077.     if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
  1078.       TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
  1079.     else
  1080.       {
  1081.         push_function_context ();
  1082.         output_inline_function (decl);
  1083.         pop_function_context ();
  1084.       }
  1085.       }
  1086.  
  1087.   /* If there were any declarations or structure tags in that level,
  1088.      or if this level is a function body,
  1089.      create a BLOCK to record them for the life of this function.  */
  1090.  
  1091.   block = NULL_TREE;
  1092.   block_previously_created = (current_binding_level->this_block != NULL_TREE);
  1093.   if (block_previously_created)
  1094.     block = current_binding_level->this_block;
  1095.   else if (keep == 1 || functionbody)
  1096.     block = make_node (BLOCK);
  1097.   if (block != NULL_TREE)
  1098.     {
  1099.       BLOCK_VARS (block) = decls;
  1100.       BLOCK_TYPE_TAGS (block) = tags;
  1101.       BLOCK_SUBBLOCKS (block) = subblocks;
  1102.       /* If we created the block earlier on, and we are just diddling it now,
  1103.      then it already should have a proper BLOCK_END_NOTE value associated
  1104.      with it, so avoid trashing that.  Otherwise, for a new block, install
  1105.      a new BLOCK_END_NOTE value.  */
  1106.       if (! block_previously_created)
  1107.     remember_end_note (block);
  1108.     }
  1109.  
  1110.   /* In each subblock, record that this is its superior.  */
  1111.  
  1112.   if (keep >= 0)
  1113.     for (link = subblocks; link; link = TREE_CHAIN (link))
  1114.       BLOCK_SUPERCONTEXT (link) = block;
  1115.  
  1116.   /* Clear out the meanings of the local variables of this level.  */
  1117.  
  1118.   for (link = current_binding_level->dead_vars_from_for;
  1119.        link != NULL_TREE; link = TREE_CHAIN (link))
  1120.     {
  1121.       if (DECL_DEAD_FOR_LOCAL (link))
  1122.     {
  1123.       tree id = DECL_NAME (link);
  1124.       if (IDENTIFIER_LOCAL_VALUE (id) == link)
  1125.         IDENTIFIER_LOCAL_VALUE (id) = DECL_SHADOWED_FOR_VAR (link);
  1126.     }
  1127.     }
  1128.  
  1129.   if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
  1130.     {
  1131.       for (link = decls; link; link = TREE_CHAIN (link))
  1132.     {
  1133.       if (TREE_CODE (link) == VAR_DECL)
  1134.         DECL_DEAD_FOR_LOCAL (link) = 1;
  1135.     }
  1136.     }
  1137.   else
  1138.     {
  1139.       for (link = decls; link; link = TREE_CHAIN (link))
  1140.     {
  1141.       if (DECL_NAME (link) != NULL_TREE)
  1142.         {
  1143.           /* If the ident. was used or addressed via a local extern decl,
  1144.          don't forget that fact.  */
  1145.           if (DECL_EXTERNAL (link))
  1146.         {
  1147.           if (TREE_USED (link))
  1148.             TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  1149.           if (TREE_ADDRESSABLE (link))
  1150.             TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  1151.         }
  1152.           IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
  1153.         }
  1154.     }
  1155.     }
  1156.  
  1157.   /* Restore all name-meanings of the outer levels
  1158.      that were shadowed by this level.  */
  1159.  
  1160.   if (current_binding_level->is_for_scope && flag_new_for_scope == 1)
  1161.     {
  1162.       struct binding_level *outer = current_binding_level->level_chain;
  1163.       for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1164.     {
  1165.       tree id = TREE_PURPOSE (link);
  1166.       tree decl = IDENTIFIER_LOCAL_VALUE (id);
  1167.       if (DECL_DEAD_FOR_LOCAL (decl))
  1168.         DECL_SHADOWED_FOR_VAR (decl) = TREE_VALUE (link);
  1169.       else
  1170.         IDENTIFIER_LOCAL_VALUE (id) = TREE_VALUE (link);
  1171.     }
  1172.  
  1173.       /* Save declarations made in a 'for' statement so we can support pre-ANSI
  1174.      'for' scoping semantics. */
  1175.  
  1176.       /* We append the current names of for-variables to those from previous
  1177.      declarations, so that when we get around to do an poplevel
  1178.      on the OUTER level, we restore the any shadowed readl bindings.
  1179.      Note that the new names are put first on the combined list,
  1180.      so they get to be restored first.  This is important if there are
  1181.      two for-loops using the same for-variable in the same block.
  1182.      The binding we really want restored is whatever binding was shadowed
  1183.      by the *first* for-variable, not the binding shadowed by the
  1184.      second for-variable (which would be the first for-variable). */
  1185.       outer->dead_vars_from_for
  1186.     = chainon (current_binding_level->names, outer->dead_vars_from_for);
  1187.     }
  1188.   else
  1189.     {
  1190.       for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1191.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1192.     }
  1193.   for (link = current_binding_level->class_shadowed;
  1194.        link; link = TREE_CHAIN (link))
  1195.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1196.   for (link = current_binding_level->type_shadowed;
  1197.        link; link = TREE_CHAIN (link))
  1198.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1199.  
  1200.   /* If the level being exited is the top level of a function,
  1201.      check over all the labels.  */
  1202.  
  1203.   if (functionbody)
  1204.     {
  1205.       /* If this is the top level block of a function,
  1206.          the vars are the function's parameters.
  1207.          Don't leave them in the BLOCK because they are
  1208.          found in the FUNCTION_DECL instead.  */
  1209.  
  1210.       BLOCK_VARS (block) = 0;
  1211.  
  1212.       /* Clear out the definitions of all label names,
  1213.      since their scopes end here.  */
  1214.  
  1215.       for (link = named_labels; link; link = TREE_CHAIN (link))
  1216.     {
  1217.       register tree label = TREE_VALUE (link);
  1218.  
  1219.       if (DECL_INITIAL (label) == NULL_TREE)
  1220.         {
  1221.           cp_error_at ("label `%D' used but not defined", label);
  1222.           /* Avoid crashing later.  */
  1223.           define_label (input_filename, 1, DECL_NAME (label));
  1224.         }
  1225.       else if (warn_unused && !TREE_USED (label))
  1226.         cp_warning_at ("label `%D' defined but not used", label);
  1227.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE);
  1228.  
  1229.           /* Put the labels into the "variables" of the
  1230.              top-level block, so debugger can see them.  */
  1231.           TREE_CHAIN (label) = BLOCK_VARS (block);
  1232.           BLOCK_VARS (block) = label;
  1233.     }
  1234.  
  1235.       named_labels = NULL_TREE;
  1236.     }
  1237.  
  1238.   /* Any uses of undefined labels now operate under constraints
  1239.      of next binding contour.  */
  1240.   {
  1241.     struct binding_level *level_chain;
  1242.     level_chain = current_binding_level->level_chain;
  1243.     if (level_chain)
  1244.       {
  1245.     tree labels;
  1246.     for (labels = named_label_uses; labels; labels = TREE_CHAIN (labels))
  1247.       if (TREE_TYPE (labels) == (tree)current_binding_level)
  1248.         {
  1249.           TREE_TYPE (labels) = (tree)level_chain;
  1250.           TREE_PURPOSE (labels) = level_chain->names;
  1251.         }
  1252.       }
  1253.   }
  1254.  
  1255.   tmp = current_binding_level->keep;
  1256.  
  1257.   pop_binding_level ();
  1258.   if (functionbody)
  1259.     DECL_INITIAL (current_function_decl) = block;
  1260.   else if (block)
  1261.     {
  1262.       if (!block_previously_created)
  1263.         current_binding_level->blocks
  1264.           = chainon (current_binding_level->blocks, block);
  1265.     }
  1266.   /* If we did not make a block for the level just exited,
  1267.      any blocks made for inner levels
  1268.      (since they cannot be recorded as subblocks in that level)
  1269.      must be carried forward so they will later become subblocks
  1270.      of something else.  */
  1271.   else if (subblocks)
  1272.     {
  1273.       if (keep == 2)
  1274.     current_binding_level->blocks
  1275.       = chainon (subblocks, current_binding_level->blocks);
  1276.       else
  1277.     current_binding_level->blocks
  1278.       = chainon (current_binding_level->blocks, subblocks);
  1279.     }
  1280.  
  1281.   /* Take care of compiler's internal binding structures.  */
  1282.   if (tmp == 2)
  1283.     {
  1284. #if 0
  1285.       /* We did not call push_momentary for this
  1286.      binding contour, so there is nothing to pop.  */
  1287.       pop_momentary ();
  1288. #endif
  1289.       expand_end_bindings (getdecls (), keep, 1);
  1290.       /* Each and every BLOCK node created here in `poplevel' is important
  1291.      (e.g. for proper debugging information) so if we created one
  1292.      earlier, mark it as "used".  */
  1293.       if (block)
  1294.     TREE_USED (block) = 1;
  1295.       block = poplevel (keep, reverse, real_functionbody);
  1296.     }
  1297.  
  1298.   /* Each and every BLOCK node created here in `poplevel' is important
  1299.      (e.g. for proper debugging information) so if we created one
  1300.      earlier, mark it as "used".  */
  1301.   if (block)
  1302.     TREE_USED (block) = 1;
  1303.   return block;
  1304. }
  1305.  
  1306. /* Resume a binding level for a namespace.  */
  1307. void
  1308. resume_level (b)
  1309.      struct binding_level *b;
  1310. {
  1311.   tree decls, link;
  1312.  
  1313.   resume_binding_level (b);
  1314.  
  1315.   /* Resume the variable caches.  */
  1316.   decls = current_binding_level->names;
  1317.  
  1318.   /* Restore the meanings of the local variables of this level.  */
  1319.  
  1320.   for (link = decls; link; link = TREE_CHAIN (link))
  1321.     {
  1322.       if (DECL_NAME (link) != NULL_TREE)
  1323.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = link;
  1324.  
  1325.       /* If this is a TYPE_DECL, push it into the type value slot.  */
  1326.       if (TREE_CODE (link) == TYPE_DECL)
  1327.     SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (link), TREE_TYPE (link));
  1328.     }
  1329. }
  1330.  
  1331. /* Delete the node BLOCK from the current binding level.
  1332.    This is used for the block inside a stmt expr ({...})
  1333.    so that the block can be reinserted where appropriate.  */
  1334.  
  1335. void
  1336. delete_block (block)
  1337.      tree block;
  1338. {
  1339.   tree t;
  1340.   if (current_binding_level->blocks == block)
  1341.     current_binding_level->blocks = TREE_CHAIN (block);
  1342.   for (t = current_binding_level->blocks; t;)
  1343.     {
  1344.       if (TREE_CHAIN (t) == block)
  1345.     TREE_CHAIN (t) = TREE_CHAIN (block);
  1346.       else
  1347.     t = TREE_CHAIN (t);
  1348.     }
  1349.   TREE_CHAIN (block) = NULL_TREE;
  1350.   /* Clear TREE_USED which is always set by poplevel.
  1351.      The flag is set again if insert_block is called.  */
  1352.   TREE_USED (block) = 0;
  1353. }
  1354.  
  1355. /* Insert BLOCK at the end of the list of subblocks of the
  1356.    current binding level.  This is used when a BIND_EXPR is expanded,
  1357.    to handle the BLOCK node inside the BIND_EXPR.  */
  1358.  
  1359. void
  1360. insert_block (block)
  1361.      tree block;
  1362. {
  1363.   TREE_USED (block) = 1;
  1364.   current_binding_level->blocks
  1365.     = chainon (current_binding_level->blocks, block);
  1366. }
  1367.  
  1368. /* Add BLOCK to the current list of blocks for this binding contour.  */
  1369. void
  1370. add_block_current_level (block)
  1371.      tree block;
  1372. {
  1373.   current_binding_level->blocks
  1374.     = chainon (current_binding_level->blocks, block);
  1375. }
  1376.  
  1377. /* Set the BLOCK node for the innermost scope
  1378.    (the one we are currently in).  */
  1379.  
  1380. void
  1381. set_block (block)
  1382.     register tree block;
  1383. {
  1384.   current_binding_level->this_block = block;
  1385. }
  1386.  
  1387. /* Do a pushlevel for class declarations.  */
  1388. void
  1389. pushlevel_class ()
  1390. {
  1391.   register struct binding_level *newlevel;
  1392.  
  1393.   /* Reuse or create a struct for this binding level.  */
  1394. #if defined(DEBUG_CP_BINDING_LEVELS)
  1395.   if (0)
  1396. #else /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1397.   if (free_binding_level)
  1398. #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */
  1399.     {
  1400.       newlevel = free_binding_level;
  1401.       free_binding_level = free_binding_level->level_chain;
  1402.     }
  1403.   else
  1404.     {
  1405.       /* Create a new `struct binding_level'.  */
  1406.       newlevel = (struct binding_level *) xmalloc (sizeof (struct binding_level));
  1407.     }
  1408.  
  1409. #if defined(DEBUG_CP_BINDING_LEVELS)
  1410.   is_class_level = 1;
  1411. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1412.  
  1413.   push_binding_level (newlevel, 0, 0);
  1414.  
  1415.   decl_stack = push_decl_level (decl_stack, &decl_obstack);
  1416.   class_binding_level = current_binding_level;
  1417.   class_binding_level->parm_flag = 2;
  1418.   /* We have just pushed into a new binding level.  Now, fake out the rest
  1419.      of the compiler.  Set the `current_binding_level' back to point to
  1420.      the most closely containing non-class binding level.  */
  1421.   do
  1422.     {
  1423.       current_binding_level = current_binding_level->level_chain;
  1424.     }
  1425.   while (current_binding_level->parm_flag == 2);
  1426. }
  1427.  
  1428. /* ...and a poplevel for class declarations.  FORCE is used to force
  1429.    clearing out of CLASS_VALUEs after a class definition.  */
  1430. tree
  1431. poplevel_class (force)
  1432.      int force;
  1433. {
  1434.   register struct binding_level *level = class_binding_level;
  1435.   tree block = NULL_TREE;
  1436.   tree shadowed;
  1437.  
  1438.   my_friendly_assert (level != 0, 354);
  1439.   
  1440.   decl_stack = pop_stack_level (decl_stack);
  1441.   for (shadowed = level->shadowed; shadowed; shadowed = TREE_CHAIN (shadowed))
  1442.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1443.   /* If we're leaving a toplevel class, don't bother to do the setting
  1444.      of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot
  1445.      shouldn't even be used when current_class_type isn't set, and second,
  1446.      if we don't touch it here, we're able to use the cache effect if the
  1447.      next time we're entering a class scope, it is the same class.  */
  1448.   if (current_class_depth != 1 || force)
  1449.     for (shadowed = level->class_shadowed;
  1450.      shadowed;
  1451.      shadowed = TREE_CHAIN (shadowed))
  1452.       IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1453.   else
  1454.     /* Remember to save what IDENTIFIER's were bound in this scope so we
  1455.        can recover from cache misses.  */
  1456.     previous_class_values = class_binding_level->class_shadowed;
  1457.   for (shadowed = level->type_shadowed;
  1458.        shadowed;
  1459.        shadowed = TREE_CHAIN (shadowed))
  1460.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed)) = TREE_VALUE (shadowed);
  1461.  
  1462.   GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level,
  1463.               (HOST_WIDE_INT) class_binding_level->level_chain,
  1464.               class_binding_level->parm_flag,
  1465.               class_binding_level->keep,
  1466.               class_binding_level->tag_transparent);
  1467.  
  1468.   if (class_binding_level->parm_flag != 2)
  1469.     class_binding_level = (struct binding_level *)0;
  1470.  
  1471.   /* Now, pop out of the the binding level which we created up in the
  1472.      `pushlevel_class' routine.  */
  1473. #if defined(DEBUG_CP_BINDING_LEVELS)
  1474.   is_class_level = 1;
  1475. #endif /* defined(DEBUG_CP_BINDING_LEVELS) */
  1476.  
  1477.   pop_binding_level ();
  1478.  
  1479.   return block;
  1480. }
  1481.  
  1482. /* For debugging.  */
  1483. int no_print_functions = 0;
  1484. int no_print_builtins = 0;
  1485.  
  1486. void
  1487. print_binding_level (lvl)
  1488.      struct binding_level *lvl;
  1489. {
  1490.   tree t;
  1491.   int i = 0, len;
  1492.   fprintf (stderr, " blocks=");
  1493.   fprintf (stderr, HOST_PTR_PRINTF, lvl->blocks);
  1494.   fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d",
  1495.        list_length (lvl->incomplete), lvl->parm_flag, lvl->keep);
  1496.   if (lvl->tag_transparent)
  1497.     fprintf (stderr, " tag-transparent");
  1498.   if (lvl->more_cleanups_ok)
  1499.     fprintf (stderr, " more-cleanups-ok");
  1500.   if (lvl->have_cleanups)
  1501.     fprintf (stderr, " have-cleanups");
  1502.   fprintf (stderr, "\n");
  1503.   if (lvl->names)
  1504.     {
  1505.       fprintf (stderr, " names:\t");
  1506.       /* We can probably fit 3 names to a line?  */
  1507.       for (t = lvl->names; t; t = TREE_CHAIN (t))
  1508.     {
  1509.       if (no_print_functions && (TREE_CODE(t) == FUNCTION_DECL)) 
  1510.         continue;
  1511.       if (no_print_builtins
  1512.           && (TREE_CODE(t) == TYPE_DECL)
  1513.           && (!strcmp(DECL_SOURCE_FILE(t),"<built-in>")))
  1514.         continue;
  1515.  
  1516.       /* Function decls tend to have longer names.  */
  1517.       if (TREE_CODE (t) == FUNCTION_DECL)
  1518.         len = 3;
  1519.       else
  1520.         len = 2;
  1521.       i += len;
  1522.       if (i > 6)
  1523.         {
  1524.           fprintf (stderr, "\n\t");
  1525.           i = len;
  1526.         }
  1527.       print_node_brief (stderr, "", t, 0);
  1528.       if (TREE_CODE (t) == ERROR_MARK)
  1529.         break;
  1530.     }
  1531.       if (i)
  1532.         fprintf (stderr, "\n");
  1533.     }
  1534.   if (lvl->tags)
  1535.     {
  1536.       fprintf (stderr, " tags:\t");
  1537.       i = 0;
  1538.       for (t = lvl->tags; t; t = TREE_CHAIN (t))
  1539.     {
  1540.       if (TREE_PURPOSE (t) == NULL_TREE)
  1541.         len = 3;
  1542.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1543.         len = 2;
  1544.       else
  1545.         len = 4;
  1546.       i += len;
  1547.       if (i > 5)
  1548.         {
  1549.           fprintf (stderr, "\n\t");
  1550.           i = len;
  1551.         }
  1552.       if (TREE_PURPOSE (t) == NULL_TREE)
  1553.         {
  1554.           print_node_brief (stderr, "<unnamed-typedef", TREE_VALUE (t), 0);
  1555.           fprintf (stderr, ">");
  1556.         }
  1557.       else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t)))
  1558.         print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1559.       else
  1560.         {
  1561.           print_node_brief (stderr, "<typedef", TREE_PURPOSE (t), 0);
  1562.           print_node_brief (stderr, "", TREE_VALUE (t), 0);
  1563.           fprintf (stderr, ">");
  1564.         }
  1565.     }
  1566.       if (i)
  1567.     fprintf (stderr, "\n");
  1568.     }
  1569.   if (lvl->shadowed)
  1570.     {
  1571.       fprintf (stderr, " shadowed:");
  1572.       for (t = lvl->shadowed; t; t = TREE_CHAIN (t))
  1573.     {
  1574.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1575.     }
  1576.       fprintf (stderr, "\n");
  1577.     }
  1578.   if (lvl->class_shadowed)
  1579.     {
  1580.       fprintf (stderr, " class-shadowed:");
  1581.       for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t))
  1582.     {
  1583.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1584.     }
  1585.       fprintf (stderr, "\n");
  1586.     }
  1587.   if (lvl->type_shadowed)
  1588.     {
  1589.       fprintf (stderr, " type-shadowed:");
  1590.       for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t))
  1591.         {
  1592. #if 0
  1593.           fprintf (stderr, "\n\t");
  1594.           print_node_brief (stderr, "<", TREE_PURPOSE (t), 0);
  1595.           if (TREE_VALUE (t))
  1596.             print_node_brief (stderr, " ", TREE_VALUE (t), 0);
  1597.           else
  1598.             fprintf (stderr, " (none)");
  1599.           fprintf (stderr, ">");
  1600. #else
  1601.       fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t)));
  1602. #endif
  1603.         }
  1604.       fprintf (stderr, "\n");
  1605.     }
  1606. }
  1607.  
  1608. void
  1609. print_other_binding_stack (stack)
  1610.      struct binding_level *stack;
  1611. {
  1612.   struct binding_level *level;
  1613.   for (level = stack; level != global_binding_level; level = level->level_chain)
  1614.     {
  1615.       fprintf (stderr, "binding level ");
  1616.       fprintf (stderr, HOST_PTR_PRINTF, level);
  1617.       fprintf (stderr, "\n");
  1618.       print_binding_level (level);
  1619.     }
  1620. }
  1621.  
  1622. void
  1623. print_binding_stack ()
  1624. {
  1625.   struct binding_level *b;
  1626.   fprintf (stderr, "current_binding_level=");
  1627.   fprintf (stderr, HOST_PTR_PRINTF, current_binding_level);
  1628.   fprintf (stderr, "\nclass_binding_level=");
  1629.   fprintf (stderr, HOST_PTR_PRINTF, class_binding_level);
  1630.   fprintf (stderr, "\nglobal_binding_level=");
  1631.   fprintf (stderr, HOST_PTR_PRINTF, global_binding_level);
  1632.   fprintf (stderr, "\n");
  1633.   if (class_binding_level)
  1634.     {
  1635.       for (b = class_binding_level; b; b = b->level_chain)
  1636.     if (b == current_binding_level)
  1637.       break;
  1638.       if (b)
  1639.     b = class_binding_level;
  1640.       else
  1641.     b = current_binding_level;
  1642.     }
  1643.   else
  1644.     b = current_binding_level;
  1645.   print_other_binding_stack (b);
  1646.   fprintf (stderr, "global:\n");
  1647.   print_binding_level (global_binding_level);
  1648. }
  1649.  
  1650. extern char * first_global_object_name;
  1651.  
  1652. /* Get a unique name for each call to this routine for unnamed namespaces.
  1653.    Mostly copied from get_file_function_name.  */
  1654. static tree
  1655. get_unique_name ()
  1656. {
  1657.   static int temp_name_counter = 0;
  1658.   char *buf;
  1659.   register char *p;
  1660.  
  1661.   if (first_global_object_name)
  1662.     p = first_global_object_name;
  1663.   else if (main_input_filename)
  1664.     p = main_input_filename;
  1665.   else
  1666.     p = input_filename;
  1667.  
  1668. #define UNNAMED_NAMESPACE_FORMAT "__%s_%d"
  1669.  
  1670.   buf = (char *) alloca (sizeof (UNNAMED_NAMESPACE_FORMAT) + strlen (p));
  1671.  
  1672.   sprintf (buf, UNNAMED_NAMESPACE_FORMAT, p, temp_name_counter++);
  1673.  
  1674.   /* Don't need to pull weird characters out of global names.  */
  1675.   if (p != first_global_object_name)
  1676.     {
  1677.       for (p = buf+11; *p; p++)
  1678.     if (! ((*p >= '0' && *p <= '9')
  1679. #if 0 /* we always want labels, which are valid C++ identifiers (+ `$') */
  1680. #ifndef ASM_IDENTIFY_GCC    /* this is required if `.' is invalid -- k. raeburn */
  1681.            || *p == '.'
  1682. #endif
  1683. #endif
  1684. #ifndef NO_DOLLAR_IN_LABEL    /* this for `$'; unlikely, but... -- kr */
  1685.            || *p == '$'
  1686. #endif
  1687. #ifndef NO_DOT_IN_LABEL        /* this for `.'; unlikely, but... */
  1688.            || *p == '.'
  1689. #endif
  1690.            || (*p >= 'A' && *p <= 'Z')
  1691.            || (*p >= 'a' && *p <= 'z')))
  1692.       *p = '_';
  1693.     }
  1694.  
  1695.   return get_identifier (buf);
  1696. }
  1697.  
  1698. /* Push into the scope of the NAME namespace.  If NAME is NULL_TREE, then we
  1699.    select a name that is unique to this compilation unit.  */
  1700. void
  1701. push_namespace (name)
  1702.      tree name;
  1703. {
  1704.   extern tree current_namespace;
  1705.   tree old_id = get_namespace_id ();
  1706.   char *buf;
  1707.   tree d = make_node (NAMESPACE_DECL);
  1708.  
  1709.   if (! name)
  1710.     {
  1711.       /* Create a truly ugly name! */
  1712.       name = get_unique_name ();
  1713.     }
  1714.  
  1715.   DECL_NAME (d) = name;
  1716.   DECL_ASSEMBLER_NAME (d) = name;
  1717.   /* pushdecl wants to check the size of it to see if it is incomplete... */
  1718.   TREE_TYPE (d) = void_type_node;
  1719.   /* Mark them as external, so redeclaration_error_message doesn't think
  1720.      they are duplicates. */
  1721.   DECL_EXTERNAL (d) = 1;
  1722.   d = pushdecl (d);
  1723.  
  1724.   if (NAMESPACE_LEVEL (d) == 0)
  1725.     {
  1726.       /* This is new for this compilation unit.  */
  1727.       pushlevel (0);
  1728.       declare_namespace_level ();
  1729.       NAMESPACE_LEVEL (d) = (tree)current_binding_level;
  1730.     }
  1731.   else
  1732.     {
  1733.       resume_level ((struct binding_level*)NAMESPACE_LEVEL (d));
  1734.     }
  1735.  
  1736.   /* This code is just is bit old now... */ 
  1737.   current_namespace = tree_cons (NULL_TREE, name, current_namespace);
  1738.   buf = (char *) alloca (4 + (old_id ? IDENTIFIER_LENGTH (old_id) : 0)
  1739.              + IDENTIFIER_LENGTH (name));
  1740.   sprintf (buf, "%s%s", old_id ? IDENTIFIER_POINTER (old_id) : "",
  1741.        IDENTIFIER_POINTER (name));
  1742.   TREE_PURPOSE (current_namespace) = get_identifier (buf);
  1743. }
  1744.  
  1745. /* Pop from the scope of the current namespace.  */
  1746. void
  1747. pop_namespace ()
  1748. {
  1749.   extern tree current_namespace;
  1750.   tree decls, link;
  1751.   current_namespace = TREE_CHAIN (current_namespace);
  1752.  
  1753.   /* Just in case we get out of sync. */
  1754.   if (! namespace_bindings_p ())
  1755.     poplevel (0, 0, 0);
  1756.  
  1757.   decls = current_binding_level->names;
  1758.  
  1759.   /* Clear out the meanings of the local variables of this level.  */
  1760.  
  1761.   for (link = decls; link; link = TREE_CHAIN (link))
  1762.     {
  1763.       if (DECL_NAME (link) != NULL_TREE)
  1764.     {
  1765.       /* If the ident. was used or addressed via a local extern decl,
  1766.          don't forget that fact.  */
  1767.       if (DECL_EXTERNAL (link))
  1768.         {
  1769.           if (TREE_USED (link))
  1770.         TREE_USED (DECL_ASSEMBLER_NAME (link)) = 1;
  1771.           if (TREE_ADDRESSABLE (link))
  1772.         TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  1773.         }
  1774.       IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = NULL_TREE;
  1775.     }
  1776.     }
  1777.  
  1778.   /* Restore all name-meanings of the outer levels
  1779.      that were shadowed by this level.  */
  1780.  
  1781.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  1782.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1783.   for (link = current_binding_level->class_shadowed;
  1784.        link; link = TREE_CHAIN (link))
  1785.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1786.   for (link = current_binding_level->type_shadowed;
  1787.        link; link = TREE_CHAIN (link))
  1788.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  1789.  
  1790.   /* suspend a level.  */
  1791.   suspend_binding_level ();
  1792. }
  1793.  
  1794. /* Subroutines for reverting temporarily to top-level for instantiation
  1795.    of templates and such.  We actually need to clear out the class- and
  1796.    local-value slots of all identifiers, so that only the global values
  1797.    are at all visible.  Simply setting current_binding_level to the global
  1798.    scope isn't enough, because more binding levels may be pushed.  */
  1799. struct saved_scope {
  1800.   struct binding_level *old_binding_level;
  1801.   tree old_bindings;
  1802.   struct saved_scope *prev;
  1803.   tree class_name, class_type, function_decl;
  1804.   tree base_init_list, member_init_list;
  1805.   struct binding_level *class_bindings;
  1806.   tree previous_class_type;
  1807.   tree *lang_base, *lang_stack, lang_name;
  1808.   int lang_stacksize;
  1809.   tree named_labels;
  1810. };
  1811. static struct saved_scope *current_saved_scope;
  1812. extern tree prev_class_type;
  1813.  
  1814. void
  1815. push_to_top_level ()
  1816. {
  1817.   extern int current_lang_stacksize;
  1818.   struct saved_scope *s =
  1819.     (struct saved_scope *) xmalloc (sizeof (struct saved_scope));
  1820.   struct binding_level *b = current_binding_level;
  1821.   tree old_bindings = NULL_TREE;
  1822.  
  1823.   /* Have to include global_binding_level, because class-level decls
  1824.      aren't listed anywhere useful.  */
  1825.   for (; b; b = b->level_chain)
  1826.     {
  1827.       tree t;
  1828.  
  1829.       if (b == global_binding_level)
  1830.     continue;
  1831.       
  1832.       for (t = b->names; t; t = TREE_CHAIN (t))
  1833.     {
  1834.       tree binding, t1, t2 = t;
  1835.       tree id = DECL_ASSEMBLER_NAME (t2);
  1836.  
  1837.       if (!id
  1838.           || (!IDENTIFIER_LOCAL_VALUE (id)
  1839.           && !IDENTIFIER_CLASS_VALUE (id)))
  1840.         continue;
  1841.  
  1842.       for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1))
  1843.         if (TREE_VEC_ELT (t1, 0) == id)
  1844.           goto skip_it;
  1845.         
  1846.       binding = make_tree_vec (4);
  1847.       if (id)
  1848.         {
  1849.           my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135);
  1850.           TREE_VEC_ELT (binding, 0) = id;
  1851.           TREE_VEC_ELT (binding, 1) = IDENTIFIER_TYPE_VALUE (id);
  1852.           TREE_VEC_ELT (binding, 2) = IDENTIFIER_LOCAL_VALUE (id);
  1853.           TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id);
  1854.           IDENTIFIER_LOCAL_VALUE (id) = NULL_TREE;
  1855.           IDENTIFIER_CLASS_VALUE (id) = NULL_TREE;
  1856.         }
  1857.       TREE_CHAIN (binding) = old_bindings;
  1858.       old_bindings = binding;
  1859.     skip_it:
  1860.       ;
  1861.     }
  1862.       /* Unwind type-value slots back to top level.  */
  1863.       for (t = b->type_shadowed; t; t = TREE_CHAIN (t))
  1864.     SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t));
  1865.     }
  1866.   /* Clear out class-level bindings cache.  */
  1867.   if (current_binding_level == global_binding_level
  1868.       && previous_class_type != NULL_TREE)
  1869.     {
  1870.       popclass (-1);
  1871.       previous_class_type = NULL_TREE;
  1872.     }
  1873.  
  1874.   s->old_binding_level = current_binding_level;
  1875.   current_binding_level = global_binding_level;
  1876.  
  1877.   s->class_name = current_class_name;
  1878.   s->class_type = current_class_type;
  1879.   s->function_decl = current_function_decl;
  1880.   s->base_init_list = current_base_init_list;
  1881.   s->member_init_list = current_member_init_list;
  1882.   s->class_bindings = class_binding_level;
  1883.   s->previous_class_type = previous_class_type;
  1884.   s->lang_stack = current_lang_stack;
  1885.   s->lang_base = current_lang_base;
  1886.   s->lang_stacksize = current_lang_stacksize;
  1887.   s->lang_name = current_lang_name;
  1888.   s->named_labels = named_labels;
  1889.   current_class_name = current_class_type = NULL_TREE;
  1890.   current_function_decl = NULL_TREE;
  1891.   class_binding_level = (struct binding_level *)0;
  1892.   previous_class_type = NULL_TREE;
  1893.   current_lang_stacksize = 10;
  1894.   current_lang_stack = current_lang_base
  1895.     = (tree *) xmalloc (current_lang_stacksize * sizeof (tree));
  1896.   current_lang_name = lang_name_cplusplus;
  1897.   strict_prototype = strict_prototypes_lang_cplusplus;
  1898.   named_labels = NULL_TREE;
  1899.  
  1900.   s->prev = current_saved_scope;
  1901.   s->old_bindings = old_bindings;
  1902.   current_saved_scope = s;
  1903. }
  1904.  
  1905. void
  1906. pop_from_top_level ()
  1907. {
  1908.   extern int current_lang_stacksize;
  1909.   struct saved_scope *s = current_saved_scope;
  1910.   tree t;
  1911.  
  1912.   if (previous_class_type)
  1913.     previous_class_type = NULL_TREE;
  1914.  
  1915.   current_binding_level = s->old_binding_level;
  1916.   current_saved_scope = s->prev;
  1917.   for (t = s->old_bindings; t; t = TREE_CHAIN (t))
  1918.     {
  1919.       tree id = TREE_VEC_ELT (t, 0);
  1920.       if (id)
  1921.     {
  1922.       IDENTIFIER_TYPE_VALUE (id) = TREE_VEC_ELT (t, 1);
  1923.       IDENTIFIER_LOCAL_VALUE (id) = TREE_VEC_ELT (t, 2);
  1924.       IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3);
  1925.     }
  1926.     }
  1927.   current_class_name = s->class_name;
  1928.   current_class_type = s->class_type;
  1929.   current_base_init_list = s->base_init_list;
  1930.   current_member_init_list = s->member_init_list;
  1931.   current_function_decl = s->function_decl;
  1932.   class_binding_level = s->class_bindings;
  1933.   previous_class_type = s->previous_class_type;
  1934.   free (current_lang_base);
  1935.   current_lang_base = s->lang_base;
  1936.   current_lang_stack = s->lang_stack;
  1937.   current_lang_name = s->lang_name;
  1938.   current_lang_stacksize = s->lang_stacksize;
  1939.   if (current_lang_name == lang_name_cplusplus)
  1940.     strict_prototype = strict_prototypes_lang_cplusplus;
  1941.   else if (current_lang_name == lang_name_c)
  1942.     strict_prototype = strict_prototypes_lang_c;
  1943.   named_labels = s->named_labels;
  1944.  
  1945.   free (s);
  1946. }
  1947.  
  1948. /* Push a definition of struct, union or enum tag "name".
  1949.    into binding_level "b".   "type" should be the type node, 
  1950.    We assume that the tag "name" is not already defined.
  1951.  
  1952.    Note that the definition may really be just a forward reference.
  1953.    In that case, the TYPE_SIZE will be a NULL_TREE.
  1954.  
  1955.    C++ gratuitously puts all these tags in the name space. */
  1956.  
  1957. /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID,
  1958.    record the shadowed value for this binding contour.  TYPE is
  1959.    the type that ID maps to.  */
  1960.  
  1961. static void
  1962. set_identifier_type_value_with_scope (id, type, b)
  1963.      tree id;
  1964.      tree type;
  1965.      struct binding_level *b;
  1966. {
  1967.   if (b != global_binding_level)
  1968.     {
  1969.       tree old_type_value = IDENTIFIER_TYPE_VALUE (id);
  1970.       b->type_shadowed
  1971.     = tree_cons (id, old_type_value, b->type_shadowed);
  1972.     }
  1973.   SET_IDENTIFIER_TYPE_VALUE (id, type);
  1974. }
  1975.  
  1976. /* As set_identifier_type_value_with_scope, but using inner_binding_level. */
  1977.  
  1978. void
  1979. set_identifier_type_value (id, type)
  1980.      tree id;
  1981.      tree type;
  1982. {
  1983.   set_identifier_type_value_with_scope (id, type, inner_binding_level);
  1984. }
  1985.  
  1986. /* Subroutine "set_nested_typename" builds the nested-typename of
  1987.    the type decl in question.  (Argument CLASSNAME can actually be
  1988.    a function as well, if that's the smallest containing scope.)  */
  1989.  
  1990. static void
  1991. set_nested_typename (decl, classname, name, type)
  1992.      tree decl, classname, name, type;
  1993. {
  1994.   char *buf;
  1995.   my_friendly_assert (TREE_CODE (decl) == TYPE_DECL, 136);
  1996.  
  1997.   /* No need to do this for anonymous names, since they're unique.  */
  1998.   if (ANON_AGGRNAME_P (name))
  1999.     {
  2000.       DECL_NESTED_TYPENAME (decl) = name;
  2001.       return;
  2002.     }
  2003.  
  2004.   if (classname == NULL_TREE)
  2005.     classname = get_identifier ("");
  2006.  
  2007.   my_friendly_assert (TREE_CODE (classname) == IDENTIFIER_NODE, 137);
  2008.   my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 138);
  2009.   buf = (char *) alloca (4 + IDENTIFIER_LENGTH (classname)
  2010.              + IDENTIFIER_LENGTH (name));
  2011.   sprintf (buf, "%s::%s", IDENTIFIER_POINTER (classname),
  2012.        IDENTIFIER_POINTER (name));
  2013.   DECL_NESTED_TYPENAME (decl) = get_identifier (buf);
  2014.   TREE_MANGLED (DECL_NESTED_TYPENAME (decl)) = 1;
  2015.  
  2016.   /* Create an extra decl so that the nested name will have a type value
  2017.      where appropriate.  */
  2018.   {
  2019.     tree nested, type_decl;
  2020.     nested = DECL_NESTED_TYPENAME (decl);
  2021.     type_decl = build_decl (TYPE_DECL, nested, type);
  2022.     DECL_NESTED_TYPENAME (type_decl) = nested;
  2023.     SET_DECL_ARTIFICIAL (type_decl);
  2024.     /* Mark the TYPE_DECL node created just above as a gratuitous one so that
  2025.        dwarfout.c will know not to generate a TAG_typedef DIE for it, and
  2026.        sdbout.c won't try to output a .def for "::foo".  */
  2027.     DECL_IGNORED_P (type_decl) = 1;
  2028.  
  2029.     /* Remove this when local classes are fixed.  */
  2030.     SET_IDENTIFIER_TYPE_VALUE (nested, type);
  2031.  
  2032.     pushdecl_nonclass_level (type_decl);
  2033.   }
  2034. }
  2035.  
  2036. /* Pop off extraneous binding levels left over due to syntax errors.
  2037.  
  2038.    We don't pop past namespaces, as they might be valid.  */
  2039. void
  2040. pop_everything ()
  2041. {
  2042. #ifdef DEBUG_CP_BINDING_LEVELS
  2043.   fprintf (stderr, "XXX entering pop_everything ()\n");
  2044. #endif
  2045.   while (! toplevel_bindings_p () && ! pseudo_global_level_p ())
  2046.     {
  2047.       if (class_binding_level)
  2048.     pop_nested_class (1);
  2049.       else
  2050.     poplevel (0, 0, 0);
  2051.     }
  2052. #ifdef DEBUG_CP_BINDING_LEVELS
  2053.   fprintf (stderr, "XXX leaving pop_everything ()\n");
  2054. #endif
  2055. }
  2056.  
  2057. #if 0 /* not yet, should get fixed properly later */
  2058. /* Create a TYPE_DECL node with the correct DECL_ASSEMBLER_NAME.
  2059.    Other routines shouldn't use build_decl directly; they'll produce
  2060.    incorrect results with `-g' unless they duplicate this code.
  2061.  
  2062.    This is currently needed mainly for dbxout.c, but we can make
  2063.    use of it in method.c later as well.  */
  2064. tree
  2065. make_type_decl (name, type)
  2066.      tree name, type;
  2067. {
  2068.   tree decl, id;
  2069.   decl = build_decl (TYPE_DECL, name, type);
  2070.   if (TYPE_NAME (type) == name)
  2071.     /* Class/union/enum definition, or a redundant typedef for same.  */
  2072.     {
  2073.       id = get_identifier (build_overload_name (type, 1, 1));
  2074.       DECL_ASSEMBLER_NAME (decl) = id;
  2075.     }
  2076.   else if (TYPE_NAME (type) != NULL_TREE)
  2077.     /* Explicit typedef, or implicit typedef for template expansion.  */
  2078.     DECL_ASSEMBLER_NAME (decl) = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
  2079.   else
  2080.     {
  2081.       /* XXX: Typedef for unnamed struct; some other situations.
  2082.      TYPE_NAME is null; what's right here?  */
  2083.     }
  2084.   return decl;
  2085. }
  2086. #endif
  2087.  
  2088. /* Push a tag name NAME for struct/class/union/enum type TYPE.
  2089.    Normally put into into the inner-most non-tag-transparent scope,
  2090.    but if GLOBALIZE is true, put it in the inner-most non-class scope.
  2091.    The latter is needed for implicit declarations. */
  2092.  
  2093. void
  2094. pushtag (name, type, globalize)
  2095.      tree name, type;
  2096.      int globalize;
  2097. {
  2098.   register struct binding_level *b;
  2099.   tree context = 0;
  2100.   tree c_decl = 0;
  2101.  
  2102.   b = inner_binding_level;
  2103.   while (b->tag_transparent
  2104.      || (globalize && b->parm_flag == 2))
  2105.     b = b->level_chain;
  2106.  
  2107.   if (toplevel_bindings_p ())
  2108.     b->tags = perm_tree_cons (name, type, b->tags);
  2109.   else
  2110.     b->tags = saveable_tree_cons (name, type, b->tags);
  2111.  
  2112.   if (name)
  2113.     {
  2114.       context = type ? TYPE_CONTEXT (type) : NULL_TREE;
  2115.       if (! context && ! globalize)
  2116.         context = current_scope ();
  2117.       if (context)
  2118.     c_decl = TREE_CODE (context) == FUNCTION_DECL
  2119.       ? context : TYPE_MAIN_DECL (context);
  2120.  
  2121. #if 0
  2122.       /* Record the identifier as the type's name if it has none.  */
  2123.       if (TYPE_NAME (type) == NULL_TREE)
  2124.         TYPE_NAME (type) = name;
  2125. #endif
  2126.       
  2127.       /* Do C++ gratuitous typedefing.  */
  2128.       if (IDENTIFIER_TYPE_VALUE (name) != type)
  2129.         {
  2130.           register tree d;
  2131.       int newdecl = 0;
  2132.       
  2133.       if (b->parm_flag != 2
  2134.           || TYPE_SIZE (current_class_type) != NULL_TREE)
  2135.         {
  2136.           d = lookup_nested_type (type, c_decl);
  2137.  
  2138.           if (d == NULL_TREE)
  2139.         {
  2140.           newdecl = 1;
  2141. #if 0 /* not yet, should get fixed properly later */
  2142.           d = make_type_decl (name, type);
  2143. #else
  2144.           d = build_decl (TYPE_DECL, name, type);
  2145.           DECL_ASSEMBLER_NAME (d) = current_namespace_id (DECL_ASSEMBLER_NAME (d));
  2146. #endif
  2147.           SET_DECL_ARTIFICIAL (d);
  2148. #ifdef DWARF_DEBUGGING_INFO
  2149.           if (write_symbols == DWARF_DEBUG)
  2150.             {
  2151.               /* Mark the TYPE_DECL node we created just above as an
  2152.              gratuitous one.  We need to do this so that dwarfout.c
  2153.              will understand that it is not supposed to output a
  2154.              TAG_typedef DIE  for it. */
  2155.               DECL_IGNORED_P (d) = 1;
  2156.             }
  2157. #endif /* DWARF_DEBUGGING_INFO */
  2158.           set_identifier_type_value_with_scope (name, type, b);
  2159.         }
  2160.           else
  2161.         d = TYPE_NAME (d);
  2162.  
  2163.           TYPE_NAME (type) = d;
  2164.  
  2165.           /* If it is anonymous, then we are called from pushdecl,
  2166.          and we don't want to infinitely recurse.  */
  2167.           if (! ANON_AGGRNAME_P (name))
  2168.         {
  2169.           if (b->parm_flag == 2)
  2170.             d = pushdecl_class_level (d);
  2171.           else
  2172.             d = pushdecl_with_scope (d, b);
  2173.         }
  2174.         }
  2175.       else
  2176.         {
  2177.           /* Make nested declarations go into class-level scope.  */
  2178.           newdecl = 1;
  2179.           d = build_decl (TYPE_DECL, name, type);
  2180.           SET_DECL_ARTIFICIAL (d);
  2181. #ifdef DWARF_DEBUGGING_INFO
  2182.           if (write_symbols == DWARF_DEBUG)
  2183.         {
  2184.           /* Mark the TYPE_DECL node we created just above as an
  2185.              gratuitous one.  We need to do this so that dwarfout.c
  2186.              will understand that it is not supposed to output a
  2187.              TAG_typedef DIE  for it. */
  2188.           DECL_IGNORED_P (d) = 1;
  2189.         }
  2190. #endif /* DWARF_DEBUGGING_INFO */
  2191.  
  2192.           TYPE_MAIN_DECL (type) = d;
  2193.  
  2194.           /* Make sure we're in this type's scope when we push the
  2195.          decl for a template, otherwise class_binding_level will
  2196.          be NULL and we'll end up dying inside of
  2197.          push_class_level_binding.  */
  2198.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  2199.         pushclass (type, 0);
  2200.           d = pushdecl_class_level (d);
  2201.           if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  2202.         popclass (0);
  2203.         }
  2204.       if (newdecl)
  2205.         {
  2206.           if (write_symbols != DWARF_DEBUG)
  2207.         {
  2208.           if (ANON_AGGRNAME_P (name))
  2209.             DECL_IGNORED_P (d) = 1;
  2210.         }
  2211.  
  2212.           if (context == NULL_TREE)
  2213.         /* Non-nested class.  */
  2214.         set_nested_typename (d, NULL_TREE, name, type);
  2215.           else if (context && TREE_CODE (context) == FUNCTION_DECL)
  2216.         /* Function-nested class.  */
  2217.         set_nested_typename (d, DECL_ASSEMBLER_NAME (c_decl),
  2218.                      name, type);
  2219.           else /* if (context && IS_AGGR_TYPE (context)) */
  2220.         /* Class-nested class.  */
  2221.         set_nested_typename (d, DECL_NESTED_TYPENAME (c_decl),
  2222.                      name, type);
  2223.  
  2224.           DECL_CONTEXT (d) = context;
  2225.           TYPE_CONTEXT (type) = DECL_CONTEXT (d);
  2226.           DECL_ASSEMBLER_NAME (d)
  2227.         = get_identifier (build_overload_name (type, 1, 1));
  2228.         }
  2229.         }
  2230.       if (b->parm_flag == 2)
  2231.     {
  2232.       TREE_NONLOCAL_FLAG (type) = 1;
  2233.       if (TYPE_SIZE (current_class_type) == NULL_TREE)
  2234.         CLASSTYPE_TAGS (current_class_type) = b->tags;
  2235.     }
  2236.     }
  2237.  
  2238.   if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
  2239.     /* Use the canonical TYPE_DECL for this node.  */
  2240.     TYPE_STUB_DECL (type) = TYPE_NAME (type);
  2241.   else
  2242.     {
  2243.       /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE
  2244.      will be the tagged type we just added to the current
  2245.      binding level.  This fake NULL-named TYPE_DECL node helps
  2246.      dwarfout.c to know when it needs to output a
  2247.      representation of a tagged type, and it also gives us a
  2248.      convenient place to record the "scope start" address for
  2249.      the tagged type.  */
  2250.  
  2251. #if 0 /* not yet, should get fixed properly later */
  2252.       tree d = make_type_decl (NULL_TREE, type);
  2253. #else
  2254.       tree d = build_decl (TYPE_DECL, NULL_TREE, type);
  2255. #endif
  2256.       TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b);
  2257.     }
  2258. }
  2259.  
  2260. /* Counter used to create anonymous type names.  */
  2261. static int anon_cnt = 0;
  2262.  
  2263. /* Return an IDENTIFIER which can be used as a name for
  2264.    anonymous structs and unions.  */
  2265. tree
  2266. make_anon_name ()
  2267. {
  2268.   char buf[32];
  2269.  
  2270.   sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++);
  2271.   return get_identifier (buf);
  2272. }
  2273.  
  2274. /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames.
  2275.    This keeps dbxout from getting confused.  */
  2276. void
  2277. clear_anon_tags ()
  2278. {
  2279.   register struct binding_level *b;
  2280.   register tree tags;
  2281.   static int last_cnt = 0;
  2282.  
  2283.   /* Fast out if no new anon names were declared.  */
  2284.   if (last_cnt == anon_cnt)
  2285.     return;
  2286.  
  2287.   b = current_binding_level;
  2288.   while (b->tag_transparent)
  2289.     b = b->level_chain;
  2290.   tags = b->tags;
  2291.   while (tags)
  2292.     {
  2293.       /* A NULL purpose means we have already processed all tags
  2294.      from here to the end of the list.  */
  2295.       if (TREE_PURPOSE (tags) == NULL_TREE)
  2296.     break;
  2297.       if (ANON_AGGRNAME_P (TREE_PURPOSE (tags)))
  2298.     TREE_PURPOSE (tags) = NULL_TREE;
  2299.       tags = TREE_CHAIN (tags);
  2300.     }
  2301.   last_cnt = anon_cnt;
  2302. }
  2303.  
  2304. /* Subroutine of duplicate_decls: return truthvalue of whether
  2305.    or not types of these decls match.
  2306.  
  2307.    For C++, we must compare the parameter list so that `int' can match
  2308.    `int&' in a parameter position, but `int&' is not confused with
  2309.    `const int&'.  */
  2310. int
  2311. decls_match (newdecl, olddecl)
  2312.      tree newdecl, olddecl;
  2313. {
  2314.   int types_match;
  2315.  
  2316.   if (TREE_CODE (newdecl) == FUNCTION_DECL
  2317.       && TREE_CODE (olddecl) == FUNCTION_DECL)
  2318.     {
  2319.       tree f1 = TREE_TYPE (newdecl);
  2320.       tree f2 = TREE_TYPE (olddecl);
  2321.       tree p1 = TYPE_ARG_TYPES (f1);
  2322.       tree p2 = TYPE_ARG_TYPES (f2);
  2323.  
  2324.       /* When we parse a static member function definition,
  2325.      we put together a FUNCTION_DECL which thinks its type
  2326.      is METHOD_TYPE.  Change that to FUNCTION_TYPE, and
  2327.      proceed.  */
  2328.       if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl))
  2329.     revert_static_member_fn (&newdecl, &f1, &p1);
  2330.       else if (TREE_CODE (f2) == METHOD_TYPE
  2331.            && DECL_STATIC_FUNCTION_P (newdecl))
  2332.     revert_static_member_fn (&olddecl, &f2, &p2);
  2333.  
  2334.       /* Here we must take care of the case where new default
  2335.      parameters are specified.  Also, warn if an old
  2336.      declaration becomes ambiguous because default
  2337.      parameters may cause the two to be ambiguous.  */
  2338.       if (TREE_CODE (f1) != TREE_CODE (f2))
  2339.     {
  2340.       if (TREE_CODE (f1) == OFFSET_TYPE)
  2341.         cp_compiler_error ("`%D' redeclared as member function", newdecl);
  2342.       else
  2343.         cp_compiler_error ("`%D' redeclared as non-member function", newdecl);
  2344.       return 0;
  2345.     }
  2346.  
  2347.       if (comptypes (TREE_TYPE (f1), TREE_TYPE (f2), 1))
  2348.     {
  2349.       if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c
  2350.           && p2 == NULL_TREE)
  2351.         {
  2352.           types_match = self_promoting_args_p (p1);
  2353.           if (p1 == void_list_node)
  2354.         TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  2355.         }
  2356.       else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c
  2357.            && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE)
  2358.         {
  2359.           types_match = self_promoting_args_p (p2);
  2360.           TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
  2361.         }
  2362.       else
  2363.         types_match = compparms (p1, p2, 3);
  2364.     }
  2365.       else
  2366.     types_match = 0;
  2367.     }
  2368.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL
  2369.        && TREE_CODE (olddecl) == TEMPLATE_DECL)
  2370.     {
  2371.     tree newargs = DECL_TEMPLATE_PARMS (newdecl);
  2372.     tree oldargs = DECL_TEMPLATE_PARMS (olddecl);
  2373.     int i, len = TREE_VEC_LENGTH (newargs);
  2374.  
  2375.     if (TREE_VEC_LENGTH (oldargs) != len)
  2376.       return 0;
  2377.     
  2378.     for (i = 0; i < len; i++)
  2379.       {
  2380.         tree newarg = TREE_VALUE (TREE_VEC_ELT (newargs, i));
  2381.         tree oldarg = TREE_VALUE (TREE_VEC_ELT (oldargs, i));
  2382.         if (TREE_CODE (newarg) != TREE_CODE (oldarg))
  2383.           return 0;
  2384.         else if (TREE_CODE (newarg) == TYPE_DECL)
  2385.           /* continue */;
  2386.         else if (! comptypes (TREE_TYPE (newarg), TREE_TYPE (oldarg), 1))
  2387.           return 0;
  2388.       }
  2389.  
  2390.     if (DECL_TEMPLATE_IS_CLASS (newdecl)
  2391.         != DECL_TEMPLATE_IS_CLASS (olddecl))
  2392.       types_match = 0;
  2393.     else if (DECL_TEMPLATE_IS_CLASS (newdecl))
  2394.       types_match = 1;
  2395.     else
  2396.       types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
  2397.                      DECL_TEMPLATE_RESULT (newdecl));
  2398.     }
  2399.   else
  2400.     {
  2401.       if (TREE_TYPE (newdecl) == error_mark_node)
  2402.     types_match = TREE_TYPE (olddecl) == error_mark_node;
  2403.       else if (TREE_TYPE (olddecl) == NULL_TREE)
  2404.     types_match = TREE_TYPE (newdecl) == NULL_TREE;
  2405.       else if (TREE_TYPE (newdecl) == NULL_TREE)
  2406.     types_match = 0;
  2407.       else
  2408.     types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 1);
  2409.     }
  2410.  
  2411.   return types_match;
  2412. }
  2413.  
  2414. /* If NEWDECL is `static' and an `extern' was seen previously,
  2415.    warn about it.  (OLDDECL may be NULL_TREE; NAME contains
  2416.    information about previous usage as an `extern'.)
  2417.  
  2418.    Note that this does not apply to the C++ case of declaring
  2419.    a variable `extern const' and then later `const'.
  2420.  
  2421.    Don't complain if -traditional, since traditional compilers
  2422.    don't complain.
  2423.  
  2424.    Don't complain about built-in functions, since they are beyond
  2425.    the user's control.  */
  2426.  
  2427. static void
  2428. warn_extern_redeclared_static (newdecl, olddecl)
  2429.      tree newdecl, olddecl;
  2430. {
  2431.   tree name;
  2432.  
  2433.   static char *explicit_extern_static_warning
  2434.     = "`%D' was declared `extern' and later `static'";
  2435.   static char *implicit_extern_static_warning
  2436.     = "`%D' was declared implicitly `extern' and later `static'";
  2437.  
  2438.   if (flag_traditional
  2439. #ifdef OBJCPLUS
  2440.       || DECL_ARTIFICIAL (olddecl)
  2441. #endif
  2442.       || TREE_CODE (newdecl) == TYPE_DECL)
  2443.     return;
  2444.  
  2445.   name = DECL_ASSEMBLER_NAME (newdecl);
  2446.   if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl))
  2447.     {
  2448.       /* It's okay to redeclare an ANSI built-in function as static,
  2449.      or to declare a non-ANSI built-in function as anything.  */
  2450.       if (! (TREE_CODE (newdecl) == FUNCTION_DECL
  2451.          && olddecl != NULL_TREE
  2452.          && TREE_CODE (olddecl) == FUNCTION_DECL
  2453.          && (DECL_BUILT_IN (olddecl)
  2454.          || DECL_BUILT_IN_NONANSI (olddecl))))
  2455.     {
  2456.       cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
  2457.               ? implicit_extern_static_warning
  2458.               : explicit_extern_static_warning, newdecl);
  2459.       if (olddecl != NULL_TREE)
  2460.         cp_pedwarn_at ("previous declaration of `%D'", olddecl);
  2461.     }
  2462.     }
  2463. }
  2464.  
  2465. /* Handle when a new declaration NEWDECL has the same name as an old
  2466.    one OLDDECL in the same binding contour.  Prints an error message
  2467.    if appropriate.
  2468.  
  2469.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  2470.    Otherwise, return 0.  */
  2471.  
  2472. int
  2473. duplicate_decls (newdecl, olddecl)
  2474.      register tree newdecl, olddecl;
  2475. {
  2476.   extern struct obstack permanent_obstack;
  2477.   unsigned olddecl_uid = DECL_UID (olddecl);
  2478.   int olddecl_friend = 0, types_match = 0;
  2479.   int new_defines_function;
  2480.   tree previous_c_decl = NULL_TREE;
  2481.  
  2482.   if (TREE_CODE_CLASS (TREE_CODE (olddecl)) == 'd')
  2483.     DECL_MACHINE_ATTRIBUTES (newdecl) = DECL_MACHINE_ATTRIBUTES (olddecl);
  2484.  
  2485.   types_match = decls_match (newdecl, olddecl);
  2486.  
  2487.   if (TREE_CODE (olddecl) != TREE_LIST)
  2488.     olddecl_friend = DECL_LANG_SPECIFIC (olddecl) && DECL_FRIEND_P (olddecl);
  2489.  
  2490.   /* If either the type of the new decl or the type of the old decl is an
  2491.      error_mark_node, then that implies that we have already issued an
  2492.      error (earlier) for some bogus type specification, and in that case,
  2493.      it is rather pointless to harass the user with yet more error message
  2494.      about the same declaration, so well just pretent the types match here.  */
  2495.   if ((TREE_TYPE (newdecl)
  2496.        && TREE_CODE (TREE_TYPE (newdecl)) == ERROR_MARK)
  2497.       || (TREE_TYPE (olddecl)
  2498.       && TREE_CODE (TREE_TYPE (olddecl)) == ERROR_MARK))
  2499.     types_match = 1;
  2500.  
  2501.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  2502.       && IDENTIFIER_IMPLICIT_DECL (DECL_ASSEMBLER_NAME (newdecl)) == olddecl)
  2503.     /* If -traditional, avoid error for redeclaring fcn
  2504.        after implicit decl.  */
  2505.     ;
  2506.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2507.        && DECL_ARTIFICIAL (olddecl)
  2508.        && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
  2509.     {
  2510.       /* If you declare a built-in or predefined function name as static,
  2511.      the old definition is overridden, but optionally warn this was a
  2512.      bad choice of name.  Ditto for overloads.  */
  2513.       if (! DECL_PUBLIC (newdecl)
  2514.       || (TREE_CODE (newdecl) == FUNCTION_DECL
  2515.           && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
  2516.     {
  2517.       if (warn_shadow)
  2518.         cp_warning ("shadowing %s function `%#D'",
  2519.             DECL_BUILT_IN (olddecl) ? "built-in" : "library",
  2520.             olddecl);
  2521.       /* Discard the old built-in function.  */
  2522.       return 0;
  2523.     }
  2524.       else if (! types_match)
  2525.     {
  2526.       if (TREE_CODE (newdecl) != FUNCTION_DECL)
  2527.         {
  2528.           /* If the built-in is not ansi, then programs can override
  2529.          it even globally without an error.  */
  2530.           if (! DECL_BUILT_IN (olddecl))
  2531.         cp_warning ("library function `%#D' redeclared as non-function `%#D'",
  2532.                 olddecl, newdecl);
  2533.           else
  2534.         {
  2535.           cp_error ("declaration of `%#D'", newdecl);
  2536.           cp_error ("conflicts with built-in declaration `%#D'",
  2537.                 olddecl);
  2538.         }
  2539.           return 0;
  2540.         }
  2541.  
  2542.       cp_warning ("declaration of `%#D'", newdecl);
  2543.       cp_warning ("conflicts with built-in declaration `%#D'",
  2544.               olddecl);
  2545.     }
  2546.     }
  2547.   else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  2548.     {
  2549.       if ((TREE_CODE (newdecl) == FUNCTION_DECL
  2550.        && TREE_CODE (olddecl) == TEMPLATE_DECL
  2551.        && ! DECL_TEMPLATE_IS_CLASS (olddecl))
  2552.       || (TREE_CODE (olddecl) == FUNCTION_DECL
  2553.           && TREE_CODE (newdecl) == TEMPLATE_DECL
  2554.           && ! DECL_TEMPLATE_IS_CLASS (newdecl)))
  2555.     return 0;
  2556.       
  2557.       cp_error ("`%#D' redeclared as different kind of symbol", newdecl);
  2558.       if (TREE_CODE (olddecl) == TREE_LIST)
  2559.     olddecl = TREE_VALUE (olddecl);
  2560.       cp_error_at ("previous declaration of `%#D'", olddecl);
  2561.  
  2562.       /* New decl is completely inconsistent with the old one =>
  2563.      tell caller to replace the old one.  */
  2564.  
  2565.       return 0;
  2566.     }
  2567.   else if (!types_match)
  2568.     {
  2569.       if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2570.     {
  2571.       /* The name of a class template may not be declared to refer to
  2572.          any other template, class, function, object, namespace, value,
  2573.          or type in the same scope. */
  2574.       if (DECL_TEMPLATE_IS_CLASS (olddecl)
  2575.           || DECL_TEMPLATE_IS_CLASS (newdecl))
  2576.         {
  2577.           cp_error ("declaration of template `%#D'", newdecl);
  2578.           cp_error_at ("conflicts with previous declaration `%#D'",
  2579.                olddecl);
  2580.         }
  2581.       return 0;
  2582.     }
  2583.       if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2584.     {
  2585.       if (DECL_LANGUAGE (newdecl) == lang_c
  2586.           && DECL_LANGUAGE (olddecl) == lang_c)
  2587.         {
  2588.           cp_error ("declaration of C function `%#D' conflicts with",
  2589.             newdecl);
  2590.           cp_error_at ("previous declaration `%#D' here", olddecl);
  2591.         }
  2592.       else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
  2593.                   TYPE_ARG_TYPES (TREE_TYPE (olddecl)), 3))
  2594.         {
  2595.           cp_error ("new declaration `%#D'", newdecl);
  2596.           cp_error_at ("ambiguates old declaration `%#D'", olddecl);
  2597.         }
  2598.       else
  2599.         return 0;
  2600.     }
  2601.  
  2602.       /* Already complained about this, so don't do so again.  */
  2603.       else if (current_class_type == NULL_TREE
  2604.       || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type)
  2605.     {
  2606.       cp_error ("conflicting types for `%#D'", newdecl);
  2607.       cp_error_at ("previous declaration as `%#D'", olddecl);
  2608.     }
  2609.     }
  2610.   else
  2611.     {
  2612.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  2613.       if (errmsg)
  2614.     {
  2615.       cp_error (errmsg, newdecl);
  2616.       if (DECL_NAME (olddecl) != NULL_TREE)
  2617.         cp_error_at ((DECL_INITIAL (olddecl)
  2618.               && current_binding_level == global_binding_level)
  2619.              ? "`%#D' previously defined here"
  2620.              : "`%#D' previously declared here", olddecl);
  2621.     }
  2622.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2623.            && DECL_INITIAL (olddecl) != NULL_TREE
  2624.            && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE
  2625.            && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE)
  2626.     {
  2627.       /* Prototype decl follows defn w/o prototype.  */
  2628.       cp_warning_at ("prototype for `%#D'", newdecl);
  2629.       cp_warning_at ("follows non-prototype definition here", olddecl);
  2630.     }
  2631.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  2632.            && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
  2633.     {
  2634.       /* extern "C" int foo ();
  2635.          int foo () { bar (); }
  2636.          is OK.  */
  2637.       if (current_lang_stack == current_lang_base)
  2638.         DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2639.       else
  2640.         {
  2641.           cp_error_at ("previous declaration of `%#D' with %L linkage",
  2642.                olddecl, DECL_LANGUAGE (olddecl));
  2643.           cp_error ("conflicts with new declaration with %L linkage",
  2644.             DECL_LANGUAGE (newdecl));
  2645.         }
  2646.     }
  2647.  
  2648.       if (TREE_CODE (olddecl) == FUNCTION_DECL)
  2649.     {
  2650.       tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
  2651.       tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
  2652.       int i = 1;
  2653.  
  2654.       if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE)
  2655.         t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2);
  2656.     
  2657.       for (; t1 && t1 != void_list_node;
  2658.            t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
  2659.         if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
  2660.           {
  2661.         if (1 == simple_cst_equal (TREE_PURPOSE (t1),
  2662.                        TREE_PURPOSE (t2)))
  2663.           {
  2664.             if (pedantic)
  2665.               {
  2666.             cp_pedwarn ("default argument given for parameter %d of `%#D'",
  2667.                     i, newdecl);
  2668.             cp_pedwarn_at ("after previous specification in `%#D'",
  2669.                        olddecl);
  2670.               }
  2671.           }
  2672.         else
  2673.           {
  2674.             cp_error ("default argument given for parameter %d of `%#D'",
  2675.                   i, newdecl);
  2676.             cp_error_at ("conflicts with previous specification in `%#D'",
  2677.                  olddecl);
  2678.           }
  2679.           }
  2680.  
  2681.       if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl))
  2682.         {
  2683. #if 0 /* I think this will be correct, but it's really annoying.  We should
  2684.      fix the compiler to find vtables by indirection so it isn't
  2685.      necessary.  (jason 8/25/95) */
  2686.           if (DECL_VINDEX (olddecl) && ! DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2687.         {
  2688.           cp_pedwarn ("virtual function `%#D' redeclared inline",
  2689.                   newdecl);
  2690.           cp_pedwarn_at ("previous non-inline declaration here",
  2691.                  olddecl);
  2692.         }
  2693.           else
  2694. #endif
  2695.           if (TREE_ADDRESSABLE (olddecl))
  2696.         {
  2697.           cp_pedwarn ("`%#D' was used before it was declared inline",
  2698.                   newdecl);
  2699.           cp_pedwarn_at ("previous non-inline declaration here",
  2700.                  olddecl);
  2701.         }
  2702.         }
  2703.     }
  2704.       /* These bits are logically part of the type for non-functions.  */
  2705.       else if (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  2706.            || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl))
  2707.     {
  2708.       cp_pedwarn ("type qualifiers for `%#D'", newdecl);
  2709.       cp_pedwarn_at ("conflict with previous decl `%#D'", olddecl);
  2710.     }
  2711.     }
  2712.  
  2713.   /* If new decl is `static' and an `extern' was seen previously,
  2714.      warn about it.  */
  2715.   warn_extern_redeclared_static (newdecl, olddecl);
  2716.  
  2717.   /* We have committed to returning 1 at this point. */
  2718.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2719.     {
  2720.       /* Now that functions must hold information normally held
  2721.      by field decls, there is extra work to do so that
  2722.      declaration information does not get destroyed during
  2723.      definition.  */
  2724.       if (DECL_VINDEX (olddecl))
  2725.     DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
  2726.       if (DECL_CONTEXT (olddecl))
  2727.     DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
  2728.       if (DECL_CLASS_CONTEXT (olddecl))
  2729.     DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl);
  2730.       if (DECL_CHAIN (newdecl) == NULL_TREE)
  2731.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2732.       if (DECL_NEXT_METHOD (newdecl) == NULL_TREE)
  2733.     DECL_NEXT_METHOD (newdecl) = DECL_NEXT_METHOD (olddecl);
  2734.       if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0)
  2735.     DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl);
  2736.       DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
  2737.       DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
  2738.       DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl);
  2739.     }
  2740.  
  2741.   /* Deal with C++: must preserve virtual function table size.  */
  2742.   if (TREE_CODE (olddecl) == TYPE_DECL)
  2743.     {
  2744.       register tree newtype = TREE_TYPE (newdecl);
  2745.       register tree oldtype = TREE_TYPE (olddecl);
  2746.  
  2747.       DECL_NESTED_TYPENAME (newdecl) = DECL_NESTED_TYPENAME (olddecl);
  2748.  
  2749.       if (newtype != error_mark_node && oldtype != error_mark_node
  2750.       && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
  2751.     {
  2752.       CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype);
  2753.       CLASSTYPE_FRIEND_CLASSES (newtype)
  2754.         = CLASSTYPE_FRIEND_CLASSES (oldtype);
  2755.     }
  2756. #if 0
  2757.       /* why assert here?  Just because debugging information is
  2758.      messed up? (mrs) */
  2759.       /* it happens on something like:
  2760.          typedef struct Thing {
  2761.                     Thing();
  2762.                 int     x;
  2763.         } Thing;
  2764.       */
  2765.       my_friendly_assert (DECL_IGNORED_P (olddecl) == DECL_IGNORED_P (newdecl),
  2766.               139);
  2767. #endif
  2768.     }
  2769.  
  2770.   /* Special handling ensues if new decl is a function definition.  */
  2771.   new_defines_function = (TREE_CODE (newdecl) == FUNCTION_DECL
  2772.               && DECL_INITIAL (newdecl) != NULL_TREE);
  2773.  
  2774.   /* Optionally warn about more than one declaration for the same name,
  2775.      but don't warn about a function declaration followed by a definition.  */
  2776.   if (warn_redundant_decls
  2777.       && ! DECL_ARTIFICIAL (olddecl)
  2778.       && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
  2779.       /* Don't warn about extern decl followed by (tentative) definition.  */
  2780.       && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)))
  2781.     {
  2782.       cp_warning ("redundant redeclaration of `%D' in same scope", newdecl);
  2783.       cp_warning_at ("previous declaration of `%D'", olddecl);
  2784.     }
  2785.  
  2786.   /* Copy all the DECL_... slots specified in the new decl
  2787.      except for any that we copy here from the old type.  */
  2788.  
  2789.   if (types_match)
  2790.     {
  2791.       /* Automatically handles default parameters.  */
  2792.       tree oldtype = TREE_TYPE (olddecl);
  2793.       tree newtype;
  2794.  
  2795.       /* Make sure we put the new type in the same obstack as the old one.  */
  2796.       if (oldtype)
  2797.     push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype));
  2798.       else
  2799.     {
  2800.       push_obstacks_nochange ();
  2801.       end_temporary_allocation ();
  2802.     }
  2803.  
  2804.       /* Merge the data types specified in the two decls.  */
  2805.       newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  2806.  
  2807.       if (TREE_CODE (newdecl) == VAR_DECL)
  2808.     DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
  2809.       /* Do this after calling `common_type' so that default
  2810.      parameters don't confuse us.  */
  2811.       else if (TREE_CODE (newdecl) == FUNCTION_DECL
  2812.       && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))
  2813.           != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl))))
  2814.     {
  2815.       tree ctype = NULL_TREE;
  2816.       ctype = DECL_CLASS_CONTEXT (newdecl);
  2817.       TREE_TYPE (newdecl) = build_exception_variant (newtype,
  2818.                              TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)));
  2819.       TREE_TYPE (olddecl) = build_exception_variant (newtype,
  2820.                              TYPE_RAISES_EXCEPTIONS (oldtype));
  2821.  
  2822.       if (! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  2823.         {
  2824.           cp_error ("declaration of `%D' throws different exceptions...",
  2825.             newdecl);
  2826.           cp_error_at ("...from previous declaration here", olddecl);
  2827.         }
  2828.     }
  2829.       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
  2830.  
  2831.       /* Lay the type out, unless already done.  */
  2832.       if (oldtype != TREE_TYPE (newdecl)
  2833.       && TREE_TYPE (newdecl) != error_mark_node)
  2834.     layout_type (TREE_TYPE (newdecl));
  2835.  
  2836.       if (TREE_CODE (newdecl) == VAR_DECL
  2837.       || TREE_CODE (newdecl) == PARM_DECL
  2838.       || TREE_CODE (newdecl) == RESULT_DECL
  2839.       || TREE_CODE (newdecl) == FIELD_DECL
  2840.       || TREE_CODE (newdecl) == TYPE_DECL)
  2841.     layout_decl (newdecl, 0);
  2842.  
  2843.       /* Merge the type qualifiers.  */
  2844.       if (TREE_READONLY (newdecl))
  2845.     TREE_READONLY (olddecl) = 1;
  2846.       if (TREE_THIS_VOLATILE (newdecl))
  2847.     TREE_THIS_VOLATILE (olddecl) = 1;
  2848.  
  2849.       /* Merge the initialization information.  */
  2850.       if (DECL_INITIAL (newdecl) == NULL_TREE
  2851.       && DECL_INITIAL (olddecl) != NULL_TREE)
  2852.     {
  2853.       DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2854.       DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
  2855.       DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
  2856.     }
  2857.  
  2858.       /* Merge the section attribute.
  2859.          We want to issue an error if the sections conflict but that must be
  2860.      done later in decl_attributes since we are called before attributes
  2861.      are assigned.  */
  2862.       if (DECL_SECTION_NAME (newdecl) == NULL_TREE)
  2863.     DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl);
  2864.  
  2865.       /* Keep the old rtl since we can safely use it, unless it's the
  2866.      call to abort() used for abstract virtuals.  */
  2867.       if ((DECL_LANG_SPECIFIC (olddecl)
  2868.        && !DECL_ABSTRACT_VIRTUAL_P (olddecl))
  2869.       || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl))
  2870.     DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2871.  
  2872.       pop_obstacks ();
  2873.     }
  2874.   /* If cannot merge, then use the new type and qualifiers,
  2875.      and don't preserve the old rtl.  */
  2876.   else
  2877.     {
  2878.       /* Clean out any memory we had of the old declaration.  */
  2879.       tree oldstatic = value_member (olddecl, static_aggregates);
  2880.       if (oldstatic)
  2881.     TREE_VALUE (oldstatic) = error_mark_node;
  2882.  
  2883.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  2884.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  2885.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  2886.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  2887.     }
  2888.  
  2889.   /* Merge the storage class information.  */
  2890.   DECL_WEAK (newdecl) |= DECL_WEAK (olddecl);
  2891.   TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  2892.   TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
  2893.   if (! DECL_EXTERNAL (olddecl))
  2894.     DECL_EXTERNAL (newdecl) = 0;
  2895.  
  2896.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2897.     {
  2898.       DECL_C_STATIC (newdecl) = DECL_C_STATIC (olddecl);
  2899.       DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
  2900.       DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
  2901.     }
  2902.  
  2903.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2904.     {
  2905.       DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl);
  2906.  
  2907.       /* If either decl says `inline', this fn is inline, unless its
  2908.          definition was passed already.  */
  2909.       if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE)
  2910.     DECL_INLINE (olddecl) = 1;
  2911.       DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
  2912.  
  2913.       if (! types_match)
  2914.     {
  2915.       DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl);
  2916.       DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl);
  2917.       DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
  2918.       DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
  2919.       DECL_RTL (olddecl) = DECL_RTL (newdecl);
  2920.     }
  2921.       if (new_defines_function)
  2922.     /* If defining a function declared with other language
  2923.        linkage, use the previously declared language linkage.  */
  2924.     DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl);
  2925.       else
  2926.     {
  2927.       /* If redeclaring a builtin function, and not a definition,
  2928.          it stays built in.  */
  2929.       if (DECL_BUILT_IN (olddecl))
  2930.         {
  2931.           DECL_BUILT_IN (newdecl) = 1;
  2932.           DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
  2933.           /* If we're keeping the built-in definition, keep the rtl,
  2934.          regardless of declaration matches.  */
  2935.           DECL_RTL (newdecl) = DECL_RTL (olddecl);
  2936.         }
  2937.       else
  2938.         DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  2939.  
  2940.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  2941.       if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl)))
  2942.         /* Previously saved insns go together with
  2943.            the function's previous definition.  */
  2944.         DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  2945.       /* Don't clear out the arguments if we're redefining a function.  */
  2946.       if (DECL_ARGUMENTS (olddecl))
  2947.         DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  2948.     }
  2949.       if (DECL_LANG_SPECIFIC (olddecl))
  2950.     DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl);
  2951.     }
  2952.  
  2953. #if defined (_WIN32) && defined (NEXT_PDO)
  2954.     /* If this decl had DECL_DLLIMPORT set, then copy that */
  2955.     DECL_DLLIMPORT(newdecl) = DECL_DLLIMPORT(olddecl);
  2956. #endif /* _WIN32 */
  2957.  
  2958.   if (TREE_CODE (newdecl) == NAMESPACE_DECL)
  2959.     {
  2960.       NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
  2961.     }
  2962.  
  2963.   if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  2964.     {
  2965.       if (DECL_TEMPLATE_INFO (olddecl)->length)
  2966.     DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
  2967.       DECL_TEMPLATE_MEMBERS (newdecl) = DECL_TEMPLATE_MEMBERS (olddecl);
  2968.       DECL_TEMPLATE_INSTANTIATIONS (newdecl)
  2969.     = DECL_TEMPLATE_INSTANTIATIONS (olddecl);
  2970.       if (DECL_CHAIN (newdecl) == NULL_TREE)
  2971.     DECL_CHAIN (newdecl) = DECL_CHAIN (olddecl);
  2972.     }
  2973.   
  2974.   /* Now preserve various other info from the definition.  */
  2975.   TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
  2976.   TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
  2977.   DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
  2978.   DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl);
  2979.  
  2980.   /* Don't really know how much of the language-specific
  2981.      values we should copy from old to new.  */
  2982.   if (DECL_LANG_SPECIFIC (olddecl))
  2983.     {
  2984.       DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
  2985.       DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
  2986.       DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
  2987.     }
  2988.  
  2989.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2990.     {
  2991.       int function_size;
  2992.       struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl);
  2993.       struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl);
  2994.  
  2995.       function_size = sizeof (struct tree_decl);
  2996.  
  2997.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  2998.          (char *) olddecl + sizeof (struct tree_common),
  2999.          function_size - sizeof (struct tree_common));
  3000.  
  3001.       /* Can we safely free the storage used by newdecl?  */
  3002.  
  3003. #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \
  3004.           & ~ obstack_alignment_mask (&permanent_obstack))
  3005.  
  3006.       if ((char *)newdecl + ROUND (function_size)
  3007.       + ROUND (sizeof (struct lang_decl))
  3008.       == obstack_next_free (&permanent_obstack))
  3009.     {
  3010.       DECL_MAIN_VARIANT (newdecl) = olddecl;
  3011.       DECL_LANG_SPECIFIC (olddecl) = ol;
  3012.       bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl));
  3013.  
  3014.       obstack_free (&permanent_obstack, newdecl);
  3015.     }
  3016.       else if (LANG_DECL_PERMANENT (ol))
  3017.     {
  3018.       if (DECL_MAIN_VARIANT (olddecl) == olddecl)
  3019.         {
  3020.           /* Save these lang_decls that would otherwise be lost.  */
  3021.           extern tree free_lang_decl_chain;
  3022.           tree free_lang_decl = (tree) ol;
  3023.           TREE_CHAIN (free_lang_decl) = free_lang_decl_chain;
  3024.           free_lang_decl_chain = free_lang_decl;
  3025.         }
  3026.       else
  3027.         {
  3028.           /* Storage leak.  */
  3029.         }
  3030.     }
  3031.     }
  3032.   else
  3033.     {
  3034.       bcopy ((char *) newdecl + sizeof (struct tree_common),
  3035.          (char *) olddecl + sizeof (struct tree_common),
  3036.          sizeof (struct tree_decl) - sizeof (struct tree_common)
  3037.          + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *));
  3038.     }
  3039.  
  3040.   DECL_UID (olddecl) = olddecl_uid;
  3041.   if (olddecl_friend)
  3042.     DECL_FRIEND_P (olddecl) = 1;
  3043.  
  3044.   return 1;
  3045. }
  3046.  
  3047. /* Record a decl-node X as belonging to the current lexical scope.
  3048.    Check for errors (such as an incompatible declaration for the same
  3049.    name already seen in the same scope).
  3050.  
  3051.    Returns either X or an old decl for the same name.
  3052.    If an old decl is returned, it may have been smashed
  3053.    to agree with what X says.  */
  3054.  
  3055. tree
  3056. pushdecl (x)
  3057.      tree x;
  3058. {
  3059.   register tree t;
  3060. #if 0 /* not yet, should get fixed properly later */
  3061.   register tree name;
  3062. #else
  3063.   register tree name = DECL_ASSEMBLER_NAME (x);
  3064. #endif
  3065.   register struct binding_level *b = current_binding_level;
  3066.  
  3067. #if 0
  3068.   static int nglobals; int len;
  3069.  
  3070.   len = list_length (global_binding_level->names);
  3071.   if (len < nglobals)
  3072.     my_friendly_abort (8);
  3073.   else if (len > nglobals)
  3074.     nglobals = len;
  3075. #endif
  3076.  
  3077.   if (x != current_function_decl
  3078.       /* Don't change DECL_CONTEXT of virtual methods.  */
  3079.       && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x))
  3080.       && ! DECL_CONTEXT (x))
  3081.     DECL_CONTEXT (x) = current_function_decl;
  3082.   /* A local declaration for a function doesn't constitute nesting.  */
  3083.   if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
  3084.     DECL_CONTEXT (x) = 0;
  3085.  
  3086. #if 0 /* not yet, should get fixed properly later */
  3087.   /* For functions and class static data, we currently look up the encoded
  3088.      form of the name.  For types, we want the real name.  The former will
  3089.      probably be changed soon, according to MDT.  */
  3090.   if (TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL)
  3091.     name = DECL_ASSEMBLER_NAME (x);
  3092.   else
  3093.     name = DECL_NAME (x);
  3094. #else
  3095.   /* Type are looked up using the DECL_NAME, as that is what the rest of the
  3096.      compiler wants to use. */
  3097.   if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL
  3098.       || TREE_CODE (x) == NAMESPACE_DECL)
  3099.     name = DECL_NAME (x);
  3100. #endif
  3101.  
  3102.   if (name)
  3103.     {
  3104.       char *file;
  3105.       int line;
  3106.  
  3107.       t = lookup_name_current_level (name);
  3108.       if (t == error_mark_node)
  3109.     {
  3110.       /* error_mark_node is 0 for a while during initialization!  */
  3111.       t = NULL_TREE;
  3112.       cp_error_at ("`%#D' used prior to declaration", x);
  3113.     }
  3114.  
  3115.       else if (t != NULL_TREE)
  3116.     {
  3117.       file = DECL_SOURCE_FILE (t);
  3118.       line = DECL_SOURCE_LINE (t);
  3119.       if (TREE_CODE (x) == VAR_DECL && DECL_DEAD_FOR_LOCAL (x))
  3120.         ; /* This is OK. */
  3121.       else if (TREE_CODE (t) == PARM_DECL)
  3122.         {
  3123.           if (DECL_CONTEXT (t) == NULL_TREE)
  3124.         fatal ("parse errors have confused me too much");
  3125.         }
  3126.       else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c)
  3127.            || (TREE_CODE (x) == TEMPLATE_DECL
  3128.            && ! DECL_TEMPLATE_IS_CLASS (x)))
  3129.           && is_overloaded_fn (t))
  3130.         /* don't do anything just yet */;
  3131.       else if (t == wchar_decl_node)
  3132.         {
  3133.           if (pedantic && ! DECL_IN_SYSTEM_HEADER (x))
  3134.         cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x));
  3135.  
  3136.           /* Throw away the redeclaration.  */
  3137.           return t;
  3138.         }
  3139.       else if (TREE_CODE (t) != TREE_CODE (x))
  3140.         {
  3141.           if ((TREE_CODE (t) == TYPE_DECL && DECL_ARTIFICIAL (t))
  3142.           || (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
  3143.         {
  3144.           /* We do nothing special here, because C++ does such nasty
  3145.              things with TYPE_DECLs.  Instead, just let the TYPE_DECL
  3146.              get shadowed, and know that if we need to find a TYPE_DECL
  3147.              for a given name, we can look in the IDENTIFIER_TYPE_VALUE
  3148.              slot of the identifier.  */
  3149.           ;
  3150.         }
  3151.           else if (duplicate_decls (x, t))
  3152.         return t;
  3153.         }
  3154.       else if (duplicate_decls (x, t))
  3155.         {
  3156. #if 0
  3157.           /* This is turned off until I have time to do it right (bpk).  */
  3158.  
  3159.           /* Also warn if they did a prototype with `static' on it, but
  3160.          then later left the `static' off.  */
  3161.           if (! TREE_PUBLIC (name) && TREE_PUBLIC (x))
  3162.         {
  3163.           if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t))
  3164.             return t;
  3165.  
  3166.           if (extra_warnings)
  3167.             {
  3168.               cp_warning ("`static' missing from declaration of `%D'",
  3169.                   t);
  3170.               warning_with_file_and_line (file, line,
  3171.                           "previous declaration of `%s'",
  3172.                           decl_as_string (t, 0));
  3173.             }
  3174.  
  3175.           /* Now fix things so it'll do what they expect.  */
  3176.           if (current_function_decl)
  3177.             TREE_PUBLIC (current_function_decl) = 0;
  3178.         }
  3179.           /* Due to interference in memory reclamation (X may be
  3180.          obstack-deallocated at this point), we must guard against
  3181.          one really special case.  [jason: This should be handled
  3182.          by start_function]  */
  3183.           if (current_function_decl == x)
  3184.         current_function_decl = t;
  3185. #endif
  3186.           if (TREE_CODE (t) == TYPE_DECL)
  3187.         SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t));
  3188.           else if (TREE_CODE (t) == FUNCTION_DECL)
  3189.         check_default_args (t);
  3190.  
  3191.           return t;
  3192.         }
  3193.     }
  3194.  
  3195.       if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x))
  3196.     {
  3197.       t = push_overloaded_decl (x, 1);
  3198.       if (t != x || DECL_LANGUAGE (x) == lang_c)
  3199.         return t;
  3200.     }
  3201.       else if (TREE_CODE (x) == TEMPLATE_DECL && ! DECL_TEMPLATE_IS_CLASS (x))
  3202.     return push_overloaded_decl (x, 0);
  3203.  
  3204.       /* If declaring a type as a typedef, and the type has no known
  3205.      typedef name, install this TYPE_DECL as its typedef name.  */
  3206.       if (TREE_CODE (x) == TYPE_DECL)
  3207.     {
  3208.       tree type = TREE_TYPE (x);
  3209.       tree name = (type != error_mark_node) ? TYPE_NAME (type) : x;
  3210.  
  3211.       if (name == NULL_TREE || TREE_CODE (name) != TYPE_DECL)
  3212.         {
  3213.           /* If these are different names, and we're at the global
  3214.          binding level, make two equivalent definitions.  */
  3215.               name = x;
  3216.               if (global_bindings_p ())
  3217.                 TYPE_NAME (type) = x;
  3218.         }
  3219.       else
  3220.         {
  3221.           tree tname = DECL_NAME (name);
  3222.  
  3223.           /* This is a disgusting kludge for dealing with UPTs.  */
  3224.           if (global_bindings_p () && ANON_AGGRNAME_P (tname))
  3225.         {
  3226.             /* do gratuitous C++ typedefing, and make sure that
  3227.                we access this type either through TREE_TYPE field
  3228.                or via the tags list.  */
  3229.           TYPE_NAME (TREE_TYPE (x)) = x;
  3230.           pushtag (tname, TREE_TYPE (x), 0);
  3231.         }
  3232.         }
  3233.       my_friendly_assert (TREE_CODE (name) == TYPE_DECL, 140);
  3234.  
  3235.       /* Don't set nested_typename on template type parms, for instance.
  3236.          Any artificial decls that need DECL_NESTED_TYPENAME will have it
  3237.          set in pushtag.  */
  3238.       if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
  3239.         set_nested_typename (x, current_class_name, DECL_NAME (x), type);
  3240.  
  3241.       if (type != error_mark_node
  3242.           && TYPE_NAME (type)
  3243.           && TYPE_IDENTIFIER (type))
  3244.             set_identifier_type_value_with_scope (DECL_NAME (x), type, b);
  3245.     }
  3246.  
  3247.       /* Multiple external decls of the same identifier ought to match.
  3248.  
  3249.      We get warnings about inline functions where they are defined.
  3250.      We get warnings about other functions from push_overloaded_decl.
  3251.      
  3252.      Avoid duplicate warnings where they are used.  */
  3253.       if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
  3254.     {
  3255.       tree decl;
  3256.  
  3257.       if (IDENTIFIER_GLOBAL_VALUE (name) != NULL_TREE
  3258.           && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  3259.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  3260.         decl = IDENTIFIER_GLOBAL_VALUE (name);
  3261.       else
  3262.         decl = NULL_TREE;
  3263.  
  3264.       if (decl
  3265.           /* If different sort of thing, we already gave an error.  */
  3266.           && TREE_CODE (decl) == TREE_CODE (x)
  3267.           && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl), 1))
  3268.         {
  3269.           cp_pedwarn ("type mismatch with previous external decl", x);
  3270.           cp_pedwarn_at ("previous external decl of `%#D'", decl);
  3271.         }
  3272.     }
  3273.  
  3274.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  3275.      take effect at top level no matter where they are.  */
  3276.       if (flag_traditional && DECL_EXTERNAL (x)
  3277.       && lookup_name (name, 0) == NULL_TREE)
  3278.     b = global_binding_level;
  3279.  
  3280.       /* This name is new in its binding level.
  3281.      Install the new declaration and return it.  */
  3282.       if (b == global_binding_level)
  3283.     {
  3284.       /* Install a global value.  */
  3285.  
  3286.       /* If the first global decl has external linkage,
  3287.          warn if we later see static one.  */
  3288.       if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && DECL_PUBLIC (x))
  3289.         TREE_PUBLIC (name) = 1;
  3290.  
  3291.       /* Don't install an artificial TYPE_DECL if we already have
  3292.          another _DECL with that name.  */
  3293.       if (TREE_CODE (x) != TYPE_DECL
  3294.           || t == NULL_TREE
  3295.           || ! DECL_ARTIFICIAL (x))
  3296.         IDENTIFIER_GLOBAL_VALUE (name) = x;
  3297.  
  3298.       /* Don't forget if the function was used via an implicit decl.  */
  3299.       if (IDENTIFIER_IMPLICIT_DECL (name)
  3300.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  3301.         TREE_USED (x) = 1;
  3302.  
  3303.       /* Don't forget if its address was taken in that way.  */
  3304.       if (IDENTIFIER_IMPLICIT_DECL (name)
  3305.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  3306.         TREE_ADDRESSABLE (x) = 1;
  3307.  
  3308.       /* Warn about mismatches against previous implicit decl.  */
  3309.       if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE
  3310.           /* If this real decl matches the implicit, don't complain.  */
  3311.           && ! (TREE_CODE (x) == FUNCTION_DECL
  3312.             && TREE_TYPE (TREE_TYPE (x)) == integer_type_node))
  3313.         cp_warning
  3314.           ("`%D' was previously implicitly declared to return `int'", x);
  3315.  
  3316.       /* If new decl is `static' and an `extern' was seen previously,
  3317.          warn about it.  */
  3318.       if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t))
  3319.         warn_extern_redeclared_static (x, t);
  3320.     }
  3321.       else
  3322.     {
  3323.       /* Here to install a non-global value.  */
  3324.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  3325.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  3326.  
  3327.       /* Don't install an artificial TYPE_DECL if we already have
  3328.          another _DECL with that name.  */
  3329.       if (TREE_CODE (x) != TYPE_DECL
  3330.           || t == NULL_TREE
  3331.           || ! DECL_ARTIFICIAL (x))
  3332.         {
  3333.           b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  3334.           IDENTIFIER_LOCAL_VALUE (name) = x;
  3335.         }
  3336.  
  3337.       /* If this is a TYPE_DECL, push it into the type value slot.  */
  3338.       if (TREE_CODE (x) == TYPE_DECL)
  3339.         set_identifier_type_value_with_scope (name, TREE_TYPE (x), b);
  3340.  
  3341.       /* Clear out any TYPE_DECL shadowed by a namespace so that
  3342.          we won't think this is a type.  The C struct hack doesn't
  3343.          go through namespaces.  */
  3344.       if (TREE_CODE (x) == NAMESPACE_DECL)
  3345.         set_identifier_type_value_with_scope (name, NULL_TREE, b);
  3346.  
  3347.       /* If this is an extern function declaration, see if we
  3348.          have a global definition or declaration for the function.  */
  3349.       if (oldlocal == NULL_TREE
  3350.           && DECL_EXTERNAL (x)
  3351.           && oldglobal != NULL_TREE
  3352.           && TREE_CODE (x) == FUNCTION_DECL
  3353.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  3354.         {
  3355.           /* We have one.  Their types must agree.  */
  3356.           if (decls_match (x, oldglobal))
  3357.         /* OK */;
  3358.           else
  3359.         {
  3360.           cp_warning ("extern declaration of `%#D' doesn't match", x);
  3361.           cp_warning_at ("global declaration `%#D'", oldglobal);
  3362.         }
  3363.         }
  3364.       /* If we have a local external declaration,
  3365.          and no file-scope declaration has yet been seen,
  3366.          then if we later have a file-scope decl it must not be static.  */
  3367.       if (oldlocal == NULL_TREE
  3368.           && oldglobal == NULL_TREE
  3369.           && DECL_EXTERNAL (x)
  3370.           && TREE_PUBLIC (x))
  3371.         {
  3372.           TREE_PUBLIC (name) = 1;
  3373.         }
  3374.  
  3375.       if (DECL_FROM_INLINE (x))
  3376.         /* Inline decls shadow nothing.  */;
  3377.  
  3378.       /* Warn if shadowing an argument at the top level of the body.  */
  3379.       else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x)
  3380.           && TREE_CODE (oldlocal) == PARM_DECL
  3381.           && TREE_CODE (x) != PARM_DECL)
  3382.         {
  3383.           /* Go to where the parms should be and see if we
  3384.          find them there.  */
  3385.           struct binding_level *b = current_binding_level->level_chain;
  3386.  
  3387.           if (cleanup_label)
  3388.         b = b->level_chain;
  3389.  
  3390.           /* ARM $8.3 */
  3391.           if (b->parm_flag == 1)
  3392.         cp_error ("declaration of `%#D' shadows a parameter", name);
  3393.         }
  3394.       else if (oldlocal != NULL_TREE && b->is_for_scope
  3395.            && !DECL_DEAD_FOR_LOCAL (oldlocal))
  3396.         {
  3397.           warning ("variable `%s' shadows local",
  3398.                IDENTIFIER_POINTER (name));
  3399.           cp_warning_at ("  this is the shadowed declaration", oldlocal);
  3400.         }           
  3401.       /* Maybe warn if shadowing something else.  */
  3402.       else if (warn_shadow && !DECL_EXTERNAL (x)
  3403.            /* No shadow warnings for internally generated vars.  */
  3404.            && ! DECL_ARTIFICIAL (x)
  3405.            /* No shadow warnings for vars made for inlining.  */
  3406.            && ! DECL_FROM_INLINE (x))
  3407.         {
  3408.           char *warnstring = NULL;
  3409.  
  3410.           if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL)
  3411.         warnstring = "declaration of `%s' shadows a parameter";
  3412.           else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE
  3413.                && current_class_decl
  3414.                && !TREE_STATIC (name))
  3415.         warnstring = "declaration of `%s' shadows a member of `this'";
  3416.           else if (oldlocal != NULL_TREE)
  3417.         warnstring = "declaration of `%s' shadows previous local";
  3418.           else if (oldglobal != NULL_TREE)
  3419.         warnstring = "declaration of `%s' shadows global declaration";
  3420.  
  3421.           if (warnstring)
  3422.         warning (warnstring, IDENTIFIER_POINTER (name));
  3423.         }
  3424.     }
  3425.  
  3426.       if (TREE_CODE (x) == FUNCTION_DECL)
  3427.     check_default_args (x);
  3428.  
  3429.       /* Keep count of variables in this level with incomplete type.  */
  3430.       if (TREE_CODE (x) == VAR_DECL
  3431.       && TREE_TYPE (x) != error_mark_node
  3432.       && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
  3433.            && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE))
  3434.           /* RTTI TD entries are created while defining the type_info.  */
  3435.           || (TYPE_LANG_SPECIFIC (TREE_TYPE (x))
  3436.           && TYPE_BEING_DEFINED (TREE_TYPE (x)))))
  3437.     b->incomplete = tree_cons (NULL_TREE, x, b->incomplete);
  3438.     }
  3439.  
  3440.   /* Put decls on list in reverse order.
  3441.      We will reverse them later if necessary.  */
  3442.   TREE_CHAIN (x) = b->names;
  3443.   b->names = x;
  3444.   if (! (b != global_binding_level || TREE_PERMANENT (x)))
  3445.     my_friendly_abort (124);
  3446.  
  3447.   return x;
  3448. }
  3449.  
  3450. /* Same as pushdecl, but define X in binding-level LEVEL. */
  3451.  
  3452. static tree
  3453. pushdecl_with_scope (x, level)
  3454.      tree x;
  3455.      struct binding_level *level;
  3456. {
  3457.   register struct binding_level *b = current_binding_level;
  3458.  
  3459.   current_binding_level = level;
  3460.   x = pushdecl (x);
  3461.   current_binding_level = b;
  3462.   return x;
  3463. }
  3464.  
  3465. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL,
  3466.    if appropriate.  */
  3467. tree
  3468. pushdecl_top_level (x)
  3469.      tree x;
  3470. {
  3471.   register struct binding_level *b = inner_binding_level;
  3472.   register tree t = pushdecl_with_scope (x, global_binding_level);
  3473.  
  3474.   /* Now, the type_shadowed stack may screw us.  Munge it so it does
  3475.      what we want.  */
  3476.   if (TREE_CODE (x) == TYPE_DECL)
  3477.     {
  3478.       tree name = DECL_NAME (x);
  3479.       tree newval;
  3480.       tree *ptr = (tree *)0;
  3481.       for (; b != global_binding_level; b = b->level_chain)
  3482.         {
  3483.           tree shadowed = b->type_shadowed;
  3484.           for (; shadowed; shadowed = TREE_CHAIN (shadowed))
  3485.             if (TREE_PURPOSE (shadowed) == name)
  3486.               {
  3487.         ptr = &TREE_VALUE (shadowed);
  3488.         /* Can't break out of the loop here because sometimes
  3489.            a binding level will have duplicate bindings for
  3490.            PT names.  It's gross, but I haven't time to fix it.  */
  3491.               }
  3492.         }
  3493.       newval = TREE_TYPE (x);
  3494.       if (ptr == (tree *)0)
  3495.         {
  3496.           /* @@ This shouldn't be needed.  My test case "zstring.cc" trips
  3497.              up here if this is changed to an assertion.  --KR  */
  3498.       SET_IDENTIFIER_TYPE_VALUE (name, newval);
  3499.     }
  3500.       else
  3501.         {
  3502. #if 0
  3503.       /* Disabled this 11/10/92, since there are many cases which
  3504.          behave just fine when *ptr doesn't satisfy either of these.
  3505.          For example, nested classes declared as friends of their enclosing
  3506.          class will not meet this criteria.  (bpk) */
  3507.       my_friendly_assert (*ptr == NULL_TREE || *ptr == newval, 141);
  3508. #endif
  3509.       *ptr = newval;
  3510.         }
  3511.     }
  3512.   return t;
  3513. }
  3514.  
  3515. /* Like push_overloaded_decl, only it places X in GLOBAL_BINDING_LEVEL,
  3516.    if appropriate.  */
  3517. void
  3518. push_overloaded_decl_top_level (x, forget)
  3519.      tree x;
  3520.      int forget;
  3521. {
  3522.   struct binding_level *b = current_binding_level;
  3523.  
  3524.   current_binding_level = global_binding_level;
  3525.   push_overloaded_decl (x, forget);
  3526.   current_binding_level = b;
  3527. }
  3528.  
  3529. /* Make the declaration of X appear in CLASS scope.  */
  3530. tree
  3531. pushdecl_class_level (x)
  3532.      tree x;
  3533. {
  3534.   /* Don't use DECL_ASSEMBLER_NAME here!  Everything that looks in class
  3535.      scope looks for the pre-mangled name.  */
  3536.   register tree name = DECL_NAME (x);
  3537.  
  3538.   if (name)
  3539.     {
  3540.       if (TYPE_BEING_DEFINED (current_class_type))
  3541.     {
  3542.       /* Check for inconsistent use of this name in the class body.
  3543.          Types, enums, and static vars are checked here; other
  3544.          members are checked in finish_struct.  */
  3545.       tree icv = IDENTIFIER_CLASS_VALUE (name);
  3546.  
  3547.       if (icv
  3548.           /* Don't complain about inherited names.  */
  3549.           && id_in_current_class (name)
  3550.           /* Or shadowed tags.  */
  3551.           && !(TREE_CODE (icv) == TYPE_DECL
  3552.            && DECL_CONTEXT (icv) == current_class_type))
  3553.         {
  3554.           cp_error ("declaration of identifier `%D' as `%#D'", name, x);
  3555.           cp_error_at ("conflicts with previous use in class as `%#D'",
  3556.                icv);
  3557.         }
  3558.     }
  3559.  
  3560.       push_class_level_binding (name, x);
  3561.       if (TREE_CODE (x) == TYPE_DECL)
  3562.     {
  3563.       set_identifier_type_value (name, TREE_TYPE (x));
  3564.  
  3565.       /* Don't set nested_typename on template type parms, for instance.
  3566.          Any artificial decls that need DECL_NESTED_TYPENAME will have it
  3567.          set in pushtag.  */
  3568.       if (! DECL_NESTED_TYPENAME (x) && ! DECL_ARTIFICIAL (x))
  3569.         set_nested_typename (x, current_class_name, name, TREE_TYPE (x));
  3570.     }
  3571.     }
  3572.   return x;
  3573. }
  3574.  
  3575. /* This function is used to push the mangled decls for nested types into
  3576.    the appropriate scope.  Previously pushdecl_top_level was used, but that
  3577.    is incorrect for members of local classes.  */
  3578. tree
  3579. pushdecl_nonclass_level (x)
  3580.      tree x;
  3581. {
  3582.   struct binding_level *b = current_binding_level;
  3583.  
  3584. #if 0
  3585.   /* Get out of class scope -- this isn't necessary, because class scope
  3586.      doesn't make it into current_binding_level.  */
  3587.   while (b->parm_flag == 2)
  3588.     b = b->level_chain;
  3589. #else
  3590.   my_friendly_assert (b->parm_flag != 2, 180);
  3591. #endif
  3592.  
  3593.   /* Get out of template binding levels */
  3594.   while (b->pseudo_global)
  3595.     b = b->level_chain;
  3596.  
  3597.   pushdecl_with_scope (x, b);
  3598. }
  3599.  
  3600. /* Make the declaration(s) of X appear in CLASS scope
  3601.    under the name NAME.  */
  3602. void
  3603. push_class_level_binding (name, x)
  3604.      tree name;
  3605.      tree x;
  3606. {
  3607.   if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)
  3608.       && purpose_member (name, class_binding_level->class_shadowed))
  3609.     return;
  3610.  
  3611.   maybe_push_cache_obstack ();
  3612.   class_binding_level->class_shadowed
  3613.       = tree_cons (name, IDENTIFIER_CLASS_VALUE (name),
  3614.            class_binding_level->class_shadowed);
  3615.   pop_obstacks ();
  3616.   IDENTIFIER_CLASS_VALUE (name) = x;
  3617.   obstack_ptr_grow (&decl_obstack, x);
  3618. }
  3619.  
  3620. /* Tell caller how to interpret a TREE_LIST which contains
  3621.    chains of FUNCTION_DECLS.  */
  3622. int
  3623. overloaded_globals_p (list)
  3624.      tree list;
  3625. {
  3626.   my_friendly_assert (TREE_CODE (list) == TREE_LIST, 142);
  3627.  
  3628.   /* Don't commit caller to seeing them as globals.  */
  3629.   if (TREE_NONLOCAL_FLAG (list))
  3630.     return -1;
  3631.   /* Do commit caller to seeing them as globals.  */
  3632.   if (TREE_CODE (TREE_PURPOSE (list)) == IDENTIFIER_NODE)
  3633.     return 1;
  3634.   /* Do commit caller to not seeing them as globals.  */
  3635.   return 0;
  3636. }
  3637.  
  3638. /* DECL is a FUNCTION_DECL which may have other definitions already in
  3639.    place.  We get around this by making the value of the identifier point
  3640.    to a list of all the things that want to be referenced by that name.  It
  3641.    is then up to the users of that name to decide what to do with that
  3642.    list.
  3643.  
  3644.    DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT
  3645.    slot.  It is dealt with the same way.
  3646.  
  3647.    The value returned may be a previous declaration if we guessed wrong
  3648.    about what language DECL should belong to (C or C++).  Otherwise,
  3649.    it's always DECL (and never something that's not a _DECL).  */
  3650. tree
  3651. push_overloaded_decl (decl, forgettable)
  3652.      tree decl;
  3653.      int forgettable;
  3654. {
  3655.   tree orig_name = DECL_NAME (decl);
  3656.   tree old;
  3657.   int doing_global = (global_bindings_p () || ! forgettable
  3658.               || flag_traditional || pseudo_global_level_p ());
  3659.  
  3660.   if (doing_global)
  3661.     {
  3662.       old = IDENTIFIER_GLOBAL_VALUE (orig_name);
  3663.       if (old && TREE_CODE (old) == FUNCTION_DECL
  3664.       && DECL_ARTIFICIAL (old)
  3665.       && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
  3666.     {
  3667.       if (duplicate_decls (decl, old))
  3668.         return old;
  3669.       old = NULL_TREE;
  3670.     }
  3671.     }
  3672.   else
  3673.     {
  3674.       old = IDENTIFIER_LOCAL_VALUE (orig_name);
  3675.  
  3676.       if (! purpose_member (orig_name, current_binding_level->shadowed))
  3677.     {
  3678.       current_binding_level->shadowed
  3679.         = tree_cons (orig_name, old, current_binding_level->shadowed);
  3680.       old = NULL_TREE;
  3681.     }
  3682.     }
  3683.  
  3684.   if (old)
  3685.     {
  3686. #if 0
  3687.       /* We cache the value of builtin functions as ADDR_EXPRs
  3688.      in the name space.  Convert it to some kind of _DECL after
  3689.      remembering what to forget.  */
  3690.       if (TREE_CODE (old) == ADDR_EXPR)
  3691.     old = TREE_OPERAND (old, 0);
  3692.       else
  3693. #endif
  3694.       if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old))
  3695.     {
  3696.       tree t = TREE_TYPE (old);
  3697.       if (IS_AGGR_TYPE (t) && warn_shadow)
  3698.         cp_warning ("`%#D' hides constructor for `%#T'", decl, t);
  3699.       old = NULL_TREE;
  3700.     }
  3701.       else if (is_overloaded_fn (old))
  3702.         {
  3703.           tree tmp;
  3704.       
  3705.       for (tmp = get_first_fn (old); tmp; tmp = DECL_CHAIN (tmp))
  3706.         if (decl == tmp || duplicate_decls (decl, tmp))
  3707.           return tmp;
  3708.     }
  3709.       else
  3710.     {
  3711.       cp_error_at ("previous non-function declaration `%#D'", old);
  3712.       cp_error ("conflicts with function declaration `%#D'", decl);
  3713.       return decl;
  3714.     }
  3715.     }
  3716.  
  3717.   if (old || TREE_CODE (decl) == TEMPLATE_DECL)
  3718.     {
  3719.       if (old && is_overloaded_fn (old))
  3720.     DECL_CHAIN (decl) = get_first_fn (old);
  3721.       else
  3722.     DECL_CHAIN (decl) = NULL_TREE;
  3723.       old = tree_cons (orig_name, decl, NULL_TREE);
  3724.       TREE_TYPE (old) = unknown_type_node;
  3725.     }
  3726.   else
  3727.     /* orig_name is not ambiguous.  */
  3728.     old = decl;
  3729.  
  3730.   if (doing_global)
  3731.     IDENTIFIER_GLOBAL_VALUE (orig_name) = old;
  3732.   else
  3733.     IDENTIFIER_LOCAL_VALUE (orig_name) = old;
  3734.  
  3735.   return decl;
  3736. }
  3737.  
  3738. /* Generate an implicit declaration for identifier FUNCTIONID
  3739.    as a function of type int ().  Print a warning if appropriate.  */
  3740.  
  3741. tree
  3742. implicitly_declare (functionid)
  3743.      tree functionid;
  3744. {
  3745.   register tree decl;
  3746.   int temp = allocation_temporary_p ();
  3747.  
  3748.   push_obstacks_nochange ();
  3749.  
  3750.   /* Save the decl permanently so we can warn if definition follows.
  3751.      In ANSI C, warn_implicit is usually false, so the saves little space.
  3752.      But in C++, it's usually true, hence the extra code.  */
  3753.   if (temp && (flag_traditional || !warn_implicit || toplevel_bindings_p ()))
  3754.     end_temporary_allocation ();
  3755.  
  3756.   /* We used to reuse an old implicit decl here,
  3757.      but this loses with inline functions because it can clobber
  3758.      the saved decl chains.  */
  3759.   decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type);
  3760.  
  3761.   DECL_EXTERNAL (decl) = 1;
  3762.   TREE_PUBLIC (decl) = 1;
  3763.  
  3764.   /* ANSI standard says implicit declarations are in the innermost block.
  3765.      So we record the decl in the standard fashion.
  3766.      If flag_traditional is set, pushdecl does it top-level.  */
  3767.   pushdecl (decl);
  3768.   rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
  3769.  
  3770.   if (warn_implicit
  3771.       /* Only one warning per identifier.  */
  3772.       && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE)
  3773.     {
  3774.       cp_pedwarn ("implicit declaration of function `%#D'", decl);
  3775.     }
  3776.  
  3777.   SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl);
  3778.  
  3779.   pop_obstacks ();
  3780.  
  3781.   return decl;
  3782. }
  3783.  
  3784. /* Return zero if the declaration NEWDECL is valid
  3785.    when the declaration OLDDECL (assumed to be for the same name)
  3786.    has already been seen.
  3787.    Otherwise return an error message format string with a %s
  3788.    where the identifier should go.  */
  3789.  
  3790. static char *
  3791. redeclaration_error_message (newdecl, olddecl)
  3792.      tree newdecl, olddecl;
  3793. {
  3794.   if (TREE_CODE (newdecl) == TYPE_DECL)
  3795.     {
  3796.       /* Because C++ can put things into name space for free,
  3797.      constructs like "typedef struct foo { ... } foo"
  3798.      would look like an erroneous redeclaration.  */
  3799.       if (comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), 0))
  3800.     return 0;
  3801.       else
  3802.     return "redefinition of `%#D'";
  3803.     }
  3804.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  3805.     {
  3806.       /* If this is a pure function, its olddecl will actually be
  3807.      the original initialization to `0' (which we force to call
  3808.      abort()).  Don't complain about redefinition in this case.  */
  3809.       if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl))
  3810.     return 0;
  3811.  
  3812.       /* We'll complain about linkage mismatches in
  3813.          warn_extern_redeclared_static.  */
  3814.  
  3815.       /* defining the same name twice is no good.  */
  3816.       if (DECL_INITIAL (olddecl) != NULL_TREE
  3817.       && DECL_INITIAL (newdecl) != NULL_TREE)
  3818.     {
  3819.       if (DECL_NAME (olddecl) == NULL_TREE)
  3820.         return "`%#D' not declared in class";
  3821.       else
  3822.         return "redefinition of `%#D'";
  3823.     }
  3824.       return 0;
  3825.     }
  3826.   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
  3827.     {
  3828.       if (DECL_INITIAL (olddecl) && DECL_INITIAL (newdecl))
  3829.     return "redefinition of `%#D'";
  3830.       return 0;
  3831.     }
  3832.   else if (current_binding_level == global_binding_level)
  3833.     {
  3834.       /* Objects declared at top level:  */
  3835.       /* If at least one is a reference, it's ok.  */
  3836.       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
  3837.     return 0;
  3838.       /* Reject two definitions.  */
  3839.       return "redefinition of `%#D'";
  3840.     }
  3841.   else
  3842.     {
  3843.       /* Objects declared with block scope:  */
  3844.       /* Reject two definitions, and reject a definition
  3845.      together with an external reference.  */
  3846.       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
  3847.     return "redeclaration of `%#D'";
  3848.       return 0;
  3849.     }
  3850. }
  3851.  
  3852. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  3853.    Create one if none exists so far for the current function.
  3854.    This function is called for both label definitions and label references.  */
  3855.  
  3856. tree
  3857. lookup_label (id)
  3858.      tree id;
  3859. {
  3860.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  3861.  
  3862.   if (current_function_decl == NULL_TREE)
  3863.     {
  3864.       error ("label `%s' referenced outside of any function",
  3865.          IDENTIFIER_POINTER (id));
  3866.       return NULL_TREE;
  3867.     }
  3868.  
  3869.   if ((decl == NULL_TREE
  3870.       || DECL_SOURCE_LINE (decl) == 0)
  3871.       && (named_label_uses == NULL_TREE
  3872.       || TREE_PURPOSE (named_label_uses) != current_binding_level->names
  3873.       || TREE_VALUE (named_label_uses) != decl))
  3874.     {
  3875.       named_label_uses
  3876.     = tree_cons (current_binding_level->names, decl, named_label_uses);
  3877.       TREE_TYPE (named_label_uses) = (tree)current_binding_level;
  3878.     }
  3879.  
  3880.   /* Use a label already defined or ref'd with this name.  */
  3881.   if (decl != NULL_TREE)
  3882.     {
  3883.       /* But not if it is inherited and wasn't declared to be inheritable.  */
  3884.       if (DECL_CONTEXT (decl) != current_function_decl
  3885.       && ! C_DECLARED_LABEL_FLAG (decl))
  3886.     return shadow_label (id);
  3887.       return decl;
  3888.     }
  3889.  
  3890.   decl = build_decl (LABEL_DECL, id, void_type_node);
  3891.  
  3892.   /* A label not explicitly declared must be local to where it's ref'd.  */
  3893.   DECL_CONTEXT (decl) = current_function_decl;
  3894.  
  3895.   DECL_MODE (decl) = VOIDmode;
  3896.  
  3897.   /* Say where one reference is to the label,
  3898.      for the sake of the error if it is not defined.  */
  3899.   DECL_SOURCE_LINE (decl) = lineno;
  3900.   DECL_SOURCE_FILE (decl) = input_filename;
  3901.  
  3902.   SET_IDENTIFIER_LABEL_VALUE (id, decl);
  3903.  
  3904.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  3905.   TREE_VALUE (named_label_uses) = decl;
  3906.  
  3907.   return decl;
  3908. }
  3909.  
  3910. /* Make a label named NAME in the current function,
  3911.    shadowing silently any that may be inherited from containing functions
  3912.    or containing scopes.
  3913.  
  3914.    Note that valid use, if the label being shadowed
  3915.    comes from another scope in the same function,
  3916.    requires calling declare_nonlocal_label right away.  */
  3917.  
  3918. tree
  3919. shadow_label (name)
  3920.      tree name;
  3921. {
  3922.   register tree decl = IDENTIFIER_LABEL_VALUE (name);
  3923.  
  3924.   if (decl != NULL_TREE)
  3925.     {
  3926.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3927.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3928.       SET_IDENTIFIER_LABEL_VALUE (decl, NULL_TREE);
  3929.     }
  3930.  
  3931.   return lookup_label (name);
  3932. }
  3933.  
  3934. /* Define a label, specifying the location in the source file.
  3935.    Return the LABEL_DECL node for the label, if the definition is valid.
  3936.    Otherwise return 0.  */
  3937.  
  3938. tree
  3939. define_label (filename, line, name)
  3940.      char *filename;
  3941.      int line;
  3942.      tree name;
  3943. {
  3944.   tree decl = lookup_label (name);
  3945.  
  3946.   /* After labels, make any new cleanups go into their
  3947.      own new (temporary) binding contour.  */
  3948.   current_binding_level->more_cleanups_ok = 0;
  3949.  
  3950.   /* If label with this name is known from an outer context, shadow it.  */
  3951.   if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl)
  3952.     {
  3953.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  3954.       SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE);
  3955.       decl = lookup_label (name);
  3956.     }
  3957.  
  3958.   if (name == get_identifier ("wchar_t"))
  3959.     cp_pedwarn ("label named wchar_t");
  3960.  
  3961.   if (DECL_INITIAL (decl) != NULL_TREE)
  3962.     {
  3963.       cp_error ("duplicate label `%D'", decl);
  3964.       return 0;
  3965.     }
  3966.   else
  3967.     {
  3968.       tree uses, prev;
  3969.       int identified = 0;
  3970.  
  3971.       /* Mark label as having been defined.  */
  3972.       DECL_INITIAL (decl) = error_mark_node;
  3973.       /* Say where in the source.  */
  3974.       DECL_SOURCE_FILE (decl) = filename;
  3975.       DECL_SOURCE_LINE (decl) = line;
  3976.  
  3977.       for (prev = NULL_TREE, uses = named_label_uses;
  3978.        uses;
  3979.        prev = uses, uses = TREE_CHAIN (uses))
  3980.     if (TREE_VALUE (uses) == decl)
  3981.       {
  3982.         struct binding_level *b = current_binding_level;
  3983.         while (b)
  3984.           {
  3985.         tree new_decls = b->names;
  3986.         tree old_decls = ((tree)b == TREE_TYPE (uses)
  3987.                   ? TREE_PURPOSE (uses) : NULL_TREE);
  3988.         while (new_decls != old_decls)
  3989.           {
  3990.             if (TREE_CODE (new_decls) == VAR_DECL
  3991.             /* Don't complain about crossing initialization
  3992.                of internal entities.  They can't be accessed,
  3993.                and they should be cleaned up
  3994.                by the time we get to the label.  */
  3995.             && ! DECL_ARTIFICIAL (new_decls)
  3996.             && ((DECL_INITIAL (new_decls) != NULL_TREE
  3997.                  && DECL_INITIAL (new_decls) != error_mark_node)
  3998.                 || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  3999.               {
  4000.             if (! identified)
  4001.               cp_error ("jump to label `%D'", decl);
  4002.             identified = 1;
  4003.             cp_error_at ("  crosses initialization of `%#D'",
  4004.                      new_decls);
  4005.               }
  4006.             new_decls = TREE_CHAIN (new_decls);
  4007.           }
  4008.         if ((tree)b == TREE_TYPE (uses))
  4009.           break;
  4010.         b = b->level_chain;
  4011.           }
  4012.  
  4013.         if (prev)
  4014.           TREE_CHAIN (prev) = TREE_CHAIN (uses);
  4015.         else
  4016.           named_label_uses = TREE_CHAIN (uses);
  4017.       }
  4018.       current_function_return_value = NULL_TREE;
  4019.       return decl;
  4020.     }
  4021. }
  4022.  
  4023. struct cp_switch
  4024. {
  4025.   struct binding_level *level;
  4026.   struct cp_switch *next;
  4027. };
  4028.  
  4029. static struct cp_switch *switch_stack;
  4030.  
  4031. void
  4032. push_switch ()
  4033. {
  4034.   struct cp_switch *p
  4035.     = (struct cp_switch *) oballoc (sizeof (struct cp_switch));
  4036.   p->level = current_binding_level;
  4037.   p->next = switch_stack;
  4038.   switch_stack = p;
  4039. }
  4040.  
  4041. void
  4042. pop_switch ()
  4043. {
  4044.   switch_stack = switch_stack->next;
  4045. }
  4046.  
  4047. /* Same, but for CASE labels.  If DECL is NULL_TREE, it's the default.  */
  4048. /* XXX Note decl is never actually used. (bpk) */
  4049. void
  4050. define_case_label (decl)
  4051.      tree decl;
  4052. {
  4053.   tree cleanup = last_cleanup_this_contour ();
  4054.   struct binding_level *b = current_binding_level;
  4055.   int identified = 0;
  4056.  
  4057.   if (cleanup)
  4058.     {
  4059.       static int explained = 0;
  4060.       cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup));
  4061.       warning ("where case label appears here");
  4062.       if (!explained)
  4063.     {
  4064.       warning ("(enclose actions of previous case statements requiring");
  4065.       warning ("destructors in their own binding contours.)");
  4066.       explained = 1;
  4067.     }
  4068.     }
  4069.  
  4070.   for (; b && b != switch_stack->level; b = b->level_chain)
  4071.     {
  4072.       tree new_decls = b->names;
  4073.       for (; new_decls; new_decls = TREE_CHAIN (new_decls))
  4074.     {
  4075.       if (TREE_CODE (new_decls) == VAR_DECL
  4076.           /* Don't complain about crossing initialization
  4077.          of internal entities.  They can't be accessed,
  4078.          and they should be cleaned up
  4079.          by the time we get to the label.  */
  4080.           && ! DECL_ARTIFICIAL (new_decls)
  4081.           && ((DECL_INITIAL (new_decls) != NULL_TREE
  4082.            && DECL_INITIAL (new_decls) != error_mark_node)
  4083.           || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls))))
  4084.         {
  4085.           if (! identified)
  4086.         error ("jump to case label");
  4087.           identified = 1;
  4088.           cp_error_at ("  crosses initialization of `%#D'",
  4089.                new_decls);
  4090.         }
  4091.     }
  4092.     }
  4093.  
  4094.   /* After labels, make any new cleanups go into their
  4095.      own new (temporary) binding contour.  */
  4096.  
  4097.   current_binding_level->more_cleanups_ok = 0;
  4098.   current_function_return_value = NULL_TREE;
  4099. }
  4100.  
  4101. /* Return the list of declarations of the current level.
  4102.    Note that this list is in reverse order unless/until
  4103.    you nreverse it; and when you do nreverse it, you must
  4104.    store the result back using `storedecls' or you will lose.  */
  4105.  
  4106. tree
  4107. getdecls ()
  4108. {
  4109.   return current_binding_level->names;
  4110. }
  4111.  
  4112. /* Return the list of type-tags (for structs, etc) of the current level.  */
  4113.  
  4114. tree
  4115. gettags ()
  4116. {
  4117.   return current_binding_level->tags;
  4118. }
  4119.  
  4120. /* Store the list of declarations of the current level.
  4121.    This is done for the parameter declarations of a function being defined,
  4122.    after they are modified in the light of any missing parameters.  */
  4123.  
  4124. static void
  4125. storedecls (decls)
  4126.      tree decls;
  4127. {
  4128.   current_binding_level->names = decls;
  4129. }
  4130.  
  4131. /* Similarly, store the list of tags of the current level.  */
  4132.  
  4133. static void
  4134. storetags (tags)
  4135.      tree tags;
  4136. {
  4137.   current_binding_level->tags = tags;
  4138. }
  4139.  
  4140. /* Given NAME, an IDENTIFIER_NODE,
  4141.    return the structure (or union or enum) definition for that name.
  4142.    Searches binding levels from BINDING_LEVEL up to the global level.
  4143.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  4144.    (but skips any tag-transparent contexts to find one that is
  4145.    meaningful for tags).
  4146.    FORM says which kind of type the caller wants;
  4147.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  4148.    If the wrong kind of type is found, and it's not a template, an error is
  4149.    reported.  */
  4150.  
  4151. static tree
  4152. lookup_tag (form, name, binding_level, thislevel_only)
  4153.      enum tree_code form;
  4154.      struct binding_level *binding_level;
  4155.      tree name;
  4156.      int thislevel_only;
  4157. {
  4158.   register struct binding_level *level;
  4159.  
  4160.   for (level = binding_level; level; level = level->level_chain)
  4161.     {
  4162.       register tree tail;
  4163.       if (ANON_AGGRNAME_P (name))
  4164.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4165.       {
  4166.         /* There's no need for error checking here, because
  4167.            anon names are unique throughout the compilation.  */
  4168.         if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name)
  4169.           return TREE_VALUE (tail);
  4170.       }
  4171.       else
  4172.     for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4173.       {
  4174.         if (TREE_PURPOSE (tail) == name)
  4175.           {
  4176.         enum tree_code code = TREE_CODE (TREE_VALUE (tail));
  4177.         /* Should tighten this up; it'll probably permit
  4178.            UNION_TYPE and a struct template, for example.  */
  4179.         if (code != form
  4180.             && !(form != ENUMERAL_TYPE
  4181.              && (code == TEMPLATE_DECL
  4182.                  || code == UNINSTANTIATED_P_TYPE)))
  4183.                
  4184.           {
  4185.             /* Definition isn't the kind we were looking for.  */
  4186.             cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail),
  4187.                   form);
  4188.           }
  4189.         return TREE_VALUE (tail);
  4190.           }
  4191.       }
  4192.       if (thislevel_only && ! level->tag_transparent)
  4193.     return NULL_TREE;
  4194.       if (current_class_type != NULL_TREE && level->level_chain == global_binding_level)
  4195.     {
  4196.       /* Try looking in this class's tags before heading into
  4197.          global binding level.  */
  4198.       tree context = current_class_type;
  4199.       while (context)
  4200.         {
  4201.           switch (TREE_CODE_CLASS (TREE_CODE (context)))
  4202.         {
  4203.         tree these_tags;
  4204.         case 't':
  4205.             these_tags = CLASSTYPE_TAGS (context);
  4206.             if (ANON_AGGRNAME_P (name))
  4207.               while (these_tags)
  4208.             {
  4209.               if (TYPE_IDENTIFIER (TREE_VALUE (these_tags))
  4210.                   == name)
  4211.                 return TREE_VALUE (tail);
  4212.               these_tags = TREE_CHAIN (these_tags);
  4213.             }
  4214.             else
  4215.               while (these_tags)
  4216.             {
  4217.               if (TREE_PURPOSE (these_tags) == name)
  4218.                 {
  4219.                   if (TREE_CODE (TREE_VALUE (these_tags)) != form)
  4220.                 {
  4221.                   cp_error ("`%#D' redeclared as %C in class scope",
  4222.                         TREE_VALUE (tail), form);
  4223.                 }
  4224.                   return TREE_VALUE (tail);
  4225.                 }
  4226.               these_tags = TREE_CHAIN (these_tags);
  4227.             }
  4228.             /* If this type is not yet complete, then don't
  4229.                look at its context.  */
  4230.             if (TYPE_SIZE (context) == NULL_TREE)
  4231.               goto no_context;
  4232.             /* Go to next enclosing type, if any.  */
  4233.             context = DECL_CONTEXT (TYPE_NAME (context));
  4234.             break;
  4235.             case 'd':
  4236.             context = DECL_CONTEXT (context);
  4237.             break;
  4238.             default:
  4239.             my_friendly_abort (10);
  4240.         }
  4241.           continue;
  4242.           no_context:
  4243.           break;
  4244.         }
  4245.     }
  4246.     }
  4247.   return NULL_TREE;
  4248. }
  4249.  
  4250. void
  4251. set_current_level_tags_transparency (tags_transparent)
  4252.      int tags_transparent;
  4253. {
  4254.   current_binding_level->tag_transparent = tags_transparent;
  4255. }
  4256.  
  4257. /* Given a type, find the tag that was defined for it and return the tag name.
  4258.    Otherwise return 0.  However, the value can never be 0
  4259.    in the cases in which this is used.
  4260.  
  4261.    C++: If NAME is non-zero, this is the new name to install.  This is
  4262.    done when replacing anonymous tags with real tag names.  */
  4263.  
  4264. static tree
  4265. lookup_tag_reverse (type, name)
  4266.      tree type;
  4267.      tree name;
  4268. {
  4269.   register struct binding_level *level;
  4270.  
  4271.   for (level = current_binding_level; level; level = level->level_chain)
  4272.     {
  4273.       register tree tail;
  4274.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  4275.     {
  4276.       if (TREE_VALUE (tail) == type)
  4277.         {
  4278.           if (name)
  4279.         TREE_PURPOSE (tail) = name;
  4280.           return TREE_PURPOSE (tail);
  4281.         }
  4282.     }
  4283.     }
  4284.   return NULL_TREE;
  4285. }
  4286.  
  4287. /* Given type TYPE which was not declared in C++ language context,
  4288.    attempt to find a name by which it is referred.  */
  4289. tree
  4290. typedecl_for_tag (tag)
  4291.      tree tag;
  4292. {
  4293.   struct binding_level *b = current_binding_level;
  4294.  
  4295.   if (TREE_CODE (TYPE_NAME (tag)) == TYPE_DECL)
  4296.     return TYPE_NAME (tag);
  4297.  
  4298.   while (b)
  4299.     {
  4300.       tree decls = b->names;
  4301.       while (decls)
  4302.     {
  4303.       if (TREE_CODE (decls) == TYPE_DECL && TREE_TYPE (decls) == tag)
  4304.         break;
  4305.       decls = TREE_CHAIN (decls);
  4306.     }
  4307.       if (decls)
  4308.     return decls;
  4309.       b = b->level_chain;
  4310.     }
  4311.   return NULL_TREE;
  4312. }
  4313.  
  4314. /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL).
  4315.    Return the type value, or NULL_TREE if not found.  */
  4316. static tree
  4317. lookup_nested_type (type, context)
  4318.      tree type;
  4319.      tree context;
  4320. {
  4321.   if (context == NULL_TREE)
  4322.     return NULL_TREE;
  4323.   while (context)
  4324.     {
  4325.       switch (TREE_CODE (context))
  4326.     {
  4327.     case TYPE_DECL:
  4328.       {
  4329.         tree ctype = TREE_TYPE (context);
  4330.         tree match = value_member (type, CLASSTYPE_TAGS (ctype));
  4331.         if (match)
  4332.           return TREE_VALUE (match);
  4333.         context = DECL_CONTEXT (context);
  4334.  
  4335.         /* When we have a nested class whose member functions have
  4336.            local types (e.g., a set of enums), we'll arrive here
  4337.            with the DECL_CONTEXT as the actual RECORD_TYPE node for
  4338.            the enclosing class.  Instead, we want to make sure we
  4339.            come back in here with the TYPE_DECL, not the RECORD_TYPE.  */
  4340.         if (context && TREE_CODE (context) == RECORD_TYPE)
  4341.           context = TREE_CHAIN (context);
  4342.       }
  4343.       break;
  4344.     case FUNCTION_DECL:
  4345.       if (TYPE_NAME (type) && TYPE_IDENTIFIER (type))
  4346.         return lookup_name (TYPE_IDENTIFIER (type), 1);
  4347.       return NULL_TREE;
  4348.     default:
  4349.       my_friendly_abort (12);
  4350.     }
  4351.     }
  4352.   return NULL_TREE;
  4353. }
  4354.  
  4355. /* Look up NAME in the NAMESPACE.  */
  4356. tree
  4357. lookup_namespace_name (namespace, name)
  4358.      tree namespace, name;
  4359. {
  4360.   struct binding_level *b = (struct binding_level *)NAMESPACE_LEVEL (namespace);
  4361.   tree x;
  4362.  
  4363.   for (x = NULL_TREE; b && !x; b = b->level_chain)
  4364.     {
  4365.       for (x = b->names; x; x = TREE_CHAIN (x))
  4366.     if (DECL_NAME (x) == name || DECL_ASSEMBLER_NAME (x) == name)
  4367.       break;
  4368.       /* Must find directly in the namespace.  */
  4369.       break;
  4370.     }
  4371.   return x;
  4372. }
  4373.  
  4374. /* Look up NAME in the current binding level and its superiors in the
  4375.    namespace of variables, functions and typedefs.  Return a ..._DECL
  4376.    node of some kind representing its definition if there is only one
  4377.    such declaration, or return a TREE_LIST with all the overloaded
  4378.    definitions if there are many, or return 0 if it is undefined.
  4379.  
  4380.    If PREFER_TYPE is > 0, we prefer TYPE_DECLs.
  4381.    If PREFER_TYPE is -2, we're being called from yylex(). (UGLY)
  4382.    Otherwise we prefer non-TYPE_DECLs.  */
  4383.  
  4384. tree
  4385. lookup_name_real (name, prefer_type, nonclass)
  4386.      tree name;
  4387.      int prefer_type, nonclass;
  4388. {
  4389.   register tree val;
  4390.   int yylex = 0;
  4391.   tree from_obj = NULL_TREE;
  4392.  
  4393.   if (prefer_type == -2)
  4394.     {
  4395.       extern int looking_for_typename;
  4396.       tree type;
  4397.  
  4398.       yylex = 1;
  4399.       prefer_type = looking_for_typename;
  4400.  
  4401.       if (got_scope)
  4402.     type = got_scope;
  4403.       else if (got_object != error_mark_node)
  4404.     type = got_object;
  4405.       
  4406.       if (type)
  4407.     {
  4408.       if (type == error_mark_node)
  4409.         return error_mark_node;
  4410.       else if (type == void_type_node)
  4411.         val = IDENTIFIER_GLOBAL_VALUE (name);
  4412.       else if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
  4413.            /* TFIXME -- don't do this for UPTs in new model.  */
  4414.            || TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
  4415.         {
  4416.           if (prefer_type > 0)
  4417.         val = create_nested_upt (type, name);
  4418.           else
  4419.         val = NULL_TREE;
  4420.         }
  4421.       else if (TREE_CODE (type) == NAMESPACE_DECL)
  4422.         {
  4423.           val = lookup_namespace_name (type, name);
  4424.         }
  4425.       else if (! IS_AGGR_TYPE (type))
  4426.         /* Someone else will give an error about this if needed. */
  4427.         val = NULL_TREE;
  4428.       else if (TYPE_BEING_DEFINED (type))
  4429.         {
  4430.           val = IDENTIFIER_CLASS_VALUE (name);
  4431.           if (val && DECL_CONTEXT (val) != type)
  4432.         {
  4433.           struct binding_level *b = class_binding_level;
  4434.           for (val = NULL_TREE; b; b = b->level_chain)
  4435.             {
  4436.               tree t = purpose_member (name, b->class_shadowed);
  4437.               if (t && TREE_VALUE (t)
  4438.               && DECL_CONTEXT (TREE_VALUE (t)) == type)
  4439.             {
  4440.               val = TREE_VALUE (t);
  4441.               break;
  4442.             }
  4443.             }
  4444.         }
  4445.           if (val == NULL_TREE
  4446.           && CLASSTYPE_LOCAL_TYPEDECLS (type))
  4447.         val = lookup_field (type, name, 0, 1);
  4448.         }
  4449.       else if (type == current_class_type)
  4450.         val = IDENTIFIER_CLASS_VALUE (name);
  4451.       else
  4452.         val = lookup_field (type, name, 0, prefer_type);
  4453.     }
  4454.       else
  4455.     val = NULL_TREE;
  4456.  
  4457.       if (got_scope)
  4458.     goto done;
  4459.  
  4460.       /* This special lookup only applies to types.  */
  4461.       else if (got_object && val && TREE_CODE (val) == TYPE_DECL)
  4462.     from_obj = val;
  4463.     }
  4464.     
  4465.   if (current_binding_level != global_binding_level
  4466.       && IDENTIFIER_LOCAL_VALUE (name))
  4467.     val = IDENTIFIER_LOCAL_VALUE (name);
  4468.   /* In C++ class fields are between local and global scope,
  4469.      just before the global scope.  */
  4470.   else if (current_class_type != NULL_TREE && ! nonclass)
  4471.     {
  4472.       val = IDENTIFIER_CLASS_VALUE (name);
  4473.       if (val == NULL_TREE
  4474.       && TYPE_BEING_DEFINED (current_class_type)
  4475.       && CLASSTYPE_LOCAL_TYPEDECLS (current_class_type))
  4476.     /* Try to find values from base classes if we are presently
  4477.        defining a type.  We are presently only interested in
  4478.        TYPE_DECLs.  */
  4479.     val = lookup_field (current_class_type, name, 0, 1);
  4480.  
  4481.       /* yylex() calls this with -2, since we should never start digging for
  4482.      the nested name at the point where we haven't even, for example,
  4483.      created the COMPONENT_REF or anything like that.  */
  4484.       if (val == NULL_TREE)
  4485.     val = lookup_nested_field (name, ! yylex);
  4486.  
  4487.       if (val == NULL_TREE)
  4488.     val = IDENTIFIER_GLOBAL_VALUE (name);
  4489.     }
  4490.   else
  4491.     val = IDENTIFIER_GLOBAL_VALUE (name);
  4492.  
  4493.  done:
  4494.   if (val)
  4495.     {
  4496.       if (from_obj && from_obj != val)
  4497.     cp_error ("lookup in the scope of `%#T' does not match lookup in the current scope",
  4498.           got_object);
  4499.  
  4500.       if ((TREE_CODE (val) == TEMPLATE_DECL && looking_for_template)
  4501.       || TREE_CODE (val) == TYPE_DECL || prefer_type <= 0)
  4502.     ;
  4503.       else if (IDENTIFIER_HAS_TYPE_VALUE (name))
  4504.     val = TYPE_NAME (IDENTIFIER_TYPE_VALUE (name));
  4505.       else if (TREE_TYPE (val) == error_mark_node)
  4506.     val = error_mark_node;
  4507.     }
  4508.   else if (from_obj)
  4509.     val = from_obj;
  4510.  
  4511.   return val;
  4512. }
  4513.  
  4514. tree
  4515. lookup_name_nonclass (name)
  4516.      tree name;
  4517. {
  4518.   return lookup_name_real (name, 0, 1);
  4519. }
  4520.  
  4521. tree
  4522. lookup_name (name, prefer_type)
  4523.      tree name;
  4524.      int prefer_type;
  4525. {
  4526.   return lookup_name_real (name, prefer_type, 0);
  4527. }
  4528.  
  4529. /* Similar to `lookup_name' but look only at current binding level.  */
  4530.  
  4531. tree
  4532. lookup_name_current_level (name)
  4533.      tree name;
  4534. {
  4535.   register tree t = NULL_TREE;
  4536.  
  4537.   if (current_binding_level == global_binding_level)
  4538.     {
  4539.       t = IDENTIFIER_GLOBAL_VALUE (name);
  4540.  
  4541.       /* extern "C" function() */
  4542.       if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST)
  4543.     t = TREE_VALUE (t);
  4544.     }
  4545.   else if (IDENTIFIER_LOCAL_VALUE (name) != NULL_TREE)
  4546.     {
  4547.       struct binding_level *b = current_binding_level;
  4548.       while (1)
  4549.     {
  4550.       for (t = b->names; t; t = TREE_CHAIN (t))
  4551.         if (DECL_NAME (t) == name || DECL_ASSEMBLER_NAME (t) == name)
  4552.           goto out;
  4553.       if (b->keep == 2)
  4554.         b = b->level_chain;
  4555.       else
  4556.         break;
  4557.     }
  4558.     out:
  4559.       ;
  4560.     }
  4561.  
  4562.   return t;
  4563. }
  4564.  
  4565. /* Arrange for the user to get a source line number, even when the
  4566.    compiler is going down in flames, so that she at least has a
  4567.    chance of working around problems in the compiler.  We used to
  4568.    call error(), but that let the segmentation fault continue
  4569.    through; now, it's much more passive by asking them to send the
  4570.    maintainers mail about the problem.  */
  4571.  
  4572. static void
  4573. signal_catch (sig)
  4574.      int sig;
  4575. {
  4576.   signal (SIGSEGV, SIG_DFL);
  4577. #ifdef SIGIOT
  4578.   signal (SIGIOT, SIG_DFL);
  4579. #endif
  4580. #ifdef SIGILL
  4581.   signal (SIGILL, SIG_DFL);
  4582. #endif
  4583. #ifdef SIGABRT
  4584.   signal (SIGABRT, SIG_DFL);
  4585. #endif
  4586. #ifdef SIGBUS
  4587.   signal (SIGBUS, SIG_DFL);
  4588. #endif
  4589.   my_friendly_abort (0);
  4590. }
  4591.  
  4592. /* Array for holding types considered "built-in".  These types
  4593.    are output in the module in which `main' is defined.  */
  4594. static tree *builtin_type_tdescs_arr;
  4595. static int builtin_type_tdescs_len, builtin_type_tdescs_max;
  4596.  
  4597. /* Push the declarations of builtin types into the namespace.
  4598.    RID_INDEX, if < RID_MAX is the index of the builtin type
  4599.    in the array RID_POINTERS.  NAME is the name used when looking
  4600.    up the builtin type.  TYPE is the _TYPE node for the builtin type.  */
  4601.  
  4602. static void
  4603. record_builtin_type (rid_index, name, type)
  4604.      enum rid rid_index;
  4605.      char *name;
  4606.      tree type;
  4607. {
  4608.   tree rname = NULL_TREE, tname = NULL_TREE;
  4609.   tree tdecl;
  4610.  
  4611.   if ((int) rid_index < (int) RID_MAX)
  4612.     rname = ridpointers[(int) rid_index];
  4613.   if (name)
  4614.     tname = get_identifier (name);
  4615.  
  4616.   TYPE_BUILT_IN (type) = 1;
  4617.   
  4618.   if (tname)
  4619.     {
  4620. #if 0 /* not yet, should get fixed properly later */
  4621.       tdecl = pushdecl (make_type_decl (tname, type));
  4622. #else
  4623.       tdecl = pushdecl (build_decl (TYPE_DECL, tname, type));
  4624. #endif
  4625.       set_identifier_type_value (tname, NULL_TREE);
  4626.       if ((int) rid_index < (int) RID_MAX)
  4627.     IDENTIFIER_GLOBAL_VALUE (tname) = tdecl;
  4628.     }
  4629.   if (rname != NULL_TREE)
  4630.     {
  4631.       if (tname != NULL_TREE)
  4632.     {
  4633.       set_identifier_type_value (rname, NULL_TREE);
  4634.       IDENTIFIER_GLOBAL_VALUE (rname) = tdecl;
  4635.     }
  4636.       else
  4637.     {
  4638. #if 0 /* not yet, should get fixed properly later */
  4639.       tdecl = pushdecl (make_type_decl (rname, type));
  4640. #else
  4641.       tdecl = pushdecl (build_decl (TYPE_DECL, rname, type));
  4642. #endif
  4643.       set_identifier_type_value (rname, NULL_TREE);
  4644.     }
  4645.     }
  4646.  
  4647.   if (flag_rtti)
  4648.     {
  4649.       if (builtin_type_tdescs_len+5 >= builtin_type_tdescs_max)
  4650.     {
  4651.       builtin_type_tdescs_max *= 2;
  4652.       builtin_type_tdescs_arr
  4653.         = (tree *)xrealloc (builtin_type_tdescs_arr,
  4654.                 builtin_type_tdescs_max * sizeof (tree));
  4655.     }
  4656.       builtin_type_tdescs_arr[builtin_type_tdescs_len++] = type;
  4657.       if (TREE_CODE (type) != POINTER_TYPE)
  4658.     {
  4659.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4660.         = build_pointer_type (type);
  4661.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4662.         = build_pointer_type (build_type_variant (type, 1, 0));
  4663.     }
  4664.       if (TREE_CODE (type) != VOID_TYPE)
  4665.     {
  4666.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4667.         = build_reference_type (type);
  4668.       builtin_type_tdescs_arr[builtin_type_tdescs_len++]
  4669.         = build_reference_type (build_type_variant (type, 1, 0));
  4670.     }
  4671.     }
  4672. }
  4673.  
  4674. static void
  4675. output_builtin_tdesc_entries ()
  4676. {
  4677.   extern struct obstack permanent_obstack;
  4678.  
  4679.   /* If there's more than one main in this file, don't crash.  */
  4680.   if (builtin_type_tdescs_arr == 0)
  4681.     return;
  4682.  
  4683.   push_obstacks (&permanent_obstack, &permanent_obstack);
  4684.   while (builtin_type_tdescs_len > 0)
  4685.     {
  4686.       tree type = builtin_type_tdescs_arr[--builtin_type_tdescs_len];
  4687.       tree tdesc = build_t_desc (type, 0);
  4688.       TREE_ASM_WRITTEN (tdesc) = 0;
  4689.       build_t_desc (type, 2);
  4690.     }
  4691.   free (builtin_type_tdescs_arr);
  4692.   builtin_type_tdescs_arr = 0;
  4693.   pop_obstacks ();
  4694. }
  4695.  
  4696. /* Push overloaded decl, in global scope, with one argument so it
  4697.    can be used as a callback from define_function.  */
  4698. static void
  4699. push_overloaded_decl_1 (x)
  4700.      tree x;
  4701. {
  4702.   push_overloaded_decl (x, 0);
  4703. }
  4704.  
  4705. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  4706.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  4707.  
  4708. #ifdef __GNUC__
  4709. __inline
  4710. #endif
  4711. tree auto_function (name, type, code)
  4712.      tree name, type;
  4713.      enum built_in_function code;
  4714. {
  4715.   return define_function
  4716.     (IDENTIFIER_POINTER (name), type, code, (void (*)())push_overloaded_decl_1,
  4717.      IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type),
  4718.                           0)));
  4719. }
  4720.  
  4721. /* Create the predefined scalar types of C,
  4722.    and some nodes representing standard constants (0, 1, (void *)0).
  4723.    Initialize the global binding level.
  4724.    Make definitions for built-in primitive functions.  */
  4725.  
  4726. void
  4727. init_decl_processing ()
  4728. {
  4729.   tree decl;
  4730.   register tree endlink, int_endlink, double_endlink, ptr_endlink;
  4731.   tree fields[20];
  4732.   /* Either char* or void*.  */
  4733.   tree traditional_ptr_type_node;
  4734.   /* Data type of memcpy.  */
  4735.   tree memcpy_ftype;
  4736. #if 0 /* Not yet.  */
  4737.   /* Data type of strncpy.  */
  4738.   tree strncpy_ftype;
  4739. #endif
  4740.   int wchar_type_size;
  4741.   tree temp;
  4742.   tree array_domain_type;
  4743.   extern int flag_strict_prototype;
  4744.  
  4745.   /* Have to make these distinct before we try using them.  */
  4746.   lang_name_cplusplus = get_identifier ("C++");
  4747.   lang_name_c = get_identifier ("C");
  4748. #ifdef OBJCPLUS
  4749.   lang_name_objc = get_identifier ("Objective-C");
  4750. #endif
  4751.  
  4752.   if (flag_strict_prototype == 2)
  4753.     {
  4754.       if (pedantic)
  4755.     strict_prototypes_lang_c = strict_prototypes_lang_cplusplus;
  4756.     }
  4757.   else
  4758.     strict_prototypes_lang_c = flag_strict_prototype;
  4759.  
  4760.   /* Initially, C.  */
  4761.   current_lang_name = lang_name_c;
  4762.  
  4763.   current_function_decl = NULL_TREE;
  4764.   named_labels = NULL_TREE;
  4765.   named_label_uses = NULL_TREE;
  4766.   current_binding_level = NULL_BINDING_LEVEL;
  4767.   free_binding_level = NULL_BINDING_LEVEL;
  4768.  
  4769.   /* Because most segmentation signals can be traced back into user
  4770.      code, catch them and at least give the user a chance of working
  4771.      around compiler bugs. */
  4772.   signal (SIGSEGV, signal_catch);
  4773.  
  4774.   /* We will also catch aborts in the back-end through signal_catch and
  4775.      give the user a chance to see where the error might be, and to defeat
  4776.      aborts in the back-end when there have been errors previously in their
  4777.      code. */
  4778. #ifdef SIGIOT
  4779.   signal (SIGIOT, signal_catch);
  4780. #endif
  4781. #ifdef SIGILL
  4782.   signal (SIGILL, signal_catch);
  4783. #endif
  4784. #ifdef SIGABRT
  4785.   signal (SIGABRT, signal_catch);
  4786. #endif
  4787. #ifdef SIGBUS
  4788.   signal (SIGBUS, signal_catch);
  4789. #endif
  4790.  
  4791.   gcc_obstack_init (&decl_obstack);
  4792.   if (flag_rtti)
  4793.     {
  4794.       builtin_type_tdescs_max = 100;
  4795.       builtin_type_tdescs_arr = (tree *)xmalloc (100 * sizeof (tree));
  4796.     }
  4797.  
  4798.   /* Must lay these out before anything else gets laid out.  */
  4799.   error_mark_node = make_node (ERROR_MARK);
  4800.   TREE_PERMANENT (error_mark_node) = 1;
  4801.   TREE_TYPE (error_mark_node) = error_mark_node;
  4802.   error_mark_list = build_tree_list (error_mark_node, error_mark_node);
  4803.   TREE_TYPE (error_mark_list) = error_mark_node;
  4804.  
  4805.   /* Make the binding_level structure for global names.  */
  4806.   pushlevel (0);
  4807.   global_binding_level = current_binding_level;
  4808.  
  4809.   this_identifier = get_identifier (THIS_NAME);
  4810.   in_charge_identifier = get_identifier (IN_CHARGE_NAME);
  4811.   pfn_identifier = get_identifier (VTABLE_PFN_NAME);
  4812.   index_identifier = get_identifier (VTABLE_INDEX_NAME);
  4813.   delta_identifier = get_identifier (VTABLE_DELTA_NAME);
  4814.   delta2_identifier = get_identifier (VTABLE_DELTA2_NAME);
  4815.   pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2");
  4816.   if (flag_handle_signatures)
  4817.     {
  4818.       tag_identifier = get_identifier (SIGTABLE_TAG_NAME);
  4819.       vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME);
  4820.       vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME);
  4821.     }
  4822.  
  4823.   /* Define `int' and `char' first so that dbx will output them first.  */
  4824.  
  4825.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  4826.   record_builtin_type (RID_INT, NULL_PTR, integer_type_node);
  4827.  
  4828.   /* Define `char', which is like either `signed char' or `unsigned char'
  4829.      but not the same as either.  */
  4830.  
  4831.   char_type_node =
  4832.     (flag_signed_char
  4833.      ? make_signed_type (CHAR_TYPE_SIZE)
  4834.      : make_unsigned_type (CHAR_TYPE_SIZE));
  4835.   record_builtin_type (RID_CHAR, "char", char_type_node);
  4836.  
  4837.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  4838.   record_builtin_type (RID_LONG, "long int", long_integer_type_node);
  4839.  
  4840.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  4841.   record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node);
  4842.  
  4843.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  4844.   record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node);
  4845.   record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node);
  4846.  
  4847.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  4848.   record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node);
  4849.  
  4850.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  4851.   record_builtin_type (RID_MAX, "long long unsigned int",
  4852.                long_long_unsigned_type_node);
  4853.   record_builtin_type (RID_MAX, "long long unsigned",
  4854.                long_long_unsigned_type_node);
  4855.  
  4856.   /* `unsigned long' is the standard type for sizeof.
  4857.      Traditionally, use a signed type.
  4858.      Note that stddef.h uses `unsigned long',
  4859.      and this must agree, even of long and int are the same size.  */
  4860.   sizetype
  4861.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
  4862.   if (flag_traditional && TREE_UNSIGNED (sizetype))
  4863.     sizetype = signed_type (sizetype);
  4864.  
  4865.   ptrdiff_type_node
  4866.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
  4867.  
  4868.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  4869.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  4870.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  4871.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  4872.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  4873.   TREE_TYPE (TYPE_SIZE (long_long_integer_type_node)) = sizetype;
  4874.   TREE_TYPE (TYPE_SIZE (long_long_unsigned_type_node)) = sizetype;
  4875.  
  4876.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  4877.   record_builtin_type (RID_SHORT, "short int", short_integer_type_node);
  4878.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  4879.   record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node);
  4880.   record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node);
  4881.  
  4882.   /* Define both `signed char' and `unsigned char'.  */
  4883.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  4884.   record_builtin_type (RID_MAX, "signed char", signed_char_type_node);
  4885.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  4886.   record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node);
  4887.  
  4888.   /* These are types that type_for_size and type_for_mode use.  */
  4889.   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
  4890.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
  4891.   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
  4892.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
  4893.   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
  4894.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
  4895.   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
  4896.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
  4897.   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
  4898.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
  4899.   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
  4900.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
  4901.   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
  4902.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
  4903.   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
  4904.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
  4905.  
  4906.   float_type_node = make_node (REAL_TYPE);
  4907.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  4908.   record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node);
  4909.   layout_type (float_type_node);
  4910.  
  4911.   double_type_node = make_node (REAL_TYPE);
  4912.   if (flag_short_double)
  4913.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  4914.   else
  4915.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  4916.   record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node);
  4917.   layout_type (double_type_node);
  4918.  
  4919.   long_double_type_node = make_node (REAL_TYPE);
  4920.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  4921.   record_builtin_type (RID_MAX, "long double", long_double_type_node);
  4922.   layout_type (long_double_type_node);
  4923.  
  4924.   integer_zero_node = build_int_2 (0, 0);
  4925.   TREE_TYPE (integer_zero_node) = integer_type_node;
  4926.   integer_one_node = build_int_2 (1, 0);
  4927.   TREE_TYPE (integer_one_node) = integer_type_node;
  4928.   integer_two_node = build_int_2 (2, 0);
  4929.   TREE_TYPE (integer_two_node) = integer_type_node;
  4930.   integer_three_node = build_int_2 (3, 0);
  4931.   TREE_TYPE (integer_three_node) = integer_type_node;
  4932.  
  4933.   boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE);
  4934.   TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
  4935.   record_builtin_type (RID_BOOL, "bool", boolean_type_node);
  4936.   boolean_false_node = build_int_2 (0, 0);
  4937.   TREE_TYPE (boolean_false_node) = boolean_type_node;
  4938.   boolean_true_node = build_int_2 (1, 0);
  4939.   TREE_TYPE (boolean_true_node) = boolean_type_node;
  4940.  
  4941.   /* These are needed by stor-layout.c.  */
  4942.   size_zero_node = size_int (0);
  4943.   size_one_node = size_int (1);
  4944.  
  4945.   void_type_node = make_node (VOID_TYPE);
  4946.   record_builtin_type (RID_VOID, NULL_PTR, void_type_node);
  4947.   layout_type (void_type_node); /* Uses integer_zero_node.  */
  4948.   void_list_node = build_tree_list (NULL_TREE, void_type_node);
  4949.   TREE_PARMLIST (void_list_node) = 1;
  4950.  
  4951.   null_pointer_node = build_int_2 (0, 0);
  4952.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  4953.   layout_type (TREE_TYPE (null_pointer_node));
  4954.  
  4955.   /* Used for expressions that do nothing, but are not errors.  */
  4956.   void_zero_node = build_int_2 (0, 0);
  4957.   TREE_TYPE (void_zero_node) = void_type_node;
  4958.  
  4959.   string_type_node = build_pointer_type (char_type_node);
  4960.   const_string_type_node =
  4961.     build_pointer_type (build_type_variant (char_type_node, 1, 0));
  4962.   record_builtin_type (RID_MAX, NULL_PTR, string_type_node);
  4963.  
  4964.   /* Make a type to be the domain of a few array types
  4965.      whose domains don't really matter.
  4966.      200 is small enough that it always fits in size_t
  4967.      and large enough that it can hold most function names for the
  4968.      initializations of __FUNCTION__ and __PRETTY_FUNCTION__.  */
  4969.   array_domain_type = build_index_type (build_int_2 (200, 0));
  4970.  
  4971.   /* make a type for arrays of characters.
  4972.      With luck nothing will ever really depend on the length of this
  4973.      array type.  */
  4974.   char_array_type_node
  4975.     = build_array_type (char_type_node, array_domain_type);
  4976.   /* Likewise for arrays of ints.  */
  4977.   int_array_type_node
  4978.     = build_array_type (integer_type_node, array_domain_type);
  4979.  
  4980.   /* This is just some anonymous class type.  Nobody should ever
  4981.      need to look inside this envelope.  */
  4982.   class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE));
  4983.  
  4984.   default_function_type
  4985.     = build_function_type (integer_type_node, NULL_TREE);
  4986.   build_pointer_type (default_function_type);
  4987.  
  4988.   ptr_type_node = build_pointer_type (void_type_node);
  4989.   const_ptr_type_node =
  4990.     build_pointer_type (build_type_variant (void_type_node, 1, 0));
  4991.   record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node);
  4992.   endlink = void_list_node;
  4993.   int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink);
  4994.   double_endlink = tree_cons (NULL_TREE, double_type_node, endlink);
  4995.   ptr_endlink = tree_cons (NULL_TREE, ptr_type_node, endlink);
  4996.  
  4997.   double_ftype_double
  4998.     = build_function_type (double_type_node, double_endlink);
  4999.  
  5000.   double_ftype_double_double
  5001.     = build_function_type (double_type_node,
  5002.                tree_cons (NULL_TREE, double_type_node,
  5003.                       double_endlink));
  5004.  
  5005.   int_ftype_int
  5006.     = build_function_type (integer_type_node, int_endlink);
  5007.  
  5008.   long_ftype_long
  5009.     = build_function_type (long_integer_type_node,
  5010.                tree_cons (NULL_TREE, long_integer_type_node,
  5011.                       endlink));
  5012.  
  5013.   void_ftype_ptr_ptr_int
  5014.     = build_function_type (void_type_node,
  5015.                tree_cons (NULL_TREE, ptr_type_node,
  5016.                       tree_cons (NULL_TREE, ptr_type_node,
  5017.                          int_endlink)));
  5018.  
  5019.   int_ftype_cptr_cptr_sizet
  5020.     = build_function_type (integer_type_node,
  5021.                tree_cons (NULL_TREE, const_ptr_type_node,
  5022.                       tree_cons (NULL_TREE, const_ptr_type_node,
  5023.                          tree_cons (NULL_TREE,
  5024.                                 sizetype,
  5025.                                 endlink))));
  5026.  
  5027.   void_ftype_ptr_int_int
  5028.     = build_function_type (void_type_node,
  5029.                tree_cons (NULL_TREE, ptr_type_node,
  5030.                       tree_cons (NULL_TREE, integer_type_node,
  5031.                          int_endlink)));
  5032.  
  5033.   string_ftype_ptr_ptr        /* strcpy prototype */
  5034.     = build_function_type (string_type_node,
  5035.                tree_cons (NULL_TREE, string_type_node,
  5036.                       tree_cons (NULL_TREE,
  5037.                          const_string_type_node,
  5038.                          endlink)));
  5039.  
  5040. #if 0
  5041.   /* Not yet.  */
  5042.   strncpy_ftype            /* strncpy prototype */
  5043.     = build_function_type (string_type_node,
  5044.                tree_cons (NULL_TREE, string_type_node,
  5045.                       tree_cons (NULL_TREE, const_string_type_node,
  5046.                          tree_cons (NULL_TREE,
  5047.                                 sizetype,
  5048.                                 endlink))));
  5049. #endif
  5050.  
  5051.   int_ftype_string_string    /* strcmp prototype */
  5052.     = build_function_type (integer_type_node,
  5053.                tree_cons (NULL_TREE, const_string_type_node,
  5054.                       tree_cons (NULL_TREE,
  5055.                          const_string_type_node,
  5056.                          endlink)));
  5057.  
  5058.   sizet_ftype_string        /* strlen prototype */
  5059.     = build_function_type (sizetype,
  5060.                tree_cons (NULL_TREE, const_string_type_node,
  5061.                       endlink));
  5062.  
  5063.   traditional_ptr_type_node
  5064.     = (flag_traditional ? string_type_node : ptr_type_node);
  5065.  
  5066.   memcpy_ftype    /* memcpy prototype */
  5067.     = build_function_type (traditional_ptr_type_node,
  5068.                tree_cons (NULL_TREE, ptr_type_node,
  5069.                       tree_cons (NULL_TREE, const_ptr_type_node,
  5070.                          tree_cons (NULL_TREE,
  5071.                                 sizetype,
  5072.                                 endlink))));
  5073.  
  5074.   if (flag_huge_objects)
  5075.     delta_type_node = long_integer_type_node;
  5076.   else
  5077.     delta_type_node = short_integer_type_node;
  5078.  
  5079.   builtin_function ("__builtin_constant_p", int_ftype_int,
  5080.             BUILT_IN_CONSTANT_P, NULL_PTR);
  5081.  
  5082.   builtin_return_address_fndecl =
  5083.   builtin_function ("__builtin_return_address",
  5084.             build_function_type (ptr_type_node, 
  5085.                      tree_cons (NULL_TREE,
  5086.                             unsigned_type_node,
  5087.                             endlink)),
  5088.             BUILT_IN_RETURN_ADDRESS, NULL_PTR);
  5089.  
  5090.   builtin_function ("__builtin_frame_address",
  5091.             build_function_type (ptr_type_node, 
  5092.                      tree_cons (NULL_TREE,
  5093.                             unsigned_type_node,
  5094.                             endlink)),
  5095.             BUILT_IN_FRAME_ADDRESS, NULL_PTR);
  5096.  
  5097.  
  5098.   builtin_function ("__builtin_alloca",
  5099.             build_function_type (ptr_type_node,
  5100.                      tree_cons (NULL_TREE,
  5101.                             sizetype,
  5102.                             endlink)),
  5103.             BUILT_IN_ALLOCA, "alloca");
  5104.   /* Define alloca, ffs as builtins.
  5105.      Declare _exit just to mark it as volatile.  */
  5106.   if (! flag_no_builtin && !flag_no_nonansi_builtin)
  5107.     {
  5108.       temp = builtin_function ("alloca",
  5109.                    build_function_type (ptr_type_node,
  5110.                             tree_cons (NULL_TREE,
  5111.                                    sizetype,
  5112.                                    endlink)),
  5113.                    BUILT_IN_ALLOCA, NULL_PTR);
  5114.       /* Suppress error if redefined as a non-function.  */
  5115.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5116.       temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
  5117.       /* Suppress error if redefined as a non-function.  */
  5118.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5119.       temp = builtin_function ("_exit", build_function_type (void_type_node,
  5120.                                  int_endlink),
  5121.                    NOT_BUILT_IN, NULL_PTR);
  5122.       TREE_THIS_VOLATILE (temp) = 1;
  5123.       TREE_SIDE_EFFECTS (temp) = 1;
  5124.       /* Suppress error if redefined as a non-function.  */
  5125.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5126.     }
  5127.  
  5128.   builtin_function ("__builtin_abs", int_ftype_int,
  5129.             BUILT_IN_ABS, NULL_PTR);
  5130.   builtin_function ("__builtin_fabs", double_ftype_double,
  5131.             BUILT_IN_FABS, NULL_PTR);
  5132.   builtin_function ("__builtin_labs", long_ftype_long,
  5133.             BUILT_IN_LABS, NULL_PTR);
  5134.   builtin_function ("__builtin_ffs", int_ftype_int,
  5135.             BUILT_IN_FFS, NULL_PTR);
  5136.   builtin_function ("__builtin_fsqrt", double_ftype_double,
  5137.             BUILT_IN_FSQRT, NULL_PTR);
  5138.   builtin_function ("__builtin_sin", double_ftype_double, 
  5139.             BUILT_IN_SIN, "sin");
  5140.   builtin_function ("__builtin_cos", double_ftype_double, 
  5141.             BUILT_IN_COS, "cos");
  5142.   builtin_function ("__builtin_saveregs",
  5143.             build_function_type (ptr_type_node, NULL_TREE),
  5144.             BUILT_IN_SAVEREGS, NULL_PTR);
  5145. /* EXPAND_BUILTIN_VARARGS is obsolete.  */
  5146. #if 0
  5147.   builtin_function ("__builtin_varargs",
  5148.             build_function_type (ptr_type_node,
  5149.                      tree_cons (NULL_TREE,
  5150.                             integer_type_node,
  5151.                             endlink)),
  5152.             BUILT_IN_VARARGS, NULL_PTR);
  5153. #endif
  5154.   builtin_function ("__builtin_classify_type", default_function_type,
  5155.             BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
  5156.   builtin_function ("__builtin_next_arg",
  5157.             build_function_type (ptr_type_node, NULL_TREE),
  5158.             BUILT_IN_NEXT_ARG, NULL_PTR);
  5159.   builtin_function ("__builtin_args_info",
  5160.             build_function_type (integer_type_node,
  5161.                      tree_cons (NULL_TREE,
  5162.                             integer_type_node,
  5163.                             endlink)),
  5164.             BUILT_IN_ARGS_INFO, NULL_PTR);
  5165.  
  5166.   /* Untyped call and return.  */
  5167.   builtin_function ("__builtin_apply_args",
  5168.             build_function_type (ptr_type_node, NULL_TREE),
  5169.             BUILT_IN_APPLY_ARGS, NULL_PTR);
  5170.  
  5171.   temp = tree_cons (NULL_TREE,
  5172.             build_pointer_type (build_function_type (void_type_node,
  5173.                                  NULL_TREE)),
  5174.             tree_cons (NULL_TREE,
  5175.                    ptr_type_node,
  5176.                    tree_cons (NULL_TREE,
  5177.                       sizetype,
  5178.                       endlink)));
  5179.   builtin_function ("__builtin_apply",
  5180.             build_function_type (ptr_type_node, temp),
  5181.             BUILT_IN_APPLY, NULL_PTR);
  5182.   builtin_function ("__builtin_return",
  5183.             build_function_type (void_type_node,
  5184.                      tree_cons (NULL_TREE,
  5185.                             ptr_type_node,
  5186.                             endlink)),
  5187.             BUILT_IN_RETURN, NULL_PTR);
  5188.  
  5189.   /* Currently under experimentation.  */
  5190.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  5191.             BUILT_IN_MEMCPY, "memcpy");
  5192.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  5193.             BUILT_IN_MEMCMP, "memcmp");
  5194.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  5195.             BUILT_IN_STRCMP, "strcmp");
  5196.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  5197.             BUILT_IN_STRCPY, "strcpy");
  5198. #if 0
  5199.   /* Not yet.  */
  5200.   builtin_function ("__builtin_strncpy", strncpy_ftype,
  5201.             BUILT_IN_STRNCPY, "strncpy");
  5202. #endif
  5203.   builtin_function ("__builtin_strlen", sizet_ftype_string,
  5204.             BUILT_IN_STRLEN, "strlen");
  5205.  
  5206.   if (!flag_no_builtin)
  5207.     {
  5208. #if 0 /* These do not work well with libg++.  */
  5209.       builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
  5210.       builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
  5211.       builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
  5212. #endif
  5213.       builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
  5214.       builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
  5215.             NULL_PTR);
  5216.       builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR);
  5217.       builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
  5218.             NULL_PTR);
  5219. #if 0
  5220.       /* Not yet.  */
  5221.       builtin_function ("strncpy", strncpy_ftype, BUILT_IN_STRNCPY, NULL_PTR);
  5222. #endif
  5223.       builtin_function ("strlen", sizet_ftype_string, BUILT_IN_STRLEN, NULL_PTR);
  5224.       builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR);
  5225.       builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR);
  5226.  
  5227.       /* Declare these functions volatile
  5228.      to avoid spurious "control drops through" warnings.  */
  5229.       temp = builtin_function ("abort",
  5230.                    build_function_type (void_type_node, endlink),
  5231.                    NOT_BUILT_IN, NULL_PTR);
  5232.       TREE_THIS_VOLATILE (temp) = 1;
  5233.       TREE_SIDE_EFFECTS (temp) = 1;
  5234.       /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on
  5235.          them...  */
  5236.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5237.       temp = builtin_function ("exit", build_function_type (void_type_node,
  5238.                                 int_endlink),
  5239.                    NOT_BUILT_IN, NULL_PTR);
  5240.       TREE_THIS_VOLATILE (temp) = 1;
  5241.       TREE_SIDE_EFFECTS (temp) = 1;
  5242.       DECL_BUILT_IN_NONANSI (temp) = 1;
  5243.     }
  5244.  
  5245. #if 0
  5246.   /* Support for these has not been written in either expand_builtin
  5247.      or build_function_call.  */
  5248.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, 0);
  5249.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, 0);
  5250.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
  5251.             0);
  5252.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, 0);
  5253.   builtin_function ("__builtin_fmod", double_ftype_double_double,
  5254.             BUILT_IN_FMOD, 0);
  5255.   builtin_function ("__builtin_frem", double_ftype_double_double,
  5256.             BUILT_IN_FREM, 0);
  5257.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET,
  5258.             0);
  5259.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
  5260.             0);
  5261.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
  5262.             0);
  5263. #endif
  5264.  
  5265.   /* C++ extensions */
  5266.  
  5267.   unknown_type_node = make_node (UNKNOWN_TYPE);
  5268. #if 0 /* not yet, should get fixed properly later */
  5269.   pushdecl (make_type_decl (get_identifier ("unknown type"),
  5270.                unknown_type_node));
  5271. #else
  5272.   decl = pushdecl (build_decl (TYPE_DECL, get_identifier ("unknown type"),
  5273.             unknown_type_node));
  5274.   /* Make sure the "unknown type" typedecl gets ignored for debug info.  */
  5275.   DECL_IGNORED_P (decl) = 1;
  5276.   TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
  5277. #endif
  5278.   TYPE_SIZE (unknown_type_node) = TYPE_SIZE (void_type_node);
  5279.   TYPE_ALIGN (unknown_type_node) = 1;
  5280.   TYPE_MODE (unknown_type_node) = TYPE_MODE (void_type_node);
  5281.   /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node.  */
  5282.   TREE_TYPE (unknown_type_node) = unknown_type_node;
  5283.   /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */
  5284.   TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
  5285.   TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
  5286.  
  5287.   /* This is for handling opaque types in signatures.  */
  5288.   opaque_type_node = copy_node (ptr_type_node);
  5289.   TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node;
  5290.   record_builtin_type (RID_MAX, 0, opaque_type_node);
  5291.  
  5292.   /* This is special for C++ so functions can be overloaded. */
  5293.   wchar_type_node
  5294.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
  5295.   wchar_type_size = TYPE_PRECISION (wchar_type_node);
  5296.   signed_wchar_type_node = make_signed_type (wchar_type_size);
  5297.   unsigned_wchar_type_node = make_unsigned_type (wchar_type_size);
  5298.   wchar_type_node
  5299.     = TREE_UNSIGNED (wchar_type_node)
  5300.       ? unsigned_wchar_type_node
  5301.       : signed_wchar_type_node;
  5302.   record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node);
  5303.  
  5304.   /* Artificial declaration of wchar_t -- can be bashed */
  5305.   wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"),
  5306.                 wchar_type_node);
  5307.   pushdecl (wchar_decl_node);
  5308.  
  5309.   /* This is for wide string constants.  */
  5310.   wchar_array_type_node
  5311.     = build_array_type (wchar_type_node, array_domain_type);
  5312.  
  5313.   /* This is a hack that should go away when we deliver the
  5314.      real gc code.  */
  5315.   if (flag_gc)
  5316.     {
  5317.       builtin_function ("__gc_main", default_function_type, NOT_BUILT_IN, 0);
  5318.       pushdecl (lookup_name (get_identifier ("__gc_main"), 0));
  5319.     }
  5320.  
  5321.   if (flag_vtable_thunks)
  5322.     {
  5323.       /* Make sure we get a unique function type, so we can give
  5324.      its pointer type a name.  (This wins for gdb.) */
  5325.       tree vfunc_type = make_node (FUNCTION_TYPE);
  5326.       TREE_TYPE (vfunc_type) = integer_type_node;
  5327.       TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
  5328.       layout_type (vfunc_type);
  5329.  
  5330.       vtable_entry_type = build_pointer_type (vfunc_type);
  5331.     }
  5332.   else
  5333.     {
  5334.       vtable_entry_type = make_lang_type (RECORD_TYPE);
  5335.       fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  5336.                      delta_type_node);
  5337.       fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  5338.                      delta_type_node);
  5339.       fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
  5340.                      ptr_type_node);
  5341.       finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2,
  5342.                double_type_node);
  5343.  
  5344.       /* Make this part of an invisible union.  */
  5345.       fields[3] = copy_node (fields[2]);
  5346.       TREE_TYPE (fields[3]) = delta_type_node;
  5347.       DECL_NAME (fields[3]) = delta2_identifier;
  5348.       DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node);
  5349.       DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node);
  5350.       TREE_UNSIGNED (fields[3]) = 0;
  5351.       TREE_CHAIN (fields[2]) = fields[3];
  5352.       vtable_entry_type = build_type_variant (vtable_entry_type, 1, 0);
  5353.     }
  5354.   record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type);
  5355.  
  5356.   vtbl_type_node
  5357.     = build_array_type (vtable_entry_type, NULL_TREE);
  5358.   layout_type (vtbl_type_node);
  5359.   vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
  5360.   record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
  5361.  
  5362.   /* Simplify life by making a "sigtable_entry_type".  Give its
  5363.      fields names so that the debugger can use them.  */
  5364.  
  5365.   if (flag_handle_signatures)
  5366.     {
  5367.       sigtable_entry_type = make_lang_type (RECORD_TYPE);
  5368.       fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier,
  5369.                      delta_type_node);
  5370.       fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier,
  5371.                      delta_type_node);
  5372.       fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  5373.                      delta_type_node);
  5374.       fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier,
  5375.                      delta_type_node);
  5376.       fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier,
  5377.                      ptr_type_node);
  5378.  
  5379.       /* Set the alignment to the max of the alignment of ptr_type_node and
  5380.      delta_type_node.  Double alignment wastes a word on the Sparc.  */
  5381.       finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4,
  5382.                (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node))
  5383.                ? ptr_type_node
  5384.                : delta_type_node);
  5385.  
  5386.       /* Make this part of an invisible union.  */
  5387.       fields[5] = copy_node (fields[4]);
  5388.       TREE_TYPE (fields[5]) = delta_type_node;
  5389.       DECL_NAME (fields[5]) = vt_off_identifier;
  5390.       DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node);
  5391.       DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node);
  5392.       TREE_UNSIGNED (fields[5]) = 0;
  5393.       TREE_CHAIN (fields[4]) = fields[5];
  5394.  
  5395.       sigtable_entry_type = build_type_variant (sigtable_entry_type, 1, 0);
  5396.       record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type);
  5397.     }
  5398.  
  5399. #if 0
  5400.   if (flag_rtti)
  5401.     {
  5402.       /* Must build __t_desc type.  Currently, type descriptors look like this:
  5403.  
  5404.      struct __t_desc
  5405.      {
  5406.            const char *name;
  5407.        int size;
  5408.        int bits;
  5409.        struct __t_desc *points_to;
  5410.        int ivars_count, meths_count;
  5411.        struct __i_desc *ivars[];
  5412.        struct __m_desc *meths[];
  5413.        struct __t_desc *parents[];
  5414.        struct __t_desc *vbases[];
  5415.        int offsets[];
  5416.      };
  5417.  
  5418.      ...as per Linton's paper.  */
  5419.  
  5420.       __t_desc_type_node = make_lang_type (RECORD_TYPE);
  5421.       __i_desc_type_node = make_lang_type (RECORD_TYPE);
  5422.       __m_desc_type_node = make_lang_type (RECORD_TYPE);
  5423.       __t_desc_array_type =
  5424.     build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE);
  5425.       __i_desc_array_type =
  5426.     build_array_type (build_pointer_type (__i_desc_type_node), NULL_TREE);
  5427.       __m_desc_array_type =
  5428.     build_array_type (build_pointer_type (__m_desc_type_node), NULL_TREE);
  5429.  
  5430.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5431.                      string_type_node);
  5432.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("size"),
  5433.                      unsigned_type_node);
  5434.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("bits"),
  5435.                      unsigned_type_node);
  5436.       fields[3] = build_lang_field_decl (FIELD_DECL,
  5437.                      get_identifier ("points_to"),
  5438.                      build_pointer_type (__t_desc_type_node));
  5439.       fields[4] = build_lang_field_decl (FIELD_DECL,
  5440.                      get_identifier ("ivars_count"),
  5441.                      integer_type_node);
  5442.       fields[5] = build_lang_field_decl (FIELD_DECL,
  5443.                      get_identifier ("meths_count"),
  5444.                      integer_type_node);
  5445.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("ivars"),
  5446.                      build_pointer_type (__i_desc_array_type));
  5447.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("meths"),
  5448.                      build_pointer_type (__m_desc_array_type));
  5449.       fields[8] = build_lang_field_decl (FIELD_DECL, get_identifier ("parents"),
  5450.                      build_pointer_type (__t_desc_array_type));
  5451.       fields[9] = build_lang_field_decl (FIELD_DECL, get_identifier ("vbases"),
  5452.                      build_pointer_type (__t_desc_array_type));
  5453.       fields[10] = build_lang_field_decl (FIELD_DECL, get_identifier ("offsets"),
  5454.                      build_pointer_type (integer_type_node));
  5455.       finish_builtin_type (__t_desc_type_node, "__t_desc", fields, 10, integer_type_node);
  5456.  
  5457.       /* ivar descriptors look like this:
  5458.  
  5459.      struct __i_desc
  5460.      {
  5461.        const char *name;
  5462.        int offset;
  5463.        struct __t_desc *type;
  5464.      };
  5465.       */
  5466.  
  5467.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5468.                      string_type_node);
  5469.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("offset"),
  5470.                      integer_type_node);
  5471.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("type"),
  5472.                      build_pointer_type (__t_desc_type_node));
  5473.       finish_builtin_type (__i_desc_type_node, "__i_desc", fields, 2,
  5474.                integer_type_node);
  5475.  
  5476.       /* method descriptors look like this:
  5477.  
  5478.      struct __m_desc
  5479.      {
  5480.        const char *name;
  5481.        int vindex;
  5482.        struct __t_desc *vcontext;
  5483.        struct __t_desc *return_type;
  5484.        void (*address)();
  5485.        short parm_count;
  5486.        short required_parms;
  5487.        struct __t_desc *parm_types[];
  5488.      };
  5489.       */
  5490.  
  5491.       fields[0] = build_lang_field_decl (FIELD_DECL, get_identifier ("name"),
  5492.                      string_type_node);
  5493.       fields[1] = build_lang_field_decl (FIELD_DECL, get_identifier ("vindex"),
  5494.                      integer_type_node);
  5495.       fields[2] = build_lang_field_decl (FIELD_DECL, get_identifier ("vcontext"),
  5496.                      build_pointer_type (__t_desc_type_node));
  5497.       fields[3] = build_lang_field_decl (FIELD_DECL, get_identifier ("return_type"),
  5498.                      build_pointer_type (__t_desc_type_node));
  5499.       fields[4] = build_lang_field_decl (FIELD_DECL, get_identifier ("address"),
  5500.                      build_pointer_type (default_function_type));
  5501.       fields[5] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_count"),
  5502.                      short_integer_type_node);
  5503.       fields[6] = build_lang_field_decl (FIELD_DECL, get_identifier ("required_parms"),
  5504.                      short_integer_type_node);
  5505.       fields[7] = build_lang_field_decl (FIELD_DECL, get_identifier ("parm_types"),
  5506.                      build_pointer_type (build_array_type (build_pointer_type (__t_desc_type_node), NULL_TREE)));
  5507.       finish_builtin_type (__m_desc_type_node, "__m_desc", fields, 7,
  5508.                integer_type_node);
  5509.     }
  5510.  
  5511.   if (flag_rtti)
  5512.     {
  5513.       int i = builtin_type_tdescs_len;
  5514.       while (i > 0)
  5515.     {
  5516.       tree tdesc = build_t_desc (builtin_type_tdescs_arr[--i], 0);
  5517.       TREE_ASM_WRITTEN (tdesc) = 1;
  5518.       TREE_PUBLIC (TREE_OPERAND (tdesc, 0)) = 1;
  5519.     }
  5520.     }
  5521. #endif /*flag_rtti*/
  5522.  
  5523.   /* Now, C++.  */
  5524.   current_lang_name = lang_name_cplusplus;
  5525.  
  5526.   auto_function (ansi_opname[(int) NEW_EXPR],
  5527.          build_function_type (ptr_type_node,
  5528.                       tree_cons (NULL_TREE, sizetype,
  5529.                          void_list_node)),
  5530.          NOT_BUILT_IN);
  5531.   auto_function (ansi_opname[(int) VEC_NEW_EXPR],
  5532.          build_function_type (ptr_type_node,
  5533.                       tree_cons (NULL_TREE, sizetype,
  5534.                          void_list_node)),
  5535.          NOT_BUILT_IN);
  5536.   auto_function (ansi_opname[(int) DELETE_EXPR],
  5537.          build_function_type (void_type_node,
  5538.                       tree_cons (NULL_TREE, ptr_type_node,
  5539.                          void_list_node)),
  5540.          NOT_BUILT_IN);
  5541.   auto_function (ansi_opname[(int) VEC_DELETE_EXPR],
  5542.          build_function_type (void_type_node,
  5543.                       tree_cons (NULL_TREE, ptr_type_node,
  5544.                          void_list_node)),
  5545.          NOT_BUILT_IN);
  5546.  
  5547.   abort_fndecl
  5548.     = define_function ("__pure_virtual",
  5549.                build_function_type (void_type_node, void_list_node),
  5550.                NOT_BUILT_IN, 0, 0);
  5551.  
  5552.   /* Perform other language dependent initializations.  */
  5553.   init_class_processing ();
  5554.   init_init_processing ();
  5555.   init_search_processing ();
  5556.  
  5557.   if (flag_handle_exceptions)
  5558.     init_exception_processing ();
  5559.   if (flag_gc)
  5560.     init_gc_processing ();
  5561.   if (flag_no_inline)
  5562.     {
  5563.       flag_inline_functions = 0;
  5564. #if 0
  5565.       /* This causes unnecessary emission of inline functions.  */
  5566.       flag_default_inline = 0;
  5567. #endif
  5568.     }
  5569.   if (flag_cadillac)
  5570.     init_cadillac ();
  5571.  
  5572.   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
  5573.   declare_function_name ();
  5574.  
  5575.   /* Prepare to check format strings against argument lists.  */
  5576.   init_function_format_info ();
  5577. }
  5578.  
  5579. /* initialize type descriptor type node of various rtti type. */
  5580.  
  5581. int
  5582. init_type_desc()
  5583. {
  5584.   tree tdecl;
  5585.  
  5586.   tdecl = lookup_name (get_identifier ("type_info"), 0);
  5587.   if (tdecl == NULL_TREE)
  5588.     return 0;
  5589.   __t_desc_type_node = TREE_TYPE(tdecl);
  5590.   __tp_desc_type_node = build_pointer_type (__t_desc_type_node);
  5591.  
  5592. #if 0
  5593.   tdecl = lookup_name (get_identifier ("__baselist_type_info"), 0);
  5594.   if (tdecl == NULL_TREE)
  5595.     return 0;
  5596.   __baselist_desc_type_node = TREE_TYPE (tdecl);
  5597. #endif
  5598.  
  5599.   tdecl = lookup_name (get_identifier ("__builtin_type_info"), 0);
  5600.   if (tdecl == NULL_TREE)
  5601.     return 0;
  5602.   __bltn_desc_type_node = TREE_TYPE (tdecl);
  5603.  
  5604.   tdecl = lookup_name (get_identifier ("__user_type_info"), 0);
  5605.   if (tdecl == NULL_TREE)
  5606.     return 0;
  5607.   __user_desc_type_node = TREE_TYPE (tdecl);
  5608.  
  5609.   tdecl = lookup_name (get_identifier ("__class_type_info"), 0);
  5610.   if (tdecl == NULL_TREE)
  5611.     return 0;
  5612.   __class_desc_type_node = TREE_TYPE (tdecl);
  5613.  
  5614.   tdecl = lookup_field (__class_desc_type_node, 
  5615.     get_identifier ("access_mode"), 0, 0);
  5616.   if (tdecl == NULL_TREE)
  5617.     return 0;
  5618.   __access_mode_type_node = TREE_TYPE (tdecl);
  5619.  
  5620.   tdecl = lookup_name (get_identifier ("__attr_type_info"), 0);
  5621.   if (tdecl == NULL_TREE)
  5622.     return 0;
  5623.   __attr_desc_type_node = TREE_TYPE (tdecl);
  5624.  
  5625.   tdecl = lookup_name (get_identifier ("__pointer_type_info"), 0);
  5626.   if (tdecl == NULL_TREE)
  5627.     return 0;
  5628.   __ptr_desc_type_node = TREE_TYPE (tdecl);
  5629.  
  5630.   tdecl = lookup_name (get_identifier ("__func_type_info"), 0);
  5631.   if (tdecl == NULL_TREE)
  5632.     return 0;
  5633.   __func_desc_type_node = TREE_TYPE (tdecl);
  5634.  
  5635.   tdecl = lookup_name (get_identifier ("__ptmf_type_info"), 0);
  5636.   if (tdecl == NULL_TREE)
  5637.     return 0;
  5638.   __ptmf_desc_type_node = TREE_TYPE (tdecl);
  5639.  
  5640.   tdecl = lookup_name (get_identifier ("__ptmd_type_info"), 0);
  5641.   if (tdecl == NULL_TREE)
  5642.     return 0;
  5643.   __ptmd_desc_type_node = TREE_TYPE (tdecl);
  5644.  
  5645.   return 1;
  5646. }
  5647. /* Make a definition for a builtin function named NAME and whose data type
  5648.    is TYPE.  TYPE should be a function type with argument types.
  5649.    FUNCTION_CODE tells later passes how to compile calls to this function.
  5650.    See tree.h for its possible values.
  5651.  
  5652.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  5653.    the name to be called if we can't opencode the function.  */
  5654.  
  5655. tree
  5656. define_function (name, type, function_code, pfn, library_name)
  5657.      char *name;
  5658.      tree type;
  5659.      enum built_in_function function_code;
  5660.      void (*pfn)();
  5661.      char *library_name;
  5662. {
  5663.   tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type);
  5664.   DECL_EXTERNAL (decl) = 1;
  5665.   TREE_PUBLIC (decl) = 1;
  5666.   DECL_ARTIFICIAL (decl) = 1;
  5667.  
  5668.   /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
  5669.      we cannot change DECL_ASSEMBLER_NAME until we have installed this
  5670.      function in the namespace.  */
  5671.   if (pfn) (*pfn) (decl);
  5672.   if (library_name)
  5673.     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
  5674.   make_function_rtl (decl);
  5675.   if (function_code != NOT_BUILT_IN)
  5676.     {
  5677.       DECL_BUILT_IN (decl) = 1;
  5678.       DECL_FUNCTION_CODE (decl) = function_code;
  5679.     }
  5680.   return decl;
  5681. }
  5682.  
  5683. /* Called when a declaration is seen that contains no names to declare.
  5684.    If its type is a reference to a structure, union or enum inherited
  5685.    from a containing scope, shadow that tag name for the current scope
  5686.    with a forward reference.
  5687.    If its type defines a new named structure or union
  5688.    or defines an enum, it is valid but we need not do anything here.
  5689.    Otherwise, it is an error.
  5690.  
  5691.    C++: may have to grok the declspecs to learn about static,
  5692.    complain for anonymous unions.  */
  5693.  
  5694. void
  5695. shadow_tag (declspecs)
  5696.      tree declspecs;
  5697. {
  5698.   int found_tag = 0;
  5699.   tree ob_modifier = NULL_TREE;
  5700.   register tree link;
  5701.   register enum tree_code code, ok_code = ERROR_MARK;
  5702.   register tree t = NULL_TREE;
  5703.  
  5704.   for (link = declspecs; link; link = TREE_CHAIN (link))
  5705.     {
  5706.       register tree value = TREE_VALUE (link);
  5707.  
  5708.       code = TREE_CODE (value);
  5709.       if (IS_AGGR_TYPE_CODE (code) || code == ENUMERAL_TYPE)
  5710.     {
  5711.       my_friendly_assert (TYPE_NAME (value) != NULL_TREE, 261);
  5712.  
  5713.       if (code == ENUMERAL_TYPE && TYPE_SIZE (value) == 0)
  5714.         cp_error ("forward declaration of `%#T'", value);
  5715.  
  5716.       t = value;
  5717.       ok_code = code;
  5718.       found_tag++;
  5719.     }
  5720.       else if (value == ridpointers[(int) RID_STATIC]
  5721.            || value == ridpointers[(int) RID_EXTERN]
  5722.            || value == ridpointers[(int) RID_AUTO]
  5723.            || value == ridpointers[(int) RID_REGISTER]
  5724.            || value == ridpointers[(int) RID_INLINE]
  5725.            || value == ridpointers[(int) RID_VIRTUAL]
  5726.            || value == ridpointers[(int) RID_EXPLICIT])
  5727.     ob_modifier = value;
  5728.     }
  5729.  
  5730.   /* This is where the variables in an anonymous union are
  5731.      declared.  An anonymous union declaration looks like:
  5732.      union { ... } ;
  5733.      because there is no declarator after the union, the parser
  5734.      sends that declaration here.  */
  5735.   if (ok_code == UNION_TYPE
  5736.       && t != NULL_TREE
  5737.       && ((TREE_CODE (TYPE_NAME (t)) == IDENTIFIER_NODE
  5738.        && ANON_AGGRNAME_P (TYPE_NAME (t)))
  5739.       || (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL
  5740.           && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))))
  5741.     {
  5742.       /* ANSI C++ June 5 1992 WP 9.5.3.  Anonymous unions may not have
  5743.      function members.  */
  5744.       if (TYPE_FIELDS (t))
  5745.     {
  5746.       tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0,
  5747.                       NULL_TREE, NULL_TREE);
  5748.       finish_anon_union (decl);
  5749.     }
  5750.       else
  5751.     error ("anonymous union cannot have a function member");
  5752.     }
  5753.   else
  5754.     {
  5755.       /* Anonymous unions are objects, that's why we only check for
  5756.      inappropriate specifiers in this branch.  */
  5757.  
  5758.       if (ob_modifier)
  5759.     {
  5760.       if (ob_modifier == ridpointers[(int) RID_INLINE]
  5761.           || ob_modifier == ridpointers[(int) RID_VIRTUAL])
  5762.         cp_error ("`%D' can only be specified for functions", ob_modifier);
  5763.       else if (ob_modifier == ridpointers[(int) RID_EXPLICIT])
  5764.         cp_error ("`%D' can only be specified for constructors",
  5765.               ob_modifier);
  5766.       else
  5767.         cp_error ("`%D' can only be specified for objects and functions",
  5768.               ob_modifier);
  5769.     }
  5770.  
  5771.       if (found_tag == 0)
  5772.     pedwarn ("abstract declarator used as declaration");
  5773.       else if (found_tag > 1)
  5774.     pedwarn ("multiple types in one declaration");
  5775.     }
  5776. }
  5777.  
  5778. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  5779.  
  5780. tree
  5781. groktypename (typename)
  5782.      tree typename;
  5783. {
  5784.   if (TREE_CODE (typename) != TREE_LIST)
  5785.     return typename;
  5786.   return grokdeclarator (TREE_VALUE (typename),
  5787.              TREE_PURPOSE (typename),
  5788.              TYPENAME, 0, NULL_TREE, NULL_TREE);
  5789. }
  5790.  
  5791. #ifdef OBJCPLUS
  5792. /* Return a PARM_DECL node for a given pair of specs and declarator.  */
  5793.  
  5794. tree
  5795. groktypename_in_parm_context (typename)
  5796.      tree typename;
  5797. {
  5798.   if (TREE_CODE (typename) != TREE_LIST)
  5799.     return typename;
  5800.   return grokdeclarator (TREE_VALUE (typename),
  5801.                          TREE_PURPOSE (typename),
  5802.                          PARM, 0, NULL_TREE, NULL_TREE);
  5803. }
  5804. #endif /* OBJCPLUS */
  5805.  
  5806. /* Decode a declarator in an ordinary declaration or data definition.
  5807.    This is called as soon as the type information and variable name
  5808.    have been parsed, before parsing the initializer if any.
  5809.    Here we create the ..._DECL node, fill in its type,
  5810.    and put it on the list of decls for the current context.
  5811.    The ..._DECL node is returned as the value.
  5812.  
  5813.    Exception: for arrays where the length is not specified,
  5814.    the type is left null, to be filled in by `cp_finish_decl'.
  5815.  
  5816.    Function definitions do not come here; they go to start_function
  5817.    instead.  However, external and forward declarations of functions
  5818.    do go through here.  Structure field declarations are done by
  5819.    grokfield and not through here.  */
  5820.  
  5821. /* Set this to zero to debug not using the temporary obstack
  5822.    to parse initializers.  */
  5823. int debug_temp_inits = 1;
  5824.  
  5825. tree
  5826. start_decl (declarator, declspecs, initialized, raises)
  5827.      tree declarator, declspecs;
  5828.      int initialized;
  5829.      tree raises;
  5830. {
  5831.   register tree decl;
  5832.   register tree type, tem;
  5833.   tree context;
  5834.   extern int have_extern_spec;
  5835.   extern int used_extern_spec;
  5836.  
  5837.   int init_written = initialized;
  5838.  
  5839.   /* This should only be done once on the top most decl. */
  5840.   if (have_extern_spec && !used_extern_spec)
  5841.     {
  5842.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"),
  5843.                   declspecs);
  5844.       used_extern_spec = 1;
  5845.     }
  5846.  
  5847.   decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, raises,
  5848.              NULL_TREE);
  5849.   if (decl == NULL_TREE || decl == void_type_node)
  5850.     return NULL_TREE;
  5851.  
  5852.   type = TREE_TYPE (decl);
  5853.  
  5854.   /* Don't lose if destructors must be executed at file-level.  */
  5855.   if (TREE_STATIC (decl)
  5856.       && TYPE_NEEDS_DESTRUCTOR (type)
  5857.       && !TREE_PERMANENT (decl))
  5858.     {
  5859.       push_obstacks (&permanent_obstack, &permanent_obstack);
  5860.       decl = copy_node (decl);
  5861.       if (TREE_CODE (type) == ARRAY_TYPE)
  5862.     {
  5863.       tree itype = TYPE_DOMAIN (type);
  5864.       if (itype && ! TREE_PERMANENT (itype))
  5865.         {
  5866.           itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype)));
  5867.           type = build_cplus_array_type (TREE_TYPE (type), itype);
  5868.           TREE_TYPE (decl) = type;
  5869.         }
  5870.     }
  5871.       pop_obstacks ();
  5872.     }
  5873.  
  5874.   /* Corresponding pop_obstacks is done in `cp_finish_decl'.  */
  5875.   push_obstacks_nochange ();
  5876.  
  5877.   context
  5878.     = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
  5879.       ? DECL_CLASS_CONTEXT (decl)
  5880.       : DECL_CONTEXT (decl);
  5881.  
  5882.   if (processing_template_decl)
  5883.     {
  5884.       tree d;
  5885.       if (TREE_CODE (decl) == FUNCTION_DECL)
  5886.         {
  5887.           /* Declarator is a call_expr; extract arguments from it, since
  5888.              grokdeclarator didn't do it.  */
  5889.           tree args;
  5890.           args = copy_to_permanent (last_function_parms);
  5891.           if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
  5892.             {
  5893.           tree t = TREE_TYPE (decl);
  5894.           
  5895.               t = TYPE_METHOD_BASETYPE (t); /* type method belongs to */
  5896.           if (TREE_CODE (t) != UNINSTANTIATED_P_TYPE)
  5897.         {
  5898.           t = build_pointer_type (t); /* base type of `this' */
  5899. #if 1
  5900.           /* I suspect this is wrong. */
  5901.           t = build_type_variant (t, flag_this_is_variable <= 0,
  5902.                       0); /* type of `this' */
  5903. #else
  5904.           t = build_type_variant (t, 0, 0); /* type of `this' */
  5905. #endif
  5906.           t = build (PARM_DECL, t, this_identifier);
  5907.           TREE_CHAIN (t) = args;
  5908.           args = t;
  5909.         }
  5910.         }
  5911.           DECL_ARGUMENTS (decl) = args;
  5912.         }
  5913.       d = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), TREE_TYPE (decl));
  5914.       TREE_PUBLIC (d) = TREE_PUBLIC (decl);
  5915.       TREE_STATIC (d) = TREE_STATIC (decl);
  5916.       DECL_EXTERNAL (d) = (DECL_EXTERNAL (decl)
  5917.                && !(context && !DECL_THIS_EXTERN (decl)));
  5918.       DECL_TEMPLATE_RESULT (d) = decl;
  5919.       decl = d;
  5920.     }
  5921.  
  5922.   /* If this type of object needs a cleanup, and control may
  5923.      jump past it, make a new binding level so that it is cleaned
  5924.      up only when it is initialized first.  */
  5925.   if (TYPE_NEEDS_DESTRUCTOR (type)
  5926.       && current_binding_level->more_cleanups_ok == 0)
  5927.     pushlevel_temporary (1);
  5928.  
  5929.   if (initialized)
  5930.     /* Is it valid for this decl to have an initializer at all?
  5931.        If not, set INITIALIZED to zero, which will indirectly
  5932.        tell `cp_finish_decl' to ignore the initializer once it is parsed.  */
  5933.     switch (TREE_CODE (decl))
  5934.       {
  5935.       case TYPE_DECL:
  5936.     /* typedef foo = bar  means give foo the same type as bar.
  5937.        We haven't parsed bar yet, so `cp_finish_decl' will fix that up.
  5938.        Any other case of an initialization in a TYPE_DECL is an error.  */
  5939.     if (pedantic || list_length (declspecs) > 1)
  5940.       {
  5941.         cp_error ("typedef `%D' is initialized", decl);
  5942.         initialized = 0;
  5943.       }
  5944.     break;
  5945.  
  5946.       case FUNCTION_DECL:
  5947.     cp_error ("function `%#D' is initialized like a variable", decl);
  5948.     initialized = 0;
  5949.     break;
  5950.  
  5951.       default:
  5952.     /* Don't allow initializations for incomplete types except for
  5953.        arrays which might be completed by the initialization.  */
  5954.     if (type == error_mark_node)
  5955.       ;            /* Don't complain again.  */
  5956.     else if (TYPE_SIZE (type) != NULL_TREE)
  5957.       ;                     /* A complete type is ok.  */
  5958.     else if (TREE_CODE (type) != ARRAY_TYPE)
  5959.       {
  5960.         cp_error ("variable `%#D' has initializer but incomplete type",
  5961.               decl);
  5962.         initialized = 0;
  5963.       }
  5964.     else if (TYPE_SIZE (TREE_TYPE (type)) == NULL_TREE)
  5965.       {
  5966.         cp_error ("elements of array `%#D' have incomplete type", decl);
  5967.         initialized = 0;
  5968.       }
  5969.       }
  5970.  
  5971.   if (!initialized
  5972.       && TREE_CODE (decl) != TYPE_DECL
  5973.       && TREE_CODE (decl) != TEMPLATE_DECL
  5974.       && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl))
  5975.     {
  5976.       if (TYPE_SIZE (type) == NULL_TREE)
  5977.     {
  5978.       cp_error ("aggregate `%#D' has incomplete type and cannot be initialized",
  5979.          decl);
  5980.       /* Change the type so that assemble_variable will give
  5981.          DECL an rtl we can live with: (mem (const_int 0)).  */
  5982.       TREE_TYPE (decl) = error_mark_node;
  5983.       type = error_mark_node;
  5984.     }
  5985.       else
  5986.     {
  5987.       /* If any base type in the hierarchy of TYPE needs a constructor,
  5988.          then we set initialized to 1.  This way any nodes which are
  5989.          created for the purposes of initializing this aggregate
  5990.          will live as long as it does.  This is necessary for global
  5991.          aggregates which do not have their initializers processed until
  5992.          the end of the file.  */
  5993.       initialized = TYPE_NEEDS_CONSTRUCTING (type);
  5994.     }
  5995.     }
  5996.  
  5997.   if (initialized)
  5998.     {
  5999.       if (! toplevel_bindings_p ()
  6000.       && DECL_EXTERNAL (decl))
  6001.     cp_warning ("declaration of `%#D' has `extern' and is initialized",
  6002.             decl);
  6003.       DECL_EXTERNAL (decl) = 0;
  6004.       if ( toplevel_bindings_p ())
  6005.     TREE_STATIC (decl) = 1;
  6006.  
  6007.       /* Tell `pushdecl' this is an initialized decl
  6008.      even though we don't yet have the initializer expression.
  6009.      Also tell `cp_finish_decl' it may store the real initializer.  */
  6010.       DECL_INITIAL (decl) = error_mark_node;
  6011.     }
  6012.  
  6013.   if (context && TYPE_SIZE (context) != NULL_TREE)
  6014.     {
  6015.       if (TREE_CODE (decl) == VAR_DECL)
  6016.     {
  6017.       tree field = lookup_field (context, DECL_NAME (decl), 0, 0);
  6018.       if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL)
  6019.         cp_error ("`%#D' is not a static member of `%#T'", decl, context);
  6020.       else if (duplicate_decls (decl, field))
  6021.         decl = field;
  6022.     }
  6023.       else
  6024.     {
  6025.       tree field = check_classfn (context, NULL_TREE, decl);
  6026.       if (field && duplicate_decls (decl, field))
  6027.         decl = field;
  6028.     }
  6029.  
  6030.       /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
  6031.       if (DECL_LANG_SPECIFIC (decl))
  6032.     DECL_IN_AGGR_P (decl) = 0;
  6033.       if (DECL_USE_TEMPLATE (decl) || CLASSTYPE_USE_TEMPLATE (context))
  6034.     SET_DECL_TEMPLATE_SPECIALIZATION (decl);
  6035.  
  6036.       /* Stupid stupid stupid stupid  (jason 7/21/95) */
  6037.       if (pedantic && DECL_EXTERNAL (decl)
  6038.       && ! DECL_TEMPLATE_SPECIALIZATION (decl))
  6039.     cp_pedwarn ("declaration of `%#D' outside of class is not definition",
  6040.             decl);
  6041.  
  6042.       pushclass (context, 2);
  6043.     }
  6044.  
  6045.   /* Add this decl to the current binding level, but not if it
  6046.      comes from another scope, e.g. a static member variable.
  6047.      TEM may equal DECL or it may be a previous decl of the same name.  */
  6048.   
  6049.   if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE)
  6050.       || (TREE_CODE (decl) == TEMPLATE_DECL && !global_bindings_p ())
  6051.       || TREE_CODE (type) == LANG_TYPE)
  6052.     tem = decl;
  6053.   else
  6054.     tem = pushdecl (decl);
  6055.          
  6056.   /* Tell the back-end to use or not use .common as appropriate.  If we say
  6057.      -fconserve-space, we want this to save space, at the expense of wrong
  6058.      semantics.  If we say -fno-conserve-space, we want this to produce
  6059.      errors about redefs; to do this we force variables into the data
  6060.      segment.  Common storage is okay for non-public uninitialized data;
  6061.      the linker can't match it with storage from other files, and we may
  6062.      save some disk space.  */
  6063.   DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem);
  6064.  
  6065. #if 0
  6066.   /* We don't do this yet for GNU C++.  */
  6067.   /* For a local variable, define the RTL now.  */
  6068.   if (! toplevel_bindings_p ()
  6069.       /* But not if this is a duplicate decl
  6070.      and we preserved the rtl from the previous one
  6071.      (which may or may not happen).  */
  6072.       && DECL_RTL (tem) == NULL_RTX)
  6073.     {
  6074.       if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE)
  6075.     expand_decl (tem);
  6076.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  6077.            && DECL_INITIAL (tem) != NULL_TREE)
  6078.     expand_decl (tem);
  6079.     }
  6080. #endif
  6081.  
  6082.   if (TREE_CODE (decl) == TEMPLATE_DECL)
  6083.     {
  6084.       tree result = DECL_TEMPLATE_RESULT (decl);
  6085.       if (DECL_CONTEXT (result) != NULL_TREE)
  6086.     {
  6087.           tree type;
  6088.           type = DECL_CONTEXT (result);
  6089.  
  6090.       if (TREE_CODE (type) != UNINSTANTIATED_P_TYPE)
  6091.         {
  6092.           cp_error ("declaration of `%D' in non-template type `%T'",
  6093.             decl, type);
  6094.           return NULL_TREE;
  6095.         }
  6096.  
  6097.       if (TREE_CODE (result) == FUNCTION_DECL)
  6098.         return tem;
  6099.       else if (TREE_CODE (result) == VAR_DECL)
  6100.         {
  6101. #if 0
  6102.               tree tmpl = UPT_TEMPLATE (type);
  6103.           
  6104.           fprintf (stderr, "%s:%d: adding ", __FILE__, __LINE__);
  6105.           print_node_brief (stderr, "", DECL_NAME (tem), 0);
  6106.           fprintf (stderr, " to class %s\n",
  6107.                IDENTIFIER_POINTER (DECL_NAME (tmpl)));
  6108.               DECL_TEMPLATE_MEMBERS (tmpl)
  6109.                 = perm_tree_cons (DECL_NAME (tem), tem,
  6110.                   DECL_TEMPLATE_MEMBERS (tmpl));
  6111.           return tem;
  6112. #else
  6113.           sorry ("static data member templates");
  6114.           return NULL_TREE;
  6115. #endif
  6116.         }
  6117.       else
  6118.         my_friendly_abort (13);
  6119.         }
  6120.       else if (TREE_CODE (result) == FUNCTION_DECL)
  6121.         /*tem = push_overloaded_decl (tem, 0)*/;
  6122.       else if (TREE_CODE (result) == VAR_DECL)
  6123.     {
  6124.       cp_error ("data template `%#D' must be member of a class template",
  6125.             result);
  6126.       return NULL_TREE;
  6127.     }
  6128.       else if (TREE_CODE (result) == TYPE_DECL)
  6129.     {
  6130.       cp_error ("invalid template `%#D'", result);
  6131.       return NULL_TREE;
  6132.     }
  6133.       else
  6134.     my_friendly_abort (14);
  6135.     }
  6136.  
  6137.   if (init_written
  6138.       && ! (TREE_CODE (tem) == PARM_DECL
  6139.         || (TREE_READONLY (tem)
  6140.         && (TREE_CODE (tem) == VAR_DECL
  6141.             || TREE_CODE (tem) == FIELD_DECL))))
  6142.     {
  6143.       /* When parsing and digesting the initializer,
  6144.      use temporary storage.  Do this even if we will ignore the value.  */
  6145.       if (toplevel_bindings_p () && debug_temp_inits)
  6146.     {
  6147.       if (TYPE_NEEDS_CONSTRUCTING (type)
  6148.           || TREE_CODE (type) == REFERENCE_TYPE)
  6149.         /* In this case, the initializer must lay down in permanent
  6150.            storage, since it will be saved until `finish_file' is run.   */
  6151.         ;
  6152.       else
  6153.         temporary_allocation ();
  6154.     }
  6155.     }
  6156.  
  6157.   if (flag_cadillac)
  6158.     cadillac_start_decl (tem);
  6159.  
  6160.   return tem;
  6161. }
  6162.  
  6163. #if 0                /* unused */
  6164. static void
  6165. make_temporary_for_reference (decl, ctor_call, init, cleanupp)
  6166.      tree decl, ctor_call, init;
  6167.      tree *cleanupp;
  6168. {
  6169.   tree type = TREE_TYPE (decl);
  6170.   tree target_type = TREE_TYPE (type);
  6171.   tree tmp, tmp_addr;
  6172.  
  6173.   if (ctor_call)
  6174.     {
  6175.       tmp_addr = TREE_VALUE (TREE_OPERAND (ctor_call, 1));
  6176.       if (TREE_CODE (tmp_addr) == NOP_EXPR)
  6177.     tmp_addr = TREE_OPERAND (tmp_addr, 0);
  6178.       my_friendly_assert (TREE_CODE (tmp_addr) == ADDR_EXPR, 146);
  6179.       tmp = TREE_OPERAND (tmp_addr, 0);
  6180.     }
  6181.   else
  6182.     {
  6183.       tmp = get_temp_name (target_type, toplevel_bindings_p ());
  6184.       tmp_addr = build_unary_op (ADDR_EXPR, tmp, 0);
  6185.     }
  6186.  
  6187.   TREE_TYPE (tmp_addr) = build_pointer_type (target_type);
  6188.   DECL_INITIAL (decl) = convert (build_pointer_type (target_type), tmp_addr);
  6189.   TREE_TYPE (DECL_INITIAL (decl)) = type;
  6190.   if (TYPE_NEEDS_CONSTRUCTING (target_type))
  6191.     {
  6192.       if (toplevel_bindings_p ())
  6193.     {
  6194.       /* lay this variable out now.  Otherwise `output_addressed_constants'
  6195.          gets confused by its initializer.  */
  6196.       make_decl_rtl (tmp, NULL_PTR, 1);
  6197.       static_aggregates = perm_tree_cons (init, tmp, static_aggregates);
  6198.     }
  6199.       else
  6200.     {
  6201.       if (ctor_call != NULL_TREE)
  6202.         init = ctor_call;
  6203.       else
  6204.         init = build_method_call (tmp, constructor_name_full (target_type),
  6205.                       build_tree_list (NULL_TREE, init),
  6206.                       NULL_TREE, LOOKUP_NORMAL);
  6207.       DECL_INITIAL (decl) = build (COMPOUND_EXPR, type, init,
  6208.                        DECL_INITIAL (decl));
  6209.       *cleanupp = maybe_build_cleanup (tmp);
  6210.     }
  6211.     }
  6212.   else
  6213.     {
  6214.       DECL_INITIAL (tmp) = init;
  6215.       TREE_STATIC (tmp) = toplevel_bindings_p ();
  6216.       cp_finish_decl (tmp, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
  6217.     }
  6218.   if (TREE_STATIC (tmp))
  6219.     preserve_initializer ();
  6220. }
  6221. #endif
  6222.  
  6223. /* Handle initialization of references.
  6224.    These three arguments from from `cp_finish_decl', and have the
  6225.    same meaning here that they do there.  */
  6226. /* quotes on semantics can be found in ARM 8.4.3. */
  6227. static void
  6228. grok_reference_init (decl, type, init, cleanupp)
  6229.      tree decl, type, init;
  6230.      tree *cleanupp;
  6231. {
  6232.   tree tmp;
  6233.  
  6234.   if (init == NULL_TREE)
  6235.     {
  6236.       if ((DECL_LANG_SPECIFIC (decl) == 0
  6237.        || DECL_IN_AGGR_P (decl) == 0)
  6238.       && ! DECL_THIS_EXTERN (decl))
  6239.     {
  6240.       cp_error ("`%D' declared as reference but not initialized", decl);
  6241.       if (TREE_CODE (decl) == VAR_DECL)
  6242.         SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  6243.     }
  6244.       return;
  6245.     }
  6246.  
  6247.   if (init == error_mark_node)
  6248.     return;
  6249.  
  6250.   if (TREE_CODE (type) == REFERENCE_TYPE
  6251.       && TREE_CODE (init) == CONSTRUCTOR)
  6252.     {
  6253.       cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl);
  6254.       return;
  6255.     }
  6256.  
  6257.   if (TREE_CODE (init) == TREE_LIST)
  6258.     init = build_compound_expr (init);
  6259.  
  6260.   if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE)
  6261.     init = convert_from_reference (init);
  6262.  
  6263.   if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
  6264.       && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
  6265.     {
  6266.       /* Note: default conversion is only called in very special cases.  */
  6267.       init = default_conversion (init);
  6268.     }
  6269.  
  6270.   tmp = convert_to_reference
  6271.     (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL, decl);
  6272.  
  6273.   if (tmp == error_mark_node)
  6274.     goto fail;
  6275.   else if (tmp != NULL_TREE)
  6276.     {
  6277.       tree subtype = TREE_TYPE (type);
  6278.       init = tmp;
  6279.  
  6280.       /* Associate the cleanup with the reference so that we
  6281.      don't get burned by "aggressive" cleanup policy.  */
  6282.       if (TYPE_NEEDS_DESTRUCTOR (subtype))
  6283.     {
  6284.       if (TREE_CODE (init) == WITH_CLEANUP_EXPR)
  6285.         {
  6286.           *cleanupp = TREE_OPERAND (init, 2);
  6287.           TREE_OPERAND (init, 2) = error_mark_node;
  6288.         }
  6289.       else
  6290.         {
  6291.           if (TREE_CODE (tmp) == ADDR_EXPR)
  6292.         tmp = TREE_OPERAND (tmp, 0);
  6293.           if (TREE_CODE (tmp) == TARGET_EXPR)
  6294.         {
  6295.           *cleanupp = build_delete
  6296.             (build_pointer_type (subtype),
  6297.              build_unary_op (ADDR_EXPR, TREE_OPERAND (tmp, 0), 0),
  6298.              integer_two_node, LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
  6299.           TREE_OPERAND (tmp, 2) = error_mark_node;
  6300.         }
  6301.         }
  6302.     }
  6303.  
  6304.       DECL_INITIAL (decl) = save_expr (init);
  6305.     }
  6306.   else
  6307.     {
  6308.       cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init));
  6309.       goto fail;
  6310.     }
  6311.  
  6312.   /* ?? Can this be optimized in some cases to
  6313.      hand back the DECL_INITIAL slot??  */
  6314.   if (TYPE_SIZE (TREE_TYPE (type)))
  6315.     {
  6316.       init = convert_from_reference (decl);
  6317.       if (TREE_PERMANENT (decl))
  6318.     init = copy_to_permanent (init);
  6319.       SET_DECL_REFERENCE_SLOT (decl, init);
  6320.     }
  6321.  
  6322.   if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl)))
  6323.     {
  6324.       expand_static_init (decl, DECL_INITIAL (decl));
  6325.       DECL_INITIAL (decl) = NULL_TREE;
  6326.     }
  6327.   return;
  6328.  
  6329.  fail:
  6330.   if (TREE_CODE (decl) == VAR_DECL)
  6331.     SET_DECL_REFERENCE_SLOT (decl, error_mark_node);
  6332.   return;
  6333. }
  6334.  
  6335. /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from
  6336.    mucking with forces it does not comprehend (i.e. initialization with a
  6337.    constructor).  If we are at global scope and won't go into COMMON, fill
  6338.    it in with a dummy CONSTRUCTOR to force the variable into .data;
  6339.    otherwise we can use error_mark_node.  */
  6340.  
  6341. static tree
  6342. obscure_complex_init (decl, init)
  6343.      tree decl, init;
  6344. {
  6345.   if (! flag_no_inline && TREE_STATIC (decl))
  6346.     {
  6347.       if (extract_init (decl, init))
  6348.     return NULL_TREE;
  6349.     }
  6350.  
  6351.   if (toplevel_bindings_p () && ! DECL_COMMON (decl))
  6352.     DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE,
  6353.                  NULL_TREE);
  6354.   else
  6355.     DECL_INITIAL (decl) = error_mark_node;
  6356.  
  6357.   return init;
  6358. }
  6359.  
  6360. /* Finish processing of a declaration;
  6361.    install its line number and initial value.
  6362.    If the length of an array type is not known before,
  6363.    it must be determined now, from the initial value, or it is an error.
  6364.  
  6365.    Call `pop_obstacks' iff NEED_POP is nonzero.
  6366.  
  6367.    For C++, `cp_finish_decl' must be fairly evasive:  it must keep initializers
  6368.    for aggregates that have constructors alive on the permanent obstack,
  6369.    so that the global initializing functions can be written at the end.
  6370.  
  6371.    INIT0 holds the value of an initializer that should be allowed to escape
  6372.    the normal rules.
  6373.  
  6374.    FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0
  6375.    if the (init) syntax was used.
  6376.  
  6377.    For functions that take default parameters, DECL points to its
  6378.    "maximal" instantiation.  `cp_finish_decl' must then also declared its
  6379.    subsequently lower and lower forms of instantiation, checking for
  6380.    ambiguity as it goes.  This can be sped up later.  */
  6381.  
  6382. void
  6383. cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
  6384.      tree decl, init;
  6385.      tree asmspec_tree;
  6386.      int need_pop;
  6387.      int flags;
  6388. {
  6389.   register tree type;
  6390.   tree cleanup = NULL_TREE, ttype;
  6391.   int was_incomplete;
  6392.   int temporary = allocation_temporary_p ();
  6393.   char *asmspec = NULL;
  6394.   int was_readonly = 0;
  6395.  
  6396.   /* If this is 0, then we did not change obstacks.  */
  6397.   if (! decl)
  6398.     {
  6399.       if (init)
  6400.     error ("assignment (not initialization) in declaration");
  6401.       return;
  6402.     }
  6403.  
  6404.   /* If a name was specified, get the string.  */
  6405.   if (asmspec_tree)
  6406.       asmspec = TREE_STRING_POINTER (asmspec_tree);
  6407.  
  6408.   /* If the type of the thing we are declaring either has
  6409.      a constructor, or has a virtual function table pointer,
  6410.      AND its initialization was accepted by `start_decl',
  6411.      then we stayed on the permanent obstack through the
  6412.      declaration, otherwise, changed obstacks as GCC would.  */
  6413.  
  6414.   type = TREE_TYPE (decl);
  6415.  
  6416.   if (type == error_mark_node)
  6417.     {
  6418.       if (toplevel_bindings_p () && temporary)
  6419.     end_temporary_allocation ();
  6420.  
  6421.       return;
  6422.     }
  6423.  
  6424.   was_incomplete = (DECL_SIZE (decl) == NULL_TREE);
  6425.  
  6426.   /* Take care of TYPE_DECLs up front.  */
  6427.   if (TREE_CODE (decl) == TYPE_DECL)
  6428.     {
  6429.       if (init && DECL_INITIAL (decl))
  6430.     {
  6431.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  6432.       TREE_TYPE (decl) = type = TREE_TYPE (init);
  6433.       DECL_INITIAL (decl) = init = NULL_TREE;
  6434.     }
  6435.       if (type != error_mark_node
  6436.       && IS_AGGR_TYPE (type) && DECL_NAME (decl))
  6437.     {
  6438.       if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
  6439.         cp_warning ("shadowing previous type declaration of `%#D'", decl);
  6440.       set_identifier_type_value (DECL_NAME (decl), type);
  6441.       CLASSTYPE_GOT_SEMICOLON (type) = 1;
  6442.     }
  6443.       GNU_xref_decl (current_function_decl, decl);
  6444.       rest_of_decl_compilation (decl, NULL_PTR,
  6445.                 DECL_CONTEXT (decl) == NULL_TREE, 0);
  6446.       goto finish_end;
  6447.     }
  6448.   if (TREE_CODE (decl) != FUNCTION_DECL)
  6449.     {
  6450.       ttype = target_type (type);
  6451. #if 0 /* WTF?  -KR
  6452.      Leave this out until we can figure out why it was
  6453.      needed/desirable in the first place.  Then put a comment
  6454.      here explaining why.  Or just delete the code if no ill
  6455.      effects arise.  */
  6456.       if (TYPE_NAME (ttype)
  6457.       && TREE_CODE (TYPE_NAME (ttype)) == TYPE_DECL
  6458.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (ttype)))
  6459.     {
  6460.       tree old_id = TYPE_IDENTIFIER (ttype);
  6461.       char *newname = (char *)alloca (IDENTIFIER_LENGTH (old_id) + 2);
  6462.       /* Need to preserve template data for UPT nodes.  */
  6463.       tree old_template = IDENTIFIER_TEMPLATE (old_id);
  6464.       newname[0] = '_';
  6465.       bcopy (IDENTIFIER_POINTER (old_id), newname + 1,
  6466.          IDENTIFIER_LENGTH (old_id) + 1);
  6467.       old_id = get_identifier (newname);
  6468.       lookup_tag_reverse (ttype, old_id);
  6469.       TYPE_IDENTIFIER (ttype) = old_id;
  6470.       IDENTIFIER_TEMPLATE (old_id) = old_template;
  6471.     }
  6472. #endif
  6473.     }
  6474.  
  6475.   if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
  6476.       && TYPE_NEEDS_CONSTRUCTING (type))
  6477.     {
  6478.  
  6479.       /* Currently, GNU C++ puts constants in text space, making them
  6480.      impossible to initialize.  In the future, one would hope for
  6481.      an operating system which understood the difference between
  6482.      initialization and the running of a program.  */
  6483.       was_readonly = 1;
  6484.       TREE_READONLY (decl) = 0;
  6485.     }
  6486.  
  6487.   if (TREE_CODE (decl) == FIELD_DECL)
  6488.     {
  6489.       if (init && init != error_mark_node)
  6490.     my_friendly_assert (TREE_PERMANENT (init), 147);
  6491.  
  6492.       if (asmspec)
  6493.     {
  6494.       /* This must override the asm specifier which was placed
  6495.          by grokclassfn.  Lay this out fresh.  */
  6496.       DECL_RTL (TREE_TYPE (decl)) = NULL_RTX;
  6497.       DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  6498.       make_decl_rtl (decl, asmspec, 0);
  6499.     }
  6500.     }
  6501.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  6502.   else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE)
  6503.     init = NULL_TREE;
  6504.   else if (DECL_EXTERNAL (decl))
  6505.     ;
  6506.   else if (TREE_CODE (type) == REFERENCE_TYPE
  6507.        || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type)))
  6508.     {
  6509.       if (TREE_STATIC (decl))
  6510.     make_decl_rtl (decl, NULL_PTR,
  6511.                toplevel_bindings_p ()
  6512.                || pseudo_global_level_p ());
  6513.       grok_reference_init (decl, type, init, &cleanup);
  6514.       init = NULL_TREE;
  6515.     }
  6516.  
  6517.   GNU_xref_decl (current_function_decl, decl);
  6518.  
  6519.   if (TREE_CODE (decl) == FIELD_DECL)
  6520.     ;
  6521.   else if (TREE_CODE (decl) == CONST_DECL)
  6522.     {
  6523.       my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
  6524.  
  6525.       DECL_INITIAL (decl) = init;
  6526.  
  6527.       /* This will keep us from needing to worry about our obstacks.  */
  6528.       my_friendly_assert (init != NULL_TREE, 149);
  6529.       init = NULL_TREE;
  6530.     }
  6531.   else if (init)
  6532.     {
  6533.       if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type))
  6534.     {
  6535.       if (TREE_CODE (type) == ARRAY_TYPE)
  6536.         init = digest_init (type, init, (tree *) 0);
  6537.       else if (TREE_CODE (init) == CONSTRUCTOR)
  6538.         {
  6539.           if (TYPE_NON_AGGREGATE_CLASS (type))
  6540.         {
  6541.           cp_error ("`%D' must be initialized by constructor, not by `{...}'",
  6542.                 decl);
  6543.           init = error_mark_node;
  6544.         }
  6545.           else
  6546.         goto dont_use_constructor;
  6547.         }
  6548.     }
  6549.       else
  6550.     {
  6551.     dont_use_constructor:
  6552.       if (TREE_CODE (init) != TREE_VEC)
  6553.         init = store_init_value (decl, init);
  6554.     }
  6555.  
  6556.       if (init)
  6557.     /* We must hide the initializer so that expand_decl
  6558.        won't try to do something it does not understand.  */
  6559.     init = obscure_complex_init (decl, init);
  6560.     }
  6561.   else if (DECL_EXTERNAL (decl))
  6562.     ;
  6563.   else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't'
  6564.        && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type)))
  6565.     {
  6566.       tree ctype = type;
  6567.       while (TREE_CODE (ctype) == ARRAY_TYPE)
  6568.     ctype = TREE_TYPE (ctype);
  6569.       if (! TYPE_NEEDS_CONSTRUCTING (ctype))
  6570.     {
  6571.       if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (ctype))
  6572.         cp_error ("structure `%D' with uninitialized const members", decl);
  6573.       if (CLASSTYPE_REF_FIELDS_NEED_INIT (ctype))
  6574.         cp_error ("structure `%D' with uninitialized reference members",
  6575.               decl);
  6576.     }
  6577.  
  6578.       if (TREE_CODE (decl) == VAR_DECL
  6579.       && !DECL_INITIAL (decl)
  6580.       && !TYPE_NEEDS_CONSTRUCTING (type)
  6581.       && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  6582.     cp_error ("uninitialized const `%D'", decl);
  6583.  
  6584.       if (TYPE_SIZE (type) != NULL_TREE
  6585.       && TYPE_NEEDS_CONSTRUCTING (type))
  6586.     init = obscure_complex_init (decl, NULL_TREE);
  6587.     }
  6588.   else if (TREE_CODE (decl) == VAR_DECL
  6589.        && TREE_CODE (type) != REFERENCE_TYPE
  6590.        && (TYPE_READONLY (type) || TREE_READONLY (decl)))
  6591.     {
  6592.       /* ``Unless explicitly declared extern, a const object does not have
  6593.      external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6
  6594.      However, if it's `const int foo = 1; const int foo;', don't complain
  6595.      about the second decl, since it does have an initializer before.
  6596.      We deliberately don't complain about arrays, because they're
  6597.      supposed to be initialized by a constructor.  */
  6598.       if (! DECL_INITIAL (decl)
  6599.       && TREE_CODE (type) != ARRAY_TYPE
  6600.       && (!pedantic || !current_class_type))
  6601.     cp_error ("uninitialized const `%#D'", decl);
  6602.     }
  6603.  
  6604.   /* For top-level declaration, the initial value was read in
  6605.      the temporary obstack.  MAXINDEX, rtl, etc. to be made below
  6606.      must go in the permanent obstack; but don't discard the
  6607.      temporary data yet.  */
  6608.  
  6609.   if (toplevel_bindings_p () && temporary)
  6610.     end_temporary_allocation ();
  6611.  
  6612.   /* Deduce size of array from initialization, if not already known.  */
  6613.  
  6614.   if (TREE_CODE (type) == ARRAY_TYPE
  6615.       && TYPE_DOMAIN (type) == NULL_TREE
  6616.       && TREE_CODE (decl) != TYPE_DECL)
  6617.     {
  6618.       int do_default
  6619.     = (TREE_STATIC (decl)
  6620.        /* Even if pedantic, an external linkage array
  6621.           may have incomplete type at first.  */
  6622.        ? pedantic && ! DECL_EXTERNAL (decl)
  6623.        : !DECL_EXTERNAL (decl));
  6624.       tree initializer = init ? init : DECL_INITIAL (decl);
  6625.       int failure = complete_array_type (type, initializer, do_default);
  6626.  
  6627.       if (failure == 1)
  6628.     cp_error ("initializer fails to determine size of `%D'", decl);
  6629.  
  6630.       if (failure == 2)
  6631.     {
  6632.       if (do_default)
  6633.         cp_error ("array size missing in `%D'", decl);
  6634.       /* If a `static' var's size isn't known, make it extern as
  6635.          well as static, so it does not get allocated.  If it's not
  6636.          `static', then don't mark it extern; finish_incomplete_decl
  6637.          will give it a default size and it will get allocated.  */
  6638.       else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
  6639.         DECL_EXTERNAL (decl) = 1;
  6640.     }
  6641.  
  6642.       if (pedantic && TYPE_DOMAIN (type) != NULL_TREE
  6643.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  6644.                   integer_zero_node))
  6645.     cp_error ("zero-size array `%D'", decl);
  6646.  
  6647.       layout_decl (decl, 0);
  6648.     }
  6649.  
  6650.   if (TREE_CODE (decl) == VAR_DECL)
  6651.     {
  6652.       if (DECL_SIZE (decl) == NULL_TREE
  6653.       && TYPE_SIZE (TREE_TYPE (decl)) != NULL_TREE)
  6654.     layout_decl (decl, 0);
  6655.  
  6656.       if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE)
  6657.     {
  6658.       /* A static variable with an incomplete type:
  6659.          that is an error if it is initialized.
  6660.          Otherwise, let it through, but if it is not `extern'
  6661.          then it may cause an error message later.  */
  6662.       if (DECL_INITIAL (decl) != NULL_TREE)
  6663.         cp_error ("storage size of `%D' isn't known", decl);
  6664.       init = NULL_TREE;
  6665.     }
  6666.       else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
  6667.     {
  6668.       /* An automatic variable with an incomplete type: that is an error.
  6669.          Don't talk about array types here, since we took care of that
  6670.          message in grokdeclarator.  */
  6671.       cp_error ("storage size of `%D' isn't known", decl);
  6672.       TREE_TYPE (decl) = error_mark_node;
  6673.     }
  6674.       else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype))
  6675.     /* Let debugger know it should output info for this type.  */
  6676.     note_debug_info_needed (ttype);
  6677.  
  6678.       if (TREE_STATIC (decl) && DECL_CONTEXT (decl)
  6679.       && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (decl))) == 't')
  6680.     note_debug_info_needed (DECL_CONTEXT (decl));
  6681.  
  6682.       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
  6683.       && DECL_SIZE (decl) != NULL_TREE
  6684.       && ! TREE_CONSTANT (DECL_SIZE (decl)))
  6685.     {
  6686.       if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
  6687.         constant_expression_warning (DECL_SIZE (decl));
  6688.       else
  6689.         cp_error ("storage size of `%D' isn't constant", decl);
  6690.     }
  6691.  
  6692.       if (!DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type))
  6693.     {
  6694.       int yes = suspend_momentary ();
  6695.  
  6696.       /* If INIT comes from a functional cast, use the cleanup
  6697.          we built for that.  Otherwise, make our own cleanup.  */
  6698.       if (init && TREE_CODE (init) == WITH_CLEANUP_EXPR
  6699.           && comptypes (TREE_TYPE (decl), TREE_TYPE (init), 1))
  6700.         {
  6701.           cleanup = TREE_OPERAND (init, 2);
  6702.           init = TREE_OPERAND (init, 0);
  6703.           current_binding_level->have_cleanups = 1;
  6704.         }
  6705.       else
  6706.         cleanup = maybe_build_cleanup (decl);
  6707.       resume_momentary (yes);
  6708.     }
  6709.     }
  6710.   /* PARM_DECLs get cleanups, too.  */
  6711.   else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type))
  6712.     {
  6713.       if (temporary)
  6714.     end_temporary_allocation ();
  6715.       cleanup = maybe_build_cleanup (decl);
  6716.       if (temporary)
  6717.     resume_temporary_allocation ();
  6718.     }
  6719.  
  6720.   /* Output the assembler code and/or RTL code for variables and functions,
  6721.      unless the type is an undefined structure or union.
  6722.      If not, it will get done when the type is completed.  */
  6723.  
  6724.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL
  6725.       || TREE_CODE (decl) == RESULT_DECL)
  6726.     {
  6727.       /* ??? FIXME: What about nested classes?  */
  6728.       int toplev = toplevel_bindings_p () || pseudo_global_level_p ();
  6729.       int was_temp
  6730.     = ((flag_traditional
  6731.         || (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type)))
  6732.        && allocation_temporary_p ());
  6733.  
  6734.       if (was_temp)
  6735.     end_temporary_allocation ();
  6736.  
  6737.       if (TREE_CODE (decl) == VAR_DECL
  6738.       && ! toplevel_bindings_p ()
  6739.       && ! TREE_STATIC (decl)
  6740.       && type_needs_gc_entry (type))
  6741.     DECL_GC_OFFSET (decl) = size_int (++current_function_obstack_index);
  6742.  
  6743.       if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl))
  6744.     make_decl_rtl (decl, NULL_PTR, toplev);
  6745.       else if (TREE_CODE (decl) == VAR_DECL
  6746.            && TREE_READONLY (decl)
  6747.            && DECL_INITIAL (decl) != NULL_TREE
  6748.            && DECL_INITIAL (decl) != error_mark_node
  6749.            && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl)))
  6750.     {
  6751.       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
  6752.  
  6753.       if (asmspec)
  6754.         DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec);
  6755.  
  6756.       if (! toplev
  6757.           && TREE_STATIC (decl)
  6758.           && ! TREE_SIDE_EFFECTS (decl)
  6759.           && ! TREE_PUBLIC (decl)
  6760.           && ! DECL_EXTERNAL (decl)
  6761.           && ! TYPE_NEEDS_DESTRUCTOR (type)
  6762.           && DECL_MODE (decl) != BLKmode)
  6763.         {
  6764.           /* If this variable is really a constant, then fill its DECL_RTL
  6765.          slot with something which won't take up storage.
  6766.          If something later should take its address, we can always give
  6767.          it legitimate RTL at that time.  */
  6768.           DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  6769.           store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
  6770.           TREE_ASM_WRITTEN (decl) = 1;
  6771.         }
  6772.       else if (toplev && ! TREE_PUBLIC (decl))
  6773.         {
  6774.           /* If this is a static const, change its apparent linkage
  6775.              if it belongs to a #pragma interface.  */
  6776.           if (!interface_unknown)
  6777.         {
  6778.           TREE_PUBLIC (decl) = 1;
  6779.           DECL_EXTERNAL (decl) = interface_only;
  6780.         }
  6781.           make_decl_rtl (decl, asmspec, toplev);
  6782.         }
  6783.       else
  6784.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6785.     }
  6786.       else if (TREE_CODE (decl) == VAR_DECL
  6787.            && DECL_LANG_SPECIFIC (decl)
  6788.            && DECL_IN_AGGR_P (decl))
  6789.     {
  6790.       if (TREE_STATIC (decl))
  6791.         {
  6792.           if (init == NULL_TREE
  6793. #ifdef DEFAULT_STATIC_DEFS
  6794.           /* If this code is dead, then users must
  6795.              explicitly declare static member variables
  6796.              outside the class def'n as well.  */
  6797.           && TYPE_NEEDS_CONSTRUCTING (type)
  6798. #endif
  6799.           )
  6800.         {
  6801.           DECL_EXTERNAL (decl) = 1;
  6802.           make_decl_rtl (decl, asmspec, 1);
  6803.         }
  6804.           else
  6805.         rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6806.         }
  6807.       else
  6808.         /* Just a constant field.  Should not need any rtl.  */
  6809.         goto finish_end0;
  6810.     }
  6811.       else
  6812.     rest_of_decl_compilation (decl, asmspec, toplev, 0);
  6813.  
  6814.       if (was_temp)
  6815.     resume_temporary_allocation ();
  6816.  
  6817.       if (type != error_mark_node
  6818.       && TYPE_LANG_SPECIFIC (type)
  6819.       && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  6820.     abstract_virtuals_error (decl, type);
  6821.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6822.         || TREE_CODE (type) == METHOD_TYPE)
  6823.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6824.            && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type)))
  6825.     abstract_virtuals_error (decl, TREE_TYPE (type));
  6826.  
  6827.       if (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type))
  6828.     signature_error (decl, type);
  6829.       else if ((TREE_CODE (type) == FUNCTION_TYPE
  6830.         || TREE_CODE (type) == METHOD_TYPE)
  6831.            && TYPE_LANG_SPECIFIC (TREE_TYPE (type))
  6832.            && IS_SIGNATURE (TREE_TYPE (type)))
  6833.     signature_error (decl, TREE_TYPE (type));
  6834.  
  6835.       if (TREE_CODE (decl) == FUNCTION_DECL)
  6836.     ;
  6837.       else if (DECL_EXTERNAL (decl))
  6838.     ;
  6839.       else if (TREE_STATIC (decl) && type != error_mark_node)
  6840.     {
  6841.       /* Cleanups for static variables are handled by `finish_file'.  */
  6842.       if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE
  6843.           || TYPE_NEEDS_DESTRUCTOR (type))
  6844.         expand_static_init (decl, init);
  6845.  
  6846.       /* Make entry in appropriate vector.  */
  6847.       if (flag_gc && type_needs_gc_entry (type))
  6848.         build_static_gc_entry (decl, type);
  6849.     }
  6850.       else if (! toplev)
  6851.     {
  6852.       tree old_cleanups = cleanups_this_call;
  6853.       /* This is a declared decl which must live until the
  6854.          end of the binding contour.  It may need a cleanup.  */
  6855.  
  6856.       /* Recompute the RTL of a local array now
  6857.          if it used to be an incomplete type.  */
  6858.       if (was_incomplete && ! TREE_STATIC (decl))
  6859.         {
  6860.           /* If we used it already as memory, it must stay in memory.  */
  6861.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  6862.           /* If it's still incomplete now, no init will save it.  */
  6863.           if (DECL_SIZE (decl) == NULL_TREE)
  6864.         DECL_INITIAL (decl) = NULL_TREE;
  6865.           expand_decl (decl);
  6866.         }
  6867.       else if (! TREE_ASM_WRITTEN (decl)
  6868.            && (TYPE_SIZE (type) != NULL_TREE
  6869.                || TREE_CODE (type) == ARRAY_TYPE))
  6870.         {
  6871.           /* Do this here, because we did not expand this decl's
  6872.          rtl in start_decl.  */
  6873.           if (DECL_RTL (decl) == NULL_RTX)
  6874.         expand_decl (decl);
  6875.           else if (cleanup)
  6876.         {
  6877.           /* XXX: Why don't we use decl here?  */
  6878.           /* Ans: Because it was already expanded? */
  6879.           if (! cp_expand_decl_cleanup (NULL_TREE, cleanup))
  6880.             cp_error ("parser lost in parsing declaration of `%D'",
  6881.                   decl);
  6882.           /* Cleanup used up here.  */
  6883.           cleanup = NULL_TREE;
  6884.         }
  6885.         }
  6886.  
  6887.       if (DECL_SIZE (decl) && type != error_mark_node)
  6888.         {
  6889.           /* Compute and store the initial value.  */
  6890.           expand_decl_init (decl);
  6891.  
  6892.           if (init || TYPE_NEEDS_CONSTRUCTING (type))
  6893.         {
  6894.           emit_line_note (DECL_SOURCE_FILE (decl),
  6895.                   DECL_SOURCE_LINE (decl));
  6896.           expand_aggr_init (decl, init, 0, flags);
  6897.         }
  6898.  
  6899.           /* Set this to 0 so we can tell whether an aggregate which
  6900.          was initialized was ever used.  Don't do this if it has a
  6901.          destructor, so we don't complain about the 'resource
  6902.          allocation is initialization' idiom.  */
  6903.           if (TYPE_NEEDS_CONSTRUCTING (type) && cleanup == NULL_TREE)
  6904.         TREE_USED (decl) = 0;
  6905.  
  6906.           /* Store the cleanup, if there was one.  */
  6907.           if (cleanup)
  6908.         {
  6909.           if (! cp_expand_decl_cleanup (decl, cleanup))
  6910.             cp_error ("parser lost in parsing declaration of `%D'",
  6911.                   decl);
  6912.         }
  6913.         }
  6914.       /* Cleanup any temporaries needed for the initial value.  */
  6915.       expand_cleanups_to (old_cleanups);
  6916.     }
  6917.     finish_end0:
  6918.  
  6919.       /* Undo call to `pushclass' that was done in `start_decl'
  6920.      due to initialization of qualified member variable.
  6921.      I.e., Foo::x = 10;  */
  6922.       {
  6923.     tree context = DECL_REAL_CONTEXT (decl);
  6924.     if (context
  6925.         && TREE_CODE_CLASS (TREE_CODE (context)) == 't'
  6926.         && (TREE_CODE (decl) == VAR_DECL
  6927.         /* We also have a pushclass done that we need to undo here
  6928.            if we're at top level and declare a method.  */
  6929.         || (TREE_CODE (decl) == FUNCTION_DECL
  6930.             /* If size hasn't been set, we're still defining it,
  6931.                and therefore inside the class body; don't pop
  6932.                the binding level..  */
  6933.             && TYPE_SIZE (context) != NULL_TREE
  6934.             /* The binding level gets popped elsewhere for a
  6935.                friend declaration inside another class.  */
  6936.             /*
  6937.             && TYPE_IDENTIFIER (context) == current_class_name
  6938.             */
  6939.             && context == current_class_type
  6940.             )))
  6941.       popclass (1);
  6942.       }
  6943.     }
  6944.  
  6945.  finish_end:
  6946.  
  6947.   /* If requested, warn about definitions of large data objects.  */
  6948.  
  6949.   if (warn_larger_than
  6950.       && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL)
  6951.       && !DECL_EXTERNAL (decl))
  6952.     {
  6953.       register tree decl_size = DECL_SIZE (decl);
  6954.  
  6955.       if (decl_size && TREE_CODE (decl_size) == INTEGER_CST)
  6956.     {
  6957.       unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT;
  6958.  
  6959.       if (units > larger_than_size)
  6960.         warning_with_decl (decl, "size of `%s' is %u bytes", units);
  6961.     }
  6962.     }
  6963.  
  6964.   if (need_pop)
  6965.     {
  6966.       /* Resume permanent allocation, if not within a function.  */
  6967.       /* The corresponding push_obstacks_nochange is in start_decl,
  6968.      start_method, groktypename, and in grokfield.  */
  6969.       pop_obstacks ();
  6970.     }
  6971.  
  6972.   if (was_readonly)
  6973.     TREE_READONLY (decl) = 1;
  6974.  
  6975.   if (flag_cadillac)
  6976.     cadillac_finish_decl (decl);
  6977. }
  6978.  
  6979. /* This is here for a midend callback from c-common.c */
  6980. void
  6981. finish_decl (decl, init, asmspec_tree)
  6982.      tree decl, init;
  6983.      tree asmspec_tree;
  6984. {
  6985.   cp_finish_decl (decl, init, asmspec_tree, 1, 0);
  6986. }
  6987.  
  6988. void
  6989. expand_static_init (decl, init)
  6990.      tree decl;
  6991.      tree init;
  6992. {
  6993.   tree oldstatic = value_member (decl, static_aggregates);
  6994.   tree old_cleanups;
  6995.  
  6996.   if (oldstatic)
  6997.     {
  6998.       if (TREE_PURPOSE (oldstatic) && init != NULL_TREE)
  6999.     cp_error ("multiple initializations given for `%D'", decl);
  7000.     }
  7001.   else if (! toplevel_bindings_p () && ! pseudo_global_level_p ())
  7002.     {
  7003.       /* Emit code to perform this initialization but once.  */
  7004.       tree temp;
  7005.  
  7006.       /* Remember this information until end of file. */
  7007.       push_obstacks (&permanent_obstack, &permanent_obstack);
  7008.  
  7009.       /* Emit code to perform this initialization but once.  */
  7010.       temp = get_temp_name (integer_type_node, 1);
  7011.       rest_of_decl_compilation (temp, NULL_PTR, 0, 0);
  7012.       expand_start_cond (build_binary_op (EQ_EXPR, temp,
  7013.                       integer_zero_node, 1), 0);
  7014.       old_cleanups = cleanups_this_call;
  7015.       expand_assignment (temp, integer_one_node, 0, 0);
  7016.       if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))
  7017.       || (init && TREE_CODE (init) == TREE_LIST))
  7018.     {
  7019.       expand_aggr_init (decl, init, 0, 0);
  7020.       do_pending_stack_adjust ();
  7021.     }
  7022.       else if (init)
  7023.     expand_assignment (decl, init, 0, 0);
  7024.  
  7025.       /* Cleanup any temporaries needed for the initial value.  */
  7026.       expand_cleanups_to (old_cleanups);
  7027.       expand_end_cond ();
  7028.       if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl)))
  7029.     {
  7030.       static_aggregates = perm_tree_cons (temp, decl, static_aggregates);
  7031.       TREE_STATIC (static_aggregates) = 1;
  7032.     }
  7033.  
  7034.       /* Resume old (possibly temporary) allocation. */
  7035.       pop_obstacks ();
  7036.     }
  7037.   else
  7038.     {
  7039.       /* This code takes into account memory allocation
  7040.      policy of `start_decl'.  Namely, if TYPE_NEEDS_CONSTRUCTING
  7041.      does not hold for this object, then we must make permanent
  7042.      the storage currently in the temporary obstack.  */
  7043.       if (! TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  7044.     preserve_initializer ();
  7045.       static_aggregates = perm_tree_cons (init, decl, static_aggregates);
  7046.     }
  7047. }
  7048.  
  7049. /* Make TYPE a complete type based on INITIAL_VALUE.
  7050.    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
  7051.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  7052.  
  7053. int
  7054. complete_array_type (type, initial_value, do_default)
  7055.      tree type, initial_value;
  7056.      int do_default;
  7057. {
  7058.   register tree maxindex = NULL_TREE;
  7059.   int value = 0;
  7060.  
  7061.   if (initial_value)
  7062.     {
  7063.       /* Note MAXINDEX  is really the maximum index,
  7064.      one less than the size.  */
  7065.       if (TREE_CODE (initial_value) == STRING_CST)
  7066.     {
  7067.       int eltsize
  7068.         = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
  7069.       maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value)
  7070.                    / eltsize) - 1, 0);
  7071.     }
  7072.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  7073.     {
  7074.       tree elts = CONSTRUCTOR_ELTS (initial_value);
  7075.       maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node);
  7076.       for (; elts; elts = TREE_CHAIN (elts))
  7077.         {
  7078.           if (TREE_PURPOSE (elts))
  7079.         maxindex = TREE_PURPOSE (elts);
  7080.           else
  7081.         maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node);
  7082.         }
  7083.       maxindex = copy_node (maxindex);
  7084.     }
  7085.       else
  7086.     {
  7087.       /* Make an error message unless that happened already.  */
  7088.       if (initial_value != error_mark_node)
  7089.         value = 1;
  7090.  
  7091.       /* Prevent further error messages.  */
  7092.       maxindex = build_int_2 (0, 0);
  7093.     }
  7094.     }
  7095.  
  7096.   if (!maxindex)
  7097.     {
  7098.       if (do_default)
  7099.     maxindex = build_int_2 (0, 0);
  7100.       value = 2;
  7101.     }
  7102.  
  7103.   if (maxindex)
  7104.     {
  7105.       tree itype;
  7106.  
  7107.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  7108.       if (! TREE_TYPE (maxindex))
  7109.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  7110.       if (initial_value)
  7111.         itype = TREE_TYPE (initial_value);
  7112.       else
  7113.     itype = NULL;
  7114.       if (itype && !TYPE_DOMAIN (itype))
  7115.     TYPE_DOMAIN (itype) = TYPE_DOMAIN (type);
  7116.       /* The type of the main variant should never be used for arrays
  7117.      of different sizes.  It should only ever be completed with the
  7118.      size of the array.  */
  7119.       if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)))
  7120.     TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = TYPE_DOMAIN (type);
  7121.     }
  7122.  
  7123.   /* Lay out the type now that we can get the real answer.  */
  7124.  
  7125.   layout_type (type);
  7126.  
  7127.   return value;
  7128. }
  7129.  
  7130. /* Return zero if something is declared to be a member of type
  7131.    CTYPE when in the context of CUR_TYPE.  STRING is the error
  7132.    message to print in that case.  Otherwise, quietly return 1.  */
  7133. static int
  7134. member_function_or_else (ctype, cur_type, string)
  7135.      tree ctype, cur_type;
  7136.      char *string;
  7137. {
  7138.   if (ctype && ctype != cur_type)
  7139.     {
  7140.       error (string, TYPE_NAME_STRING (ctype));
  7141.       return 0;
  7142.     }
  7143.   return 1;
  7144. }
  7145.  
  7146. /* Subroutine of `grokdeclarator'.  */
  7147.  
  7148. /* Generate errors possibly applicable for a given set of specifiers.
  7149.    This is for ARM $7.1.2.  */
  7150. static void
  7151. bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises)
  7152.      tree object;
  7153.      char *type;
  7154.      int virtualp, quals, friendp, raises, inlinep;
  7155. {
  7156.   if (virtualp)
  7157.     cp_error ("`%D' declared as a `virtual' %s", object, type);
  7158.   if (inlinep)
  7159.     cp_error ("`%D' declared as an `inline' %s", object, type);
  7160.   if (quals)
  7161.     cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration",
  7162.           object, type);
  7163.   if (friendp)
  7164.     cp_error_at ("invalid friend declaration", object);
  7165.   if (raises)
  7166.     cp_error_at ("invalid exception specifications", object);
  7167. }
  7168.  
  7169. /* CTYPE is class type, or null if non-class.
  7170.    TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
  7171.    or METHOD_TYPE.
  7172.    DECLARATOR is the function's name.
  7173.    VIRTUALP is truthvalue of whether the function is virtual or not.
  7174.    FLAGS are to be passed through to `grokclassfn'.
  7175.    QUALS are qualifiers indicating whether the function is `const'
  7176.    or `volatile'.
  7177.    RAISES is a list of exceptions that this function can raise.
  7178.    CHECK is 1 if we must find this method in CTYPE, 0 if we should
  7179.    not look, and -1 if we should not call `grokclassfn' at all.  */
  7180. static tree
  7181. grokfndecl (ctype, type, declarator, virtualp, flags, quals,
  7182.         raises, attrlist, check, publicp, inlinep)
  7183.      tree ctype, type;
  7184.      tree declarator;
  7185.      int virtualp;
  7186.      enum overload_flags flags;
  7187.      tree quals, raises, attrlist;
  7188.      int check, publicp, inlinep;
  7189. {
  7190.   tree cname, decl;
  7191.   int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE;
  7192.  
  7193.   if (ctype)
  7194.     cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL
  7195.       ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype);
  7196.   else
  7197.     cname = NULL_TREE;
  7198.  
  7199.   if (raises)
  7200.     {
  7201.       type = build_exception_variant (type, raises);
  7202.       raises = TYPE_RAISES_EXCEPTIONS (type);
  7203.     }
  7204.   decl = build_lang_decl (FUNCTION_DECL, declarator, type);
  7205.   /* propagate volatile out from type to decl */
  7206.   if (TYPE_VOLATILE (type))
  7207.       TREE_THIS_VOLATILE (decl) = 1;
  7208.  
  7209.   /* Should probably propagate const out from type to decl I bet (mrs).  */
  7210.   if (staticp)
  7211.     {
  7212.       DECL_STATIC_FUNCTION_P (decl) = 1;
  7213.       DECL_CONTEXT (decl) = ctype;
  7214.       DECL_CLASS_CONTEXT (decl) = ctype;
  7215.     }
  7216.  
  7217.   /* All function decls start out public; we'll fix their linkage later (at
  7218.      definition or EOF) if appropriate.  */
  7219.   TREE_PUBLIC (decl) = 1;
  7220.  
  7221.   if (ctype == NULL_TREE && ! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  7222.     {
  7223.       if (inlinep)
  7224.     error ("cannot declare `main' to be inline");
  7225.       else if (! publicp)
  7226.     error ("cannot declare `main' to be static");
  7227.       inlinep = 0;
  7228.       publicp = 1;
  7229.     }
  7230.       
  7231.   if (! publicp)
  7232.     DECL_C_STATIC (decl) = 1;
  7233.  
  7234.   if (inlinep)
  7235.     DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1;
  7236.  
  7237.   DECL_EXTERNAL (decl) = 1;
  7238.   if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE)
  7239.     {
  7240.       cp_error ("%smember function `%D' cannot have `%T' method qualifier",
  7241.         (ctype ? "static " : "non-"), decl, TREE_VALUE (quals));
  7242.       quals = NULL_TREE;
  7243.     }
  7244.  
  7245.   if (IDENTIFIER_OPNAME_P (DECL_NAME (decl)))
  7246.     grok_op_properties (decl, virtualp, check < 0);
  7247.  
  7248.   /* Caller will do the rest of this.  */
  7249.   if (check < 0)
  7250.     return decl;
  7251.  
  7252.   if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator)
  7253.     {
  7254.       tree tmp;
  7255.       /* Just handle constructors here.  We could do this
  7256.      inside the following if stmt, but I think
  7257.      that the code is more legible by breaking this
  7258.      case out.  See comments below for what each of
  7259.      the following calls is supposed to do.  */
  7260.       DECL_CONSTRUCTOR_P (decl) = 1;
  7261.  
  7262.       grokclassfn (ctype, declarator, decl, flags, quals);
  7263.       if (check)
  7264.     check_classfn (ctype, declarator, decl);
  7265.       if (! grok_ctor_properties (ctype, decl))
  7266.     return NULL_TREE;
  7267.  
  7268.       if (check == 0 && ! current_function_decl)
  7269.     {
  7270.       /* FIXME: this should only need to look at
  7271.              IDENTIFIER_GLOBAL_VALUE.  */
  7272.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  7273.       if (tmp == NULL_TREE)
  7274.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  7275.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  7276.         cp_error ("inconsistent declarations for `%D'", decl);
  7277.       else
  7278.         {
  7279.           duplicate_decls (decl, tmp);
  7280.           decl = tmp;
  7281.           /* avoid creating circularities.  */
  7282.           DECL_CHAIN (decl) = NULL_TREE;
  7283.         }
  7284.       make_decl_rtl (decl, NULL_PTR, 1);
  7285.     }
  7286.     }
  7287.   else
  7288.     {
  7289.       tree tmp;
  7290.  
  7291.       /* Function gets the ugly name, field gets the nice one.
  7292.      This call may change the type of the function (because
  7293.      of default parameters)!  */
  7294.       if (ctype != NULL_TREE)
  7295.     grokclassfn (ctype, cname, decl, flags, quals);
  7296.  
  7297.       if (ctype != NULL_TREE && check)
  7298.     check_classfn (ctype, cname, decl);
  7299.  
  7300.       if (ctype == NULL_TREE || check)
  7301.     return decl;
  7302.  
  7303.       /* Now install the declaration of this function so that others may
  7304.      find it (esp. its DECL_FRIENDLIST).  Don't do this for local class
  7305.      methods, though.  */
  7306.       if (! current_function_decl)
  7307.     {
  7308.       /* FIXME: this should only need to look at
  7309.              IDENTIFIER_GLOBAL_VALUE.  */
  7310.       tmp = lookup_name (DECL_ASSEMBLER_NAME (decl), 0);
  7311.       if (tmp == NULL_TREE)
  7312.         IDENTIFIER_GLOBAL_VALUE (DECL_ASSEMBLER_NAME (decl)) = decl;
  7313.       else if (TREE_CODE (tmp) != TREE_CODE (decl))
  7314.         cp_error ("inconsistent declarations for `%D'", decl);
  7315.       else
  7316.         {
  7317.           duplicate_decls (decl, tmp);
  7318.           decl = tmp;
  7319.           /* avoid creating circularities.  */
  7320.           DECL_CHAIN (decl) = NULL_TREE;
  7321.         }
  7322.  
  7323.       if (attrlist)
  7324.         cplus_decl_attributes (decl, TREE_PURPOSE (attrlist),
  7325.                    TREE_VALUE (attrlist));
  7326.       make_decl_rtl (decl, NULL_PTR, 1);
  7327.     }
  7328.  
  7329.       /* If this declaration supersedes the declaration of
  7330.      a method declared virtual in the base class, then
  7331.      mark this field as being virtual as well.  */
  7332.       {
  7333.     tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
  7334.     int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
  7335.  
  7336.     for (i = 0; i < n_baselinks; i++)
  7337.       {
  7338.         tree base_binfo = TREE_VEC_ELT (binfos, i);
  7339.         if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo))
  7340.         || flag_all_virtual == 1)
  7341.           {
  7342.         tmp = get_matching_virtual (base_binfo, decl,
  7343.                         flags == DTOR_FLAG);
  7344.         if (tmp)
  7345.           {
  7346.             /* If this function overrides some virtual in some base
  7347.                class, then the function itself is also necessarily
  7348.                virtual, even if the user didn't explicitly say so.  */
  7349.             DECL_VIRTUAL_P (decl) = 1;
  7350.  
  7351.             /* The TMP we really want is the one from the deepest
  7352.                baseclass on this path, taking care not to
  7353.                duplicate if we have already found it (via another
  7354.                path to its virtual baseclass.  */
  7355.             if (staticp)
  7356.               {
  7357.             cp_error ("method `%D' may not be declared static",
  7358.                   decl);
  7359.             cp_error_at ("(since `%D' declared virtual in base class.)",
  7360.                      tmp);
  7361.             break;
  7362.               }
  7363.             virtualp = 1;
  7364.  
  7365.             {
  7366.               /* The argument types may have changed... */
  7367.               tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  7368.               tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
  7369.  
  7370.               argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
  7371.                           TREE_CHAIN (argtypes));
  7372.               /* But the return type has not.  */
  7373.               type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
  7374.               if (raises)
  7375.             {
  7376.               type = build_exception_variant (type, raises);
  7377.               raises = TYPE_RAISES_EXCEPTIONS (type);
  7378.             }
  7379.               TREE_TYPE (decl) = type;
  7380.               DECL_VINDEX (decl)
  7381.             = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
  7382.             }
  7383.             break;
  7384.           }
  7385.           }
  7386.       }
  7387.       }
  7388.       if (virtualp)
  7389.     {
  7390.       if (DECL_VINDEX (decl) == NULL_TREE)
  7391.         DECL_VINDEX (decl) = error_mark_node;
  7392.       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
  7393.       if (ctype && CLASSTYPE_VTABLE_NEEDS_WRITING (ctype)
  7394.           /* If this function is derived from a template, don't
  7395.          make it public.  This shouldn't be here, but there's
  7396.          no good way to override the interface pragmas for one
  7397.          function or class only.  Bletch.  */
  7398.           && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (ctype)) == NULL_TREE
  7399.           && (write_virtuals == 2
  7400.           || (write_virtuals == 3
  7401.               && CLASSTYPE_INTERFACE_KNOWN (ctype))))
  7402.         TREE_PUBLIC (decl) = 1;
  7403.     }
  7404.     }
  7405.   return decl;
  7406. }
  7407.  
  7408. static tree
  7409. grokvardecl (type, declarator, specbits, initialized, constp)
  7410.      tree type;
  7411.      tree declarator;
  7412.      RID_BIT_TYPE specbits;
  7413.      int initialized;
  7414.      int constp;
  7415. {
  7416.   tree decl;
  7417.  
  7418.   if (TREE_CODE (type) == OFFSET_TYPE)
  7419.     {
  7420.       /* If you declare a static member so that it
  7421.      can be initialized, the code will reach here.  */
  7422.       tree basetype = TYPE_OFFSET_BASETYPE (type);
  7423.       type = TREE_TYPE (type);
  7424.       decl = build_lang_field_decl (VAR_DECL, declarator, type);
  7425.       DECL_CONTEXT (decl) = basetype;
  7426.       DECL_CLASS_CONTEXT (decl) = basetype;
  7427.       DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator);
  7428.     }
  7429.   else
  7430.     decl = build_decl (VAR_DECL, declarator, type);
  7431.  
  7432.   DECL_ASSEMBLER_NAME (decl) = current_namespace_id (DECL_ASSEMBLER_NAME (decl));
  7433.  
  7434.   if (RIDBIT_SETP (RID_EXTERN, specbits))
  7435.     {
  7436.       DECL_THIS_EXTERN (decl) = 1;
  7437.       DECL_EXTERNAL (decl) = !initialized;
  7438.     }
  7439.  
  7440.   /* In class context, static means one per class,
  7441.      public access, and static storage.  */
  7442.   if (DECL_FIELD_CONTEXT (decl) != NULL_TREE
  7443.       && IS_AGGR_TYPE (DECL_FIELD_CONTEXT (decl)))
  7444.     {
  7445.       TREE_PUBLIC (decl) = 1;
  7446.       TREE_STATIC (decl) = 1;
  7447.       DECL_EXTERNAL (decl) = 0;
  7448.     }
  7449.   /* At top level, either `static' or no s.c. makes a definition
  7450.      (perhaps tentative), and absence of `static' makes it public.  */
  7451.   else if (toplevel_bindings_p ())
  7452.     {
  7453.       TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits)
  7454.                 && (DECL_THIS_EXTERN (decl) || ! constp));
  7455.       TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
  7456.     }
  7457.   /* Not at top level, only `static' makes a static definition.  */
  7458.   else
  7459.     {
  7460.       TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits);
  7461.       TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
  7462.     }
  7463.   return decl;
  7464. }
  7465.  
  7466. /* Create a canonical pointer to member function type. */
  7467.  
  7468. tree
  7469. build_ptrmemfunc_type (type)
  7470.      tree type;
  7471. {
  7472.   tree fields[4];
  7473.   tree t;
  7474.   tree u;
  7475.  
  7476.   /* If a canonical type already exists for this type, use it.  We use
  7477.      this method instead of type_hash_canon, because it only does a
  7478.      simple equality check on the list of field members.  */
  7479.  
  7480.   if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type)))
  7481.     return t;
  7482.  
  7483.   push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type));
  7484.  
  7485.   u = make_lang_type (UNION_TYPE);
  7486.   IS_AGGR_TYPE (u) = 0;
  7487.   fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type);
  7488.   fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier,
  7489.                      delta_type_node);
  7490.   finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node);
  7491.   TYPE_NAME (u) = NULL_TREE;
  7492.  
  7493.   t = make_lang_type (RECORD_TYPE);
  7494.  
  7495.   /* Let the front-end know this is a pointer to member function. */
  7496.   TYPE_PTRMEMFUNC_FLAG (t) = 1;
  7497.   /* and not really an aggregate.  */
  7498.   IS_AGGR_TYPE (t) = 0;
  7499.  
  7500.   fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier,
  7501.                      delta_type_node);
  7502.   fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier,
  7503.                      delta_type_node);
  7504.   fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u);
  7505.   finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node);
  7506.  
  7507.   pop_obstacks ();
  7508.  
  7509.   /* Zap out the name so that the back-end will give us the debugging
  7510.      information for this anonymous RECORD_TYPE.  */
  7511.   TYPE_NAME (t) = NULL_TREE;
  7512.  
  7513.   TYPE_SET_PTRMEMFUNC_TYPE (type, t);
  7514.  
  7515.   /* Seems to be wanted. */
  7516.   CLASSTYPE_GOT_SEMICOLON (t) = 1;
  7517.   return t;
  7518. }
  7519.  
  7520. /* Given declspecs and a declarator,
  7521.    determine the name and type of the object declared
  7522.    and construct a ..._DECL node for it.
  7523.    (In one case we can return a ..._TYPE node instead.
  7524.     For invalid input we sometimes return 0.)
  7525.  
  7526.    DECLSPECS is a chain of tree_list nodes whose value fields
  7527.     are the storage classes and type specifiers.
  7528.  
  7529.    DECL_CONTEXT says which syntactic context this declaration is in:
  7530.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  7531.      FUNCDEF for a function definition.  Like NORMAL but a few different
  7532.       error messages in each case.  Return value may be zero meaning
  7533.       this definition is too screwy to try to parse.
  7534.      MEMFUNCDEF for a function definition.  Like FUNCDEF but prepares to
  7535.       handle member functions (which have FIELD context).
  7536.       Return value may be zero meaning this definition is too screwy to
  7537.       try to parse.
  7538.      PARM for a parameter declaration (either within a function prototype
  7539.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  7540.      CATCHPARM for a parameter declaration before a catch clause.
  7541.      TYPENAME if for a typename (in a cast or sizeof).
  7542.       Don't make a DECL node; just return the ..._TYPE node.
  7543.      FIELD for a struct or union field; make a FIELD_DECL.
  7544.      BITFIELD for a field with specified width.
  7545.    INITIALIZED is 1 if the decl has an initializer.
  7546.  
  7547.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  7548.    It may also be so in the PARM case, for a prototype where the
  7549.    argument type is specified but not the name.
  7550.  
  7551.    This function is where the complicated C meanings of `static'
  7552.    and `extern' are interpreted.
  7553.  
  7554.    For C++, if there is any monkey business to do, the function which
  7555.    calls this one must do it, i.e., prepending instance variables,
  7556.    renaming overloaded function names, etc.
  7557.  
  7558.    Note that for this C++, it is an error to define a method within a class
  7559.    which does not belong to that class.
  7560.  
  7561.    Except in the case where SCOPE_REFs are implicitly known (such as
  7562.    methods within a class being redundantly qualified),
  7563.    declarations which involve SCOPE_REFs are returned as SCOPE_REFs
  7564.    (class_name::decl_name).  The caller must also deal with this.
  7565.  
  7566.    If a constructor or destructor is seen, and the context is FIELD,
  7567.    then the type gains the attribute TREE_HAS_x.  If such a declaration
  7568.    is erroneous, NULL_TREE is returned.
  7569.  
  7570.    QUALS is used only for FUNCDEF and MEMFUNCDEF cases.  For a member
  7571.    function, these are the qualifiers to give to the `this' pointer.
  7572.  
  7573.    May return void_type_node if the declarator turned out to be a friend.
  7574.    See grokfield for details.  */
  7575.  
  7576. enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
  7577.  
  7578. tree
  7579. grokdeclarator (declarator, declspecs, decl_context, initialized, raises, attrlist)
  7580.      tree declspecs;
  7581.      tree declarator;
  7582.      enum decl_context decl_context;
  7583.      int initialized;
  7584.      tree raises, attrlist;
  7585. {
  7586.   RID_BIT_TYPE specbits;
  7587.   int nclasses = 0;
  7588.   tree spec;
  7589.   tree type = NULL_TREE;
  7590.   int longlong = 0;
  7591.   int constp;
  7592.   int volatilep;
  7593.   int virtualp, explicitp, friendp, inlinep, staticp;
  7594.   int explicit_int = 0;
  7595.   int explicit_char = 0;
  7596.   int opaque_typedef = 0;
  7597.   tree typedef_decl = NULL_TREE;
  7598.   char *name;
  7599.   tree typedef_type = NULL_TREE;
  7600.   int funcdef_flag = 0;
  7601.   enum tree_code innermost_code = ERROR_MARK;
  7602.   int bitfield = 0;
  7603.   int size_varies = 0;
  7604.   tree decl_machine_attr = NULL_TREE;
  7605. #if defined (_WIN32) && defined (NEXT_PDO)
  7606.   int stdcallp;     // Needed to support the __stdcall keyword used by Microsoft
  7607. #endif
  7608.  
  7609.   /* Set this to error_mark_node for FIELD_DECLs we could not handle properly.
  7610.      All FIELD_DECLs we build here have `init' put into their DECL_INITIAL.  */
  7611.   tree init = NULL_TREE;
  7612.  
  7613.   /* Keep track of what sort of function is being processed
  7614.      so that we can warn about default return values, or explicit
  7615.      return values which do not match prescribed defaults.  */
  7616.   enum return_types return_type = return_normal;
  7617.  
  7618.   tree dname = NULL_TREE;
  7619.   tree ctype = current_class_type;
  7620.   tree ctor_return_type = NULL_TREE;
  7621.   enum overload_flags flags = NO_SPECIAL;
  7622.   tree quals = NULL_TREE;
  7623.  
  7624.   RIDBIT_RESET_ALL (specbits);
  7625.   if (decl_context == FUNCDEF)
  7626.     funcdef_flag = 1, decl_context = NORMAL;
  7627.   else if (decl_context == MEMFUNCDEF)
  7628.     funcdef_flag = -1, decl_context = FIELD;
  7629.   else if (decl_context == BITFIELD)
  7630.     bitfield = 1, decl_context = FIELD;
  7631.  
  7632.   if (flag_traditional && allocation_temporary_p ())
  7633.     end_temporary_allocation ();
  7634.  
  7635.   /* Look inside a declarator for the name being declared
  7636.      and get it as a string, for an error message.  */
  7637.   {
  7638.     tree last = NULL_TREE;
  7639.     register tree decl = declarator;
  7640.     name = NULL;
  7641.  
  7642.     while (decl)
  7643.       switch (TREE_CODE (decl))
  7644.         {
  7645.     case COND_EXPR:
  7646.       ctype = NULL_TREE;
  7647.       decl = TREE_OPERAND (decl, 0);
  7648.       break;
  7649.  
  7650.     case BIT_NOT_EXPR:      /* for C++ destructors!  */
  7651.       {
  7652.         tree name = TREE_OPERAND (decl, 0);
  7653.         tree rename = NULL_TREE;
  7654.  
  7655.         my_friendly_assert (flags == NO_SPECIAL, 152);
  7656.         flags = DTOR_FLAG;
  7657.         return_type = return_dtor;
  7658.         my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153);
  7659.         if (ctype == NULL_TREE)
  7660.           {
  7661.         if (current_class_type == NULL_TREE)
  7662.           {
  7663.             error ("destructors must be member functions");
  7664.             flags = NO_SPECIAL;
  7665.           }
  7666.         else
  7667.           {
  7668.             tree t = constructor_name (current_class_name);
  7669.             if (t != name)
  7670.               rename = t;
  7671.           }
  7672.           }
  7673.         else
  7674.           {
  7675.         tree t = constructor_name (ctype);
  7676.         if (t != name)
  7677.           rename = t;
  7678.           }
  7679.  
  7680.         if (rename)
  7681.           {
  7682.         error ("destructor `%s' must match class name `%s'",
  7683.                IDENTIFIER_POINTER (name),
  7684.                IDENTIFIER_POINTER (rename));
  7685.         TREE_OPERAND (decl, 0) = rename;
  7686.           }
  7687.         decl = name;
  7688.       }
  7689.       break;
  7690.  
  7691.     case ADDR_EXPR:         /* C++ reference declaration */
  7692.       /* fall through */
  7693.     case ARRAY_REF:
  7694.     case INDIRECT_REF:
  7695.       ctype = NULL_TREE;
  7696.       innermost_code = TREE_CODE (decl);
  7697.       last = decl;
  7698.       decl = TREE_OPERAND (decl, 0);
  7699.       break;
  7700.  
  7701.     case CALL_EXPR:
  7702.       if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
  7703.         {
  7704.           /* This is actually a variable declaration using constructor
  7705.          syntax.  We need to call start_decl and cp_finish_decl so we
  7706.          can get the variable initialized...  */
  7707.  
  7708.           if (last)
  7709.         /* We need to insinuate ourselves into the declarator in place
  7710.            of the CALL_EXPR.  */
  7711.         TREE_OPERAND (last, 0) = TREE_OPERAND (decl, 0);
  7712.           else
  7713.         declarator = TREE_OPERAND (decl, 0);
  7714.  
  7715.           init = TREE_OPERAND (decl, 1);
  7716.  
  7717.           decl = start_decl (declarator, declspecs, 1, NULL_TREE);
  7718.           finish_decl (decl, init, NULL_TREE);
  7719.           return 0;
  7720.         }
  7721.       innermost_code = TREE_CODE (decl);
  7722.       if (decl_context == FIELD && ctype == NULL_TREE)
  7723.         ctype = current_class_type;
  7724.       if (ctype
  7725.           && TREE_OPERAND (decl, 0) == constructor_name_full (ctype))
  7726.         TREE_OPERAND (decl, 0) = constructor_name (ctype);
  7727.       decl = TREE_OPERAND (decl, 0);
  7728.       if (ctype != NULL_TREE
  7729.           && decl != NULL_TREE && flags != DTOR_FLAG
  7730.           && decl == constructor_name (ctype))
  7731.         {
  7732.           return_type = return_ctor;
  7733.           ctor_return_type = ctype;
  7734.         }
  7735.       ctype = NULL_TREE;
  7736.       break;
  7737.  
  7738.     case IDENTIFIER_NODE:
  7739.       dname = decl;
  7740.       decl = NULL_TREE;
  7741.  
  7742.       if (! IDENTIFIER_OPNAME_P (dname)
  7743.           /* Linux headers use '__op'.  Arrgh.  */
  7744.           || IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))
  7745.         name = IDENTIFIER_POINTER (dname);
  7746.       else
  7747.         {
  7748.           if (IDENTIFIER_TYPENAME_P (dname))
  7749.         {
  7750.           my_friendly_assert (flags == NO_SPECIAL, 154);
  7751.           flags = TYPENAME_FLAG;
  7752.           ctor_return_type = TREE_TYPE (dname);
  7753.           return_type = return_conversion;
  7754.         }
  7755.           name = operator_name_string (dname);
  7756.         }
  7757.       break;
  7758.  
  7759.     case RECORD_TYPE:
  7760.     case UNION_TYPE:
  7761.     case ENUMERAL_TYPE:
  7762.       /* Parse error puts this typespec where
  7763.          a declarator should go.  */
  7764.       error ("declarator name missing");
  7765.       dname = TYPE_NAME (decl);
  7766.       if (dname && TREE_CODE (dname) == TYPE_DECL)
  7767.         dname = DECL_NAME (dname);
  7768.       name = dname ? IDENTIFIER_POINTER (dname) : "<nameless>";
  7769.       declspecs = temp_tree_cons (NULL_TREE, decl, declspecs);
  7770.       decl = NULL_TREE;
  7771.       break;
  7772.  
  7773.       /* C++ extension */
  7774.     case SCOPE_REF:
  7775.       {
  7776.         /* Perform error checking, and convert class names to types.
  7777.            We may call grokdeclarator multiple times for the same
  7778.            tree structure, so only do the conversion once.  In this
  7779.            case, we have exactly what we want for `ctype'.  */
  7780.         tree cname = TREE_OPERAND (decl, 0);
  7781.         if (cname == NULL_TREE)
  7782.           ctype = NULL_TREE;
  7783.         /* Can't use IS_AGGR_TYPE because CNAME might not be a type.  */
  7784.         else if (IS_AGGR_TYPE_CODE (TREE_CODE (cname))
  7785.              || TREE_CODE (cname) == UNINSTANTIATED_P_TYPE)
  7786.           ctype = cname;
  7787.         else if (! is_aggr_typedef (cname, 1))
  7788.           {
  7789.         TREE_OPERAND (decl, 0) = NULL_TREE;
  7790.           }
  7791.         /* Must test TREE_OPERAND (decl, 1), in case user gives
  7792.            us `typedef (class::memfunc)(int); memfunc *memfuncptr;'  */
  7793.         else if (TREE_OPERAND (decl, 1)
  7794.              && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF)
  7795.           {
  7796.         TREE_OPERAND (decl, 0) = IDENTIFIER_TYPE_VALUE (cname);
  7797.           }
  7798.         else if (ctype == NULL_TREE)
  7799.           {
  7800.         ctype = IDENTIFIER_TYPE_VALUE (cname);
  7801.         TREE_OPERAND (decl, 0) = ctype;
  7802.           }
  7803.         else if (TREE_COMPLEXITY (decl) == current_class_depth)
  7804.           TREE_OPERAND (decl, 0) = ctype;
  7805.         else
  7806.           {
  7807.         if (! UNIQUELY_DERIVED_FROM_P (IDENTIFIER_TYPE_VALUE (cname),
  7808.                            ctype))
  7809.           {
  7810.             cp_error ("type `%T' is not derived from type `%T'",
  7811.                   IDENTIFIER_TYPE_VALUE (cname), ctype);
  7812.             TREE_OPERAND (decl, 0) = NULL_TREE;
  7813.           }
  7814.         else
  7815.           {
  7816.             ctype = IDENTIFIER_TYPE_VALUE (cname);
  7817.             TREE_OPERAND (decl, 0) = ctype;
  7818.           }
  7819.           }
  7820.  
  7821.         if (ctype
  7822.         && TREE_OPERAND (decl, 1) == constructor_name_full (ctype))
  7823.           TREE_OPERAND (decl, 1) = constructor_name (ctype);
  7824.         decl = TREE_OPERAND (decl, 1);
  7825.         if (ctype)
  7826.           {
  7827.         if (TREE_CODE (decl) == IDENTIFIER_NODE
  7828.             && constructor_name (ctype) == decl)
  7829.           {
  7830.             return_type = return_ctor;
  7831.             ctor_return_type = ctype;
  7832.           }
  7833.         else if (TREE_CODE (decl) == BIT_NOT_EXPR
  7834.              && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
  7835.              && (constructor_name (ctype) == TREE_OPERAND (decl, 0)
  7836.                  || constructor_name_full (ctype) == TREE_OPERAND (decl, 0)))
  7837.           {
  7838.             return_type = return_dtor;
  7839.             ctor_return_type = ctype;
  7840.             flags = DTOR_FLAG;
  7841.             decl = TREE_OPERAND (decl, 0) = constructor_name (ctype);
  7842.           }
  7843.           }
  7844.       }
  7845.       break;
  7846.  
  7847.     case ERROR_MARK:
  7848.       decl = NULL_TREE;
  7849.       break;
  7850.  
  7851.     default:
  7852.       return 0; /* We used to do a 155 abort here.  */
  7853.     }
  7854.     if (name == NULL)
  7855.       name = "type name";
  7856.   }
  7857.  
  7858.   /* A function definition's declarator must have the form of
  7859.      a function declarator.  */
  7860.  
  7861.   if (funcdef_flag && innermost_code != CALL_EXPR)
  7862.     return 0;
  7863.  
  7864.   if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG)
  7865.       && innermost_code != CALL_EXPR
  7866.       && ! (ctype && declspecs == NULL_TREE))
  7867.     {
  7868.       cp_error ("declaration of `%D' as non-function", dname);
  7869.       return void_type_node;
  7870.     }
  7871.  
  7872.   /* Anything declared one level down from the top level
  7873.      must be one of the parameters of a function
  7874.      (because the body is at least two levels down).  */
  7875.  
  7876.   /* This heuristic cannot be applied to C++ nodes! Fixed, however,
  7877.      by not allowing C++ class definitions to specify their parameters
  7878.      with xdecls (must be spec.d in the parmlist).
  7879.  
  7880.      Since we now wait to push a class scope until we are sure that
  7881.      we are in a legitimate method context, we must set oldcname
  7882.      explicitly (since current_class_name is not yet alive).
  7883.  
  7884.      We also want to avoid calling this a PARM if it is in a namespace.  */
  7885.  
  7886.   if (decl_context == NORMAL && ! namespace_bindings_p ())
  7887.     {
  7888.       struct binding_level *b = current_binding_level;
  7889.       current_binding_level = b->level_chain;
  7890.       if (current_binding_level != 0 && toplevel_bindings_p ())
  7891.     decl_context = PARM;
  7892.       current_binding_level = b;
  7893.     }
  7894.  
  7895.   /* Look through the decl specs and record which ones appear.
  7896.      Some typespecs are defined as built-in typenames.
  7897.      Others, the ones that are modifiers of other types,
  7898.      are represented by bits in SPECBITS: set the bits for
  7899.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  7900.  
  7901.      If there is a typedef name or a type, store the type in TYPE.
  7902.      This includes builtin typedefs such as `int'.
  7903.  
  7904.      Set EXPLICIT_INT if the type is `int' or `char' and did not
  7905.      come from a user typedef.
  7906.  
  7907.      Set LONGLONG if `long' is mentioned twice.
  7908.  
  7909.      For C++, constructors and destructors have their own fast treatment.  */
  7910.  
  7911.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  7912.     {
  7913.       register int i;
  7914.       register tree id;
  7915.  
  7916.       /* Certain parse errors slip through.  For example,
  7917.      `int class;' is not caught by the parser. Try
  7918.      weakly to recover here.  */
  7919.       if (TREE_CODE (spec) != TREE_LIST)
  7920.     return 0;
  7921.  
  7922.       id = TREE_VALUE (spec);
  7923.  
  7924.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  7925.     {
  7926.       if (id == ridpointers[(int) RID_INT]
  7927.           || id == ridpointers[(int) RID_CHAR]
  7928.           || id == ridpointers[(int) RID_BOOL]
  7929.           || id == ridpointers[(int) RID_WCHAR])
  7930.         {
  7931.           if (type)
  7932.         {
  7933.           if (id == ridpointers[(int) RID_BOOL])
  7934.             error ("`bool' is now a keyword");
  7935.           else
  7936.             cp_error ("extraneous `%T' ignored", id);
  7937.         }
  7938.           else
  7939.         {
  7940.           if (id == ridpointers[(int) RID_INT])
  7941.             explicit_int = 1;
  7942.           else if (id == ridpointers[(int) RID_CHAR])
  7943.             explicit_char = 1;
  7944.           type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id));
  7945.         }
  7946.           goto found;
  7947.         }
  7948.       /* C++ aggregate types. */
  7949.       if (IDENTIFIER_HAS_TYPE_VALUE (id))
  7950.         {
  7951.           if (type)
  7952.         cp_error ("multiple declarations `%T' and `%T'", type, id);
  7953.           else
  7954.         type = IDENTIFIER_TYPE_VALUE (id);
  7955.           goto found;
  7956.         }
  7957.  
  7958.       for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++)
  7959.         {
  7960.           if (ridpointers[i] == id)
  7961.         {
  7962.           if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits))
  7963.             {
  7964.               if (pedantic && ! in_system_header)
  7965.             pedwarn ("ANSI C++ does not support `long long'");
  7966.               else if (longlong)
  7967.             error ("`long long long' is too long for GCC");
  7968.               else
  7969.             longlong = 1;
  7970.             }
  7971.           else if (RIDBIT_SETP (i, specbits))
  7972.             pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  7973.           RIDBIT_SET (i, specbits);
  7974.           goto found;
  7975.         }
  7976.         }
  7977.     }
  7978.       if (type)
  7979.     error ("two or more data types in declaration of `%s'", name);
  7980.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  7981.     {
  7982.       register tree t = lookup_name (id, 1);
  7983.       if (!t || TREE_CODE (t) != TYPE_DECL)
  7984.         error ("`%s' fails to be a typedef or built in type",
  7985.            IDENTIFIER_POINTER (id));
  7986.       else
  7987.         {
  7988.           type = TREE_TYPE (t);
  7989.           decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id);
  7990.           typedef_decl = t;
  7991.         }
  7992.     }
  7993.       else if (TREE_CODE (id) != ERROR_MARK)
  7994.     /* Can't change CLASS nodes into RECORD nodes here!  */
  7995.     type = id;
  7996.  
  7997.     found: ;
  7998.     }
  7999.  
  8000. #if defined (_WIN32) && defined (NEXT_PDO)
  8001.   if (RIDBIT_SETP (RID_DLLIMPORT, specbits))
  8002.     {
  8003.       /* If this is a variable that is being dllimported, then
  8004.      it's really a pointer to a variable where the address 
  8005.      of the variable is what is pointed to.  */
  8006. /*        if( TREE_CODE (declarator) != CALL_EXPR )
  8007.             declarator = build1 (INDIRECT_REF, NULL_TREE, declarator);*/
  8008.     }
  8009. #endif /* _WIN32 */
  8010.  
  8011.   typedef_type = type;
  8012.  
  8013.   /* No type at all: default to `int', and set EXPLICIT_INT
  8014.      because it was not a user-defined typedef.
  8015.      Except when we have a `typedef' inside a signature, in
  8016.      which case the type defaults to `unknown type' and is
  8017.      instantiated when assigning to a signature pointer or ref.  */
  8018.  
  8019.   if (type == NULL_TREE
  8020.       && (RIDBIT_SETP (RID_SIGNED, specbits)
  8021.       || RIDBIT_SETP (RID_UNSIGNED, specbits)
  8022.       || RIDBIT_SETP (RID_LONG, specbits)
  8023.       || RIDBIT_SETP (RID_SHORT, specbits)))
  8024.     {
  8025.       /* These imply 'int'.  */
  8026.       type = integer_type_node;
  8027.       explicit_int = 1;
  8028.     }
  8029.  
  8030.   if (type == NULL_TREE)
  8031.     {
  8032.       explicit_int = -1;
  8033.       if (return_type == return_dtor)
  8034.     type = void_type_node;
  8035.       else if (return_type == return_ctor)
  8036.     type = build_pointer_type (ctor_return_type);
  8037.       else if (return_type == return_conversion)
  8038.     type = ctor_return_type;
  8039.       else if (current_class_type
  8040.            && IS_SIGNATURE (current_class_type)
  8041.            && (RIDBIT_SETP (RID_TYPEDEF, specbits)
  8042.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8043.            && (decl_context == FIELD || decl_context == NORMAL))
  8044.     {
  8045.       explicit_int = 0;
  8046.       opaque_typedef = 1;
  8047.       type = copy_node (opaque_type_node);
  8048.     }
  8049.       /* access declaration */
  8050.       else if (decl_context == FIELD && declarator
  8051.            && TREE_CODE (declarator) == SCOPE_REF)
  8052.     type = void_type_node;
  8053.       else
  8054.     {
  8055.       if (funcdef_flag)
  8056.         {
  8057.           if (warn_return_type
  8058.           && return_type == return_normal)
  8059.         /* Save warning until we know what is really going on.  */
  8060.         warn_about_return_type = 1;
  8061.         }
  8062.       else if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8063.         pedwarn ("ANSI C++ forbids typedef which does not specify a type");
  8064.       else if (declspecs == NULL_TREE &&
  8065.            (innermost_code != CALL_EXPR || pedantic))
  8066.         cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type or storage class",
  8067.             dname);
  8068.       type = integer_type_node;
  8069.     }
  8070.     }
  8071.   else if (return_type == return_dtor)
  8072.     {
  8073.       error ("return type specification for destructor invalid");
  8074.       type = void_type_node;
  8075.     }
  8076.   else if (return_type == return_ctor)
  8077.     {
  8078.       error ("return type specification for constructor invalid");
  8079.       type = build_pointer_type (ctor_return_type);
  8080.     }
  8081.   else if (return_type == return_conversion)
  8082.     {
  8083.       if (comptypes (type, ctor_return_type, 1) == 0)
  8084.     cp_error ("operator `%T' declared to return `%T'",
  8085.           ctor_return_type, type);
  8086.       else
  8087.     cp_pedwarn ("return type specified for `operator %T'",
  8088.             ctor_return_type);
  8089.  
  8090.       type = ctor_return_type;
  8091.     }
  8092.   /* Catch typedefs that only specify a type, like 'typedef int;'.  */
  8093.   else if (RIDBIT_SETP (RID_TYPEDEF, specbits) && declarator == NULL_TREE)
  8094.     {
  8095.       /* Template "this is a type" syntax; just ignore for now.  */
  8096.       if (processing_template_defn)
  8097.     return void_type_node;
  8098.     }
  8099.  
  8100.   ctype = NULL_TREE;
  8101.  
  8102.   /* Now process the modifiers that were specified
  8103.      and check for invalid combinations.  */
  8104.  
  8105.   /* Long double is a special combination.  */
  8106.  
  8107.   if (RIDBIT_SETP (RID_LONG, specbits)
  8108.       && TYPE_MAIN_VARIANT (type) == double_type_node)
  8109.     {
  8110.       RIDBIT_RESET (RID_LONG, specbits);
  8111.       type = build_type_variant (long_double_type_node, TYPE_READONLY (type),
  8112.                  TYPE_VOLATILE (type));
  8113.     }
  8114.  
  8115.   /* Check all other uses of type modifiers.  */
  8116.  
  8117.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  8118.       || RIDBIT_SETP (RID_SIGNED, specbits)
  8119.       || RIDBIT_SETP (RID_LONG, specbits)
  8120.       || RIDBIT_SETP (RID_SHORT, specbits))
  8121.     {
  8122.       int ok = 0;
  8123.  
  8124.       if (TREE_CODE (type) == REAL_TYPE)
  8125.     error ("short, signed or unsigned invalid for `%s'", name);
  8126.       else if (TREE_CODE (type) != INTEGER_TYPE)
  8127.     error ("long, short, signed or unsigned invalid for `%s'", name);
  8128.       else if (RIDBIT_SETP (RID_LONG, specbits)
  8129.            && RIDBIT_SETP (RID_SHORT, specbits))
  8130.     error ("long and short specified together for `%s'", name);
  8131.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  8132.         || RIDBIT_SETP (RID_SHORT, specbits))
  8133.            && explicit_char)
  8134.     error ("long or short specified with char for `%s'", name);
  8135.       else if ((RIDBIT_SETP (RID_LONG, specbits)
  8136.         || RIDBIT_SETP (RID_SHORT, specbits))
  8137.            && TREE_CODE (type) == REAL_TYPE)
  8138.     error ("long or short specified with floating type for `%s'", name);
  8139.       else if (RIDBIT_SETP (RID_SIGNED, specbits)
  8140.            && RIDBIT_SETP (RID_UNSIGNED, specbits))
  8141.     error ("signed and unsigned given together for `%s'", name);
  8142.       else
  8143.     {
  8144.       ok = 1;
  8145.       if (!explicit_int && !explicit_char && pedantic)
  8146.         {
  8147.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  8148.                name);
  8149.           if (flag_pedantic_errors)
  8150.         ok = 0;
  8151.         }
  8152.     }
  8153.  
  8154.       /* Discard the type modifiers if they are invalid.  */
  8155.       if (! ok)
  8156.     {
  8157.       RIDBIT_RESET (RID_UNSIGNED, specbits);
  8158.       RIDBIT_RESET (RID_SIGNED, specbits);
  8159.       RIDBIT_RESET (RID_LONG, specbits);
  8160.       RIDBIT_RESET (RID_SHORT, specbits);
  8161.       longlong = 0;
  8162.     }
  8163.     }
  8164.  
  8165.   /* Decide whether an integer type is signed or not.
  8166.      Optionally treat bitfields as signed by default.  */
  8167.   if (RIDBIT_SETP (RID_UNSIGNED, specbits)
  8168.       /* Traditionally, all bitfields are unsigned.  */
  8169.       || (bitfield && flag_traditional)
  8170.       || (bitfield && ! flag_signed_bitfields
  8171.       && (explicit_int || explicit_char
  8172.           /* A typedef for plain `int' without `signed'
  8173.          can be controlled just like plain `int'.  */
  8174.           || ! (typedef_decl != NULL_TREE
  8175.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  8176.       && TREE_CODE (type) != ENUMERAL_TYPE
  8177.       && RIDBIT_NOTSETP (RID_SIGNED, specbits)))
  8178.     {
  8179.       if (longlong)
  8180.     type = long_long_unsigned_type_node;
  8181.       else if (RIDBIT_SETP (RID_LONG, specbits))
  8182.     type = long_unsigned_type_node;
  8183.       else if (RIDBIT_SETP (RID_SHORT, specbits))
  8184.     type = short_unsigned_type_node;
  8185.       else if (type == char_type_node)
  8186.     type = unsigned_char_type_node;
  8187.       else if (typedef_decl)
  8188.     type = unsigned_type (type);
  8189.       else
  8190.     type = unsigned_type_node;
  8191.     }
  8192.   else if (RIDBIT_SETP (RID_SIGNED, specbits)
  8193.        && type == char_type_node)
  8194.     type = signed_char_type_node;
  8195.   else if (longlong)
  8196.     type = long_long_integer_type_node;
  8197.   else if (RIDBIT_SETP (RID_LONG, specbits))
  8198.     type = long_integer_type_node;
  8199.   else if (RIDBIT_SETP (RID_SHORT, specbits))
  8200.     type = short_integer_type_node;
  8201.  
  8202.   /* Set CONSTP if this declaration is `const', whether by
  8203.      explicit specification or via a typedef.
  8204.      Likewise for VOLATILEP.  */
  8205.  
  8206.   constp = !! RIDBIT_SETP (RID_CONST, specbits) + TYPE_READONLY (type);
  8207.   volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + TYPE_VOLATILE (type);
  8208.   staticp = 0;
  8209.   inlinep = !! RIDBIT_SETP (RID_INLINE, specbits);
  8210. #if defined (_WIN32) && defined (NEXT_PDO)
  8211.   /* TYPE_STDCALL checks the stdcall_flag in the tree structure which indicates
  8212.      that this function uses the stdcall calling convention where the callee
  8213.      pops the arguments off the stack on return, the caller does nothing. */
  8214.   stdcallp = !! (RIDBIT_SETP (RID_STDCALL, specbits))/* + TYPE_STDCALL (type)*/;
  8215. #endif
  8216.  
  8217. #if 0
  8218.   /* This sort of redundancy is blessed in a footnote to the Sep 94 WP.  */
  8219.   if (constp > 1)
  8220.     warning ("duplicate `const'");
  8221.   if (volatilep > 1)
  8222.     warning ("duplicate `volatile'");
  8223. #endif
  8224.   virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits);
  8225.   RIDBIT_RESET (RID_VIRTUAL, specbits);
  8226.   explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0;
  8227.   RIDBIT_RESET (RID_EXPLICIT, specbits);
  8228.  
  8229.   if (RIDBIT_SETP (RID_STATIC, specbits))
  8230.     staticp = 1 + (decl_context == FIELD);
  8231.  
  8232.   if (virtualp && staticp == 2)
  8233.     {
  8234.       cp_error ("member `%D' cannot be declared both virtual and static",
  8235.         dname);
  8236.       staticp = 0;
  8237.     }
  8238.   friendp = RIDBIT_SETP (RID_FRIEND, specbits);
  8239.   RIDBIT_RESET (RID_FRIEND, specbits);
  8240.  
  8241.   if (RIDBIT_SETP (RID_MUTABLE, specbits))
  8242.     {
  8243.       if (decl_context == PARM)
  8244.     {
  8245.       error ("non-member `%s' cannot be declared `mutable'", name);
  8246.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8247.     }
  8248.       else if (friendp || decl_context == TYPENAME)
  8249.     {
  8250.       error ("non-object member `%s' cannot be declared `mutable'", name);
  8251.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8252.     }
  8253. #if 0
  8254.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8255.     {
  8256.       error ("non-object member `%s' cannot be declared `mutable'", name);
  8257.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8258.     }
  8259.       /* Because local typedefs are parsed twice, we don't want this
  8260.      message here. */
  8261.       else if (decl_context != FIELD)
  8262.     {
  8263.       error ("non-member `%s' cannot be declared `mutable'", name);
  8264.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8265.     }
  8266. #endif
  8267.     }
  8268.  
  8269.   /* Warn if two storage classes are given. Default to `auto'.  */
  8270.  
  8271.   if (RIDBIT_ANY_SET (specbits))
  8272.     {
  8273.       if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++;
  8274.       if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++;
  8275.       if (decl_context == PARM && nclasses > 0)
  8276.     error ("storage class specifiers invalid in parameter declarations");
  8277.       if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  8278.     {
  8279.       if (decl_context == PARM)
  8280.         error ("typedef declaration invalid in parameter declaration");
  8281.       nclasses++;
  8282.     }
  8283.       if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++;
  8284.       if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++;
  8285.     }
  8286.  
  8287.   /* Give error if `virtual' is used outside of class declaration.  */
  8288.   if (virtualp
  8289.       && (current_class_name == NULL_TREE || decl_context != FIELD))
  8290.     {
  8291.       error ("virtual outside class declaration");
  8292.       virtualp = 0;
  8293.     }
  8294.   if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits))
  8295.     {
  8296.       error ("only members can be declared mutable");
  8297.       RIDBIT_RESET (RID_MUTABLE, specbits);
  8298.     }
  8299.  
  8300.   /* Static anonymous unions are dealt with here.  */
  8301.   if (staticp && decl_context == TYPENAME
  8302.       && TREE_CODE (declspecs) == TREE_LIST
  8303.       && TREE_CODE (TREE_VALUE (declspecs)) == UNION_TYPE
  8304.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (TREE_VALUE (declspecs))))
  8305.     decl_context = FIELD;
  8306.  
  8307.   /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual'
  8308.      is used in a signature member function declaration.  */
  8309.  
  8310.   if (decl_context == FIELD 
  8311.       && current_class_type != NULL_TREE
  8312.       && IS_SIGNATURE (current_class_type)
  8313.       && RIDBIT_NOTSETP(RID_TYPEDEF, specbits)
  8314.       && !SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8315.     {
  8316.       if (constp)
  8317.     {
  8318.       error ("`const' specified for signature member function `%s'", name);
  8319.       constp = 0;
  8320.     }
  8321.       if (volatilep)
  8322.     {
  8323.       error ("`volatile' specified for signature member function `%s'",
  8324.          name);
  8325.       volatilep = 0;
  8326.     }
  8327.       if (inlinep)
  8328.     {
  8329.       error ("`inline' specified for signature member function `%s'", name);
  8330.       /* Later, we'll make signature member functions inline.  */
  8331.       inlinep = 0;
  8332.     }
  8333.       if (friendp)
  8334.     {
  8335.       error ("`friend' declaration in signature definition");
  8336.       friendp = 0;
  8337.     }
  8338.       if (virtualp)
  8339.     {
  8340.       error ("`virtual' specified for signature member function `%s'",
  8341.          name);
  8342.       /* Later, we'll make signature member functions virtual.  */
  8343.       virtualp = 0;
  8344.     }
  8345.     }
  8346.  
  8347.   /* Warn about storage classes that are invalid for certain
  8348.      kinds of declarations (parameters, typenames, etc.).  */
  8349.  
  8350.   if (nclasses > 1)
  8351.     error ("multiple storage classes in declaration of `%s'", name);
  8352.   else if (decl_context != NORMAL && nclasses > 0)
  8353.     {
  8354.       if ((decl_context == PARM || decl_context == CATCHPARM)
  8355.       && (RIDBIT_SETP (RID_REGISTER, specbits)
  8356.           || RIDBIT_SETP (RID_AUTO, specbits)))
  8357.     ;
  8358.       else if (decl_context == FIELD
  8359.            && RIDBIT_SETP (RID_TYPEDEF, specbits))
  8360.     {
  8361.       /* Processing a typedef declaration nested within a class type
  8362.          definition.  */
  8363.       register tree scanner;
  8364.       register tree previous_declspec;
  8365.         tree loc_typedecl;
  8366.   
  8367.       if (initialized)
  8368.         error ("typedef declaration includes an initializer");
  8369.   
  8370.       /* To process a class-local typedef declaration, we descend down
  8371.          the chain of declspecs looking for the `typedef' spec.  When
  8372.          we find it, we replace it with `static', and then recursively
  8373.          call `grokdeclarator' with the original declarator and with
  8374.          the newly adjusted declspecs.  This call should return a
  8375.          FIELD_DECL node with the TREE_TYPE (and other parts) set
  8376.          appropriately.  We can then just change the TREE_CODE on that
  8377.          from FIELD_DECL to TYPE_DECL and we're done.  */
  8378.  
  8379.       for (previous_declspec = NULL_TREE, scanner = declspecs;
  8380.            scanner;
  8381.            previous_declspec = scanner, scanner = TREE_CHAIN (scanner))
  8382.           {
  8383.           if (TREE_VALUE (scanner) == ridpointers[(int) RID_TYPEDEF])
  8384.         break;
  8385.           }
  8386.  
  8387.       if (previous_declspec)
  8388.         TREE_CHAIN (previous_declspec) = TREE_CHAIN (scanner);
  8389.       else
  8390.         declspecs = TREE_CHAIN (scanner);
  8391.  
  8392.       declspecs = tree_cons (NULL_TREE, ridpointers[(int) RID_STATIC],
  8393.                  declspecs);
  8394.  
  8395.       /* In the recursive call to grokdeclarator we need to know
  8396.          whether we are working on a signature-local typedef.  */
  8397.       if (IS_SIGNATURE (current_class_type))
  8398.         SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 1;
  8399.   
  8400.       loc_typedecl =
  8401.         grokdeclarator (declarator, declspecs, FIELD, 0, NULL_TREE, NULL_TREE);
  8402.  
  8403.       if (previous_declspec)
  8404.         TREE_CHAIN (previous_declspec) = scanner;
  8405.   
  8406.       if (loc_typedecl != error_mark_node)
  8407.           {
  8408.           register int i = sizeof (struct lang_decl_flags) / sizeof (int);
  8409.           register int *pi;
  8410.   
  8411.           TREE_SET_CODE (loc_typedecl, TYPE_DECL);
  8412.           /* This is the same field as DECL_ARGUMENTS, which is set for
  8413.          function typedefs by the above grokdeclarator.  */
  8414.           DECL_NESTED_TYPENAME (loc_typedecl) = 0;
  8415.   
  8416.           pi = (int *) permalloc (sizeof (struct lang_decl_flags));
  8417.           while (i > 0)
  8418.             pi[--i] = 0;
  8419.           DECL_LANG_SPECIFIC (loc_typedecl) = (struct lang_decl *) pi;
  8420.         }
  8421.   
  8422.       if (IS_SIGNATURE (current_class_type))
  8423.         {
  8424.           SIGNATURE_GROKKING_TYPEDEF (current_class_type) = 0;
  8425.           if (loc_typedecl != error_mark_node && opaque_typedef)
  8426.         SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1;
  8427.         }
  8428.  
  8429.         return loc_typedecl;
  8430.     }
  8431.       else if (decl_context == FIELD
  8432.            && (! IS_SIGNATURE (current_class_type)
  8433.            || SIGNATURE_GROKKING_TYPEDEF (current_class_type))
  8434.             /* C++ allows static class elements  */
  8435.             && RIDBIT_SETP (RID_STATIC, specbits))
  8436.      /* C++ also allows inlines and signed and unsigned elements,
  8437.         but in those cases we don't come in here.  */
  8438.     ;
  8439.       else
  8440.     {
  8441.       if (decl_context == FIELD)
  8442.         {
  8443.           tree tmp = NULL_TREE;
  8444.           register int op = 0;
  8445.  
  8446.           if (declarator)
  8447.         {
  8448.           tmp = TREE_OPERAND (declarator, 0);
  8449.           op = IDENTIFIER_OPNAME_P (tmp);
  8450.         }
  8451.           error ("storage class specified for %s `%s'",
  8452.              IS_SIGNATURE (current_class_type)
  8453.              ? (op
  8454.             ? "signature member operator"
  8455.             : "signature member function")
  8456.              : (op ? "member operator" : "field"),
  8457.              op ? operator_name_string (tmp) : name);
  8458.         }
  8459.       else
  8460.         error (((decl_context == PARM || decl_context == CATCHPARM)
  8461.             ? "storage class specified for parameter `%s'"
  8462.             : "storage class specified for typename"), name);
  8463.       RIDBIT_RESET (RID_REGISTER, specbits);
  8464.       RIDBIT_RESET (RID_AUTO, specbits);
  8465.       RIDBIT_RESET (RID_EXTERN, specbits);
  8466.  
  8467.       if (decl_context == FIELD && IS_SIGNATURE (current_class_type))
  8468.         {
  8469.           RIDBIT_RESET (RID_STATIC, specbits);
  8470.           staticp = 0;
  8471.         }
  8472.     }
  8473.     }
  8474.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag)
  8475.     {
  8476.       if (toplevel_bindings_p ())
  8477.     {
  8478.       /* It's common practice (and completely valid) to have a const
  8479.          be initialized and declared extern.  */
  8480.       if (! constp)
  8481.         warning ("`%s' initialized and declared `extern'", name);
  8482.     }
  8483.       else
  8484.     error ("`%s' has both `extern' and initializer", name);
  8485.     }
  8486.   else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag
  8487.        && ! toplevel_bindings_p ())
  8488.     error ("nested function `%s' declared `extern'", name);
  8489.   else if (toplevel_bindings_p ())
  8490.     {
  8491.       if (RIDBIT_SETP (RID_AUTO, specbits))
  8492.     error ("top-level declaration of `%s' specifies `auto'", name);
  8493. #if 0
  8494.       if (RIDBIT_SETP (RID_REGISTER, specbits))
  8495.     error ("top-level declaration of `%s' specifies `register'", name);
  8496. #endif
  8497. #if 0
  8498.       /* I'm not sure under what circumstances we should turn
  8499.      on the extern bit, and under what circumstances we should
  8500.      warn if other bits are turned on.  */
  8501.       if (decl_context == NORMAL
  8502.       && RIDBIT_NOSETP (RID_EXTERN, specbits)
  8503.       && ! root_lang_context_p ())
  8504.     {
  8505.       RIDBIT_SET (RID_EXTERN, specbits);
  8506.     }
  8507. #endif
  8508.     }
  8509.  
  8510.   /* Now figure out the structure of the declarator proper.
  8511.      Descend through it, creating more complex types, until we reach
  8512.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  8513.  
  8514.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  8515.     {
  8516.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  8517.      an INDIRECT_REF (for *...),
  8518.      a CALL_EXPR (for ...(...)),
  8519.      an identifier (for the name being declared)
  8520.      or a null pointer (for the place in an absolute declarator
  8521.      where the name was omitted).
  8522.      For the last two cases, we have just exited the loop.
  8523.  
  8524.      For C++ it could also be
  8525.      a SCOPE_REF (for class :: ...).  In this case, we have converted
  8526.      sensible names to types, and those are the values we use to
  8527.      qualify the member name.
  8528.      an ADDR_EXPR (for &...),
  8529.      a BIT_NOT_EXPR (for destructors)
  8530.  
  8531.      At this point, TYPE is the type of elements of an array,
  8532.      or for a function to return, or for a pointer to point to.
  8533.      After this sequence of ifs, TYPE is the type of the
  8534.      array or function or pointer, and DECLARATOR has had its
  8535.      outermost layer removed.  */
  8536.  
  8537.       if (TREE_CODE (type) == ERROR_MARK)
  8538.     {
  8539.       if (TREE_CODE (declarator) == SCOPE_REF)
  8540.         declarator = TREE_OPERAND (declarator, 1);
  8541.       else
  8542.         declarator = TREE_OPERAND (declarator, 0);
  8543.       continue;
  8544.     }
  8545.       if (quals != NULL_TREE
  8546.       && (declarator == NULL_TREE
  8547.           || TREE_CODE (declarator) != SCOPE_REF))
  8548.     {
  8549.       if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE)
  8550.         ctype = TYPE_METHOD_BASETYPE (type);
  8551.       if (ctype != NULL_TREE)
  8552.         {
  8553. #if 0 /* not yet, should get fixed properly later */
  8554.           tree dummy = make_type_decl (NULL_TREE, type);
  8555. #else
  8556.           tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
  8557. #endif
  8558.           ctype = grok_method_quals (ctype, dummy, quals);
  8559.           type = TREE_TYPE (dummy);
  8560.           quals = NULL_TREE;
  8561.         }
  8562.     }
  8563.       switch (TREE_CODE (declarator))
  8564.     {
  8565.     case ARRAY_REF:
  8566.       {
  8567.         register tree itype = NULL_TREE;
  8568.         register tree size = TREE_OPERAND (declarator, 1);
  8569.         /* The index is a signed object `sizetype' bits wide.  */
  8570.         tree index_type = signed_type (sizetype);
  8571.  
  8572.         declarator = TREE_OPERAND (declarator, 0);
  8573.  
  8574.         /* Check for some types that there cannot be arrays of.  */
  8575.  
  8576.         if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8577.           {
  8578.         cp_error ("declaration of `%D' as array of voids", dname);
  8579.         type = error_mark_node;
  8580.           }
  8581.  
  8582.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8583.           {
  8584.         cp_error ("declaration of `%D' as array of functions", dname);
  8585.         type = error_mark_node;
  8586.           }
  8587.  
  8588.         /* ARM $8.4.3: Since you can't have a pointer to a reference,
  8589.            you can't have arrays of references.  If we allowed them,
  8590.            then we'd be saying x[i] is valid for an array x, but
  8591.            then you'd have to ask: what does `*(x + i)' mean?  */
  8592.         if (TREE_CODE (type) == REFERENCE_TYPE)
  8593.           {
  8594.         if (decl_context == TYPENAME)
  8595.           cp_error ("cannot make arrays of references");
  8596.         else
  8597.           cp_error ("declaration of `%D' as array of references",
  8598.                 dname);
  8599.         type = error_mark_node;
  8600.           }
  8601.  
  8602.         if (TREE_CODE (type) == OFFSET_TYPE)
  8603.           {
  8604.           cp_error ("declaration of `%D' as array of data members",
  8605.                 dname);
  8606.         type = error_mark_node;
  8607.           }
  8608.  
  8609.         if (TREE_CODE (type) == METHOD_TYPE)
  8610.           {
  8611.         cp_error ("declaration of `%D' as array of function members",
  8612.               dname);
  8613.         type = error_mark_node;
  8614.           }
  8615.  
  8616.         if (size == error_mark_node)
  8617.           type = error_mark_node;
  8618.  
  8619.         if (type == error_mark_node)
  8620.           continue;
  8621.  
  8622.         if (size)
  8623.           {
  8624.         /* Must suspend_momentary here because the index
  8625.            type may need to live until the end of the function.
  8626.            For example, it is used in the declaration of a
  8627.            variable which requires destructing at the end of
  8628.            the function; then build_vec_delete will need this
  8629.            value.  */
  8630.         int yes = suspend_momentary ();
  8631.         /* might be a cast */
  8632.         if (TREE_CODE (size) == NOP_EXPR
  8633.             && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
  8634.           size = TREE_OPERAND (size, 0);
  8635.  
  8636.         /* If this is a template parameter, it'll be constant, but
  8637.            we don't know what the value is yet.  */
  8638.         if (TREE_CODE (size) == TEMPLATE_CONST_PARM)
  8639.           goto dont_grok_size;
  8640.  
  8641.         if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  8642.             && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  8643.           {
  8644.             cp_error ("size of array `%D' has non-integer type",
  8645.                   dname);
  8646.             size = integer_one_node;
  8647.           }
  8648.         if (TREE_READONLY_DECL_P (size))
  8649.           size = decl_constant_value (size);
  8650.         if (pedantic && integer_zerop (size))
  8651.           cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
  8652.         if (TREE_CONSTANT (size))
  8653.           {
  8654.             int old_flag_pedantic_errors = flag_pedantic_errors;
  8655.             int old_pedantic = pedantic;
  8656.             pedantic = flag_pedantic_errors = 1;
  8657.             /* Always give overflow errors on array subscripts.  */
  8658.             constant_expression_warning (size);
  8659.             pedantic = old_pedantic;
  8660.             flag_pedantic_errors = old_flag_pedantic_errors;
  8661.             if (INT_CST_LT (size, integer_zero_node))
  8662.               {
  8663.             cp_error ("size of array `%D' is negative", dname);
  8664.             size = integer_one_node;
  8665.               }
  8666.           }
  8667.         else
  8668.           {
  8669.             if (pedantic)
  8670.               {
  8671.             if (dname)
  8672.               cp_pedwarn ("ANSI C++ forbids variable-size array `%D'",
  8673.                       dname);
  8674.             else
  8675.               cp_pedwarn ("ANSI C++ forbids variable-size array");
  8676.               }
  8677.             /* Make sure the array size remains visibly nonconstant
  8678.                even if it is (eg) a const variable with known value. */
  8679.             size_varies = 1;
  8680.           }
  8681.  
  8682.           dont_grok_size:
  8683.         itype =
  8684.           fold (build_binary_op (MINUS_EXPR,
  8685.                      convert (index_type, size),
  8686.                      convert (index_type,
  8687.                           integer_one_node), 1));
  8688.         if (! TREE_CONSTANT (itype))
  8689.           itype = variable_size (itype);
  8690.         itype = build_index_type (itype);
  8691.         resume_momentary (yes);
  8692.           }
  8693.  
  8694.       /* Build the array type itself, then merge any constancy or
  8695.          volatility into the target type.  We must do it in this order
  8696.          to ensure that the TYPE_MAIN_VARIANT field of the array type
  8697.          is set correctly.  */
  8698.  
  8699.         type = build_cplus_array_type (type, itype);
  8700.         if (constp || volatilep)
  8701.           type = cp_build_type_variant (type, constp, volatilep);
  8702.  
  8703.         ctype = NULL_TREE;
  8704.       }
  8705.       break;
  8706.  
  8707.     case CALL_EXPR:
  8708.       {
  8709.         tree arg_types;
  8710.         int funcdecl_p;
  8711.         tree inner_parms = TREE_OPERAND (declarator, 1);
  8712.         tree inner_decl = TREE_OPERAND (declarator, 0);
  8713.  
  8714.         /* Declaring a function type.
  8715.            Make sure we have a valid type for the function to return.  */
  8716. #if 0
  8717.         /* Is this an error?  Should they be merged into TYPE here?  */
  8718.         if (pedantic && (constp || volatilep))
  8719.           pedwarn ("function declared to return const or volatile result");
  8720. #else
  8721.         /* Merge any constancy or volatility into the function return
  8722.                type.  */
  8723.  
  8724.         if (constp || volatilep)
  8725.           {
  8726.         type = cp_build_type_variant (type, constp, volatilep);
  8727.         if (IS_AGGR_TYPE (type))
  8728.           build_pointer_type (type);
  8729.         constp = 0;
  8730.         volatilep = 0;
  8731.           }
  8732. #endif
  8733.  
  8734.         /* Warn about some types functions can't return.  */
  8735.  
  8736.         if (TREE_CODE (type) == FUNCTION_TYPE)
  8737.           {
  8738.         error ("`%s' declared as function returning a function", name);
  8739.         type = integer_type_node;
  8740.           }
  8741.         if (TREE_CODE (type) == ARRAY_TYPE)
  8742.           {
  8743.         error ("`%s' declared as function returning an array", name);
  8744.         type = integer_type_node;
  8745.           }
  8746.  
  8747.         if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF)
  8748.           inner_decl = TREE_OPERAND (inner_decl, 1);
  8749.  
  8750.         /* Pick up type qualifiers which should be applied to `this'.  */
  8751.         quals = TREE_OPERAND (declarator, 2);
  8752.  
  8753.         /* Say it's a definition only for the CALL_EXPR
  8754.            closest to the identifier.  */
  8755.         funcdecl_p =
  8756.           inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE
  8757.                  || TREE_CODE (inner_decl) == BIT_NOT_EXPR);
  8758.  
  8759.         if (ctype == NULL_TREE
  8760.         && decl_context == FIELD
  8761.         && funcdecl_p
  8762.         && (friendp == 0 || dname == current_class_name))
  8763.           ctype = current_class_type;
  8764.  
  8765.         if (ctype && return_type == return_conversion)
  8766.           TYPE_HAS_CONVERSION (ctype) = 1;
  8767.         if (ctype && constructor_name (ctype) == dname)
  8768.           {
  8769.         /* We are within a class's scope. If our declarator name
  8770.            is the same as the class name, and we are defining
  8771.            a function, then it is a constructor/destructor, and
  8772.            therefore returns a void type.  */
  8773.  
  8774.         if (flags == DTOR_FLAG)
  8775.           {
  8776.             /* ANSI C++ June 5 1992 WP 12.4.1.  A destructor may
  8777.                not be declared const or volatile.  A destructor
  8778.                may not be static.  */
  8779.             if (staticp == 2)
  8780.               error ("destructor cannot be static member function");
  8781.             if (quals)
  8782.               {
  8783.             error ("destructors cannot be declared `const' or `volatile'");
  8784.             return void_type_node;
  8785.               }
  8786.             if (decl_context == FIELD)
  8787.               {
  8788.             if (! member_function_or_else (ctype, current_class_type,
  8789.                                "destructor for alien class `%s' cannot be a member"))
  8790.               return void_type_node;
  8791.               }
  8792.           }
  8793.         else            /* it's a constructor. */
  8794.           {
  8795.             if (explicitp == 1)
  8796.               explicitp = 2;
  8797.             /* ANSI C++ June 5 1992 WP 12.1.2.  A constructor may
  8798.                not be declared const or volatile.  A constructor may
  8799.                not be virtual.  A constructor may not be static.  */
  8800.             if (staticp == 2)
  8801.               error ("constructor cannot be static member function");
  8802.             if (virtualp)
  8803.               {
  8804.             pedwarn ("constructors cannot be declared virtual");
  8805.             virtualp = 0;
  8806.               }
  8807.             if (quals)
  8808.               {
  8809.             error ("constructors cannot be declared `const' or `volatile'");
  8810.             return void_type_node;
  8811.                }
  8812.             {
  8813.               RID_BIT_TYPE tmp_bits;
  8814.               bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof(RID_BIT_TYPE));
  8815.               RIDBIT_RESET (RID_INLINE, tmp_bits);
  8816.               RIDBIT_RESET (RID_STATIC, tmp_bits);
  8817.               if (RIDBIT_ANY_SET (tmp_bits))
  8818.             error ("return value type specifier for constructor ignored");
  8819.             }
  8820.             type = build_pointer_type (ctype);
  8821.             if (decl_context == FIELD &&
  8822.             IS_SIGNATURE (current_class_type))
  8823.               {
  8824.             error ("constructor not allowed in signature");
  8825.             return void_type_node;
  8826.               }              
  8827.             else if (decl_context == FIELD)
  8828.               {
  8829.             if (! member_function_or_else (ctype, current_class_type,
  8830.                                "constructor for alien class `%s' cannot be member"))
  8831.               return void_type_node;
  8832.             TYPE_HAS_CONSTRUCTOR (ctype) = 1;
  8833.             if (return_type != return_ctor)
  8834.               return NULL_TREE;
  8835.               }
  8836.           }
  8837.         if (decl_context == FIELD)
  8838.           staticp = 0;
  8839.           }
  8840.         else if (friendp)
  8841.           {
  8842.         if (initialized)
  8843.           error ("can't initialize friend function `%s'", name);
  8844.         if (virtualp)
  8845.           {
  8846.             /* Cannot be both friend and virtual.  */
  8847.             error ("virtual functions cannot be friends");
  8848.             RIDBIT_RESET (RID_FRIEND, specbits);
  8849.             friendp = 0;
  8850.           }
  8851.         if (decl_context == NORMAL)
  8852.           error ("friend declaration not in class definition");
  8853.         if (current_function_decl && funcdef_flag)
  8854.           cp_error ("can't define friend function `%s' in a local class definition",
  8855.                 name);
  8856.           }
  8857.  
  8858.         /* Traditionally, declaring return type float means double.  */
  8859.  
  8860.         if (flag_traditional
  8861.         && TYPE_MAIN_VARIANT (type) == float_type_node)
  8862.           {
  8863.         type = build_type_variant (double_type_node,
  8864.                        TYPE_READONLY (type),
  8865.                        TYPE_VOLATILE (type));
  8866.           }
  8867.  
  8868.         /* Construct the function type and go to the next
  8869.            inner layer of declarator.  */
  8870.  
  8871.         declarator = TREE_OPERAND (declarator, 0);
  8872.  
  8873.         /* FIXME: This is where default args should be fully
  8874.            processed.  */
  8875.  
  8876.         arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0);
  8877.  
  8878.         if (declarator)
  8879.           {
  8880.         /* Get past destructors, etc.
  8881.            We know we have one because FLAGS will be non-zero.
  8882.  
  8883.            Complain about improper parameter lists here.  */
  8884.         if (TREE_CODE (declarator) == BIT_NOT_EXPR)
  8885.           {
  8886.             declarator = TREE_OPERAND (declarator, 0);
  8887.  
  8888.             if (strict_prototype == 0 && arg_types == NULL_TREE)
  8889.               arg_types = void_list_node;
  8890.             else if (arg_types == NULL_TREE
  8891.                  || arg_types != void_list_node)
  8892.               {
  8893.             error ("destructors cannot be specified with parameters");
  8894.             arg_types = void_list_node;
  8895.               }
  8896.           }
  8897.           }
  8898.  
  8899.         /* ANSI seems to say that `const int foo ();'
  8900.            does not make the function foo const.  */
  8901.         type = build_function_type (type,
  8902.                     flag_traditional ? 0 : arg_types);
  8903. #ifdef _WIN32
  8904.         /* If this function uses the stdcall calling conventions, mark the 
  8905.         tree as such by setting the stdcall_flag to 1. */
  8906.         if( stdcallp )
  8907.         {
  8908.         type = build_type_copy( type );
  8909.         TYPE_STDCALL( type ) = 1;
  8910.         }
  8911. #endif /* _WIN32 */
  8912.  
  8913.       }
  8914.       break;
  8915.  
  8916.     case ADDR_EXPR:
  8917.     case INDIRECT_REF:
  8918.       /* Filter out pointers-to-references and references-to-references.
  8919.          We can get these if a TYPE_DECL is used.  */
  8920.  
  8921.       if (TREE_CODE (type) == REFERENCE_TYPE)
  8922.         {
  8923.           error ("cannot declare %s to references",
  8924.              TREE_CODE (declarator) == ADDR_EXPR
  8925.              ? "references" : "pointers");
  8926.           declarator = TREE_OPERAND (declarator, 0);
  8927.           continue;
  8928.         }
  8929.  
  8930.       if (TREE_CODE (type) == OFFSET_TYPE
  8931.           && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE
  8932.           || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE))
  8933.         {
  8934.           cp_error ("cannot declare pointer to `%#T' member",
  8935.             TREE_TYPE (type));
  8936.           type = TREE_TYPE (type);
  8937.         }
  8938.  
  8939.       /* Merge any constancy or volatility into the target type
  8940.          for the pointer.  */
  8941.  
  8942.       if (constp || volatilep)
  8943.         {
  8944.           /* A const or volatile signature pointer/reference is
  8945.          pointing to a const or volatile object, i.e., the
  8946.          `optr' is const or volatile, respectively, not the
  8947.          signature pointer/reference itself.  */
  8948.           if (! IS_SIGNATURE (type))
  8949.         {
  8950.           type = cp_build_type_variant (type, constp, volatilep);
  8951.           if (IS_AGGR_TYPE (type))
  8952.             build_pointer_type (type);
  8953.           constp = 0;
  8954.           volatilep = 0;
  8955.         }
  8956.         }
  8957.  
  8958.       if (IS_SIGNATURE (type))
  8959.         {
  8960.           if (TREE_CODE (declarator) == ADDR_EXPR)
  8961.         {
  8962.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8963.               && TYPE_SIZE (type))
  8964.             cp_warning ("empty signature `%T' used in signature reference declaration",
  8965.                 type);
  8966. #if 0
  8967.           type = build_signature_reference_type (type,
  8968.                              constp, volatilep);
  8969. #else
  8970.           sorry ("signature reference");
  8971.           return NULL_TREE;
  8972. #endif
  8973.         }
  8974.           else
  8975.         {
  8976.           if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE
  8977.               && TYPE_SIZE (type))
  8978.             cp_warning ("empty signature `%T' used in signature pointer declaration",
  8979.                 type);
  8980.           type = build_signature_pointer_type (type,
  8981.                                constp, volatilep);
  8982.         }
  8983.           constp = 0;
  8984.           volatilep = 0;
  8985.         }
  8986.       else if (TREE_CODE (declarator) == ADDR_EXPR)
  8987.         {
  8988.           if (TREE_CODE (type) == FUNCTION_TYPE)
  8989.         {
  8990.           error ("cannot declare references to functions; use pointer to function instead");
  8991.           type = build_pointer_type (type);
  8992.         }
  8993.           else
  8994.         {
  8995.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  8996.             error ("invalid type: `void &'");
  8997.           else
  8998.             type = build_reference_type (type);
  8999.         }
  9000.         }
  9001.       else if (TREE_CODE (type) == METHOD_TYPE)
  9002.         {
  9003.           type = build_ptrmemfunc_type (build_pointer_type (type));
  9004.         }
  9005.       else
  9006.         type = build_pointer_type (type);
  9007.  
  9008.       /* Process a list of type modifier keywords (such as
  9009.          const or volatile) that were given inside the `*' or `&'.  */
  9010.  
  9011.       if (TREE_TYPE (declarator))
  9012.         {
  9013.           register tree typemodlist;
  9014.           int erred = 0;
  9015.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  9016.            typemodlist = TREE_CHAIN (typemodlist))
  9017.         {
  9018.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  9019.             constp++;
  9020.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  9021.             volatilep++;
  9022. #ifdef _WIN32
  9023.           /* We had a problem under NT with the __stdcall keyword where calling 
  9024.              a __stdcall function indirectly wouldn't use the correct calling 
  9025.              convention.  This was added so that when the pointer to the function
  9026.              is declared it is marked as using the stdcall conventions. */
  9027.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_STDCALL])
  9028.           {
  9029.               stdcallp++;
  9030.                 type = build_type_copy( TREE_TYPE( type ) );
  9031.                 type = build_pointer_type( type );
  9032.                 TYPE_STDCALL( TREE_TYPE( type ) ) = 1;
  9033.           }
  9034. #endif /* _WIN32 */
  9035.           else if (!erred)
  9036.             {
  9037.               erred = 1;
  9038.               error ("invalid type modifier within %s declarator",
  9039.                  TREE_CODE (declarator) == ADDR_EXPR
  9040.                  ? "reference" : "pointer");
  9041.             }
  9042.         }
  9043.           if (constp > 1)
  9044.         pedwarn ("duplicate `const'");
  9045.           if (volatilep > 1)
  9046.         pedwarn ("duplicate `volatile'");
  9047. #ifdef _WIN32
  9048.           if (stdcallp > 1)
  9049.         pedwarn ("duplicate `stdcall'");
  9050. #endif /* _WIN32 */
  9051.           if (TREE_CODE (declarator) == ADDR_EXPR
  9052.           && (constp || volatilep))
  9053.         {
  9054.           if (constp)
  9055.             pedwarn ("discarding `const' applied to a reference");
  9056.           if (volatilep)
  9057.             pedwarn ("discarding `volatile' applied to a reference");
  9058.           constp = volatilep = 0;
  9059.         }
  9060.         }
  9061.       declarator = TREE_OPERAND (declarator, 0);
  9062.       ctype = NULL_TREE;
  9063.       break;
  9064.  
  9065.     case SCOPE_REF:
  9066.       {
  9067.         /* We have converted type names to NULL_TREE if the
  9068.            name was bogus, or to a _TYPE node, if not.
  9069.  
  9070.            The variable CTYPE holds the type we will ultimately
  9071.            resolve to.  The code here just needs to build
  9072.            up appropriate member types.  */
  9073.         tree sname = TREE_OPERAND (declarator, 1);
  9074.         /* Destructors can have their visibilities changed as well.  */
  9075.         if (TREE_CODE (sname) == BIT_NOT_EXPR)
  9076.           sname = TREE_OPERAND (sname, 0);
  9077.  
  9078.         if (TREE_COMPLEXITY (declarator) == 0)
  9079.           /* This needs to be here, in case we are called
  9080.          multiple times.  */ ;
  9081.         else if (friendp && (TREE_COMPLEXITY (declarator) < 2))
  9082.           /* don't fall out into global scope. Hides real bug? --eichin */ ;
  9083.         else if (TREE_COMPLEXITY (declarator) == current_class_depth)
  9084.           {
  9085.         /* This pop_nested_class corresponds to the
  9086.                    push_nested_class used to push into class scope for
  9087.                    parsing the argument list of a function decl, in
  9088.                    qualified_id.  */
  9089.         pop_nested_class (1);
  9090.         TREE_COMPLEXITY (declarator) = current_class_depth;
  9091.           }
  9092.         else
  9093.           my_friendly_abort (16);
  9094.  
  9095.         if (TREE_OPERAND (declarator, 0) == NULL_TREE)
  9096.           {
  9097.         /* We had a reference to a global decl, or
  9098.            perhaps we were given a non-aggregate typedef,
  9099.            in which case we cleared this out, and should just
  9100.            keep going as though it wasn't there.  */
  9101.         declarator = sname;
  9102.         continue;
  9103.           }
  9104.         ctype = TREE_OPERAND (declarator, 0);
  9105.  
  9106.         if (sname == NULL_TREE)
  9107.           goto done_scoping;
  9108.  
  9109.         if (TREE_CODE (sname) == IDENTIFIER_NODE)
  9110.           {
  9111.         /* This is the `standard' use of the scoping operator:
  9112.            basetype :: member .  */
  9113.  
  9114.         if (ctype == current_class_type)
  9115.           {
  9116.             /* class A {
  9117.                  void A::f ();
  9118.                };
  9119.  
  9120.                Is this ill-formed?  */
  9121.  
  9122.             if (pedantic)
  9123.               cp_pedwarn ("extra qualification `%T::' on member `%s' ignored",
  9124.                   ctype, name);
  9125.           }
  9126.         else if (TREE_CODE (type) == FUNCTION_TYPE)
  9127.           {
  9128.             if (current_class_type == NULL_TREE
  9129.             || friendp)
  9130.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9131.                               TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9132.             else
  9133.               {
  9134.             cp_error ("cannot declare member function `%T::%s' within `%T'",
  9135.                   ctype, name, current_class_type);
  9136.             return void_type_node;
  9137.               }
  9138.           }
  9139.         else if (TYPE_SIZE (ctype) != NULL_TREE
  9140.              || (RIDBIT_SETP (RID_TYPEDEF, specbits)))
  9141.           {
  9142.             tree t;
  9143.             /* have to move this code elsewhere in this function.
  9144.                this code is used for i.e., typedef int A::M; M *pm;
  9145.  
  9146.                It is?  How? jason 10/2/94 */
  9147.  
  9148.             if (explicit_int == -1 && decl_context == FIELD
  9149.             && funcdef_flag == 0)
  9150.               {
  9151.             /* The code in here should only be used to build
  9152.                stuff that will be grokked as access decls.  */
  9153.             t = lookup_field (ctype, sname, 0, 0);
  9154.             if (t)
  9155.               {
  9156.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  9157.                 DECL_INITIAL (t) = init;
  9158.                 return t;
  9159.               }
  9160.             /* No such field, try member functions.  */
  9161.             t = lookup_fnfields (TYPE_BINFO (ctype), sname, 0);
  9162.             if (t)
  9163.               {
  9164.                 if (flags == DTOR_FLAG)
  9165.                   t = TREE_VALUE (t);
  9166.                 else if (CLASSTYPE_METHOD_VEC (ctype)
  9167.                      && TREE_VALUE (t) == TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (ctype), 0))
  9168.                   {
  9169.                 /* Don't include destructor with constructors.  */
  9170.                 t = DECL_CHAIN (TREE_VALUE (t));
  9171.                 if (t == NULL_TREE)
  9172.                   cp_error ("`%T' does not have any constructors",
  9173.                         ctype);
  9174.                 t = build_tree_list (NULL_TREE, t);
  9175.                   }
  9176.                 t = build_lang_field_decl (FIELD_DECL, build_nt (SCOPE_REF, ctype, t), type);
  9177.                 DECL_INITIAL (t) = init;
  9178.                 return t;
  9179.               }
  9180.  
  9181.             cp_error
  9182.               ("field `%D' is not a member of structure `%T'",
  9183.                sname, ctype);
  9184.               }
  9185.  
  9186.             if (current_class_type)
  9187.               {
  9188.             cp_error ("cannot declare member `%T::%s' within `%T'",
  9189.                   ctype, name, current_class_type);
  9190.             return void_type_node;
  9191.               }
  9192.             type = build_offset_type (ctype, type);
  9193.           }
  9194.         else if (uses_template_parms (ctype))
  9195.           {
  9196.                     enum tree_code c;
  9197.                     if (TREE_CODE (type) == FUNCTION_TYPE)
  9198.               {
  9199.             type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9200.                             TREE_TYPE (type),
  9201.                             TYPE_ARG_TYPES (type));
  9202.             c = FUNCTION_DECL;
  9203.               }
  9204.             }
  9205.         else
  9206.           {
  9207.             cp_error ("structure `%T' not yet defined", ctype);
  9208.             return error_mark_node;
  9209.           }
  9210.  
  9211.         declarator = sname;
  9212.           }
  9213.         else if (TREE_CODE (sname) == SCOPE_REF)
  9214.           my_friendly_abort (17);
  9215.         else
  9216.           {
  9217.           done_scoping:
  9218.         declarator = TREE_OPERAND (declarator, 1);
  9219.         if (declarator && TREE_CODE (declarator) == CALL_EXPR)
  9220.           /* In this case, we will deal with it later.  */
  9221.           ;
  9222.         else
  9223.           {
  9224.             if (TREE_CODE (type) == FUNCTION_TYPE)
  9225.               type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep), TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9226.             else
  9227.               type = build_offset_type (ctype, type);
  9228.           }
  9229.           }
  9230.       }
  9231.       break;
  9232.  
  9233.     case BIT_NOT_EXPR:
  9234.       declarator = TREE_OPERAND (declarator, 0);
  9235.       break;
  9236.  
  9237.     case RECORD_TYPE:
  9238.     case UNION_TYPE:
  9239.     case ENUMERAL_TYPE:
  9240.       declarator = NULL_TREE;
  9241.       break;
  9242.  
  9243.     case ERROR_MARK:
  9244.       declarator = NULL_TREE;
  9245.       break;
  9246.  
  9247.     default:
  9248.       my_friendly_abort (158);
  9249.     }
  9250.     }
  9251.  
  9252.   if (explicitp == 1)
  9253.     {
  9254.       error ("only constructors can be declared `explicit'");
  9255.       explicitp = 0;
  9256.     }
  9257.  
  9258.   /* Now TYPE has the actual type.  */
  9259.  
  9260.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  9261.  
  9262.   if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9263.     {
  9264.       if (constp)
  9265.     {
  9266.       error ("const `%s' cannot be declared `mutable'", name);
  9267.       RIDBIT_RESET (RID_MUTABLE, specbits);
  9268.     }
  9269.       else if (staticp)
  9270.     {
  9271.       error ("static `%s' cannot be declared `mutable'", name);
  9272.       RIDBIT_RESET (RID_MUTABLE, specbits);
  9273.     }
  9274.     }
  9275.  
  9276.   if (RIDBIT_SETP (RID_TYPEDEF, specbits))
  9277.     {
  9278.       tree decl;
  9279.  
  9280.       /* Note that the grammar rejects storage classes
  9281.      in typenames, fields or parameters.  */
  9282.       if (constp || volatilep)
  9283.     type = cp_build_type_variant (type, constp, volatilep);
  9284.  
  9285.       /* If the user declares "struct {...} foo" then `foo' will have
  9286.      an anonymous name.  Fill that name in now.  Nothing can
  9287.      refer to it, so nothing needs know about the name change.
  9288.      The TYPE_NAME field was filled in by build_struct_xref.  */
  9289.       if (type != error_mark_node
  9290.       && TYPE_NAME (type)
  9291.       && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  9292.       && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type)))
  9293.     {
  9294.       /* replace the anonymous name with the real name everywhere.  */
  9295.       lookup_tag_reverse (type, declarator);
  9296.       TYPE_IDENTIFIER (type) = declarator;
  9297.  
  9298.       if (TYPE_LANG_SPECIFIC (type))
  9299.         TYPE_WAS_ANONYMOUS (type) = 1;
  9300.  
  9301.       {
  9302.         tree d = TYPE_NAME (type), c = DECL_CONTEXT (d);
  9303.  
  9304.         if (!c)
  9305.           set_nested_typename (d, 0, declarator, type);
  9306.         else if (TREE_CODE (c) == FUNCTION_DECL)
  9307.           set_nested_typename (d, DECL_ASSEMBLER_NAME (c),
  9308.                    declarator, type);
  9309.         else
  9310.           set_nested_typename (d, TYPE_NESTED_NAME (c), declarator, type);
  9311.  
  9312.         DECL_ASSEMBLER_NAME (d) = DECL_NAME (d);
  9313.         DECL_ASSEMBLER_NAME (d)
  9314.           = get_identifier (build_overload_name (type, 1, 1));
  9315.       }
  9316.     }
  9317.  
  9318. #if 0 /* not yet, should get fixed properly later */
  9319.       decl = make_type_decl (declarator, type);
  9320. #else
  9321.       decl = build_decl (TYPE_DECL, declarator, type);
  9322. #endif
  9323.       if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE)
  9324.     {
  9325.       cp_error_at ("typedef name may not be class-qualified", decl);
  9326.       return NULL_TREE;
  9327.     }
  9328.       else if (quals)
  9329.     {
  9330.       if (ctype == NULL_TREE)
  9331.         {
  9332.           if (TREE_CODE (type) != METHOD_TYPE)
  9333.         cp_error_at ("invalid type qualifier for non-method type", decl);
  9334.           else
  9335.         ctype = TYPE_METHOD_BASETYPE (type);
  9336.         }
  9337.       if (ctype != NULL_TREE)
  9338.         grok_method_quals (ctype, decl, quals);
  9339.     }
  9340.  
  9341.       if (RIDBIT_SETP (RID_SIGNED, specbits)
  9342.       || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  9343.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  9344.  
  9345.       if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9346.     {
  9347.       error ("non-object member `%s' cannot be declared mutable", name);
  9348.     }
  9349.  
  9350. #ifdef _WIN32
  9351.       /* If this function uses the stdcall calling conventions, mark the 
  9352.          tree as such by setting the stdcall_flag to 1. */
  9353.       if( stdcallp )
  9354.           TYPE_STDCALL( type ) = 1;
  9355. #endif /* _WIN32 */
  9356.  
  9357.       return decl;
  9358.     }
  9359.  
  9360.   /* Detect the case of an array type of unspecified size
  9361.      which came, as such, direct from a typedef name.
  9362.      We must copy the type, so that each identifier gets
  9363.      a distinct type, so that each identifier's size can be
  9364.      controlled separately by its own initializer.  */
  9365.  
  9366.   if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE
  9367.       && TYPE_DOMAIN (type) == NULL_TREE)
  9368.     {
  9369.       type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type));
  9370.     }
  9371.  
  9372.   /* If this is a type name (such as, in a cast or sizeof),
  9373.      compute the type and return it now.  */
  9374.  
  9375.   if (decl_context == TYPENAME)
  9376.     {
  9377.       /* Note that the grammar rejects storage classes
  9378.      in typenames, fields or parameters.  */
  9379.       if (constp || volatilep)
  9380.     if (IS_SIGNATURE (type))
  9381.       error ("`const' or `volatile' specified with signature type");
  9382.     else  
  9383.       type = cp_build_type_variant (type, constp, volatilep);
  9384.  
  9385.       /* Special case: "friend class foo" looks like a TYPENAME context.  */
  9386.       if (friendp)
  9387.     {
  9388.       if (volatilep)
  9389.         {
  9390.           cp_error ("`volatile' specified for friend class declaration");
  9391.           volatilep = 0;
  9392.         }
  9393.       if (inlinep)
  9394.         {
  9395.           cp_error ("`inline' specified for friend class declaration");
  9396.           inlinep = 0;
  9397.         }
  9398.  
  9399.       /* Only try to do this stuff if we didn't already give up.  */
  9400.       if (type != integer_type_node)
  9401.         {
  9402.           /* A friendly class?  */
  9403.           if (current_class_type)
  9404.         make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type));
  9405.           else
  9406.         error ("trying to make class `%s' a friend of global scope",
  9407.                TYPE_NAME_STRING (type));
  9408.           type = void_type_node;
  9409.         }
  9410.     }
  9411.       else if (quals)
  9412.     {
  9413. #if 0 /* not yet, should get fixed properly later */
  9414.       tree dummy = make_type_decl (declarator, type);
  9415. #else
  9416.       tree dummy = build_decl (TYPE_DECL, declarator, type);
  9417. #endif
  9418.       if (ctype == NULL_TREE)
  9419.         {
  9420.           my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159);
  9421.           ctype = TYPE_METHOD_BASETYPE (type);
  9422.         }
  9423.       grok_method_quals (ctype, dummy, quals);
  9424.       type = TREE_TYPE (dummy);
  9425.     }
  9426.  
  9427.       return type;
  9428.     }
  9429.   else if (declarator == NULL_TREE && decl_context != PARM
  9430.        && decl_context != CATCHPARM
  9431.        && TREE_CODE (type) != UNION_TYPE
  9432.        && ! bitfield)
  9433.     {
  9434.       cp_error ("abstract declarator `%T' used as declaration", type);
  9435.       declarator = make_anon_name ();
  9436.     }
  9437.  
  9438.   /* `void' at top level (not within pointer)
  9439.      is allowed only in typedefs or type names.
  9440.      We don't complain about parms either, but that is because
  9441.      a better error message can be made later.  */
  9442.  
  9443.   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
  9444.     {
  9445.       if (! declarator)
  9446.     error ("unnamed variable or field declared void");
  9447.       else if (TREE_CODE (declarator) == IDENTIFIER_NODE)
  9448.     {
  9449.       if (IDENTIFIER_OPNAME_P (declarator))
  9450. #if 0                /* How could this happen? */
  9451.         error ("operator `%s' declared void",
  9452.            operator_name_string (declarator));
  9453. #else
  9454.         my_friendly_abort (356);
  9455. #endif
  9456.       else
  9457.         error ("variable or field `%s' declared void", name);
  9458.     }
  9459.       else
  9460.     error ("variable or field declared void");
  9461.       type = integer_type_node;
  9462.     }
  9463.  
  9464.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  9465.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  9466.  
  9467.   {
  9468.     register tree decl;
  9469.  
  9470.     if (decl_context == PARM)
  9471.       {
  9472.     if (ctype)
  9473.       error ("cannot use `::' in parameter declaration");
  9474.  
  9475.     /* A parameter declared as an array of T is really a pointer to T.
  9476.        One declared as a function is really a pointer to a function.
  9477.        One declared as a member is really a pointer to member.  */
  9478.  
  9479.     if (TREE_CODE (type) == ARRAY_TYPE)
  9480.       {
  9481.         /* Transfer const-ness of array into that of type pointed to. */
  9482.         type = build_pointer_type
  9483.           (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
  9484.         volatilep = constp = 0;
  9485.       }
  9486.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  9487.       type = build_pointer_type (type);
  9488.     else if (TREE_CODE (type) == OFFSET_TYPE)
  9489.       type = build_pointer_type (type);
  9490.     else if (type == void_type_node && declarator)
  9491.       {
  9492.         error ("declaration of `%s' as void", name);
  9493.         return NULL_TREE;
  9494.       }
  9495.  
  9496.     decl = build_decl (PARM_DECL, declarator, type);
  9497.  
  9498.     bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE,
  9499.             inlinep, friendp, raises != NULL_TREE);
  9500.     if (current_class_type
  9501.         && IS_SIGNATURE (current_class_type))
  9502.       {
  9503.         if (inlinep)
  9504.           error ("parameter of signature member function declared `inline'");
  9505.         if (RIDBIT_SETP (RID_AUTO, specbits))
  9506.           error ("parameter of signature member function declared `auto'");
  9507.         if (RIDBIT_SETP (RID_REGISTER, specbits))
  9508.           error ("parameter of signature member function declared `register'");
  9509.       }
  9510.  
  9511.     /* Compute the type actually passed in the parmlist,
  9512.        for the case where there is no prototype.
  9513.        (For example, shorts and chars are passed as ints.)
  9514.        When there is a prototype, this is overridden later.  */
  9515.  
  9516.     DECL_ARG_TYPE (decl) = type_promotes_to (type);
  9517.       }
  9518.     else if (decl_context == FIELD)
  9519.       {
  9520.     if (type == error_mark_node)
  9521.       {
  9522.         /* Happens when declaring arrays of sizes which
  9523.            are error_mark_node, for example.  */
  9524.         decl = NULL_TREE;
  9525.       }
  9526.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  9527.       {
  9528.         int publicp = 0;
  9529.  
  9530.         if (friendp == 0)
  9531.           {
  9532.         if (ctype == NULL_TREE)
  9533.           ctype = current_class_type;
  9534.  
  9535.         if (ctype == NULL_TREE)
  9536.           {
  9537.             cp_error ("can't make `%D' into a method -- not in a class",
  9538.                   declarator);
  9539.             return void_type_node;
  9540.           }
  9541.  
  9542.         /* ``A union may [ ... ] not [ have ] virtual functions.''
  9543.            ARM 9.5 */
  9544.         if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
  9545.           {
  9546.             cp_error ("function `%D' declared virtual inside a union",
  9547.                   declarator);
  9548.             return void_type_node;
  9549.           }
  9550.  
  9551.         if (declarator == ansi_opname[(int) NEW_EXPR]
  9552.             || declarator == ansi_opname[(int) VEC_NEW_EXPR]
  9553.             || declarator == ansi_opname[(int) DELETE_EXPR]
  9554.             || declarator == ansi_opname[(int) VEC_DELETE_EXPR])
  9555.           {
  9556.             if (virtualp)
  9557.               {
  9558.             cp_error ("`%D' cannot be declared virtual, since it is always static",
  9559.                   declarator);
  9560.             virtualp = 0;
  9561.               }
  9562.           }
  9563.         else if (staticp < 2)
  9564.           type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9565.                           TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9566.           }
  9567.  
  9568.         /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node.  */
  9569.         publicp = (! friendp
  9570.                || RIDBIT_SETP (RID_EXTERN, specbits)
  9571.                || ! (funcdef_flag < 0 || inlinep));
  9572.         decl = grokfndecl (ctype, type, declarator,
  9573.                    virtualp, flags, quals, raises, attrlist,
  9574.                    friendp ? -1 : 0, publicp, inlinep);
  9575.         if (decl == NULL_TREE)
  9576.           return NULL_TREE;
  9577.         decl = build_decl_attribute_variant (decl, decl_machine_attr);
  9578.  
  9579. #ifdef _WIN32 
  9580.     if( stdcallp )
  9581.         DECL_STDCALL( decl ) = stdcallp;
  9582. #endif /* _WIN32 */
  9583.  
  9584.         if (explicitp == 2)
  9585.           DECL_NONCONVERTING_P (decl) = 1;
  9586.       }
  9587.     else if (TREE_CODE (type) == METHOD_TYPE)
  9588.       {
  9589.         /* We only get here for friend declarations of
  9590.            members of other classes.  */
  9591.         /* All method decls are public, so tell grokfndecl to set
  9592.            TREE_PUBLIC, also.  */
  9593.         decl = grokfndecl (ctype, type, declarator,
  9594.                    virtualp, flags, quals, raises, attrlist,
  9595.                    friendp ? -1 : 0, 1, 0);
  9596.         if (decl == NULL_TREE)
  9597.           return NULL_TREE;
  9598.       }
  9599.     else if (TYPE_SIZE (type) == NULL_TREE && !staticp
  9600.          && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0))
  9601.       {
  9602.         if (declarator)
  9603.           cp_error ("field `%D' has incomplete type", declarator);
  9604.         else
  9605.           cp_error ("name `%T' has incomplete type", type);
  9606.  
  9607.         /* If we're instantiating a template, tell them which
  9608.            instantiation made the field's type be incomplete.  */
  9609.         if (current_class_type
  9610.         && TYPE_NAME (current_class_type)
  9611.         && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (current_class_type)))
  9612.         && declspecs && TREE_VALUE (declspecs)
  9613.         && TREE_TYPE (TREE_VALUE (declspecs)) == type)
  9614.           cp_error ("  in instantiation of template `%T'",
  9615.             current_class_type);
  9616.  
  9617.         type = error_mark_node;
  9618.         decl = NULL_TREE;
  9619.       }
  9620.     else
  9621.       {
  9622.         if (friendp)
  9623.           {
  9624.         error ("`%s' is neither function nor method; cannot be declared friend",
  9625.                IDENTIFIER_POINTER (declarator));
  9626.         friendp = 0;
  9627.           }
  9628.         decl = NULL_TREE;
  9629.       }
  9630.  
  9631.     if (friendp)
  9632.       {
  9633.         /* Friends are treated specially.  */
  9634.         if (ctype == current_class_type)
  9635.           warning ("member functions are implicitly friends of their class");
  9636.         else
  9637.           {
  9638.         tree t = NULL_TREE;
  9639.         if (decl && DECL_NAME (decl))
  9640.           t = do_friend (ctype, declarator, decl,
  9641.                  last_function_parms, flags, quals);
  9642.         if (t && funcdef_flag)
  9643.           return t;
  9644.         
  9645.         return void_type_node;
  9646.           }
  9647.       }
  9648.  
  9649.     /* Structure field.  It may not be a function, except for C++ */
  9650.  
  9651.     if (decl == NULL_TREE)
  9652.       {
  9653.         if (initialized)
  9654.           {
  9655.         /* Motion 10 at San Diego: If a static const integral data
  9656.            member is initialized with an integral constant
  9657.            expression, the initializer may appear either in the
  9658.            declaration (within the class), or in the definition,
  9659.            but not both.  If it appears in the class, the member is
  9660.            a member constant.  The file-scope definition is always
  9661.            required.  */
  9662.         if (staticp)
  9663.           {
  9664.             if (pedantic)
  9665.               {
  9666.             if (! constp)
  9667.               cp_pedwarn ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  9668.                       declarator);
  9669.  
  9670.             else if (! INTEGRAL_TYPE_P (type))
  9671.               cp_pedwarn ("ANSI C++ forbids member constant `%D' of non-integral type `%T'", declarator, type);
  9672.               }
  9673.           }
  9674.  
  9675.         /* Note that initialization of const members is prohibited
  9676.            by the draft ANSI standard, though it appears to be in
  9677.            common practice.  12.6.2: The argument list is used to
  9678.            initialize the named nonstatic member....  This (or an
  9679.            initializer list) is the only way to initialize
  9680.            nonstatic const and reference members.  */
  9681.         else if (pedantic || ! constp)
  9682.           cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
  9683.                   constp ? "const member" : "member", declarator);
  9684.           }
  9685.  
  9686.         if (staticp || (constp && initialized))
  9687.           {
  9688.         /* ANSI C++ Apr '95 wp 9.2 */
  9689.         if (staticp && declarator == current_class_name)
  9690.           cp_pedwarn ("ANSI C++ forbids static member `%D' with same name as enclosing class",
  9691.                   declarator);
  9692.  
  9693.         /* C++ allows static class members.
  9694.            All other work for this is done by grokfield.
  9695.            This VAR_DECL is built by build_lang_field_decl.
  9696.            All other VAR_DECLs are built by build_decl.  */
  9697.         decl = build_lang_field_decl (VAR_DECL, declarator, type);
  9698.         TREE_STATIC (decl) = 1;
  9699.         /* In class context, 'static' means public access.  */
  9700.         TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = !!staticp;
  9701.           }
  9702.         else
  9703.           {
  9704.         decl = build_lang_field_decl (FIELD_DECL, declarator, type);
  9705.         if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9706.           {
  9707.             DECL_MUTABLE_P (decl) = 1;
  9708.             RIDBIT_RESET (RID_MUTABLE, specbits);
  9709.           }
  9710.           }
  9711.  
  9712.         bad_specifiers (decl, "field", virtualp, quals != NULL_TREE,
  9713.                 inlinep, friendp, raises != NULL_TREE);
  9714.       }
  9715.       }
  9716.     else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
  9717.       {
  9718.     tree original_name = declarator;
  9719.     int publicp = 0;
  9720.  
  9721.     if (! declarator)
  9722.       return NULL_TREE;
  9723.  
  9724.     if (RIDBIT_SETP (RID_AUTO, specbits))
  9725.       error ("storage class `auto' invalid for function `%s'", name);
  9726.     else if (RIDBIT_SETP (RID_REGISTER, specbits))
  9727.       error ("storage class `register' invalid for function `%s'", name);
  9728.  
  9729.     /* Function declaration not at top level.
  9730.        Storage classes other than `extern' are not allowed
  9731.        and `extern' makes no difference.  */
  9732.     if (! toplevel_bindings_p ()
  9733.         && ! processing_template_decl
  9734.         && (RIDBIT_SETP (RID_STATIC, specbits)
  9735.         || RIDBIT_SETP (RID_INLINE, specbits))
  9736.         && pedantic)
  9737.       {
  9738.         if (RIDBIT_SETP (RID_STATIC, specbits))
  9739.           pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name);
  9740.         else
  9741.           pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name);
  9742.       }
  9743.     
  9744.     if (ctype == NULL_TREE)
  9745.       {
  9746.         if (virtualp)
  9747.           {
  9748.         error ("virtual non-class function `%s'", name);
  9749.         virtualp = 0;
  9750.           }
  9751.  
  9752.         if (current_lang_name == lang_name_cplusplus
  9753.         && ! (IDENTIFIER_LENGTH (original_name) == 4
  9754.               && IDENTIFIER_POINTER (original_name)[0] == 'm'
  9755.               && strcmp (IDENTIFIER_POINTER (original_name), "main") == 0)
  9756.         && ! (IDENTIFIER_LENGTH (original_name) > 10
  9757.               && IDENTIFIER_POINTER (original_name)[0] == '_'
  9758.               && IDENTIFIER_POINTER (original_name)[1] == '_'
  9759.               && strncmp (IDENTIFIER_POINTER (original_name)+2, "builtin_", 8) == 0))
  9760.           /* Plain overloading: will not be grok'd by grokclassfn.  */
  9761.           declarator = build_decl_overload (dname, TYPE_ARG_TYPES (type), 0);
  9762.       }
  9763.     else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2)
  9764.       type = build_cplus_method_type (build_type_variant (ctype, constp, volatilep),
  9765.                       TREE_TYPE (type), TYPE_ARG_TYPES (type));
  9766.  
  9767.     /* Record presence of `static'.  In C++, `inline' implies `static'.  */
  9768.     publicp = (ctype != NULL_TREE
  9769.            || RIDBIT_SETP (RID_EXTERN, specbits)
  9770.            || (!RIDBIT_SETP (RID_STATIC, specbits)
  9771.                && !RIDBIT_SETP (RID_INLINE, specbits)));
  9772.  
  9773.     decl = grokfndecl (ctype, type, original_name,
  9774.                virtualp, flags, quals, raises, attrlist,
  9775.                processing_template_decl ? 0 : friendp ? 2 : 1,
  9776.                publicp, inlinep);
  9777.     if (decl == NULL_TREE)
  9778.       return NULL_TREE;
  9779.  
  9780.     if (ctype == NULL_TREE && DECL_LANGUAGE (decl) != lang_c)
  9781.       DECL_ASSEMBLER_NAME (decl) = current_namespace_id (declarator);
  9782.  
  9783.     if (staticp == 1)
  9784.       {
  9785.         int illegal_static = 0;
  9786.  
  9787.         /* Don't allow a static member function in a class, and forbid
  9788.            declaring main to be static.  */
  9789.         if (TREE_CODE (type) == METHOD_TYPE)
  9790.           {
  9791.         cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl);
  9792.         illegal_static = 1;
  9793.           }
  9794.         else if (current_function_decl)
  9795.           {
  9796.         /* FIXME need arm citation */
  9797.         error ("cannot declare static function inside another function");
  9798.         illegal_static = 1;
  9799.           }
  9800.  
  9801.         if (illegal_static)
  9802.           {
  9803.         staticp = 0;
  9804.         RIDBIT_RESET (RID_STATIC, specbits);
  9805.           }
  9806.       }
  9807.       }
  9808.     else
  9809.       {
  9810.     /* It's a variable.  */
  9811.  
  9812.     if (decl_context == CATCHPARM)
  9813.       {
  9814.         if (ctype)
  9815.           {
  9816.         ctype = NULL_TREE;
  9817.         error ("cannot use `::' in parameter declaration");
  9818.           }
  9819.  
  9820.         /* A parameter declared as an array of T is really a pointer to T.
  9821.            One declared as a function is really a pointer to a function.
  9822.            One declared as a member is really a pointer to member.  */
  9823.  
  9824.         if (TREE_CODE (type) == ARRAY_TYPE)
  9825.           {
  9826.         /* Transfer const-ness of array into that of type pointed to. */
  9827.         type = build_pointer_type
  9828.           (cp_build_type_variant (TREE_TYPE (type), constp, volatilep));
  9829.         volatilep = constp = 0;
  9830.           }
  9831.         else if (TREE_CODE (type) == FUNCTION_TYPE)
  9832.           type = build_pointer_type (type);
  9833.         else if (TREE_CODE (type) == OFFSET_TYPE)
  9834.           type = build_pointer_type (type);
  9835.       }
  9836.  
  9837.     /* An uninitialized decl with `extern' is a reference.  */
  9838.     decl = grokvardecl (type, declarator, specbits, initialized, constp);
  9839.     bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
  9840.             inlinep, friendp, raises != NULL_TREE);
  9841.  
  9842.     if (ctype)
  9843.       {
  9844.         DECL_CONTEXT (decl) = ctype;
  9845.         if (staticp == 1)
  9846.           {
  9847.             cp_pedwarn ("static member `%D' re-declared as static", decl);
  9848.             staticp = 0;
  9849.         RIDBIT_RESET (RID_STATIC, specbits);
  9850.           }
  9851.         if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl))
  9852.           {
  9853.         cp_error ("static member `%D' declared `register'", decl);
  9854.         RIDBIT_RESET (RID_REGISTER, specbits);
  9855.           }
  9856.         if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic)
  9857.           {
  9858.             cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage",
  9859.                 decl);
  9860.         RIDBIT_RESET (RID_EXTERN, specbits);
  9861.           }
  9862.       }
  9863.       }
  9864.  
  9865.     if (RIDBIT_SETP (RID_MUTABLE, specbits))
  9866.       {
  9867.     error ("`%s' cannot be declared mutable", name);
  9868.       }
  9869.  
  9870.     /* Record `register' declaration for warnings on &
  9871.        and in case doing stupid register allocation.  */
  9872.  
  9873.     if (RIDBIT_SETP (RID_REGISTER, specbits))
  9874.       DECL_REGISTER (decl) = 1;
  9875.  
  9876.     if (RIDBIT_SETP (RID_EXTERN, specbits))
  9877.       DECL_THIS_EXTERN (decl) = 1;
  9878.  
  9879.     if (RIDBIT_SETP (RID_STATIC, specbits))
  9880.       DECL_THIS_STATIC (decl) = 1;
  9881.  
  9882.     /* Record constancy and volatility.  */
  9883.  
  9884.     if (constp)
  9885.       TREE_READONLY (decl) = TREE_CODE (type) != REFERENCE_TYPE;
  9886.     if (volatilep)
  9887.       {
  9888.     TREE_SIDE_EFFECTS (decl) = 1;
  9889.     TREE_THIS_VOLATILE (decl) = 1;
  9890.       }
  9891.  
  9892. #if defined (_WIN32) && defined (NEXT_PDO)
  9893.     /* If this function is a stdcall function, set the stdcall_flag using the TYPE_STDCALL
  9894.        macro */
  9895.     if (stdcallp)
  9896.       TYPE_STDCALL (decl) = 1;
  9897.     if (RIDBIT_SETP(RID_DLLIMPORT, specbits))
  9898.     {
  9899.         DECL_EXTERNAL (decl) = 1;
  9900.  
  9901.         {
  9902.             char* newName = (char*)malloc( 
  9903.                 strlen( IDENTIFIER_POINTER(DECL_NAME(decl)) ) + 7 ); // to allow for '_imp__' and \0
  9904.  
  9905.             sprintf( newName, "_imp__%s", IDENTIFIER_POINTER(DECL_NAME(decl)) );
  9906.             DECL_ASSEMBLER_NAME(decl) = get_identifier( newName );
  9907.             DECL_DLLIMPORT(decl) = 1;
  9908.         }
  9909.     }
  9910.     else if (RIDBIT_SETP(RID_DLLEXPORT, specbits))
  9911.     {
  9912.         char prependCharacter = '_';
  9913.         char* tail = "";
  9914.         int length = 0;
  9915.  
  9916.         if( TREE_CODE (decl) != FUNCTION_DECL )
  9917.             tail = ",data";
  9918.         if( exportNamesForDLL )
  9919.             length = strlen( exportNamesForDLL );
  9920.         length += strlen( " -export:" );
  9921.         length += strlen (IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl))) + 1;            // Include the '_' here
  9922.         if( strncmp( IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl)), "objc_class_name", 15 ) == 0 )
  9923.         {
  9924.             prependCharacter = '.';
  9925.             tail = "";
  9926.         }
  9927.         length += strlen( tail );
  9928.         if( exportNamesForDLL )
  9929.             exportNamesForDLL = (char*)realloc( (void*)exportNamesForDLL, length + 1 );
  9930.         else
  9931.           {
  9932.             exportNamesForDLL = (char*)malloc( length + 1 );
  9933.             *exportNamesForDLL = '\0';
  9934.           }
  9935.         sprintf( exportNamesForDLL, "%s%s%c%s%s", exportNamesForDLL, 
  9936.             " -export:", prependCharacter, IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(decl)), tail );
  9937.     }
  9938. #endif /* _WIN32 */
  9939.  
  9940.     return decl;
  9941.   }
  9942. }
  9943.  
  9944. /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist.
  9945.    An empty exprlist is a parmlist.  An exprlist which
  9946.    contains only identifiers at the global level
  9947.    is a parmlist.  Otherwise, it is an exprlist.  */
  9948. int
  9949. parmlist_is_exprlist (exprs)
  9950.      tree exprs;
  9951. {
  9952.   if (exprs == NULL_TREE || TREE_PARMLIST (exprs))
  9953.     return 0;
  9954.  
  9955.   if (toplevel_bindings_p ())
  9956.     {
  9957.       /* At the global level, if these are all identifiers,
  9958.      then it is a parmlist.  */
  9959.       while (exprs)
  9960.     {
  9961.       if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE)
  9962.         return 1;
  9963.       exprs = TREE_CHAIN (exprs);
  9964.     }
  9965.       return 0;
  9966.     }
  9967.   return 1;
  9968. }
  9969.  
  9970. /* Subroutine of `grokparms'.  In a fcn definition, arg types must
  9971.    be complete.
  9972.  
  9973.    C++: also subroutine of `start_function'.  */
  9974. static void
  9975. require_complete_types_for_parms (parms)
  9976.      tree parms;
  9977. {
  9978.   while (parms)
  9979.     {
  9980.       tree type = TREE_TYPE (parms);
  9981.       if (TYPE_SIZE (type) == NULL_TREE)
  9982.     {
  9983.       if (DECL_NAME (parms))
  9984.         error ("parameter `%s' has incomplete type",
  9985.            IDENTIFIER_POINTER (DECL_NAME (parms)));
  9986.       else
  9987.         error ("parameter has incomplete type");
  9988.       TREE_TYPE (parms) = error_mark_node;
  9989.     }
  9990. #if 0
  9991.       /* If the arg types are incomplete in a declaration,
  9992.      they must include undefined tags.
  9993.      These tags can never be defined in the scope of the declaration,
  9994.      so the types can never be completed,
  9995.      and no call can be compiled successfully.  */
  9996.       /* This is not the right behavior for C++, but not having
  9997.      it is also probably wrong.  */
  9998.       else
  9999.     {
  10000.       /* Now warn if is a pointer to an incomplete type.  */
  10001.       while (TREE_CODE (type) == POINTER_TYPE
  10002.          || TREE_CODE (type) == REFERENCE_TYPE)
  10003.         type = TREE_TYPE (type);
  10004.       type = TYPE_MAIN_VARIANT (type);
  10005.       if (TYPE_SIZE (type) == NULL_TREE)
  10006.         {
  10007.           if (DECL_NAME (parm) != NULL_TREE)
  10008.         warning ("parameter `%s' points to incomplete type",
  10009.              IDENTIFIER_POINTER (DECL_NAME (parm)));
  10010.           else
  10011.         warning ("parameter points to incomplete type");
  10012.         }
  10013.     }
  10014. #endif
  10015.       parms = TREE_CHAIN (parms);
  10016.     }
  10017. }
  10018.  
  10019. /* Decode the list of parameter types for a function type.
  10020.    Given the list of things declared inside the parens,
  10021.    return a list of types.
  10022.  
  10023.    The list we receive can have three kinds of elements:
  10024.    an IDENTIFIER_NODE for names given without types,
  10025.    a TREE_LIST node for arguments given as typespecs or names with typespecs,
  10026.    or void_type_node, to mark the end of an argument list
  10027.    when additional arguments are not permitted (... was not used).
  10028.  
  10029.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  10030.    a mere declaration.  A nonempty identifier-list gets an error message
  10031.    when FUNCDEF_FLAG is zero.
  10032.    If FUNCDEF_FLAG is 1, then parameter types must be complete.
  10033.    If FUNCDEF_FLAG is -1, then parameter types may be incomplete.
  10034.  
  10035.    If all elements of the input list contain types,
  10036.    we return a list of the types.
  10037.    If all elements contain no type (except perhaps a void_type_node
  10038.    at the end), we return a null list.
  10039.    If some have types and some do not, it is an error, and we
  10040.    return a null list.
  10041.  
  10042.    Also set last_function_parms to either
  10043.    a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs.
  10044.    A list of names is converted to a chain of PARM_DECLs
  10045.    by store_parm_decls so that ultimately it is always a chain of decls.
  10046.  
  10047.    Note that in C++, parameters can take default values.  These default
  10048.    values are in the TREE_PURPOSE field of the TREE_LIST.  It is
  10049.    an error to specify default values which are followed by parameters
  10050.    that have no default values, or an ELLIPSES.  For simplicities sake,
  10051.    only parameters which are specified with their types can take on
  10052.    default values.  */
  10053.  
  10054. tree
  10055. grokparms (first_parm, funcdef_flag)
  10056.      tree first_parm;
  10057.      int funcdef_flag;
  10058. {
  10059.   tree result = NULL_TREE;
  10060.   tree decls = NULL_TREE;
  10061.  
  10062.   if (first_parm != NULL_TREE
  10063.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  10064.     {
  10065.       if (! funcdef_flag)
  10066.     pedwarn ("parameter names (without types) in function declaration");
  10067.       last_function_parms = first_parm;
  10068.       return NULL_TREE;
  10069.     }
  10070.   else if (first_parm != NULL_TREE
  10071.        && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST
  10072.        && TREE_VALUE (first_parm) != void_type_node)
  10073. #ifdef OBJCPLUS
  10074. /* snaroff (3/30/96): this is a total "COPOUT" fix for a problem briefly
  10075.    described below. Nevertheless, it appears to work. Without it, we
  10076.    would die anyway. A more elegant fix would require sifting through
  10077.    subtle changes between grokparms for C++ and grokparms for ANSI-C.
  10078.    I don't have the time right now
  10079.  */
  10080.     return first_parm;
  10081. #else
  10082.     my_friendly_abort (145);
  10083. #endif
  10084.   else
  10085.     {
  10086.       /* Types were specified.  This is a list of declarators
  10087.      each represented as a TREE_LIST node.  */
  10088.       register tree parm, chain;
  10089.       int any_init = 0, any_error = 0, saw_void = 0;
  10090.  
  10091.       if (first_parm != NULL_TREE)
  10092.     {
  10093.       tree last_result = NULL_TREE;
  10094.       tree last_decl = NULL_TREE;
  10095.  
  10096.       for (parm = first_parm; parm != NULL_TREE; parm = chain)
  10097.         {
  10098.           tree type, list_node = parm;
  10099.           register tree decl = TREE_VALUE (parm);
  10100.           tree init = TREE_PURPOSE (parm);
  10101.  
  10102.           chain = TREE_CHAIN (parm);
  10103.           /* @@ weak defense against parse errors.  */
  10104.           if (decl != void_type_node && TREE_CODE (decl) != TREE_LIST)
  10105.         {
  10106.           /* Give various messages as the need arises.  */
  10107.           if (TREE_CODE (decl) == STRING_CST)
  10108.             error ("invalid string constant `%s'",
  10109.                TREE_STRING_POINTER (decl));
  10110.           else if (TREE_CODE (decl) == INTEGER_CST)
  10111.             error ("invalid integer constant in parameter list, did you forget to give parameter name?");
  10112.           continue;
  10113.         }
  10114.  
  10115.           if (decl != void_type_node)
  10116.         {
  10117.           /* @@ May need to fetch out a `raises' here.  */
  10118.           decl = grokdeclarator (TREE_VALUE (decl),
  10119.                      TREE_PURPOSE (decl),
  10120.                      PARM, init != NULL_TREE,
  10121.                      NULL_TREE, NULL_TREE);
  10122.           if (! decl)
  10123.             continue;
  10124.           type = TREE_TYPE (decl);
  10125.           if (TYPE_MAIN_VARIANT (type) == void_type_node)
  10126.             decl = void_type_node;
  10127.           else if (TREE_CODE (type) == METHOD_TYPE)
  10128.             {
  10129.               if (DECL_NAME (decl))
  10130.             /* Cannot use `error_with_decl' here because
  10131.                we don't have DECL_CONTEXT set up yet.  */
  10132.             error ("parameter `%s' invalidly declared method type",
  10133.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  10134.               else
  10135.             error ("parameter invalidly declared method type");
  10136.               type = build_pointer_type (type);
  10137.               TREE_TYPE (decl) = type;
  10138.             }
  10139.           else if (TREE_CODE (type) == OFFSET_TYPE)
  10140.             {
  10141.               if (DECL_NAME (decl))
  10142.             error ("parameter `%s' invalidly declared offset type",
  10143.                    IDENTIFIER_POINTER (DECL_NAME (decl)));
  10144.               else
  10145.             error ("parameter invalidly declared offset type");
  10146.               type = build_pointer_type (type);
  10147.               TREE_TYPE (decl) = type;
  10148.             }
  10149.                   else if (TREE_CODE (type) == RECORD_TYPE
  10150.                            && TYPE_LANG_SPECIFIC (type)
  10151.                            && CLASSTYPE_ABSTRACT_VIRTUALS (type))
  10152.                     {
  10153.                       abstract_virtuals_error (decl, type);
  10154.                       any_error = 1;  /* seems like a good idea */
  10155.                     }
  10156.                   else if (TREE_CODE (type) == RECORD_TYPE
  10157.                            && TYPE_LANG_SPECIFIC (type)
  10158.                            && IS_SIGNATURE (type))
  10159.                     {
  10160.                       signature_error (decl, type);
  10161.                       any_error = 1;  /* seems like a good idea */
  10162.                     }
  10163.         }
  10164.  
  10165.           if (decl == void_type_node)
  10166.         {
  10167.           if (result == NULL_TREE)
  10168.             {
  10169.               result = void_list_node;
  10170.               last_result = result;
  10171.             }
  10172.           else
  10173.             {
  10174.               TREE_CHAIN (last_result) = void_list_node;
  10175.               last_result = void_list_node;
  10176.             }
  10177.           saw_void = 1;
  10178.           if (chain
  10179.               && (chain != void_list_node || TREE_CHAIN (chain)))
  10180.             error ("`void' in parameter list must be entire list");
  10181.           break;
  10182.         }
  10183.  
  10184.           /* Since there is a prototype, args are passed in their own types.  */
  10185.           DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
  10186. #ifdef PROMOTE_PROTOTYPES
  10187.           if ((TREE_CODE (type) == INTEGER_TYPE
  10188.            || TREE_CODE (type) == ENUMERAL_TYPE)
  10189.           && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  10190.         DECL_ARG_TYPE (decl) = integer_type_node;
  10191. #endif
  10192.           if (!any_error)
  10193.         {
  10194.           if (init)
  10195.             {
  10196.               any_init++;
  10197.               if (TREE_CODE (init) == SAVE_EXPR)
  10198.             PARM_DECL_EXPR (init) = 1;
  10199.               else if (TREE_CODE (init) == VAR_DECL
  10200.                    || TREE_CODE (init) == PARM_DECL)
  10201.             {
  10202.               if (IDENTIFIER_LOCAL_VALUE (DECL_NAME (init)))
  10203.                 {
  10204.                   /* ``Local variables may not be used in default
  10205.                  argument expressions.'' dpANSI C++ 8.2.6 */
  10206.                   /* If extern int i; within a function is not
  10207.                  considered a local variable, then this code is
  10208.                  wrong. */
  10209.                   cp_error ("local variable `%D' may not be used as a default argument", init);
  10210.                   any_error = 1;
  10211.                 }
  10212.               else if (TREE_READONLY_DECL_P (init))
  10213.                 init = decl_constant_value (init);
  10214.             }
  10215.               else
  10216.             init = require_instantiated_type (type, init, integer_zero_node);
  10217.         }
  10218. #if 0 /* This is too early to check; trailing parms might be merged in by
  10219.      duplicate_decls.  */
  10220.           else if (any_init)
  10221.             {
  10222.               error ("all trailing parameters must have default arguments");
  10223.               any_error = 1;
  10224.             }
  10225. #endif
  10226.         }
  10227.           else
  10228.         init = NULL_TREE;
  10229.  
  10230.           if (decls == NULL_TREE)
  10231.         {
  10232.           decls = decl;
  10233.           last_decl = decls;
  10234.         }
  10235.           else
  10236.         {
  10237.           TREE_CHAIN (last_decl) = decl;
  10238.           last_decl = decl;
  10239.         }
  10240. /* snaroff (3/30/96): add_instance_method/comp_proto_with_proto and
  10241.    really_start_method assume the parm list is immutable. This enables
  10242.    obcp-act.c to call this routine multiple times. Without this,
  10243.    we crash with "error(145)"...see beginning of this method.
  10244.  */
  10245.           if (TREE_PERMANENT (list_node))
  10246.         {
  10247.           TREE_PURPOSE (list_node) = init;
  10248.           TREE_VALUE (list_node) = type;
  10249.           TREE_CHAIN (list_node) = NULL_TREE;
  10250.         }
  10251.           else
  10252.         list_node = saveable_tree_cons (init, type, NULL_TREE);
  10253.           if (result == NULL_TREE)
  10254.         {
  10255.           result = list_node;
  10256.           last_result = result;
  10257.         }
  10258.           else
  10259.         {
  10260.           TREE_CHAIN (last_result) = list_node;
  10261.           last_result = list_node;
  10262.         }
  10263.         }
  10264.       if (last_result)
  10265.         TREE_CHAIN (last_result) = NULL_TREE;
  10266.       /* If there are no parameters, and the function does not end
  10267.          with `...', then last_decl will be NULL_TREE.  */
  10268.       if (last_decl != NULL_TREE)
  10269.         TREE_CHAIN (last_decl) = NULL_TREE;
  10270.     }
  10271.     }
  10272.  
  10273.   last_function_parms = decls;
  10274.  
  10275.   /* In a fcn definition, arg types must be complete.  */
  10276.   if (funcdef_flag > 0)
  10277.     require_complete_types_for_parms (last_function_parms);
  10278.  
  10279.   return result;
  10280. }
  10281.  
  10282. /* These memoizing functions keep track of special properties which
  10283.    a class may have.  `grok_ctor_properties' notices whether a class
  10284.    has a constructor of the form X(X&), and also complains
  10285.    if the class has a constructor of the form X(X).
  10286.    `grok_op_properties' takes notice of the various forms of
  10287.    operator= which are defined, as well as what sorts of type conversion
  10288.    may apply.  Both functions take a FUNCTION_DECL as an argument.  */
  10289. int
  10290. grok_ctor_properties (ctype, decl)
  10291.      tree ctype, decl;
  10292. {
  10293.   tree parmtypes = FUNCTION_ARG_CHAIN (decl);
  10294.   tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
  10295.  
  10296.   /* When a type has virtual baseclasses, a magical first int argument is
  10297.      added to any ctor so we can tell if the class has been initialized
  10298.      yet.  This could screw things up in this function, so we deliberately
  10299.      ignore the leading int if we're in that situation.  */
  10300.   if (parmtypes
  10301.       && TREE_VALUE (parmtypes) == integer_type_node
  10302.       && TYPE_USES_VIRTUAL_BASECLASSES (ctype))
  10303.     {
  10304.       parmtypes = TREE_CHAIN (parmtypes);
  10305.       parmtype = TREE_VALUE (parmtypes);
  10306.     }
  10307.  
  10308.   if (TREE_CODE (parmtype) == REFERENCE_TYPE
  10309.       && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype)
  10310.     {
  10311.       if (TREE_CHAIN (parmtypes) == NULL_TREE
  10312.       || TREE_CHAIN (parmtypes) == void_list_node
  10313.       || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
  10314.     {
  10315.       TYPE_HAS_INIT_REF (ctype) = 1;
  10316.       if (TYPE_READONLY (TREE_TYPE (parmtype)))
  10317.         TYPE_HAS_CONST_INIT_REF (ctype) = 1;
  10318.     }
  10319.       else
  10320.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  10321.     }
  10322.   else if (TYPE_MAIN_VARIANT (parmtype) == ctype)
  10323.     {
  10324.       if (TREE_CHAIN (parmtypes) != NULL_TREE
  10325.       && TREE_CHAIN (parmtypes) == void_list_node)
  10326.     {
  10327.       cp_error ("invalid constructor; you probably meant `%T (%T&)'",
  10328.             ctype, ctype);
  10329.       SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype);
  10330.  
  10331.       return 0;
  10332.     }
  10333.       else
  10334.     TYPE_GETS_INIT_AGGR (ctype) = 1;
  10335.     }
  10336.   else if (TREE_CODE (parmtype) == VOID_TYPE
  10337.        || TREE_PURPOSE (parmtypes) != NULL_TREE)
  10338.     TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1;
  10339.  
  10340.   return 1;
  10341. }
  10342.  
  10343. /* An operator with this name can be either unary or binary.  */
  10344. static int
  10345. ambi_op_p (name)
  10346.      tree name;
  10347. {
  10348.   return (name == ansi_opname [(int) INDIRECT_REF]
  10349.       || name == ansi_opname [(int) ADDR_EXPR]
  10350.       || name == ansi_opname [(int) NEGATE_EXPR]
  10351.       || name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10352.       || name == ansi_opname[(int) POSTDECREMENT_EXPR]
  10353.       || name == ansi_opname [(int) CONVERT_EXPR]);
  10354. }
  10355.  
  10356. /* An operator with this name can only be unary.  */
  10357. static int
  10358. unary_op_p (name)
  10359.      tree name;
  10360. {
  10361.   return (name == ansi_opname [(int) TRUTH_NOT_EXPR]
  10362.       || name == ansi_opname [(int) BIT_NOT_EXPR]
  10363.       || name == ansi_opname [(int) COMPONENT_REF]
  10364.       || OPERATOR_TYPENAME_P (name));
  10365. }
  10366.  
  10367. /* Do a little sanity-checking on how they declared their operator.  */
  10368. static void
  10369. grok_op_properties (decl, virtualp, friendp)
  10370.      tree decl;
  10371.      int virtualp, friendp;
  10372. {
  10373.   tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
  10374.   int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE);
  10375.   tree name = DECL_NAME (decl);
  10376.  
  10377.   if (current_class_type == NULL_TREE)
  10378.     friendp = 1;
  10379.  
  10380.   if (! friendp)
  10381.     {
  10382.       if (name == ansi_opname[(int) MODIFY_EXPR])
  10383.     TYPE_HAS_ASSIGNMENT (current_class_type) = 1;
  10384.       else if (name == ansi_opname[(int) CALL_EXPR])
  10385.     TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1;
  10386.       else if (name == ansi_opname[(int) ARRAY_REF])
  10387.     TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1;
  10388.       else if (name == ansi_opname[(int) COMPONENT_REF]
  10389.            || name == ansi_opname[(int) MEMBER_REF])
  10390.     TYPE_OVERLOADS_ARROW (current_class_type) = 1;
  10391.       else if (name == ansi_opname[(int) NEW_EXPR])
  10392.     TYPE_GETS_NEW (current_class_type) |= 1;
  10393.       else if (name == ansi_opname[(int) DELETE_EXPR])
  10394.     TYPE_GETS_DELETE (current_class_type) |= 1;
  10395.       else if (name == ansi_opname[(int) VEC_NEW_EXPR])
  10396.     TYPE_GETS_NEW (current_class_type) |= 2;
  10397.       else if (name == ansi_opname[(int) VEC_DELETE_EXPR])
  10398.     TYPE_GETS_DELETE (current_class_type) |= 2;
  10399.     }
  10400.  
  10401.   if (name == ansi_opname[(int) NEW_EXPR]
  10402.       || name == ansi_opname[(int) VEC_NEW_EXPR])
  10403.     {
  10404.       /* When the compiler encounters the definition of A::operator new, it
  10405.      doesn't look at the class declaration to find out if it's static.  */
  10406.       if (methodp)
  10407.     revert_static_member_fn (&decl, NULL, NULL);
  10408.      
  10409.       /* Take care of function decl if we had syntax errors.  */
  10410.       if (argtypes == NULL_TREE)
  10411.     TREE_TYPE (decl) =
  10412.       build_function_type (ptr_type_node,
  10413.                    hash_tree_chain (integer_type_node,
  10414.                         void_list_node));
  10415.       else
  10416.     TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl));
  10417.     }
  10418.   else if (name == ansi_opname[(int) DELETE_EXPR]
  10419.        || name == ansi_opname[(int) VEC_DELETE_EXPR])
  10420.     {
  10421.       if (methodp)
  10422.     revert_static_member_fn (&decl, NULL, NULL);
  10423.      
  10424.       if (argtypes == NULL_TREE)
  10425.     TREE_TYPE (decl) =
  10426.       build_function_type (void_type_node,
  10427.                    hash_tree_chain (ptr_type_node,
  10428.                         void_list_node));
  10429.       else
  10430.     {
  10431.       TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl));
  10432.  
  10433.       if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR]
  10434.           && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl)))
  10435.           != void_list_node))
  10436.         TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1;
  10437.     }
  10438.     }
  10439.   else
  10440.     {
  10441.       /* An operator function must either be a non-static member function
  10442.      or have at least one parameter of a class, a reference to a class,
  10443.      an enumeration, or a reference to an enumeration.  13.4.0.6 */
  10444.       if (! methodp || DECL_STATIC_FUNCTION_P (decl))
  10445.     {
  10446.       if (OPERATOR_TYPENAME_P (name)
  10447.           || name == ansi_opname[(int) CALL_EXPR]
  10448.           || name == ansi_opname[(int) MODIFY_EXPR]
  10449.           || name == ansi_opname[(int) COMPONENT_REF]
  10450.           || name == ansi_opname[(int) ARRAY_REF])
  10451.         cp_error ("`%D' must be a nonstatic member function", decl);
  10452.       else
  10453.         {
  10454.           tree p = argtypes;
  10455.  
  10456.           if (DECL_STATIC_FUNCTION_P (decl))
  10457.         cp_error ("`%D' must be either a non-static member function or a non-member function", decl);
  10458.  
  10459.           if (p)
  10460.         for (; TREE_VALUE (p) != void_type_node ; p = TREE_CHAIN (p))
  10461.           {
  10462.             tree arg = TREE_VALUE (p);
  10463.             if (TREE_CODE (arg) == REFERENCE_TYPE)
  10464.               arg = TREE_TYPE (arg);
  10465.  
  10466.             /* This lets bad template code slip through.  */
  10467.             if (IS_AGGR_TYPE (arg)
  10468.             || TREE_CODE (arg) == ENUMERAL_TYPE
  10469.             || TREE_CODE (arg) == TEMPLATE_TYPE_PARM)
  10470.               goto foundaggr;
  10471.           }
  10472.           cp_error
  10473.         ("`%D' must have an argument of class or enumerated type",
  10474.          decl);
  10475.         foundaggr:
  10476.           ;
  10477.         }
  10478.     }
  10479.       
  10480.       if (name == ansi_opname[(int) CALL_EXPR]
  10481.       || name == ansi_opname[(int) METHOD_CALL_EXPR])
  10482.     return;            /* no restrictions on args */
  10483.  
  10484.       if (IDENTIFIER_TYPENAME_P (name))
  10485.     {
  10486.       tree t = TREE_TYPE (name);
  10487.       if (TREE_CODE (t) == VOID_TYPE)
  10488.         pedwarn ("void is not a valid type conversion operator");
  10489.       else if (! friendp)
  10490.         {
  10491.           int ref = (TREE_CODE (t) == REFERENCE_TYPE);
  10492.           char *what = 0;
  10493.           if (ref)
  10494.         t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
  10495.  
  10496.           if (t == current_class_type)
  10497.         what = "the same type";
  10498.           else if (IS_AGGR_TYPE (t)
  10499.                && DERIVED_FROM_P (t, current_class_type))
  10500.         what = "a base class";
  10501.  
  10502.           if (what)
  10503.         warning ("conversion to %s%s will never use a type conversion operator",
  10504.              ref ? "a reference to " : "", what);
  10505.         }
  10506.     }
  10507.  
  10508.       if (name == ansi_opname[(int) MODIFY_EXPR])
  10509.     {
  10510.       tree parmtype;
  10511.  
  10512.       if (list_length (argtypes) != 3 && methodp)
  10513.         {
  10514.           cp_error ("`%D' must take exactly one argument", decl);
  10515.           return;
  10516.         }
  10517.       parmtype = TREE_VALUE (TREE_CHAIN (argtypes));
  10518.  
  10519.       if (copy_assignment_arg_p (parmtype, virtualp)
  10520.           && ! friendp)
  10521.         {
  10522.           TYPE_HAS_ASSIGN_REF (current_class_type) = 1;
  10523.           if (TREE_CODE (parmtype) != REFERENCE_TYPE
  10524.           || TYPE_READONLY (TREE_TYPE (parmtype)))
  10525.         TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1;
  10526. #if 0 /* Too soon; done in grok_function_init */
  10527.           if (DECL_ABSTRACT_VIRTUAL_P (decl))
  10528.         TYPE_HAS_ABSTRACT_ASSIGN_REF (current_class_type) = 1;
  10529. #endif
  10530.         }
  10531.     }
  10532.       else if (name == ansi_opname[(int) COND_EXPR])
  10533.     {
  10534.       /* 13.4.0.3 */
  10535.       pedwarn ("ANSI C++ prohibits overloading operator ?:");
  10536.       if (list_length (argtypes) != 4)
  10537.         cp_error ("`%D' must take exactly three arguments", decl);
  10538.     }      
  10539.       else if (ambi_op_p (name))
  10540.     {
  10541.       if (list_length (argtypes) == 2)
  10542.         /* prefix */;
  10543.       else if (list_length (argtypes) == 3)
  10544.         {
  10545.           if ((name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10546.            || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  10547.           && TREE_VALUE (TREE_CHAIN (argtypes)) != integer_type_node)
  10548.         {
  10549.           if (methodp)
  10550.             cp_error ("postfix `%D' must take `int' as its argument",
  10551.                   decl);
  10552.           else
  10553.             cp_error
  10554.               ("postfix `%D' must take `int' as its second argument",
  10555.                decl);
  10556.         }
  10557.         }
  10558.       else
  10559.         {
  10560.           if (methodp)
  10561.         cp_error ("`%D' must take either zero or one argument", decl);
  10562.           else
  10563.         cp_error ("`%D' must take either one or two arguments", decl);
  10564.         }
  10565.     }
  10566.       else if (unary_op_p (name))
  10567.     {
  10568.       if (list_length (argtypes) != 2)
  10569.         {
  10570.           if (methodp)
  10571.         cp_error ("`%D' must take `void'", decl);
  10572.           else
  10573.         cp_error ("`%D' must take exactly one argument", decl);
  10574.         }
  10575.     }
  10576.       else /* if (binary_op_p (name)) */
  10577.     {
  10578.       if (list_length (argtypes) != 3)
  10579.         {
  10580.           if (methodp)
  10581.         cp_error ("`%D' must take exactly one argument", decl);
  10582.           else
  10583.         cp_error ("`%D' must take exactly two arguments", decl);
  10584.         }
  10585.     }
  10586.  
  10587.       /* 13.4.0.8 */
  10588.       if (argtypes)
  10589.     for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes))
  10590.       if (TREE_PURPOSE (argtypes))
  10591.         {
  10592.           TREE_PURPOSE (argtypes) = NULL_TREE;
  10593.           if (name == ansi_opname[(int) POSTINCREMENT_EXPR]
  10594.           || name == ansi_opname[(int) POSTDECREMENT_EXPR])
  10595.         {
  10596.           if (pedantic)
  10597.             cp_pedwarn ("`%D' cannot have default arguments", decl);
  10598.         }
  10599.           else
  10600.         cp_error ("`%D' cannot have default arguments", decl);
  10601.         }
  10602.     }
  10603. }
  10604.  
  10605. /* Get the struct, enum or union (CODE says which) with tag NAME.
  10606.    Define the tag as a forward-reference if it is not defined.
  10607.  
  10608.    C++: If a class derivation is given, process it here, and report
  10609.    an error if multiple derivation declarations are not identical.
  10610.  
  10611.    If this is a definition, come in through xref_tag and only look in
  10612.    the current frame for the name (since C++ allows new names in any
  10613.    scope.)  */
  10614.  
  10615. tree
  10616. xref_tag (code_type_node, name, binfo, globalize)
  10617.      tree code_type_node;
  10618.      tree name, binfo;
  10619.      int globalize;
  10620. {
  10621.   enum tag_types tag_code;
  10622.   enum tree_code code;
  10623.   int temp = 0;
  10624.   int i;
  10625.   register tree ref, t;
  10626.   struct binding_level *b = inner_binding_level;
  10627.  
  10628.   tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  10629.   switch (tag_code)
  10630.     {
  10631.     case record_type:
  10632.     case class_type:
  10633.     case signature_type:
  10634.       code = RECORD_TYPE;
  10635.       break;
  10636.     case union_type:
  10637.       code = UNION_TYPE;
  10638.       break;
  10639.     case enum_type:
  10640.       code = ENUMERAL_TYPE;
  10641.       break;
  10642.     default:
  10643.       my_friendly_abort (18);
  10644.     }
  10645.  
  10646.   /* If a cross reference is requested, look up the type
  10647.      already defined for this tag and return it.  */
  10648.   t = IDENTIFIER_TYPE_VALUE (name);
  10649.   if (t && TREE_CODE (t) != code)
  10650.     t = NULL_TREE;
  10651.  
  10652.   if (! globalize)
  10653.     {
  10654.       /* If we know we are defining this tag, only look it up in this scope
  10655.        * and don't try to find it as a type. */
  10656.       if (t && TYPE_CONTEXT(t) && TREE_MANGLED (name))
  10657.     ref = t;
  10658.       else
  10659.           ref = lookup_tag (code, name, b, 1);
  10660.     }
  10661.   else
  10662.     {
  10663.       if (t)
  10664.     ref = t;
  10665.       else
  10666.         ref = lookup_tag (code, name, b, 0);
  10667.  
  10668.       if (! ref)
  10669.     {
  10670.       /* Try finding it as a type declaration.  If that wins, use it.  */
  10671.       ref = lookup_name (name, 1);
  10672.       if (ref && TREE_CODE (ref) == TYPE_DECL
  10673.           && TREE_CODE (TREE_TYPE (ref)) == code)
  10674.         ref = TREE_TYPE (ref);
  10675.       else
  10676.         ref = NULL_TREE;
  10677.     }
  10678.     }
  10679.  
  10680.   push_obstacks_nochange ();
  10681.  
  10682.   if (! ref)
  10683.     {
  10684.       /* If no such tag is yet defined, create a forward-reference node
  10685.      and record it as the "definition".
  10686.      When a real declaration of this type is found,
  10687.      the forward-reference will be altered into a real type.  */
  10688.  
  10689.       /* In C++, since these migrate into the global scope, we must
  10690.      build them on the permanent obstack.  */
  10691.  
  10692.       temp = allocation_temporary_p ();
  10693.       if (temp)
  10694.     end_temporary_allocation ();
  10695.  
  10696.       if (code == ENUMERAL_TYPE)
  10697.     {
  10698.       ref = make_node (ENUMERAL_TYPE);
  10699.  
  10700.       /* Give the type a default layout like unsigned int
  10701.          to avoid crashing if it does not get defined.  */
  10702.       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
  10703.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  10704.       TREE_UNSIGNED (ref) = 1;
  10705.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  10706.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  10707.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  10708.  
  10709.       /* Enable us to recognize when a type is created in class context.
  10710.          To do nested classes correctly, this should probably be cleared
  10711.          out when we leave this classes scope.  Currently this in only
  10712.          done in `start_enum'.  */
  10713.  
  10714.       pushtag (name, ref, globalize);
  10715.       if (flag_cadillac)
  10716.         cadillac_start_enum (ref);
  10717.     }
  10718.       else
  10719.     {
  10720.       struct binding_level *old_b = class_binding_level;
  10721.  
  10722.       ref = make_lang_type (code);
  10723.  
  10724.       if (tag_code == signature_type)
  10725.         {
  10726.           SET_SIGNATURE (ref);
  10727.           /* Since a signature type will be turned into the type
  10728.          of signature tables, it's not only an interface.  */
  10729.           CLASSTYPE_INTERFACE_ONLY (ref) = 0;
  10730.           SET_CLASSTYPE_INTERFACE_KNOWN (ref);
  10731.           /* A signature doesn't have a vtable.  */
  10732.           CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0;
  10733.         }
  10734.  
  10735. #ifdef NONNESTED_CLASSES
  10736.       /* Class types don't nest the way enums do.  */
  10737.       class_binding_level = (struct binding_level *)0;
  10738. #endif
  10739.       pushtag (name, ref, globalize);
  10740.       class_binding_level = old_b;
  10741.  
  10742.       if (flag_cadillac)
  10743.         cadillac_start_struct (ref);
  10744.     }
  10745.     }
  10746.   else
  10747.     {
  10748.       /* If it no longer looks like a nested type, make sure it's
  10749.      in global scope.  */
  10750.       if (b == global_binding_level && !class_binding_level
  10751.       && IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
  10752.     IDENTIFIER_GLOBAL_VALUE (name) = TYPE_NAME (ref);
  10753.  
  10754. #if 0
  10755.       if (binfo)
  10756.     {
  10757.       tree tt1 = binfo;
  10758.       tree tt2 = TYPE_BINFO_BASETYPES (ref);
  10759.  
  10760.       if (TYPE_BINFO_BASETYPES (ref))
  10761.         for (i = 0; tt1; i++, tt1 = TREE_CHAIN (tt1))
  10762.           if (TREE_VALUE (tt1) != TYPE_IDENTIFIER (BINFO_TYPE (TREE_VEC_ELT (tt2, i))))
  10763.         {
  10764.           cp_error ("redeclaration of derivation chain of type `%#T'",
  10765.                 ref);
  10766.           break;
  10767.         }
  10768.  
  10769.       if (tt1 == NULL_TREE)
  10770.         /* The user told us something we already knew.  */
  10771.         goto just_return;
  10772.  
  10773.       /* In C++, since these migrate into the global scope, we must
  10774.          build them on the permanent obstack.  */
  10775.       end_temporary_allocation ();
  10776.     }
  10777. #endif
  10778.     }
  10779.  
  10780.   if (binfo)
  10781.     xref_basetypes (code_type_node, name, ref, binfo);
  10782.  
  10783.  just_return:
  10784.  
  10785.   /* Until the type is defined, tentatively accept whatever
  10786.      structure tag the user hands us.  */
  10787.   if (TYPE_SIZE (ref) == NULL_TREE
  10788.       && ref != current_class_type
  10789.       /* Have to check this, in case we have contradictory tag info.  */
  10790.       && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
  10791.     {
  10792.       if (tag_code == class_type)
  10793.     CLASSTYPE_DECLARED_CLASS (ref) = 1;
  10794.       else if (tag_code == record_type || tag_code == signature_type)
  10795.     CLASSTYPE_DECLARED_CLASS (ref) = 0;
  10796.     }
  10797.  
  10798.   pop_obstacks ();
  10799.  
  10800.   return ref;
  10801. }
  10802.  
  10803. void
  10804. xref_basetypes (code_type_node, name, ref, binfo)
  10805.      tree code_type_node;
  10806.      tree name, ref;
  10807.      tree binfo;
  10808. {
  10809.   /* In the declaration `A : X, Y, ... Z' we mark all the types
  10810.      (A, X, Y, ..., Z) so we can check for duplicates.  */
  10811.   tree binfos;
  10812.   int i, len;
  10813.   enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node);
  10814.  
  10815.   if (tag_code == union_type)
  10816.     {
  10817.       cp_error ("derived union `%T' invalid", ref);
  10818.       return;
  10819.     }
  10820.  
  10821.   len = list_length (binfo);
  10822.   push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref));
  10823.  
  10824.   SET_CLASSTYPE_MARKED (ref);
  10825.   BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len);
  10826.  
  10827.   for (i = 0; binfo; binfo = TREE_CHAIN (binfo))
  10828.     {
  10829.       /* The base of a derived struct is public by default.  */
  10830.       int via_public
  10831.     = (TREE_PURPOSE (binfo) == (tree)access_public
  10832.        || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10833.        || (tag_code != class_type
  10834.            && (TREE_PURPOSE (binfo) == (tree)access_default
  10835.            || TREE_PURPOSE (binfo) == (tree)access_default_virtual)));
  10836.       int via_protected = TREE_PURPOSE (binfo) == (tree)access_protected;
  10837.       int via_virtual
  10838.     = (TREE_PURPOSE (binfo) == (tree)access_private_virtual
  10839.        || TREE_PURPOSE (binfo) == (tree)access_public_virtual
  10840.        || TREE_PURPOSE (binfo) == (tree)access_default_virtual);
  10841.       tree basetype = TREE_TYPE (TREE_VALUE (binfo));
  10842.       tree base_binfo;
  10843.  
  10844.       GNU_xref_hier (IDENTIFIER_POINTER (name),
  10845.              IDENTIFIER_POINTER (TREE_VALUE (binfo)),
  10846.              via_public, via_virtual, 0);
  10847.  
  10848.       if (basetype && TREE_CODE (basetype) == TYPE_DECL)
  10849.     basetype = TREE_TYPE (basetype);
  10850.       if (!basetype || TREE_CODE (basetype) != RECORD_TYPE)
  10851.     {
  10852.       cp_error ("base type `%T' fails to be a struct or class type",
  10853.             TREE_VALUE (binfo));
  10854.       continue;
  10855.     }
  10856. #if 1
  10857.       /* This code replaces similar code in layout_basetypes.  */
  10858.       else if (TYPE_INCOMPLETE (basetype))
  10859.     {
  10860.       cp_error ("base class `%T' has incomplete type", basetype);
  10861.       continue;
  10862.     }
  10863. #endif
  10864.       else
  10865.     {
  10866.       if (CLASSTYPE_MARKED (basetype))
  10867.         {
  10868.           if (basetype == ref)
  10869.         cp_error ("recursive type `%T' undefined", basetype);
  10870.           else
  10871.         cp_error ("duplicate base type `%T' invalid", basetype);
  10872.           continue;
  10873.         }
  10874.  
  10875.       /* Note that the BINFO records which describe individual
  10876.          inheritances are *not* shared in the lattice!  They
  10877.          cannot be shared because a given baseclass may be
  10878.          inherited with different `accessibility' by different
  10879.          derived classes.  (Each BINFO record describing an
  10880.          individual inheritance contains flags which say what
  10881.          the `accessibility' of that particular inheritance is.)  */
  10882.   
  10883.       base_binfo = make_binfo (integer_zero_node, basetype,
  10884.                    TYPE_BINFO_VTABLE (basetype),
  10885.                    TYPE_BINFO_VIRTUALS (basetype), NULL_TREE);
  10886.  
  10887.       TREE_VEC_ELT (binfos, i) = base_binfo;
  10888.       TREE_VIA_PUBLIC (base_binfo) = via_public;
  10889.       TREE_VIA_PROTECTED (base_binfo) = via_protected;
  10890.       TREE_VIA_VIRTUAL (base_binfo) = via_virtual;
  10891.       BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref);
  10892.  
  10893.       SET_CLASSTYPE_MARKED (basetype);
  10894. #if 0
  10895.       /* XYZZY TEST VIRTUAL BASECLASSES */
  10896.       if (CLASSTYPE_N_BASECLASSES (basetype) == NULL_TREE
  10897.           && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
  10898.           && via_virtual == 0)
  10899.         {
  10900.           warning ("making type `%s' a virtual baseclass",
  10901.                TYPE_NAME_STRING (basetype));
  10902.           via_virtual = 1;
  10903.         }
  10904. #endif
  10905.       /* We are free to modify these bits because they are meaningless
  10906.          at top level, and BASETYPE is a top-level type.  */
  10907.       if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype))
  10908.         {
  10909.           TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1;
  10910.           TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10911.         }
  10912.  
  10913.       TYPE_OVERLOADS_METHOD_CALL_EXPR (ref) |= TYPE_OVERLOADS_METHOD_CALL_EXPR (basetype);
  10914.       TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype);
  10915.       TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
  10916.       CLASSTYPE_LOCAL_TYPEDECLS (ref) |= CLASSTYPE_LOCAL_TYPEDECLS (basetype);
  10917.       i += 1;
  10918.     }
  10919.     }
  10920.   if (i)
  10921.     TREE_VEC_LENGTH (binfos) = i;
  10922.   else
  10923.     BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE;
  10924.  
  10925.   if (i > 1)
  10926.     TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1;
  10927.   else if (i == 1)
  10928.     TYPE_USES_MULTIPLE_INHERITANCE (ref)
  10929.       = TYPE_USES_MULTIPLE_INHERITANCE (BINFO_TYPE (TREE_VEC_ELT (binfos, 0)));
  10930.   if (TYPE_USES_MULTIPLE_INHERITANCE (ref))
  10931.     TYPE_USES_COMPLEX_INHERITANCE (ref) = 1;
  10932.  
  10933.   /* Unmark all the types.  */
  10934.   while (--i >= 0)
  10935.     CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i)));
  10936.   CLEAR_CLASSTYPE_MARKED (ref);
  10937.  
  10938.   pop_obstacks ();
  10939. }
  10940.   
  10941.  
  10942. static tree current_local_enum = NULL_TREE;
  10943.  
  10944. /* Begin compiling the definition of an enumeration type.
  10945.    NAME is its name (or null if anonymous).
  10946.    Returns the type object, as yet incomplete.
  10947.    Also records info about it so that build_enumerator
  10948.    may be used to declare the individual values as they are read.  */
  10949.  
  10950. tree
  10951. start_enum (name)
  10952.      tree name;
  10953. {
  10954.   register tree enumtype = NULL_TREE;
  10955.   struct binding_level *b = inner_binding_level;
  10956.  
  10957.   /* If this is the real definition for a previous forward reference,
  10958.      fill in the contents in the same object that used to be the
  10959.      forward reference.  */
  10960.  
  10961.   if (name != NULL_TREE)
  10962.     enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1);
  10963.  
  10964.   if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE)
  10965.     cp_error ("multiple definition of enum `%T'", enumtype);
  10966.   else
  10967.     {
  10968.       enumtype = make_node (ENUMERAL_TYPE);
  10969.       pushtag (name, enumtype, 0);
  10970.     }
  10971.  
  10972.   if (current_class_type)
  10973.     TREE_ADDRESSABLE (b->tags) = 1;
  10974.   current_local_enum = NULL_TREE;
  10975.  
  10976. #if 0 /* This stuff gets cleared in finish_enum anyway.  */
  10977.   if (TYPE_VALUES (enumtype) != NULL_TREE)
  10978.     /* Completely replace its old definition.
  10979.        The old enumerators remain defined, however.  */
  10980.     TYPE_VALUES (enumtype) = NULL_TREE;
  10981.  
  10982.   /* Initially, set up this enum as like `int'
  10983.      so that we can create the enumerators' declarations and values.
  10984.      Later on, the precision of the type may be changed and
  10985.      it may be laid out again.  */
  10986.  
  10987.   TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  10988.   TYPE_SIZE (enumtype) = NULL_TREE;
  10989.   fixup_signed_type (enumtype);
  10990. #endif
  10991.  
  10992.   /* We copy this value because enumerated type constants
  10993.      are really of the type of the enumerator, not integer_type_node.  */
  10994.   enum_next_value = copy_node (integer_zero_node);
  10995.   enum_overflow = 0;
  10996.  
  10997.   GNU_xref_decl (current_function_decl, enumtype);
  10998.   return enumtype;
  10999. }
  11000.  
  11001. /* After processing and defining all the values of an enumeration type,
  11002.    install their decls in the enumeration type and finish it off.
  11003.    ENUMTYPE is the type object and VALUES a list of name-value pairs.
  11004.    Returns ENUMTYPE.  */
  11005.  
  11006. tree
  11007. finish_enum (enumtype, values)
  11008.      register tree enumtype, values;
  11009. {
  11010.   register tree minnode, maxnode;
  11011.   /* Calculate the maximum value of any enumerator in this type.  */
  11012.  
  11013.   if (values)
  11014.     {
  11015.       register tree pair;
  11016.       register tree value = DECL_INITIAL (TREE_VALUE (values));
  11017.       
  11018.       /* Speed up the main loop by performing some precalculations */
  11019.       TREE_TYPE (TREE_VALUE (values)) = enumtype;
  11020.       TREE_TYPE (value) = enumtype;
  11021.       TREE_VALUE (values) = value;
  11022.       minnode = maxnode = value;
  11023.       
  11024.       for (pair = TREE_CHAIN (values); pair; pair = TREE_CHAIN (pair))
  11025.     {
  11026.       value = DECL_INITIAL (TREE_VALUE (pair));
  11027.       TREE_TYPE (TREE_VALUE (pair)) = enumtype;
  11028.       TREE_TYPE (value) = enumtype;
  11029.       TREE_VALUE (pair) = value;
  11030.       if (tree_int_cst_lt (maxnode, value))
  11031.         maxnode = value;
  11032.       else if (tree_int_cst_lt (value, minnode))
  11033.         minnode = value;
  11034.     }
  11035.     }
  11036.   else
  11037.     maxnode = minnode = integer_zero_node;
  11038.  
  11039.   TYPE_VALUES (enumtype) = values;
  11040.  
  11041.   {
  11042.     int unsignedp = tree_int_cst_sgn (minnode) >= 0;
  11043.     int lowprec = min_precision (minnode, unsignedp);
  11044.     int highprec = min_precision (maxnode, unsignedp);
  11045.     int precision = MAX (lowprec, highprec);
  11046.  
  11047.     TYPE_SIZE (enumtype) = NULL_TREE;
  11048.  
  11049.     /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'.  */
  11050.  
  11051.     TYPE_PRECISION (enumtype) = precision;
  11052.     if (unsignedp)
  11053.       fixup_unsigned_type (enumtype);
  11054.     else
  11055.       fixup_signed_type (enumtype);
  11056.  
  11057.     if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node))
  11058.       /* Use the width of the narrowest normal C type which is wide enough.  */
  11059.       TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size
  11060.                           (precision, 1));
  11061.     else
  11062.       TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  11063.  
  11064.     TYPE_SIZE (enumtype) = 0;
  11065.     layout_type (enumtype);
  11066.   }
  11067.  
  11068.   if (flag_cadillac)
  11069.     cadillac_finish_enum (enumtype);
  11070.  
  11071.   {
  11072.     register tree tem;
  11073.     
  11074.     /* Fix up all variant types of this enum type.  */
  11075.     for (tem = TYPE_MAIN_VARIANT (enumtype); tem;
  11076.      tem = TYPE_NEXT_VARIANT (tem))
  11077.       {
  11078.     TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
  11079.     TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
  11080.     TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
  11081.     TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
  11082.     TYPE_MODE (tem) = TYPE_MODE (enumtype);
  11083.     TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
  11084.     TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
  11085.     TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
  11086.       }
  11087.   }
  11088.  
  11089.   /* Finish debugging output for this type.  */
  11090. #if 0
  11091.   /* @@ Do we ever generate generate ENUMERAL_TYPE nodes for which debugging
  11092.      information should *not* be generated?  I think not.  */
  11093.   if (! DECL_IGNORED_P (TYPE_NAME (enumtype)))
  11094. #endif
  11095.     rest_of_type_compilation (enumtype, global_bindings_p ());
  11096.  
  11097.   return enumtype;
  11098. }
  11099.  
  11100. /* Build and install a CONST_DECL for one value of the
  11101.    current enumeration type (one that was begun with start_enum).
  11102.    Return a tree-list containing the name and its value.
  11103.    Assignment of sequential values by default is handled here.  */
  11104.  
  11105. tree
  11106. build_enumerator (name, value)
  11107.      tree name, value;
  11108. {
  11109.   tree decl, result;
  11110.   /* Change this to zero if we find VALUE is not shareable.  */
  11111.   int shareable = 1;
  11112.  
  11113.   /* Remove no-op casts from the value.  */
  11114.   if (value)
  11115.     STRIP_TYPE_NOPS (value);
  11116.  
  11117.   /* Validate and default VALUE.  */
  11118.   if (value != NULL_TREE)
  11119.     {
  11120.       if (TREE_READONLY_DECL_P (value))
  11121.     {
  11122.       value = decl_constant_value (value);
  11123.       shareable = 0;
  11124.     }
  11125.  
  11126.       if (TREE_CODE (value) == INTEGER_CST)
  11127.     {
  11128.       value = default_conversion (value);
  11129.       constant_expression_warning (value);
  11130.     }
  11131.       else
  11132.     {
  11133.       cp_error ("enumerator value for `%D' not integer constant", name);
  11134.       value = NULL_TREE;
  11135.     }
  11136.     }
  11137.  
  11138.   /* The order of things is reversed here so that we
  11139.      can check for possible sharing of enum values,
  11140.      to keep that from happening.  */
  11141.   /* Default based on previous value.  */
  11142.   if (value == NULL_TREE)
  11143.     {
  11144.       value = enum_next_value;
  11145.       if (enum_overflow)
  11146.     cp_error ("overflow in enumeration values at `%D'", name);
  11147.     }
  11148.  
  11149.   /* Remove no-op casts from the value.  */
  11150.   if (value)
  11151.     STRIP_TYPE_NOPS (value);
  11152.  
  11153.   /* Make up for hacks in lex.c.  */
  11154.   if (value == integer_zero_node)
  11155.     value = build_int_2 (0, 0);
  11156.   else if (value == integer_one_node)
  11157.     value = build_int_2 (1, 0);
  11158.   else if (TREE_CODE (value) == INTEGER_CST
  11159.        && (shareable == 0
  11160.            || TREE_CODE (TREE_TYPE (value)) == ENUMERAL_TYPE))
  11161.     {
  11162.       value = copy_node (value);
  11163.       TREE_TYPE (value) = integer_type_node;
  11164.     }
  11165.  
  11166.   /* C++ associates enums with global, function, or class declarations.  */
  11167.  
  11168.   decl = current_scope ();
  11169.   if (decl && decl == current_class_type)
  11170.     {
  11171.       /* This enum declaration is local to the class, so we must put
  11172.      it in that class's list of decls.  */
  11173.       decl = build_lang_field_decl (CONST_DECL, name, integer_type_node);
  11174.       DECL_INITIAL (decl) = value;
  11175.       TREE_READONLY (decl) = 1;
  11176.       pushdecl_class_level (decl);
  11177.       TREE_CHAIN (decl) = current_local_enum;
  11178.       current_local_enum = decl;
  11179.     }
  11180.   else
  11181.     {
  11182.       /* It's a global enum, or it's local to a function.  (Note local to
  11183.      a function could mean local to a class method.  */
  11184.       decl = build_decl (CONST_DECL, name, integer_type_node);
  11185.       DECL_INITIAL (decl) = value;
  11186.  
  11187.       pushdecl (decl);
  11188.       GNU_xref_decl (current_function_decl, decl);
  11189.     }
  11190.  
  11191.   /* Set basis for default for next value.  */
  11192.   enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value,
  11193.                            integer_one_node, PLUS_EXPR);
  11194.   enum_overflow = tree_int_cst_lt (enum_next_value, value);
  11195.   
  11196.   if (enum_next_value == integer_one_node)
  11197.     enum_next_value = copy_node (enum_next_value);
  11198.  
  11199.   result = saveable_tree_cons (name, decl, NULL_TREE);
  11200.   return result;
  11201. }
  11202.  
  11203. tree
  11204. grok_enum_decls (type, decl)
  11205.      tree type, decl;
  11206. {
  11207.   tree d = current_local_enum;
  11208.   
  11209.   if (d == NULL_TREE)
  11210.     return decl;
  11211.   
  11212.   while (1)
  11213.     {
  11214.       TREE_TYPE (d) = type;
  11215.       if (TREE_CHAIN (d) == NULL_TREE)
  11216.     {
  11217.       TREE_CHAIN (d) = decl;
  11218.       break;
  11219.     }
  11220.       d = TREE_CHAIN (d);
  11221.     }
  11222.  
  11223.   decl = current_local_enum;
  11224.   current_local_enum = NULL_TREE;
  11225.   
  11226.   return decl;
  11227. }
  11228.  
  11229. /* Create the FUNCTION_DECL for a function definition.
  11230.    DECLSPECS and DECLARATOR are the parts of the declaration;
  11231.    they describe the function's name and the type it returns,
  11232.    but twisted together in a fashion that parallels the syntax of C.
  11233.  
  11234.    This function creates a binding context for the function body
  11235.    as well as setting up the FUNCTION_DECL in current_function_decl.
  11236.  
  11237.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  11238.    (it defines a datum instead), we return 0, which tells
  11239.    yyparse to report a parse error.
  11240.  
  11241.    For C++, we must first check whether that datum makes any sense.
  11242.    For example, "class A local_a(1,2);" means that variable local_a
  11243.    is an aggregate of type A, which should have a constructor
  11244.    applied to it with the argument list [1, 2].
  11245.  
  11246.    @@ There is currently no way to retrieve the storage
  11247.    @@ allocated to FUNCTION (or all of its parms) if we return
  11248.    @@ something we had previously.  */
  11249.  
  11250. int
  11251. start_function (declspecs, declarator, raises, attrs, pre_parsed_p)
  11252.      tree declspecs, declarator, raises, attrs;
  11253.      int pre_parsed_p;
  11254. {
  11255.   tree decl1, olddecl;
  11256.   tree ctype = NULL_TREE;
  11257.   tree fntype;
  11258.   tree restype;
  11259.   extern int have_extern_spec;
  11260.   extern int used_extern_spec;
  11261.   int doing_friend = 0;
  11262.  
  11263.   /* Sanity check.  */
  11264.   my_friendly_assert (TREE_VALUE (void_list_node) == void_type_node, 160);
  11265.   my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161);
  11266.  
  11267.   /* Assume, until we see it does. */
  11268.   current_function_returns_value = 0;
  11269.   current_function_returns_null = 0;
  11270.   warn_about_return_type = 0;
  11271.   named_labels = 0;
  11272.   shadowed_labels = 0;
  11273.   current_function_assigns_this = 0;
  11274.   current_function_just_assigned_this = 0;
  11275.   current_function_parms_stored = 0;
  11276.   original_result_rtx = NULL_RTX;
  11277.   current_function_obstack_index = 0;
  11278.   current_function_obstack_usage = 0;
  11279.   base_init_expr = NULL_TREE;
  11280.   protect_list = NULL_TREE;
  11281.   current_base_init_list = NULL_TREE;
  11282.   current_member_init_list = NULL_TREE;
  11283.   ctor_label = dtor_label = NULL_TREE;
  11284.  
  11285.   clear_temp_name ();
  11286.  
  11287.   /* This should only be done once on the top most decl. */
  11288.   if (have_extern_spec && !used_extern_spec)
  11289.     {
  11290.       declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs);
  11291.       used_extern_spec = 1;
  11292.     }
  11293.  
  11294.   if (pre_parsed_p)
  11295.     {
  11296.       decl1 = declarator;
  11297.  
  11298.       if (! DECL_ARGUMENTS (decl1)
  11299.       && !DECL_STATIC_FUNCTION_P (decl1)
  11300.       && DECL_CONTEXT (decl1)
  11301.       && DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))
  11302.       && IDENTIFIER_TEMPLATE (DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl1)))))
  11303.     {
  11304.       cp_error ("redeclaration of `%#D'", decl1);
  11305.       if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)))
  11306.         cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1)));
  11307.       else if (IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)))
  11308.         cp_error_at ("previous declaration here", IDENTIFIER_GLOBAL_VALUE (DECL_NAME (decl1)));
  11309.     }
  11310.  
  11311.       /* This can happen if a template class is instantiated as part of the
  11312.      specialization of a member function which is defined in the class
  11313.      template.  We should just use the specialization, but for now give an
  11314.      error.  */
  11315.       if (DECL_INITIAL (decl1) != NULL_TREE)
  11316.     {
  11317.       cp_error_at ("specialization of `%#D' not supported", decl1);
  11318.       cp_error ("when defined in the class template body", decl1);
  11319.     }
  11320.  
  11321.       last_function_parms = DECL_ARGUMENTS (decl1);
  11322.       last_function_parm_tags = NULL_TREE;
  11323.       fntype = TREE_TYPE (decl1);
  11324.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11325.     ctype = TYPE_METHOD_BASETYPE (fntype);
  11326.  
  11327.       /* ANSI C++ June 5 1992 WP 11.4.5.  A friend function defined in a
  11328.      class is in the (lexical) scope of the class in which it is
  11329.      defined.  */
  11330.       if (!ctype && DECL_FRIEND_P (decl1))
  11331.     {
  11332.       ctype = DECL_CLASS_CONTEXT (decl1);
  11333.  
  11334.       /* CTYPE could be null here if we're dealing with a template;
  11335.          for example, `inline friend float foo()' inside a template
  11336.          will have no CTYPE set.  */
  11337.       if (ctype && TREE_CODE (ctype) != RECORD_TYPE)
  11338.         ctype = NULL_TREE;
  11339.       else
  11340.         doing_friend = 1;
  11341.     }
  11342.  
  11343.       raises = TYPE_RAISES_EXCEPTIONS (fntype);
  11344.  
  11345.       /* In a fcn definition, arg types must be complete.  */
  11346.       require_complete_types_for_parms (last_function_parms);
  11347.  
  11348.       /* In case some arg types were completed since the declaration was
  11349.          parsed, fix up the decls.  */
  11350.       {
  11351.     tree t = last_function_parms;
  11352.     for (; t; t = TREE_CHAIN (t))
  11353.       layout_decl (t, 0);
  11354.       }
  11355.     }
  11356.   else
  11357.     {
  11358.       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, raises,
  11359.                   NULL_TREE);
  11360.       /* If the declarator is not suitable for a function definition,
  11361.      cause a syntax error.  */
  11362.       if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0;
  11363.  
  11364.       fntype = TREE_TYPE (decl1);
  11365.  
  11366.       restype = TREE_TYPE (fntype);
  11367.       if (IS_AGGR_TYPE (restype) && ! TYPE_PTRMEMFUNC_P (restype)
  11368.       && ! CLASSTYPE_GOT_SEMICOLON (restype))
  11369.     {
  11370.       cp_error ("semicolon missing after declaration of `%#T'", restype);
  11371.       shadow_tag (build_tree_list (NULL_TREE, restype));
  11372.       CLASSTYPE_GOT_SEMICOLON (restype) = 1;
  11373.       if (TREE_CODE (fntype) == FUNCTION_TYPE)
  11374.         fntype = build_function_type (integer_type_node,
  11375.                       TYPE_ARG_TYPES (fntype));
  11376.       else
  11377.         fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)),
  11378.                           integer_type_node,
  11379.                           TYPE_ARG_TYPES (fntype));
  11380.       TREE_TYPE (decl1) = fntype;
  11381.     }
  11382.  
  11383.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11384.     ctype = TYPE_METHOD_BASETYPE (fntype);
  11385.       else if (IDENTIFIER_LENGTH (DECL_NAME (decl1)) == 4
  11386.            && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (decl1)), "main")
  11387.            && DECL_CONTEXT (decl1) == NULL_TREE)
  11388.     {
  11389.       /* If this doesn't return integer_type, complain.  */
  11390.       if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node)
  11391.         {
  11392.           if (pedantic || warn_return_type)
  11393.         pedwarn ("return type for `main' changed to integer type");
  11394.           TREE_TYPE (decl1) = fntype = default_function_type;
  11395.         }
  11396.       warn_about_return_type = 0;
  11397.     }
  11398.     }
  11399.  
  11400.   /* Warn if function was previously implicitly declared
  11401.      (but not if we warned then).  */
  11402.   if (! warn_implicit
  11403.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE)
  11404.     cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)));
  11405.  
  11406.   current_function_decl = decl1;
  11407.  
  11408.   if (flag_cadillac)
  11409.     cadillac_start_function (decl1);
  11410.   else
  11411.     announce_function (decl1);
  11412.  
  11413.   if (TYPE_SIZE (TREE_TYPE (fntype)) == NULL_TREE)
  11414.     {
  11415.       if (IS_AGGR_TYPE (TREE_TYPE (fntype)))
  11416.     error_with_aggr_type (TREE_TYPE (fntype),
  11417.                   "return-type `%s' is an incomplete type");
  11418.       else
  11419.     error ("return-type is an incomplete type");
  11420.  
  11421.       /* Make it return void instead, but don't change the
  11422.      type of the DECL_RESULT, in case we have a named return value.  */
  11423.       if (ctype)
  11424.     TREE_TYPE (decl1)
  11425.       = build_cplus_method_type (build_type_variant (ctype,
  11426.                              TREE_READONLY (decl1),
  11427.                              TREE_SIDE_EFFECTS (decl1)),
  11428.                      void_type_node,
  11429.                      FUNCTION_ARG_CHAIN (decl1));
  11430.       else
  11431.     TREE_TYPE (decl1)
  11432.       = build_function_type (void_type_node,
  11433.                  TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  11434.       DECL_RESULT (decl1)
  11435.     = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype)));
  11436.       TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (TREE_TYPE (fntype));
  11437.       TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (TREE_TYPE (fntype));
  11438.     }
  11439.  
  11440.   if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype))
  11441.       && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype)))
  11442.     abstract_virtuals_error (decl1, TREE_TYPE (fntype));
  11443.  
  11444.   if (warn_about_return_type)
  11445.     warning ("return-type defaults to `int'");
  11446.  
  11447.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  11448.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  11449.   DECL_INITIAL (decl1) = error_mark_node;
  11450.  
  11451.   /* Didn't get anything from C.  */
  11452.   olddecl = NULL_TREE;
  11453.  
  11454.   /* This function exists in static storage.
  11455.      (This does not mean `static' in the C sense!)  */
  11456.   TREE_STATIC (decl1) = 1;
  11457.  
  11458.   /* Record the decl so that the function name is defined.
  11459.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  11460.      use the old decl.  */
  11461.  
  11462.   if (pre_parsed_p == 0)
  11463.     {
  11464.       current_function_decl = decl1 = pushdecl (decl1);
  11465.       DECL_MAIN_VARIANT (decl1) = decl1;
  11466.       fntype = TREE_TYPE (decl1);
  11467.     }
  11468.   else
  11469.     current_function_decl = decl1;
  11470.  
  11471.   if (DECL_INTERFACE_KNOWN (decl1))
  11472.     {
  11473.       if (DECL_NOT_REALLY_EXTERN (decl1))
  11474.     DECL_EXTERNAL (decl1) = 0;
  11475.     }
  11476.   /* If this function belongs to an interface, it is public.
  11477.      If it belongs to someone else's interface, it is also external.
  11478.      It doesn't matter whether it's inline or not.  */
  11479.   else if (interface_unknown == 0)
  11480.     {
  11481.       if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1))
  11482.     DECL_EXTERNAL (decl1)
  11483.       = (interface_only
  11484.          || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines));
  11485.       else
  11486.     DECL_EXTERNAL (decl1) = 0;
  11487.       DECL_NOT_REALLY_EXTERN (decl1) = 0;
  11488.       DECL_INTERFACE_KNOWN (decl1) = 1;
  11489.     }
  11490.   else
  11491.     {
  11492.       /* This is a definition, not a reference.
  11493.      So clear DECL_EXTERNAL.  */
  11494.       DECL_EXTERNAL (decl1) = 0;
  11495.  
  11496.       if (DECL_THIS_INLINE (decl1) && ! DECL_INTERFACE_KNOWN (decl1))
  11497.     DECL_DEFER_OUTPUT (decl1) = 1;
  11498.       else
  11499.     {
  11500.       DECL_INTERFACE_KNOWN (decl1) = 1;
  11501.       if (DECL_C_STATIC (decl1))
  11502.         TREE_PUBLIC (decl1) = 0;
  11503.     }
  11504.     }
  11505.  
  11506.   if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1))
  11507.     {
  11508.       if (TREE_CODE (fntype) == METHOD_TYPE)
  11509.     TREE_TYPE (decl1) = fntype
  11510.       = build_function_type (TREE_TYPE (fntype),
  11511.                  TREE_CHAIN (TYPE_ARG_TYPES (fntype)));
  11512.       last_function_parms = TREE_CHAIN (last_function_parms);
  11513.       DECL_ARGUMENTS (decl1) = last_function_parms;
  11514.       ctype = NULL_TREE;
  11515.     }
  11516.   restype = TREE_TYPE (fntype);
  11517.  
  11518.   if (ctype)
  11519.     {
  11520.       push_nested_class (ctype, 1);
  11521.  
  11522.       /* If we're compiling a friend function, neither of the variables
  11523.      current_class_decl nor current_class_type will have values.  */
  11524.       if (! doing_friend)
  11525.     {
  11526.       /* We know that this was set up by `grokclassfn'.
  11527.          We do not wait until `store_parm_decls', since evil
  11528.          parse errors may never get us to that point.  Here
  11529.          we keep the consistency between `current_class_type'
  11530.          and `current_class_decl'.  */
  11531.       tree t = last_function_parms;
  11532.  
  11533.       my_friendly_assert (t != NULL_TREE
  11534.                   && TREE_CODE (t) == PARM_DECL, 162);
  11535.  
  11536.       if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE)
  11537.         {
  11538.           int i = suspend_momentary ();
  11539.  
  11540.           /* Fool build_indirect_ref.  */
  11541.           current_class_decl = NULL_TREE;
  11542.           C_C_D = build_indirect_ref (t, NULL_PTR);
  11543.           current_class_decl = t;
  11544.           resume_momentary (i);
  11545.         }
  11546.       else
  11547.         /* We're having a signature pointer here.  */
  11548.         C_C_D = current_class_decl = t;
  11549.  
  11550.     }
  11551.     }
  11552.   else
  11553.     {
  11554.       if (DECL_STATIC_FUNCTION_P (decl1))
  11555.     push_nested_class (DECL_CONTEXT (decl1), 2);
  11556.       else
  11557.     push_memoized_context (0, 1);
  11558.       current_class_decl = C_C_D = NULL_TREE;
  11559.     }
  11560.  
  11561.   pushlevel (0);
  11562.   current_binding_level->parm_flag = 1;
  11563.  
  11564.   /* Save the parm names or decls from this function's declarator
  11565.      where store_parm_decls will find them.  */
  11566.   current_function_parms = last_function_parms;
  11567.   current_function_parm_tags = last_function_parm_tags;
  11568.  
  11569.   GNU_xref_function (decl1, current_function_parms);
  11570.  
  11571.   if (attrs)
  11572.     cplus_decl_attributes (decl1, NULL_TREE, attrs);
  11573.   make_function_rtl (decl1);
  11574.  
  11575.   /* Allocate further tree nodes temporarily during compilation
  11576.      of this function only.  Tiemann moved up here from bottom of fn.  */
  11577.   temporary_allocation ();
  11578.  
  11579.   /* Promote the value to int before returning it.  */
  11580.   if (C_PROMOTING_INTEGER_TYPE_P (restype))
  11581.     {
  11582.       /* It retains unsignedness if traditional or if it isn't
  11583.      really getting wider.  */
  11584.       if (TREE_UNSIGNED (restype)
  11585.       && (flag_traditional
  11586.           || TYPE_PRECISION (restype)
  11587.            == TYPE_PRECISION (integer_type_node)))
  11588.     restype = unsigned_type_node;
  11589.       else
  11590.     restype = integer_type_node;
  11591.     }
  11592.   if (DECL_RESULT (decl1) == NULL_TREE)
  11593.     {
  11594.       DECL_RESULT (decl1)
  11595.     = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
  11596.       TREE_READONLY (DECL_RESULT (decl1)) = TYPE_READONLY (restype);
  11597.       TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = TYPE_VOLATILE (restype);
  11598.     }
  11599.  
  11600.   if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1))
  11601.       && DECL_LANGUAGE (decl1) == lang_cplusplus)
  11602.     {
  11603.       dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11604.       ctor_label = NULL_TREE;
  11605.     }
  11606.   else
  11607.     {
  11608.       dtor_label = NULL_TREE;
  11609.       if (DECL_CONSTRUCTOR_P (decl1))
  11610.     ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  11611.     }
  11612.  
  11613.   /* If this fcn was already referenced via a block-scope `extern' decl
  11614.      (or an implicit decl), propagate certain information about the usage.  */
  11615.   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1)))
  11616.     TREE_ADDRESSABLE (decl1) = 1;
  11617.  
  11618.   return 1;
  11619. }
  11620.  
  11621. void
  11622. expand_start_early_try_stmts ()
  11623. {
  11624.   rtx insns;
  11625.   start_sequence ();
  11626.   expand_start_try_stmts ();
  11627.   insns = get_insns ();
  11628.   end_sequence ();
  11629.   store_in_parms (insns);
  11630. }
  11631.  
  11632. void
  11633. store_in_parms (insns)
  11634.      rtx insns;
  11635. {
  11636.   rtx last_parm_insn;
  11637.  
  11638.   last_parm_insn = get_first_nonparm_insn ();
  11639.   if (last_parm_insn == NULL_RTX)
  11640.     emit_insns (insns);
  11641.   else
  11642.     emit_insns_before (insns, previous_insn (last_parm_insn));
  11643. }
  11644.  
  11645. /* Store the parameter declarations into the current function declaration.
  11646.    This is called after parsing the parameter declarations, before
  11647.    digesting the body of the function.
  11648.  
  11649.    Also install to binding contour return value identifier, if any.  */
  11650.  
  11651. void
  11652. store_parm_decls ()
  11653. {
  11654.   register tree fndecl = current_function_decl;
  11655.   register tree parm;
  11656.   int parms_have_cleanups = 0;
  11657.  
  11658.   /* This is either a chain of PARM_DECLs (when a prototype is used).  */
  11659.   tree specparms = current_function_parms;
  11660.  
  11661.   /* This is a list of types declared among parms in a prototype.  */
  11662.   tree parmtags = current_function_parm_tags;
  11663.  
  11664.   /* This is a chain of any other decls that came in among the parm
  11665.      declarations.  If a parm is declared with  enum {foo, bar} x;
  11666.      then CONST_DECLs for foo and bar are put here.  */
  11667.   tree nonparms = NULL_TREE;
  11668.  
  11669.   if (toplevel_bindings_p ())
  11670.     fatal ("parse errors have confused me too much");
  11671.  
  11672.   /* Initialize RTL machinery.  */
  11673.   init_function_start (fndecl, input_filename, lineno);
  11674.  
  11675.   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
  11676.   declare_function_name ();
  11677.  
  11678.   /* Create a binding level for the parms.  */
  11679.   expand_start_bindings (0);
  11680.  
  11681.   if (specparms != NULL_TREE)
  11682.     {
  11683.       /* This case is when the function was defined with an ANSI prototype.
  11684.      The parms already have decls, so we need not do anything here
  11685.      except record them as in effect
  11686.      and complain if any redundant old-style parm decls were written.  */
  11687.  
  11688.       register tree next;
  11689.  
  11690.       /* Must clear this because it might contain TYPE_DECLs declared
  11691.      at class level.  */
  11692.       storedecls (NULL_TREE);
  11693.       for (parm = nreverse (specparms); parm; parm = next)
  11694.     {
  11695.       next = TREE_CHAIN (parm);
  11696.       if (TREE_CODE (parm) == PARM_DECL)
  11697.         {
  11698.           tree cleanup = maybe_build_cleanup (parm);
  11699.           if (DECL_NAME (parm) == NULL_TREE)
  11700.         {
  11701. #if 0
  11702.           cp_error_at ("parameter name omitted", parm);
  11703. #else
  11704.           /* for C++, this is not an error.  */
  11705.           pushdecl (parm);
  11706. #endif
  11707.         }
  11708.           else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  11709.         cp_error ("parameter `%D' declared void", parm);
  11710.           else
  11711.         {
  11712.           /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls.
  11713.              A parameter is assumed not to have any side effects.
  11714.              If this should change for any reason, then this
  11715.              will have to wrap the bashed reference type in a save_expr.
  11716.              
  11717.              Also, if the parameter type is declared to be an X
  11718.              and there is an X(X&) constructor, we cannot lay it
  11719.              into the stack (any more), so we make this parameter
  11720.              look like it is really of reference type.  Functions
  11721.              which pass parameters to this function will know to
  11722.              create a temporary in their frame, and pass a reference
  11723.              to that.  */
  11724.  
  11725.           if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE
  11726.               && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm))))
  11727.             SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm));
  11728.  
  11729.           pushdecl (parm);
  11730.         }
  11731.           if (cleanup)
  11732.         {
  11733.           expand_decl (parm);
  11734.           if (! cp_expand_decl_cleanup (parm, cleanup))
  11735.             cp_error ("parser lost in parsing declaration of `%D'",
  11736.                   parm);
  11737.           parms_have_cleanups = 1;
  11738.         }
  11739.         }
  11740.       else
  11741.         {
  11742.           /* If we find an enum constant or a type tag,
  11743.          put it aside for the moment.  */
  11744.           TREE_CHAIN (parm) = NULL_TREE;
  11745.           nonparms = chainon (nonparms, parm);
  11746.         }
  11747.     }
  11748.  
  11749.       /* Get the decls in their original chain order
  11750.      and record in the function.  This is all and only the
  11751.      PARM_DECLs that were pushed into scope by the loop above.  */
  11752.       DECL_ARGUMENTS (fndecl) = getdecls ();
  11753.  
  11754.       storetags (chainon (parmtags, gettags ()));
  11755.     }
  11756.   else
  11757.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  11758.  
  11759.   /* Now store the final chain of decls for the arguments
  11760.      as the decl-chain of the current lexical scope.
  11761.      Put the enumerators in as well, at the front so that
  11762.      DECL_ARGUMENTS is not modified.  */
  11763.  
  11764.   storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  11765.  
  11766.   /* Initialize the RTL code for the function.  */
  11767.   DECL_SAVED_INSNS (fndecl) = NULL_RTX;
  11768.   expand_function_start (fndecl, parms_have_cleanups);
  11769.  
  11770.   /* Create a binding contour which can be used to catch
  11771.      cleanup-generated temporaries.  Also, if the return value needs or
  11772.      has initialization, deal with that now.  */
  11773.   if (parms_have_cleanups)
  11774.     {
  11775.       pushlevel (0);
  11776.       expand_start_bindings (0);
  11777.     }
  11778.  
  11779.   current_function_parms_stored = 1;
  11780.  
  11781.   if (flag_gc)
  11782.     {
  11783.       maybe_gc_cleanup = build_tree_list (NULL_TREE, error_mark_node);
  11784.       if (! cp_expand_decl_cleanup (NULL_TREE, maybe_gc_cleanup))
  11785.     cp_error ("parser lost in parsing declaration of `%D'", fndecl);
  11786.     }
  11787.  
  11788.   /* If this function is `main', emit a call to `__main'
  11789.      to run global initializers, etc.  */
  11790.   if (DECL_NAME (fndecl)
  11791.       && IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  11792. #ifdef _WIN32
  11793.       && (strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  11794.       || strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "WinMain") == 0)
  11795. #else
  11796.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  11797. #endif /* _WIN32 */
  11798.       && DECL_CONTEXT (fndecl) == NULL_TREE)
  11799.     {
  11800.       expand_main_function ();
  11801.  
  11802.       if (flag_gc)
  11803.     expand_expr (build_function_call (lookup_name (get_identifier ("__gc_main"), 0), NULL_TREE),
  11804.              0, VOIDmode, 0);
  11805. #if 0
  11806.       /* done at a different time */
  11807.       if (flag_rtti)
  11808.     output_builtin_tdesc_entries ();
  11809. #endif
  11810.     }
  11811.  
  11812.   /* Take care of exception handling things. */
  11813.   if (flag_handle_exceptions)
  11814.     {
  11815.       rtx insns;
  11816.       start_sequence ();
  11817.  
  11818.       /* Mark the start of a stack unwinder if we need one.  */
  11819.       start_eh_unwinder ();
  11820.  
  11821.       /* Do the starting of the exception specifications, if we have any.  */
  11822.       if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl)))
  11823.     expand_start_eh_spec ();
  11824.  
  11825.       insns = get_insns ();
  11826.       end_sequence ();
  11827.  
  11828.       if (insns)
  11829.     store_in_parms (insns);
  11830.     }
  11831. }
  11832.  
  11833. /* Bind a name and initialization to the return value of
  11834.    the current function.  */
  11835. void
  11836. store_return_init (return_id, init)
  11837.      tree return_id, init;
  11838. {
  11839.   tree decl = DECL_RESULT (current_function_decl);
  11840.  
  11841.   if (pedantic)
  11842.     /* Give this error as many times as there are occurrences,
  11843.        so that users can use Emacs compilation buffers to find
  11844.        and fix all such places.  */
  11845.     pedwarn ("ANSI C++ does not permit named return values");
  11846.  
  11847.   if (return_id != NULL_TREE)
  11848.     {
  11849.       if (DECL_NAME (decl) == NULL_TREE)
  11850.     {
  11851.       DECL_NAME (decl) = return_id;
  11852.       DECL_ASSEMBLER_NAME (decl) = return_id;
  11853.     }
  11854.       else
  11855.     error ("return identifier `%s' already in place",
  11856.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  11857.     }
  11858.  
  11859.   /* Can't let this happen for constructors.  */
  11860.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  11861.     {
  11862.       error ("can't redefine default return value for constructors");
  11863.       return;
  11864.     }
  11865.  
  11866.   /* If we have a named return value, put that in our scope as well.  */
  11867.   if (DECL_NAME (decl) != NULL_TREE)
  11868.     {
  11869.       /* If this named return value comes in a register,
  11870.      put it in a pseudo-register.  */
  11871.       if (DECL_REGISTER (decl))
  11872.     {
  11873.       original_result_rtx = DECL_RTL (decl);
  11874.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  11875.     }
  11876.  
  11877.       /* Let `cp_finish_decl' know that this initializer is ok.  */
  11878.       DECL_INITIAL (decl) = init;
  11879.       pushdecl (decl);
  11880.       cp_finish_decl (decl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
  11881.     }
  11882. }
  11883.  
  11884.  
  11885. /* Finish up a function declaration and compile that function
  11886.    all the way to assembler language output.  The free the storage
  11887.    for the function definition.
  11888.  
  11889.    This is called after parsing the body of the function definition.
  11890.    LINENO is the current line number.
  11891.  
  11892.    C++: CALL_POPLEVEL is non-zero if an extra call to poplevel
  11893.    (and expand_end_bindings) must be made to take care of the binding
  11894.    contour for the base initializers.  This is only relevant for
  11895.    constructors.  */
  11896.  
  11897. void
  11898. finish_function (lineno, call_poplevel, nested)
  11899.      int lineno;
  11900.      int call_poplevel;
  11901.      int nested;
  11902. {
  11903.   register tree fndecl = current_function_decl;
  11904.   tree fntype, ctype = NULL_TREE;
  11905.   rtx last_parm_insn, insns;
  11906.   /* Label to use if this function is supposed to return a value.  */
  11907.   tree no_return_label = NULL_TREE;
  11908.   tree decls = NULL_TREE;
  11909.  
  11910.   /* When we get some parse errors, we can end up without a
  11911.      current_function_decl, so cope.  */
  11912.   if (fndecl == NULL_TREE)
  11913.     return;
  11914.  
  11915.   fntype = TREE_TYPE (fndecl);
  11916.  
  11917. /*  TREE_READONLY (fndecl) = 1;
  11918.     This caused &foo to be of type ptr-to-const-function
  11919.     which then got a warning when stored in a ptr-to-function variable.  */
  11920.  
  11921.   /* This happens on strange parse errors.  */
  11922.   if (! current_function_parms_stored)
  11923.     {
  11924.       call_poplevel = 0;
  11925.       store_parm_decls ();
  11926.     }
  11927.  
  11928.   if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/)
  11929.     {
  11930.       tree ttype = target_type (fntype);
  11931.       tree parmdecl;
  11932.  
  11933.       if (IS_AGGR_TYPE (ttype))
  11934.     /* Let debugger know it should output info for this type.  */
  11935.     note_debug_info_needed (ttype);
  11936.  
  11937.       for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl))
  11938.     {
  11939.       ttype = target_type (TREE_TYPE (parmdecl));
  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.     }
  11945.  
  11946.   /* Clean house because we will need to reorder insns here.  */
  11947.   do_pending_stack_adjust ();
  11948.  
  11949.   if (dtor_label)
  11950.     {
  11951.       tree binfo = TYPE_BINFO (current_class_type);
  11952.       tree cond = integer_one_node;
  11953.       tree exprstmt, vfields;
  11954.       tree in_charge_node = lookup_name (in_charge_identifier, 0);
  11955.       tree virtual_size;
  11956.       int ok_to_optimize_dtor = 0;
  11957.  
  11958.       if (current_function_assigns_this)
  11959.     cond = build (NE_EXPR, boolean_type_node,
  11960.               current_class_decl, integer_zero_node);
  11961.       else
  11962.     {
  11963.       int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type);
  11964.  
  11965.       /* If this destructor is empty, then we don't need to check
  11966.          whether `this' is NULL in some cases.  */
  11967.       if ((flag_this_is_variable & 1) == 0)
  11968.         ok_to_optimize_dtor = 1;
  11969.       else if (get_last_insn () == get_first_nonparm_insn ())
  11970.         ok_to_optimize_dtor
  11971.           = (n_baseclasses == 0
  11972.          || (n_baseclasses == 1
  11973.              && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0))));
  11974.     }
  11975.  
  11976.       /* These initializations might go inline.  Protect
  11977.      the binding level of the parms.  */
  11978.       pushlevel (0);
  11979.       expand_start_bindings (0);
  11980.  
  11981.       if (current_function_assigns_this)
  11982.     {
  11983.       current_function_assigns_this = 0;
  11984.       current_function_just_assigned_this = 0;
  11985.     }
  11986.  
  11987.       /* Generate the code to call destructor on base class.
  11988.      If this destructor belongs to a class with virtual
  11989.      functions, then set the virtual function table
  11990.      pointer to represent the type of our base class.  */
  11991.  
  11992.       /* This side-effect makes call to `build_delete' generate the
  11993.      code we have to have at the end of this destructor.  */
  11994.       TYPE_HAS_DESTRUCTOR (current_class_type) = 0;
  11995.  
  11996.       /* These are two cases where we cannot delegate deletion.  */
  11997.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)
  11998.       || TYPE_GETS_REG_DELETE (current_class_type))
  11999.     exprstmt = build_delete (current_class_type, C_C_D, integer_zero_node,
  12000.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  12001.       else
  12002.     exprstmt = build_delete (current_class_type, C_C_D, in_charge_node,
  12003.                  LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
  12004.  
  12005.       /* If we did not assign to this, then `this' is non-zero at
  12006.      the end of a destructor.  As a special optimization, don't
  12007.      emit test if this is an empty destructor.  If it does nothing,
  12008.      it does nothing.  If it calls a base destructor, the base
  12009.      destructor will perform the test.  */
  12010.  
  12011.       if (exprstmt != error_mark_node
  12012.       && (TREE_CODE (exprstmt) != NOP_EXPR
  12013.           || TREE_OPERAND (exprstmt, 0) != integer_zero_node
  12014.           || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)))
  12015.     {
  12016.       expand_label (dtor_label);
  12017.       if (cond != integer_one_node)
  12018.         expand_start_cond (cond, 0);
  12019.       if (exprstmt != void_zero_node)
  12020.         /* Don't call `expand_expr_stmt' if we're not going to do
  12021.            anything, since -Wall will give a diagnostic.  */
  12022.         expand_expr_stmt (exprstmt);
  12023.  
  12024.       /* Run destructor on all virtual baseclasses.  */
  12025.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12026.         {
  12027.           tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type)));
  12028.           expand_start_cond (build (BIT_AND_EXPR, integer_type_node,
  12029.                     in_charge_node, integer_two_node), 0);
  12030.           while (vbases)
  12031.         {
  12032.           if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases)))
  12033.             {
  12034.               tree ptr = convert_pointer_to_vbase (BINFO_TYPE (vbases), current_class_decl);
  12035.               expand_expr_stmt (build_delete (build_pointer_type (BINFO_TYPE (vbases)),
  12036.                               ptr, integer_zero_node,
  12037.                               LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_HAS_IN_CHARGE, 0));
  12038.             }
  12039.           vbases = TREE_CHAIN (vbases);
  12040.         }
  12041.           expand_end_cond ();
  12042.         }
  12043.  
  12044.       do_pending_stack_adjust ();
  12045.       if (cond != integer_one_node)
  12046.         expand_end_cond ();
  12047.     }
  12048.  
  12049.       TYPE_HAS_DESTRUCTOR (current_class_type) = 1;
  12050.  
  12051.       virtual_size = c_sizeof (current_class_type);
  12052.  
  12053.       /* At the end, call delete if that's what's requested.  */
  12054.       if (TYPE_GETS_REG_DELETE (current_class_type))
  12055.     /* This NOP_EXPR means we are in a static call context.  */
  12056.     exprstmt =
  12057.       build_method_call
  12058.         (build_indirect_ref
  12059.          (build1 (NOP_EXPR, build_pointer_type (current_class_type),
  12060.               error_mark_node),
  12061.           NULL_PTR),
  12062.          ansi_opname[(int) DELETE_EXPR],
  12063.          tree_cons (NULL_TREE, current_class_decl,
  12064.             build_tree_list (NULL_TREE, virtual_size)),
  12065.          NULL_TREE, LOOKUP_NORMAL);
  12066.       else if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12067.     exprstmt = build_x_delete (ptr_type_node, current_class_decl, 0,
  12068.                    virtual_size);
  12069.       else
  12070.     exprstmt = NULL_TREE;
  12071.  
  12072.       if (exprstmt)
  12073.     {
  12074.       cond = build (BIT_AND_EXPR, integer_type_node,
  12075.             in_charge_node, integer_one_node);
  12076.       expand_start_cond (cond, 0);
  12077.       expand_expr_stmt (exprstmt);
  12078.       expand_end_cond ();
  12079.     }
  12080.  
  12081.       /* End of destructor.  */
  12082.       expand_end_bindings (NULL_TREE, getdecls() != NULL_TREE, 0);
  12083.       poplevel (2, 0, 0); /* XXX change to 1 */
  12084.  
  12085.       /* Back to the top of destructor.  */
  12086.       /* Dont execute destructor code if `this' is NULL.  */
  12087.  
  12088.       start_sequence ();
  12089.  
  12090.       /* Make all virtual function table pointers in non-virtual base
  12091.      classes point to CURRENT_CLASS_TYPE's virtual function
  12092.      tables.  */
  12093.       expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_decl);
  12094.       if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))
  12095.     expand_indirect_vtbls_init (binfo, C_C_D, current_class_decl, 0);
  12096.       if (! ok_to_optimize_dtor)
  12097.     {
  12098.       cond = build_binary_op (NE_EXPR,
  12099.                   current_class_decl, integer_zero_node, 1);
  12100.       expand_start_cond (cond, 0);
  12101.     }
  12102.  
  12103.       insns = get_insns ();
  12104.       end_sequence ();
  12105.  
  12106.       last_parm_insn = get_first_nonparm_insn ();
  12107.       if (last_parm_insn == NULL_RTX)
  12108.     last_parm_insn = get_last_insn ();
  12109.       else
  12110.     last_parm_insn = previous_insn (last_parm_insn);
  12111.  
  12112.       emit_insns_after (insns, last_parm_insn);
  12113.  
  12114.       if (! ok_to_optimize_dtor)
  12115.     expand_end_cond ();
  12116.     }
  12117.   else if (current_function_assigns_this)
  12118.     {
  12119.       /* Does not need to call emit_base_init, because
  12120.      that is done (if needed) just after assignment to this
  12121.      is seen.  */
  12122.  
  12123.       if (DECL_CONSTRUCTOR_P (current_function_decl))
  12124.     {
  12125.       end_protect_partials ();
  12126.       expand_label (ctor_label);
  12127.       ctor_label = NULL_TREE;
  12128.  
  12129.       if (call_poplevel)
  12130.         {
  12131.           decls = getdecls ();
  12132.           expand_end_bindings (decls, decls != NULL_TREE, 0);
  12133.           poplevel (decls != NULL_TREE, 0, 0);
  12134.         }
  12135.       c_expand_return (current_class_decl);
  12136.     }
  12137.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (
  12138.             DECL_RESULT (current_function_decl))) != void_type_node
  12139.            && return_label != NULL_RTX)
  12140.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  12141.  
  12142.       current_function_assigns_this = 0;
  12143.       current_function_just_assigned_this = 0;
  12144.       base_init_expr = NULL_TREE;
  12145.     }
  12146.   else if (DECL_CONSTRUCTOR_P (fndecl))
  12147.     {
  12148.       tree allocated_this;
  12149.       tree cond, thenclause;
  12150.       /* Allow constructor for a type to get a new instance of the object
  12151.      using `build_new'.  */
  12152.       tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type);
  12153.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE;
  12154.  
  12155.       DECL_RETURNS_FIRST_ARG (fndecl) = 1;
  12156.  
  12157.       if (flag_this_is_variable > 0)
  12158.     {
  12159.       cond = build_binary_op (EQ_EXPR,
  12160.                   current_class_decl, integer_zero_node, 1);
  12161.       thenclause = build_modify_expr (current_class_decl, NOP_EXPR,
  12162.                       build_new (NULL_TREE, current_class_type, void_type_node, 0));
  12163.     }
  12164.  
  12165.       CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals;
  12166.  
  12167.       start_sequence ();
  12168.  
  12169.       if (flag_this_is_variable > 0)
  12170.     {
  12171.       expand_start_cond (cond, 0);
  12172.       expand_expr_stmt (thenclause);
  12173.       expand_end_cond ();
  12174.     }
  12175.  
  12176. #if 0
  12177.       if (DECL_NAME (fndecl) == NULL_TREE
  12178.       && TREE_CHAIN (DECL_ARGUMENTS (fndecl)) != NULL_TREE)
  12179.     build_default_constructor (fndecl);
  12180. #endif
  12181.  
  12182.       /* Emit insns from `emit_base_init' which sets up virtual
  12183.      function table pointer(s).  */
  12184.       if (base_init_expr)
  12185.     {
  12186.       expand_expr_stmt (base_init_expr);
  12187.       base_init_expr = NULL_TREE;
  12188.     }
  12189.  
  12190.       insns = get_insns ();
  12191.       end_sequence ();
  12192.  
  12193.       /* This is where the body of the constructor begins.
  12194.      If there were no insns in this function body, then the
  12195.      last_parm_insn is also the last insn.
  12196.  
  12197.      If optimization is enabled, last_parm_insn may move, so
  12198.      we don't hold on to it (across emit_base_init).  */
  12199.       last_parm_insn = get_first_nonparm_insn ();
  12200.       if (last_parm_insn == NULL_RTX)
  12201.     last_parm_insn = get_last_insn ();
  12202.       else
  12203.     last_parm_insn = previous_insn (last_parm_insn);
  12204.  
  12205.       emit_insns_after (insns, last_parm_insn);
  12206.  
  12207.       end_protect_partials ();
  12208.  
  12209.       /* This is where the body of the constructor ends.  */
  12210.       expand_label (ctor_label);
  12211.       ctor_label = NULL_TREE;
  12212.  
  12213.       if (call_poplevel)
  12214.     {
  12215.       decls = getdecls ();
  12216.       expand_end_bindings (decls, decls != NULL_TREE, 0);
  12217.       poplevel (decls != NULL_TREE, 1, 0);
  12218.     }
  12219.  
  12220.       c_expand_return (current_class_decl);
  12221.  
  12222.       current_function_assigns_this = 0;
  12223.       current_function_just_assigned_this = 0;
  12224.     }
  12225.   else if (IDENTIFIER_LENGTH (DECL_NAME (fndecl)) == 4
  12226.        && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main")
  12227.        && DECL_CONTEXT (fndecl) == NULL_TREE)
  12228.     {
  12229.       /* Make it so that `main' always returns 0 by default.  */
  12230. #ifdef VMS
  12231.       c_expand_return (integer_one_node);
  12232. #else
  12233.       c_expand_return (integer_zero_node);
  12234. #endif
  12235.     }
  12236.   else if (return_label != NULL_RTX
  12237.        && current_function_return_value == NULL_TREE
  12238.        && ! DECL_NAME (DECL_RESULT (current_function_decl)))
  12239.     no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  12240.  
  12241.   if (flag_gc)
  12242.     expand_gc_prologue_and_epilogue ();
  12243.  
  12244.   /* If this function is supposed to return a value, ensure that
  12245.      we do not fall into the cleanups by mistake.  The end of our
  12246.      function will look like this:
  12247.  
  12248.     user code (may have return stmt somewhere)
  12249.     goto no_return_label
  12250.     cleanup_label:
  12251.     cleanups
  12252.     goto return_label
  12253.     no_return_label:
  12254.     NOTE_INSN_FUNCTION_END
  12255.     return_label:
  12256.     things for return
  12257.  
  12258.      If the user omits a return stmt in the USER CODE section, we
  12259.      will have a control path which reaches NOTE_INSN_FUNCTION_END.
  12260.      Otherwise, we won't.  */
  12261.   if (no_return_label)
  12262.     {
  12263.       DECL_CONTEXT (no_return_label) = fndecl;
  12264.       DECL_INITIAL (no_return_label) = error_mark_node;
  12265.       DECL_SOURCE_FILE (no_return_label) = input_filename;
  12266.       DECL_SOURCE_LINE (no_return_label) = lineno;
  12267.       expand_goto (no_return_label);
  12268.     }
  12269.  
  12270.   if (cleanup_label)
  12271.     {
  12272.       /* remove the binding contour which is used
  12273.      to catch cleanup-generated temporaries.  */
  12274.       expand_end_bindings (0, 0, 0);
  12275.       poplevel (0, 0, 0);
  12276.     }
  12277.  
  12278.   if (cleanup_label)
  12279.     /* Emit label at beginning of cleanup code for parameters.  */
  12280.     emit_label (cleanup_label);
  12281.  
  12282.   /* Get return value into register if that's where it's supposed to be.  */
  12283.   if (original_result_rtx)
  12284.     fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx);
  12285.  
  12286.   /* Finish building code that will trigger warnings if users forget
  12287.      to make their functions return values.  */
  12288.   if (no_return_label || cleanup_label)
  12289.     emit_jump (return_label);
  12290.   if (no_return_label)
  12291.     {
  12292.       /* We don't need to call `expand_*_return' here because we
  12293.      don't need any cleanups here--this path of code is only
  12294.      for error checking purposes.  */
  12295.       expand_label (no_return_label);
  12296.     }
  12297.  
  12298.   /* Generate rtl for function exit.  */
  12299.   expand_function_end (input_filename, lineno, 1);
  12300.  
  12301.   if (flag_handle_exceptions)
  12302.     expand_exception_blocks ();
  12303.  
  12304.   /* This must come after expand_function_end because cleanups might
  12305.      have declarations (from inline functions) that need to go into
  12306.      this function's blocks.  */
  12307.   if (current_binding_level->parm_flag != 1)
  12308.     my_friendly_abort (122);
  12309.   poplevel (1, 0, 1);
  12310.  
  12311.   /* reset scope for C++: if we were in the scope of a class,
  12312.      then when we finish this function, we are not longer so.
  12313.      This cannot be done until we know for sure that no more
  12314.      class members will ever be referenced in this function
  12315.      (i.e., calls to destructors).  */
  12316.   if (current_class_name)
  12317.     {
  12318.       ctype = current_class_type;
  12319.       pop_nested_class (1);
  12320.     }
  12321.   else
  12322.     pop_memoized_context (1);
  12323.  
  12324.   /* Must mark the RESULT_DECL as being in this function.  */
  12325.   DECL_CONTEXT (DECL_RESULT (fndecl)) = DECL_INITIAL (fndecl);
  12326.  
  12327.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  12328.   if (flag_traditional && current_function_calls_setjmp)
  12329.     setjmp_protect (DECL_INITIAL (fndecl));
  12330.  
  12331.   /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
  12332.      to the FUNCTION_DECL node itself.  */
  12333.   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
  12334.  
  12335.   /* So we can tell if jump_optimize sets it to 1.  */
  12336.   can_reach_end = 0;
  12337.  
  12338.   /* Run the optimizers and output the assembler code for this function.  */
  12339.   rest_of_compilation (fndecl);
  12340.  
  12341.   if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl))
  12342.     {
  12343.       /* Set DECL_EXTERNAL so that assemble_external will be called as
  12344.          necessary.  We'll clear it again in finish_file.  */
  12345.       if (! DECL_EXTERNAL (fndecl))
  12346.     DECL_NOT_REALLY_EXTERN (fndecl) = 1;
  12347.       DECL_EXTERNAL (fndecl) = 1;
  12348.       mark_inline_for_output (fndecl);
  12349.     }
  12350.  
  12351.   if (ctype && TREE_ASM_WRITTEN (fndecl))
  12352.     note_debug_info_needed (ctype);
  12353.  
  12354.   current_function_returns_null |= can_reach_end;
  12355.  
  12356.   /* Since we don't normally go through c_expand_return for constructors,
  12357.      this normally gets the wrong value.
  12358.      Also, named return values have their return codes emitted after
  12359.      NOTE_INSN_FUNCTION_END, confusing jump.c.  */
  12360.   if (DECL_CONSTRUCTOR_P (fndecl)
  12361.       || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE)
  12362.     current_function_returns_null = 0;
  12363.  
  12364.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  12365.     cp_warning ("`noreturn' function `%D' does return", fndecl);
  12366.   else if ((warn_return_type || pedantic)
  12367.        && current_function_returns_null
  12368.        && TYPE_MAIN_VARIANT (TREE_TYPE (fntype)) != void_type_node)
  12369.     {
  12370.       /* If this function returns non-void and control can drop through,
  12371.      complain.  */
  12372.       cp_pedwarn ("control reaches end of non-void function `%D'", fndecl);
  12373.     }
  12374.   /* With just -W, complain only if function returns both with
  12375.      and without a value.  */
  12376.   else if (extra_warnings
  12377.        && current_function_returns_value && current_function_returns_null)
  12378.     warning ("this function may return with or without a value");
  12379.  
  12380.   /* Free all the tree nodes making up this function.  */
  12381.   /* Switch back to allocating nodes permanently
  12382.      until we start another function.  */
  12383.   if (! nested)
  12384.     permanent_allocation (1);
  12385.  
  12386.   if (flag_cadillac)
  12387.     cadillac_finish_function (fndecl);
  12388.  
  12389.   if (DECL_SAVED_INSNS (fndecl) == NULL_RTX)
  12390.     {
  12391.       /* Stop pointing to the local nodes about to be freed.  */
  12392.       /* But DECL_INITIAL must remain nonzero so we know this
  12393.      was an actual function definition.  */
  12394.       DECL_INITIAL (fndecl) = error_mark_node;
  12395.       if (! DECL_CONSTRUCTOR_P (fndecl)
  12396.       || !TYPE_USES_VIRTUAL_BASECLASSES (TYPE_METHOD_BASETYPE (fntype)))
  12397.     DECL_ARGUMENTS (fndecl) = NULL_TREE;
  12398.     }
  12399.  
  12400.   if (DECL_STATIC_CONSTRUCTOR (fndecl))
  12401.     static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors);
  12402.   if (DECL_STATIC_DESTRUCTOR (fndecl))
  12403.     static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors);
  12404.  
  12405.   if (! nested)
  12406.     {
  12407.       /* Let the error reporting routines know that we're outside a
  12408.          function.  For a nested function, this value is used in
  12409.          pop_cp_function_context and then reset via pop_function_context.  */
  12410.       current_function_decl = NULL_TREE;
  12411.     }
  12412.  
  12413.   named_label_uses = NULL_TREE;
  12414.   current_class_decl = NULL_TREE;
  12415. }
  12416.  
  12417. /* Create the FUNCTION_DECL for a function definition.
  12418.    LINE1 is the line number that the definition absolutely begins on.
  12419.    LINE2 is the line number that the name of the function appears on.
  12420.    DECLSPECS and DECLARATOR are the parts of the declaration;
  12421.    they describe the return type and the name of the function,
  12422.    but twisted together in a fashion that parallels the syntax of C.
  12423.  
  12424.    This function creates a binding context for the function body
  12425.    as well as setting up the FUNCTION_DECL in current_function_decl.
  12426.  
  12427.    Returns a FUNCTION_DECL on success.
  12428.  
  12429.    If the DECLARATOR is not suitable for a function (it defines a datum
  12430.    instead), we return 0, which tells yyparse to report a parse error.
  12431.  
  12432.    May return void_type_node indicating that this method is actually
  12433.    a friend.  See grokfield for more details.
  12434.  
  12435.    Came here with a `.pushlevel' .
  12436.  
  12437.    DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
  12438.    CHANGES TO CODE IN `grokfield'.  */
  12439. tree
  12440. start_method (declspecs, declarator, raises)
  12441.      tree declarator, declspecs, raises;
  12442. {
  12443.   tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, raises,
  12444.                 NULL_TREE);
  12445.  
  12446.   /* Something too ugly to handle.  */
  12447.   if (fndecl == NULL_TREE)
  12448.     return NULL_TREE;
  12449.  
  12450.   /* Pass friends other than inline friend functions back.  */
  12451.   if (TYPE_MAIN_VARIANT (fndecl) == void_type_node)
  12452.     return fndecl;
  12453.  
  12454.   if (TREE_CODE (fndecl) != FUNCTION_DECL)
  12455.     /* Not a function, tell parser to report parse error.  */
  12456.     return NULL_TREE;
  12457.  
  12458.   if (IS_SIGNATURE (current_class_type))
  12459.     {
  12460.       IS_DEFAULT_IMPLEMENTATION (fndecl) = 1;
  12461.       /* In case we need this info later.  */
  12462.       HAS_DEFAULT_IMPLEMENTATION (current_class_type) = 1;
  12463.     }
  12464.  
  12465.   if (DECL_IN_AGGR_P (fndecl))
  12466.     {
  12467.       if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type)
  12468.     {
  12469.       if (DECL_CONTEXT (fndecl))
  12470.         cp_error ("`%D' is already defined in class %s", fndecl,
  12471.                  TYPE_NAME_STRING (DECL_CONTEXT (fndecl)));
  12472.     }
  12473.       return void_type_node;
  12474.     }
  12475.  
  12476.   DECL_THIS_INLINE (fndecl) = 1;
  12477.  
  12478.   if (flag_default_inline)
  12479.     DECL_INLINE (fndecl) = 1;
  12480.  
  12481.   if (processing_template_defn)
  12482.     {
  12483.       SET_DECL_IMPLICIT_INSTANTIATION (fndecl);
  12484.       repo_template_used (fndecl);
  12485.     }
  12486.  
  12487.   /* We read in the parameters on the maybepermanent_obstack,
  12488.      but we won't be getting back to them until after we
  12489.      may have clobbered them.  So the call to preserve_data
  12490.      will keep them safe.  */
  12491.   preserve_data ();
  12492.  
  12493.   if (! DECL_FRIEND_P (fndecl))
  12494.     {
  12495.       if (DECL_CHAIN (fndecl) != NULL_TREE)
  12496.     {
  12497.       /* Need a fresh node here so that we don't get circularity
  12498.          when we link these together.  If FNDECL was a friend, then
  12499.          `pushdecl' does the right thing, which is nothing wrt its
  12500.          current value of DECL_CHAIN.  */
  12501.       fndecl = copy_node (fndecl);
  12502.     }
  12503.       if (TREE_CHAIN (fndecl))
  12504.     {
  12505.       fndecl = copy_node (fndecl);
  12506.       TREE_CHAIN (fndecl) = NULL_TREE;
  12507.     }
  12508.  
  12509.       if (DECL_CONSTRUCTOR_P (fndecl))
  12510.     {
  12511.       if (! grok_ctor_properties (current_class_type, fndecl))
  12512.         return void_type_node;
  12513.     }
  12514.       else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl)))
  12515.     grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0);
  12516.     }
  12517.  
  12518.   cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0);
  12519.  
  12520.   /* Make a place for the parms */
  12521.   pushlevel (0);
  12522.   current_binding_level->parm_flag = 1;
  12523.   
  12524.   DECL_IN_AGGR_P (fndecl) = 1;
  12525.   return fndecl;
  12526. }
  12527.  
  12528. /* Go through the motions of finishing a function definition.
  12529.    We don't compile this method until after the whole class has
  12530.    been processed.
  12531.  
  12532.    FINISH_METHOD must return something that looks as though it
  12533.    came from GROKFIELD (since we are defining a method, after all).
  12534.  
  12535.    This is called after parsing the body of the function definition.
  12536.    STMTS is the chain of statements that makes up the function body.
  12537.  
  12538.    DECL is the ..._DECL that `start_method' provided.  */
  12539.  
  12540. tree
  12541. finish_method (decl)
  12542.      tree decl;
  12543. {
  12544.   register tree fndecl = decl;
  12545.   tree old_initial;
  12546.  
  12547.   register tree link;
  12548.  
  12549.   if (TYPE_MAIN_VARIANT (decl) == void_type_node)
  12550.     return decl;
  12551.  
  12552.   old_initial = DECL_INITIAL (fndecl);
  12553.  
  12554.   /* Undo the level for the parms (from start_method).
  12555.      This is like poplevel, but it causes nothing to be
  12556.      saved.  Saving information here confuses symbol-table
  12557.      output routines.  Besides, this information will
  12558.      be correctly output when this method is actually
  12559.      compiled.  */
  12560.  
  12561.   /* Clear out the meanings of the local variables of this level;
  12562.      also record in each decl which block it belongs to.  */
  12563.  
  12564.   for (link = current_binding_level->names; link; link = TREE_CHAIN (link))
  12565.     {
  12566.       if (DECL_NAME (link) != NULL_TREE)
  12567.     IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  12568.       my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163);
  12569.       DECL_CONTEXT (link) = NULL_TREE;
  12570.     }
  12571.  
  12572.   /* Restore all name-meanings of the outer levels
  12573.      that were shadowed by this level.  */
  12574.  
  12575.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  12576.       IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12577.   for (link = current_binding_level->class_shadowed;
  12578.        link; link = TREE_CHAIN (link))
  12579.     IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12580.   for (link = current_binding_level->type_shadowed;
  12581.        link; link = TREE_CHAIN (link))
  12582.     IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  12583.  
  12584.   GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level,
  12585.               (HOST_WIDE_INT) current_binding_level->level_chain,
  12586.               current_binding_level->parm_flag,
  12587.               current_binding_level->keep,
  12588.               current_binding_level->tag_transparent);
  12589.  
  12590.   poplevel (0, 0, 0);
  12591.  
  12592.   DECL_INITIAL (fndecl) = old_initial;
  12593.  
  12594.   /* We used to check if the context of FNDECL was different from
  12595.      current_class_type as another way to get inside here.  This didn't work
  12596.      for String.cc in libg++.  */
  12597.   if (DECL_FRIEND_P (fndecl))
  12598.     {
  12599.       CLASSTYPE_INLINE_FRIENDS (current_class_type)
  12600.     = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type));
  12601.       decl = void_type_node;
  12602.     }
  12603.  
  12604.   return decl;
  12605. }
  12606.  
  12607. /* Called when a new struct TYPE is defined.
  12608.    If this structure or union completes the type of any previous
  12609.    variable declaration, lay it out and output its rtl.  */
  12610.  
  12611. void
  12612. hack_incomplete_structures (type)
  12613.      tree type;
  12614. {
  12615.   tree *list;
  12616.  
  12617.   if (current_binding_level->incomplete == NULL_TREE)
  12618.     return;
  12619.  
  12620.   if (!type) /* Don't do this for class templates.  */
  12621.     return;
  12622.  
  12623.   for (list = ¤t_binding_level->incomplete; *list; )
  12624.     {
  12625.       tree decl = TREE_VALUE (*list);
  12626.       if (decl && TREE_TYPE (decl) == type
  12627.       || (TREE_TYPE (decl)
  12628.           && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  12629.           && TREE_TYPE (TREE_TYPE (decl)) == type))
  12630.     {
  12631.       int toplevel = toplevel_bindings_p ();
  12632.       if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  12633.           && TREE_TYPE (TREE_TYPE (decl)) == type)
  12634.         layout_type (TREE_TYPE (decl));
  12635.       layout_decl (decl, 0);
  12636.       rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
  12637.       if (! toplevel)
  12638.         {
  12639.           tree cleanup;
  12640.           expand_decl (decl);
  12641.           cleanup = maybe_build_cleanup (decl);
  12642.           expand_decl_init (decl);
  12643.           if (! cp_expand_decl_cleanup (decl, cleanup))
  12644.         cp_error ("parser lost in parsing declaration of `%D'",
  12645.               decl);
  12646.         }
  12647.       *list = TREE_CHAIN (*list);
  12648.     }
  12649.       else
  12650.     list = &TREE_CHAIN (*list);
  12651.     }
  12652. }
  12653.  
  12654. /* Nonzero if presently building a cleanup.  Needed because
  12655.    SAVE_EXPRs are not the right things to use inside of cleanups.
  12656.    They are only ever evaluated once, where the cleanup
  12657.    might be evaluated several times.  In this case, a later evaluation
  12658.    of the cleanup might fill in the SAVE_EXPR_RTL, and it will
  12659.    not be valid for an earlier cleanup.  */
  12660.  
  12661. int building_cleanup;
  12662.  
  12663. /* If DECL is of a type which needs a cleanup, build that cleanup here.
  12664.    We don't build cleanups if just going for syntax checking, since
  12665.    fixup_cleanups does not know how to not handle them.
  12666.  
  12667.    Don't build these on the momentary obstack; they must live
  12668.    the life of the binding contour.  */
  12669. tree
  12670. maybe_build_cleanup (decl)
  12671.      tree decl;
  12672. {
  12673.   tree type = TREE_TYPE (decl);
  12674.   if (TYPE_NEEDS_DESTRUCTOR (type))
  12675.     {
  12676.       int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR;
  12677.       tree rval;
  12678.       int old_building_cleanup = building_cleanup;
  12679.       building_cleanup = 1;
  12680.  
  12681.       if (TREE_CODE (decl) != PARM_DECL)
  12682.     temp = suspend_momentary ();
  12683.  
  12684.       if (TREE_CODE (type) == ARRAY_TYPE)
  12685.     rval = decl;
  12686.       else
  12687.     {
  12688.       mark_addressable (decl);
  12689.       rval = build_unary_op (ADDR_EXPR, decl, 0);
  12690.     }
  12691.  
  12692.       /* Optimize for space over speed here.  */
  12693.       if (! TYPE_USES_VIRTUAL_BASECLASSES (type)
  12694.       || flag_expensive_optimizations)
  12695.     flags |= LOOKUP_NONVIRTUAL;
  12696.  
  12697.       rval = build_delete (TREE_TYPE (rval), rval, integer_two_node, flags, 0);
  12698.  
  12699.       if (TYPE_USES_VIRTUAL_BASECLASSES (type)
  12700.       && ! TYPE_HAS_DESTRUCTOR (type))
  12701.     rval = build_compound_expr (tree_cons (NULL_TREE, rval,
  12702.                            build_tree_list (NULL_TREE, build_vbase_delete (type, decl))));
  12703.  
  12704.       if (TREE_CODE (decl) != PARM_DECL)
  12705.     resume_momentary (temp);
  12706.  
  12707.       building_cleanup = old_building_cleanup;
  12708.  
  12709.       return rval;
  12710.     }
  12711.   return 0;
  12712. }
  12713.  
  12714. /* Expand a C++ expression at the statement level.
  12715.    This is needed to ferret out nodes which have UNKNOWN_TYPE.
  12716.    The C++ type checker should get all of these out when
  12717.    expressions are combined with other, type-providing, expressions,
  12718.    leaving only orphan expressions, such as:
  12719.  
  12720.    &class::bar;        / / takes its address, but does nothing with it.
  12721.  
  12722.    */
  12723. void
  12724. cplus_expand_expr_stmt (exp)
  12725.      tree exp;
  12726. {
  12727.   if (TREE_TYPE (exp) == unknown_type_node)
  12728.     {
  12729.       if (TREE_CODE (exp) == ADDR_EXPR || TREE_CODE (exp) == TREE_LIST)
  12730.     error ("address of overloaded function with no contextual type information");
  12731.       else if (TREE_CODE (exp) == COMPONENT_REF)
  12732.     warning ("useless reference to a member function name, did you forget the ()?");
  12733.     }
  12734.   else
  12735.     {
  12736.       int remove_implicit_immediately = 0;
  12737.  
  12738.       if (TREE_CODE (exp) == FUNCTION_DECL)
  12739.     {
  12740.       cp_warning ("reference, not call, to function `%D'", exp);
  12741.       warning ("at this point in file");
  12742.     }
  12743.  
  12744. #if 0
  12745.       /* We should do this eventually, but right now this causes regex.o from
  12746.      libg++ to miscompile, and tString to core dump.  */
  12747.       exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp);
  12748. #endif
  12749.       expand_expr_stmt (break_out_cleanups (exp));
  12750.     }
  12751.  
  12752.   /* Clean up any pending cleanups.  This happens when a function call
  12753.      returns a cleanup-needing value that nobody uses.  */
  12754.   expand_cleanups_to (NULL_TREE);
  12755. }
  12756.  
  12757. /* When a stmt has been parsed, this function is called.
  12758.  
  12759.    Currently, this function only does something within a
  12760.    constructor's scope: if a stmt has just assigned to this,
  12761.    and we are in a derived class, we call `emit_base_init'.  */
  12762.  
  12763. void
  12764. finish_stmt ()
  12765. {
  12766.   extern struct nesting *cond_stack, *loop_stack, *case_stack;
  12767.  
  12768.   
  12769.   if (current_function_assigns_this
  12770.       || ! current_function_just_assigned_this)
  12771.     return;
  12772.   if (DECL_CONSTRUCTOR_P (current_function_decl))
  12773.     {
  12774.       /* Constructors must wait until we are out of control
  12775.      zones before calling base constructors.  */
  12776.       if (cond_stack || loop_stack || case_stack)
  12777.     return;
  12778.       expand_expr_stmt (base_init_expr);
  12779.       check_base_init (current_class_type);
  12780.     }
  12781.   current_function_assigns_this = 1;
  12782.  
  12783.   if (flag_cadillac)
  12784.     cadillac_finish_stmt ();
  12785. }
  12786.  
  12787. /* Change a static member function definition into a FUNCTION_TYPE, instead
  12788.    of the METHOD_TYPE that we create when it's originally parsed.
  12789.  
  12790.    WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES
  12791.    (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of
  12792.    other decls.  Either pass the addresses of local variables or NULL.  */
  12793.  
  12794. void
  12795. revert_static_member_fn (decl, fn, argtypes)
  12796.      tree *decl, *fn, *argtypes;
  12797. {
  12798.   tree tmp;
  12799.   tree function = fn ? *fn : TREE_TYPE (*decl);
  12800.   tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function);
  12801.  
  12802.   if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (args))))
  12803.     cp_error ("static member function `%#D' declared const", *decl);
  12804.   if (TYPE_VOLATILE (TREE_TYPE (TREE_VALUE (args))))
  12805.     cp_error ("static member function `%#D' declared volatile", *decl);
  12806.  
  12807.   args = TREE_CHAIN (args);
  12808.   tmp = build_function_type (TREE_TYPE (function), args);
  12809.   tmp = build_type_variant (tmp, TYPE_READONLY (function),
  12810.                 TYPE_VOLATILE (function));
  12811.   tmp = build_exception_variant (tmp,
  12812.                  TYPE_RAISES_EXCEPTIONS (function));
  12813.   TREE_TYPE (*decl) = tmp;
  12814.   if (DECL_ARGUMENTS (*decl))
  12815.     DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl));
  12816.   DECL_STATIC_FUNCTION_P (*decl) = 1;
  12817.   if (fn)
  12818.     *fn = tmp;
  12819.   if (argtypes)
  12820.     *argtypes = args;
  12821. }
  12822.  
  12823. int
  12824. id_in_current_class (id)
  12825.      tree id;
  12826. {
  12827.   return !!purpose_member (id, class_binding_level->class_shadowed);
  12828. }
  12829.  
  12830. struct cp_function
  12831. {
  12832.   int returns_value;
  12833.   int returns_null;
  12834.   int warn_about_return_type;
  12835.   int assigns_this;
  12836.   int just_assigned_this;
  12837.   int parms_stored;
  12838.   int temp_name_counter;
  12839.   tree named_labels;
  12840.   tree shadowed_labels;
  12841.   tree ctor_label;
  12842.   tree dtor_label;
  12843.   tree protect_list;
  12844.   tree base_init_list;
  12845.   tree member_init_list;
  12846.   tree base_init_expr;
  12847.   tree class_decl;
  12848.   tree C_C_D;
  12849.   rtx result_rtx;
  12850.   struct cp_function *next;
  12851.   struct binding_level *binding_level;
  12852. };
  12853.  
  12854. struct cp_function *cp_function_chain;
  12855.  
  12856. extern int temp_name_counter;
  12857.  
  12858. /* Save and reinitialize the variables
  12859.    used during compilation of a C++ function.  */
  12860.  
  12861. void
  12862. push_cp_function_context (context)
  12863.      tree context;
  12864. {
  12865.   struct cp_function *p
  12866.     = (struct cp_function *) xmalloc (sizeof (struct cp_function));
  12867.  
  12868.   push_function_context_to (context);
  12869.  
  12870.   p->next = cp_function_chain;
  12871.   cp_function_chain = p;
  12872.  
  12873.   p->named_labels = named_labels;
  12874.   p->shadowed_labels = shadowed_labels;
  12875.   p->returns_value = current_function_returns_value;
  12876.   p->returns_null = current_function_returns_null;
  12877.   p->warn_about_return_type = warn_about_return_type;
  12878.   p->binding_level = current_binding_level;
  12879.   p->ctor_label = ctor_label;
  12880.   p->dtor_label = dtor_label;
  12881.   p->assigns_this = current_function_assigns_this;
  12882.   p->just_assigned_this = current_function_just_assigned_this;
  12883.   p->parms_stored = current_function_parms_stored;
  12884.   p->result_rtx = original_result_rtx;
  12885.   p->base_init_expr = base_init_expr;
  12886.   p->protect_list = protect_list;
  12887.   p->temp_name_counter = temp_name_counter;
  12888.   p->base_init_list = current_base_init_list;
  12889.   p->member_init_list = current_member_init_list;
  12890.   p->class_decl = current_class_decl;
  12891.   p->C_C_D = C_C_D;
  12892. }
  12893.  
  12894. /* Restore the variables used during compilation of a C++ function.  */
  12895.  
  12896. void
  12897. pop_cp_function_context (context)
  12898.      tree context;
  12899. {
  12900.   struct cp_function *p = cp_function_chain;
  12901.   tree link;
  12902.  
  12903.   /* Bring back all the labels that were shadowed.  */
  12904.   for (link = shadowed_labels; link; link = TREE_CHAIN (link))
  12905.     if (DECL_NAME (TREE_VALUE (link)) != 0)
  12906.       SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)),
  12907.                   TREE_VALUE (link));
  12908.  
  12909. #if 0
  12910.   if (DECL_SAVED_INSNS (current_function_decl) == 0)
  12911.     {
  12912.       /* Stop pointing to the local nodes about to be freed.  */
  12913.       /* But DECL_INITIAL must remain nonzero so we know this
  12914.      was an actual function definition.  */
  12915.       DECL_INITIAL (current_function_decl) = error_mark_node;
  12916.       DECL_ARGUMENTS (current_function_decl) = 0;
  12917.     }
  12918. #endif
  12919.  
  12920.   pop_function_context_from (context);
  12921.  
  12922.   cp_function_chain = p->next;
  12923.  
  12924.   named_labels = p->named_labels;
  12925.   shadowed_labels = p->shadowed_labels;
  12926.   current_function_returns_value = p->returns_value;
  12927.   current_function_returns_null = p->returns_null;
  12928.   warn_about_return_type = p->warn_about_return_type;
  12929.   current_binding_level = p->binding_level;
  12930.   ctor_label = p->ctor_label;
  12931.   dtor_label = p->dtor_label;
  12932.   protect_list = p->protect_list;
  12933.   current_function_assigns_this = p->assigns_this;
  12934.   current_function_just_assigned_this = p->just_assigned_this;
  12935.   current_function_parms_stored = p->parms_stored;
  12936.   original_result_rtx = p->result_rtx;
  12937.   base_init_expr = p->base_init_expr;
  12938.   temp_name_counter = p->temp_name_counter;
  12939.   current_base_init_list = p->base_init_list;
  12940.   current_member_init_list = p->member_init_list;
  12941.   current_class_decl = p->class_decl;
  12942.   C_C_D = p->C_C_D;
  12943.  
  12944.   free (p);
  12945. }
  12946.  
  12947. /* FSF LOCAL dje prefix attributes */
  12948. /* Split SPECS_ATTRS, a list of declspecs and prefix attributes, into two
  12949.    lists.  SPECS_ATTRS may also be just a typespec (eg: RECORD_TYPE).
  12950.  
  12951.    The head of the declspec list is stored in DECLSPECS.
  12952.    The head of the attribute list is stored in PREFIX_ATTRIBUTES.
  12953.  
  12954.    Note that attributes in SPECS_ATTRS are stored in the TREE_PURPOSE of
  12955.    the list elements.  We drop the containing TREE_LIST nodes and link the
  12956.    resulting attributes together the way decl_attributes expects them.  */
  12957.  
  12958. void
  12959. split_specs_attrs (specs_attrs, declspecs, prefix_attributes)
  12960.      tree specs_attrs;
  12961.      tree *declspecs, *prefix_attributes;
  12962. {
  12963.   tree t, s, a, next, specs, attrs;
  12964.  
  12965.   /* This can happen in c++ (eg: decl: typespec initdecls ';').  */
  12966.   if (specs_attrs != NULL_TREE
  12967.       && TREE_CODE (specs_attrs) != TREE_LIST)
  12968.     {
  12969.       *declspecs = specs_attrs;
  12970.       *prefix_attributes = NULL_TREE;
  12971.       return;
  12972.     }
  12973.  
  12974.   /* Remember to keep the lists in the same order, element-wise.  */
  12975.  
  12976.   specs = s = NULL_TREE;
  12977.   attrs = a = NULL_TREE;
  12978.   for (t = specs_attrs; t; t = next)
  12979.     {
  12980.       next = TREE_CHAIN (t);
  12981.       /* Declspecs have a non-NULL TREE_VALUE.  */
  12982.       if (TREE_VALUE (t) != NULL_TREE)
  12983.     {
  12984.       if (specs == NULL_TREE)
  12985.         specs = s = t;
  12986.       else
  12987.         {
  12988.           TREE_CHAIN (s) = t;
  12989.           s = t;
  12990.         }
  12991.     }
  12992.       else
  12993.     {
  12994.       if (attrs == NULL_TREE)
  12995.         attrs = a = TREE_PURPOSE (t);
  12996.       else
  12997.         {
  12998.           TREE_CHAIN (a) = TREE_PURPOSE (t);
  12999.           a = TREE_PURPOSE (t);
  13000.         }
  13001.     }
  13002.     }
  13003.  
  13004.   /* Terminate the lists.  */
  13005.   if (s != NULL_TREE)
  13006.     TREE_CHAIN (s) = NULL_TREE;
  13007.   if (a != NULL_TREE)
  13008.     TREE_CHAIN (a) = NULL_TREE;
  13009.  
  13010.   /* All done.  */
  13011.   *declspecs = specs;
  13012.   *prefix_attributes = attrs;
  13013. }
  13014.  
  13015. /* Strip attributes from SPECS_ATTRS, a list of declspecs and attributes.
  13016.    This function is used by the parser when a rule will accept attributes
  13017.    in a particular position, but we don't want to support that just yet.
  13018.  
  13019.    A warning is issued for every ignored attribute.  */
  13020.  
  13021. tree
  13022. strip_attrs (specs_attrs)
  13023.      tree specs_attrs;
  13024. {
  13025.   tree specs, attrs;
  13026.  
  13027.   split_specs_attrs (specs_attrs, &specs, &attrs);
  13028.  
  13029.   while (attrs)
  13030.     {
  13031.       warning ("`%s' attribute ignored",
  13032.            IDENTIFIER_POINTER (TREE_PURPOSE (attrs)));
  13033.       attrs = TREE_CHAIN (attrs);
  13034.     }
  13035.  
  13036.   return specs;
  13037. }
  13038. /* END FSF LOCAL */
  13039.  
  13040.  
  13041. #ifdef OBJCPLUS
  13042. #define builtin_function(NAME, TYPE, CODE, LIBNAME) \
  13043.   define_function (NAME, TYPE, CODE, (void (*)())pushdecl, LIBNAME)
  13044. #endif
  13045.  
  13046. int
  13047. call_destructor_dynamically (dfndecl)
  13048.      tree dfndecl;
  13049. {
  13050.   tree parms;
  13051.   tree call;
  13052.   tree atexit_decl;
  13053.   tree atexit_type;
  13054.   tree fnct_type = build_pointer_type (default_function_type);
  13055.  
  13056.   extern tree default_function_type;
  13057.   extern tree void_type_node;
  13058.  
  13059.   atexit_type = build_function_type (void_type_node, 
  13060.                      tree_cons (0, fnct_type, 0));
  13061.   atexit_decl =(tree) builtin_function ("atexit", 
  13062.                     atexit_type,
  13063.                     NOT_BUILT_IN, 0);
  13064.   parms = (tree) build_tree_list (NULL_TREE, 
  13065.                 build1 (ADDR_EXPR, 
  13066.                     fnct_type,
  13067.                     dfndecl));
  13068.   
  13069.   call = build_function_call (atexit_decl, parms);
  13070.   expand_call (call, 0, 0);
  13071. }
  13072.