Sat Jul 10 04:47:25 2021 UTC ()
lint: merge duplicate code in declmods and declmod

No functional change.


(rillig)
diff -r1.278 -r1.279 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.278 -r1.279 src/usr.bin/xlint/lint1/cgram.y (switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/10 04:25:47 1.278
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 04:47:25 1.279
@@ -1,1567 +1,1566 @@ @@ -1,1567 +1,1566 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution. 16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software 17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement: 18 * must display the following acknowledgement:
19 * This product includes software developed by Jochen Pohl for 19 * This product includes software developed by Jochen Pohl for
20 * The NetBSD Project. 20 * The NetBSD Project.
21 * 4. The name of the author may not be used to endorse or promote products 21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission. 22 * derived from this software without specific prior written permission.
23 * 23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.279 2021/07/10 04:47:25 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
52 */ 52 */
53int block_level; 53int block_level;
54 54
55/* 55/*
56 * level for memory allocation. Normally the same as block_level. 56 * level for memory allocation. Normally the same as block_level.
57 * An exception is the declaration of arguments in prototypes. Memory 57 * An exception is the declaration of arguments in prototypes. Memory
58 * for these can't be freed after the declaration, but symbols must 58 * for these can't be freed after the declaration, but symbols must
59 * be removed from the symbol table after the declaration. 59 * be removed from the symbol table after the declaration.
60 */ 60 */
61int mem_block_level; 61int mem_block_level;
62 62
63/* 63/*
64 * Save the no-warns state and restore it to avoid the problem where 64 * Save the no-warns state and restore it to avoid the problem where
65 * if (expr) { stmt } / * NOLINT * / stmt; 65 * if (expr) { stmt } / * NOLINT * / stmt;
66 */ 66 */
67static int olwarn = LWARN_BAD; 67static int olwarn = LWARN_BAD;
68 68
69static void cgram_declare(sym_t *, bool, sbuf_t *); 69static void cgram_declare(sym_t *, bool, sbuf_t *);
70static void ignore_up_to_rparen(void); 70static void ignore_up_to_rparen(void);
71static sym_t *symbolrename(sym_t *, sbuf_t *); 71static sym_t *symbolrename(sym_t *, sbuf_t *);
72 72
73 73
74#ifdef DEBUG 74#ifdef DEBUG
75static void 75static void
76CLEAR_WARN_FLAGS(const char *file, size_t line) 76CLEAR_WARN_FLAGS(const char *file, size_t line)
77{ 77{
78 printf("%s:%d: %s:%zu: clearing flags\n", 78 printf("%s:%d: %s:%zu: clearing flags\n",
79 curr_pos.p_file, curr_pos.p_line, file, line); 79 curr_pos.p_file, curr_pos.p_line, file, line);
80 clear_warn_flags(); 80 clear_warn_flags();
81 olwarn = LWARN_BAD; 81 olwarn = LWARN_BAD;
82} 82}
83 83
84static void 84static void
85SAVE_WARN_FLAGS(const char *file, size_t line) 85SAVE_WARN_FLAGS(const char *file, size_t line)
86{ 86{
87 lint_assert(olwarn == LWARN_BAD); 87 lint_assert(olwarn == LWARN_BAD);
88 printf("%s:%d: %s:%zu: saving flags %d\n", 88 printf("%s:%d: %s:%zu: saving flags %d\n",
89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
90 olwarn = lwarn; 90 olwarn = lwarn;
91} 91}
92 92
93static void 93static void
94RESTORE_WARN_FLAGS(const char *file, size_t line) 94RESTORE_WARN_FLAGS(const char *file, size_t line)
95{ 95{
96 if (olwarn != LWARN_BAD) { 96 if (olwarn != LWARN_BAD) {
97 lwarn = olwarn; 97 lwarn = olwarn;
98 printf("%s:%d: %s:%zu: restoring flags %d\n", 98 printf("%s:%d: %s:%zu: restoring flags %d\n",
99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
100 olwarn = LWARN_BAD; 100 olwarn = LWARN_BAD;
101 } else 101 } else
102 CLEAR_WARN_FLAGS(file, line); 102 CLEAR_WARN_FLAGS(file, line);
103} 103}
104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args) 104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
105#else 105#else
106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD 106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD
107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn 107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn
108#define RESTORE_WARN_FLAGS(f, l) \ 108#define RESTORE_WARN_FLAGS(f, l) \
109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn)) 109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
110#define cgram_debug(fmt, args...) do { } while (false) 110#define cgram_debug(fmt, args...) do { } while (false)
111#endif 111#endif
112 112
113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__) 113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__)
114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__) 114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__)
115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__) 115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__)
116 116
117/* unbind the anonymous struct members from the struct */ 117/* unbind the anonymous struct members from the struct */
118static void 118static void
119anonymize(sym_t *s) 119anonymize(sym_t *s)
120{ 120{
121 for ( ; s != NULL; s = s->s_next) 121 for ( ; s != NULL; s = s->s_next)
122 s->s_styp = NULL; 122 s->s_styp = NULL;
123} 123}
124%} 124%}
125 125
126%expect 150 126%expect 150
127 127
128%union { 128%union {
129 val_t *y_val; 129 val_t *y_val;
130 sbuf_t *y_sb; 130 sbuf_t *y_sb;
131 sym_t *y_sym; 131 sym_t *y_sym;
132 op_t y_op; 132 op_t y_op;
133 scl_t y_scl; 133 scl_t y_scl;
134 tspec_t y_tspec; 134 tspec_t y_tspec;
135 tqual_t y_tqual; 135 tqual_t y_tqual;
136 type_t *y_type; 136 type_t *y_type;
137 tnode_t *y_tnode; 137 tnode_t *y_tnode;
138 range_t y_range; 138 range_t y_range;
139 strg_t *y_string; 139 strg_t *y_string;
140 qual_ptr *y_qual_ptr; 140 qual_ptr *y_qual_ptr;
141 bool y_seen_statement; 141 bool y_seen_statement;
142 struct generic_association *y_generic; 142 struct generic_association *y_generic;
143}; 143};
144 144
145%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN 145%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
146%token T_POINT T_ARROW 146%token T_POINT T_ARROW
147%token <y_op> T_UNARY 147%token <y_op> T_UNARY
148%token <y_op> T_INCDEC 148%token <y_op> T_INCDEC
149%token T_SIZEOF 149%token T_SIZEOF
150%token T_BUILTIN_OFFSETOF 150%token T_BUILTIN_OFFSETOF
151%token T_TYPEOF 151%token T_TYPEOF
152%token T_EXTENSION 152%token T_EXTENSION
153%token T_ALIGNAS 153%token T_ALIGNAS
154%token T_ALIGNOF 154%token T_ALIGNOF
155%token T_ASTERISK 155%token T_ASTERISK
156%token <y_op> T_MULTIPLICATIVE 156%token <y_op> T_MULTIPLICATIVE
157%token <y_op> T_ADDITIVE 157%token <y_op> T_ADDITIVE
158%token <y_op> T_SHIFT 158%token <y_op> T_SHIFT
159%token <y_op> T_RELATIONAL 159%token <y_op> T_RELATIONAL
160%token <y_op> T_EQUALITY 160%token <y_op> T_EQUALITY
161%token T_AMPER 161%token T_AMPER
162%token T_BITXOR 162%token T_BITXOR
163%token T_BITOR 163%token T_BITOR
164%token T_LOGAND 164%token T_LOGAND
165%token T_LOGOR 165%token T_LOGOR
166%token T_QUEST 166%token T_QUEST
167%token T_COLON 167%token T_COLON
168%token T_ASSIGN 168%token T_ASSIGN
169%token <y_op> T_OPASSIGN 169%token <y_op> T_OPASSIGN
170%token T_COMMA 170%token T_COMMA
171%token T_SEMI 171%token T_SEMI
172%token T_ELLIPSIS 172%token T_ELLIPSIS
173%token T_REAL 173%token T_REAL
174%token T_IMAG 174%token T_IMAG
175%token T_GENERIC 175%token T_GENERIC
176%token T_NORETURN 176%token T_NORETURN
177 177
178/* storage classes (extern, static, auto, register and typedef) */ 178/* storage classes (extern, static, auto, register and typedef) */
179%token <y_scl> T_SCLASS 179%token <y_scl> T_SCLASS
180 180
181/* 181/*
182 * predefined type keywords (char, int, short, long, unsigned, signed, 182 * predefined type keywords (char, int, short, long, unsigned, signed,
183 * float, double, void); see T_TYPENAME 183 * float, double, void); see T_TYPENAME
184 */ 184 */
185%token <y_tspec> T_TYPE 185%token <y_tspec> T_TYPE
186 186
187/* qualifiers (const, volatile, restrict, _Thread_local) */ 187/* qualifiers (const, volatile, restrict, _Thread_local) */
188%token <y_tqual> T_QUAL 188%token <y_tqual> T_QUAL
189 189
190/* struct or union */ 190/* struct or union */
191%token <y_tspec> T_STRUCT_OR_UNION 191%token <y_tspec> T_STRUCT_OR_UNION
192 192
193/* remaining keywords */ 193/* remaining keywords */
194%token T_ASM 194%token T_ASM
195%token T_BREAK 195%token T_BREAK
196%token T_CASE 196%token T_CASE
197%token T_CONTINUE 197%token T_CONTINUE
198%token T_DEFAULT 198%token T_DEFAULT
199%token T_DO 199%token T_DO
200%token T_ELSE 200%token T_ELSE
201%token T_ENUM 201%token T_ENUM
202%token T_FOR 202%token T_FOR
203%token T_GOTO 203%token T_GOTO
204%token T_IF 204%token T_IF
205%token T_PACKED 205%token T_PACKED
206%token T_RETURN 206%token T_RETURN
207%token T_SWITCH 207%token T_SWITCH
208%token T_SYMBOLRENAME 208%token T_SYMBOLRENAME
209%token T_WHILE 209%token T_WHILE
210 210
211%token T_ATTRIBUTE 211%token T_ATTRIBUTE
212%token T_AT_ALIAS 212%token T_AT_ALIAS
213%token T_AT_ALIGNED 213%token T_AT_ALIGNED
214%token T_AT_ALLOC_SIZE 214%token T_AT_ALLOC_SIZE
215%token T_AT_ALWAYS_INLINE 215%token T_AT_ALWAYS_INLINE
216%token T_AT_BOUNDED 216%token T_AT_BOUNDED
217%token T_AT_BUFFER 217%token T_AT_BUFFER
218%token T_AT_COLD 218%token T_AT_COLD
219%token T_AT_COMMON 219%token T_AT_COMMON
220%token T_AT_CONSTRUCTOR 220%token T_AT_CONSTRUCTOR
221%token T_AT_DEPRECATED 221%token T_AT_DEPRECATED
222%token T_AT_DESTRUCTOR 222%token T_AT_DESTRUCTOR
223%token T_AT_FALLTHROUGH 223%token T_AT_FALLTHROUGH
224%token T_AT_FORMAT 224%token T_AT_FORMAT
225%token T_AT_FORMAT_ARG 225%token T_AT_FORMAT_ARG
226%token T_AT_FORMAT_GNU_PRINTF 226%token T_AT_FORMAT_GNU_PRINTF
227%token T_AT_FORMAT_PRINTF 227%token T_AT_FORMAT_PRINTF
228%token T_AT_FORMAT_SCANF 228%token T_AT_FORMAT_SCANF
229%token T_AT_FORMAT_STRFMON 229%token T_AT_FORMAT_STRFMON
230%token T_AT_FORMAT_STRFTIME 230%token T_AT_FORMAT_STRFTIME
231%token T_AT_FORMAT_SYSLOG 231%token T_AT_FORMAT_SYSLOG
232%token T_AT_GNU_INLINE 232%token T_AT_GNU_INLINE
233%token T_AT_MALLOC 233%token T_AT_MALLOC
234%token T_AT_MAY_ALIAS 234%token T_AT_MAY_ALIAS
235%token T_AT_MINBYTES 235%token T_AT_MINBYTES
236%token T_AT_MODE 236%token T_AT_MODE
237%token T_AT_NOINLINE 237%token T_AT_NOINLINE
238%token T_AT_NONNULL 238%token T_AT_NONNULL
239%token T_AT_NONSTRING 239%token T_AT_NONSTRING
240%token T_AT_NORETURN 240%token T_AT_NORETURN
241%token T_AT_NOTHROW 241%token T_AT_NOTHROW
242%token T_AT_NO_INSTRUMENT_FUNCTION 242%token T_AT_NO_INSTRUMENT_FUNCTION
243%token T_AT_OPTIMIZE 243%token T_AT_OPTIMIZE
244%token T_AT_PACKED 244%token T_AT_PACKED
245%token T_AT_PCS 245%token T_AT_PCS
246%token T_AT_PURE 246%token T_AT_PURE
247%token T_AT_RETURNS_TWICE 247%token T_AT_RETURNS_TWICE
248%token T_AT_SECTION 248%token T_AT_SECTION
249%token T_AT_SENTINEL 249%token T_AT_SENTINEL
250%token T_AT_STRING 250%token T_AT_STRING
251%token T_AT_TLS_MODEL 251%token T_AT_TLS_MODEL
252%token T_AT_TUNION 252%token T_AT_TUNION
253%token T_AT_UNUSED 253%token T_AT_UNUSED
254%token T_AT_USED 254%token T_AT_USED
255%token T_AT_VISIBILITY 255%token T_AT_VISIBILITY
256%token T_AT_WARN_UNUSED_RESULT 256%token T_AT_WARN_UNUSED_RESULT
257%token T_AT_WEAK 257%token T_AT_WEAK
258 258
259%left T_COMMA 259%left T_COMMA
260%right T_ASSIGN T_OPASSIGN 260%right T_ASSIGN T_OPASSIGN
261%right T_QUEST T_COLON 261%right T_QUEST T_COLON
262%left T_LOGOR 262%left T_LOGOR
263%left T_LOGAND 263%left T_LOGAND
264%left T_BITOR 264%left T_BITOR
265%left T_BITXOR 265%left T_BITXOR
266%left T_AMPER 266%left T_AMPER
267%left T_EQUALITY 267%left T_EQUALITY
268%left T_RELATIONAL 268%left T_RELATIONAL
269%left T_SHIFT 269%left T_SHIFT
270%left T_ADDITIVE 270%left T_ADDITIVE
271%left T_ASTERISK T_MULTIPLICATIVE 271%left T_ASTERISK T_MULTIPLICATIVE
272%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG 272%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG
273%left T_LPAREN T_LBRACK T_POINT T_ARROW 273%left T_LPAREN T_LBRACK T_POINT T_ARROW
274 274
275%token <y_sb> T_NAME 275%token <y_sb> T_NAME
276%token <y_sb> T_TYPENAME 276%token <y_sb> T_TYPENAME
277%token <y_val> T_CON 277%token <y_val> T_CON
278%token <y_string> T_STRING 278%token <y_string> T_STRING
279 279
280%type <y_sym> func_decl 280%type <y_sym> func_decl
281%type <y_sym> notype_decl 281%type <y_sym> notype_decl
282%type <y_sym> type_decl 282%type <y_sym> type_decl
283%type <y_type> typespec 283%type <y_type> typespec
284%type <y_type> clrtyp_typespec 284%type <y_type> clrtyp_typespec
285%type <y_type> notype_typespec 285%type <y_type> notype_typespec
286%type <y_type> struct_spec 286%type <y_type> struct_spec
287%type <y_type> enum_spec 287%type <y_type> enum_spec
288%type <y_sym> struct_tag 288%type <y_sym> struct_tag
289%type <y_sym> enum_tag 289%type <y_sym> enum_tag
290%type <y_tspec> struct 290%type <y_tspec> struct
291%type <y_sym> struct_declaration 291%type <y_sym> struct_declaration
292%type <y_sb> identifier 292%type <y_sb> identifier
293%type <y_sym> member_declaration_list_semi 293%type <y_sym> member_declaration_list_semi
294%type <y_sym> member_declaration_list 294%type <y_sym> member_declaration_list
295%type <y_sym> member_declaration 295%type <y_sym> member_declaration
296%type <y_sym> notype_member_decls 296%type <y_sym> notype_member_decls
297%type <y_sym> type_member_decls 297%type <y_sym> type_member_decls
298%type <y_sym> notype_member_decl 298%type <y_sym> notype_member_decl
299%type <y_sym> type_member_decl 299%type <y_sym> type_member_decl
300%type <y_tnode> constant_expr 300%type <y_tnode> constant_expr
301%type <y_tnode> array_size 301%type <y_tnode> array_size
302%type <y_sym> enum_declaration 302%type <y_sym> enum_declaration
303%type <y_sym> enumerator_list 303%type <y_sym> enumerator_list
304%type <y_sym> enumerator 304%type <y_sym> enumerator
305%type <y_sym> enumeration_constant 305%type <y_sym> enumeration_constant
306%type <y_sym> notype_direct_decl 306%type <y_sym> notype_direct_decl
307%type <y_sym> type_direct_decl 307%type <y_sym> type_direct_decl
308%type <y_qual_ptr> pointer 308%type <y_qual_ptr> pointer
309%type <y_qual_ptr> asterisk 309%type <y_qual_ptr> asterisk
310%type <y_sym> type_param_decl 310%type <y_sym> type_param_decl
311%type <y_sym> param_list 311%type <y_sym> param_list
312%type <y_sym> abstract_decl_param_list 312%type <y_sym> abstract_decl_param_list
313%type <y_sym> direct_param_decl 313%type <y_sym> direct_param_decl
314%type <y_sym> notype_param_decl 314%type <y_sym> notype_param_decl
315%type <y_sym> direct_notype_param_decl 315%type <y_sym> direct_notype_param_decl
316%type <y_qual_ptr> type_qualifier_list_opt 316%type <y_qual_ptr> type_qualifier_list_opt
317%type <y_qual_ptr> type_qualifier_list 317%type <y_qual_ptr> type_qualifier_list
318%type <y_qual_ptr> type_qualifier 318%type <y_qual_ptr> type_qualifier
319%type <y_sym> identifier_list 319%type <y_sym> identifier_list
320%type <y_sym> abstract_declarator 320%type <y_sym> abstract_declarator
321%type <y_sym> direct_abstract_declarator 321%type <y_sym> direct_abstract_declarator
322%type <y_sym> vararg_parameter_type_list 322%type <y_sym> vararg_parameter_type_list
323%type <y_sym> parameter_type_list 323%type <y_sym> parameter_type_list
324%type <y_sym> parameter_declaration 324%type <y_sym> parameter_declaration
325%type <y_tnode> expr 325%type <y_tnode> expr
326%type <y_tnode> assignment_expression 326%type <y_tnode> assignment_expression
327%type <y_tnode> gcc_statement_expr_list 327%type <y_tnode> gcc_statement_expr_list
328%type <y_tnode> gcc_statement_expr_item 328%type <y_tnode> gcc_statement_expr_item
329%type <y_tnode> term 329%type <y_tnode> term
330%type <y_tnode> generic_selection 330%type <y_tnode> generic_selection
331%type <y_tnode> func_arg_list 331%type <y_tnode> func_arg_list
332%type <y_op> point_or_arrow 332%type <y_op> point_or_arrow
333%type <y_type> type_name 333%type <y_type> type_name
334%type <y_sym> abstract_declaration 334%type <y_sym> abstract_declaration
335%type <y_tnode> do_while_expr 335%type <y_tnode> do_while_expr
336%type <y_tnode> expr_opt 336%type <y_tnode> expr_opt
337%type <y_string> string 337%type <y_string> string
338%type <y_string> string2 338%type <y_string> string2
339%type <y_sb> asm_or_symbolrename_opt 339%type <y_sb> asm_or_symbolrename_opt
340%type <y_range> range 340%type <y_range> range
341%type <y_seen_statement> block_item_list 341%type <y_seen_statement> block_item_list
342%type <y_seen_statement> block_item 342%type <y_seen_statement> block_item
343%type <y_generic> generic_assoc_list 343%type <y_generic> generic_assoc_list
344%type <y_generic> generic_association 344%type <y_generic> generic_association
345 345
346%% 346%%
347 347
348program: 348program:
349 /* empty */ { 349 /* empty */ {
350 if (sflag) { 350 if (sflag) {
351 /* empty translation unit */ 351 /* empty translation unit */
352 error(272); 352 error(272);
353 } else if (!tflag) { 353 } else if (!tflag) {
354 /* empty translation unit */ 354 /* empty translation unit */
355 warning(272); 355 warning(272);
356 } 356 }
357 } 357 }
358 | translation_unit 358 | translation_unit
359 ; 359 ;
360 360
361translation_unit: /* C99 6.9 */ 361translation_unit: /* C99 6.9 */
362 external_declaration 362 external_declaration
363 | translation_unit external_declaration 363 | translation_unit external_declaration
364 ; 364 ;
365 365
366external_declaration: /* C99 6.9 */ 366external_declaration: /* C99 6.9 */
367 asm_statement 367 asm_statement
368 | function_definition { 368 | function_definition {
369 global_clean_up_decl(false); 369 global_clean_up_decl(false);
370 clear_warning_flags(); 370 clear_warning_flags();
371 } 371 }
372 | top_level_declaration { 372 | top_level_declaration {
373 global_clean_up_decl(false); 373 global_clean_up_decl(false);
374 clear_warning_flags(); 374 clear_warning_flags();
375 } 375 }
376 ; 376 ;
377 377
378/* 378/*
379 * On the top level, lint allows several forms of declarations that it doesn't 379 * On the top level, lint allows several forms of declarations that it doesn't
380 * allow in functions. For example, a single ';' is an empty declaration and 380 * allow in functions. For example, a single ';' is an empty declaration and
381 * is supported by some compilers, but in a function it would be an empty 381 * is supported by some compilers, but in a function it would be an empty
382 * statement, not a declaration. This makes a difference in C90 mode, where 382 * statement, not a declaration. This makes a difference in C90 mode, where
383 * a statement must not be followed by a declaration. 383 * a statement must not be followed by a declaration.
384 * 384 *
385 * See 'declaration' for all other declarations. 385 * See 'declaration' for all other declarations.
386 */ 386 */
387top_level_declaration: /* C99 6.9 calls this 'declaration' */ 387top_level_declaration: /* C99 6.9 calls this 'declaration' */
388 T_SEMI { 388 T_SEMI {
389 if (sflag) { 389 if (sflag) {
390 /* empty declaration */ 390 /* empty declaration */
391 error(0); 391 error(0);
392 } else if (!tflag) { 392 } else if (!tflag) {
393 /* empty declaration */ 393 /* empty declaration */
394 warning(0); 394 warning(0);
395 } 395 }
396 } 396 }
397 | clrtyp deftyp notype_init_decls T_SEMI { 397 | clrtyp deftyp notype_init_decls T_SEMI {
398 if (sflag) { 398 if (sflag) {
399 /* old style declaration; add 'int' */ 399 /* old style declaration; add 'int' */
400 error(1); 400 error(1);
401 } else if (!tflag) { 401 } else if (!tflag) {
402 /* old style declaration; add 'int' */ 402 /* old style declaration; add 'int' */
403 warning(1); 403 warning(1);
404 } 404 }
405 } 405 }
406 | declaration_noerror 406 | declaration_noerror
407 | error T_SEMI { 407 | error T_SEMI {
408 global_clean_up(); 408 global_clean_up();
409 } 409 }
410 | error T_RBRACE { 410 | error T_RBRACE {
411 global_clean_up(); 411 global_clean_up();
412 } 412 }
413 ; 413 ;
414 414
415function_definition: /* C99 6.9.1 */ 415function_definition: /* C99 6.9.1 */
416 func_decl { 416 func_decl {
417 if ($1->s_type->t_tspec != FUNC) { 417 if ($1->s_type->t_tspec != FUNC) {
418 /* syntax error '%s' */ 418 /* syntax error '%s' */
419 error(249, yytext); 419 error(249, yytext);
420 YYERROR; 420 YYERROR;
421 } 421 }
422 if ($1->s_type->t_typedef) { 422 if ($1->s_type->t_typedef) {
423 /* ()-less function definition */ 423 /* ()-less function definition */
424 error(64); 424 error(64);
425 YYERROR; 425 YYERROR;
426 } 426 }
427 funcdef($1); 427 funcdef($1);
428 block_level++; 428 block_level++;
429 begin_declaration_level(ARG); 429 begin_declaration_level(ARG);
430 if (lwarn == LWARN_NONE) 430 if (lwarn == LWARN_NONE)
431 $1->s_used = true; 431 $1->s_used = true;
432 } arg_declaration_list_opt { 432 } arg_declaration_list_opt {
433 end_declaration_level(); 433 end_declaration_level();
434 block_level--; 434 block_level--;
435 check_func_lint_directives(); 435 check_func_lint_directives();
436 check_func_old_style_arguments(); 436 check_func_old_style_arguments();
437 begin_control_statement(CS_FUNCTION_BODY); 437 begin_control_statement(CS_FUNCTION_BODY);
438 } compound_statement { 438 } compound_statement {
439 funcend(); 439 funcend();
440 end_control_statement(CS_FUNCTION_BODY); 440 end_control_statement(CS_FUNCTION_BODY);
441 } 441 }
442 ; 442 ;
443 443
444func_decl: 444func_decl:
445 clrtyp deftyp notype_decl { 445 clrtyp deftyp notype_decl {
446 $$ = $3; 446 $$ = $3;
447 } 447 }
448 | declmods deftyp notype_decl { 448 | declmods deftyp notype_decl {
449 $$ = $3; 449 $$ = $3;
450 } 450 }
451 | declaration_specifiers deftyp type_decl { 451 | declaration_specifiers deftyp type_decl {
452 $$ = $3; 452 $$ = $3;
453 } 453 }
454 ; 454 ;
455 455
456arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ 456arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */
457 /* empty */ 457 /* empty */
458 | arg_declaration_list 458 | arg_declaration_list
459 ; 459 ;
460 460
461arg_declaration_list: /* C99 6.9.1p13 example 1 */ 461arg_declaration_list: /* C99 6.9.1p13 example 1 */
462 arg_declaration 462 arg_declaration
463 | arg_declaration_list arg_declaration 463 | arg_declaration_list arg_declaration
464 /* XXX or better "arg_declaration error" ? */ 464 /* XXX or better "arg_declaration error" ? */
465 | error 465 | error
466 ; 466 ;
467 467
468/* 468/*
469 * "arg_declaration" is separated from "declaration" because it 469 * "arg_declaration" is separated from "declaration" because it
470 * needs other error handling. 470 * needs other error handling.
471 */ 471 */
472arg_declaration: 472arg_declaration:
473 declmods deftyp T_SEMI { 473 declmods deftyp T_SEMI {
474 /* empty declaration */ 474 /* empty declaration */
475 warning(2); 475 warning(2);
476 } 476 }
477 | declmods deftyp notype_init_decls T_SEMI 477 | declmods deftyp notype_init_decls T_SEMI
478 | declaration_specifiers deftyp T_SEMI { 478 | declaration_specifiers deftyp T_SEMI {
479 if (!dcs->d_nonempty_decl) { 479 if (!dcs->d_nonempty_decl) {
480 /* empty declaration */ 480 /* empty declaration */
481 warning(2); 481 warning(2);
482 } else { 482 } else {
483 /* '%s' declared in argument declaration list */ 483 /* '%s' declared in argument declaration list */
484 warning(3, type_name(dcs->d_type)); 484 warning(3, type_name(dcs->d_type));
485 } 485 }
486 } 486 }
487 | declaration_specifiers deftyp type_init_decls T_SEMI { 487 | declaration_specifiers deftyp type_init_decls T_SEMI {
488 if (dcs->d_nonempty_decl) { 488 if (dcs->d_nonempty_decl) {
489 /* '%s' declared in argument declaration list */ 489 /* '%s' declared in argument declaration list */
490 warning(3, type_name(dcs->d_type)); 490 warning(3, type_name(dcs->d_type));
491 } 491 }
492 } 492 }
493 | declmods error 493 | declmods error
494 | declaration_specifiers error 494 | declaration_specifiers error
495 ; 495 ;
496 496
497declaration: /* C99 6.7 */ 497declaration: /* C99 6.7 */
498 declaration_noerror 498 declaration_noerror
499 | error T_SEMI 499 | error T_SEMI
500 ; 500 ;
501 501
502declaration_noerror: /* see C99 6.7 'declaration' */ 502declaration_noerror: /* see C99 6.7 'declaration' */
503 declmods deftyp T_SEMI { 503 declmods deftyp T_SEMI {
504 if (dcs->d_scl == TYPEDEF) { 504 if (dcs->d_scl == TYPEDEF) {
505 /* typedef declares no type name */ 505 /* typedef declares no type name */
506 warning(72); 506 warning(72);
507 } else { 507 } else {
508 /* empty declaration */ 508 /* empty declaration */
509 warning(2); 509 warning(2);
510 } 510 }
511 } 511 }
512 | declmods deftyp notype_init_decls T_SEMI 512 | declmods deftyp notype_init_decls T_SEMI
513 | declaration_specifiers deftyp T_SEMI { 513 | declaration_specifiers deftyp T_SEMI {
514 if (dcs->d_scl == TYPEDEF) { 514 if (dcs->d_scl == TYPEDEF) {
515 /* typedef declares no type name */ 515 /* typedef declares no type name */
516 warning(72); 516 warning(72);
517 } else if (!dcs->d_nonempty_decl) { 517 } else if (!dcs->d_nonempty_decl) {
518 /* empty declaration */ 518 /* empty declaration */
519 warning(2); 519 warning(2);
520 } 520 }
521 } 521 }
522 | declaration_specifiers deftyp type_init_decls T_SEMI 522 | declaration_specifiers deftyp type_init_decls T_SEMI
523 ; 523 ;
524 524
525clrtyp: 525clrtyp:
526 /* empty */ { 526 /* empty */ {
527 clrtyp(); 527 clrtyp();
528 } 528 }
529 ; 529 ;
530 530
531deftyp: 531deftyp:
532 /* empty */ { 532 /* empty */ {
533 deftyp(); 533 deftyp();
534 } 534 }
535 ; 535 ;
536 536
537declaration_specifiers: /* C99 6.7 */ 537declaration_specifiers: /* C99 6.7 */
538 clrtyp_typespec { 538 clrtyp_typespec {
539 add_type($1); 539 add_type($1);
540 } 540 }
541 | declmods typespec { 541 | declmods typespec {
542 add_type($2); 542 add_type($2);
543 } 543 }
544 | type_attribute declaration_specifiers 544 | type_attribute declaration_specifiers
545 | declaration_specifiers declmod 545 | declaration_specifiers declmod
546 | declaration_specifiers notype_typespec { 546 | declaration_specifiers notype_typespec {
547 add_type($2); 547 add_type($2);
548 } 548 }
549 ; 549 ;
550 550
551declmods: 551declmods:
552 clrtyp T_QUAL { 552 clrtyp qualifier_or_storage_class
553 add_qualifier($2); 
554 } 
555 | clrtyp T_SCLASS { 
556 add_storage_class($2); 
557 } 
558 | declmods declmod 553 | declmods declmod
559 ; 554 ;
560 555
561declmod: 556declmod:
 557 qualifier_or_storage_class
 558 | type_attribute
 559 ;
 560
 561qualifier_or_storage_class:
