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