Wed Jul 21 21:24:45 2021 UTC ()
lint: move assignments to $$ at the end of the action

They are closely related to return statements.

While here, add some more remarks from reviewing the grammar.

No functional change.


(rillig)
diff -r1.333 -r1.334 src/usr.bin/xlint/lint1/cgram.y

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/21 21:17:57 1.333
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/21 21:24:45 1.334
@@ -1,2131 +1,2142 @@ @@ -1,2131 +1,2142 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.333 2021/07/21 21:17:57 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 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.333 2021/07/21 21:17:57 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.334 2021/07/21 21:24:45 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 read_until_rparen(void); 70static void read_until_rparen(void);
71static sym_t *symbolrename(sym_t *, sbuf_t *); 71static sym_t *symbolrename(sym_t *, sbuf_t *);
72 72
73 73
74#ifdef DEBUG 74#ifdef DEBUG
75static void 75static void
76CLEAR_WARN_FLAGS(const char *file, size_t line) 76CLEAR_WARN_FLAGS(const char *file, size_t line)
77{ 77{
78 printf("%s:%d: %s:%zu: clearing flags\n", 78 printf("%s:%d: %s:%zu: clearing flags\n",
79 curr_pos.p_file, curr_pos.p_line, file, line); 79 curr_pos.p_file, curr_pos.p_line, file, line);
80 clear_warn_flags(); 80 clear_warn_flags();
81 olwarn = LWARN_BAD; 81 olwarn = LWARN_BAD;
82} 82}
83 83
84static void 84static void
85SAVE_WARN_FLAGS(const char *file, size_t line) 85SAVE_WARN_FLAGS(const char *file, size_t line)
86{ 86{
87 lint_assert(olwarn == LWARN_BAD); 87 lint_assert(olwarn == LWARN_BAD);
88 printf("%s:%d: %s:%zu: saving flags %d\n", 88 printf("%s:%d: %s:%zu: saving flags %d\n",
89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
90 olwarn = lwarn; 90 olwarn = lwarn;
91} 91}
92 92
93static void 93static void
94RESTORE_WARN_FLAGS(const char *file, size_t line) 94RESTORE_WARN_FLAGS(const char *file, size_t line)
95{ 95{
96 if (olwarn != LWARN_BAD) { 96 if (olwarn != LWARN_BAD) {
97 lwarn = olwarn; 97 lwarn = olwarn;
98 printf("%s:%d: %s:%zu: restoring flags %d\n", 98 printf("%s:%d: %s:%zu: restoring flags %d\n",
99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
100 olwarn = LWARN_BAD; 100 olwarn = LWARN_BAD;
101 } else 101 } else
102 CLEAR_WARN_FLAGS(file, line); 102 CLEAR_WARN_FLAGS(file, line);
103} 103}
104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args) 104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
105#else 105#else
106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD 106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD
107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn 107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn
108#define RESTORE_WARN_FLAGS(f, l) \ 108#define RESTORE_WARN_FLAGS(f, l) \
109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn)) 109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
110#define cgram_debug(fmt, args...) do { } while (false) 110#define cgram_debug(fmt, args...) do { } while (false)
111#endif 111#endif
112 112
113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__) 113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__)
114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__) 114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__)
115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__) 115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__)
116 116
117/* unbind the anonymous struct members from the struct */ 117/* unbind the anonymous struct members from the struct */
118static void 118static void
119anonymize(sym_t *s) 119anonymize(sym_t *s)
120{ 120{
121 for ( ; s != NULL; s = s->s_next) 121 for ( ; s != NULL; s = s->s_next)
122 s->s_styp = NULL; 122 s->s_styp = NULL;
123} 123}
124 124
125%} 125%}
126 126
127%expect 165 127%expect 165
128 128
129%union { 129%union {
130 val_t *y_val; 130 val_t *y_val;
131 sbuf_t *y_name; 131 sbuf_t *y_name;
132 sym_t *y_sym; 132 sym_t *y_sym;
133 op_t y_op; 133 op_t y_op;
134 scl_t y_scl; 134 scl_t y_scl;
135 tspec_t y_tspec; 135 tspec_t y_tspec;
136 tqual_t y_tqual; 136 tqual_t y_tqual;
137 type_t *y_type; 137 type_t *y_type;
138 tnode_t *y_tnode; 138 tnode_t *y_tnode;
139 range_t y_range; 139 range_t y_range;
140 strg_t *y_string; 140 strg_t *y_string;
141 qual_ptr *y_qual_ptr; 141 qual_ptr *y_qual_ptr;
142 bool y_seen_statement; 142 bool y_seen_statement;
143 struct generic_association *y_generic; 143 struct generic_association *y_generic;
144}; 144};
145 145
146%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN 146%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
147%token T_POINT T_ARROW 147%token T_POINT T_ARROW
148%token T_COMPLEMENT T_LOGNOT 148%token T_COMPLEMENT T_LOGNOT
149%token <y_op> T_INCDEC 149%token <y_op> T_INCDEC
150%token T_SIZEOF 150%token T_SIZEOF
151%token T_BUILTIN_OFFSETOF 151%token T_BUILTIN_OFFSETOF
152%token T_TYPEOF 152%token T_TYPEOF
153%token T_EXTENSION 153%token T_EXTENSION
154%token T_ALIGNAS 154%token T_ALIGNAS
155%token T_ALIGNOF 155%token T_ALIGNOF
156%token T_ASTERISK 156%token T_ASTERISK
157%token <y_op> T_MULTIPLICATIVE 157%token <y_op> T_MULTIPLICATIVE
158%token <y_op> T_ADDITIVE 158%token <y_op> T_ADDITIVE
159%token <y_op> T_SHIFT 159%token <y_op> T_SHIFT
160%token <y_op> T_RELATIONAL 160%token <y_op> T_RELATIONAL
161%token <y_op> T_EQUALITY 161%token <y_op> T_EQUALITY
162%token T_AMPER 162%token T_AMPER
163%token T_BITXOR 163%token T_BITXOR
164%token T_BITOR 164%token T_BITOR
165%token T_LOGAND 165%token T_LOGAND
166%token T_LOGOR 166%token T_LOGOR
167%token T_QUEST 167%token T_QUEST
168%token T_COLON 168%token T_COLON
169%token T_ASSIGN 169%token T_ASSIGN
170%token <y_op> T_OPASSIGN 170%token <y_op> T_OPASSIGN
171%token T_COMMA 171%token T_COMMA
172%token T_SEMI 172%token T_SEMI
173%token T_ELLIPSIS 173%token T_ELLIPSIS
174%token T_REAL 174%token T_REAL
175%token T_IMAG 175%token T_IMAG
176%token T_GENERIC 176%token T_GENERIC
177%token T_NORETURN 177%token T_NORETURN
178 178
179/* storage classes (extern, static, auto, register and typedef) */ 179/* storage classes (extern, static, auto, register and typedef) */
180%token <y_scl> T_SCLASS 180%token <y_scl> T_SCLASS
181 181
182/* 182/*
183 * predefined type keywords (char, int, short, long, unsigned, signed, 183 * predefined type keywords (char, int, short, long, unsigned, signed,
184 * float, double, void); see T_TYPENAME for types from typedef 184 * float, double, void); see T_TYPENAME for types from typedef
185 */ 185 */
186%token <y_tspec> T_TYPE 186%token <y_tspec> T_TYPE
187 187
188/* qualifiers (const, volatile, restrict, _Thread_local) */ 188/* qualifiers (const, volatile, restrict, _Thread_local) */
189%token <y_tqual> T_QUAL 189%token <y_tqual> T_QUAL
190 190
191/* struct or union */ 191/* struct or union */
192%token <y_tspec> T_STRUCT_OR_UNION 192%token <y_tspec> T_STRUCT_OR_UNION
193 193
194/* remaining keywords */ 194/* remaining keywords */
195%token T_ASM 195%token T_ASM
196%token T_BREAK 196%token T_BREAK
197%token T_CASE 197%token T_CASE
198%token T_CONTINUE 198%token T_CONTINUE
199%token T_DEFAULT 199%token T_DEFAULT
200%token T_DO 200%token T_DO
201%token T_ELSE 201%token T_ELSE
202%token T_ENUM 202%token T_ENUM
203%token T_FOR 203%token T_FOR
204%token T_GOTO 204%token T_GOTO
205%token T_IF 205%token T_IF
206%token T_PACKED 206%token T_PACKED
207%token T_RETURN 207%token T_RETURN
208%token T_SWITCH 208%token T_SWITCH
209%token T_SYMBOLRENAME 209%token T_SYMBOLRENAME
210%token T_WHILE 210%token T_WHILE
211 211
212%token T_ATTRIBUTE 212%token T_ATTRIBUTE
213%token T_AT_ALIAS 213%token T_AT_ALIAS
214%token T_AT_ALIGNED 214%token T_AT_ALIGNED
215%token T_AT_ALLOC_SIZE 215%token T_AT_ALLOC_SIZE
216%token T_AT_ALWAYS_INLINE 216%token T_AT_ALWAYS_INLINE
217%token T_AT_BOUNDED 217%token T_AT_BOUNDED
218%token T_AT_BUFFER 218%token T_AT_BUFFER
219%token T_AT_COLD 219%token T_AT_COLD
220%token T_AT_COMMON 220%token T_AT_COMMON
221%token T_AT_CONSTRUCTOR 221%token T_AT_CONSTRUCTOR
222%token T_AT_DEPRECATED 222%token T_AT_DEPRECATED
223%token T_AT_DESTRUCTOR 223%token T_AT_DESTRUCTOR
224%token T_AT_FALLTHROUGH 224%token T_AT_FALLTHROUGH
225%token T_AT_FORMAT 225%token T_AT_FORMAT
226%token T_AT_FORMAT_ARG 226%token T_AT_FORMAT_ARG
227%token T_AT_FORMAT_GNU_PRINTF 227%token T_AT_FORMAT_GNU_PRINTF
228%token T_AT_FORMAT_PRINTF 228%token T_AT_FORMAT_PRINTF
229%token T_AT_FORMAT_SCANF 229%token T_AT_FORMAT_SCANF
230%token T_AT_FORMAT_STRFMON 230%token T_AT_FORMAT_STRFMON
231%token T_AT_FORMAT_STRFTIME 231%token T_AT_FORMAT_STRFTIME
232%token T_AT_FORMAT_SYSLOG 232%token T_AT_FORMAT_SYSLOG
233%token T_AT_GNU_INLINE 233%token T_AT_GNU_INLINE
234%token T_AT_HOT 234%token T_AT_HOT
235%token T_AT_MALLOC 235%token T_AT_MALLOC
236%token T_AT_MAY_ALIAS 236%token T_AT_MAY_ALIAS
237%token T_AT_MINBYTES 237%token T_AT_MINBYTES
238%token T_AT_MODE 238%token T_AT_MODE
239%token T_AT_NOINLINE 239%token T_AT_NOINLINE
240%token T_AT_NONNULL 240%token T_AT_NONNULL
241%token T_AT_NONSTRING 241%token T_AT_NONSTRING
242%token T_AT_NORETURN 242%token T_AT_NORETURN
243%token T_AT_NOTHROW 243%token T_AT_NOTHROW
244%token T_AT_NO_INSTRUMENT_FUNCTION 244%token T_AT_NO_INSTRUMENT_FUNCTION
245%token T_AT_OPTIMIZE 245%token T_AT_OPTIMIZE
246%token T_AT_PACKED 246%token T_AT_PACKED
247%token T_AT_PCS 247%token T_AT_PCS
248%token T_AT_PURE 248%token T_AT_PURE
249%token T_AT_RETURNS_TWICE 249%token T_AT_RETURNS_TWICE
250%token T_AT_SECTION 250%token T_AT_SECTION
251%token T_AT_SENTINEL 251%token T_AT_SENTINEL
252%token T_AT_STRING 252%token T_AT_STRING
253%token T_AT_TLS_MODEL 253%token T_AT_TLS_MODEL
254%token T_AT_TUNION 254%token T_AT_TUNION
255%token T_AT_UNUSED 255%token T_AT_UNUSED
256%token T_AT_USED 256%token T_AT_USED
257%token T_AT_VISIBILITY 257%token T_AT_VISIBILITY
258%token T_AT_WARN_UNUSED_RESULT 258%token T_AT_WARN_UNUSED_RESULT
259%token T_AT_WEAK 259%token T_AT_WEAK
260 260
261%left T_THEN 261%left T_THEN
262%left T_ELSE 262%left T_ELSE
263%left T_COMMA 263%left T_COMMA
264%right T_ASSIGN T_OPASSIGN 264%right T_ASSIGN T_OPASSIGN
265%right T_QUEST T_COLON 265%right T_QUEST T_COLON
266%left T_LOGOR 266%left T_LOGOR
267%left T_LOGAND 267%left T_LOGAND
268%left T_BITOR 268%left T_BITOR
269%left T_BITXOR 269%left T_BITXOR
270%left T_AMPER 270%left T_AMPER
271%left T_EQUALITY 271%left T_EQUALITY
272%left T_RELATIONAL 272%left T_RELATIONAL
273%left T_SHIFT 273%left T_SHIFT
274%left T_ADDITIVE 274%left T_ADDITIVE
275%left T_ASTERISK T_MULTIPLICATIVE 275%left T_ASTERISK T_MULTIPLICATIVE
276 276
277%token <y_name> T_NAME 277%token <y_name> T_NAME
278%token <y_name> T_TYPENAME 278%token <y_name> T_TYPENAME
279%token <y_val> T_CON 279%token <y_val> T_CON
280%token <y_string> T_STRING 280%token <y_string> T_STRING
281 281
282%type <y_sym> identifier_sym 282%type <y_sym> identifier_sym
283%type <y_name> identifier 283%type <y_name> identifier
284%type <y_string> string 284%type <y_string> string
285%type <y_string> string2 285%type <y_string> string2
286 286
287%type <y_tnode> primary_expression 287%type <y_tnode> primary_expression
288%type <y_tnode> generic_selection 288%type <y_tnode> generic_selection
289%type <y_generic> generic_assoc_list 289%type <y_generic> generic_assoc_list
290%type <y_generic> generic_association 290%type <y_generic> generic_association
291%type <y_tnode> postfix_expression 291%type <y_tnode> postfix_expression
292%type <y_tnode> gcc_statement_expr_list 292%type <y_tnode> gcc_statement_expr_list
293%type <y_tnode> gcc_statement_expr_item 293%type <y_tnode> gcc_statement_expr_item
294%type <y_op> point_or_arrow 294%type <y_op> point_or_arrow
295%type <y_tnode> argument_expression_list 295%type <y_tnode> argument_expression_list
296%type <y_tnode> unary_expression 296%type <y_tnode> unary_expression
297%type <y_tnode> cast_expression 297%type <y_tnode> cast_expression
298%type <y_tnode> conditional_expression 298%type <y_tnode> conditional_expression
299%type <y_tnode> assignment_expression 299%type <y_tnode> assignment_expression
300%type <y_tnode> expression_opt 300%type <y_tnode> expression_opt
301%type <y_tnode> expression 301%type <y_tnode> expression
302%type <y_tnode> constant_expr 302%type <y_tnode> constant_expr
303 303
304%type <y_type> begin_type_typespec 304%type <y_type> begin_type_typespec
305%type <y_type> type_specifier 305%type <y_type> type_specifier
306%type <y_type> notype_type_specifier 306%type <y_type> notype_type_specifier
307%type <y_type> struct_or_union_specifier 307%type <y_type> struct_or_union_specifier
308%type <y_tspec> struct_or_union 308%type <y_tspec> struct_or_union
309%type <y_sym> braced_struct_declaration_list 309%type <y_sym> braced_struct_declaration_list
310%type <y_sym> struct_declaration_list_with_rbrace 310%type <y_sym> struct_declaration_list_with_rbrace
311%type <y_sym> struct_declaration_list 311%type <y_sym> struct_declaration_list
312%type <y_sym> struct_declaration 312%type <y_sym> struct_declaration
313%type <y_sym> notype_struct_declarators 313%type <y_sym> notype_struct_declarators
314%type <y_sym> type_struct_declarators 314%type <y_sym> type_struct_declarators
315%type <y_sym> notype_struct_declarator 315%type <y_sym> notype_struct_declarator
316%type <y_sym> type_struct_declarator 316%type <y_sym> type_struct_declarator
317%type <y_type> enum_specifier 317%type <y_type> enum_specifier
318%type <y_sym> enum_declaration 318%type <y_sym> enum_declaration
319%type <y_sym> enums_with_opt_comma 319%type <y_sym> enums_with_opt_comma
320%type <y_sym> enumerator_list 320%type <y_sym> enumerator_list
321%type <y_sym> enumerator 321%type <y_sym> enumerator
322%type <y_qual_ptr> type_qualifier 322%type <y_qual_ptr> type_qualifier
323%type <y_qual_ptr> pointer 323%type <y_qual_ptr> pointer
324%type <y_qual_ptr> asterisk 324%type <y_qual_ptr> asterisk
325%type <y_qual_ptr> type_qualifier_list_opt 325%type <y_qual_ptr> type_qualifier_list_opt
326%type <y_qual_ptr> type_qualifier_list 326%type <y_qual_ptr> type_qualifier_list
327%type <y_sym> notype_declarator 327%type <y_sym> notype_declarator
328%type <y_sym> type_declarator 328%type <y_sym> type_declarator
329%type <y_sym> notype_direct_declarator 329%type <y_sym> notype_direct_declarator
330%type <y_sym> type_direct_declarator 330%type <y_sym> type_direct_declarator
331%type <y_sym> type_param_declarator 331%type <y_sym> type_param_declarator
332%type <y_sym> notype_param_declarator 332%type <y_sym> notype_param_declarator
333%type <y_sym> direct_param_declarator 333%type <y_sym> direct_param_declarator
334%type <y_sym> direct_notype_param_declarator 334%type <y_sym> direct_notype_param_declarator
335%type <y_sym> param_list 335%type <y_sym> param_list
336%type <y_tnode> array_size 336%type <y_tnode> array_size
337%type <y_sym> identifier_list 337%type <y_sym> identifier_list
338%type <y_type> type_name 338%type <y_type> type_name
339%type <y_sym> abstract_declaration 339%type <y_sym> abstract_declaration
340%type <y_sym> abstract_declarator 340%type <y_sym> abstract_declarator
341%type <y_sym> direct_abstract_declarator 341%type <y_sym> direct_abstract_declarator
342%type <y_sym> abstract_decl_param_list 342%type <y_sym> abstract_decl_param_list
343%type <y_sym> vararg_parameter_type_list 343%type <y_sym> vararg_parameter_type_list
344%type <y_sym> parameter_type_list 344%type <y_sym> parameter_type_list
345%type <y_sym> parameter_declaration 345%type <y_sym> parameter_declaration
346%type <y_range> range 346%type <y_range> range
347%type <y_name> asm_or_symbolrename_opt 347%type <y_name> asm_or_symbolrename_opt
348 348
349%type <y_seen_statement> block_item_list 349%type <y_seen_statement> block_item_list
350%type <y_seen_statement> block_item 350%type <y_seen_statement> block_item
351%type <y_tnode> do_while_expr 351%type <y_tnode> do_while_expr
352%type <y_sym> func_declarator 352%type <y_sym> func_declarator
353 353
354%% 354%%
355 355
356program: 356program:
357 /* empty */ { 357 /* empty */ {
358 if (sflag) { 358 if (sflag) {
359 /* empty translation unit */ 359 /* empty translation unit */
360 error(272); 360 error(272);
361 } else if (!tflag) { 361 } else if (!tflag) {
362 /* empty translation unit */ 362 /* empty translation unit */
363 warning(272); 363 warning(272);
364 } 364 }
365 } 365 }
366 | translation_unit 366 | translation_unit
367 ; 367 ;
368 368
369identifier_sym: /* helper for struct/union/enum */ 369identifier_sym: /* helper for struct/union/enum */
370 identifier { 370 identifier {
371 $$ = getsym($1); 371 $$ = getsym($1);
372 } 372 }
373 ; 373 ;
374 374
375/* K&R ???, C90 ???, C99 6.4.2.1, C11 ??? */ 375/* K&R ???, C90 ???, C99 6.4.2.1, C11 ??? */
376identifier: 376identifier:
377 T_NAME { 377 T_NAME {
 378 cgram_debug("name '%s'", $1->sb_name);
378 $$ = $1; 379 $$ = $1;
379 cgram_debug("name '%s'", $$->sb_name); 
380 } 380 }
381 | T_TYPENAME { 381 | T_TYPENAME {
 382 cgram_debug("typename '%s'", $1->sb_name);
382 $$ = $1; 383 $$ = $1;
383 cgram_debug("typename '%s'", $$->sb_name); 
384 } 384 }
385 ; 385 ;
386 386
387/* see C99 6.4.5, string literals are joined by 5.1.1.2 */ 387/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
388string: 388string:
389 T_STRING 389 T_STRING
390 | T_STRING string2 { 390 | T_STRING string2 {
391 $$ = cat_strings($1, $2); 391 $$ = cat_strings($1, $2);
392 } 392 }
393 ; 393 ;
394 394
395/* see C99 6.4.5, string literals are joined by 5.1.1.2 */ 395/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
396string2: 396string2:
397 T_STRING { 397 T_STRING {
398 if (tflag) { 398 if (tflag) {
399 /* concatenated strings are illegal in traditional C */ 399 /* concatenated strings are illegal in traditional C */
400 warning(219); 400 warning(219);
401 } 401 }
402 $$ = $1; 402 $$ = $1;
403 } 403 }
404 | string2 T_STRING { 404 | string2 T_STRING {
405 $$ = cat_strings($1, $2); 405 $$ = cat_strings($1, $2);
406 } 406 }
407 ; 407 ;
408 408
409/* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */ 409/* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1 */
410primary_expression: 410primary_expression:
411 T_NAME { 411 T_NAME {
412 /* XXX really necessary? */ 412 /* XXX really necessary? */
413 if (yychar < 0) 413 if (yychar < 0)
414 yychar = yylex(); 414 yychar = yylex();
415 $$ = build_name(getsym($1), yychar); 415 $$ = build_name(getsym($1), yychar);
416 } 416 }
417 | T_CON { 417 | T_CON {
418 $$ = build_constant(gettyp($1->v_tspec), $1); 418 $$ = build_constant(gettyp($1->v_tspec), $1);
419 } 419 }
420 | string { 420 | string {
421 $$ = build_string($1); 421 $$ = build_string($1);
422 } 422 }
423 | T_LPAREN expression T_RPAREN { 423 | T_LPAREN expression T_RPAREN {
424 if ($2 != NULL) 424 if ($2 != NULL)
425 $2->tn_parenthesized = true; 425 $2->tn_parenthesized = true;
426 $$ = $2; 426 $$ = $2;
427 } 427 }
428 | generic_selection 428 | generic_selection
429 /* GCC primary-expression, see c_parser_postfix_expression */ 429 /* GCC primary-expression, see c_parser_postfix_expression */
430 | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN { 430 | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
431 symtyp = FMEMBER; 431 symtyp = FMEMBER;
432 $$ = build_offsetof($3, getsym($5)); 432 $$ = build_offsetof($3, getsym($5));
433 } 433 }
434 ; 434 ;
435 435
436/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */ 436/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
437generic_selection: 437generic_selection:
438 T_GENERIC T_LPAREN assignment_expression T_COMMA 438 T_GENERIC T_LPAREN assignment_expression T_COMMA
439 generic_assoc_list T_RPAREN { 439 generic_assoc_list T_RPAREN {
440 /* generic selection requires C11 or later */ 440 /* generic selection requires C11 or later */
441 c11ism(345); 441 c11ism(345);
442 $$ = build_generic_selection($3, $5); 442 $$ = build_generic_selection($3, $5);
443 } 443 }
444 ; 444 ;
445 445
446/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */ 446/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
447generic_assoc_list: 447generic_assoc_list:
448 generic_association 448 generic_association
449 | generic_assoc_list T_COMMA generic_association { 449 | generic_assoc_list T_COMMA generic_association {
450 $3->ga_prev = $1; 450 $3->ga_prev = $1;
451 $$ = $3; 451 $$ = $3;
452 } 452 }
453 ; 453 ;
454 454
455/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */ 455/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1 */
456generic_association: 456generic_association:
457 type_name T_COLON assignment_expression { 457 type_name T_COLON assignment_expression {
458 $$ = getblk(sizeof(*$$)); 458 $$ = getblk(sizeof(*$$));
459 $$->ga_arg = $1; 459 $$->ga_arg = $1;
460 $$->ga_result = $3; 460 $$->ga_result = $3;
461 } 461 }
462 | T_DEFAULT T_COLON assignment_expression { 462 | T_DEFAULT T_COLON assignment_expression {
463 $$ = getblk(sizeof(*$$)); 463 $$ = getblk(sizeof(*$$));
464 $$->ga_arg = NULL; 464 $$->ga_arg = NULL;
465 $$->ga_result = $3; 465 $$->ga_result = $3;
466 } 466 }
467 ; 467 ;
468 468
469/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */ 469/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
470postfix_expression: 470postfix_expression:
471 primary_expression 471 primary_expression
472 | postfix_expression T_LBRACK expression T_RBRACK { 472 | postfix_expression T_LBRACK expression T_RBRACK {
473 $$ = build_unary(INDIR, build_binary($1, PLUS, $3)); 473 $$ = build_unary(INDIR, build_binary($1, PLUS, $3));
474 } 474 }
475 | postfix_expression T_LPAREN T_RPAREN { 475 | postfix_expression T_LPAREN T_RPAREN {
476 $$ = build_function_call($1, NULL); 476 $$ = build_function_call($1, NULL);
477 } 477 }
478 | postfix_expression T_LPAREN argument_expression_list T_RPAREN { 478 | postfix_expression T_LPAREN argument_expression_list T_RPAREN {
479 $$ = build_function_call($1, $3); 479 $$ = build_function_call($1, $3);
480 } 480 }
481 | postfix_expression point_or_arrow T_NAME { 481 | postfix_expression point_or_arrow T_NAME {
482 $$ = build_member_access($1, $2, $3); 482 $$ = build_member_access($1, $2, $3);
483 } 483 }
484 | postfix_expression T_INCDEC { 484 | postfix_expression T_INCDEC {
485 $$ = build_unary($2 == INC ? INCAFT : DECAFT, $1); 485 $$ = build_unary($2 == INC ? INCAFT : DECAFT, $1);
486 } 486 }
487 | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */ 487 | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */
488 sym_t *tmp = mktempsym($2); 488 sym_t *tmp = mktempsym($2);
489 begin_initialization(tmp); 489 begin_initialization(tmp);
490 cgram_declare(tmp, true, NULL); 490 cgram_declare(tmp, true, NULL);
491 } init_lbrace initializer_list comma_opt init_rbrace { 491 } init_lbrace initializer_list comma_opt init_rbrace {
492 if (!Sflag) 492 if (!Sflag)
493 /* compound literals are a C9X/GCC extension */ 493 /* compound literals are a C9X/GCC extension */
494 gnuism(319); 494 gnuism(319);
495 $$ = build_name(*current_initsym(), 0); 495 $$ = build_name(*current_initsym(), 0);
496 end_initialization(); 496 end_initialization();
497 } 497 }
498 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list { 498 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
499 block_level--; 499 block_level--;
500 mem_block_level--; 500 mem_block_level--;
501 begin_initialization(mktempsym(dup_type($3->tn_type))); 501 begin_initialization(mktempsym(dup_type($3->tn_type)));
502 mem_block_level++; 502 mem_block_level++;
503 block_level++; 503 block_level++;
504 /* ({ }) is a GCC extension */ 504 /* ({ }) is a GCC extension */
505 gnuism(320); 505 gnuism(320);
506 } compound_statement_rbrace T_RPAREN { 506 } compound_statement_rbrace T_RPAREN {
507 $$ = build_name(*current_initsym(), 0); 507 $$ = build_name(*current_initsym(), 0);
508 end_initialization(); 508 end_initialization();
509 } 509 }
510 ; 510 ;
511 511
512comma_opt: /* helper for 'postfix_expression' */ 512comma_opt: /* helper for 'postfix_expression' */
513 /* empty */ 513 /* empty */
514 | T_COMMA 514 | T_COMMA
515 ; 515 ;
516 516
517/* 517/*
518 * The inner part of a GCC statement-expression of the form ({ ... }). 518 * The inner part of a GCC statement-expression of the form ({ ... }).
519 * 519 *
520 * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html 520 * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
521 */ 521 */
522gcc_statement_expr_list: 522gcc_statement_expr_list:
523 gcc_statement_expr_item 523 gcc_statement_expr_item
524 | gcc_statement_expr_list gcc_statement_expr_item { 524 | gcc_statement_expr_list gcc_statement_expr_item {
525 $$ = $2; 525 $$ = $2;
526 } 526 }
527 ; 527 ;
528 528
529gcc_statement_expr_item: 529gcc_statement_expr_item:
530 declaration_or_error { 530 declaration_or_error {
531 clear_warning_flags(); 531 clear_warning_flags();
532 $$ = NULL; 532 $$ = NULL;
533 } 533 }
534 | non_expr_statement { 534 | non_expr_statement {
535 $$ = expr_zalloc_tnode(); 535 $$ = expr_zalloc_tnode();
536 $$->tn_type = gettyp(VOID); 536 $$->tn_type = gettyp(VOID);
537 } 537 }
538 | expression T_SEMI { 538 | expression T_SEMI {
539 if ($1 == NULL) { /* in case of syntax errors */ 539 if ($1 == NULL) { /* in case of syntax errors */
540 $$ = expr_zalloc_tnode(); 540 $$ = expr_zalloc_tnode();
541 $$->tn_type = gettyp(VOID); 541 $$->tn_type = gettyp(VOID);
542 } else { 542 } else {
543 /* XXX: do that only on the last name */ 543 /* XXX: do that only on the last name */
544 if ($1->tn_op == NAME) 544 if ($1->tn_op == NAME)
545 $1->tn_sym->s_used = true; 545 $1->tn_sym->s_used = true;
546 $$ = $1; 
547 expr($1, false, false, false, false); 546 expr($1, false, false, false, false);
548 seen_fallthrough = false; 547 seen_fallthrough = false;
 548 $$ = $1;
549 } 549 }
550 } 550 }
551 ; 551 ;
552 552
553point_or_arrow: /* helper for 'postfix_expression' */ 553point_or_arrow: /* helper for 'postfix_expression' */
554 T_POINT { 554 T_POINT {
555 symtyp = FMEMBER; 555 symtyp = FMEMBER;
556 $$ = POINT; 556 $$ = POINT;
557 } 557 }
558 | T_ARROW { 558 | T_ARROW {
559 symtyp = FMEMBER; 559 symtyp = FMEMBER;
560 $$ = ARROW; 560 $$ = ARROW;
561 } 561 }
562 ; 562 ;
563 563
564/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */ 564/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2 */
565argument_expression_list: 565argument_expression_list:
566 assignment_expression { 566 assignment_expression {
567 $$ = build_function_argument(NULL, $1); 567 $$ = build_function_argument(NULL, $1);
568 } 568 }
569 | argument_expression_list T_COMMA assignment_expression { 569 | argument_expression_list T_COMMA assignment_expression {
570 $$ = build_function_argument($1, $3); 570 $$ = build_function_argument($1, $3);
571 } 571 }
572 ; 572 ;
573 573
574/* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */ 574/* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3 */
575unary_expression: 575unary_expression:
576 postfix_expression 576 postfix_expression
577 | T_INCDEC unary_expression { 577 | T_INCDEC unary_expression {
578 $$ = build_unary($1 == INC ? INCBEF : DECBEF, $2); 578 $$ = build_unary($1 == INC ? INCBEF : DECBEF, $2);
579 } 579 }
580 | T_AMPER cast_expression { 580 | T_AMPER cast_expression {
581 $$ = build_unary(ADDR, $2); 581 $$ = build_unary(ADDR, $2);
582 } 582 }
583 | T_ASTERISK cast_expression { 583 | T_ASTERISK cast_expression {
584 $$ = build_unary(INDIR, $2); 584 $$ = build_unary(INDIR, $2);
585 } 585 }
586 | T_ADDITIVE cast_expression { 586 | T_ADDITIVE cast_expression {
587 if (tflag && $1 == PLUS) { 587 if (tflag && $1 == PLUS) {
588 /* unary + is illegal in traditional C */ 588 /* unary + is illegal in traditional C */
589 warning(100); 589 warning(100);
590 } 590 }
591 $$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2); 591 $$ = build_unary($1 == PLUS ? UPLUS : UMINUS, $2);
592 } 592 }
593 | T_COMPLEMENT cast_expression { 593 | T_COMPLEMENT cast_expression {
594 $$ = build_unary(COMPL, $2); 594 $$ = build_unary(COMPL, $2);
595 } 595 }
596 | T_LOGNOT cast_expression { 596 | T_LOGNOT cast_expression {
597 $$ = build_unary(NOT, $2); 597 $$ = build_unary(NOT, $2);
598 } 598 }
599 | T_REAL cast_expression { /* GCC c_parser_unary_expression */ 599 | T_REAL cast_expression { /* GCC c_parser_unary_expression */
600 $$ = build_unary(REAL, $2); 600 $$ = build_unary(REAL, $2);
601 } 601 }
602 | T_IMAG cast_expression { /* GCC c_parser_unary_expression */ 602 | T_IMAG cast_expression { /* GCC c_parser_unary_expression */
603 $$ = build_unary(IMAG, $2); 603 $$ = build_unary(IMAG, $2);
604 } 604 }
605 | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */ 605 | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */
606 $$ = $2; 606 $$ = $2;
607 } 607 }
608 | T_SIZEOF unary_expression { 608 | T_SIZEOF unary_expression {
609 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type); 609 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
610 if ($$ != NULL) 610 if ($$ != NULL)
611 check_expr_misc($2, false, false, false, false, false, true); 611 check_expr_misc($2, false, false, false, false, false, true);
612 } 612 }
613 | T_SIZEOF T_LPAREN type_name T_RPAREN { 613 | T_SIZEOF T_LPAREN type_name T_RPAREN {
614 $$ = build_sizeof($3); 614 $$ = build_sizeof($3);
615 } 615 }
616 /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */ 616 /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */
617 | T_ALIGNOF T_LPAREN type_name T_RPAREN { 617 | T_ALIGNOF T_LPAREN type_name T_RPAREN {
 618 /* TODO: c11ism */
618 $$ = build_alignof($3); 619 $$ = build_alignof($3);
619 } 620 }
620 ; 621 ;
621 622
622/* The rule 'unary_operator' is inlined into unary_expression. */ 623/* The rule 'unary_operator' is inlined into unary_expression. */
623 624
624/* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */ 625/* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4 */
625cast_expression: 626cast_expression:
626 unary_expression 627 unary_expression
627 | T_LPAREN type_name T_RPAREN cast_expression { 628 | T_LPAREN type_name T_RPAREN cast_expression {
628 $$ = cast($4, $2); 629 $$ = cast($4, $2);
629 } 630 }
630 ; 631 ;
631 632
632expression_opt: 633expression_opt:
633 /* empty */ { 634 /* empty */ {
634 $$ = NULL; 635 $$ = NULL;
635 } 636 }
636 | expression 637 | expression
637 ; 638 ;
638 639
639/* 'conditional_expression' also implements 'multiplicative_expression'. */ 640/* 'conditional_expression' also implements 'multiplicative_expression'. */
640/* 'conditional_expression' also implements 'additive_expression'. */ 641/* 'conditional_expression' also implements 'additive_expression'. */
641/* 'conditional_expression' also implements 'shift_expression'. */ 642/* 'conditional_expression' also implements 'shift_expression'. */
642/* 'conditional_expression' also implements 'relational_expression'. */ 643/* 'conditional_expression' also implements 'relational_expression'. */
643/* 'conditional_expression' also implements 'equality_expression'. */ 644/* 'conditional_expression' also implements 'equality_expression'. */
644/* 'conditional_expression' also implements 'AND_expression'. */ 645/* 'conditional_expression' also implements 'AND_expression'. */
645/* 'conditional_expression' also implements 'exclusive_OR_expression'. */ 646/* 'conditional_expression' also implements 'exclusive_OR_expression'. */
646/* 'conditional_expression' also implements 'inclusive_OR_expression'. */ 647/* 'conditional_expression' also implements 'inclusive_OR_expression'. */
647/* 'conditional_expression' also implements 'logical_AND_expression'. */ 648/* 'conditional_expression' also implements 'logical_AND_expression'. */
648/* 'conditional_expression' also implements 'logical_OR_expression'. */ 649/* 'conditional_expression' also implements 'logical_OR_expression'. */
649/* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */ 650/* K&R ???, C90 ???, C99 6.5.5 to 6.5.15, C11 6.5.5 to 6.5.15 */
650conditional_expression: 651conditional_expression:
651 conditional_expression T_ASTERISK conditional_expression { 652 conditional_expression T_ASTERISK conditional_expression {
652 $$ = build_binary($1, MULT, $3); 653 $$ = build_binary($1, MULT, $3);
653 } 654 }
654 | conditional_expression T_MULTIPLICATIVE conditional_expression { 655 | conditional_expression T_MULTIPLICATIVE conditional_expression {
655 $$ = build_binary($1, $2, $3); 656 $$ = build_binary($1, $2, $3);
656 } 657 }
657 | conditional_expression T_ADDITIVE conditional_expression { 658 | conditional_expression T_ADDITIVE conditional_expression {
658 $$ = build_binary($1, $2, $3); 659 $$ = build_binary($1, $2, $3);
659 } 660 }
660 | conditional_expression T_SHIFT conditional_expression { 661 | conditional_expression T_SHIFT conditional_expression {
661 $$ = build_binary($1, $2, $3); 662 $$ = build_binary($1, $2, $3);
662 } 663 }
663 | conditional_expression T_RELATIONAL conditional_expression { 664 | conditional_expression T_RELATIONAL conditional_expression {
664 $$ = build_binary($1, $2, $3); 665 $$ = build_binary($1, $2, $3);
665 } 666 }
666 | conditional_expression T_EQUALITY conditional_expression { 667 | conditional_expression T_EQUALITY conditional_expression {
667 $$ = build_binary($1, $2, $3); 668 $$ = build_binary($1, $2, $3);
668 } 669 }
669 | conditional_expression T_AMPER conditional_expression { 670 | conditional_expression T_AMPER conditional_expression {
670 $$ = build_binary($1, BITAND, $3); 671 $$ = build_binary($1, BITAND, $3);
671 } 672 }
672 | conditional_expression T_BITXOR conditional_expression { 673 | conditional_expression T_BITXOR conditional_expression {
673 $$ = build_binary($1, BITXOR, $3); 674 $$ = build_binary($1, BITXOR, $3);
674 } 675 }
675 | conditional_expression T_BITOR conditional_expression { 676 | conditional_expression T_BITOR conditional_expression {
676 $$ = build_binary($1, BITOR, $3); 677 $$ = build_binary($1, BITOR, $3);
677 } 678 }
678 | conditional_expression T_LOGAND conditional_expression { 679 | conditional_expression T_LOGAND conditional_expression {
679 $$ = build_binary($1, LOGAND, $3); 680 $$ = build_binary($1, LOGAND, $3);
680 } 681 }
681 | conditional_expression T_LOGOR conditional_expression { 682 | conditional_expression T_LOGOR conditional_expression {
682 $$ = build_binary($1, LOGOR, $3); 683 $$ = build_binary($1, LOGOR, $3);
683 } 684 }
684 | conditional_expression T_QUEST conditional_expression 685 | conditional_expression T_QUEST conditional_expression
685 T_COLON conditional_expression { 686 T_COLON conditional_expression {
686 $$ = build_binary($1, QUEST, build_binary($3, COLON, $5)); 687 $$ = build_binary($1, QUEST, build_binary($3, COLON, $5));
687 } 688 }
688 | cast_expression; 689 | cast_expression;
689 690
690/* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */ 691/* K&R ???, C90 ???, C99 6.5.16, C11 6.5.16 */
691assignment_expression: 692assignment_expression:
692 conditional_expression 693 conditional_expression
693 | assignment_expression T_ASSIGN conditional_expression { 694 | assignment_expression T_ASSIGN conditional_expression {
694 $$ = build_binary($1, ASSIGN, $3); 695 $$ = build_binary($1, ASSIGN, $3);
695 } 696 }
696 | assignment_expression T_OPASSIGN conditional_expression { 697 | assignment_expression T_OPASSIGN conditional_expression {
697 $$ = build_binary($1, $2, $3); 698 $$ = build_binary($1, $2, $3);
698 } 699 }
699 ; 700 ;
700 701
701/* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */ 702/* K&R ???, C90 ???, C99 6.5.17, C11 6.5.17 */
702expression: 703expression:
703 assignment_expression 704 assignment_expression
704 | expression T_COMMA assignment_expression { 705 | expression T_COMMA assignment_expression {
705 $$ = build_binary($1, COMMA, $3); 706 $$ = build_binary($1, COMMA, $3);
706 } 707 }
707 ; 708 ;
708 709
709constant_expr_list_opt: /* helper for gcc_attribute */ 710constant_expr_list_opt: /* helper for gcc_attribute */
710 /* empty */ 711 /* empty */
711 | constant_expr_list 712 | constant_expr_list
712 ; 713 ;
713 714
714constant_expr_list: /* helper for gcc_attribute */ 715constant_expr_list: /* helper for gcc_attribute */
715 constant_expr 716 constant_expr
716 | constant_expr_list T_COMMA constant_expr 717 | constant_expr_list T_COMMA constant_expr
717 ; 718 ;
718 719
719constant_expr: /* C99 6.6 */ 720constant_expr: /* C99 6.6 */
720 conditional_expression 721 conditional_expression
721 ; 722 ;
722 723
723declaration_or_error: 724declaration_or_error:
724 declaration 725 declaration
725 | error T_SEMI 726 | error T_SEMI
726 ; 727 ;
727 728
728declaration: /* C99 6.7 */ 729declaration: /* C99 6.7 */
729 begin_type_declmods end_type T_SEMI { 730 begin_type_declmods end_type T_SEMI {
730 if (dcs->d_scl == TYPEDEF) { 731 if (dcs->d_scl == TYPEDEF) {
731 /* typedef declares no type name */ 732 /* typedef declares no type name */
732 warning(72); 733 warning(72);
733 } else { 734 } else {
734 /* empty declaration */ 735 /* empty declaration */
735 warning(2); 736 warning(2);
736 } 737 }
737 } 738 }
738 | begin_type_declmods end_type notype_init_declarators T_SEMI 739 | begin_type_declmods end_type notype_init_declarators T_SEMI
 740 /* ^^ There is no check for the missing type-specifier. */