562 T_QUAL { 562 T_QUAL {
563 add_qualifier($1); 563 add_qualifier($1);
564 } 564 }
565 | T_SCLASS { 565 | T_SCLASS {
566 add_storage_class($1); 566 add_storage_class($1);
567 } 567 }
568 | type_attribute 
569 ; 568 ;
570 569
571clrtyp_typespec: 570clrtyp_typespec:
572 clrtyp notype_typespec { 571 clrtyp notype_typespec {
573 $$ = $2; 572 $$ = $2;
574 } 573 }
575 | T_TYPENAME clrtyp { 574 | T_TYPENAME clrtyp {
576 $$ = getsym($1)->s_type; 575 $$ = getsym($1)->s_type;
577 } 576 }
578 ; 577 ;
579 578
580typespec: 579typespec:
581 notype_typespec 580 notype_typespec
582 | T_TYPENAME { 581 | T_TYPENAME {
583 $$ = getsym($1)->s_type; 582 $$ = getsym($1)->s_type;
584 } 583 }
585 ; 584 ;
586 585
587notype_typespec: 586notype_typespec:
588 T_TYPE { 587 T_TYPE {
589 $$ = gettyp($1); 588 $$ = gettyp($1);
590 } 589 }
591 | T_TYPEOF term { 590 | T_TYPEOF term {
592 $$ = $2->tn_type; 591 $$ = $2->tn_type;
593 } 592 }
594 | struct_spec { 593 | struct_spec {
595 end_declaration_level(); 594 end_declaration_level();
596 $$ = $1; 595 $$ = $1;
597 } 596 }
598 | enum_spec { 597 | enum_spec {
599 end_declaration_level(); 598 end_declaration_level();
600 $$ = $1; 599 $$ = $1;
601 } 600 }
602 ; 601 ;
603 602
604struct_spec: 603struct_spec:
605 struct struct_tag { 604 struct struct_tag {
606 /* 605 /*
607 * STDC requires that "struct a;" always introduces 606 * STDC requires that "struct a;" always introduces
608 * a new tag if "a" is not declared at current level 607 * a new tag if "a" is not declared at current level
609 * 608 *
610 * yychar is valid because otherwise the parser would not 609 * yychar is valid because otherwise the parser would not
611 * have been able to decide if it must shift or reduce 610 * have been able to decide if it must shift or reduce
612 */ 611 */
613 $$ = mktag($2, $1, false, yychar == T_SEMI); 612 $$ = mktag($2, $1, false, yychar == T_SEMI);
614 } 613 }
615 | struct struct_tag { 614 | struct struct_tag {
616 dcs->d_tagtyp = mktag($2, $1, true, false); 615 dcs->d_tagtyp = mktag($2, $1, true, false);
617 } struct_declaration { 616 } struct_declaration {
618 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4); 617 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
619 } 618 }
620 | struct { 619 | struct {
621 dcs->d_tagtyp = mktag(NULL, $1, true, false); 620 dcs->d_tagtyp = mktag(NULL, $1, true, false);
622 } struct_declaration { 621 } struct_declaration {
623 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); 622 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
624 } 623 }
625 | struct error { 624 | struct error {
626 symtyp = FVFT; 625 symtyp = FVFT;
627 $$ = gettyp(INT); 626 $$ = gettyp(INT);
628 } 627 }
629 ; 628 ;
630 629
631struct: 630struct:
632 T_STRUCT_OR_UNION { 631 T_STRUCT_OR_UNION {
633 symtyp = FTAG; 632 symtyp = FTAG;
634 begin_declaration_level($1 == STRUCT ? MOS : MOU); 633 begin_declaration_level($1 == STRUCT ? MOS : MOU);
635 dcs->d_offset = 0; 634 dcs->d_offset = 0;
636 dcs->d_sou_align_in_bits = CHAR_SIZE; 635 dcs->d_sou_align_in_bits = CHAR_SIZE;
637 } type_attribute_list_opt 636 } type_attribute_list_opt
638 ; 637 ;
639 638
640struct_tag: 639struct_tag:
641 identifier { 640 identifier {
642 $$ = getsym($1); 641 $$ = getsym($1);
643 } 642 }
644 ; 643 ;
645 644
646struct_declaration: 645struct_declaration:
647 T_LBRACE { 646 T_LBRACE {
648 symtyp = FVFT; 647 symtyp = FVFT;
649 } member_declaration_list_semi T_RBRACE { 648 } member_declaration_list_semi T_RBRACE {
650 $$ = $3; 649 $$ = $3;
651 } 650 }
652 ; 651 ;
653 652
654member_declaration_list_semi: 653member_declaration_list_semi:
655 /* empty */ { 654 /* empty */ {
656 $$ = NULL; 655 $$ = NULL;
657 } 656 }
658 | member_declaration_list T_SEMI 657 | member_declaration_list T_SEMI
659 | member_declaration_list { 658 | member_declaration_list {
660 if (sflag) { 659 if (sflag) {
661 /* syntax req. ';' after last struct/union member */ 660 /* syntax req. ';' after last struct/union member */
662 error(66); 661 error(66);
663 } else { 662 } else {
664 /* syntax req. ';' after last struct/union member */ 663 /* syntax req. ';' after last struct/union member */
665 warning(66); 664 warning(66);
666 } 665 }
667 $$ = $1; 666 $$ = $1;
668 } 667 }
669 ; 668 ;
670 669
671member_declaration_list: 670member_declaration_list:
672 member_declaration 671 member_declaration
673 | member_declaration_list T_SEMI member_declaration { 672 | member_declaration_list T_SEMI member_declaration {
674 $$ = lnklst($1, $3); 673 $$ = lnklst($1, $3);
675 } 674 }
676 ; 675 ;
677 676
678member_declaration: 677member_declaration:
679 noclass_declmods deftyp { 678 noclass_declmods deftyp {
680 /* too late, i know, but getsym() compensates it */ 679 /* too late, i know, but getsym() compensates it */
681 symtyp = FMEMBER; 680 symtyp = FMEMBER;
682 } notype_member_decls type_attribute_opt { 681 } notype_member_decls type_attribute_opt {
683 symtyp = FVFT; 682 symtyp = FVFT;
684 $$ = $4; 683 $$ = $4;
685 } 684 }
686 | noclass_declspecs deftyp { 685 | noclass_declspecs deftyp {
687 symtyp = FMEMBER; 686 symtyp = FMEMBER;
688 } type_member_decls type_attribute_opt { 687 } type_member_decls type_attribute_opt {
689 symtyp = FVFT; 688 symtyp = FVFT;
690 $$ = $4; 689 $$ = $4;
691 } 690 }
692 | noclass_declmods deftyp type_attribute_opt { 691 | noclass_declmods deftyp type_attribute_opt {
693 symtyp = FVFT; 692 symtyp = FVFT;
694 /* struct or union member must be named */ 693 /* struct or union member must be named */
695 if (!Sflag) 694 if (!Sflag)
696 /* anonymous struct/union members is a C9X feature */ 695 /* anonymous struct/union members is a C9X feature */
697 warning(49); 696 warning(49);
698 /* add all the members of the anonymous struct/union */ 697 /* add all the members of the anonymous struct/union */
699 lint_assert(is_struct_or_union(dcs->d_type->t_tspec)); 698 lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
700 $$ = dcs->d_type->t_str->sou_first_member; 699 $$ = dcs->d_type->t_str->sou_first_member;
701 anonymize($$); 700 anonymize($$);
702 } 701 }
703 | noclass_declspecs deftyp type_attribute_opt { 702 | noclass_declspecs deftyp type_attribute_opt {
704 symtyp = FVFT; 703 symtyp = FVFT;
705 /* struct or union member must be named */ 704 /* struct or union member must be named */
706 if (!Sflag) 705 if (!Sflag)
707 /* anonymous struct/union members is a C9X feature */ 706 /* anonymous struct/union members is a C9X feature */
708 warning(49); 707 warning(49);
709 if (is_struct_or_union(dcs->d_type->t_tspec)) { 708 if (is_struct_or_union(dcs->d_type->t_tspec)) {
710 $$ = dcs->d_type->t_str->sou_first_member; 709 $$ = dcs->d_type->t_str->sou_first_member;
711 /* add all the members of the anonymous struct/union */ 710 /* add all the members of the anonymous struct/union */
712 anonymize($$); 711 anonymize($$);
713 } else { 712 } else {
714 /* syntax error '%s' */ 713 /* syntax error '%s' */
715 error(249, "unnamed member"); 714 error(249, "unnamed member");
716 $$ = NULL; 715 $$ = NULL;
717 } 716 }
718 } 717 }
719 | error { 718 | error {
720 symtyp = FVFT; 719 symtyp = FVFT;
721 $$ = NULL; 720 $$ = NULL;
722 } 721 }
723 ; 722 ;
724 723
725/* 724/*
726 * XXX: shift/reduce conflict, caused by: 725 * XXX: shift/reduce conflict, caused by:
727 * type_attribute noclass_declspecs 726 * type_attribute noclass_declspecs
728 * noclass_declspecs type_attribute 727 * noclass_declspecs type_attribute
729 */ 728 */
730noclass_declspecs: 729noclass_declspecs:
731 clrtyp_typespec { 730 clrtyp_typespec {
732 add_type($1); 731 add_type($1);
733 } 732 }
734 | type_attribute noclass_declspecs 733 | type_attribute noclass_declspecs
735 | noclass_declmods typespec { 734 | noclass_declmods typespec {
736 add_type($2); 735 add_type($2);
737 } 736 }
738 | noclass_declspecs T_QUAL { 737 | noclass_declspecs T_QUAL {
739 add_qualifier($2); 738 add_qualifier($2);
740 } 739 }
741 | noclass_declspecs notype_typespec { 740 | noclass_declspecs notype_typespec {
742 add_type($2); 741 add_type($2);
743 } 742 }
744 | noclass_declspecs type_attribute 743 | noclass_declspecs type_attribute
745 ; 744 ;
746 745
747noclass_declmods: 746noclass_declmods:
748 clrtyp T_QUAL { 747 clrtyp T_QUAL {
749 add_qualifier($2); 748 add_qualifier($2);
750 } 749 }
751 | noclass_declmods T_QUAL { 750 | noclass_declmods T_QUAL {
752 add_qualifier($2); 751 add_qualifier($2);
753 } 752 }
754 ; 753 ;
755 754
756notype_member_decls: 755notype_member_decls:
757 notype_member_decl { 756 notype_member_decl {
758 $$ = declarator_1_struct_union($1); 757 $$ = declarator_1_struct_union($1);
759 } 758 }
760 | notype_member_decls { 759 | notype_member_decls {
761 symtyp = FMEMBER; 760 symtyp = FMEMBER;
762 } T_COMMA type_member_decl { 761 } T_COMMA type_member_decl {
763 $$ = lnklst($1, declarator_1_struct_union($4)); 762 $$ = lnklst($1, declarator_1_struct_union($4));
764 } 763 }
765 ; 764 ;
766 765
767type_member_decls: 766type_member_decls:
768 type_member_decl { 767 type_member_decl {
769 $$ = declarator_1_struct_union($1); 768 $$ = declarator_1_struct_union($1);
770 } 769 }
771 | type_member_decls { 770 | type_member_decls {
772 symtyp = FMEMBER; 771 symtyp = FMEMBER;
773 } T_COMMA type_member_decl { 772 } T_COMMA type_member_decl {
774 $$ = lnklst($1, declarator_1_struct_union($4)); 773 $$ = lnklst($1, declarator_1_struct_union($4));
775 } 774 }
776 ; 775 ;
777 776
778notype_member_decl: 777notype_member_decl:
779 notype_decl 778 notype_decl
780 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */ 779 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */
781 $$ = bitfield($1, to_int_constant($3, true)); 780 $$ = bitfield($1, to_int_constant($3, true));
782 } 781 }
783 | { 782 | {
784 symtyp = FVFT; 783 symtyp = FVFT;
785 } T_COLON constant_expr { /* C99 6.7.2.1 */ 784 } T_COLON constant_expr { /* C99 6.7.2.1 */
786 $$ = bitfield(NULL, to_int_constant($3, true)); 785 $$ = bitfield(NULL, to_int_constant($3, true));
787 } 786 }
788 ; 787 ;
789 788
790type_member_decl: 789type_member_decl:
791 type_decl 790 type_decl
792 | type_decl T_COLON constant_expr { 791 | type_decl T_COLON constant_expr {
793 $$ = bitfield($1, to_int_constant($3, true)); 792 $$ = bitfield($1, to_int_constant($3, true));
794 } 793 }
795 | { 794 | {
796 symtyp = FVFT; 795 symtyp = FVFT;
797 } T_COLON constant_expr { 796 } T_COLON constant_expr {
798 $$ = bitfield(NULL, to_int_constant($3, true)); 797 $$ = bitfield(NULL, to_int_constant($3, true));
799 } 798 }
800 ; 799 ;
801 800
802enum_spec: 801enum_spec:
803 enum enum_tag { 802 enum enum_tag {
804 $$ = mktag($2, ENUM, false, false); 803 $$ = mktag($2, ENUM, false, false);
805 } 804 }
806 | enum enum_tag { 805 | enum enum_tag {
807 dcs->d_tagtyp = mktag($2, ENUM, true, false); 806 dcs->d_tagtyp = mktag($2, ENUM, true, false);
808 } enum_declaration { 807 } enum_declaration {
809 $$ = complete_tag_enum(dcs->d_tagtyp, $4); 808 $$ = complete_tag_enum(dcs->d_tagtyp, $4);
810 } 809 }
811 | enum { 810 | enum {
812 dcs->d_tagtyp = mktag(NULL, ENUM, true, false); 811 dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
813 } enum_declaration { 812 } enum_declaration {
814 $$ = complete_tag_enum(dcs->d_tagtyp, $3); 813 $$ = complete_tag_enum(dcs->d_tagtyp, $3);
815 } 814 }
816 | enum error { 815 | enum error {
817 symtyp = FVFT; 816 symtyp = FVFT;
818 $$ = gettyp(INT); 817 $$ = gettyp(INT);
819 } 818 }
820 ; 819 ;
821 820
822enum: 821enum:
823 T_ENUM { 822 T_ENUM {
824 symtyp = FTAG; 823 symtyp = FTAG;
825 begin_declaration_level(CTCONST); 824 begin_declaration_level(CTCONST);
826 } 825 }
827 ; 826 ;
828 827
829enum_tag: 828enum_tag:
830 identifier { 829 identifier {
831 $$ = getsym($1); 830 $$ = getsym($1);
832 } 831 }
833 ; 832 ;
834 833
835enum_declaration: 834enum_declaration:
836 T_LBRACE { 835 T_LBRACE {
837 symtyp = FVFT; 836 symtyp = FVFT;
838 enumval = 0; 837 enumval = 0;
839 } enumerator_list enumerator_list_comma_opt T_RBRACE { 838 } enumerator_list enumerator_list_comma_opt T_RBRACE {
840 $$ = $3; 839 $$ = $3;
841 } 840 }
842 ; 841 ;
843 842
844enumerator_list: /* C99 6.7.2.2 */ 843enumerator_list: /* C99 6.7.2.2 */
845 enumerator 844 enumerator
846 | enumerator_list T_COMMA enumerator { 845 | enumerator_list T_COMMA enumerator {
847 $$ = lnklst($1, $3); 846 $$ = lnklst($1, $3);
848 } 847 }
849 | error { 848 | error {
850 $$ = NULL; 849 $$ = NULL;
851 } 850 }
852 ; 851 ;
853 852
854enumerator_list_comma_opt: 853enumerator_list_comma_opt:
855 /* empty */ 854 /* empty */
856 | T_COMMA { 855 | T_COMMA {
857 if (sflag) { 856 if (sflag) {
858 /* trailing ',' prohibited in enum declaration */ 857 /* trailing ',' prohibited in enum declaration */
859 error(54); 858 error(54);
860 } else { 859 } else {
861 /* trailing ',' prohibited in enum declaration */ 860 /* trailing ',' prohibited in enum declaration */
862 c99ism(54); 861 c99ism(54);
863 } 862 }
864 } 863 }
865 ; 864 ;
866 865
867enumerator: /* C99 6.7.2.2 */ 866enumerator: /* C99 6.7.2.2 */
868 enumeration_constant { 867 enumeration_constant {
869 $$ = enumeration_constant($1, enumval, true); 868 $$ = enumeration_constant($1, enumval, true);
870 } 869 }
871 | enumeration_constant T_ASSIGN constant_expr { 870 | enumeration_constant T_ASSIGN constant_expr {
872 $$ = enumeration_constant($1, to_int_constant($3, true), false); 871 $$ = enumeration_constant($1, to_int_constant($3, true), false);
873 } 872 }
874 ; 873 ;
875 874
876enumeration_constant: /* C99 6.4.4.3 */ 875enumeration_constant: /* C99 6.4.4.3 */
877 identifier { 876 identifier {
878 $$ = getsym($1); 877 $$ = getsym($1);
879 } 878 }
880 ; 879 ;
881 880
882 881
883/* 882/*
884 * For an explanation of 'notype' in the following rules, see the Bison 883 * For an explanation of 'notype' in the following rules, see the Bison
885 * manual, section 7.1 "Semantic Info in Token Kinds". 884 * manual, section 7.1 "Semantic Info in Token Kinds".
886 */ 885 */
887 886
888notype_init_decls: 887notype_init_decls:
889 notype_init_decl 888 notype_init_decl
890 | notype_init_decls T_COMMA type_init_decl 889 | notype_init_decls T_COMMA type_init_decl
891 ; 890 ;
892 891
893type_init_decls: 892type_init_decls:
894 type_init_decl 893 type_init_decl
895 | type_init_decls T_COMMA type_init_decl 894 | type_init_decls T_COMMA type_init_decl
896 ; 895 ;
897 896
898notype_init_decl: 897notype_init_decl:
899 notype_decl asm_or_symbolrename_opt { 898 notype_decl asm_or_symbolrename_opt {
900 cgram_declare($1, false, $2); 899 cgram_declare($1, false, $2);
901 check_size($1); 900 check_size($1);
902 } 901 }
903 | notype_decl asm_or_symbolrename_opt { 902 | notype_decl asm_or_symbolrename_opt {
904 begin_initialization($1); 903 begin_initialization($1);
905 cgram_declare($1, true, $2); 904 cgram_declare($1, true, $2);
906 } T_ASSIGN initializer { 905 } T_ASSIGN initializer {
907 check_size($1); 906 check_size($1);
908 end_initialization(); 907 end_initialization();
909 } 908 }
910 ; 909 ;
911 910
912type_init_decl: 911type_init_decl:
913 type_decl asm_or_symbolrename_opt { 912 type_decl asm_or_symbolrename_opt {
914 cgram_declare($1, false, $2); 913 cgram_declare($1, false, $2);
915 check_size($1); 914 check_size($1);
916 } 915 }
917 | type_decl asm_or_symbolrename_opt { 916 | type_decl asm_or_symbolrename_opt {
918 begin_initialization($1); 917 begin_initialization($1);
919 cgram_declare($1, true, $2); 918 cgram_declare($1, true, $2);
920 } T_ASSIGN initializer { 919 } T_ASSIGN initializer {
921 check_size($1); 920 check_size($1);
922 end_initialization(); 921 end_initialization();
923 } 922 }
924 ; 923 ;
925 924
926notype_decl: 925notype_decl:
927 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */ 926 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */
928 type_attribute_list_opt notype_direct_decl { 927 type_attribute_list_opt notype_direct_decl {
929 $$ = $2; 928 $$ = $2;
930 } 929 }
931 | pointer type_attribute_list_opt notype_direct_decl { 930 | pointer type_attribute_list_opt notype_direct_decl {
932 $$ = add_pointer($3, $1); 931 $$ = add_pointer($3, $1);
933 } 932 }
934 ; 933 ;
935 934
936type_decl: 935type_decl:
937 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */ 936 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */
938 type_attribute_list_opt type_direct_decl { 937 type_attribute_list_opt type_direct_decl {
939 $$ = $2; 938 $$ = $2;
940 } 939 }
941 | pointer type_attribute_list_opt type_direct_decl { 940 | pointer type_attribute_list_opt type_direct_decl {
942 $$ = add_pointer($3, $1); 941 $$ = add_pointer($3, $1);
943 } 942 }
944 ; 943 ;
945 944
946notype_direct_decl: 945notype_direct_decl:
947 T_NAME { 946 T_NAME {
948 $$ = declarator_name(getsym($1)); 947 $$ = declarator_name(getsym($1));
949 } 948 }
950 | T_LPAREN type_decl T_RPAREN { 949 | T_LPAREN type_decl T_RPAREN {
951 $$ = $2; 950 $$ = $2;
952 } 951 }
953 | notype_direct_decl T_LBRACK T_RBRACK { 952 | notype_direct_decl T_LBRACK T_RBRACK {
954 $$ = add_array($1, false, 0); 953 $$ = add_array($1, false, 0);
955 } 954 }
956 | notype_direct_decl T_LBRACK array_size T_RBRACK { 955 | notype_direct_decl T_LBRACK array_size T_RBRACK {
957 $$ = add_array($1, true, to_int_constant($3, false)); 956 $$ = add_array($1, true, to_int_constant($3, false));
958 } 957 }
959 | notype_direct_decl param_list asm_or_symbolrename_opt { 958 | notype_direct_decl param_list asm_or_symbolrename_opt {
960 $$ = add_function(symbolrename($1, $3), $2); 959 $$ = add_function(symbolrename($1, $3), $2);
961 end_declaration_level(); 960 end_declaration_level();
962 block_level--; 961 block_level--;
963 } 962 }
964 | notype_direct_decl type_attribute 963 | notype_direct_decl type_attribute
965 ; 964 ;
966 965
967type_direct_decl: 966type_direct_decl:
968 identifier { 967 identifier {
969 $$ = declarator_name(getsym($1)); 968 $$ = declarator_name(getsym($1));
970 } 969 }
971 | T_LPAREN type_decl T_RPAREN { 970 | T_LPAREN type_decl T_RPAREN {
972 $$ = $2; 971 $$ = $2;
973 } 972 }
974 | type_direct_decl T_LBRACK T_RBRACK { 973 | type_direct_decl T_LBRACK T_RBRACK {
975 $$ = add_array($1, false, 0); 974 $$ = add_array($1, false, 0);
976 } 975 }
977 | type_direct_decl T_LBRACK array_size T_RBRACK { 976 | type_direct_decl T_LBRACK array_size T_RBRACK {
978 $$ = add_array($1, true, to_int_constant($3, false)); 977 $$ = add_array($1, true, to_int_constant($3, false));
979 } 978 }
980 | type_direct_decl param_list asm_or_symbolrename_opt { 979 | type_direct_decl param_list asm_or_symbolrename_opt {
981 $$ = add_function(symbolrename($1, $3), $2); 980 $$ = add_function(symbolrename($1, $3), $2);
982 end_declaration_level(); 981 end_declaration_level();
983 block_level--; 982 block_level--;
984 } 983 }
985 | type_direct_decl type_attribute 984 | type_direct_decl type_attribute
986 ; 985 ;
987 986
988/* 987/*
989 * The two distinct rules type_param_decl and notype_param_decl avoid a 988 * The two distinct rules type_param_decl and notype_param_decl avoid a
990 * conflict in argument lists. A typename enclosed in parentheses is always 989 * conflict in argument lists. A typename enclosed in parentheses is always
991 * treated as a typename, not an argument name. For example, after 990 * treated as a typename, not an argument name. For example, after
992 * "typedef double a;", the declaration "f(int (a));" is interpreted as 991 * "typedef double a;", the declaration "f(int (a));" is interpreted as
993 * "f(int (double));", not "f(int a);". 992 * "f(int (double));", not "f(int a);".
994 */ 993 */
995type_param_decl: 994type_param_decl:
996 direct_param_decl 995 direct_param_decl
997 | pointer direct_param_decl { 996 | pointer direct_param_decl {
998 $$ = add_pointer($2, $1); 997 $$ = add_pointer($2, $1);
999 } 998 }
1000 ; 999 ;
1001 1000
1002notype_param_decl: 1001notype_param_decl:
1003 direct_notype_param_decl 1002 direct_notype_param_decl
1004 | pointer direct_notype_param_decl { 1003 | pointer direct_notype_param_decl {
1005 $$ = add_pointer($2, $1); 1004 $$ = add_pointer($2, $1);
1006 } 1005 }
1007 ; 1006 ;
1008 1007
1009direct_param_decl: 1008direct_param_decl:
1010 identifier type_attribute_list_opt { 1009 identifier type_attribute_list_opt {
1011 $$ = declarator_name(getsym($1)); 1010 $$ = declarator_name(getsym($1));
1012 } 1011 }
1013 | T_LPAREN notype_param_decl T_RPAREN { 1012 | T_LPAREN notype_param_decl T_RPAREN {
1014 $$ = $2; 1013 $$ = $2;
1015 } 1014 }
1016 | direct_param_decl T_LBRACK T_RBRACK { 1015 | direct_param_decl T_LBRACK T_RBRACK {
1017 $$ = add_array($1, false, 0); 1016 $$ = add_array($1, false, 0);
1018 } 1017 }
1019 | direct_param_decl T_LBRACK array_size T_RBRACK { 1018 | direct_param_decl T_LBRACK array_size T_RBRACK {
1020 $$ = add_array($1, true, to_int_constant($3, false)); 1019 $$ = add_array($1, true, to_int_constant($3, false));
1021 } 1020 }
1022 | direct_param_decl param_list asm_or_symbolrename_opt { 1021 | direct_param_decl param_list asm_or_symbolrename_opt {
1023 $$ = add_function(symbolrename($1, $3), $2); 1022 $$ = add_function(symbolrename($1, $3), $2);
1024 end_declaration_level(); 1023 end_declaration_level();
1025 block_level--; 1024 block_level--;
1026 } 1025 }
1027 ; 1026 ;
1028 1027
1029direct_notype_param_decl: 1028direct_notype_param_decl:
1030 identifier /* XXX: missing type_attribute_list_opt? */ { 1029 identifier /* XXX: missing type_attribute_list_opt? */ {
1031 $$ = declarator_name(getsym($1)); 1030 $$ = declarator_name(getsym($1));
1032 } 1031 }
1033 | T_LPAREN notype_param_decl T_RPAREN { 1032 | T_LPAREN notype_param_decl T_RPAREN {
1034 $$ = $2; 1033 $$ = $2;
1035 } 1034 }
1036 | direct_notype_param_decl T_LBRACK T_RBRACK { 1035 | direct_notype_param_decl T_LBRACK T_RBRACK {
1037 $$ = add_array($1, false, 0); 1036 $$ = add_array($1, false, 0);
1038 } 1037 }
1039 | direct_notype_param_decl T_LBRACK array_size T_RBRACK { 1038 | direct_notype_param_decl T_LBRACK array_size T_RBRACK {
1040 $$ = add_array($1, true, to_int_constant($3, false)); 1039 $$ = add_array($1, true, to_int_constant($3, false));
1041 } 1040 }
1042 | direct_notype_param_decl param_list asm_or_symbolrename_opt { 1041 | direct_notype_param_decl param_list asm_or_symbolrename_opt {
1043 $$ = add_function(symbolrename($1, $3), $2); 1042 $$ = add_function(symbolrename($1, $3), $2);
1044 end_declaration_level(); 1043 end_declaration_level();
1045 block_level--; 1044 block_level--;
1046 } 1045 }
1047 ; 1046 ;
1048 1047
1049pointer: /* C99 6.7.5 */ 1048pointer: /* C99 6.7.5 */
1050 asterisk type_qualifier_list_opt { 1049 asterisk type_qualifier_list_opt {
1051 $$ = merge_qualified_pointer($1, $2); 1050 $$ = merge_qualified_pointer($1, $2);
1052 } 1051 }
1053 | asterisk type_qualifier_list_opt pointer { 1052 | asterisk type_qualifier_list_opt pointer {
1054 $$ = merge_qualified_pointer($1, $2); 1053 $$ = merge_qualified_pointer($1, $2);
1055 $$ = merge_qualified_pointer($$, $3); 1054 $$ = merge_qualified_pointer($$, $3);
1056 } 1055 }
1057 ; 1056 ;
1058 1057
1059asterisk: 1058asterisk:
1060 T_ASTERISK { 1059 T_ASTERISK {
1061 $$ = xcalloc(1, sizeof(*$$)); 1060 $$ = xcalloc(1, sizeof(*$$));
1062 $$->p_pointer = true; 1061 $$->p_pointer = true;
1063 } 1062 }
1064 ; 1063 ;
1065 1064
1066type_qualifier_list_opt: 1065type_qualifier_list_opt:
1067 /* empty */ { 1066 /* empty */ {
1068 $$ = NULL; 1067 $$ = NULL;
1069 } 1068 }
1070 | type_qualifier_list 1069 | type_qualifier_list
1071 ; 1070 ;
1072 1071
1073type_qualifier_list: /* C99 6.7.5 */ 1072type_qualifier_list: /* C99 6.7.5 */
1074 type_qualifier 1073 type_qualifier
1075 | type_qualifier_list type_qualifier { 1074 | type_qualifier_list type_qualifier {
1076 $$ = merge_qualified_pointer($1, $2); 1075 $$ = merge_qualified_pointer($1, $2);
1077 } 1076 }
1078 ; 1077 ;
1079 1078
1080type_qualifier: 1079type_qualifier:
1081 T_QUAL { 1080 T_QUAL {
1082 $$ = xcalloc(1, sizeof(*$$)); 1081 $$ = xcalloc(1, sizeof(*$$));
1083 if ($1 == CONST) { 1082 if ($1 == CONST) {
1084 $$->p_const = true; 1083 $$->p_const = true;
1085 } else if ($1 == VOLATILE) { 1084 } else if ($1 == VOLATILE) {
1086 $$->p_volatile = true; 1085 $$->p_volatile = true;
1087 } else { 1086 } else {
1088 lint_assert($1 == RESTRICT || $1 == THREAD); 1087 lint_assert($1 == RESTRICT || $1 == THREAD);
1089 } 1088 }
1090 } 1089 }
1091 ; 1090 ;
1092 1091
1093align_as: /* See alignment-specifier in C11 6.7.5 */ 1092align_as: /* See alignment-specifier in C11 6.7.5 */
1094 typespec 1093 typespec
1095 | constant_expr 1094 | constant_expr
1096 ; 1095 ;
1097 1096
1098param_list: 1097param_list:
1099 id_list_lparen identifier_list T_RPAREN { 1098 id_list_lparen identifier_list T_RPAREN {
1100 $$ = $2; 1099 $$ = $2;
1101 } 1100 }
1102 | abstract_decl_param_list 1101 | abstract_decl_param_list
1103 ; 1102 ;
1104 1103
1105id_list_lparen: 1104id_list_lparen:
1106 T_LPAREN { 1105 T_LPAREN {
1107 block_level++; 1106 block_level++;
1108 begin_declaration_level(PROTO_ARG); 1107 begin_declaration_level(PROTO_ARG);
1109 } 1108 }
1110 ; 1109 ;
1111 1110
1112identifier_list: 1111identifier_list:
1113 T_NAME { 1112 T_NAME {
1114 $$ = old_style_function_name(getsym($1)); 1113 $$ = old_style_function_name(getsym($1));
1115 } 1114 }
1116 | identifier_list T_COMMA T_NAME { 1115 | identifier_list T_COMMA T_NAME {
1117 $$ = lnklst($1, old_style_function_name(getsym($3))); 1116 $$ = lnklst($1, old_style_function_name(getsym($3)));
1118 } 1117 }
1119 | identifier_list error 1118 | identifier_list error
1120 ; 1119 ;
1121 1120
1122abstract_decl_param_list: 1121abstract_decl_param_list:
1123 abstract_decl_lparen T_RPAREN type_attribute_opt { 1122 abstract_decl_lparen T_RPAREN type_attribute_opt {
1124 $$ = NULL; 1123 $$ = NULL;
1125 } 1124 }
1126 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { 1125 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1127 dcs->d_proto = true; 1126 dcs->d_proto = true;
1128 $$ = $2; 1127 $$ = $2;
1129 } 1128 }
1130 | abstract_decl_lparen error T_RPAREN type_attribute_opt { 1129 | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1131 $$ = NULL; 1130 $$ = NULL;
1132 } 1131 }
1133 ; 1132 ;
1134 1133
1135abstract_decl_lparen: 1134abstract_decl_lparen:
1136 T_LPAREN { 1135 T_LPAREN {
1137 block_level++; 1136 block_level++;
1138 begin_declaration_level(PROTO_ARG); 1137 begin_declaration_level(PROTO_ARG);
1139 } 1138 }
1140 ; 1139 ;
1141 1140
1142vararg_parameter_type_list: 1141vararg_parameter_type_list:
1143 parameter_type_list 1142 parameter_type_list
1144 | parameter_type_list T_COMMA T_ELLIPSIS { 1143 | parameter_type_list T_COMMA T_ELLIPSIS {
1145 dcs->d_vararg = true; 1144 dcs->d_vararg = true;
1146 $$ = $1; 1145 $$ = $1;
1147 } 1146 }
1148 | T_ELLIPSIS { 1147 | T_ELLIPSIS {
1149 if (sflag) { 1148 if (sflag) {
1150 /* ANSI C requires formal parameter before '...' */ 1149 /* ANSI C requires formal parameter before '...' */
1151 error(84); 1150 error(84);
1152 } else if (!tflag) { 1151 } else if (!tflag) {
1153 /* ANSI C requires formal parameter before '...' */ 1152 /* ANSI C requires formal parameter before '...' */
1154 warning(84); 1153 warning(84);
1155 } 1154 }
1156 dcs->d_vararg = true; 1155 dcs->d_vararg = true;
1157 $$ = NULL; 1156 $$ = NULL;
1158 } 1157 }
1159 ; 1158 ;
1160 1159
1161parameter_type_list: 1160parameter_type_list:
1162 parameter_declaration 1161 parameter_declaration
1163 | parameter_type_list T_COMMA parameter_declaration { 1162 | parameter_type_list T_COMMA parameter_declaration {
1164 $$ = lnklst($1, $3); 1163 $$ = lnklst($1, $3);
1165 } 1164 }
1166 ; 1165 ;
1167 1166
1168/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ 1167/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1169parameter_declaration: 1168parameter_declaration:
1170 declmods deftyp { 1169 declmods deftyp {
1171 $$ = declare_argument(abstract_name(), false); 1170 $$ = declare_argument(abstract_name(), false);
1172 } 1171 }
1173 | declaration_specifiers deftyp { 1172 | declaration_specifiers deftyp {
1174 $$ = declare_argument(abstract_name(), false); 1173 $$ = declare_argument(abstract_name(), false);
1175 } 1174 }
1176 | declmods deftyp notype_param_decl { 1175 | declmods deftyp notype_param_decl {
1177 $$ = declare_argument($3, false); 1176 $$ = declare_argument($3, false);
1178 } 1177 }
1179 | declaration_specifiers deftyp type_param_decl { 1178 | declaration_specifiers deftyp type_param_decl {
1180 $$ = declare_argument($3, false); 1179 $$ = declare_argument($3, false);
1181 } 1180 }
1182 | declmods deftyp abstract_declarator { 1181 | declmods deftyp abstract_declarator {
1183 $$ = declare_argument($3, false); 1182 $$ = declare_argument($3, false);
1184 } 1183 }
1185 | declaration_specifiers deftyp abstract_declarator { 1184 | declaration_specifiers deftyp abstract_declarator {
1186 $$ = declare_argument($3, false); 1185 $$ = declare_argument($3, false);
1187 } 1186 }
1188 ; 1187 ;
1189 1188
1190asm_or_symbolrename_opt: /* expect only one */ 1189asm_or_symbolrename_opt: /* expect only one */
1191 /* empty */ { 1190 /* empty */ {
1192 $$ = NULL; 1191 $$ = NULL;
1193 } 1192 }
1194 | T_ASM T_LPAREN T_STRING T_RPAREN { 1193 | T_ASM T_LPAREN T_STRING T_RPAREN {
1195 freeyyv(&$3, T_STRING); 1194 freeyyv(&$3, T_STRING);
1196 $$ = NULL; 1195 $$ = NULL;
1197 } 1196 }
1198 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { 1197 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
1199 $$ = $3; 1198 $$ = $3;
1200 } 1199 }
1201 ; 1200 ;
1202 1201
1203initializer: /* C99 6.7.8 "Initialization" */ 1202initializer: /* C99 6.7.8 "Initialization" */
1204 expr %prec T_COMMA { 1203 expr %prec T_COMMA {
1205 init_expr($1); 1204 init_expr($1);
1206 } 1205 }
1207 | init_lbrace init_rbrace { 1206 | init_lbrace init_rbrace {
1208 /* XXX: Empty braces are not covered by C99 6.7.8. */ 1207 /* XXX: Empty braces are not covered by C99 6.7.8. */
1209 } 1208 }
1210 | init_lbrace initializer_list comma_opt init_rbrace 1209 | init_lbrace initializer_list comma_opt init_rbrace
1211 | error 1210 | error
1212 ; 1211 ;
1213 1212
1214initializer_list: /* C99 6.7.8 "Initialization" */ 1213initializer_list: /* C99 6.7.8 "Initialization" */
1215 initializer_list_item 1214 initializer_list_item
1216 | initializer_list T_COMMA initializer_list_item 1215 | initializer_list T_COMMA initializer_list_item
1217 ; 1216 ;
1218 1217
1219initializer_list_item: 1218initializer_list_item:
1220 designation initializer 1219 designation initializer
1221 | initializer 1220 | initializer
1222 ; 1221 ;
1223 1222
1224designation: /* C99 6.7.8 "Initialization" */ 1223designation: /* C99 6.7.8 "Initialization" */
1225 designator_list T_ASSIGN 1224 designator_list T_ASSIGN
1226 | identifier T_COLON { 1225 | identifier T_COLON {
1227 /* GCC style struct or union member name in initializer */ 1226 /* GCC style struct or union member name in initializer */
1228 gnuism(315); 1227 gnuism(315);
1229 add_designator_member($1); 1228 add_designator_member($1);
1230 } 1229 }
1231 ; 1230 ;
1232 1231
1233designator_list: /* C99 6.7.8 "Initialization" */ 1232designator_list: /* C99 6.7.8 "Initialization" */
1234 designator 1233 designator
1235 | designator_list designator 1234 | designator_list designator
1236 ; 1235 ;
1237 1236
1238designator: /* C99 6.7.8 "Initialization" */ 1237designator: /* C99 6.7.8 "Initialization" */
1239 T_LBRACK range T_RBRACK { 1238 T_LBRACK range T_RBRACK {
1240 add_designator_subscript($2); 1239 add_designator_subscript($2);
1241 if (!Sflag) 1240 if (!Sflag)
1242 /* array initializer with des.s is a C9X feature */ 1241 /* array initializer with des.s is a C9X feature */
1243 warning(321); 1242 warning(321);
1244 } 1243 }
1245 | T_POINT identifier { 1244 | T_POINT identifier {
1246 if (!Sflag) 1245 if (!Sflag)
1247 /* struct or union member name in initializer is ... */ 1246 /* struct or union member name in initializer is ... */
1248 warning(313); 1247 warning(313);
1249 add_designator_member($2); 1248 add_designator_member($2);
1250 } 1249 }
1251 ; 1250 ;
1252 1251
1253range: 1252range:
1254 constant_expr { 1253 constant_expr {
1255 $$.lo = to_int_constant($1, true); 1254 $$.lo = to_int_constant($1, true);
1256 $$.hi = $$.lo; 1255 $$.hi = $$.lo;
1257 } 1256 }
1258 | constant_expr T_ELLIPSIS constant_expr { 1257 | constant_expr T_ELLIPSIS constant_expr {
1259 $$.lo = to_int_constant($1, true); 1258 $$.lo = to_int_constant($1, true);
1260 $$.hi = to_int_constant($3, true); 1259 $$.hi = to_int_constant($3, true);
1261 /* initialization with '[a...b]' is a GCC extension */ 1260 /* initialization with '[a...b]' is a GCC extension */
1262 gnuism(340); 1261 gnuism(340);
1263 } 1262 }
1264 ; 1263 ;
1265 1264
1266init_lbrace: 1265init_lbrace:
1267 T_LBRACE { 1266 T_LBRACE {
1268 init_lbrace(); 1267 init_lbrace();
1269 } 1268 }
1270 ; 1269 ;
1271 1270
1272init_rbrace: 1271init_rbrace:
1273 T_RBRACE { 1272 T_RBRACE {
1274 init_rbrace(); 1273 init_rbrace();
1275 } 1274 }
1276 ; 1275 ;
1277 1276
1278type_name: /* C99 6.7.6 */ 1277type_name: /* C99 6.7.6 */
1279 { 1278 {
1280 begin_declaration_level(ABSTRACT); 1279 begin_declaration_level(ABSTRACT);
1281 } abstract_declaration { 1280 } abstract_declaration {
1282 end_declaration_level(); 1281 end_declaration_level();
1283 $$ = $2->s_type; 1282 $$ = $2->s_type;
1284 } 1283 }
1285 ; 1284 ;
1286 1285
1287abstract_declaration: 1286abstract_declaration:
1288 noclass_declmods deftyp { 1287 noclass_declmods deftyp {
1289 $$ = declare_1_abstract(abstract_name()); 1288 $$ = declare_1_abstract(abstract_name());
1290 } 1289 }
1291 | noclass_declspecs deftyp { 1290 | noclass_declspecs deftyp {
1292 $$ = declare_1_abstract(abstract_name()); 1291 $$ = declare_1_abstract(abstract_name());
1293 } 1292 }
1294 | noclass_declmods deftyp abstract_declarator { 1293 | noclass_declmods deftyp abstract_declarator {
1295 $$ = declare_1_abstract($3); 1294 $$ = declare_1_abstract($3);
1296 } 1295 }
1297 | noclass_declspecs deftyp abstract_declarator { 1296 | noclass_declspecs deftyp abstract_declarator {
1298 $$ = declare_1_abstract($3); 1297 $$ = declare_1_abstract($3);
1299 } 1298 }
1300 ; 1299 ;
1301 1300
1302abstract_declarator: /* C99 6.7.6 */ 1301abstract_declarator: /* C99 6.7.6 */
1303 pointer { 1302 pointer {
1304 $$ = add_pointer(abstract_name(), $1); 1303 $$ = add_pointer(abstract_name(), $1);
1305 } 1304 }
1306 | direct_abstract_declarator 1305 | direct_abstract_declarator
1307 | pointer direct_abstract_declarator { 1306 | pointer direct_abstract_declarator {
1308 $$ = add_pointer($2, $1); 1307 $$ = add_pointer($2, $1);
1309 } 1308 }
1310 | T_TYPEOF term { /* GCC extension */ 1309 | T_TYPEOF term { /* GCC extension */
1311 $$ = mktempsym($2->tn_type); 1310 $$ = mktempsym($2->tn_type);
1312 } 1311 }
1313 ; 1312 ;
1314 1313
1315/* 1314/*
1316 * XXX: shift/reduce conflict, caused by: 1315 * XXX: shift/reduce conflict, caused by:
1317 * type_attribute direct_abstract_declarator 1316 * type_attribute direct_abstract_declarator
1318 * direct_abstract_declarator type_attribute 1317 * direct_abstract_declarator type_attribute
1319 */ 1318 */
1320direct_abstract_declarator: /* C99 6.7.6 */ 1319direct_abstract_declarator: /* C99 6.7.6 */
1321 T_LPAREN abstract_declarator T_RPAREN { 1320 T_LPAREN abstract_declarator T_RPAREN {
1322 $$ = $2; 1321 $$ = $2;
1323 } 1322 }
1324 | T_LBRACK T_RBRACK { 1323 | T_LBRACK T_RBRACK {
1325 $$ = add_array(abstract_name(), false, 0); 1324 $$ = add_array(abstract_name(), false, 0);
1326 } 1325 }
1327 | T_LBRACK array_size T_RBRACK { 1326 | T_LBRACK array_size T_RBRACK {
1328 $$ = add_array(abstract_name(), true, to_int_constant($2, false)); 1327 $$ = add_array(abstract_name(), true, to_int_constant($2, false));
1329 } 1328 }
1330 | type_attribute direct_abstract_declarator { 1329 | type_attribute direct_abstract_declarator {
1331 $$ = $2; 1330 $$ = $2;
1332 } 1331 }
1333 | direct_abstract_declarator T_LBRACK T_RBRACK { 1332 | direct_abstract_declarator T_LBRACK T_RBRACK {
1334 $$ = add_array($1, false, 0); 1333 $$ = add_array($1, false, 0);
1335 } 1334 }
1336 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */ 1335 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
1337 $$ = add_array($1, false, 0); 1336 $$ = add_array($1, false, 0);
1338 } 1337 }
1339 | direct_abstract_declarator T_LBRACK array_size T_RBRACK { 1338 | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
1340 $$ = add_array($1, true, to_int_constant($3, false)); 1339 $$ = add_array($1, true, to_int_constant($3, false));
1341 } 1340 }
1342 | abstract_decl_param_list asm_or_symbolrename_opt { 1341 | abstract_decl_param_list asm_or_symbolrename_opt {
1343 $$ = add_function(symbolrename(abstract_name(), $2), $1); 1342 $$ = add_function(symbolrename(abstract_name(), $2), $1);
1344 end_declaration_level(); 1343 end_declaration_level();
1345 block_level--; 1344 block_level--;
1346 } 1345 }
1347 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt { 1346 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
1348 $$ = add_function(symbolrename($1, $3), $2); 1347 $$ = add_function(symbolrename($1, $3), $2);
1349 end_declaration_level(); 1348 end_declaration_level();
1350 block_level--; 1349 block_level--;
1351 } 1350 }
1352 | direct_abstract_declarator type_attribute 1351 | direct_abstract_declarator type_attribute
1353 ; 1352 ;
1354 1353
1355array_size: 1354array_size:
1356 type_qualifier_list_opt T_SCLASS constant_expr { 1355 type_qualifier_list_opt T_SCLASS constant_expr {
1357 /* C11 6.7.6.3p7 */ 1356 /* C11 6.7.6.3p7 */
1358 if ($2 != STATIC) 1357 if ($2 != STATIC)
1359 yyerror("Bad attribute"); 1358 yyerror("Bad attribute");
1360 /* static array size is a C11 extension */ 1359 /* static array size is a C11 extension */
1361 c11ism(343); 1360 c11ism(343);
1362 $$ = $3; 1361 $$ = $3;
1363 } 1362 }
1364 | constant_expr 1363 | constant_expr
1365 ; 1364 ;
1366 1365
1367non_expr_statement: 1366non_expr_statement:
1368 type_attribute T_SEMI 1367 type_attribute T_SEMI
1369 | labeled_statement 1368 | labeled_statement
1370 | compound_statement 1369 | compound_statement
1371 | selection_statement 1370 | selection_statement
1372 | iteration_statement 1371 | iteration_statement
1373 | jump_statement { 1372 | jump_statement {
1374 seen_fallthrough = false; 1373 seen_fallthrough = false;
1375 } 1374 }
1376 | asm_statement 1375 | asm_statement
1377 ; 1376 ;
1378 1377
1379statement: /* C99 6.8 */ 1378statement: /* C99 6.8 */
1380 expression_statement 1379 expression_statement
1381 | non_expr_statement 1380 | non_expr_statement
1382 ; 1381 ;
1383 1382
1384labeled_statement: /* C99 6.8.1 */ 1383labeled_statement: /* C99 6.8.1 */
1385 label gcc_attribute_list_opt statement 1384 label gcc_attribute_list_opt statement
1386 ; 1385 ;
1387 1386
1388label: 1387label:
1389 T_NAME T_COLON { 1388 T_NAME T_COLON {
1390 symtyp = FLABEL; 1389 symtyp = FLABEL;
1391 named_label(getsym($1)); 1390 named_label(getsym($1));
1392 } 1391 }
1393 | T_CASE constant_expr T_COLON { 1392 | T_CASE constant_expr T_COLON {
1394 case_label($2); 1393 case_label($2);
1395 seen_fallthrough = true; 1394 seen_fallthrough = true;
1396 } 1395 }
1397 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON { 1396 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1398 /* XXX: We don't fill all cases */ 1397 /* XXX: We don't fill all cases */
1399 case_label($2); 1398 case_label($2);
1400 seen_fallthrough = true; 1399 seen_fallthrough = true;
1401 } 1400 }
1402 | T_DEFAULT T_COLON { 1401 | T_DEFAULT T_COLON {
1403 default_label(); 1402 default_label();
1404 seen_fallthrough = true; 1403 seen_fallthrough = true;
1405 } 1404 }
1406 ; 1405 ;
1407 1406
1408compound_statement: /* C99 6.8.2 */ 1407compound_statement: /* C99 6.8.2 */
1409 compound_statement_lbrace block_item_list_opt 1408 compound_statement_lbrace block_item_list_opt
1410 compound_statement_rbrace 1409 compound_statement_rbrace
1411 ; 1410 ;
1412 1411
1413compound_statement_lbrace: 1412compound_statement_lbrace:
1414 T_LBRACE { 1413 T_LBRACE {
1415 block_level++; 1414 block_level++;
1416 mem_block_level++; 1415 mem_block_level++;
1417 begin_declaration_level(AUTO); 1416 begin_declaration_level(AUTO);
1418 } 1417 }
1419 ; 1418 ;
1420 1419
1421compound_statement_rbrace: 1420compound_statement_rbrace:
1422 T_RBRACE { 1421 T_RBRACE {
1423 end_declaration_level(); 1422 end_declaration_level();
1424 freeblk(); 1423 freeblk();
1425 mem_block_level--; 1424 mem_block_level--;
1426 block_level--; 1425 block_level--;
1427 seen_fallthrough = false; 1426 seen_fallthrough = false;
1428 } 1427 }
1429 ; 1428 ;
1430 1429
1431block_item_list_opt: /* C99 6.8.2 */ 1430block_item_list_opt: /* C99 6.8.2 */
1432 /* empty */ 1431 /* empty */
1433 | block_item_list 1432 | block_item_list
1434 ; 1433 ;
1435 1434
1436block_item_list: 1435block_item_list:
1437 block_item 1436 block_item
1438 | block_item_list block_item { 1437 | block_item_list block_item {
1439 if (!Sflag && $1 && !$2) 1438 if (!Sflag && $1 && !$2)
1440 /* declarations after statements is a C99 feature */ 1439 /* declarations after statements is a C99 feature */
1441 c99ism(327); 1440 c99ism(327);
1442 $$ = $1 || $2; 1441 $$ = $1 || $2;
1443 } 1442 }
1444 ; 1443 ;
1445 1444
1446block_item: 1445block_item:
1447 statement { 1446 statement {
1448 $$ = true; 1447 $$ = true;
1449 restore_warning_flags(); 1448 restore_warning_flags();
1450 } 1449 }
1451 | declaration { 1450 | declaration {
1452 $$ = false; 1451 $$ = false;
1453 restore_warning_flags(); 1452 restore_warning_flags();
1454 } 1453 }
1455 ; 1454 ;
1456 1455
1457expression_statement: /* C99 6.8.3 */ 1456expression_statement: /* C99 6.8.3 */
1458 expr T_SEMI { 1457 expr T_SEMI {
1459 expr($1, false, false, false, false); 1458 expr($1, false, false, false, false);
1460 seen_fallthrough = false; 1459 seen_fallthrough = false;
1461 } 1460 }
1462 | T_SEMI { 1461 | T_SEMI {
1463 seen_fallthrough = false; 1462 seen_fallthrough = false;
1464 } 1463 }
1465 ; 1464 ;
1466 1465
1467selection_statement: /* C99 6.8.4 */ 1466selection_statement: /* C99 6.8.4 */
1468 if_without_else { 1467 if_without_else {
1469 save_warning_flags(); 1468 save_warning_flags();
1470 if2(); 1469 if2();
1471 if3(false); 1470 if3(false);
1472 } 1471 }
1473 | if_without_else T_ELSE { 1472 | if_without_else T_ELSE {
1474 save_warning_flags(); 1473 save_warning_flags();
1475 if2(); 1474 if2();
1476 } statement { 1475 } statement {
1477 clear_warning_flags(); 1476 clear_warning_flags();
1478 if3(true); 1477 if3(true);
1479 } 1478 }
1480 | if_without_else T_ELSE error { 1479 | if_without_else T_ELSE error {
1481 clear_warning_flags(); 1480 clear_warning_flags();
1482 if3(false); 1481 if3(false);
1483 } 1482 }
1484 | switch_expr statement { 1483 | switch_expr statement {
1485 clear_warning_flags(); 1484 clear_warning_flags();
1486 switch2(); 1485 switch2();
1487 } 1486 }
1488 | switch_expr error { 1487 | switch_expr error {
1489 clear_warning_flags(); 1488 clear_warning_flags();
1490 switch2(); 1489 switch2();
1491 } 1490 }
1492 ; 1491 ;
1493 1492
1494if_without_else: /* see C99 6.8.4 */ 1493if_without_else: /* see C99 6.8.4 */
1495 if_expr statement 1494 if_expr statement
1496 | if_expr error 1495 | if_expr error
1497 ; 1496 ;
1498 1497
1499if_expr: /* see C99 6.8.4 */ 1498if_expr: /* see C99 6.8.4 */
1500 T_IF T_LPAREN expr T_RPAREN { 1499 T_IF T_LPAREN expr T_RPAREN {
1501 if1($3); 1500 if1($3);
1502 clear_warning_flags(); 1501 clear_warning_flags();
1503 } 1502 }
1504 ; 1503 ;
1505 1504
1506switch_expr: /* see C99 6.8.4 */ 1505switch_expr: /* see C99 6.8.4 */
1507 T_SWITCH T_LPAREN expr T_RPAREN { 1506 T_SWITCH T_LPAREN expr T_RPAREN {
1508 switch1($3); 1507 switch1($3);
1509 clear_warning_flags(); 1508 clear_warning_flags();
1510 } 1509 }
1511 ; 1510 ;
1512 1511
1513do_statement: /* C99 6.8.5 */ 1512do_statement: /* C99 6.8.5 */
1514 do statement { 1513 do statement {
1515 clear_warning_flags(); 1514 clear_warning_flags();
1516 } 1515 }
1517 ; 1516 ;
1518 1517
1519iteration_statement: /* C99 6.8.5 */ 1518iteration_statement: /* C99 6.8.5 */
1520 while_expr statement { 1519 while_expr statement {
1521 clear_warning_flags(); 1520 clear_warning_flags();
1522 while2(); 1521 while2();
1523 } 1522 }
1524 | while_expr error { 1523 | while_expr error {
1525 clear_warning_flags(); 1524 clear_warning_flags();
1526 while2(); 1525 while2();
1527 } 1526 }
1528 | do_statement do_while_expr { 1527 | do_statement do_while_expr {
1529 do2($2); 1528 do2($2);
1530 seen_fallthrough = false; 1529 seen_fallthrough = false;
1531 } 1530 }
1532 | do error { 1531 | do error {
1533 clear_warning_flags(); 1532 clear_warning_flags();
1534 do2(NULL); 1533 do2(NULL);
1535 } 1534 }
1536 | for_exprs statement { 1535 | for_exprs statement {
1537 clear_warning_flags(); 1536 clear_warning_flags();
1538 for2(); 1537 for2();
1539 end_declaration_level(); 1538 end_declaration_level();
1540 block_level--; 1539 block_level--;
1541 } 1540 }
1542 | for_exprs error { 1541 | for_exprs error {
1543 clear_warning_flags(); 1542 clear_warning_flags();
1544 for2(); 1543 for2();
1545 end_declaration_level(); 1544 end_declaration_level();
1546 block_level--; 1545 block_level--;
1547 } 1546 }
1548 ; 1547 ;
1549 1548
1550while_expr: /* see C99 6.8.5 */ 1549while_expr: /* see C99 6.8.5 */
1551 T_WHILE T_LPAREN expr T_RPAREN { 1550 T_WHILE T_LPAREN expr T_RPAREN {
1552 while1($3); 1551 while1($3);
1553 clear_warning_flags(); 1552 clear_warning_flags();
1554 } 1553 }
1555 ; 1554 ;
1556 1555
1557do: /* see C99 6.8.5 */ 1556do: /* see C99 6.8.5 */
1558 T_DO { 1557 T_DO {
1559 do1(); 1558 do1();
1560 } 1559 }
1561 ; 1560 ;
1562 1561
1563do_while_expr: /* see C99 6.8.5 */ 1562do_while_expr: /* see C99 6.8.5 */
1564 T_WHILE T_LPAREN expr T_RPAREN T_SEMI { 1563 T_WHILE T_LPAREN expr T_RPAREN T_SEMI {
1565 $$ = $3; 1564 $$ = $3;
1566 } 1565 }
1567 ; 1566 ;