Fri Jul 9 06:37:11 2021 UTC ()
lint: indent grammar actions properly

No functional change.


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

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

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