739 | begin_type_declaration_specifiers end_type T_SEMI { 741 | begin_type_declaration_specifiers end_type T_SEMI {
740 if (dcs->d_scl == TYPEDEF) { 742 if (dcs->d_scl == TYPEDEF) {
741 /* typedef declares no type name */ 743 /* typedef declares no type name */
742 warning(72); 744 warning(72);
743 } else if (!dcs->d_nonempty_decl) { 745 } else if (!dcs->d_nonempty_decl) {
744 /* empty declaration */ 746 /* empty declaration */
745 warning(2); 747 warning(2);
746 } 748 }
747 } 749 }
748 | begin_type_declaration_specifiers end_type 750 | begin_type_declaration_specifiers end_type
749 type_init_declarators T_SEMI 751 type_init_declarators T_SEMI
750 ; 752 ;
751 753
752begin_type_declaration_specifiers: /* see C99 6.7 */ 754begin_type_declaration_specifiers: /* see C99 6.7 */
753 begin_type_typespec { 755 begin_type_typespec {
754 add_type($1); 756 add_type($1);
755 } 757 }
756 | begin_type_declmods type_specifier { 758 | begin_type_declmods type_specifier {
757 add_type($2); 759 add_type($2);
758 } 760 }
759 | type_attribute begin_type_declaration_specifiers 761 | type_attribute begin_type_declaration_specifiers
760 | begin_type_declaration_specifiers declmod 762 | begin_type_declaration_specifiers declmod
761 | begin_type_declaration_specifiers notype_type_specifier { 763 | begin_type_declaration_specifiers notype_type_specifier {
762 add_type($2); 764 add_type($2);
763 } 765 }
764 ; 766 ;
765 767
766begin_type_declmods: /* see C99 6.7 */ 768begin_type_declmods: /* see C99 6.7 */
767 begin_type T_QUAL { 769 begin_type T_QUAL {
768 add_qualifier($2); 770 add_qualifier($2);
769 } 771 }
770 | begin_type T_SCLASS { 772 | begin_type T_SCLASS {
771 add_storage_class($2); 773 add_storage_class($2);
772 } 774 }
773 | begin_type_declmods declmod 775 | begin_type_declmods declmod
774 ; 776 ;
775 777
776begin_type_specifier_qualifier_list: /* see C11 6.7.2.1 */ 778begin_type_specifier_qualifier_list: /* see C11 6.7.2.1 */
777 begin_type_typespec { 779 begin_type_typespec {
778 add_type($1); 780 add_type($1);
779 } 781 }
 782 /* TODO: shift/reduce conflict for type_attribute */
