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