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