780 | type_attribute begin_type_specifier_qualifier_list 783 | type_attribute begin_type_specifier_qualifier_list
781 | begin_type_qualifier_list type_specifier { 784 | begin_type_qualifier_list type_specifier {
782 add_type($2); 785 add_type($2);
783 } 786 }
784 | begin_type_specifier_qualifier_list T_QUAL { 787 | begin_type_specifier_qualifier_list T_QUAL {
785 add_qualifier($2); 788 add_qualifier($2);
786 } 789 }
787 | begin_type_specifier_qualifier_list notype_type_specifier { 790 | begin_type_specifier_qualifier_list notype_type_specifier {
788 add_type($2); 791 add_type($2);
789 } 792 }
790 | begin_type_specifier_qualifier_list type_attribute 793 | begin_type_specifier_qualifier_list type_attribute
791 ; 794 ;
792 795
793begin_type_typespec: 796begin_type_typespec:
794 begin_type notype_type_specifier { 797 begin_type notype_type_specifier {
795 $$ = $2; 798 $$ = $2;
796 } 799 }
797 | T_TYPENAME begin_type { 800 | T_TYPENAME begin_type {
798 $$ = getsym($1)->s_type; 801 $$ = getsym($1)->s_type;
799 } 802 }
800 ; 803 ;
801 804
802begin_type_qualifier_list: 805begin_type_qualifier_list:
803 begin_type T_QUAL { 806 begin_type T_QUAL {
804 add_qualifier($2); 807 add_qualifier($2);
805 } 808 }
806 | begin_type_qualifier_list T_QUAL { 809 | begin_type_qualifier_list T_QUAL {
807 add_qualifier($2); 810 add_qualifier($2);
808 } 811 }
809 ; 812 ;
810 813
811declmod: 814declmod:
812 T_QUAL { 815 T_QUAL {
813 add_qualifier($1); 816 add_qualifier($1);
814 } 817 }
815 | T_SCLASS { 818 | T_SCLASS {
816 add_storage_class($1); 819 add_storage_class($1);
817 } 820 }
818 | type_attribute_list 821 | type_attribute_list
819 ; 822 ;
820 823
821type_attribute_list: 824type_attribute_list:
822 type_attribute 825 type_attribute
823 | type_attribute_list type_attribute 826 | type_attribute_list type_attribute
824 ; 827 ;
825 828
826type_attribute_opt: 829type_attribute_opt:
827 /* empty */ 830 /* empty */
828 | type_attribute 831 | type_attribute
829 ; 832 ;
830 833
831type_attribute: /* See C11 6.7 declaration-specifiers */ 834type_attribute: /* See C11 6.7 declaration-specifiers */
832 T_ATTRIBUTE T_LPAREN T_LPAREN { 835 T_ATTRIBUTE T_LPAREN T_LPAREN {
833 attron = true; 836 attron = true;
834 } gcc_attribute_spec_list { 837 } gcc_attribute_spec_list {
835 attron = false; 838 attron = false;
836 } T_RPAREN T_RPAREN 839 } T_RPAREN T_RPAREN
 840 /* TODO: c11ism */
