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