Fri Jan 1 10:55:28 2021 UTC ()
lint: split label handling into separate functions

The only thing these cases have in common is the name "label" and the
"reached = 1" assignment.  That's not reason enough to combine
completely unrelated functions.


(rillig)
diff -r1.124 -r1.125 src/usr.bin/xlint/lint1/cgram.y
diff -r1.42 -r1.43 src/usr.bin/xlint/lint1/externs1.h
diff -r1.41 -r1.42 src/usr.bin/xlint/lint1/func.c

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

--- src/usr.bin/xlint/lint1/cgram.y 2021/01/01 09:28:22 1.124
+++ src/usr.bin/xlint/lint1/cgram.y 2021/01/01 10:55:27 1.125
@@ -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
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. 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 */
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#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 */
114static void 114static void
115anonymize(sym_t *s) 115anonymize(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
335program: 335program:
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
348translation_unit: 348translation_unit:
349 ext_decl 349 ext_decl
350 | translation_unit ext_decl 350 | translation_unit ext_decl
351 ; 351 ;
352 352
353ext_decl: 353ext_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
365data_def: 365data_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
412func_def: 412func_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
441func_decl: 441func_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
453opt_arg_declaration_list: 453opt_arg_declaration_list:
454 /* empty */ 454 /* empty */
455 | arg_declaration_list 455 | arg_declaration_list
456 ; 456 ;
457 457
458arg_declaration_list: 458arg_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
470arg_declaration: 470arg_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
499declaration: 499declaration:
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
523type_attribute_format_type: 523type_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
532type_attribute_bounded_type: 532type_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
539type_attribute_spec: 539type_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
593type_attribute_spec_list: 593type_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
598type_attribute: 598type_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
611type_attribute_list: 611type_attribute_list:
612 type_attribute 612 type_attribute
613 | type_attribute_list type_attribute 613 | type_attribute_list type_attribute
614 ; 614 ;
615 615
616clrtyp: 616clrtyp:
617 /* empty */ { 617 /* empty */ {
618 clrtyp(); 618 clrtyp();
619 } 619 }
620 ; 620 ;
621 621
622deftyp: 622deftyp:
623 /* empty */ { 623 /* empty */ {
624 deftyp(); 624 deftyp();
625 } 625 }
626 ; 626 ;
627 627
628declspecs: 628declspecs:
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
642declmods: 642declmods:
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
652declmod: 652declmod:
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
662clrtyp_typespec: 662clrtyp_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
671typespec: 671typespec:
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
680notype_typespec: 680notype_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
697struct_spec: 697struct_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
724struct: 724struct:
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
735struct_tag: 735struct_tag:
736 identifier { 736 identifier {
737 $$ = getsym($1); 737 $$ = getsym($1);
738 } 738 }
739 ; 739 ;
740 740
741struct_declaration: 741struct_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
747struct_decl_lbrace: 747struct_decl_lbrace:
748 T_LBRACE { 748 T_LBRACE {
749 symtyp = FVFT; 749 symtyp = FVFT;
750 } 750 }
751 ; 751 ;
752 752
753member_declaration_list_with_rbrace: 753member_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
772opt_type_attribute: 772opt_type_attribute:
773 /* empty */ 773 /* empty */
774 | type_attribute 774 | type_attribute
775 ; 775 ;
776 776
777member_declaration_list: 777member_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
786member_declaration: 786member_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
824noclass_declspecs: 824noclass_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
841noclass_declmods: 841noclass_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
850notype_member_decls: 850notype_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
861type_member_decls: 861type_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
872notype_member_decl: 872notype_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
886type_member_decl: 886type_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
900enum_spec: 900enum_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
920enum: 920enum:
921 T_ENUM { 921 T_ENUM {
922 symtyp = FTAG; 922 symtyp = FTAG;
923 pushdecl(ENUMCON); 923 pushdecl(ENUMCON);
924 } 924 }
925 ; 925 ;
926 926
927enum_tag: 927enum_tag:
928 identifier { 928 identifier {
929 $$ = getsym($1); 929 $$ = getsym($1);
930 } 930 }
931 ; 931 ;
932 932
933enum_declaration: 933enum_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
939enum_decl_lbrace: 939enum_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
946enums_with_opt_comma: 946enums_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
962enums: 962enums:
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
974enumerator: 974enumerator:
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
983ename: 983ename:
984 identifier { 984 identifier {
985 $$ = getsym($1); 985 $$ = getsym($1);
986 } 986 }
987 ; 987 ;
988 988
989 989
990notype_init_decls: 990notype_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
995type_init_decls: 995type_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
1000notype_init_decl: 1000notype_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
1012type_init_decl: 1012type_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
1024notype_decl: 1024notype_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
1033notype_direct_decl: 1033notype_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
1057type_decl: 1057type_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
1066type_direct_decl: 1066type_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 */
1097param_decl: 1097param_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
1106direct_param_decl: 1106direct_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
1129notype_param_decl: 1129notype_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
1138direct_notype_param_decl: 1138direct_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
1158pointer: 1158pointer:
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
1174asterisk: 1174asterisk:
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
1181type_qualifier_list: 1181type_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
1190type_qualifier: 1190type_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
1201param_list: 1201param_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
1210id_list_lparn: 1210id_list_lparn:
1211 T_LPARN { 1211 T_LPARN {
1212 blklev++; 1212 blklev++;
1213 pushdecl(PARG); 1213 pushdecl(PARG);
1214 } 1214 }
1215 ; 1215 ;
1216 1216
1217identifier_list: 1217identifier_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
1229abs_decl_param_list: 1229abs_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
1242abs_decl_lparn: 1242abs_decl_lparn:
1243 T_LPARN { 1243 T_LPARN {
1244 blklev++; 1244 blklev++;
1245 pushdecl(PARG); 1245 pushdecl(PARG);
1246 } 1246 }
1247 ; 1247 ;
1248 1248
1249vararg_parameter_type_list: 1249vararg_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
1270parameter_type_list: 1270parameter_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
1279parameter_declaration: 1279parameter_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
1307opt_asm_or_symbolrename: /* expect only one */ 1307opt_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
1320initializer: 1320initializer:
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
1328init_assign_expr: 1328init_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
1332init_base_expr: 1332init_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
1342init_expr_list: 1342init_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
1347lorange: 1347lorange:
1348 constant T_ELLIPSE { 1348 constant T_ELLIPSE {
1349 $$.lo = toicon($1, 1); 1349 $$.lo = toicon($1, 1);
1350 } 1350 }
1351 ; 1351 ;
1352range: 1352range:
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
1363init_field: 1363init_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
1375init_field_list: 1375init_field_list:
1376 init_field 1376 init_field
1377 | init_field_list init_field 1377 | init_field_list init_field
1378 ; 1378 ;
1379 1379
1380init_by_name: 1380init_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
1388init_lbrace: 1388init_lbrace:
1389 T_LBRACE { 1389 T_LBRACE {
1390 init_lbrace(); 1390 init_lbrace();
1391 } 1391 }
1392 ; 1392 ;
1393 1393
1394init_rbrace: 1394init_rbrace:
1395 T_RBRACE { 1395 T_RBRACE {
1396 init_rbrace(); 1396 init_rbrace();
1397 } 1397 }
1398 ; 1398 ;
1399 1399
1400type_name: 1400type_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
1409abstract_declaration: 1409abstract_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
1424abs_decl: 1424abs_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
1439direct_abs_decl: 1439direct_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
1471non_expr_stmnt: 1471non_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
1481stmnt: 1481stmnt:
1482 expr_stmnt 1482 expr_stmnt
1483 | non_expr_stmnt 1483 | non_expr_stmnt
1484 ; 1484 ;
1485 1485
1486labeled_stmnt: 1486labeled_stmnt:
1487 label stmnt 1487 label stmnt
1488 ; 1488 ;
1489 1489
1490label: 1490label:
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
1510stmnt_d_list: 1510stmnt_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
1518comp_stmnt: 1518comp_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
1525comp_stmnt_lbrace: 1525comp_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
1533comp_stmnt_rbrace: 1533comp_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
1543stmnt_list: 1543stmnt_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
1551expr_stmnt: 1551expr_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 */
1566expr_stmnt_val: 1566expr_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
1581expr_stmnt_list: 1581expr_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
1588selection_stmnt: 1588selection_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
1615if_without_else: 1615if_without_else:
1616 if_expr stmnt 1616 if_expr stmnt
1617 | if_expr error 1617 | if_expr error
1618 ; 1618 ;
1619 1619
1620if_expr: 1620if_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
1627switch_expr: 1627switch_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
1634association: 1634association:
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
1639association_list: 1639association_list:
1640 association 1640 association
1641 | association_list T_COMMA association 1641 | association_list T_COMMA association
1642 ; 1642 ;
1643 1643
1644generic_expr: 1644generic_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
1650do_stmnt: 1650do_stmnt:
1651 do stmnt { 1651 do stmnt {
1652 CLRWFLGS(__FILE__, __LINE__); 1652 CLRWFLGS(__FILE__, __LINE__);
1653 } 1653 }
1654 ; 1654 ;
1655 1655
1656iteration_stmnt: 1656iteration_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
1687while_expr: 1687while_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
1694do: 1694do:
1695 T_DO { 1695 T_DO {
1696 do1(); 1696 do1();
1697 } 1697 }
1698 ; 1698 ;
1699 1699
1700do_while_expr: 1700do_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
1706for_start: 1706for_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 ;
1712for_exprs: 1712for_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
1725opt_expr: 1725opt_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
1734jump_stmnt: 1734jump_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
1755goto: 1755goto:
1756 T_GOTO { 1756 T_GOTO {
1757 symtyp = FLABEL; 1757 symtyp = FLABEL;
1758 } 1758 }
1759 ; 1759 ;
1760 1760
1761asm_stmnt: 1761asm_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
1771read_until_rparn: 1771read_until_rparn:
1772 /* empty */ { 1772 /* empty */ {
1773 ignuptorp(); 1773 ignuptorp();
1774 } 1774 }
1775 ; 1775 ;
1776 1776
1777declaration_list: 1777declaration_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
1786constant: 1786constant:
1787 expr %prec T_COMMA { 1787 expr %prec T_COMMA {
1788 $$ = $1; 1788 $$ = $1;
1789 } 1789 }
1790 ; 1790 ;
1791 1791
1792expr: 1792expr:
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
1846term: 1846term:
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
1979string: 1979string:
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
1988string2: 1988string2:
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
2001func_arg_list: 2001func_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
2010point_or_arrow: 2010point_or_arrow:
2011 T_STROP { 2011 T_STROP {
2012 symtyp = FMEMBER; 2012 symtyp = FMEMBER;
2013 $$ = $1; 2013 $$ = $1;
2014 } 2014 }
2015 ; 2015 ;
2016 2016
2017point: 2017point:
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
2025identifier: 2025identifier:
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 */
2039int 2039int
2040yyerror(const char *msg) 2040yyerror(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
2048static __inline int uq_gt(uint64_t, uint64_t); 2048static __inline int uq_gt(uint64_t, uint64_t);
2049static __inline int q_gt(int64_t, int64_t); 2049static __inline int q_gt(int64_t, int64_t);
2050 2050
2051static __inline int 2051static __inline int
2052uq_gt(uint64_t a, uint64_t b) 2052uq_gt(uint64_t a, uint64_t b)
2053{ 2053{
2054 2054
2055 return a > b; 2055 return a > b;
2056} 2056}
2057 2057
2058static __inline int 2058static __inline int
2059q_gt(int64_t a, int64_t b) 2059q_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 */
2076static int 2076static int
2077toicon(tnode_t *tn, int required) 2077toicon(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
2118static void 2118static void
2119idecl(sym_t *decl, int initflg, sbuf_t *renaming) 2119idecl(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 */
2168static void 2168static void
2169ignuptorp(void) 2169ignuptorp(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
2190static sym_t * 2190static sym_t *
2191symbolrename(sym_t *s, sbuf_t *sb) 2191symbolrename(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}

cvs diff -r1.42 -r1.43 src/usr.bin/xlint/lint1/externs1.h (switch to unified diff)

--- src/usr.bin/xlint/lint1/externs1.h 2020/12/30 13:17:42 1.42
+++ src/usr.bin/xlint/lint1/externs1.h 2021/01/01 10:55:28 1.43
@@ -1,307 +1,309 @@ @@ -1,307 +1,309 @@
1/* $NetBSD: externs1.h,v 1.42 2020/12/30 13:17:42 rillig Exp $ */ 1/* $NetBSD: externs1.h,v 1.43 2021/01/01 10:55:28 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for 17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project. 18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products 19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission. 20 * derived from this software without specific prior written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34/* 34/*
35 * main.c 35 * main.c
36 */ 36 */
37extern int aflag; 37extern int aflag;
38extern int bflag; 38extern int bflag;
39extern int cflag; 39extern int cflag;
40extern int dflag; 40extern int dflag;
41extern int eflag; 41extern int eflag;
42extern int Fflag; 42extern int Fflag;
43extern int gflag; 43extern int gflag;
44extern int hflag; 44extern int hflag;
45extern int rflag; 45extern int rflag;
46extern int sflag; 46extern int sflag;
47extern int tflag; 47extern int tflag;
48extern int uflag; 48extern int uflag;
49extern int vflag; 49extern int vflag;
50extern int yflag; 50extern int yflag;
51extern int wflag; 51extern int wflag;
52extern int zflag; 52extern int zflag;
53extern int Sflag; 53extern int Sflag;
54extern int Pflag; 54extern int Pflag;
55 55
56extern void norecover(void); 56extern void norecover(void);
57 57
58/* 58/*
59 * cgram.y 59 * cgram.y
60 */ 60 */
61extern int blklev; 61extern int blklev;
62extern int mblklev; 62extern int mblklev;
63extern int yydebug; 63extern int yydebug;
64 64
65extern int yyerror(const char *); 65extern int yyerror(const char *);
66extern int yyparse(void); 66extern int yyparse(void);
67 67
68/* 68/*
69 * scan.l 69 * scan.l
70 */ 70 */
71extern int attron; 71extern int attron;
72extern pos_t curr_pos; 72extern pos_t curr_pos;
73extern pos_t csrc_pos; 73extern pos_t csrc_pos;
74extern symt_t symtyp; 74extern symt_t symtyp;
75extern FILE *yyin; 75extern FILE *yyin;
76extern uint64_t qbmasks[], qlmasks[], qumasks[]; 76extern uint64_t qbmasks[], qlmasks[], qumasks[];
77 77
78extern void initscan(void); 78extern void initscan(void);
79extern int sign(int64_t, tspec_t, int); 79extern int sign(int64_t, tspec_t, int);
80extern int msb(int64_t, tspec_t, int); 80extern int msb(int64_t, tspec_t, int);
81extern int64_t xsign(int64_t, tspec_t, int); 81extern int64_t xsign(int64_t, tspec_t, int);
82extern void clrwflgs(void); 82extern void clrwflgs(void);
83extern sym_t *getsym(sbuf_t *); 83extern sym_t *getsym(sbuf_t *);
84extern void cleanup(void); 84extern void cleanup(void);
85extern sym_t *pushdown(sym_t *); 85extern sym_t *pushdown(sym_t *);
86extern sym_t *mktempsym(type_t *); 86extern sym_t *mktempsym(type_t *);
87extern void rmsym(sym_t *); 87extern void rmsym(sym_t *);
88extern void rmsyms(sym_t *); 88extern void rmsyms(sym_t *);
89extern void inssym(int, sym_t *); 89extern void inssym(int, sym_t *);
90extern void freeyyv(void *, int); 90extern void freeyyv(void *, int);
91extern int yylex(void); 91extern int yylex(void);
92 92
93/* 93/*
94 * mem1.c 94 * mem1.c
95 */ 95 */
96extern const char *fnalloc(const char *); 96extern const char *fnalloc(const char *);
97extern const char *fnnalloc(const char *, size_t); 97extern const char *fnnalloc(const char *, size_t);
98extern int getfnid(const char *); 98extern int getfnid(const char *);
99extern void fnaddreplsrcdir(char *); 99extern void fnaddreplsrcdir(char *);
100extern const char *fnxform(const char *, size_t); 100extern const char *fnxform(const char *, size_t);
101 101
102extern void initmem(void); 102extern void initmem(void);
103 103
104extern void *getblk(size_t); 104extern void *getblk(size_t);
105extern void *getlblk(size_t, size_t); 105extern void *getlblk(size_t, size_t);
106extern void freeblk(void); 106extern void freeblk(void);
107extern void freelblk(int); 107extern void freelblk(int);
108 108
109extern void *tgetblk(size_t); 109extern void *tgetblk(size_t);
110extern tnode_t *getnode(void); 110extern tnode_t *getnode(void);
111extern void tfreeblk(void); 111extern void tfreeblk(void);
112extern struct mbl *tsave(void); 112extern struct mbl *tsave(void);
113extern void trestor(struct mbl *); 113extern void trestor(struct mbl *);
114 114
115/* 115/*
116 * err.c 116 * err.c
117 */ 117 */
118extern int nerr; 118extern int nerr;
119extern int sytxerr; 119extern int sytxerr;
120extern const char *msgs[]; 120extern const char *msgs[];
121 121
122extern void msglist(void); 122extern void msglist(void);
123extern void error(int, ...); 123extern void error(int, ...);
124extern void warning(int, ...); 124extern void warning(int, ...);
125extern void message(int, ...); 125extern void message(int, ...);
126extern int gnuism(int, ...); 126extern int gnuism(int, ...);
127extern int c99ism(int, ...); 127extern int c99ism(int, ...);
128extern void lerror(const char *, int, const char *, ...) 128extern void lerror(const char *, int, const char *, ...)
129 __attribute__((__noreturn__,__format__(__printf__, 3, 4))); 129 __attribute__((__noreturn__,__format__(__printf__, 3, 4)));
130extern void assert_failed(const char *, int, const char *, const char *) 130extern void assert_failed(const char *, int, const char *, const char *)
131 __attribute__((__noreturn__)); 131 __attribute__((__noreturn__));
132 132
133/* 133/*
134 * decl.c 134 * decl.c
135 */ 135 */
136extern dinfo_t *dcs; 136extern dinfo_t *dcs;
137extern const char *unnamed; 137extern const char *unnamed;
138extern int enumval; 138extern int enumval;
139 139
140extern void initdecl(void); 140extern void initdecl(void);
141extern type_t *gettyp(tspec_t); 141extern type_t *gettyp(tspec_t);
142extern type_t *duptyp(const type_t *); 142extern type_t *duptyp(const type_t *);
143extern type_t *tduptyp(const type_t *); 143extern type_t *tduptyp(const type_t *);
144extern int incompl(type_t *); 144extern int incompl(type_t *);
145extern void setcomplete(type_t *, int); 145extern void setcomplete(type_t *, int);
146extern void add_storage_class(scl_t); 146extern void add_storage_class(scl_t);
147extern void add_type(type_t *); 147extern void add_type(type_t *);
148extern void add_qualifier(tqual_t); 148extern void add_qualifier(tqual_t);
149extern void addpacked(void); 149extern void addpacked(void);
150extern void add_attr_used(void); 150extern void add_attr_used(void);
151extern void pushdecl(scl_t); 151extern void pushdecl(scl_t);
152extern void popdecl(void); 152extern void popdecl(void);
153extern void setasm(void); 153extern void setasm(void);
154extern void clrtyp(void); 154extern void clrtyp(void);
155extern void deftyp(void); 155extern void deftyp(void);
156extern int length(type_t *, const char *); 156extern int length(type_t *, const char *);
157extern int getbound(type_t *); 157extern int getbound(type_t *);
158extern sym_t *lnklst(sym_t *, sym_t *); 158extern sym_t *lnklst(sym_t *, sym_t *);
159extern void check_type(sym_t *); 159extern void check_type(sym_t *);
160extern sym_t *declarator_1_struct_union(sym_t *); 160extern sym_t *declarator_1_struct_union(sym_t *);
161extern sym_t *bitfield(sym_t *, int); 161extern sym_t *bitfield(sym_t *, int);
162extern pqinf_t *merge_pointers_and_qualifiers(pqinf_t *, pqinf_t *); 162extern pqinf_t *merge_pointers_and_qualifiers(pqinf_t *, pqinf_t *);
163extern sym_t *add_pointer(sym_t *, pqinf_t *); 163extern sym_t *add_pointer(sym_t *, pqinf_t *);
164extern sym_t *add_array(sym_t *, int, int); 164extern sym_t *add_array(sym_t *, int, int);
165extern sym_t *add_function(sym_t *, sym_t *); 165extern sym_t *add_function(sym_t *, sym_t *);
166extern void check_function_definition(sym_t *, int); 166extern void check_function_definition(sym_t *, int);
167extern sym_t *declarator_name(sym_t *); 167extern sym_t *declarator_name(sym_t *);
168extern sym_t *old_style_function_name(sym_t *); 168extern sym_t *old_style_function_name(sym_t *);
169extern type_t *mktag(sym_t *, tspec_t, int, int); 169extern type_t *mktag(sym_t *, tspec_t, int, int);
170extern const char *storage_class_name(scl_t); 170extern const char *storage_class_name(scl_t);
171extern type_t *complete_tag_struct_or_union(type_t *, sym_t *); 171extern type_t *complete_tag_struct_or_union(type_t *, sym_t *);
172extern type_t *complete_tag_enum(type_t *, sym_t *); 172extern type_t *complete_tag_enum(type_t *, sym_t *);
173extern sym_t *ename(sym_t *, int, int); 173extern sym_t *ename(sym_t *, int, int);
174extern void decl1ext(sym_t *, int); 174extern void decl1ext(sym_t *, int);
175extern void copy_usage_info(sym_t *, sym_t *); 175extern void copy_usage_info(sym_t *, sym_t *);
176extern int check_redeclaration(sym_t *, int *); 176extern int check_redeclaration(sym_t *, int *);
177extern int eqptrtype(type_t *, type_t *, int); 177extern int eqptrtype(type_t *, type_t *, int);
178extern int eqtype(type_t *, type_t *, int, int, int *); 178extern int eqtype(type_t *, type_t *, int, int, int *);
179extern void complete_type(sym_t *, sym_t *); 179extern void complete_type(sym_t *, sym_t *);
180extern sym_t *decl1arg(sym_t *, int); 180extern sym_t *decl1arg(sym_t *, int);
181extern void check_func_lint_directives(void); 181extern void check_func_lint_directives(void);
182extern void check_func_old_style_arguments(void); 182extern void check_func_old_style_arguments(void);
183 183
184extern void decl1loc(sym_t *, int); 184extern void decl1loc(sym_t *, int);
185extern sym_t *abstract_name(void); 185extern sym_t *abstract_name(void);
186extern void global_clean_up(void); 186extern void global_clean_up(void);
187extern sym_t *declare_1_abstract(sym_t *); 187extern sym_t *declare_1_abstract(sym_t *);
188extern void check_size(sym_t *); 188extern void check_size(sym_t *);
189extern void mark_as_set(sym_t *); 189extern void mark_as_set(sym_t *);
190extern void mark_as_used(sym_t *, int, int); 190extern void mark_as_used(sym_t *, int, int);
191extern void check_usage(dinfo_t *); 191extern void check_usage(dinfo_t *);
192extern void check_usage_sym(int, sym_t *); 192extern void check_usage_sym(int, sym_t *);
193extern void check_global_symbols(void); 193extern void check_global_symbols(void);
194extern void print_previous_declaration(int, sym_t *); 194extern void print_previous_declaration(int, sym_t *);
195 195
196/* 196/*
197 * tree.c 197 * tree.c
198 */ 198 */
199extern type_t *incref(type_t *, tspec_t); 199extern type_t *incref(type_t *, tspec_t);
200extern type_t *tincref(type_t *, tspec_t); 200extern type_t *tincref(type_t *, tspec_t);
201extern tnode_t *getcnode(type_t *, val_t *); 201extern tnode_t *getcnode(type_t *, val_t *);
202extern tnode_t *getnnode(sym_t *, int); 202extern tnode_t *getnnode(sym_t *, int);
203extern tnode_t *getsnode(strg_t *); 203extern tnode_t *getsnode(strg_t *);
204extern sym_t *struct_or_union_member(tnode_t *, op_t, sym_t *); 204extern sym_t *struct_or_union_member(tnode_t *, op_t, sym_t *);
205extern tnode_t *build(op_t, tnode_t *, tnode_t *); 205extern tnode_t *build(op_t, tnode_t *, tnode_t *);
206extern tnode_t *cconv(tnode_t *); 206extern tnode_t *cconv(tnode_t *);
207extern int typeok(op_t, int, tnode_t *, tnode_t *); 207extern int typeok(op_t, int, tnode_t *, tnode_t *);
208extern tnode_t *promote(op_t, int, tnode_t *); 208extern tnode_t *promote(op_t, int, tnode_t *);
209extern tnode_t *convert(op_t, int, type_t *, tnode_t *); 209extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
210extern void cvtcon(op_t, int, type_t *, val_t *, val_t *); 210extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
211extern tnode_t *build_sizeof(type_t *); 211extern tnode_t *build_sizeof(type_t *);
212extern tnode_t *build_offsetof(type_t *, sym_t *); 212extern tnode_t *build_offsetof(type_t *, sym_t *);
213extern tnode_t *build_alignof(type_t *); 213extern tnode_t *build_alignof(type_t *);
214extern tnode_t *cast(tnode_t *, type_t *); 214extern tnode_t *cast(tnode_t *, type_t *);
215extern tnode_t *funcarg(tnode_t *, tnode_t *); 215extern tnode_t *funcarg(tnode_t *, tnode_t *);
216extern tnode_t *funccall(tnode_t *, tnode_t *); 216extern tnode_t *funccall(tnode_t *, tnode_t *);
217extern val_t *constant(tnode_t *, int); 217extern val_t *constant(tnode_t *, int);
218extern void expr(tnode_t *, int, int, int); 218extern void expr(tnode_t *, int, int, int);
219extern void check_expr_misc(tnode_t *, int, int, int, int, int, int); 219extern void check_expr_misc(tnode_t *, int, int, int, int, int, int);
220extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *); 220extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
221extern strg_t *cat_strings(strg_t *, strg_t *); 221extern strg_t *cat_strings(strg_t *, strg_t *);
222extern int64_t tsize(type_t *); 222extern int64_t tsize(type_t *);
223 223
224/* 224/*
225 * func.c 225 * func.c
226 */ 226 */
227extern sym_t *funcsym; 227extern sym_t *funcsym;
228extern int reached; 228extern int reached;
229extern int rchflg; 229extern int rchflg;
230extern int ftflg; 230extern int ftflg;
231extern int nargusg; 231extern int nargusg;
232extern pos_t argsused_pos; 232extern pos_t argsused_pos;
233extern int nvararg; 233extern int nvararg;
234extern pos_t vapos; 234extern pos_t vapos;
235extern int prflstrg; 235extern int prflstrg;
236extern pos_t printflike_pos; 236extern pos_t printflike_pos;
237extern int scflstrg; 237extern int scflstrg;
238extern pos_t scanflike_pos; 238extern pos_t scanflike_pos;
239extern int constcond_flag; 239extern int constcond_flag;
240extern int llibflg; 240extern int llibflg;
241extern int lwarn; 241extern int lwarn;
242extern int bitfieldtype_ok; 242extern int bitfieldtype_ok;
243extern int plibflg; 243extern int plibflg;
244extern int quadflg; 244extern int quadflg;
245 245
246extern void pushctrl(int); 246extern void pushctrl(int);
247extern void popctrl(int); 247extern void popctrl(int);
248extern void check_statement_reachable(void); 248extern void check_statement_reachable(void);
249extern void funcdef(sym_t *); 249extern void funcdef(sym_t *);
250extern void funcend(void); 250extern void funcend(void);
251extern void label(int, sym_t *, tnode_t *); 251extern void named_label(sym_t *);
 252extern void case_label(tnode_t *);
 253extern void default_label(void);
252extern void if1(tnode_t *); 254extern void if1(tnode_t *);
253extern void if2(void); 255extern void if2(void);
254extern void if3(int); 256extern void if3(int);
255extern void switch1(tnode_t *); 257extern void switch1(tnode_t *);
256extern void switch2(void); 258extern void switch2(void);
257extern void while1(tnode_t *); 259extern void while1(tnode_t *);
258extern void while2(void); 260extern void while2(void);
259extern void do1(void); 261extern void do1(void);
260extern void do2(tnode_t *); 262extern void do2(tnode_t *);
261extern void for1(tnode_t *, tnode_t *, tnode_t *); 263extern void for1(tnode_t *, tnode_t *, tnode_t *);
262extern void for2(void); 264extern void for2(void);
263extern void dogoto(sym_t *); 265extern void dogoto(sym_t *);
264extern void docont(void); 266extern void docont(void);
265extern void dobreak(void); 267extern void dobreak(void);
266extern void doreturn(tnode_t *); 268extern void doreturn(tnode_t *);
267extern void global_clean_up_decl(int); 269extern void global_clean_up_decl(int);
268extern void argsused(int); 270extern void argsused(int);
269extern void constcond(int); 271extern void constcond(int);
270extern void fallthru(int); 272extern void fallthru(int);
271extern void notreach(int); 273extern void notreach(int);
272extern void lintlib(int); 274extern void lintlib(int);
273extern void linted(int); 275extern void linted(int);
274extern void varargs(int); 276extern void varargs(int);
275extern void printflike(int); 277extern void printflike(int);
276extern void scanflike(int); 278extern void scanflike(int);
277extern void protolib(int); 279extern void protolib(int);
278extern void longlong(int); 280extern void longlong(int);
279extern void bitfieldtype(int); 281extern void bitfieldtype(int);
280 282
281/* 283/*
282 * init.c 284 * init.c
283 */ 285 */
284extern int initerr; 286extern int initerr;
285extern sym_t *initsym; 287extern sym_t *initsym;
286extern int startinit; 288extern int startinit;
287 289
288extern void initstack_init(void); 290extern void initstack_init(void);
289extern void init_rbrace(void); 291extern void init_rbrace(void);
290extern void init_lbrace(void); 292extern void init_lbrace(void);
291extern void mkinit(tnode_t *); 293extern void mkinit(tnode_t *);
292extern void push_member(sbuf_t *); 294extern void push_member(sbuf_t *);
293 295
294/* 296/*
295 * emit.c 297 * emit.c
296 */ 298 */
297extern void outtype(type_t *); 299extern void outtype(type_t *);
298extern const char *ttos(type_t *); 300extern const char *ttos(type_t *);
299extern void outsym(sym_t *, scl_t, def_t); 301extern void outsym(sym_t *, scl_t, def_t);
300extern void outfdef(sym_t *, pos_t *, int, int, sym_t *); 302extern void outfdef(sym_t *, pos_t *, int, int, sym_t *);
301extern void outcall(tnode_t *, int, int); 303extern void outcall(tnode_t *, int, int);
302extern void outusg(sym_t *); 304extern void outusg(sym_t *);
303 305
304/* 306/*
305 * print.c 307 * print.c
306 */ 308 */
307extern char *print_tnode(char *, size_t, const tnode_t *); 309extern char *print_tnode(char *, size_t, const tnode_t *);

cvs diff -r1.41 -r1.42 src/usr.bin/xlint/lint1/func.c (switch to unified diff)

--- src/usr.bin/xlint/lint1/func.c 2021/01/01 09:11:40 1.41
+++ src/usr.bin/xlint/lint1/func.c 2021/01/01 10:55:28 1.42
@@ -1,1289 +1,1287 @@ @@ -1,1289 +1,1287 @@
1/* $NetBSD: func.c,v 1.41 2021/01/01 09:11:40 rillig Exp $ */ 1/* $NetBSD: func.c,v 1.42 2021/01/01 10:55:28 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * All Rights Reserved. 5 * All Rights Reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software 15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement: 16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for 17 * This product includes software developed by Jochen Pohl for
18 * The NetBSD Project. 18 * The NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products 19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission. 20 * derived from this software without specific prior written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39#if defined(__RCSID) && !defined(lint) 39#if defined(__RCSID) && !defined(lint)
40__RCSID("$NetBSD: func.c,v 1.41 2021/01/01 09:11:40 rillig Exp $"); 40__RCSID("$NetBSD: func.c,v 1.42 2021/01/01 10:55:28 rillig Exp $");
41#endif 41#endif
42 42
43#include <stdlib.h> 43#include <stdlib.h>
44#include <string.h> 44#include <string.h>
45 45
46#include "lint1.h" 46#include "lint1.h"
47#include "cgram.h" 47#include "cgram.h"
48 48
49/* 49/*
50 * Contains a pointer to the symbol table entry of the current function 50 * Contains a pointer to the symbol table entry of the current function
51 * definition. 51 * definition.
52 */ 52 */
53sym_t *funcsym; 53sym_t *funcsym;
54 54
55/* Is set as long as a statement can be reached. Must be set at level 0. */ 55/* Is set as long as a statement can be reached. Must be set at level 0. */
56int reached = 1; 56int reached = 1;
57 57
58/* 58/*
59 * Is set as long as NOTREACHED is in effect. 59 * Is set as long as NOTREACHED is in effect.
60 * Is reset everywhere where reached can become 0. 60 * Is reset everywhere where reached can become 0.
61 */ 61 */
62int rchflg; 62int rchflg;
63 63
64/* 64/*
65 * In conjunction with reached ontrols printing of "fallthrough on ..." 65 * In conjunction with reached ontrols printing of "fallthrough on ..."
66 * warnings. 66 * warnings.
67 * Reset by each statement and set by FALLTHROUGH, switch (switch1()) 67 * Reset by each statement and set by FALLTHROUGH, switch (switch1())
68 * and case (label()). 68 * and case (label()).
69 * 69 *
70 * Control statements if, for, while and switch do not reset ftflg because 70 * Control statements if, for, while and switch do not reset ftflg because
71 * this must be done by the controlled statement. At least for if this is 71 * this must be done by the controlled statement. At least for if this is
72 * important because ** FALLTHROUGH ** after "if (expr) stmnt" is evaluated 72 * important because ** FALLTHROUGH ** after "if (expr) stmnt" is evaluated
73 * before the following token, wich causes reduction of above. 73 * before the following token, wich causes reduction of above.
74 * This means that ** FALLTHROUGH ** after "if ..." would always be ignored. 74 * This means that ** FALLTHROUGH ** after "if ..." would always be ignored.
75 */ 75 */
76int ftflg; 76int ftflg;
77 77
78/* Top element of stack for control statements */ 78/* Top element of stack for control statements */
79cstk_t *cstk; 79cstk_t *cstk;
80 80
81/* 81/*
82 * Number of arguments which will be checked for usage in following 82 * Number of arguments which will be checked for usage in following
83 * function definition. -1 stands for all arguments. 83 * function definition. -1 stands for all arguments.
84 * 84 *
85 * The position of the last ARGSUSED comment is stored in argsused_pos. 85 * The position of the last ARGSUSED comment is stored in argsused_pos.
86 */ 86 */
87int nargusg = -1; 87int nargusg = -1;
88pos_t argsused_pos; 88pos_t argsused_pos;
89 89
90/* 90/*
91 * Number of arguments of the following function definition whose types 91 * Number of arguments of the following function definition whose types
92 * shall be checked by lint2. -1 stands for all arguments. 92 * shall be checked by lint2. -1 stands for all arguments.
93 * 93 *
94 * The position of the last VARARGS comment is stored in vapos. 94 * The position of the last VARARGS comment is stored in vapos.
95 */ 95 */
96int nvararg = -1; 96int nvararg = -1;
97pos_t vapos; 97pos_t vapos;
98 98
99/* 99/*
100 * Both prflstr and scflstrg contain the number of the argument which 100 * Both prflstr and scflstrg contain the number of the argument which
101 * shall be used to check the types of remaining arguments (for PRINTFLIKE 101 * shall be used to check the types of remaining arguments (for PRINTFLIKE
102 * and SCANFLIKE). 102 * and SCANFLIKE).
103 * 103 *
104 * printflike_pos and scanflike_pos are the positions of the last PRINTFLIKE 104 * printflike_pos and scanflike_pos are the positions of the last PRINTFLIKE
105 * or SCANFLIKE comment. 105 * or SCANFLIKE comment.
106 */ 106 */
107int prflstrg = -1; 107int prflstrg = -1;
108int scflstrg = -1; 108int scflstrg = -1;
109pos_t printflike_pos; 109pos_t printflike_pos;
110pos_t scanflike_pos; 110pos_t scanflike_pos;
111 111
112/* 112/*
113 * If both plibflg and llibflg are set, prototypes are written as function 113 * If both plibflg and llibflg are set, prototypes are written as function
114 * definitions to the output file. 114 * definitions to the output file.
115 */ 115 */
116int plibflg; 116int plibflg;
117 117
118/* 118/*
119 * Nonzero means that no warnings about constants in conditional 119 * Nonzero means that no warnings about constants in conditional
120 * context are printed. 120 * context are printed.
121 */ 121 */
122int constcond_flag; 122int constcond_flag;
123 123
124/* 124/*
125 * llibflg is set if a lint library shall be created. The effect of 125 * llibflg is set if a lint library shall be created. The effect of
126 * llibflg is that all defined symbols are treated as used. 126 * llibflg is that all defined symbols are treated as used.
127 * (The LINTLIBRARY comment also resets vflag.) 127 * (The LINTLIBRARY comment also resets vflag.)
128 */ 128 */
129int llibflg; 129int llibflg;
130 130
131/* 131/*
132 * Nonzero if warnings are suppressed by a LINTED directive 132 * Nonzero if warnings are suppressed by a LINTED directive
133 * LWARN_BAD: error 133 * LWARN_BAD: error
134 * LWARN_ALL: warnings on 134 * LWARN_ALL: warnings on
135 * LWARN_NONE: all warnings ignored 135 * LWARN_NONE: all warnings ignored
136 * 0..n: warning n ignored 136 * 0..n: warning n ignored
137 */ 137 */
138int lwarn = LWARN_ALL; 138int lwarn = LWARN_ALL;
139 139
140/* 140/*
141 * Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE 141 * Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE
142 * directive. 142 * directive.
143 */ 143 */
144int bitfieldtype_ok; 144int bitfieldtype_ok;
145 145
146/* 146/*
147 * Nonzero if complaints about use of "long long" are suppressed in 147 * Nonzero if complaints about use of "long long" are suppressed in
148 * the next statement or declaration. 148 * the next statement or declaration.
149 */ 149 */
150int quadflg; 150int quadflg;
151 151
152/* 152/*
153 * Puts a new element at the top of the stack used for control statements. 153 * Puts a new element at the top of the stack used for control statements.
154 */ 154 */
155void 155void
156pushctrl(int env) 156pushctrl(int env)
157{ 157{
158 cstk_t *ci; 158 cstk_t *ci;
159 159
160 ci = xcalloc(1, sizeof (cstk_t)); 160 ci = xcalloc(1, sizeof (cstk_t));
161 ci->c_env = env; 161 ci->c_env = env;
162 ci->c_next = cstk; 162 ci->c_next = cstk;
163 cstk = ci; 163 cstk = ci;
164} 164}
165 165
166/* 166/*
167 * Removes the top element of the stack used for control statements. 167 * Removes the top element of the stack used for control statements.
168 */ 168 */
169void 169void
170popctrl(int env) 170popctrl(int env)
171{ 171{
172 cstk_t *ci; 172 cstk_t *ci;
173 clst_t *cl; 173 clst_t *cl;
174 174
175 lint_assert(cstk != NULL); 175 lint_assert(cstk != NULL);
176 lint_assert(cstk->c_env == env); 176 lint_assert(cstk->c_env == env);
177 177
178 cstk = (ci = cstk)->c_next; 178 cstk = (ci = cstk)->c_next;
179 179
180 while ((cl = ci->c_clst) != NULL) { 180 while ((cl = ci->c_clst) != NULL) {
181 ci->c_clst = cl->cl_next; 181 ci->c_clst = cl->cl_next;
182 free(cl); 182 free(cl);
183 } 183 }
184 184
185 if (ci->c_swtype != NULL) 185 if (ci->c_swtype != NULL)
186 free(ci->c_swtype); 186 free(ci->c_swtype);
187 187
188 free(ci); 188 free(ci);
189} 189}
190 190
191/* 191/*
192 * Prints a warning if a statement cannot be reached. 192 * Prints a warning if a statement cannot be reached.
193 */ 193 */
194void 194void
195check_statement_reachable(void) 195check_statement_reachable(void)
196{ 196{
197 if (!reached && !rchflg) { 197 if (!reached && !rchflg) {
198 /* statement not reached */ 198 /* statement not reached */
199 warning(193); 199 warning(193);
200 reached = 1; 200 reached = 1;
201 } 201 }
202} 202}
203 203
204/* 204/*
205 * Called after a function declaration which introduces a function definition 205 * Called after a function declaration which introduces a function definition
206 * and before an (optional) old style argument declaration list. 206 * and before an (optional) old style argument declaration list.
207 * 207 *
208 * Puts all symbols declared in the prototype or in an old style argument 208 * Puts all symbols declared in the prototype or in an old style argument
209 * list back to the symbol table. 209 * list back to the symbol table.
210 * 210 *
211 * Does the usual checking of storage class, type (return value), 211 * Does the usual checking of storage class, type (return value),
212 * redeclaration, etc. 212 * redeclaration, etc.
213 */ 213 */
214void 214void
215funcdef(sym_t *fsym) 215funcdef(sym_t *fsym)
216{ 216{
217 int n, dowarn; 217 int n, dowarn;
218 sym_t *arg, *sym, *rdsym; 218 sym_t *arg, *sym, *rdsym;
219 219
220 funcsym = fsym; 220 funcsym = fsym;
221 221
222 /* 222 /*
223 * Put all symbols declared in the argument list back to the 223 * Put all symbols declared in the argument list back to the
224 * symbol table. 224 * symbol table.
225 */ 225 */
226 for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) { 226 for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) {
227 if (sym->s_blklev != -1) { 227 if (sym->s_blklev != -1) {
228 lint_assert(sym->s_blklev == 1); 228 lint_assert(sym->s_blklev == 1);
229 inssym(1, sym); 229 inssym(1, sym);
230 } 230 }
231 } 231 }
232 232
233 /* 233 /*
234 * In old_style_function() we did not know whether it is an old 234 * In old_style_function() we did not know whether it is an old
235 * style function definition or only an old style declaration, 235 * style function definition or only an old style declaration,
236 * if there are no arguments inside the argument list ("f()"). 236 * if there are no arguments inside the argument list ("f()").
237 */ 237 */
238 if (!fsym->s_type->t_proto && fsym->s_args == NULL) 238 if (!fsym->s_type->t_proto && fsym->s_args == NULL)
239 fsym->s_osdef = 1; 239 fsym->s_osdef = 1;
240 240
241 check_type(fsym); 241 check_type(fsym);
242 242
243 /* 243 /*
244 * check_type() checks for almost all possible errors, but not for 244 * check_type() checks for almost all possible errors, but not for
245 * incomplete return values (these are allowed in declarations) 245 * incomplete return values (these are allowed in declarations)
246 */ 246 */
247 if (fsym->s_type->t_subt->t_tspec != VOID && 247 if (fsym->s_type->t_subt->t_tspec != VOID &&
248 incompl(fsym->s_type->t_subt)) { 248 incompl(fsym->s_type->t_subt)) {
249 /* cannot return incomplete type */ 249 /* cannot return incomplete type */
250 error(67); 250 error(67);
251 } 251 }
252 252
253 fsym->s_def = DEF; 253 fsym->s_def = DEF;
254 254
255 if (fsym->s_scl == TYPEDEF) { 255 if (fsym->s_scl == TYPEDEF) {
256 fsym->s_scl = EXTERN; 256 fsym->s_scl = EXTERN;
257 /* illegal storage class */ 257 /* illegal storage class */
258 error(8); 258 error(8);
259 } 259 }
260 260
261 if (dcs->d_inline) 261 if (dcs->d_inline)
262 fsym->s_inline = 1; 262 fsym->s_inline = 1;
263 263
264 /* 264 /*
265 * Arguments in new style function declarations need a name. 265 * Arguments in new style function declarations need a name.
266 * (void is already removed from the list of arguments) 266 * (void is already removed from the list of arguments)
267 */ 267 */
268 n = 1; 268 n = 1;
269 for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) { 269 for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_next) {
270 if (arg->s_scl == ABSTRACT) { 270 if (arg->s_scl == ABSTRACT) {
271 lint_assert(arg->s_name == unnamed); 271 lint_assert(arg->s_name == unnamed);
272 /* formal parameter lacks name: param #%d */ 272 /* formal parameter lacks name: param #%d */
273 error(59, n); 273 error(59, n);
274 } else { 274 } else {
275 lint_assert(arg->s_name != unnamed); 275 lint_assert(arg->s_name != unnamed);
276 } 276 }
277 n++; 277 n++;
278 } 278 }
279 279
280 /* 280 /*
281 * We must also remember the position. s_def_pos is overwritten 281 * We must also remember the position. s_def_pos is overwritten
282 * if this is an old style definition and we had already a 282 * if this is an old style definition and we had already a
283 * prototype. 283 * prototype.
284 */ 284 */
285 dcs->d_fdpos = fsym->s_def_pos; 285 dcs->d_fdpos = fsym->s_def_pos;
286 286
287 if ((rdsym = dcs->d_rdcsym) != NULL) { 287 if ((rdsym = dcs->d_rdcsym) != NULL) {
288 288
289 if (!check_redeclaration(fsym, (dowarn = 0, &dowarn))) { 289 if (!check_redeclaration(fsym, (dowarn = 0, &dowarn))) {
290 290
291 /* 291 /*
292 * Print nothing if the newly defined function 292 * Print nothing if the newly defined function
293 * is defined in old style. A better warning will 293 * is defined in old style. A better warning will
294 * be printed in check_func_lint_directives(). 294 * be printed in check_func_lint_directives().
295 */ 295 */
296 if (dowarn && !fsym->s_osdef) { 296 if (dowarn && !fsym->s_osdef) {
297 /* redeclaration of %s */ 297 /* redeclaration of %s */
298 (*(sflag ? error : warning))(27, fsym->s_name); 298 (*(sflag ? error : warning))(27, fsym->s_name);
299 print_previous_declaration(-1, rdsym); 299 print_previous_declaration(-1, rdsym);
300 } 300 }
301 301
302 /* copy usage information */ 302 /* copy usage information */
303 copy_usage_info(fsym, rdsym); 303 copy_usage_info(fsym, rdsym);
304 304
305 /* 305 /*
306 * If the old symbol was a prototype and the new 306 * If the old symbol was a prototype and the new
307 * one is none, overtake the position of the 307 * one is none, overtake the position of the
308 * declaration of the prototype. 308 * declaration of the prototype.
309 */ 309 */
310 if (fsym->s_osdef && rdsym->s_type->t_proto) 310 if (fsym->s_osdef && rdsym->s_type->t_proto)
311 fsym->s_def_pos = rdsym->s_def_pos; 311 fsym->s_def_pos = rdsym->s_def_pos;
312 312
313 /* complete the type */ 313 /* complete the type */
314 complete_type(fsym, rdsym); 314 complete_type(fsym, rdsym);
315 315
316 /* once a function is inline it remains inline */ 316 /* once a function is inline it remains inline */
317 if (rdsym->s_inline) 317 if (rdsym->s_inline)
318 fsym->s_inline = 1; 318 fsym->s_inline = 1;
319 319
320 } 320 }
321 321
322 /* remove the old symbol from the symbol table */ 322 /* remove the old symbol from the symbol table */
323 rmsym(rdsym); 323 rmsym(rdsym);
324 324
325 } 325 }
326 326
327 if (fsym->s_osdef && !fsym->s_type->t_proto) { 327 if (fsym->s_osdef && !fsym->s_type->t_proto) {
328 if (sflag && hflag && strcmp(fsym->s_name, "main") != 0) 328 if (sflag && hflag && strcmp(fsym->s_name, "main") != 0)
329 /* function definition is not a prototype */ 329 /* function definition is not a prototype */
330 warning(286); 330 warning(286);
331 } 331 }
332 332
333 if (dcs->d_notyp) 333 if (dcs->d_notyp)
334 /* return value is implicitly declared to be int */ 334 /* return value is implicitly declared to be int */
335 fsym->s_rimpl = 1; 335 fsym->s_rimpl = 1;
336 336
337 reached = 1; 337 reached = 1;
338} 338}
339 339
340/* 340/*
341 * Called at the end of a function definition. 341 * Called at the end of a function definition.
342 */ 342 */
343void 343void
344funcend(void) 344funcend(void)
345{ 345{
346 sym_t *arg; 346 sym_t *arg;
347 int n; 347 int n;
348 348
349 if (reached) { 349 if (reached) {
350 cstk->c_noretval = 1; 350 cstk->c_noretval = 1;
351 if (funcsym->s_type->t_subt->t_tspec != VOID && 351 if (funcsym->s_type->t_subt->t_tspec != VOID &&
352 !funcsym->s_rimpl) { 352 !funcsym->s_rimpl) {
353 /* func. %s falls off bottom without returning value */ 353 /* func. %s falls off bottom without returning value */
354 warning(217, funcsym->s_name); 354 warning(217, funcsym->s_name);
355 } 355 }
356 } 356 }
357 357
358 /* 358 /*
359 * This warning is printed only if the return value was implicitly 359 * This warning is printed only if the return value was implicitly
360 * declared to be int. Otherwise the wrong return statement 360 * declared to be int. Otherwise the wrong return statement
361 * has already printed a warning. 361 * has already printed a warning.
362 */ 362 */
363 if (cstk->c_noretval && cstk->c_retval && funcsym->s_rimpl) 363 if (cstk->c_noretval && cstk->c_retval && funcsym->s_rimpl)
364 /* function %s has return (e); and return; */ 364 /* function %s has return (e); and return; */
365 warning(216, funcsym->s_name); 365 warning(216, funcsym->s_name);
366 366
367 /* Print warnings for unused arguments */ 367 /* Print warnings for unused arguments */
368 arg = dcs->d_fargs; 368 arg = dcs->d_fargs;
369 n = 0; 369 n = 0;
370 while (arg != NULL && (nargusg == -1 || n < nargusg)) { 370 while (arg != NULL && (nargusg == -1 || n < nargusg)) {
371 check_usage_sym(dcs->d_asm, arg); 371 check_usage_sym(dcs->d_asm, arg);
372 arg = arg->s_next; 372 arg = arg->s_next;
373 n++; 373 n++;
374 } 374 }
375 nargusg = -1; 375 nargusg = -1;
376 376
377 /* 377 /*
378 * write the information about the function definition to the 378 * write the information about the function definition to the
379 * output file 379 * output file
380 * inline functions explicitly declared extern are written as 380 * inline functions explicitly declared extern are written as
381 * declarations only. 381 * declarations only.
382 */ 382 */
383 if (dcs->d_scl == EXTERN && funcsym->s_inline) { 383 if (dcs->d_scl == EXTERN && funcsym->s_inline) {
384 outsym(funcsym, funcsym->s_scl, DECL); 384 outsym(funcsym, funcsym->s_scl, DECL);
385 } else { 385 } else {
386 outfdef(funcsym, &dcs->d_fdpos, cstk->c_retval, 386 outfdef(funcsym, &dcs->d_fdpos, cstk->c_retval,
387 funcsym->s_osdef, dcs->d_fargs); 387 funcsym->s_osdef, dcs->d_fargs);
388 } 388 }
389 389
390 /* 390 /*
391 * remove all symbols declared during argument declaration from 391 * remove all symbols declared during argument declaration from
392 * the symbol table 392 * the symbol table
393 */ 393 */
394 lint_assert(dcs->d_next == NULL); 394 lint_assert(dcs->d_next == NULL);
395 lint_assert(dcs->d_ctx == EXTERN); 395 lint_assert(dcs->d_ctx == EXTERN);
396 rmsyms(dcs->d_fpsyms); 396 rmsyms(dcs->d_fpsyms);
397 397
398 /* must be set on level 0 */ 398 /* must be set on level 0 */
399 reached = 1; 399 reached = 1;
400} 400}
401 401
402/* 
403 * Process a label. 
404 * 
405 * typ type of the label (T_NAME, T_DEFAULT or T_CASE). 
406 * sym symbol table entry of label if typ == T_NAME 
407 * tn expression if typ == T_CASE 
408 */ 
409void 402void
410label(int typ, sym_t *sym, tnode_t *tn) 403named_label(sym_t *sym)
 404{
 405
 406 if (sym->s_set) {
 407 /* label %s redefined */
 408 error(194, sym->s_name);
 409 } else {
 410 mark_as_set(sym);
 411 }
 412
 413 reached = 1;
 414}
 415
 416void
 417case_label(tnode_t *tn)