837 | T_ALIGNAS T_LPAREN align_as T_RPAREN 841 | T_ALIGNAS T_LPAREN align_as T_RPAREN
838 | T_PACKED { 842 | T_PACKED {
839 addpacked(); 843 addpacked();
840 } 844 }
841 | T_NORETURN 845 | T_NORETURN
842 ; 846 ;
843 847
844align_as: /* See alignment-specifier in C11 6.7.5 */ 848align_as: /* See alignment-specifier in C11 6.7.5 */
845 type_specifier 849 type_specifier
846 | constant_expr 850 | constant_expr
847 ; 851 ;
848 852
849begin_type: 853begin_type:
850 /* empty */ { 854 /* empty */ {
851 begin_type(); 855 begin_type();
852 } 856 }
853 ; 857 ;
854 858
855end_type: 859end_type:
856 /* empty */ { 860 /* empty */ {
857 end_type(); 861 end_type();
858 } 862 }
859 ; 863 ;
860 864
861type_specifier: /* C99 6.7.2 */ 865type_specifier: /* C99 6.7.2 */
862 notype_type_specifier 866 notype_type_specifier
863 | T_TYPENAME { 867 | T_TYPENAME {
864 $$ = getsym($1)->s_type; 868 $$ = getsym($1)->s_type;
865 } 869 }
866 ; 870 ;
867 871
868notype_type_specifier: /* see C99 6.7.2 */ 872notype_type_specifier: /* see C99 6.7.2 */
869 T_TYPE { 873 T_TYPE {
870 $$ = gettyp($1); 874 $$ = gettyp($1);
871 } 875 }
872 | T_TYPEOF cast_expression { /* GCC extension */ 876 | T_TYPEOF cast_expression { /* GCC extension */
873 $$ = $2->tn_type; 877 $$ = $2->tn_type;
874 } 878 }
875 | struct_or_union_specifier { 879 | struct_or_union_specifier {
876 end_declaration_level(); 880 end_declaration_level();
877 $$ = $1; 881 $$ = $1;
878 } 882 }
879 | enum_specifier { 883 | enum_specifier {
880 end_declaration_level(); 884 end_declaration_level();
881 $$ = $1; 885 $$ = $1;
882 } 886 }
883 ; 887 ;
884 888
885struct_or_union_specifier: /* C99 6.7.2.1 */ 889struct_or_union_specifier: /* C99 6.7.2.1 */
886 struct_or_union identifier_sym { 890 struct_or_union identifier_sym {
887 /* 891 /*
888 * STDC requires that "struct a;" always introduces 892 * STDC requires that "struct a;" always introduces
889 * a new tag if "a" is not declared at current level 893 * a new tag if "a" is not declared at current level
890 * 894 *
891 * yychar is valid because otherwise the parser would not 895 * yychar is valid because otherwise the parser would not
892 * have been able to decide if it must shift or reduce 896 * have been able to decide if it must shift or reduce
893 */ 897 */
894 $$ = mktag($2, $1, false, yychar == T_SEMI); 898 $$ = mktag($2, $1, false, yychar == T_SEMI);
895 } 899 }
896 | struct_or_union identifier_sym { 900 | struct_or_union identifier_sym {
897 dcs->d_tagtyp = mktag($2, $1, true, false); 901 dcs->d_tagtyp = mktag($2, $1, true, false);
898 } braced_struct_declaration_list { 902 } braced_struct_declaration_list {
899 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4); 903 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
900 } 904 }
901 | struct_or_union { 905 | struct_or_union {
902 dcs->d_tagtyp = mktag(NULL, $1, true, false); 906 dcs->d_tagtyp = mktag(NULL, $1, true, false);
903 } braced_struct_declaration_list { 907 } braced_struct_declaration_list {
904 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); 908 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
905 } 909 }
906 | struct_or_union error { 910 | struct_or_union error {
907 symtyp = FVFT; 911 symtyp = FVFT;
908 $$ = gettyp(INT); 912 $$ = gettyp(INT);
909 } 913 }
910 ; 914 ;
911 915
912struct_or_union: /* C99 6.7.2.1 */ 916struct_or_union: /* C99 6.7.2.1 */
913 struct_or_union type_attribute 917 struct_or_union type_attribute
914 | T_STRUCT_OR_UNION { 918 | T_STRUCT_OR_UNION {
915 symtyp = FTAG; 919 symtyp = FTAG;
916 begin_declaration_level($1 == STRUCT ? MOS : MOU); 920 begin_declaration_level($1 == STRUCT ? MOS : MOU);
917 dcs->d_offset = 0; 921 dcs->d_offset = 0;
918 dcs->d_sou_align_in_bits = CHAR_SIZE; 922 dcs->d_sou_align_in_bits = CHAR_SIZE;
919 $$ = $1; 923 $$ = $1;
920 } 924 }
921 ; 925 ;
922 926
923braced_struct_declaration_list: /* see C99 6.7.2.1 */ 927braced_struct_declaration_list: /* see C99 6.7.2.1 */
924 struct_declaration_lbrace struct_declaration_list_with_rbrace { 928 struct_declaration_lbrace struct_declaration_list_with_rbrace {
925 $$ = $2; 929 $$ = $2;
926 } 930 }
927 ; 931 ;
928 932
929struct_declaration_lbrace: /* see C99 6.7.2.1 */ 933struct_declaration_lbrace: /* see C99 6.7.2.1 */
930 T_LBRACE { 934 T_LBRACE {
931 symtyp = FVFT; 935 symtyp = FVFT;
932 } 936 }
933 ; 937 ;
934 938
935struct_declaration_list_with_rbrace: /* see C99 6.7.2.1 */ 939struct_declaration_list_with_rbrace: /* see C99 6.7.2.1 */
936 struct_declaration_list T_RBRACE 940 struct_declaration_list T_RBRACE
937 | T_RBRACE { 941 | T_RBRACE {
938 /* XXX: This is not allowed by any C standard. */ 942 /* XXX: This is not allowed by any C standard. */
939 $$ = NULL; 943 $$ = NULL;
940 } 944 }
941 ; 945 ;
942 946
943struct_declaration_list: /* C99 6.7.2.1 */ 947struct_declaration_list: /* C99 6.7.2.1 */
944 struct_declaration 948 struct_declaration
945 | struct_declaration_list struct_declaration { 949 | struct_declaration_list struct_declaration {
946 $$ = lnklst($1, $2); 950 $$ = lnklst($1, $2);
947 } 951 }
948 ; 952 ;
949 953
950struct_declaration: /* C99 6.7.2.1 */ 954struct_declaration: /* C99 6.7.2.1 */
951 begin_type_qualifier_list end_type { 955 begin_type_qualifier_list end_type {
 956 /* ^^ There is no check for the missing type-specifier. */
952 /* too late, i know, but getsym() compensates it */ 957 /* too late, i know, but getsym() compensates it */
953 symtyp = FMEMBER; 958 symtyp = FMEMBER;
954 } notype_struct_declarators type_attribute_opt T_SEMI { 959 } notype_struct_declarators type_attribute_opt T_SEMI {
955 symtyp = FVFT; 960 symtyp = FVFT;
956 $$ = $4; 961 $$ = $4;
957 } 962 }
958 | begin_type_specifier_qualifier_list end_type { 963 | begin_type_specifier_qualifier_list end_type {
959 symtyp = FMEMBER; 964 symtyp = FMEMBER;
960 } type_struct_declarators type_attribute_opt T_SEMI { 965 } type_struct_declarators type_attribute_opt T_SEMI {
961 symtyp = FVFT; 966 symtyp = FVFT;
962 $$ = $4; 967 $$ = $4;
963 } 968 }
964 | begin_type_qualifier_list end_type type_attribute_opt T_SEMI { 969 | begin_type_qualifier_list end_type type_attribute_opt T_SEMI {
965 /* syntax error '%s' */ 970 /* syntax error '%s' */
966 error(249, "member without type"); 971 error(249, "member without type");
967 $$ = NULL; 972 $$ = NULL;
968 } 973 }
969 | begin_type_specifier_qualifier_list end_type type_attribute_opt T_SEMI { 974 | begin_type_specifier_qualifier_list end_type type_attribute_opt T_SEMI {
970 symtyp = FVFT; 975 symtyp = FVFT;
971 if (!Sflag) 976 if (!Sflag)
972 /* anonymous struct/union members is a C9X feature */ 977 /* anonymous struct/union members is a C9X feature */
973 warning(49); 978 warning(49);
974 if (is_struct_or_union(dcs->d_type->t_tspec)) { 979 if (is_struct_or_union(dcs->d_type->t_tspec)) {
975 $$ = dcs->d_type->t_str->sou_first_member; 980 $$ = dcs->d_type->t_str->sou_first_member;
976 /* add all the members of the anonymous struct/union */ 981 /* add all the members of the anonymous struct/union */
977 anonymize($$); 982 anonymize($$);
978 } else { 983 } else {
979 /* syntax error '%s' */ 984 /* syntax error '%s' */
980 error(249, "unnamed member"); 985 error(249, "unnamed member");
981 $$ = NULL; 986 $$ = NULL;
982 } 987 }
983 } 988 }
984 | error T_SEMI { 989 | error T_SEMI {
985 symtyp = FVFT; 990 symtyp = FVFT;
986 $$ = NULL; 991 $$ = NULL;
987 } 992 }
988 ; 993 ;
989 994
990notype_struct_declarators: 995notype_struct_declarators:
991 notype_struct_declarator { 996 notype_struct_declarator {
992 $$ = declarator_1_struct_union($1); 997 $$ = declarator_1_struct_union($1);
993 } 998 }
994 | notype_struct_declarators { 999 | notype_struct_declarators {
995 symtyp = FMEMBER; 1000 symtyp = FMEMBER;
996 } T_COMMA type_struct_declarator { 1001 } T_COMMA type_struct_declarator {
997 $$ = lnklst($1, declarator_1_struct_union($4)); 1002 $$ = lnklst($1, declarator_1_struct_union($4));
998 } 1003 }
999 ; 1004 ;
1000 1005
1001type_struct_declarators: 1006type_struct_declarators:
1002 type_struct_declarator { 1007 type_struct_declarator {
1003 $$ = declarator_1_struct_union($1); 1008 $$ = declarator_1_struct_union($1);
1004 } 1009 }
1005 | type_struct_declarators { 1010 | type_struct_declarators {
1006 symtyp = FMEMBER; 1011 symtyp = FMEMBER;
1007 } T_COMMA type_struct_declarator { 1012 } T_COMMA type_struct_declarator {
1008 $$ = lnklst($1, declarator_1_struct_union($4)); 1013 $$ = lnklst($1, declarator_1_struct_union($4));
1009 } 1014 }
1010 ; 1015 ;
1011 1016
1012notype_struct_declarator: 1017notype_struct_declarator:
1013 notype_declarator 1018 notype_declarator
1014 | notype_declarator T_COLON constant_expr { /* C99 6.7.2.1 */ 1019 | notype_declarator T_COLON constant_expr { /* C99 6.7.2.1 */
1015 $$ = bitfield($1, to_int_constant($3, true)); 1020 $$ = bitfield($1, to_int_constant($3, true));
1016 } 1021 }
1017 | { 1022 | {
1018 symtyp = FVFT; 1023 symtyp = FVFT;
1019 } T_COLON constant_expr { /* C99 6.7.2.1 */ 1024 } T_COLON constant_expr { /* C99 6.7.2.1 */
1020 $$ = bitfield(NULL, to_int_constant($3, true)); 1025 $$ = bitfield(NULL, to_int_constant($3, true));
1021 } 1026 }
1022 ; 1027 ;
1023 1028
1024type_struct_declarator: 1029type_struct_declarator:
1025 type_declarator 1030 type_declarator
1026 | type_declarator T_COLON constant_expr { 1031 | type_declarator T_COLON constant_expr {
1027 $$ = bitfield($1, to_int_constant($3, true)); 1032 $$ = bitfield($1, to_int_constant($3, true));
1028 } 1033 }
1029 | { 1034 | {
1030 symtyp = FVFT; 1035 symtyp = FVFT;
1031 } T_COLON constant_expr { 1036 } T_COLON constant_expr {
1032 $$ = bitfield(NULL, to_int_constant($3, true)); 1037 $$ = bitfield(NULL, to_int_constant($3, true));
1033 } 1038 }
1034 ; 1039 ;
1035 1040
1036enum_specifier: /* C99 6.7.2.2 */ 1041enum_specifier: /* C99 6.7.2.2 */
1037 enum identifier_sym { 1042 enum identifier_sym {
1038 $$ = mktag($2, ENUM, false, false); 1043 $$ = mktag($2, ENUM, false, false);
1039 } 1044 }
1040 | enum identifier_sym { 1045 | enum identifier_sym {
1041 dcs->d_tagtyp = mktag($2, ENUM, true, false); 1046 dcs->d_tagtyp = mktag($2, ENUM, true, false);
1042 } enum_declaration { 1047 } enum_declaration {
1043 $$ = complete_tag_enum(dcs->d_tagtyp, $4); 1048 $$ = complete_tag_enum(dcs->d_tagtyp, $4);
1044 } 1049 }
1045 | enum { 1050 | enum {
1046 dcs->d_tagtyp = mktag(NULL, ENUM, true, false); 1051 dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
1047 } enum_declaration { 1052 } enum_declaration {
1048 $$ = complete_tag_enum(dcs->d_tagtyp, $3); 1053 $$ = complete_tag_enum(dcs->d_tagtyp, $3);
1049 } 1054 }
1050 | enum error { 1055 | enum error {
1051 symtyp = FVFT; 1056 symtyp = FVFT;
1052 $$ = gettyp(INT); 1057 $$ = gettyp(INT);
1053 } 1058 }
1054 ; 1059 ;
1055 1060
1056enum: /* helper for C99 6.7.2.2 */ 1061enum: /* helper for C99 6.7.2.2 */
1057 T_ENUM { 1062 T_ENUM {
1058 symtyp = FTAG; 1063 symtyp = FTAG;
1059 begin_declaration_level(CTCONST); 1064 begin_declaration_level(CTCONST);
1060 } 1065 }
1061 ; 1066 ;
1062 1067
1063enum_declaration: /* helper for C99 6.7.2.2 */ 1068enum_declaration: /* helper for C99 6.7.2.2 */
1064 enum_decl_lbrace enums_with_opt_comma T_RBRACE { 1069 enum_decl_lbrace enums_with_opt_comma T_RBRACE {
1065 $$ = $2; 1070 $$ = $2;
1066 } 1071 }
1067 ; 1072 ;
1068 1073
1069enum_decl_lbrace: /* helper for C99 6.7.2.2 */ 1074enum_decl_lbrace: /* helper for C99 6.7.2.2 */
1070 T_LBRACE { 1075 T_LBRACE {
1071 symtyp = FVFT; 1076 symtyp = FVFT;
1072 enumval = 0; 1077 enumval = 0;
1073 } 1078 }
1074 ; 1079 ;
1075 1080
1076enums_with_opt_comma: /* helper for C99 6.7.2.2 */ 1081enums_with_opt_comma: /* helper for C99 6.7.2.2 */
1077 enumerator_list 1082 enumerator_list
1078 | enumerator_list T_COMMA { 1083 | enumerator_list T_COMMA {
1079 if (sflag) { 1084 if (sflag) {
1080 /* trailing ',' prohibited in enum declaration */ 1085 /* trailing ',' prohibited in enum declaration */
1081 error(54); 1086 error(54);
1082 } else { 1087 } else {
1083 /* trailing ',' prohibited in enum declaration */ 1088 /* trailing ',' prohibited in enum declaration */
1084 c99ism(54); 1089 c99ism(54);
1085 } 1090 }
1086 $$ = $1; 1091 $$ = $1;
1087 } 1092 }
1088 ; 1093 ;
1089 1094
1090enumerator_list: /* C99 6.7.2.2 */ 1095enumerator_list: /* C99 6.7.2.2 */
1091 enumerator 1096 enumerator
1092 | enumerator_list T_COMMA enumerator { 1097 | enumerator_list T_COMMA enumerator {
1093 $$ = lnklst($1, $3); 1098 $$ = lnklst($1, $3);
1094 } 1099 }
1095 | error { 1100 | error {
1096 $$ = NULL; 1101 $$ = NULL;
1097 } 1102 }
1098 ; 1103 ;
1099 1104
1100enumerator: /* C99 6.7.2.2 */ 1105enumerator: /* C99 6.7.2.2 */
1101 identifier_sym { 1106 identifier_sym {
1102 $$ = enumeration_constant($1, enumval, true); 1107 $$ = enumeration_constant($1, enumval, true);
1103 } 1108 }
1104 | identifier_sym T_ASSIGN constant_expr { 1109 | identifier_sym T_ASSIGN constant_expr {
1105 $$ = enumeration_constant($1, to_int_constant($3, true), false); 1110 $$ = enumeration_constant($1, to_int_constant($3, true), false);
1106 } 1111 }
1107 ; 1112 ;
1108 1113
1109type_qualifier: /* C99 6.7.3 */ 1114type_qualifier: /* C99 6.7.3 */
1110 T_QUAL { 1115 T_QUAL {
1111 $$ = xcalloc(1, sizeof(*$$)); 1116 $$ = xcalloc(1, sizeof(*$$));
1112 if ($1 == CONST) 1117 if ($1 == CONST)
1113 $$->p_const = true; 1118 $$->p_const = true;
1114 if ($1 == VOLATILE) 1119 if ($1 == VOLATILE)
1115 $$->p_volatile = true; 1120 $$->p_volatile = true;
1116 } 1121 }
1117 ; 1122 ;
1118 1123
1119pointer: /* C99 6.7.5 */ 1124pointer: /* C99 6.7.5 */
1120 asterisk type_qualifier_list_opt { 1125 asterisk type_qualifier_list_opt {
1121 $$ = merge_qualified_pointer($1, $2); 1126 $$ = merge_qualified_pointer($1, $2);
1122 } 1127 }
1123 | asterisk type_qualifier_list_opt pointer { 1128 | asterisk type_qualifier_list_opt pointer {
1124 $$ = merge_qualified_pointer($1, $2); 1129 $$ = merge_qualified_pointer($1, $2);
1125 $$ = merge_qualified_pointer($$, $3); 1130 $$ = merge_qualified_pointer($$, $3);
1126 } 1131 }
1127 ; 1132 ;
1128 1133
1129asterisk: /* helper for 'pointer' */ 1134asterisk: /* helper for 'pointer' */
1130 T_ASTERISK { 1135 T_ASTERISK {
1131 $$ = xcalloc(1, sizeof(*$$)); 1136 $$ = xcalloc(1, sizeof(*$$));
1132 $$->p_pointer = true; 1137 $$->p_pointer = true;
1133 } 1138 }
1134 ; 1139 ;
1135 1140
1136type_qualifier_list_opt: /* see C99 6.7.5 */ 1141type_qualifier_list_opt: /* see C99 6.7.5 */
1137 /* empty */ { 1142 /* empty */ {
1138 $$ = NULL; 1143 $$ = NULL;
1139 } 1144 }
1140 | type_qualifier_list 1145 | type_qualifier_list
1141 ; 1146 ;
1142 1147
1143type_qualifier_list: /* C99 6.7.5 */ 1148type_qualifier_list: /* C99 6.7.5 */
1144 type_qualifier 1149 type_qualifier
1145 | type_qualifier_list type_qualifier { 1150 | type_qualifier_list type_qualifier {
1146 $$ = merge_qualified_pointer($1, $2); 1151 $$ = merge_qualified_pointer($1, $2);
1147 } 1152 }
1148 ; 1153 ;
1149 1154
1150/* 1155/*
1151 * For an explanation of 'notype' in the following rules, see the Bison 1156 * For an explanation of 'notype' in the following rules, see the Bison
1152 * manual, section 7.1 "Semantic Info in Token Kinds". 1157 * manual, section 7.1 "Semantic Info in Token Kinds".
1153 */ 1158 */
1154 1159
1155notype_init_declarators: 1160notype_init_declarators:
1156 notype_init_declarator 1161 notype_init_declarator
1157 | notype_init_declarators T_COMMA type_init_declarator 1162 | notype_init_declarators T_COMMA type_init_declarator
1158 ; 1163 ;
1159 1164
1160type_init_declarators: 1165type_init_declarators:
1161 type_init_declarator 1166 type_init_declarator
1162 | type_init_declarators T_COMMA type_init_declarator 1167 | type_init_declarators T_COMMA type_init_declarator
1163 ; 1168 ;
1164 1169
1165notype_init_declarator: 1170notype_init_declarator:
1166 notype_declarator asm_or_symbolrename_opt { 1171 notype_declarator asm_or_symbolrename_opt {
1167 cgram_declare($1, false, $2); 1172 cgram_declare($1, false, $2);
1168 check_size($1); 1173 check_size($1);
1169 } 1174 }
1170 | notype_declarator asm_or_symbolrename_opt { 1175 | notype_declarator asm_or_symbolrename_opt {
1171 begin_initialization($1); 1176 begin_initialization($1);
1172 cgram_declare($1, true, $2); 1177 cgram_declare($1, true, $2);
1173 } T_ASSIGN initializer { 1178 } T_ASSIGN initializer {
1174 check_size($1); 1179 check_size($1);
1175 end_initialization(); 1180 end_initialization();
1176 } 1181 }
1177 ; 1182 ;
1178 1183
1179type_init_declarator: 1184type_init_declarator:
1180 type_declarator asm_or_symbolrename_opt { 1185 type_declarator asm_or_symbolrename_opt {
1181 cgram_declare($1, false, $2); 1186 cgram_declare($1, false, $2);
1182 check_size($1); 1187 check_size($1);
1183 } 1188 }
1184 | type_declarator asm_or_symbolrename_opt { 1189 | type_declarator asm_or_symbolrename_opt {
1185 begin_initialization($1); 1190 begin_initialization($1);
1186 cgram_declare($1, true, $2); 1191 cgram_declare($1, true, $2);
1187 } T_ASSIGN initializer { 1192 } T_ASSIGN initializer {
1188 check_size($1); 1193 check_size($1);
1189 end_initialization(); 1194 end_initialization();
1190 } 1195 }
1191 ; 1196 ;
1192 1197
1193notype_declarator: 1198notype_declarator:
1194 notype_direct_declarator 1199 notype_direct_declarator
1195 | pointer notype_direct_declarator { 1200 | pointer notype_direct_declarator {
1196 $$ = add_pointer($2, $1); 1201 $$ = add_pointer($2, $1);
1197 } 1202 }
1198 ; 1203 ;
1199 1204
1200type_declarator: 1205type_declarator:
1201 type_direct_declarator 1206 type_direct_declarator
1202 | pointer type_direct_declarator { 1207 | pointer type_direct_declarator {
1203 $$ = add_pointer($2, $1); 1208 $$ = add_pointer($2, $1);
1204 } 1209 }
1205 ; 1210 ;
1206 1211
1207notype_direct_declarator: 1212notype_direct_declarator:
1208 T_NAME { 1213 T_NAME {
1209 $$ = declarator_name(getsym($1)); 1214 $$ = declarator_name(getsym($1));
1210 } 1215 }
1211 | T_LPAREN type_declarator T_RPAREN { 1216 | T_LPAREN type_declarator T_RPAREN {
1212 $$ = $2; 1217 $$ = $2;
1213 } 1218 }
1214 | type_attribute notype_direct_declarator { 1219 | type_attribute notype_direct_declarator {
1215 $$ = $2; 1220 $$ = $2;
1216 } 1221 }
1217 | notype_direct_declarator T_LBRACK T_RBRACK { 1222 | notype_direct_declarator T_LBRACK T_RBRACK {
1218 $$ = add_array($1, false, 0); 1223 $$ = add_array($1, false, 0);
1219 } 1224 }
1220 | notype_direct_declarator T_LBRACK array_size T_RBRACK { 1225 | notype_direct_declarator T_LBRACK array_size T_RBRACK {
1221 $$ = add_array($1, true, to_int_constant($3, false)); 1226 $$ = add_array($1, true, to_int_constant($3, false));
1222 } 1227 }
1223 | notype_direct_declarator param_list asm_or_symbolrename_opt { 1228 | notype_direct_declarator param_list asm_or_symbolrename_opt {
1224 $$ = add_function(symbolrename($1, $3), $2); 1229 $$ = add_function(symbolrename($1, $3), $2);
1225 end_declaration_level(); 1230 end_declaration_level();
1226 block_level--; 1231 block_level--;
1227 } 1232 }
1228 | notype_direct_declarator type_attribute 1233 | notype_direct_declarator type_attribute
1229 ; 1234 ;
1230 1235
1231type_direct_declarator: 1236type_direct_declarator:
1232 identifier { 1237 identifier {
1233 $$ = declarator_name(getsym($1)); 1238 $$ = declarator_name(getsym($1));
1234 } 1239 }
1235 | T_LPAREN type_declarator T_RPAREN { 1240 | T_LPAREN type_declarator T_RPAREN {
1236 $$ = $2; 1241 $$ = $2;
1237 } 1242 }
1238 | type_attribute type_direct_declarator { 1243 | type_attribute type_direct_declarator {
1239 $$ = $2; 1244 $$ = $2;
1240 } 1245 }
1241 | type_direct_declarator T_LBRACK T_RBRACK { 1246 | type_direct_declarator T_LBRACK T_RBRACK {
1242 $$ = add_array($1, false, 0); 1247 $$ = add_array($1, false, 0);
1243 } 1248 }
1244 | type_direct_declarator T_LBRACK array_size T_RBRACK { 1249 | type_direct_declarator T_LBRACK array_size T_RBRACK {
1245 $$ = add_array($1, true, to_int_constant($3, false)); 1250 $$ = add_array($1, true, to_int_constant($3, false));
1246 } 1251 }
1247 | type_direct_declarator param_list asm_or_symbolrename_opt { 1252 | type_direct_declarator param_list asm_or_symbolrename_opt {
1248 $$ = add_function(symbolrename($1, $3), $2); 1253 $$ = add_function(symbolrename($1, $3), $2);
1249 end_declaration_level(); 1254 end_declaration_level();
1250 block_level--; 1255 block_level--;
1251 } 1256 }
1252 | type_direct_declarator type_attribute 1257 | type_direct_declarator type_attribute
1253 ; 1258 ;
1254 1259
1255/* 1260/*
1256 * The two distinct rules type_param_declarator and notype_param_declarator avoid a 1261 * The two distinct rules type_param_declarator and notype_param_declarator avoid a
1257 * conflict in argument lists. A typename enclosed in parentheses is always 1262 * conflict in argument lists. A typename enclosed in parentheses is always
1258 * treated as a typename, not an argument name. For example, after 1263 * treated as a typename, not an argument name. For example, after
1259 * "typedef double a;", the declaration "f(int (a));" is interpreted as 1264 * "typedef double a;", the declaration "f(int (a));" is interpreted as
1260 * "f(int (double));", not "f(int a);". 1265 * "f(int (double));", not "f(int a);".
1261 */ 1266 */
1262type_param_declarator: 1267type_param_declarator:
1263 direct_param_declarator 1268 direct_param_declarator
1264 | pointer direct_param_declarator { 1269 | pointer direct_param_declarator {
1265 $$ = add_pointer($2, $1); 1270 $$ = add_pointer($2, $1);
1266 } 1271 }
1267 ; 1272 ;
1268 1273
1269notype_param_declarator: 1274notype_param_declarator:
1270 direct_notype_param_declarator 1275 direct_notype_param_declarator
1271 | pointer direct_notype_param_declarator { 1276 | pointer direct_notype_param_declarator {
1272 $$ = add_pointer($2, $1); 1277 $$ = add_pointer($2, $1);
1273 } 1278 }
1274 ; 1279 ;
1275 1280
1276direct_param_declarator: 1281direct_param_declarator:
1277 identifier type_attribute_list { 1282 identifier type_attribute_list {
1278 $$ = declarator_name(getsym($1)); 1283 $$ = declarator_name(getsym($1));
1279 } 1284 }
1280 | identifier { 1285 | identifier {
1281 $$ = declarator_name(getsym($1)); 1286 $$ = declarator_name(getsym($1));
1282 } 1287 }
1283 | T_LPAREN notype_param_declarator T_RPAREN { 1288 | T_LPAREN notype_param_declarator T_RPAREN {
1284 $$ = $2; 1289 $$ = $2;
1285 } 1290 }
1286 | direct_param_declarator T_LBRACK T_RBRACK { 1291 | direct_param_declarator T_LBRACK T_RBRACK {
1287 $$ = add_array($1, false, 0); 1292 $$ = add_array($1, false, 0);
1288 } 1293 }
1289 | direct_param_declarator T_LBRACK array_size T_RBRACK { 1294 | direct_param_declarator T_LBRACK array_size T_RBRACK {
1290 $$ = add_array($1, true, to_int_constant($3, false)); 1295 $$ = add_array($1, true, to_int_constant($3, false));
1291 } 1296 }
1292 | direct_param_declarator param_list asm_or_symbolrename_opt { 1297 | direct_param_declarator param_list asm_or_symbolrename_opt {
1293 $$ = add_function(symbolrename($1, $3), $2); 1298 $$ = add_function(symbolrename($1, $3), $2);
1294 end_declaration_level(); 1299 end_declaration_level();
1295 block_level--; 1300 block_level--;
1296 } 1301 }
1297 ; 1302 ;
1298 1303
1299direct_notype_param_declarator: 1304direct_notype_param_declarator:
1300 identifier { 1305 identifier {
1301 $$ = declarator_name(getsym($1)); 1306 $$ = declarator_name(getsym($1));
1302 } 1307 }
1303 | T_LPAREN notype_param_declarator T_RPAREN { 1308 | T_LPAREN notype_param_declarator T_RPAREN {
1304 $$ = $2; 1309 $$ = $2;
1305 } 1310 }
1306 | direct_notype_param_declarator T_LBRACK T_RBRACK { 1311 | direct_notype_param_declarator T_LBRACK T_RBRACK {
1307 $$ = add_array($1, false, 0); 1312 $$ = add_array($1, false, 0);
1308 } 1313 }
1309 | direct_notype_param_declarator T_LBRACK array_size T_RBRACK { 1314 | direct_notype_param_declarator T_LBRACK array_size T_RBRACK {
1310 $$ = add_array($1, true, to_int_constant($3, false)); 1315 $$ = add_array($1, true, to_int_constant($3, false));
1311 } 1316 }
1312 | direct_notype_param_declarator param_list asm_or_symbolrename_opt { 1317 | direct_notype_param_declarator param_list asm_or_symbolrename_opt {
1313 $$ = add_function(symbolrename($1, $3), $2); 1318 $$ = add_function(symbolrename($1, $3), $2);
1314 end_declaration_level(); 1319 end_declaration_level();
1315 block_level--; 1320 block_level--;
1316 } 1321 }
1317 ; 1322 ;
1318 1323
1319param_list: 1324param_list:
1320 id_list_lparen identifier_list T_RPAREN { 1325 id_list_lparen identifier_list T_RPAREN {
1321 $$ = $2; 1326 $$ = $2;
1322 } 1327 }
1323 | abstract_decl_param_list 1328 | abstract_decl_param_list
1324 ; 1329 ;
1325 1330
1326id_list_lparen: 1331id_list_lparen:
1327 T_LPAREN { 1332 T_LPAREN {
1328 block_level++; 1333 block_level++;
1329 begin_declaration_level(PROTO_ARG); 1334 begin_declaration_level(PROTO_ARG);
1330 } 1335 }
1331 ; 1336 ;
1332 1337
1333array_size: 1338array_size:
1334 type_qualifier_list_opt T_SCLASS constant_expr { 1339 type_qualifier_list_opt T_SCLASS constant_expr {
1335 /* C11 6.7.6.3p7 */ 1340 /* C11 6.7.6.3p7 */
1336 if ($2 != STATIC) 1341 if ($2 != STATIC)
1337 yyerror("Bad attribute"); 1342 yyerror("Bad attribute");
1338 /* static array size is a C11 extension */ 1343 /* static array size is a C11 extension */
1339 c11ism(343); 1344 c11ism(343);
1340 $$ = $3; 1345 $$ = $3;
1341 } 1346 }
1342 | constant_expr 1347 | constant_expr
1343 ; 1348 ;
1344 1349
1345identifier_list: /* C99 6.7.5 */ 1350identifier_list: /* C99 6.7.5 */
1346 T_NAME { 1351 T_NAME {
1347 $$ = old_style_function_name(getsym($1)); 1352 $$ = old_style_function_name(getsym($1));
1348 } 1353 }
1349 | identifier_list T_COMMA T_NAME { 1354 | identifier_list T_COMMA T_NAME {
1350 $$ = lnklst($1, old_style_function_name(getsym($3))); 1355 $$ = lnklst($1, old_style_function_name(getsym($3)));
1351 } 1356 }
1352 | identifier_list error 1357 | identifier_list error
1353 ; 1358 ;
1354 1359
1355/* XXX: C99 requires an additional specifier-qualifier-list. */ 1360/* XXX: C99 requires an additional specifier-qualifier-list. */
1356type_name: /* C99 6.7.6 */ 1361type_name: /* C99 6.7.6 */
1357 { 1362 {
1358 begin_declaration_level(ABSTRACT); 1363 begin_declaration_level(ABSTRACT);
1359 } abstract_declaration { 1364 } abstract_declaration {
1360 end_declaration_level(); 1365 end_declaration_level();
1361 $$ = $2->s_type; 1366 $$ = $2->s_type;
1362 } 1367 }
1363 ; 1368 ;
1364 1369
1365abstract_declaration: 1370abstract_declaration:
1366 begin_type_qualifier_list end_type { 1371 begin_type_qualifier_list end_type {
1367 $$ = declare_1_abstract(abstract_name()); 1372 $$ = declare_1_abstract(abstract_name());
1368 } 1373 }
1369 | begin_type_specifier_qualifier_list end_type { 1374 | begin_type_specifier_qualifier_list end_type {
1370 $$ = declare_1_abstract(abstract_name()); 1375 $$ = declare_1_abstract(abstract_name());
1371 } 1376 }
1372 | begin_type_qualifier_list end_type abstract_declarator { 1377 | begin_type_qualifier_list end_type abstract_declarator {
1373 $$ = declare_1_abstract($3); 1378 $$ = declare_1_abstract($3);
1374 } 1379 }
1375 | begin_type_specifier_qualifier_list end_type abstract_declarator { 1380 | begin_type_specifier_qualifier_list end_type abstract_declarator {
1376 $$ = declare_1_abstract($3); 1381 $$ = declare_1_abstract($3);
1377 } 1382 }
1378 ; 1383 ;
1379 1384
1380abstract_declarator: /* C99 6.7.6 */ 1385abstract_declarator: /* C99 6.7.6 */
1381 pointer { 1386 pointer {
1382 $$ = add_pointer(abstract_name(), $1); 1387 $$ = add_pointer(abstract_name(), $1);
1383 } 1388 }
1384 | direct_abstract_declarator 1389 | direct_abstract_declarator
1385 | pointer direct_abstract_declarator { 1390 | pointer direct_abstract_declarator {
1386 $$ = add_pointer($2, $1); 1391 $$ = add_pointer($2, $1);
1387 } 1392 }
1388 | T_TYPEOF cast_expression { /* GCC extension */ 1393 | T_TYPEOF cast_expression { /* GCC extension */
1389 $$ = mktempsym($2->tn_type); 1394 $$ = mktempsym($2->tn_type);
1390 } 1395 }
1391 ; 1396 ;
1392 1397
1393direct_abstract_declarator: /* C99 6.7.6 */ 1398direct_abstract_declarator: /* C99 6.7.6 */
1394 T_LPAREN abstract_declarator T_RPAREN { 1399 T_LPAREN abstract_declarator T_RPAREN {
1395 $$ = $2; 1400 $$ = $2;
1396 } 1401 }
1397 | T_LBRACK T_RBRACK { 1402 | T_LBRACK T_RBRACK {
1398 $$ = add_array(abstract_name(), false, 0); 1403 $$ = add_array(abstract_name(), false, 0);
1399 } 1404 }
1400 | T_LBRACK array_size T_RBRACK { 1405 | T_LBRACK array_size T_RBRACK {
1401 $$ = add_array(abstract_name(), true, to_int_constant($2, false)); 1406 $$ = add_array(abstract_name(), true, to_int_constant($2, false));
1402 } 1407 }
1403 | type_attribute direct_abstract_declarator { 1408 | type_attribute direct_abstract_declarator {
1404 $$ = $2; 1409 $$ = $2;
1405 } 1410 }
1406 | direct_abstract_declarator T_LBRACK T_RBRACK { 1411 | direct_abstract_declarator T_LBRACK T_RBRACK {
1407 $$ = add_array($1, false, 0); 1412 $$ = add_array($1, false, 0);
1408 } 1413 }
1409 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */ 1414 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
1410 $$ = add_array($1, false, 0); 1415 $$ = add_array($1, false, 0);
1411 } 1416 }
1412 | direct_abstract_declarator T_LBRACK array_size T_RBRACK { 1417 | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
1413 $$ = add_array($1, true, to_int_constant($3, false)); 1418 $$ = add_array($1, true, to_int_constant($3, false));
1414 } 1419 }
1415 | abstract_decl_param_list asm_or_symbolrename_opt { 1420 | abstract_decl_param_list asm_or_symbolrename_opt {
1416 $$ = add_function(symbolrename(abstract_name(), $2), $1); 1421 $$ = add_function(symbolrename(abstract_name(), $2), $1);
1417 end_declaration_level(); 1422 end_declaration_level();
1418 block_level--; 1423 block_level--;
1419 } 1424 }
1420 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt { 1425 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
1421 $$ = add_function(symbolrename($1, $3), $2); 1426 $$ = add_function(symbolrename($1, $3), $2);
1422 end_declaration_level(); 1427 end_declaration_level();
1423 block_level--; 1428 block_level--;
1424 } 1429 }
1425 | direct_abstract_declarator type_attribute_list 1430 | direct_abstract_declarator type_attribute_list
1426 ; 1431 ;
1427 1432
1428abstract_decl_param_list: 1433abstract_decl_param_list:
1429 abstract_decl_lparen T_RPAREN type_attribute_opt { 1434 abstract_decl_lparen T_RPAREN type_attribute_opt {
1430 $$ = NULL; 1435 $$ = NULL;
1431 } 1436 }
1432 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { 1437 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1433 dcs->d_proto = true; 1438 dcs->d_proto = true;
1434 $$ = $2; 1439 $$ = $2;
1435 } 1440 }
1436 | abstract_decl_lparen error T_RPAREN type_attribute_opt { 1441 | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1437 $$ = NULL; 1442 $$ = NULL;
1438 } 1443 }
1439 ; 1444 ;
1440 1445
1441abstract_decl_lparen: 1446abstract_decl_lparen:
1442 T_LPAREN { 1447 T_LPAREN {
1443 block_level++; 1448 block_level++;
1444 begin_declaration_level(PROTO_ARG); 1449 begin_declaration_level(PROTO_ARG);
1445 } 1450 }
1446 ; 1451 ;
1447 1452
1448vararg_parameter_type_list: 1453vararg_parameter_type_list:
1449 parameter_type_list 1454 parameter_type_list
1450 | parameter_type_list T_COMMA T_ELLIPSIS { 1455 | parameter_type_list T_COMMA T_ELLIPSIS {
1451 dcs->d_vararg = true; 1456 dcs->d_vararg = true;
1452 $$ = $1; 1457 $$ = $1;
1453 } 1458 }
1454 | T_ELLIPSIS { 1459 | T_ELLIPSIS {
1455 if (sflag) { 1460 if (sflag) {
1456 /* ANSI C requires formal parameter before '...' */ 1461 /* ANSI C requires formal parameter before '...' */
1457 error(84); 1462 error(84);
1458 } else if (!tflag) { 1463 } else if (!tflag) {
1459 /* ANSI C requires formal parameter before '...' */ 1464 /* ANSI C requires formal parameter before '...' */
1460 warning(84); 1465 warning(84);
1461 } 1466 }
1462 dcs->d_vararg = true; 1467 dcs->d_vararg = true;
1463 $$ = NULL; 1468 $$ = NULL;
1464 } 1469 }
1465 ; 1470 ;
1466 1471
1467/* XXX: C99 6.7.5 defines the same name, but it looks different. */ 1472/* XXX: C99 6.7.5 defines the same name, but it looks different. */
1468parameter_type_list: 1473parameter_type_list:
1469 parameter_declaration 1474 parameter_declaration
1470 | parameter_type_list T_COMMA parameter_declaration { 1475 | parameter_type_list T_COMMA parameter_declaration {
1471 $$ = lnklst($1, $3); 1476 $$ = lnklst($1, $3);
1472 } 1477 }
1473 ; 1478 ;
1474 1479
1475/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ 1480/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1476parameter_declaration: 1481parameter_declaration:
1477 begin_type_declmods end_type { 1482 begin_type_declmods end_type {
 1483 /* ^^ There is no check for the missing type-specifier. */
1478 $$ = declare_argument(abstract_name(), false); 1484 $$ = declare_argument(abstract_name(), false);
1479 } 1485 }
1480 | begin_type_declaration_specifiers end_type { 1486 | begin_type_declaration_specifiers end_type {
1481 $$ = declare_argument(abstract_name(), false); 1487 $$ = declare_argument(abstract_name(), false);
1482 } 1488 }
1483 | begin_type_declmods end_type notype_param_declarator { 1489 | begin_type_declmods end_type notype_param_declarator {
 1490 /* ^^ There is no check for the missing type-specifier. */
1484 $$ = declare_argument($3, false); 1491 $$ = declare_argument($3, false);
1485 } 1492 }
1486 /* 1493 /*
1487 * type_param_declarator is needed because of following conflict: 1494 * type_param_declarator is needed because of following conflict:
1488 * "typedef int a; f(int (a));" could be parsed as 1495 * "typedef int a; f(int (a));" could be parsed as
1489 * "function with argument a of type int", or 1496 * "function with argument a of type int", or
1490 * "function with an abstract argument of type function". 1497 * "function with an abstract argument of type function".
1491 * This grammar realizes the second case. 1498 * This grammar realizes the second case.
1492 */ 1499 */
1493 | begin_type_declaration_specifiers end_type type_param_declarator { 1500 | begin_type_declaration_specifiers end_type type_param_declarator {
1494 $$ = declare_argument($3, false); 1501 $$ = declare_argument($3, false);
1495 } 1502 }
1496 | begin_type_declmods end_type abstract_declarator { 1503 | begin_type_declmods end_type abstract_declarator {
 1504 /* ^^ There is no check for the missing type-specifier. */
1497 $$ = declare_argument($3, false); 1505 $$ = declare_argument($3, false);
1498 } 1506 }
1499 | begin_type_declaration_specifiers end_type abstract_declarator { 1507 | begin_type_declaration_specifiers end_type abstract_declarator {
1500 $$ = declare_argument($3, false); 1508 $$ = declare_argument($3, false);
1501 } 1509 }
1502 ; 1510 ;
1503 1511
1504initializer: /* C99 6.7.8 "Initialization" */ 1512initializer: /* C99 6.7.8 "Initialization" */
1505 assignment_expression { 1513 assignment_expression {
1506 init_expr($1); 1514 init_expr($1);
1507 } 1515 }
1508 | init_lbrace init_rbrace { 1516 | init_lbrace init_rbrace {
1509 /* XXX: Empty braces are not covered by C99 6.7.8. */ 1517 /* XXX: Empty braces are not covered by C99 6.7.8. */
1510 } 1518 }
1511 | init_lbrace initializer_list comma_opt init_rbrace 1519 | init_lbrace initializer_list comma_opt init_rbrace
 1520 /* XXX: What is this error handling for? */
