Sat Jul 10 04:25:47 2021 UTC ()
lint: remove duplicate code for parsing declarations

No functional change.


(rillig)
diff -r1.277 -r1.278 src/usr.bin/xlint/lint1/cgram.y

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/09 20:51:27 1.277
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 04:25:47 1.278
@@ -1,1536 +1,1521 @@ @@ -1,1536 +1,1521 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 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.277 2021/07/09 20:51:27 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
52 */ 52 */
53int block_level; 53int block_level;
54 54
55/* 55/*
56 * level for memory allocation. Normally the same as block_level. 56 * level for memory allocation. Normally the same as block_level.
57 * An exception is the declaration of arguments in prototypes. Memory 57 * An exception is the declaration of arguments in prototypes. Memory
58 * for these can't be freed after the declaration, but symbols must 58 * for these can't be freed after the declaration, but symbols must
59 * be removed from the symbol table after the declaration. 59 * be removed from the symbol table after the declaration.
60 */ 60 */
61int mem_block_level; 61int mem_block_level;
62 62
63/* 63/*
64 * Save the no-warns state and restore it to avoid the problem where 64 * Save the no-warns state and restore it to avoid the problem where
65 * if (expr) { stmt } / * NOLINT * / stmt; 65 * if (expr) { stmt } / * NOLINT * / stmt;
66 */ 66 */
67static int olwarn = LWARN_BAD; 67static int olwarn = LWARN_BAD;
68 68
69static void cgram_declare(sym_t *, bool, sbuf_t *); 69static void cgram_declare(sym_t *, bool, sbuf_t *);
70static void ignore_up_to_rparen(void); 70static void ignore_up_to_rparen(void);
71static sym_t *symbolrename(sym_t *, sbuf_t *); 71static sym_t *symbolrename(sym_t *, sbuf_t *);
72 72
73 73
74#ifdef DEBUG 74#ifdef DEBUG
75static void 75static void
76CLEAR_WARN_FLAGS(const char *file, size_t line) 76CLEAR_WARN_FLAGS(const char *file, size_t line)
77{ 77{
78 printf("%s:%d: %s:%zu: clearing flags\n", 78 printf("%s:%d: %s:%zu: clearing flags\n",
79 curr_pos.p_file, curr_pos.p_line, file, line); 79 curr_pos.p_file, curr_pos.p_line, file, line);
80 clear_warn_flags(); 80 clear_warn_flags();
81 olwarn = LWARN_BAD; 81 olwarn = LWARN_BAD;
82} 82}
83 83
84static void 84static void
85SAVE_WARN_FLAGS(const char *file, size_t line) 85SAVE_WARN_FLAGS(const char *file, size_t line)
86{ 86{
87 lint_assert(olwarn == LWARN_BAD); 87 lint_assert(olwarn == LWARN_BAD);
88 printf("%s:%d: %s:%zu: saving flags %d\n", 88 printf("%s:%d: %s:%zu: saving flags %d\n",
89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 89 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
90 olwarn = lwarn; 90 olwarn = lwarn;
91} 91}
92 92
93static void 93static void
94RESTORE_WARN_FLAGS(const char *file, size_t line) 94RESTORE_WARN_FLAGS(const char *file, size_t line)
95{ 95{
96 if (olwarn != LWARN_BAD) { 96 if (olwarn != LWARN_BAD) {
97 lwarn = olwarn; 97 lwarn = olwarn;
98 printf("%s:%d: %s:%zu: restoring flags %d\n", 98 printf("%s:%d: %s:%zu: restoring flags %d\n",
99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn); 99 curr_pos.p_file, curr_pos.p_line, file, line, lwarn);
100 olwarn = LWARN_BAD; 100 olwarn = LWARN_BAD;
101 } else 101 } else
102 CLEAR_WARN_FLAGS(file, line); 102 CLEAR_WARN_FLAGS(file, line);
103} 103}
104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args) 104#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
105#else 105#else
106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD 106#define CLEAR_WARN_FLAGS(f, l) clear_warn_flags(), olwarn = LWARN_BAD
107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn 107#define SAVE_WARN_FLAGS(f, l) olwarn = lwarn
108#define RESTORE_WARN_FLAGS(f, l) \ 108#define RESTORE_WARN_FLAGS(f, l) \
109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn)) 109 (void)(olwarn == LWARN_BAD ? (clear_warn_flags(), 0) : (lwarn = olwarn))
110#define cgram_debug(fmt, args...) do { } while (false) 110#define cgram_debug(fmt, args...) do { } while (false)
111#endif 111#endif
112 112
113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__) 113#define clear_warning_flags() CLEAR_WARN_FLAGS(__FILE__, __LINE__)
114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__) 114#define save_warning_flags() SAVE_WARN_FLAGS(__FILE__, __LINE__)
115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__) 115#define restore_warning_flags() RESTORE_WARN_FLAGS(__FILE__, __LINE__)
116 116
117/* unbind the anonymous struct members from the struct */ 117/* unbind the anonymous struct members from the struct */
118static void 118static void
119anonymize(sym_t *s) 119anonymize(sym_t *s)
120{ 120{
121 for ( ; s != NULL; s = s->s_next) 121 for ( ; s != NULL; s = s->s_next)
122 s->s_styp = NULL; 122 s->s_styp = NULL;
123} 123}
124%} 124%}
125 125
126%expect 150 126%expect 150
127 127
128%union { 128%union {
129 val_t *y_val; 129 val_t *y_val;
130 sbuf_t *y_sb; 130 sbuf_t *y_sb;
131 sym_t *y_sym; 131 sym_t *y_sym;
132 op_t y_op; 132 op_t y_op;
133 scl_t y_scl; 133 scl_t y_scl;
134 tspec_t y_tspec; 134 tspec_t y_tspec;
135 tqual_t y_tqual; 135 tqual_t y_tqual;
136 type_t *y_type; 136 type_t *y_type;
137 tnode_t *y_tnode; 137 tnode_t *y_tnode;
138 range_t y_range; 138 range_t y_range;
139 strg_t *y_string; 139 strg_t *y_string;
140 qual_ptr *y_qual_ptr; 140 qual_ptr *y_qual_ptr;
141 bool y_seen_statement; 141 bool y_seen_statement;
142 struct generic_association *y_generic; 142 struct generic_association *y_generic;
143}; 143};
144 144
145%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN 145%token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
146%token T_POINT T_ARROW 146%token T_POINT T_ARROW
147%token <y_op> T_UNARY 147%token <y_op> T_UNARY
148%token <y_op> T_INCDEC 148%token <y_op> T_INCDEC
149%token T_SIZEOF 149%token T_SIZEOF
150%token T_BUILTIN_OFFSETOF 150%token T_BUILTIN_OFFSETOF
151%token T_TYPEOF 151%token T_TYPEOF
152%token T_EXTENSION 152%token T_EXTENSION
153%token T_ALIGNAS 153%token T_ALIGNAS
154%token T_ALIGNOF 154%token T_ALIGNOF
155%token T_ASTERISK 155%token T_ASTERISK
156%token <y_op> T_MULTIPLICATIVE 156%token <y_op> T_MULTIPLICATIVE
157%token <y_op> T_ADDITIVE 157%token <y_op> T_ADDITIVE
158%token <y_op> T_SHIFT 158%token <y_op> T_SHIFT
159%token <y_op> T_RELATIONAL 159%token <y_op> T_RELATIONAL
160%token <y_op> T_EQUALITY 160%token <y_op> T_EQUALITY
161%token T_AMPER 161%token T_AMPER
162%token T_BITXOR 162%token T_BITXOR
163%token T_BITOR 163%token T_BITOR
164%token T_LOGAND 164%token T_LOGAND
165%token T_LOGOR 165%token T_LOGOR
166%token T_QUEST 166%token T_QUEST
167%token T_COLON 167%token T_COLON
168%token T_ASSIGN 168%token T_ASSIGN
169%token <y_op> T_OPASSIGN 169%token <y_op> T_OPASSIGN
170%token T_COMMA 170%token T_COMMA
171%token T_SEMI 171%token T_SEMI
172%token T_ELLIPSIS 172%token T_ELLIPSIS
173%token T_REAL 173%token T_REAL
174%token T_IMAG 174%token T_IMAG
175%token T_GENERIC 175%token T_GENERIC
176%token T_NORETURN 176%token T_NORETURN
177 177
178/* storage classes (extern, static, auto, register and typedef) */ 178/* storage classes (extern, static, auto, register and typedef) */
179%token <y_scl> T_SCLASS 179%token <y_scl> T_SCLASS
180 180
181/* 181/*
182 * predefined type keywords (char, int, short, long, unsigned, signed, 182 * predefined type keywords (char, int, short, long, unsigned, signed,
183 * float, double, void); see T_TYPENAME 183 * float, double, void); see T_TYPENAME
184 */ 184 */
185%token <y_tspec> T_TYPE 185%token <y_tspec> T_TYPE
186 186
187/* qualifiers (const, volatile, restrict, _Thread_local) */ 187/* qualifiers (const, volatile, restrict, _Thread_local) */
188%token <y_tqual> T_QUAL 188%token <y_tqual> T_QUAL
189 189
190/* struct or union */ 190/* struct or union */
191%token <y_tspec> T_STRUCT_OR_UNION 191%token <y_tspec> T_STRUCT_OR_UNION
192 192
193/* remaining keywords */ 193/* remaining keywords */
194%token T_ASM 194%token T_ASM
195%token T_BREAK 195%token T_BREAK
196%token T_CASE 196%token T_CASE
197%token T_CONTINUE 197%token T_CONTINUE
198%token T_DEFAULT 198%token T_DEFAULT
199%token T_DO 199%token T_DO
200%token T_ELSE 200%token T_ELSE
201%token T_ENUM 201%token T_ENUM
202%token T_FOR 202%token T_FOR
203%token T_GOTO 203%token T_GOTO
204%token T_IF 204%token T_IF
205%token T_PACKED 205%token T_PACKED
206%token T_RETURN 206%token T_RETURN
207%token T_SWITCH 207%token T_SWITCH
208%token T_SYMBOLRENAME 208%token T_SYMBOLRENAME
209%token T_WHILE 209%token T_WHILE
210 210
211%token T_ATTRIBUTE 211%token T_ATTRIBUTE
212%token T_AT_ALIAS 212%token T_AT_ALIAS
213%token T_AT_ALIGNED 213%token T_AT_ALIGNED
214%token T_AT_ALLOC_SIZE 214%token T_AT_ALLOC_SIZE
215%token T_AT_ALWAYS_INLINE 215%token T_AT_ALWAYS_INLINE
216%token T_AT_BOUNDED 216%token T_AT_BOUNDED
217%token T_AT_BUFFER 217%token T_AT_BUFFER
218%token T_AT_COLD 218%token T_AT_COLD
219%token T_AT_COMMON 219%token T_AT_COMMON
220%token T_AT_CONSTRUCTOR 220%token T_AT_CONSTRUCTOR
221%token T_AT_DEPRECATED 221%token T_AT_DEPRECATED
222%token T_AT_DESTRUCTOR 222%token T_AT_DESTRUCTOR
223%token T_AT_FALLTHROUGH 223%token T_AT_FALLTHROUGH
224%token T_AT_FORMAT 224%token T_AT_FORMAT
225%token T_AT_FORMAT_ARG 225%token T_AT_FORMAT_ARG
226%token T_AT_FORMAT_GNU_PRINTF 226%token T_AT_FORMAT_GNU_PRINTF
227%token T_AT_FORMAT_PRINTF 227%token T_AT_FORMAT_PRINTF
228%token T_AT_FORMAT_SCANF 228%token T_AT_FORMAT_SCANF
229%token T_AT_FORMAT_STRFMON 229%token T_AT_FORMAT_STRFMON
230%token T_AT_FORMAT_STRFTIME 230%token T_AT_FORMAT_STRFTIME
231%token T_AT_FORMAT_SYSLOG 231%token T_AT_FORMAT_SYSLOG
232%token T_AT_GNU_INLINE 232%token T_AT_GNU_INLINE
233%token T_AT_MALLOC 233%token T_AT_MALLOC
234%token T_AT_MAY_ALIAS 234%token T_AT_MAY_ALIAS
235%token T_AT_MINBYTES 235%token T_AT_MINBYTES
236%token T_AT_MODE 236%token T_AT_MODE
237%token T_AT_NOINLINE 237%token T_AT_NOINLINE
238%token T_AT_NONNULL 238%token T_AT_NONNULL
239%token T_AT_NONSTRING 239%token T_AT_NONSTRING
240%token T_AT_NORETURN 240%token T_AT_NORETURN
241%token T_AT_NOTHROW 241%token T_AT_NOTHROW
242%token T_AT_NO_INSTRUMENT_FUNCTION 242%token T_AT_NO_INSTRUMENT_FUNCTION
243%token T_AT_OPTIMIZE 243%token T_AT_OPTIMIZE
244%token T_AT_PACKED 244%token T_AT_PACKED
245%token T_AT_PCS 245%token T_AT_PCS
246%token T_AT_PURE 246%token T_AT_PURE
247%token T_AT_RETURNS_TWICE 247%token T_AT_RETURNS_TWICE
248%token T_AT_SECTION 248%token T_AT_SECTION
249%token T_AT_SENTINEL 249%token T_AT_SENTINEL
250%token T_AT_STRING 250%token T_AT_STRING
251%token T_AT_TLS_MODEL 251%token T_AT_TLS_MODEL
252%token T_AT_TUNION 252%token T_AT_TUNION
253%token T_AT_UNUSED 253%token T_AT_UNUSED
254%token T_AT_USED 254%token T_AT_USED
255%token T_AT_VISIBILITY 255%token T_AT_VISIBILITY
256%token T_AT_WARN_UNUSED_RESULT 256%token T_AT_WARN_UNUSED_RESULT
257%token T_AT_WEAK 257%token T_AT_WEAK
258 258
259%left T_COMMA 259%left T_COMMA
260%right T_ASSIGN T_OPASSIGN 260%right T_ASSIGN T_OPASSIGN
261%right T_QUEST T_COLON 261%right T_QUEST T_COLON
262%left T_LOGOR 262%left T_LOGOR
263%left T_LOGAND 263%left T_LOGAND
264%left T_BITOR 264%left T_BITOR
265%left T_BITXOR 265%left T_BITXOR
266%left T_AMPER 266%left T_AMPER
267%left T_EQUALITY 267%left T_EQUALITY
268%left T_RELATIONAL 268%left T_RELATIONAL
269%left T_SHIFT 269%left T_SHIFT
270%left T_ADDITIVE 270%left T_ADDITIVE
271%left T_ASTERISK T_MULTIPLICATIVE 271%left T_ASTERISK T_MULTIPLICATIVE
272%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG 272%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG
273%left T_LPAREN T_LBRACK T_POINT T_ARROW 273%left T_LPAREN T_LBRACK T_POINT T_ARROW
274 274
275%token <y_sb> T_NAME 275%token <y_sb> T_NAME
276%token <y_sb> T_TYPENAME 276%token <y_sb> T_TYPENAME
277%token <y_val> T_CON 277%token <y_val> T_CON
278%token <y_string> T_STRING 278%token <y_string> T_STRING
279 279
280%type <y_sym> func_decl 280%type <y_sym> func_decl
281%type <y_sym> notype_decl 281%type <y_sym> notype_decl
282%type <y_sym> type_decl 282%type <y_sym> type_decl
283%type <y_type> typespec 283%type <y_type> typespec
284%type <y_type> clrtyp_typespec 284%type <y_type> clrtyp_typespec
285%type <y_type> notype_typespec 285%type <y_type> notype_typespec
286%type <y_type> struct_spec 286%type <y_type> struct_spec
287%type <y_type> enum_spec 287%type <y_type> enum_spec
288%type <y_sym> struct_tag 288%type <y_sym> struct_tag
289%type <y_sym> enum_tag 289%type <y_sym> enum_tag
290%type <y_tspec> struct 290%type <y_tspec> struct
291%type <y_sym> struct_declaration 291%type <y_sym> struct_declaration
292%type <y_sb> identifier 292%type <y_sb> identifier
293%type <y_sym> member_declaration_list_semi 293%type <y_sym> member_declaration_list_semi
294%type <y_sym> member_declaration_list 294%type <y_sym> member_declaration_list
295%type <y_sym> member_declaration 295%type <y_sym> member_declaration
296%type <y_sym> notype_member_decls 296%type <y_sym> notype_member_decls
297%type <y_sym> type_member_decls 297%type <y_sym> type_member_decls
298%type <y_sym> notype_member_decl 298%type <y_sym> notype_member_decl
299%type <y_sym> type_member_decl 299%type <y_sym> type_member_decl
300%type <y_tnode> constant_expr 300%type <y_tnode> constant_expr
301%type <y_tnode> array_size 301%type <y_tnode> array_size
302%type <y_sym> enum_declaration 302%type <y_sym> enum_declaration
303%type <y_sym> enumerator_list 303%type <y_sym> enumerator_list
304%type <y_sym> enumerator 304%type <y_sym> enumerator
305%type <y_sym> enumeration_constant 305%type <y_sym> enumeration_constant
306%type <y_sym> notype_direct_decl 306%type <y_sym> notype_direct_decl
307%type <y_sym> type_direct_decl 307%type <y_sym> type_direct_decl
308%type <y_qual_ptr> pointer 308%type <y_qual_ptr> pointer
309%type <y_qual_ptr> asterisk 309%type <y_qual_ptr> asterisk
310%type <y_sym> type_param_decl 310%type <y_sym> type_param_decl
311%type <y_sym> param_list 311%type <y_sym> param_list
312%type <y_sym> abstract_decl_param_list 312%type <y_sym> abstract_decl_param_list
313%type <y_sym> direct_param_decl 313%type <y_sym> direct_param_decl
314%type <y_sym> notype_param_decl 314%type <y_sym> notype_param_decl
315%type <y_sym> direct_notype_param_decl 315%type <y_sym> direct_notype_param_decl
316%type <y_qual_ptr> type_qualifier_list_opt 316%type <y_qual_ptr> type_qualifier_list_opt
317%type <y_qual_ptr> type_qualifier_list 317%type <y_qual_ptr> type_qualifier_list
318%type <y_qual_ptr> type_qualifier 318%type <y_qual_ptr> type_qualifier
319%type <y_sym> identifier_list 319%type <y_sym> identifier_list
320%type <y_sym> abstract_declarator 320%type <y_sym> abstract_declarator
321%type <y_sym> direct_abstract_declarator 321%type <y_sym> direct_abstract_declarator
322%type <y_sym> vararg_parameter_type_list 322%type <y_sym> vararg_parameter_type_list
323%type <y_sym> parameter_type_list 323%type <y_sym> parameter_type_list
324%type <y_sym> parameter_declaration 324%type <y_sym> parameter_declaration
325%type <y_tnode> expr 325%type <y_tnode> expr
326%type <y_tnode> assignment_expression 326%type <y_tnode> assignment_expression
327%type <y_tnode> gcc_statement_expr_list 327%type <y_tnode> gcc_statement_expr_list
328%type <y_tnode> gcc_statement_expr_item 328%type <y_tnode> gcc_statement_expr_item
329%type <y_tnode> term 329%type <y_tnode> term
330%type <y_tnode> generic_selection 330%type <y_tnode> generic_selection
331%type <y_tnode> func_arg_list 331%type <y_tnode> func_arg_list
332%type <y_op> point_or_arrow 332%type <y_op> point_or_arrow
333%type <y_type> type_name 333%type <y_type> type_name
334%type <y_sym> abstract_declaration 334%type <y_sym> abstract_declaration
335%type <y_tnode> do_while_expr 335%type <y_tnode> do_while_expr
336%type <y_tnode> expr_opt 336%type <y_tnode> expr_opt
337%type <y_string> string 337%type <y_string> string
338%type <y_string> string2 338%type <y_string> string2
339%type <y_sb> asm_or_symbolrename_opt 339%type <y_sb> asm_or_symbolrename_opt
340%type <y_range> range 340%type <y_range> range
341%type <y_seen_statement> block_item_list 341%type <y_seen_statement> block_item_list
342%type <y_seen_statement> block_item 342%type <y_seen_statement> block_item
343%type <y_generic> generic_assoc_list 343%type <y_generic> generic_assoc_list
344%type <y_generic> generic_association 344%type <y_generic> generic_association
345 345
346%% 346%%
347 347
348program: 348program:
349 /* empty */ { 349 /* empty */ {
350 if (sflag) { 350 if (sflag) {
351 /* empty translation unit */ 351 /* empty translation unit */
352 error(272); 352 error(272);
353 } else if (!tflag) { 353 } else if (!tflag) {
354 /* empty translation unit */ 354 /* empty translation unit */
355 warning(272); 355 warning(272);
356 } 356 }
357 } 357 }
358 | translation_unit 358 | translation_unit
359 ; 359 ;
360 360
361translation_unit: /* C99 6.9 */ 361translation_unit: /* C99 6.9 */
362 external_declaration 362 external_declaration
363 | translation_unit external_declaration 363 | translation_unit external_declaration
364 ; 364 ;
365 365
366external_declaration: /* C99 6.9 */ 366external_declaration: /* C99 6.9 */
367 asm_statement 367 asm_statement
368 | function_definition { 368 | function_definition {
369 global_clean_up_decl(false); 369 global_clean_up_decl(false);
370 clear_warning_flags(); 370 clear_warning_flags();
371 } 371 }
372 | top_level_declaration { 372 | top_level_declaration {
373 global_clean_up_decl(false); 373 global_clean_up_decl(false);
374 clear_warning_flags(); 374 clear_warning_flags();
375 } 375 }
376 ; 376 ;
377 377
378/* 378/*
379 * On the top level, lint allows several forms of declarations that it doesn't 379 * On the top level, lint allows several forms of declarations that it doesn't
380 * allow in functions. For example, a single ';' is an empty declaration and 380 * allow in functions. For example, a single ';' is an empty declaration and
381 * is supported by some compilers, but in a function it would be an empty 381 * is supported by some compilers, but in a function it would be an empty
382 * statement, not a declaration. This makes a difference in C90 mode, where 382 * statement, not a declaration. This makes a difference in C90 mode, where
383 * a statement must not be followed by a declaration. 383 * a statement must not be followed by a declaration.
384 * 384 *
385 * See 'declaration' for all other declarations. 385 * See 'declaration' for all other declarations.
386 */ 386 */
387top_level_declaration: /* C99 6.9 calls this 'declaration' */ 387top_level_declaration: /* C99 6.9 calls this 'declaration' */
388 T_SEMI { 388 T_SEMI {
389 if (sflag) { 389 if (sflag) {
390 /* empty declaration */ 390 /* empty declaration */
391 error(0); 391 error(0);
392 } else if (!tflag) { 392 } else if (!tflag) {
393 /* empty declaration */ 393 /* empty declaration */
394 warning(0); 394 warning(0);
395 } 395 }
396 } 396 }
397 | clrtyp deftyp notype_init_decls T_SEMI { 397 | clrtyp deftyp notype_init_decls T_SEMI {
398 if (sflag) { 398 if (sflag) {
399 /* old style declaration; add 'int' */ 399 /* old style declaration; add 'int' */
400 error(1); 400 error(1);
401 } else if (!tflag) { 401 } else if (!tflag) {
402 /* old style declaration; add 'int' */ 402 /* old style declaration; add 'int' */
403 warning(1); 403 warning(1);
404 } 404 }
405 } 405 }
406 | declmods deftyp T_SEMI { 406 | declaration_noerror
407 if (dcs->d_scl == TYPEDEF) { 
408 /* typedef declares no type name */ 
409 warning(72); 
410 } else { 
411 /* empty declaration */ 
412 warning(2); 
413 } 
414 } 
415 | declmods deftyp notype_init_decls T_SEMI 
416 | declaration_specifiers deftyp T_SEMI { 
417 if (dcs->d_scl == TYPEDEF) { 
418 /* typedef declares no type name */ 
419 warning(72); 
420 } else if (!dcs->d_nonempty_decl) { 
421 /* empty declaration */ 
422 warning(2); 
423 } 
424 } 
425 | declaration_specifiers deftyp type_init_decls T_SEMI 
426 | error T_SEMI { 407 | error T_SEMI {
427 global_clean_up(); 408 global_clean_up();
428 } 409 }
429 | error T_RBRACE { 410 | error T_RBRACE {
430 global_clean_up(); 411 global_clean_up();
431 } 412 }
432 ; 413 ;
433 414
434function_definition: /* C99 6.9.1 */ 415function_definition: /* C99 6.9.1 */
435 func_decl { 416 func_decl {
436 if ($1->s_type->t_tspec != FUNC) { 417 if ($1->s_type->t_tspec != FUNC) {
437 /* syntax error '%s' */ 418 /* syntax error '%s' */
438 error(249, yytext); 419 error(249, yytext);
439 YYERROR; 420 YYERROR;
440 } 421 }
441 if ($1->s_type->t_typedef) { 422 if ($1->s_type->t_typedef) {
442 /* ()-less function definition */ 423 /* ()-less function definition */
443 error(64); 424 error(64);
444 YYERROR; 425 YYERROR;
445 } 426 }
446 funcdef($1); 427 funcdef($1);
447 block_level++; 428 block_level++;
448 begin_declaration_level(ARG); 429 begin_declaration_level(ARG);
449 if (lwarn == LWARN_NONE) 430 if (lwarn == LWARN_NONE)
450 $1->s_used = true; 431 $1->s_used = true;
451 } arg_declaration_list_opt { 432 } arg_declaration_list_opt {
452 end_declaration_level(); 433 end_declaration_level();
453 block_level--; 434 block_level--;
454 check_func_lint_directives(); 435 check_func_lint_directives();
455 check_func_old_style_arguments(); 436 check_func_old_style_arguments();
456 begin_control_statement(CS_FUNCTION_BODY); 437 begin_control_statement(CS_FUNCTION_BODY);
457 } compound_statement { 438 } compound_statement {
458 funcend(); 439 funcend();
459 end_control_statement(CS_FUNCTION_BODY); 440 end_control_statement(CS_FUNCTION_BODY);
460 } 441 }
461 ; 442 ;
462 443
463func_decl: 444func_decl:
464 clrtyp deftyp notype_decl { 445 clrtyp deftyp notype_decl {
465 $$ = $3; 446 $$ = $3;
466 } 447 }
467 | declmods deftyp notype_decl { 448 | declmods deftyp notype_decl {
468 $$ = $3; 449 $$ = $3;
469 } 450 }
470 | declaration_specifiers deftyp type_decl { 451 | declaration_specifiers deftyp type_decl {
471 $$ = $3; 452 $$ = $3;
472 } 453 }
473 ; 454 ;
474 455
475arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ 456arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */
476 /* empty */ 457 /* empty */
477 | arg_declaration_list 458 | arg_declaration_list
478 ; 459 ;
479 460
480arg_declaration_list: /* C99 6.9.1p13 example 1 */ 461arg_declaration_list: /* C99 6.9.1p13 example 1 */
481 arg_declaration 462 arg_declaration
482 | arg_declaration_list arg_declaration 463 | arg_declaration_list arg_declaration
483 /* XXX or better "arg_declaration error" ? */ 464 /* XXX or better "arg_declaration error" ? */
484 | error 465 | error
485 ; 466 ;
486 467
487/* 468/*
488 * "arg_declaration" is separated from "declaration" because it 469 * "arg_declaration" is separated from "declaration" because it
489 * needs other error handling. 470 * needs other error handling.
490 */ 471 */
491arg_declaration: 472arg_declaration:
492 declmods deftyp T_SEMI { 473 declmods deftyp T_SEMI {
493 /* empty declaration */ 474 /* empty declaration */
494 warning(2); 475 warning(2);
495 } 476 }
496 | declmods deftyp notype_init_decls T_SEMI 477 | declmods deftyp notype_init_decls T_SEMI
497 | declaration_specifiers deftyp T_SEMI { 478 | declaration_specifiers deftyp T_SEMI {
498 if (!dcs->d_nonempty_decl) { 479 if (!dcs->d_nonempty_decl) {
499 /* empty declaration */ 480 /* empty declaration */
500 warning(2); 481 warning(2);
501 } else { 482 } else {
502 /* '%s' declared in argument declaration list */ 483 /* '%s' declared in argument declaration list */
503 warning(3, type_name(dcs->d_type)); 484 warning(3, type_name(dcs->d_type));
504 } 485 }
505 } 486 }
506 | declaration_specifiers deftyp type_init_decls T_SEMI { 487 | declaration_specifiers deftyp type_init_decls T_SEMI {
507 if (dcs->d_nonempty_decl) { 488 if (dcs->d_nonempty_decl) {
508 /* '%s' declared in argument declaration list */ 489 /* '%s' declared in argument declaration list */
509 warning(3, type_name(dcs->d_type)); 490 warning(3, type_name(dcs->d_type));
510 } 491 }
511 } 492 }
512 | declmods error 493 | declmods error
513 | declaration_specifiers error 494 | declaration_specifiers error
514 ; 495 ;
515 496
516declaration: /* C99 6.7 */ 497declaration: /* C99 6.7 */
 498 declaration_noerror
 499 | error T_SEMI
 500 ;
 501
 502declaration_noerror: /* see C99 6.7 'declaration' */