411{ 418{
412 cstk_t *ci; 419 cstk_t *ci;
413 clst_t *cl; 420 clst_t *cl;
414 val_t *v; 421 val_t *v;
415 val_t nv; 422 val_t nv;
416 tspec_t t; 423 tspec_t t;
417 424
418 switch (typ) { 425 /* find the stack entry for the innermost switch statement */
419 426 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next)
420 case T_NAME: 427 continue;
421 if (sym->s_set) { 
422 /* label %s redefined */ 
423 error(194, sym->s_name); 
424 } else { 
425 mark_as_set(sym); 
426 } 
427 break; 
428 
429 case T_CASE: 
430 428
431 /* find the stack entry for the innermost switch statement */ 429 if (ci == NULL) {
432 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) 430 /* case not in switch */
433 continue; 431 error(195);
434 432 tn = NULL;
435 if (ci == NULL) { 433 } else if (tn != NULL && tn->tn_op != CON) {
436 /* case not in switch */ 434 /* non-constant case expression */
437 error(195); 435 error(197);
438 tn = NULL; 436 tn = NULL;
439 } else if (tn != NULL && tn->tn_op != CON) { 437 } else if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
440 /* non-constant case expression */ 438 /* non-integral case expression */
441 error(197); 439 error(198);
442 tn = NULL; 440 tn = NULL;
443 } else if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { 441 }
444 /* non-integral case expression */ 
445 error(198); 
446 tn = NULL; 
447 } 
448 442
449 if (tn != NULL) { 443 if (tn != NULL) {
450 444
451 lint_assert(ci->c_swtype != NULL); 445 lint_assert(ci->c_swtype != NULL);
452 446
453 if (reached && !ftflg) { 447 if (reached && !ftflg) {
454 if (hflag) 448 if (hflag)
455 /* fallthrough on case statement */ 449 /* fallthrough on case statement */
456 warning(220); 450 warning(220);
457 } 451 }
458 452
459 t = tn->tn_type->t_tspec; 453 t = tn->tn_type->t_tspec;
460 if (t == LONG || t == ULONG || 454 if (t == LONG || t == ULONG ||
461 t == QUAD || t == UQUAD) { 455 t == QUAD || t == UQUAD) {
462 if (tflag) 456 if (tflag)
463 /* case label must be of type ... */ 457 /* case label must be of type ... */
464 warning(203); 458 warning(203);
465 } 459 }
466 460
 461 /*
 462 * get the value of the expression and convert it
 463 * to the type of the switch expression
 464 */
 465 v = constant(tn, 1);
 466 (void) memset(&nv, 0, sizeof nv);
 467 cvtcon(CASE, 0, ci->c_swtype, &nv, v);
 468 free(v);
 469
 470 /* look if we had this value already */
 471 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) {
 472 if (cl->cl_val.v_quad == nv.v_quad)
 473 break;
 474 }
 475 if (cl != NULL && tspec_is_uint(nv.v_tspec)) {
 476 /* duplicate case in switch: %lu */
 477 error(200, (u_long)nv.v_quad);
 478 } else if (cl != NULL) {
 479 /* duplicate case in switch: %ld */
 480 error(199, (long)nv.v_quad);
 481 } else {
467 /* 482 /*
468 * get the value of the expression and convert it 483 * append the value to the list of
469 * to the type of the switch expression 484 * case values
470 */ 485 */
471 v = constant(tn, 1); 486 cl = xcalloc(1, sizeof (clst_t));
472 (void) memset(&nv, 0, sizeof nv); 487 cl->cl_val = nv;
473 cvtcon(CASE, 0, ci->c_swtype, &nv, v); 488 cl->cl_next = ci->c_clst;
474 free(v); 489 ci->c_clst = cl;
475 
476 /* look if we had this value already */ 
477 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) { 
478 if (cl->cl_val.v_quad == nv.v_quad) 
479 break; 
480 } 
481 if (cl != NULL && tspec_is_uint(nv.v_tspec)) { 
482 /* duplicate case in switch: %lu */ 
483 error(200, (u_long)nv.v_quad); 
484 } else if (cl != NULL) { 
485 /* duplicate case in switch: %ld */ 
486 error(199, (long)nv.v_quad); 
487 } else { 
488 /* 
489 * append the value to the list of 
490 * case values 
491 */ 
492 cl = xcalloc(1, sizeof (clst_t)); 
493 cl->cl_val = nv; 
494 cl->cl_next = ci->c_clst; 
495 ci->c_clst = cl; 
496 } 
497 } 490 }
498 tfreeblk(); 491 }
499 break; 492 tfreeblk();
 493
 494 reached = 1;
 495}
