Sat Jul 10 21:44:51 2021 UTC ()
lint: inline grammar rules declmod and qualifier_or_storage_class

The rule declmod had a confusing name since declmods was not exactly a
list of declmod.

Inlining the rules reduces the abstraction level.  There are still some
shift/reduce conflicts in that area, so make the rules as simple as
possible, in order to resolve these conflicts.

No functional change.


(rillig)
diff -r1.303 -r1.304 src/usr.bin/xlint/lint1/cgram.y

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

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