517 declmods deftyp T_SEMI { 503 declmods deftyp T_SEMI {
518 if (dcs->d_scl == TYPEDEF) { 504 if (dcs->d_scl == TYPEDEF) {
519 /* typedef declares no type name */ 505 /* typedef declares no type name */
520 warning(72); 506 warning(72);
521 } else { 507 } else {
522 /* empty declaration */ 508 /* empty declaration */
523 warning(2); 509 warning(2);
524 } 510 }
525 } 511 }
526 | declmods deftyp notype_init_decls T_SEMI 512 | declmods deftyp notype_init_decls T_SEMI
527 | declaration_specifiers deftyp T_SEMI { 513 | declaration_specifiers deftyp T_SEMI {
528 if (dcs->d_scl == TYPEDEF) { 514 if (dcs->d_scl == TYPEDEF) {
529 /* typedef declares no type name */ 515 /* typedef declares no type name */
530 warning(72); 516 warning(72);
531 } else if (!dcs->d_nonempty_decl) { 517 } else if (!dcs->d_nonempty_decl) {
532 /* empty declaration */ 518 /* empty declaration */
533 warning(2); 519 warning(2);
534 } 520 }
535 } 521 }
536 | declaration_specifiers deftyp type_init_decls T_SEMI 522 | declaration_specifiers deftyp type_init_decls T_SEMI
537 | error T_SEMI 
538 ; 523 ;
539 524
540clrtyp: 525clrtyp:
541 /* empty */ { 526 /* empty */ {
542 clrtyp(); 527 clrtyp();
543 } 528 }
544 ; 529 ;
545 530
546deftyp: 531deftyp:
547 /* empty */ { 532 /* empty */ {
548 deftyp(); 533 deftyp();
549 } 534 }
550 ; 535 ;
551 536
552declaration_specifiers: /* C99 6.7 */ 537declaration_specifiers: /* C99 6.7 */
553 clrtyp_typespec { 538 clrtyp_typespec {
554 add_type($1); 539 add_type($1);
555 } 540 }
556 | declmods typespec { 541 | declmods typespec {
557 add_type($2); 542 add_type($2);
558 } 543 }
559 | type_attribute declaration_specifiers 544 | type_attribute declaration_specifiers
560 | declaration_specifiers declmod 545 | declaration_specifiers declmod
561 | declaration_specifiers notype_typespec { 546 | declaration_specifiers notype_typespec {
562 add_type($2); 547 add_type($2);
563 } 548 }
564 ; 549 ;
565 550
566declmods: 551declmods:
567 clrtyp T_QUAL { 552 clrtyp T_QUAL {
568 add_qualifier($2); 553 add_qualifier($2);
569 } 554 }
570 | clrtyp T_SCLASS { 555 | clrtyp T_SCLASS {
571 add_storage_class($2); 556 add_storage_class($2);
572 } 557 }
573 | declmods declmod 558 | declmods declmod
574 ; 559 ;
575 560
576declmod: 561declmod:
577 T_QUAL { 562 T_QUAL {
578 add_qualifier($1); 563 add_qualifier($1);
579 } 564 }
580 | T_SCLASS { 565 | T_SCLASS {
581 add_storage_class($1); 566 add_storage_class($1);
582 } 567 }
583 | type_attribute 568 | type_attribute
584 ; 569 ;
585 570
586clrtyp_typespec: 571clrtyp_typespec:
587 clrtyp notype_typespec { 572 clrtyp notype_typespec {
588 $$ = $2; 573 $$ = $2;
589 } 574 }
590 | T_TYPENAME clrtyp { 575 | T_TYPENAME clrtyp {
591 $$ = getsym($1)->s_type; 576 $$ = getsym($1)->s_type;
592 } 577 }
593 ; 578 ;
594 579
595typespec: 580typespec:
596 notype_typespec 581 notype_typespec
597 | T_TYPENAME { 582 | T_TYPENAME {
598 $$ = getsym($1)->s_type; 583 $$ = getsym($1)->s_type;
599 } 584 }
600 ; 585 ;
601 586
602notype_typespec: 587notype_typespec:
603 T_TYPE { 588 T_TYPE {
604 $$ = gettyp($1); 589 $$ = gettyp($1);
605 } 590 }
606 | T_TYPEOF term { 591 | T_TYPEOF term {
607 $$ = $2->tn_type; 592 $$ = $2->tn_type;
608 } 593 }
609 | struct_spec { 594 | struct_spec {
610 end_declaration_level(); 595 end_declaration_level();
611 $$ = $1; 596 $$ = $1;
612 } 597 }
613 | enum_spec { 598 | enum_spec {
614 end_declaration_level(); 599 end_declaration_level();
615 $$ = $1; 600 $$ = $1;
616 } 601 }
617 ; 602 ;
618 603
619struct_spec: 604struct_spec:
620 struct struct_tag { 605 struct struct_tag {
621 /* 606 /*
622 * STDC requires that "struct a;" always introduces 607 * STDC requires that "struct a;" always introduces
623 * a new tag if "a" is not declared at current level 608 * a new tag if "a" is not declared at current level
624 * 609 *
625 * yychar is valid because otherwise the parser would not 610 * yychar is valid because otherwise the parser would not
626 * have been able to decide if it must shift or reduce 611 * have been able to decide if it must shift or reduce
627 */ 612 */
628 $$ = mktag($2, $1, false, yychar == T_SEMI); 613 $$ = mktag($2, $1, false, yychar == T_SEMI);
629 } 614 }
630 | struct struct_tag { 615 | struct struct_tag {
631 dcs->d_tagtyp = mktag($2, $1, true, false); 616 dcs->d_tagtyp = mktag($2, $1, true, false);
632 } struct_declaration { 617 } struct_declaration {
633 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4); 618 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $4);
634 } 619 }
635 | struct { 620 | struct {
636 dcs->d_tagtyp = mktag(NULL, $1, true, false); 621 dcs->d_tagtyp = mktag(NULL, $1, true, false);
637 } struct_declaration { 622 } struct_declaration {
638 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3); 623 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $3);
639 } 624 }
640 | struct error { 625 | struct error {
641 symtyp = FVFT; 626 symtyp = FVFT;
642 $$ = gettyp(INT); 627 $$ = gettyp(INT);
643 } 628 }
644 ; 629 ;
645 630
646struct: 631struct:
647 T_STRUCT_OR_UNION { 632 T_STRUCT_OR_UNION {
648 symtyp = FTAG; 633 symtyp = FTAG;
649 begin_declaration_level($1 == STRUCT ? MOS : MOU); 634 begin_declaration_level($1 == STRUCT ? MOS : MOU);
650 dcs->d_offset = 0; 635 dcs->d_offset = 0;
651 dcs->d_sou_align_in_bits = CHAR_SIZE; 636 dcs->d_sou_align_in_bits = CHAR_SIZE;
652 } type_attribute_list_opt 637 } type_attribute_list_opt
653 ; 638 ;
654 639
655struct_tag: 640struct_tag:
656 identifier { 641 identifier {
657 $$ = getsym($1); 642 $$ = getsym($1);
658 } 643 }
659 ; 644 ;
660 645
661struct_declaration: 646struct_declaration:
662 T_LBRACE { 647 T_LBRACE {
663 symtyp = FVFT; 648 symtyp = FVFT;
664 } member_declaration_list_semi T_RBRACE { 649 } member_declaration_list_semi T_RBRACE {
665 $$ = $3; 650 $$ = $3;
666 } 651 }
667 ; 652 ;
668 653
669member_declaration_list_semi: 654member_declaration_list_semi:
670 /* empty */ { 655 /* empty */ {
671 $$ = NULL; 656 $$ = NULL;
672 } 657 }
673 | member_declaration_list T_SEMI 658 | member_declaration_list T_SEMI
674 | member_declaration_list { 659 | member_declaration_list {
675 if (sflag) { 660 if (sflag) {
676 /* syntax req. ';' after last struct/union member */ 661 /* syntax req. ';' after last struct/union member */
677 error(66); 662 error(66);
678 } else { 663 } else {
679 /* syntax req. ';' after last struct/union member */ 664 /* syntax req. ';' after last struct/union member */
680 warning(66); 665 warning(66);
681 } 666 }
682 $$ = $1; 667 $$ = $1;
683 } 668 }
684 ; 669 ;
685 670
686member_declaration_list: 671member_declaration_list:
687 member_declaration 672 member_declaration
688 | member_declaration_list T_SEMI member_declaration { 673 | member_declaration_list T_SEMI member_declaration {
689 $$ = lnklst($1, $3); 674 $$ = lnklst($1, $3);
690 } 675 }
691 ; 676 ;
692 677
693member_declaration: 678member_declaration:
694 noclass_declmods deftyp { 679 noclass_declmods deftyp {
695 /* too late, i know, but getsym() compensates it */ 680 /* too late, i know, but getsym() compensates it */
696 symtyp = FMEMBER; 681 symtyp = FMEMBER;
697 } notype_member_decls type_attribute_opt { 682 } notype_member_decls type_attribute_opt {
698 symtyp = FVFT; 683 symtyp = FVFT;
699 $$ = $4; 684 $$ = $4;
700 } 685 }
701 | noclass_declspecs deftyp { 686 | noclass_declspecs deftyp {
702 symtyp = FMEMBER; 687 symtyp = FMEMBER;
703 } type_member_decls type_attribute_opt { 688 } type_member_decls type_attribute_opt {
704 symtyp = FVFT; 689 symtyp = FVFT;
705 $$ = $4; 690 $$ = $4;
706 } 691 }
707 | noclass_declmods deftyp type_attribute_opt { 692 | noclass_declmods deftyp type_attribute_opt {
708 symtyp = FVFT; 693 symtyp = FVFT;
709 /* struct or union member must be named */ 694 /* struct or union member must be named */
710 if (!Sflag) 695 if (!Sflag)
711 /* anonymous struct/union members is a C9X feature */ 696 /* anonymous struct/union members is a C9X feature */
712 warning(49); 697 warning(49);
713 /* add all the members of the anonymous struct/union */ 698 /* add all the members of the anonymous struct/union */
714 lint_assert(is_struct_or_union(dcs->d_type->t_tspec)); 699 lint_assert(is_struct_or_union(dcs->d_type->t_tspec));
715 $$ = dcs->d_type->t_str->sou_first_member; 700 $$ = dcs->d_type->t_str->sou_first_member;
716 anonymize($$); 701 anonymize($$);
717 } 702 }
718 | noclass_declspecs deftyp type_attribute_opt { 703 | noclass_declspecs deftyp type_attribute_opt {
719 symtyp = FVFT; 704 symtyp = FVFT;
720 /* struct or union member must be named */ 705 /* struct or union member must be named */
721 if (!Sflag) 706 if (!Sflag)
722 /* anonymous struct/union members is a C9X feature */ 707 /* anonymous struct/union members is a C9X feature */
723 warning(49); 708 warning(49);
724 if (is_struct_or_union(dcs->d_type->t_tspec)) { 709 if (is_struct_or_union(dcs->d_type->t_tspec)) {
725 $$ = dcs->d_type->t_str->sou_first_member; 710 $$ = dcs->d_type->t_str->sou_first_member;
726 /* add all the members of the anonymous struct/union */ 711 /* add all the members of the anonymous struct/union */
727 anonymize($$); 712 anonymize($$);
728 } else { 713 } else {
729 /* syntax error '%s' */ 714 /* syntax error '%s' */
730 error(249, "unnamed member"); 715 error(249, "unnamed member");
731 $$ = NULL; 716 $$ = NULL;
732 } 717 }
733 } 718 }
734 | error { 719 | error {
735 symtyp = FVFT; 720 symtyp = FVFT;
736 $$ = NULL; 721 $$ = NULL;
737 } 722 }
738 ; 723 ;
739 724
740/* 725/*
741 * XXX: shift/reduce conflict, caused by: 726 * XXX: shift/reduce conflict, caused by:
742 * type_attribute noclass_declspecs 727 * type_attribute noclass_declspecs
743 * noclass_declspecs type_attribute 728 * noclass_declspecs type_attribute
744 */ 729 */
745noclass_declspecs: 730noclass_declspecs:
746 clrtyp_typespec { 731 clrtyp_typespec {
747 add_type($1); 732 add_type($1);
748 } 733 }
749 | type_attribute noclass_declspecs 734 | type_attribute noclass_declspecs
750 | noclass_declmods typespec { 735 | noclass_declmods typespec {
751 add_type($2); 736 add_type($2);
752 } 737 }
753 | noclass_declspecs T_QUAL { 738 | noclass_declspecs T_QUAL {
754 add_qualifier($2); 739 add_qualifier($2);
755 } 740 }
756 | noclass_declspecs notype_typespec { 741 | noclass_declspecs notype_typespec {
757 add_type($2); 742 add_type($2);
758 } 743 }
759 | noclass_declspecs type_attribute 744 | noclass_declspecs type_attribute
760 ; 745 ;
761 746
762noclass_declmods: 747noclass_declmods:
763 clrtyp T_QUAL { 748 clrtyp T_QUAL {
764 add_qualifier($2); 749 add_qualifier($2);
765 } 750 }
766 | noclass_declmods T_QUAL { 751 | noclass_declmods T_QUAL {
767 add_qualifier($2); 752 add_qualifier($2);
768 } 753 }
769 ; 754 ;
770 755
771notype_member_decls: 756notype_member_decls:
772 notype_member_decl { 757 notype_member_decl {
773 $$ = declarator_1_struct_union($1); 758 $$ = declarator_1_struct_union($1);
774 } 759 }
775 | notype_member_decls { 760 | notype_member_decls {
776 symtyp = FMEMBER; 761 symtyp = FMEMBER;
777 } T_COMMA type_member_decl { 762 } T_COMMA type_member_decl {
778 $$ = lnklst($1, declarator_1_struct_union($4)); 763 $$ = lnklst($1, declarator_1_struct_union($4));
779 } 764 }
780 ; 765 ;
781 766
782type_member_decls: 767type_member_decls:
783 type_member_decl { 768 type_member_decl {
784 $$ = declarator_1_struct_union($1); 769 $$ = declarator_1_struct_union($1);
785 } 770 }
786 | type_member_decls { 771 | type_member_decls {
787 symtyp = FMEMBER; 772 symtyp = FMEMBER;
788 } T_COMMA type_member_decl { 773 } T_COMMA type_member_decl {
789 $$ = lnklst($1, declarator_1_struct_union($4)); 774 $$ = lnklst($1, declarator_1_struct_union($4));
790 } 775 }
791 ; 776 ;
792 777
793notype_member_decl: 778notype_member_decl:
794 notype_decl 779 notype_decl
795 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */ 780 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */
796 $$ = bitfield($1, to_int_constant($3, true)); 781 $$ = bitfield($1, to_int_constant($3, true));
797 } 782 }
798 | { 783 | {
799 symtyp = FVFT; 784 symtyp = FVFT;
800 } T_COLON constant_expr { /* C99 6.7.2.1 */ 785 } T_COLON constant_expr { /* C99 6.7.2.1 */
801 $$ = bitfield(NULL, to_int_constant($3, true)); 786 $$ = bitfield(NULL, to_int_constant($3, true));
802 } 787 }
803 ; 788 ;
804 789
805type_member_decl: 790type_member_decl:
806 type_decl 791 type_decl
807 | type_decl T_COLON constant_expr { 792 | type_decl T_COLON constant_expr {
808 $$ = bitfield($1, to_int_constant($3, true)); 793 $$ = bitfield($1, to_int_constant($3, true));
809 } 794 }
810 | { 795 | {
811 symtyp = FVFT; 796 symtyp = FVFT;
812 } T_COLON constant_expr { 797 } T_COLON constant_expr {
813 $$ = bitfield(NULL, to_int_constant($3, true)); 798 $$ = bitfield(NULL, to_int_constant($3, true));
814 } 799 }
815 ; 800 ;
816 801
817enum_spec: 802enum_spec:
818 enum enum_tag { 803 enum enum_tag {
819 $$ = mktag($2, ENUM, false, false); 804 $$ = mktag($2, ENUM, false, false);
820 } 805 }
821 | enum enum_tag { 806 | enum enum_tag {
822 dcs->d_tagtyp = mktag($2, ENUM, true, false); 807 dcs->d_tagtyp = mktag($2, ENUM, true, false);
823 } enum_declaration { 808 } enum_declaration {
824 $$ = complete_tag_enum(dcs->d_tagtyp, $4); 809 $$ = complete_tag_enum(dcs->d_tagtyp, $4);
825 } 810 }
826 | enum { 811 | enum {
827 dcs->d_tagtyp = mktag(NULL, ENUM, true, false); 812 dcs->d_tagtyp = mktag(NULL, ENUM, true, false);
828 } enum_declaration { 813 } enum_declaration {
829 $$ = complete_tag_enum(dcs->d_tagtyp, $3); 814 $$ = complete_tag_enum(dcs->d_tagtyp, $3);
830 } 815 }
831 | enum error { 816 | enum error {
832 symtyp = FVFT; 817 symtyp = FVFT;
833 $$ = gettyp(INT); 818 $$ = gettyp(INT);
834 } 819 }
835 ; 820 ;
836 821
837enum: 822enum:
838 T_ENUM { 823 T_ENUM {
839 symtyp = FTAG; 824 symtyp = FTAG;
840 begin_declaration_level(CTCONST); 825 begin_declaration_level(CTCONST);
841 } 826 }
842 ; 827 ;
843 828
844enum_tag: 829enum_tag:
845 identifier { 830 identifier {
846 $$ = getsym($1); 831 $$ = getsym($1);
847 } 832 }
848 ; 833 ;
849 834
850enum_declaration: 835enum_declaration:
851 T_LBRACE { 836 T_LBRACE {
852 symtyp = FVFT; 837 symtyp = FVFT;
853 enumval = 0; 838 enumval = 0;
854 } enumerator_list enumerator_list_comma_opt T_RBRACE { 839 } enumerator_list enumerator_list_comma_opt T_RBRACE {
855 $$ = $3; 840 $$ = $3;
856 } 841 }
857 ; 842 ;
858 843
859enumerator_list: /* C99 6.7.2.2 */ 844enumerator_list: /* C99 6.7.2.2 */
860 enumerator 845 enumerator
861 | enumerator_list T_COMMA enumerator { 846 | enumerator_list T_COMMA enumerator {
862 $$ = lnklst($1, $3); 847 $$ = lnklst($1, $3);
863 } 848 }
864 | error { 849 | error {
865 $$ = NULL; 850 $$ = NULL;
866 } 851 }
867 ; 852 ;
868 853
869enumerator_list_comma_opt: 854enumerator_list_comma_opt:
870 /* empty */ 855 /* empty */
871 | T_COMMA { 856 | T_COMMA {
872 if (sflag) { 857 if (sflag) {
873 /* trailing ',' prohibited in enum declaration */ 858 /* trailing ',' prohibited in enum declaration */
874 error(54); 859 error(54);
875 } else { 860 } else {
876 /* trailing ',' prohibited in enum declaration */ 861 /* trailing ',' prohibited in enum declaration */
877 c99ism(54); 862 c99ism(54);
878 } 863 }
879 } 864 }
880 ; 865 ;
881 866
882enumerator: /* C99 6.7.2.2 */ 867enumerator: /* C99 6.7.2.2 */
883 enumeration_constant { 868 enumeration_constant {
884 $$ = enumeration_constant($1, enumval, true); 869 $$ = enumeration_constant($1, enumval, true);
885 } 870 }
886 | enumeration_constant T_ASSIGN constant_expr { 871 | enumeration_constant T_ASSIGN constant_expr {
887 $$ = enumeration_constant($1, to_int_constant($3, true), false); 872 $$ = enumeration_constant($1, to_int_constant($3, true), false);
888 } 873 }
889 ; 874 ;
890 875
891enumeration_constant: /* C99 6.4.4.3 */ 876enumeration_constant: /* C99 6.4.4.3 */
892 identifier { 877 identifier {
893 $$ = getsym($1); 878 $$ = getsym($1);
894 } 879 }
895 ; 880 ;
896 881
897 882
898/* 883/*
899 * For an explanation of 'notype' in the following rules, see the Bison 884 * For an explanation of 'notype' in the following rules, see the Bison
900 * manual, section 7.1 "Semantic Info in Token Kinds". 885 * manual, section 7.1 "Semantic Info in Token Kinds".
901 */ 886 */
902 887
903notype_init_decls: 888notype_init_decls:
904 notype_init_decl 889 notype_init_decl
905 | notype_init_decls T_COMMA type_init_decl 890 | notype_init_decls T_COMMA type_init_decl
906 ; 891 ;
907 892
908type_init_decls: 893type_init_decls:
909 type_init_decl 894 type_init_decl
910 | type_init_decls T_COMMA type_init_decl 895 | type_init_decls T_COMMA type_init_decl
911 ; 896 ;
912 897
913notype_init_decl: 898notype_init_decl:
914 notype_decl asm_or_symbolrename_opt { 899 notype_decl asm_or_symbolrename_opt {
915 cgram_declare($1, false, $2); 900 cgram_declare($1, false, $2);
916 check_size($1); 901 check_size($1);
917 } 902 }
918 | notype_decl asm_or_symbolrename_opt { 903 | notype_decl asm_or_symbolrename_opt {
919 begin_initialization($1); 904 begin_initialization($1);
920 cgram_declare($1, true, $2); 905 cgram_declare($1, true, $2);
921 } T_ASSIGN initializer { 906 } T_ASSIGN initializer {
922 check_size($1); 907 check_size($1);
923 end_initialization(); 908 end_initialization();
924 } 909 }
925 ; 910 ;
926 911
927type_init_decl: 912type_init_decl:
928 type_decl asm_or_symbolrename_opt { 913 type_decl asm_or_symbolrename_opt {
929 cgram_declare($1, false, $2); 914 cgram_declare($1, false, $2);
930 check_size($1); 915 check_size($1);
931 } 916 }
932 | type_decl asm_or_symbolrename_opt { 917 | type_decl asm_or_symbolrename_opt {
933 begin_initialization($1); 918 begin_initialization($1);
934 cgram_declare($1, true, $2); 919 cgram_declare($1, true, $2);
935 } T_ASSIGN initializer { 920 } T_ASSIGN initializer {
936 check_size($1); 921 check_size($1);
937 end_initialization(); 922 end_initialization();
938 } 923 }
939 ; 924 ;
940 925
941notype_decl: 926notype_decl:
942 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */ 927 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */
943 type_attribute_list_opt notype_direct_decl { 928 type_attribute_list_opt notype_direct_decl {
944 $$ = $2; 929 $$ = $2;
945 } 930 }
946 | pointer type_attribute_list_opt notype_direct_decl { 931 | pointer type_attribute_list_opt notype_direct_decl {
947 $$ = add_pointer($3, $1); 932 $$ = add_pointer($3, $1);
948 } 933 }
949 ; 934 ;
950 935
951type_decl: 936type_decl:
952 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */ 937 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */
953 type_attribute_list_opt type_direct_decl { 938 type_attribute_list_opt type_direct_decl {
954 $$ = $2; 939 $$ = $2;
955 } 940 }
956 | pointer type_attribute_list_opt type_direct_decl { 941 | pointer type_attribute_list_opt type_direct_decl {
957 $$ = add_pointer($3, $1); 942 $$ = add_pointer($3, $1);
958 } 943 }
959 ; 944 ;
960 945
961notype_direct_decl: 946notype_direct_decl:
962 T_NAME { 947 T_NAME {
963 $$ = declarator_name(getsym($1)); 948 $$ = declarator_name(getsym($1));
964 } 949 }
965 | T_LPAREN type_decl T_RPAREN { 950 | T_LPAREN type_decl T_RPAREN {
966 $$ = $2; 951 $$ = $2;
967 } 952 }
968 | notype_direct_decl T_LBRACK T_RBRACK { 953 | notype_direct_decl T_LBRACK T_RBRACK {
969 $$ = add_array($1, false, 0); 954 $$ = add_array($1, false, 0);
970 } 955 }
971 | notype_direct_decl T_LBRACK array_size T_RBRACK { 956 | notype_direct_decl T_LBRACK array_size T_RBRACK {
972 $$ = add_array($1, true, to_int_constant($3, false)); 957 $$ = add_array($1, true, to_int_constant($3, false));
973 } 958 }
974 | notype_direct_decl param_list asm_or_symbolrename_opt { 959 | notype_direct_decl param_list asm_or_symbolrename_opt {
975 $$ = add_function(symbolrename($1, $3), $2); 960 $$ = add_function(symbolrename($1, $3), $2);
976 end_declaration_level(); 961 end_declaration_level();
977 block_level--; 962 block_level--;
978 } 963 }
979 | notype_direct_decl type_attribute 964 | notype_direct_decl type_attribute
980 ; 965 ;
981 966
982type_direct_decl: 967type_direct_decl:
983 identifier { 968 identifier {
984 $$ = declarator_name(getsym($1)); 969 $$ = declarator_name(getsym($1));
985 } 970 }
986 | T_LPAREN type_decl T_RPAREN { 971 | T_LPAREN type_decl T_RPAREN {
987 $$ = $2; 972 $$ = $2;
988 } 973 }
989 | type_direct_decl T_LBRACK T_RBRACK { 974 | type_direct_decl T_LBRACK T_RBRACK {
990 $$ = add_array($1, false, 0); 975 $$ = add_array($1, false, 0);
991 } 976 }
992 | type_direct_decl T_LBRACK array_size T_RBRACK { 977 | type_direct_decl T_LBRACK array_size T_RBRACK {
993 $$ = add_array($1, true, to_int_constant($3, false)); 978 $$ = add_array($1, true, to_int_constant($3, false));
994 } 979 }
995 | type_direct_decl param_list asm_or_symbolrename_opt { 980 | type_direct_decl param_list asm_or_symbolrename_opt {
996 $$ = add_function(symbolrename($1, $3), $2); 981 $$ = add_function(symbolrename($1, $3), $2);
997 end_declaration_level(); 982 end_declaration_level();
998 block_level--; 983 block_level--;
999 } 984 }
1000 | type_direct_decl type_attribute 985 | type_direct_decl type_attribute
1001 ; 986 ;
1002 987
1003/* 988/*
1004 * The two distinct rules type_param_decl and notype_param_decl avoid a 989 * The two distinct rules type_param_decl and notype_param_decl avoid a
1005 * conflict in argument lists. A typename enclosed in parentheses is always 990 * conflict in argument lists. A typename enclosed in parentheses is always
1006 * treated as a typename, not an argument name. For example, after 991 * treated as a typename, not an argument name. For example, after
1007 * "typedef double a;", the declaration "f(int (a));" is interpreted as 992 * "typedef double a;", the declaration "f(int (a));" is interpreted as
1008 * "f(int (double));", not "f(int a);". 993 * "f(int (double));", not "f(int a);".
1009 */ 994 */
1010type_param_decl: 995type_param_decl:
1011 direct_param_decl 996 direct_param_decl
1012 | pointer direct_param_decl { 997 | pointer direct_param_decl {
1013 $$ = add_pointer($2, $1); 998 $$ = add_pointer($2, $1);
1014 } 999 }
1015 ; 1000 ;
1016 1001
1017notype_param_decl: 1002notype_param_decl:
1018 direct_notype_param_decl 1003 direct_notype_param_decl
1019 | pointer direct_notype_param_decl { 1004 | pointer direct_notype_param_decl {
1020 $$ = add_pointer($2, $1); 1005 $$ = add_pointer($2, $1);
1021 } 1006 }
1022 ; 1007 ;
1023 1008
1024direct_param_decl: 1009direct_param_decl:
1025 identifier type_attribute_list_opt { 1010 identifier type_attribute_list_opt {
1026 $$ = declarator_name(getsym($1)); 1011 $$ = declarator_name(getsym($1));
1027 } 1012 }
1028 | T_LPAREN notype_param_decl T_RPAREN { 1013 | T_LPAREN notype_param_decl T_RPAREN {
1029 $$ = $2; 1014 $$ = $2;
1030 } 1015 }
1031 | direct_param_decl T_LBRACK T_RBRACK { 1016 | direct_param_decl T_LBRACK T_RBRACK {
1032 $$ = add_array($1, false, 0); 1017 $$ = add_array($1, false, 0);
1033 } 1018 }
1034 | direct_param_decl T_LBRACK array_size T_RBRACK { 1019 | direct_param_decl T_LBRACK array_size T_RBRACK {
1035 $$ = add_array($1, true, to_int_constant($3, false)); 1020 $$ = add_array($1, true, to_int_constant($3, false));
1036 } 1021 }
1037 | direct_param_decl param_list asm_or_symbolrename_opt { 1022 | direct_param_decl param_list asm_or_symbolrename_opt {
1038 $$ = add_function(symbolrename($1, $3), $2); 1023 $$ = add_function(symbolrename($1, $3), $2);
1039 end_declaration_level(); 1024 end_declaration_level();
1040 block_level--; 1025 block_level--;
1041 } 1026 }
1042 ; 1027 ;
1043 1028
1044direct_notype_param_decl: 1029direct_notype_param_decl:
1045 identifier /* XXX: missing type_attribute_list_opt? */ { 1030 identifier /* XXX: missing type_attribute_list_opt? */ {
1046 $$ = declarator_name(getsym($1)); 1031 $$ = declarator_name(getsym($1));
1047 } 1032 }
1048 | T_LPAREN notype_param_decl T_RPAREN { 1033 | T_LPAREN notype_param_decl T_RPAREN {
1049 $$ = $2; 1034 $$ = $2;
1050 } 1035 }
1051 | direct_notype_param_decl T_LBRACK T_RBRACK { 1036 | direct_notype_param_decl T_LBRACK T_RBRACK {
1052 $$ = add_array($1, false, 0); 1037 $$ = add_array($1, false, 0);
1053 } 1038 }
1054 | direct_notype_param_decl T_LBRACK array_size T_RBRACK { 1039 | direct_notype_param_decl T_LBRACK array_size T_RBRACK {
1055 $$ = add_array($1, true, to_int_constant($3, false)); 1040 $$ = add_array($1, true, to_int_constant($3, false));
1056 } 1041 }
1057 | direct_notype_param_decl param_list asm_or_symbolrename_opt { 1042 | direct_notype_param_decl param_list asm_or_symbolrename_opt {
1058 $$ = add_function(symbolrename($1, $3), $2); 1043 $$ = add_function(symbolrename($1, $3), $2);
1059 end_declaration_level(); 1044 end_declaration_level();
1060 block_level--; 1045 block_level--;
1061 } 1046 }
1062 ; 1047 ;
1063 1048
1064pointer: /* C99 6.7.5 */ 1049pointer: /* C99 6.7.5 */
1065 asterisk type_qualifier_list_opt { 1050 asterisk type_qualifier_list_opt {
1066 $$ = merge_qualified_pointer($1, $2); 1051 $$ = merge_qualified_pointer($1, $2);
1067 } 1052 }
1068 | asterisk type_qualifier_list_opt pointer { 1053 | asterisk type_qualifier_list_opt pointer {
1069 $$ = merge_qualified_pointer($1, $2); 1054 $$ = merge_qualified_pointer($1, $2);
1070 $$ = merge_qualified_pointer($$, $3); 1055 $$ = merge_qualified_pointer($$, $3);
1071 } 1056 }
1072 ; 1057 ;
1073 1058
1074asterisk: 1059asterisk:
1075 T_ASTERISK { 1060 T_ASTERISK {
1076 $$ = xcalloc(1, sizeof(*$$)); 1061 $$ = xcalloc(1, sizeof(*$$));
1077 $$->p_pointer = true; 1062 $$->p_pointer = true;
1078 } 1063 }
1079 ; 1064 ;
1080 1065
1081type_qualifier_list_opt: 1066type_qualifier_list_opt:
1082 /* empty */ { 1067 /* empty */ {
1083 $$ = NULL; 1068 $$ = NULL;
1084 } 1069 }
1085 | type_qualifier_list 1070 | type_qualifier_list
1086 ; 1071 ;
1087 1072
1088type_qualifier_list: /* C99 6.7.5 */ 1073type_qualifier_list: /* C99 6.7.5 */
1089 type_qualifier 1074 type_qualifier
1090 | type_qualifier_list type_qualifier { 1075 | type_qualifier_list type_qualifier {
1091 $$ = merge_qualified_pointer($1, $2); 1076 $$ = merge_qualified_pointer($1, $2);
1092 } 1077 }
1093 ; 1078 ;
1094 1079
1095type_qualifier: 1080type_qualifier:
1096 T_QUAL { 1081 T_QUAL {
1097 $$ = xcalloc(1, sizeof(*$$)); 1082 $$ = xcalloc(1, sizeof(*$$));
1098 if ($1 == CONST) { 1083 if ($1 == CONST) {
1099 $$->p_const = true; 1084 $$->p_const = true;
1100 } else if ($1 == VOLATILE) { 1085 } else if ($1 == VOLATILE) {
1101 $$->p_volatile = true; 1086 $$->p_volatile = true;
1102 } else { 1087 } else {
1103 lint_assert($1 == RESTRICT || $1 == THREAD); 1088 lint_assert($1 == RESTRICT || $1 == THREAD);
1104 } 1089 }
1105 } 1090 }
1106 ; 1091 ;
1107 1092
1108align_as: /* See alignment-specifier in C11 6.7.5 */ 1093align_as: /* See alignment-specifier in C11 6.7.5 */
1109 typespec 1094 typespec
1110 | constant_expr 1095 | constant_expr
1111 ; 1096 ;
1112 1097
1113param_list: 1098param_list:
1114 id_list_lparen identifier_list T_RPAREN { 1099 id_list_lparen identifier_list T_RPAREN {
1115 $$ = $2; 1100 $$ = $2;
1116 } 1101 }
1117 | abstract_decl_param_list 1102 | abstract_decl_param_list
1118 ; 1103 ;
1119 1104
1120id_list_lparen: 1105id_list_lparen:
1121 T_LPAREN { 1106 T_LPAREN {
1122 block_level++; 1107 block_level++;
1123 begin_declaration_level(PROTO_ARG); 1108 begin_declaration_level(PROTO_ARG);
1124 } 1109 }
1125 ; 1110 ;
1126 1111
1127identifier_list: 1112identifier_list:
1128 T_NAME { 1113 T_NAME {
1129 $$ = old_style_function_name(getsym($1)); 1114 $$ = old_style_function_name(getsym($1));
1130 } 1115 }
1131 | identifier_list T_COMMA T_NAME { 1116 | identifier_list T_COMMA T_NAME {
1132 $$ = lnklst($1, old_style_function_name(getsym($3))); 1117 $$ = lnklst($1, old_style_function_name(getsym($3)));
1133 } 1118 }
1134 | identifier_list error 1119 | identifier_list error
1135 ; 1120 ;
1136 1121
1137abstract_decl_param_list: 1122abstract_decl_param_list:
1138 abstract_decl_lparen T_RPAREN type_attribute_opt { 1123 abstract_decl_lparen T_RPAREN type_attribute_opt {
1139 $$ = NULL; 1124 $$ = NULL;
1140 } 1125 }
1141 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { 1126 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1142 dcs->d_proto = true; 1127 dcs->d_proto = true;
1143 $$ = $2; 1128 $$ = $2;
1144 } 1129 }
1145 | abstract_decl_lparen error T_RPAREN type_attribute_opt { 1130 | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1146 $$ = NULL; 1131 $$ = NULL;
1147 } 1132 }
1148 ; 1133 ;
1149 1134
1150abstract_decl_lparen: 1135abstract_decl_lparen:
1151 T_LPAREN { 1136 T_LPAREN {
1152 block_level++; 1137 block_level++;
1153 begin_declaration_level(PROTO_ARG); 1138 begin_declaration_level(PROTO_ARG);
1154 } 1139 }
1155 ; 1140 ;
1156 1141
1157vararg_parameter_type_list: 1142vararg_parameter_type_list:
1158 parameter_type_list 1143 parameter_type_list
1159 | parameter_type_list T_COMMA T_ELLIPSIS { 1144 | parameter_type_list T_COMMA T_ELLIPSIS {
1160 dcs->d_vararg = true; 1145 dcs->d_vararg = true;
1161 $$ = $1; 1146 $$ = $1;
1162 } 1147 }
1163 | T_ELLIPSIS { 1148 | T_ELLIPSIS {
1164 if (sflag) { 1149 if (sflag) {
1165 /* ANSI C requires formal parameter before '...' */ 1150 /* ANSI C requires formal parameter before '...' */
1166 error(84); 1151 error(84);
1167 } else if (!tflag) { 1152 } else if (!tflag) {
1168 /* ANSI C requires formal parameter before '...' */ 1153 /* ANSI C requires formal parameter before '...' */
1169 warning(84); 1154 warning(84);
1170 } 1155 }
1171 dcs->d_vararg = true; 1156 dcs->d_vararg = true;
1172 $$ = NULL; 1157 $$ = NULL;
1173 } 1158 }
1174 ; 1159 ;
1175 1160
1176parameter_type_list: 1161parameter_type_list:
1177 parameter_declaration 1162 parameter_declaration
1178 | parameter_type_list T_COMMA parameter_declaration { 1163 | parameter_type_list T_COMMA parameter_declaration {
1179 $$ = lnklst($1, $3); 1164 $$ = lnklst($1, $3);
1180 } 1165 }
1181 ; 1166 ;
1182 1167
1183/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ 1168/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1184parameter_declaration: 1169parameter_declaration:
1185 declmods deftyp { 1170 declmods deftyp {
1186 $$ = declare_argument(abstract_name(), false); 1171 $$ = declare_argument(abstract_name(), false);
1187 } 1172 }
1188 | declaration_specifiers deftyp { 1173 | declaration_specifiers deftyp {
1189 $$ = declare_argument(abstract_name(), false); 1174 $$ = declare_argument(abstract_name(), false);
1190 } 1175 }
1191 | declmods deftyp notype_param_decl { 1176 | declmods deftyp notype_param_decl {
1192 $$ = declare_argument($3, false); 1177 $$ = declare_argument($3, false);
1193 } 1178 }
1194 | declaration_specifiers deftyp type_param_decl { 1179 | declaration_specifiers deftyp type_param_decl {
1195 $$ = declare_argument($3, false); 1180 $$ = declare_argument($3, false);
1196 } 1181 }
1197 | declmods deftyp abstract_declarator { 1182 | declmods deftyp abstract_declarator {
1198 $$ = declare_argument($3, false); 1183 $$ = declare_argument($3, false);
1199 } 1184 }
1200 | declaration_specifiers deftyp abstract_declarator { 1185 | declaration_specifiers deftyp abstract_declarator {
1201 $$ = declare_argument($3, false); 1186 $$ = declare_argument($3, false);
1202 } 1187 }
1203 ; 1188 ;
1204 1189
1205asm_or_symbolrename_opt: /* expect only one */ 1190asm_or_symbolrename_opt: /* expect only one */
1206 /* empty */ { 1191 /* empty */ {
1207 $$ = NULL; 1192 $$ = NULL;
1208 } 1193 }
1209 | T_ASM T_LPAREN T_STRING T_RPAREN { 1194 | T_ASM T_LPAREN T_STRING T_RPAREN {
1210 freeyyv(&$3, T_STRING); 1195 freeyyv(&$3, T_STRING);
1211 $$ = NULL; 1196 $$ = NULL;
1212 } 1197 }
1213 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { 1198 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
1214 $$ = $3; 1199 $$ = $3;
1215 } 1200 }
1216 ; 1201 ;
1217 1202
1218initializer: /* C99 6.7.8 "Initialization" */ 1203initializer: /* C99 6.7.8 "Initialization" */
1219 expr %prec T_COMMA { 1204 expr %prec T_COMMA {
1220 init_expr($1); 1205 init_expr($1);
1221 } 1206 }
1222 | init_lbrace init_rbrace { 1207 | init_lbrace init_rbrace {
1223 /* XXX: Empty braces are not covered by C99 6.7.8. */ 1208 /* XXX: Empty braces are not covered by C99 6.7.8. */
1224 } 1209 }
1225 | init_lbrace initializer_list comma_opt init_rbrace 1210 | init_lbrace initializer_list comma_opt init_rbrace
1226 | error 1211 | error
1227 ; 1212 ;
1228 1213
1229initializer_list: /* C99 6.7.8 "Initialization" */ 1214initializer_list: /* C99 6.7.8 "Initialization" */
1230 initializer_list_item 1215 initializer_list_item
1231 | initializer_list T_COMMA initializer_list_item 1216 | initializer_list T_COMMA initializer_list_item
1232 ; 1217 ;
1233 1218
1234initializer_list_item: 1219initializer_list_item:
1235 designation initializer 1220 designation initializer
1236 | initializer 1221 | initializer
1237 ; 1222 ;
1238 1223
1239designation: /* C99 6.7.8 "Initialization" */ 1224designation: /* C99 6.7.8 "Initialization" */
1240 designator_list T_ASSIGN 1225 designator_list T_ASSIGN
1241 | identifier T_COLON { 1226 | identifier T_COLON {
1242 /* GCC style struct or union member name in initializer */ 1227 /* GCC style struct or union member name in initializer */
1243 gnuism(315); 1228 gnuism(315);
1244 add_designator_member($1); 1229 add_designator_member($1);
1245 } 1230 }
1246 ; 1231 ;
1247 1232
1248designator_list: /* C99 6.7.8 "Initialization" */ 1233designator_list: /* C99 6.7.8 "Initialization" */
1249 designator 1234 designator
1250 | designator_list designator 1235 | designator_list designator
1251 ; 1236 ;
1252 1237
1253designator: /* C99 6.7.8 "Initialization" */ 1238designator: /* C99 6.7.8 "Initialization" */
1254 T_LBRACK range T_RBRACK { 1239 T_LBRACK range T_RBRACK {
1255 add_designator_subscript($2); 1240 add_designator_subscript($2);
1256 if (!Sflag) 1241 if (!Sflag)
1257 /* array initializer with des.s is a C9X feature */ 1242 /* array initializer with des.s is a C9X feature */
1258 warning(321); 1243 warning(321);
1259 } 1244 }
1260 | T_POINT identifier { 1245 | T_POINT identifier {
1261 if (!Sflag) 1246 if (!Sflag)
1262 /* struct or union member name in initializer is ... */ 1247 /* struct or union member name in initializer is ... */
1263 warning(313); 1248 warning(313);
1264 add_designator_member($2); 1249 add_designator_member($2);
1265 } 1250 }
1266 ; 1251 ;
1267 1252
1268range: 1253range:
1269 constant_expr { 1254 constant_expr {
1270 $$.lo = to_int_constant($1, true); 1255 $$.lo = to_int_constant($1, true);
1271 $$.hi = $$.lo; 1256 $$.hi = $$.lo;
1272 } 1257 }
1273 | constant_expr T_ELLIPSIS constant_expr { 1258 | constant_expr T_ELLIPSIS constant_expr {
1274 $$.lo = to_int_constant($1, true); 1259 $$.lo = to_int_constant($1, true);
1275 $$.hi = to_int_constant($3, true); 1260 $$.hi = to_int_constant($3, true);
1276 /* initialization with '[a...b]' is a GCC extension */ 1261 /* initialization with '[a...b]' is a GCC extension */
1277 gnuism(340); 1262 gnuism(340);
1278 } 1263 }
1279 ; 1264 ;
1280 1265
1281init_lbrace: 1266init_lbrace:
1282 T_LBRACE { 1267 T_LBRACE {
1283 init_lbrace(); 1268 init_lbrace();
1284 } 1269 }
1285 ; 1270 ;
1286 1271
1287init_rbrace: 1272init_rbrace:
1288 T_RBRACE { 1273 T_RBRACE {
1289 init_rbrace(); 1274 init_rbrace();
1290 } 1275 }
1291 ; 1276 ;
1292 1277
1293type_name: /* C99 6.7.6 */ 1278type_name: /* C99 6.7.6 */
1294 { 1279 {
1295 begin_declaration_level(ABSTRACT); 1280 begin_declaration_level(ABSTRACT);
1296 } abstract_declaration { 1281 } abstract_declaration {
1297 end_declaration_level(); 1282 end_declaration_level();
1298 $$ = $2->s_type; 1283 $$ = $2->s_type;
1299 } 1284 }
1300 ; 1285 ;
1301 1286
1302abstract_declaration: 1287abstract_declaration:
1303 noclass_declmods deftyp { 1288 noclass_declmods deftyp {
1304 $$ = declare_1_abstract(abstract_name()); 1289 $$ = declare_1_abstract(abstract_name());
1305 } 1290 }
1306 | noclass_declspecs deftyp { 1291 | noclass_declspecs deftyp {
1307 $$ = declare_1_abstract(abstract_name()); 1292 $$ = declare_1_abstract(abstract_name());
1308 } 1293 }
1309 | noclass_declmods deftyp abstract_declarator { 1294 | noclass_declmods deftyp abstract_declarator {
1310 $$ = declare_1_abstract($3); 1295 $$ = declare_1_abstract($3);
1311 } 1296 }
1312 | noclass_declspecs deftyp abstract_declarator { 1297 | noclass_declspecs deftyp abstract_declarator {
1313 $$ = declare_1_abstract($3); 1298 $$ = declare_1_abstract($3);
1314 } 1299 }
1315 ; 1300 ;
1316 1301
1317abstract_declarator: /* C99 6.7.6 */ 1302abstract_declarator: /* C99 6.7.6 */
1318 pointer { 1303 pointer {
1319 $$ = add_pointer(abstract_name(), $1); 1304 $$ = add_pointer(abstract_name(), $1);
1320 } 1305 }
1321 | direct_abstract_declarator 1306 | direct_abstract_declarator
1322 | pointer direct_abstract_declarator { 1307 | pointer direct_abstract_declarator {
1323 $$ = add_pointer($2, $1); 1308 $$ = add_pointer($2, $1);
1324 } 1309 }
1325 | T_TYPEOF term { /* GCC extension */ 1310 | T_TYPEOF term { /* GCC extension */
1326 $$ = mktempsym($2->tn_type); 1311 $$ = mktempsym($2->tn_type);
1327 } 1312 }
1328 ; 1313 ;
1329 1314
1330/* 1315/*
1331 * XXX: shift/reduce conflict, caused by: 1316 * XXX: shift/reduce conflict, caused by:
1332 * type_attribute direct_abstract_declarator 1317 * type_attribute direct_abstract_declarator
1333 * direct_abstract_declarator type_attribute 1318 * direct_abstract_declarator type_attribute
1334 */ 1319 */
1335direct_abstract_declarator: /* C99 6.7.6 */ 1320direct_abstract_declarator: /* C99 6.7.6 */
1336 T_LPAREN abstract_declarator T_RPAREN { 1321 T_LPAREN abstract_declarator T_RPAREN {
1337 $$ = $2; 1322 $$ = $2;
1338 } 1323 }
1339 | T_LBRACK T_RBRACK { 1324 | T_LBRACK T_RBRACK {
1340 $$ = add_array(abstract_name(), false, 0); 1325 $$ = add_array(abstract_name(), false, 0);
1341 } 1326 }
1342 | T_LBRACK array_size T_RBRACK { 1327 | T_LBRACK array_size T_RBRACK {
1343 $$ = add_array(abstract_name(), true, to_int_constant($2, false)); 1328 $$ = add_array(abstract_name(), true, to_int_constant($2, false));
1344 } 1329 }
1345 | type_attribute direct_abstract_declarator { 1330 | type_attribute direct_abstract_declarator {
1346 $$ = $2; 1331 $$ = $2;
1347 } 1332 }
1348 | direct_abstract_declarator T_LBRACK T_RBRACK { 1333 | direct_abstract_declarator T_LBRACK T_RBRACK {
1349 $$ = add_array($1, false, 0); 1334 $$ = add_array($1, false, 0);
1350 } 1335 }
1351 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */ 1336 | direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
1352 $$ = add_array($1, false, 0); 1337 $$ = add_array($1, false, 0);
1353 } 1338 }
1354 | direct_abstract_declarator T_LBRACK array_size T_RBRACK { 1339 | direct_abstract_declarator T_LBRACK array_size T_RBRACK {
1355 $$ = add_array($1, true, to_int_constant($3, false)); 1340 $$ = add_array($1, true, to_int_constant($3, false));
1356 } 1341 }
1357 | abstract_decl_param_list asm_or_symbolrename_opt { 1342 | abstract_decl_param_list asm_or_symbolrename_opt {
1358 $$ = add_function(symbolrename(abstract_name(), $2), $1); 1343 $$ = add_function(symbolrename(abstract_name(), $2), $1);
1359 end_declaration_level(); 1344 end_declaration_level();
1360 block_level--; 1345 block_level--;
1361 } 1346 }
1362 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt { 1347 | direct_abstract_declarator abstract_decl_param_list asm_or_symbolrename_opt {
1363 $$ = add_function(symbolrename($1, $3), $2); 1348 $$ = add_function(symbolrename($1, $3), $2);
1364 end_declaration_level(); 1349 end_declaration_level();
1365 block_level--; 1350 block_level--;
1366 } 1351 }
1367 | direct_abstract_declarator type_attribute 1352 | direct_abstract_declarator type_attribute
1368 ; 1353 ;
1369 1354
1370array_size: 1355array_size:
1371 type_qualifier_list_opt T_SCLASS constant_expr { 1356 type_qualifier_list_opt T_SCLASS constant_expr {
1372 /* C11 6.7.6.3p7 */ 1357 /* C11 6.7.6.3p7 */
1373 if ($2 != STATIC) 1358 if ($2 != STATIC)
1374 yyerror("Bad attribute"); 1359 yyerror("Bad attribute");
1375 /* static array size is a C11 extension */ 1360 /* static array size is a C11 extension */
1376 c11ism(343); 1361 c11ism(343);
1377 $$ = $3; 1362 $$ = $3;
1378 } 1363 }
1379 | constant_expr 1364 | constant_expr
1380 ; 1365 ;
1381 1366
1382non_expr_statement: 1367non_expr_statement:
1383 type_attribute T_SEMI 1368 type_attribute T_SEMI
1384 | labeled_statement 1369 | labeled_statement
1385 | compound_statement 1370 | compound_statement
1386 | selection_statement 1371 | selection_statement
1387 | iteration_statement 1372 | iteration_statement
1388 | jump_statement { 1373 | jump_statement {
1389 seen_fallthrough = false; 1374 seen_fallthrough = false;
1390 } 1375 }
1391 | asm_statement 1376 | asm_statement
1392 ; 1377 ;
1393 1378
1394statement: /* C99 6.8 */ 1379statement: /* C99 6.8 */
1395 expression_statement 1380 expression_statement
1396 | non_expr_statement 1381 | non_expr_statement
1397 ; 1382 ;
1398 1383
1399labeled_statement: /* C99 6.8.1 */ 1384labeled_statement: /* C99 6.8.1 */
1400 label gcc_attribute_list_opt statement 1385 label gcc_attribute_list_opt statement
1401 ; 1386 ;
1402 1387
1403label: 1388label:
1404 T_NAME T_COLON { 1389 T_NAME T_COLON {
1405 symtyp = FLABEL; 1390 symtyp = FLABEL;
1406 named_label(getsym($1)); 1391 named_label(getsym($1));
1407 } 1392 }
1408 | T_CASE constant_expr T_COLON { 1393 | T_CASE constant_expr T_COLON {
1409 case_label($2); 1394 case_label($2);
1410 seen_fallthrough = true; 1395 seen_fallthrough = true;
1411 } 1396 }
1412 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON { 1397 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1413 /* XXX: We don't fill all cases */ 1398 /* XXX: We don't fill all cases */
1414 case_label($2); 1399 case_label($2);
1415 seen_fallthrough = true; 1400 seen_fallthrough = true;
1416 } 1401 }
1417 | T_DEFAULT T_COLON { 1402 | T_DEFAULT T_COLON {
1418 default_label(); 1403 default_label();
1419 seen_fallthrough = true; 1404 seen_fallthrough = true;
1420 } 1405 }
1421 ; 1406 ;
1422 1407
1423compound_statement: /* C99 6.8.2 */ 1408compound_statement: /* C99 6.8.2 */
1424 compound_statement_lbrace block_item_list_opt 1409 compound_statement_lbrace block_item_list_opt
1425 compound_statement_rbrace 1410 compound_statement_rbrace
1426 ; 1411 ;
1427 1412
1428compound_statement_lbrace: 1413compound_statement_lbrace:
1429 T_LBRACE { 1414 T_LBRACE {
1430 block_level++; 1415 block_level++;
1431 mem_block_level++; 1416 mem_block_level++;
1432 begin_declaration_level(AUTO); 1417 begin_declaration_level(AUTO);
1433 } 1418 }
1434 ; 1419 ;
1435 1420
1436compound_statement_rbrace: 1421compound_statement_rbrace:
1437 T_RBRACE { 1422 T_RBRACE {
1438 end_declaration_level(); 1423 end_declaration_level();
1439 freeblk(); 1424 freeblk();
1440 mem_block_level--; 1425 mem_block_level--;
1441 block_level--; 1426 block_level--;
1442 seen_fallthrough = false; 1427 seen_fallthrough = false;
1443 } 1428 }
1444 ; 1429 ;
1445 1430
1446block_item_list_opt: /* C99 6.8.2 */ 1431block_item_list_opt: /* C99 6.8.2 */
1447 /* empty */ 1432 /* empty */
1448 | block_item_list 1433 | block_item_list
1449 ; 1434 ;
1450 1435
1451block_item_list: 1436block_item_list:
1452 block_item 1437 block_item
1453 | block_item_list block_item { 1438 | block_item_list block_item {
1454 if (!Sflag && $1 && !$2) 1439 if (!Sflag && $1 && !$2)
1455 /* declarations after statements is a C99 feature */ 1440 /* declarations after statements is a C99 feature */
1456 c99ism(327); 1441 c99ism(327);
1457 $$ = $1 || $2; 1442 $$ = $1 || $2;
1458 } 1443 }
1459 ; 1444 ;
1460 1445
1461block_item: 1446block_item:
1462 statement { 1447 statement {
1463 $$ = true; 1448 $$ = true;
1464 restore_warning_flags(); 1449 restore_warning_flags();
1465 } 1450 }
1466 | declaration { 1451 | declaration {
1467 $$ = false; 1452 $$ = false;
1468 restore_warning_flags(); 1453 restore_warning_flags();
1469 } 1454 }
1470 ; 1455 ;
1471 1456
1472expression_statement: /* C99 6.8.3 */ 1457expression_statement: /* C99 6.8.3 */
1473 expr T_SEMI { 1458 expr T_SEMI {
1474 expr($1, false, false, false, false); 1459 expr($1, false, false, false, false);
1475 seen_fallthrough = false; 1460 seen_fallthrough = false;
1476 } 1461 }
1477 | T_SEMI { 1462 | T_SEMI {
1478 seen_fallthrough = false; 1463 seen_fallthrough = false;
1479 } 1464 }
1480 ; 1465 ;
1481 1466
1482selection_statement: /* C99 6.8.4 */ 1467selection_statement: /* C99 6.8.4 */
1483 if_without_else { 1468 if_without_else {
1484 save_warning_flags(); 1469 save_warning_flags();
1485 if2(); 1470 if2();
1486 if3(false); 1471 if3(false);
1487 } 1472 }
1488 | if_without_else T_ELSE { 1473 | if_without_else T_ELSE {
1489 save_warning_flags(); 1474 save_warning_flags();
1490 if2(); 1475 if2();
1491 } statement { 1476 } statement {
1492 clear_warning_flags(); 1477 clear_warning_flags();
1493 if3(true); 1478 if3(true);
1494 } 1479 }
1495 | if_without_else T_ELSE error { 1480 | if_without_else T_ELSE error {
1496 clear_warning_flags(); 1481 clear_warning_flags();
1497 if3(false); 1482 if3(false);
1498 } 1483 }
1499 | switch_expr statement { 1484 | switch_expr statement {
1500 clear_warning_flags(); 1485 clear_warning_flags();
1501 switch2(); 1486 switch2();
1502 } 1487 }
1503 | switch_expr error { 1488 | switch_expr error {
1504 clear_warning_flags(); 1489 clear_warning_flags();
1505 switch2(); 1490 switch2();
1506 } 1491 }
1507 ; 1492 ;
1508 1493
1509if_without_else: /* see C99 6.8.4 */ 1494if_without_else: /* see C99 6.8.4 */
1510 if_expr statement 1495 if_expr statement
1511 | if_expr error 1496 | if_expr error
1512 ; 1497 ;
1513 1498
1514if_expr: /* see C99 6.8.4 */ 1499if_expr: /* see C99 6.8.4 */
1515 T_IF T_LPAREN expr T_RPAREN { 1500 T_IF T_LPAREN expr T_RPAREN {
1516 if1($3); 1501 if1($3);
1517 clear_warning_flags(); 1502 clear_warning_flags();
1518 } 1503 }
1519 ; 1504 ;
1520 1505
1521switch_expr: /* see C99 6.8.4 */ 1506switch_expr: /* see C99 6.8.4 */
1522 T_SWITCH T_LPAREN expr T_RPAREN { 1507 T_SWITCH T_LPAREN expr T_RPAREN {
1523 switch1($3); 1508 switch1($3);
1524 clear_warning_flags(); 1509 clear_warning_flags();
1525 } 1510 }
1526 ; 1511 ;
1527 1512
1528do_statement: /* C99 6.8.5 */ 1513do_statement: /* C99 6.8.5 */
1529 do statement { 1514 do statement {
1530 clear_warning_flags(); 1515 clear_warning_flags();
1531 } 1516 }
1532 ; 1517 ;
1533 1518
1534iteration_statement: /* C99 6.8.5 */ 1519iteration_statement: /* C99 6.8.5 */
1535 while_expr statement { 1520 while_expr statement {
1536 clear_warning_flags(); 1521 clear_warning_flags();