Mon Mar 6 11:58:31 2017 UTC ()
handle typeof in casts


(christos)
diff -r1.92 -r1.93 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.92 -r1.93 src/usr.bin/xlint/lint1/cgram.y (switch to unified diff)

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