Sat Jul 10 22:46:02 2021 UTC ()
lint: fix parsing of __attribute__ for member (since 2021-07-10)

Since cgram.y 1.280 from 2021-07-10, lint could not parse struct members
that have multiple __attribute__ in front of their type.


(rillig)
diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_struct_member.c
diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/decl_struct_member.exp
diff -r1.304 -r1.305 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/decl_struct_member.c (switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/07/10 22:34:02 1.4
+++ src/tests/usr.bin/xlint/lint1/decl_struct_member.c 2021/07/10 22:46:02 1.5
@@ -1,32 +1,31 @@ @@ -1,32 +1,31 @@
1/* $NetBSD: decl_struct_member.c,v 1.4 2021/07/10 22:34:02 rillig Exp $ */ 1/* $NetBSD: decl_struct_member.c,v 1.5 2021/07/10 22:46:02 rillig Exp $ */
2# 3 "decl_struct_member.c" 2# 3 "decl_struct_member.c"
3 3
4struct multi_attributes { 4struct multi_attributes {
5 __attribute__((deprecated)) 5 __attribute__((deprecated))
6 /* expect+1: error: syntax error '__attribute__' [249] */ 
7 __attribute__((deprecated)) 6 __attribute__((deprecated))
8 __attribute__((deprecated)) 7 __attribute__((deprecated))
9 int deprecated; 8 int deprecated;
10}; 9};
11 10
12/* 11/*
13 * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure: 12 * Before cgram.y 1.228 from 2021-06-19, lint ran into an assertion failure:
14 * 13 *
15 * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846 14 * "is_struct_or_union(dcs->d_type->t_tspec)" at cgram.y:846
16 */ 15 */
17struct { 16struct {
18 char; /* expect: syntax error 'unnamed member' */ 17 char; /* expect: syntax error 'unnamed member' */
19}; 18};
20 19
21/* 20/*
22 * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault. 21 * Before decl.c 1.188 from 2021-06-20, lint ran into a segmentation fault.
23 */ 22 */
24struct { 23struct {
25 char a(_)0 /* expect: syntax error '0' */ 24 char a(_)0 /* expect: syntax error '0' */
26} /* expect: ';' after last */ 25} /* expect: ';' after last */
27/* 26/*
28 * FIXME: adding a semicolon here triggers another assertion: 27 * FIXME: adding a semicolon here triggers another assertion:
29 * 28 *
30 * assertion "t == NOTSPEC" failed in end_type at decl.c:774 29 * assertion "t == NOTSPEC" failed in end_type at decl.c:774
31 */ 30 */
32/* expect+1: cannot recover from previous errors */ 31/* expect+1: cannot recover from previous errors */

cvs diff -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp (switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp 2021/07/10 22:34:02 1.3
+++ src/tests/usr.bin/xlint/lint1/Attic/decl_struct_member.exp 2021/07/10 22:46:02 1.4
@@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
1decl_struct_member.c(7): error: syntax error '__attribute__' [249] 1decl_struct_member.c(17): error: syntax error 'unnamed member' [249]
2decl_struct_member.c(18): error: syntax error 'unnamed member' [249] 2decl_struct_member.c(24): error: syntax error '0' [249]
3decl_struct_member.c(25): error: syntax error '0' [249] 3decl_struct_member.c(25): warning: syntax requires ';' after last struct/union member [66]
4decl_struct_member.c(26): warning: syntax requires ';' after last struct/union member [66] 4decl_struct_member.c(32): error: cannot recover from previous errors [224]
5decl_struct_member.c(33): error: cannot recover from previous errors [224] 

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/10 21:44:51 1.304
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 22:46:02 1.305
@@ -1,1717 +1,1717 @@ @@ -1,1717 +1,1717 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.304 2021/07/10 21:44:51 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.305 2021/07/10 22:46:02 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.304 2021/07/10 21:44:51 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.305 2021/07/10 22:46:02 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 136 127%expect 131
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 <y_op> T_UNARY 148%token <y_op> T_UNARY
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_COMMA 260%left T_COMMA
261%right T_ASSIGN T_OPASSIGN 261%right T_ASSIGN T_OPASSIGN
262%right T_QUEST T_COLON 262%right T_QUEST T_COLON
263%left T_LOGOR 263%left T_LOGOR
264%left T_LOGAND 264%left T_LOGAND
265%left T_BITOR 265%left T_BITOR
266%left T_BITXOR 266%left T_BITXOR
267%left T_AMPER 267%left T_AMPER
268%left T_EQUALITY 268%left T_EQUALITY
269%left T_RELATIONAL 269%left T_RELATIONAL
270%left T_SHIFT 270%left T_SHIFT
271%left T_ADDITIVE 271%left T_ADDITIVE
272%left T_ASTERISK T_MULTIPLICATIVE 272%left T_ASTERISK T_MULTIPLICATIVE
273%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG 273%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG
274%left T_LPAREN T_LBRACK T_POINT T_ARROW 274%left T_LPAREN T_LBRACK T_POINT T_ARROW
275 275
276%token <y_name> T_NAME 276%token <y_name> T_NAME
277%token <y_name> T_TYPENAME 277%token <y_name> T_TYPENAME
278%token <y_val> T_CON 278%token <y_val> T_CON
279%token <y_string> T_STRING 279%token <y_string> T_STRING
280 280
281%type <y_sym> func_decl 281%type <y_sym> func_decl
282%type <y_sym> notype_decl 282%type <y_sym> notype_decl
283%type <y_sym> type_decl 283%type <y_sym> type_decl
284%type <y_type> type_specifier 284%type <y_type> type_specifier
285%type <y_type> notype_type_specifier 285%type <y_type> notype_type_specifier
286%type <y_type> struct_or_union_specifier 286%type <y_type> struct_or_union_specifier
287%type <y_type> enum_specifier 287%type <y_type> enum_specifier
288%type <y_tspec> struct_or_union 288%type <y_tspec> struct_or_union
289%type <y_sym> identifier_sym_opt 289%type <y_sym> identifier_sym_opt
290%type <y_sym> identifier_sym 290%type <y_sym> identifier_sym
291%type <y_name> identifier 291%type <y_name> identifier
292%type <y_sym> struct_declaration_list_semi 292%type <y_sym> struct_declaration_list_semi
293%type <y_sym> struct_declaration_list 293%type <y_sym> struct_declaration_list
294%type <y_sym> struct_declaration 294%type <y_sym> struct_declaration
295%type <y_sym> notype_member_decls 295%type <y_sym> notype_member_decls
296%type <y_sym> type_member_decls 296%type <y_sym> type_member_decls
297%type <y_sym> notype_member_decl 297%type <y_sym> notype_member_decl
298%type <y_sym> type_member_decl 298%type <y_sym> type_member_decl
299%type <y_tnode> constant_expr 299%type <y_tnode> constant_expr
300%type <y_tnode> array_size 300%type <y_tnode> array_size
301%type <y_sym> enumerator_list 301%type <y_sym> enumerator_list
302%type <y_sym> enumerator 302%type <y_sym> enumerator
303%type <y_sym> notype_direct_decl 303%type <y_sym> notype_direct_decl
304%type <y_sym> type_direct_decl 304%type <y_sym> type_direct_decl
305%type <y_qual_ptr> pointer 305%type <y_qual_ptr> pointer
306%type <y_qual_ptr> asterisk 306%type <y_qual_ptr> asterisk
307%type <y_sym> type_param_decl 307%type <y_sym> type_param_decl
308%type <y_sym> param_list 308%type <y_sym> param_list
309%type <y_sym> abstract_decl_param_list 309%type <y_sym> abstract_decl_param_list
310%type <y_sym> direct_param_decl 310%type <y_sym> direct_param_decl
311%type <y_sym> notype_param_decl 311%type <y_sym> notype_param_decl
312%type <y_sym> direct_notype_param_decl 312%type <y_sym> direct_notype_param_decl
313%type <y_qual_ptr> type_qualifier_list_opt 313%type <y_qual_ptr> type_qualifier_list_opt
314%type <y_qual_ptr> type_qualifier_list 314%type <y_qual_ptr> type_qualifier_list
315%type <y_qual_ptr> type_qualifier 315%type <y_qual_ptr> type_qualifier
316%type <y_sym> identifier_list 316%type <y_sym> identifier_list
317%type <y_sym> abstract_declarator 317%type <y_sym> abstract_declarator
318%type <y_sym> direct_abstract_declarator 318%type <y_sym> direct_abstract_declarator
319%type <y_sym> direct_abstract_declarator_postfix 319%type <y_sym> direct_abstract_declarator_postfix
320%type <y_sym> vararg_parameter_type_list 320%type <y_sym> vararg_parameter_type_list
321%type <y_sym> parameter_type_list 321%type <y_sym> parameter_type_list
322%type <y_sym> parameter_declaration 322%type <y_sym> parameter_declaration
323%type <y_tnode> expr 323%type <y_tnode> expr
324%type <y_tnode> assignment_expression 324%type <y_tnode> assignment_expression
325%type <y_tnode> gcc_statement_expr_list 325%type <y_tnode> gcc_statement_expr_list
326%type <y_tnode> gcc_statement_expr_item 326%type <y_tnode> gcc_statement_expr_item
327%type <y_tnode> term 327%type <y_tnode> term
328%type <y_tnode> generic_selection 328%type <y_tnode> generic_selection
329%type <y_tnode> argument_expression_list 329%type <y_tnode> argument_expression_list
330%type <y_op> point_or_arrow 330%type <y_op> point_or_arrow
331%type <y_type> type_name 331%type <y_type> type_name
332%type <y_sym> abstract_declaration 332%type <y_sym> abstract_declaration
333%type <y_tnode> expr_opt 333%type <y_tnode> expr_opt
334%type <y_string> string 334%type <y_string> string
335%type <y_string> string2 335%type <y_string> string2
336%type <y_name> asm_or_symbolrename_opt 336%type <y_name> asm_or_symbolrename_opt
337%type <y_range> range 337%type <y_range> range
338%type <y_seen_statement> block_item_list 338%type <y_seen_statement> block_item_list
339%type <y_seen_statement> block_item 339%type <y_seen_statement> block_item
340%type <y_generic> generic_assoc_list 340%type <y_generic> generic_assoc_list
341%type <y_generic> generic_association 341%type <y_generic> generic_association
342 342
343%% 343%%
344 344
345program: 345program:
346 /* empty */ { 346 /* empty */ {
347 if (sflag) { 347 if (sflag) {
348 /* empty translation unit */ 348 /* empty translation unit */
349 error(272); 349 error(272);
350 } else if (!tflag) { 350 } else if (!tflag) {
351 /* empty translation unit */ 351 /* empty translation unit */
352 warning(272); 352 warning(272);
353 } 353 }
354 } 354 }
355 | translation_unit 355 | translation_unit
356 ; 356 ;
357 357
358translation_unit: /* C99 6.9 */ 358translation_unit: /* C99 6.9 */
359 external_declaration 359 external_declaration
360 | translation_unit external_declaration 360 | translation_unit external_declaration
361 ; 361 ;
362 362
363external_declaration: /* C99 6.9 */ 363external_declaration: /* C99 6.9 */
364 asm_statement 364 asm_statement
365 | function_definition { 365 | function_definition {
366 global_clean_up_decl(false); 366 global_clean_up_decl(false);
367 clear_warning_flags(); 367 clear_warning_flags();
368 } 368 }
369 | top_level_declaration { 369 | top_level_declaration {
370 global_clean_up_decl(false); 370 global_clean_up_decl(false);
371 clear_warning_flags(); 371 clear_warning_flags();
372 } 372 }
373 ; 373 ;
374 374
375/* 375/*
376 * On the top level, lint allows several forms of declarations that it doesn't 376 * On the top level, lint allows several forms of declarations that it doesn't
377 * allow in functions. For example, a single ';' is an empty declaration and 377 * allow in functions. For example, a single ';' is an empty declaration and
378 * is supported by some compilers, but in a function it would be an empty 378 * is supported by some compilers, but in a function it would be an empty
379 * statement, not a declaration. This makes a difference in C90 mode, where 379 * statement, not a declaration. This makes a difference in C90 mode, where
380 * a statement must not be followed by a declaration. 380 * a statement must not be followed by a declaration.
381 * 381 *
382 * See 'declaration' for all other declarations. 382 * See 'declaration' for all other declarations.
383 */ 383 */
384top_level_declaration: /* C99 6.9 calls this 'declaration' */ 384top_level_declaration: /* C99 6.9 calls this 'declaration' */
385 T_SEMI { 385 T_SEMI {
386 if (sflag) { 386 if (sflag) {
387 /* empty declaration */ 387 /* empty declaration */
388 error(0); 388 error(0);
389 } else if (!tflag) { 389 } else if (!tflag) {
390 /* empty declaration */ 390 /* empty declaration */
391 warning(0); 391 warning(0);
392 } 392 }
393 } 393 }
394 | begin_type end_type notype_init_decls T_SEMI { 394 | begin_type end_type notype_init_decls T_SEMI {
395 if (sflag) { 395 if (sflag) {
396 /* old style declaration; add 'int' */ 396 /* old style declaration; add 'int' */
397 error(1); 397 error(1);
398 } else if (!tflag) { 398 } else if (!tflag) {
399 /* old style declaration; add 'int' */ 399 /* old style declaration; add 'int' */
400 warning(1); 400 warning(1);
401 } 401 }
402 } 402 }
403 | declaration_noerror 403 | declaration_noerror
404 | error T_SEMI { 404 | error T_SEMI {
405 global_clean_up(); 405 global_clean_up();
406 } 406 }
407 | error T_RBRACE { 407 | error T_RBRACE {
408 global_clean_up(); 408 global_clean_up();
409 } 409 }
410 ; 410 ;
411 411
412function_definition: /* C99 6.9.1 */ 412function_definition: /* C99 6.9.1 */
413 func_decl { 413 func_decl {
414 if ($1->s_type->t_tspec != FUNC) { 414 if ($1->s_type->t_tspec != FUNC) {
415 /* syntax error '%s' */ 415 /* syntax error '%s' */
416 error(249, yytext); 416 error(249, yytext);
417 YYERROR; 417 YYERROR;
418 } 418 }
419 if ($1->s_type->t_typedef) { 419 if ($1->s_type->t_typedef) {
420 /* ()-less function definition */ 420 /* ()-less function definition */
421 error(64); 421 error(64);
422 YYERROR; 422 YYERROR;
423 } 423 }
424 funcdef($1); 424 funcdef($1);
425 block_level++; 425 block_level++;
426 begin_declaration_level(ARG); 426 begin_declaration_level(ARG);
427 if (lwarn == LWARN_NONE) 427 if (lwarn == LWARN_NONE)
428 $1->s_used = true; 428 $1->s_used = true;
429 } arg_declaration_list_opt { 429 } arg_declaration_list_opt {
430 end_declaration_level(); 430 end_declaration_level();
431 block_level--; 431 block_level--;
432 check_func_lint_directives(); 432 check_func_lint_directives();
433 check_func_old_style_arguments(); 433 check_func_old_style_arguments();
434 begin_control_statement(CS_FUNCTION_BODY); 434 begin_control_statement(CS_FUNCTION_BODY);
435 } compound_statement { 435 } compound_statement {
436 funcend(); 436 funcend();
437 end_control_statement(CS_FUNCTION_BODY); 437 end_control_statement(CS_FUNCTION_BODY);
438 } 438 }
439 ; 439 ;
440 440
441func_decl: 441func_decl:
442 begin_type end_type notype_decl { 442 begin_type end_type notype_decl {
443 $$ = $3; 443 $$ = $3;
444 } 444 }
445 | begin_type declmods end_type notype_decl { 445 | begin_type declmods end_type notype_decl {
446 $$ = $4; 446 $$ = $4;
447 } 447 }
448 | begin_type declaration_specifiers end_type type_decl { 448 | begin_type declaration_specifiers end_type type_decl {
449 $$ = $4; 449 $$ = $4;
450 } 450 }
451 ; 451 ;
452 452
453arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */ 453arg_declaration_list_opt: /* C99 6.9.1p13 example 1 */
454 /* empty */ 454 /* empty */
455 | arg_declaration_list 455 | arg_declaration_list
456 ; 456 ;
457 457
458arg_declaration_list: /* C99 6.9.1p13 example 1 */ 458arg_declaration_list: /* C99 6.9.1p13 example 1 */
459 arg_declaration 459 arg_declaration
460 | arg_declaration_list arg_declaration 460 | arg_declaration_list arg_declaration
461 /* XXX or better "arg_declaration error" ? */ 461 /* XXX or better "arg_declaration error" ? */
462 | error 462 | error
463 ; 463 ;
464 464
465/* 465/*
466 * "arg_declaration" is separated from "declaration" because it 466 * "arg_declaration" is separated from "declaration" because it
467 * needs other error handling. 467 * needs other error handling.
468 */ 468 */
469arg_declaration: 469arg_declaration:
470 begin_type declmods end_type T_SEMI { 470 begin_type declmods end_type T_SEMI {
471 /* empty declaration */ 471 /* empty declaration */
472 warning(2); 472 warning(2);
473 } 473 }
474 | begin_type declmods end_type notype_init_decls T_SEMI 474 | begin_type declmods end_type notype_init_decls T_SEMI
475 | begin_type declaration_specifiers end_type T_SEMI { 475 | begin_type declaration_specifiers end_type T_SEMI {
476 if (!dcs->d_nonempty_decl) { 476 if (!dcs->d_nonempty_decl) {
477 /* empty declaration */ 477 /* empty declaration */
478 warning(2); 478 warning(2);
479 } else { 479 } else {
480 /* '%s' declared in argument declaration list */ 480 /* '%s' declared in argument declaration list */
481 warning(3, type_name(dcs->d_type)); 481 warning(3, type_name(dcs->d_type));
482 } 482 }
483 } 483 }
484 | begin_type declaration_specifiers end_type type_init_decls T_SEMI { 484 | begin_type declaration_specifiers end_type type_init_decls T_SEMI {
485 if (dcs->d_nonempty_decl) { 485 if (dcs->d_nonempty_decl) {
486 /* '%s' declared in argument declaration list */ 486 /* '%s' declared in argument declaration list */
487 warning(3, type_name(dcs->d_type)); 487 warning(3, type_name(dcs->d_type));
488 } 488 }
489 } 489 }
490 | begin_type declmods error 490 | begin_type declmods error
491 | begin_type declaration_specifiers error 491 | begin_type declaration_specifiers error
492 ; 492 ;
493 493
494declaration: /* C99 6.7 */ 494declaration: /* C99 6.7 */
495 declaration_noerror 495 declaration_noerror
496 | error T_SEMI 496 | error T_SEMI
497 ; 497 ;
498 498
499declaration_noerror: /* see C99 6.7 'declaration' */ 499declaration_noerror: /* see C99 6.7 'declaration' */
500 begin_type declmods end_type T_SEMI { 500 begin_type declmods end_type T_SEMI {
501 if (dcs->d_scl == TYPEDEF) { 501 if (dcs->d_scl == TYPEDEF) {
502 /* typedef declares no type name */ 502 /* typedef declares no type name */
503 warning(72); 503 warning(72);
504 } else { 504 } else {
505 /* empty declaration */ 505 /* empty declaration */
506 warning(2); 506 warning(2);
507 } 507 }
508 } 508 }
509 | begin_type declmods end_type notype_init_decls T_SEMI 509 | begin_type declmods end_type notype_init_decls T_SEMI
510 | begin_type declaration_specifiers end_type T_SEMI { 510 | begin_type declaration_specifiers end_type T_SEMI {
511 if (dcs->d_scl == TYPEDEF) { 511 if (dcs->d_scl == TYPEDEF) {
512 /* typedef declares no type name */ 512 /* typedef declares no type name */
513 warning(72); 513 warning(72);
514 } else if (!dcs->d_nonempty_decl) { 514 } else if (!dcs->d_nonempty_decl) {
515 /* empty declaration */ 515 /* empty declaration */
516 warning(2); 516 warning(2);
517 } 517 }
518 } 518 }
519 | begin_type declaration_specifiers end_type type_init_decls T_SEMI 519 | begin_type declaration_specifiers end_type type_init_decls T_SEMI
520 ; 520 ;
521 521
522begin_type: 522begin_type:
523 /* empty */ { 523 /* empty */ {
524 begin_type(); 524 begin_type();
525 } 525 }
526 ; 526 ;
527 527
528end_type: 528end_type:
529 /* empty */ { 529 /* empty */ {
530 end_type(); 530 end_type();
531 } 531 }
532 ; 532 ;
533 533
534declaration_specifiers: /* C99 6.7 */ 534declaration_specifiers: /* C99 6.7 */
535 add_type_specifier 535 add_type_specifier
536 | declmods add_type_specifier 536 | declmods add_type_specifier
537 | type_attribute declaration_specifiers 537 | type_attribute declaration_specifiers
538 | declaration_specifiers add_storage_class 538 | declaration_specifiers add_storage_class
539 | declaration_specifiers add_notype_type_specifier 539 | declaration_specifiers add_notype_type_specifier
540 | declaration_specifiers add_type_qualifier 540 | declaration_specifiers add_type_qualifier
541 | declaration_specifiers type_attribute 541 | declaration_specifiers type_attribute
542 ; 542 ;
543 543
544declmods: 544declmods:
545 add_storage_class 545 add_storage_class
546 | add_type_qualifier 546 | add_type_qualifier
547 | declmods add_storage_class 547 | declmods add_storage_class
548 | declmods add_type_qualifier 548 | declmods add_type_qualifier
549 | declmods type_attribute 549 | declmods type_attribute
550 ; 550 ;
551 551
552add_storage_class: 552add_storage_class:
553 T_SCLASS { 553 T_SCLASS {
554 add_storage_class($1); 554 add_storage_class($1);
555 } 555 }
556 ; 556 ;
557 557
558add_type_specifier: 558add_type_specifier:
559 type_specifier { 559 type_specifier {
560 add_type($1); 560 add_type($1);
561 } 561 }
562 ; 562 ;
563 563
564type_attribute_list_opt: 564type_attribute_list_opt:
565 /* empty */ 565 /* empty */
566 | type_attribute_list 566 | type_attribute_list
567 ; 567 ;
568 568
569type_attribute_list: 569type_attribute_list:
570 type_attribute 570 type_attribute
571 | type_attribute_list type_attribute 571 | type_attribute_list type_attribute
572 ; 572 ;
573 573
574type_attribute_opt: 574type_attribute_opt:
575 /* empty */ 575 /* empty */
576 | type_attribute 576 | type_attribute
577 ; 577 ;
578 578
579type_attribute: /* See C11 6.7 declaration-specifiers */ 579type_attribute: /* See C11 6.7 declaration-specifiers */
580 gcc_attribute 580 gcc_attribute
581 | T_ALIGNAS T_LPAREN align_as T_RPAREN 581 | T_ALIGNAS T_LPAREN align_as T_RPAREN
582 | T_PACKED { 582 | T_PACKED {
583 addpacked(); 583 addpacked();
584 } 584 }
585 | T_NORETURN 585 | T_NORETURN
586 ; 586 ;
587 587
588type_specifier: /* C99 6.7.2 */ 588type_specifier: /* C99 6.7.2 */
589 notype_type_specifier 589 notype_type_specifier
590 | T_TYPENAME { 590 | T_TYPENAME {
591 $$ = getsym($1)->s_type; 591 $$ = getsym($1)->s_type;
592 } 592 }
593 ; 593 ;
594 594
595add_notype_type_specifier: 595add_notype_type_specifier:
596 notype_type_specifier { 596 notype_type_specifier {
597 add_type($1); 597 add_type($1);
598 } 598 }
599 ; 599 ;
600 600
601/* Like type_specifier, but without typedef-name. */ 601/* Like type_specifier, but without typedef-name. */
602notype_type_specifier: 602notype_type_specifier:
603 T_TYPE { 603 T_TYPE {
604 $$ = gettyp($1); 604 $$ = gettyp($1);
605 } 605 }
606 | T_TYPEOF term { 606 | T_TYPEOF term {
607 $$ = $2->tn_type; 607 $$ = $2->tn_type;
608 } 608 }
609 | struct_or_union_specifier { 609 | struct_or_union_specifier {
610 end_declaration_level(); 610 end_declaration_level();
611 $$ = $1; 611 $$ = $1;
612 } 612 }
613 | enum_specifier { 613 | enum_specifier {
614 end_declaration_level(); 614 end_declaration_level();
615 $$ = $1; 615 $$ = $1;
616 } 616 }
617 ; 617 ;
618 618
619struct_or_union_specifier: /* C99 6.7.2.1 */ 619struct_or_union_specifier: /* C99 6.7.2.1 */
620 struct_or_union identifier_sym { 620 struct_or_union identifier_sym {
621 /* 621 /*
622 * STDC requires that "struct a;" always introduces 622 * STDC requires that "struct a;" always introduces
623 * a new tag if "a" is not declared at current level 623 * a new tag if "a" is not declared at current level
624 * 624 *
625 * yychar is valid because otherwise the parser would not 625 * yychar is valid because otherwise the parser would not
626 * have been able to decide if it must shift or reduce 626 * have been able to decide if it must shift or reduce
627 */ 627 */
628 $$ = mktag($2, $1, false, yychar == T_SEMI); 628 $$ = mktag($2, $1, false, yychar == T_SEMI);
629 } 629 }
630 | struct_or_union identifier_sym_opt { 630 | struct_or_union identifier_sym_opt {
631 dcs->d_tagtyp = mktag($2, $1, true, false); 631 dcs->d_tagtyp = mktag($2, $1, true, false);
632 } T_LBRACE { 632 } T_LBRACE {
633 symtyp = FVFT; 633 symtyp = FVFT;
634 } struct_declaration_list_semi T_RBRACE { 634 } struct_declaration_list_semi T_RBRACE {
635 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $6); 635 $$ = complete_tag_struct_or_union(dcs->d_tagtyp, $6);
636 } 636 }
637 | struct_or_union error { 637 | struct_or_union error {
638 symtyp = FVFT; 638 symtyp = FVFT;
639 $$ = gettyp(INT); 639 $$ = gettyp(INT);
640 } 640 }
641 ; 641 ;
642 642
643struct_or_union: /* C99 6.7.2.1 */ 643struct_or_union: /* C99 6.7.2.1 */
644 T_STRUCT_OR_UNION { 644 T_STRUCT_OR_UNION {
645 symtyp = FTAG; 645 symtyp = FTAG;
646 begin_declaration_level($1 == STRUCT ? MOS : MOU); 646 begin_declaration_level($1 == STRUCT ? MOS : MOU);
647 dcs->d_offset = 0; 647 dcs->d_offset = 0;
648 dcs->d_sou_align_in_bits = CHAR_SIZE; 648 dcs->d_sou_align_in_bits = CHAR_SIZE;
649 } type_attribute_list_opt 649 } type_attribute_list_opt
650 ; 650 ;
651 651
652struct_declaration_list_semi: 652struct_declaration_list_semi:
653 /* empty */ { 653 /* empty */ {
654 $$ = NULL; 654 $$ = NULL;
655 } 655 }
656 | struct_declaration_list T_SEMI 656 | struct_declaration_list T_SEMI
657 | struct_declaration_list { 657 | struct_declaration_list {
658 if (sflag) { 658 if (sflag) {
659 /* syntax req. ';' after last struct/union member */ 659 /* syntax req. ';' after last struct/union member */
660 error(66); 660 error(66);
661 } else { 661 } else {
662 /* syntax req. ';' after last struct/union member */ 662 /* syntax req. ';' after last struct/union member */
663 warning(66); 663 warning(66);
664 } 664 }
665 $$ = $1; 665 $$ = $1;
666 } 666 }
667 ; 667 ;
668 668
669struct_declaration_list: 669struct_declaration_list:
670 struct_declaration 670 struct_declaration
671 | struct_declaration_list T_SEMI struct_declaration { 671 | struct_declaration_list T_SEMI struct_declaration {
672 $$ = lnklst($1, $3); 672 $$ = lnklst($1, $3);
673 } 673 }
674 ; 674 ;
675 675
676struct_declaration: 676struct_declaration:
677 begin_type add_type_qualifier_list end_type { 677 begin_type add_type_qualifier_list end_type {
678 /* too late, i know, but getsym() compensates it */ 678 /* too late, i know, but getsym() compensates it */
679 symtyp = FMEMBER; 679 symtyp = FMEMBER;
680 } notype_member_decls type_attribute_opt { 680 } notype_member_decls type_attribute_opt {
681 symtyp = FVFT; 681 symtyp = FVFT;
682 $$ = $5; 682 $$ = $5;
683 } 683 }
684 | begin_type noclass_declspecs end_type { 684 | begin_type noclass_declspecs end_type {
685 symtyp = FMEMBER; 685 symtyp = FMEMBER;
686 } type_member_decls type_attribute_opt { 686 } type_member_decls type_attribute_opt {
687 symtyp = FVFT; 687 symtyp = FVFT;
688 $$ = $5; 688 $$ = $5;
689 } 689 }
690 | begin_type add_type_qualifier_list end_type type_attribute_opt { 690 | begin_type add_type_qualifier_list end_type type_attribute_opt {
691 /* syntax error '%s' */ 691 /* syntax error '%s' */
692 error(249, "member without type"); 692 error(249, "member without type");
693 $$ = NULL; 693 $$ = NULL;
694 } 694 }
695 | begin_type noclass_declspecs end_type type_attribute_opt { 695 | begin_type noclass_declspecs end_type type_attribute_opt {
696 symtyp = FVFT; 696 symtyp = FVFT;
697 if (!Sflag) 697 if (!Sflag)
698 /* anonymous struct/union members is a C9X feature */ 698 /* anonymous struct/union members is a C9X feature */
699 warning(49); 699 warning(49);
700 if (is_struct_or_union(dcs->d_type->t_tspec)) { 700 if (is_struct_or_union(dcs->d_type->t_tspec)) {
701 $$ = dcs->d_type->t_str->sou_first_member; 701 $$ = dcs->d_type->t_str->sou_first_member;
702 /* add all the members of the anonymous struct/union */ 702 /* add all the members of the anonymous struct/union */
703 anonymize($$); 703 anonymize($$);
704 } else { 704 } else {
705 /* syntax error '%s' */ 705 /* syntax error '%s' */
706 error(249, "unnamed member"); 706 error(249, "unnamed member");
707 $$ = NULL; 707 $$ = NULL;
708 } 708 }
709 } 709 }
710 | error { 710 | error {
711 symtyp = FVFT; 711 symtyp = FVFT;
712 $$ = NULL; 712 $$ = NULL;
713 } 713 }
714 ; 714 ;
715 715
716noclass_declspecs: 716noclass_declspecs:
717 noclass_declspecs_postfix 717 noclass_declspecs_postfix
718 | type_attribute noclass_declspecs_postfix 718 | type_attribute noclass_declspecs
719 ; 719 ;
720 720
721noclass_declspecs_postfix: 721noclass_declspecs_postfix:
722 add_type_specifier 722 add_type_specifier
723 | add_type_qualifier_list add_type_specifier 723 | add_type_qualifier_list add_type_specifier
724 | noclass_declspecs_postfix add_type_qualifier 724 | noclass_declspecs_postfix add_type_qualifier
725 | noclass_declspecs_postfix add_notype_type_specifier 725 | noclass_declspecs_postfix add_notype_type_specifier
726 | noclass_declspecs_postfix type_attribute 726 | noclass_declspecs_postfix type_attribute
727 ; 727 ;
728 728
729add_type_qualifier_list: 729add_type_qualifier_list:
730 add_type_qualifier 730 add_type_qualifier
731 | add_type_qualifier_list add_type_qualifier 731 | add_type_qualifier_list add_type_qualifier
732 ; 732 ;
733 733
734add_type_qualifier: 734add_type_qualifier:
735 T_QUAL { 735 T_QUAL {
736 add_qualifier($1); 736 add_qualifier($1);
737 } 737 }
738 ; 738 ;
739 739
740notype_member_decls: 740notype_member_decls:
741 notype_member_decl { 741 notype_member_decl {
742 $$ = declarator_1_struct_union($1); 742 $$ = declarator_1_struct_union($1);
743 } 743 }
744 | notype_member_decls { 744 | notype_member_decls {
745 symtyp = FMEMBER; 745 symtyp = FMEMBER;
746 } T_COMMA type_member_decl { 746 } T_COMMA type_member_decl {
747 $$ = lnklst($1, declarator_1_struct_union($4)); 747 $$ = lnklst($1, declarator_1_struct_union($4));
748 } 748 }
749 ; 749 ;
750 750
751type_member_decls: 751type_member_decls:
752 type_member_decl { 752 type_member_decl {
753 $$ = declarator_1_struct_union($1); 753 $$ = declarator_1_struct_union($1);
754 } 754 }
755 | type_member_decls { 755 | type_member_decls {
756 symtyp = FMEMBER; 756 symtyp = FMEMBER;
757 } T_COMMA type_member_decl { 757 } T_COMMA type_member_decl {
758 $$ = lnklst($1, declarator_1_struct_union($4)); 758 $$ = lnklst($1, declarator_1_struct_union($4));
759 } 759 }
760 ; 760 ;
761 761
762notype_member_decl: 762notype_member_decl:
763 notype_decl 763 notype_decl
764 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */ 764 | notype_decl T_COLON constant_expr { /* C99 6.7.2.1 */
765 $$ = bitfield($1, to_int_constant($3, true)); 765 $$ = bitfield($1, to_int_constant($3, true));
766 } 766 }
767 | { 767 | {
768 symtyp = FVFT; 768 symtyp = FVFT;
769 } T_COLON constant_expr { /* C99 6.7.2.1 */ 769 } T_COLON constant_expr { /* C99 6.7.2.1 */
770 $$ = bitfield(NULL, to_int_constant($3, true)); 770 $$ = bitfield(NULL, to_int_constant($3, true));
771 } 771 }
772 ; 772 ;
773 773
774type_member_decl: 774type_member_decl:
775 type_decl 775 type_decl
776 | type_decl T_COLON constant_expr { 776 | type_decl T_COLON constant_expr {
777 $$ = bitfield($1, to_int_constant($3, true)); 777 $$ = bitfield($1, to_int_constant($3, true));
778 } 778 }
779 | { 779 | {
780 symtyp = FVFT; 780 symtyp = FVFT;
781 } T_COLON constant_expr { 781 } T_COLON constant_expr {
782 $$ = bitfield(NULL, to_int_constant($3, true)); 782 $$ = bitfield(NULL, to_int_constant($3, true));
783 } 783 }
784 ; 784 ;
785 785
786enum_specifier: /* C99 6.7.2.2 */ 786enum_specifier: /* C99 6.7.2.2 */
787 enum identifier_sym { 787 enum identifier_sym {
788 $$ = mktag($2, ENUM, false, false); 788 $$ = mktag($2, ENUM, false, false);
789 } 789 }
790 | enum identifier_sym_opt { 790 | enum identifier_sym_opt {
791 dcs->d_tagtyp = mktag($2, ENUM, true, false); 791 dcs->d_tagtyp = mktag($2, ENUM, true, false);
792 } T_LBRACE { 792 } T_LBRACE {
793 symtyp = FVFT; 793 symtyp = FVFT;
794 enumval = 0; 794 enumval = 0;
795 } enumerator_list enumerator_list_comma_opt T_RBRACE { 795 } enumerator_list enumerator_list_comma_opt T_RBRACE {
796 $$ = complete_tag_enum(dcs->d_tagtyp, $6); 796 $$ = complete_tag_enum(dcs->d_tagtyp, $6);
797 } 797 }
798 | enum error { 798 | enum error {
799 symtyp = FVFT; 799 symtyp = FVFT;
800 $$ = gettyp(INT); 800 $$ = gettyp(INT);
801 } 801 }
802 ; 802 ;
803 803
804enum: 804enum:
805 T_ENUM { 805 T_ENUM {
806 symtyp = FTAG; 806 symtyp = FTAG;
807 begin_declaration_level(CTCONST); 807 begin_declaration_level(CTCONST);
808 } 808 }
809 ; 809 ;
810 810
811enumerator_list: /* C99 6.7.2.2 */ 811enumerator_list: /* C99 6.7.2.2 */
812 enumerator 812 enumerator
813 | enumerator_list T_COMMA enumerator { 813 | enumerator_list T_COMMA enumerator {
814 $$ = lnklst($1, $3); 814 $$ = lnklst($1, $3);
815 } 815 }
816 | error { 816 | error {
817 $$ = NULL; 817 $$ = NULL;
818 } 818 }
819 ; 819 ;
820 820
821enumerator_list_comma_opt: 821enumerator_list_comma_opt:
822 /* empty */ 822 /* empty */
823 | T_COMMA { 823 | T_COMMA {
824 if (sflag) { 824 if (sflag) {
825 /* trailing ',' prohibited in enum declaration */ 825 /* trailing ',' prohibited in enum declaration */
826 error(54); 826 error(54);
827 } else { 827 } else {
828 /* trailing ',' prohibited in enum declaration */ 828 /* trailing ',' prohibited in enum declaration */
829 c99ism(54); 829 c99ism(54);
830 } 830 }
831 } 831 }
832 ; 832 ;
833 833
834enumerator: /* C99 6.7.2.2 */ 834enumerator: /* C99 6.7.2.2 */
835 identifier_sym { 835 identifier_sym {
836 $$ = enumeration_constant($1, enumval, true); 836 $$ = enumeration_constant($1, enumval, true);
837 } 837 }
838 | identifier_sym T_ASSIGN constant_expr { 838 | identifier_sym T_ASSIGN constant_expr {
839 $$ = enumeration_constant($1, to_int_constant($3, true), false); 839 $$ = enumeration_constant($1, to_int_constant($3, true), false);
840 } 840 }
841 ; 841 ;
842 842
843 843
844/* 844/*
845 * For an explanation of 'notype' in the following rules, see the Bison 845 * For an explanation of 'notype' in the following rules, see the Bison
846 * manual, section 7.1 "Semantic Info in Token Kinds". 846 * manual, section 7.1 "Semantic Info in Token Kinds".
847 */ 847 */
848 848
849notype_init_decls: 849notype_init_decls:
850 notype_init_decl 850 notype_init_decl
851 | notype_init_decls T_COMMA type_init_decl 851 | notype_init_decls T_COMMA type_init_decl
852 ; 852 ;
853 853
854type_init_decls: 854type_init_decls:
855 type_init_decl 855 type_init_decl
856 | type_init_decls T_COMMA type_init_decl 856 | type_init_decls T_COMMA type_init_decl
857 ; 857 ;
858 858
859notype_init_decl: 859notype_init_decl:
860 notype_decl asm_or_symbolrename_opt { 860 notype_decl asm_or_symbolrename_opt {
861 cgram_declare($1, false, $2); 861 cgram_declare($1, false, $2);
862 check_size($1); 862 check_size($1);
863 } 863 }
864 | notype_decl asm_or_symbolrename_opt { 864 | notype_decl asm_or_symbolrename_opt {
865 begin_initialization($1); 865 begin_initialization($1);
866 cgram_declare($1, true, $2); 866 cgram_declare($1, true, $2);
867 } T_ASSIGN initializer { 867 } T_ASSIGN initializer {
868 check_size($1); 868 check_size($1);
869 end_initialization(); 869 end_initialization();
870 } 870 }
871 ; 871 ;
872 872
873type_init_decl: 873type_init_decl:
874 type_decl asm_or_symbolrename_opt { 874 type_decl asm_or_symbolrename_opt {
875 cgram_declare($1, false, $2); 875 cgram_declare($1, false, $2);
876 check_size($1); 876 check_size($1);
877 } 877 }
878 | type_decl asm_or_symbolrename_opt { 878 | type_decl asm_or_symbolrename_opt {
879 begin_initialization($1); 879 begin_initialization($1);
880 cgram_declare($1, true, $2); 880 cgram_declare($1, true, $2);
881 } T_ASSIGN initializer { 881 } T_ASSIGN initializer {
882 check_size($1); 882 check_size($1);
883 end_initialization(); 883 end_initialization();
884 } 884 }
885 ; 885 ;
886 886
887notype_decl: 887notype_decl:
888 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */ 888 /* TODO: removing type_attribute_list_opt here removes another 18 conflicts */
889 type_attribute_list_opt notype_direct_decl { 889 type_attribute_list_opt notype_direct_decl {
890 $$ = $2; 890 $$ = $2;
891 } 891 }
892 | pointer type_attribute_list_opt notype_direct_decl { 892 | pointer type_attribute_list_opt notype_direct_decl {
893 $$ = add_pointer($3, $1); 893 $$ = add_pointer($3, $1);
894 } 894 }
895 ; 895 ;
896 896
897type_decl: 897type_decl:
898 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */ 898 /* TODO: removing type_attribute_list_opt here removes another 16 conflicts */
899 type_attribute_list_opt type_direct_decl { 899 type_attribute_list_opt type_direct_decl {
900 $$ = $2; 900 $$ = $2;
901 } 901 }
902 | pointer type_attribute_list_opt type_direct_decl { 902 | pointer type_attribute_list_opt type_direct_decl {
903 $$ = add_pointer($3, $1); 903 $$ = add_pointer($3, $1);
904 } 904 }
905 ; 905 ;
906 906
907notype_direct_decl: 907notype_direct_decl:
908 T_NAME { 908 T_NAME {
909 $$ = declarator_name(getsym($1)); 909 $$ = declarator_name(getsym($1));
910 } 910 }
911 | T_LPAREN type_decl T_RPAREN { 911 | T_LPAREN type_decl T_RPAREN {
912 $$ = $2; 912 $$ = $2;
913 } 913 }
914 | notype_direct_decl T_LBRACK T_RBRACK { 914 | notype_direct_decl T_LBRACK T_RBRACK {
915 $$ = add_array($1, false, 0); 915 $$ = add_array($1, false, 0);
916 } 916 }
917 | notype_direct_decl T_LBRACK array_size T_RBRACK { 917 | notype_direct_decl T_LBRACK array_size T_RBRACK {
918 $$ = add_array($1, true, to_int_constant($3, false)); 918 $$ = add_array($1, true, to_int_constant($3, false));
919 } 919 }
920 | notype_direct_decl param_list asm_or_symbolrename_opt { 920 | notype_direct_decl param_list asm_or_symbolrename_opt {
921 $$ = add_function(symbolrename($1, $3), $2); 921 $$ = add_function(symbolrename($1, $3), $2);
922 end_declaration_level(); 922 end_declaration_level();
923 block_level--; 923 block_level--;
924 } 924 }
925 | notype_direct_decl type_attribute 925 | notype_direct_decl type_attribute
926 ; 926 ;
927 927
928type_direct_decl: 928type_direct_decl:
929 identifier { 929 identifier {
930 $$ = declarator_name(getsym($1)); 930 $$ = declarator_name(getsym($1));
931 } 931 }
932 | T_LPAREN type_decl T_RPAREN { 932 | T_LPAREN type_decl T_RPAREN {
933 $$ = $2; 933 $$ = $2;
934 } 934 }
935 | type_direct_decl T_LBRACK T_RBRACK { 935 | type_direct_decl T_LBRACK T_RBRACK {
936 $$ = add_array($1, false, 0); 936 $$ = add_array($1, false, 0);
937 } 937 }
938 | type_direct_decl T_LBRACK array_size T_RBRACK { 938 | type_direct_decl T_LBRACK array_size T_RBRACK {
939 $$ = add_array($1, true, to_int_constant($3, false)); 939 $$ = add_array($1, true, to_int_constant($3, false));
940 } 940 }
941 | type_direct_decl param_list asm_or_symbolrename_opt { 941 | type_direct_decl param_list asm_or_symbolrename_opt {
942 $$ = add_function(symbolrename($1, $3), $2); 942 $$ = add_function(symbolrename($1, $3), $2);
943 end_declaration_level(); 943 end_declaration_level();
944 block_level--; 944 block_level--;
945 } 945 }
946 | type_direct_decl type_attribute 946 | type_direct_decl type_attribute
947 ; 947 ;
948 948
949/* 949/*
950 * The two distinct rules type_param_decl and notype_param_decl avoid a 950 * The two distinct rules type_param_decl and notype_param_decl avoid a
951 * conflict in argument lists. A typename enclosed in parentheses is always 951 * conflict in argument lists. A typename enclosed in parentheses is always
952 * treated as a typename, not an argument name. For example, after 952 * treated as a typename, not an argument name. For example, after
953 * "typedef double a;", the declaration "f(int (a));" is interpreted as 953 * "typedef double a;", the declaration "f(int (a));" is interpreted as
954 * "f(int (double));", not "f(int a);". 954 * "f(int (double));", not "f(int a);".
955 */ 955 */
956type_param_decl: 956type_param_decl:
957 direct_param_decl 957 direct_param_decl
958 | pointer direct_param_decl { 958 | pointer direct_param_decl {
959 $$ = add_pointer($2, $1); 959 $$ = add_pointer($2, $1);
960 } 960 }
961 ; 961 ;
962 962
963notype_param_decl: 963notype_param_decl:
964 direct_notype_param_decl 964 direct_notype_param_decl
965 | pointer direct_notype_param_decl { 965 | pointer direct_notype_param_decl {
966 $$ = add_pointer($2, $1); 966 $$ = add_pointer($2, $1);
967 } 967 }
968 ; 968 ;
969 969
970direct_param_decl: 970direct_param_decl:
971 identifier type_attribute_list_opt { 971 identifier type_attribute_list_opt {
972 $$ = declarator_name(getsym($1)); 972 $$ = declarator_name(getsym($1));
973 } 973 }
974 | T_LPAREN notype_param_decl T_RPAREN { 974 | T_LPAREN notype_param_decl T_RPAREN {
975 $$ = $2; 975 $$ = $2;
976 } 976 }
977 | direct_param_decl T_LBRACK T_RBRACK { 977 | direct_param_decl T_LBRACK T_RBRACK {
978 $$ = add_array($1, false, 0); 978 $$ = add_array($1, false, 0);
979 } 979 }
980 | direct_param_decl T_LBRACK array_size T_RBRACK { 980 | direct_param_decl T_LBRACK array_size T_RBRACK {
981 $$ = add_array($1, true, to_int_constant($3, false)); 981 $$ = add_array($1, true, to_int_constant($3, false));
982 } 982 }
983 | direct_param_decl param_list asm_or_symbolrename_opt { 983 | direct_param_decl param_list asm_or_symbolrename_opt {
984 $$ = add_function(symbolrename($1, $3), $2); 984 $$ = add_function(symbolrename($1, $3), $2);
985 end_declaration_level(); 985 end_declaration_level();
986 block_level--; 986 block_level--;
987 } 987 }
988 ; 988 ;
989 989
990direct_notype_param_decl: 990direct_notype_param_decl:
991 identifier /* XXX: missing type_attribute_list_opt? */ { 991 identifier /* XXX: missing type_attribute_list_opt? */ {
992 $$ = declarator_name(getsym($1)); 992 $$ = declarator_name(getsym($1));
993 } 993 }
994 | T_LPAREN notype_param_decl T_RPAREN { 994 | T_LPAREN notype_param_decl T_RPAREN {
995 $$ = $2; 995 $$ = $2;
996 } 996 }
997 | direct_notype_param_decl T_LBRACK T_RBRACK { 997 | direct_notype_param_decl T_LBRACK T_RBRACK {
998 $$ = add_array($1, false, 0); 998 $$ = add_array($1, false, 0);
999 } 999 }
1000 | direct_notype_param_decl T_LBRACK array_size T_RBRACK { 1000 | direct_notype_param_decl T_LBRACK array_size T_RBRACK {
1001 $$ = add_array($1, true, to_int_constant($3, false)); 1001 $$ = add_array($1, true, to_int_constant($3, false));
1002 } 1002 }
1003 | direct_notype_param_decl param_list asm_or_symbolrename_opt { 1003 | direct_notype_param_decl param_list asm_or_symbolrename_opt {
1004 $$ = add_function(symbolrename($1, $3), $2); 1004 $$ = add_function(symbolrename($1, $3), $2);
1005 end_declaration_level(); 1005 end_declaration_level();
1006 block_level--; 1006 block_level--;
1007 } 1007 }
1008 ; 1008 ;
1009 1009
1010pointer: /* C99 6.7.5 */ 1010pointer: /* C99 6.7.5 */
1011 asterisk type_qualifier_list_opt { 1011 asterisk type_qualifier_list_opt {
1012 $$ = merge_qualified_pointer($1, $2); 1012 $$ = merge_qualified_pointer($1, $2);
1013 } 1013 }
1014 | asterisk type_qualifier_list_opt pointer { 1014 | asterisk type_qualifier_list_opt pointer {
1015 $$ = merge_qualified_pointer($1, $2); 1015 $$ = merge_qualified_pointer($1, $2);
1016 $$ = merge_qualified_pointer($$, $3); 1016 $$ = merge_qualified_pointer($$, $3);
1017 } 1017 }
1018 ; 1018 ;
1019 1019
1020asterisk: 1020asterisk:
1021 T_ASTERISK { 1021 T_ASTERISK {
1022 $$ = xcalloc(1, sizeof(*$$)); 1022 $$ = xcalloc(1, sizeof(*$$));
1023 $$->p_pointer = true; 1023 $$->p_pointer = true;
1024 } 1024 }
1025 ; 1025 ;
1026 1026
1027type_qualifier_list_opt: 1027type_qualifier_list_opt:
1028 /* empty */ { 1028 /* empty */ {
1029 $$ = NULL; 1029 $$ = NULL;
1030 } 1030 }
1031 | type_qualifier_list 1031 | type_qualifier_list
1032 ; 1032 ;
1033 1033
1034type_qualifier_list: /* C99 6.7.5 */ 1034type_qualifier_list: /* C99 6.7.5 */
1035 type_qualifier 1035 type_qualifier
1036 | type_qualifier_list type_qualifier { 1036 | type_qualifier_list type_qualifier {
1037 $$ = merge_qualified_pointer($1, $2); 1037 $$ = merge_qualified_pointer($1, $2);
1038 } 1038 }
1039 ; 1039 ;
1040 1040
1041type_qualifier: 1041type_qualifier:
1042 T_QUAL { 1042 T_QUAL {
1043 $$ = xcalloc(1, sizeof(*$$)); 1043 $$ = xcalloc(1, sizeof(*$$));
1044 if ($1 == CONST) { 1044 if ($1 == CONST) {
1045 $$->p_const = true; 1045 $$->p_const = true;
1046 } else if ($1 == VOLATILE) { 1046 } else if ($1 == VOLATILE) {
1047 $$->p_volatile = true; 1047 $$->p_volatile = true;
1048 } else { 1048 } else {
1049 lint_assert($1 == RESTRICT || $1 == THREAD); 1049 lint_assert($1 == RESTRICT || $1 == THREAD);
1050 } 1050 }
1051 } 1051 }
1052 ; 1052 ;
1053 1053
1054align_as: /* See alignment-specifier in C11 6.7.5 */ 1054align_as: /* See alignment-specifier in C11 6.7.5 */
1055 type_specifier 1055 type_specifier
1056 | constant_expr 1056 | constant_expr
1057 ; 1057 ;
1058 1058
1059param_list: 1059param_list:
1060 id_list_lparen identifier_list T_RPAREN { 1060 id_list_lparen identifier_list T_RPAREN {
1061 $$ = $2; 1061 $$ = $2;
1062 } 1062 }
1063 | abstract_decl_param_list 1063 | abstract_decl_param_list
1064 ; 1064 ;
1065 1065
1066id_list_lparen: 1066id_list_lparen:
1067 T_LPAREN { 1067 T_LPAREN {
1068 block_level++; 1068 block_level++;
1069 begin_declaration_level(PROTO_ARG); 1069 begin_declaration_level(PROTO_ARG);
1070 } 1070 }
1071 ; 1071 ;
1072 1072
1073identifier_list: 1073identifier_list:
1074 T_NAME { 1074 T_NAME {
1075 $$ = old_style_function_name(getsym($1)); 1075 $$ = old_style_function_name(getsym($1));
1076 } 1076 }
1077 | identifier_list T_COMMA T_NAME { 1077 | identifier_list T_COMMA T_NAME {
1078 $$ = lnklst($1, old_style_function_name(getsym($3))); 1078 $$ = lnklst($1, old_style_function_name(getsym($3)));
1079 } 1079 }
1080 | identifier_list error 1080 | identifier_list error
1081 ; 1081 ;
1082 1082
1083abstract_decl_param_list: 1083abstract_decl_param_list:
1084 abstract_decl_lparen T_RPAREN type_attribute_opt { 1084 abstract_decl_lparen T_RPAREN type_attribute_opt {
1085 $$ = NULL; 1085 $$ = NULL;
1086 } 1086 }
1087 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt { 1087 | abstract_decl_lparen vararg_parameter_type_list T_RPAREN type_attribute_opt {
1088 dcs->d_proto = true; 1088 dcs->d_proto = true;
1089 $$ = $2; 1089 $$ = $2;
1090 } 1090 }
1091 | abstract_decl_lparen error T_RPAREN type_attribute_opt { 1091 | abstract_decl_lparen error T_RPAREN type_attribute_opt {
1092 $$ = NULL; 1092 $$ = NULL;
1093 } 1093 }
1094 ; 1094 ;
1095 1095
1096abstract_decl_lparen: 1096abstract_decl_lparen:
1097 T_LPAREN { 1097 T_LPAREN {
1098 block_level++; 1098 block_level++;
1099 begin_declaration_level(PROTO_ARG); 1099 begin_declaration_level(PROTO_ARG);
1100 } 1100 }
1101 ; 1101 ;
1102 1102
1103vararg_parameter_type_list: 1103vararg_parameter_type_list:
1104 parameter_type_list 1104 parameter_type_list
1105 | parameter_type_list T_COMMA T_ELLIPSIS { 1105 | parameter_type_list T_COMMA T_ELLIPSIS {
1106 dcs->d_vararg = true; 1106 dcs->d_vararg = true;
1107 $$ = $1; 1107 $$ = $1;
1108 } 1108 }
1109 | T_ELLIPSIS { 1109 | T_ELLIPSIS {
1110 if (sflag) { 1110 if (sflag) {
1111 /* ANSI C requires formal parameter before '...' */ 1111 /* ANSI C requires formal parameter before '...' */
1112 error(84); 1112 error(84);
1113 } else if (!tflag) { 1113 } else if (!tflag) {
1114 /* ANSI C requires formal parameter before '...' */ 1114 /* ANSI C requires formal parameter before '...' */
1115 warning(84); 1115 warning(84);
1116 } 1116 }
1117 dcs->d_vararg = true; 1117 dcs->d_vararg = true;
1118 $$ = NULL; 1118 $$ = NULL;
1119 } 1119 }
1120 ; 1120 ;
1121 1121
1122parameter_type_list: 1122parameter_type_list:
1123 parameter_declaration 1123 parameter_declaration
1124 | parameter_type_list T_COMMA parameter_declaration { 1124 | parameter_type_list T_COMMA parameter_declaration {
1125 $$ = lnklst($1, $3); 1125 $$ = lnklst($1, $3);
1126 } 1126 }
1127 ; 1127 ;
1128 1128
1129/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */ 1129/* XXX: C99 6.7.5 defines the same name, but it looks completely different. */
1130parameter_declaration: 1130parameter_declaration:
1131 begin_type declmods end_type { 1131 begin_type declmods end_type {
1132 $$ = declare_argument(abstract_name(), false); 1132 $$ = declare_argument(abstract_name(), false);
1133 } 1133 }
1134 | begin_type declaration_specifiers end_type { 1134 | begin_type declaration_specifiers end_type {
1135 $$ = declare_argument(abstract_name(), false); 1135 $$ = declare_argument(abstract_name(), false);
1136 } 1136 }
1137 | begin_type declmods end_type notype_param_decl { 1137 | begin_type declmods end_type notype_param_decl {
1138 $$ = declare_argument($4, false); 1138 $$ = declare_argument($4, false);
1139 } 1139 }
1140 | begin_type declaration_specifiers end_type type_param_decl { 1140 | begin_type declaration_specifiers end_type type_param_decl {
1141 $$ = declare_argument($4, false); 1141 $$ = declare_argument($4, false);
1142 } 1142 }
1143 | begin_type declmods end_type abstract_declarator { 1143 | begin_type declmods end_type abstract_declarator {
1144 $$ = declare_argument($4, false); 1144 $$ = declare_argument($4, false);
1145 } 1145 }
1146 | begin_type declaration_specifiers end_type abstract_declarator { 1146 | begin_type declaration_specifiers end_type abstract_declarator {
1147 $$ = declare_argument($4, false); 1147 $$ = declare_argument($4, false);
1148 } 1148 }
1149 ; 1149 ;
1150 1150
1151asm_or_symbolrename_opt: /* expect only one */ 1151asm_or_symbolrename_opt: /* expect only one */
1152 /* empty */ { 1152 /* empty */ {
1153 $$ = NULL; 1153 $$ = NULL;
1154 } 1154 }
1155 | T_ASM T_LPAREN T_STRING T_RPAREN { 1155 | T_ASM T_LPAREN T_STRING T_RPAREN {
1156 freeyyv(&$3, T_STRING); 1156 freeyyv(&$3, T_STRING);
1157 $$ = NULL; 1157 $$ = NULL;
1158 } 1158 }
1159 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN { 1159 | T_SYMBOLRENAME T_LPAREN T_NAME T_RPAREN {
1160 $$ = $3; 1160 $$ = $3;
1161 } 1161 }
1162 ; 1162 ;
1163 1163
1164initializer: /* C99 6.7.8 "Initialization" */ 1164initializer: /* C99 6.7.8 "Initialization" */
1165 expr %prec T_COMMA { 1165 expr %prec T_COMMA {
1166 init_expr($1); 1166 init_expr($1);
1167 } 1167 }
1168 | init_lbrace init_rbrace { 1168 | init_lbrace init_rbrace {
1169 /* XXX: Empty braces are not covered by C99 6.7.8. */ 1169 /* XXX: Empty braces are not covered by C99 6.7.8. */
1170 } 1170 }
1171 | init_lbrace initializer_list comma_opt init_rbrace 1171 | init_lbrace initializer_list comma_opt init_rbrace
1172 | error 1172 | error
1173 ; 1173 ;
1174 1174
1175initializer_list: /* C99 6.7.8 "Initialization" */ 1175initializer_list: /* C99 6.7.8 "Initialization" */
1176 initializer_list_item 1176 initializer_list_item
1177 | initializer_list T_COMMA initializer_list_item 1177 | initializer_list T_COMMA initializer_list_item
1178 ; 1178 ;
1179 1179
1180initializer_list_item: 1180initializer_list_item:
1181 designation initializer 1181 designation initializer
1182 | initializer 1182 | initializer
1183 ; 1183 ;
1184 1184
1185designation: /* C99 6.7.8 "Initialization" */ 1185designation: /* C99 6.7.8 "Initialization" */
1186 designator_list T_ASSIGN 1186 designator_list T_ASSIGN
1187 | identifier T_COLON { 1187 | identifier T_COLON {
1188 /* GCC style struct or union member name in initializer */ 1188 /* GCC style struct or union member name in initializer */
1189 gnuism(315); 1189 gnuism(315);
1190 add_designator_member($1); 1190 add_designator_member($1);
1191 } 1191 }
1192 ; 1192 ;
1193 1193
1194designator_list: /* C99 6.7.8 "Initialization" */ 1194designator_list: /* C99 6.7.8 "Initialization" */
1195 designator 1195 designator
1196 | designator_list designator 1196 | designator_list designator
1197 ; 1197 ;
1198 1198
1199designator: /* C99 6.7.8 "Initialization" */ 1199designator: /* C99 6.7.8 "Initialization" */
1200 T_LBRACK range T_RBRACK { 1200 T_LBRACK range T_RBRACK {
1201 add_designator_subscript($2); 1201 add_designator_subscript($2);
1202 if (!Sflag) 1202 if (!Sflag)
1203 /* array initializer with des.s is a C9X feature */ 1203 /* array initializer with des.s is a C9X feature */
1204 warning(321); 1204 warning(321);
1205 } 1205 }
1206 | T_POINT identifier { 1206 | T_POINT identifier {
1207 if (!Sflag) 1207 if (!Sflag)
1208 /* struct or union member name in initializer is ... */ 1208 /* struct or union member name in initializer is ... */
1209 warning(313); 1209 warning(313);
1210 add_designator_member($2); 1210 add_designator_member($2);
1211 } 1211 }
1212 ; 1212 ;
1213 1213
1214range: 1214range:
1215 constant_expr { 1215 constant_expr {
1216 $$.lo = to_int_constant($1, true); 1216 $$.lo = to_int_constant($1, true);
1217 $$.hi = $$.lo; 1217 $$.hi = $$.lo;
1218 } 1218 }
1219 | constant_expr T_ELLIPSIS constant_expr { 1219 | constant_expr T_ELLIPSIS constant_expr {
1220 $$.lo = to_int_constant($1, true); 1220 $$.lo = to_int_constant($1, true);
1221 $$.hi = to_int_constant($3, true); 1221 $$.hi = to_int_constant($3, true);
1222 /* initialization with '[a...b]' is a GCC extension */ 1222 /* initialization with '[a...b]' is a GCC extension */
1223 gnuism(340); 1223 gnuism(340);
1224 } 1224 }
1225 ; 1225 ;
1226 1226
1227init_lbrace: 1227init_lbrace:
1228 T_LBRACE { 1228 T_LBRACE {
1229 init_lbrace(); 1229 init_lbrace();
1230 } 1230 }
1231 ; 1231 ;
1232 1232
1233init_rbrace: 1233init_rbrace:
1234 T_RBRACE { 1234 T_RBRACE {
1235 init_rbrace(); 1235 init_rbrace();
1236 } 1236 }
1237 ; 1237 ;
1238 1238
1239type_name: /* C99 6.7.6 */ 1239type_name: /* C99 6.7.6 */
1240 { 1240 {
1241 begin_declaration_level(ABSTRACT); 1241 begin_declaration_level(ABSTRACT);
1242 } abstract_declaration { 1242 } abstract_declaration {
1243 end_declaration_level(); 1243 end_declaration_level();
1244 $$ = $2->s_type; 1244 $$ = $2->s_type;
1245 } 1245 }
1246 ; 1246 ;
1247 1247
1248abstract_declaration: 1248abstract_declaration:
1249 begin_type add_type_qualifier_list end_type { 1249 begin_type add_type_qualifier_list end_type {
1250 $$ = declare_1_abstract(abstract_name()); 1250 $$ = declare_1_abstract(abstract_name());
1251 } 1251 }
1252 | begin_type noclass_declspecs end_type { 1252 | begin_type noclass_declspecs end_type {
1253 $$ = declare_1_abstract(abstract_name()); 1253 $$ = declare_1_abstract(abstract_name());
1254 } 1254 }
1255 | begin_type add_type_qualifier_list end_type abstract_declarator { 1255 | begin_type add_type_qualifier_list end_type abstract_declarator {
1256 $$ = declare_1_abstract($4); 1256 $$ = declare_1_abstract($4);
1257 } 1257 }
1258 | begin_type noclass_declspecs end_type abstract_declarator { 1258 | begin_type noclass_declspecs end_type abstract_declarator {
1259 $$ = declare_1_abstract($4); 1259 $$ = declare_1_abstract($4);
1260 } 1260 }
1261 ; 1261 ;
1262 1262
1263abstract_declarator: /* C99 6.7.6 */ 1263abstract_declarator: /* C99 6.7.6 */
1264 pointer { 1264 pointer {
1265 $$ = add_pointer(abstract_name(), $1); 1265 $$ = add_pointer(abstract_name(), $1);
1266 } 1266 }
1267 | direct_abstract_declarator 1267 | direct_abstract_declarator
1268 | pointer direct_abstract_declarator { 1268 | pointer direct_abstract_declarator {
1269 $$ = add_pointer($2, $1); 1269 $$ = add_pointer($2, $1);
1270 } 1270 }
1271 | T_TYPEOF term { /* GCC extension */ 1271 | T_TYPEOF term { /* GCC extension */
1272 $$ = mktempsym($2->tn_type); 1272 $$ = mktempsym($2->tn_type);
1273 } 1273 }
1274 ; 1274 ;
1275 1275
1276direct_abstract_declarator: /* C99 6.7.6 */ 1276direct_abstract_declarator: /* C99 6.7.6 */
1277 direct_abstract_declarator_postfix 1277 direct_abstract_declarator_postfix
1278 | type_attribute direct_abstract_declarator_postfix { 1278 | type_attribute direct_abstract_declarator_postfix {
1279 $$ = $2; 1279 $$ = $2;
1280 } 1280 }
1281 ; 1281 ;
1282 1282
1283direct_abstract_declarator_postfix: /* C99 6.7.6 */ 1283direct_abstract_declarator_postfix: /* C99 6.7.6 */
1284 T_LPAREN abstract_declarator T_RPAREN { 1284 T_LPAREN abstract_declarator T_RPAREN {
1285 $$ = $2; 1285 $$ = $2;
1286 } 1286 }
1287 | T_LBRACK T_RBRACK { 1287 | T_LBRACK T_RBRACK {
1288 $$ = add_array(abstract_name(), false, 0); 1288 $$ = add_array(abstract_name(), false, 0);
1289 } 1289 }
1290 | T_LBRACK array_size T_RBRACK { 1290 | T_LBRACK array_size T_RBRACK {
1291 $$ = add_array(abstract_name(), true, to_int_constant($2, false)); 1291 $$ = add_array(abstract_name(), true, to_int_constant($2, false));
1292 } 1292 }
1293 | direct_abstract_declarator_postfix T_LBRACK T_RBRACK { 1293 | direct_abstract_declarator_postfix T_LBRACK T_RBRACK {
1294 $$ = add_array($1, false, 0); 1294 $$ = add_array($1, false, 0);
1295 } 1295 }
1296 | direct_abstract_declarator_postfix 1296 | direct_abstract_declarator_postfix
1297 T_LBRACK T_ASTERISK T_RBRACK { /* C99 */ 1297 T_LBRACK T_ASTERISK T_RBRACK { /* C99 */
1298 $$ = add_array($1, false, 0); 1298 $$ = add_array($1, false, 0);
1299 } 1299 }
1300 | direct_abstract_declarator_postfix T_LBRACK array_size T_RBRACK { 1300 | direct_abstract_declarator_postfix T_LBRACK array_size T_RBRACK {
1301 $$ = add_array($1, true, to_int_constant($3, false)); 1301 $$ = add_array($1, true, to_int_constant($3, false));
1302 } 1302 }
1303 | abstract_decl_param_list asm_or_symbolrename_opt { 1303 | abstract_decl_param_list asm_or_symbolrename_opt {
1304 $$ = add_function(symbolrename(abstract_name(), $2), $1); 1304 $$ = add_function(symbolrename(abstract_name(), $2), $1);
1305 end_declaration_level(); 1305 end_declaration_level();
1306 block_level--; 1306 block_level--;
1307 } 1307 }
1308 | direct_abstract_declarator_postfix abstract_decl_param_list 1308 | direct_abstract_declarator_postfix abstract_decl_param_list
1309 asm_or_symbolrename_opt { 1309 asm_or_symbolrename_opt {
1310 $$ = add_function(symbolrename($1, $3), $2); 1310 $$ = add_function(symbolrename($1, $3), $2);
1311 end_declaration_level(); 1311 end_declaration_level();
1312 block_level--; 1312 block_level--;
1313 } 1313 }
1314 | direct_abstract_declarator_postfix type_attribute 1314 | direct_abstract_declarator_postfix type_attribute
1315 ; 1315 ;
1316 1316
1317array_size: 1317array_size:
1318 type_qualifier_list_opt T_SCLASS constant_expr { 1318 type_qualifier_list_opt T_SCLASS constant_expr {
1319 /* C11 6.7.6.3p7 */ 1319 /* C11 6.7.6.3p7 */
1320 if ($2 != STATIC) 1320 if ($2 != STATIC)
1321 yyerror("Bad attribute"); 1321 yyerror("Bad attribute");
1322 /* static array size is a C11 extension */ 1322 /* static array size is a C11 extension */
1323 c11ism(343); 1323 c11ism(343);
1324 $$ = $3; 1324 $$ = $3;
1325 } 1325 }
1326 | constant_expr 1326 | constant_expr
1327 ; 1327 ;
1328 1328
1329non_expr_statement: 1329non_expr_statement:
1330 gcc_attribute T_SEMI 1330 gcc_attribute T_SEMI
1331 | labeled_statement 1331 | labeled_statement
1332 | compound_statement 1332 | compound_statement
1333 | selection_statement 1333 | selection_statement
1334 | iteration_statement 1334 | iteration_statement
1335 | jump_statement { 1335 | jump_statement {
1336 seen_fallthrough = false; 1336 seen_fallthrough = false;
1337 } 1337 }
1338 | asm_statement 1338 | asm_statement
1339 ; 1339 ;
1340 1340
1341statement: /* C99 6.8 */ 1341statement: /* C99 6.8 */
1342 expression_statement 1342 expression_statement
1343 | non_expr_statement 1343 | non_expr_statement
1344 ; 1344 ;
1345 1345
1346labeled_statement: /* C99 6.8.1 */ 1346labeled_statement: /* C99 6.8.1 */
1347 label gcc_attribute_list_opt statement 1347 label gcc_attribute_list_opt statement
1348 ; 1348 ;
1349 1349
1350label: 1350label:
1351 T_NAME T_COLON { 1351 T_NAME T_COLON {
1352 symtyp = FLABEL; 1352 symtyp = FLABEL;
1353 named_label(getsym($1)); 1353 named_label(getsym($1));
1354 } 1354 }
1355 | T_CASE constant_expr T_COLON { 1355 | T_CASE constant_expr T_COLON {
1356 case_label($2); 1356 case_label($2);
1357 seen_fallthrough = true; 1357 seen_fallthrough = true;
1358 } 1358 }
1359 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON { 1359 | T_CASE constant_expr T_ELLIPSIS constant_expr T_COLON {
1360 /* XXX: We don't fill all cases */ 1360 /* XXX: We don't fill all cases */
1361 case_label($2); 1361 case_label($2);
1362 seen_fallthrough = true; 1362 seen_fallthrough = true;
1363 } 1363 }
1364 | T_DEFAULT T_COLON { 1364 | T_DEFAULT T_COLON {
1365 default_label(); 1365 default_label();
1366 seen_fallthrough = true; 1366 seen_fallthrough = true;
1367 } 1367 }
1368 ; 1368 ;
1369 1369
1370compound_statement: /* C99 6.8.2 */ 1370compound_statement: /* C99 6.8.2 */
1371 compound_statement_lbrace block_item_list_opt 1371 compound_statement_lbrace block_item_list_opt
1372 compound_statement_rbrace 1372 compound_statement_rbrace
1373 ; 1373 ;
1374 1374
1375compound_statement_lbrace: 1375compound_statement_lbrace:
1376 T_LBRACE { 1376 T_LBRACE {
1377 block_level++; 1377 block_level++;
1378 mem_block_level++; 1378 mem_block_level++;
1379 begin_declaration_level(AUTO); 1379 begin_declaration_level(AUTO);
1380 } 1380 }
1381 ; 1381 ;
1382 1382
1383compound_statement_rbrace: 1383compound_statement_rbrace:
1384 T_RBRACE { 1384 T_RBRACE {
1385 end_declaration_level(); 1385 end_declaration_level();
1386 freeblk(); 1386 freeblk();
1387 mem_block_level--; 1387 mem_block_level--;
1388 block_level--; 1388 block_level--;
1389 seen_fallthrough = false; 1389 seen_fallthrough = false;
1390 } 1390 }
1391 ; 1391 ;
1392 1392
1393block_item_list_opt: /* C99 6.8.2 */ 1393block_item_list_opt: /* C99 6.8.2 */
1394 /* empty */ 1394 /* empty */
1395 | block_item_list 1395 | block_item_list
1396 ; 1396 ;
1397 1397
1398block_item_list: /* C99 6.8.2 */ 1398block_item_list: /* C99 6.8.2 */
1399 block_item 1399 block_item
1400 | block_item_list block_item { 1400 | block_item_list block_item {
1401 if (!Sflag && $1 && !$2) 1401 if (!Sflag && $1 && !$2)
1402 /* declarations after statements is a C99 feature */ 1402 /* declarations after statements is a C99 feature */
1403 c99ism(327); 1403 c99ism(327);
1404 $$ = $1 || $2; 1404 $$ = $1 || $2;
1405 } 1405 }
1406 ; 1406 ;
1407 1407
1408block_item: /* C99 6.8.2 */ 1408block_item: /* C99 6.8.2 */
1409 declaration { 1409 declaration {
1410 $$ = false; 1410 $$ = false;
1411 restore_warning_flags(); 1411 restore_warning_flags();
1412 } 1412 }
1413 | statement { 1413 | statement {
1414 $$ = true; 1414 $$ = true;
1415 restore_warning_flags(); 1415 restore_warning_flags();
1416 } 1416 }
1417 ; 1417 ;
1418 1418
1419expression_statement: /* C99 6.8.3 */ 1419expression_statement: /* C99 6.8.3 */
1420 expr T_SEMI { 1420 expr T_SEMI {
1421 expr($1, false, false, false, false); 1421 expr($1, false, false, false, false);
1422 seen_fallthrough = false; 1422 seen_fallthrough = false;
1423 } 1423 }
1424 | T_SEMI { 1424 | T_SEMI {
1425 seen_fallthrough = false; 1425 seen_fallthrough = false;
1426 } 1426 }
1427 ; 1427 ;
1428 1428
1429selection_statement: /* C99 6.8.4 */ 1429selection_statement: /* C99 6.8.4 */
1430 if_without_else { 1430 if_without_else {
1431 save_warning_flags(); 1431 save_warning_flags();
1432 if2(); 1432 if2();
1433 if3(false); 1433 if3(false);
1434 } 1434 }
1435 | if_without_else T_ELSE { 1435 | if_without_else T_ELSE {
1436 save_warning_flags(); 1436 save_warning_flags();
1437 if2(); 1437 if2();
1438 } statement { 1438 } statement {
1439 clear_warning_flags(); 1439 clear_warning_flags();
1440 if3(true); 1440 if3(true);
1441 } 1441 }
1442 | if_without_else T_ELSE error { 1442 | if_without_else T_ELSE error {
1443 clear_warning_flags(); 1443 clear_warning_flags();
1444 if3(false); 1444 if3(false);
1445 } 1445 }
1446 | switch_expr statement { 1446 | switch_expr statement {
1447 clear_warning_flags(); 1447 clear_warning_flags();
1448 switch2(); 1448 switch2();
1449 } 1449 }
1450 | switch_expr error { 1450 | switch_expr error {
1451 clear_warning_flags(); 1451 clear_warning_flags();
1452 switch2(); 1452 switch2();
1453 } 1453 }
1454 ; 1454 ;
1455 1455
1456if_without_else: /* see C99 6.8.4 */ 1456if_without_else: /* see C99 6.8.4 */
1457 if_expr statement 1457 if_expr statement
1458 | if_expr error 1458 | if_expr error
1459 ; 1459 ;
1460 1460
1461if_expr: /* see C99 6.8.4 */ 1461if_expr: /* see C99 6.8.4 */
1462 T_IF T_LPAREN expr T_RPAREN { 1462 T_IF T_LPAREN expr T_RPAREN {
1463 if1($3); 1463 if1($3);
1464 clear_warning_flags(); 1464 clear_warning_flags();
1465 } 1465 }
1466 ; 1466 ;
1467 1467
1468switch_expr: /* see C99 6.8.4 */ 1468switch_expr: /* see C99 6.8.4 */
1469 T_SWITCH T_LPAREN expr T_RPAREN { 1469 T_SWITCH T_LPAREN expr T_RPAREN {
1470 switch1($3); 1470 switch1($3);
1471 clear_warning_flags(); 1471 clear_warning_flags();
1472 } 1472 }
1473 ; 1473 ;
1474 1474
1475iteration_statement: /* C99 6.8.5 */ 1475iteration_statement: /* C99 6.8.5 */
1476 T_WHILE T_LPAREN expr T_RPAREN { 1476 T_WHILE T_LPAREN expr T_RPAREN {
1477 while1($3); 1477 while1($3);
1478 clear_warning_flags(); 1478 clear_warning_flags();
1479 } iteration_body { 1479 } iteration_body {
1480 clear_warning_flags(); 1480 clear_warning_flags();
1481 while2(); 1481 while2();
1482 } 1482 }
1483 | do statement { 1483 | do statement {
1484 clear_warning_flags(); 1484 clear_warning_flags();
1485 } T_WHILE T_LPAREN expr T_RPAREN T_SEMI { 1485 } T_WHILE T_LPAREN expr T_RPAREN T_SEMI {
1486 do2($6); 1486 do2($6);
1487 seen_fallthrough = false; 1487 seen_fallthrough = false;
1488 } 1488 }
1489 | do error { 1489 | do error {
1490 clear_warning_flags(); 1490 clear_warning_flags();
1491 do2(NULL); 1491 do2(NULL);
1492 } 1492 }
1493 | for_exprs iteration_body { 1493 | for_exprs iteration_body {
1494 clear_warning_flags(); 1494 clear_warning_flags();
1495 for2(); 1495 for2();
1496 end_declaration_level(); 1496 end_declaration_level();
1497 block_level--; 1497 block_level--;
1498 } 1498 }
1499 ; 1499 ;
1500 1500
1501iteration_body: 1501iteration_body:
1502 statement 1502 statement
1503 | error 1503 | error
1504 ; 1504 ;
1505 1505
1506do: /* see C99 6.8.5 */ 1506do: /* see C99 6.8.5 */
1507 T_DO { 1507 T_DO {
1508 do1(); 1508 do1();
1509 } 1509 }
1510 ; 1510 ;
1511 1511
1512for_start: /* see C99 6.8.5 */ 1512for_start: /* see C99 6.8.5 */
1513 T_FOR T_LPAREN { 1513 T_FOR T_LPAREN {
1514 begin_declaration_level(AUTO); 1514 begin_declaration_level(AUTO);
1515 block_level++; 1515 block_level++;
1516 } 1516 }
1517 ; 1517 ;
1518 1518
1519for_exprs: /* see C99 6.8.5 */ 1519for_exprs: /* see C99 6.8.5 */
1520 for_start 1520 for_start
1521 begin_type declaration_specifiers end_type notype_init_decls T_SEMI 1521 begin_type declaration_specifiers end_type notype_init_decls T_SEMI
1522 expr_opt T_SEMI 1522 expr_opt T_SEMI
1523 expr_opt T_RPAREN { 1523 expr_opt T_RPAREN {
1524 /* variable declaration in for loop */ 1524 /* variable declaration in for loop */
1525 c99ism(325); 1525 c99ism(325);
1526 for1(NULL, $7, $9); 1526 for1(NULL, $7, $9);
1527 clear_warning_flags(); 1527 clear_warning_flags();
1528 } 1528 }
1529 | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN { 1529 | for_start expr_opt T_SEMI expr_opt T_SEMI expr_opt T_RPAREN {
1530 for1($2, $4, $6); 1530 for1($2, $4, $6);
1531 clear_warning_flags(); 1531 clear_warning_flags();
1532 } 1532 }
1533 ; 1533 ;
1534 1534
1535jump_statement: /* C99 6.8.6 */ 1535jump_statement: /* C99 6.8.6 */
1536 goto identifier T_SEMI { 1536 goto identifier T_SEMI {
1537 do_goto(getsym($2)); 1537 do_goto(getsym($2));
1538 } 1538 }
1539 | goto error T_SEMI { 1539 | goto error T_SEMI {
1540 symtyp = FVFT; 1540 symtyp = FVFT;
1541 } 1541 }
1542 | T_CONTINUE T_SEMI { 1542 | T_CONTINUE T_SEMI {
1543 do_continue(); 1543 do_continue();
1544 } 1544 }
1545 | T_BREAK T_SEMI { 1545 | T_BREAK T_SEMI {
1546 do_break(); 1546 do_break();
1547 } 1547 }
1548 | T_RETURN T_SEMI { 1548 | T_RETURN T_SEMI {
1549 do_return(NULL); 1549 do_return(NULL);
1550 } 1550 }
1551 | T_RETURN expr T_SEMI { 1551 | T_RETURN expr T_SEMI {
1552 do_return($2); 1552 do_return($2);
1553 } 1553 }
1554 ; 1554 ;
1555 1555
1556goto: 1556goto:
1557 T_GOTO { 1557 T_GOTO {
1558 symtyp = FLABEL; 1558 symtyp = FLABEL;
1559 } 1559 }
1560 ; 1560 ;
1561 1561
1562asm_statement: 1562asm_statement:
1563 T_ASM T_LPAREN read_until_rparen T_SEMI { 1563 T_ASM T_LPAREN read_until_rparen T_SEMI {
1564 setasm(); 1564 setasm();
1565 } 1565 }
1566 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI { 1566 | T_ASM T_QUAL T_LPAREN read_until_rparen T_SEMI {
1567 setasm(); 1567 setasm();
1568 } 1568 }
1569 | T_ASM error 1569 | T_ASM error
1570 ; 1570 ;
1571 1571
1572read_until_rparen: 1572read_until_rparen:
1573 /* empty */ { 1573 /* empty */ {
1574 ignore_up_to_rparen(); 1574 ignore_up_to_rparen();
1575 } 1575 }
1576 ; 1576 ;
1577 1577
1578constant_expr_list_opt: 1578constant_expr_list_opt:
1579 /* empty */ 1579 /* empty */
1580 | constant_expr_list 1580 | constant_expr_list
1581 ; 1581 ;
1582 1582
1583constant_expr_list: 1583constant_expr_list:
1584 constant_expr 1584 constant_expr
1585 | constant_expr_list T_COMMA constant_expr 1585 | constant_expr_list T_COMMA constant_expr
1586 ; 1586 ;
1587 1587
1588constant_expr: /* C99 6.6 */ 1588constant_expr: /* C99 6.6 */
1589 expr %prec T_ASSIGN 1589 expr %prec T_ASSIGN
1590 ; 1590 ;
1591 1591
1592expr_opt: 1592expr_opt:
1593 /* empty */ { 1593 /* empty */ {
1594 $$ = NULL; 1594 $$ = NULL;
1595 } 1595 }
1596 | expr 1596 | expr
1597 ; 1597 ;
1598 1598
1599expr: /* C99 6.5 */ 1599expr: /* C99 6.5 */
1600 expr T_ASTERISK expr { 1600 expr T_ASTERISK expr {
1601 $$ = build(MULT, $1, $3); 1601 $$ = build(MULT, $1, $3);
1602 } 1602 }
1603 | expr T_MULTIPLICATIVE expr { 1603 | expr T_MULTIPLICATIVE expr {
1604 $$ = build($2, $1, $3); 1604 $$ = build($2, $1, $3);
1605 } 1605 }
1606 | expr T_ADDITIVE expr { 1606 | expr T_ADDITIVE expr {
1607 $$ = build($2, $1, $3); 1607 $$ = build($2, $1, $3);
1608 } 1608 }
1609 | expr T_SHIFT expr { 1609 | expr T_SHIFT expr {
1610 $$ = build($2, $1, $3); 1610 $$ = build($2, $1, $3);
1611 } 1611 }
1612 | expr T_RELATIONAL expr { 1612 | expr T_RELATIONAL expr {
1613 $$ = build($2, $1, $3); 1613 $$ = build($2, $1, $3);
1614 } 1614 }
1615 | expr T_EQUALITY expr { 1615 | expr T_EQUALITY expr {
1616 $$ = build($2, $1, $3); 1616 $$ = build($2, $1, $3);
1617 } 1617 }
1618 | expr T_AMPER expr { 1618 | expr T_AMPER expr {
1619 $$ = build(BITAND, $1, $3); 1619 $$ = build(BITAND, $1, $3);
1620 } 1620 }
1621 | expr T_BITXOR expr { 1621 | expr T_BITXOR expr {
1622 $$ = build(BITXOR, $1, $3); 1622 $$ = build(BITXOR, $1, $3);
1623 } 1623 }
1624 | expr T_BITOR expr { 1624 | expr T_BITOR expr {
1625 $$ = build(BITOR, $1, $3); 1625 $$ = build(BITOR, $1, $3);
1626 } 1626 }
1627 | expr T_LOGAND expr { 1627 | expr T_LOGAND expr {
1628 $$ = build(LOGAND, $1, $3); 1628 $$ = build(LOGAND, $1, $3);
1629 } 1629 }
1630 | expr T_LOGOR expr { 1630 | expr T_LOGOR expr {
1631 $$ = build(LOGOR, $1, $3); 1631 $$ = build(LOGOR, $1, $3);
1632 } 1632 }
1633 | expr T_QUEST expr T_COLON expr { 1633 | expr T_QUEST expr T_COLON expr {
1634 $$ = build(QUEST, $1, build(COLON, $3, $5)); 1634 $$ = build(QUEST, $1, build(COLON, $3, $5));
1635 } 1635 }
1636 | expr T_ASSIGN expr { 1636 | expr T_ASSIGN expr {
1637 $$ = build(ASSIGN, $1, $3); 1637 $$ = build(ASSIGN, $1, $3);
1638 } 1638 }
1639 | expr T_OPASSIGN expr { 1639 | expr T_OPASSIGN expr {
1640 $$ = build($2, $1, $3); 1640 $$ = build($2, $1, $3);
1641 } 1641 }
1642 | expr T_COMMA expr { 1642 | expr T_COMMA expr {
1643 $$ = build(COMMA, $1, $3); 1643 $$ = build(COMMA, $1, $3);
1644 } 1644 }
1645 | term 1645 | term
1646 | generic_selection 1646 | generic_selection
1647 ; 1647 ;
1648 1648
1649assignment_expression: /* C99 6.5.16 */ 1649assignment_expression: /* C99 6.5.16 */
1650 expr %prec T_ASSIGN 1650 expr %prec T_ASSIGN
1651 ; 1651 ;
1652 1652
1653term: /* see C99 6.5.1 */ 1653term: /* see C99 6.5.1 */
1654 T_NAME { 1654 T_NAME {
1655 /* XXX really necessary? */ 1655 /* XXX really necessary? */
1656 if (yychar < 0) 1656 if (yychar < 0)
1657 yychar = yylex(); 1657 yychar = yylex();
1658 $$ = new_name_node(getsym($1), yychar); 1658 $$ = new_name_node(getsym($1), yychar);
1659 } 1659 }
1660 | string { 1660 | string {
1661 $$ = new_string_node($1); 1661 $$ = new_string_node($1);
1662 } 1662 }
1663 | T_CON { 1663 | T_CON {
1664 $$ = expr_new_constant(gettyp($1->v_tspec), $1); 1664 $$ = expr_new_constant(gettyp($1->v_tspec), $1);
1665 } 1665 }
1666 | T_LPAREN expr T_RPAREN { 1666 | T_LPAREN expr T_RPAREN {
1667 if ($2 != NULL) 1667 if ($2 != NULL)
1668 $2->tn_parenthesized = true; 1668 $2->tn_parenthesized = true;
1669 $$ = $2; 1669 $$ = $2;
1670 } 1670 }
1671 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list { 1671 | T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
1672 block_level--; 1672 block_level--;
1673 mem_block_level--; 1673 mem_block_level--;
1674 begin_initialization(mktempsym(dup_type($3->tn_type))); 1674 begin_initialization(mktempsym(dup_type($3->tn_type)));
1675 mem_block_level++; 1675 mem_block_level++;
1676 block_level++; 1676 block_level++;
1677 /* ({ }) is a GCC extension */ 1677 /* ({ }) is a GCC extension */
1678 gnuism(320); 1678 gnuism(320);
1679 } compound_statement_rbrace T_RPAREN { 1679 } compound_statement_rbrace T_RPAREN {
1680 $$ = new_name_node(*current_initsym(), 0); 1680 $$ = new_name_node(*current_initsym(), 0);
1681 end_initialization(); 1681 end_initialization();
1682 } 1682 }
1683 | term T_INCDEC { 1683 | term T_INCDEC {
1684 $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL); 1684 $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
1685 } 1685 }
1686 | T_INCDEC term { 1686 | T_INCDEC term {
1687 $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL); 1687 $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
1688 } 1688 }
1689 | T_ASTERISK term { 1689 | T_ASTERISK term {
1690 $$ = build(INDIR, $2, NULL); 1690 $$ = build(INDIR, $2, NULL);
1691 } 1691 }
1692 | T_AMPER term { 1692 | T_AMPER term {
1693 $$ = build(ADDR, $2, NULL); 1693 $$ = build(ADDR, $2, NULL);
1694 } 1694 }
1695 | T_UNARY term { 1695 | T_UNARY term {
1696 $$ = build($1, $2, NULL); 1696 $$ = build($1, $2, NULL);
1697 } 1697 }
1698 | T_ADDITIVE term { 1698 | T_ADDITIVE term {
1699 if (tflag && $1 == PLUS) { 1699 if (tflag && $1 == PLUS) {
1700 /* unary + is illegal in traditional C */ 1700 /* unary + is illegal in traditional C */
1701 warning(100); 1701 warning(100);
1702 } 1702 }
1703 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL); 1703 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
1704 } 1704 }
1705 | term T_LBRACK expr T_RBRACK { 1705 | term T_LBRACK expr T_RBRACK {
1706 $$ = build(INDIR, build(PLUS, $1, $3), NULL); 1706 $$ = build(INDIR, build(PLUS, $1, $3), NULL);
1707 } 1707 }
1708 | term T_LPAREN T_RPAREN { 1708 | term T_LPAREN T_RPAREN {
1709 $$ = new_function_call_node($1, NULL); 1709 $$ = new_function_call_node($1, NULL);
1710 } 1710 }
1711 | term T_LPAREN argument_expression_list T_RPAREN { 1711 | term T_LPAREN argument_expression_list T_RPAREN {
1712 $$ = new_function_call_node($1, $3); 1712 $$ = new_function_call_node($1, $3);
1713 } 1713 }
1714 | term point_or_arrow T_NAME { 1714 | term point_or_arrow T_NAME {
1715 if ($1 != NULL) { 1715 if ($1 != NULL) {
1716 sym_t *msym; 1716 sym_t *msym;
1717 /* 1717 /*