Sun Jul 11 19:01:37 2021 UTC ()
lint: fix shift/reduce conflict for dangling else

The following line no longer occurs in the yacc output:
257: shift/reduce conflict (shift 427, reduce 270) on T_ELSE

No functional change.


(rillig)
diff -r1.311 -r1.312 src/usr.bin/xlint/lint1/cgram.y

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

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