Thu Jul 8 03:35:07 2021 UTC ()
lint: clean up grammar for member declarations

No functional change.


(rillig)
diff -r1.268 -r1.269 src/usr.bin/xlint/lint1/cgram.y

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

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