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