1512 | error 1521 | error
1513 ; 1522 ;
1514 1523
1515initializer_list: /* C99 6.7.8 "Initialization" */ 1524initializer_list: /* C99 6.7.8 "Initialization" */
1516 initializer_list_item 1525 initializer_list_item
1517 | initializer_list T_COMMA initializer_list_item 1526 | initializer_list T_COMMA initializer_list_item
1518 ; 1527 ;
1519 1528
1520initializer_list_item: /* helper */ 1529initializer_list_item: /* helper */
1521 designation initializer 1530 designation initializer
1522 | initializer 1531 | initializer
1523 ; 1532 ;
1524 1533
1525designation: /* C99 6.7.8 "Initialization" */ 1534designation: /* C99 6.7.8 "Initialization" */
1526 designator_list T_ASSIGN 1535 designator_list T_ASSIGN
1527 | identifier T_COLON { 1536 | identifier T_COLON {
1528 /* GCC style struct or union member name in initializer */ 1537 /* GCC style struct or union member name in initializer */
1529 gnuism(315); 1538 gnuism(315);
1530 add_designator_member($1); 1539 add_designator_member($1);
1531 } 1540 }
1532 ; 1541 ;
1533 1542
1534designator_list: /* C99 6.7.8 "Initialization" */ 1543designator_list: /* C99 6.7.8 "Initialization" */
1535 designator 1544 designator
1536 | designator_list designator 1545 | designator_list designator
1537 ; 1546 ;
1538 1547
1539designator: /* C99 6.7.8 "Initialization" */ 1548designator: /* C99 6.7.8 "Initialization" */
1540 T_LBRACK range T_RBRACK { 1549 T_LBRACK range T_RBRACK {
1541 add_designator_subscript($2); 1550 add_designator_subscript($2);
1542 if (!Sflag) 1551 if (!Sflag)
1543 /* array initializer with des.s is a C9X feature */ 1552 /* array initializer with des.s is a C9X feature */
1544 warning(321); 1553 warning(321);
1545 } 1554 }
1546 | T_POINT identifier { 1555 | T_POINT identifier {
1547 if (!Sflag) 1556 if (!Sflag)
1548 /* struct or union member name in initializer is ... */ 1557 /* struct or union member name in initializer is ... */
1549 warning(313); 1558 warning(313);
1550 add_designator_member($2); 1559 add_designator_member($2);
1551 } 1560 }
1552 ; 1561 ;
1553 1562
1554range: 1563range:
1555 constant_expr { 1564 constant_expr {
1556 $$.lo = to_int_constant($1, true); 1565 $$.lo = to_int_constant($1, true);
1557 $$.hi = $$.lo; 1566 $$.hi = $$.lo;
1558 } 1567 }
1559 | constant_expr T_ELLIPSIS constant_expr { 1568 | constant_expr T_ELLIPSIS constant_expr {
1560 $$.lo = to_int_constant($1, true); 1569 $$.lo = to_int_constant($1, true);
1561 $$.hi = to_int_constant($3, true); 1570 $$.hi = to_int_constant($3, true);
1562 /* initialization with '[a...b]' is a GCC extension */ 1571 /* initialization with '[a...b]' is a GCC extension */
1563 gnuism(340); 1572 gnuism(340);
1564 } 1573 }
1565 ; 1574 ;
1566 1575
1567init_lbrace: /* helper */ 1576init_lbrace: /* helper */
1568 T_LBRACE { 1577 T_LBRACE {
1569 init_lbrace(); 1578 init_lbrace();
1570 } 1579 }
1571 ; 1580 ;
1572 1581
1573init_rbrace: /* helper */ 1582init_rbrace: /* helper */
1574 T_RBRACE { 1583 T_RBRACE {
1575 init_rbrace(); 1584 init_rbrace();
1576 } 1585 }
1577 ; 1586 ;
1578 1587
1579asm_or_symbolrename_opt: /* GCC extensions */ 1588asm_or_symbolrename_opt: /* GCC extensions */
1580 /* empty */ { 1589 /* empty */ {
1581 $$ = NULL; 1590 $$ = NULL;
1582 } 1591 }
1583 | T_ASM T_LPAREN T_STRING T_RPAREN { 1592 | T_ASM T_LPAREN T_STRING T_RPAREN {
1584 freeyyv(&$3, T_STRING); 1593 freeyyv(&$3, T_STRING);
1585 $$ = NULL; 1594 $$ = NULL;
1586 } 1595 }
1587 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { 1596 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
1588 $$ = $3; 1597 $$ = $3;
1589 } 1598 }
1590 ; 1599 ;
1591 1600
1592statement: /* C99 6.8 */ 1601statement: /* C99 6.8 */
1593 expression_statement 1602 expression_statement
1594 | non_expr_statement 1603 | non_expr_statement
1595 ; 1604 ;
1596 1605
1597non_expr_statement: /* helper for C99 6.8 */ 1606non_expr_statement: /* helper for C99 6.8 */
1598 type_attribute T_SEMI 1607 type_attribute T_SEMI
1599 | labeled_statement 1608 | labeled_statement
1600 | compound_statement 1609 | compound_statement
1601 | selection_statement 1610 | selection_statement
1602 | iteration_statement 1611 | iteration_statement
1603 | jump_statement { 1612 | jump_statement {
1604 seen_fallthrough = false; 1613 seen_fallthrough = false;
1605 } 1614 }
1606 | asm_statement 1615 | asm_statement
1607 ; 1616 ;
1608 1617
1609labeled_statement: /* C99 6.8.1 */ 1618labeled_statement: /* C99 6.8.1 */
1610 label type_attribute_opt statement 1619 label type_attribute_opt statement
1611 ; 1620 ;
1612 1621
1613label: 1622label:
1614 T_NAME T_COLON { 1623 T_NAME T_COLON {
1615 symtyp = FLABEL; 1624 symtyp = FLABEL;
1616 named_label(getsym($1)); 1625 named_label(getsym($1));
1617 } 1626 }
1618 | T_CASE constant_expr T_COLON { 1627 | T_CASE constant_expr T_COLON {
1619 case_label($2); 1628 case_label($2);
1620 seen_fallthrough = true; 1629 seen_fallthrough = true;
1621 } 1630 }
1622 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON { 1631 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1623 /* XXX: We don't fill all cases */ 1632 /* XXX: We don't fill all cases */
1624 case_label($2); 1633 case_label($2);
1625 seen_fallthrough = true; 1634 seen_fallthrough = true;
1626 } 1635 }
1627 | T_DEFAULT T_COLON { 1636 | T_DEFAULT T_COLON {
1628 default_label(); 1637 default_label();
1629 seen_fallthrough = true; 1638 seen_fallthrough = true;
1630 } 1639 }
1631 ; 1640 ;
1632 1641
1633compound_statement: /* C99 6.8.2 */ 1642compound_statement: /* C99 6.8.2 */
1634 compound_statement_lbrace compound_statement_rbrace 1643 compound_statement_lbrace compound_statement_rbrace
1635 | compound_statement_lbrace block_item_list compound_statement_rbrace 1644 | compound_statement_lbrace block_item_list compound_statement_rbrace
1636 ; 1645 ;
1637 1646
1638compound_statement_lbrace: 1647compound_statement_lbrace:
1639 T_LBRACE { 1648 T_LBRACE {
1640 block_level++; 1649 block_level++;
1641 mem_block_level++; 1650 mem_block_level++;
1642 begin_declaration_level(AUTO); 1651 begin_declaration_level(AUTO);
1643 } 1652 }
1644 ; 1653 ;
1645 1654
1646compound_statement_rbrace: 1655compound_statement_rbrace:
1647 T_RBRACE { 1656 T_RBRACE {
1648 end_declaration_level(); 1657 end_declaration_level();
1649 freeblk(); 1658 freeblk();
1650 mem_block_level--; 1659 mem_block_level--;
1651 block_level--; 1660 block_level--;
1652 seen_fallthrough = false; 1661 seen_fallthrough = false;
1653 } 1662 }
1654 ; 1663 ;
1655 1664
1656block_item_list: /* C99 6.8.2 */ 1665block_item_list: /* C99 6.8.2 */
1657 block_item 1666 block_item
1658 | block_item_list block_item { 1667 | block_item_list block_item {
1659 if (!Sflag && $1 && !$2) 1668 if (!Sflag && $1 && !$2)
1660 /* declarations after statements is a C99 feature */ 1669 /* declarations after statements is a C99 feature */
1661 c99ism(327); 1670 c99ism(327);
1662 $$ = $1 || $2; 1671 $$ = $1 || $2;
1663 } 1672 }
1664 ; 1673 ;
1665 1674
1666block_item: /* C99 6.8.2 */ 1675block_item: /* C99 6.8.2 */
1667 declaration_or_error { 1676 declaration_or_error {
1668 $$ = false; 1677 $$ = false;
1669 restore_warning_flags(); 1678 restore_warning_flags();
1670 } 1679 }
1671 | statement { 1680 | statement {
1672 $$ = true; 1681 $$ = true;
1673 restore_warning_flags(); 1682 restore_warning_flags();
1674 } 1683 }
1675 ; 1684 ;
1676 1685
1677expression_statement: /* C99 6.8.3 */ 1686expression_statement: /* C99 6.8.3 */
1678 expression T_SEMI { 1687 expression T_SEMI {
1679 expr($1, false, false, false, false); 1688 expr($1, false, false, false, false);
1680 seen_fallthrough = false; 1689 seen_fallthrough = false;
1681 } 1690 }
1682 | T_SEMI { 1691 | T_SEMI {
1683 seen_fallthrough = false; 1692 seen_fallthrough = false;
1684 } 1693 }
1685 ; 1694 ;
1686 1695
1687selection_statement: /* C99 6.8.4 */ 1696selection_statement: /* C99 6.8.4 */
1688 if_without_else %prec T_THEN { 1697 if_without_else %prec T_THEN {
1689 save_warning_flags(); 1698 save_warning_flags();
1690 if2(); 1699 if2();
1691 if3(false); 1700 if3(false);
1692 } 1701 }
1693 | if_without_else T_ELSE { 1702 | if_without_else T_ELSE {
1694 save_warning_flags(); 1703 save_warning_flags();
1695 if2(); 1704 if2();
1696 } statement { 1705 } statement {
1697 clear_warning_flags(); 1706 clear_warning_flags();
1698 if3(true); 1707 if3(true);
1699 } 1708 }
1700 | if_without_else T_ELSE error { 1709 | if_without_else T_ELSE error {
1701 clear_warning_flags(); 1710 clear_warning_flags();
1702 if3(false); 1711 if3(false);
1703 } 1712 }
1704 | switch_expr statement { 1713 | switch_expr statement {
1705 clear_warning_flags(); 1714 clear_warning_flags();
1706 switch2(); 1715 switch2();
1707 } 1716 }
1708 | switch_expr error { 1717 | switch_expr error {
1709 clear_warning_flags(); 1718 clear_warning_flags();
1710 switch2(); 1719 switch2();
1711 } 1720 }
1712 ; 1721 ;
1713 1722
1714if_without_else: /* see C99 6.8.4 */ 1723if_without_else: /* see C99 6.8.4 */
1715 if_expr statement 1724 if_expr statement
1716 | if_expr error 1725 | if_expr error
1717 ; 1726 ;
1718 1727
1719if_expr: /* see C99 6.8.4 */ 1728if_expr: /* see C99 6.8.4 */
1720 T_IF T_LPAREN expression T_RPAREN { 1729 T_IF T_LPAREN expression T_RPAREN {
1721 if1($3); 1730 if1($3);
1722 clear_warning_flags(); 1731 clear_warning_flags();
1723 } 1732 }
1724 ; 1733 ;
1725 1734
1726switch_expr: /* see C99 6.8.4 */ 1735switch_expr: /* see C99 6.8.4 */
1727 T_SWITCH T_LPAREN expression T_RPAREN { 1736 T_SWITCH T_LPAREN expression T_RPAREN {
1728 switch1($3); 1737 switch1($3);
1729 clear_warning_flags(); 1738 clear_warning_flags();
1730 } 1739 }
1731 ; 1740 ;
1732 1741
1733iteration_statement: /* C99 6.8.5 */ 1742iteration_statement: /* C99 6.8.5 */
1734 while_expr statement { 1743 while_expr statement {
1735 clear_warning_flags(); 1744 clear_warning_flags();
1736 while2(); 1745 while2();
1737 } 1746 }
1738 | while_expr error { 1747 | while_expr error {
1739 clear_warning_flags(); 1748 clear_warning_flags();
1740 while2(); 1749 while2();
1741 } 1750 }
1742 | do_statement do_while_expr { 1751 | do_statement do_while_expr {
1743 do2($2); 1752 do2($2);
1744 seen_fallthrough = false; 1753 seen_fallthrough = false;
1745 } 1754 }
1746 | do error { 1755 | do error {
1747 clear_warning_flags(); 1756 clear_warning_flags();
1748 do2(NULL); 1757 do2(NULL);
1749 } 1758 }
1750 | for_exprs statement { 1759 | for_exprs statement {
1751 clear_warning_flags(); 1760 clear_warning_flags();
1752 for2(); 1761 for2();
1753 end_declaration_level(); 1762 end_declaration_level();
1754 block_level--; 1763 block_level--;
1755 } 1764 }
1756 | for_exprs error { 1765 | for_exprs error {
1757 clear_warning_flags(); 1766 clear_warning_flags();
1758 for2(); 1767 for2();
1759 end_declaration_level(); 1768 end_declaration_level();
1760 block_level--; 1769 block_level--;
1761 } 1770 }
1762 ; 1771 ;
1763 1772
1764while_expr: /* see C99 6.8.5 */ 1773while_expr: /* see C99 6.8.5 */
1765 T_WHILE T_LPAREN expression T_RPAREN { 1774 T_WHILE T_LPAREN expression T_RPAREN {
1766 while1($3); 1775 while1($3);
1767 clear_warning_flags(); 1776 clear_warning_flags();
1768 } 1777 }
1769 ; 1778 ;
1770 1779
1771do_statement: /* see C99 6.8.5 */ 1780do_statement: /* see C99 6.8.5 */
1772 do statement { 1781 do statement {
1773 clear_warning_flags(); 1782 clear_warning_flags();
1774 } 1783 }
1775 ; 1784 ;
1776 1785
1777do: /* see C99 6.8.5 */ 1786do: /* see C99 6.8.5 */
1778 T_DO { 1787 T_DO {
1779 do1(); 1788 do1();
1780 } 1789 }
1781 ; 1790 ;
1782 1791
1783do_while_expr: /* see C99 6.8.5 */ 1792do_while_expr: /* see C99 6.8.5 */
1784 T_WHILE T_LPAREN expression T_RPAREN T_SEMI { 1793 T_WHILE T_LPAREN expression T_RPAREN T_SEMI {
1785 $$ = $3; 1794 $$ = $3;
1786 } 1795 }
1787 ; 1796 ;
1788 1797
1789for_start: /* see C99 6.8.5 */ 1798for_start: /* see C99 6.8.5 */
1790 T_FOR T_LPAREN { 1799 T_FOR T_LPAREN {
1791 begin_declaration_level(AUTO); 1800 begin_declaration_level(AUTO);
1792 block_level++; 1801 block_level++;
1793 } 1802 }
1794 ; 1803 ;
1795 1804
1796for_exprs: /* see C99 6.8.5 */ 1805for_exprs: /* see C99 6.8.5 */
1797 for_start 1806 for_start
1798 begin_type_declaration_specifiers end_type 1807 begin_type_declaration_specifiers end_type
1799 notype_init_declarators T_SEMI 1808 notype_init_declarators T_SEMI
1800 expression_opt T_SEMI expression_opt T_RPAREN { 1809 expression_opt T_SEMI expression_opt T_RPAREN {
1801 /* variable declaration in for loop */ 1810 /* variable declaration in for loop */
1802 c99ism(325); 1811 c99ism(325);
1803 for1(NULL, $6, $8); 1812 for1(NULL, $6, $8);
1804 clear_warning_flags(); 1813 clear_warning_flags();
1805 } 1814 }
1806 | for_start 1815 | for_start
1807 expression_opt T_SEMI 1816 expression_opt T_SEMI
1808 expression_opt T_SEMI 1817 expression_opt T_SEMI
1809 expression_opt T_RPAREN { 1818 expression_opt T_RPAREN {
1810 for1($2, $4, $6); 1819 for1($2, $4, $6);
1811 clear_warning_flags(); 1820 clear_warning_flags();
1812 } 1821 }
1813 ; 1822 ;
1814 1823
1815jump_statement: /* C99 6.8.6 */ 1824jump_statement: /* C99 6.8.6 */
1816 goto identifier T_SEMI { 1825 goto identifier T_SEMI {
1817 do_goto(getsym($2)); 1826 do_goto(getsym($2));
1818 } 1827 }
1819 | goto error T_SEMI { 1828 | goto error T_SEMI {
1820 symtyp = FVFT; 1829 symtyp = FVFT;
1821 } 1830 }
1822 | T_CONTINUE T_SEMI { 1831 | T_CONTINUE T_SEMI {
1823 do_continue(); 1832 do_continue();
1824 } 1833 }
1825 | T_BREAK T_SEMI { 1834 | T_BREAK T_SEMI {
1826 do_break(); 1835 do_break();
1827 } 1836 }
1828 | T_RETURN T_SEMI { 1837 | T_RETURN T_SEMI {
1829 do_return(NULL); 1838 do_return(NULL);
1830 } 1839 }
1831 | T_RETURN expression T_SEMI { 1840 | T_RETURN expression T_SEMI {
1832 do_return($2); 1841 do_return($2);
1833 } 1842 }
1834 ; 1843 ;
1835 1844
1836goto: /* see C99 6.8.6 */ 1845goto: /* see C99 6.8.6 */
1837 T_GOTO { 1846 T_GOTO {
1838 symtyp = FLABEL; 1847 symtyp = FLABEL;
1839 } 1848 }
1840 ; 1849 ;
1841 1850
1842asm_statement: /* GCC extension */ 1851asm_statement: /* GCC extension */
1843 T_ASM T_LPAREN read_until_rparen T_SEMI { 1852 T_ASM T_LPAREN read_until_rparen T_SEMI {
1844 setasm(); 1853 setasm();
1845 } 1854 }
1846 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI { 1855 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI {
1847 setasm(); 1856 setasm();
1848 } 1857 }
1849 | T_ASM error 1858 | T_ASM error
1850 ; 1859 ;
1851 1860
1852read_until_rparen: /* helper for 'asm_statement' */ 1861read_until_rparen: /* helper for 'asm_statement' */
1853 /* empty */ { 1862 /* empty */ {
1854 read_until_rparen(); 1863 read_until_rparen();
1855 } 1864 }
1856 ; 1865 ;
1857 1866
1858translation_unit: /* C99 6.9 */ 1867translation_unit: /* C99 6.9 */
1859 external_declaration 1868 external_declaration
1860 | translation_unit external_declaration 1869 | translation_unit external_declaration
1861 ; 1870 ;
1862 1871
1863external_declaration: /* C99 6.9 */ 1872external_declaration: /* C99 6.9 */
1864 asm_statement 1873 asm_statement
1865 | function_definition { 1874 | function_definition {
1866 global_clean_up_decl(false); 1875 global_clean_up_decl(false);
1867 clear_warning_flags(); 1876 clear_warning_flags();
1868 } 1877 }
1869 | top_level_declaration { 1878 | top_level_declaration {
1870 global_clean_up_decl(false); 1879 global_clean_up_decl(false);
1871 clear_warning_flags(); 1880 clear_warning_flags();
1872 } 1881 }
1873 ; 1882 ;
1874 1883
1875/* 1884/*
1876 * On the top level, lint allows several forms of declarations that it doesn't 1885 * On the top level, lint allows several forms of declarations that it doesn't
1877 * allow in functions. For example, a single ';' is an empty declaration and 1886 * allow in functions. For example, a single ';' is an empty declaration and
1878 * is supported by some compilers, but in a function it would be an empty 1887 * is supported by some compilers, but in a function it would be an empty
1879 * statement, not a declaration. This makes a difference in C90 mode, where 1888 * statement, not a declaration. This makes a difference in C90 mode, where
1880 * a statement must not be followed by a declaration. 1889 * a statement must not be followed by a declaration.
1881 * 1890 *
1882 * See 'declaration' for all other declarations. 1891 * See 'declaration' for all other declarations.
1883 */ 1892 */
1884top_level_declaration: /* C99 6.9 calls this 'declaration' */ 1893top_level_declaration: /* C99 6.9 calls this 'declaration' */
1885 T_SEMI { 1894 T_SEMI {
1886 if (sflag) { 1895 if (sflag) {
1887 /* empty declaration */ 1896 /* empty declaration */
1888 error(0); 1897 error(0);
1889 } else if (!tflag) { 1898 } else if (!tflag) {
1890 /* empty declaration */ 1899 /* empty declaration */
1891 warning(0); 1900 warning(0);
1892 } 1901 }
1893 } 1902 }
1894 | begin_type end_type notype_init_declarators T_SEMI { 1903 | begin_type end_type notype_init_declarators T_SEMI {
1895 if (sflag) { 1904 if (sflag) {
1896 /* old style declaration; add 'int' */ 1905 /* old style declaration; add 'int' */
1897 error(1); 1906 error(1);
1898 } else if (!tflag) { 1907 } else if (!tflag) {
1899 /* old style declaration; add 'int' */ 1908 /* old style declaration; add 'int' */
1900 warning(1); 1909 warning(1);
1901 } 1910 }
1902 } 1911 }
1903 | declaration 1912 | declaration
1904 | error T_SEMI { 1913 | error T_SEMI {
1905 global_clean_up(); 1914 global_clean_up();
1906 } 1915 }
1907 | error T_RBRACE { 1916 | error T_RBRACE {
1908 global_clean_up(); 1917 global_clean_up();
1909 } 1918 }
1910 ; 1919 ;
1911 1920
1912function_definition: /* C99 6.9.1 */ 1921function_definition: /* C99 6.9.1 */
1913 func_declarator { 1922 func_declarator {
1914 if ($1->s_type->t_tspec != FUNC) { 1923 if ($1->s_type->t_tspec != FUNC) {
1915 /* syntax error '%s' */ 1924 /* syntax error '%s' */
1916 error(249, yytext); 1925 error(249, yytext);
1917 YYERROR; 1926 YYERROR;
1918 } 1927 }
1919 if ($1->s_type->t_typedef) { 1928 if ($1->s_type->t_typedef) {
1920 /* ()-less function definition */ 1929 /* ()-less function definition */
1921 error(64); 1930 error(64);
1922 YYERROR; 1931 YYERROR;
1923 } 1932 }
1924 funcdef($1); 1933 funcdef($1);
1925 block_level++; 1934 block_level++;
1926 begin_declaration_level(ARG); 1935 begin_declaration_level(ARG);
1927 if (lwarn == LWARN_NONE) 1936 if (lwarn == LWARN_NONE)
1928 $1->s_used = true; 1937 $1->s_used = true;
1929 } arg_declaration_list_opt { 1938 } arg_declaration_list_opt {
1930 end_declaration_level(); 1939 end_declaration_level();
1931 block_level--; 1940 block_level--;
1932 check_func_lint_directives(); 1941 check_func_lint_directives();
1933 check_func_old_style_arguments(); 1942 check_func_old_style_arguments();
1934 begin_control_statement(CS_FUNCTION_BODY); 1943 begin_control_statement(CS_FUNCTION_BODY);
1935 } compound_statement { 1944 } compound_statement {
1936 funcend(); 1945 funcend();
1937 end_control_statement(CS_FUNCTION_BODY); 1946 end_control_statement(CS_FUNCTION_BODY);
1938 } 1947 }
1939 ; 1948 ;
1940 1949
1941func_declarator: 1950func_declarator:
1942 begin_type end_type notype_declarator { 1951 begin_type end_type notype_declarator {
 1952 /* ^^ There is no check for the missing type-specifier. */
1943 $$ = $3; 1953 $$ = $3;
1944 } 1954 }
1945 | begin_type_declmods end_type notype_declarator { 1955 | begin_type_declmods end_type notype_declarator {
 1956 /* ^^ There is no check for the missing type-specifier. */
1946 $$ = $3; 1957 $$ = $3;
1947 } 1958 }
1948 | begin_type_declaration_specifiers end_type type_declarator { 1959 | begin_type_declaration_specifiers end_type type_declarator {
1949 $$ = $3; 1960 $$ = $3;
1950 } 1961 }
1951 ; 1962 ;
1952 1963
1953arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ 1964arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */
1954 /* empty */ 1965 /* empty */
1955 | arg_declaration_list 1966 | arg_declaration_list
1956 ; 1967 ;
1957 1968
1958arg_declaration_list: /* C99 6.9.1p13 example 1 */ 1969arg_declaration_list: /* C99 6.9.1p13 example 1 */
1959 arg_declaration 1970 arg_declaration
1960 | arg_declaration_list arg_declaration 1971 | arg_declaration_list arg_declaration
1961 /* XXX or better "arg_declaration error" ? */ 1972 /* XXX or better "arg_declaration error" ? */
1962 | error 1973 | error
1963 ; 1974 ;
1964 1975
1965/* 1976/*
1966 * "arg_declaration" is separated from "declaration" because it 1977 * "arg_declaration" is separated from "declaration" because it
1967 * needs other error handling. 1978 * needs other error handling.
1968 */ 1979 */
1969arg_declaration: 1980arg_declaration:
1970 begin_type_declmods end_type T_SEMI { 1981 begin_type_declmods end_type T_SEMI {
1971 /* empty declaration */ 1982 /* empty declaration */
1972 warning(2); 1983 warning(2);
1973 } 1984 }
1974 | begin_type_declmods end_type notype_init_declarators T_SEMI 1985 | begin_type_declmods end_type notype_init_declarators T_SEMI
1975 | begin_type_declaration_specifiers end_type T_SEMI { 1986 | begin_type_declaration_specifiers end_type T_SEMI {
1976 if (!dcs->d_nonempty_decl) { 1987 if (!dcs->d_nonempty_decl) {
1977 /* empty declaration */ 1988 /* empty declaration */
1978 warning(2); 1989 warning(2);
1979 } else { 1990 } else {
1980 /* '%s' declared in argument declaration list */ 1991 /* '%s' declared in argument declaration list */
1981 warning(3, type_name(dcs->d_type)); 1992 warning(3, type_name(dcs->d_type));
1982 } 1993 }
1983 } 1994 }
1984 | begin_type_declaration_specifiers end_type 1995 | begin_type_declaration_specifiers end_type
1985 type_init_declarators T_SEMI { 1996 type_init_declarators T_SEMI {
1986 if (dcs->d_nonempty_decl) { 1997 if (dcs->d_nonempty_decl) {
1987 /* '%s' declared in argument declaration list */ 1998 /* '%s' declared in argument declaration list */
1988 warning(3, type_name(dcs->d_type)); 1999 warning(3, type_name(dcs->d_type));
1989 } 2000 }
1990 } 2001 }
1991 | begin_type_declmods error 2002 | begin_type_declmods error
1992 | begin_type_declaration_specifiers error 2003 | begin_type_declaration_specifiers error
1993 ; 2004 ;
1994 2005
1995gcc_attribute_spec_list: 2006gcc_attribute_spec_list:
1996 gcc_attribute_spec 2007 gcc_attribute_spec
1997 | gcc_attribute_spec_list T_COMMA gcc_attribute_spec 2008 | gcc_attribute_spec_list T_COMMA gcc_attribute_spec
1998 ; 2009 ;
1999 2010
2000gcc_attribute_spec: 2011gcc_attribute_spec:
2001 /* empty */ 2012 /* empty */
2002 | T_AT_ALWAYS_INLINE 2013 | T_AT_ALWAYS_INLINE
2003 | T_AT_ALIAS T_LPAREN string T_RPAREN 2014 | T_AT_ALIAS T_LPAREN string T_RPAREN
2004 | T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN 2015 | T_AT_ALIGNED T_LPAREN constant_expr T_RPAREN
2005 | T_AT_ALIGNED 2016 | T_AT_ALIGNED
2006 | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN 2017 | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_COMMA constant_expr T_RPAREN
2007 | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN 2018 | T_AT_ALLOC_SIZE T_LPAREN constant_expr T_RPAREN
2008 | T_AT_BOUNDED T_LPAREN gcc_attribute_bounded 2019 | T_AT_BOUNDED T_LPAREN gcc_attribute_bounded
2009 T_COMMA constant_expr T_COMMA constant_expr T_RPAREN 2020 T_COMMA constant_expr T_COMMA constant_expr T_RPAREN
2010 | T_AT_COLD 2021 | T_AT_COLD
2011 | T_AT_COMMON 2022 | T_AT_COMMON
2012 | T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN 2023 | T_AT_CONSTRUCTOR T_LPAREN constant_expr T_RPAREN
2013 | T_AT_CONSTRUCTOR 2024 | T_AT_CONSTRUCTOR
2014 | T_AT_DEPRECATED T_LPAREN string T_RPAREN 2025 | T_AT_DEPRECATED T_LPAREN string T_RPAREN
2015 | T_AT_DEPRECATED 2026 | T_AT_DEPRECATED
2016 | T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN 2027 | T_AT_DESTRUCTOR T_LPAREN constant_expr T_RPAREN
2017 | T_AT_DESTRUCTOR 2028 | T_AT_DESTRUCTOR
2018 | T_AT_FALLTHROUGH { 2029 | T_AT_FALLTHROUGH {
2019 fallthru(1); 2030 fallthru(1);
2020 } 2031 }
2021 | T_AT_FORMAT T_LPAREN gcc_attribute_format T_COMMA 2032 | T_AT_FORMAT T_LPAREN gcc_attribute_format T_COMMA
2022 constant_expr T_COMMA constant_expr T_RPAREN 2033 constant_expr T_COMMA constant_expr T_RPAREN
2023 | T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN 2034 | T_AT_FORMAT_ARG T_LPAREN constant_expr T_RPAREN
2024 | T_AT_GNU_INLINE 2035 | T_AT_GNU_INLINE
2025 | T_AT_HOT 2036 | T_AT_HOT
2026 | T_AT_MALLOC 2037 | T_AT_MALLOC
2027 | T_AT_MAY_ALIAS 2038 | T_AT_MAY_ALIAS
2028 | T_AT_MODE T_LPAREN T_NAME T_RPAREN 2039 | T_AT_MODE T_LPAREN T_NAME T_RPAREN
2029 | T_AT_NOINLINE 2040 | T_AT_NOINLINE
2030 | T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN 2041 | T_AT_NONNULL T_LPAREN constant_expr_list_opt T_RPAREN
2031 | T_AT_NONNULL 2042 | T_AT_NONNULL
2032 | T_AT_NONSTRING 2043 | T_AT_NONSTRING
2033 | T_AT_NORETURN 2044 | T_AT_NORETURN
2034 | T_AT_NOTHROW 2045 | T_AT_NOTHROW
2035 | T_AT_NO_INSTRUMENT_FUNCTION 2046 | T_AT_NO_INSTRUMENT_FUNCTION
2036 | T_AT_OPTIMIZE T_LPAREN string T_RPAREN 2047 | T_AT_OPTIMIZE T_LPAREN string T_RPAREN
2037 | T_AT_PACKED { 2048 | T_AT_PACKED {
2038 addpacked(); 2049 addpacked();
2039 } 2050 }
2040 | T_AT_PCS T_LPAREN string T_RPAREN 2051 | T_AT_PCS T_LPAREN string T_RPAREN
2041 | T_AT_PURE 2052 | T_AT_PURE
2042 | T_AT_RETURNS_TWICE 2053 | T_AT_RETURNS_TWICE
2043 | T_AT_SECTION T_LPAREN string T_RPAREN 2054 | T_AT_SECTION T_LPAREN string T_RPAREN
2044 | T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN 2055 | T_AT_SENTINEL T_LPAREN constant_expr T_RPAREN
2045 | T_AT_SENTINEL 2056 | T_AT_SENTINEL
2046 | T_AT_TLS_MODEL T_LPAREN string T_RPAREN 2057 | T_AT_TLS_MODEL T_LPAREN string T_RPAREN
2047 | T_AT_TUNION 2058 | T_AT_TUNION
2048 | T_AT_UNUSED { 2059 | T_AT_UNUSED {
2049 add_attr_used(); 2060 add_attr_used();
2050 } 2061 }
2051 | T_AT_USED { 2062 | T_AT_USED {
2052 add_attr_used(); 2063 add_attr_used();
2053 } 2064 }
2054 | T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN 2065 | T_AT_VISIBILITY T_LPAREN constant_expr T_RPAREN
2055 | T_AT_WARN_UNUSED_RESULT 2066 | T_AT_WARN_UNUSED_RESULT
2056 | T_AT_WEAK 2067 | T_AT_WEAK
2057 | T_QUAL { 2068 | T_QUAL {
2058 if ($1 != CONST) 2069 if ($1 != CONST)
2059 yyerror("Bad attribute"); 2070 yyerror("Bad attribute");
2060 } 2071 }
2061 ; 2072 ;
2062 2073
2063gcc_attribute_bounded: 2074gcc_attribute_bounded:
2064 T_AT_MINBYTES 2075 T_AT_MINBYTES
2065 | T_AT_STRING 2076 | T_AT_STRING
2066 | T_AT_BUFFER 2077 | T_AT_BUFFER
2067 ; 2078 ;
2068 2079
2069gcc_attribute_format: 2080gcc_attribute_format:
2070 T_AT_FORMAT_GNU_PRINTF 2081 T_AT_FORMAT_GNU_PRINTF
2071 | T_AT_FORMAT_PRINTF 2082 | T_AT_FORMAT_PRINTF
2072 | T_AT_FORMAT_SCANF 2083 | T_AT_FORMAT_SCANF
2073 | T_AT_FORMAT_STRFMON 2084 | T_AT_FORMAT_STRFMON
2074 | T_AT_FORMAT_STRFTIME 2085 | T_AT_FORMAT_STRFTIME
2075 | T_AT_FORMAT_SYSLOG 2086 | T_AT_FORMAT_SYSLOG
2076 ; 2087 ;
2077 2088
2078%% 2089%%
2079 2090
2080/* ARGSUSED */ 2091/* ARGSUSED */
2081int 2092int
2082yyerror(const char *msg) 2093yyerror(const char *msg)
2083{ 2094{
2084 /* syntax error '%s' */ 2095 /* syntax error '%s' */
2085 error(249, yytext); 2096 error(249, yytext);
2086 if (++sytxerr >= 5) 2097 if (++sytxerr >= 5)
2087 norecover(); 2098 norecover();
2088 return 0; 2099 return 0;
2089} 2100}
2090 2101
2091static void 2102static void
2092cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming) 2103cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
2093{ 2104{
2094 declare(decl, initflg, renaming); 2105 declare(decl, initflg, renaming);
2095 if (renaming != NULL) 2106 if (renaming != NULL)
2096 freeyyv(&renaming, T_NAME); 2107 freeyyv(&renaming, T_NAME);
2097} 2108}
2098 2109
2099/* 2110/*
2100 * Discard all input tokens up to and including the next 2111 * Discard all input tokens up to and including the next
2101 * unmatched right paren 2112 * unmatched right paren
2102 */ 2113 */
2103static void 2114static void
2104read_until_rparen(void) 2115read_until_rparen(void)
2105{ 2116{
2106 int level; 2117 int level;
2107 2118
2108 if (yychar < 0) 2119 if (yychar < 0)
2109 yychar = yylex(); 2120 yychar = yylex();
2110 freeyyv(&yylval, yychar); 2121 freeyyv(&yylval, yychar);
2111 2122
2112 level = 1; 2123 level = 1;
2113 while (yychar != T_RPAREN || --level > 0) { 2124 while (yychar != T_RPAREN || --level > 0) {
2114 if (yychar == T_LPAREN) { 2125 if (yychar == T_LPAREN) {
2115 level++; 2126 level++;
2116 } else if (yychar <= 0) { 2127 } else if (yychar <= 0) {
2117 break; 2128 break;
2118 } 2129 }
2119 freeyyv(&yylval, yychar = yylex()); 2130 freeyyv(&yylval, yychar = yylex());
2120 } 2131 }
2121 2132
2122 yyclearin; 2133 yyclearin;
2123} 2134}
2124 2135
2125static sym_t * 2136static sym_t *
2126symbolrename(sym_t *s, sbuf_t *sb) 2137symbolrename(sym_t *s, sbuf_t *sb)
2127{ 2138{
2128 if (sb != NULL) 2139 if (sb != NULL)
2129 s->s_rename = sb->sb_name; 2140 s->s_rename = sb->sb_name;
2130 return s; 2141 return s;
2131} 2142}