home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-C / c-decl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-01  |  201.7 KB  |  6,429 lines  |  [TEXT/MPS ]

  1. /* Process declarations and variables for C compiler.
  2.    Copyright (C) 1988, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Process declarations and symbol lookup for C front end.
  22.    Also constructs types; the standard scalar types at initialization,
  23.    and structure, union, array and enum types when they are declared.  */
  24.  
  25. /* ??? not all decl nodes are given the most useful possible
  26.    line numbers.  For example, the CONST_DECLs for enum values.  */
  27.  
  28. #include "config.h"
  29. #include "tree.h"
  30. #include "flags.h"
  31. #include "c-tree.h"
  32. #include "c-lex.h"
  33. #include <stdio.h>
  34.  
  35. extern int parameter_pragma_supplied;
  36. extern char current_name_in_pragma[];
  37. extern struct call_convention current_call_convention;
  38.  
  39. /* In grokdeclarator, distinguish syntactic contexts of declarators.  */
  40. enum decl_context
  41. { NORMAL,            /* Ordinary declaration */
  42.   FUNCDEF,            /* Function definition */
  43.   PARM,                /* Declaration of parm before function body */
  44.   FIELD,            /* Declaration inside struct or union */
  45.   BITFIELD,            /* Likewise but with specified width */
  46.   TYPENAME
  47. #ifdef MPW_C
  48. , DC_intifier = 1000000
  49. #endif /* MPW_C */
  50. };            /* Typename (inside cast or sizeof)  */
  51.  
  52. #ifndef CHAR_TYPE_SIZE
  53. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  54. #endif
  55.  
  56. #ifndef SHORT_TYPE_SIZE
  57. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  58. #endif
  59.  
  60. #ifndef INT_TYPE_SIZE
  61. #define INT_TYPE_SIZE BITS_PER_WORD
  62. #endif
  63.  
  64. #ifndef LONG_TYPE_SIZE
  65. #define LONG_TYPE_SIZE BITS_PER_WORD
  66. #endif
  67.  
  68. #ifndef LONG_LONG_TYPE_SIZE
  69. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  70. #endif
  71.  
  72. #ifndef WCHAR_UNSIGNED
  73. #define WCHAR_UNSIGNED 0
  74. #endif
  75.  
  76. #ifndef FLOAT_TYPE_SIZE
  77. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  78. #endif
  79.  
  80. #ifndef DOUBLE_TYPE_SIZE
  81. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  82. #endif
  83.  
  84. #ifndef LONG_DOUBLE_TYPE_SIZE
  85. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  86. #endif
  87.  
  88. /* We let tm.h override the types used here, to handle trivial differences
  89.    such as the choice of unsigned int or long unsigned int for size_t.
  90.    When machines start needing nontrivial differences in the size type,
  91.    it would be best to do something here to figure out automatically
  92.    from other information what type to use.  */
  93.  
  94. #ifndef SIZE_TYPE
  95. #define SIZE_TYPE "long unsigned int"
  96. #endif
  97.  
  98. #ifndef PTRDIFF_TYPE
  99. #define PTRDIFF_TYPE "long int"
  100. #endif
  101.  
  102. #ifndef WCHAR_TYPE
  103. #define WCHAR_TYPE "int"
  104. #endif
  105.  
  106. /* a node which has tree code ERROR_MARK, and whose type is itself.
  107.    All erroneous expressions are replaced with this node.  All functions
  108.    that accept nodes as arguments should avoid generating error messages
  109.    if this node is one of the arguments, since it is undesirable to get
  110.    multiple error messages from one error in the input.  */
  111.  
  112. tree error_mark_node;
  113.  
  114. /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */
  115.  
  116. tree short_integer_type_node;
  117. tree integer_type_node;
  118. tree long_integer_type_node;
  119. tree long_long_integer_type_node;
  120.  
  121. tree short_unsigned_type_node;
  122. tree unsigned_type_node;
  123. tree long_unsigned_type_node;
  124. tree long_long_unsigned_type_node;
  125.  
  126. tree ptrdiff_type_node;
  127.  
  128. tree unsigned_char_type_node;
  129. tree signed_char_type_node;
  130. tree char_type_node;
  131. tree wchar_type_node;
  132. tree signed_wchar_type_node;
  133. tree unsigned_wchar_type_node;
  134.  
  135. tree float_type_node;
  136. tree double_type_node;
  137. tree long_double_type_node;
  138.  
  139. tree intQI_type_node;
  140. tree intHI_type_node;
  141. tree intSI_type_node;
  142. tree intDI_type_node;
  143.  
  144. tree unsigned_intQI_type_node;
  145. tree unsigned_intHI_type_node;
  146. tree unsigned_intSI_type_node;
  147. tree unsigned_intDI_type_node;
  148.  
  149. /* a VOID_TYPE node.  */
  150.  
  151. tree void_type_node;
  152.  
  153. /* Nodes for types `void *' and `const void *'.  */
  154.  
  155. tree ptr_type_node, const_ptr_type_node;
  156.  
  157. /* Nodes for types `char *' and `const char *'.  */
  158.  
  159. tree string_type_node, const_string_type_node;
  160.  
  161. /* Type `char[256]' or something like it.
  162.    Used when an array of char is needed and the size is irrelevant.  */
  163.  
  164. tree char_array_type_node;
  165.  
  166. /* Type `int[256]' or something like it.
  167.    Used when an array of int needed and the size is irrelevant.  */
  168.  
  169. tree int_array_type_node;
  170.  
  171. /* Type `wchar_t[256]' or something like it.
  172.    Used when a wide string literal is created.  */
  173.  
  174. tree wchar_array_type_node;
  175.  
  176. /* type `int ()' -- used for implicit declaration of functions.  */
  177.  
  178. tree default_function_type;
  179.  
  180. /* function types `double (double)' and `double (double, double)', etc.  */
  181.  
  182. tree double_ftype_double, double_ftype_double_double;
  183. tree int_ftype_int, long_ftype_long;
  184.  
  185. /* Function type `extended (extended)'. */
  186.  
  187. tree extended_ftype_extended;
  188.  
  189. /* Function type `void (void *, void *, int)' and similar ones */
  190.  
  191. tree void_ftype_ptr_ptr_int, int_ftype_ptr_ptr_int, void_ftype_ptr_int_int;
  192.  
  193. /* Function type `char *(char *, char *)' and similar ones */
  194. tree string_ftype_ptr_ptr, int_ftype_string_string;
  195.  
  196. /* Function type `int (const void *, const void *, size_t)' */
  197. tree int_ftype_cptr_cptr_sizet;
  198.  
  199. /* Two expressions that are constants with value zero.
  200.    The first is of type `int', the second of type `void *'.  */
  201.  
  202. tree integer_zero_node;
  203. #ifdef PTR_HACK
  204. tree null_DPpointer_node;
  205. tree null_TPpointer_node;
  206. #else
  207. tree null_pointer_node;
  208. #endif
  209.  
  210. /* A node for the integer constant 1.  */
  211.  
  212. tree integer_one_node;
  213.  
  214. /* Nonzero if we have seen an invalid cross reference
  215.    to a struct, union, or enum, but not yet printed the message.  */
  216.  
  217. tree pending_invalid_xref;
  218. /* File and line to appear in the eventual error message.  */
  219. char *pending_invalid_xref_file;
  220. int pending_invalid_xref_line;
  221.  
  222. /* While defining an enum type, this is 1 plus the last enumerator
  223.    constant value.  */
  224.  
  225. static tree enum_next_value;
  226.  
  227. /* Nonzero means that there was overflow computing enum_next_value.  */
  228.  
  229. static int enum_overflow;
  230.  
  231. /* Parsing a function declarator leaves a list of parameter names
  232.    or a chain or parameter decls here.  */
  233.  
  234. static tree last_function_parms;
  235.  
  236. /* Parsing a function declarator leaves here a chain of structure
  237.    and enum types declared in the parmlist.  */
  238.  
  239. static tree last_function_parm_tags;
  240.  
  241. /* After parsing the declarator that starts a function definition,
  242.    `start_function' puts here the list of parameter names or chain of decls.
  243.    `store_parm_decls' finds it here.  */
  244.  
  245. static tree current_function_parms;
  246.  
  247. /* Similar, for last_function_parm_tags.  */
  248. static tree current_function_parm_tags;
  249.  
  250. /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function
  251.    that have names.  Here so we can clear out their names' definitions
  252.    at the end of the function.  */
  253.  
  254. static tree named_labels;
  255.  
  256. /* A list of LABEL_DECLs from outer contexts that are currently shadowed.  */
  257.  
  258. static tree shadowed_labels;
  259.  
  260. /* Nonzero when store_parm_decls is called indicates a varargs function.
  261.    Value not meaningful after store_parm_decls.  */
  262.  
  263. static int c_function_varargs;
  264.  
  265. /* The FUNCTION_DECL for the function currently being compiled,
  266.    or 0 if between functions.  */
  267. tree current_function_decl;
  268.  
  269. /* Set to 0 at beginning of a function definition, set to 1 if
  270.    a return statement that specifies a return value is seen.  */
  271.  
  272. int current_function_returns_value;
  273.  
  274. /* Set to 0 at beginning of a function definition, set to 1 if
  275.    a return statement with no argument is seen.  */
  276.  
  277. int current_function_returns_null;
  278.  
  279. /* Set to nonzero by `grokdeclarator' for a function
  280.    whose return type is defaulted, if warnings for this are desired.  */
  281.  
  282. static int warn_about_return_type;
  283.  
  284. /* Nonzero when starting a function declared `extern inline'.  */
  285.  
  286. static int current_extern_inline;
  287.  
  288. /* For each binding contour we allocate a binding_level structure
  289.  * which records the names defined in that contour.
  290.  * Contours include:
  291.  *  0) the global one
  292.  *  1) one for each function definition,
  293.  *     where internal declarations of the parameters appear.
  294.  *  2) one for each compound statement,
  295.  *     to record its declarations.
  296.  *
  297.  * The current meaning of a name can be found by searching the levels from
  298.  * the current one out to the global one.
  299.  */
  300.  
  301. /* Note that the information in the `names' component of the global contour
  302.    is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers.  */
  303.  
  304. struct binding_level
  305.   {
  306.     /* A chain of _DECL nodes for all variables, constants, functions,
  307.        and typedef types.  These are in the reverse of the order supplied.
  308.      */
  309.     tree names;
  310.  
  311.     /* A list of structure, union and enum definitions,
  312.      * for looking up tag names.
  313.      * It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name,
  314.      * or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE,
  315.      * or ENUMERAL_TYPE node.
  316.      */
  317.     tree tags;
  318.  
  319.     /* For each level, a list of shadowed outer-level local definitions
  320.        to be restored when this level is popped.
  321.        Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
  322.        whose TREE_VALUE is its old definition (a kind of ..._DECL node).  */
  323.     tree shadowed;
  324.  
  325.     /* For each level (except not the global one),
  326.        a chain of BLOCK nodes for all the levels
  327.        that were entered and exited one level down.  */
  328.     tree blocks;
  329.  
  330.     /* The BLOCK node for this level, if one has been preallocated.
  331.        If 0, the BLOCK is allocated (if needed) when the level is popped.  */
  332.     tree this_block;
  333.  
  334.     /* The binding level which this one is contained in (inherits from).  */
  335.     struct binding_level *level_chain;
  336.  
  337.     /* Nonzero for the level that holds the parameters of a function.  */
  338.     /* 2 for a definition, 1 for a declaration.  */
  339.     char parm_flag;
  340.  
  341.     /* Nonzero if this level "doesn't exist" for tags.  */
  342.     char tag_transparent;
  343.  
  344.     /* Nonzero if sublevels of this level "don't exist" for tags.
  345.        This is set in the parm level of a function definition
  346.        while reading the function body, so that the outermost block
  347.        of the function body will be tag-transparent.  */
  348.     char subblocks_tag_transparent;
  349.  
  350.     /* Nonzero means make a BLOCK for this level regardless of all else.  */
  351.     char keep;
  352.  
  353.     /* Nonzero means make a BLOCK if this level has any subblocks.  */
  354.     char keep_if_subblocks;
  355.  
  356.     /* Number of decls in `names' that have incomplete 
  357.        structure or union types.  */
  358.     int n_incomplete;
  359.  
  360.     /* A list of decls giving the (reversed) specified order of parms,
  361.        not including any forward-decls in the parmlist.
  362.        This is so we can put the parms in proper order for assign_parms.  */
  363.     tree parm_order;
  364.   };
  365.  
  366. #define NULL_BINDING_LEVEL (struct binding_level *) NULL
  367.   
  368. /* The binding level currently in effect.  */
  369.  
  370. static struct binding_level *current_binding_level;
  371.  
  372. /* A chain of binding_level structures awaiting reuse.  */
  373.  
  374. static struct binding_level *free_binding_level;
  375.  
  376. /* The outermost binding level, for names of file scope.
  377.    This is created when the compiler is started and exists
  378.    through the entire run.  */
  379.  
  380. static struct binding_level *global_binding_level;
  381.  
  382. /* Binding level structures are initialized by copying this one.  */
  383.  
  384. static struct binding_level clear_binding_level
  385.   = {NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0};
  386.  
  387. /* Nonzero means unconditionally make a BLOCK for the next level pushed.  */
  388.  
  389. static int keep_next_level_flag;
  390.  
  391. /* Nonzero means make a BLOCK for the next level pushed
  392.    if it has subblocks.  */
  393.  
  394. static int keep_next_if_subblocks;
  395.   
  396. /* The chain of outer levels of label scopes.
  397.    This uses the same data structure used for binding levels,
  398.    but it works differently: each link in the chain records
  399.    saved values of named_labels and shadowed_labels for
  400.    a label binding level outside the current one.  */
  401.  
  402. static struct binding_level *label_level_chain;
  403.  
  404. /* Forward declarations.  */
  405.  
  406. static tree grokparms (), grokdeclarator ();
  407. tree pushdecl ();
  408. tree builtin_function ();
  409. void shadow_tag_warned ();
  410.  
  411. static tree lookup_tag ();
  412. static tree lookup_tag_reverse ();
  413. static tree lookup_name_current_level ();
  414. static char *redeclaration_error_message ();
  415. static void layout_array_type ();
  416.  
  417. /* C-specific option variables.  */
  418.  
  419. /* Nonzero means allow type mismatches in conditional expressions;
  420.    just make their values `void'.   */
  421.  
  422. int flag_cond_mismatch;
  423.  
  424. /* Nonzero means give `double' the same size as `float'.  */
  425.  
  426. int flag_short_double;
  427.  
  428. /* Nonzero means don't recognize the keyword `asm'.  */
  429.  
  430. int flag_no_asm;
  431.  
  432. /* Nonzero means don't recognize any builtin functions.  */
  433.  
  434. int flag_no_builtin;
  435.  
  436. /* Nonzero means don't recognize the non-ANSI builtin functions.
  437.    -ansi sets this.  */
  438.  
  439. int flag_no_nonansi_builtin;
  440.  
  441. /* Nonzero means do some things the same way PCC does.  */
  442.  
  443. int flag_traditional;
  444.  
  445. /* Nonzero means to treat bitfields as signed unless they say `unsigned'.  */
  446.  
  447. int flag_signed_bitfields = 1;
  448. int explicit_flag_signed_bitfields = 0;
  449.  
  450. /* Nonzero means handle `#ident' directives.  0 means ignore them.  */
  451.  
  452. int flag_no_ident = 0;
  453.  
  454. /* Nonzero means warn about implicit declarations.  */
  455.  
  456. int warn_implicit;
  457.  
  458. /* Nonzero means give string constants the type `const char *'
  459.    to get extra warnings from them.  These warnings will be too numerous
  460.    to be useful, except in thoroughly ANSIfied programs.  */
  461.  
  462. int warn_write_strings;
  463.  
  464. /* Nonzero means warn about pointer casts that can drop a type qualifier
  465.    from the pointer target type.  */
  466.  
  467. int warn_cast_qual;
  468.  
  469. /* Warn about traditional constructs whose meanings changed in ANSI C.  */
  470.  
  471. int warn_traditional;
  472.  
  473. /* Nonzero means warn about sizeof(function) or addition/subtraction
  474.    of function pointers.  */
  475.  
  476. int warn_pointer_arith;
  477.  
  478. /* Nonzero means warn for non-prototype function decls
  479.    or non-prototyped defs without previous prototype.  */
  480.  
  481. int warn_strict_prototypes;
  482.  
  483. /* Nonzero means warn for any global function def
  484.    without separate previous prototype decl.  */
  485.  
  486. int warn_missing_prototypes;
  487.  
  488. /* Nonzero means warn about multiple (redundant) decls for the same single
  489.    variable or function.  */
  490.  
  491. int warn_redundant_decls = 0;
  492.  
  493. /* Nonzero means warn about extern declarations of objects not at
  494.    file-scope level and about *all* declarations of functions (whether
  495.    extern or static) not at file-scope level.  Note that we exclude
  496.    implicit function declarations.  To get warnings about those, use
  497.    -Wimplicit.  */
  498.  
  499. int warn_nested_externs = 0;
  500.  
  501. /* Warn about *printf or *scanf format/argument anomalies. */
  502.  
  503. int warn_format;
  504.  
  505. /* Warn about a subscript that has type char.  */
  506.  
  507. int warn_char_subscripts = 0;
  508.  
  509. /* Warn if a type conversion is done that might have confusing results.  */
  510.  
  511. int warn_conversion;
  512.  
  513. /* Warn if adding () is suggested.  */
  514.  
  515. int warn_parentheses;
  516.  
  517. /* Nonzero means `$' can be in an identifier.
  518.    See cccp.c for reasons why this breaks some obscure ANSI C programs.  */
  519.  
  520. #ifndef DOLLARS_IN_IDENTIFIERS
  521. #define DOLLARS_IN_IDENTIFIERS 1
  522. #endif
  523. int dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1;
  524.  
  525. char *language_string = "GNU C";
  526.  
  527. /* Decode the string P as a language-specific option for C.
  528.    Return 1 if it is recognized (and handle it);
  529.    return 0 if not recognized.  */
  530.    
  531. int
  532. c_decode_option (p)
  533.      char *p;
  534. {
  535.   if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
  536.     {
  537.       flag_traditional = 1;
  538.       flag_writable_strings = 1;
  539. #if DOLLARS_IN_IDENTIFIERS > 0
  540.       dollars_in_ident = 1;
  541. #endif
  542.     }
  543.   else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional"))
  544.     {
  545.       flag_traditional = 0;
  546.       flag_writable_strings = 0;
  547.       dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1;
  548.     }
  549.   /* Recognize the -apple and -no-apple options, which control whether any of
  550.      the Apple extensions to C are recognized. */
  551.   else if (!strcmp (p, "-fapple") || !strcmp (p, "-apple" ))
  552.     flag_apple = 1;
  553.   else if (!strcmp (p, "-fnoapple") || !strcmp (p, "-fno-apple"))
  554.     flag_apple = 0;
  555.   else if (!strcmp (p, "-fsigned-char"))
  556.     flag_signed_char = 1;
  557.   else if (!strcmp (p, "-funsigned-char"))
  558.     flag_signed_char = 0;
  559.   else if (!strcmp (p, "-fno-signed-char"))
  560.     flag_signed_char = 0;
  561.   else if (!strcmp (p, "-fno-unsigned-char"))
  562.     flag_signed_char = 1;
  563.   else if (!strcmp (p, "-fsigned-bitfields")
  564.        || !strcmp (p, "-fno-unsigned-bitfields"))
  565.     {
  566.       flag_signed_bitfields = 1;
  567.       explicit_flag_signed_bitfields = 1;
  568.     }
  569.   else if (!strcmp (p, "-funsigned-bitfields")
  570.        || !strcmp (p, "-fno-signed-bitfields"))
  571.     {
  572.       flag_signed_bitfields = 0;
  573.       explicit_flag_signed_bitfields = 1;
  574.     }
  575.   else if (!strcmp (p, "-fshort-enums"))
  576.     flag_short_enums = 1;
  577.   else if (!strcmp (p, "-fno-short-enums"))
  578.     flag_short_enums = 0;
  579.   else if (!strcmp (p, "-fcond-mismatch"))
  580.     flag_cond_mismatch = 1;
  581.   else if (!strcmp (p, "-fno-cond-mismatch"))
  582.     flag_cond_mismatch = 0;
  583.   else if (!strcmp (p, "-fshort-double"))
  584.     flag_short_double = 1;
  585.   else if (!strcmp (p, "-fno-short-double"))
  586.     flag_short_double = 0;
  587.   else if (!strcmp (p, "-fasm"))
  588.     flag_no_asm = 0;
  589.   else if (!strcmp (p, "-fno-asm"))
  590.     flag_no_asm = 1;
  591.   else if (!strcmp (p, "-fbuiltin"))
  592.     flag_no_builtin = 0;
  593.   else if (!strcmp (p, "-fno-builtin"))
  594.     flag_no_builtin = 1;
  595.   else if (!strcmp (p, "-fno-ident"))
  596.     flag_no_ident = 1;
  597.   else if (!strcmp (p, "-fident"))
  598.     flag_no_ident = 0;
  599.   else if (!strcmp (p, "-ansi"))
  600.     flag_no_asm = 1, flag_no_nonansi_builtin = 1, dollars_in_ident = 0;
  601.   else if (!strcmp (p, "-Wimplicit"))
  602.     warn_implicit = 1;
  603.   else if (!strcmp (p, "-Wno-implicit"))
  604.     warn_implicit = 0;
  605.   else if (!strcmp (p, "-Wwrite-strings"))
  606.     warn_write_strings = 1;
  607.   else if (!strcmp (p, "-Wno-write-strings"))
  608.     warn_write_strings = 0;
  609.   else if (!strcmp (p, "-Wcast-qual"))
  610.     warn_cast_qual = 1;
  611.   else if (!strcmp (p, "-Wno-cast-qual"))
  612.     warn_cast_qual = 0;
  613.   else if (!strcmp (p, "-Wpointer-arith"))
  614.     warn_pointer_arith = 1;
  615.   else if (!strcmp (p, "-Wno-pointer-arith"))
  616.     warn_pointer_arith = 0;
  617.   else if (!strcmp (p, "-Wstrict-prototypes"))
  618.     warn_strict_prototypes = 1;
  619.   else if (!strcmp (p, "-Wno-strict-prototypes"))
  620.     warn_strict_prototypes = 0;
  621.   else if (!strcmp (p, "-Wmissing-prototypes"))
  622.     warn_missing_prototypes = 1;
  623.   else if (!strcmp (p, "-Wno-missing-prototypes"))
  624.     warn_missing_prototypes = 0;
  625.   else if (!strcmp (p, "-Wredundant-decls"))
  626.     warn_redundant_decls = 1;
  627.   else if (!strcmp (p, "-Wno-redundant-decls"))
  628.     warn_redundant_decls = 0;
  629.   else if (!strcmp (p, "-Wnested-externs"))
  630.     warn_nested_externs = 1;
  631.   else if (!strcmp (p, "-Wno-nested-externs"))
  632.     warn_nested_externs = 0;
  633.   else if (!strcmp (p, "-Wtraditional"))
  634.     warn_traditional = 1;
  635.   else if (!strcmp (p, "-Wno-traditional"))
  636.     warn_traditional = 0;
  637.   else if (!strcmp (p, "-Wformat"))
  638.     warn_format = 1;
  639.   else if (!strcmp (p, "-Wno-format"))
  640.     warn_format = 0;
  641.   else if (!strcmp (p, "-Wchar-subscripts"))
  642.     warn_char_subscripts = 1;
  643.   else if (!strcmp (p, "-Wno-char-subscripts"))
  644.     warn_char_subscripts = 0;
  645.   else if (!strcmp (p, "-Wconversion"))
  646.     warn_conversion = 1;
  647.   else if (!strcmp (p, "-Wno-conversion"))
  648.     warn_conversion = 0;
  649.   else if (!strcmp (p, "-Wparentheses"))
  650.     warn_parentheses = 1;
  651.   else if (!strcmp (p, "-Wno-parentheses"))
  652.     warn_parentheses = 0;
  653.   else if (!strcmp (p, "-Wreturn-type"))
  654.     warn_return_type = 1;
  655.   else if (!strcmp (p, "-Wno-return-type"))
  656.     warn_return_type = 0;
  657.   else if (!strcmp (p, "-Wcomment"))
  658.     ; /* cpp handles this one.  */
  659.   else if (!strcmp (p, "-Wno-comment"))
  660.     ; /* cpp handles this one.  */
  661.   else if (!strcmp (p, "-Wcomments"))
  662.     ; /* cpp handles this one.  */
  663.   else if (!strcmp (p, "-Wno-comments"))
  664.     ; /* cpp handles this one.  */
  665.   else if (!strcmp (p, "-Wtrigraphs"))
  666.     ; /* cpp handles this one.  */
  667.   else if (!strcmp (p, "-Wno-trigraphs"))
  668.     ; /* cpp handles this one.  */
  669.   else if (!strcmp (p, "-Wimport"))
  670.     ; /* cpp handles this one.  */
  671.   else if (!strcmp (p, "-Wno-import"))
  672.     ; /* cpp handles this one.  */
  673.   else if (!strcmp (p, "-Wall"))
  674.     {
  675.       extra_warnings = 1;
  676.       warn_uninitialized = 1;
  677.       warn_implicit = 1;
  678.       warn_return_type = 1;
  679.       warn_unused = 1;
  680.       warn_switch = 1;
  681.       warn_format = 1;
  682.       warn_char_subscripts = 1;
  683.       warn_parentheses = 1;
  684.     }
  685.   else
  686.     return 0;
  687.  
  688.   return 1;
  689. }
  690.  
  691. /* Hooks for print_node.  */
  692.  
  693. void
  694. print_lang_decl ()
  695. {
  696. }
  697.  
  698. void
  699. print_lang_type ()
  700. {
  701. }
  702.  
  703. void
  704. print_lang_identifier (file, node, indent)
  705.      FILE *file;
  706.      tree node;
  707.      int indent;
  708. {
  709.   print_node (file, "global", IDENTIFIER_GLOBAL_VALUE (node), indent + 4);
  710.   print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
  711.   print_node (file, "label", IDENTIFIER_LABEL_VALUE (node), indent + 4);
  712.   print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
  713.   print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
  714.   print_node (file, "limbo value", IDENTIFIER_LIMBO_VALUE (node), indent + 4);
  715. }
  716.  
  717. /* Create a new `struct binding_level'.  */
  718.  
  719. static
  720. struct binding_level *
  721. make_binding_level ()
  722. {
  723.   /* NOSTRICT */
  724.   return (struct binding_level *) xmalloc (sizeof (struct binding_level));
  725. }
  726.  
  727. /* Nonzero if we are currently in the global binding level.  */
  728.  
  729. int
  730. global_bindings_p ()
  731. {
  732.   return current_binding_level == global_binding_level;
  733. }
  734.  
  735. void
  736. keep_next_level ()
  737. {
  738.   keep_next_level_flag = 1;
  739. }
  740.  
  741. /* Nonzero if the current level needs to have a BLOCK made.  */
  742.  
  743. int
  744. kept_level_p ()
  745. {
  746.   return ((current_binding_level->keep_if_subblocks
  747.        && current_binding_level->blocks != 0)
  748.       || current_binding_level->keep
  749.       || current_binding_level->names != 0
  750.       || (current_binding_level->tags != 0
  751.           && !current_binding_level->tag_transparent));
  752. }
  753.  
  754. /* Identify this binding level as a level of parameters.
  755.    DEFINITION_FLAG is 1 for a definition, 0 for a declaration.  */
  756.  
  757. void
  758. declare_parm_level (definition_flag)
  759.      int definition_flag;
  760. {
  761.   current_binding_level->parm_flag = 1 + definition_flag;
  762. }
  763.  
  764. /* Nonzero if currently making parm declarations.  */
  765.  
  766. int
  767. in_parm_level_p ()
  768. {
  769.   return current_binding_level->parm_flag;
  770. }
  771.  
  772. /* Enter a new binding level.
  773.    If TAG_TRANSPARENT is nonzero, do so only for the name space of variables,
  774.    not for that of tags.  */
  775.  
  776. void
  777. pushlevel (tag_transparent)
  778.      int tag_transparent;
  779. {
  780.   register struct binding_level *newlevel = NULL_BINDING_LEVEL;
  781.  
  782.   /* If this is the top level of a function,
  783.      just make sure that NAMED_LABELS is 0.  */
  784.  
  785.   if (current_binding_level == global_binding_level)
  786.     {
  787.       named_labels = 0;
  788.     }
  789.  
  790.   /* Reuse or create a struct for this binding level.  */
  791.  
  792.   if (free_binding_level)
  793.     {
  794.       newlevel = free_binding_level;
  795.       free_binding_level = free_binding_level->level_chain;
  796.     }
  797.   else
  798.     {
  799.       newlevel = make_binding_level ();
  800.     }
  801.  
  802.   /* Add this level to the front of the chain (stack) of levels that
  803.      are active.  */
  804.  
  805.   *newlevel = clear_binding_level;
  806.   newlevel->tag_transparent
  807.     = (tag_transparent
  808.        || (current_binding_level
  809.        ? current_binding_level->subblocks_tag_transparent
  810.        : 0));
  811.   newlevel->level_chain = current_binding_level;
  812.   current_binding_level = newlevel;
  813.   newlevel->keep = keep_next_level_flag;
  814.   keep_next_level_flag = 0;
  815.   newlevel->keep_if_subblocks = keep_next_if_subblocks;
  816.   keep_next_if_subblocks = 0;
  817. }
  818.  
  819. /* Exit a binding level.
  820.    Pop the level off, and restore the state of the identifier-decl mappings
  821.    that were in effect when this level was entered.
  822.  
  823.    If KEEP is nonzero, this level had explicit declarations, so
  824.    and create a "block" (a BLOCK node) for the level
  825.    to record its declarations and subblocks for symbol table output.
  826.  
  827.    If FUNCTIONBODY is nonzero, this level is the body of a function,
  828.    so create a block as if KEEP were set and also clear out all
  829.    label names.
  830.  
  831.    If REVERSE is nonzero, reverse the order of decls before putting
  832.    them into the BLOCK.  */
  833.  
  834. tree
  835. poplevel (keep, reverse, functionbody)
  836.      int keep;
  837.      int reverse;
  838.      int functionbody;
  839. {
  840.   register tree link;
  841.   /* The chain of decls was accumulated in reverse order.
  842.      Put it into forward order, just for cleanliness.  */
  843.   tree decls;
  844.   tree tags = current_binding_level->tags;
  845.   tree subblocks = current_binding_level->blocks;
  846.   tree block = 0;
  847.   tree decl;
  848.   int block_previously_created;
  849.  
  850.   keep |= current_binding_level->keep;
  851.  
  852.   /* This warning is turned off because it causes warnings for
  853.      declarations like `extern struct foo *x'.  */
  854. #if 0
  855.   /* Warn about incomplete structure types in this level.  */
  856.   for (link = tags; link; link = TREE_CHAIN (link))
  857.     if (TYPE_SIZE (TREE_VALUE (link)) == 0)
  858.       {
  859.     tree type = TREE_VALUE (link);
  860.     char *errmsg;
  861.     switch (TREE_CODE (type))
  862.       {
  863.       case RECORD_TYPE:
  864.         errmsg = "`struct %s' incomplete in scope ending here";
  865.         break;
  866.       case UNION_TYPE:
  867.         errmsg = "`union %s' incomplete in scope ending here";
  868.         break;
  869.       case ENUMERAL_TYPE:
  870.         errmsg = "`enum %s' incomplete in scope ending here";
  871.         break;
  872.       }
  873.     if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  874.       error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  875.     else
  876.       /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  877.       error (errmsg, IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  878.       }
  879. #endif /* 0 */
  880.  
  881.   /* Get the decls in the order they were written.
  882.      Usually current_binding_level->names is in reverse order.
  883.      But parameter decls were previously put in forward order.  */
  884.  
  885.   if (reverse)
  886.     current_binding_level->names
  887.       = decls = nreverse (current_binding_level->names);
  888.   else
  889.     decls = current_binding_level->names;
  890.  
  891.   /* Output any nested inline functions within this block
  892.      if they weren't already output.  */
  893.  
  894.   for (decl = decls; decl; decl = TREE_CHAIN (decl))
  895.     if (TREE_CODE (decl) == FUNCTION_DECL
  896.     && ! TREE_ASM_WRITTEN (decl)
  897.     && DECL_INITIAL (decl) != 0
  898.     && TREE_ADDRESSABLE (decl))
  899.       {
  900.     /* If this decl was copied from a file-scope decl
  901.        on account of a block-scope extern decl,
  902.        propagate TREE_ADDRESSABLE to the file-scope decl.  */
  903.     if (DECL_ABSTRACT_ORIGIN (decl) != 0)
  904.       TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
  905.     else
  906.       output_inline_function (decl);
  907.       }
  908.  
  909.   /* If there were any declarations or structure tags in that level,
  910.      or if this level is a function body,
  911.      create a BLOCK to record them for the life of this function.  */
  912.  
  913.   block = 0;
  914.   block_previously_created = (current_binding_level->this_block != 0);
  915.   if (block_previously_created)
  916.     block = current_binding_level->this_block;
  917.   else if (keep || functionbody
  918.        || (current_binding_level->keep_if_subblocks && subblocks != 0))
  919.     block = make_node (BLOCK);
  920.   if (block != 0)
  921.     {
  922.       BLOCK_VARS (block) = decls;
  923.       BLOCK_TYPE_TAGS (block) = tags;
  924.       BLOCK_SUBBLOCKS (block) = subblocks;
  925.       remember_end_note (block);
  926.     }
  927.  
  928.   /* In each subblock, record that this is its superior.  */
  929.  
  930.   for (link = subblocks; link; link = TREE_CHAIN (link))
  931.     BLOCK_SUPERCONTEXT (link) = block;
  932.  
  933.   /* Clear out the meanings of the local variables of this level.  */
  934.  
  935.   for (link = decls; link; link = TREE_CHAIN (link))
  936.     {
  937.       if (DECL_NAME (link) != 0)
  938.     {
  939.       /* If the ident. was used or addressed via a local extern decl,
  940.          don't forget that fact.  */
  941.       if (DECL_EXTERNAL (link))
  942.         {
  943.           if (TREE_USED (link))
  944.         TREE_USED (DECL_NAME (link)) = 1;
  945.           if (TREE_ADDRESSABLE (link))
  946.         TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (link)) = 1;
  947.         }
  948.       IDENTIFIER_LOCAL_VALUE (DECL_NAME (link)) = 0;
  949.     }
  950.     }
  951.  
  952.   /* Restore all name-meanings of the outer levels
  953.      that were shadowed by this level.  */
  954.  
  955.   for (link = current_binding_level->shadowed; link; link = TREE_CHAIN (link))
  956.     IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  957.  
  958.   /* If the level being exited is the top level of a function,
  959.      check over all the labels, and clear out the current
  960.      (function local) meanings of their names.  */
  961.  
  962.   if (functionbody)
  963.     {
  964.       /* If this is the top level block of a function,
  965.      the vars are the function's parameters.
  966.      Don't leave them in the BLOCK because they are
  967.      found in the FUNCTION_DECL instead.  */
  968.  
  969.       BLOCK_VARS (block) = 0;
  970.  
  971.       /* Clear out the definitions of all label names,
  972.      since their scopes end here,
  973.      and add them to BLOCK_VARS.  */
  974.  
  975.       for (link = named_labels; link; link = TREE_CHAIN (link))
  976.     {
  977.       register tree label = TREE_VALUE (link);
  978.  
  979.       if (DECL_INITIAL (label) == 0)
  980.         {
  981.           error_with_decl (label, "label `%s' used but not defined");
  982.           /* Avoid crashing later.  */
  983.           define_label (input_filename, lineno,
  984.                 DECL_NAME (label));
  985.         }
  986.       else if (warn_unused && !TREE_USED (label))
  987.         warning_with_decl (label, "label `%s' defined but not used");
  988.       IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
  989.  
  990.       /* Put the labels into the "variables" of the
  991.          top-level block, so debugger can see them.  */
  992.       TREE_CHAIN (label) = BLOCK_VARS (block);
  993.       BLOCK_VARS (block) = label;
  994.     }
  995.     }
  996.  
  997.   /* Pop the current level, and free the structure for reuse.  */
  998.  
  999.   {
  1000.     register struct binding_level *level = current_binding_level;
  1001.     current_binding_level = current_binding_level->level_chain;
  1002.  
  1003.     level->level_chain = free_binding_level;
  1004.     free_binding_level = level;
  1005.   }
  1006.  
  1007.   /* Dispose of the block that we just made inside some higher level.  */
  1008.   if (functionbody)
  1009.     DECL_INITIAL (current_function_decl) = block;
  1010.   else if (block)
  1011.     {
  1012.       if (!block_previously_created)
  1013.         current_binding_level->blocks
  1014.           = chainon (current_binding_level->blocks, block);
  1015.     }
  1016.   /* If we did not make a block for the level just exited,
  1017.      any blocks made for inner levels
  1018.      (since they cannot be recorded as subblocks in that level)
  1019.      must be carried forward so they will later become subblocks
  1020.      of something else.  */
  1021.   else if (subblocks)
  1022.     current_binding_level->blocks
  1023.       = chainon (current_binding_level->blocks, subblocks);
  1024.  
  1025.   /* Set the TYPE_CONTEXTs for all of the tagged types belonging to this
  1026.      binding contour so that they point to the appropriate construct, i.e.
  1027.      either to the current FUNCTION_DECL node, or else to the BLOCK node
  1028.      we just constructed.
  1029.  
  1030.      Note that for tagged types whose scope is just the formal parameter
  1031.      list for some function type specification, we can't properly set
  1032.      their TYPE_CONTEXTs here, because we don't have a pointer to the
  1033.      appropriate FUNCTION_TYPE node readily available to us.  For those
  1034.      cases, the TYPE_CONTEXTs of the relevant tagged type nodes get set
  1035.      in `grokdeclarator' as soon as we have created the FUNCTION_TYPE
  1036.      node which will represent the "scope" for these "parameter list local"
  1037.      tagged types.
  1038.   */
  1039.  
  1040.   if (functionbody)
  1041.     for (link = tags; link; link = TREE_CHAIN (link))
  1042.       TYPE_CONTEXT (TREE_VALUE (link)) = current_function_decl;
  1043.   else if (block)
  1044.     for (link = tags; link; link = TREE_CHAIN (link))
  1045.       TYPE_CONTEXT (TREE_VALUE (link)) = block;
  1046.  
  1047.   if (block)
  1048.     TREE_USED (block) = 1;
  1049.   return block;
  1050. }
  1051.  
  1052. /* Delete the node BLOCK from the current binding level.
  1053.    This is used for the block inside a stmt expr ({...})
  1054.    so that the block can be reinserted where appropriate.  */
  1055.  
  1056. void
  1057. delete_block (block)
  1058.      tree block;
  1059. {
  1060.   tree t;
  1061.   if (current_binding_level->blocks == block)
  1062.     current_binding_level->blocks = TREE_CHAIN (block);
  1063.   for (t = current_binding_level->blocks; t;)
  1064.     {
  1065.       if (TREE_CHAIN (t) == block)
  1066.     TREE_CHAIN (t) = TREE_CHAIN (block);
  1067.       else
  1068.     t = TREE_CHAIN (t);
  1069.     }
  1070.   TREE_CHAIN (block) = NULL;
  1071.   /* Clear TREE_USED which is always set by poplevel.
  1072.      The flag is set again if insert_block is called.  */
  1073.   TREE_USED (block) = 0;
  1074. }
  1075.  
  1076. /* Insert BLOCK at the end of the list of subblocks of the
  1077.    current binding level.  This is used when a BIND_EXPR is expanded,
  1078.    to handle the BLOCK node inside teh BIND_EXPR.  */
  1079.  
  1080. void
  1081. insert_block (block)
  1082.      tree block;
  1083. {
  1084.   TREE_USED (block) = 1;
  1085.   current_binding_level->blocks
  1086.     = chainon (current_binding_level->blocks, block);
  1087. }
  1088.  
  1089. /* Set the BLOCK node for the innermost scope
  1090.    (the one we are currently in).  */
  1091.  
  1092. void
  1093. set_block (block)
  1094.      register tree block;
  1095. {
  1096.   current_binding_level->this_block = block;
  1097. }
  1098.  
  1099. void
  1100. push_label_level ()
  1101. {
  1102.   register struct binding_level *newlevel;
  1103.  
  1104.   /* Reuse or create a struct for this binding level.  */
  1105.  
  1106.   if (free_binding_level)
  1107.     {
  1108.       newlevel = free_binding_level;
  1109.       free_binding_level = free_binding_level->level_chain;
  1110.     }
  1111.   else
  1112.     {
  1113.       newlevel = make_binding_level ();
  1114.     }
  1115.  
  1116.   /* Add this level to the front of the chain (stack) of label levels.  */
  1117.  
  1118.   newlevel->level_chain = label_level_chain;
  1119.   label_level_chain = newlevel;
  1120.  
  1121.   newlevel->names = named_labels;
  1122.   newlevel->shadowed = shadowed_labels;
  1123.   named_labels = 0;
  1124.   shadowed_labels = 0;
  1125. }
  1126.  
  1127. void
  1128. pop_label_level ()
  1129. {
  1130.   register struct binding_level *level = label_level_chain;
  1131.   tree link, prev;
  1132.  
  1133.   /* Clear out the definitions of the declared labels in this level.
  1134.      Leave in the list any ordinary, non-declared labels.  */
  1135.   for (link = named_labels, prev = 0; link;)
  1136.     {
  1137.       if (C_DECLARED_LABEL_FLAG (TREE_VALUE (link)))
  1138.     {
  1139.       if (DECL_SOURCE_LINE (TREE_VALUE (link)) == 0)
  1140.         {
  1141.           error_with_decl ("label `%s' used but not defined",
  1142.                    TREE_VALUE (link));
  1143.           /* Avoid crashing later.  */
  1144.           define_label (input_filename, lineno,
  1145.                 DECL_NAME (TREE_VALUE (link)));
  1146.         }
  1147.       else if (warn_unused && !TREE_USED (TREE_VALUE (link)))
  1148.         warning_with_decl (TREE_VALUE (link), 
  1149.                    "label `%s' defined but not used");
  1150.       IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link))) = 0;
  1151.  
  1152.       /* Delete this element from the list.  */
  1153.       link = TREE_CHAIN (link);
  1154.       if (prev)
  1155.         TREE_CHAIN (prev) = link;
  1156.       else
  1157.         named_labels = link;
  1158.     }
  1159.       else
  1160.     {
  1161.       prev = link;
  1162.       link = TREE_CHAIN (link);
  1163.     }
  1164.     }
  1165.  
  1166.   /* Bring back all the labels that were shadowed.  */
  1167.   for (link = shadowed_labels; link; link = TREE_CHAIN (link))
  1168.     if (DECL_NAME (TREE_VALUE (link)) != 0)
  1169.       IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
  1170.     = TREE_VALUE (link);
  1171.  
  1172.   named_labels = chainon (named_labels, level->names);
  1173.   shadowed_labels = level->shadowed;
  1174.  
  1175.   /* Pop the current level, and free the structure for reuse.  */
  1176.   label_level_chain = label_level_chain->level_chain;
  1177.   level->level_chain = free_binding_level;
  1178.   free_binding_level = level;
  1179. }
  1180.  
  1181. /* Push a definition or a declaration of struct, union or enum tag "name".
  1182.    "type" should be the type node.
  1183.    We assume that the tag "name" is not already defined.
  1184.  
  1185.    Note that the definition may really be just a forward reference.
  1186.    In that case, the TYPE_SIZE will be zero.  */
  1187.  
  1188. void
  1189. pushtag (name, type)
  1190.      tree name, type;
  1191. {
  1192.   register struct binding_level *b;
  1193.  
  1194.   /* Find the proper binding level for this type tag.  */
  1195.  
  1196.   for (b = current_binding_level; b->tag_transparent; b = b->level_chain)
  1197.     continue;
  1198.  
  1199.   if (name)
  1200.     {
  1201.       /* Record the identifier as the type's name if it has none.  */
  1202.  
  1203.       if (TYPE_NAME (type) == 0)
  1204.     TYPE_NAME (type) = name;
  1205.     }
  1206.  
  1207.   if (b == global_binding_level)
  1208.     b->tags = perm_tree_cons (name, type, b->tags);
  1209.   else
  1210.     b->tags = saveable_tree_cons (name, type, b->tags);
  1211.  
  1212.   /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
  1213.      tagged type we just added to the current binding level.  This fake
  1214.      NULL-named TYPE_DECL node helps dwarfout.c to know when it needs
  1215.      to output a representation of a tagged type, and it also gives
  1216.      us a convenient place to record the "scope start" address for the
  1217.      tagged type.  */
  1218.  
  1219.   TYPE_STUB_DECL (type) = pushdecl (build_decl (TYPE_DECL, NULL_TREE, type));
  1220. }
  1221.  
  1222. /* Handle when a new declaration NEWDECL
  1223.    has the same name as an old one OLDDECL
  1224.    in the same binding contour.
  1225.    Prints an error message if appropriate.
  1226.  
  1227.    If safely possible, alter OLDDECL to look like NEWDECL, and return 1.
  1228.    Otherwise, return 0.  */
  1229.  
  1230. static int
  1231. duplicate_decls (newdecl, olddecl)
  1232.      register tree newdecl, olddecl;
  1233. {
  1234.   int types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
  1235.   int new_is_definition = (TREE_CODE (newdecl) == FUNCTION_DECL
  1236.                && DECL_INITIAL (newdecl) != 0);
  1237.   tree oldtype = TREE_TYPE (olddecl);
  1238.   tree newtype = TREE_TYPE (newdecl);
  1239.  
  1240.   if (TREE_CODE (newtype) == ERROR_MARK
  1241.       || TREE_CODE (oldtype) == ERROR_MARK)
  1242.     types_match = 0;
  1243.  
  1244.   /* New decl is completely inconsistent with the old one =>
  1245.      tell caller to replace the old one.
  1246.      This is always an error except in the case of shadowing a builtin.  */
  1247.   if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
  1248.     {
  1249.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1250.       && DECL_BUILT_IN (olddecl))
  1251.     {
  1252.       /* If you declare a built-in function name as static, the
  1253.          built-in definition is overridden,
  1254.          but optionally warn this was a bad choice of name.  */
  1255.       if (!TREE_PUBLIC (newdecl))
  1256.         {
  1257.           if (warn_shadow)
  1258.         warning_with_decl (newdecl, "shadowing built-in function `%s'");
  1259.         }
  1260.       /* Likewise, if the built-in is not ansi, then programs can
  1261.          override it even globally without an error.  */
  1262.       else if (DECL_BUILT_IN_NONANSI (olddecl))
  1263.         warning_with_decl (newdecl,
  1264.                    "built-in function `%s' declared as non-function");
  1265.       else
  1266.         error_with_decl (newdecl,
  1267.                  "built-in function `%s' declared as non-function");
  1268.     }
  1269.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1270.            && DECL_BUILT_IN_NONANSI (olddecl))
  1271.     {
  1272.       /* If overriding decl is static,
  1273.          optionally warn this was a bad choice of name.  */
  1274.       if (!TREE_PUBLIC (newdecl))
  1275.         {
  1276.           if (warn_shadow)
  1277.         warning_with_decl (newdecl, "shadowing library function `%s'");
  1278.         }
  1279.       /* Otherwise, always warn.  */
  1280.       else
  1281.         warning_with_decl (newdecl,
  1282.                    "library function `%s' declared as non-function");
  1283.     }
  1284.       else
  1285.     {
  1286.       error_with_decl (newdecl, "`%s' redeclared as different kind of symbol");
  1287.       error_with_decl (olddecl, "previous declaration of `%s'");
  1288.     }
  1289.  
  1290.       return 0;
  1291.     }
  1292.  
  1293.   /* For real parm decl following a forward decl,
  1294.      return 1 so old decl will be reused.  */
  1295.   if (types_match && TREE_CODE (newdecl) == PARM_DECL
  1296.       && TREE_ASM_WRITTEN (olddecl) && ! TREE_ASM_WRITTEN (newdecl))
  1297.     return 1;
  1298.  
  1299.   /* The new declaration is the same kind of object as the old one.
  1300.      The declarations may partially match.  Print warnings if they don't
  1301.      match enough.  Ultimately, copy most of the information from the new
  1302.      decl to the old one, and keep using the old one.  */
  1303.  
  1304.   if (flag_traditional && TREE_CODE (newdecl) == FUNCTION_DECL
  1305.       && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (newdecl)) == olddecl
  1306.       && DECL_INITIAL (olddecl) == 0)
  1307.     /* If -traditional, avoid error for redeclaring fcn
  1308.        after implicit decl.  */
  1309.     ;
  1310.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1311.        && DECL_BUILT_IN (olddecl))
  1312.     {
  1313.       /* A function declaration for a built-in function.  */
  1314.       if (!TREE_PUBLIC (newdecl))
  1315.     {
  1316.       /* If you declare a built-in function name as static, the
  1317.          built-in definition is overridden,
  1318.          but optionally warn this was a bad choice of name.  */
  1319.       if (warn_shadow)
  1320.         warning_with_decl (newdecl, "shadowing built-in function `%s'");
  1321.       /* Discard the old built-in function.  */
  1322.       return 0;
  1323.     }
  1324.       else if (!types_match)
  1325.     {
  1326.           /* Accept the return type of the new declaration if same modes.  */
  1327.       tree oldreturntype = TREE_TYPE (TREE_TYPE (olddecl));
  1328.       tree newreturntype = TREE_TYPE (TREE_TYPE (newdecl));
  1329.           if (TYPE_MODE (oldreturntype) == TYPE_MODE (newreturntype))
  1330.             {
  1331.           /* Function types may be shared, so we can't just modify
  1332.          the return type of olddecl's function type.  */
  1333.           tree newtype
  1334.         = build_function_type (newreturntype,
  1335.                        TYPE_ARG_TYPES (TREE_TYPE (olddecl)));
  1336.           
  1337.               types_match = comptypes (TREE_TYPE (newdecl), newtype);
  1338.           if (types_match)
  1339.         TREE_TYPE (olddecl) = newtype;
  1340.         }
  1341.     }
  1342.       if (!types_match)
  1343.     {
  1344.       /* If types don't match for a built-in, throw away the built-in.  */
  1345.       warning_with_decl (newdecl, "conflicting types for built-in function `%s'");
  1346.       return 0;
  1347.     }
  1348.     }
  1349.   else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1350.        && DECL_SOURCE_LINE (olddecl) == 0)
  1351.     {
  1352.       /* A function declaration for a predeclared function
  1353.      that isn't actually built in.  */
  1354.       if (!TREE_PUBLIC (newdecl))
  1355.     {
  1356.       /* If you declare it as static, the
  1357.          default definition is overridden.  */
  1358.       return 0;
  1359.     }
  1360.       else if (!types_match)
  1361.     {
  1362.       /* If the types don't match, preserve volatility indication.
  1363.          Later on, we will discard everything else about the
  1364.          default declaration.  */
  1365.       TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
  1366.     }
  1367.     }
  1368.   /* Permit char *foo () to match void *foo (...) if not pedantic,
  1369.      if one of them came from a system header file.  */
  1370.   else if (!types_match
  1371.        && TREE_CODE (olddecl) == FUNCTION_DECL
  1372.        && TREE_CODE (newdecl) == FUNCTION_DECL
  1373.        && TREE_CODE (TREE_TYPE (oldtype)) == POINTER_TYPE
  1374.        && TREE_CODE (TREE_TYPE (newtype)) == POINTER_TYPE
  1375.        && (DECL_IN_SYSTEM_HEADER (olddecl)
  1376.            || DECL_IN_SYSTEM_HEADER (newdecl))
  1377.        && ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (newtype))) == void_type_node
  1378.         && TYPE_ARG_TYPES (oldtype) == 0
  1379.         && self_promoting_args_p (TYPE_ARG_TYPES (newtype))
  1380.         && TREE_TYPE (TREE_TYPE (oldtype)) == char_type_node)
  1381.            ||
  1382.            (TREE_TYPE (TREE_TYPE (newtype)) == char_type_node
  1383.         && TYPE_ARG_TYPES (newtype) == 0
  1384.         && self_promoting_args_p (TYPE_ARG_TYPES (oldtype))
  1385.         && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)))
  1386.     {
  1387.       if (pedantic)
  1388.     pedwarn_with_decl (newdecl, "conflicting types for `%s'");
  1389.       /* Make sure we keep void * as ret type, not char *.  */
  1390.       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (oldtype))) == void_type_node)
  1391.     TREE_TYPE (newdecl) = newtype = oldtype;
  1392.     }
  1393.   else if (!types_match
  1394.        /* Permit char *foo (int, ...); followed by char *foo ();
  1395.           if not pedantic.  */
  1396.        && ! (TREE_CODE (olddecl) == FUNCTION_DECL
  1397.          && ! pedantic
  1398.          /* Return types must still match.  */
  1399.          && comptypes (TREE_TYPE (oldtype),
  1400.                    TREE_TYPE (newtype))
  1401.          && TYPE_ARG_TYPES (newtype) == 0))
  1402.     {
  1403.       error_with_decl (newdecl, "conflicting types for `%s'");
  1404.       /* Check for function type mismatch
  1405.      involving an empty arglist vs a nonempty one.  */
  1406.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1407.       && comptypes (TREE_TYPE (oldtype),
  1408.             TREE_TYPE (newtype))
  1409.       && ((TYPE_ARG_TYPES (oldtype) == 0
  1410.            && DECL_INITIAL (olddecl) == 0)
  1411.           ||
  1412.           (TYPE_ARG_TYPES (newtype) == 0
  1413.            && DECL_INITIAL (newdecl) == 0)))
  1414.     {
  1415.       /* Classify the problem further.  */
  1416.       register tree t = TYPE_ARG_TYPES (oldtype);
  1417.       if (t == 0)
  1418.         t = TYPE_ARG_TYPES (newtype);
  1419.       for (; t; t = TREE_CHAIN (t))
  1420.         {
  1421.           register tree type = TREE_VALUE (t);
  1422.  
  1423.           if (TREE_CHAIN (t) == 0
  1424.           && TYPE_MAIN_VARIANT (type) != void_type_node)
  1425.         {
  1426.           error ("A parameter list with an ellipsis can't match");
  1427.           error ("an empty parameter name list declaration.");
  1428.           break;
  1429.         }
  1430.  
  1431.           if (TYPE_MAIN_VARIANT (type) == float_type_node
  1432.           || C_PROMOTING_INTEGER_TYPE_P (type))
  1433.         {
  1434.           error ("An argument type that has a default promotion");
  1435.           error ("can't match an empty parameter name list declaration.");
  1436.           break;
  1437.         }
  1438.         }
  1439.     }
  1440.       error_with_decl (olddecl, "previous declaration of `%s'");
  1441.     }
  1442.   else
  1443.     {
  1444.       char *errmsg = redeclaration_error_message (newdecl, olddecl);
  1445.       if (errmsg)
  1446.     {
  1447.       error_with_decl (newdecl, errmsg);
  1448.       error_with_decl (olddecl,
  1449.                ((DECL_INITIAL (olddecl)
  1450.                  && current_binding_level == global_binding_level)
  1451.                 ? "`%s' previously defined here"
  1452.                 : "`%s' previously declared here"));
  1453.     }
  1454.       else if (TREE_CODE (olddecl) == FUNCTION_DECL
  1455.            && DECL_INITIAL (olddecl) != 0
  1456.            && TYPE_ARG_TYPES (oldtype) == 0
  1457.            && TYPE_ARG_TYPES (newtype) != 0)
  1458.     {
  1459.       register tree type, parm;
  1460.       register int nargs;
  1461.       /* Prototype decl follows defn w/o prototype.  */
  1462.  
  1463.       for (parm = TYPE_ACTUAL_ARG_TYPES (oldtype),
  1464.            type = TYPE_ARG_TYPES (newtype),
  1465.            nargs = 1;
  1466.            (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) != void_type_node
  1467.         || TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
  1468.            parm = TREE_CHAIN (parm), type = TREE_CHAIN (type), nargs++)
  1469.         {
  1470.           if (TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == void_type_node
  1471.           || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
  1472.         {
  1473.           errmsg = "prototype for `%s' follows and number of arguments";
  1474.           break;
  1475.         }
  1476.           /* Type for passing arg must be consistent
  1477.          with that declared for the arg.  */
  1478.           if (! comptypes (TREE_VALUE (parm), TREE_VALUE (type))
  1479.           /* If -traditional, allow `unsigned int' instead of `int'
  1480.              in the prototype.  */
  1481.           && (! (flag_traditional
  1482.              && TYPE_MAIN_VARIANT (TREE_VALUE (parm)) == integer_type_node
  1483.              && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node)))
  1484.         {
  1485.           errmsg = "prototype for `%s' follows and argument %d";
  1486.           break;
  1487.         }
  1488.         }
  1489.       if (errmsg)
  1490.         {
  1491.           error_with_decl (newdecl, errmsg, nargs);
  1492.           error_with_decl (olddecl,
  1493.                    "doesn't match non-prototype definition here");
  1494.         }
  1495.       else
  1496.         {
  1497.           warning_with_decl (newdecl, "prototype for `%s' follows");
  1498.           warning_with_decl (olddecl, "non-prototype definition here");
  1499.         }
  1500.     }
  1501.       /* Warn about mismatches in various flags.  */
  1502.       else
  1503.     {
  1504.       /* Warn if function is now inline
  1505.          but was previously declared not inline and has been called.  */
  1506.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1507.           && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
  1508.           && TREE_USED (olddecl))
  1509.         warning_with_decl (newdecl,
  1510.                    "`%s' declared inline after being called");
  1511.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1512.           && ! DECL_INLINE (olddecl) && DECL_INLINE (newdecl)
  1513.           && DECL_INITIAL (olddecl) != 0)
  1514.         warning_with_decl (newdecl,
  1515.                    "`%s' declared inline after its definition");
  1516.       /* It is nice to warn when a function is declared
  1517.          global first and then static.  */
  1518.       if (TREE_CODE (olddecl) == FUNCTION_DECL
  1519.           && TREE_PUBLIC (olddecl)
  1520.           && !TREE_PUBLIC (newdecl))
  1521.         warning_with_decl (newdecl, "static declaration for `%s' follows non-static");
  1522.  
  1523.       /* These bits are logically part of the type, for variables.
  1524.          But not for functions
  1525.          (where qualifiers are not valid ANSI anyway).  */
  1526.       if (pedantic && TREE_CODE (olddecl) != FUNCTION_DECL
  1527.           && (TREE_READONLY (newdecl) != TREE_READONLY (olddecl)
  1528.           || TREE_THIS_VOLATILE (newdecl) != TREE_THIS_VOLATILE (olddecl)))
  1529.         pedwarn_with_decl (newdecl, "type qualifiers for `%s' conflict with previous decl");
  1530.     }
  1531.     }
  1532.  
  1533.   /* Optionally warn about more than one declaration for the same name.  */
  1534.   if (warn_redundant_decls && DECL_SOURCE_LINE (olddecl) != 0
  1535.       /* Dont warn about a function declaration
  1536.      followed by a definition.  */
  1537.       && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) != 0
  1538.        && DECL_INITIAL (olddecl) == 0))
  1539.     {
  1540.       warning_with_decl (newdecl, "redundant redeclaration of `%s' in same scope");
  1541.       warning_with_decl (olddecl, "previous declaration of `%s'");
  1542.     }
  1543.  
  1544.   /* Copy all the DECL_... slots specified in the new decl
  1545.      except for any that we copy here from the old type.
  1546.  
  1547.      Past this point, we don't change OLDTYPE and NEWTYPE
  1548.      even if we change the types of NEWDECL and OLDDECL.  */
  1549.  
  1550.   if (types_match)
  1551.     {
  1552.       /* Merge the data types specified in the two decls.  */
  1553.       if (TREE_CODE (newdecl) != FUNCTION_DECL || !DECL_BUILT_IN (olddecl))
  1554.     TREE_TYPE (newdecl)
  1555.       = TREE_TYPE (olddecl)
  1556.         = common_type (newtype, oldtype);
  1557.  
  1558.       /* Lay the type out, unless already done.  */
  1559.       if (oldtype != TREE_TYPE (newdecl))
  1560.     {
  1561.       if (TREE_TYPE (newdecl) != error_mark_node)
  1562.         layout_type (TREE_TYPE (newdecl));
  1563.       if (TREE_CODE (newdecl) != FUNCTION_DECL
  1564.           && TREE_CODE (newdecl) != TYPE_DECL
  1565.           && TREE_CODE (newdecl) != CONST_DECL)
  1566.         layout_decl (newdecl, 0);
  1567.     }
  1568.       else
  1569.     {
  1570.       /* Since the type is OLDDECL's, make OLDDECL's size go with.  */
  1571.       DECL_SIZE (newdecl) = DECL_SIZE (olddecl);
  1572.       if (TREE_CODE (olddecl) != FUNCTION_DECL)
  1573.         if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
  1574.           DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl);
  1575.     }
  1576.  
  1577.       /* Keep the old rtl since we can safely use it.  */
  1578.       DECL_RTL (newdecl) = DECL_RTL (olddecl);
  1579.  
  1580.       /* Merge the type qualifiers.  */
  1581.       if (DECL_BUILT_IN_NONANSI (olddecl) && TREE_THIS_VOLATILE (olddecl)
  1582.       && !TREE_THIS_VOLATILE (newdecl))
  1583.     TREE_THIS_VOLATILE (olddecl) = 0;
  1584.       if (TREE_READONLY (newdecl))
  1585.     TREE_READONLY (olddecl) = 1;
  1586.       if (TREE_THIS_VOLATILE (newdecl))
  1587.     {
  1588.       TREE_THIS_VOLATILE (olddecl) = 1;
  1589.       if (TREE_CODE (newdecl) == VAR_DECL)
  1590.         make_var_volatile (newdecl);
  1591.     }
  1592.  
  1593.       /* Keep source location of definition rather than declaration.  */
  1594.       if (DECL_INITIAL (newdecl) == 0 && DECL_INITIAL (olddecl) != 0)
  1595.     {
  1596.       DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl);
  1597.       DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl);
  1598.     }
  1599.  
  1600.       /* Merge the unused-warning information.  */
  1601.       if (DECL_IN_SYSTEM_HEADER (olddecl))
  1602.     DECL_IN_SYSTEM_HEADER (newdecl) = 1;
  1603.       else if (DECL_IN_SYSTEM_HEADER (newdecl))
  1604.     DECL_IN_SYSTEM_HEADER (olddecl) = 1;
  1605.  
  1606.       /* Merge the initialization information.  */
  1607.       if (DECL_INITIAL (newdecl) == 0)
  1608.     DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1609.     }
  1610.   /* If cannot merge, then use the new type and qualifiers,
  1611.      and don't preserve the old rtl.  */
  1612.   else
  1613.     {
  1614.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  1615.       TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
  1616.       TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
  1617.       TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
  1618.     }
  1619.  
  1620.   /* Merge the storage class information.  */
  1621.   /* For functions, static overrides non-static.  */
  1622.   if (TREE_CODE (newdecl) == FUNCTION_DECL)
  1623.     {
  1624.       TREE_PUBLIC (newdecl) &= TREE_PUBLIC (olddecl);
  1625.       /* This is since we don't automatically
  1626.      copy the attributes of NEWDECL into OLDDECL.  */
  1627.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1628.       /* If this clears `static', clear it in the identifier too.  */
  1629.       if (! TREE_PUBLIC (olddecl))
  1630.     TREE_PUBLIC (DECL_NAME (olddecl)) = 0;
  1631.     }
  1632.   if (DECL_EXTERNAL (newdecl))
  1633.     {
  1634.       TREE_STATIC (newdecl) = TREE_STATIC (olddecl);
  1635.       DECL_EXTERNAL (newdecl) = DECL_EXTERNAL (olddecl);
  1636.       /* An extern decl does not override previous storage class.  */
  1637.       TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
  1638.     }
  1639.   else
  1640.     {
  1641.       TREE_STATIC (olddecl) = TREE_STATIC (newdecl);
  1642.       TREE_PUBLIC (olddecl) = TREE_PUBLIC (newdecl);
  1643.     }
  1644.  
  1645.   /* If either decl says `inline', this fn is inline,
  1646.      unless its definition was passed already.  */
  1647.   if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == 0)
  1648.     DECL_INLINE (olddecl) = 1;
  1649.   DECL_INLINE (newdecl) = DECL_INLINE (olddecl);
  1650.  
  1651.   /* Get rid of any built-in function if new arg types don't match it
  1652.      or if we have a function definition.  */
  1653.   if (TREE_CODE (newdecl) == FUNCTION_DECL
  1654.       && DECL_BUILT_IN (olddecl)
  1655.       && (!types_match || new_is_definition))
  1656.     {
  1657.       TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
  1658.       DECL_BUILT_IN (olddecl) = 0;
  1659.     }
  1660.  
  1661.   /* If redeclaring a builtin function, and not a definition,
  1662.      it stays built in.
  1663.      Also preserve various other info from the definition.  */
  1664.   if (TREE_CODE (newdecl) == FUNCTION_DECL && !new_is_definition)
  1665.     {
  1666.       if (DECL_BUILT_IN (olddecl))
  1667.     {
  1668.       DECL_BUILT_IN (newdecl) = 1;
  1669.       DECL_SET_FUNCTION_CODE (newdecl, DECL_FUNCTION_CODE (olddecl));
  1670.     }
  1671.       else
  1672.     DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl);
  1673.  
  1674.       DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
  1675.       DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
  1676.       DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl);
  1677.       DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
  1678.     }
  1679.  
  1680.   /* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
  1681.      But preserve OLDdECL's DECL_UID.  */
  1682.   {
  1683.     register unsigned olddecl_uid = DECL_UID (olddecl);
  1684.  
  1685.     bcopy ((char *) newdecl + sizeof (struct tree_common),
  1686.        (char *) olddecl + sizeof (struct tree_common),
  1687.        sizeof (struct tree_decl) - sizeof (struct tree_common));
  1688.     DECL_UID (olddecl) = olddecl_uid;
  1689.   }
  1690.  
  1691.   return 1;
  1692. }
  1693.  
  1694. #ifdef MPW
  1695. #pragma segment CDECL01
  1696. #endif
  1697.  
  1698. /* Record a decl-node X as belonging to the current lexical scope.
  1699.    Check for errors (such as an incompatible declaration for the same
  1700.    name already seen in the same scope).
  1701.  
  1702.    Returns either X or an old decl for the same name.
  1703.    If an old decl is returned, it may have been smashed
  1704.    to agree with what X says.  */
  1705.  
  1706. tree
  1707. pushdecl (x)
  1708.      tree x;
  1709. {
  1710.   register tree t;
  1711.   register tree name = DECL_NAME (x);
  1712.   register struct binding_level *b = current_binding_level;
  1713.  
  1714.   DECL_CONTEXT (x) = current_function_decl;
  1715.   /* A local declaration for a function doesn't constitute nesting.  */
  1716.   if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0)
  1717.     DECL_CONTEXT (x) = 0;
  1718.  
  1719.   if (warn_nested_externs && DECL_EXTERNAL (x) && b != global_binding_level
  1720.       && x != IDENTIFIER_IMPLICIT_DECL (name))
  1721.     warning ("nested extern declaration of `%s'", IDENTIFIER_POINTER (name));
  1722.  
  1723.   if (name)
  1724.     {
  1725.       char *file;
  1726.       int line;
  1727.  
  1728.       t = lookup_name_current_level (name);
  1729.       if (t != 0 && t == error_mark_node)
  1730.     /* error_mark_node is 0 for a while during initialization!  */
  1731.     {
  1732.       t = 0;
  1733.       error_with_decl (x, "`%s' used prior to declaration");
  1734.     }
  1735.  
  1736.       if (t != 0)
  1737.     {
  1738.       file = DECL_SOURCE_FILE (t);
  1739.       line = DECL_SOURCE_LINE (t);
  1740.     }
  1741.  
  1742.       if (t != 0 && duplicate_decls (x, t))
  1743.     {
  1744.       if (TREE_CODE (t) == PARM_DECL)
  1745.         {
  1746.           /* Don't allow more than one "real" duplicate
  1747.          of a forward parm decl.  */
  1748.           TREE_ASM_WRITTEN (t) = TREE_ASM_WRITTEN (x);
  1749.           return t;
  1750.         }
  1751.       /* If this decl is `static' and an implicit decl was seen previously,
  1752.          warn.  But don't complain if -traditional,
  1753.          since traditional compilers don't complain.  */
  1754.       if (!flag_traditional && TREE_PUBLIC (name)
  1755.           && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x)
  1756.           /* We used to warn also for explicit extern followed by static,
  1757.          but sometimes you need to do it that way.  */
  1758.           && IDENTIFIER_IMPLICIT_DECL (name) != 0)
  1759.         {
  1760.           pedwarn ("`%s' was declared implicitly `extern' and later `static'",
  1761.                IDENTIFIER_POINTER (name));
  1762.           pedwarn_with_file_and_line (file, line,
  1763.                       "previous declaration of `%s'",
  1764.                       IDENTIFIER_POINTER (name));
  1765.         }
  1766.  
  1767.       return t;
  1768.     }
  1769.  
  1770.       /* If we are processing a typedef statement, generate a whole new
  1771.      ..._TYPE node (which will be just an variant of the existing
  1772.      ..._TYPE node with identical properties) and then install the
  1773.      TYPE_DECL node generated to represent the typedef name as the
  1774.      TYPE_NAME of this brand new (duplicate) ..._TYPE node.
  1775.  
  1776.      The whole point here is to end up with a situation where each
  1777.      and every ..._TYPE node the compiler creates will be uniquely
  1778.      associated with AT MOST one node representing a typedef name.
  1779.      This way, even though the compiler substitutes corresponding
  1780.      ..._TYPE nodes for TYPE_DECL (i.e. "typedef name") nodes very
  1781.      early on, later parts of the compiler can always do the reverse
  1782.      translation and get back the corresponding typedef name.  For
  1783.      example, given:
  1784.  
  1785.         typedef struct S MY_TYPE;
  1786.         MY_TYPE object;
  1787.  
  1788.      Later parts of the compiler might only know that `object' was of
  1789.      type `struct S' if if were not for code just below.  With this
  1790.      code however, later parts of the compiler see something like:
  1791.  
  1792.         struct S' == struct S
  1793.         typedef struct S' MY_TYPE;
  1794.         struct S' object;
  1795.  
  1796.      And they can then deduce (from the node for type struct S') that
  1797.      the original object declaration was:
  1798.  
  1799.         MY_TYPE object;
  1800.  
  1801.      Being able to do this is important for proper support of protoize,
  1802.      and also for generating precise symbolic debugging information
  1803.      which takes full account of the programmer's (typedef) vocabulary.
  1804.  
  1805.          Obviously, we don't want to generate a duplicate ..._TYPE node if
  1806.      the TYPE_DECL node that we are now processing really represents a
  1807.      standard built-in type.
  1808.  
  1809.          Since all standard types are effectively declared at line zero
  1810.          in the source file, we can easily check to see if we are working
  1811.          on a standard type by checking the current value of lineno.  */
  1812.  
  1813.       if (TREE_CODE (x) == TYPE_DECL)
  1814.         {
  1815.           if (DECL_SOURCE_LINE (x) == 0)
  1816.             {
  1817.           if (TYPE_NAME (TREE_TYPE (x)) == 0)
  1818.             TYPE_NAME (TREE_TYPE (x)) = x;
  1819.             }
  1820.           else
  1821.             {
  1822.               tree tt = TREE_TYPE (x);
  1823.  
  1824.               tt = build_type_copy (tt);
  1825.               TYPE_NAME (tt) = x;
  1826.               TREE_TYPE (x) = tt;
  1827.             }
  1828.         }
  1829.  
  1830.       /* Multiple external decls of the same identifier ought to match.
  1831.      Check against both global declarations and out of scope (limbo) block
  1832.      level declarations.
  1833.  
  1834.      We get warnings about inline functions where they are defined.
  1835.      Avoid duplicate warnings where they are used.  */
  1836.       if (DECL_EXTERNAL (x) && ! DECL_INLINE (x))
  1837.     {
  1838.       tree decl;
  1839.  
  1840.       if (IDENTIFIER_GLOBAL_VALUE (name) != 0
  1841.           && (DECL_EXTERNAL (IDENTIFIER_GLOBAL_VALUE (name))
  1842.           || TREE_PUBLIC (IDENTIFIER_GLOBAL_VALUE (name))))
  1843.         decl = IDENTIFIER_GLOBAL_VALUE (name);
  1844.       else if (IDENTIFIER_LIMBO_VALUE (name) != 0)
  1845.         /* Decls in limbo are always extern, so no need to check that.  */
  1846.         decl = IDENTIFIER_LIMBO_VALUE (name);
  1847.       else
  1848.         decl = 0;
  1849.  
  1850.       if (decl && ! comptypes (TREE_TYPE (x), TREE_TYPE (decl)))
  1851.         {
  1852.           pedwarn_with_decl (x,
  1853.                  "type mismatch with previous external decl");
  1854.           pedwarn_with_decl (decl, "previous external decl of `%s'");
  1855.         }
  1856.     }
  1857.  
  1858.       /* If a function has had an implicit declaration, and then is defined,
  1859.      make sure they are compatible.  */
  1860.  
  1861.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  1862.       && IDENTIFIER_GLOBAL_VALUE (name) == 0
  1863.       && TREE_CODE (x) == FUNCTION_DECL
  1864.       && ! comptypes (TREE_TYPE (x),
  1865.               TREE_TYPE (IDENTIFIER_IMPLICIT_DECL (name))))
  1866.     {
  1867.       warning_with_decl (x, "type mismatch with previous implicit declaration");
  1868.       warning_with_decl (IDENTIFIER_IMPLICIT_DECL (name),
  1869.                  "previous implicit declaration of `%s'");
  1870.     }
  1871.  
  1872.       /* In PCC-compatibility mode, extern decls of vars with no current decl
  1873.      take effect at top level no matter where they are.  */
  1874.       if (flag_traditional && DECL_EXTERNAL (x)
  1875.       && lookup_name (name) == 0)
  1876.     {
  1877.       tree type = TREE_TYPE (x);
  1878.  
  1879.       /* But don't do this if the type contains temporary nodes.  */
  1880.       while (type)
  1881.         {
  1882.           if (type == error_mark_node)
  1883.         break;
  1884.           if (! TREE_PERMANENT (type))
  1885.         {
  1886.           warning_with_decl (x, "type of external `%s' is not global");
  1887.           /* By exiting the loop early, we leave TYPE nonzero,
  1888.              and thus prevent globalization of the decl.  */
  1889.           break;
  1890.         }
  1891.           else if (TREE_CODE (type) == FUNCTION_TYPE
  1892.                && TYPE_ARG_TYPES (type) != 0)
  1893.         /* The types might not be truly local,
  1894.            but the list of arg types certainly is temporary.
  1895.            Since prototypes are nontraditional,
  1896.            ok not to do the traditional thing.  */
  1897.         break;
  1898.           type = TREE_TYPE (type);
  1899.         }
  1900.  
  1901.       if (type == 0)
  1902.         b = global_binding_level;
  1903.     }
  1904.  
  1905.       /* This name is new in its binding level.
  1906.      Install the new declaration and return it.  */
  1907.       if (b == global_binding_level)
  1908.     {
  1909.       /* Install a global value.  */
  1910.       
  1911.       /* If the first global decl has external linkage,
  1912.          warn if we later see static one.  */
  1913.       if (IDENTIFIER_GLOBAL_VALUE (name) == 0 && TREE_PUBLIC (x))
  1914.         TREE_PUBLIC (name) = 1;
  1915.  
  1916.       IDENTIFIER_GLOBAL_VALUE (name) = x;
  1917.  
  1918.       /* We no longer care about any previous block level declarations.  */
  1919.       IDENTIFIER_LIMBO_VALUE (name) = 0;
  1920.  
  1921.       /* Don't forget if the function was used via an implicit decl.  */
  1922.       if (IDENTIFIER_IMPLICIT_DECL (name)
  1923.           && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name)))
  1924.         TREE_USED (x) = 1, TREE_USED (name) = 1;
  1925.  
  1926.       /* Don't forget if its address was taken in that way.  */
  1927.       if (IDENTIFIER_IMPLICIT_DECL (name)
  1928.           && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name)))
  1929.         TREE_ADDRESSABLE (x) = 1;
  1930.  
  1931.       /* Warn about mismatches against previous implicit decl.  */
  1932.       if (IDENTIFIER_IMPLICIT_DECL (name) != 0
  1933.           /* If this real decl matches the implicit, don't complain.  */
  1934.           && ! (TREE_CODE (x) == FUNCTION_DECL
  1935.             && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (x)))
  1936.             == integer_type_node)))
  1937.         pedwarn ("`%s' was previously implicitly declared to return `int'",
  1938.              IDENTIFIER_POINTER (name));
  1939.  
  1940.       /* If this decl is `static' and an `extern' was seen previously,
  1941.          that is erroneous.  */
  1942.       if (TREE_PUBLIC (name)
  1943.           && ! TREE_PUBLIC (x) && ! DECL_EXTERNAL (x))
  1944.         {
  1945.           /* Okay to redeclare an ANSI built-in as static.  */
  1946.           if (t != 0 && DECL_BUILT_IN (t))
  1947.         ;
  1948.           /* Okay to declare a non-ANSI built-in as anything.  */
  1949.           else if (t != 0 && DECL_BUILT_IN_NONANSI (t))
  1950.         ;
  1951.           else if (IDENTIFIER_IMPLICIT_DECL (name))
  1952.         pedwarn ("`%s' was declared implicitly `extern' and later `static'",
  1953.              IDENTIFIER_POINTER (name));
  1954.           else
  1955.         pedwarn ("`%s' was declared `extern' and later `static'",
  1956.              IDENTIFIER_POINTER (name));
  1957.         }
  1958.     }
  1959.       else
  1960.     {
  1961.       /* Here to install a non-global value.  */
  1962.       tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
  1963.       tree oldglobal = IDENTIFIER_GLOBAL_VALUE (name);
  1964.       IDENTIFIER_LOCAL_VALUE (name) = x;
  1965.  
  1966.       /* If this is an extern function declaration, see if we
  1967.          have a global definition or declaration for the function.  */
  1968.       if (oldlocal == 0
  1969.           && DECL_EXTERNAL (x) && !DECL_INLINE (x)
  1970.           && oldglobal != 0
  1971.           && TREE_CODE (x) == FUNCTION_DECL
  1972.           && TREE_CODE (oldglobal) == FUNCTION_DECL)
  1973.         {
  1974.           /* We have one.  Their types must agree.  */
  1975.           if (! comptypes (TREE_TYPE (x),
  1976.                    TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (name))))
  1977.         pedwarn_with_decl (x, "extern declaration of `%s' doesn't match global one");
  1978.           else
  1979.         {
  1980.           /* Inner extern decl is inline if global one is.
  1981.              Copy enough to really inline it.  */
  1982.           if (DECL_INLINE (oldglobal))
  1983.             {
  1984.               DECL_INLINE (x) = DECL_INLINE (oldglobal);
  1985.               DECL_INITIAL (x) = (current_function_decl == oldglobal
  1986.                       ? 0 : DECL_INITIAL (oldglobal));
  1987.               DECL_SAVED_INSNS (x) = DECL_SAVED_INSNS (oldglobal);
  1988.               DECL_ARGUMENTS (x) = DECL_ARGUMENTS (oldglobal);
  1989.               DECL_RESULT (x) = DECL_RESULT (oldglobal);
  1990.               TREE_ASM_WRITTEN (x) = TREE_ASM_WRITTEN (oldglobal);
  1991.               DECL_ABSTRACT_ORIGIN (x) = oldglobal;
  1992.             }
  1993.           /* Inner extern decl is built-in if global one is.  */
  1994.           if (DECL_BUILT_IN (oldglobal))
  1995.             {
  1996.               DECL_BUILT_IN (x) = DECL_BUILT_IN (oldglobal);
  1997.               DECL_SET_FUNCTION_CODE (x, DECL_FUNCTION_CODE (oldglobal));
  1998.             }
  1999.           /* Keep the arg types from a file-scope fcn defn.  */
  2000.           if (TYPE_ARG_TYPES (TREE_TYPE (oldglobal)) != 0
  2001.               && DECL_INITIAL (oldglobal)
  2002.               && TYPE_ARG_TYPES (TREE_TYPE (x)) == 0)
  2003.             TREE_TYPE (x) = TREE_TYPE (oldglobal);
  2004.         }
  2005.         }
  2006.  
  2007. #if 0 /* This case is probably sometimes the right thing to do.  */
  2008.       /* If we have a local external declaration,
  2009.          then any file-scope declaration should not
  2010.          have been static.  */
  2011.       if (oldlocal == 0 && oldglobal != 0
  2012.           && !TREE_PUBLIC (oldglobal)
  2013.           && DECL_EXTERNAL (x) && TREE_PUBLIC (x))
  2014.         warning ("`%s' locally external but globally static",
  2015.              IDENTIFIER_POINTER (name));
  2016. #endif
  2017.  
  2018.       /* If we have a local external declaration,
  2019.          and no file-scope declaration has yet been seen,
  2020.          then if we later have a file-scope decl it must not be static.  */
  2021.       if (oldlocal == 0
  2022.           && oldglobal == 0
  2023.           && DECL_EXTERNAL (x)
  2024.           && TREE_PUBLIC (x))
  2025.         {
  2026.           TREE_PUBLIC (name) = 1;
  2027.  
  2028.           /* Save this decl, so that we can do type checking against
  2029.          other decls after it falls out of scope.
  2030.  
  2031.          Only save it once.  This prevents temporary decls created in
  2032.          expand_inline_function from being used here, since this
  2033.          will have been set when the inline function was parsed.
  2034.          It also helps give slightly better warnings.  */
  2035.           if (IDENTIFIER_LIMBO_VALUE (name) == 0)
  2036.         IDENTIFIER_LIMBO_VALUE (name) = x;
  2037.         }
  2038.  
  2039.       /* Warn if shadowing an argument at the top level of the body.  */
  2040.       if (oldlocal != 0 && !DECL_EXTERNAL (x)
  2041.           /* This warning doesn't apply to the parms of a nested fcn.  */
  2042.           && ! current_binding_level->parm_flag
  2043.           /* Check that this is one level down from the parms.  */
  2044.           && current_binding_level->level_chain->parm_flag
  2045.           /* Check that the decl being shadowed
  2046.          comes from the parm level, one level up.  */
  2047.           && chain_member (oldlocal, current_binding_level->level_chain->names))
  2048.         {
  2049.           if (TREE_CODE (oldlocal) == PARM_DECL)
  2050.         pedwarn ("declaration of `%s' shadows a parameter",
  2051.              IDENTIFIER_POINTER (name));
  2052.           else
  2053.         pedwarn ("declaration of `%s' shadows a symbol from the parameter list",
  2054.              IDENTIFIER_POINTER (name));
  2055.         }
  2056.  
  2057.       /* Maybe warn if shadowing something else.  */
  2058.       else if (warn_shadow && !DECL_EXTERNAL (x)
  2059.            /* No shadow warnings for internally generated vars.  */
  2060.            && DECL_SOURCE_LINE (x) != 0
  2061.            /* No shadow warnings for vars made for inlining.  */
  2062.            && ! DECL_FROM_INLINE (x))
  2063.         {
  2064.           char *warnstring = 0;
  2065.  
  2066.           if (TREE_CODE (x) == PARM_DECL
  2067.           && current_binding_level->parm_flag == 1)
  2068.         /* Don't warn about the parm names in a declaration.  */
  2069.         ;
  2070.           else if (oldlocal != 0 && TREE_CODE (oldlocal) == PARM_DECL)
  2071.         warnstring = "declaration of `%s' shadows a parameter";
  2072.           else if (oldlocal != 0)
  2073.         warnstring = "declaration of `%s' shadows previous local";
  2074.           else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
  2075.                && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
  2076.         warnstring = "declaration of `%s' shadows global declaration";
  2077.  
  2078.           if (warnstring)
  2079.         warning (warnstring, IDENTIFIER_POINTER (name));
  2080.         }
  2081.  
  2082.       /* If storing a local value, there may already be one (inherited).
  2083.          If so, record it for restoration when this binding level ends.  */
  2084.       if (oldlocal != 0)
  2085.         b->shadowed = tree_cons (name, oldlocal, b->shadowed);
  2086.     }
  2087.  
  2088.       /* Keep count of variables in this level with incomplete type.  */
  2089.       if (TYPE_SIZE (TREE_TYPE (x)) == 0)
  2090.     ++b->n_incomplete;
  2091.     }
  2092.  
  2093.   /* Put decls on list in reverse order.
  2094.      We will reverse them later if necessary.  */
  2095.   TREE_CHAIN (x) = b->names;
  2096.   b->names = x;
  2097.  
  2098.   return x;
  2099. }
  2100.  
  2101. /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate.  */
  2102.  
  2103. tree
  2104. pushdecl_top_level (x)
  2105.      tree x;
  2106. {
  2107.   register tree t;
  2108.   register struct binding_level *b = current_binding_level;
  2109.  
  2110.   current_binding_level = global_binding_level;
  2111.   t = pushdecl (x);
  2112.   current_binding_level = b;
  2113.   return t;
  2114. }
  2115.  
  2116. /* Generate an implicit declaration for identifier FUNCTIONID
  2117.    as a function of type int ().  Print a warning if appropriate.  */
  2118.  
  2119. tree
  2120. implicitly_declare (functionid)
  2121.      tree functionid;
  2122. {
  2123.   register tree decl;
  2124.   int traditional_warning = 0;
  2125.   /* Only one "implicit declaration" warning per identifier.  */
  2126.   int implicit_warning;
  2127.  
  2128.   /* Save the decl permanently so we can warn if definition follows.  */
  2129.   push_obstacks_nochange ();
  2130.   end_temporary_allocation ();
  2131.  
  2132.   /* We used to reuse an old implicit decl here,
  2133.      but this loses with inline functions because it can clobber
  2134.      the saved decl chains.  */
  2135. /*  if (IDENTIFIER_IMPLICIT_DECL (functionid) != 0)
  2136.     decl = IDENTIFIER_IMPLICIT_DECL (functionid);
  2137.   else  */
  2138.     decl = build_decl (FUNCTION_DECL, functionid, default_function_type);
  2139.  
  2140.   /* Warn of implicit decl following explicit local extern decl.
  2141.      This is probably a program designed for traditional C.  */
  2142.   if (TREE_PUBLIC (functionid) && IDENTIFIER_GLOBAL_VALUE (functionid) == 0)
  2143.     traditional_warning = 1;
  2144.  
  2145.   /* Warn once of an implicit declaration.  */
  2146.   implicit_warning = (IDENTIFIER_IMPLICIT_DECL (functionid) == 0);
  2147.  
  2148.   DECL_EXTERNAL (decl) = 1;
  2149.   TREE_PUBLIC (decl) = 1;
  2150.  
  2151.   /* Record that we have an implicit decl and this is it.  */
  2152.   IDENTIFIER_IMPLICIT_DECL (functionid) = decl;
  2153.  
  2154.   /* ANSI standard says implicit declarations are in the innermost block.
  2155.      So we record the decl in the standard fashion.
  2156.      If flag_traditional is set, pushdecl does it top-level.  */
  2157.   pushdecl (decl);
  2158.  
  2159.   /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
  2160.   maybe_objc_check_decl (decl);
  2161.  
  2162.   rest_of_decl_compilation (decl, NULL_PTR, 0, 0);
  2163.  
  2164.   if (warn_implicit && implicit_warning)
  2165.     warning ("implicit declaration of function `%s'",
  2166.          IDENTIFIER_POINTER (functionid));
  2167.   else if (warn_traditional && traditional_warning)
  2168.     warning ("function `%s' was previously declared within a block",
  2169.          IDENTIFIER_POINTER (functionid));
  2170.  
  2171.   /* Write a record describing this implicit function declaration to the
  2172.      prototypes file (if requested).  */
  2173.  
  2174.   gen_aux_info_record (decl, 0, 1, 0);
  2175.  
  2176.   pop_obstacks ();
  2177.  
  2178.   return decl;
  2179. }
  2180.  
  2181. /* Return zero if the declaration NEWDECL is valid
  2182.    when the declaration OLDDECL (assumed to be for the same name)
  2183.    has already been seen.
  2184.    Otherwise return an error message format string with a %s
  2185.    where the identifier should go.  */
  2186.  
  2187. static char *
  2188. redeclaration_error_message (newdecl, olddecl)
  2189.      tree newdecl, olddecl;
  2190. {
  2191.   if (TREE_CODE (newdecl) == TYPE_DECL)
  2192.     {
  2193.       if (flag_traditional && TREE_TYPE (newdecl) == TREE_TYPE (olddecl))
  2194.     return 0;
  2195.       return "redefinition of `%s'";
  2196.     }
  2197.   else if (TREE_CODE (newdecl) == FUNCTION_DECL)
  2198.     {
  2199.       /* Declarations of functions can insist on internal linkage
  2200.      but they can't be inconsistent with internal linkage,
  2201.      so there can be no error on that account.
  2202.      However defining the same name twice is no good.  */
  2203.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0
  2204.       /* However, defining once as extern inline and a second
  2205.          time in another way is ok.  */
  2206.       && !(DECL_INLINE (olddecl) && DECL_EXTERNAL (olddecl)
  2207.            && !(DECL_INLINE (newdecl) && DECL_EXTERNAL (newdecl))))
  2208.     return "redefinition of `%s'";
  2209.       return 0;
  2210.     }
  2211.   else if (current_binding_level == global_binding_level)
  2212.     {
  2213.       /* Objects declared at top level:  */
  2214.       /* If at least one is a reference, it's ok.  */
  2215.       if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
  2216.     return 0;
  2217.       /* Reject two definitions.  */
  2218.       if (DECL_INITIAL (olddecl) != 0 && DECL_INITIAL (newdecl) != 0)
  2219.     return "redefinition of `%s'";
  2220.       /* Now we have two tentative defs, or one tentative and one real def.  */
  2221.       /* Insist that the linkage match.  */
  2222.       if (TREE_PUBLIC (olddecl) != TREE_PUBLIC (newdecl))
  2223.     return "conflicting declarations of `%s'";
  2224.       return 0;
  2225.     }
  2226.   else if (current_binding_level->parm_flag
  2227.        && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl))
  2228.     return 0;
  2229.   else
  2230.     {
  2231.       /* Objects declared with block scope:  */
  2232.       /* Reject two definitions, and reject a definition
  2233.      together with an external reference.  */
  2234.       if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
  2235.     return "redeclaration of `%s'";
  2236.       return 0;
  2237.     }
  2238. }
  2239.  
  2240. /* Get the LABEL_DECL corresponding to identifier ID as a label.
  2241.    Create one if none exists so far for the current function.
  2242.    This function is called for both label definitions and label references.  */
  2243.  
  2244. tree
  2245. lookup_label (id)
  2246.      tree id;
  2247. {
  2248.   register tree decl = IDENTIFIER_LABEL_VALUE (id);
  2249.  
  2250.   /* Use a label already defined or ref'd with this name.  */
  2251.   if (decl != 0)
  2252.     {
  2253.       /* But not if it is inherited and wasn't declared to be inheritable.  */
  2254.       if (DECL_CONTEXT (decl) != current_function_decl
  2255.       && ! C_DECLARED_LABEL_FLAG (decl))
  2256.     return shadow_label (id);
  2257.       return decl;
  2258.     }
  2259.  
  2260.   decl = build_decl (LABEL_DECL, id, void_type_node);
  2261.  
  2262.   /* Make sure every label has an rtx.  */
  2263.   label_rtx (decl);
  2264.  
  2265.   /* A label not explicitly declared must be local to where it's ref'd.  */
  2266.   DECL_CONTEXT (decl) = current_function_decl;
  2267.  
  2268.   DECL_MODE (decl) = VOIDmode;
  2269.  
  2270.   /* Say where one reference is to the label,
  2271.      for the sake of the error if it is not defined.  */
  2272.   DECL_SOURCE_LINE (decl) = lineno;
  2273.   DECL_SOURCE_FILE (decl) = input_filename;
  2274.  
  2275.   IDENTIFIER_LABEL_VALUE (id) = decl;
  2276.  
  2277.   named_labels = tree_cons (NULL_TREE, decl, named_labels);
  2278.  
  2279.   return decl;
  2280. }
  2281.  
  2282. /* Make a label named NAME in the current function,
  2283.    shadowing silently any that may be inherited from containing functions
  2284.    or containing scopes.
  2285.  
  2286.    Note that valid use, if the label being shadowed
  2287.    comes from another scope in the same function,
  2288.    requires calling declare_nonlocal_label right away.  */
  2289.  
  2290. tree
  2291. shadow_label (name)
  2292.      tree name;
  2293. {
  2294.   register tree decl = IDENTIFIER_LABEL_VALUE (name);
  2295.  
  2296.   if (decl != 0)
  2297.     {
  2298.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  2299.       IDENTIFIER_LABEL_VALUE (name) = decl = 0;
  2300.     }
  2301.  
  2302.   return lookup_label (name);
  2303. }
  2304.  
  2305. /* Define a label, specifying the location in the source file.
  2306.    Return the LABEL_DECL node for the label, if the definition is valid.
  2307.    Otherwise return 0.  */
  2308.  
  2309. tree
  2310. define_label (filename, line, name)
  2311.      char *filename;
  2312.      int line;
  2313.      tree name;
  2314. {
  2315.   tree decl = lookup_label (name);
  2316.  
  2317.   /* If label with this name is known from an outer context, shadow it.  */
  2318.   if (decl != 0 && DECL_CONTEXT (decl) != current_function_decl)
  2319.     {
  2320.       shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels);
  2321.       IDENTIFIER_LABEL_VALUE (name) = 0;
  2322.       decl = lookup_label (name);
  2323.     }
  2324.  
  2325.   if (DECL_INITIAL (decl) != 0)
  2326.     {
  2327.       error_with_decl (decl, "duplicate label `%s'");
  2328.       return 0;
  2329.     }
  2330.   else
  2331.     {
  2332.       /* Mark label as having been defined.  */
  2333.       DECL_INITIAL (decl) = error_mark_node;
  2334.       /* Say where in the source.  */
  2335.       DECL_SOURCE_FILE (decl) = filename;
  2336.       DECL_SOURCE_LINE (decl) = line;
  2337.       return decl;
  2338.     }
  2339. }
  2340.  
  2341. /* Return the list of declarations of the current level.
  2342.    Note that this list is in reverse order unless/until
  2343.    you nreverse it; and when you do nreverse it, you must
  2344.    store the result back using `storedecls' or you will lose.  */
  2345.  
  2346. tree
  2347. getdecls ()
  2348. {
  2349.   return current_binding_level->names;
  2350. }
  2351.  
  2352. /* Return the list of type-tags (for structs, etc) of the current level.  */
  2353.  
  2354. tree
  2355. gettags ()
  2356. {
  2357.   return current_binding_level->tags;
  2358. }
  2359.  
  2360. /* Store the list of declarations of the current level.
  2361.    This is done for the parameter declarations of a function being defined,
  2362.    after they are modified in the light of any missing parameters.  */
  2363.  
  2364. static void
  2365. storedecls (decls)
  2366.      tree decls;
  2367. {
  2368.   current_binding_level->names = decls;
  2369. }
  2370.  
  2371. /* Similarly, store the list of tags of the current level.  */
  2372.  
  2373. static void
  2374. storetags (tags)
  2375.      tree tags;
  2376. {
  2377.   current_binding_level->tags = tags;
  2378. }
  2379.  
  2380. /* Given NAME, an IDENTIFIER_NODE,
  2381.    return the structure (or union or enum) definition for that name.
  2382.    Searches binding levels from BINDING_LEVEL up to the global level.
  2383.    If THISLEVEL_ONLY is nonzero, searches only the specified context
  2384.    (but skips any tag-transparent contexts to find one that is
  2385.    meaningful for tags).
  2386.    CODE says which kind of type the caller wants;
  2387.    it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE.
  2388.    If the wrong kind of type is found, an error is reported.  */
  2389.  
  2390. static tree
  2391. lookup_tag (code, name, binding_level, thislevel_only)
  2392.      enum tree_code code;
  2393.      struct binding_level *binding_level;
  2394.      tree name;
  2395.      int thislevel_only;
  2396. {
  2397.   register struct binding_level *level;
  2398.  
  2399.   for (level = binding_level; level; level = level->level_chain)
  2400.     {
  2401.       register tree tail;
  2402.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2403.     {
  2404.       if (TREE_PURPOSE (tail) == name)
  2405.         {
  2406.           if (TREE_CODE (TREE_VALUE (tail)) != code)
  2407.         {
  2408.           /* Definition isn't the kind we were looking for.  */
  2409.           pending_invalid_xref = name;
  2410.           pending_invalid_xref_file = input_filename;
  2411.           pending_invalid_xref_line = lineno;
  2412.         }
  2413.           return TREE_VALUE (tail);
  2414.         }
  2415.     }
  2416.       if (thislevel_only && ! level->tag_transparent)
  2417.     return NULL_TREE;
  2418.     }
  2419.   return NULL_TREE;
  2420. }
  2421.  
  2422. /* Print an error message now
  2423.    for a recent invalid struct, union or enum cross reference.
  2424.    We don't print them immediately because they are not invalid
  2425.    when used in the `struct foo;' construct for shadowing.  */
  2426.  
  2427. void
  2428. pending_xref_error ()
  2429. {
  2430.   if (pending_invalid_xref != 0)
  2431.     error_with_file_and_line (pending_invalid_xref_file,
  2432.                   pending_invalid_xref_line,
  2433.                   "`%s' defined as wrong kind of tag",
  2434.                   IDENTIFIER_POINTER (pending_invalid_xref));
  2435.   pending_invalid_xref = 0;
  2436. }
  2437.  
  2438. /* Given a type, find the tag that was defined for it and return the tag name.
  2439.    Otherwise return 0.  */
  2440.  
  2441. static tree
  2442. lookup_tag_reverse (type)
  2443.      tree type;
  2444. {
  2445.   register struct binding_level *level;
  2446.  
  2447.   for (level = current_binding_level; level; level = level->level_chain)
  2448.     {
  2449.       register tree tail;
  2450.       for (tail = level->tags; tail; tail = TREE_CHAIN (tail))
  2451.     {
  2452.       if (TREE_VALUE (tail) == type)
  2453.         return TREE_PURPOSE (tail);
  2454.     }
  2455.     }
  2456.   return NULL_TREE;
  2457. }
  2458.  
  2459. /* Look up NAME in the current binding level and its superiors
  2460.    in the namespace of variables, functions and typedefs.
  2461.    Return a ..._DECL node of some kind representing its definition,
  2462.    or return 0 if it is undefined.  */
  2463.  
  2464. tree
  2465. lookup_name (name)
  2466.      tree name;
  2467. {
  2468.   register tree val;
  2469.   if (current_binding_level != global_binding_level
  2470.       && IDENTIFIER_LOCAL_VALUE (name))
  2471.     val = IDENTIFIER_LOCAL_VALUE (name);
  2472.   else
  2473.     val = IDENTIFIER_GLOBAL_VALUE (name);
  2474.   return val;
  2475. }
  2476.  
  2477. /* Similar to `lookup_name' but look only at current binding level.  */
  2478.  
  2479. static tree
  2480. lookup_name_current_level (name)
  2481.      tree name;
  2482. {
  2483.   register tree t;
  2484.  
  2485.   if (current_binding_level == global_binding_level)
  2486.     return IDENTIFIER_GLOBAL_VALUE (name);
  2487.  
  2488.   if (IDENTIFIER_LOCAL_VALUE (name) == 0)
  2489.     return 0;
  2490.  
  2491.   for (t = current_binding_level->names; t; t = TREE_CHAIN (t))
  2492.     if (DECL_NAME (t) == name)
  2493.       break;
  2494.  
  2495.   return t;
  2496. }
  2497.  
  2498. /* Create the predefined scalar types of C,
  2499.    and some nodes representing standard constants (0, 1, (void *)0).
  2500.    Initialize the global binding level.
  2501.    Make definitions for built-in primitive functions.  */
  2502.  
  2503. void
  2504. init_decl_processing ()
  2505. {
  2506.   register tree endlink;
  2507.   /* Either char* or void*.  */
  2508.   tree traditional_ptr_type_node;
  2509.   /* Data types of memcpy and strlen.  */
  2510.   tree memcpy_ftype, strlen_ftype;
  2511.   tree void_ftype_any;
  2512.   int wchar_type_size;
  2513.   tree temp;
  2514.  
  2515.   current_function_decl = NULL;
  2516.   named_labels = NULL;
  2517.   current_binding_level = NULL_BINDING_LEVEL;
  2518.   free_binding_level = NULL_BINDING_LEVEL;
  2519.   pushlevel (0);    /* make the binding_level structure for global names */
  2520.   global_binding_level = current_binding_level;
  2521.  
  2522.   /* Define `int' and `char' first so that dbx will output them first.  */
  2523.  
  2524.   integer_type_node = make_signed_type (INT_TYPE_SIZE);
  2525.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_INT],
  2526.             integer_type_node));
  2527.  
  2528.   /* Define `char', which is like either `signed char' or `unsigned char'
  2529.      but not the same as either.  */
  2530.  
  2531.   char_type_node
  2532.     = (flag_signed_char
  2533.        ? make_signed_type (CHAR_TYPE_SIZE)
  2534.        : make_unsigned_type (CHAR_TYPE_SIZE));
  2535.   pushdecl (build_decl (TYPE_DECL, get_identifier ("char"),
  2536.             char_type_node));
  2537.  
  2538.   long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
  2539.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long int"),
  2540.             long_integer_type_node));
  2541.  
  2542.   unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE);
  2543.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned int"),
  2544.             unsigned_type_node));
  2545.  
  2546.   long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE);
  2547.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long unsigned int"),
  2548.             long_unsigned_type_node));
  2549.  
  2550.   /* `unsigned long' is the standard type for sizeof.
  2551.      Traditionally, use a signed type.
  2552.      Note that stddef.h uses `unsigned long',
  2553.      and this must agree, even of long and int are the same size.  */
  2554.   if (flag_traditional)
  2555.     sizetype = long_integer_type_node;
  2556.   else
  2557.     sizetype
  2558.       = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)));
  2559.  
  2560.   ptrdiff_type_node
  2561.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE)));
  2562.  
  2563.   TREE_TYPE (TYPE_SIZE (integer_type_node)) = sizetype;
  2564.   TREE_TYPE (TYPE_SIZE (char_type_node)) = sizetype;
  2565.   TREE_TYPE (TYPE_SIZE (unsigned_type_node)) = sizetype;
  2566.   TREE_TYPE (TYPE_SIZE (long_unsigned_type_node)) = sizetype;
  2567.   TREE_TYPE (TYPE_SIZE (long_integer_type_node)) = sizetype;
  2568.  
  2569.   error_mark_node = make_node (ERROR_MARK);
  2570.   TREE_TYPE (error_mark_node) = error_mark_node;
  2571.  
  2572.   short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE);
  2573.   pushdecl (build_decl (TYPE_DECL, get_identifier ("short int"),
  2574.             short_integer_type_node));
  2575.  
  2576.   long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE);
  2577.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long int"),
  2578.             long_long_integer_type_node));
  2579.  
  2580.   short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE);
  2581.   pushdecl (build_decl (TYPE_DECL, get_identifier ("short unsigned int"),
  2582.             short_unsigned_type_node));
  2583.  
  2584.   long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE);
  2585.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long long unsigned int"),
  2586.             long_long_unsigned_type_node));
  2587.  
  2588.   /* Define both `signed char' and `unsigned char'.  */
  2589.   signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE);
  2590.   pushdecl (build_decl (TYPE_DECL, get_identifier ("signed char"),
  2591.             signed_char_type_node));
  2592.  
  2593.   unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE);
  2594.   pushdecl (build_decl (TYPE_DECL, get_identifier ("unsigned char"),
  2595.             unsigned_char_type_node));
  2596.  
  2597.   intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode));
  2598.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node));
  2599.  
  2600.   intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode));
  2601.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node));
  2602.  
  2603.   intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode));
  2604.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node));
  2605.  
  2606.   intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode));
  2607.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node));
  2608.  
  2609.   unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode));
  2610.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node));
  2611.  
  2612.   unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode));
  2613.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node));
  2614.  
  2615.   unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode));
  2616.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node));
  2617.  
  2618.   unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode));
  2619.   pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node));
  2620.  
  2621.   float_type_node = make_node (REAL_TYPE);
  2622.   TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE;
  2623.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
  2624.             float_type_node));
  2625.   layout_type (float_type_node);
  2626.  
  2627.   double_type_node = make_node (REAL_TYPE);
  2628.   if (flag_short_double)
  2629.     TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE;
  2630.   else
  2631.     TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE;
  2632.   pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
  2633.             double_type_node));
  2634.   layout_type (double_type_node);
  2635.  
  2636.   long_double_type_node = make_node (REAL_TYPE);
  2637.   TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE;
  2638.   pushdecl (build_decl (TYPE_DECL, get_identifier ("long double"),
  2639.             long_double_type_node));
  2640.   layout_type (long_double_type_node);
  2641.  
  2642.   /* Maybe add recognizers for `comp' and `extended' type keywords.
  2643.      They are identical to `long long' and `long double'. */
  2644.   if (flag_apple)
  2645.     {
  2646.       pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_COMP],
  2647.                 long_long_integer_type_node));
  2648.       pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_EXTENDED],
  2649.                 long_double_type_node));
  2650.     }
  2651.  
  2652.   wchar_type_node
  2653.     = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE)));
  2654.   wchar_type_size = TYPE_PRECISION (wchar_type_node);
  2655.   signed_wchar_type_node = type_for_size (wchar_type_size, 0);
  2656.   unsigned_wchar_type_node = type_for_size (wchar_type_size, 1);
  2657.  
  2658.   integer_zero_node = build_int_2 (0, 0);
  2659.   TREE_TYPE (integer_zero_node) = integer_type_node;
  2660.   integer_one_node = build_int_2 (1, 0);
  2661.   TREE_TYPE (integer_one_node) = integer_type_node;
  2662.  
  2663.   size_zero_node = build_int_2 (0, 0);
  2664.   TREE_TYPE (size_zero_node) = sizetype;
  2665.   size_one_node = build_int_2 (1, 0);
  2666.   TREE_TYPE (size_one_node) = sizetype;
  2667.  
  2668.   void_type_node = make_node (VOID_TYPE);
  2669.   pushdecl (build_decl (TYPE_DECL,
  2670.             ridpointers[(int) RID_VOID], void_type_node));
  2671.   layout_type (void_type_node);    /* Uses integer_zero_node */
  2672.   /* We are not going to have real types in C with less than byte alignment,
  2673.      so we might as well not have any types that claim to have it.  */
  2674.   TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
  2675.  
  2676. #ifdef PTR_HACK
  2677.   null_DPpointer_node = build_int_2 (0, 0);
  2678.   TREE_TYPE (null_DPpointer_node) = copy_node(build_pointer_type (void_type_node));
  2679.   layout_type (TREE_TYPE (null_DPpointer_node));
  2680.   TYPE_MODE(TREE_TYPE (null_TPpointer_node)) = DPmode;
  2681.   null_TPpointer_node = build_int_2 (0, 0);
  2682.   TREE_TYPE (null_TPpointer_node) = copy_node(build_pointer_type (void_type_node));
  2683.   layout_type (TREE_TYPE (null_TPpointer_node));
  2684.   TYPE_MODE(TREE_TYPE (null_TPpointer_node)) = TPmode;
  2685. #else
  2686.   null_pointer_node = build_int_2 (0, 0);
  2687.   TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node);
  2688.   layout_type (TREE_TYPE (null_pointer_node));
  2689. #endif
  2690.  
  2691.   string_type_node = build_pointer_type (char_type_node);
  2692.   const_string_type_node
  2693.     = build_pointer_type (build_type_variant (char_type_node, 1, 0));
  2694.  
  2695.   /* make a type for arrays of 256 characters.
  2696.      256 is picked randomly because we have a type for integers from 0 to 255.
  2697.      With luck nothing will ever really depend on the length of this
  2698.      array type.  */
  2699.   char_array_type_node
  2700.     = build_array_type (char_type_node, unsigned_char_type_node);
  2701.   /* Likewise for arrays of ints.  */
  2702.   int_array_type_node
  2703.     = build_array_type (integer_type_node, unsigned_char_type_node);
  2704.   /* This is for wide string constants.  */
  2705.   wchar_array_type_node
  2706.     = build_array_type (wchar_type_node, unsigned_char_type_node);
  2707.  
  2708.   default_function_type
  2709.     = build_function_type (integer_type_node, NULL_TREE);
  2710.  
  2711.   ptr_type_node = build_pointer_type (void_type_node);
  2712.   const_ptr_type_node
  2713.     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
  2714.  
  2715.   endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
  2716.  
  2717.   void_ftype_any
  2718.     = build_function_type (void_type_node, NULL_TREE);
  2719.  
  2720.   double_ftype_double
  2721.     = build_function_type (double_type_node,
  2722.                tree_cons (NULL_TREE, double_type_node, endlink));
  2723.  
  2724.   /* If Apple extensions are enabled, we need a function type to go with some
  2725.      of the library functions that take and return extended floats. */
  2726.   if (flag_apple)
  2727.     {
  2728.       /* Initialize the "extended arg returning extended" function type. */
  2729.       extended_ftype_extended
  2730.         = build_function_type (long_double_type_node,
  2731.                    tree_cons (NULL_TREE,
  2732.                       long_double_type_node, endlink));
  2733.     }
  2734.  
  2735.   double_ftype_double_double
  2736.     = build_function_type (double_type_node,
  2737.                tree_cons (NULL_TREE, double_type_node,
  2738.                       tree_cons (NULL_TREE,
  2739.                          double_type_node, endlink)));
  2740.  
  2741.   int_ftype_int
  2742.     = build_function_type (integer_type_node,
  2743.                tree_cons (NULL_TREE, integer_type_node, endlink));
  2744.  
  2745.   long_ftype_long
  2746.     = build_function_type (long_integer_type_node,
  2747.                tree_cons (NULL_TREE,
  2748.                       long_integer_type_node, endlink));
  2749.  
  2750.   void_ftype_ptr_ptr_int
  2751.     = build_function_type (void_type_node,
  2752.                tree_cons (NULL_TREE, ptr_type_node,
  2753.                       tree_cons (NULL_TREE, ptr_type_node,
  2754.                          tree_cons (NULL_TREE,
  2755.                                 integer_type_node,
  2756.                                 endlink))));
  2757.  
  2758.   int_ftype_cptr_cptr_sizet
  2759.     = build_function_type (integer_type_node,
  2760.                tree_cons (NULL_TREE, const_ptr_type_node,
  2761.                       tree_cons (NULL_TREE, const_ptr_type_node,
  2762.                          tree_cons (NULL_TREE,
  2763.                                 sizetype,
  2764.                                 endlink))));
  2765.  
  2766.   void_ftype_ptr_int_int
  2767.     = build_function_type (void_type_node,
  2768.                tree_cons (NULL_TREE, ptr_type_node,
  2769.                       tree_cons (NULL_TREE, integer_type_node,
  2770.                          tree_cons (NULL_TREE,
  2771.                                 integer_type_node,
  2772.                                 endlink))));
  2773.  
  2774.   string_ftype_ptr_ptr        /* strcpy prototype */
  2775.     = build_function_type (string_type_node,
  2776.                tree_cons (NULL_TREE, string_type_node,
  2777.                       tree_cons (NULL_TREE,
  2778.                          const_string_type_node,
  2779.                          endlink)));
  2780.  
  2781.   int_ftype_string_string    /* strcmp prototype */
  2782.     = build_function_type (integer_type_node,
  2783.                tree_cons (NULL_TREE, const_string_type_node,
  2784.                       tree_cons (NULL_TREE,
  2785.                          const_string_type_node,
  2786.                          endlink)));
  2787.  
  2788.   strlen_ftype        /* strlen prototype */
  2789.     = build_function_type (flag_traditional ? integer_type_node : sizetype,
  2790.                tree_cons (NULL_TREE, const_string_type_node,
  2791.                       endlink));
  2792.  
  2793.   traditional_ptr_type_node
  2794.     = (flag_traditional ? string_type_node : ptr_type_node);
  2795.  
  2796.   memcpy_ftype    /* memcpy prototype */
  2797.     = build_function_type (traditional_ptr_type_node,
  2798.                tree_cons (NULL_TREE, ptr_type_node,
  2799.                       tree_cons (NULL_TREE, const_ptr_type_node,
  2800.                          tree_cons (NULL_TREE,
  2801.                                 sizetype,
  2802.                                 endlink))));
  2803.  
  2804.   /* ``integer_tpe_node'' misspelling corrected: North-Keys 30 Mar 91 */
  2805.   builtin_function ("__builtin_constant_p", int_ftype_int,
  2806.             BUILT_IN_CONSTANT_P, NULL_PTR);
  2807.  
  2808.   builtin_function ("__builtin_return_address",
  2809.             build_function_type (ptr_type_node, 
  2810.                      tree_cons (NULL_TREE,
  2811.                             unsigned_type_node,
  2812.                             endlink)),
  2813.             BUILT_IN_RETURN_ADDRESS, NULL_PTR);
  2814.  
  2815.   builtin_function ("__builtin_frame_address",
  2816.             build_function_type (ptr_type_node, 
  2817.                      tree_cons (NULL_TREE,
  2818.                             unsigned_type_node,
  2819.                             endlink)),
  2820.             BUILT_IN_FRAME_ADDRESS, NULL_PTR);
  2821.  
  2822.   builtin_function ("__builtin_alloca",
  2823.             build_function_type (ptr_type_node,
  2824.                      tree_cons (NULL_TREE,
  2825.                             sizetype,
  2826.                             endlink)),
  2827.             BUILT_IN_ALLOCA, "alloca");
  2828.   if (! flag_no_builtin && !flag_no_nonansi_builtin)
  2829.     {
  2830.       temp = builtin_function ("alloca",
  2831.                    build_function_type (ptr_type_node,
  2832.                             tree_cons (NULL_TREE,
  2833.                                    sizetype,
  2834.                                    endlink)),
  2835.                    BUILT_IN_ALLOCA, NULL_PTR);
  2836.       /* Suppress error if redefined as a non-function.  */
  2837.       DECL_BUILT_IN_NONANSI (temp) = 1;
  2838.       temp = builtin_function ("_exit", void_ftype_any, NOT_BUILT_IN,
  2839.                    NULL_PTR);
  2840.       TREE_THIS_VOLATILE (temp) = 1;
  2841.       TREE_SIDE_EFFECTS (temp) = 1;
  2842.       /* Suppress error if redefined as a non-function.  */
  2843.       DECL_BUILT_IN_NONANSI (temp) = 1;
  2844.     }
  2845.  
  2846.   builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
  2847.   builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS,
  2848.             NULL_PTR);
  2849.   builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS,
  2850.             NULL_PTR);
  2851.   builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR);
  2852.   builtin_function ("__builtin_saveregs",
  2853.             build_function_type (ptr_type_node, NULL_TREE),
  2854.             BUILT_IN_SAVEREGS, NULL_PTR);
  2855. /* EXPAND_BUILTIN_VARARGS is obsolete.  */
  2856. #if 0
  2857.   builtin_function ("__builtin_varargs",
  2858.             build_function_type (ptr_type_node,
  2859.                      tree_cons (NULL_TREE,
  2860.                             integer_type_node,
  2861.                             endlink)),
  2862.             BUILT_IN_VARARGS, NULL_PTR);
  2863. #endif
  2864.   builtin_function ("__builtin_classify_type", default_function_type,
  2865.             BUILT_IN_CLASSIFY_TYPE, NULL_PTR);
  2866.   builtin_function ("__builtin_next_arg",
  2867.             build_function_type (ptr_type_node, endlink),
  2868.             BUILT_IN_NEXT_ARG, NULL_PTR);
  2869.   builtin_function ("__builtin_args_info",
  2870.             build_function_type (integer_type_node,
  2871.                      tree_cons (NULL_TREE,
  2872.                             integer_type_node,
  2873.                             endlink)),
  2874.             BUILT_IN_ARGS_INFO, NULL_PTR);
  2875.  
  2876.   /* Currently under experimentation.  */
  2877.   builtin_function ("__builtin_memcpy", memcpy_ftype,
  2878.             BUILT_IN_MEMCPY, "memcpy");
  2879.   builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet,
  2880.             BUILT_IN_MEMCMP, "memcmp");
  2881.   builtin_function ("__builtin_strcmp", int_ftype_string_string,
  2882.             BUILT_IN_STRCMP, "strcmp");
  2883.   builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr,
  2884.             BUILT_IN_STRCPY, "strcpy");
  2885.   builtin_function ("__builtin_strlen", strlen_ftype,
  2886.             BUILT_IN_STRLEN, "strlen");
  2887.   builtin_function ("__builtin_fsqrt", double_ftype_double, 
  2888.             BUILT_IN_FSQRT, "sqrt");
  2889.   builtin_function ("__builtin_sin", double_ftype_double, 
  2890.             BUILT_IN_SIN, "sin");
  2891.   builtin_function ("__builtin_cos", double_ftype_double, 
  2892.             BUILT_IN_COS, "cos");
  2893.  
  2894.   /* In an ANSI C program, it is okay to supply built-in meanings
  2895.      for these functions, since applications cannot validly use them
  2896.      with any other meaning.
  2897.      However, honor the -fno-builtin option.  */
  2898.   if (!flag_no_builtin)
  2899.     {
  2900.       builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR);
  2901.       /* The default float type is extended in Apple C. */
  2902.       if (flag_apple)
  2903.         {
  2904.           builtin_function ("fabs", extended_ftype_extended, BUILT_IN_FABS, NULL_PTR);
  2905.     }
  2906.       else
  2907.         {
  2908.           builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR);
  2909.     }
  2910.       builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR);
  2911.       builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR);
  2912.       builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP,
  2913.             NULL_PTR);
  2914.       builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP,
  2915.             NULL_PTR);
  2916.       builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY,
  2917.             NULL_PTR);
  2918.       builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR);
  2919.  
  2920.       /* Declare these functions volatile
  2921.      to avoid spurious "control drops through" warnings.  */
  2922.       /* Don't specify the argument types, to avoid errors
  2923.      from certain code which isn't valid in ANSI but which exists.  */
  2924.       temp = builtin_function ("abort", void_ftype_any, NOT_BUILT_IN,
  2925.                    NULL_PTR);
  2926.       TREE_THIS_VOLATILE (temp) = 1;
  2927.       TREE_SIDE_EFFECTS (temp) = 1;
  2928.       temp = builtin_function ("exit", void_ftype_any, NOT_BUILT_IN, NULL_PTR);
  2929.       TREE_THIS_VOLATILE (temp) = 1;
  2930.       TREE_SIDE_EFFECTS (temp) = 1;
  2931.     }
  2932.  
  2933. #if 0
  2934.   /* Support for these has not been written in either expand_builtin
  2935.      or build_function_call.  */
  2936.   builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR);
  2937.   builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR);
  2938.   builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR,
  2939.             NULL_PTR);
  2940.   builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL,
  2941.             NULL_PTR);
  2942.   builtin_function ("__builtin_fmod", double_ftype_double_double,
  2943.             BUILT_IN_FMOD, NULL_PTR);
  2944.   builtin_function ("__builtin_frem", double_ftype_double_double,
  2945.             BUILT_IN_FREM, NULL_PTR);
  2946.   builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int,
  2947.             BUILT_IN_MEMSET, NULL_PTR);
  2948.   builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP,
  2949.             NULL_PTR);
  2950.   builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN,
  2951.             NULL_PTR);
  2952. #endif
  2953.   /* Hook to add extra builtin functions. */
  2954. #ifdef ADDITIONAL_BUILTINS
  2955.   ADDITIONAL_BUILTINS;
  2956. #endif
  2957.  
  2958.   /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__.  */
  2959.   declare_function_name ();
  2960.  
  2961.   start_identifier_warnings ();
  2962.  
  2963.   init_format_info_table ();
  2964. }
  2965.  
  2966. /* Return a definition for a builtin function named NAME and whose data type
  2967.    is TYPE.  TYPE should be a function type with argument types.
  2968.    FUNCTION_CODE tells later passes how to compile calls to this function.
  2969.    See tree.h for its possible values.
  2970.  
  2971.    If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
  2972.    the name to be called if we can't opencode the function.  */
  2973.  
  2974. tree
  2975. builtin_function (name, type, function_code, library_name)
  2976.      char *name;
  2977.      tree type;
  2978.      enum built_in_function function_code;
  2979.      char *library_name;
  2980. {
  2981.   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
  2982.   DECL_EXTERNAL (decl) = 1;
  2983.   TREE_PUBLIC (decl) = 1;
  2984.   /* If -traditional, permit redefining a builtin function any way you like.
  2985.      (Though really, if the program redefines these functions,
  2986.      it probably won't work right unless compiled with -fno-builtin.)  */
  2987.   if (flag_traditional && name[0] != '_')
  2988.     DECL_BUILT_IN_NONANSI (decl) = 1;
  2989.   if (library_name)
  2990.     DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
  2991.   make_decl_rtl (decl, NULL_PTR, 1);
  2992.   pushdecl (decl);
  2993.   if (function_code != NOT_BUILT_IN)
  2994.     {
  2995.       DECL_BUILT_IN (decl) = 1;
  2996.       DECL_SET_FUNCTION_CODE (decl, function_code);
  2997.     }
  2998.   /* Warn if a function in the namespace for users
  2999.      is used without an occasion to consider it declared.  */
  3000.   if (name[0] != '_' || name[1] != '_')
  3001.     C_DECL_ANTICIPATED (decl) = 1;
  3002.  
  3003.   return decl;
  3004. }
  3005.  
  3006. /* Called when a declaration is seen that contains no names to declare.
  3007.    If its type is a reference to a structure, union or enum inherited
  3008.    from a containing scope, shadow that tag name for the current scope
  3009.    with a forward reference.
  3010.    If its type defines a new named structure or union
  3011.    or defines an enum, it is valid but we need not do anything here.
  3012.    Otherwise, it is an error.  */
  3013.  
  3014. void
  3015. shadow_tag (declspecs)
  3016.      tree declspecs;
  3017. {
  3018.   shadow_tag_warned (declspecs, 0);
  3019. }
  3020.  
  3021. void
  3022. shadow_tag_warned (declspecs, warned)
  3023.      tree declspecs;
  3024.      int warned;
  3025. {
  3026.   int found_tag = 0;
  3027.   register tree link;
  3028.  
  3029.   pending_invalid_xref = 0;
  3030.  
  3031.   for (link = declspecs; link; link = TREE_CHAIN (link))
  3032.     {
  3033.       register tree value = TREE_VALUE (link);
  3034.       register enum tree_code code = TREE_CODE (value);
  3035.  
  3036.       if (code == RECORD_TYPE || code == UNION_TYPE || code == ENUMERAL_TYPE)
  3037.     /* Used to test also that TYPE_SIZE (value) != 0.
  3038.        That caused warning for `struct foo;' at top level in the file.  */
  3039.     {
  3040.       register tree name = lookup_tag_reverse (value);
  3041.       register tree t;
  3042.  
  3043.       found_tag++;
  3044.  
  3045.       if (name == 0)
  3046.         {
  3047.           if (!warned && code != ENUMERAL_TYPE) /* Empty unnamed enum OK */
  3048.         {
  3049.           pedwarn ("unnamed struct/union that defines no instances");
  3050.           warned = 1;
  3051.         }
  3052.         }
  3053.       else
  3054.         {
  3055.           t = lookup_tag (code, name, current_binding_level, 1);
  3056.  
  3057.           if (t == 0)
  3058.         {
  3059.           t = make_node (code);
  3060.           pushtag (name, t);
  3061.         }
  3062.         }
  3063.     }
  3064.       else
  3065.     {
  3066.       if (!warned)
  3067.         pedwarn ("useless keyword or type name in empty declaration");
  3068.       warned = 1;
  3069.     }
  3070.     }
  3071.  
  3072.   if (!warned)
  3073.     {
  3074.       if (found_tag > 1)
  3075.     error ("two types specified in one empty declaration");
  3076.       if (found_tag == 0)
  3077.     pedwarn ("empty declaration");
  3078.     }
  3079. }
  3080.  
  3081. /* Decode a "typename", such as "int **", returning a ..._TYPE node.  */
  3082.  
  3083. tree
  3084. groktypename (typename)
  3085.      tree typename;
  3086. {
  3087.   if (TREE_CODE (typename) != TREE_LIST)
  3088.     return typename;
  3089.   return grokdeclarator (TREE_VALUE (typename),
  3090.              TREE_PURPOSE (typename),
  3091.              TYPENAME, 0);
  3092. }
  3093.  
  3094. /* Return a PARM_DECL node for a given pair of specs and declarator.  */
  3095.  
  3096. tree
  3097. groktypename_in_parm_context (typename)
  3098.      tree typename;
  3099. {
  3100.   if (TREE_CODE (typename) != TREE_LIST)
  3101.     return typename;
  3102.   return grokdeclarator (TREE_VALUE (typename),
  3103.              TREE_PURPOSE (typename),
  3104.              PARM, 0);
  3105. }
  3106.  
  3107. /* Decode a declarator in an ordinary declaration or data definition.
  3108.    This is called as soon as the type information and variable name
  3109.    have been parsed, before parsing the initializer if any.
  3110.    Here we create the ..._DECL node, fill in its type,
  3111.    and put it on the list of decls for the current context.
  3112.    The ..._DECL node is returned as the value.
  3113.  
  3114.    Exception: for arrays where the length is not specified,
  3115.    the type is left null, to be filled in by `finish_decl'.
  3116.  
  3117.    Function definitions do not come here; they go to start_function
  3118.    instead.  However, external and forward declarations of functions
  3119.    do go through here.  Structure field declarations are done by
  3120.    grokfield and not through here.  */
  3121.  
  3122. /* Set this to zero to debug not using the temporary obstack
  3123.    to parse initializers.  */
  3124. int debug_temp_inits = 1;
  3125.  
  3126. tree
  3127. start_decl (declarator, declspecs, initialized)
  3128.      tree declspecs, declarator;
  3129.      int initialized;
  3130. {
  3131.   register tree decl = grokdeclarator (declarator, declspecs,
  3132.                        NORMAL, initialized);
  3133.   register tree tem;
  3134.   int init_written = initialized;
  3135.  
  3136.   /* The corresponding pop_obstacks is in finish_decl.  */
  3137.   push_obstacks_nochange ();
  3138.  
  3139.   if (initialized)
  3140.     /* Is it valid for this decl to have an initializer at all?
  3141.        If not, set INITIALIZED to zero, which will indirectly
  3142.        tell `finish_decl' to ignore the initializer once it is parsed.  */
  3143.     switch (TREE_CODE (decl))
  3144.       {
  3145.       case TYPE_DECL:
  3146.     /* typedef foo = bar  means give foo the same type as bar.
  3147.        We haven't parsed bar yet, so `finish_decl' will fix that up.
  3148.        Any other case of an initialization in a TYPE_DECL is an error.  */
  3149.     if (pedantic || list_length (declspecs) > 1)
  3150.       {
  3151.         error ("typedef `%s' is initialized",
  3152.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3153.         initialized = 0;
  3154.       }
  3155.     break;
  3156.  
  3157.       case FUNCTION_DECL:
  3158.         /* If Apple extensions are enabled, we recognize direct function
  3159.        definitions. */
  3160.         if (flag_apple)
  3161.       {
  3162.         /* A direct function definition looks exactly like a function
  3163.            being initialized like a variable.  We don't need to do anything
  3164.            with the initialization yet. */
  3165.         TREE_DIRECT (decl) = 1;
  3166.         break;
  3167.       }
  3168.     error ("function `%s' is initialized like a variable",
  3169.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3170.     initialized = 0;
  3171.     break;
  3172.  
  3173.       case PARM_DECL:
  3174.     /* DECL_INITIAL in a PARM_DECL is really DECL_ARG_TYPE.  */
  3175.     error ("parameter `%s' is initialized",
  3176.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3177.     initialized = 0;
  3178.     break;
  3179.  
  3180.       default:
  3181.     /* Don't allow initializations for incomplete types
  3182.        except for arrays which might be completed by the initialization.  */
  3183.     if (TYPE_SIZE (TREE_TYPE (decl)) != 0)
  3184.       {
  3185.         /* A complete type is ok if size is fixed.  */
  3186.  
  3187.         if (TREE_CODE (TYPE_SIZE (TREE_TYPE (decl))) != INTEGER_CST
  3188.         || C_DECL_VARIABLE_SIZE (decl))
  3189.           {
  3190.         error ("variable-sized object may not be initialized");
  3191.         initialized = 0;
  3192.           }
  3193.       }
  3194.     else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
  3195.       {
  3196.         error ("variable `%s' has initializer but incomplete type",
  3197.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3198.         initialized = 0;
  3199.       }
  3200.     else if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))) == 0)
  3201.       {
  3202.         error ("elements of array `%s' have incomplete type",
  3203.            IDENTIFIER_POINTER (DECL_NAME (decl)));
  3204.         initialized = 0;
  3205.       }
  3206.       }
  3207.  
  3208.   if (initialized)
  3209.     {
  3210. #if 0  /* Seems redundant with grokdeclarator.  */
  3211.       if (current_binding_level != global_binding_level
  3212.       && DECL_EXTERNAL (decl)
  3213.       && TREE_CODE (decl) != FUNCTION_DECL)
  3214.     warning ("declaration of `%s' has `extern' and is initialized",
  3215.          IDENTIFIER_POINTER (DECL_NAME (decl)));
  3216. #endif
  3217.       DECL_EXTERNAL (decl) = 0;
  3218.       if (current_binding_level == global_binding_level)
  3219.     TREE_STATIC (decl) = 1;
  3220.  
  3221.       /* Tell `pushdecl' this is an initialized decl
  3222.      even though we don't yet have the initializer expression.
  3223.      Also tell `finish_decl' it may store the real initializer.  */
  3224.       DECL_INITIAL (decl) = error_mark_node;
  3225.     }
  3226.  
  3227.   /* If this is a function declaration, write a record describing it to the
  3228.      prototypes file (if requested).  */
  3229.  
  3230.   if (TREE_CODE (decl) == FUNCTION_DECL)
  3231.     gen_aux_info_record (decl, 0, 0, TYPE_ARG_TYPES (TREE_TYPE (decl)) != 0);
  3232.  
  3233.   /* Add this decl to the current binding level.
  3234.      TEM may equal DECL or it may be a previous decl of the same name.  */
  3235.   tem = pushdecl (decl);
  3236.  
  3237.   /* For a local variable, define the RTL now.  */
  3238.   if (current_binding_level != global_binding_level
  3239.       /* But not if this is a duplicate decl
  3240.      and we preserved the rtl from the previous one
  3241.      (which may or may not happen).  */
  3242.       && DECL_RTL (tem) == 0)
  3243.     {
  3244.       if (TYPE_SIZE (TREE_TYPE (tem)) != 0)
  3245.     expand_decl (tem);
  3246.       else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE
  3247.            && DECL_INITIAL (tem) != 0)
  3248.     expand_decl (tem);
  3249.     }
  3250.  
  3251.   if (init_written)
  3252.     {
  3253.       /* When parsing and digesting the initializer,
  3254.      use temporary storage.  Do this even if we will ignore the value.  */
  3255.       if (current_binding_level == global_binding_level && debug_temp_inits)
  3256.     temporary_allocation ();
  3257.     }
  3258. #ifdef APPLE_ASM  /* never used?? */
  3259.   if (current_binding_level == global_binding_level && flag_apple)
  3260.     start_module (IDENTIFIER_POINTER (DECL_NAME (decl)));
  3261. #endif
  3262.  
  3263.   return tem;
  3264. }
  3265.  
  3266. /* Finish processing of a declaration;
  3267.    install its initial value.
  3268.    If the length of an array type is not known before,
  3269.    it must be determined now, from the initial value, or it is an error.  */
  3270.  
  3271. void
  3272. finish_decl (decl, init, asmspec_tree)
  3273.      tree decl, init;
  3274.      tree asmspec_tree;
  3275. {
  3276.   register tree type = TREE_TYPE (decl);
  3277.   int was_incomplete = (DECL_SIZE (decl) == 0);
  3278.   int temporary = allocation_temporary_p ();
  3279.   char *asmspec = 0;
  3280.  
  3281.   if (asmspec_tree)
  3282.     asmspec = TREE_STRING_POINTER (asmspec_tree);
  3283.  
  3284.   /* If `start_decl' didn't like having an initialization, ignore it now.  */
  3285.  
  3286.   if (init != 0 && DECL_INITIAL (decl) == 0)
  3287.     init = 0;
  3288.   /* Don't crash if parm is initialized.  */
  3289.   if (TREE_CODE (decl) == PARM_DECL)
  3290.     init = 0;
  3291.  
  3292.   if (init)
  3293.     {
  3294.       if (TREE_CODE (decl) != TYPE_DECL)
  3295.     store_init_value (decl, init);
  3296.       else
  3297.     {
  3298.       /* typedef foo = bar; store the type of bar as the type of foo.  */
  3299.       TREE_TYPE (decl) = TREE_TYPE (init);
  3300.       DECL_INITIAL (decl) = init = 0;
  3301.     }
  3302.     }
  3303.  
  3304.   /* Pop back to the obstack that is current for this binding level.
  3305.      This is because MAXINDEX, rtl, etc. to be made below
  3306.      must go in the permanent obstack.  But don't discard the
  3307.      temporary data yet.  */
  3308.   pop_obstacks ();
  3309. #if 0 /* pop_obstacks was near the end; this is what was here.  */
  3310.   if (current_binding_level == global_binding_level && temporary)
  3311.     end_temporary_allocation ();
  3312. #endif
  3313.  
  3314.   /* Deduce size of array from initialization, if not already known */
  3315.  
  3316.   if (TREE_CODE (type) == ARRAY_TYPE
  3317.       && TYPE_DOMAIN (type) == 0
  3318.       && TREE_CODE (decl) != TYPE_DECL)
  3319.     {
  3320.       int do_default
  3321.     = (TREE_STATIC (decl)
  3322.        /* Even if pedantic, an external linkage array
  3323.           may have incomplete type at first.  */
  3324.        ? pedantic && !TREE_PUBLIC (decl)
  3325.        : !DECL_EXTERNAL (decl));
  3326.       int failure
  3327.     = complete_array_type (type, DECL_INITIAL (decl), do_default);
  3328.  
  3329.       /* Get the completed type made by complete_array_type.  */
  3330.       type = TREE_TYPE (decl);
  3331.  
  3332.       if (failure == 1)
  3333.     error_with_decl (decl, "initializer fails to determine size of `%s'");
  3334.  
  3335.       if (failure == 2)
  3336.     {
  3337.       if (do_default)
  3338.         error_with_decl (decl, "array size missing in `%s'");
  3339.       else if (!pedantic && TREE_STATIC (decl))
  3340.         DECL_EXTERNAL (decl) = 1;
  3341.     }
  3342.  
  3343.       if (pedantic && TYPE_DOMAIN (type) != 0
  3344.       && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
  3345.                   integer_zero_node))
  3346.     error_with_decl (decl, "zero-size array `%s'");
  3347.  
  3348.       layout_decl (decl, 0);
  3349.     }
  3350.  
  3351.   if (TREE_CODE (decl) == VAR_DECL)
  3352.     {
  3353.       if (DECL_SIZE (decl) == 0
  3354.       && (TREE_STATIC (decl)
  3355.           ?
  3356.         /* A static variable with an incomplete type
  3357.            is an error if it is initialized or `static'.
  3358.            Otherwise, let it through, but if it is not `extern'
  3359.            then it may cause an error message later.  */
  3360.         !TREE_PUBLIC (decl) || DECL_INITIAL (decl)
  3361.           :
  3362.         /* An automatic variable with an incomplete type
  3363.            is an error.  */
  3364.         !DECL_EXTERNAL (decl)))
  3365.     {
  3366.       error_with_decl (decl, "storage size of `%s' isn't known");
  3367.       TREE_TYPE (decl) = error_mark_node;
  3368.     }
  3369.  
  3370.       if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
  3371.       && DECL_SIZE (decl) != 0
  3372.       && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
  3373.     error_with_decl (decl, "storage size of `%s' isn't constant");
  3374.     }
  3375.  
  3376.   /* Output the assembler code and/or RTL code for variables and functions,
  3377.      unless the type is an undefined structure or union.
  3378.      If not, it will get done when the type is completed.  */
  3379.  
  3380.   if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
  3381.     {
  3382.       if (flag_traditional && allocation_temporary_p ())
  3383.     {
  3384.       push_obstacks_nochange ();
  3385.       end_temporary_allocation ();
  3386.       /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
  3387.       maybe_objc_check_decl (decl);
  3388.       rest_of_decl_compilation (decl, asmspec,
  3389.                     current_binding_level == global_binding_level,
  3390.                     0);
  3391.       pop_obstacks ();
  3392.     }
  3393.       else
  3394.     {
  3395.       /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
  3396.       maybe_objc_check_decl (decl);
  3397.       rest_of_decl_compilation (decl, asmspec,
  3398.                     current_binding_level == global_binding_level,
  3399.                     0);
  3400.     }
  3401.       if (current_binding_level != global_binding_level)
  3402.     {
  3403.       /* Recompute the RTL of a local array now
  3404.          if it used to be an incomplete type.  */
  3405.       if (was_incomplete
  3406.           && ! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
  3407.         {
  3408.           /* If we used it already as memory, it must stay in memory.  */
  3409.           TREE_ADDRESSABLE (decl) = TREE_USED (decl);
  3410.           /* If it's still incomplete now, no init will save it.  */
  3411.           if (DECL_SIZE (decl) == 0)
  3412.         DECL_INITIAL (decl) = 0;
  3413.           expand_decl (decl);
  3414.         }
  3415.       /* Compute and store the initial value.  */
  3416.       if (TREE_CODE (decl) != FUNCTION_DECL)
  3417.         expand_decl_init (decl);
  3418.     }
  3419.     }
  3420.  
  3421.   if (TREE_CODE (decl) == TYPE_DECL)
  3422.     {
  3423.       /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
  3424.       maybe_objc_check_decl (decl);
  3425.       rest_of_decl_compilation (decl, NULL_PTR,
  3426.                 current_binding_level == global_binding_level,
  3427.                 0);
  3428.     }
  3429.  
  3430.   /* ??? After 2.3, test (init != 0) instead of TREE_CODE.  */
  3431.   if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
  3432.       && temporary && TREE_PERMANENT (decl))
  3433.     {
  3434.       /* We need to remember that this array HAD an initialization,
  3435.      but discard the actual temporary nodes,
  3436.      since we can't have a permanent node keep pointing to them.  */
  3437.       /* We make an exception for inline functions, since it's
  3438.      normal for a local extern redeclaration of an inline function
  3439.      to have a copy of the top-level decl's DECL_INLINE.  */
  3440.       if (DECL_INITIAL (decl) != 0)
  3441.     DECL_INITIAL (decl) = error_mark_node;
  3442.     }
  3443.  
  3444. #if 0
  3445.   /* Resume permanent allocation, if not within a function.  */
  3446.   /* The corresponding push_obstacks_nochange is in start_decl,
  3447.      and in push_parm_decl and in grokfield.  */
  3448.   pop_obstacks ();
  3449. #endif
  3450.  
  3451.   /* If we have gone back from temporary to permanent allocation,
  3452.      actually free the temporary space that we no longer need.  */
  3453.   if (temporary && !allocation_temporary_p ())
  3454.     permanent_allocation ();
  3455.  
  3456.   /* At the end of a declaration, throw away any variable type sizes
  3457.      of types defined inside that declaration.  There is no use
  3458.      computing them in the following function definition.  */
  3459.   if (current_binding_level == global_binding_level)
  3460.     get_pending_sizes ();
  3461. #ifdef MPW_ASM
  3462.   /* At the end of a declaration, we can close off the declaration's module. */
  3463.   if (current_binding_level == global_binding_level && !DECL_IGNORED_P(decl)) {
  3464.     finish_module (IDENTIFIER_POINTER (DECL_NAME (decl)));
  3465.   }
  3466. #endif
  3467.  
  3468. #ifdef TARGET_SYMOFFSETS
  3469.   if (TARGET_SYMOFFSETS)
  3470.     write_struct_type (decl);
  3471. #endif
  3472. }
  3473.  
  3474. /* If DECL has a cleanup, build and return that cleanup here.
  3475.    This is a callback called by expand_expr.  */
  3476.  
  3477. tree
  3478. maybe_build_cleanup (decl)
  3479.      tree decl;
  3480. {
  3481.   /* There are no cleanups in C.  */
  3482.   return NULL_TREE;
  3483. }
  3484.  
  3485. /* Given a parsed parameter declaration,
  3486.    decode it into a PARM_DECL and push that on the current binding level.
  3487.    Also, for the sake of forward parm decls,
  3488.    record the given order of parms in `parm_order'.  */
  3489.  
  3490. void
  3491. push_parm_decl (parm)
  3492.      tree parm;
  3493. {
  3494.   tree decl, olddecl;
  3495.   int old_immediate_size_expand = immediate_size_expand;
  3496.   /* Don't try computing parm sizes now -- wait till fn is called.  */
  3497.   immediate_size_expand = 0;
  3498.  
  3499.   /* The corresponding pop_obstacks is in finish_decl.  */
  3500.   push_obstacks_nochange ();
  3501.  
  3502.   decl = grokdeclarator (TREE_VALUE (parm), TREE_PURPOSE (parm), PARM, 0);
  3503.   if (DECL_NAME (decl))
  3504.     {
  3505.       olddecl = lookup_name (DECL_NAME (decl));
  3506.       if (pedantic && olddecl != 0 && TREE_CODE (olddecl) == TYPE_DECL)
  3507.     pedwarn_with_decl (decl, "ANSI C forbids parameter `%s' shadowing typedef");
  3508.     }
  3509.   decl = pushdecl (decl);
  3510.  
  3511.   immediate_size_expand = old_immediate_size_expand;
  3512.  
  3513.   current_binding_level->parm_order
  3514.     = tree_cons (NULL_TREE, decl, current_binding_level->parm_order);
  3515.  
  3516.   /* Add this decl to the current binding level.  */
  3517.   finish_decl (decl, NULL_TREE, NULL_TREE);
  3518. }
  3519.  
  3520. /* Clear the given order of parms in `parm_order'.
  3521.    Used at start of parm list,
  3522.    and also at semicolon terminating forward decls.  */
  3523.  
  3524. void
  3525. clear_parm_order ()
  3526. {
  3527.   current_binding_level->parm_order = NULL_TREE;
  3528. }
  3529.  
  3530. /* Make TYPE a complete type based on INITIAL_VALUE.
  3531.    Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
  3532.    2 if there was no information (in which case assume 1 if DO_DEFAULT).  */
  3533.  
  3534. int
  3535. complete_array_type (type, initial_value, do_default)
  3536.      tree type;
  3537.      tree initial_value;
  3538.      int do_default;
  3539. {
  3540.   register tree maxindex = NULL_TREE;
  3541.   int value = 0;
  3542.  
  3543.   if (initial_value)
  3544.     {
  3545.       /* Note MAXINDEX  is really the maximum index,
  3546.      one less than the size.  */
  3547.       if (TREE_CODE (initial_value) == STRING_CST)
  3548.     {
  3549.       int eltsize
  3550.         = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value)));
  3551.       maxindex = build_int_2 (TREE_STRING_LENGTH (initial_value) / eltsize - 1, 0);
  3552.     }
  3553.       else if (TREE_CODE (initial_value) == CONSTRUCTOR)
  3554.     {
  3555.       register int nelts
  3556.         = list_length (CONSTRUCTOR_ELTS (initial_value));
  3557.       maxindex = build_int_2 (nelts - 1, 0);
  3558.     }
  3559.       else
  3560.     {
  3561.       /* Make an error message unless that happened already.  */
  3562.       if (initial_value != error_mark_node)
  3563.         value = 1;
  3564.  
  3565.       /* Prevent further error messages.  */
  3566.       maxindex = build_int_2 (1, 0);
  3567.     }
  3568.     }
  3569.  
  3570.   if (!maxindex)
  3571.     {
  3572.       if (do_default)
  3573.     maxindex = build_int_2 (1, 0);
  3574.       value = 2;
  3575.     }
  3576.  
  3577.   if (maxindex)
  3578.     {
  3579.       TYPE_DOMAIN (type) = build_index_type (maxindex);
  3580.       if (!TREE_TYPE (maxindex))
  3581.     TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
  3582.     }
  3583.  
  3584.   /* Lay out the type now that we can get the real answer.  */
  3585.  
  3586.   layout_type (type);
  3587.  
  3588.   return value;
  3589. }
  3590.  
  3591. /* Given declspecs and a declarator,
  3592.    determine the name and type of the object declared
  3593.    and construct a ..._DECL node for it.
  3594.    (In one case we can return a ..._TYPE node instead.
  3595.     For invalid input we sometimes return 0.)
  3596.  
  3597.    DECLSPECS is a chain of tree_list nodes whose value fields
  3598.     are the storage classes and type specifiers.
  3599.  
  3600.    DECL_CONTEXT says which syntactic context this declaration is in:
  3601.      NORMAL for most contexts.  Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
  3602.      FUNCDEF for a function definition.  Like NORMAL but a few different
  3603.       error messages in each case.  Return value may be zero meaning
  3604.       this definition is too screwy to try to parse.
  3605.      PARM for a parameter declaration (either within a function prototype
  3606.       or before a function body).  Make a PARM_DECL, or return void_type_node.
  3607.      TYPENAME if for a typename (in a cast or sizeof).
  3608.       Don't make a DECL node; just return the ..._TYPE node.
  3609.      FIELD for a struct or union field; make a FIELD_DECL.
  3610.      BITFIELD for a field with specified width.
  3611.    INITIALIZED is 1 if the decl has an initializer.
  3612.  
  3613.    In the TYPENAME case, DECLARATOR is really an absolute declarator.
  3614.    It may also be so in the PARM case, for a prototype where the
  3615.    argument type is specified but not the name.
  3616.  
  3617.    This function is where the complicated C meanings of `static'
  3618.    and `extern' are interpreted.  */
  3619.  
  3620. static tree
  3621. grokdeclarator (declarator, declspecs, decl_context, initialized)
  3622.      tree declspecs;
  3623.      tree declarator;
  3624.      enum decl_context decl_context;
  3625.      int initialized;
  3626. {
  3627.   int specbits = 0;
  3628.   tree spec;
  3629.   tree type = NULL_TREE;
  3630.   int longlong = 0;
  3631.   int constp;
  3632.   int volatilep;
  3633.   int inlinep;
  3634.   /* Apple flag to detect a pascal declaration of a function or variable. */
  3635.   int pascalp = 0;
  3636.   int explicit_int = 0;
  3637.   int explicit_char = 0;
  3638.   tree typedef_decl = 0;
  3639.   char *name;
  3640.   tree typedef_type = 0;
  3641.   int funcdef_flag = 0;
  3642.   enum tree_code innermost_code = ERROR_MARK;
  3643.   int bitfield = 0;
  3644.   int size_varies = 0;
  3645.  
  3646.   if (decl_context == BITFIELD)
  3647.     bitfield = 1, decl_context = FIELD;
  3648.  
  3649.   if (decl_context == FUNCDEF)
  3650.     funcdef_flag = 1, decl_context = NORMAL;
  3651.  
  3652.   push_obstacks_nochange ();
  3653.  
  3654.   if (flag_traditional && allocation_temporary_p ())
  3655.     end_temporary_allocation ();
  3656.  
  3657.   /* Look inside a declarator for the name being declared
  3658.      and get it as a string, for an error message.  */
  3659.   {
  3660.     register tree decl = declarator;
  3661.     name = 0;
  3662.  
  3663.     while (decl)
  3664.       switch (TREE_CODE (decl))
  3665.     {
  3666.     case ARRAY_REF:
  3667.     case INDIRECT_REF:
  3668.     case CALL_EXPR:
  3669.       innermost_code = TREE_CODE (decl);
  3670.       decl = TREE_OPERAND (decl, 0);
  3671.       break;
  3672.  
  3673.     case IDENTIFIER_NODE:
  3674.       name = IDENTIFIER_POINTER (decl);
  3675.       decl = 0;
  3676.       break;
  3677.  
  3678.     default:
  3679.       abort ();
  3680.     }
  3681.     if (name == 0)
  3682.       name = "type name";
  3683.   }
  3684.  
  3685.   /* A function definition's declarator must have the form of
  3686.      a function declarator.  */
  3687.  
  3688.   if (funcdef_flag && innermost_code != CALL_EXPR)
  3689.     return 0;
  3690.  
  3691.   /* Anything declared one level down from the top level
  3692.      must be one of the parameters of a function
  3693.      (because the body is at least two levels down).  */
  3694.  
  3695.   /* If this looks like a function definition, make it one,
  3696.      even if it occurs where parms are expected.
  3697.      Then store_parm_decls will reject it and not use it as a parm.  */
  3698.   if (decl_context == NORMAL && !funcdef_flag
  3699.       && current_binding_level->level_chain == global_binding_level)
  3700.     decl_context = PARM;
  3701.  
  3702.   /* Look through the decl specs and record which ones appear.
  3703.      Some typespecs are defined as built-in typenames.
  3704.      Others, the ones that are modifiers of other types,
  3705.      are represented by bits in SPECBITS: set the bits for
  3706.      the modifiers that appear.  Storage class keywords are also in SPECBITS.
  3707.  
  3708.      If there is a typedef name or a type, store the type in TYPE.
  3709.      This includes builtin typedefs such as `int'.
  3710.  
  3711.      Set EXPLICIT_INT or EXPLICIT_CHAR if the type is `int' or `char'
  3712.      and did not come from a user typedef.
  3713.  
  3714.      Set LONGLONG if `long' is mentioned twice.  */
  3715.  
  3716.   for (spec = declspecs; spec; spec = TREE_CHAIN (spec))
  3717.     {
  3718.       register int i;
  3719.       register tree id = TREE_VALUE (spec);
  3720.  
  3721.       if (id == ridpointers[(int) RID_INT])
  3722.     explicit_int = 1;
  3723.       if (id == ridpointers[(int) RID_CHAR])
  3724.     explicit_char = 1;
  3725.  
  3726.       if (TREE_CODE (id) == IDENTIFIER_NODE)
  3727.     for (i = (int) RID_FIRST_MODIFIER; i < (int) RID_MAX; i++)
  3728.       {
  3729.         if (ridpointers[i] == id)
  3730.           {
  3731.         if (i == (int) RID_LONG && specbits & (1<<i))
  3732.           {
  3733.             if (pedantic)
  3734.               pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  3735.             else if (longlong)
  3736.               error ("`long long long' is too long for GCC");
  3737.             else
  3738.               longlong = 1;
  3739.           }
  3740.         else if (specbits & (1 << i))
  3741.           pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id));
  3742.         specbits |= 1 << i;
  3743.         goto found;
  3744.           }
  3745.       }
  3746.       if (type)
  3747.     error ("two or more data types in declaration of `%s'", name);
  3748.       /* Actual typedefs come to us as TYPE_DECL nodes.  */
  3749.       else if (TREE_CODE (id) == TYPE_DECL)
  3750.     {
  3751.       type = TREE_TYPE (id);
  3752.       typedef_decl = id;
  3753.     }
  3754.       /* Built-in types come as identifiers.  */
  3755.       else if (TREE_CODE (id) == IDENTIFIER_NODE)
  3756.     {
  3757.       register tree t = lookup_name (id);
  3758.       if (TREE_TYPE (t) == error_mark_node)
  3759.         ;
  3760.       else if (!t || TREE_CODE (t) != TYPE_DECL)
  3761.         error ("`%s' fails to be a typedef or built in type",
  3762.            IDENTIFIER_POINTER (id));
  3763.       else
  3764.         {
  3765.           type = TREE_TYPE (t);
  3766.           typedef_decl = t;
  3767.         }
  3768.     }
  3769.       else if (TREE_CODE (id) != ERROR_MARK)
  3770.     type = id;
  3771.  
  3772.     found: {}
  3773.     }
  3774.  
  3775.   typedef_type = type;
  3776.   if (type)
  3777.     size_varies = C_TYPE_VARIABLE_SIZE (type);
  3778.  
  3779.   /* No type at all: default to `int', and set EXPLICIT_INT
  3780.      because it was not a user-defined typedef.  */
  3781.  
  3782.   if (type == 0)
  3783.     {
  3784.       if (funcdef_flag && warn_return_type
  3785.       && ! (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  3786.                 | (1 << (int) RID_SIGNED) | (1 << (int) RID_UNSIGNED))))
  3787.     warn_about_return_type = 1;
  3788.       explicit_int = 1;
  3789.       type = integer_type_node;
  3790.     }
  3791.  
  3792.   /* Now process the modifiers that were specified
  3793.      and check for invalid combinations.  */
  3794.  
  3795.   /* Long double is a special combination.  */
  3796.  
  3797.   if ((specbits & 1 << (int) RID_LONG)
  3798.       && TYPE_MAIN_VARIANT (type) == double_type_node)
  3799.     {
  3800.       specbits &= ~ (1 << (int) RID_LONG);
  3801.       type = long_double_type_node;
  3802.     }
  3803.  
  3804.   /* Check all other uses of type modifiers.  */
  3805.  
  3806.   if (specbits & ((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  3807.           | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED)))
  3808.     {
  3809.       int ok = 0;
  3810.  
  3811.       if (TREE_CODE (type) != INTEGER_TYPE)
  3812.     error ("long, short, signed or unsigned invalid for `%s'", name);
  3813.       else if ((specbits & 1 << (int) RID_LONG)
  3814.            && (specbits & 1 << (int) RID_SHORT))
  3815.     error ("long and short specified together for `%s'", name);
  3816.       else if (((specbits & 1 << (int) RID_LONG)
  3817.         || (specbits & 1 << (int) RID_SHORT))
  3818.            && explicit_char)
  3819.     error ("long or short specified with char for `%s'", name);
  3820.       else if (((specbits & 1 << (int) RID_LONG)
  3821.         || (specbits & 1 << (int) RID_SHORT))
  3822.            && TREE_CODE (type) == REAL_TYPE)
  3823.     error ("long or short specified with floating type for `%s'", name);
  3824.       else if ((specbits & 1 << (int) RID_SIGNED)
  3825.            && (specbits & 1 << (int) RID_UNSIGNED))
  3826.     error ("signed and unsigned given together for `%s'", name);
  3827.       else
  3828.     {
  3829.       ok = 1;
  3830.       if (!explicit_int && !explicit_char && pedantic)
  3831.         {
  3832.           pedwarn ("long, short, signed or unsigned used invalidly for `%s'",
  3833.                name);
  3834.           if (flag_pedantic_errors)
  3835.         ok = 0;
  3836.         }
  3837.     }
  3838.  
  3839.       /* Discard the type modifiers if they are invalid.  */
  3840.       if (! ok)
  3841.     {
  3842.       specbits &= ~((1 << (int) RID_LONG) | (1 << (int) RID_SHORT)
  3843.             | (1 << (int) RID_UNSIGNED) | (1 << (int) RID_SIGNED));
  3844.       longlong = 0;
  3845.     }
  3846.     }
  3847.  
  3848.   /* Decide whether an integer type is signed or not.
  3849.      Optionally treat bitfields as signed by default.  */
  3850.   if (specbits & 1 << (int) RID_UNSIGNED
  3851.       /* Traditionally, all bitfields are unsigned.  */
  3852.       || (bitfield && flag_traditional
  3853.       && (! explicit_flag_signed_bitfields || !flag_signed_bitfields))
  3854.       || (bitfield && ! flag_signed_bitfields
  3855.       && (explicit_int || explicit_char
  3856.           /* A typedef for plain `int' without `signed'
  3857.          can be controlled just like plain `int'.  */
  3858.           || ! (typedef_decl != 0
  3859.             && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  3860.       && TREE_CODE (type) != ENUMERAL_TYPE
  3861.       && !(specbits & 1 << (int) RID_SIGNED)))
  3862.     {
  3863.       if (longlong)
  3864.     type = long_long_unsigned_type_node;
  3865.       else if (specbits & 1 << (int) RID_LONG)
  3866.     type = long_unsigned_type_node;
  3867.       else if (specbits & 1 << (int) RID_SHORT)
  3868.     type = short_unsigned_type_node;
  3869.       else if (type == char_type_node)
  3870.     type = unsigned_char_type_node;
  3871.       else if (typedef_decl)
  3872.     type = unsigned_type (type);
  3873.       else
  3874.     type = unsigned_type_node;
  3875.     }
  3876.   else if ((specbits & 1 << (int) RID_SIGNED)
  3877.        && type == char_type_node)
  3878.     type = signed_char_type_node;
  3879.   else if (longlong)
  3880.     type = long_long_integer_type_node;
  3881.   else if (specbits & 1 << (int) RID_LONG)
  3882.     type = long_integer_type_node;
  3883.   else if (specbits & 1 << (int) RID_SHORT)
  3884.     type = short_integer_type_node;
  3885.  
  3886.   /* Set CONSTP if this declaration is `const', whether by
  3887.      explicit specification or via a typedef.
  3888.      Likewise for VOLATILEP.  */
  3889.  
  3890.   constp = !! (specbits & 1 << (int) RID_CONST) + TYPE_READONLY (type);
  3891.   volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
  3892.   inlinep = !! (specbits & (1 << (int) RID_INLINE));
  3893.   /* If Apple extensions are enabled, recognize the pascal keyword. */
  3894.   if (flag_apple)
  3895.     {
  3896.       /* Set a flag if the keyword `pascal' appeared in the declspecs. */
  3897.       pascalp = !! (specbits & 1 << (int) RID_PASCAL);
  3898.       /* Grumble about duplicates, just for consistency. */
  3899.       if (pascalp > 1)
  3900.     pedwarn ("duplicate `pascal'");
  3901.     }
  3902.   if (constp > 1)
  3903.     pedwarn ("duplicate `const'");
  3904.   if (volatilep > 1)
  3905.     pedwarn ("duplicate `volatile'");
  3906.   if (! flag_gen_aux_info && (TYPE_READONLY (type) || TYPE_VOLATILE (type)))
  3907.     type = TYPE_MAIN_VARIANT (type);
  3908.  
  3909.   /* Warn if two storage classes are given. Default to `auto'.  */
  3910.  
  3911.   {
  3912.     int nclasses = 0;
  3913.  
  3914.     if (specbits & 1 << (int) RID_AUTO) nclasses++;
  3915.     if (specbits & 1 << (int) RID_STATIC) nclasses++;
  3916.     if (specbits & 1 << (int) RID_EXTERN) nclasses++;
  3917.     if (specbits & 1 << (int) RID_REGISTER) nclasses++;
  3918.     if (specbits & 1 << (int) RID_TYPEDEF) nclasses++;
  3919.  
  3920.     /* Warn about storage classes that are invalid for certain
  3921.        kinds of declarations (parameters, typenames, etc.).  */
  3922.  
  3923.     if (nclasses > 1)
  3924.       error ("multiple storage classes in declaration of `%s'", name);
  3925.     else if (funcdef_flag
  3926.          && (specbits
  3927.          & ((1 << (int) RID_REGISTER)
  3928.             | (1 << (int) RID_AUTO)
  3929.             | (1 << (int) RID_TYPEDEF))))
  3930.       {
  3931.     if (specbits & 1 << (int) RID_AUTO
  3932.         && (pedantic || current_binding_level == global_binding_level))
  3933.       pedwarn ("function definition declared `auto'");
  3934.     if (specbits & 1 << (int) RID_REGISTER)
  3935.       error ("function definition declared `register'");
  3936.     if (specbits & 1 << (int) RID_TYPEDEF)
  3937.       error ("function definition declared `typedef'");
  3938.     specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
  3939.                | (1 << (int) RID_AUTO));
  3940.       }
  3941.     else if (decl_context != NORMAL && nclasses > 0)
  3942.       {
  3943.     if (decl_context == PARM && specbits & 1 << (int) RID_REGISTER)
  3944.       ;
  3945.     else
  3946.       {
  3947.         error ((decl_context == FIELD
  3948.             ? "storage class specified for structure field `%s'"
  3949.             : (decl_context == PARM
  3950.                ? "storage class specified for parameter `%s'"
  3951.                : "storage class specified for typename")),
  3952.            name);
  3953.         specbits &= ~ ((1 << (int) RID_TYPEDEF) | (1 << (int) RID_REGISTER)
  3954.                | (1 << (int) RID_AUTO) | (1 << (int) RID_STATIC)
  3955.                | (1 << (int) RID_EXTERN));
  3956.       }
  3957.       }
  3958.     else if (specbits & 1 << (int) RID_EXTERN && initialized && ! funcdef_flag)
  3959.       {
  3960.     /* `extern' with initialization is invalid if not at top level.  */
  3961.     if (current_binding_level == global_binding_level)
  3962.       warning ("`%s' initialized and declared `extern'", name);
  3963.     else
  3964.       error ("`%s' has both `extern' and initializer", name);
  3965.       }
  3966.     else if (specbits & 1 << (int) RID_EXTERN && funcdef_flag
  3967.          && current_binding_level != global_binding_level)
  3968.       error ("nested function `%s' declared `extern'", name);
  3969.     else if (current_binding_level == global_binding_level
  3970.          && specbits & (1 << (int) RID_AUTO))
  3971.       error ("top-level declaration of `%s' specifies `auto'", name);
  3972.   }
  3973.  
  3974.   /* Now figure out the structure of the declarator proper.
  3975.      Descend through it, creating more complex types, until we reach
  3976.      the declared identifier (or NULL_TREE, in an absolute declarator).  */
  3977.  
  3978.   while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE)
  3979.     {
  3980.       if (type == error_mark_node)
  3981.     {
  3982.       declarator = TREE_OPERAND (declarator, 0);
  3983.       continue;
  3984.     }
  3985.  
  3986.       /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]),
  3987.      an INDIRECT_REF (for *...),
  3988.      a CALL_EXPR (for ...(...)),
  3989.      an identifier (for the name being declared)
  3990.      or a null pointer (for the place in an absolute declarator
  3991.      where the name was omitted).
  3992.      For the last two cases, we have just exited the loop.
  3993.  
  3994.      At this point, TYPE is the type of elements of an array,
  3995.      or for a function to return, or for a pointer to point to.
  3996.      After this sequence of ifs, TYPE is the type of the
  3997.      array or function or pointer, and DECLARATOR has had its
  3998.      outermost layer removed.  */
  3999.  
  4000.       if (TREE_CODE (declarator) == ARRAY_REF)
  4001.     {
  4002.       register tree itype = NULL_TREE;
  4003.       register tree size = TREE_OPERAND (declarator, 1);
  4004.  
  4005.       declarator = TREE_OPERAND (declarator, 0);
  4006.  
  4007.       /* Check for some types that there cannot be arrays of.  */
  4008.  
  4009.       if (TYPE_MAIN_VARIANT (type) == void_type_node)
  4010.         {
  4011.           error ("declaration of `%s' as array of voids", name);
  4012.           type = error_mark_node;
  4013.         }
  4014.  
  4015.       if (TREE_CODE (type) == FUNCTION_TYPE)
  4016.         {
  4017.           error ("declaration of `%s' as array of functions", name);
  4018.           type = error_mark_node;
  4019.         }
  4020.  
  4021.       if (size == error_mark_node)
  4022.         type = error_mark_node;
  4023.  
  4024.       if (type == error_mark_node)
  4025.         continue;
  4026.  
  4027.       /* If size was specified, set ITYPE to a range-type for that size.
  4028.          Otherwise, ITYPE remains null.  finish_decl may figure it out
  4029.          from an initial value.  */
  4030.  
  4031.       if (size)
  4032.         {
  4033.           /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  4034.           STRIP_TYPE_NOPS (size);
  4035.  
  4036.           if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE
  4037.           && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE)
  4038.         {
  4039.           error ("size of array `%s' has non-integer type", name);
  4040.           size = integer_one_node;
  4041.         }
  4042.           if (pedantic && integer_zerop (size))
  4043.         pedwarn ("ANSI C forbids zero-size array `%s'", name);
  4044.           if (TREE_CODE (size) == INTEGER_CST)
  4045.         {
  4046.           if (INT_CST_LT (size, integer_zero_node))
  4047.             {
  4048.               error ("size of array `%s' is negative", name);
  4049.               size = integer_one_node;
  4050.             }
  4051.           itype = build_index_type (size_binop (MINUS_EXPR, size,
  4052.                             size_one_node));
  4053.         }
  4054.           else
  4055.         {
  4056.           if (pedantic)
  4057.             pedwarn ("ANSI C forbids variable-size array `%s'", name);
  4058.           itype = build_binary_op (MINUS_EXPR, size, integer_one_node,
  4059.                        1);
  4060.           /* Make sure the array size remains visibly nonconstant
  4061.              even if it is (eg) a const variable with known value.  */
  4062.           size_varies = 1;
  4063.           itype = variable_size (itype);
  4064.           itype = build_index_type (itype);
  4065.         }
  4066.         }
  4067.  
  4068. #if 0 /* This had bad results for pointers to arrays, as in
  4069.      union incomplete (*foo)[4];  */
  4070.       /* Complain about arrays of incomplete types, except in typedefs.  */
  4071.  
  4072.       if (TYPE_SIZE (type) == 0
  4073.           /* Avoid multiple warnings for nested array types.  */
  4074.           && TREE_CODE (type) != ARRAY_TYPE
  4075.           && !(specbits & (1 << (int) RID_TYPEDEF))
  4076.           && !C_TYPE_BEING_DEFINED (type))
  4077.         warning ("array type has incomplete element type");
  4078. #endif
  4079.  
  4080.       /* Build the array type itself.
  4081.          Merge any constancy or volatility into the target type.  */
  4082.  
  4083. #if 0  /* We shouldn't have a function type here at all!
  4084.       Functions aren't allowed as array elements.  */
  4085.       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
  4086.           && (constp || volatilep))
  4087.         pedwarn ("ANSI C forbids const or volatile function types");
  4088. #endif
  4089.       if (constp || volatilep)
  4090.         type = c_build_type_variant (type, constp, volatilep);
  4091.  
  4092. #if 0    /* don't clear these; leave them set so that the array type
  4093.        or the variable is itself const or volatile.  */
  4094.       constp = 0;
  4095.       volatilep = 0;
  4096. #endif
  4097.  
  4098.       type = build_array_type (type, itype);
  4099.       if (size_varies)
  4100.         C_TYPE_VARIABLE_SIZE (type) = 1;
  4101.     }
  4102.       else if (TREE_CODE (declarator) == CALL_EXPR)
  4103.     {
  4104.       int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
  4105.                 || current_binding_level == global_binding_level);
  4106.       tree arg_types;
  4107.  
  4108.       /* Declaring a function type.
  4109.          Make sure we have a valid type for the function to return.  */
  4110.       if (type == error_mark_node)
  4111.         continue;
  4112.  
  4113.       size_varies = 0;
  4114.  
  4115.       /* Warn about some types functions can't return.  */
  4116.  
  4117.       if (TREE_CODE (type) == FUNCTION_TYPE)
  4118.         {
  4119.           error ("`%s' declared as function returning a function", name);
  4120.           type = integer_type_node;
  4121.         }
  4122.       if (TREE_CODE (type) == ARRAY_TYPE)
  4123.         {
  4124.           error ("`%s' declared as function returning an array", name);
  4125.           type = integer_type_node;
  4126.         }
  4127.  
  4128. #ifndef TRADITIONAL_RETURN_FLOAT
  4129.       /* Traditionally, declaring return type float means double.  */
  4130.  
  4131.       if (flag_traditional && TYPE_MAIN_VARIANT (type) == float_type_node)
  4132.         type = double_type_node;
  4133. #endif /* TRADITIONAL_RETURN_FLOAT */
  4134.  
  4135.       /* If this is a block level extern, it must live past the end
  4136.          of the function so that we can check it against other extern
  4137.          declarations (IDENTIFIER_LIMBO_VALUE).  */
  4138.       if (extern_ref && allocation_temporary_p ())
  4139.         end_temporary_allocation ();
  4140.  
  4141.       /* Construct the function type and go to the next
  4142.          inner layer of declarator.  */
  4143.  
  4144.       arg_types = grokparms (TREE_OPERAND (declarator, 1),
  4145.                  funcdef_flag
  4146.                  /* Say it's a definition
  4147.                     only for the CALL_EXPR
  4148.                     closest to the identifier.  */
  4149.                  && TREE_CODE (TREE_OPERAND (declarator, 0)) == IDENTIFIER_NODE);
  4150.       /* Bash types of functions returning floats, last-ditch effort. */
  4151.       if (flag_apple
  4152.           && (type == float_type_node || type == double_type_node))
  4153.         type = long_double_type_node;
  4154. #if 0 /* This seems to be false.  We turn off temporary allocation
  4155.      above in this function if -traditional.
  4156.      And this code caused inconsistent results with prototypes:
  4157.      callers would ignore them, and pass arguments wrong.  */
  4158.  
  4159.       /* Omit the arg types if -traditional, since the arg types
  4160.          and the list links might not be permanent.  */
  4161.       type = build_function_type (type,
  4162.                       flag_traditional 
  4163.                       ? NULL_TREE : arg_types);
  4164. #endif
  4165.       /* If Apple extensions are enabled and we saw a `pascal' keyword,
  4166.          make a special type of function. */
  4167.       /* The global flag affects the process of building the function
  4168.          type in build_function_type. */
  4169.       if (flag_apple
  4170.           && (pascalp
  4171.           || (parameter_pragma_supplied
  4172.               && strcmp(current_name_in_pragma, name) == 0)))
  4173.         this_type_has_convention = 1;
  4174.  
  4175.       type = build_function_type (type, arg_types);
  4176.       declarator = TREE_OPERAND (declarator, 0);
  4177.  
  4178.       if (flag_apple && pascalp)
  4179.         {
  4180. #ifdef TYPE_CALL_CONVENTION_PASCAL
  4181.           /* Might have failed to make the special structure. */
  4182.           if (TYPE_CALL_CONVENTION (type) == NULL) abort();
  4183.           TYPE_CALL_CONVENTION_PASCAL (type) = 1;
  4184. #endif
  4185.           /* Warn about this, if we're trying to be strictly ANSI,
  4186.          but not while we're reading system headers. */
  4187. /*          if (pedantic && ! DECL_IN_SYSTEM_HEADER (decl))
  4188.         pedwarn ("ANSI C forbids `pascal' functions"); */
  4189.         }
  4190.  
  4191. #ifdef SPECIAL_CALLING_CONVENTIONS
  4192.       if (flag_apple &&
  4193.           (parameter_pragma_supplied
  4194.            && strcmp(current_name_in_pragma, name) == 0))
  4195.         {
  4196.           /* Might have failed to make the special structure. */
  4197.           if (TYPE_CALL_CONVENTION (type) == NULL) abort();
  4198.           COPY_CALL_CONVENTION(TYPE_CALL_CONVENTION (type),
  4199.                    ¤t_call_convention);
  4200.         }
  4201. #endif
  4202.  
  4203.       /* Set the TYPE_CONTEXTs for each tagged type which is local to
  4204.          the formal parameter list of this FUNCTION_TYPE to point to
  4205.          the FUNCTION_TYPE node itself.  */
  4206.  
  4207.       {
  4208.         register tree link;
  4209.  
  4210.         for (link = current_function_parm_tags;
  4211.          link;
  4212.          link = TREE_CHAIN (link))
  4213.           TYPE_CONTEXT (TREE_VALUE (link)) = type;
  4214.       }
  4215.     }
  4216.       else if (TREE_CODE (declarator) == INDIRECT_REF)
  4217.     {
  4218.       /* Merge any constancy or volatility into the target type
  4219.          for the pointer.  */
  4220.  
  4221.       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
  4222.           && (constp || volatilep))
  4223.         pedwarn ("ANSI C forbids const or volatile function types");
  4224.       if (constp || volatilep)
  4225.         type = c_build_type_variant (type, constp, volatilep);
  4226.       constp = 0;
  4227.       volatilep = 0;
  4228.       size_varies = 0;
  4229.  
  4230.       type = build_pointer_type (type);
  4231.  
  4232.       /* Process a list of type modifier keywords
  4233.          (such as const or volatile) that were given inside the `*'.  */
  4234.  
  4235.       if (TREE_TYPE (declarator))
  4236.         {
  4237.           register tree typemodlist;
  4238.           int erred = 0;
  4239.           for (typemodlist = TREE_TYPE (declarator); typemodlist;
  4240.            typemodlist = TREE_CHAIN (typemodlist))
  4241.         {
  4242.           if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_CONST])
  4243.             constp++;
  4244.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_VOLATILE])
  4245.             volatilep++;
  4246.           else if (TREE_VALUE (typemodlist) == ridpointers[(int) RID_PASCAL])
  4247.             pascalp++;
  4248.           else if (!erred)
  4249.             {
  4250.               erred = 1;
  4251.               error ("invalid type modifier within pointer declarator");
  4252.             }
  4253.         }
  4254.           if (constp > 1)
  4255.         pedwarn ("duplicate `const'");
  4256.           if (volatilep > 1)
  4257.         pedwarn ("duplicate `volatile'");
  4258.           if (pascalp > 1)
  4259.         pedwarn ("duplicate `pascal'");
  4260.         }
  4261.  
  4262.       declarator = TREE_OPERAND (declarator, 0);
  4263.     }
  4264.       else
  4265.     abort ();
  4266.  
  4267.     }
  4268.  
  4269.   /* Now TYPE has the actual type.  */
  4270.  
  4271.   /* If this is declaring a typedef name, return a TYPE_DECL.  */
  4272.  
  4273.   if (specbits & (1 << (int) RID_TYPEDEF))
  4274.     {
  4275.       tree decl;
  4276.       /* Note that the grammar rejects storage classes
  4277.      in typenames, fields or parameters */
  4278.       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
  4279.       && (constp || volatilep))
  4280.     pedwarn ("ANSI C forbids const or volatile function types");
  4281.       if (constp || volatilep)
  4282.     type = c_build_type_variant (type, constp, volatilep);
  4283.       pop_obstacks ();
  4284.       decl = build_decl (TYPE_DECL, declarator, type);
  4285.       if ((specbits & (1 << (int) RID_SIGNED))
  4286.       || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
  4287.     C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
  4288.       return decl;
  4289.     }
  4290.  
  4291.   /* Detect the case of an array type of unspecified size
  4292.      which came, as such, direct from a typedef name.
  4293.      We must copy the type, so that each identifier gets
  4294.      a distinct type, so that each identifier's size can be
  4295.      controlled separately by its own initializer.  */
  4296.  
  4297.   if (type != 0 && typedef_type != 0
  4298.       && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type)
  4299.       && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == 0)
  4300.     {
  4301.       type = build_array_type (TREE_TYPE (type), 0);
  4302.       if (size_varies)
  4303.     C_TYPE_VARIABLE_SIZE (type) = 1;
  4304.     }
  4305.  
  4306.   /* If this is a type name (such as, in a cast or sizeof),
  4307.      compute the type and return it now.  */
  4308.  
  4309.   if (decl_context == TYPENAME)
  4310.     {
  4311.       /* Note that the grammar rejects storage classes
  4312.      in typenames, fields or parameters */
  4313.       if (pedantic && TREE_CODE (type) == FUNCTION_TYPE
  4314.       && (constp || volatilep))
  4315.     pedwarn ("ANSI C forbids const or volatile function types");
  4316.       if (constp || volatilep)
  4317.     type = c_build_type_variant (type, constp, volatilep);
  4318.       pop_obstacks ();
  4319.       return type;
  4320.     }
  4321.  
  4322.   /* `void' at top level (not within pointer)
  4323.      is allowed only in typedefs or type names.
  4324.      We don't complain about parms either, but that is because
  4325.      a better error message can be made later.  */
  4326.  
  4327.   if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM)
  4328.     {
  4329.       error ("variable or field `%s' declared void",
  4330.          IDENTIFIER_POINTER (declarator));
  4331.       type = integer_type_node;
  4332.     }
  4333.  
  4334.   /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
  4335.      or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE.  */
  4336.  
  4337.   {
  4338.     register tree decl;
  4339.  
  4340.     if (decl_context == PARM)
  4341.       {
  4342.     tree type_as_written = type;
  4343.     tree main_type;
  4344.  
  4345.     /* A parameter declared as an array of T is really a pointer to T.
  4346.        One declared as a function is really a pointer to a function.  */
  4347.  
  4348.     if (TREE_CODE (type) == ARRAY_TYPE)
  4349.       {
  4350.         /* Transfer const-ness of array into that of type pointed to.  */
  4351.         type = build_pointer_type
  4352.             (c_build_type_variant (TREE_TYPE (type), constp, volatilep));
  4353.         volatilep = constp = 0;
  4354.         size_varies = 0;
  4355.       }
  4356.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  4357.       {
  4358.         if (pedantic && (constp || volatilep))
  4359.           pedwarn ("ANSI C forbids const or volatile function types");
  4360.         type = build_pointer_type (c_build_type_variant (type, constp, volatilep));
  4361.         volatilep = constp = 0;
  4362.       }
  4363.  
  4364.     decl = build_decl (PARM_DECL, declarator, type);
  4365.     if (size_varies)
  4366.       C_DECL_VARIABLE_SIZE (decl) = 1;
  4367.  
  4368.     /* Compute the type actually passed in the parmlist,
  4369.        for the case where there is no prototype.
  4370.        (For example, shorts and chars are passed as ints.)
  4371.        When there is a prototype, this is overridden later.  */
  4372.  
  4373.     DECL_ARG_TYPE (decl) = type;
  4374.     main_type = TYPE_MAIN_VARIANT (type);
  4375.     /* All float args are actually passed as long doubles. */
  4376.     if (flag_apple
  4377.         && (main_type == float_type_node || main_type == double_type_node))
  4378.       DECL_ARG_TYPE (decl) = long_double_type_node;
  4379.     else if (main_type == float_type_node)
  4380.       DECL_ARG_TYPE (decl) = double_type_node;
  4381.     /* Don't use TYPE_PREISION to decide whether to promote,
  4382.        because we should convert short if it's the same size as int,
  4383.        but we should not convert long if it's the same size as int.  */
  4384.     else if (C_PROMOTING_INTEGER_TYPE_P (main_type))
  4385.       {
  4386.         if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
  4387.         && TREE_UNSIGNED (type))
  4388.           DECL_ARG_TYPE (decl) = unsigned_type_node;
  4389.         else
  4390.           DECL_ARG_TYPE (decl) = integer_type_node;
  4391.       }
  4392.  
  4393.     DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
  4394.       }
  4395.     else if (decl_context == FIELD)
  4396.       {
  4397.     /* Structure field.  It may not be a function.  */
  4398.  
  4399.     if (TREE_CODE (type) == FUNCTION_TYPE)
  4400.       {
  4401.         error ("field `%s' declared as a function",
  4402.            IDENTIFIER_POINTER (declarator));
  4403.         type = build_pointer_type (type);
  4404.       }
  4405.     else if (TREE_CODE (type) != ERROR_MARK && TYPE_SIZE (type) == 0)
  4406.       {
  4407.         error ("field `%s' has incomplete type",
  4408.            IDENTIFIER_POINTER (declarator));
  4409.         type = error_mark_node;
  4410.       }
  4411.     /* Move type qualifiers down to element of an array.  */
  4412.     if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep))
  4413.       {
  4414.         type = build_array_type (c_build_type_variant (TREE_TYPE (type),
  4415.                                constp, volatilep),
  4416.                      TYPE_DOMAIN (type));
  4417. #if 0 /* Leave the field const or volatile as well.  */
  4418.         constp = volatilep = 0;
  4419. #endif
  4420.       }
  4421.     decl = build_decl (FIELD_DECL, declarator, type);
  4422.     if (size_varies)
  4423.       C_DECL_VARIABLE_SIZE (decl) = 1;
  4424.       }
  4425.     else if (TREE_CODE (type) == FUNCTION_TYPE)
  4426.       {
  4427.     /* Every function declaration is "external"
  4428.        except for those which are inside a function body
  4429.        in which `auto' is used.
  4430.        That is a case not specified by ANSI C,
  4431.        and we use it for forward declarations for nested functions.  */
  4432.     int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
  4433.               || current_binding_level == global_binding_level);
  4434.  
  4435.     if (specbits & (1 << (int) RID_AUTO)
  4436.         && (pedantic || current_binding_level == global_binding_level))
  4437.       pedwarn ("invalid storage class for function `%s'",
  4438.          IDENTIFIER_POINTER (declarator));
  4439.     if (specbits & (1 << (int) RID_REGISTER))
  4440.       error ("invalid storage class for function `%s'",
  4441.          IDENTIFIER_POINTER (declarator));
  4442.     /* Function declaration not at top level.
  4443.        Storage classes other than `extern' are not allowed
  4444.        and `extern' makes no difference.  */
  4445.     if (current_binding_level != global_binding_level
  4446.         && (specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_INLINE)))
  4447.         && pedantic)
  4448.       pedwarn ("invalid storage class for function `%s'",
  4449.            IDENTIFIER_POINTER (declarator));
  4450.  
  4451.     /* If this is a block level extern, it must live past the end
  4452.        of the function so that we can check it against other
  4453.        extern declarations (IDENTIFIER_LIMBO_VALUE).  */
  4454.     if (extern_ref && allocation_temporary_p ())
  4455.       end_temporary_allocation ();
  4456.  
  4457.     decl = build_decl (FUNCTION_DECL, declarator, type);
  4458.  
  4459.     if (pedantic && (constp || volatilep)
  4460.         && ! DECL_IN_SYSTEM_HEADER (decl))
  4461.       pedwarn ("ANSI C forbids const or volatile functions");
  4462.  
  4463.     if (extern_ref)
  4464.       DECL_EXTERNAL (decl) = 1;
  4465.     /* Record absence of global scope for `static' or `auto'.  */
  4466.     TREE_PUBLIC (decl)
  4467.       = !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
  4468.     /* Record presence of `inline', if it is reasonable.  */
  4469.     if (inlinep)
  4470.       {
  4471.         tree last = tree_last (TYPE_ARG_TYPES (type));
  4472.  
  4473.         if (! strcmp (IDENTIFIER_POINTER (declarator), "main"))
  4474.           warning ("cannot inline function `main'");
  4475.         else if (last && (TYPE_MAIN_VARIANT (TREE_VALUE (last))
  4476.                   != void_type_node))
  4477.           warning ("inline declaration ignored for function with `...'");
  4478.         else
  4479.           /* Assume that otherwise the function can be inlined.  */
  4480.           DECL_INLINE (decl) = 1;
  4481.  
  4482.         if (specbits & (1 << (int) RID_EXTERN))
  4483.           current_extern_inline = 1;
  4484.       }
  4485.     /* Record that the function declaration is pascal. */
  4486.     if (flag_apple && pascalp)
  4487.       {
  4488.         TREE_PASCAL (decl) = 1;
  4489.       }
  4490.       }
  4491.     else
  4492.       {
  4493.     /* It's a variable.  */
  4494.     /* An uninitialized decl with `extern' is a reference.  */
  4495.     int extern_ref = !initialized && (specbits & (1 << (int) RID_EXTERN));
  4496.  
  4497.     /* Move type qualifiers down to element of an array.  */
  4498.     if (TREE_CODE (type) == ARRAY_TYPE && (constp || volatilep))
  4499.       {
  4500.         type = build_array_type (c_build_type_variant (TREE_TYPE (type),
  4501.                                constp, volatilep),
  4502.                      TYPE_DOMAIN (type));
  4503. #if 0 /* Leave the variable const or volatile as well.  */
  4504.         constp = volatilep = 0;
  4505. #endif
  4506.       }
  4507.  
  4508.     /* If this is a block level extern, it must live past the end
  4509.        of the function so that we can check it against other
  4510.        extern declarations (IDENTIFIER_LIMBO_VALUE).  */
  4511.     if (extern_ref && allocation_temporary_p ())
  4512.       end_temporary_allocation ();
  4513.  
  4514.     decl = build_decl (VAR_DECL, declarator, type);
  4515.     if (size_varies)
  4516.       C_DECL_VARIABLE_SIZE (decl) = 1;
  4517.  
  4518.     if (inlinep)
  4519.       pedwarn_with_decl (decl, "variable `%s' declared `inline'");
  4520.     /* If Apple extensions are enabled and we saw a `pascal' keyword,
  4521.        set a bit in the variable's tree node. */
  4522.     if (flag_apple && pascalp)
  4523.       {
  4524.         TREE_PASCAL (decl) = 1;
  4525.         /* Maybe complain if we're trying to be strictly ANSI. */
  4526.         if (pedantic)
  4527.           pedwarn_with_decl (decl, "variable `%s' declared `pascal'");
  4528.       }
  4529.  
  4530.     DECL_EXTERNAL (decl) = extern_ref;
  4531.     /* At top level, the presence of a `static' or `register' storage
  4532.        class specifier, or the absence of all storage class specifiers
  4533.        makes this declaration a definition (perhaps tentative).  Also,
  4534.        the absence of both `static' and `register' makes it public.  */
  4535.     if (current_binding_level == global_binding_level)
  4536.       {
  4537.         TREE_PUBLIC (decl)
  4538.           = !(specbits
  4539.           & ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)));
  4540.         TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
  4541.       }
  4542.     /* Not at top level, only `static' makes a static definition.  */
  4543.     else
  4544.       {
  4545.         TREE_STATIC (decl) = (specbits & (1 << (int) RID_STATIC)) != 0;
  4546.         TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
  4547.       }
  4548.       }
  4549.  
  4550.     /* Record `register' declaration for warnings on &
  4551.        and in case doing stupid register allocation.  */
  4552.  
  4553.     if (specbits & (1 << (int) RID_REGISTER))
  4554.       DECL_REGISTER (decl) = 1;
  4555.  
  4556.     /* Record constancy and volatility.  */
  4557.  
  4558.     if (constp)
  4559.       TREE_READONLY (decl) = 1;
  4560. #ifdef APPLE_HAX
  4561.     /* ??? */
  4562.     if (volatilep
  4563.     || (flag_force_volatile && TREE_CODE (type) != FUNCTION_TYPE))
  4564. #else
  4565.     if (volatilep)
  4566. #endif
  4567.       {
  4568.     TREE_SIDE_EFFECTS (decl) = 1;
  4569.     TREE_THIS_VOLATILE (decl) = 1;
  4570.       }
  4571.     /* If a type has volatile components, it should be stored in memory.
  4572.        Otherwise, the fact that those components are volatile
  4573.        will be ignored, and would even crash the compiler.  */
  4574.     if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl)))
  4575.       mark_addressable (decl);
  4576.  
  4577.     pop_obstacks ();
  4578.  
  4579.     return decl;
  4580.   }
  4581. }
  4582.  
  4583. /* Make a variant type in the proper way for C, propagating qualifiers
  4584.    down to the element type of an array.  */
  4585.  
  4586. tree
  4587. c_build_type_variant (type, constp, volatilep)
  4588.      tree type;
  4589.      int constp, volatilep;
  4590. {
  4591.   if (TREE_CODE (type) == ARRAY_TYPE)
  4592.     type = build_array_type (c_build_type_variant (TREE_TYPE (type),
  4593.                            constp, volatilep),
  4594.                  TYPE_DOMAIN (type));
  4595.   return build_type_variant (type, constp, volatilep);
  4596. }
  4597.  
  4598. /* Decode the parameter-list info for a function type or function definition.
  4599.    The argument is the value returned by `get_parm_info' (or made in parse.y
  4600.    if there is an identifier list instead of a parameter decl list).
  4601.    These two functions are separate because when a function returns
  4602.    or receives functions then each is called multiple times but the order
  4603.    of calls is different.  The last call to `grokparms' is always the one
  4604.    that contains the formal parameter names of a function definition.
  4605.  
  4606.    Store in `last_function_parms' a chain of the decls of parms.
  4607.    Also store in `last_function_parm_tags' a chain of the struct, union,
  4608.    and enum tags declared among the parms.
  4609.  
  4610.    Return a list of arg types to use in the FUNCTION_TYPE for this function.
  4611.  
  4612.    FUNCDEF_FLAG is nonzero for a function definition, 0 for
  4613.    a mere declaration.  A nonempty identifier-list gets an error message
  4614.    when FUNCDEF_FLAG is zero.  */
  4615.  
  4616. static tree
  4617. grokparms (parms_info, funcdef_flag)
  4618.      tree parms_info;
  4619.      int funcdef_flag;
  4620. {
  4621.   tree first_parm = TREE_CHAIN (parms_info);
  4622.  
  4623.   last_function_parms = TREE_PURPOSE (parms_info);
  4624.   last_function_parm_tags = TREE_VALUE (parms_info);
  4625.  
  4626.   if (warn_strict_prototypes && first_parm == 0 && !funcdef_flag
  4627.       && !in_system_header)
  4628.     warning ("function declaration isn't a prototype");
  4629.  
  4630.   if (first_parm != 0
  4631.       && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE)
  4632.     {
  4633.       if (! funcdef_flag)
  4634.     pedwarn ("parameter names (without types) in function declaration");
  4635.  
  4636.       last_function_parms = first_parm;
  4637.       return 0;
  4638.     }
  4639.   else
  4640.     {
  4641.       tree parm;
  4642.       tree typelt;
  4643.       /* We no longer test FUNCDEF_FLAG.
  4644.      If the arg types are incomplete in a declaration,
  4645.      they must include undefined tags.
  4646.      These tags can never be defined in the scope of the declaration,
  4647.      so the types can never be completed,
  4648.      and no call can be compiled successfully.  */
  4649. #if 0
  4650.       /* In a fcn definition, arg types must be complete.  */
  4651.       if (funcdef_flag)
  4652. #endif
  4653.     for (parm = last_function_parms, typelt = first_parm;
  4654.          parm;
  4655.          parm = TREE_CHAIN (parm))
  4656.       /* Skip over any enumeration constants declared here.  */
  4657.       if (TREE_CODE (parm) == PARM_DECL)
  4658.         {
  4659.           /* Barf if the parameter itself has an incomplete type.  */
  4660.           tree type = TREE_VALUE (typelt);
  4661.           if (TYPE_SIZE (type) == 0)
  4662.         {
  4663.           if (funcdef_flag && DECL_NAME (parm) != 0)
  4664.             error ("parameter `%s' has incomplete type",
  4665.                IDENTIFIER_POINTER (DECL_NAME (parm)));
  4666.           else
  4667.             warning ("parameter has incomplete type");
  4668.           if (funcdef_flag)
  4669.             {
  4670.               TREE_VALUE (typelt) = error_mark_node;
  4671.               TREE_TYPE (parm) = error_mark_node;
  4672.             }
  4673.         }
  4674. #if 0  /* This has been replaced by parm_tags_warning
  4675.       which uses a more accurate criterion for what to warn about.  */
  4676.           else
  4677.         {
  4678.           /* Now warn if is a pointer to an incomplete type.  */
  4679.           while (TREE_CODE (type) == POINTER_TYPE
  4680.              || TREE_CODE (type) == REFERENCE_TYPE)
  4681.             type = TREE_TYPE (type);
  4682.           type = TYPE_MAIN_VARIANT (type);
  4683.           if (TYPE_SIZE (type) == 0)
  4684.             {
  4685.               if (DECL_NAME (parm) != 0)
  4686.             warning ("parameter `%s' points to incomplete type",
  4687.                  IDENTIFIER_POINTER (DECL_NAME (parm)));
  4688.               else
  4689.             warning ("parameter points to incomplete type");
  4690.             }
  4691.         }
  4692. #endif
  4693.           typelt = TREE_CHAIN (typelt);
  4694.         }
  4695.  
  4696.       /* Allocate the list of types the way we allocate a type.  */
  4697.       if (first_parm && ! TREE_PERMANENT (first_parm))
  4698.     {
  4699.       /* Construct a copy of the list of types
  4700.          on the saveable obstack.  */
  4701.       tree result = NULL;
  4702.       for (typelt = first_parm; typelt; typelt = TREE_CHAIN (typelt))
  4703.         result = saveable_tree_cons (NULL_TREE, TREE_VALUE (typelt),
  4704.                      result);
  4705.       return nreverse (result);
  4706.     }
  4707.       else
  4708.     /* The list we have is permanent already.  */
  4709.     return first_parm;
  4710.     }
  4711. }
  4712.  
  4713. #ifdef MPW
  4714. #pragma segment CDECL02
  4715. #endif
  4716.  
  4717. /* Return a tree_list node with info on a parameter list just parsed.
  4718.    The TREE_PURPOSE is a chain of decls of those parms.
  4719.    The TREE_VALUE is a list of structure, union and enum tags defined.
  4720.    The TREE_CHAIN is a list of argument types to go in the FUNCTION_TYPE.
  4721.    This tree_list node is later fed to `grokparms'.
  4722.  
  4723.    VOID_AT_END nonzero means append `void' to the end of the type-list.
  4724.    Zero means the parmlist ended with an ellipsis so don't append `void'.  */
  4725.  
  4726. tree
  4727. get_parm_info (void_at_end)
  4728.      int void_at_end;
  4729. {
  4730.   register tree decl, t;
  4731.   register tree types = 0;
  4732.   int erred = 0;
  4733.   tree tags = gettags ();
  4734.   tree parms = getdecls ();
  4735.   tree new_parms = 0;
  4736.   tree order = current_binding_level->parm_order;
  4737.  
  4738.   /* Just `void' (and no ellipsis) is special.  There are really no parms.  */
  4739.   if (void_at_end && parms != 0
  4740.       && TREE_CHAIN (parms) == 0
  4741.       && TYPE_MAIN_VARIANT (TREE_TYPE (parms)) == void_type_node
  4742.       && DECL_NAME (parms) == 0)
  4743.     {
  4744.       parms = NULL_TREE;
  4745.       storedecls (NULL_TREE);
  4746.       return saveable_tree_cons (NULL_TREE, NULL_TREE,
  4747.                  saveable_tree_cons (NULL_TREE, void_type_node, NULL_TREE));
  4748.     }
  4749.  
  4750.   /* Extract enumerator values and other non-parms declared with the parms.
  4751.      Likewise any forward parm decls that didn't have real parm decls.  */
  4752.   for (decl = parms; decl; )
  4753.     {
  4754.       tree next = TREE_CHAIN (decl);
  4755.  
  4756.       if (TREE_CODE (decl) != PARM_DECL)
  4757.     {
  4758.       TREE_CHAIN (decl) = new_parms;
  4759.       new_parms = decl;
  4760.     }
  4761.       else if (TREE_ASM_WRITTEN (decl))
  4762.     {
  4763.       error_with_decl (decl, "parameter `%s' has just a forward declaration");
  4764.       TREE_CHAIN (decl) = new_parms;
  4765.       new_parms = decl;
  4766.     }
  4767.       decl = next;
  4768.     }
  4769.  
  4770.   /* Put the parm decls back in the order they were in in the parm list.  */
  4771.   for (t = order; t; t = TREE_CHAIN (t))
  4772.     {
  4773.       if (TREE_CHAIN (t))
  4774.     TREE_CHAIN (TREE_VALUE (t)) = TREE_VALUE (TREE_CHAIN (t));
  4775.       else
  4776.     TREE_CHAIN (TREE_VALUE (t)) = 0;
  4777.     }
  4778.  
  4779.   new_parms = chainon (order ? nreverse (TREE_VALUE (order)) : 0,
  4780.                new_parms);
  4781.  
  4782.   /* Store the parmlist in the binding level since the old one
  4783.      is no longer a valid list.  (We have changed the chain pointers.)  */
  4784.   storedecls (new_parms);
  4785.  
  4786.   for (decl = new_parms; decl; decl = TREE_CHAIN (decl))
  4787.     /* There may also be declarations for enumerators if an enumeration
  4788.        type is declared among the parms.  Ignore them here.  */
  4789.     if (TREE_CODE (decl) == PARM_DECL)
  4790.       {
  4791.     /* Since there is a prototype,
  4792.        args are passed in their declared types.  */
  4793.     tree type = TREE_TYPE (decl);
  4794.     DECL_ARG_TYPE (decl) = type;
  4795. #ifdef PROMOTE_PROTOTYPES
  4796.     if (TREE_CODE (type) == INTEGER_TYPE
  4797.         /* Don't promote 2-byte integer args to pascal functions. */
  4798.         && (flag_apple && current_function_decl && ! TREE_PASCAL (current_function_decl))
  4799.         && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
  4800.       DECL_ARG_TYPE (decl) = integer_type_node;
  4801. #endif
  4802.     /* Promote all floating parameters to long double. */
  4803.     if (flag_apple && TREE_CODE (type) == REAL_TYPE
  4804.         && TYPE_PRECISION (type) < TYPE_PRECISION (long_double_type_node))
  4805.       DECL_ARG_TYPE (decl) = long_double_type_node;
  4806.  
  4807.     types = saveable_tree_cons (NULL_TREE, TREE_TYPE (decl), types);
  4808.     if (TYPE_MAIN_VARIANT (TREE_VALUE (types)) == void_type_node && ! erred
  4809.         && DECL_NAME (decl) == 0)
  4810.       {
  4811.         error ("`void' in parameter list must be the entire list");
  4812.         erred = 1;
  4813.       }
  4814.       }
  4815.  
  4816.   if (void_at_end)
  4817.     return saveable_tree_cons (new_parms, tags,
  4818.                    nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types)));
  4819.  
  4820.   return saveable_tree_cons (new_parms, tags, nreverse (types));
  4821. }
  4822.  
  4823. /* At end of parameter list, warn about any struct, union or enum tags
  4824.    defined within.  Do so because these types cannot ever become complete.  */
  4825.  
  4826. void
  4827. parmlist_tags_warning ()
  4828. {
  4829.   tree elt;
  4830.   static int already;
  4831.  
  4832.   for (elt = current_binding_level->tags; elt; elt = TREE_CHAIN (elt))
  4833.     {
  4834.       enum tree_code code = TREE_CODE (TREE_VALUE (elt));
  4835.       /* An anonymous union parm type is meaningful as a GNU extension.
  4836.      So don't warn for that.  */
  4837.       if (code == UNION_TYPE && !pedantic)
  4838.     continue;
  4839.       if (TREE_PURPOSE (elt) != 0)
  4840.     warning ("`%s %s' declared inside parameter list",
  4841.          (code == RECORD_TYPE ? "struct"
  4842.           : code == UNION_TYPE ? "union"
  4843.           : "enum"),
  4844.          IDENTIFIER_POINTER (TREE_PURPOSE (elt)));
  4845.       else
  4846.     warning ("anonymous %s declared inside parameter list",
  4847.          (code == RECORD_TYPE ? "struct"
  4848.           : code == UNION_TYPE ? "union"
  4849.           : "enum"));
  4850.  
  4851.       if (! already)
  4852.     {
  4853.       warning ("its scope is only this definition or declaration,");
  4854.       warning ("which is probably not what you want.");
  4855.       already = 1;
  4856.     }
  4857.     }
  4858. }
  4859.  
  4860. /* Get the struct, enum or union (CODE says which) with tag NAME.
  4861.    Define the tag as a forward-reference if it is not defined.  */
  4862.  
  4863. tree
  4864. xref_tag (code, name)
  4865.      enum tree_code code;
  4866.      tree name;
  4867. {
  4868.   int temporary = allocation_temporary_p ();
  4869.  
  4870.   /* If a cross reference is requested, look up the type
  4871.      already defined for this tag and return it.  */
  4872.  
  4873.   register tree ref = lookup_tag (code, name, current_binding_level, 0);
  4874.   /* Even if this is the wrong type of tag, return what we found.
  4875.      There will be an error message anyway, from pending_xref_error.
  4876.      If we create an empty xref just for an invalid use of the type,
  4877.      the main result is to create lots of superfluous error messages.  */
  4878.   if (ref)
  4879.     return ref;
  4880.  
  4881.   push_obstacks_nochange ();
  4882.  
  4883.   if (current_binding_level == global_binding_level && temporary)
  4884.     end_temporary_allocation ();
  4885.  
  4886.   /* If no such tag is yet defined, create a forward-reference node
  4887.      and record it as the "definition".
  4888.      When a real declaration of this type is found,
  4889.      the forward-reference will be altered into a real type.  */
  4890.  
  4891.   ref = make_node (code);
  4892.   if (code == ENUMERAL_TYPE)
  4893.     {
  4894.       /* (In ANSI, Enums can be referred to only if already defined.)  */
  4895.       if (pedantic)
  4896.     pedwarn ("ANSI C forbids forward references to `enum' types");
  4897.       /* Give the type a default layout like unsigned int
  4898.      to avoid crashing if it does not get defined.  */
  4899.       TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node);
  4900.       TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node);
  4901.       TREE_UNSIGNED (ref) = 1;
  4902.       TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node);
  4903.       TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node);
  4904.       TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node);
  4905.     }
  4906.  
  4907.   pushtag (name, ref);
  4908.  
  4909.   pop_obstacks ();
  4910.  
  4911.   return ref;
  4912. }
  4913.  
  4914. /* Make sure that the tag NAME is defined *in the current binding level*
  4915.    at least as a forward reference.
  4916.    CODE says which kind of tag NAME ought to be.
  4917.  
  4918.    We also do a push_obstacks_nochange
  4919.    whose matching pop is in finish_struct.  */
  4920.  
  4921. tree
  4922. start_struct (code, name)
  4923.      enum tree_code code;
  4924.      tree name;
  4925. {
  4926.   /* If there is already a tag defined at this binding level
  4927.      (as a forward reference), just return it.  */
  4928.  
  4929.   register tree ref = 0;
  4930.  
  4931.   push_obstacks_nochange ();
  4932.   if (current_binding_level == global_binding_level)
  4933.     end_temporary_allocation ();
  4934.  
  4935.   if (name != 0)
  4936.     ref = lookup_tag (code, name, current_binding_level, 1);
  4937.   if (ref && TREE_CODE (ref) == code)
  4938.     {
  4939.       C_TYPE_BEING_DEFINED (ref) = 1;
  4940.       if (TYPE_FIELDS (ref))
  4941.     error ((code == UNION_TYPE ? "redefinition of `union %s'"
  4942.         : "redefinition of `struct %s'"),
  4943.            IDENTIFIER_POINTER (name));
  4944.  
  4945.       return ref;
  4946.     }
  4947.  
  4948.   /* Otherwise create a forward-reference just so the tag is in scope.  */
  4949.  
  4950.   ref = make_node (code);
  4951.   pushtag (name, ref);
  4952.   C_TYPE_BEING_DEFINED (ref) = 1;
  4953.   return ref;
  4954. }
  4955.  
  4956. /* Process the specs, declarator (NULL if omitted) and width (NULL if omitted)
  4957.    of a structure component, returning a FIELD_DECL node.
  4958.    WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node.
  4959.  
  4960.    This is done during the parsing of the struct declaration.
  4961.    The FIELD_DECL nodes are chained together and the lot of them
  4962.    are ultimately passed to `build_struct' to make the RECORD_TYPE node.  */
  4963.  
  4964. tree
  4965. grokfield (filename, line, declarator, declspecs, width)
  4966.      char *filename;
  4967.      int line;
  4968.      tree declarator, declspecs, width;
  4969. {
  4970.   tree value;
  4971.  
  4972.   /* The corresponding pop_obstacks is in finish_decl.  */
  4973.   push_obstacks_nochange ();
  4974.  
  4975.   value = grokdeclarator (declarator, declspecs, width ? BITFIELD : FIELD, 0);
  4976.  
  4977.   finish_decl (value, NULL_TREE, NULL_TREE);
  4978.   DECL_INITIAL (value) = width;
  4979.  
  4980.   return value;
  4981. }
  4982.  
  4983. /* Function to help qsort sort FIELD_DECLs by name order.  */
  4984.  
  4985. static int
  4986. field_decl_cmp (x, y)
  4987.      tree *x, *y;
  4988. {
  4989.   return (long)DECL_NAME (*x) - (long)DECL_NAME (*y);
  4990. }
  4991.  
  4992. /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
  4993.    FIELDLIST is a chain of FIELD_DECL nodes for the fields.
  4994.  
  4995.    We also do a pop_obstacks to match the push in start_struct.  */
  4996.  
  4997. tree
  4998. finish_struct (t, fieldlist)
  4999.      register tree t, fieldlist;
  5000. {
  5001.   register tree x;
  5002.   int old_momentary;
  5003.   int toplevel = global_binding_level == current_binding_level;
  5004.  
  5005.   /* If this type was previously laid out as a forward reference,
  5006.      make sure we lay it out again.  */
  5007.  
  5008.   TYPE_SIZE (t) = 0;
  5009.  
  5010.   /* Nameless union parm types are useful as GCC extension.  */
  5011.   if (! (TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) == 0) && !pedantic)
  5012.     /* Otherwise, warn about any struct or union def. in parmlist.  */
  5013.     if (in_parm_level_p ())
  5014.       {
  5015.     if (pedantic)
  5016.       pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
  5017.             : "structure defined inside parms"));
  5018.     else
  5019.       warning ((TREE_CODE (t) == UNION_TYPE ? "union defined inside parms"
  5020.             : "structure defined inside parms"));
  5021.       }
  5022.  
  5023.   old_momentary = suspend_momentary ();
  5024.  
  5025.   if (fieldlist == 0 && pedantic)
  5026.     pedwarn ((TREE_CODE (t) == UNION_TYPE ? "union has no members"
  5027.           : "structure has no members"));
  5028.  
  5029.   /* Install struct as DECL_CONTEXT of each field decl.
  5030.      Also process specified field sizes.
  5031.      Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
  5032.      The specified size is found in the DECL_INITIAL.
  5033.      Store 0 there, except for ": 0" fields (so we can find them
  5034.      and delete them, below).  */
  5035.  
  5036.   for (x = fieldlist; x; x = TREE_CHAIN (x))
  5037.     {
  5038.       DECL_CONTEXT (x) = t;
  5039.       DECL_FIELD_SIZE (x) = 0;
  5040.  
  5041.       /* If any field is const, the structure type is pseudo-const.  */
  5042.       if (TREE_READONLY (x))
  5043.     C_TYPE_FIELDS_READONLY (t) = 1;
  5044.       else
  5045.     {
  5046.       /* A field that is pseudo-const makes the structure likewise.  */
  5047.       tree t1 = TREE_TYPE (x);
  5048.       while (TREE_CODE (t1) == ARRAY_TYPE)
  5049.         t1 = TREE_TYPE (t1);
  5050.       if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE)
  5051.           && C_TYPE_FIELDS_READONLY (t1))
  5052.         C_TYPE_FIELDS_READONLY (t) = 1;
  5053.     }
  5054.  
  5055.       /* Any field that is volatile means variables of this type must be
  5056.      treated in some ways as volatile.  */
  5057.       if (TREE_THIS_VOLATILE (x))
  5058.     C_TYPE_FIELDS_VOLATILE (t) = 1;
  5059.  
  5060.       /* Any field of nominal variable size implies structure is too.  */
  5061.       if (C_DECL_VARIABLE_SIZE (x))
  5062.     C_TYPE_VARIABLE_SIZE (t) = 1;
  5063.  
  5064.       /* Detect invalid nested redefinition.  */
  5065.       if (TREE_TYPE (x) == t)
  5066.     error ("nested redefinition of `%s'",
  5067.            IDENTIFIER_POINTER (TYPE_NAME (t)));
  5068.  
  5069.       /* Detect invalid bit-field size.  */
  5070.       if (DECL_INITIAL (x))
  5071.     STRIP_NOPS (DECL_INITIAL (x));
  5072.       if (DECL_INITIAL (x) && TREE_CODE (DECL_INITIAL (x)) != INTEGER_CST)
  5073.     {
  5074.       error_with_decl (x, "bit-field `%s' width not an integer constant");
  5075.       DECL_INITIAL (x) = NULL;
  5076.     }
  5077.  
  5078.       /* Detect invalid bit-field type.  */
  5079.       if (DECL_INITIAL (x)
  5080.       && TREE_CODE (TREE_TYPE (x)) != INTEGER_TYPE
  5081.       && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
  5082.     {
  5083.       error_with_decl (x, "bit-field `%s' has invalid type");
  5084.       DECL_INITIAL (x) = NULL;
  5085.     }
  5086.       if (DECL_INITIAL (x) && pedantic
  5087.       && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
  5088.       && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node)
  5089.     pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C");
  5090.  
  5091.       /* Detect and ignore out of range field width.  */
  5092.       if (DECL_INITIAL (x))
  5093.     {
  5094.       unsigned HOST_WIDE_INT width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  5095.  
  5096.       if (tree_int_cst_lt (DECL_INITIAL (x), integer_zero_node))
  5097.         {
  5098.           DECL_INITIAL (x) = NULL;
  5099.           error_with_decl (x, "negative width in bit-field `%s'");
  5100.         }
  5101.       else if (TREE_INT_CST_HIGH (DECL_INITIAL (x)) != 0
  5102.            || width > TYPE_PRECISION (TREE_TYPE (x)))
  5103.         {
  5104.           DECL_INITIAL (x) = NULL;
  5105.           pedwarn_with_decl (x, "width of `%s' exceeds its type");
  5106.         }
  5107.       else if (width == 0 && DECL_NAME (x) != 0)
  5108.         {
  5109.           error_with_decl (x, "zero width for bit-field `%s'");
  5110.           DECL_INITIAL (x) = NULL;
  5111.         }
  5112.     }
  5113.  
  5114.       /* Process valid field width.  */
  5115.       if (DECL_INITIAL (x))
  5116.     {
  5117.       register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
  5118.  
  5119.       DECL_FIELD_SIZE (x) = width;
  5120.       DECL_BIT_FIELD (x) = 1;
  5121.       DECL_INITIAL (x) = NULL;
  5122.  
  5123.       if (width == 0)
  5124.         {
  5125.           /* field size 0 => force desired amount of alignment.  */
  5126. #ifdef EMPTY_FIELD_BOUNDARY
  5127.           DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
  5128. #endif
  5129. #ifdef PCC_BITFIELD_TYPE_MATTERS
  5130.           DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
  5131.                     TYPE_ALIGN (TREE_TYPE (x)));
  5132. #endif
  5133.         }
  5134.     }
  5135.       else
  5136.     {
  5137.       int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
  5138.                : TYPE_ALIGN (TREE_TYPE (x)));
  5139.       /* Non-bit-fields are aligned for their type, except packed
  5140.          fields which require only BITS_PER_UNIT alignment.  */
  5141.       DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
  5142.     }
  5143.     }
  5144.  
  5145.   /* Now DECL_INITIAL is null on all members.  */
  5146.  
  5147.   /* Delete all duplicate fields from the fieldlist */
  5148.   for (x = fieldlist; x && TREE_CHAIN (x);)
  5149.     /* Anonymous fields aren't duplicates.  */
  5150.     if (DECL_NAME (TREE_CHAIN (x)) == 0)
  5151.       x = TREE_CHAIN (x);
  5152.     else
  5153.       {
  5154.     register tree y = fieldlist;
  5155.       
  5156.     while (1)
  5157.       {
  5158.         if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
  5159.           break;
  5160.         if (y == x)
  5161.           break;
  5162.         y = TREE_CHAIN (y);
  5163.       }
  5164.     if (DECL_NAME (y) == DECL_NAME (TREE_CHAIN (x)))
  5165.       {
  5166.         error_with_decl (TREE_CHAIN (x), "duplicate member `%s'");
  5167.         TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
  5168.       }
  5169.     else x = TREE_CHAIN (x);
  5170.       }
  5171.  
  5172.   /* Now we have the nearly final fieldlist.  Record it,
  5173.      then lay out the structure or union (including the fields).  */
  5174.  
  5175.   TYPE_FIELDS (t) = fieldlist;
  5176.  
  5177.   layout_type (t);
  5178.  
  5179.   /* Delete all zero-width bit-fields from the front of the fieldlist */
  5180.   while (fieldlist
  5181.      && DECL_INITIAL (fieldlist))
  5182.     fieldlist = TREE_CHAIN (fieldlist);
  5183.   /* Delete all such members from the rest of the fieldlist */
  5184.   for (x = fieldlist; x;)
  5185.     {
  5186.       if (TREE_CHAIN (x) && DECL_INITIAL (TREE_CHAIN (x)))
  5187.     TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
  5188.       else x = TREE_CHAIN (x);
  5189.     }
  5190.  
  5191.   /*  Now we have the truly final field list.
  5192.       Store it in this type and in the variants.  */
  5193.  
  5194.   TYPE_FIELDS (t) = fieldlist;
  5195.  
  5196.   /* If there are lots of fields, sort so we can look through them fast.
  5197.      We arbitrarily consider 16 or more elts to be "a lot".  */
  5198.   {
  5199.     int len = 0;
  5200.  
  5201.     for (x = fieldlist; x; x = TREE_CHAIN (x))
  5202.       {
  5203.     if (len > 15)
  5204.       break;
  5205.     len += 1;
  5206.       }
  5207.     if (len > 15)
  5208.       {
  5209.     tree *field_array;
  5210.     char *space;
  5211.  
  5212.     len += list_length (x);
  5213.     /* Use the same allocation policy here that make_node uses, to
  5214.        ensure that this lives as long as the rest of the struct decl.
  5215.        All decls in an inline function need to be saved.  */
  5216.     if (allocation_temporary_p ())
  5217.       space = savealloc (sizeof (struct lang_type) + len * sizeof (tree));
  5218.     else
  5219.       space = oballoc (sizeof (struct lang_type) + len * sizeof (tree));
  5220.  
  5221.     TYPE_LANG_SPECIFIC (t) = (struct lang_type *) space;
  5222.     TYPE_LANG_SPECIFIC (t)->len = len;
  5223.  
  5224.     field_array = &TYPE_LANG_SPECIFIC (t)->elts[0];
  5225.     len = 0;
  5226.     for (x = fieldlist; x; x = TREE_CHAIN (x))
  5227.       field_array[len++] = x;
  5228.  
  5229.     qsort (field_array, len, sizeof (tree), field_decl_cmp);
  5230.       }
  5231.   }
  5232.  
  5233.   for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
  5234.     {
  5235.       TYPE_FIELDS (x) = TYPE_FIELDS (t);
  5236.       TYPE_LANG_SPECIFIC (x) = TYPE_LANG_SPECIFIC (t);
  5237.       TYPE_ALIGN (x) = TYPE_ALIGN (t);
  5238.     }
  5239.  
  5240.   /* Promote each bit-field's type to int if it is narrower than that.  */
  5241.   for (x = fieldlist; x; x = TREE_CHAIN (x))
  5242.     if (DECL_BIT_FIELD (x)
  5243.     && C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x)))
  5244.     {
  5245.       tree type = TREE_TYPE (x);
  5246.  
  5247.       /* Preserve unsignedness if traditional or if not really any wider.  */
  5248.       if (TREE_UNSIGNED (type)
  5249.       && (flag_traditional
  5250.           || (TYPE_PRECISION (type)
  5251.           == TYPE_PRECISION (integer_type_node))))
  5252.     TREE_TYPE (x) = unsigned_type_node;
  5253.       else
  5254.     TREE_TYPE (x) = integer_type_node;
  5255.     }
  5256.  
  5257.   /* If this structure or union completes the type of any previous
  5258.      variable declaration, lay it out and output its rtl.  */
  5259.  
  5260.   if (current_binding_level->n_incomplete != 0)
  5261.     {
  5262.       tree decl;
  5263.       for (decl = current_binding_level->names; decl; decl = TREE_CHAIN (decl))
  5264.     {
  5265.       if (TREE_TYPE (decl) == t
  5266.           && TREE_CODE (decl) != TYPE_DECL)
  5267.         {
  5268.           layout_decl (decl, 0);
  5269.           /* This is a no-op in c-lang.c or something real in objc-actions.c.  */
  5270.           maybe_objc_check_decl (decl);
  5271.           rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0);
  5272.           if (! toplevel)
  5273.         expand_decl (decl);
  5274.           --current_binding_level->n_incomplete;
  5275.         }
  5276.       else if (TYPE_SIZE (TREE_TYPE (decl)) == 0
  5277.            && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
  5278.         {
  5279.           tree element = TREE_TYPE (decl);
  5280.           while (TREE_CODE (element) == ARRAY_TYPE)
  5281.         element = TREE_TYPE (element);
  5282.           if (element == t)
  5283.         layout_array_type (TREE_TYPE (decl));
  5284.         }
  5285.     }
  5286.     }
  5287.  
  5288.   resume_momentary (old_momentary);
  5289.  
  5290.   /* Finish debugging output for this type.  */
  5291.   rest_of_type_compilation (t, toplevel);
  5292.  
  5293.   /* The matching push is in start_struct.  */
  5294.   pop_obstacks ();
  5295.  
  5296.   return t;
  5297. }
  5298.  
  5299. /* Lay out the type T, and its element type, and so on.  */
  5300.  
  5301. static void
  5302. layout_array_type (t)
  5303.      tree t;
  5304. {
  5305.   if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
  5306.     layout_array_type (TREE_TYPE (t));
  5307.   layout_type (t);
  5308. }
  5309.  
  5310. /* Begin compiling the definition of an enumeration type.
  5311.    NAME is its name (or null if anonymous).
  5312.    Returns the type object, as yet incomplete.
  5313.    Also records info about it so that build_enumerator
  5314.    may be used to declare the individual values as they are read.  */
  5315.  
  5316. tree
  5317. start_enum (name)
  5318.      tree name;
  5319. {
  5320.   register tree enumtype = 0;
  5321.  
  5322.   /* If this is the real definition for a previous forward reference,
  5323.      fill in the contents in the same object that used to be the
  5324.      forward reference.  */
  5325.  
  5326.   if (name != 0)
  5327.     enumtype = lookup_tag (ENUMERAL_TYPE, name, current_binding_level, 1);
  5328.  
  5329.   /* The corresponding pop_obstacks is in finish_enum.  */
  5330.   push_obstacks_nochange ();
  5331.   /* If these symbols and types are global, make them permanent.  */
  5332.   if (current_binding_level == global_binding_level)
  5333.     end_temporary_allocation ();
  5334.  
  5335.   if (enumtype == 0 || TREE_CODE (enumtype) != ENUMERAL_TYPE)
  5336.     {
  5337.       enumtype = make_node (ENUMERAL_TYPE);
  5338.       pushtag (name, enumtype);
  5339.     }
  5340.  
  5341.   C_TYPE_BEING_DEFINED (enumtype) = 1;
  5342.  
  5343.   if (TYPE_VALUES (enumtype) != 0)
  5344.     {
  5345.       /* This enum is a named one that has been declared already.  */
  5346.       error ("redeclaration of `enum %s'", IDENTIFIER_POINTER (name));
  5347.  
  5348.       /* Completely replace its old definition.
  5349.      The old enumerators remain defined, however.  */
  5350.       TYPE_VALUES (enumtype) = 0;
  5351.     }
  5352.  
  5353.   enum_next_value = integer_zero_node;
  5354.   enum_overflow = 0;
  5355.  
  5356.   return enumtype;
  5357. }
  5358.  
  5359. /* After processing and defining all the values of an enumeration type,
  5360.    install their decls in the enumeration type and finish it off.
  5361.    ENUMTYPE is the type object and VALUES a list of decl-value pairs.
  5362.    Returns ENUMTYPE.  */
  5363.  
  5364. tree
  5365. finish_enum (enumtype, values)
  5366.      register tree enumtype, values;
  5367. {
  5368.   register tree pair;
  5369.   tree minnode = 0, maxnode = 0;
  5370.   register HOST_WIDE_INT maxvalue = 0;
  5371.   register HOST_WIDE_INT minvalue = 0;
  5372.   register int i;
  5373.   unsigned precision = 0;
  5374.   int toplevel = global_binding_level == current_binding_level;
  5375.   int temporary = allocation_temporary_p ();
  5376.  
  5377.   if (in_parm_level_p ())
  5378.     warning ("enum defined inside parms");
  5379.  
  5380.   /* Calculate the maximum value of any enumerator in this type.  */
  5381.  
  5382.   for (pair = values; pair; pair = TREE_CHAIN (pair))
  5383.     {
  5384.       tree value = TREE_VALUE (pair);
  5385.       if (pair == values)
  5386.     minnode = maxnode = TREE_VALUE (pair);
  5387.       else
  5388.     {
  5389.       if (tree_int_cst_lt (maxnode, value))
  5390.         maxnode = value;
  5391.       if (tree_int_cst_lt (value, minnode))
  5392.         minnode = value;
  5393.     }
  5394.     }
  5395.  
  5396.   TYPE_MIN_VALUE (enumtype) = minnode;
  5397.   TYPE_MAX_VALUE (enumtype) = maxnode;
  5398.  
  5399.   /* Determine the precision this type needs.  */
  5400.  
  5401.   if (TREE_INT_CST_HIGH (minnode) >= 0
  5402.       ? tree_int_cst_lt (TYPE_MAX_VALUE (unsigned_type_node), maxnode)
  5403.       : (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
  5404.      || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode)))
  5405.     precision = TYPE_PRECISION (long_long_integer_type_node);
  5406.   else
  5407.     {
  5408.       maxvalue = TREE_INT_CST_LOW (maxnode);
  5409.       minvalue = TREE_INT_CST_LOW (minnode);
  5410.  
  5411.       if (maxvalue > 0)
  5412.     precision = floor_log2 (maxvalue) + 1;
  5413.       if (minvalue < 0)
  5414.     {
  5415.       /* Compute number of bits to represent magnitude of a negative value.
  5416.          Add one to MINVALUE since range of negative numbers
  5417.          includes the power of two.  */
  5418.       unsigned negprecision = floor_log2 (-minvalue - 1) + 1;
  5419.       if (negprecision > precision)
  5420.         precision = negprecision;
  5421.       precision += 1;    /* room for sign bit */
  5422.     }
  5423.  
  5424.       if (!precision)
  5425.     precision = 1;
  5426.     }
  5427.  
  5428.   if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node))
  5429.     /* Use the width of the narrowest normal C type which is wide enough.  */
  5430.     TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1));
  5431.   else
  5432.     TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
  5433. #if 1
  5434. if(TYPE_PRECISION (enumtype) == 1) warning("Enum precision = 1");
  5435. #endif
  5436.  
  5437.   TYPE_SIZE (enumtype) = 0;
  5438.   layout_type (enumtype);
  5439. #if 1
  5440. if(TYPE_SIZE (enumtype) == 1) warning("Enum size = 1");
  5441. if(TYPE_MODE (enumtype) == QImode) warning("Enum is qi");
  5442. #endif
  5443.  
  5444.  
  5445.   /* An enum can have some negative values; then it is signed.  */
  5446.   TREE_UNSIGNED (enumtype) = ! tree_int_cst_lt (minnode, integer_zero_node);
  5447.  
  5448.   /* If the enumerators might not fit in an int, change their type now.  */
  5449.   /* It seems more useful in the debugger to leave these as int
  5450.      unless the enumerator is wider than int.  */
  5451.   if (TYPE_PRECISION (enumtype) <= TYPE_PRECISION (integer_type_node))
  5452.     for (pair = values; pair; pair = TREE_CHAIN (pair))
  5453.       {
  5454.     TREE_TYPE (TREE_PURPOSE (pair)) = enumtype;
  5455.     DECL_SIZE (TREE_PURPOSE (pair)) = TYPE_SIZE (enumtype);
  5456.     if (TREE_CODE (TREE_PURPOSE (pair)) != FUNCTION_DECL)
  5457.       DECL_ALIGN (TREE_PURPOSE (pair)) = TYPE_ALIGN (enumtype);
  5458.       }
  5459.  
  5460.   /* Replace the decl nodes in VALUES with their names.  */
  5461.   for (pair = values; pair; pair = TREE_CHAIN (pair))
  5462.     TREE_PURPOSE (pair) = DECL_NAME (TREE_PURPOSE (pair));
  5463.  
  5464.   TYPE_VALUES (enumtype) = values;
  5465.  
  5466.   /* Finish debugging output for this type.  */
  5467.   rest_of_type_compilation (enumtype, toplevel);
  5468.  
  5469.   /* This matches a push in start_enum.  */
  5470.   pop_obstacks ();
  5471.  
  5472.   return enumtype;
  5473. }
  5474.  
  5475. /* Build and install a CONST_DECL for one value of the
  5476.    current enumeration type (one that was begun with start_enum).
  5477.    Return a tree-list containing the CONST_DECL and its value.
  5478.    Assignment of sequential values by default is handled here.  */
  5479.  
  5480. tree
  5481. build_enumerator (name, value)
  5482.      tree name, value;
  5483. {
  5484.   register tree decl;
  5485.  
  5486.   /* Validate and default VALUE.  */
  5487.  
  5488.   /* Remove no-op casts from the value.  */
  5489.   if (value)
  5490.     STRIP_TYPE_NOPS (value);
  5491.  
  5492.   if (value != 0 && TREE_CODE (value) != INTEGER_CST)
  5493.     {
  5494.       error ("enumerator value for `%s' not integer constant",
  5495.          IDENTIFIER_POINTER (name));
  5496.       value = 0;
  5497.     }
  5498.  
  5499.   /* Default based on previous value.  */
  5500.   /* It should no longer be possible to have NON_LVALUE_EXPR
  5501.      in the default.  */
  5502.   if (value == 0)
  5503.     {
  5504.       value = enum_next_value;
  5505.       if (enum_overflow)
  5506.     error ("overflow in enumeration values");
  5507.     }
  5508.  
  5509.   if (pedantic && ! int_fits_type_p (value, integer_type_node))
  5510.     {
  5511.       pedwarn ("ANSI C restricts enumerator values to range of `int'");
  5512.       value = integer_zero_node;
  5513.     }
  5514.  
  5515.   /* Set basis for default for next value.  */
  5516.   enum_next_value = build_binary_op (PLUS_EXPR, value, integer_one_node, 0);
  5517.   enum_overflow = tree_int_cst_lt (enum_next_value, value);
  5518.  
  5519.   /* Now create a declaration for the enum value name.  */
  5520.  
  5521.   decl = build_decl (CONST_DECL, name, integer_type_node);
  5522.   DECL_INITIAL (decl) = value;
  5523.   TREE_TYPE (value) = integer_type_node;
  5524.   pushdecl (decl);
  5525.  
  5526.   return saveable_tree_cons (decl, value, NULL_TREE);
  5527. }
  5528.  
  5529. /* Create the FUNCTION_DECL for a function definition.
  5530.    DECLSPECS and DECLARATOR are the parts of the declaration;
  5531.    they describe the function's name and the type it returns,
  5532.    but twisted together in a fashion that parallels the syntax of C.
  5533.  
  5534.    This function creates a binding context for the function body
  5535.    as well as setting up the FUNCTION_DECL in current_function_decl.
  5536.  
  5537.    Returns 1 on success.  If the DECLARATOR is not suitable for a function
  5538.    (it defines a datum instead), we return 0, which tells
  5539.    yyparse to report a parse error.
  5540.  
  5541.    NESTED is nonzero for a function nested within another function.  */
  5542.  
  5543. int
  5544. start_function (declspecs, declarator, nested)
  5545.      tree declarator, declspecs;
  5546.      int nested;
  5547. {
  5548.   tree decl1, old_decl;
  5549.   tree restype;
  5550.  
  5551.   current_function_returns_value = 0;  /* Assume, until we see it does. */
  5552.   current_function_returns_null = 0;
  5553.   warn_about_return_type = 0;
  5554.   current_extern_inline = 0;
  5555.   c_function_varargs = 0;
  5556.   named_labels = 0;
  5557.   shadowed_labels = 0;
  5558.  
  5559.   decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1);
  5560.  
  5561.   /* If the declarator is not suitable for a function definition,
  5562.      cause a syntax error.  */
  5563.   if (decl1 == 0)
  5564.     return 0;
  5565.  
  5566.   announce_function (decl1);
  5567.  
  5568.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
  5569.     {
  5570.       error ("return-type is an incomplete type");
  5571.       /* Make it return void instead.  */
  5572.       TREE_TYPE (decl1)
  5573.     = build_function_type (void_type_node,
  5574.                    TYPE_ARG_TYPES (TREE_TYPE (decl1)));
  5575.     }
  5576.  
  5577.   if (warn_about_return_type)
  5578.     warning ("return-type defaults to `int'");
  5579.  
  5580.   /* Save the parm names or decls from this function's declarator
  5581.      where store_parm_decls will find them.  */
  5582.   current_function_parms = last_function_parms;
  5583.   current_function_parm_tags = last_function_parm_tags;
  5584.  
  5585.   /* Make the init_value nonzero so pushdecl knows this is not tentative.
  5586.      error_mark_node is replaced below (in poplevel) with the BLOCK.  */
  5587.   DECL_INITIAL (decl1) = error_mark_node;
  5588.  
  5589.   /* If this definition isn't a prototype and we had a prototype declaration
  5590.      before, copy the arg type info from that prototype.
  5591.      But not if what we had before was a builtin function.  */
  5592.   old_decl = lookup_name_current_level (DECL_NAME (decl1));
  5593.   if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE
  5594.       && !DECL_BUILT_IN (old_decl)
  5595.       && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
  5596.       == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl))))
  5597.       && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0)
  5598.     TREE_TYPE (decl1) = TREE_TYPE (old_decl);
  5599.  
  5600.   /* Optionally warn of old-fashioned def with no previous prototype.  */
  5601.   if (warn_strict_prototypes
  5602.       && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0
  5603.       && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
  5604.     warning ("function declaration isn't a prototype");
  5605.   /* Optionally warn of any global def with no previous prototype.  */
  5606.   else if (warn_missing_prototypes
  5607.        && TREE_PUBLIC (decl1)
  5608.        && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
  5609.     warning_with_decl (decl1, "no previous prototype for `%s'");
  5610.   /* Optionally warn of any def with no previous prototype
  5611.      if the function has already been used.  */
  5612.   else if (warn_missing_prototypes
  5613.        && old_decl != 0 && TREE_USED (old_decl)
  5614.        && !(old_decl != 0 && TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != 0))
  5615.     warning_with_decl (decl1, "`%s' was used with no prototype before its definition");
  5616.  
  5617.   /* This is a definition, not a reference.
  5618.      So normally clear DECL_EXTERNAL.
  5619.      However, `extern inline' acts like a declaration
  5620.      except for defining how to inline.  So set DECL_EXTERNAL in that case.  */
  5621.   DECL_EXTERNAL (decl1) = current_extern_inline;
  5622.  
  5623.   /* This function exists in static storage.
  5624.      (This does not mean `static' in the C sense!)  */
  5625.   TREE_STATIC (decl1) = 1;
  5626.  
  5627.   /* A nested function is not global.  */
  5628.   if (current_function_decl != 0)
  5629.     TREE_PUBLIC (decl1) = 0;
  5630.  
  5631.   /* Record the decl so that the function name is defined.
  5632.      If we already have a decl for this name, and it is a FUNCTION_DECL,
  5633.      use the old decl.  */
  5634.  
  5635.   current_function_decl = pushdecl (decl1);
  5636.  
  5637.   pushlevel (0);
  5638.   declare_parm_level (1);
  5639.   current_binding_level->subblocks_tag_transparent = 1;
  5640.  
  5641.   make_function_rtl (current_function_decl);
  5642.  
  5643.   restype = TREE_TYPE (TREE_TYPE (current_function_decl));
  5644.   /* Promote the value to int before returning it.  */
  5645.   if (C_PROMOTING_INTEGER_TYPE_P (restype)
  5646.       /* ...but not if we're doing Apple C and this is a pascal-declared
  5647.      function. */
  5648. #ifdef TYPE_CALL_CONVENTION_PASCAL
  5649.     && !(flag_apple
  5650.        && TYPE_CALL_CONVENTION (TREE_TYPE (current_function_decl))
  5651.        && TYPE_CALL_CONVENTION_PASCAL (TREE_TYPE (current_function_decl)))
  5652. #endif
  5653.        )
  5654.     {
  5655.       /* It retains unsignedness if traditional
  5656.      or if not really getting wider.  */
  5657.       if (TREE_UNSIGNED (restype)
  5658.       && (flag_traditional
  5659.           || (TYPE_PRECISION (restype)
  5660.           == TYPE_PRECISION (integer_type_node))))
  5661.     restype = unsigned_type_node;
  5662.       else
  5663.     restype = integer_type_node;
  5664.     }
  5665.   /* If Apple extensions are on, all float types automagically become
  5666.      extended. */
  5667.   if (flag_apple && TREE_CODE (restype) == REAL_TYPE)
  5668.     restype = long_double_type_node;
  5669.   DECL_RESULT (current_function_decl)
  5670.     = build_decl (RESULT_DECL, NULL_TREE, restype);
  5671.  
  5672.   if (!nested)
  5673.     /* Allocate further tree nodes temporarily during compilation
  5674.        of this function only.  */
  5675.     temporary_allocation ();
  5676.  
  5677.   /* If this fcn was already referenced via a block-scope `extern' decl
  5678.      (or an implicit decl), propagate certain information about the usage.  */
  5679.   if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
  5680.     TREE_ADDRESSABLE (current_function_decl) = 1;
  5681. #ifdef MPW_ASM  /* this should be moved elsewhere? */
  5682.   /* Start on collecting names for this function module. */
  5683.   start_module (IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
  5684. #endif /* MPW_ASM */
  5685.  
  5686.   return 1;
  5687. }
  5688.  
  5689. /* Record that this function is going to be a varargs function.
  5690.    This is called before store_parm_decls, which is too early
  5691.    to call mark_varargs directly.  */
  5692.  
  5693. void
  5694. c_mark_varargs ()
  5695. {
  5696.   c_function_varargs = 1;
  5697. }
  5698.  
  5699. /* Store the parameter declarations into the current function declaration.
  5700.    This is called after parsing the parameter declarations, before
  5701.    digesting the body of the function.
  5702.  
  5703.    For an old-style definition, modify the function's type
  5704.    to specify at least the number of arguments.  */
  5705.  
  5706. void
  5707. store_parm_decls ()
  5708. {
  5709.   register tree fndecl = current_function_decl;
  5710.   register tree parm;
  5711.  
  5712.   /* This is either a chain of PARM_DECLs (if a prototype was used)
  5713.      or a list of IDENTIFIER_NODEs (for an old-fashioned C definition).  */
  5714.   tree specparms = current_function_parms;
  5715.  
  5716.   /* This is a list of types declared among parms in a prototype.  */
  5717.   tree parmtags = current_function_parm_tags;
  5718.  
  5719.   /* This is a chain of PARM_DECLs from old-style parm declarations.  */
  5720.   register tree parmdecls = getdecls ();
  5721.  
  5722.   /* This is a chain of any other decls that came in among the parm
  5723.      declarations.  If a parm is declared with  enum {foo, bar} x;
  5724.      then CONST_DECLs for foo and bar are put here.  */
  5725.   tree nonparms = 0;
  5726.  
  5727.   /* Nonzero if this definition is written with a prototype.  */
  5728.   int prototype = 0;
  5729.  
  5730.   if (specparms != 0 && TREE_CODE (specparms) != TREE_LIST)
  5731.     {
  5732.       /* This case is when the function was defined with an ANSI prototype.
  5733.      The parms already have decls, so we need not do anything here
  5734.      except record them as in effect
  5735.      and complain if any redundant old-style parm decls were written.  */
  5736.  
  5737.       register tree next;
  5738.       tree others = 0;
  5739.  
  5740.       prototype = 1;
  5741.  
  5742.       if (parmdecls != 0)
  5743.     {
  5744.       tree decl, link;
  5745.  
  5746.       error_with_decl (fndecl,
  5747.                "parm types given both in parmlist and separately");
  5748.       /* Get rid of the erroneous decls; don't keep them on
  5749.          the list of parms, since they might not be PARM_DECLs.  */
  5750.       for (decl = current_binding_level->names;
  5751.            decl; decl = TREE_CHAIN (decl))
  5752.         if (DECL_NAME (decl))
  5753.           IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
  5754.       for (link = current_binding_level->shadowed;
  5755.            link; link = TREE_CHAIN (link))
  5756.         IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
  5757.       current_binding_level->names = 0;
  5758.       current_binding_level->shadowed = 0;
  5759.     }
  5760.  
  5761.       specparms = nreverse (specparms);
  5762.       for (parm = specparms; parm; parm = next)
  5763.     {
  5764.       next = TREE_CHAIN (parm);
  5765.       if (TREE_CODE (parm) == PARM_DECL)
  5766.         {
  5767.           if (DECL_NAME (parm) == 0)
  5768.         error_with_decl (parm, "parameter name omitted");
  5769.           else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  5770.         {
  5771.           error_with_decl (parm, "parameter `%s' declared void");
  5772.           /* Change the type to error_mark_node so this parameter
  5773.              will be ignored by assign_parms.  */
  5774.           TREE_TYPE (parm) = error_mark_node;
  5775.         }
  5776.           pushdecl (parm);
  5777.         }
  5778.       else
  5779.         {
  5780.           /* If we find an enum constant or a type tag,
  5781.          put it aside for the moment.  */
  5782.           TREE_CHAIN (parm) = 0;
  5783.           others = chainon (others, parm);
  5784.         }
  5785.     }
  5786.  
  5787.       /* Get the decls in their original chain order
  5788.      and record in the function.  */
  5789.       DECL_ARGUMENTS (fndecl) = getdecls ();
  5790.  
  5791. #if 0
  5792.       /* If this function takes a variable number of arguments,
  5793.      add a phony parameter to the end of the parm list,
  5794.      to represent the position of the first unnamed argument.  */
  5795.       if (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
  5796.       != void_type_node)
  5797.     {
  5798.       tree dummy = build_decl (PARM_DECL, NULL_TREE, void_type_node);
  5799.       /* Let's hope the address of the unnamed parm
  5800.          won't depend on its type.  */
  5801.       TREE_TYPE (dummy) = integer_type_node;
  5802.       DECL_ARG_TYPE (dummy) = integer_type_node;
  5803.       DECL_ARGUMENTS (fndecl)
  5804.         = chainon (DECL_ARGUMENTS (fndecl), dummy);
  5805.     }
  5806. #endif
  5807.  
  5808.       /* Now pushdecl the enum constants.  */
  5809.       for (parm = others; parm; parm = next)
  5810.     {
  5811.       next = TREE_CHAIN (parm);
  5812.       if (DECL_NAME (parm) == 0)
  5813.         ;
  5814.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == void_type_node)
  5815.         ;
  5816.       else if (TREE_CODE (parm) != PARM_DECL)
  5817.         pushdecl (parm);
  5818.     }
  5819.  
  5820.       storetags (chainon (parmtags, gettags ()));
  5821.     }
  5822.   else
  5823.     {
  5824.       /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
  5825.      each with a parm name as the TREE_VALUE.
  5826.  
  5827.      PARMDECLS is a chain of declarations for parameters.
  5828.      Warning! It can also contain CONST_DECLs which are not parameters
  5829.      but are names of enumerators of any enum types
  5830.      declared among the parameters.
  5831.  
  5832.      First match each formal parameter name with its declaration.
  5833.      Associate decls with the names and store the decls
  5834.      into the TREE_PURPOSE slots.  */
  5835.  
  5836.       for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
  5837.     DECL_RESULT (parm) = 0;
  5838.  
  5839.       for (parm = specparms; parm; parm = TREE_CHAIN (parm))
  5840.     {
  5841.       register tree tail, found = NULL;
  5842.  
  5843.       if (TREE_VALUE (parm) == 0)
  5844.         {
  5845.           error_with_decl (fndecl, "parameter name missing from parameter list");
  5846.           TREE_PURPOSE (parm) = 0;
  5847.           continue;
  5848.         }
  5849.  
  5850.       /* See if any of the parmdecls specifies this parm by name.
  5851.          Ignore any enumerator decls.  */
  5852.       for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
  5853.         if (DECL_NAME (tail) == TREE_VALUE (parm)
  5854.         && TREE_CODE (tail) == PARM_DECL)
  5855.           {
  5856.         found = tail;
  5857.         break;
  5858.           }
  5859.  
  5860.       /* If declaration already marked, we have a duplicate name.
  5861.          Complain, and don't use this decl twice.   */
  5862.       if (found && DECL_RESULT (found) != 0)
  5863.         {
  5864.           error_with_decl (found, "multiple parameters named `%s'");
  5865.           found = 0;
  5866.         }
  5867.  
  5868.       /* If the declaration says "void", complain and ignore it.  */
  5869.       if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
  5870.         {
  5871.           error_with_decl (found, "parameter `%s' declared void");
  5872.           TREE_TYPE (found) = integer_type_node;
  5873.           DECL_ARG_TYPE (found) = integer_type_node;
  5874.           layout_decl (found, 0);
  5875.         }
  5876.  
  5877.       /* Traditionally, a parm declared float is actually a double.  */
  5878.       if (found && flag_traditional
  5879.           && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
  5880.         TREE_TYPE (found) = double_type_node;
  5881.  
  5882.       /* If no declaration found, default to int.  */
  5883.       if (!found)
  5884.         {
  5885.           found = build_decl (PARM_DECL, TREE_VALUE (parm),
  5886.                   integer_type_node);
  5887.           DECL_ARG_TYPE (found) = TREE_TYPE (found);
  5888.           DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
  5889.           DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
  5890.           if (extra_warnings)
  5891.         warning_with_decl (found, "type of `%s' defaults to `int'");
  5892.           pushdecl (found);
  5893.         }
  5894.  
  5895.       TREE_PURPOSE (parm) = found;
  5896.  
  5897.       /* Mark this decl as "already found" -- see test, above.
  5898.          It is safe to use DECL_RESULT for this
  5899.          since it is not used in PARM_DECLs or CONST_DECLs.  */
  5900.       DECL_RESULT (found) = error_mark_node;
  5901.     }
  5902.  
  5903.       /* Put anything which is on the parmdecls chain and which is
  5904.      not a PARM_DECL onto the list NONPARMS.  (The types of
  5905.      non-parm things which might appear on the list include
  5906.      enumerators and NULL-named TYPE_DECL nodes.) Complain about
  5907.      any actual PARM_DECLs not matched with any names.  */
  5908.  
  5909.       nonparms = 0;
  5910.       for (parm = parmdecls; parm; )
  5911.     {
  5912.       tree next = TREE_CHAIN (parm);
  5913.       TREE_CHAIN (parm) = 0;
  5914.  
  5915.       if (TREE_CODE (parm) != PARM_DECL)
  5916.         nonparms = chainon (nonparms, parm);
  5917.       else
  5918.         {
  5919.           /* Complain about args with incomplete types.  */
  5920.           if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
  5921.             {
  5922.               error_with_decl (parm, "parameter `%s' has incomplete type");
  5923.               TREE_TYPE (parm) = error_mark_node;
  5924.             }
  5925.  
  5926.           if (DECL_RESULT (parm) == 0)
  5927.             {
  5928.               error_with_decl (parm,
  5929.                        "declaration for parameter `%s' but no such parameter");
  5930.               /* Pretend the parameter was not missing.
  5931.              This gets us to a standard state and minimizes
  5932.              further error messages.  */
  5933.               specparms
  5934.             = chainon (specparms,
  5935.                    tree_cons (parm, NULL_TREE, NULL_TREE));
  5936.         }
  5937.         }
  5938.  
  5939.       parm = next;
  5940.     }
  5941.  
  5942.       /* Chain the declarations together in the order of the list of names.  */
  5943.       /* Store that chain in the function decl, replacing the list of names.  */
  5944.       parm = specparms;
  5945.       DECL_ARGUMENTS (fndecl) = 0;
  5946.       {
  5947.     register tree last;
  5948.     for (last = 0; parm; parm = TREE_CHAIN (parm))
  5949.       if (TREE_PURPOSE (parm))
  5950.         {
  5951.           if (last == 0)
  5952.         DECL_ARGUMENTS (fndecl) = TREE_PURPOSE (parm);
  5953.           else
  5954.         TREE_CHAIN (last) = TREE_PURPOSE (parm);
  5955.           last = TREE_PURPOSE (parm);
  5956.           TREE_CHAIN (last) = 0;
  5957.         }
  5958.       }
  5959.  
  5960.       /* If there was a previous prototype,
  5961.      set the DECL_ARG_TYPE of each argument according to
  5962.      the type previously specified, and report any mismatches.  */
  5963.  
  5964.       if (TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
  5965.     {
  5966.       register tree type;
  5967.       for (parm = DECL_ARGUMENTS (fndecl),
  5968.            type = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
  5969.            parm || (type && (TYPE_MAIN_VARIANT (TREE_VALUE (type))
  5970.                  != void_type_node));
  5971.            parm = TREE_CHAIN (parm), type = TREE_CHAIN (type))
  5972.         {
  5973.           if (parm == 0 || type == 0
  5974.           || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
  5975.         {
  5976.           error ("number of arguments doesn't match prototype");
  5977.           break;
  5978.         }
  5979.           /* Type for passing arg must be consistent
  5980.          with that declared for the arg.  */
  5981.           if (! comptypes (DECL_ARG_TYPE (parm), TREE_VALUE (type)))
  5982.         {
  5983.           if (TYPE_MAIN_VARIANT (TREE_TYPE (parm))
  5984.               == TYPE_MAIN_VARIANT (TREE_VALUE (type)))
  5985.             {
  5986.               /* Adjust argument to match prototype.  E.g. a previous
  5987.              `int foo(float);' prototype causes
  5988.              `int foo(x) float x; {...}' to be treated like
  5989.              `int foo(float x) {...}'.  This is particularly
  5990.              useful for argument types like uid_t.  */
  5991.               DECL_ARG_TYPE (parm) = TREE_TYPE (parm);
  5992. #ifdef PROMOTE_PROTOTYPES
  5993.               if (TREE_CODE (TREE_TYPE (parm)) == INTEGER_TYPE
  5994.               && TYPE_PRECISION (TREE_TYPE (parm))
  5995.               < TYPE_PRECISION (integer_type_node))
  5996.             DECL_ARG_TYPE (parm) = integer_type_node;
  5997. #endif
  5998.               if (pedantic)
  5999.             warning ("promoted argument `%s' doesn't match prototype",
  6000.                  IDENTIFIER_POINTER (DECL_NAME (parm)));
  6001.             }
  6002.           /* If -traditional, allow `int' argument to match
  6003.              `unsigned' prototype.  */
  6004.           else if (! (flag_traditional
  6005.                   && TYPE_MAIN_VARIANT (TREE_TYPE (parm)) == integer_type_node
  6006.                   && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == unsigned_type_node))
  6007.           /* Mac programs are guilty a lot here, and making this
  6008.              a warning doesn't seem to affect the output code.  */
  6009.           warning ("argument `%s' doesn't match function prototype",
  6010.                IDENTIFIER_POINTER (DECL_NAME (parm)));
  6011.         }
  6012.         }
  6013.       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = 0;
  6014.     }
  6015.  
  6016.       /* Otherwise, create a prototype that would match.  */
  6017.  
  6018.       else
  6019.     {
  6020.       register tree actual, type;
  6021.       register tree last = 0;
  6022.  
  6023.       for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
  6024.         {
  6025.           type = perm_tree_cons (NULL_TREE, DECL_ARG_TYPE (parm),
  6026.                      NULL_TREE);
  6027.           if (last)
  6028.         TREE_CHAIN (last) = type;
  6029.           else
  6030.         actual = type;
  6031.           last = type;
  6032.         }
  6033.       type = perm_tree_cons (NULL_TREE, void_type_node, NULL_TREE);
  6034.       if (last)
  6035.         TREE_CHAIN (last) = type;
  6036.       else
  6037.         actual = type;
  6038.  
  6039.       /* We are going to assign a new value for the TYPE_ACTUAL_ARG_TYPES
  6040.          of the type of this function, but we need to avoid having this
  6041.          affect the types of other similarly-typed functions, so we must
  6042.          first force the generation of an identical (but separate) type
  6043.          node for the relevant function type.  The new node we create
  6044.          will be a variant of the main variant of the original function
  6045.          type.  */
  6046.  
  6047.       TREE_TYPE (fndecl) = build_type_copy (TREE_TYPE (fndecl));
  6048.  
  6049.       TYPE_ACTUAL_ARG_TYPES (TREE_TYPE (fndecl)) = actual;
  6050.     }
  6051.  
  6052.       /* Now store the final chain of decls for the arguments
  6053.      as the decl-chain of the current lexical scope.
  6054.      Put the enumerators in as well, at the front so that
  6055.      DECL_ARGUMENTS is not modified.  */
  6056.  
  6057.       storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl)));
  6058.     }
  6059.  
  6060.   /* Make sure the binding level for the top of the function body
  6061.      gets a BLOCK if there are any in the function.
  6062.      Otherwise, the dbx output is wrong.  */
  6063.  
  6064.   keep_next_if_subblocks = 1;
  6065.  
  6066.   /* ??? This might be an improvement,
  6067.      but needs to be thought about some more.  */
  6068. #if 0
  6069.   keep_next_level_flag = 1;
  6070. #endif
  6071.  
  6072.   /* Write a record describing this function definition to the prototypes
  6073.      file (if requested).  */
  6074.  
  6075.   gen_aux_info_record (fndecl, 1, 0, prototype);
  6076.  
  6077.   /* Initialize the RTL code for the function.  */
  6078.  
  6079.   init_function_start (fndecl, input_filename, lineno);
  6080.  
  6081.   /* If this is a varargs function, inform function.c.  */
  6082.  
  6083.   if (c_function_varargs)
  6084.     mark_varargs ();
  6085.  
  6086.   /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function.  */
  6087.  
  6088.   declare_function_name ();
  6089.  
  6090.   /* Set up parameters and prepare for return, for the function.  */
  6091.  
  6092.   expand_function_start (fndecl, 0);
  6093.  
  6094.   /* If this function is `main', emit a call to `__main'
  6095.      to run global initializers, etc.  */
  6096.   if (DECL_NAME (fndecl)
  6097.       && strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main") == 0
  6098.       && DECL_CONTEXT (fndecl) == NULL_TREE)
  6099.     expand_main_function ();
  6100. }
  6101.  
  6102. /* SPECPARMS is an identifier list--a chain of TREE_LIST nodes
  6103.    each with a parm name as the TREE_VALUE.  A null pointer as TREE_VALUE
  6104.    stands for an ellipsis in the identifier list.
  6105.  
  6106.    PARMLIST is the data returned by get_parm_info for the
  6107.    parmlist that follows the semicolon.
  6108.  
  6109.    We return a value of the same sort that get_parm_info returns,
  6110.    except that it describes the combination of identifiers and parmlist.  */
  6111.  
  6112. tree
  6113. combine_parm_decls (specparms, parmlist, void_at_end)
  6114.      tree specparms, parmlist;
  6115.      int void_at_end;
  6116. {
  6117.   register tree fndecl = current_function_decl;
  6118.   register tree parm;
  6119.  
  6120.   tree parmdecls = TREE_PURPOSE (parmlist);
  6121.  
  6122.   /* This is a chain of any other decls that came in among the parm
  6123.      declarations.  They were separated already by get_parm_info,
  6124.      so we just need to keep them separate.  */
  6125.   tree nonparms = TREE_VALUE (parmlist);
  6126.  
  6127.   tree types = 0;
  6128.  
  6129.   for (parm = parmdecls; parm; parm = TREE_CHAIN (parm))
  6130.     DECL_RESULT (parm) = 0;
  6131.  
  6132.   for (parm = specparms; parm; parm = TREE_CHAIN (parm))
  6133.     {
  6134.       register tree tail, found = NULL;
  6135.  
  6136.       /* See if any of the parmdecls specifies this parm by name.  */
  6137.       for (tail = parmdecls; tail; tail = TREE_CHAIN (tail))
  6138.     if (DECL_NAME (tail) == TREE_VALUE (parm))
  6139.       {
  6140.         found = tail;
  6141.         break;
  6142.       }
  6143.  
  6144.       /* If declaration already marked, we have a duplicate name.
  6145.      Complain, and don't use this decl twice.   */
  6146.       if (found && DECL_RESULT (found) != 0)
  6147.     {
  6148.       error_with_decl (found, "multiple parameters named `%s'");
  6149.       found = 0;
  6150.     }
  6151.  
  6152.       /* If the declaration says "void", complain and ignore it.  */
  6153.       if (found && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == void_type_node)
  6154.     {
  6155.       error_with_decl (found, "parameter `%s' declared void");
  6156.       TREE_TYPE (found) = integer_type_node;
  6157.       DECL_ARG_TYPE (found) = integer_type_node;
  6158.       layout_decl (found, 0);
  6159.     }
  6160.  
  6161.       /* Traditionally, a parm declared float is actually a double.  */
  6162.       if (found && flag_traditional
  6163.       && TYPE_MAIN_VARIANT (TREE_TYPE (found)) == float_type_node)
  6164.     TREE_TYPE (found) = double_type_node;
  6165.  
  6166.       /* If no declaration found, default to int.  */
  6167.       if (!found)
  6168.     {
  6169.       found = build_decl (PARM_DECL, TREE_VALUE (parm),
  6170.                   integer_type_node);
  6171.       DECL_ARG_TYPE (found) = TREE_TYPE (found);
  6172.       DECL_SOURCE_LINE (found) = DECL_SOURCE_LINE (fndecl);
  6173.       DECL_SOURCE_FILE (found) = DECL_SOURCE_FILE (fndecl);
  6174.       error (found, "type of parameter `%s' is not declared");
  6175.       pushdecl (found);
  6176.     }
  6177.  
  6178.       TREE_PURPOSE (parm) = found;
  6179.  
  6180.       /* Mark this decl as "already found" -- see test, above.
  6181.      It is safe to use DECL_RESULT for this
  6182.      since it is not used in PARM_DECLs or CONST_DECLs.  */
  6183.       DECL_RESULT (found) = error_mark_node;
  6184.     }
  6185.  
  6186.   /* Complain about any actual PARM_DECLs not matched with any names.  */
  6187.  
  6188.   for (parm = parmdecls; parm; )
  6189.     {
  6190.       tree next = TREE_CHAIN (parm);
  6191.       TREE_CHAIN (parm) = 0;
  6192.  
  6193.       /* Complain about args with incomplete types.  */
  6194.       if (TYPE_SIZE (TREE_TYPE (parm)) == 0)
  6195.     {
  6196.       error_with_decl (parm, "parameter `%s' has incomplete type");
  6197.       TREE_TYPE (parm) = error_mark_node;
  6198.     }
  6199.  
  6200.       if (DECL_RESULT (parm) == 0)
  6201.     {
  6202.       error_with_decl (parm,
  6203.                "declaration for parameter `%s' but no such parameter");
  6204.       /* Pretend the parameter was not missing.
  6205.          This gets us to a standard state and minimizes
  6206.          further error messages.  */
  6207.       specparms
  6208.         = chainon (specparms,
  6209.                tree_cons (parm, NULL_TREE, NULL_TREE));
  6210.     }
  6211.  
  6212.       parm = next;
  6213.     }
  6214.  
  6215.   /* Chain the declarations together in the order of the list of names.
  6216.      At the same time, build up a list of their types, in reverse order.  */
  6217.  
  6218.   parm = specparms;
  6219.   parmdecls = 0;
  6220.   {
  6221.     register tree last;
  6222.     for (last = 0; parm; parm = TREE_CHAIN (parm))
  6223.       if (TREE_PURPOSE (parm))
  6224.     {
  6225.       if (last == 0)
  6226.         parmdecls = TREE_PURPOSE (parm);
  6227.       else
  6228.         TREE_CHAIN (last) = TREE_PURPOSE (parm);
  6229.       last = TREE_PURPOSE (parm);
  6230.       TREE_CHAIN (last) = 0;
  6231.  
  6232.       types = saveable_tree_cons (NULL_TREE, TREE_TYPE (parm), types);
  6233.     }
  6234.   }
  6235.   
  6236.   if (void_at_end)
  6237.     return saveable_tree_cons (parmdecls, nonparms,
  6238.                    nreverse (saveable_tree_cons (NULL_TREE, void_type_node, types)));
  6239.  
  6240.   return saveable_tree_cons (parmdecls, nonparms, nreverse (types));
  6241. }
  6242.  
  6243. /* Finish up a function declaration and compile that function
  6244.    all the way to assembler language output.  The free the storage
  6245.    for the function definition.
  6246.  
  6247.    This is called after parsing the body of the function definition.
  6248.  
  6249.    NESTED is nonzero if the function being finished is nested in another.  */
  6250.  
  6251. void
  6252. finish_function (nested)
  6253.      int nested;
  6254. {
  6255.   register tree fndecl = current_function_decl;
  6256.  
  6257. /*  TREE_READONLY (fndecl) = 1;
  6258.     This caused &foo to be of type ptr-to-const-function
  6259.     which then got a warning when stored in a ptr-to-function variable.  */
  6260.  
  6261.   poplevel (1, 0, 1);
  6262.   BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
  6263.  
  6264.   /* Must mark the RESULT_DECL as being in this function.  */
  6265.  
  6266.   DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
  6267.  
  6268.   /* Obey `register' declarations if `setjmp' is called in this fn.  */
  6269.   if (flag_traditional && current_function_calls_setjmp)
  6270.     {
  6271.       setjmp_protect (DECL_INITIAL (fndecl));
  6272.       setjmp_protect_args ();
  6273.     }
  6274.  
  6275. #ifdef DEFAULT_MAIN_RETURN
  6276.   if (! strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), "main"))
  6277.     {
  6278.       if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
  6279.       != integer_type_node)
  6280.     warning_with_decl (fndecl, "return type of `%s' is not `int'");
  6281.       else
  6282.     {
  6283.       /* Make it so that `main' always returns success by default.  */
  6284.       DEFAULT_MAIN_RETURN;
  6285.     }
  6286.     }
  6287. #endif
  6288.  
  6289.   /* Generate rtl for function exit.  */
  6290.   expand_function_end (input_filename, lineno);
  6291.  
  6292.   /* So we can tell if jump_optimize sets it to 1.  */
  6293.   can_reach_end = 0;
  6294.  
  6295.   /* Run the optimizers and output the assembler code for this function.  */
  6296.   rest_of_compilation (fndecl);
  6297.  
  6298.   current_function_returns_null |= can_reach_end;
  6299.  
  6300.   if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null)
  6301.     warning ("`volatile' function does return");
  6302.   else if (warn_return_type && can_reach_end
  6303.        && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) != void_type_node)
  6304.     /* If this function returns non-void and control can drop through,
  6305.        complain.  */
  6306.     warning ("control reaches end of non-void function");
  6307.   /* With just -W, complain only if function returns both with
  6308.      and without a value.  */
  6309.   else if (extra_warnings
  6310.        && current_function_returns_value && current_function_returns_null)
  6311.     warning ("this function may return with or without a value");
  6312.  
  6313.   /* Free all the tree nodes making up this function.  */
  6314.   /* Switch back to allocating nodes permanently
  6315.      until we start another function.  */
  6316.   if (! nested)
  6317.     permanent_allocation ();
  6318.  
  6319.   if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested)
  6320.     {
  6321.       /* Stop pointing to the local nodes about to be freed.  */
  6322.       /* But DECL_INITIAL must remain nonzero so we know this
  6323.      was an actual function definition.  */
  6324.       /* For a nested function, this is done in pop_c_function_context.  */
  6325.       DECL_INITIAL (fndecl) = error_mark_node;
  6326.       DECL_ARGUMENTS (fndecl) = 0;
  6327.     }
  6328.  
  6329. #ifdef MPW_ASM
  6330.   /* (should account for nesting?) */
  6331.   /* All the names that might need to be imported into this module have
  6332.      now been seen. */
  6333.   finish_module (IDENTIFIER_POINTER (DECL_NAME (fndecl)));
  6334. #endif /* MPW_ASM */
  6335.  
  6336.   if (! nested)
  6337.     {
  6338.       /* Let the error reporting routines know that we're outside a
  6339.      function.  For a nested function, this value is used in
  6340.      pop_c_function_context and then reset via pop_function_context.  */
  6341.       current_function_decl = NULL;
  6342.     }
  6343. }
  6344.  
  6345. /* Save and restore the variables in this file and elsewhere
  6346.    that keep track of the progress of compilation of the current function.
  6347.    Used for nested functions.  */
  6348.  
  6349. struct c_function
  6350. {
  6351.   struct c_function *next;
  6352.   tree enum_next_value;
  6353.   tree named_labels;
  6354.   tree shadowed_labels;
  6355.   int returns_value;
  6356.   int returns_null;
  6357.   int warn_about_return_type;
  6358.   int extern_inline;
  6359.   struct binding_level *binding_level;
  6360. };
  6361.  
  6362. struct c_function *c_function_chain;
  6363.  
  6364. /* Save and reinitialize the variables
  6365.    used during compilation of a C function.  */
  6366.  
  6367. void
  6368. push_c_function_context ()
  6369. {
  6370.   struct c_function *p
  6371.     = (struct c_function *) xmalloc (sizeof (struct c_function));
  6372.  
  6373.   if (pedantic)
  6374.     pedwarn ("ANSI C forbids nested functions");
  6375.  
  6376.   push_function_context ();
  6377.  
  6378.   p->next = c_function_chain;
  6379.   c_function_chain = p;
  6380.  
  6381.   p->enum_next_value = enum_next_value;
  6382.   p->named_labels = named_labels;
  6383.   p->shadowed_labels = shadowed_labels;
  6384.   p->returns_value = current_function_returns_value;
  6385.   p->returns_null = current_function_returns_null;
  6386.   p->warn_about_return_type = warn_about_return_type;
  6387.   p->extern_inline = current_extern_inline;
  6388.   p->binding_level = current_binding_level;
  6389. }
  6390.  
  6391. /* Restore the variables used during compilation of a C function.  */
  6392.  
  6393. void
  6394. pop_c_function_context ()
  6395. {
  6396.   struct c_function *p = c_function_chain;
  6397.   tree link;
  6398.  
  6399.   /* Bring back all the labels that were shadowed.  */
  6400.   for (link = shadowed_labels; link; link = TREE_CHAIN (link))
  6401.     if (DECL_NAME (TREE_VALUE (link)) != 0)
  6402.       IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
  6403.     = TREE_VALUE (link);
  6404.  
  6405.   if (DECL_SAVED_INSNS (current_function_decl) == 0)
  6406.     {
  6407.       /* Stop pointing to the local nodes about to be freed.  */
  6408.       /* But DECL_INITIAL must remain nonzero so we know this
  6409.      was an actual function definition.  */
  6410.       DECL_INITIAL (current_function_decl) = error_mark_node;
  6411.       DECL_ARGUMENTS (current_function_decl) = 0;
  6412.     }
  6413.  
  6414.   pop_function_context ();
  6415.  
  6416.   c_function_chain = p->next;
  6417.  
  6418.   enum_next_value = p->enum_next_value;
  6419.   named_labels = p->named_labels;
  6420.   shadowed_labels = p->shadowed_labels;
  6421.   current_function_returns_value = p->returns_value;
  6422.   current_function_returns_null = p->returns_null;
  6423.   warn_about_return_type = p->warn_about_return_type;
  6424.   current_extern_inline = p->extern_inline;
  6425.   current_binding_level = p->binding_level;
  6426.  
  6427.   free (p);
  6428. }
  6429.