Sat Jul 10 05:42:30 2021 UTC ()
lint: do not allow __packed or _Alignas in statement

When the rule 'statement: type_attribute T_SEMI' was added in cgram.y
1.214 from 2021-04-14, type_attribute was the closest match since there
was no definition for gcc_attribute yet.


(rillig)
diff -r1.281 -r1.282 src/usr.bin/xlint/lint1/cgram.y

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

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