Home | History | Annotate | Line # | Download | only in lint1
cgram.y revision 1.117
      1    1.2       cgd %{
      2  1.117    rillig /* $NetBSD: cgram.y,v 1.117 2020/12/30 01:02:38 rillig Exp $ */
      3    1.2       cgd 
      4    1.1       cgd /*
      5    1.9       cgd  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
      6    1.1       cgd  * Copyright (c) 1994, 1995 Jochen Pohl
      7    1.1       cgd  * All Rights Reserved.
      8    1.1       cgd  *
      9    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     10    1.1       cgd  * modification, are permitted provided that the following conditions
     11    1.1       cgd  * are met:
     12    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     13    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     14    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     15    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     16    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     17    1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     18    1.1       cgd  *    must display the following acknowledgement:
     19    1.1       cgd  *      This product includes software developed by Jochen Pohl for
     20    1.1       cgd  *	The NetBSD Project.
     21    1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     22    1.1       cgd  *    derived from this software without specific prior written permission.
     23    1.1       cgd  *
     24    1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25    1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26    1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27    1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28    1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29    1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30    1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31    1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32    1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33    1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34    1.1       cgd  */
     35    1.1       cgd 
     36   1.13  christos #include <sys/cdefs.h>
     37   1.23        tv #if defined(__RCSID) && !defined(lint)
     38  1.117    rillig __RCSID("$NetBSD: cgram.y,v 1.117 2020/12/30 01:02:38 rillig Exp $");
     39    1.1       cgd #endif
     40    1.1       cgd 
     41  1.108    rillig #include <limits.h>
     42    1.1       cgd #include <stdlib.h>
     43   1.12       cjs #include <string.h>
     44    1.1       cgd 
     45    1.1       cgd #include "lint1.h"
     46    1.1       cgd 
     47   1.41  christos extern char *yytext;
     48    1.1       cgd /*
     49    1.1       cgd  * Contains the level of current declaration. 0 is extern.
     50    1.1       cgd  * Used for symbol table entries.
     51    1.1       cgd  */
     52    1.1       cgd int	blklev;
     53    1.1       cgd 
     54    1.1       cgd /*
     55  1.110    rillig  * level for memory allocation. Normally the same as blklev.
     56   1.49       wiz  * An exception is the declaration of arguments in prototypes. Memory
     57    1.1       cgd  * for these can't be freed after the declaration, but symbols must
     58    1.1       cgd  * be removed from the symbol table after the declaration.
     59    1.1       cgd  */
     60    1.1       cgd int	mblklev;
     61    1.1       cgd 
     62   1.15  christos /*
     63   1.15  christos  * Save the no-warns state and restore it to avoid the problem where
     64   1.15  christos  * if (expr) { stmt } / * NOLINT * / stmt;
     65   1.15  christos  */
     66   1.55  christos static int olwarn = LWARN_BAD;
     67   1.15  christos 
     68   1.27  christos static	int	toicon(tnode_t *, int);
     69   1.20     lukem static	void	idecl(sym_t *, int, sbuf_t *);
     70   1.20     lukem static	void	ignuptorp(void);
     71   1.75  christos static	sym_t	*symbolrename(sym_t *, sbuf_t *);
     72   1.75  christos 
     73    1.1       cgd 
     74   1.15  christos #ifdef DEBUG
     75   1.39  christos static inline void CLRWFLGS(const char *file, size_t line);
     76   1.39  christos static inline void CLRWFLGS(const char *file, size_t line)
     77   1.15  christos {
     78   1.39  christos 	printf("%s, %d: clear flags %s %zu\n", curr_pos.p_file,
     79   1.39  christos 	    curr_pos.p_line, file, line);
     80   1.15  christos 	clrwflgs();
     81   1.55  christos 	olwarn = LWARN_BAD;
     82   1.15  christos }
     83   1.15  christos 
     84   1.39  christos static inline void SAVE(const char *file, size_t line);
     85   1.39  christos static inline void SAVE(const char *file, size_t line)
     86   1.15  christos {
     87   1.55  christos 	if (olwarn != LWARN_BAD)
     88   1.15  christos 		abort();
     89   1.39  christos 	printf("%s, %d: save flags %s %zu = %d\n", curr_pos.p_file,
     90   1.55  christos 	    curr_pos.p_line, file, line, lwarn);
     91   1.55  christos 	olwarn = lwarn;
     92   1.15  christos }
     93   1.15  christos 
     94   1.39  christos static inline void RESTORE(const char *file, size_t line);
     95   1.39  christos static inline void RESTORE(const char *file, size_t line)
     96   1.15  christos {
     97   1.55  christos 	if (olwarn != LWARN_BAD) {
     98   1.55  christos 		lwarn = olwarn;
     99   1.39  christos 		printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file,
    100   1.55  christos 		    curr_pos.p_line, file, line, lwarn);
    101   1.55  christos 		olwarn = LWARN_BAD;
    102   1.15  christos 	} else
    103   1.39  christos 		CLRWFLGS(file, line);
    104   1.15  christos }
    105  1.117    rillig #define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
    106   1.15  christos #else
    107   1.55  christos #define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD
    108   1.55  christos #define SAVE(f, l)	olwarn = lwarn
    109   1.55  christos #define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn))
    110  1.117    rillig #define cgram_debug(fmt, args...) (void)0
    111   1.15  christos #endif
    112   1.73  christos 
    113   1.73  christos /* unbind the anonymous struct members from the struct */
    114   1.73  christos static void
    115   1.73  christos anonymize(sym_t *s)
    116   1.73  christos {
    117   1.73  christos 	for ( ; s; s = s->s_nxt)
    118   1.73  christos 		s->s_styp = NULL;
    119   1.73  christos }
    120    1.1       cgd %}
    121    1.1       cgd 
    122   1.95  christos %expect 138
    123   1.40  christos 
    124    1.1       cgd %union {
    125    1.1       cgd 	int	y_int;
    126    1.1       cgd 	val_t	*y_val;
    127    1.1       cgd 	sbuf_t	*y_sb;
    128    1.1       cgd 	sym_t	*y_sym;
    129    1.1       cgd 	op_t	y_op;
    130    1.1       cgd 	scl_t	y_scl;
    131    1.1       cgd 	tspec_t	y_tspec;
    132    1.1       cgd 	tqual_t	y_tqual;
    133    1.1       cgd 	type_t	*y_type;
    134    1.1       cgd 	tnode_t	*y_tnode;
    135   1.35  christos 	range_t	y_range;
    136    1.1       cgd 	strg_t	*y_strg;
    137    1.1       cgd 	pqinf_t	*y_pqinf;
    138    1.1       cgd };
    139    1.1       cgd 
    140    1.1       cgd %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPARN T_RPARN
    141    1.1       cgd %token	<y_op>		T_STROP
    142    1.1       cgd %token	<y_op>		T_UNOP
    143    1.1       cgd %token	<y_op>		T_INCDEC
    144    1.1       cgd %token			T_SIZEOF
    145   1.94  christos %token			T_BUILTIN_OFFSETOF
    146   1.58  christos %token			T_TYPEOF
    147   1.58  christos %token			T_EXTENSION
    148   1.44  christos %token			T_ALIGNOF
    149    1.1       cgd %token	<y_op>		T_MULT
    150    1.1       cgd %token	<y_op>		T_DIVOP
    151    1.1       cgd %token	<y_op>		T_ADDOP
    152    1.1       cgd %token	<y_op>		T_SHFTOP
    153    1.1       cgd %token	<y_op>		T_RELOP
    154    1.1       cgd %token	<y_op>		T_EQOP
    155    1.1       cgd %token	<y_op>		T_AND
    156    1.1       cgd %token	<y_op>		T_XOR
    157    1.1       cgd %token	<y_op>		T_OR
    158    1.1       cgd %token	<y_op>		T_LOGAND
    159    1.1       cgd %token	<y_op>		T_LOGOR
    160    1.1       cgd %token			T_QUEST
    161    1.1       cgd %token			T_COLON
    162    1.1       cgd %token	<y_op>		T_ASSIGN
    163    1.1       cgd %token	<y_op>		T_OPASS
    164    1.1       cgd %token			T_COMMA
    165    1.1       cgd %token			T_SEMI
    166    1.1       cgd %token			T_ELLIPSE
    167   1.41  christos %token			T_REAL
    168   1.41  christos %token			T_IMAG
    169   1.81  christos %token			T_GENERIC
    170   1.95  christos %token			T_NORETURN
    171    1.1       cgd 
    172    1.1       cgd /* storage classes (extern, static, auto, register and typedef) */
    173    1.1       cgd %token	<y_scl>		T_SCLASS
    174    1.1       cgd 
    175    1.1       cgd /* types (char, int, short, long, unsigned, signed, float, double, void) */
    176    1.1       cgd %token	<y_tspec>	T_TYPE
    177    1.1       cgd 
    178    1.1       cgd /* qualifiers (const, volatile) */
    179    1.1       cgd %token	<y_tqual>	T_QUAL
    180    1.1       cgd 
    181    1.1       cgd /* struct or union */
    182    1.1       cgd %token	<y_tspec>	T_SOU
    183    1.1       cgd 
    184    1.1       cgd /* enum */
    185    1.1       cgd %token			T_ENUM
    186    1.1       cgd 
    187    1.1       cgd /* remaining keywords */
    188    1.1       cgd %token			T_CASE
    189    1.1       cgd %token			T_DEFAULT
    190    1.1       cgd %token			T_IF
    191    1.1       cgd %token			T_ELSE
    192    1.1       cgd %token			T_SWITCH
    193    1.1       cgd %token			T_DO
    194    1.1       cgd %token			T_WHILE
    195    1.1       cgd %token			T_FOR
    196    1.1       cgd %token			T_GOTO
    197    1.1       cgd %token			T_CONTINUE
    198    1.1       cgd %token			T_BREAK
    199    1.1       cgd %token			T_RETURN
    200    1.6       jpo %token			T_ASM
    201   1.11       cgd %token			T_SYMBOLRENAME
    202   1.45  christos %token			T_PACKED
    203   1.45  christos /* Type Attributes */
    204   1.45  christos %token <y_type>		T_ATTRIBUTE
    205   1.86  christos %token <y_type>		T_AT_ALIAS
    206  1.101  christos %token <y_type>		T_AT_ALLOC_SIZE
    207   1.45  christos %token <y_type>		T_AT_ALIGNED
    208   1.85  christos %token <y_type>		T_AT_ALWAYS_INLINE
    209   1.89  christos %token <y_type>		T_AT_BOUNDED
    210   1.91  christos %token <y_type>		T_AT_BUFFER
    211   1.84  christos %token <y_type>		T_AT_COLD
    212   1.84  christos %token <y_type>		T_AT_CONSTRUCTOR
    213   1.45  christos %token <y_type>		T_AT_DEPRECATED
    214  1.100  christos %token <y_type>		T_AT_DESTRUCTOR
    215   1.84  christos %token <y_type>		T_AT_FORMAT
    216   1.84  christos %token <y_type>		T_AT_FORMAT_ARG
    217  1.102  christos %token <y_type>		T_AT_FORMAT_GNU_PRINTF
    218   1.84  christos %token <y_type>		T_AT_FORMAT_PRINTF
    219   1.84  christos %token <y_type>		T_AT_FORMAT_SCANF
    220   1.90  christos %token <y_type>		T_AT_FORMAT_STRFMON
    221   1.84  christos %token <y_type>		T_AT_FORMAT_STRFTIME
    222   1.96  christos %token <y_type>		T_AT_FORMAT_SYSLOG
    223   1.77  christos %token <y_type>		T_AT_GNU_INLINE
    224  1.101  christos %token <y_type>		T_AT_MALLOC
    225   1.45  christos %token <y_type>		T_AT_MAY_ALIAS
    226   1.89  christos %token <y_type>		T_AT_MINBYTES
    227   1.84  christos %token <y_type>		T_AT_MODE
    228   1.97  christos %token <y_type>		T_AT_NOINLINE
    229   1.90  christos %token <y_type>		T_AT_NONNULL
    230   1.84  christos %token <y_type>		T_AT_NORETURN
    231  1.101  christos %token <y_type>		T_AT_NOTHROW
    232   1.84  christos %token <y_type>		T_AT_NO_INSTRUMENT_FUNCTION
    233  1.105  christos %token <y_type>		T_AT_OPTIMIZE
    234   1.45  christos %token <y_type>		T_AT_PACKED
    235   1.92  christos %token <y_type>		T_AT_PCS
    236   1.61  christos %token <y_type>		T_AT_PURE
    237   1.84  christos %token <y_type>		T_AT_RETURNS_TWICE
    238   1.84  christos %token <y_type>		T_AT_SECTION
    239   1.84  christos %token <y_type>		T_AT_SENTINEL
    240   1.89  christos %token <y_type>		T_AT_STRING
    241  1.104  christos %token <y_type>		T_AT_TLS_MODEL
    242   1.45  christos %token <y_type>		T_AT_TUNION
    243   1.45  christos %token <y_type>		T_AT_UNUSED
    244   1.84  christos %token <y_type>		T_AT_USED
    245   1.84  christos %token <y_type>		T_AT_VISIBILITY
    246   1.99  christos %token <y_type>		T_AT_WARN_UNUSED_RESULT
    247   1.76  christos %token <y_type>		T_AT_WEAK
    248    1.1       cgd 
    249    1.1       cgd %left	T_COMMA
    250    1.1       cgd %right	T_ASSIGN T_OPASS
    251    1.1       cgd %right	T_QUEST T_COLON
    252    1.1       cgd %left	T_LOGOR
    253    1.1       cgd %left	T_LOGAND
    254    1.1       cgd %left	T_OR
    255    1.1       cgd %left	T_XOR
    256    1.1       cgd %left	T_AND
    257    1.1       cgd %left	T_EQOP
    258    1.1       cgd %left	T_RELOP
    259    1.1       cgd %left	T_SHFTOP
    260    1.1       cgd %left	T_ADDOP
    261    1.1       cgd %left	T_MULT T_DIVOP
    262   1.94  christos %right	T_UNOP T_INCDEC T_SIZEOF TBUILTIN_SIZEOF T_ALIGNOF T_REAL T_IMAG
    263    1.1       cgd %left	T_LPARN T_LBRACK T_STROP
    264    1.1       cgd 
    265    1.1       cgd %token	<y_sb>		T_NAME
    266    1.1       cgd %token	<y_sb>		T_TYPENAME
    267    1.1       cgd %token	<y_val>		T_CON
    268    1.1       cgd %token	<y_strg>	T_STRING
    269    1.1       cgd 
    270    1.1       cgd %type	<y_sym>		func_decl
    271    1.1       cgd %type	<y_sym>		notype_decl
    272    1.1       cgd %type	<y_sym>		type_decl
    273    1.1       cgd %type	<y_type>	typespec
    274    1.1       cgd %type	<y_type>	clrtyp_typespec
    275    1.1       cgd %type	<y_type>	notype_typespec
    276    1.1       cgd %type	<y_type>	struct_spec
    277    1.1       cgd %type	<y_type>	enum_spec
    278   1.45  christos %type	<y_type>	type_attribute
    279    1.1       cgd %type	<y_sym>		struct_tag
    280    1.1       cgd %type	<y_sym>		enum_tag
    281    1.1       cgd %type	<y_tspec>	struct
    282    1.1       cgd %type	<y_sym>		struct_declaration
    283    1.1       cgd %type	<y_sb>		identifier
    284    1.1       cgd %type	<y_sym>		member_declaration_list_with_rbrace
    285    1.1       cgd %type	<y_sym>		member_declaration_list
    286    1.1       cgd %type	<y_sym>		member_declaration
    287    1.1       cgd %type	<y_sym>		notype_member_decls
    288    1.1       cgd %type	<y_sym>		type_member_decls
    289    1.1       cgd %type	<y_sym>		notype_member_decl
    290    1.1       cgd %type	<y_sym>		type_member_decl
    291    1.1       cgd %type	<y_tnode>	constant
    292    1.1       cgd %type	<y_sym>		enum_declaration
    293    1.1       cgd %type	<y_sym>		enums_with_opt_comma
    294    1.1       cgd %type	<y_sym>		enums
    295    1.1       cgd %type	<y_sym>		enumerator
    296    1.1       cgd %type	<y_sym>		ename
    297    1.1       cgd %type	<y_sym>		notype_direct_decl
    298    1.1       cgd %type	<y_sym>		type_direct_decl
    299    1.1       cgd %type	<y_pqinf>	pointer
    300    1.1       cgd %type	<y_pqinf>	asterisk
    301    1.1       cgd %type	<y_sym>		param_decl
    302    1.1       cgd %type	<y_sym>		param_list
    303    1.1       cgd %type	<y_sym>		abs_decl_param_list
    304    1.1       cgd %type	<y_sym>		direct_param_decl
    305    1.1       cgd %type	<y_sym>		notype_param_decl
    306    1.1       cgd %type	<y_sym>		direct_notype_param_decl
    307    1.1       cgd %type	<y_pqinf>	type_qualifier_list
    308    1.1       cgd %type	<y_pqinf>	type_qualifier
    309    1.1       cgd %type	<y_sym>		identifier_list
    310    1.1       cgd %type	<y_sym>		abs_decl
    311    1.1       cgd %type	<y_sym>		direct_abs_decl
    312    1.1       cgd %type	<y_sym>		vararg_parameter_type_list
    313    1.1       cgd %type	<y_sym>		parameter_type_list
    314    1.1       cgd %type	<y_sym>		parameter_declaration
    315    1.1       cgd %type	<y_tnode>	expr
    316   1.29  christos %type	<y_tnode>	expr_stmnt_val
    317   1.29  christos %type	<y_tnode>	expr_stmnt_list
    318    1.1       cgd %type	<y_tnode>	term
    319   1.81  christos %type	<y_tnode>	generic_expr
    320    1.1       cgd %type	<y_tnode>	func_arg_list
    321    1.1       cgd %type	<y_op>		point_or_arrow
    322    1.1       cgd %type	<y_type>	type_name
    323    1.1       cgd %type	<y_sym>		abstract_declaration
    324    1.1       cgd %type	<y_tnode>	do_while_expr
    325    1.1       cgd %type	<y_tnode>	opt_expr
    326    1.1       cgd %type	<y_strg>	string
    327    1.1       cgd %type	<y_strg>	string2
    328   1.11       cgd %type	<y_sb>		opt_asm_or_symbolrename
    329   1.35  christos %type	<y_range>	range
    330   1.35  christos %type	<y_range>	lorange
    331    1.1       cgd 
    332    1.1       cgd 
    333    1.1       cgd %%
    334    1.1       cgd 
    335    1.1       cgd program:
    336    1.1       cgd 	  /* empty */ {
    337    1.1       cgd 		if (sflag) {
    338    1.1       cgd 			/* empty translation unit */
    339    1.1       cgd 			error(272);
    340    1.1       cgd 		} else if (!tflag) {
    341    1.1       cgd 			/* empty translation unit */
    342    1.1       cgd 			warning(272);
    343    1.1       cgd 		}
    344    1.1       cgd 	  }
    345    1.1       cgd 	| translation_unit
    346    1.1       cgd 	;
    347    1.1       cgd 
    348    1.1       cgd translation_unit:
    349    1.1       cgd 	  ext_decl
    350    1.1       cgd 	| translation_unit ext_decl
    351    1.1       cgd 	;
    352    1.1       cgd 
    353    1.1       cgd ext_decl:
    354    1.9       cgd 	  asm_stmnt
    355    1.9       cgd 	| func_def {
    356  1.114    rillig 		global_clean_up_decl(0);
    357   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
    358    1.1       cgd 	  }
    359    1.1       cgd 	| data_def {
    360  1.114    rillig 		global_clean_up_decl(0);
    361   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
    362    1.1       cgd 	  }
    363    1.1       cgd 	;
    364    1.1       cgd 
    365    1.1       cgd data_def:
    366    1.1       cgd 	  T_SEMI {
    367    1.1       cgd 		if (sflag) {
    368    1.1       cgd 			/* syntax error: empty declaration */
    369    1.1       cgd 			error(0);
    370    1.1       cgd 		} else if (!tflag) {
    371    1.1       cgd 			/* syntax error: empty declaration */
    372    1.1       cgd 			warning(0);
    373    1.1       cgd 		}
    374    1.1       cgd 	  }
    375    1.1       cgd 	| clrtyp deftyp notype_init_decls T_SEMI {
    376    1.1       cgd 		if (sflag) {
    377    1.1       cgd 			/* old style declaration; add "int" */
    378    1.1       cgd 			error(1);
    379    1.1       cgd 		} else if (!tflag) {
    380    1.1       cgd 			/* old style declaration; add "int" */
    381    1.1       cgd 			warning(1);
    382    1.1       cgd 		}
    383    1.1       cgd 	  }
    384    1.1       cgd 	| declmods deftyp T_SEMI {
    385    1.3       jpo 		if (dcs->d_scl == TYPEDEF) {
    386    1.1       cgd 			/* typedef declares no type name */
    387    1.1       cgd 			warning(72);
    388    1.1       cgd 		} else {
    389    1.1       cgd 			/* empty declaration */
    390    1.1       cgd 			warning(2);
    391    1.1       cgd 		}
    392    1.1       cgd 	  }
    393    1.1       cgd 	| declmods deftyp notype_init_decls T_SEMI
    394    1.1       cgd 	| declspecs deftyp T_SEMI {
    395    1.3       jpo 		if (dcs->d_scl == TYPEDEF) {
    396    1.1       cgd 			/* typedef declares no type name */
    397    1.1       cgd 			warning(72);
    398    1.3       jpo 		} else if (!dcs->d_nedecl) {
    399    1.1       cgd 			/* empty declaration */
    400    1.1       cgd 			warning(2);
    401    1.1       cgd 		}
    402    1.1       cgd 	  }
    403    1.1       cgd 	| declspecs deftyp type_init_decls T_SEMI
    404    1.1       cgd 	| error T_SEMI {
    405  1.114    rillig 		global_clean_up();
    406    1.1       cgd 	  }
    407    1.1       cgd 	| error T_RBRACE {
    408  1.114    rillig 		global_clean_up();
    409    1.1       cgd 	  }
    410    1.1       cgd 	;
    411    1.1       cgd 
    412    1.1       cgd func_def:
    413    1.1       cgd 	  func_decl {
    414    1.1       cgd 		if ($1->s_type->t_tspec != FUNC) {
    415    1.1       cgd 			/* syntax error */
    416   1.41  christos 			error(249, yytext);
    417    1.1       cgd 			YYERROR;
    418    1.1       cgd 		}
    419    1.1       cgd 		if ($1->s_type->t_typedef) {
    420    1.1       cgd 			/* ()-less function definition */
    421    1.1       cgd 			error(64);
    422    1.1       cgd 			YYERROR;
    423    1.1       cgd 		}
    424    1.1       cgd 		funcdef($1);
    425    1.1       cgd 		blklev++;
    426    1.1       cgd 		pushdecl(ARG);
    427   1.55  christos 		if (lwarn == LWARN_NONE)
    428   1.39  christos 			$1->s_used = 1;
    429    1.1       cgd 	  } opt_arg_declaration_list {
    430    1.1       cgd 		popdecl();
    431    1.1       cgd 		blklev--;
    432    1.1       cgd 		cluparg();
    433    1.1       cgd 		pushctrl(0);
    434    1.1       cgd 	  } comp_stmnt {
    435    1.1       cgd 		funcend();
    436    1.1       cgd 		popctrl(0);
    437    1.1       cgd 	  }
    438    1.1       cgd 	;
    439    1.1       cgd 
    440    1.1       cgd func_decl:
    441    1.1       cgd 	  clrtyp deftyp notype_decl {
    442    1.1       cgd 		$$ = $3;
    443    1.1       cgd 	  }
    444    1.1       cgd 	| declmods deftyp notype_decl {
    445    1.1       cgd 		$$ = $3;
    446    1.1       cgd 	  }
    447    1.1       cgd 	| declspecs deftyp type_decl {
    448    1.1       cgd 		$$ = $3;
    449    1.1       cgd 	  }
    450    1.1       cgd 	;
    451    1.1       cgd 
    452    1.1       cgd opt_arg_declaration_list:
    453    1.1       cgd 	  /* empty */
    454    1.1       cgd 	| arg_declaration_list
    455    1.1       cgd 	;
    456    1.1       cgd 
    457    1.1       cgd arg_declaration_list:
    458    1.1       cgd 	  arg_declaration
    459    1.1       cgd 	| arg_declaration_list arg_declaration
    460    1.1       cgd 	/* XXX or better "arg_declaration error" ? */
    461    1.1       cgd 	| error
    462    1.1       cgd 	;
    463    1.1       cgd 
    464    1.1       cgd /*
    465    1.1       cgd  * "arg_declaration" is separated from "declaration" because it
    466    1.1       cgd  * needs other error handling.
    467    1.1       cgd  */
    468    1.1       cgd 
    469    1.1       cgd arg_declaration:
    470    1.1       cgd 	  declmods deftyp T_SEMI {
    471    1.1       cgd 		/* empty declaration */
    472    1.1       cgd 		warning(2);
    473    1.1       cgd 	  }
    474    1.1       cgd 	| declmods deftyp notype_init_decls T_SEMI
    475    1.1       cgd 	| declspecs deftyp T_SEMI {
    476    1.3       jpo 		if (!dcs->d_nedecl) {
    477    1.1       cgd 			/* empty declaration */
    478    1.1       cgd 			warning(2);
    479    1.1       cgd 		} else {
    480    1.3       jpo 			tspec_t	ts = dcs->d_type->t_tspec;
    481    1.1       cgd 			/* %s declared in argument declaration list */
    482    1.1       cgd 			warning(3, ts == STRUCT ? "struct" :
    483    1.1       cgd 				(ts == UNION ? "union" : "enum"));
    484    1.1       cgd 		}
    485    1.1       cgd 	  }
    486    1.1       cgd 	| declspecs deftyp type_init_decls T_SEMI {
    487    1.3       jpo 		if (dcs->d_nedecl) {
    488    1.3       jpo 			tspec_t	ts = dcs->d_type->t_tspec;
    489    1.1       cgd 			/* %s declared in argument declaration list */
    490    1.1       cgd 			warning(3, ts == STRUCT ? "struct" :
    491    1.1       cgd 				(ts == UNION ? "union" : "enum"));
    492    1.1       cgd 		}
    493    1.1       cgd 	  }
    494    1.1       cgd 	| declmods error
    495    1.1       cgd 	| declspecs error
    496    1.1       cgd 	;
    497    1.1       cgd 
    498    1.1       cgd declaration:
    499    1.1       cgd 	  declmods deftyp T_SEMI {
    500    1.3       jpo 		if (dcs->d_scl == TYPEDEF) {
    501    1.1       cgd 			/* typedef declares no type name */
    502    1.1       cgd 			warning(72);
    503    1.1       cgd 		} else {
    504    1.1       cgd 			/* empty declaration */
    505    1.1       cgd 			warning(2);
    506    1.1       cgd 		}
    507    1.1       cgd 	  }
    508    1.1       cgd 	| declmods deftyp notype_init_decls T_SEMI
    509    1.1       cgd 	| declspecs deftyp T_SEMI {
    510    1.3       jpo 		if (dcs->d_scl == TYPEDEF) {
    511    1.1       cgd 			/* typedef declares no type name */
    512    1.1       cgd 			warning(72);
    513    1.3       jpo 		} else if (!dcs->d_nedecl) {
    514    1.1       cgd 			/* empty declaration */
    515    1.1       cgd 			warning(2);
    516    1.1       cgd 		}
    517    1.1       cgd 	  }
    518    1.1       cgd 	| declspecs deftyp type_init_decls T_SEMI
    519    1.1       cgd 	| error T_SEMI
    520    1.1       cgd 	;
    521    1.1       cgd 
    522   1.61  christos type_attribute_format_type:
    523  1.102  christos 	  T_AT_FORMAT_GNU_PRINTF
    524  1.102  christos 	| T_AT_FORMAT_PRINTF
    525   1.61  christos 	| T_AT_FORMAT_SCANF
    526   1.84  christos 	| T_AT_FORMAT_STRFMON
    527   1.61  christos 	| T_AT_FORMAT_STRFTIME
    528   1.96  christos 	| T_AT_FORMAT_SYSLOG
    529   1.61  christos 	;
    530   1.61  christos 
    531   1.91  christos type_attribute_bounded_type:
    532   1.91  christos 	  T_AT_MINBYTES
    533   1.91  christos 	| T_AT_STRING
    534   1.91  christos 	| T_AT_BUFFER
    535   1.91  christos 	;
    536   1.91  christos 
    537   1.98  christos 
    538   1.45  christos type_attribute_spec:
    539  1.109    rillig 	  /* empty */
    540   1.98  christos 	| T_AT_DEPRECATED T_LPARN string T_RPARN
    541   1.91  christos 	| T_AT_DEPRECATED
    542   1.45  christos 	| T_AT_ALIGNED T_LPARN constant T_RPARN
    543  1.103  christos 	| T_AT_ALLOC_SIZE T_LPARN constant T_COMMA constant T_RPARN
    544  1.101  christos 	| T_AT_ALLOC_SIZE T_LPARN constant T_RPARN
    545   1.91  christos 	| T_AT_BOUNDED T_LPARN type_attribute_bounded_type
    546   1.91  christos 	  T_COMMA constant T_COMMA constant T_RPARN
    547   1.65  christos 	| T_AT_SENTINEL T_LPARN constant T_RPARN
    548  1.106  christos 	| T_AT_SENTINEL
    549   1.65  christos 	| T_AT_FORMAT_ARG T_LPARN constant T_RPARN
    550   1.89  christos 	| T_AT_NONNULL T_LPARN constant T_RPARN
    551   1.84  christos 	| T_AT_MODE T_LPARN T_NAME T_RPARN
    552   1.86  christos 	| T_AT_ALIAS T_LPARN string T_RPARN
    553  1.105  christos 	| T_AT_OPTIMIZE T_LPARN string T_RPARN
    554   1.92  christos 	| T_AT_PCS T_LPARN string T_RPARN
    555   1.84  christos 	| T_AT_SECTION T_LPARN string T_RPARN
    556  1.104  christos 	| T_AT_TLS_MODEL T_LPARN string T_RPARN
    557  1.109    rillig 	| T_AT_ALIGNED
    558  1.109    rillig 	| T_AT_CONSTRUCTOR
    559  1.109    rillig 	| T_AT_DESTRUCTOR
    560  1.101  christos 	| T_AT_MALLOC
    561   1.45  christos 	| T_AT_MAY_ALIAS
    562   1.84  christos 	| T_AT_NO_INSTRUMENT_FUNCTION
    563   1.97  christos 	| T_AT_NOINLINE
    564   1.61  christos 	| T_AT_NORETURN
    565  1.101  christos 	| T_AT_NOTHROW
    566   1.65  christos 	| T_AT_COLD
    567   1.65  christos 	| T_AT_RETURNS_TWICE
    568   1.45  christos 	| T_AT_PACKED {
    569   1.45  christos 		addpacked();
    570   1.45  christos 	}
    571   1.61  christos 	| T_AT_PURE
    572   1.45  christos 	| T_AT_TUNION
    573   1.77  christos 	| T_AT_GNU_INLINE
    574   1.85  christos 	| T_AT_ALWAYS_INLINE
    575   1.61  christos 	| T_AT_FORMAT T_LPARN type_attribute_format_type T_COMMA
    576   1.61  christos 	    constant T_COMMA constant T_RPARN
    577   1.84  christos 	| T_AT_USED {
    578  1.114    rillig 		add_attr_used();
    579   1.84  christos 	}
    580   1.82  christos 	| T_AT_UNUSED {
    581  1.114    rillig 		add_attr_used();
    582   1.82  christos 	}
    583   1.99  christos 	| T_AT_WARN_UNUSED_RESULT
    584   1.76  christos 	| T_AT_WEAK
    585   1.76  christos 	| T_AT_VISIBILITY T_LPARN constant T_RPARN
    586   1.62  christos 	| T_QUAL {
    587  1.109    rillig 		if ($1 != CONST)
    588   1.62  christos 			yyerror("Bad attribute");
    589   1.62  christos 	}
    590   1.45  christos 	;
    591   1.45  christos 
    592   1.84  christos type_attribute_spec_list:
    593   1.84  christos 	  type_attribute_spec
    594   1.84  christos 	| type_attribute_spec_list T_COMMA type_attribute_spec
    595   1.84  christos 	;
    596   1.84  christos 
    597   1.45  christos type_attribute:
    598   1.61  christos 	  T_ATTRIBUTE T_LPARN T_LPARN {
    599   1.61  christos 	    attron = 1;
    600   1.84  christos 	} type_attribute_spec_list {
    601   1.61  christos 	    attron = 0;
    602   1.61  christos 	} T_RPARN T_RPARN
    603   1.45  christos 	| T_PACKED {
    604   1.45  christos 		addpacked();
    605   1.45  christos 	}
    606   1.95  christos 	| T_NORETURN {
    607   1.95  christos 	}
    608   1.45  christos 	;
    609   1.45  christos 
    610   1.87  christos type_attribute_list:
    611   1.87  christos 	  type_attribute
    612   1.87  christos 	| type_attribute_list type_attribute
    613   1.87  christos 	;
    614   1.87  christos 
    615    1.1       cgd clrtyp:
    616  1.110    rillig 	  /* empty */ {
    617    1.1       cgd 		clrtyp();
    618    1.1       cgd 	  }
    619    1.1       cgd 	;
    620    1.1       cgd 
    621    1.1       cgd deftyp:
    622    1.1       cgd 	  /* empty */ {
    623    1.1       cgd 		deftyp();
    624    1.1       cgd 	  }
    625    1.1       cgd 	;
    626    1.1       cgd 
    627    1.1       cgd declspecs:
    628    1.1       cgd 	  clrtyp_typespec {
    629  1.114    rillig 		add_type($1);
    630    1.1       cgd 	  }
    631    1.1       cgd 	| declmods typespec {
    632  1.114    rillig 		add_type($2);
    633    1.1       cgd 	  }
    634   1.63  christos 	| type_attribute declspecs
    635    1.1       cgd 	| declspecs declmod
    636    1.1       cgd 	| declspecs notype_typespec {
    637  1.114    rillig 		add_type($2);
    638    1.1       cgd 	  }
    639    1.1       cgd 	;
    640    1.1       cgd 
    641    1.1       cgd declmods:
    642    1.1       cgd 	  clrtyp T_QUAL {
    643  1.114    rillig 		add_qualifier($2);
    644    1.1       cgd 	  }
    645    1.1       cgd 	| clrtyp T_SCLASS {
    646  1.114    rillig 		add_storage_class($2);
    647    1.1       cgd 	  }
    648    1.1       cgd 	| declmods declmod
    649    1.1       cgd 	;
    650    1.1       cgd 
    651    1.1       cgd declmod:
    652    1.1       cgd 	  T_QUAL {
    653  1.114    rillig 		add_qualifier($1);
    654    1.1       cgd 	  }
    655    1.1       cgd 	| T_SCLASS {
    656  1.114    rillig 		add_storage_class($1);
    657    1.1       cgd 	  }
    658   1.87  christos 	| type_attribute_list
    659    1.1       cgd 	;
    660    1.1       cgd 
    661    1.1       cgd clrtyp_typespec:
    662    1.1       cgd 	  clrtyp notype_typespec {
    663    1.1       cgd 		$$ = $2;
    664    1.1       cgd 	  }
    665    1.1       cgd 	| T_TYPENAME clrtyp {
    666    1.1       cgd 		$$ = getsym($1)->s_type;
    667    1.1       cgd 	  }
    668    1.1       cgd 	;
    669    1.1       cgd 
    670    1.1       cgd typespec:
    671    1.1       cgd 	  notype_typespec {
    672    1.1       cgd 		$$ = $1;
    673    1.1       cgd 	  }
    674    1.1       cgd 	| T_TYPENAME {
    675    1.1       cgd 		$$ = getsym($1)->s_type;
    676    1.1       cgd 	  }
    677    1.1       cgd 	;
    678    1.1       cgd 
    679    1.1       cgd notype_typespec:
    680    1.1       cgd 	  T_TYPE {
    681    1.1       cgd 		$$ = gettyp($1);
    682    1.1       cgd 	  }
    683   1.60  christos 	| T_TYPEOF term {
    684   1.60  christos 		$$ = $2->tn_type;
    685   1.58  christos 	  }
    686    1.1       cgd 	| struct_spec {
    687    1.1       cgd 		popdecl();
    688    1.1       cgd 		$$ = $1;
    689    1.1       cgd 	  }
    690    1.1       cgd 	| enum_spec {
    691    1.1       cgd 		popdecl();
    692    1.1       cgd 		$$ = $1;
    693    1.1       cgd 	  }
    694    1.1       cgd 	;
    695    1.1       cgd 
    696    1.1       cgd struct_spec:
    697    1.1       cgd 	  struct struct_tag {
    698    1.1       cgd 		/*
    699    1.1       cgd 		 * STDC requires that "struct a;" always introduces
    700    1.1       cgd 		 * a new tag if "a" is not declared at current level
    701    1.1       cgd 		 *
    702  1.110    rillig 		 * yychar is valid because otherwise the parser would not
    703  1.110    rillig 		 * have been able to decide if it must shift or reduce
    704    1.1       cgd 		 */
    705    1.1       cgd 		$$ = mktag($2, $1, 0, yychar == T_SEMI);
    706    1.1       cgd 	  }
    707    1.1       cgd 	| struct struct_tag {
    708    1.3       jpo 		dcs->d_tagtyp = mktag($2, $1, 1, 0);
    709    1.1       cgd 	  } struct_declaration {
    710  1.116    rillig 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
    711    1.1       cgd 	  }
    712    1.1       cgd 	| struct {
    713    1.3       jpo 		dcs->d_tagtyp = mktag(NULL, $1, 1, 0);
    714    1.1       cgd 	  } struct_declaration {
    715  1.116    rillig 		$$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
    716    1.1       cgd 	  }
    717    1.1       cgd 	| struct error {
    718    1.1       cgd 		symtyp = FVFT;
    719    1.1       cgd 		$$ = gettyp(INT);
    720    1.1       cgd 	  }
    721    1.1       cgd 	;
    722    1.1       cgd 
    723    1.1       cgd struct:
    724   1.46  christos 	  struct type_attribute
    725   1.46  christos 	| T_SOU {
    726    1.1       cgd 		symtyp = FTAG;
    727    1.1       cgd 		pushdecl($1 == STRUCT ? MOS : MOU);
    728    1.3       jpo 		dcs->d_offset = 0;
    729    1.3       jpo 		dcs->d_stralign = CHAR_BIT;
    730    1.1       cgd 		$$ = $1;
    731    1.1       cgd 	  }
    732    1.1       cgd 	;
    733    1.1       cgd 
    734    1.1       cgd struct_tag:
    735    1.1       cgd 	  identifier {
    736    1.1       cgd 		$$ = getsym($1);
    737    1.1       cgd 	  }
    738    1.1       cgd 	;
    739    1.1       cgd 
    740    1.1       cgd struct_declaration:
    741    1.1       cgd 	  struct_decl_lbrace member_declaration_list_with_rbrace {
    742    1.1       cgd 		$$ = $2;
    743    1.1       cgd 	  }
    744    1.1       cgd 	;
    745    1.1       cgd 
    746    1.1       cgd struct_decl_lbrace:
    747    1.1       cgd 	  T_LBRACE {
    748    1.1       cgd 		symtyp = FVFT;
    749    1.1       cgd 	  }
    750    1.1       cgd 	;
    751    1.1       cgd 
    752    1.1       cgd member_declaration_list_with_rbrace:
    753    1.1       cgd 	  member_declaration_list T_SEMI T_RBRACE {
    754    1.1       cgd 		$$ = $1;
    755    1.1       cgd 	  }
    756    1.1       cgd 	| member_declaration_list T_RBRACE {
    757    1.1       cgd 		if (sflag) {
    758    1.1       cgd 			/* syntax req. ";" after last struct/union member */
    759    1.1       cgd 			error(66);
    760    1.1       cgd 		} else {
    761    1.1       cgd 			/* syntax req. ";" after last struct/union member */
    762    1.1       cgd 			warning(66);
    763    1.1       cgd 		}
    764    1.1       cgd 		$$ = $1;
    765    1.1       cgd 	  }
    766    1.1       cgd 	| T_RBRACE {
    767    1.1       cgd 		$$ = NULL;
    768    1.1       cgd 	  }
    769    1.1       cgd 	;
    770    1.1       cgd 
    771   1.83  christos opt_type_attribute:
    772   1.91  christos 	  /* empty */
    773   1.83  christos 	| type_attribute
    774   1.83  christos 	;
    775   1.83  christos 
    776    1.1       cgd member_declaration_list:
    777    1.1       cgd 	  member_declaration {
    778    1.1       cgd 		$$ = $1;
    779    1.1       cgd 	  }
    780    1.1       cgd 	| member_declaration_list T_SEMI member_declaration {
    781    1.1       cgd 		$$ = lnklst($1, $3);
    782    1.1       cgd 	  }
    783    1.1       cgd 	;
    784    1.1       cgd 
    785    1.1       cgd member_declaration:
    786    1.1       cgd 	  noclass_declmods deftyp {
    787    1.1       cgd 		/* too late, i know, but getsym() compensates it */
    788    1.1       cgd 		symtyp = FMOS;
    789   1.83  christos 	  } notype_member_decls opt_type_attribute {
    790    1.1       cgd 		symtyp = FVFT;
    791    1.1       cgd 		$$ = $4;
    792    1.1       cgd 	  }
    793    1.1       cgd 	| noclass_declspecs deftyp {
    794    1.1       cgd 		symtyp = FMOS;
    795   1.83  christos 	  } type_member_decls opt_type_attribute {
    796    1.1       cgd 		symtyp = FVFT;
    797    1.1       cgd 		$$ = $4;
    798    1.1       cgd 	  }
    799   1.83  christos 	| noclass_declmods deftyp opt_type_attribute {
    800   1.74  christos 		symtyp = FVFT;
    801    1.1       cgd 		/* struct or union member must be named */
    802   1.73  christos 		if (!Sflag)
    803   1.73  christos 			warning(49);
    804   1.73  christos 		/* add all the members of the anonymous struct/union */
    805   1.73  christos 		$$ = dcs->d_type->t_str->memb;
    806   1.73  christos 		anonymize($$);
    807    1.1       cgd 	  }
    808   1.83  christos 	| noclass_declspecs deftyp opt_type_attribute {
    809   1.74  christos 		symtyp = FVFT;
    810    1.1       cgd 		/* struct or union member must be named */
    811   1.73  christos 		if (!Sflag)
    812   1.73  christos 			warning(49);
    813   1.73  christos 		$$ = dcs->d_type->t_str->memb;
    814   1.73  christos 		/* add all the members of the anonymous struct/union */
    815   1.73  christos 		anonymize($$);
    816    1.1       cgd 	  }
    817    1.1       cgd 	| error {
    818    1.1       cgd 		symtyp = FVFT;
    819    1.1       cgd 		$$ = NULL;
    820    1.1       cgd 	  }
    821    1.1       cgd 	;
    822    1.1       cgd 
    823    1.1       cgd noclass_declspecs:
    824    1.1       cgd 	  clrtyp_typespec {
    825  1.114    rillig 		add_type($1);
    826    1.1       cgd 	  }
    827   1.63  christos 	| type_attribute noclass_declspecs
    828    1.1       cgd 	| noclass_declmods typespec {
    829  1.114    rillig 		add_type($2);
    830    1.1       cgd 	  }
    831    1.1       cgd 	| noclass_declspecs T_QUAL {
    832  1.114    rillig 		add_qualifier($2);
    833    1.1       cgd 	  }
    834    1.1       cgd 	| noclass_declspecs notype_typespec {
    835  1.114    rillig 		add_type($2);
    836    1.1       cgd 	  }
    837   1.48  christos 	| noclass_declspecs type_attribute
    838    1.1       cgd 	;
    839    1.1       cgd 
    840    1.1       cgd noclass_declmods:
    841    1.1       cgd 	  clrtyp T_QUAL {
    842  1.114    rillig 		add_qualifier($2);
    843    1.1       cgd 	  }
    844    1.1       cgd 	| noclass_declmods T_QUAL {
    845  1.114    rillig 		add_qualifier($2);
    846    1.1       cgd 	  }
    847    1.1       cgd 	;
    848    1.1       cgd 
    849    1.1       cgd notype_member_decls:
    850    1.1       cgd 	  notype_member_decl {
    851  1.111    rillig 		$$ = declarator_1_struct_union($1);
    852    1.1       cgd 	  }
    853    1.1       cgd 	| notype_member_decls {
    854    1.1       cgd 		symtyp = FMOS;
    855    1.1       cgd 	  } T_COMMA type_member_decl {
    856  1.111    rillig 		$$ = lnklst($1, declarator_1_struct_union($4));
    857    1.1       cgd 	  }
    858    1.1       cgd 	;
    859    1.1       cgd 
    860    1.1       cgd type_member_decls:
    861    1.1       cgd 	  type_member_decl {
    862  1.111    rillig 		$$ = declarator_1_struct_union($1);
    863    1.1       cgd 	  }
    864    1.1       cgd 	| type_member_decls {
    865    1.1       cgd 		symtyp = FMOS;
    866    1.1       cgd 	  } T_COMMA type_member_decl {
    867  1.111    rillig 		$$ = lnklst($1, declarator_1_struct_union($4));
    868    1.1       cgd 	  }
    869    1.1       cgd 	;
    870    1.1       cgd 
    871    1.1       cgd notype_member_decl:
    872    1.1       cgd 	  notype_decl {
    873    1.1       cgd 		$$ = $1;
    874    1.1       cgd 	  }
    875    1.1       cgd 	| notype_decl T_COLON constant {
    876   1.27  christos 		$$ = bitfield($1, toicon($3, 1));
    877    1.1       cgd 	  }
    878    1.1       cgd 	| {
    879    1.1       cgd 		symtyp = FVFT;
    880    1.1       cgd 	  } T_COLON constant {
    881   1.27  christos 		$$ = bitfield(NULL, toicon($3, 1));
    882    1.1       cgd 	  }
    883    1.1       cgd 	;
    884    1.1       cgd 
    885    1.1       cgd type_member_decl:
    886    1.1       cgd 	  type_decl {
    887    1.1       cgd 		$$ = $1;
    888    1.1       cgd 	  }
    889    1.1       cgd 	| type_decl T_COLON constant {
    890   1.27  christos 		$$ = bitfield($1, toicon($3, 1));
    891    1.1       cgd 	  }
    892    1.1       cgd 	| {
    893    1.1       cgd 		symtyp = FVFT;
    894    1.1       cgd 	  } T_COLON constant {
    895   1.27  christos 		$$ = bitfield(NULL, toicon($3, 1));
    896    1.1       cgd 	  }
    897    1.1       cgd 	;
    898    1.1       cgd 
    899    1.1       cgd enum_spec:
    900    1.1       cgd 	  enum enum_tag {
    901    1.1       cgd 		$$ = mktag($2, ENUM, 0, 0);
    902    1.1       cgd 	  }
    903    1.1       cgd 	| enum enum_tag {
    904    1.3       jpo 		dcs->d_tagtyp = mktag($2, ENUM, 1, 0);
    905    1.1       cgd 	  } enum_declaration {
    906  1.116    rillig 		$$ = complete_tag_enum(dcs->d_tagtyp, $4);
    907    1.1       cgd 	  }
    908    1.1       cgd 	| enum {
    909    1.3       jpo 		dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0);
    910    1.1       cgd 	  } enum_declaration {
    911  1.116    rillig 		$$ = complete_tag_enum(dcs->d_tagtyp, $3);
    912    1.1       cgd 	  }
    913    1.1       cgd 	| enum error {
    914    1.1       cgd 		symtyp = FVFT;
    915    1.1       cgd 		$$ = gettyp(INT);
    916    1.1       cgd 	  }
    917    1.1       cgd 	;
    918    1.1       cgd 
    919    1.1       cgd enum:
    920    1.1       cgd 	  T_ENUM {
    921    1.1       cgd 		symtyp = FTAG;
    922    1.1       cgd 		pushdecl(ENUMCON);
    923    1.1       cgd 	  }
    924    1.1       cgd 	;
    925    1.1       cgd 
    926    1.1       cgd enum_tag:
    927    1.1       cgd 	  identifier {
    928    1.1       cgd 		$$ = getsym($1);
    929    1.1       cgd 	  }
    930    1.1       cgd 	;
    931    1.1       cgd 
    932    1.1       cgd enum_declaration:
    933    1.1       cgd 	  enum_decl_lbrace enums_with_opt_comma T_RBRACE {
    934    1.1       cgd 		$$ = $2;
    935    1.1       cgd 	  }
    936    1.1       cgd 	;
    937    1.1       cgd 
    938    1.1       cgd enum_decl_lbrace:
    939    1.1       cgd 	  T_LBRACE {
    940    1.1       cgd 		symtyp = FVFT;
    941    1.1       cgd 		enumval = 0;
    942    1.1       cgd 	  }
    943    1.1       cgd 	;
    944    1.1       cgd 
    945    1.1       cgd enums_with_opt_comma:
    946    1.1       cgd 	  enums {
    947    1.1       cgd 		$$ = $1;
    948    1.1       cgd 	  }
    949    1.1       cgd 	| enums T_COMMA {
    950    1.1       cgd 		if (sflag) {
    951    1.1       cgd 			/* trailing "," prohibited in enum declaration */
    952    1.1       cgd 			error(54);
    953    1.1       cgd 		} else {
    954    1.1       cgd 			/* trailing "," prohibited in enum declaration */
    955   1.51     njoly 			c99ism(54);
    956    1.1       cgd 		}
    957    1.1       cgd 		$$ = $1;
    958    1.1       cgd 	  }
    959    1.1       cgd 	;
    960    1.1       cgd 
    961    1.1       cgd enums:
    962    1.1       cgd 	  enumerator {
    963    1.1       cgd 		$$ = $1;
    964    1.1       cgd 	  }
    965    1.1       cgd 	| enums T_COMMA enumerator {
    966    1.1       cgd 		$$ = lnklst($1, $3);
    967    1.1       cgd 	  }
    968    1.1       cgd 	| error {
    969    1.1       cgd 		$$ = NULL;
    970    1.1       cgd 	  }
    971    1.1       cgd 	;
    972    1.1       cgd 
    973    1.1       cgd enumerator:
    974    1.1       cgd 	  ename {
    975    1.1       cgd 		$$ = ename($1, enumval, 1);
    976    1.1       cgd 	  }
    977    1.1       cgd 	| ename T_ASSIGN constant {
    978   1.27  christos 		$$ = ename($1, toicon($3, 1), 0);
    979    1.1       cgd 	  }
    980    1.1       cgd 	;
    981    1.1       cgd 
    982    1.1       cgd ename:
    983    1.1       cgd 	  identifier {
    984    1.1       cgd 		$$ = getsym($1);
    985    1.1       cgd 	  }
    986    1.1       cgd 	;
    987    1.1       cgd 
    988    1.1       cgd 
    989    1.1       cgd notype_init_decls:
    990    1.1       cgd 	  notype_init_decl
    991    1.1       cgd 	| notype_init_decls T_COMMA type_init_decl
    992    1.1       cgd 	;
    993    1.1       cgd 
    994    1.1       cgd type_init_decls:
    995    1.1       cgd 	  type_init_decl
    996    1.1       cgd 	| type_init_decls T_COMMA type_init_decl
    997    1.1       cgd 	;
    998    1.1       cgd 
    999    1.1       cgd notype_init_decl:
   1000  1.110    rillig 	  notype_decl opt_asm_or_symbolrename {
   1001   1.11       cgd 		idecl($1, 0, $2);
   1002  1.111    rillig 		check_size($1);
   1003    1.1       cgd 	  }
   1004   1.11       cgd 	| notype_decl opt_asm_or_symbolrename {
   1005   1.11       cgd 		idecl($1, 1, $2);
   1006    1.1       cgd 	  } T_ASSIGN initializer {
   1007  1.111    rillig 		check_size($1);
   1008    1.1       cgd 	  }
   1009    1.1       cgd 	;
   1010    1.1       cgd 
   1011    1.1       cgd type_init_decl:
   1012  1.110    rillig 	  type_decl opt_asm_or_symbolrename {
   1013   1.11       cgd 		idecl($1, 0, $2);
   1014  1.111    rillig 		check_size($1);
   1015    1.1       cgd 	  }
   1016   1.11       cgd 	| type_decl opt_asm_or_symbolrename {
   1017   1.11       cgd 		idecl($1, 1, $2);
   1018    1.1       cgd 	  } T_ASSIGN initializer {
   1019  1.111    rillig 		check_size($1);
   1020    1.1       cgd 	  }
   1021    1.1       cgd 	;
   1022    1.1       cgd 
   1023    1.1       cgd notype_decl:
   1024    1.1       cgd 	  notype_direct_decl {
   1025    1.1       cgd 		$$ = $1;
   1026    1.1       cgd 	  }
   1027    1.1       cgd 	| pointer notype_direct_decl {
   1028  1.111    rillig 		$$ = add_pointer($2, $1);
   1029    1.1       cgd 	  }
   1030    1.1       cgd 	;
   1031    1.1       cgd 
   1032    1.1       cgd notype_direct_decl:
   1033    1.1       cgd 	  T_NAME {
   1034  1.111    rillig 		$$ = declarator_name(getsym($1));
   1035    1.1       cgd 	  }
   1036    1.1       cgd 	| T_LPARN type_decl T_RPARN {
   1037    1.1       cgd 		$$ = $2;
   1038    1.1       cgd 	  }
   1039   1.63  christos 	| type_attribute notype_direct_decl {
   1040   1.63  christos 		$$ = $2;
   1041   1.63  christos 	}
   1042    1.1       cgd 	| notype_direct_decl T_LBRACK T_RBRACK {
   1043  1.111    rillig 		$$ = add_array($1, 0, 0);
   1044    1.1       cgd 	  }
   1045    1.1       cgd 	| notype_direct_decl T_LBRACK constant T_RBRACK {
   1046  1.111    rillig 		$$ = add_array($1, 1, toicon($3, 0));
   1047    1.1       cgd 	  }
   1048   1.64  christos 	| notype_direct_decl param_list opt_asm_or_symbolrename {
   1049  1.111    rillig 		$$ = add_function(symbolrename($1, $3), $2);
   1050    1.1       cgd 		popdecl();
   1051    1.1       cgd 		blklev--;
   1052    1.1       cgd 	  }
   1053   1.87  christos 	| notype_direct_decl type_attribute_list
   1054    1.1       cgd 	;
   1055    1.1       cgd 
   1056    1.1       cgd type_decl:
   1057    1.1       cgd 	  type_direct_decl {
   1058    1.1       cgd 		$$ = $1;
   1059    1.1       cgd 	  }
   1060    1.1       cgd 	| pointer type_direct_decl {
   1061  1.111    rillig 		$$ = add_pointer($2, $1);
   1062    1.1       cgd 	  }
   1063    1.1       cgd 	;
   1064    1.1       cgd 
   1065    1.1       cgd type_direct_decl:
   1066    1.1       cgd 	  identifier {
   1067  1.111    rillig 		$$ = declarator_name(getsym($1));
   1068    1.1       cgd 	  }
   1069    1.1       cgd 	| T_LPARN type_decl T_RPARN {
   1070    1.1       cgd 		$$ = $2;
   1071    1.1       cgd 	  }
   1072   1.63  christos 	| type_attribute type_direct_decl {
   1073   1.63  christos 		$$ = $2;
   1074   1.63  christos 	}
   1075    1.1       cgd 	| type_direct_decl T_LBRACK T_RBRACK {
   1076  1.111    rillig 		$$ = add_array($1, 0, 0);
   1077    1.1       cgd 	  }
   1078    1.1       cgd 	| type_direct_decl T_LBRACK constant T_RBRACK {
   1079  1.111    rillig 		$$ = add_array($1, 1, toicon($3, 0));
   1080    1.1       cgd 	  }
   1081   1.64  christos 	| type_direct_decl param_list opt_asm_or_symbolrename {
   1082  1.111    rillig 		$$ = add_function(symbolrename($1, $3), $2);
   1083    1.1       cgd 		popdecl();
   1084    1.1       cgd 		blklev--;
   1085    1.1       cgd 	  }
   1086   1.87  christos 	| type_direct_decl type_attribute_list
   1087    1.1       cgd 	;
   1088    1.1       cgd 
   1089    1.1       cgd /*
   1090    1.1       cgd  * param_decl and notype_param_decl exist to avoid a conflict in
   1091    1.1       cgd  * argument lists. A typename enclosed in parens should always be
   1092    1.1       cgd  * treated as a typename, not an argument.
   1093    1.1       cgd  * "typedef int a; f(int (a));" is  "typedef int a; f(int foo(a));"
   1094    1.1       cgd  *				not "typedef int a; f(int a);"
   1095    1.1       cgd  */
   1096    1.1       cgd param_decl:
   1097    1.1       cgd 	  direct_param_decl {
   1098    1.1       cgd 		$$ = $1;
   1099    1.1       cgd 	  }
   1100    1.1       cgd 	| pointer direct_param_decl {
   1101  1.111    rillig 		$$ = add_pointer($2, $1);
   1102    1.1       cgd 	  }
   1103    1.1       cgd 	;
   1104    1.1       cgd 
   1105    1.1       cgd direct_param_decl:
   1106   1.87  christos 	  identifier type_attribute_list {
   1107  1.111    rillig 		$$ = declarator_name(getsym($1));
   1108   1.78  christos 	  }
   1109   1.78  christos 	| identifier {
   1110  1.111    rillig 		$$ = declarator_name(getsym($1));
   1111    1.1       cgd 	  }
   1112    1.1       cgd 	| T_LPARN notype_param_decl T_RPARN {
   1113    1.1       cgd 		$$ = $2;
   1114    1.1       cgd 	  }
   1115    1.1       cgd 	| direct_param_decl T_LBRACK T_RBRACK {
   1116  1.111    rillig 		$$ = add_array($1, 0, 0);
   1117    1.1       cgd 	  }
   1118    1.1       cgd 	| direct_param_decl T_LBRACK constant T_RBRACK {
   1119  1.111    rillig 		$$ = add_array($1, 1, toicon($3, 0));
   1120    1.1       cgd 	  }
   1121   1.64  christos 	| direct_param_decl param_list opt_asm_or_symbolrename {
   1122  1.111    rillig 		$$ = add_function(symbolrename($1, $3), $2);
   1123    1.1       cgd 		popdecl();
   1124    1.1       cgd 		blklev--;
   1125    1.1       cgd 	  }
   1126    1.1       cgd 	;
   1127    1.1       cgd 
   1128    1.1       cgd notype_param_decl:
   1129    1.1       cgd 	  direct_notype_param_decl {
   1130    1.1       cgd 		$$ = $1;
   1131    1.1       cgd 	  }
   1132    1.1       cgd 	| pointer direct_notype_param_decl {
   1133  1.111    rillig 		$$ = add_pointer($2, $1);
   1134    1.1       cgd 	  }
   1135    1.1       cgd 	;
   1136    1.1       cgd 
   1137    1.1       cgd direct_notype_param_decl:
   1138   1.68  christos 	  identifier {
   1139  1.111    rillig 		$$ = declarator_name(getsym($1));
   1140    1.1       cgd 	  }
   1141    1.1       cgd 	| T_LPARN notype_param_decl T_RPARN {
   1142    1.1       cgd 		$$ = $2;
   1143    1.1       cgd 	  }
   1144    1.1       cgd 	| direct_notype_param_decl T_LBRACK T_RBRACK {
   1145  1.111    rillig 		$$ = add_array($1, 0, 0);
   1146    1.1       cgd 	  }
   1147    1.1       cgd 	| direct_notype_param_decl T_LBRACK constant T_RBRACK {
   1148  1.111    rillig 		$$ = add_array($1, 1, toicon($3, 0));
   1149    1.1       cgd 	  }
   1150   1.64  christos 	| direct_notype_param_decl param_list opt_asm_or_symbolrename {
   1151  1.111    rillig 		$$ = add_function(symbolrename($1, $3), $2);
   1152    1.1       cgd 		popdecl();
   1153    1.1       cgd 		blklev--;
   1154    1.1       cgd 	  }
   1155    1.1       cgd 	;
   1156    1.1       cgd 
   1157    1.1       cgd pointer:
   1158    1.1       cgd 	  asterisk {
   1159    1.1       cgd 		$$ = $1;
   1160    1.1       cgd 	  }
   1161    1.1       cgd 	| asterisk type_qualifier_list {
   1162  1.111    rillig 		$$ = merge_pointers_and_qualifiers($1, $2);
   1163    1.1       cgd 	  }
   1164    1.1       cgd 	| asterisk pointer {
   1165  1.111    rillig 		$$ = merge_pointers_and_qualifiers($1, $2);
   1166    1.1       cgd 	  }
   1167    1.1       cgd 	| asterisk type_qualifier_list pointer {
   1168  1.111    rillig 		$$ = merge_pointers_and_qualifiers(
   1169  1.111    rillig 		    merge_pointers_and_qualifiers($1, $2), $3);
   1170    1.1       cgd 	  }
   1171    1.1       cgd 	;
   1172    1.1       cgd 
   1173    1.1       cgd asterisk:
   1174    1.1       cgd 	  T_MULT {
   1175    1.1       cgd 		$$ = xcalloc(1, sizeof (pqinf_t));
   1176    1.1       cgd 		$$->p_pcnt = 1;
   1177    1.1       cgd 	  }
   1178    1.1       cgd 	;
   1179    1.1       cgd 
   1180    1.1       cgd type_qualifier_list:
   1181    1.1       cgd 	  type_qualifier {
   1182    1.1       cgd 		$$ = $1;
   1183    1.1       cgd 	  }
   1184    1.1       cgd 	| type_qualifier_list type_qualifier {
   1185  1.111    rillig 		$$ = merge_pointers_and_qualifiers($1, $2);
   1186    1.1       cgd 	  }
   1187    1.1       cgd 	;
   1188    1.1       cgd 
   1189    1.1       cgd type_qualifier:
   1190    1.1       cgd 	  T_QUAL {
   1191    1.1       cgd 		$$ = xcalloc(1, sizeof (pqinf_t));
   1192    1.5       jpo 		if ($1 == CONST) {
   1193    1.5       jpo 			$$->p_const = 1;
   1194    1.1       cgd 		} else {
   1195    1.5       jpo 			$$->p_volatile = 1;
   1196    1.1       cgd 		}
   1197    1.1       cgd 	  }
   1198    1.1       cgd 	;
   1199    1.1       cgd 
   1200    1.1       cgd param_list:
   1201    1.1       cgd 	  id_list_lparn identifier_list T_RPARN {
   1202    1.1       cgd 		$$ = $2;
   1203    1.1       cgd 	  }
   1204    1.1       cgd 	| abs_decl_param_list {
   1205    1.1       cgd 		$$ = $1;
   1206    1.1       cgd 	  }
   1207    1.1       cgd 	;
   1208    1.1       cgd 
   1209    1.1       cgd id_list_lparn:
   1210    1.1       cgd 	  T_LPARN {
   1211    1.1       cgd 		blklev++;
   1212    1.1       cgd 		pushdecl(PARG);
   1213    1.1       cgd 	  }
   1214    1.1       cgd 	;
   1215    1.1       cgd 
   1216    1.1       cgd identifier_list:
   1217    1.1       cgd 	  T_NAME {
   1218  1.111    rillig 		$$ = old_style_function_name(getsym($1));
   1219    1.1       cgd 	  }
   1220    1.1       cgd 	| identifier_list T_COMMA T_NAME {
   1221  1.111    rillig 		$$ = lnklst($1, old_style_function_name(getsym($3)));
   1222    1.1       cgd 	  }
   1223    1.1       cgd 	| identifier_list error {
   1224    1.1       cgd 		$$ = $1;
   1225    1.1       cgd 	  }
   1226    1.1       cgd 	;
   1227    1.1       cgd 
   1228    1.1       cgd abs_decl_param_list:
   1229    1.1       cgd 	  abs_decl_lparn T_RPARN {
   1230    1.1       cgd 		$$ = NULL;
   1231    1.1       cgd 	  }
   1232    1.1       cgd 	| abs_decl_lparn vararg_parameter_type_list T_RPARN {
   1233    1.3       jpo 		dcs->d_proto = 1;
   1234    1.1       cgd 		$$ = $2;
   1235    1.1       cgd 	  }
   1236    1.1       cgd 	| abs_decl_lparn error T_RPARN {
   1237    1.1       cgd 		$$ = NULL;
   1238    1.1       cgd 	  }
   1239    1.1       cgd 	;
   1240    1.1       cgd 
   1241    1.1       cgd abs_decl_lparn:
   1242    1.1       cgd 	  T_LPARN {
   1243    1.1       cgd 		blklev++;
   1244    1.1       cgd 		pushdecl(PARG);
   1245    1.1       cgd 	  }
   1246    1.1       cgd 	;
   1247    1.1       cgd 
   1248    1.1       cgd vararg_parameter_type_list:
   1249    1.1       cgd 	  parameter_type_list {
   1250    1.1       cgd 		$$ = $1;
   1251    1.1       cgd 	  }
   1252    1.1       cgd 	| parameter_type_list T_COMMA T_ELLIPSE {
   1253    1.3       jpo 		dcs->d_vararg = 1;
   1254    1.1       cgd 		$$ = $1;
   1255    1.1       cgd 	  }
   1256    1.1       cgd 	| T_ELLIPSE {
   1257    1.1       cgd 		if (sflag) {
   1258    1.1       cgd 			/* ANSI C requires formal parameter before "..." */
   1259    1.1       cgd 			error(84);
   1260    1.1       cgd 		} else if (!tflag) {
   1261    1.1       cgd 			/* ANSI C requires formal parameter before "..." */
   1262    1.1       cgd 			warning(84);
   1263    1.1       cgd 		}
   1264    1.3       jpo 		dcs->d_vararg = 1;
   1265    1.1       cgd 		$$ = NULL;
   1266    1.1       cgd 	  }
   1267    1.1       cgd 	;
   1268    1.1       cgd 
   1269    1.1       cgd parameter_type_list:
   1270   1.11       cgd 	  parameter_declaration {
   1271    1.1       cgd 		$$ = $1;
   1272    1.1       cgd 	  }
   1273   1.11       cgd 	| parameter_type_list T_COMMA parameter_declaration {
   1274    1.1       cgd 		$$ = lnklst($1, $3);
   1275    1.1       cgd 	  }
   1276    1.1       cgd 	;
   1277    1.1       cgd 
   1278    1.1       cgd parameter_declaration:
   1279    1.1       cgd 	  declmods deftyp {
   1280  1.111    rillig 		$$ = decl1arg(abstract_name(), 0);
   1281    1.1       cgd 	  }
   1282    1.1       cgd 	| declspecs deftyp {
   1283  1.111    rillig 		$$ = decl1arg(abstract_name(), 0);
   1284    1.1       cgd 	  }
   1285    1.1       cgd 	| declmods deftyp notype_param_decl {
   1286    1.1       cgd 		$$ = decl1arg($3, 0);
   1287    1.1       cgd 	  }
   1288    1.1       cgd 	/*
   1289    1.1       cgd 	 * param_decl is needed because of following conflict:
   1290    1.1       cgd 	 * "typedef int a; f(int (a));" could be parsed as
   1291    1.1       cgd 	 * "function with argument a of type int", or
   1292    1.1       cgd 	 * "function with an abstract argument of type function".
   1293    1.1       cgd 	 * This grammar realizes the second case.
   1294    1.1       cgd 	 */
   1295    1.1       cgd 	| declspecs deftyp param_decl {
   1296    1.1       cgd 		$$ = decl1arg($3, 0);
   1297    1.1       cgd 	  }
   1298    1.1       cgd 	| declmods deftyp abs_decl {
   1299    1.1       cgd 		$$ = decl1arg($3, 0);
   1300    1.1       cgd 	  }
   1301    1.1       cgd 	| declspecs deftyp abs_decl {
   1302    1.1       cgd 		$$ = decl1arg($3, 0);
   1303    1.1       cgd 	  }
   1304    1.1       cgd 	;
   1305    1.1       cgd 
   1306   1.11       cgd opt_asm_or_symbolrename:		/* expect only one */
   1307   1.11       cgd 	  /* empty */ {
   1308   1.11       cgd 		$$ = NULL;
   1309   1.11       cgd 	  }
   1310    1.6       jpo 	| T_ASM T_LPARN T_STRING T_RPARN {
   1311    1.6       jpo 		freeyyv(&$3, T_STRING);
   1312   1.11       cgd 		$$ = NULL;
   1313   1.11       cgd 	  }
   1314   1.11       cgd 	| T_SYMBOLRENAME T_LPARN T_NAME T_RPARN {
   1315   1.11       cgd 		$$ = $3;
   1316    1.6       jpo 	  }
   1317    1.6       jpo 	;
   1318    1.6       jpo 
   1319    1.1       cgd initializer:
   1320  1.117    rillig 	  {
   1321  1.117    rillig 		cgram_debug("begin initializer");
   1322  1.117    rillig 	  } init_assign_expr {
   1323  1.117    rillig 		cgram_debug("end initializer");
   1324  1.117    rillig 	  }
   1325    1.1       cgd 	;
   1326    1.1       cgd 
   1327   1.79  dholland init_assign_expr:
   1328   1.79  dholland 	| init_by_name init_base_expr	%prec T_COMMA
   1329   1.79  dholland 	| init_base_expr
   1330   1.79  dholland 
   1331   1.79  dholland init_base_expr:
   1332   1.79  dholland 	  expr				%prec T_COMMA {
   1333    1.1       cgd 		mkinit($1);
   1334    1.1       cgd 	  }
   1335   1.56  christos 	| init_lbrace init_rbrace
   1336    1.1       cgd 	| init_lbrace init_expr_list init_rbrace
   1337    1.1       cgd 	| init_lbrace init_expr_list T_COMMA init_rbrace
   1338    1.1       cgd 	| error
   1339    1.1       cgd 	;
   1340    1.1       cgd 
   1341    1.1       cgd init_expr_list:
   1342   1.79  dholland 	  init_assign_expr		%prec T_COMMA
   1343   1.79  dholland 	| init_expr_list T_COMMA init_assign_expr
   1344    1.1       cgd 	;
   1345    1.1       cgd 
   1346  1.109    rillig lorange:
   1347   1.35  christos 	  constant T_ELLIPSE {
   1348   1.35  christos 		$$.lo = toicon($1, 1);
   1349   1.35  christos 	  }
   1350   1.35  christos 	;
   1351   1.35  christos range:
   1352  1.110    rillig 	  constant {
   1353   1.35  christos 		$$.lo = toicon($1, 1);
   1354   1.35  christos 		$$.hi = $$.lo + 1;
   1355   1.35  christos 	  }
   1356   1.35  christos 	| lorange constant {
   1357   1.35  christos 		$$.lo = $1.lo;
   1358   1.35  christos 		$$.hi = toicon($2, 1);
   1359   1.35  christos 	  }
   1360   1.35  christos 	;
   1361   1.35  christos 
   1362   1.71  christos init_field:
   1363   1.71  christos 	  T_LBRACK range T_RBRACK {
   1364   1.34      yamt 		if (!Sflag)
   1365   1.34      yamt 			warning(321);
   1366   1.34      yamt 	  }
   1367   1.71  christos 	| point identifier {
   1368   1.26  christos 		if (!Sflag)
   1369   1.26  christos 			warning(313);
   1370  1.114    rillig 		push_member($2);
   1371   1.26  christos 	  }
   1372   1.71  christos 	;
   1373   1.71  christos 
   1374   1.71  christos init_field_list:
   1375   1.71  christos 	  init_field
   1376   1.71  christos 	| init_field_list init_field
   1377   1.71  christos 	;
   1378   1.71  christos 
   1379   1.71  christos init_by_name:
   1380   1.71  christos 	  init_field_list T_ASSIGN
   1381   1.37  christos 	| identifier T_COLON {
   1382   1.26  christos 		gnuism(315);
   1383  1.114    rillig 		push_member($1);
   1384   1.26  christos 	  }
   1385   1.26  christos 	;
   1386   1.26  christos 
   1387    1.1       cgd init_lbrace:
   1388    1.1       cgd 	  T_LBRACE {
   1389  1.114    rillig 		init_lbrace();
   1390    1.1       cgd 	  }
   1391    1.1       cgd 	;
   1392    1.1       cgd 
   1393    1.1       cgd init_rbrace:
   1394    1.1       cgd 	  T_RBRACE {
   1395  1.114    rillig 		init_rbrace();
   1396    1.1       cgd 	  }
   1397    1.1       cgd 	;
   1398    1.1       cgd 
   1399    1.1       cgd type_name:
   1400  1.110    rillig 	  {
   1401    1.1       cgd 		pushdecl(ABSTRACT);
   1402    1.1       cgd 	  } abstract_declaration {
   1403    1.1       cgd 		popdecl();
   1404    1.1       cgd 		$$ = $2->s_type;
   1405    1.1       cgd 	  }
   1406    1.1       cgd 	;
   1407    1.1       cgd 
   1408    1.1       cgd abstract_declaration:
   1409    1.1       cgd 	  noclass_declmods deftyp {
   1410  1.111    rillig 		$$ = declare_1_abstract(abstract_name());
   1411    1.1       cgd 	  }
   1412    1.1       cgd 	| noclass_declspecs deftyp {
   1413  1.111    rillig 		$$ = declare_1_abstract(abstract_name());
   1414    1.1       cgd 	  }
   1415    1.1       cgd 	| noclass_declmods deftyp abs_decl {
   1416  1.111    rillig 		$$ = declare_1_abstract($3);
   1417    1.1       cgd 	  }
   1418    1.1       cgd 	| noclass_declspecs deftyp abs_decl {
   1419  1.111    rillig 		$$ = declare_1_abstract($3);
   1420    1.1       cgd 	  }
   1421    1.1       cgd 	;
   1422    1.1       cgd 
   1423    1.1       cgd abs_decl:
   1424    1.1       cgd 	  pointer {
   1425  1.111    rillig 		$$ = add_pointer(abstract_name(), $1);
   1426    1.1       cgd 	  }
   1427    1.1       cgd 	| direct_abs_decl {
   1428    1.1       cgd 		$$ = $1;
   1429    1.1       cgd 	  }
   1430    1.1       cgd 	| pointer direct_abs_decl {
   1431  1.111    rillig 		$$ = add_pointer($2, $1);
   1432    1.1       cgd 	  }
   1433   1.94  christos 	| T_TYPEOF term {
   1434   1.94  christos 		$$ = mktempsym($2->tn_type);
   1435   1.94  christos 	  }
   1436    1.1       cgd 	;
   1437    1.1       cgd 
   1438    1.1       cgd direct_abs_decl:
   1439    1.1       cgd 	  T_LPARN abs_decl T_RPARN {
   1440    1.1       cgd 		$$ = $2;
   1441    1.1       cgd 	  }
   1442    1.1       cgd 	| T_LBRACK T_RBRACK {
   1443  1.111    rillig 		$$ = add_array(abstract_name(), 0, 0);
   1444    1.1       cgd 	  }
   1445    1.1       cgd 	| T_LBRACK constant T_RBRACK {
   1446  1.111    rillig 		$$ = add_array(abstract_name(), 1, toicon($2, 0));
   1447    1.1       cgd 	  }
   1448   1.63  christos 	| type_attribute direct_abs_decl {
   1449   1.63  christos 		$$ = $2;
   1450   1.63  christos 	}
   1451    1.1       cgd 	| direct_abs_decl T_LBRACK T_RBRACK {
   1452  1.111    rillig 		$$ = add_array($1, 0, 0);
   1453    1.1       cgd 	  }
   1454    1.1       cgd 	| direct_abs_decl T_LBRACK constant T_RBRACK {
   1455  1.111    rillig 		$$ = add_array($1, 1, toicon($3, 0));
   1456    1.1       cgd 	  }
   1457   1.64  christos 	| abs_decl_param_list opt_asm_or_symbolrename {
   1458  1.111    rillig 		$$ = add_function(symbolrename(abstract_name(), $2), $1);
   1459    1.1       cgd 		popdecl();
   1460    1.1       cgd 		blklev--;
   1461    1.1       cgd 	  }
   1462   1.64  christos 	| direct_abs_decl abs_decl_param_list opt_asm_or_symbolrename {
   1463  1.111    rillig 		$$ = add_function(symbolrename($1, $3), $2);
   1464    1.1       cgd 		popdecl();
   1465    1.1       cgd 		blklev--;
   1466    1.1       cgd 	  }
   1467   1.87  christos 	| direct_abs_decl type_attribute_list
   1468    1.1       cgd 	;
   1469    1.1       cgd 
   1470   1.32  christos non_expr_stmnt:
   1471    1.1       cgd 	  labeled_stmnt
   1472    1.1       cgd 	| comp_stmnt
   1473    1.1       cgd 	| selection_stmnt
   1474    1.1       cgd 	| iteration_stmnt
   1475    1.1       cgd 	| jump_stmnt {
   1476    1.1       cgd 		ftflg = 0;
   1477    1.1       cgd 	  }
   1478    1.6       jpo 	| asm_stmnt
   1479   1.32  christos 
   1480   1.32  christos stmnt:
   1481   1.32  christos 	  expr_stmnt
   1482   1.32  christos 	| non_expr_stmnt
   1483    1.1       cgd 	;
   1484    1.1       cgd 
   1485    1.1       cgd labeled_stmnt:
   1486    1.1       cgd 	  label stmnt
   1487    1.1       cgd 	;
   1488    1.1       cgd 
   1489    1.1       cgd label:
   1490   1.53  christos 	  T_NAME T_COLON {
   1491    1.1       cgd 		symtyp = FLAB;
   1492    1.1       cgd 		label(T_NAME, getsym($1), NULL);
   1493    1.1       cgd 	  }
   1494    1.1       cgd 	| T_CASE constant T_COLON {
   1495    1.1       cgd 		label(T_CASE, NULL, $2);
   1496    1.1       cgd 		ftflg = 1;
   1497   1.40  christos 	}
   1498   1.40  christos 	| T_CASE constant T_ELLIPSE constant T_COLON {
   1499   1.40  christos 		/* XXX: We don't fill all cases */
   1500   1.40  christos 		label(T_CASE, NULL, $2);
   1501   1.40  christos 		ftflg = 1;
   1502   1.40  christos 	}
   1503    1.1       cgd 	| T_DEFAULT T_COLON {
   1504    1.1       cgd 		label(T_DEFAULT, NULL, NULL);
   1505    1.1       cgd 		ftflg = 1;
   1506    1.1       cgd 	  }
   1507    1.1       cgd 	;
   1508    1.1       cgd 
   1509   1.50  christos stmnt_d_list:
   1510   1.50  christos 	  stmnt_list
   1511   1.50  christos 	| stmnt_d_list declaration_list stmnt_list {
   1512   1.50  christos 		if (!Sflag)
   1513   1.50  christos 			c99ism(327);
   1514   1.50  christos 	}
   1515   1.50  christos 	;
   1516   1.50  christos 
   1517    1.1       cgd comp_stmnt:
   1518   1.50  christos 	  comp_stmnt_lbrace comp_stmnt_rbrace
   1519   1.57     njoly 	| comp_stmnt_lbrace stmnt_d_list comp_stmnt_rbrace
   1520   1.50  christos 	| comp_stmnt_lbrace declaration_list comp_stmnt_rbrace
   1521   1.50  christos 	| comp_stmnt_lbrace declaration_list stmnt_d_list comp_stmnt_rbrace
   1522    1.1       cgd 	;
   1523    1.1       cgd 
   1524   1.29  christos comp_stmnt_lbrace:
   1525    1.1       cgd 	  T_LBRACE {
   1526    1.1       cgd 		blklev++;
   1527    1.1       cgd 		mblklev++;
   1528    1.1       cgd 		pushdecl(AUTO);
   1529    1.1       cgd 	  }
   1530    1.1       cgd 	;
   1531    1.1       cgd 
   1532   1.29  christos comp_stmnt_rbrace:
   1533    1.1       cgd 	  T_RBRACE {
   1534    1.1       cgd 		popdecl();
   1535    1.1       cgd 		freeblk();
   1536    1.1       cgd 		mblklev--;
   1537    1.1       cgd 		blklev--;
   1538    1.1       cgd 		ftflg = 0;
   1539    1.1       cgd 	  }
   1540    1.1       cgd 	;
   1541    1.1       cgd 
   1542    1.1       cgd stmnt_list:
   1543   1.14  christos 	  stmnt
   1544    1.7       jpo 	| stmnt_list stmnt {
   1545   1.39  christos 		RESTORE(__FILE__, __LINE__);
   1546    1.7       jpo 	  }
   1547   1.15  christos 	| stmnt_list error T_SEMI
   1548    1.1       cgd 	;
   1549    1.1       cgd 
   1550    1.1       cgd expr_stmnt:
   1551    1.1       cgd 	  expr T_SEMI {
   1552   1.80  christos 		expr($1, 0, 0, 0);
   1553    1.1       cgd 		ftflg = 0;
   1554    1.1       cgd 	  }
   1555    1.1       cgd 	| T_SEMI {
   1556    1.1       cgd 		ftflg = 0;
   1557    1.1       cgd 	  }
   1558    1.1       cgd 	;
   1559    1.1       cgd 
   1560   1.30  christos /*
   1561  1.109    rillig  * The following two productions are used to implement
   1562   1.32  christos  * ({ [[decl-list] stmt-list] }).
   1563   1.32  christos  * XXX: This is not well tested.
   1564   1.30  christos  */
   1565   1.29  christos expr_stmnt_val:
   1566   1.29  christos 	  expr T_SEMI {
   1567   1.29  christos 		/* XXX: We should really do that only on the last name */
   1568   1.29  christos 		if ($1->tn_op == NAME)
   1569   1.29  christos 			$1->tn_sym->s_used = 1;
   1570   1.29  christos 		$$ = $1;
   1571   1.29  christos 		expr($1, 0, 0, 0);
   1572   1.29  christos 		ftflg = 0;
   1573   1.29  christos 	  }
   1574   1.33  christos 	| non_expr_stmnt {
   1575   1.33  christos 		$$ = getnode();
   1576   1.33  christos 		$$->tn_type = gettyp(VOID);
   1577   1.33  christos 	}
   1578   1.29  christos 	;
   1579   1.29  christos 
   1580   1.29  christos expr_stmnt_list:
   1581   1.32  christos 	  expr_stmnt_val
   1582   1.33  christos 	| expr_stmnt_list expr_stmnt_val {
   1583   1.32  christos 		$$ = $2;
   1584   1.32  christos 	}
   1585   1.29  christos 	;
   1586   1.29  christos 
   1587    1.1       cgd selection_stmnt:
   1588    1.1       cgd 	  if_without_else {
   1589   1.39  christos 		SAVE(__FILE__, __LINE__);
   1590    1.1       cgd 		if2();
   1591    1.1       cgd 		if3(0);
   1592    1.1       cgd 	  }
   1593    1.1       cgd 	| if_without_else T_ELSE {
   1594   1.39  christos 		SAVE(__FILE__, __LINE__);
   1595    1.1       cgd 		if2();
   1596    1.1       cgd 	  } stmnt {
   1597   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1598    1.1       cgd 		if3(1);
   1599    1.1       cgd 	  }
   1600    1.1       cgd 	| if_without_else T_ELSE error {
   1601   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1602    1.1       cgd 		if3(0);
   1603    1.1       cgd 	  }
   1604    1.1       cgd 	| switch_expr stmnt {
   1605   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1606    1.1       cgd 		switch2();
   1607    1.1       cgd 	  }
   1608    1.1       cgd 	| switch_expr error {
   1609   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1610    1.1       cgd 		switch2();
   1611    1.1       cgd 	  }
   1612    1.1       cgd 	;
   1613    1.1       cgd 
   1614    1.1       cgd if_without_else:
   1615    1.1       cgd 	  if_expr stmnt
   1616    1.1       cgd 	| if_expr error
   1617    1.1       cgd 	;
   1618    1.1       cgd 
   1619    1.1       cgd if_expr:
   1620    1.1       cgd 	  T_IF T_LPARN expr T_RPARN {
   1621    1.1       cgd 		if1($3);
   1622   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1623    1.1       cgd 	  }
   1624    1.1       cgd 	;
   1625    1.1       cgd 
   1626    1.1       cgd switch_expr:
   1627    1.1       cgd 	  T_SWITCH T_LPARN expr T_RPARN {
   1628    1.1       cgd 		switch1($3);
   1629   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1630    1.1       cgd 	  }
   1631    1.1       cgd 	;
   1632    1.1       cgd 
   1633   1.81  christos association:
   1634   1.81  christos 	  type_name T_COLON expr
   1635  1.109    rillig 	| T_DEFAULT T_COLON expr
   1636   1.81  christos 	;
   1637   1.81  christos 
   1638   1.81  christos association_list:
   1639   1.81  christos 	  association
   1640   1.81  christos 	| association_list T_COMMA association
   1641   1.81  christos 	;
   1642   1.81  christos 
   1643   1.81  christos generic_expr:
   1644   1.81  christos 	  T_GENERIC T_LPARN expr T_COMMA association_list T_RPARN {
   1645   1.81  christos 		$$ = $3;
   1646   1.81  christos 	  }
   1647   1.81  christos 	;
   1648   1.81  christos 
   1649   1.14  christos do_stmnt:
   1650   1.14  christos 	  do stmnt {
   1651   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1652   1.14  christos 	  }
   1653   1.14  christos 	;
   1654   1.14  christos 
   1655    1.1       cgd iteration_stmnt:
   1656    1.1       cgd 	  while_expr stmnt {
   1657   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1658    1.1       cgd 		while2();
   1659    1.1       cgd 	  }
   1660    1.1       cgd 	| while_expr error {
   1661   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1662    1.1       cgd 		while2();
   1663    1.1       cgd 	  }
   1664   1.14  christos 	| do_stmnt do_while_expr {
   1665   1.14  christos 		do2($2);
   1666    1.1       cgd 		ftflg = 0;
   1667    1.1       cgd 	  }
   1668    1.1       cgd 	| do error {
   1669   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1670    1.1       cgd 		do2(NULL);
   1671    1.1       cgd 	  }
   1672    1.1       cgd 	| for_exprs stmnt {
   1673   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1674    1.1       cgd 		for2();
   1675   1.67  christos 		popdecl();
   1676   1.67  christos 		blklev--;
   1677    1.1       cgd 	  }
   1678    1.1       cgd 	| for_exprs error {
   1679   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1680    1.1       cgd 		for2();
   1681   1.67  christos 		popdecl();
   1682   1.67  christos 		blklev--;
   1683    1.1       cgd 	  }
   1684    1.1       cgd 	;
   1685    1.1       cgd 
   1686    1.1       cgd while_expr:
   1687    1.1       cgd 	  T_WHILE T_LPARN expr T_RPARN {
   1688    1.1       cgd 		while1($3);
   1689   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1690    1.1       cgd 	  }
   1691    1.1       cgd 	;
   1692    1.1       cgd 
   1693    1.1       cgd do:
   1694    1.1       cgd 	  T_DO {
   1695    1.1       cgd 		do1();
   1696    1.1       cgd 	  }
   1697    1.1       cgd 	;
   1698    1.1       cgd 
   1699    1.1       cgd do_while_expr:
   1700    1.1       cgd 	  T_WHILE T_LPARN expr T_RPARN T_SEMI {
   1701    1.1       cgd 		$$ = $3;
   1702    1.1       cgd 	  }
   1703    1.1       cgd 	;
   1704    1.1       cgd 
   1705   1.66  christos for_start:
   1706   1.66  christos 	  T_FOR T_LPARN {
   1707   1.66  christos 		pushdecl(AUTO);
   1708   1.66  christos 		blklev++;
   1709   1.66  christos 	  }
   1710   1.66  christos 	;
   1711    1.1       cgd for_exprs:
   1712  1.110    rillig 	  for_start declspecs deftyp notype_init_decls T_SEMI opt_expr
   1713  1.110    rillig 	  T_SEMI opt_expr T_RPARN {
   1714   1.43  christos 		c99ism(325);
   1715   1.66  christos 		for1(NULL, $6, $8);
   1716   1.43  christos 		CLRWFLGS(__FILE__, __LINE__);
   1717   1.43  christos 	    }
   1718   1.66  christos 	  | for_start opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN {
   1719   1.66  christos 		for1($2, $4, $6);
   1720   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1721    1.1       cgd 	  }
   1722    1.1       cgd 	;
   1723    1.1       cgd 
   1724    1.1       cgd opt_expr:
   1725    1.1       cgd 	  /* empty */ {
   1726    1.1       cgd 		$$ = NULL;
   1727    1.1       cgd 	  }
   1728    1.1       cgd 	| expr {
   1729    1.1       cgd 		$$ = $1;
   1730    1.1       cgd 	  }
   1731    1.1       cgd 	;
   1732    1.1       cgd 
   1733    1.1       cgd jump_stmnt:
   1734    1.1       cgd 	  goto identifier T_SEMI {
   1735    1.1       cgd 		dogoto(getsym($2));
   1736    1.1       cgd 	  }
   1737    1.1       cgd 	| goto error T_SEMI {
   1738    1.1       cgd 		symtyp = FVFT;
   1739    1.1       cgd 	  }
   1740    1.1       cgd 	| T_CONTINUE T_SEMI {
   1741    1.1       cgd 		docont();
   1742    1.1       cgd 	  }
   1743    1.1       cgd 	| T_BREAK T_SEMI {
   1744    1.1       cgd 		dobreak();
   1745    1.1       cgd 	  }
   1746    1.1       cgd 	| T_RETURN T_SEMI {
   1747    1.1       cgd 		doreturn(NULL);
   1748    1.1       cgd 	  }
   1749    1.1       cgd 	| T_RETURN expr T_SEMI {
   1750    1.1       cgd 		doreturn($2);
   1751    1.1       cgd 	  }
   1752    1.1       cgd 	;
   1753    1.1       cgd 
   1754    1.1       cgd goto:
   1755    1.1       cgd 	  T_GOTO {
   1756    1.1       cgd 		symtyp = FLAB;
   1757    1.1       cgd 	  }
   1758    1.1       cgd 	;
   1759    1.1       cgd 
   1760    1.6       jpo asm_stmnt:
   1761    1.8       jpo 	  T_ASM T_LPARN read_until_rparn T_SEMI {
   1762    1.8       jpo 		setasm();
   1763    1.8       jpo 	  }
   1764    1.8       jpo 	| T_ASM T_QUAL T_LPARN read_until_rparn T_SEMI {
   1765    1.8       jpo 		setasm();
   1766    1.8       jpo 	  }
   1767    1.8       jpo 	| T_ASM error
   1768    1.6       jpo 	;
   1769    1.6       jpo 
   1770    1.6       jpo read_until_rparn:
   1771    1.6       jpo 	  /* empty */ {
   1772    1.6       jpo 		ignuptorp();
   1773    1.6       jpo 	  }
   1774    1.6       jpo 	;
   1775    1.6       jpo 
   1776    1.1       cgd declaration_list:
   1777    1.7       jpo 	  declaration {
   1778   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1779    1.7       jpo 	  }
   1780    1.7       jpo 	| declaration_list declaration {
   1781   1.39  christos 		CLRWFLGS(__FILE__, __LINE__);
   1782    1.7       jpo 	  }
   1783    1.1       cgd 	;
   1784    1.1       cgd 
   1785    1.1       cgd constant:
   1786    1.1       cgd 	  expr				%prec T_COMMA {
   1787    1.1       cgd 		  $$ = $1;
   1788    1.1       cgd 	  }
   1789    1.1       cgd 	;
   1790    1.1       cgd 
   1791    1.1       cgd expr:
   1792    1.1       cgd 	  expr T_MULT expr {
   1793    1.1       cgd 		$$ = build(MULT, $1, $3);
   1794    1.1       cgd 	  }
   1795    1.1       cgd 	| expr T_DIVOP expr {
   1796    1.1       cgd 		$$ = build($2, $1, $3);
   1797    1.1       cgd 	  }
   1798    1.1       cgd 	| expr T_ADDOP expr {
   1799    1.1       cgd 		$$ = build($2, $1, $3);
   1800    1.1       cgd 	  }
   1801    1.1       cgd 	| expr T_SHFTOP expr {
   1802    1.1       cgd 		$$ = build($2, $1, $3);
   1803    1.1       cgd 	  }
   1804    1.1       cgd 	| expr T_RELOP expr {
   1805    1.1       cgd 		$$ = build($2, $1, $3);
   1806    1.1       cgd 	  }
   1807    1.1       cgd 	| expr T_EQOP expr {
   1808    1.1       cgd 		$$ = build($2, $1, $3);
   1809    1.1       cgd 	  }
   1810    1.1       cgd 	| expr T_AND expr {
   1811    1.1       cgd 		$$ = build(AND, $1, $3);
   1812    1.1       cgd 	  }
   1813    1.1       cgd 	| expr T_XOR expr {
   1814    1.1       cgd 		$$ = build(XOR, $1, $3);
   1815    1.1       cgd 	  }
   1816    1.1       cgd 	| expr T_OR expr {
   1817    1.1       cgd 		$$ = build(OR, $1, $3);
   1818    1.1       cgd 	  }
   1819    1.1       cgd 	| expr T_LOGAND expr {
   1820    1.1       cgd 		$$ = build(LOGAND, $1, $3);
   1821    1.1       cgd 	  }
   1822    1.1       cgd 	| expr T_LOGOR expr {
   1823    1.1       cgd 		$$ = build(LOGOR, $1, $3);
   1824    1.1       cgd 	  }
   1825    1.1       cgd 	| expr T_QUEST expr T_COLON expr {
   1826    1.1       cgd 		$$ = build(QUEST, $1, build(COLON, $3, $5));
   1827    1.1       cgd 	  }
   1828    1.1       cgd 	| expr T_ASSIGN expr {
   1829    1.1       cgd 		$$ = build(ASSIGN, $1, $3);
   1830    1.1       cgd 	  }
   1831    1.1       cgd 	| expr T_OPASS expr {
   1832    1.1       cgd 		$$ = build($2, $1, $3);
   1833    1.1       cgd 	  }
   1834    1.1       cgd 	| expr T_COMMA expr {
   1835    1.1       cgd 		$$ = build(COMMA, $1, $3);
   1836    1.1       cgd 	  }
   1837    1.1       cgd 	| term {
   1838    1.1       cgd 		$$ = $1;
   1839    1.1       cgd 	  }
   1840   1.81  christos 	| generic_expr {
   1841   1.81  christos 		$$ = $1;
   1842   1.81  christos 	  }
   1843    1.1       cgd 	;
   1844    1.1       cgd 
   1845    1.1       cgd term:
   1846    1.1       cgd 	  T_NAME {
   1847   1.21       wiz 		/* XXX really necessary? */
   1848    1.1       cgd 		if (yychar < 0)
   1849    1.1       cgd 			yychar = yylex();
   1850    1.1       cgd 		$$ = getnnode(getsym($1), yychar);
   1851    1.1       cgd 	  }
   1852    1.1       cgd 	| string {
   1853    1.1       cgd 		$$ = getsnode($1);
   1854    1.1       cgd 	  }
   1855    1.1       cgd 	| T_CON {
   1856    1.1       cgd 		$$ = getcnode(gettyp($1->v_tspec), $1);
   1857    1.1       cgd 	  }
   1858    1.1       cgd 	| T_LPARN expr T_RPARN {
   1859    1.1       cgd 		if ($2 != NULL)
   1860    1.1       cgd 			$2->tn_parn = 1;
   1861    1.1       cgd 		$$ = $2;
   1862    1.1       cgd 	  }
   1863   1.29  christos 	| T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list {
   1864   1.29  christos 		blklev--;
   1865   1.29  christos 		mblklev--;
   1866   1.31  kristerw 		initsym = mktempsym(duptyp($4->tn_type));
   1867   1.29  christos 		mblklev++;
   1868   1.29  christos 		blklev++;
   1869   1.29  christos 		gnuism(320);
   1870   1.29  christos 	} comp_stmnt_rbrace T_RPARN {
   1871   1.29  christos 		$$ = getnnode(initsym, 0);
   1872   1.29  christos 	}
   1873   1.29  christos 	| T_LPARN comp_stmnt_lbrace expr_stmnt_list {
   1874   1.29  christos 		blklev--;
   1875   1.29  christos 		mblklev--;
   1876   1.29  christos 		initsym = mktempsym($3->tn_type);
   1877   1.29  christos 		mblklev++;
   1878   1.29  christos 		blklev++;
   1879   1.29  christos 		gnuism(320);
   1880   1.29  christos 	} comp_stmnt_rbrace T_RPARN {
   1881   1.29  christos 		$$ = getnnode(initsym, 0);
   1882   1.29  christos 	}
   1883    1.1       cgd 	| term T_INCDEC {
   1884    1.1       cgd 		$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
   1885    1.1       cgd 	  }
   1886    1.1       cgd 	| T_INCDEC term {
   1887    1.1       cgd 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
   1888    1.1       cgd 	  }
   1889    1.1       cgd 	| T_MULT term {
   1890    1.1       cgd 		$$ = build(STAR, $2, NULL);
   1891    1.1       cgd 	  }
   1892    1.1       cgd 	| T_AND term {
   1893    1.1       cgd 		$$ = build(AMPER, $2, NULL);
   1894    1.1       cgd 	  }
   1895    1.1       cgd 	| T_UNOP term {
   1896    1.1       cgd 		$$ = build($1, $2, NULL);
   1897    1.1       cgd 	  }
   1898    1.1       cgd 	| T_ADDOP term {
   1899    1.1       cgd 		if (tflag && $1 == PLUS) {
   1900    1.1       cgd 			/* unary + is illegal in traditional C */
   1901    1.1       cgd 			warning(100);
   1902    1.1       cgd 		}
   1903    1.1       cgd 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
   1904    1.1       cgd 	  }
   1905    1.1       cgd 	| term T_LBRACK expr T_RBRACK {
   1906    1.1       cgd 		$$ = build(STAR, build(PLUS, $1, $3), NULL);
   1907    1.1       cgd 	  }
   1908    1.1       cgd 	| term T_LPARN T_RPARN {
   1909    1.1       cgd 		$$ = funccall($1, NULL);
   1910    1.1       cgd 	  }
   1911    1.1       cgd 	| term T_LPARN func_arg_list T_RPARN {
   1912    1.1       cgd 		$$ = funccall($1, $3);
   1913    1.1       cgd 	  }
   1914    1.1       cgd 	| term point_or_arrow T_NAME {
   1915    1.1       cgd 		if ($1 != NULL) {
   1916    1.1       cgd 			sym_t	*msym;
   1917  1.114    rillig 			/*
   1918  1.114    rillig 			 * XXX struct_or_union_member should be integrated
   1919  1.114    rillig 			 * in build()
   1920  1.114    rillig 			 */
   1921    1.1       cgd 			if ($2 == ARROW) {
   1922  1.114    rillig 				/*
   1923  1.114    rillig 				 * must do this before struct_or_union_member
   1924  1.114    rillig 				 * is called
   1925  1.114    rillig 				 */
   1926    1.1       cgd 				$1 = cconv($1);
   1927    1.1       cgd 			}
   1928  1.114    rillig 			msym = struct_or_union_member($1, $2, getsym($3));
   1929    1.1       cgd 			$$ = build($2, $1, getnnode(msym, 0));
   1930    1.1       cgd 		} else {
   1931    1.1       cgd 			$$ = NULL;
   1932    1.1       cgd 		}
   1933    1.1       cgd 	  }
   1934   1.41  christos 	| T_REAL term {
   1935   1.41  christos 		$$ = build(REAL, $2, NULL);
   1936   1.41  christos 	  }
   1937   1.41  christos 	| T_IMAG term {
   1938   1.41  christos 		$$ = build(IMAG, $2, NULL);
   1939   1.41  christos 	  }
   1940   1.60  christos 	| T_EXTENSION term {
   1941   1.60  christos 		$$ = $2;
   1942   1.60  christos 	  }
   1943   1.41  christos 	| T_REAL T_LPARN term T_RPARN {
   1944   1.41  christos 		$$ = build(REAL, $3, NULL);
   1945   1.41  christos 	  }
   1946   1.41  christos 	| T_IMAG T_LPARN term T_RPARN {
   1947   1.41  christos 		$$ = build(IMAG, $3, NULL);
   1948   1.41  christos 	  }
   1949   1.94  christos 	| T_BUILTIN_OFFSETOF T_LPARN type_name T_COMMA identifier T_RPARN
   1950   1.94  christos 						    %prec T_BUILTIN_OFFSETOF {
   1951   1.94  christos 		symtyp = FMOS;
   1952  1.114    rillig 		$$ = build_offsetof($3, getsym($5));
   1953   1.94  christos 	  }
   1954    1.1       cgd 	| T_SIZEOF term					%prec T_SIZEOF {
   1955  1.114    rillig 		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
   1956  1.114    rillig 		if ($$ != NULL)
   1957  1.114    rillig 			check_expr_misc($2, 0, 0, 0, 0, 0, 1);
   1958    1.1       cgd 	  }
   1959    1.1       cgd 	| T_SIZEOF T_LPARN type_name T_RPARN		%prec T_SIZEOF {
   1960  1.114    rillig 		$$ = build_sizeof($3);
   1961    1.1       cgd 	  }
   1962   1.44  christos 	| T_ALIGNOF T_LPARN type_name T_RPARN		%prec T_ALIGNOF {
   1963  1.114    rillig 		$$ = build_alignof($3);
   1964   1.44  christos 	  }
   1965    1.1       cgd 	| T_LPARN type_name T_RPARN term		%prec T_UNOP {
   1966    1.1       cgd 		$$ = cast($4, $2);
   1967    1.1       cgd 	  }
   1968  1.113    rillig 	| T_LPARN type_name T_RPARN			%prec T_UNOP {
   1969   1.28  christos 		sym_t *tmp = mktempsym($2);
   1970   1.28  christos 		idecl(tmp, 1, NULL);
   1971   1.28  christos 	  } init_lbrace init_expr_list init_rbrace {
   1972   1.28  christos 		if (!Sflag)
   1973   1.28  christos 			gnuism(319);
   1974   1.28  christos 		$$ = getnnode(initsym, 0);
   1975   1.28  christos 	  }
   1976    1.1       cgd 	;
   1977    1.1       cgd 
   1978    1.1       cgd string:
   1979    1.1       cgd 	  T_STRING {
   1980    1.1       cgd 		$$ = $1;
   1981    1.1       cgd 	  }
   1982    1.1       cgd 	| T_STRING string2 {
   1983  1.114    rillig 		$$ = cat_strings($1, $2);
   1984    1.1       cgd 	  }
   1985    1.1       cgd 	;
   1986    1.1       cgd 
   1987    1.1       cgd string2:
   1988  1.110    rillig 	  T_STRING {
   1989    1.1       cgd 		if (tflag) {
   1990    1.1       cgd 			/* concatenated strings are illegal in traditional C */
   1991    1.1       cgd 			warning(219);
   1992    1.1       cgd 		}
   1993    1.1       cgd 		$$ = $1;
   1994    1.1       cgd 	  }
   1995    1.1       cgd 	| string2 T_STRING {
   1996  1.114    rillig 		$$ = cat_strings($1, $2);
   1997    1.1       cgd 	  }
   1998    1.1       cgd 	;
   1999    1.1       cgd 
   2000    1.1       cgd func_arg_list:
   2001    1.1       cgd 	  expr						%prec T_COMMA {
   2002    1.1       cgd 		$$ = funcarg(NULL, $1);
   2003    1.1       cgd 	  }
   2004    1.1       cgd 	| func_arg_list T_COMMA expr {
   2005    1.1       cgd 		$$ = funcarg($1, $3);
   2006    1.1       cgd 	  }
   2007    1.1       cgd 	;
   2008    1.1       cgd 
   2009    1.1       cgd point_or_arrow:
   2010    1.1       cgd 	  T_STROP {
   2011    1.1       cgd 		symtyp = FMOS;
   2012    1.1       cgd 		$$ = $1;
   2013   1.26  christos 	  }
   2014   1.26  christos 	;
   2015   1.26  christos 
   2016   1.26  christos point:
   2017   1.26  christos 	  T_STROP {
   2018   1.50  christos 		if ($1 != POINT) {
   2019   1.41  christos 			error(249, yytext);
   2020   1.50  christos 		}
   2021    1.1       cgd 	  }
   2022    1.1       cgd 	;
   2023    1.1       cgd 
   2024    1.1       cgd identifier:
   2025    1.1       cgd 	  T_NAME {
   2026    1.1       cgd 		$$ = $1;
   2027  1.117    rillig 		cgram_debug("name '%s'", $$->sb_name);
   2028    1.1       cgd 	  }
   2029    1.1       cgd 	| T_TYPENAME {
   2030    1.1       cgd 		$$ = $1;
   2031  1.117    rillig 		cgram_debug("typename '%s'", $$->sb_name);
   2032    1.1       cgd 	  }
   2033    1.1       cgd 	;
   2034    1.1       cgd 
   2035    1.1       cgd %%
   2036    1.1       cgd 
   2037    1.1       cgd /* ARGSUSED */
   2038    1.1       cgd int
   2039   1.42  dholland yyerror(const char *msg)
   2040    1.1       cgd {
   2041   1.41  christos 	error(249, yytext);
   2042    1.1       cgd 	if (++sytxerr >= 5)
   2043    1.1       cgd 		norecover();
   2044  1.112    rillig 	return 0;
   2045    1.1       cgd }
   2046    1.1       cgd 
   2047   1.38        he static __inline int uq_gt(uint64_t, uint64_t);
   2048   1.38        he static __inline int q_gt(int64_t, int64_t);
   2049   1.10   mycroft 
   2050   1.38        he static __inline int
   2051   1.24   thorpej uq_gt(uint64_t a, uint64_t b)
   2052   1.10   mycroft {
   2053   1.10   mycroft 
   2054  1.112    rillig 	return a > b;
   2055   1.10   mycroft }
   2056   1.10   mycroft 
   2057   1.38        he static __inline int
   2058   1.24   thorpej q_gt(int64_t a, int64_t b)
   2059   1.10   mycroft {
   2060   1.10   mycroft 
   2061  1.112    rillig 	return a > b;
   2062   1.10   mycroft }
   2063   1.10   mycroft 
   2064   1.10   mycroft #define	q_lt(a, b)	q_gt(b, a)
   2065   1.10   mycroft 
   2066    1.1       cgd /*
   2067    1.1       cgd  * Gets a node for a constant and returns the value of this constant
   2068    1.1       cgd  * as integer.
   2069    1.1       cgd  * Is the node not constant or too large for int or of type float,
   2070    1.1       cgd  * a warning will be printed.
   2071    1.1       cgd  *
   2072    1.1       cgd  * toicon() should be used only inside declarations. If it is used in
   2073    1.1       cgd  * expressions, it frees the memory used for the expression.
   2074    1.1       cgd  */
   2075    1.1       cgd static int
   2076   1.27  christos toicon(tnode_t *tn, int required)
   2077    1.1       cgd {
   2078    1.1       cgd 	int	i;
   2079    1.1       cgd 	tspec_t	t;
   2080    1.1       cgd 	val_t	*v;
   2081    1.1       cgd 
   2082   1.27  christos 	v = constant(tn, required);
   2083    1.1       cgd 
   2084    1.1       cgd 	/*
   2085    1.1       cgd 	 * Abstract declarations are used inside expression. To free
   2086    1.1       cgd 	 * the memory would be a fatal error.
   2087   1.70  christos 	 * We don't free blocks that are inside casts because these
   2088   1.70  christos 	 * will be used later to match types.
   2089    1.1       cgd 	 */
   2090   1.70  christos 	if (tn->tn_op != CON && dcs->d_ctx != ABSTRACT)
   2091    1.1       cgd 		tfreeblk();
   2092    1.1       cgd 
   2093    1.1       cgd 	if ((t = v->v_tspec) == FLOAT || t == DOUBLE || t == LDOUBLE) {
   2094    1.1       cgd 		i = (int)v->v_ldbl;
   2095    1.1       cgd 		/* integral constant expression expected */
   2096    1.1       cgd 		error(55);
   2097    1.1       cgd 	} else {
   2098    1.1       cgd 		i = (int)v->v_quad;
   2099  1.107    rillig 		if (tspec_is_uint(t)) {
   2100   1.24   thorpej 			if (uq_gt((uint64_t)v->v_quad,
   2101   1.54  christos 				  (uint64_t)TARG_INT_MAX)) {
   2102    1.1       cgd 				/* integral constant too large */
   2103    1.1       cgd 				warning(56);
   2104    1.1       cgd 			}
   2105    1.1       cgd 		} else {
   2106   1.54  christos 			if (q_gt(v->v_quad, (int64_t)TARG_INT_MAX) ||
   2107   1.54  christos 			    q_lt(v->v_quad, (int64_t)TARG_INT_MIN)) {
   2108    1.1       cgd 				/* integral constant too large */
   2109    1.1       cgd 				warning(56);
   2110    1.1       cgd 			}
   2111    1.1       cgd 		}
   2112    1.1       cgd 	}
   2113    1.1       cgd 	free(v);
   2114  1.112    rillig 	return i;
   2115    1.1       cgd }
   2116    1.1       cgd 
   2117    1.1       cgd static void
   2118   1.42  dholland idecl(sym_t *decl, int initflg, sbuf_t *renaming)
   2119    1.1       cgd {
   2120   1.11       cgd 	char *s;
   2121   1.11       cgd 
   2122    1.1       cgd 	initerr = 0;
   2123    1.1       cgd 	initsym = decl;
   2124    1.1       cgd 
   2125    1.3       jpo 	switch (dcs->d_ctx) {
   2126    1.1       cgd 	case EXTERN:
   2127   1.42  dholland 		if (renaming != NULL) {
   2128   1.11       cgd 			if (decl->s_rename != NULL)
   2129   1.72  christos 				LERROR("idecl(rename)");
   2130   1.11       cgd 
   2131   1.42  dholland 			s = getlblk(1, renaming->sb_len + 1);
   2132   1.42  dholland 	                (void)memcpy(s, renaming->sb_name, renaming->sb_len + 1);
   2133   1.11       cgd 			decl->s_rename = s;
   2134   1.42  dholland 			freeyyv(&renaming, T_NAME);
   2135   1.11       cgd 		}
   2136    1.1       cgd 		decl1ext(decl, initflg);
   2137    1.1       cgd 		break;
   2138    1.1       cgd 	case ARG:
   2139   1.42  dholland 		if (renaming != NULL) {
   2140   1.11       cgd 			/* symbol renaming can't be used on function arguments */
   2141   1.11       cgd 			error(310);
   2142   1.42  dholland 			freeyyv(&renaming, T_NAME);
   2143   1.11       cgd 			break;
   2144   1.11       cgd 		}
   2145    1.1       cgd 		(void)decl1arg(decl, initflg);
   2146    1.1       cgd 		break;
   2147    1.1       cgd 	case AUTO:
   2148   1.42  dholland 		if (renaming != NULL) {
   2149   1.11       cgd 			/* symbol renaming can't be used on automatic variables */
   2150   1.11       cgd 			error(311);
   2151   1.42  dholland 			freeyyv(&renaming, T_NAME);
   2152   1.11       cgd 			break;
   2153   1.11       cgd 		}
   2154    1.1       cgd 		decl1loc(decl, initflg);
   2155    1.1       cgd 		break;
   2156    1.1       cgd 	default:
   2157   1.72  christos 		LERROR("idecl(%d)", dcs->d_ctx);
   2158    1.1       cgd 	}
   2159    1.1       cgd 
   2160    1.1       cgd 	if (initflg && !initerr)
   2161  1.115    rillig 		initstack_init();
   2162    1.6       jpo }
   2163    1.6       jpo 
   2164    1.6       jpo /*
   2165    1.6       jpo  * Discard all input tokens up to and including the next
   2166    1.6       jpo  * unmatched right paren
   2167    1.6       jpo  */
   2168   1.22   thorpej static void
   2169   1.20     lukem ignuptorp(void)
   2170    1.6       jpo {
   2171    1.6       jpo 	int	level;
   2172    1.6       jpo 
   2173    1.6       jpo 	if (yychar < 0)
   2174    1.6       jpo 		yychar = yylex();
   2175    1.6       jpo 	freeyyv(&yylval, yychar);
   2176    1.6       jpo 
   2177    1.6       jpo 	level = 1;
   2178    1.6       jpo 	while (yychar != T_RPARN || --level > 0) {
   2179    1.6       jpo 		if (yychar == T_LPARN) {
   2180    1.6       jpo 			level++;
   2181    1.6       jpo 		} else if (yychar <= 0) {
   2182    1.6       jpo 			break;
   2183    1.6       jpo 		}
   2184    1.6       jpo 		freeyyv(&yylval, yychar = yylex());
   2185    1.6       jpo 	}
   2186    1.6       jpo 
   2187    1.6       jpo 	yyclearin;
   2188    1.1       cgd }
   2189   1.75  christos 
   2190   1.75  christos static	sym_t *
   2191   1.75  christos symbolrename(sym_t *s, sbuf_t *sb)
   2192   1.75  christos {
   2193   1.75  christos 	if (sb)
   2194   1.75  christos 		s->s_rename = sb->sb_name;
   2195   1.75  christos 	return s;
   2196   1.75  christos }
   2197