Thu Jul 8 19:08:03 2021 UTC ()
lint: fix assignment to midrule in grammar (since today)

When compiling the grammar with Bison, it complains:

	error: $$ for the midrule at $2 of 'struct' has no declared type

Yacc does not complain, instead it assumes that a midrule has the same
type as the rule itself.

The assignment '$$ = $1' in the midrule action does not influence the $$
of the whole rule, it only assigns to $2.  The assignment to $$ was done
via the default action, therefore everything worked as expected.  Any
missing assignment in this rule would have been caught quickly by the
strict assertion in mktag.

No functional change.


(rillig)
diff -r1.273 -r1.274 src/usr.bin/xlint/lint1/cgram.y

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/08 18:53:57 1.273
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/08 19:08:03 1.274
@@ -1,1651 +1,1650 @@ @@ -1,1651 +1,1650 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.273 2021/07/08 18:53:57 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 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.273 2021/07/08 18:53:57 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.274 2021/07/08 19:08:03 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 162 126%expect 162
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 | declmods deftyp T_SEMI { 406 | declmods deftyp T_SEMI {
407 if (dcs->d_scl == TYPEDEF) { 407 if (dcs->d_scl == TYPEDEF) {
408 /* typedef declares no type name */ 408 /* typedef declares no type name */
409 warning(72); 409 warning(72);
410 } else { 410 } else {
411 /* empty declaration */ 411 /* empty declaration */
412 warning(2); 412 warning(2);
413 } 413 }
414 } 414 }
415 | declmods deftyp notype_init_decls T_SEMI 415 | declmods deftyp notype_init_decls T_SEMI
416 | declaration_specifiers deftyp T_SEMI { 416 | declaration_specifiers deftyp T_SEMI {
417 if (dcs->d_scl == TYPEDEF) { 417 if (dcs->d_scl == TYPEDEF) {
418 /* typedef declares no type name */ 418 /* typedef declares no type name */
419 warning(72); 419 warning(72);
420 } else if (!dcs->d_nonempty_decl) { 420 } else if (!dcs->d_nonempty_decl) {
421 /* empty declaration */ 421 /* empty declaration */
422 warning(2); 422 warning(2);
423 } 423 }
424 } 424 }
425 | declaration_specifiers deftyp type_init_decls T_SEMI 425 | declaration_specifiers deftyp type_init_decls T_SEMI
426 | error T_SEMI { 426 | error T_SEMI {
427 global_clean_up(); 427 global_clean_up();
428 } 428 }
429 | error T_RBRACE { 429 | error T_RBRACE {
430 global_clean_up(); 430 global_clean_up();
431 } 431 }
432 ; 432 ;
433 433
434function_definition: /* C99 6.9.1 */ 434function_definition: /* C99 6.9.1 */
435 func_decl { 435 func_decl {
436 if ($1->s_type->t_tspec != FUNC) { 436 if ($1->s_type->t_tspec != FUNC) {
437 /* syntax error '%s' */ 437 /* syntax error '%s' */
438 error(249, yytext); 438 error(249, yytext);
439 YYERROR; 439 YYERROR;
440 } 440 }
441 if ($1->s_type->t_typedef) { 441 if ($1->s_type->t_typedef) {
442 /* ()-less function definition */ 442 /* ()-less function definition */
443 error(64); 443 error(64);
444 YYERROR; 444 YYERROR;
445 } 445 }
446 funcdef($1); 446 funcdef($1);
447 block_level++; 447 block_level++;
448 begin_declaration_level(ARG); 448 begin_declaration_level(ARG);
449 if (lwarn == LWARN_NONE) 449 if (lwarn == LWARN_NONE)
450 $1->s_used = true; 450 $1->s_used = true;
451 } arg_declaration_list_opt { 451 } arg_declaration_list_opt {
452 end_declaration_level(); 452 end_declaration_level();
453 block_level--; 453 block_level--;
454 check_func_lint_directives(); 454 check_func_lint_directives();
455 check_func_old_style_arguments(); 455 check_func_old_style_arguments();
456 begin_control_statement(CS_FUNCTION_BODY); 456 begin_control_statement(CS_FUNCTION_BODY);
457 } compound_statement { 457 } compound_statement {
458 funcend(); 458 funcend();
459 end_control_statement(CS_FUNCTION_BODY); 459 end_control_statement(CS_FUNCTION_BODY);
460 } 460 }
461 ; 461 ;
462 462
463func_decl: 463func_decl:
464 clrtyp deftyp notype_decl { 464 clrtyp deftyp notype_decl {
465 $$ = $3; 465 $$ = $3;
466 } 466 }
467 | declmods deftyp notype_decl { 467 | declmods deftyp notype_decl {
468 $$ = $3; 468 $$ = $3;
469 } 469 }
470 | declaration_specifiers deftyp type_decl { 470 | declaration_specifiers deftyp type_decl {
471 $$ = $3; 471 $$ = $3;
472 } 472 }
473 ; 473 ;
474 474
475arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ 475arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */
476 /* empty */ 476 /* empty */
477 | arg_declaration_list 477 | arg_declaration_list
478 ; 478 ;
479 479
480arg_declaration_list: /* C99 6.9.1p13 example 1 */ 480arg_declaration_list: /* C99 6.9.1p13 example 1 */
481 arg_declaration 481 arg_declaration
482 | arg_declaration_list arg_declaration 482 | arg_declaration_list arg_declaration
483 /* XXX or better "arg_declaration error" ? */ 483 /* XXX or better "arg_declaration error" ? */
484 | error 484 | error
485 ; 485 ;
486 486
487/* 487/*
488 * "arg_declaration" is separated from "declaration" because it 488 * "arg_declaration" is separated from "declaration" because it
489 * needs other error handling. 489 * needs other error handling.
490 */ 490 */
491arg_declaration: 491arg_declaration:
492 declmods deftyp T_SEMI { 492 declmods deftyp T_SEMI {
493 /* empty declaration */ 493 /* empty declaration */
494 warning(2); 494 warning(2);
495 } 495 }
496 | declmods deftyp notype_init_decls T_SEMI 496 | declmods deftyp notype_init_decls T_SEMI
497 | declaration_specifiers deftyp T_SEMI { 497 | declaration_specifiers deftyp T_SEMI {
498 if (!dcs->d_nonempty_decl) { 498 if (!dcs->d_nonempty_decl) {
499 /* empty declaration */ 499 /* empty declaration */
500 warning(2); 500 warning(2);
501 } else { 501 } else {
502 /* '%s' declared in argument declaration list */ 502 /* '%s' declared in argument declaration list */
503 warning(3, type_name(dcs->d_type)); 503 warning(3, type_name(dcs->d_type));
504 } 504 }
505 } 505 }
506 | declaration_specifiers deftyp type_init_decls T_SEMI { 506 | declaration_specifiers deftyp type_init_decls T_SEMI {
507 if (dcs->d_nonempty_decl) { 507 if (dcs->d_nonempty_decl) {
508 /* '%s' declared in argument declaration list */ 508 /* '%s' declared in argument declaration list */
509 warning(3, type_name(dcs->d_type)); 509 warning(3, type_name(dcs->d_type));
510 } 510 }
511 } 511 }
512 | declmods error 512 | declmods error
513 | declaration_specifiers error 513 | declaration_specifiers error
514 ; 514 ;
515 515
516declaration: /* C99 6.7 */ 516declaration: /* C99 6.7 */
517 declmods deftyp T_SEMI { 517 declmods deftyp T_SEMI {
518 if (dcs->d_scl == TYPEDEF) { 518 if (dcs->d_scl == TYPEDEF) {
519 /* typedef declares no type name */ 519 /* typedef declares no type name */
520 warning(72); 520 warning(72);
521 } else { 521 } else {
522 /* empty declaration */ 522 /* empty declaration */
523 warning(2); 523 warning(2);
524 } 524 }
525 } 525 }
526 | declmods deftyp notype_init_decls T_SEMI 526 | declmods deftyp notype_init_decls T_SEMI
527 | declaration_specifiers deftyp T_SEMI { 527 | declaration_specifiers deftyp T_SEMI {
528 if (dcs->d_scl == TYPEDEF) { 528 if (dcs->d_scl == TYPEDEF) {
529 /* typedef declares no type name */ 529 /* typedef declares no type name */
530 warning(72); 530 warning(72);
531 } else if (!dcs->d_nonempty_decl) { 531 } else if (!dcs->d_nonempty_decl) {
532 /* empty declaration */ 532 /* empty declaration */
533 warning(2); 533 warning(2);
534 } 534 }
535 } 535 }
536 | declaration_specifiers deftyp type_init_decls T_SEMI 536 | declaration_specifiers deftyp type_init_decls T_SEMI
537 | error T_SEMI 537 | error T_SEMI
538 ; 538 ;
539 539
540clrtyp: 540clrtyp:
541 /* empty */ { 541 /* empty */ {
542 clrtyp(); 542 clrtyp();
543 } 543 }
544 ; 544 ;
545 545
546deftyp: 546deftyp:
547 /* empty */ { 547 /* empty */ {
548 deftyp(); 548 deftyp();
549 } 549 }
550 ; 550 ;
551 551
552declaration_specifiers: /* C99 6.7 */ 552declaration_specifiers: /* C99 6.7 */
553 clrtyp_typespec { 553 clrtyp_typespec {
554 add_type($1); 554 add_type($1);
555 } 555 }
556 | declmods typespec { 556 | declmods typespec {
557 add_type($2); 557 add_type($2);
558 } 558 }
559 | type_attribute declaration_specifiers 559 | type_attribute declaration_specifiers
560 | declaration_specifiers declmod 560 | declaration_specifiers declmod
561 | declaration_specifiers notype_typespec { 561 | declaration_specifiers notype_typespec {
562 add_type($2); 562 add_type($2);
563 } 563 }
564 ; 564 ;
565 565
566declmods: 566declmods:
567 clrtyp T_QUAL { 567 clrtyp T_QUAL {
568 add_qualifier($2); 568 add_qualifier($2);
569 } 569 }
570 | clrtyp T_SCLASS { 570 | clrtyp T_SCLASS {
571 add_storage_class($2); 571 add_storage_class($2);
572 } 572 }
573 | declmods declmod 573 | declmods declmod
574 ; 574 ;
575 575
576declmod: 576declmod:
577 T_QUAL { 577 T_QUAL {
578 add_qualifier($1); 578 add_qualifier($1);
579 } 579 }
580 | T_SCLASS { 580 | T_SCLASS {
581 add_storage_class($1); 581 add_storage_class($1);
582 } 582 }
583 | type_attribute 583 | type_attribute
584 ; 584 ;
585 585
586clrtyp_typespec: 586clrtyp_typespec:
587 clrtyp notype_typespec { 587 clrtyp notype_typespec {
588 $$ = $2; 588 $$ = $2;
589 } 589 }
590 | T_TYPENAME clrtyp { 590 | T_TYPENAME clrtyp {
591 $$ = getsym($1)->s_type; 591 $$ = getsym($1)->s_type;
592 } 592 }
593 ; 593 ;
594 594
595typespec: 595typespec:
596 notype_typespec 596 notype_typespec
597 | T_TYPENAME { 597 | T_TYPENAME {
598 $$ = getsym($1)->s_type; 598 $$ = getsym($1)->s_type;
599 } 599 }
600 ; 600 ;
601 601
602notype_typespec: 602notype_typespec:
603 T_TYPE { 603 T_TYPE {
604 $$ = gettyp($1); 604 $$ = gettyp($1);
605 } 605 }
606 | T_TYPEOF term { 606 | T_TYPEOF term {
607 $$ = $2->tn_type; 607 $$ = $2->tn_type;
608 } 608 }
609 | struct_spec { 609 | struct_spec {
610 end_declaration_level(); 610 end_declaration_level();
611 $$ = $1; 611 $$ = $1;
612 } 612 }
613 | enum_spec { 613 | enum_spec {
614 end_declaration_level(); 614 end_declaration_level();
615 $$ = $1; 615 $$ = $1;
616 } 616 }
617 ; 617 ;
618 618
619struct_spec: 619struct_spec:
620 struct struct_tag { 620 struct struct_tag {
621 /* 621 /*
622 * STDC requires that "struct a;" always introduces 622 * STDC requires that "struct a;" always introduces
623 * a new tag if "a" is not declared at current level 623 * a new tag if "a" is not declared at current level
624 * 624 *
625 * yychar is valid because otherwise the parser would not 625 * yychar is valid because otherwise the parser would not
626 * have been able to decide if it must shift or reduce 626 * have been able to decide if it must shift or reduce
627 */ 627 */
628 $$ = mktag($2, $1, false, yychar == T_SEMI); 628 $$ = mktag($2, $1, false, yychar == T_SEMI);
629 } 629 }
630 | struct struct_tag { 630 | struct struct_tag {
631 dcs->d_tagtyp = mktag($2, $1, true, false); 631 dcs->d_tagtyp = mktag($2, $1, true, false);
632 } struct_declaration { 632 } struct_declaration {
633 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4); 633 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
634 } 634 }
635 | struct { 635 | struct {
636 dcs->d_tagtyp = mktag(NULL, $1, true, false); 636 dcs->d_tagtyp = mktag(NULL, $1, true, false);
637 } struct_declaration { 637 } struct_declaration {
638 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); 638 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
639 } 639 }
640 | struct error { 640 | struct error {
641 symtyp = FVFT; 641 symtyp = FVFT;
642 $$ = gettyp(INT); 642 $$ = gettyp(INT);
643 } 643 }
644 ; 644 ;
645 645
646struct: 646struct:
647 T_STRUCT_OR_UNION { 647 T_STRUCT_OR_UNION {
648 symtyp = FTAG; 648 symtyp = FTAG;
649 begin_declaration_level($1 == STRUCT ? MOS : MOU); 649 begin_declaration_level($1 == STRUCT ? MOS : MOU);
650 dcs->d_offset = 0; 650 dcs->d_offset = 0;
651 dcs->d_sou_align_in_bits = CHAR_SIZE; 651 dcs->d_sou_align_in_bits = CHAR_SIZE;
652 $$ = $1; 
653 } type_attribute_list_opt 652 } type_attribute_list_opt
654 ; 653 ;
655 654
656struct_tag: 655struct_tag:
657 identifier { 656 identifier {
658 $$ = getsym($1); 657 $$ = getsym($1);
659 } 658 }
660 ; 659 ;
661 660
662struct_declaration: 661struct_declaration:
663 T_LBRACE { 662 T_LBRACE {
664 symtyp = FVFT; 663 symtyp = FVFT;
665 } member_declaration_list_semi T_RBRACE { 664 } member_declaration_list_semi T_RBRACE {
666 $$ = $3; 665 $$ = $3;
667 } 666 }
668 ; 667 ;
669 668
670member_declaration_list_semi: 669member_declaration_list_semi:
671 /* empty */ { 670 /* empty */ {
672 $$ = NULL; 671 $$ = NULL;
673 } 672 }
674 | member_declaration_list T_SEMI 673 | member_declaration_list T_SEMI
675 | member_declaration_list { 674 | member_declaration_list {
676 if (sflag) { 675 if (sflag) {
677 /* syntax req. ';' after last struct/union member */ 676 /* syntax req. ';' after last struct/union member */
678 error(66); 677 error(66);
679 } else { 678 } else {
680 /* syntax req. ';' after last struct/union member */ 679 /* syntax req. ';' after last struct/union member */
681 warning(66); 680 warning(66);
682 } 681 }
683 $$ = $1; 682 $$ = $1;
684 } 683 }
685 ; 684 ;
686 685
687member_declaration_list: 686member_declaration_list:
688 member_declaration 687 member_declaration
689 | member_declaration_list T_SEMI member_declaration { 688 | member_declaration_list T_SEMI member_declaration {
690 $$ = lnklst($1, $3); 689 $$ = lnklst($1, $3);
691 } 690 }
692 ; 691 ;
693 692
694member_declaration: 693member_declaration:
695 noclass_declmods deftyp { 694 noclass_declmods deftyp {
696 /* too late, i know, but getsym() compensates it */ 695 /* too late, i know, but getsym() compensates it */
697 symtyp = FMEMBER; 696 symtyp = FMEMBER;
698 } notype_member_decls type_attribute_opt { 697 } notype_member_decls type_attribute_opt {
699 symtyp = FVFT; 698 symtyp = FVFT;
700 $$ = $4; 699 $$ = $4;
701 } 700 }
702 | noclass_declspecs deftyp { 701 | noclass_declspecs deftyp {
703 symtyp = FMEMBER; 702 symtyp = FMEMBER;
704 } type_member_decls type_attribute_opt { 703 } type_member_decls type_attribute_opt {
705 symtyp = FVFT; 704 symtyp = FVFT;
706 $$ = $4; 705 $$ = $4;
707 } 706 }
708 | noclass_declmods deftyp type_attribute_opt { 707 | noclass_declmods deftyp type_attribute_opt {
709 symtyp = FVFT; 708 symtyp = FVFT;
710 /* struct or union member must be named */ 709 /* struct or union member must be named */
711 if (!Sflag) 710 if (!Sflag)
712 /* anonymous struct/union members is a C9X feature */ 711 /* anonymous struct/union members is a C9X feature */
713 warning(49); 712 warning(49);
714 /* add all the members of the anonymous struct/union */ 713 /* add all the members of the anonymous struct/union */
715 lint_assert(is_struct_or_union(dcs->d_type->t_tspec)); 714 lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
716 $$ = dcs->d_type->t_str->sou_first_member; 715 $$ = dcs->d_type->t_str->sou_first_member;
717 anonymize($$); 716 anonymize($$);
718 } 717 }
719 | noclass_declspecs deftyp type_attribute_opt { 718 | noclass_declspecs deftyp type_attribute_opt {
720 symtyp = FVFT; 719 symtyp = FVFT;
721 /* struct or union member must be named */ 720 /* struct or union member must be named */
722 if (!Sflag) 721 if (!Sflag)
723 /* anonymous struct/union members is a C9X feature */ 722 /* anonymous struct/union members is a C9X feature */
724 warning(49); 723 warning(49);
725 if (is_struct_or_union(dcs->d_type->t_tspec)) { 724 if (is_struct_or_union(dcs->d_type->t_tspec)) {
726 $$ = dcs->d_type->t_str->sou_first_member; 725 $$ = dcs->d_type->t_str->sou_first_member;
727 /* add all the members of the anonymous struct/union */ 726 /* add all the members of the anonymous struct/union */
728 anonymize($$); 727 anonymize($$);
729 } else { 728 } else {
730 /* syntax error '%s' */ 729 /* syntax error '%s' */
731 error(249, "unnamed member"); 730 error(249, "unnamed member");
732 $$ = NULL; 731 $$ = NULL;
733 } 732 }
734 } 733 }
735 | error { 734 | error {
736 symtyp = FVFT; 735 symtyp = FVFT;
737 $$ = NULL; 736 $$ = NULL;
738 } 737 }
739 ; 738 ;
740 739
741/* 740/*
742 * XXX: shift/reduce conflict, caused by: 741 * XXX: shift/reduce conflict, caused by:
743 * type_attribute noclass_declspecs 742 * type_attribute noclass_declspecs
744 * noclass_declspecs type_attribute 743 * noclass_declspecs type_attribute
745 */ 744 */
746noclass_declspecs: 745noclass_declspecs:
747 clrtyp_typespec { 746 clrtyp_typespec {
748 add_type($1); 747 add_type($1);
749 } 748 }
750 | type_attribute noclass_declspecs 749 | type_attribute noclass_declspecs
751 | noclass_declmods typespec { 750 | noclass_declmods typespec {
752 add_type($2); 751 add_type($2);
753 } 752 }
754 | noclass_declspecs T_QUAL { 753 | noclass_declspecs T_QUAL {
755 add_qualifier($2); 754 add_qualifier($2);
756 } 755 }
757 | noclass_declspecs notype_typespec { 756 | noclass_declspecs notype_typespec {
758 add_type($2); 757 add_type($2);
759 } 758 }
760 | noclass_declspecs type_attribute 759 | noclass_declspecs type_attribute
761 ; 760 ;
762 761
763noclass_declmods: 762noclass_declmods:
764 clrtyp T_QUAL { 763 clrtyp T_QUAL {
765 add_qualifier($2); 764 add_qualifier($2);
766 } 765 }
767 | noclass_declmods T_QUAL { 766 | noclass_declmods T_QUAL {
768 add_qualifier($2); 767 add_qualifier($2);
769 } 768 }
770 ; 769 ;
771 770
772notype_member_decls: 771notype_member_decls:
773 notype_member_decl { 772 notype_member_decl {
774 $$ = declarator_1_struct_union($1); 773 $$ = declarator_1_struct_union($1);
775 } 774 }
776 | notype_member_decls { 775 | notype_member_decls {
777 symtyp = FMEMBER; 776 symtyp = FMEMBER;
778 } T_COMMA type_member_decl { 777 } T_COMMA type_member_decl {
779 $$ = lnklst($1, declarator_1_struct_union($4)); 778 $$ = lnklst($1, declarator_1_struct_union($4));
780 } 779 }
781 ; 780 ;
782 781
783type_member_decls: 782type_member_decls:
784 type_member_decl { 783 type_member_decl {
785 $$ = declarator_1_struct_union($1); 784 $$ = declarator_1_struct_union($1);
786 } 785 }
787 | type_member_decls { 786 | type_member_decls {
788 symtyp = FMEMBER; 787 symtyp = FMEMBER;
789 } T_COMMA type_member_decl { 788 } T_COMMA type_member_decl {
790 $$ = lnklst($1, declarator_1_struct_union($4)); 789 $$ = lnklst($1, declarator_1_struct_union($4));
791 } 790 }
792 ; 791 ;
793 792
794notype_member_decl: 793notype_member_decl:
795 notype_decl 794 notype_decl
796 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */ 795 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */
797 $$ = bitfield($1, to_int_constant($3, true)); 796 $$ = bitfield($1, to_int_constant($3, true));
798 } 797 }
799 | { 798 | {
800 symtyp = FVFT; 799 symtyp = FVFT;
801 } T_COLON constant_expr { /* C99 6.7.2.1 */ 800 } T_COLON constant_expr { /* C99 6.7.2.1 */
802 $$ = bitfield(NULL, to_int_constant($3, true)); 801 $$ = bitfield(NULL, to_int_constant($3, true));
803 } 802 }
804 ; 803 ;
805 804
806type_member_decl: 805type_member_decl:
807 type_decl 806 type_decl
808 | type_decl T_COLON constant_expr { 807 | type_decl T_COLON constant_expr {
809 $$ = bitfield($1, to_int_constant($3, true)); 808 $$ = bitfield($1, to_int_constant($3, true));
810 } 809 }
811 | { 810 | {
812 symtyp = FVFT; 811 symtyp = FVFT;
813 } T_COLON constant_expr { 812 } T_COLON constant_expr {
814 $$ = bitfield(NULL, to_int_constant($3, true)); 813 $$ = bitfield(NULL, to_int_constant($3, true));
815 } 814 }
816 ; 815 ;
817 816
818enum_spec: 817enum_spec:
819 enum enum_tag { 818 enum enum_tag {
820 $$ = mktag($2, ENUM, false, false); 819 $$ = mktag($2, ENUM, false, false);
821 } 820 }
822 | enum enum_tag { 821 | enum enum_tag {
823 dcs->d_tagtyp = mktag($2, ENUM, true, false); 822 dcs->d_tagtyp = mktag($2, ENUM, true, false);
824 } enum_declaration { 823 } enum_declaration {
825 $$ = complete_tag_enum(dcs->d_tagtyp, $4); 824 $$ = complete_tag_enum(dcs->d_tagtyp, $4);
826 } 825 }
827 | enum { 826 | enum {
828 dcs->d_tagtyp = mktag(NULL, ENUM, true, false); 827 dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
829 } enum_declaration { 828 } enum_declaration {
830 $$ = complete_tag_enum(dcs->d_tagtyp, $3); 829 $$ = complete_tag_enum(dcs->d_tagtyp, $3);
831 } 830 }
832 | enum error { 831 | enum error {
833 symtyp = FVFT; 832 symtyp = FVFT;
834 $$ = gettyp(INT); 833 $$ = gettyp(INT);
835 } 834 }
836 ; 835 ;
837 836
838enum: 837enum:
839 T_ENUM { 838 T_ENUM {
840 symtyp = FTAG; 839 symtyp = FTAG;
841 begin_declaration_level(CTCONST); 840 begin_declaration_level(CTCONST);
842 } 841 }
843 ; 842 ;
844 843
845enum_tag: 844enum_tag:
846 identifier { 845 identifier {
847 $$ = getsym($1); 846 $$ = getsym($1);
848 } 847 }
849 ; 848 ;
850 849
851enum_declaration: 850enum_declaration:
852 T_LBRACE { 851 T_LBRACE {
853 symtyp = FVFT; 852 symtyp = FVFT;
854 enumval = 0; 853 enumval = 0;
855 } enumerator_list enumerator_list_comma_opt T_RBRACE { 854 } enumerator_list enumerator_list_comma_opt T_RBRACE {
856 $$ = $3; 855 $$ = $3;
857 } 856 }
858 ; 857 ;
859 858
860enumerator_list: /* C99 6.7.2.2 */ 859enumerator_list: /* C99 6.7.2.2 */
861 enumerator 860 enumerator
862 | enumerator_list T_COMMA enumerator { 861 | enumerator_list T_COMMA enumerator {
863 $$ = lnklst($1, $3); 862 $$ = lnklst($1, $3);
864 } 863 }
865 | error { 864 | error {
866 $$ = NULL; 865 $$ = NULL;
867 } 866 }
868 ; 867 ;
869 868
870enumerator_list_comma_opt: 869enumerator_list_comma_opt:
871 /* empty */ 870 /* empty */
872 | T_COMMA { 871 | T_COMMA {
873 if (sflag) { 872 if (sflag) {
874 /* trailing ',' prohibited in enum declaration */ 873 /* trailing ',' prohibited in enum declaration */
875 error(54); 874 error(54);
876 } else { 875 } else {
877 /* trailing ',' prohibited in enum declaration */ 876 /* trailing ',' prohibited in enum declaration */
878 c99ism(54); 877 c99ism(54);
879 } 878 }
880 } 879 }
881 ; 880 ;
882 881
883enumerator: /* C99 6.7.2.2 */ 882enumerator: /* C99 6.7.2.2 */
884 enumeration_constant { 883 enumeration_constant {
885 $$ = enumeration_constant($1, enumval, true); 884 $$ = enumeration_constant($1, enumval, true);
886 } 885 }
887 | enumeration_constant T_ASSIGN constant_expr { 886 | enumeration_constant T_ASSIGN constant_expr {
888 $$ = enumeration_constant($1, to_int_constant($3, true), false); 887 $$ = enumeration_constant($1, to_int_constant($3, true), false);
889 } 888 }
890 ; 889 ;
891 890
892enumeration_constant: /* C99 6.4.4.3 */ 891enumeration_constant: /* C99 6.4.4.3 */
893 identifier { 892 identifier {
894 $$ = getsym($1); 893 $$ = getsym($1);
895 } 894 }
896 ; 895 ;
897 896
898 897
899/* 898/*
900 * For an explanation of 'notype' in the following rules, see the Bison 899 * For an explanation of 'notype' in the following rules, see the Bison
901 * manual, section 7.1 "Semantic Info in Token Kinds". 900 * manual, section 7.1 "Semantic Info in Token Kinds".
902 */ 901 */
903 902
904notype_init_decls: 903notype_init_decls:
905 notype_init_decl 904 notype_init_decl
906 | notype_init_decls T_COMMA type_init_decl 905 | notype_init_decls T_COMMA type_init_decl
907 ; 906 ;
908 907
909type_init_decls: 908type_init_decls:
910 type_init_decl 909 type_init_decl
911 | type_init_decls T_COMMA type_init_decl 910 | type_init_decls T_COMMA type_init_decl
912 ; 911 ;
913 912
914notype_init_decl: 913notype_init_decl:
915 notype_decl asm_or_symbolrename_opt { 914 notype_decl asm_or_symbolrename_opt {
916 cgram_declare($1, false, $2); 915 cgram_declare($1, false, $2);
917 check_size($1); 916 check_size($1);
918 } 917 }
919 | notype_decl asm_or_symbolrename_opt { 918 | notype_decl asm_or_symbolrename_opt {
920 begin_initialization($1); 919 begin_initialization($1);
921 cgram_declare($1, true, $2); 920 cgram_declare($1, true, $2);
922 } T_ASSIGN initializer { 921 } T_ASSIGN initializer {
923 check_size($1); 922 check_size($1);
924 end_initialization(); 923 end_initialization();
925 } 924 }
926 ; 925 ;
927 926
928type_init_decl: 927type_init_decl:
929 type_decl asm_or_symbolrename_opt { 928 type_decl asm_or_symbolrename_opt {
930 cgram_declare($1, false, $2); 929 cgram_declare($1, false, $2);
931 check_size($1); 930 check_size($1);
932 } 931 }
933 | type_decl asm_or_symbolrename_opt { 932 | type_decl asm_or_symbolrename_opt {
934 begin_initialization($1); 933 begin_initialization($1);
935 cgram_declare($1, true, $2); 934 cgram_declare($1, true, $2);
936 } T_ASSIGN initializer { 935 } T_ASSIGN initializer {
937 check_size($1); 936 check_size($1);
938 end_initialization(); 937 end_initialization();
939 } 938 }
940 ; 939 ;
941 940
942notype_decl: 941notype_decl:
943 notype_direct_decl 942 notype_direct_decl
944 | pointer notype_direct_decl { 943 | pointer notype_direct_decl {
945 $$ = add_pointer($2, $1); 944 $$ = add_pointer($2, $1);
946 } 945 }
947 ; 946 ;
948 947
949type_decl: 948type_decl:
950 type_direct_decl 949 type_direct_decl
951 | pointer type_direct_decl { 950 | pointer type_direct_decl {
952 $$ = add_pointer($2, $1); 951 $$ = add_pointer($2, $1);
953 } 952 }
954 ; 953 ;
955 954
956/* 955/*
957 * XXX: shift/reduce conflict, caused by: 956 * XXX: shift/reduce conflict, caused by:
958 * type_attribute notype_direct_decl 957 * type_attribute notype_direct_decl
959 * notype_direct_decl type_attribute 958 * notype_direct_decl type_attribute
960 */ 959 */
961notype_direct_decl: 960notype_direct_decl:
962 T_NAME { 961 T_NAME {
963 $$ = declarator_name(getsym($1)); 962 $$ = declarator_name(getsym($1));
964 } 963 }
965 | T_LPAREN type_decl T_RPAREN { 964 | T_LPAREN type_decl T_RPAREN {
966 $$ = $2; 965 $$ = $2;
967 } 966 }
968 | type_attribute notype_direct_decl { 967 | type_attribute notype_direct_decl {
969 $$ = $2; 968 $$ = $2;
970 } 969 }
971 | notype_direct_decl T_LBRACK T_RBRACK { 970 | notype_direct_decl T_LBRACK T_RBRACK {
972 $$ = add_array($1, false, 0); 971 $$ = add_array($1, false, 0);
973 } 972 }
974 | notype_direct_decl T_LBRACK array_size T_RBRACK { 973 | notype_direct_decl T_LBRACK array_size T_RBRACK {
975 $$ = add_array($1, true, to_int_constant($3, false)); 974 $$ = add_array($1, true, to_int_constant($3, false));
976 } 975 }
977 | notype_direct_decl param_list asm_or_symbolrename_opt { 976 | notype_direct_decl param_list asm_or_symbolrename_opt {
978 $$ = add_function(symbolrename($1, $3), $2); 977 $$ = add_function(symbolrename($1, $3), $2);
979 end_declaration_level(); 978 end_declaration_level();
980 block_level--; 979 block_level--;
981 } 980 }
982 | notype_direct_decl type_attribute 981 | notype_direct_decl type_attribute
983 ; 982 ;
984 983
985/* 984/*
986 * XXX: shift/reduce conflict, caused by: 985 * XXX: shift/reduce conflict, caused by:
987 * type_attribute type_direct_decl 986 * type_attribute type_direct_decl
988 * type_direct_decl type_attribute 987 * type_direct_decl type_attribute
989 */ 988 */
990type_direct_decl: 989type_direct_decl:
991 identifier { 990 identifier {
992 $$ = declarator_name(getsym($1)); 991 $$ = declarator_name(getsym($1));
993 } 992 }
994 | T_LPAREN type_decl T_RPAREN { 993 | T_LPAREN type_decl T_RPAREN {
995 $$ = $2; 994 $$ = $2;
996 } 995 }
997 | type_attribute type_direct_decl { 996 | type_attribute type_direct_decl {
998 $$ = $2; 997 $$ = $2;
999 } 998 }
1000 | type_direct_decl T_LBRACK T_RBRACK { 999 | type_direct_decl T_LBRACK T_RBRACK {
1001 $$ = add_array($1, false, 0); 1000 $$ = add_array($1, false, 0);
1002 } 1001 }
1003 | type_direct_decl T_LBRACK array_size T_RBRACK { 1002 | type_direct_decl T_LBRACK array_size T_RBRACK {
1004 $$ = add_array($1, true, to_int_constant($3, false)); 1003 $$ = add_array($1, true, to_int_constant($3, false));
1005 } 1004 }
1006 | type_direct_decl param_list asm_or_symbolrename_opt { 1005 | type_direct_decl param_list asm_or_symbolrename_opt {
1007 $$ = add_function(symbolrename($1, $3), $2); 1006 $$ = add_function(symbolrename($1, $3), $2);
1008 end_declaration_level(); 1007 end_declaration_level();
1009 block_level--; 1008 block_level--;
1010 } 1009 }
1011 | type_direct_decl type_attribute 1010 | type_direct_decl type_attribute
1012 ; 1011 ;
1013 1012
1014/* 1013/*
1015 * The two distinct rules type_param_decl and notype_param_decl avoid a 1014 * The two distinct rules type_param_decl and notype_param_decl avoid a
1016 * conflict in argument lists. A typename enclosed in parentheses is always 1015 * conflict in argument lists. A typename enclosed in parentheses is always
1017 * treated as a typename, not an argument name. For example, after 1016 * treated as a typename, not an argument name. For example, after
1018 * "typedef double a;", the declaration "f(int (a));" is interpreted as 1017 * "typedef double a;", the declaration "f(int (a));" is interpreted as
1019 * "f(int (double));", not "f(int a);". 1018 * "f(int (double));", not "f(int a);".
1020 */ 1019 */
1021type_param_decl: 1020type_param_decl:
1022 direct_param_decl 1021 direct_param_decl
1023 | pointer direct_param_decl { 1022 | pointer direct_param_decl {
1024 $$ = add_pointer($2, $1); 1023 $$ = add_pointer($2, $1);
1025 } 1024 }
1026 ; 1025 ;
1027 1026
1028notype_param_decl: 1027notype_param_decl:
1029 direct_notype_param_decl 1028 direct_notype_param_decl
1030 | pointer direct_notype_param_decl { 1029 | pointer direct_notype_param_decl {
1031 $$ = add_pointer($2, $1); 1030 $$ = add_pointer($2, $1);
1032 } 1031 }
1033 ; 1032 ;
1034 1033
1035direct_param_decl: 1034direct_param_decl:
1036 identifier type_attribute_list_opt { 1035 identifier type_attribute_list_opt {
1037 $$ = declarator_name(getsym($1)); 1036 $$ = declarator_name(getsym($1));
1038 } 1037 }
1039 | T_LPAREN notype_param_decl T_RPAREN { 1038 | T_LPAREN notype_param_decl T_RPAREN {
1040 $$ = $2; 1039 $$ = $2;
1041 } 1040 }
1042 | direct_param_decl T_LBRACK T_RBRACK { 1041 | direct_param_decl T_LBRACK T_RBRACK {
1043 $$ = add_array($1, false, 0); 1042 $$ = add_array($1, false, 0);
1044 } 1043 }
1045 | direct_param_decl T_LBRACK array_size T_RBRACK { 1044 | direct_param_decl T_LBRACK array_size T_RBRACK {
1046 $$ = add_array($1, true, to_int_constant($3, false)); 1045 $$ = add_array($1, true, to_int_constant($3, false));
1047 } 1046 }
1048 | direct_param_decl param_list asm_or_symbolrename_opt { 1047 | direct_param_decl param_list asm_or_symbolrename_opt {
1049 $$ = add_function(symbolrename($1, $3), $2); 1048 $$ = add_function(symbolrename($1, $3), $2);
1050 end_declaration_level(); 1049 end_declaration_level();
1051 block_level--; 1050 block_level--;
1052 } 1051 }
1053 ; 1052 ;
1054 1053
1055direct_notype_param_decl: 1054direct_notype_param_decl:
1056 identifier /* XXX: missing type_attribute_list_opt? */ { 1055 identifier /* XXX: missing type_attribute_list_opt? */ {
1057 $$ = declarator_name(getsym($1)); 1056 $$ = declarator_name(getsym($1));
1058 } 1057 }
1059 | T_LPAREN notype_param_decl T_RPAREN { 1058 | T_LPAREN notype_param_decl T_RPAREN {
1060 $$ = $2; 1059 $$ = $2;
1061 } 1060 }
1062 | direct_notype_param_decl T_LBRACK T_RBRACK { 1061 | direct_notype_param_decl T_LBRACK T_RBRACK {
1063 $$ = add_array($1, false, 0); 1062 $$ = add_array($1, false, 0);
1064 } 1063 }
1065 | direct_notype_param_decl T_LBRACK array_size T_RBRACK { 1064 | direct_notype_param_decl T_LBRACK array_size T_RBRACK {
1066 $$ = add_array($1, true, to_int_constant($3, false)); 1065 $$ = add_array($1, true, to_int_constant($3, false));
1067 } 1066 }
1068 | direct_notype_param_decl param_list asm_or_symbolrename_opt { 1067 | direct_notype_param_decl param_list asm_or_symbolrename_opt {
1069 $$ = add_function(symbolrename($1, $3), $2); 1068 $$ = add_function(symbolrename($1, $3), $2);
1070 end_declaration_level(); 1069 end_declaration_level();
1071 block_level--; 1070 block_level--;
1072 } 1071 }
1073 ; 1072 ;
1074 1073
1075pointer: /* C99 6.7.5 */ 1074pointer: /* C99 6.7.5 */
1076 asterisk type_qualifier_list_opt { 1075 asterisk type_qualifier_list_opt {
1077 $$ = merge_qualified_pointer($1, $2); 1076 $$ = merge_qualified_pointer($1, $2);
1078 } 1077 }
1079 | asterisk type_qualifier_list_opt pointer { 1078 | asterisk type_qualifier_list_opt pointer {
1080 $$ = merge_qualified_pointer($1, $2); 1079 $$ = merge_qualified_pointer($1, $2);
1081 $$ = merge_qualified_pointer($$, $3); 1080 $$ = merge_qualified_pointer($$, $3);
1082 } 1081 }
1083 ; 1082 ;
1084 1083
1085asterisk: 1084asterisk:
1086 T_ASTERISK { 1085 T_ASTERISK {
1087 $$ = xcalloc(1, sizeof(*$$)); 1086 $$ = xcalloc(1, sizeof(*$$));
1088 $$->p_pointer = true; 1087 $$->p_pointer = true;
1089 } 1088 }
1090 ; 1089 ;
1091 1090
1092type_qualifier_list_opt: 1091type_qualifier_list_opt:
1093 /* empty */ { 1092 /* empty */ {
1094 $$ = NULL; 1093 $$ = NULL;
1095 } 1094 }
1096 | type_qualifier_list 1095 | type_qualifier_list
1097 ; 1096 ;
1098 1097
1099type_qualifier_list: /* C99 6.7.5 */ 1098type_qualifier_list: /* C99 6.7.5 */
1100 type_qualifier 1099 type_qualifier
1101 | type_qualifier_list type_qualifier { 1100 | type_qualifier_list type_qualifier {
1102 $$ = merge_qualified_pointer($1, $2); 1101 $$ = merge_qualified_pointer($1, $2);
1103 } 1102 }
1104 ; 1103 ;
1105 1104
1106type_qualifier: 1105type_qualifier:
1107 T_QUAL { 1106 T_QUAL {
1108 $$ = xcalloc(1, sizeof(*$$)); 1107 $$ = xcalloc(1, sizeof(*$$));
1109 if ($1 == CONST) { 1108 if ($1 == CONST) {
1110 $$->p_const = true; 1109 $$->p_const = true;
1111 } else if ($1 == VOLATILE) { 1110 } else if ($1 == VOLATILE) {
1112 $$->p_volatile = true; 1111 $$->p_volatile = true;
1113 } else { 1112 } else {
1114 lint_assert($1 == RESTRICT || $1 == THREAD); 1113 lint_assert($1 == RESTRICT || $1 == THREAD);
1115 } 1114 }
1116 } 1115 }
1117 ; 1116 ;
1118 1117
1119align_as: /* See alignment-specifier in C11 6.7.5 */ 1118align_as: /* See alignment-specifier in C11 6.7.5 */
1120 typespec 1119 typespec
1121 | constant_expr 1120 | constant_expr
1122 ; 1121 ;
1123 1122
1124param_list: 1123param_list:
1125 id_list_lparen identifier_list T_RPAREN { 1124 id_list_lparen identifier_list T_RPAREN {
1126 $$ = $2; 1125 $$ = $2;
1127 } 1126 }
1128 | abstract_decl_param_list 1127 | abstract_decl_param_list
1129 ; 1128 ;
1130 1129
1131id_list_lparen: 1130id_list_lparen:
1132 T_LPAREN { 1131 T_LPAREN {
1133 block_level++; 1132 block_level++;
1134 begin_declaration_level(PROTO_ARG); 1133 begin_declaration_level(PROTO_ARG);
1135 } 1134 }
1136 ; 1135 ;
1137 1136
1138identifier_list: 1137identifier_list:
1139 T_NAME { 1138 T_NAME {
1140 $$ = old_style_function_name(getsym($1)); 1139 $$ = old_style_function_name(getsym($1));
1141 } 1140 }
1142 | identifier_list T_COMMA T_NAME { 1141 | identifier_list T_COMMA T_NAME {
1143 $$ = lnklst($1, old_style_function_name(getsym($3))); 1142 $$ = lnklst($1, old_style_function_name(getsym($3)));
1144 } 1143 }
1145 | identifier_list error 1144 | identifier_list error
1146 ; 1145 ;
1147 1146
1148abstract_decl_param_list: 1147abstract_decl_param_list:
1149 abstract_decl_lparen T_RPAREN type_attribute_opt { 1148 abstract_decl_lparen T_RPAREN type_attribute_opt {
1150 $$ = NULL; 1149 $$ = NULL;
1151 } 1150 }
1152 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { 1151 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1153 dcs->d_proto = true; 1152 dcs->d_proto = true;
1154 $$ = $2; 1153 $$ = $2;
1155 } 1154 }
1156 | abstract_decl_lparen error T_RPAREN type_attribute_opt { 1155 | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1157 $$ = NULL; 1156 $$ = NULL;
1158 } 1157 }
1159 ; 1158 ;
1160 1159
1161abstract_decl_lparen: 1160abstract_decl_lparen:
1162 T_LPAREN { 1161 T_LPAREN {
1163 block_level++; 1162 block_level++;
1164 begin_declaration_level(PROTO_ARG); 1163 begin_declaration_level(PROTO_ARG);
1165 } 1164 }
1166 ; 1165 ;
1167 1166
1168vararg_parameter_type_list: 1167vararg_parameter_type_list:
1169 parameter_type_list 1168 parameter_type_list
1170 | parameter_type_list T_COMMA T_ELLIPSIS { 1169 | parameter_type_list T_COMMA T_ELLIPSIS {
1171 dcs->d_vararg = true; 1170 dcs->d_vararg = true;
1172 $$ = $1; 1171 $$ = $1;
1173 } 1172 }
1174 | T_ELLIPSIS { 1173 | T_ELLIPSIS {
1175 if (sflag) { 1174 if (sflag) {
1176 /* ANSI C requires formal parameter before '...' */ 1175 /* ANSI C requires formal parameter before '...' */
1177 error(84); 1176 error(84);
1178 } else if (!tflag) { 1177 } else if (!tflag) {
1179 /* ANSI C requires formal parameter before '...' */ 1178 /* ANSI C requires formal parameter before '...' */
1180 warning(84); 1179 warning(84);
1181 } 1180 }
1182 dcs->d_vararg = true; 1181 dcs->d_vararg = true;
1183 $$ = NULL; 1182 $$ = NULL;
1184 } 1183 }
1185 ; 1184 ;
1186 1185
1187parameter_type_list: 1186parameter_type_list:
1188 parameter_declaration 1187 parameter_declaration
1189 | parameter_type_list T_COMMA parameter_declaration { 1188 | parameter_type_list T_COMMA parameter_declaration {
1190 $$ = lnklst($1, $3); 1189 $$ = lnklst($1, $3);
1191 } 1190 }
1192 ; 1191 ;
1193 1192
1194/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ 1193/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1195parameter_declaration: 1194parameter_declaration:
1196 declmods deftyp { 1195 declmods deftyp {
1197 $$ = declare_argument(abstract_name(), false); 1196 $$ = declare_argument(abstract_name(), false);
1198 } 1197 }
1199 | declaration_specifiers deftyp { 1198 | declaration_specifiers deftyp {
1200 $$ = declare_argument(abstract_name(), false); 1199 $$ = declare_argument(abstract_name(), false);
1201 } 1200 }
1202 | declmods deftyp notype_param_decl { 1201 | declmods deftyp notype_param_decl {
1203 $$ = declare_argument($3, false); 1202 $$ = declare_argument($3, false);
1204 } 1203 }
1205 | declaration_specifiers deftyp type_param_decl { 1204 | declaration_specifiers deftyp type_param_decl {
1206 $$ = declare_argument($3, false); 1205 $$ = declare_argument($3, false);
1207 } 1206 }
1208 | declmods deftyp abstract_declarator { 1207 | declmods deftyp abstract_declarator {
1209 $$ = declare_argument($3, false); 1208 $$ = declare_argument($3, false);
1210 } 1209 }
1211 | declaration_specifiers deftyp abstract_declarator { 1210 | declaration_specifiers deftyp abstract_declarator {
1212 $$ = declare_argument($3, false); 1211 $$ = declare_argument($3, false);
1213 } 1212 }
1214 ; 1213 ;
1215 1214
1216asm_or_symbolrename_opt: /* expect only one */ 1215asm_or_symbolrename_opt: /* expect only one */
1217 /* empty */ { 1216 /* empty */ {
1218 $$ = NULL; 1217 $$ = NULL;
1219 } 1218 }
1220 | T_ASM T_LPAREN T_STRING T_RPAREN { 1219 | T_ASM T_LPAREN T_STRING T_RPAREN {
1221 freeyyv(&$3, T_STRING); 1220 freeyyv(&$3, T_STRING);
1222 $$ = NULL; 1221 $$ = NULL;
1223 } 1222 }
1224 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { 1223 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
1225 $$ = $3; 1224 $$ = $3;
1226 } 1225 }
1227 ; 1226 ;
1228 1227
1229initializer: /* C99 6.7.8 "Initialization" */ 1228initializer: /* C99 6.7.8 "Initialization" */
1230 expr %prec T_COMMA { 1229 expr %prec T_COMMA {
1231 init_expr($1); 1230 init_expr($1);
1232 } 1231 }
1233 | init_lbrace init_rbrace { 1232 | init_lbrace init_rbrace {
1234 /* XXX: Empty braces are not covered by C99 6.7.8. */ 1233 /* XXX: Empty braces are not covered by C99 6.7.8. */
1235 } 1234 }
1236 | init_lbrace initializer_list comma_opt init_rbrace 1235 | init_lbrace initializer_list comma_opt init_rbrace
1237 | error 1236 | error
1238 ; 1237 ;
1239 1238
1240initializer_list: /* C99 6.7.8 "Initialization" */ 1239initializer_list: /* C99 6.7.8 "Initialization" */
1241 initializer_list_item 1240 initializer_list_item
1242 | initializer_list T_COMMA initializer_list_item 1241 | initializer_list T_COMMA initializer_list_item
1243 ; 1242 ;
1244 1243
1245initializer_list_item: 1244initializer_list_item:
1246 designation initializer 1245 designation initializer
1247 | initializer 1246 | initializer
1248 ; 1247 ;
1249 1248
1250designation: /* C99 6.7.8 "Initialization" */ 1249designation: /* C99 6.7.8 "Initialization" */
1251 designator_list T_ASSIGN 1250 designator_list T_ASSIGN
1252 | identifier T_COLON { 1251 | identifier T_COLON {
1253 /* GCC style struct or union member name in initializer */ 1252 /* GCC style struct or union member name in initializer */
1254 gnuism(315); 1253 gnuism(315);
1255 add_designator_member($1); 1254 add_designator_member($1);
1256 } 1255 }
1257 ; 1256 ;
1258 1257
1259designator_list: /* C99 6.7.8 "Initialization" */ 1258designator_list: /* C99 6.7.8 "Initialization" */
1260 designator 1259 designator
1261 | designator_list designator 1260 | designator_list designator
1262 ; 1261 ;
1263 1262
1264designator: /* C99 6.7.8 "Initialization" */ 1263designator: /* C99 6.7.8 "Initialization" */
1265 T_LBRACK range T_RBRACK { 1264 T_LBRACK range T_RBRACK {
1266 add_designator_subscript($2); 1265 add_designator_subscript($2);
1267 if (!Sflag) 1266 if (!Sflag)
1268 /* array initializer with des.s is a C9X feature */ 1267 /* array initializer with des.s is a C9X feature */
1269 warning(321); 1268 warning(321);
1270 } 1269 }
1271 | T_POINT identifier { 1270 | T_POINT identifier {
1272 if (!Sflag) 1271 if (!Sflag)
1273 /* struct or union member name in initializer is ... */ 1272 /* struct or union member name in initializer is ... */
1274 warning(313); 1273 warning(313);
1275 add_designator_member($2); 1274 add_designator_member($2);
1276 } 1275 }
1277 ; 1276 ;
1278 1277
1279range: 1278range:
1280 constant_expr { 1279 constant_expr {
1281 $$.lo = to_int_constant($1, true); 1280 $$.lo = to_int_constant($1, true);
1282 $$.hi = $$.lo; 1281 $$.hi = $$.lo;
1283 } 1282 }
1284 | constant_expr T_ELLIPSIS constant_expr { 1283 | constant_expr T_ELLIPSIS constant_expr {
1285 $$.lo = to_int_constant($1, true); 1284 $$.lo = to_int_constant($1, true);
1286 $$.hi = to_int_constant($3, true); 1285 $$.hi = to_int_constant($3, true);
1287 /* initialization with '[a...b]' is a GCC extension */ 1286 /* initialization with '[a...b]' is a GCC extension */
1288 gnuism(340); 1287 gnuism(340);
1289 } 1288 }
1290 ; 1289 ;
1291 1290
1292init_lbrace: 1291init_lbrace:
1293 T_LBRACE { 1292 T_LBRACE {
1294 init_lbrace(); 1293 init_lbrace();
1295 } 1294 }
1296 ; 1295 ;
1297 1296
1298init_rbrace: 1297init_rbrace:
1299 T_RBRACE { 1298 T_RBRACE {
1300 init_rbrace(); 1299 init_rbrace();
1301 } 1300 }
1302 ; 1301 ;
1303 1302
1304type_name: /* C99 6.7.6 */ 1303type_name: /* C99 6.7.6 */
1305 { 1304 {
1306 begin_declaration_level(ABSTRACT); 1305 begin_declaration_level(ABSTRACT);
1307 } abstract_declaration { 1306 } abstract_declaration {
1308 end_declaration_level(); 1307 end_declaration_level();
1309 $$ = $2->s_type; 1308 $$ = $2->s_type;
1310 } 1309 }
1311 ; 1310 ;
1312 1311
1313abstract_declaration: 1312abstract_declaration:
1314 noclass_declmods deftyp { 1313 noclass_declmods deftyp {
1315 $$ = declare_1_abstract(abstract_name()); 1314 $$ = declare_1_abstract(abstract_name());
1316 } 1315 }
1317 | noclass_declspecs deftyp { 1316 | noclass_declspecs deftyp {
1318 $$ = declare_1_abstract(abstract_name()); 1317 $$ = declare_1_abstract(abstract_name());
1319 } 1318 }
1320 | noclass_declmods deftyp abstract_declarator { 1319 | noclass_declmods deftyp abstract_declarator {
1321 $$ = declare_1_abstract($3); 1320 $$ = declare_1_abstract($3);
1322 } 1321 }
1323 | noclass_declspecs deftyp abstract_declarator { 1322 | noclass_declspecs deftyp abstract_declarator {
1324 $$ = declare_1_abstract($3); 1323 $$ = declare_1_abstract($3);
1325 } 1324 }
1326 ; 1325 ;
1327 1326
1328abstract_declarator: /* C99 6.7.6 */ 1327abstract_declarator: /* C99 6.7.6 */
1329 pointer { 1328 pointer {
1330 $$ = add_pointer(abstract_name(), $1); 1329 $$ = add_pointer(abstract_name(), $1);
1331 } 1330 }
1332 | direct_abstract_declarator 1331 | direct_abstract_declarator
1333 | pointer direct_abstract_declarator { 1332 | pointer direct_abstract_declarator {
1334 $$ = add_pointer($2, $1); 1333 $$ = add_pointer($2, $1);
1335 } 1334 }
1336 | T_TYPEOF term { /* GCC extension */ 1335 | T_TYPEOF term { /* GCC extension */
1337 $$ = mktempsym($2->tn_type); 1336 $$ = mktempsym($2->tn_type);
1338 } 1337 }
1339 ; 1338 ;
1340 1339
1341/* 1340/*
1342 * XXX: shift/reduce conflict, caused by: 1341 * XXX: shift/reduce conflict, caused by:
1343 * type_attribute direct_abstract_declarator 1342 * type_attribute direct_abstract_declarator
1344 * direct_abstract_declarator type_attribute 1343 * direct_abstract_declarator type_attribute
1345 */ 1344 */
1346direct_abstract_declarator: /* C99 6.7.6 */ 1345direct_abstract_declarator: /* C99 6.7.6 */
1347 T_LPAREN abstract_declarator T_RPAREN { 1346 T_LPAREN abstract_declarator T_RPAREN {
1348 $$ = $2; 1347 $$ = $2;
1349 } 1348 }
1350 | T_LBRACK T_RBRACK { 1349 | T_LBRACK T_RBRACK {
1351 $$ = add_array(abstract_name(), false, 0); 1350 $$ = add_array(abstract_name(), false, 0);
1352 } 1351 }
1353 | T_LBRACK array_size T_RBRACK { 1352 | T_LBRACK array_size T_RBRACK {
1354 $$ = add_array(abstract_name(), true, to_int_constant($2, false)); 1353 $$ = add_array(abstract_name(), true, to_int_constant($2, false));
1355 } 1354 }
1356 | type_attribute direct_abstract_declarator { 1355 | type_attribute direct_abstract_declarator {
1357 $$ = $2; 1356 $$ = $2;
1358 } 1357 }
1359 | direct_abstract_declarator T_LBRACK T_RBRACK { 1358 | direct_abstract_declarator T_LBRACK T_RBRACK {
1360 $$ = add_array($1, false, 0); 1359 $$ = add_array($1, false, 0);
1361 } 1360 }
1362 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */ 1361 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
1363 $$ = add_array($1, false, 0); 1362 $$ = add_array($1, false, 0);
1364 } 1363 }
1365 | direct_abstract_declarator T_LBRACK array_size T_RBRACK { 1364 | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
1366 $$ = add_array($1, true, to_int_constant($3, false)); 1365 $$ = add_array($1, true, to_int_constant($3, false));
1367 } 1366 }
1368 | abstract_decl_param_list asm_or_symbolrename_opt { 1367 | abstract_decl_param_list asm_or_symbolrename_opt {
1369 $$ = add_function(symbolrename(abstract_name(), $2), $1); 1368 $$ = add_function(symbolrename(abstract_name(), $2), $1);
1370 end_declaration_level(); 1369 end_declaration_level();
1371 block_level--; 1370 block_level--;
1372 } 1371 }
1373 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt { 1372 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
1374 $$ = add_function(symbolrename($1, $3), $2); 1373 $$ = add_function(symbolrename($1, $3), $2);
1375 end_declaration_level(); 1374 end_declaration_level();
1376 block_level--; 1375 block_level--;
1377 } 1376 }
1378 | direct_abstract_declarator type_attribute 1377 | direct_abstract_declarator type_attribute
1379 ; 1378 ;
1380 1379
1381array_size: 1380array_size:
1382 type_qualifier_list_opt T_SCLASS constant_expr { 1381 type_qualifier_list_opt T_SCLASS constant_expr {
1383 /* C11 6.7.6.3p7 */ 1382 /* C11 6.7.6.3p7 */
1384 if ($2 != STATIC) 1383 if ($2 != STATIC)
1385 yyerror("Bad attribute"); 1384 yyerror("Bad attribute");
1386 /* static array size is a C11 extension */ 1385 /* static array size is a C11 extension */
1387 c11ism(343); 1386 c11ism(343);
1388 $$ = $3; 1387 $$ = $3;
1389 } 1388 }
1390 | constant_expr 1389 | constant_expr
1391 ; 1390 ;
1392 1391
1393non_expr_statement: 1392non_expr_statement:
1394 type_attribute T_SEMI 1393 type_attribute T_SEMI
1395 | labeled_statement 1394 | labeled_statement
1396 | compound_statement 1395 | compound_statement
1397 | selection_statement 1396 | selection_statement
1398 | iteration_statement 1397 | iteration_statement
1399 | jump_statement { 1398 | jump_statement {
1400 seen_fallthrough = false; 1399 seen_fallthrough = false;
1401 } 1400 }
1402 | asm_statement 1401 | asm_statement
1403 ; 1402 ;
1404 1403
1405statement: /* C99 6.8 */ 1404statement: /* C99 6.8 */
1406 expression_statement 1405 expression_statement
1407 | non_expr_statement 1406 | non_expr_statement
1408 ; 1407 ;
1409 1408
1410labeled_statement: /* C99 6.8.1 */ 1409labeled_statement: /* C99 6.8.1 */
1411 label gcc_attribute_list_opt statement 1410 label gcc_attribute_list_opt statement
1412 ; 1411 ;
1413 1412
1414label: 1413label:
1415 T_NAME T_COLON { 1414 T_NAME T_COLON {
1416 symtyp = FLABEL; 1415 symtyp = FLABEL;
1417 named_label(getsym($1)); 1416 named_label(getsym($1));
1418 } 1417 }
1419 | T_CASE constant_expr T_COLON { 1418 | T_CASE constant_expr T_COLON {
1420 case_label($2); 1419 case_label($2);
1421 seen_fallthrough = true; 1420 seen_fallthrough = true;
1422 } 1421 }
1423 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON { 1422 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1424 /* XXX: We don't fill all cases */ 1423 /* XXX: We don't fill all cases */
1425 case_label($2); 1424 case_label($2);
1426 seen_fallthrough = true; 1425 seen_fallthrough = true;
1427 } 1426 }
1428 | T_DEFAULT T_COLON { 1427 | T_DEFAULT T_COLON {
1429 default_label(); 1428 default_label();
1430 seen_fallthrough = true; 1429 seen_fallthrough = true;
1431 } 1430 }
1432 ; 1431 ;
1433 1432
1434compound_statement: /* C99 6.8.2 */ 1433compound_statement: /* C99 6.8.2 */
1435 compound_statement_lbrace block_item_list_opt 1434 compound_statement_lbrace block_item_list_opt
1436 compound_statement_rbrace 1435 compound_statement_rbrace
1437 ; 1436 ;
1438 1437
1439compound_statement_lbrace: 1438compound_statement_lbrace:
1440 T_LBRACE { 1439 T_LBRACE {
1441 block_level++; 1440 block_level++;
1442 mem_block_level++; 1441 mem_block_level++;
1443 begin_declaration_level(AUTO); 1442 begin_declaration_level(AUTO);
1444 } 1443 }
1445 ; 1444 ;
1446 1445
1447compound_statement_rbrace: 1446compound_statement_rbrace:
1448 T_RBRACE { 1447 T_RBRACE {
1449 end_declaration_level(); 1448 end_declaration_level();
1450 freeblk(); 1449 freeblk();
1451 mem_block_level--; 1450 mem_block_level--;
1452 block_level--; 1451 block_level--;
1453 seen_fallthrough = false; 1452 seen_fallthrough = false;
1454 } 1453 }
1455 ; 1454 ;
1456 1455
1457block_item_list_opt: /* C99 6.8.2 */ 1456block_item_list_opt: /* C99 6.8.2 */
1458 /* empty */ 1457 /* empty */
1459 | block_item_list 1458 | block_item_list
1460 ; 1459 ;
1461 1460
1462block_item_list: 1461block_item_list:
1463 block_item 1462 block_item
1464 | block_item_list block_item { 1463 | block_item_list block_item {
1465 if (!Sflag && $1 && !$2) 1464 if (!Sflag && $1 && !$2)
1466 /* declarations after statements is a C99 feature */ 1465 /* declarations after statements is a C99 feature */
1467 c99ism(327); 1466 c99ism(327);
1468 $$ = $1 || $2; 1467 $$ = $1 || $2;
1469 } 1468 }
1470 ; 1469 ;
1471 1470
1472block_item: 1471block_item:
1473 statement { 1472 statement {
1474 $$ = true; 1473 $$ = true;
1475 restore_warning_flags(); 1474 restore_warning_flags();
1476 } 1475 }
1477 | declaration { 1476 | declaration {
1478 $$ = false; 1477 $$ = false;
1479 restore_warning_flags(); 1478 restore_warning_flags();
1480 } 1479 }
1481 ; 1480 ;
1482 1481
1483expression_statement: /* C99 6.8.3 */ 1482expression_statement: /* C99 6.8.3 */
1484 expr T_SEMI { 1483 expr T_SEMI {
1485 expr($1, false, false, false, false); 1484 expr($1, false, false, false, false);
1486 seen_fallthrough = false; 1485 seen_fallthrough = false;
1487 } 1486 }
1488 | T_SEMI { 1487 | T_SEMI {
1489 seen_fallthrough = false; 1488 seen_fallthrough = false;
1490 } 1489 }
1491 ; 1490 ;
1492 1491
1493selection_statement: /* C99 6.8.4 */ 1492selection_statement: /* C99 6.8.4 */
1494 if_without_else { 1493 if_without_else {
1495 save_warning_flags(); 1494 save_warning_flags();
1496 if2(); 1495 if2();
1497 if3(false); 1496 if3(false);
1498 } 1497 }
1499 | if_without_else T_ELSE { 1498 | if_without_else T_ELSE {
1500 save_warning_flags(); 1499 save_warning_flags();
1501 if2(); 1500 if2();
1502 } statement { 1501 } statement {
1503 clear_warning_flags(); 1502 clear_warning_flags();
1504 if3(true); 1503 if3(true);
1505 } 1504 }
1506 | if_without_else T_ELSE error { 1505 | if_without_else T_ELSE error {
1507 clear_warning_flags(); 1506 clear_warning_flags();
1508 if3(false); 1507 if3(false);
1509 } 1508 }
1510 | switch_expr statement { 1509 | switch_expr statement {
1511 clear_warning_flags(); 1510 clear_warning_flags();
1512 switch2(); 1511 switch2();
1513 } 1512 }
1514 | switch_expr error { 1513 | switch_expr error {
1515 clear_warning_flags(); 1514 clear_warning_flags();
1516 switch2(); 1515 switch2();
1517 } 1516 }
1518 ; 1517 ;
1519 1518
1520if_without_else: /* see C99 6.8.4 */ 1519if_without_else: /* see C99 6.8.4 */
1521 if_expr statement 1520 if_expr statement
1522 | if_expr error 1521 | if_expr error
1523 ; 1522 ;
1524 1523
1525if_expr: /* see C99 6.8.4 */ 1524if_expr: /* see C99 6.8.4 */
1526 T_IF T_LPAREN expr T_RPAREN { 1525 T_IF T_LPAREN expr T_RPAREN {
1527 if1($3); 1526 if1($3);
1528 clear_warning_flags(); 1527 clear_warning_flags();
1529 } 1528 }
1530 ; 1529 ;
1531 1530
1532switch_expr: /* see C99 6.8.4 */ 1531switch_expr: /* see C99 6.8.4 */
1533 T_SWITCH T_LPAREN expr T_RPAREN { 1532 T_SWITCH T_LPAREN expr T_RPAREN {
1534 switch1($3); 1533 switch1($3);
1535 clear_warning_flags(); 1534 clear_warning_flags();
1536 } 1535 }
1537 ; 1536 ;
1538 1537
1539do_statement: /* C99 6.8.5 */ 1538do_statement: /* C99 6.8.5 */
1540 do statement { 1539 do statement {
1541 clear_warning_flags(); 1540 clear_warning_flags();
1542 } 1541 }
1543 ; 1542 ;
1544 1543
1545iteration_statement: /* C99 6.8.5 */ 1544iteration_statement: /* C99 6.8.5 */
1546 while_expr statement { 1545 while_expr statement {
1547 clear_warning_flags(); 1546 clear_warning_flags();
1548 while2(); 1547 while2();
1549 } 1548 }
1550 | while_expr error { 1549 | while_expr error {
1551 clear_warning_flags(); 1550 clear_warning_flags();
1552 while2(); 1551 while2();
1553 } 1552 }
1554 | do_statement do_while_expr { 1553 | do_statement do_while_expr {
1555 do2($2); 1554 do2($2);
1556 seen_fallthrough = false; 1555 seen_fallthrough = false;
1557 } 1556 }
1558 | do error { 1557 | do error {
1559 clear_warning_flags(); 1558 clear_warning_flags();
1560 do2(NULL); 1559 do2(NULL);
1561 } 1560 }
1562 | for_exprs statement { 1561 | for_exprs statement {
1563 clear_warning_flags(); 1562 clear_warning_flags();
1564 for2(); 1563 for2();
1565 end_declaration_level(); 1564 end_declaration_level();
1566 block_level--; 1565 block_level--;
1567 } 1566 }
1568 | for_exprs error { 1567 | for_exprs error {
1569 clear_warning_flags(); 1568 clear_warning_flags();
1570 for2(); 1569 for2();
1571 end_declaration_level(); 1570 end_declaration_level();
1572 block_level--; 1571 block_level--;
1573 } 1572 }
1574 ; 1573 ;
1575 1574
1576while_expr: /* see C99 6.8.5 */ 1575while_expr: /* see C99 6.8.5 */
1577 T_WHILE T_LPAREN expr T_RPAREN { 1576 T_WHILE T_LPAREN expr T_RPAREN {
1578 while1($3); 1577 while1($3);
1579 clear_warning_flags(); 1578 clear_warning_flags();
1580 } 1579 }
1581 ; 1580 ;
1582 1581
1583do: /* see C99 6.8.5 */ 1582do: /* see C99 6.8.5 */
1584 T_DO { 1583 T_DO {
1585 do1(); 1584 do1();
1586 } 1585 }
1587 ; 1586 ;
1588 1587
1589do_while_expr: /* see C99 6.8.5 */ 1588do_while_expr: /* see C99 6.8.5 */
1590 T_WHILE T_LPAREN expr T_RPAREN T_SEMI { 1589 T_WHILE T_LPAREN expr T_RPAREN T_SEMI {
1591 $$ = $3; 1590 $$ = $3;
1592 } 1591 }
1593 ; 1592 ;
1594 1593
1595for_start: /* see C99 6.8.5 */ 1594for_start: /* see C99 6.8.5 */
1596 T_FOR T_LPAREN { 1595 T_FOR T_LPAREN {
1597 begin_declaration_level(AUTO); 1596 begin_declaration_level(AUTO);
1598 block_level++; 1597 block_level++;
1599 } 1598 }
1600 ; 1599 ;
1601 1600
1602for_exprs: /* see C99 6.8.5 */ 1601for_exprs: /* see C99 6.8.5 */
1603 for_start declaration_specifiers deftyp notype_init_decls T_SEMI 1602 for_start declaration_specifiers deftyp notype_init_decls T_SEMI
1604 expr_opt T_SEMI expr_opt T_RPAREN { 1603 expr_opt T_SEMI expr_opt T_RPAREN {
1605 /* variable declaration in for loop */ 1604 /* variable declaration in for loop */
1606 c99ism(325); 1605 c99ism(325);
1607 for1(NULL, $6, $8); 1606 for1(NULL, $6, $8);
1608 clear_warning_flags(); 1607 clear_warning_flags();
1609 } 1608 }
1610 | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN { 1609 | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN {
1611 for1($2, $4, $6); 1610 for1($2, $4, $6);
1612 clear_warning_flags(); 1611 clear_warning_flags();
1613 } 1612 }
1614 ; 1613 ;
1615 1614
1616jump_statement: /* C99 6.8.6 */ 1615jump_statement: /* C99 6.8.6 */
1617 goto identifier T_SEMI { 1616 goto identifier T_SEMI {
1618 do_goto(getsym($2)); 1617 do_goto(getsym($2));
1619 } 1618 }
1620 | goto error T_SEMI { 1619 | goto error T_SEMI {
1621 symtyp = FVFT; 1620 symtyp = FVFT;
1622 } 1621 }
1623 | T_CONTINUE T_SEMI { 1622 | T_CONTINUE T_SEMI {
1624 do_continue(); 1623 do_continue();
1625 } 1624 }
1626 | T_BREAK T_SEMI { 1625 | T_BREAK T_SEMI {
1627 do_break(); 1626 do_break();
1628 } 1627 }
1629 | T_RETURN T_SEMI { 1628 | T_RETURN T_SEMI {
1630 do_return(NULL); 1629 do_return(NULL);
1631 } 1630 }
1632 | T_RETURN expr T_SEMI { 1631 | T_RETURN expr T_SEMI {
1633 do_return($2); 1632 do_return($2);
1634 } 1633 }
1635 ; 1634 ;
1636 1635
1637goto: 1636goto:
1638 T_GOTO { 1637 T_GOTO {
1639 symtyp = FLABEL; 1638 symtyp = FLABEL;
1640 } 1639 }
1641 ; 1640 ;
1642 1641
1643asm_statement: 1642asm_statement:
1644 T_ASM T_LPAREN read_until_rparen T_SEMI { 1643 T_ASM T_LPAREN read_until_rparen T_SEMI {
1645 setasm(); 1644 setasm();
1646 } 1645 }
1647 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI { 1646 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI {
1648 setasm(); 1647 setasm();
1649 } 1648 }
1650 | T_ASM error 1649 | T_ASM error
1651 ; 1650 ;