500 496
501 case T_DEFAULT: 497void
 498default_label(void)
 499{
 500 cstk_t *ci;
502 501
503 /* find the stack entry for the innermost switch statement */ 502 /* find the stack entry for the innermost switch statement */
504 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) 503 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next)
505 continue; 504 continue;
506 505
507 if (ci == NULL) { 506 if (ci == NULL) {
508 /* default outside switch */ 507 /* default outside switch */
509 error(201); 508 error(201);
510 } else if (ci->c_default) { 509 } else if (ci->c_default) {
511 /* duplicate default in switch */ 510 /* duplicate default in switch */
512 error(202); 511 error(202);
513 } else { 512 } else {
514 if (reached && !ftflg) { 513 if (reached && !ftflg) {
515 if (hflag) 514 if (hflag)
516 /* fallthrough on default statement */ 515 /* fallthrough on default statement */
517 warning(284); 516 warning(284);
518 } 
519 ci->c_default = 1; 
520 } 517 }
521 break; 518 ci->c_default = 1;
522 }; 519 }
 520
523 reached = 1; 521 reached = 1;
524} 522}
525 523
526static tnode_t * 524static tnode_t *
527check_controlling_expression(tnode_t *tn) 525check_controlling_expression(tnode_t *tn)
528{ 526{
529 tspec_t t = tn->tn_type->t_tspec; 527 tspec_t t = tn->tn_type->t_tspec;
530 528
531 if (tn != NULL) 529 if (tn != NULL)
532 tn = cconv(tn); 530 tn = cconv(tn);
533 if (tn != NULL) 531 if (tn != NULL)
534 tn = promote(NOOP, 0, tn); 532 tn = promote(NOOP, 0, tn);
535 533
536 if (tn != NULL && !tspec_is_scalar(t)) { 534 if (tn != NULL && !tspec_is_scalar(t)) {
537 /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */ 535 /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */
538 /* C99 6.8.4.1p1 for if statements */ 536 /* C99 6.8.4.1p1 for if statements */
539 /* C99 6.8.5p2 for while, do and for loops */ 537 /* C99 6.8.5p2 for while, do and for loops */
540 /* controlling expressions must have scalar type */ 538 /* controlling expressions must have scalar type */
541 error(204); 539 error(204);
542 return NULL; 540 return NULL;
543 } 541 }
544 542
545 return tn; 543 return tn;
546} 544}
547 545
548/* 546/*
549 * T_IF T_LPARN expr T_RPARN 547 * T_IF T_LPARN expr T_RPARN
550 */ 548 */
551void 549void
552if1(tnode_t *tn) 550if1(tnode_t *tn)
553{ 551{
554 552
555 if (tn != NULL) 553 if (tn != NULL)
556 tn = check_controlling_expression(tn); 554 tn = check_controlling_expression(tn);
557 if (tn != NULL) 555 if (tn != NULL)
558 expr(tn, 0, 1, 0); 556 expr(tn, 0, 1, 0);
559 pushctrl(T_IF); 557 pushctrl(T_IF);
560} 558}
561 559
562/* 560/*
563 * if_without_else 561 * if_without_else
564 * if_without_else T_ELSE 562 * if_without_else T_ELSE
565 */ 563 */
566void 564void
567if2(void) 565if2(void)
568{ 566{
569 567
570 cstk->c_rchif = reached ? 1 : 0; 568 cstk->c_rchif = reached ? 1 : 0;
571 reached = 1; 569 reached = 1;
572} 570}
573 571
574/* 572/*
575 * if_without_else 573 * if_without_else
576 * if_without_else T_ELSE stmnt 574 * if_without_else T_ELSE stmnt
577 */ 575 */
578void 576void
579if3(int els) 577if3(int els)
580{ 578{
581 579
582 if (els) { 580 if (els) {
583 reached |= cstk->c_rchif; 581 reached |= cstk->c_rchif;
584 } else { 582 } else {
585 reached = 1; 583 reached = 1;
586 } 584 }
587 popctrl(T_IF); 585 popctrl(T_IF);
588} 586}
589 587
590/* 588/*
591 * T_SWITCH T_LPARN expr T_RPARN 589 * T_SWITCH T_LPARN expr T_RPARN
592 */ 590 */
593void 591void
594switch1(tnode_t *tn) 592switch1(tnode_t *tn)
595{ 593{
596 tspec_t t; 594 tspec_t t;
597 type_t *tp; 595 type_t *tp;
598 596
599 if (tn != NULL) 597 if (tn != NULL)
600 tn = cconv(tn); 598 tn = cconv(tn);
601 if (tn != NULL) 599 if (tn != NULL)
602 tn = promote(NOOP, 0, tn); 600 tn = promote(NOOP, 0, tn);
603 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { 601 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
604 /* switch expression must have integral type */ 602 /* switch expression must have integral type */
605 error(205); 603 error(205);
606 tn = NULL; 604 tn = NULL;
607 } 605 }
608 if (tn != NULL && tflag) { 606 if (tn != NULL && tflag) {
609 t = tn->tn_type->t_tspec; 607 t = tn->tn_type->t_tspec;
610 if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) { 608 if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) {
611 /* switch expr. must be of type `int' in trad. C */ 609 /* switch expr. must be of type `int' in trad. C */
612 warning(271); 610 warning(271);
613 } 611 }
614 } 612 }
615 613
616 /* 614 /*
617 * Remember the type of the expression. Because it's possible 615 * Remember the type of the expression. Because it's possible
618 * that (*tp) is allocated on tree memory, the type must be 616 * that (*tp) is allocated on tree memory, the type must be
619 * duplicated. This is not too complicated because it is 617 * duplicated. This is not too complicated because it is
620 * only an integer type. 618 * only an integer type.
621 */ 619 */
622 tp = xcalloc(1, sizeof (type_t)); 620 tp = xcalloc(1, sizeof (type_t));
623 if (tn != NULL) { 621 if (tn != NULL) {
624 tp->t_tspec = tn->tn_type->t_tspec; 622 tp->t_tspec = tn->tn_type->t_tspec;
625 if ((tp->t_isenum = tn->tn_type->t_isenum) != 0) 623 if ((tp->t_isenum = tn->tn_type->t_isenum) != 0)
626 tp->t_enum = tn->tn_type->t_enum; 624 tp->t_enum = tn->tn_type->t_enum;
627 } else { 625 } else {
628 tp->t_tspec = INT; 626 tp->t_tspec = INT;
629 } 627 }
630 628
631 expr(tn, 1, 0, 1); 629 expr(tn, 1, 0, 1);
632 630
633 pushctrl(T_SWITCH); 631 pushctrl(T_SWITCH);
634 cstk->c_switch = 1; 632 cstk->c_switch = 1;
635 cstk->c_swtype = tp; 633 cstk->c_swtype = tp;
636 634
637 reached = rchflg = 0; 635 reached = rchflg = 0;
638 ftflg = 1; 636 ftflg = 1;
639} 637}
640 638
641/* 639/*
642 * switch_expr stmnt 640 * switch_expr stmnt
643 */ 641 */
644void 642void
645switch2(void) 643switch2(void)
646{ 644{
647 int nenum = 0, nclab = 0; 645 int nenum = 0, nclab = 0;
648 sym_t *esym; 646 sym_t *esym;
649 clst_t *cl; 647 clst_t *cl;
650 648
651 lint_assert(cstk->c_swtype != NULL); 649 lint_assert(cstk->c_swtype != NULL);
652 650
653 /* 651 /*
654 * If the switch expression was of type enumeration, count the case 652 * If the switch expression was of type enumeration, count the case
655 * labels and the number of enumerators. If both counts are not 653 * labels and the number of enumerators. If both counts are not
656 * equal print a warning. 654 * equal print a warning.
657 */ 655 */
658 if (cstk->c_swtype->t_isenum) { 656 if (cstk->c_swtype->t_isenum) {
659 nenum = nclab = 0; 657 nenum = nclab = 0;
660 lint_assert(cstk->c_swtype->t_enum != NULL); 658 lint_assert(cstk->c_swtype->t_enum != NULL);
661 for (esym = cstk->c_swtype->t_enum->elem; 659 for (esym = cstk->c_swtype->t_enum->elem;
662 esym != NULL; esym = esym->s_next) { 660 esym != NULL; esym = esym->s_next) {
663 nenum++; 661 nenum++;
664 } 662 }
665 for (cl = cstk->c_clst; cl != NULL; cl = cl->cl_next) 663 for (cl = cstk->c_clst; cl != NULL; cl = cl->cl_next)
666 nclab++; 664 nclab++;
667 if (hflag && eflag && nenum != nclab && !cstk->c_default) { 665 if (hflag && eflag && nenum != nclab && !cstk->c_default) {
668 /* enumeration value(s) not handled in switch */ 666 /* enumeration value(s) not handled in switch */
669 warning(206); 667 warning(206);
670 } 668 }
671 } 669 }
672 670
673 if (cstk->c_break) { 671 if (cstk->c_break) {
674 /* 672 /*
675 * end of switch alway reached (c_break is only set if the 673 * end of switch alway reached (c_break is only set if the
676 * break statement can be reached). 674 * break statement can be reached).
677 */ 675 */
678 reached = 1; 676 reached = 1;
679 } else if (!cstk->c_default && 677 } else if (!cstk->c_default &&
680 (!hflag || !cstk->c_swtype->t_isenum || nenum != nclab)) { 678 (!hflag || !cstk->c_swtype->t_isenum || nenum != nclab)) {
681 /* 679 /*
682 * there are possible values which are not handled in 680 * there are possible values which are not handled in
683 * switch 681 * switch
684 */ 682 */
685 reached = 1; 683 reached = 1;
686 } /* 684 } /*
687 * otherwise the end of the switch expression is reached 685 * otherwise the end of the switch expression is reached
688 * if the end of the last statement inside it is reached. 686 * if the end of the last statement inside it is reached.
689 */ 687 */
690 688
691 popctrl(T_SWITCH); 689 popctrl(T_SWITCH);
692} 690}
693 691
694/* 692/*
695 * T_WHILE T_LPARN expr T_RPARN 693 * T_WHILE T_LPARN expr T_RPARN
696 */ 694 */
697void 695void
698while1(tnode_t *tn) 696while1(tnode_t *tn)
699{ 697{
700 698
701 if (!reached) { 699 if (!reached) {
702 /* loop not entered at top */ 700 /* loop not entered at top */
703 warning(207); 701 warning(207);
704 reached = 1; 702 reached = 1;
705 } 703 }
706 704
707 if (tn != NULL) 705 if (tn != NULL)
708 tn = check_controlling_expression(tn); 706 tn = check_controlling_expression(tn);
709 707
710 pushctrl(T_WHILE); 708 pushctrl(T_WHILE);
711 cstk->c_loop = 1; 709 cstk->c_loop = 1;
712 if (tn != NULL && tn->tn_op == CON) { 710 if (tn != NULL && tn->tn_op == CON) {
713 if (tspec_is_int(tn->tn_type->t_tspec)) { 711 if (tspec_is_int(tn->tn_type->t_tspec)) {
714 cstk->c_infinite = tn->tn_val->v_quad != 0; 712 cstk->c_infinite = tn->tn_val->v_quad != 0;
715 } else { 713 } else {
716 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; 714 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
717 } 715 }
718 } 716 }
719 717
720 expr(tn, 0, 1, 1); 718 expr(tn, 0, 1, 1);
721} 719}
722 720
723/* 721/*
724 * while_expr stmnt 722 * while_expr stmnt
725 * while_expr error 723 * while_expr error
726 */ 724 */
727void 725void
728while2(void) 726while2(void)
729{ 727{
730 728
731 /* 729 /*
732 * The end of the loop can be reached if it is no endless loop 730 * The end of the loop can be reached if it is no endless loop
733 * or there was a break statement which was reached. 731 * or there was a break statement which was reached.
734 */ 732 */
735 reached = !cstk->c_infinite || cstk->c_break; 733 reached = !cstk->c_infinite || cstk->c_break;
736 rchflg = 0; 734 rchflg = 0;
737 735
738 popctrl(T_WHILE); 736 popctrl(T_WHILE);
739} 737}
740 738
741/* 739/*
742 * T_DO 740 * T_DO
743 */ 741 */
744void 742void
745do1(void) 743do1(void)
746{ 744{
747 745
748 if (!reached) { 746 if (!reached) {
749 /* loop not entered at top */ 747 /* loop not entered at top */
750 warning(207); 748 warning(207);
751 reached = 1; 749 reached = 1;
752 } 750 }
753 751
754 pushctrl(T_DO); 752 pushctrl(T_DO);
755 cstk->c_loop = 1; 753 cstk->c_loop = 1;
756} 754}
757 755
758/* 756/*
759 * do stmnt do_while_expr 757 * do stmnt do_while_expr
760 * do error 758 * do error
761 */ 759 */
762void 760void
763do2(tnode_t *tn) 761do2(tnode_t *tn)
764{ 762{
765 763
766 /* 764 /*
767 * If there was a continue statement, the expression controlling the 765 * If there was a continue statement, the expression controlling the
768 * loop is reached. 766 * loop is reached.
769 */ 767 */
770 if (cstk->c_cont) 768 if (cstk->c_cont)
771 reached = 1; 769 reached = 1;
772 770
773 if (tn != NULL) 771 if (tn != NULL)
774 tn = check_controlling_expression(tn); 772 tn = check_controlling_expression(tn);
775 773
776 if (tn != NULL && tn->tn_op == CON) { 774 if (tn != NULL && tn->tn_op == CON) {
777 if (tspec_is_int(tn->tn_type->t_tspec)) { 775 if (tspec_is_int(tn->tn_type->t_tspec)) {
778 cstk->c_infinite = tn->tn_val->v_quad != 0; 776 cstk->c_infinite = tn->tn_val->v_quad != 0;
779 } else { 777 } else {
780 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; 778 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
781 } 779 }
782 if (!cstk->c_infinite && cstk->c_cont) 780 if (!cstk->c_infinite && cstk->c_cont)
783 error(323); 781 error(323);
784 } 782 }
785 783
786 expr(tn, 0, 1, 1); 784 expr(tn, 0, 1, 1);
787 785
788 /* 786 /*
789 * The end of the loop is only reached if it is no endless loop 787 * The end of the loop is only reached if it is no endless loop
790 * or there was a break statement which could be reached. 788 * or there was a break statement which could be reached.
791 */ 789 */
792 reached = !cstk->c_infinite || cstk->c_break; 790 reached = !cstk->c_infinite || cstk->c_break;
793 rchflg = 0; 791 rchflg = 0;
794 792
795 popctrl(T_DO); 793 popctrl(T_DO);
796} 794}
797 795
798/* 796/*
799 * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN 797 * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN
800 */ 798 */
801void 799void
802for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) 800for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
803{ 801{
804 802
805 /* 803 /*
806 * If there is no initialisation expression it is possible that 804 * If there is no initialisation expression it is possible that
807 * it is intended not to enter the loop at top. 805 * it is intended not to enter the loop at top.
808 */ 806 */
809 if (tn1 != NULL && !reached) { 807 if (tn1 != NULL && !reached) {
810 /* loop not entered at top */ 808 /* loop not entered at top */
811 warning(207); 809 warning(207);
812 reached = 1; 810 reached = 1;
813 } 811 }
814 812
815 pushctrl(T_FOR); 813 pushctrl(T_FOR);
816 cstk->c_loop = 1; 814 cstk->c_loop = 1;
817 815
818 /* 816 /*
819 * Store the tree memory for the reinitialisation expression. 817 * Store the tree memory for the reinitialisation expression.
820 * Also remember this expression itself. We must check it at 818 * Also remember this expression itself. We must check it at
821 * the end of the loop to get "used but not set" warnings correct. 819 * the end of the loop to get "used but not set" warnings correct.
822 */ 820 */
823 cstk->c_fexprm = tsave(); 821 cstk->c_fexprm = tsave();
824 cstk->c_f3expr = tn3; 822 cstk->c_f3expr = tn3;
825 cstk->c_fpos = curr_pos; 823 cstk->c_fpos = curr_pos;
826 cstk->c_cfpos = csrc_pos; 824 cstk->c_cfpos = csrc_pos;
827 825
828 if (tn1 != NULL) 826 if (tn1 != NULL)
829 expr(tn1, 0, 0, 1); 827 expr(tn1, 0, 0, 1);
830 828
831 if (tn2 != NULL) 829 if (tn2 != NULL)
832 tn2 = check_controlling_expression(tn2); 830 tn2 = check_controlling_expression(tn2);
833 if (tn2 != NULL) 831 if (tn2 != NULL)
834 expr(tn2, 0, 1, 1); 832 expr(tn2, 0, 1, 1);
835 833
836 if (tn2 == NULL) { 834 if (tn2 == NULL) {
837 cstk->c_infinite = 1; 835 cstk->c_infinite = 1;
838 } else if (tn2->tn_op == CON) { 836 } else if (tn2->tn_op == CON) {
839 if (tspec_is_int(tn2->tn_type->t_tspec)) { 837 if (tspec_is_int(tn2->tn_type->t_tspec)) {
840 cstk->c_infinite = tn2->tn_val->v_quad != 0; 838 cstk->c_infinite = tn2->tn_val->v_quad != 0;
841 } else { 839 } else {
842 cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0; 840 cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0;
843 } 841 }
844 } 842 }
845 843
846 /* Checking the reinitialisation expression is done in for2() */ 844 /* Checking the reinitialisation expression is done in for2() */
847 845
848 reached = 1; 846 reached = 1;
849} 847}
850 848
851/* 849/*
852 * for_exprs stmnt 850 * for_exprs stmnt
853 * for_exprs error 851 * for_exprs error
854 */ 852 */
855void 853void
856for2(void) 854for2(void)
857{ 855{
858 pos_t cpos, cspos; 856 pos_t cpos, cspos;
859 tnode_t *tn3; 857 tnode_t *tn3;
860 858
861 if (cstk->c_cont) 859 if (cstk->c_cont)
862 reached = 1; 860 reached = 1;
863 861
864 cpos = curr_pos; 862 cpos = curr_pos;
865 cspos = csrc_pos; 863 cspos = csrc_pos;
866 864
867 /* Restore the tree memory for the reinitialisation expression */ 865 /* Restore the tree memory for the reinitialisation expression */
868 trestor(cstk->c_fexprm); 866 trestor(cstk->c_fexprm);
869 tn3 = cstk->c_f3expr; 867 tn3 = cstk->c_f3expr;
870 curr_pos = cstk->c_fpos; 868 curr_pos = cstk->c_fpos;
871 csrc_pos = cstk->c_cfpos; 869 csrc_pos = cstk->c_cfpos;
872 870
873 /* simply "statement not reached" would be confusing */ 871 /* simply "statement not reached" would be confusing */
874 if (!reached && !rchflg) { 872 if (!reached && !rchflg) {
875 /* end-of-loop code not reached */ 873 /* end-of-loop code not reached */
876 warning(223); 874 warning(223);
877 reached = 1; 875 reached = 1;
878 } 876 }
879 877
880 if (tn3 != NULL) { 878 if (tn3 != NULL) {
881 expr(tn3, 0, 0, 1); 879 expr(tn3, 0, 0, 1);
882 } else { 880 } else {
883 tfreeblk(); 881 tfreeblk();
884 } 882 }
885 883
886 curr_pos = cpos; 884 curr_pos = cpos;
887 csrc_pos = cspos; 885 csrc_pos = cspos;
888 886
889 /* An endless loop without break will never terminate */ 887 /* An endless loop without break will never terminate */
890 reached = cstk->c_break || !cstk->c_infinite; 888 reached = cstk->c_break || !cstk->c_infinite;
891 rchflg = 0; 889 rchflg = 0;
892 890
893 popctrl(T_FOR); 891 popctrl(T_FOR);
894} 892}
895 893
896/* 894/*
897 * T_GOTO identifier T_SEMI 895 * T_GOTO identifier T_SEMI
898 * T_GOTO error T_SEMI 896 * T_GOTO error T_SEMI
899 */ 897 */
900void 898void
901dogoto(sym_t *lab) 899dogoto(sym_t *lab)
902{ 900{
903 901
904 mark_as_used(lab, 0, 0); 902 mark_as_used(lab, 0, 0);
905 903
906 check_statement_reachable(); 904 check_statement_reachable();
907 905
908 reached = rchflg = 0; 906 reached = rchflg = 0;
909} 907}
910 908
911/* 909/*
912 * T_BREAK T_SEMI 910 * T_BREAK T_SEMI
913 */ 911 */
914void 912void
915dobreak(void) 913dobreak(void)
916{ 914{
917 cstk_t *ci; 915 cstk_t *ci;
918 916
919 ci = cstk; 917 ci = cstk;
920 while (ci != NULL && !ci->c_loop && !ci->c_switch) 918 while (ci != NULL && !ci->c_loop && !ci->c_switch)
921 ci = ci->c_next; 919 ci = ci->c_next;
922 920
923 if (ci == NULL) { 921 if (ci == NULL) {
924 /* break outside loop or switch */ 922 /* break outside loop or switch */
925 error(208); 923 error(208);
926 } else { 924 } else {
927 if (reached) 925 if (reached)
928 ci->c_break = 1; 926 ci->c_break = 1;
929 } 927 }
930 928
931 if (bflag) 929 if (bflag)
932 check_statement_reachable(); 930 check_statement_reachable();
933 931
934 reached = rchflg = 0; 932 reached = rchflg = 0;
935} 933}
936 934
937/* 935/*
938 * T_CONTINUE T_SEMI 936 * T_CONTINUE T_SEMI
939 */ 937 */
940void 938void
941docont(void) 939docont(void)
942{ 940{
943 cstk_t *ci; 941 cstk_t *ci;
944 942
945 for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_next) 943 for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_next)
946 continue; 944 continue;
947 945
948 if (ci == NULL) { 946 if (ci == NULL) {
949 /* continue outside loop */ 947 /* continue outside loop */
950 error(209); 948 error(209);
951 } else { 949 } else {
952 ci->c_cont = 1; 950 ci->c_cont = 1;
953 } 951 }
954 952
955 check_statement_reachable(); 953 check_statement_reachable();
956 954
957 reached = rchflg = 0; 955 reached = rchflg = 0;
958} 956}
959 957
960/* 958/*
961 * T_RETURN T_SEMI 959 * T_RETURN T_SEMI
962 * T_RETURN expr T_SEMI 960 * T_RETURN expr T_SEMI
963 */ 961 */
964void 962void
965doreturn(tnode_t *tn) 963doreturn(tnode_t *tn)
966{ 964{
967 tnode_t *ln, *rn; 965 tnode_t *ln, *rn;
968 cstk_t *ci; 966 cstk_t *ci;
969 op_t op; 967 op_t op;
970 968
971 for (ci = cstk; ci->c_next != NULL; ci = ci->c_next) 969 for (ci = cstk; ci->c_next != NULL; ci = ci->c_next)
972 continue; 970 continue;
973 971
974 if (tn != NULL) { 972 if (tn != NULL) {
975 ci->c_retval = 1; 973 ci->c_retval = 1;
976 } else { 974 } else {
977 ci->c_noretval = 1; 975 ci->c_noretval = 1;
978 } 976 }
979 977
980 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { 978 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) {
981 /* void function %s cannot return value */ 979 /* void function %s cannot return value */
982 error(213, funcsym->s_name); 980 error(213, funcsym->s_name);
983 tfreeblk(); 981 tfreeblk();
984 tn = NULL; 982 tn = NULL;
985 } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { 983 } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) {
986 /* 984 /*
987 * Assume that the function has a return value only if it 985 * Assume that the function has a return value only if it
988 * is explicitly declared. 986 * is explicitly declared.
989 */ 987 */
990 if (!funcsym->s_rimpl) 988 if (!funcsym->s_rimpl)
991 /* function %s expects to return value */ 989 /* function %s expects to return value */
992 warning(214, funcsym->s_name); 990 warning(214, funcsym->s_name);
993 } 991 }
994 992
995 if (tn != NULL) { 993 if (tn != NULL) {
996 994
997 /* Create a temporary node for the left side */ 995 /* Create a temporary node for the left side */
998 ln = tgetblk(sizeof (tnode_t)); 996 ln = tgetblk(sizeof (tnode_t));
999 ln->tn_op = NAME; 997 ln->tn_op = NAME;
1000 ln->tn_type = tduptyp(funcsym->s_type->t_subt); 998 ln->tn_type = tduptyp(funcsym->s_type->t_subt);
1001 ln->tn_type->t_const = 0; 999 ln->tn_type->t_const = 0;
1002 ln->tn_lvalue = 1; 1000 ln->tn_lvalue = 1;
1003 ln->tn_sym = funcsym; /* better than nothing */ 1001 ln->tn_sym = funcsym; /* better than nothing */
1004 1002
1005 tn = build(RETURN, ln, tn); 1003 tn = build(RETURN, ln, tn);
1006 1004
1007 if (tn != NULL) { 1005 if (tn != NULL) {
1008 rn = tn->tn_right; 1006 rn = tn->tn_right;
1009 while ((op = rn->tn_op) == CVT || op == PLUS) 1007 while ((op = rn->tn_op) == CVT || op == PLUS)
1010 rn = rn->tn_left; 1008 rn = rn->tn_left;
1011 if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME && 1009 if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME &&
1012 rn->tn_left->tn_sym->s_scl == AUTO) { 1010 rn->tn_left->tn_sym->s_scl == AUTO) {
1013 /* %s returns pointer to automatic object */ 1011 /* %s returns pointer to automatic object */
1014 warning(302, funcsym->s_name); 1012 warning(302, funcsym->s_name);
1015 } 1013 }
1016 } 1014 }
1017 1015
1018 expr(tn, 1, 0, 1); 1016 expr(tn, 1, 0, 1);
1019 1017
1020 } else { 1018 } else {
1021 1019
1022 check_statement_reachable(); 1020 check_statement_reachable();
1023 1021
1024 } 1022 }
1025 1023
1026 reached = rchflg = 0; 1024 reached = rchflg = 0;
1027} 1025}
1028 1026
1029/* 1027/*
1030 * Do some cleanup after a global declaration or definition. 1028 * Do some cleanup after a global declaration or definition.
1031 * Especially remove information about unused lint comments. 1029 * Especially remove information about unused lint comments.
1032 */ 1030 */
1033void 1031void
1034global_clean_up_decl(int silent) 1032global_clean_up_decl(int silent)
1035{ 1033{
1036 pos_t cpos; 1034 pos_t cpos;
1037 1035
1038 cpos = curr_pos; 1036 cpos = curr_pos;
1039 1037
1040 if (nargusg != -1) { 1038 if (nargusg != -1) {
1041 if (!silent) { 1039 if (!silent) {
1042 curr_pos = argsused_pos; 1040 curr_pos = argsused_pos;
1043 /* must precede function definition: ** %s ** */ 1041 /* must precede function definition: ** %s ** */
1044 warning(282, "ARGSUSED"); 1042 warning(282, "ARGSUSED");
1045 } 1043 }
1046 nargusg = -1; 1044 nargusg = -1;
1047 } 1045 }
1048 if (nvararg != -1) { 1046 if (nvararg != -1) {
1049 if (!silent) { 1047 if (!silent) {
1050 curr_pos = vapos; 1048 curr_pos = vapos;
1051 /* must precede function definition: ** %s ** */ 1049 /* must precede function definition: ** %s ** */
1052 warning(282, "VARARGS"); 1050 warning(282, "VARARGS");
1053 } 1051 }
1054 nvararg = -1; 1052 nvararg = -1;
1055 } 1053 }
1056 if (prflstrg != -1) { 1054 if (prflstrg != -1) {
1057 if (!silent) { 1055 if (!silent) {
1058 curr_pos = printflike_pos; 1056 curr_pos = printflike_pos;
1059 /* must precede function definition: ** %s ** */ 1057 /* must precede function definition: ** %s ** */
1060 warning(282, "PRINTFLIKE"); 1058 warning(282, "PRINTFLIKE");
1061 } 1059 }
1062 prflstrg = -1; 1060 prflstrg = -1;
1063 } 1061 }
1064 if (scflstrg != -1) { 1062 if (scflstrg != -1) {
1065 if (!silent) { 1063 if (!silent) {
1066 curr_pos = scanflike_pos; 1064 curr_pos = scanflike_pos;
1067 /* must precede function definition: ** %s ** */ 1065 /* must precede function definition: ** %s ** */
1068 warning(282, "SCANFLIKE"); 1066 warning(282, "SCANFLIKE");
1069 } 1067 }
1070 scflstrg = -1; 1068 scflstrg = -1;
1071 } 1069 }
1072 1070
1073 curr_pos = cpos; 1071 curr_pos = cpos;
1074 1072
1075 dcs->d_asm = 0; 1073 dcs->d_asm = 0;
1076} 1074}
1077 1075
1078/* 1076/*
1079 * ARGSUSED comment 1077 * ARGSUSED comment
1080 * 1078 *
1081 * Only the first n arguments of the following function are checked 1079 * Only the first n arguments of the following function are checked
1082 * for usage. A missing argument is taken to be 0. 1080 * for usage. A missing argument is taken to be 0.
1083 */ 1081 */
1084void 1082void
1085argsused(int n) 1083argsused(int n)
1086{ 1084{
1087 1085
1088 if (n == -1) 1086 if (n == -1)
1089 n = 0; 1087 n = 0;
1090 1088
1091 if (dcs->d_ctx != EXTERN) { 1089 if (dcs->d_ctx != EXTERN) {
1092 /* must be outside function: ** %s ** */ 1090 /* must be outside function: ** %s ** */
1093 warning(280, "ARGSUSED"); 1091 warning(280, "ARGSUSED");
1094 return; 1092 return;
1095 } 1093 }
1096 if (nargusg != -1) { 1094 if (nargusg != -1) {
1097 /* duplicate use of ** %s ** */ 1095 /* duplicate use of ** %s ** */
1098 warning(281, "ARGSUSED"); 1096 warning(281, "ARGSUSED");
1099 } 1097 }
1100 nargusg = n; 1098 nargusg = n;
1101 argsused_pos = curr_pos; 1099 argsused_pos = curr_pos;
1102} 1100}
1103 1101
1104/* 1102/*
1105 * VARARGS comment 1103 * VARARGS comment
1106 * 1104 *
1107 * Causes lint2 to check only the first n arguments for compatibility 1105 * Causes lint2 to check only the first n arguments for compatibility
1108 * with the function definition. A missing argument is taken to be 0. 1106 * with the function definition. A missing argument is taken to be 0.
1109 */ 1107 */
1110void 1108void
1111varargs(int n) 1109varargs(int n)
1112{ 1110{
1113 1111
1114 if (n == -1) 1112 if (n == -1)
1115 n = 0; 1113 n = 0;
1116 1114
1117 if (dcs->d_ctx != EXTERN) { 1115 if (dcs->d_ctx != EXTERN) {
1118 /* must be outside function: ** %s ** */ 1116 /* must be outside function: ** %s ** */
1119 warning(280, "VARARGS"); 1117 warning(280, "VARARGS");
1120 return; 1118 return;
1121 } 1119 }
1122 if (nvararg != -1) { 1120 if (nvararg != -1) {
1123 /* duplicate use of ** %s ** */ 1121 /* duplicate use of ** %s ** */
1124 warning(281, "VARARGS"); 1122 warning(281, "VARARGS");
1125 } 1123 }
1126 nvararg = n; 1124 nvararg = n;
1127 vapos = curr_pos; 1125 vapos = curr_pos;
1128} 1126}
1129 1127
1130/* 1128/*
1131 * PRINTFLIKE comment 1129 * PRINTFLIKE comment
1132 * 1130 *
1133 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1131 * Check all arguments until the (n-1)-th as usual. The n-th argument is
1134 * used the check the types of remaining arguments. 1132 * used the check the types of remaining arguments.
1135 */ 1133 */
1136void 1134void
1137printflike(int n) 1135printflike(int n)
1138{ 1136{
1139 1137
1140 if (n == -1) 1138 if (n == -1)
1141 n = 0; 1139 n = 0;
1142 1140
1143 if (dcs->d_ctx != EXTERN) { 1141 if (dcs->d_ctx != EXTERN) {
1144 /* must be outside function: ** %s ** */ 1142 /* must be outside function: ** %s ** */
1145 warning(280, "PRINTFLIKE"); 1143 warning(280, "PRINTFLIKE");
1146 return; 1144 return;
1147 } 1145 }
1148 if (prflstrg != -1) { 1146 if (prflstrg != -1) {
1149 /* duplicate use of ** %s ** */ 1147 /* duplicate use of ** %s ** */
1150 warning(281, "PRINTFLIKE"); 1148 warning(281, "PRINTFLIKE");
1151 } 1149 }
1152 prflstrg = n; 1150 prflstrg = n;
1153 printflike_pos = curr_pos; 1151 printflike_pos = curr_pos;
1154} 1152}
1155 1153
1156/* 1154/*
1157 * SCANFLIKE comment 1155 * SCANFLIKE comment
1158 * 1156 *
1159 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1157 * Check all arguments until the (n-1)-th as usual. The n-th argument is
1160 * used the check the types of remaining arguments. 1158 * used the check the types of remaining arguments.
1161 */ 1159 */
1162void 1160void
1163scanflike(int n) 1161scanflike(int n)
1164{ 1162{
1165 1163
1166 if (n == -1) 1164 if (n == -1)
1167 n = 0; 1165 n = 0;
1168 1166
1169 if (dcs->d_ctx != EXTERN) { 1167 if (dcs->d_ctx != EXTERN) {
1170 /* must be outside function: ** %s ** */ 1168 /* must be outside function: ** %s ** */
1171 warning(280, "SCANFLIKE"); 1169 warning(280, "SCANFLIKE");
1172 return; 1170 return;
1173 } 1171 }
1174 if (scflstrg != -1) { 1172 if (scflstrg != -1) {
1175 /* duplicate use of ** %s ** */ 1173 /* duplicate use of ** %s ** */
1176 warning(281, "SCANFLIKE"); 1174 warning(281, "SCANFLIKE");
1177 } 1175 }
1178 scflstrg = n; 1176 scflstrg = n;
1179 scanflike_pos = curr_pos; 1177 scanflike_pos = curr_pos;
1180} 1178}
1181 1179
1182/* 1180/*
1183 * Set the linenumber for a CONSTCOND comment. At this and the following 1181 * Set the linenumber for a CONSTCOND comment. At this and the following
1184 * line no warnings about constants in conditional contexts are printed. 1182 * line no warnings about constants in conditional contexts are printed.
1185 */ 1183 */
1186/* ARGSUSED */ 1184/* ARGSUSED */
1187void 1185void
1188constcond(int n) 1186constcond(int n)
1189{ 1187{
1190 1188
1191 constcond_flag = 1; 1189 constcond_flag = 1;
1192} 1190}
1193 1191
1194/* 1192/*
1195 * Suppress printing of "fallthrough on ..." warnings until next 1193 * Suppress printing of "fallthrough on ..." warnings until next
1196 * statement. 1194 * statement.
1197 */ 1195 */
1198/* ARGSUSED */ 1196/* ARGSUSED */
1199void 1197void
1200fallthru(int n) 1198fallthru(int n)
1201{ 1199{
1202 1200
1203 ftflg = 1; 1201 ftflg = 1;
1204} 1202}
1205 1203
1206/* 1204/*
1207 * Stop warnings about statements which cannot be reached. Also tells lint 1205 * Stop warnings about statements which cannot be reached. Also tells lint
1208 * that the following statements cannot be reached (e.g. after exit()). 1206 * that the following statements cannot be reached (e.g. after exit()).
1209 */ 1207 */
1210/* ARGSUSED */ 1208/* ARGSUSED */
1211void 1209void
1212notreach(int n) 1210notreach(int n)
1213{ 1211{
1214 1212
1215 reached = 0; 1213 reached = 0;
1216 rchflg = 1; 1214 rchflg = 1;
1217} 1215}
1218 1216
1219/* ARGSUSED */ 1217/* ARGSUSED */
1220void 1218void
1221lintlib(int n) 1219lintlib(int n)
1222{ 1220{
1223 1221
1224 if (dcs->d_ctx != EXTERN) { 1222 if (dcs->d_ctx != EXTERN) {
1225 /* must be outside function: ** %s ** */ 1223 /* must be outside function: ** %s ** */
1226 warning(280, "LINTLIBRARY"); 1224 warning(280, "LINTLIBRARY");
1227 return; 1225 return;
1228 } 1226 }
1229 llibflg = 1; 1227 llibflg = 1;
1230 vflag = 0; 1228 vflag = 0;
1231} 1229}
1232 1230
1233/* 1231/*
1234 * Suppress most warnings at the current and the following line. 1232 * Suppress most warnings at the current and the following line.
1235 */ 1233 */
1236/* ARGSUSED */ 1234/* ARGSUSED */
1237void 1235void
1238linted(int n) 1236linted(int n)
1239{ 1237{
1240 1238
1241#ifdef DEBUG 1239#ifdef DEBUG
1242 printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n); 1240 printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n);
1243#endif 1241#endif
1244 lwarn = n; 1242 lwarn = n;
1245} 1243}
1246 1244
1247/* 1245/*
1248 * Suppress bitfield type errors on the current line. 1246 * Suppress bitfield type errors on the current line.
1249 */ 1247 */
1250/* ARGSUSED */ 1248/* ARGSUSED */
1251void 1249void
1252bitfieldtype(int n) 1250bitfieldtype(int n)
1253{ 1251{
1254 1252
1255#ifdef DEBUG 1253#ifdef DEBUG
1256 printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file, 1254 printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file,
1257 curr_pos.p_line); 1255 curr_pos.p_line);
1258#endif 1256#endif
1259 bitfieldtype_ok = 1; 1257 bitfieldtype_ok = 1;
1260} 1258}
1261 1259
1262/* 1260/*
1263 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle 1261 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle
1264 * prototypes like function definitions. This is done if the argument 1262 * prototypes like function definitions. This is done if the argument
1265 * to PROTOLIB is nonzero. Otherwise prototypes are handled normally. 1263 * to PROTOLIB is nonzero. Otherwise prototypes are handled normally.
1266 */ 1264 */
1267void 1265void
1268protolib(int n) 1266protolib(int n)
1269{ 1267{
1270 1268
1271 if (dcs->d_ctx != EXTERN) { 1269 if (dcs->d_ctx != EXTERN) {
1272 /* must be outside function: ** %s ** */ 1270 /* must be outside function: ** %s ** */
1273 warning(280, "PROTOLIB"); 1271 warning(280, "PROTOLIB");
1274 return; 1272 return;
1275 } 1273 }
1276 plibflg = n == 0 ? 0 : 1; 1274 plibflg = n == 0 ? 0 : 1;
1277} 1275}
1278 1276
1279/* 1277/*
1280 * Set quadflg to nonzero which means that the next statement/declaration 1278 * Set quadflg to nonzero which means that the next statement/declaration
1281 * may use "long long" without an error or warning. 1279 * may use "long long" without an error or warning.
1282 */ 1280 */
1283/* ARGSUSED */ 1281/* ARGSUSED */
1284void 1282void
1285longlong(int n) 1283longlong(int n)
1286{ 1284{
1287 1285
1288 quadflg = 1; 1286 quadflg = 1;
1289} 1287}