Sun Jan 3 20:04:09 2021 UTC ()
lint: rename cstk to cstmt

Most of the code that deals with control statements is only interested
in the innermost control statement, and not if that is a stack or not.
Therefore, emphasize that part in the variable name.

The member c_next was confusing since the "direction" of this "next
element" was ambiguous.  In a sequence of if statements, the "next"
element could have equally been the following one, not the surrounding
one.


(rillig)
diff -r1.47 -r1.48 src/usr.bin/xlint/lint1/func.c
diff -r1.51 -r1.52 src/usr.bin/xlint/lint1/lint1.h

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

--- src/usr.bin/xlint/lint1/func.c 2021/01/02 18:44:58 1.47
+++ src/usr.bin/xlint/lint1/func.c 2021/01/03 20:04:08 1.48
@@ -1,1297 +1,1297 @@ @@ -1,1297 +1,1297 @@
1/* $NetBSD: func.c,v 1.47 2021/01/02 18:44:58 rillig Exp $ */ 1/* $NetBSD: func.c,v 1.48 2021/01/03 20:04:08 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.47 2021/01/02 18:44:58 rillig Exp $"); 40__RCSID("$NetBSD: func.c,v 1.48 2021/01/03 20:04:08 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/* The innermost control statement */
79cstk_t *cstk; 79cstk_t *cstmt;
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 * Whether bitfield type errors are suppressed by a BITFIELDTYPE 141 * Whether bitfield type errors are suppressed by a BITFIELDTYPE
142 * directive. 142 * directive.
143 */ 143 */
144bool bitfieldtype_ok; 144bool 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_surrounding = cstmt;
163 cstk = ci; 163 cstmt = 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(cstmt != NULL);
176 lint_assert(cstk->c_env == env); 176 lint_assert(cstmt->c_env == env);
177 177
178 cstk = (ci = cstk)->c_next; 178 cstmt = (ci = cstmt)->c_surrounding;
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 cstmt->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 (cstmt->c_noretval && cstmt->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, cstmt->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
402void 402void
403named_label(sym_t *sym) 403named_label(sym_t *sym)
404{ 404{
405 405
406 if (sym->s_set) { 406 if (sym->s_set) {
407 /* label %s redefined */ 407 /* label %s redefined */
408 error(194, sym->s_name); 408 error(194, sym->s_name);
409 } else { 409 } else {
410 mark_as_set(sym); 410 mark_as_set(sym);
411 } 411 }
412 412
413 reached = 1; 413 reached = 1;
414} 414}
415 415
416static void 416static void
417check_case_label(tnode_t *tn, cstk_t *ci) 417check_case_label(tnode_t *tn, cstk_t *ci)
418{ 418{
419 clst_t *cl; 419 clst_t *cl;
420 val_t *v; 420 val_t *v;
421 val_t nv; 421 val_t nv;
422 tspec_t t; 422 tspec_t t;
423 423
424 if (ci == NULL) { 424 if (ci == NULL) {
425 /* case not in switch */ 425 /* case not in switch */
426 error(195); 426 error(195);
427 return; 427 return;
428 } 428 }
429 429
430 if (tn != NULL && tn->tn_op != CON) { 430 if (tn != NULL && tn->tn_op != CON) {
431 /* non-constant case expression */ 431 /* non-constant case expression */
432 error(197); 432 error(197);
433 return; 433 return;
434 } 434 }
435 435
436 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { 436 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
437 /* non-integral case expression */ 437 /* non-integral case expression */
438 error(198); 438 error(198);
439 return; 439 return;
440 } 440 }
441 441
442 lint_assert(ci->c_swtype != NULL); 442 lint_assert(ci->c_swtype != NULL);
443 443
444 if (reached && !ftflg) { 444 if (reached && !ftflg) {
445 if (hflag) 445 if (hflag)
446 /* fallthrough on case statement */ 446 /* fallthrough on case statement */
447 warning(220); 447 warning(220);
448 } 448 }
449 449
450 t = tn->tn_type->t_tspec; 450 t = tn->tn_type->t_tspec;
451 if (t == LONG || t == ULONG || 451 if (t == LONG || t == ULONG ||
452 t == QUAD || t == UQUAD) { 452 t == QUAD || t == UQUAD) {
453 if (tflag) 453 if (tflag)
454 /* case label must be of type `int' in traditional C */ 454 /* case label must be of type `int' in traditional C */
455 warning(203); 455 warning(203);
456 } 456 }
457 457
458 /* 458 /*
459 * get the value of the expression and convert it 459 * get the value of the expression and convert it
460 * to the type of the switch expression 460 * to the type of the switch expression
461 */ 461 */
462 v = constant(tn, 1); 462 v = constant(tn, 1);
463 (void) memset(&nv, 0, sizeof nv); 463 (void) memset(&nv, 0, sizeof nv);
464 cvtcon(CASE, 0, ci->c_swtype, &nv, v); 464 cvtcon(CASE, 0, ci->c_swtype, &nv, v);
465 free(v); 465 free(v);
466 466
467 /* look if we had this value already */ 467 /* look if we had this value already */
468 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) { 468 for (cl = ci->c_clst; cl != NULL; cl = cl->cl_next) {
469 if (cl->cl_val.v_quad == nv.v_quad) 469 if (cl->cl_val.v_quad == nv.v_quad)
470 break; 470 break;
471 } 471 }
472 if (cl != NULL && tspec_is_uint(nv.v_tspec)) { 472 if (cl != NULL && tspec_is_uint(nv.v_tspec)) {
473 /* duplicate case in switch: %lu */ 473 /* duplicate case in switch: %lu */
474 error(200, (u_long)nv.v_quad); 474 error(200, (u_long)nv.v_quad);
475 } else if (cl != NULL) { 475 } else if (cl != NULL) {
476 /* duplicate case in switch: %ld */ 476 /* duplicate case in switch: %ld */
477 error(199, (long)nv.v_quad); 477 error(199, (long)nv.v_quad);
478 } else { 478 } else {
479 /* 479 /*
480 * append the value to the list of 480 * append the value to the list of
481 * case values 481 * case values
482 */ 482 */
483 cl = xcalloc(1, sizeof (clst_t)); 483 cl = xcalloc(1, sizeof (clst_t));
484 cl->cl_val = nv; 484 cl->cl_val = nv;
485 cl->cl_next = ci->c_clst; 485 cl->cl_next = ci->c_clst;
486 ci->c_clst = cl; 486 ci->c_clst = cl;
487 } 487 }
488} 488}
489 489
490void 490void
491case_label(tnode_t *tn) 491case_label(tnode_t *tn)
492{ 492{
493 cstk_t *ci; 493 cstk_t *ci;
494 494
495 /* find the stack entry for the innermost switch statement */ 495 /* find the stack entry for the innermost switch statement */
496 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) 496 for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding)
497 continue; 497 continue;
498 498
499 check_case_label(tn, ci); 499 check_case_label(tn, ci);
500 500
501 tfreeblk(); 501 tfreeblk();
502 502
503 reached = 1; 503 reached = 1;
504} 504}
505 505
506void 506void
507default_label(void) 507default_label(void)
508{ 508{
509 cstk_t *ci; 509 cstk_t *ci;
510 510
511 /* find the stack entry for the innermost switch statement */ 511 /* find the stack entry for the innermost switch statement */
512 for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_next) 512 for (ci = cstmt; ci != NULL && !ci->c_switch; ci = ci->c_surrounding)
513 continue; 513 continue;
514 514
515 if (ci == NULL) { 515 if (ci == NULL) {
516 /* default outside switch */ 516 /* default outside switch */
517 error(201); 517 error(201);
518 } else if (ci->c_default) { 518 } else if (ci->c_default) {
519 /* duplicate default in switch */ 519 /* duplicate default in switch */
520 error(202); 520 error(202);
521 } else { 521 } else {
522 if (reached && !ftflg) { 522 if (reached && !ftflg) {
523 if (hflag) 523 if (hflag)
524 /* fallthrough on default statement */ 524 /* fallthrough on default statement */
525 warning(284); 525 warning(284);
526 } 526 }
527 ci->c_default = 1; 527 ci->c_default = 1;
528 } 528 }
529 529
530 reached = 1; 530 reached = 1;
531} 531}
532 532
533static tnode_t * 533static tnode_t *
534check_controlling_expression(tnode_t *tn) 534check_controlling_expression(tnode_t *tn)
535{ 535{
536 tspec_t t = tn->tn_type->t_tspec; 536 tspec_t t = tn->tn_type->t_tspec;
537 537
538 if (tn != NULL) 538 if (tn != NULL)
539 tn = cconv(tn); 539 tn = cconv(tn);
540 if (tn != NULL) 540 if (tn != NULL)
541 tn = promote(NOOP, 0, tn); 541 tn = promote(NOOP, 0, tn);
542 542
543 if (tn != NULL && !tspec_is_scalar(t)) { 543 if (tn != NULL && !tspec_is_scalar(t)) {
544 /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */ 544 /* C99 6.5.15p4 for the ?: operator; see typeok:QUEST */
545 /* C99 6.8.4.1p1 for if statements */ 545 /* C99 6.8.4.1p1 for if statements */
546 /* C99 6.8.5p2 for while, do and for loops */ 546 /* C99 6.8.5p2 for while, do and for loops */
547 /* controlling expressions must have scalar type */ 547 /* controlling expressions must have scalar type */
548 error(204); 548 error(204);
549 return NULL; 549 return NULL;
550 } 550 }
551 551
552 return tn; 552 return tn;
553} 553}
554 554
555/* 555/*
556 * T_IF T_LPAREN expr T_RPAREN 556 * T_IF T_LPAREN expr T_RPAREN
557 */ 557 */
558void 558void
559if1(tnode_t *tn) 559if1(tnode_t *tn)
560{ 560{
561 561
562 if (tn != NULL) 562 if (tn != NULL)
563 tn = check_controlling_expression(tn); 563 tn = check_controlling_expression(tn);
564 if (tn != NULL) 564 if (tn != NULL)
565 expr(tn, 0, 1, 0); 565 expr(tn, 0, 1, 0);
566 pushctrl(T_IF); 566 pushctrl(T_IF);
567} 567}
568 568
569/* 569/*
570 * if_without_else 570 * if_without_else
571 * if_without_else T_ELSE 571 * if_without_else T_ELSE
572 */ 572 */
573void 573void
574if2(void) 574if2(void)
575{ 575{
576 576
577 cstk->c_rchif = reached ? 1 : 0; 577 cstmt->c_rchif = reached ? 1 : 0;
578 reached = 1; 578 reached = 1;
579} 579}
580 580
581/* 581/*
582 * if_without_else 582 * if_without_else
583 * if_without_else T_ELSE stmnt 583 * if_without_else T_ELSE stmnt
584 */ 584 */
585void 585void
586if3(int els) 586if3(int els)
587{ 587{
588 588
589 if (els) { 589 if (els) {
590 reached |= cstk->c_rchif; 590 reached |= cstmt->c_rchif;
591 } else { 591 } else {
592 reached = 1; 592 reached = 1;
593 } 593 }
594 popctrl(T_IF); 594 popctrl(T_IF);
595} 595}
596 596
597/* 597/*
598 * T_SWITCH T_LPAREN expr T_RPAREN 598 * T_SWITCH T_LPAREN expr T_RPAREN
599 */ 599 */
600void 600void
601switch1(tnode_t *tn) 601switch1(tnode_t *tn)
602{ 602{
603 tspec_t t; 603 tspec_t t;
604 type_t *tp; 604 type_t *tp;
605 605
606 if (tn != NULL) 606 if (tn != NULL)
607 tn = cconv(tn); 607 tn = cconv(tn);
608 if (tn != NULL) 608 if (tn != NULL)
609 tn = promote(NOOP, 0, tn); 609 tn = promote(NOOP, 0, tn);
610 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) { 610 if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
611 /* switch expression must have integral type */ 611 /* switch expression must have integral type */
612 error(205); 612 error(205);
613 tn = NULL; 613 tn = NULL;
614 } 614 }
615 if (tn != NULL && tflag) { 615 if (tn != NULL && tflag) {
616 t = tn->tn_type->t_tspec; 616 t = tn->tn_type->t_tspec;
617 if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) { 617 if (t == LONG || t == ULONG || t == QUAD || t == UQUAD) {
618 /* switch expr. must be of type `int' in trad. C */ 618 /* switch expr. must be of type `int' in trad. C */
619 warning(271); 619 warning(271);
620 } 620 }
621 } 621 }
622 622
623 /* 623 /*
624 * Remember the type of the expression. Because it's possible 624 * Remember the type of the expression. Because it's possible
625 * that (*tp) is allocated on tree memory, the type must be 625 * that (*tp) is allocated on tree memory, the type must be
626 * duplicated. This is not too complicated because it is 626 * duplicated. This is not too complicated because it is
627 * only an integer type. 627 * only an integer type.
628 */ 628 */
629 tp = xcalloc(1, sizeof (type_t)); 629 tp = xcalloc(1, sizeof (type_t));
630 if (tn != NULL) { 630 if (tn != NULL) {
631 tp->t_tspec = tn->tn_type->t_tspec; 631 tp->t_tspec = tn->tn_type->t_tspec;
632 if ((tp->t_isenum = tn->tn_type->t_isenum) != 0) 632 if ((tp->t_isenum = tn->tn_type->t_isenum) != 0)
633 tp->t_enum = tn->tn_type->t_enum; 633 tp->t_enum = tn->tn_type->t_enum;
634 } else { 634 } else {
635 tp->t_tspec = INT; 635 tp->t_tspec = INT;
636 } 636 }
637 637
638 expr(tn, 1, 0, 1); 638 expr(tn, 1, 0, 1);
639 639
640 pushctrl(T_SWITCH); 640 pushctrl(T_SWITCH);
641 cstk->c_switch = 1; 641 cstmt->c_switch = 1;
642 cstk->c_swtype = tp; 642 cstmt->c_swtype = tp;
643 643
644 reached = rchflg = 0; 644 reached = rchflg = 0;
645 ftflg = 1; 645 ftflg = 1;
646} 646}
647 647
648/* 648/*
649 * switch_expr stmnt 649 * switch_expr stmnt
650 */ 650 */
651void 651void
652switch2(void) 652switch2(void)
653{ 653{
654 int nenum = 0, nclab = 0; 654 int nenum = 0, nclab = 0;
655 sym_t *esym; 655 sym_t *esym;
656 clst_t *cl; 656 clst_t *cl;
657 657
658 lint_assert(cstk->c_swtype != NULL); 658 lint_assert(cstmt->c_swtype != NULL);
659 659
660 /* 660 /*
661 * If the switch expression was of type enumeration, count the case 661 * If the switch expression was of type enumeration, count the case
662 * labels and the number of enumerators. If both counts are not 662 * labels and the number of enumerators. If both counts are not
663 * equal print a warning. 663 * equal print a warning.
664 */ 664 */
665 if (cstk->c_swtype->t_isenum) { 665 if (cstmt->c_swtype->t_isenum) {
666 nenum = nclab = 0; 666 nenum = nclab = 0;
667 lint_assert(cstk->c_swtype->t_enum != NULL); 667 lint_assert(cstmt->c_swtype->t_enum != NULL);
668 for (esym = cstk->c_swtype->t_enum->elem; 668 for (esym = cstmt->c_swtype->t_enum->elem;
669 esym != NULL; esym = esym->s_next) { 669 esym != NULL; esym = esym->s_next) {
670 nenum++; 670 nenum++;
671 } 671 }
672 for (cl = cstk->c_clst; cl != NULL; cl = cl->cl_next) 672 for (cl = cstmt->c_clst; cl != NULL; cl = cl->cl_next)
673 nclab++; 673 nclab++;
674 if (hflag && eflag && nenum != nclab && !cstk->c_default) { 674 if (hflag && eflag && nenum != nclab && !cstmt->c_default) {
675 /* enumeration value(s) not handled in switch */ 675 /* enumeration value(s) not handled in switch */
676 warning(206); 676 warning(206);
677 } 677 }
678 } 678 }
679 679
680 if (cstk->c_break) { 680 if (cstmt->c_break) {
681 /* 681 /*
682 * end of switch alway reached (c_break is only set if the 682 * end of switch alway reached (c_break is only set if the
683 * break statement can be reached). 683 * break statement can be reached).
684 */ 684 */
685 reached = 1; 685 reached = 1;
686 } else if (!cstk->c_default && 686 } else if (!cstmt->c_default &&
687 (!hflag || !cstk->c_swtype->t_isenum || nenum != nclab)) { 687 (!hflag || !cstmt->c_swtype->t_isenum || nenum != nclab)) {
688 /* 688 /*
689 * there are possible values which are not handled in 689 * there are possible values which are not handled in
690 * switch 690 * switch
691 */ 691 */
692 reached = 1; 692 reached = 1;
693 } /* 693 } /*
694 * otherwise the end of the switch expression is reached 694 * otherwise the end of the switch expression is reached
695 * if the end of the last statement inside it is reached. 695 * if the end of the last statement inside it is reached.
696 */ 696 */
697 697
698 popctrl(T_SWITCH); 698 popctrl(T_SWITCH);
699} 699}
700 700
701/* 701/*
702 * T_WHILE T_LPAREN expr T_RPAREN 702 * T_WHILE T_LPAREN expr T_RPAREN
703 */ 703 */
704void 704void
705while1(tnode_t *tn) 705while1(tnode_t *tn)
706{ 706{
707 707
708 if (!reached) { 708 if (!reached) {
709 /* loop not entered at top */ 709 /* loop not entered at top */
710 warning(207); 710 warning(207);
711 reached = 1; 711 reached = 1;
712 } 712 }
713 713
714 if (tn != NULL) 714 if (tn != NULL)
715 tn = check_controlling_expression(tn); 715 tn = check_controlling_expression(tn);
716 716
717 pushctrl(T_WHILE); 717 pushctrl(T_WHILE);
718 cstk->c_loop = 1; 718 cstmt->c_loop = 1;
719 if (tn != NULL && tn->tn_op == CON) { 719 if (tn != NULL && tn->tn_op == CON) {
720 if (tspec_is_int(tn->tn_type->t_tspec)) { 720 if (tspec_is_int(tn->tn_type->t_tspec)) {
721 cstk->c_infinite = tn->tn_val->v_quad != 0; 721 cstmt->c_infinite = tn->tn_val->v_quad != 0;
722 } else { 722 } else {
723 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; 723 cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0;
724 } 724 }
725 } 725 }
726 726
727 expr(tn, 0, 1, 1); 727 expr(tn, 0, 1, 1);
728} 728}
729 729
730/* 730/*
731 * while_expr stmnt 731 * while_expr stmnt
732 * while_expr error 732 * while_expr error
733 */ 733 */
734void 734void
735while2(void) 735while2(void)
736{ 736{
737 737
738 /* 738 /*
739 * The end of the loop can be reached if it is no endless loop 739 * The end of the loop can be reached if it is no endless loop
740 * or there was a break statement which was reached. 740 * or there was a break statement which was reached.
741 */ 741 */
742 reached = !cstk->c_infinite || cstk->c_break; 742 reached = !cstmt->c_infinite || cstmt->c_break;
743 rchflg = 0; 743 rchflg = 0;
744 744
745 popctrl(T_WHILE); 745 popctrl(T_WHILE);
746} 746}
747 747
748/* 748/*
749 * T_DO 749 * T_DO
750 */ 750 */
751void 751void
752do1(void) 752do1(void)
753{ 753{
754 754
755 if (!reached) { 755 if (!reached) {
756 /* loop not entered at top */ 756 /* loop not entered at top */
757 warning(207); 757 warning(207);
758 reached = 1; 758 reached = 1;
759 } 759 }
760 760
761 pushctrl(T_DO); 761 pushctrl(T_DO);
762 cstk->c_loop = 1; 762 cstmt->c_loop = 1;
763} 763}
764 764
765/* 765/*
766 * do stmnt do_while_expr 766 * do stmnt do_while_expr
767 * do error 767 * do error
768 */ 768 */
769void 769void
770do2(tnode_t *tn) 770do2(tnode_t *tn)
771{ 771{
772 772
773 /* 773 /*
774 * If there was a continue statement, the expression controlling the 774 * If there was a continue statement, the expression controlling the
775 * loop is reached. 775 * loop is reached.
776 */ 776 */
777 if (cstk->c_cont) 777 if (cstmt->c_cont)
778 reached = 1; 778 reached = 1;
779 779
780 if (tn != NULL) 780 if (tn != NULL)
781 tn = check_controlling_expression(tn); 781 tn = check_controlling_expression(tn);
782 782
783 if (tn != NULL && tn->tn_op == CON) { 783 if (tn != NULL && tn->tn_op == CON) {
784 if (tspec_is_int(tn->tn_type->t_tspec)) { 784 if (tspec_is_int(tn->tn_type->t_tspec)) {
785 cstk->c_infinite = tn->tn_val->v_quad != 0; 785 cstmt->c_infinite = tn->tn_val->v_quad != 0;
786 } else { 786 } else {
787 cstk->c_infinite = tn->tn_val->v_ldbl != 0.0; 787 cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0;
788 } 788 }
789 if (!cstk->c_infinite && cstk->c_cont) 789 if (!cstmt->c_infinite && cstmt->c_cont)
790 /* continue in 'do ... while (0)' loop */ 790 /* continue in 'do ... while (0)' loop */
791 error(323); 791 error(323);
792 } 792 }
793 793
794 expr(tn, 0, 1, 1); 794 expr(tn, 0, 1, 1);
795 795
796 /* 796 /*
797 * The end of the loop is only reached if it is no endless loop 797 * The end of the loop is only reached if it is no endless loop
798 * or there was a break statement which could be reached. 798 * or there was a break statement which could be reached.
799 */ 799 */
800 reached = !cstk->c_infinite || cstk->c_break; 800 reached = !cstmt->c_infinite || cstmt->c_break;
801 rchflg = 0; 801 rchflg = 0;
802 802
803 popctrl(T_DO); 803 popctrl(T_DO);
804} 804}
805 805
806/* 806/*
807 * T_FOR T_LPAREN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN 807 * T_FOR T_LPAREN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPAREN
808 */ 808 */
809void 809void
810for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) 810for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3)
811{ 811{
812 812
813 /* 813 /*
814 * If there is no initialisation expression it is possible that 814 * If there is no initialisation expression it is possible that
815 * it is intended not to enter the loop at top. 815 * it is intended not to enter the loop at top.
816 */ 816 */
817 if (tn1 != NULL && !reached) { 817 if (tn1 != NULL && !reached) {
818 /* loop not entered at top */ 818 /* loop not entered at top */
819 warning(207); 819 warning(207);
820 reached = 1; 820 reached = 1;
821 } 821 }
822 822
823 pushctrl(T_FOR); 823 pushctrl(T_FOR);
824 cstk->c_loop = 1; 824 cstmt->c_loop = 1;
825 825
826 /* 826 /*
827 * Store the tree memory for the reinitialisation expression. 827 * Store the tree memory for the reinitialisation expression.
828 * Also remember this expression itself. We must check it at 828 * Also remember this expression itself. We must check it at
829 * the end of the loop to get "used but not set" warnings correct. 829 * the end of the loop to get "used but not set" warnings correct.
830 */ 830 */
831 cstk->c_fexprm = tsave(); 831 cstmt->c_fexprm = tsave();
832 cstk->c_f3expr = tn3; 832 cstmt->c_f3expr = tn3;
833 cstk->c_fpos = curr_pos; 833 cstmt->c_fpos = curr_pos;
834 cstk->c_cfpos = csrc_pos; 834 cstmt->c_cfpos = csrc_pos;
835 835
836 if (tn1 != NULL) 836 if (tn1 != NULL)
837 expr(tn1, 0, 0, 1); 837 expr(tn1, 0, 0, 1);
838 838
839 if (tn2 != NULL) 839 if (tn2 != NULL)
840 tn2 = check_controlling_expression(tn2); 840 tn2 = check_controlling_expression(tn2);
841 if (tn2 != NULL) 841 if (tn2 != NULL)
842 expr(tn2, 0, 1, 1); 842 expr(tn2, 0, 1, 1);
843 843
844 if (tn2 == NULL) { 844 if (tn2 == NULL) {
845 cstk->c_infinite = 1; 845 cstmt->c_infinite = 1;
846 } else if (tn2->tn_op == CON) { 846 } else if (tn2->tn_op == CON) {
847 if (tspec_is_int(tn2->tn_type->t_tspec)) { 847 if (tspec_is_int(tn2->tn_type->t_tspec)) {
848 cstk->c_infinite = tn2->tn_val->v_quad != 0; 848 cstmt->c_infinite = tn2->tn_val->v_quad != 0;
849 } else { 849 } else {
850 cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0; 850 cstmt->c_infinite = tn2->tn_val->v_ldbl != 0.0;
851 } 851 }
852 } 852 }
853 853
854 /* Checking the reinitialisation expression is done in for2() */ 854 /* Checking the reinitialisation expression is done in for2() */
855 855
856 reached = 1; 856 reached = 1;
857} 857}
858 858
859/* 859/*
860 * for_exprs stmnt 860 * for_exprs stmnt
861 * for_exprs error 861 * for_exprs error
862 */ 862 */
863void 863void
864for2(void) 864for2(void)
865{ 865{
866 pos_t cpos, cspos; 866 pos_t cpos, cspos;
867 tnode_t *tn3; 867 tnode_t *tn3;
868 868
869 if (cstk->c_cont) 869 if (cstmt->c_cont)
870 reached = 1; 870 reached = 1;
871 871
872 cpos = curr_pos; 872 cpos = curr_pos;
873 cspos = csrc_pos; 873 cspos = csrc_pos;
874 874
875 /* Restore the tree memory for the reinitialisation expression */ 875 /* Restore the tree memory for the reinitialisation expression */
876 trestor(cstk->c_fexprm); 876 trestor(cstmt->c_fexprm);
877 tn3 = cstk->c_f3expr; 877 tn3 = cstmt->c_f3expr;
878 curr_pos = cstk->c_fpos; 878 curr_pos = cstmt->c_fpos;
879 csrc_pos = cstk->c_cfpos; 879 csrc_pos = cstmt->c_cfpos;
880 880
881 /* simply "statement not reached" would be confusing */ 881 /* simply "statement not reached" would be confusing */
882 if (!reached && !rchflg) { 882 if (!reached && !rchflg) {
883 /* end-of-loop code not reached */ 883 /* end-of-loop code not reached */
884 warning(223); 884 warning(223);
885 reached = 1; 885 reached = 1;
886 } 886 }
887 887
888 if (tn3 != NULL) { 888 if (tn3 != NULL) {
889 expr(tn3, 0, 0, 1); 889 expr(tn3, 0, 0, 1);
890 } else { 890 } else {
891 tfreeblk(); 891 tfreeblk();
892 } 892 }
893 893
894 curr_pos = cpos; 894 curr_pos = cpos;
895 csrc_pos = cspos; 895 csrc_pos = cspos;
896 896
897 /* An endless loop without break will never terminate */ 897 /* An endless loop without break will never terminate */
898 reached = cstk->c_break || !cstk->c_infinite; 898 reached = cstmt->c_break || !cstmt->c_infinite;
899 rchflg = 0; 899 rchflg = 0;
900 900
901 popctrl(T_FOR); 901 popctrl(T_FOR);
902} 902}
903 903
904/* 904/*
905 * T_GOTO identifier T_SEMI 905 * T_GOTO identifier T_SEMI
906 * T_GOTO error T_SEMI 906 * T_GOTO error T_SEMI
907 */ 907 */
908void 908void
909dogoto(sym_t *lab) 909dogoto(sym_t *lab)
910{ 910{
911 911
912 mark_as_used(lab, 0, 0); 912 mark_as_used(lab, 0, 0);
913 913
914 check_statement_reachable(); 914 check_statement_reachable();
915 915
916 reached = rchflg = 0; 916 reached = rchflg = 0;
917} 917}
918 918
919/* 919/*
920 * T_BREAK T_SEMI 920 * T_BREAK T_SEMI
921 */ 921 */
922void 922void
923dobreak(void) 923dobreak(void)
924{ 924{
925 cstk_t *ci; 925 cstk_t *ci;
926 926
927 ci = cstk; 927 ci = cstmt;
928 while (ci != NULL && !ci->c_loop && !ci->c_switch) 928 while (ci != NULL && !ci->c_loop && !ci->c_switch)
929 ci = ci->c_next; 929 ci = ci->c_surrounding;
930 930
931 if (ci == NULL) { 931 if (ci == NULL) {
932 /* break outside loop or switch */ 932 /* break outside loop or switch */
933 error(208); 933 error(208);
934 } else { 934 } else {
935 if (reached) 935 if (reached)
936 ci->c_break = 1; 936 ci->c_break = 1;
937 } 937 }
938 938
939 if (bflag) 939 if (bflag)
940 check_statement_reachable(); 940 check_statement_reachable();
941 941
942 reached = rchflg = 0; 942 reached = rchflg = 0;
943} 943}
944 944
945/* 945/*
946 * T_CONTINUE T_SEMI 946 * T_CONTINUE T_SEMI
947 */ 947 */
948void 948void
949docont(void) 949docont(void)
950{ 950{
951 cstk_t *ci; 951 cstk_t *ci;
952 952
953 for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_next) 953 for (ci = cstmt; ci != NULL && !ci->c_loop; ci = ci->c_surrounding)
954 continue; 954 continue;
955 955
956 if (ci == NULL) { 956 if (ci == NULL) {
957 /* continue outside loop */ 957 /* continue outside loop */
958 error(209); 958 error(209);
959 } else { 959 } else {
960 ci->c_cont = 1; 960 ci->c_cont = 1;
961 } 961 }
962 962
963 check_statement_reachable(); 963 check_statement_reachable();
964 964
965 reached = rchflg = 0; 965 reached = rchflg = 0;
966} 966}
967 967
968/* 968/*
969 * T_RETURN T_SEMI 969 * T_RETURN T_SEMI
970 * T_RETURN expr T_SEMI 970 * T_RETURN expr T_SEMI
971 */ 971 */
972void 972void
973doreturn(tnode_t *tn) 973doreturn(tnode_t *tn)
974{ 974{
975 tnode_t *ln, *rn; 975 tnode_t *ln, *rn;
976 cstk_t *ci; 976 cstk_t *ci;
977 op_t op; 977 op_t op;
978 978
979 for (ci = cstk; ci->c_next != NULL; ci = ci->c_next) 979 for (ci = cstmt; ci->c_surrounding != NULL; ci = ci->c_surrounding)
980 continue; 980 continue;
981 981
982 if (tn != NULL) { 982 if (tn != NULL) {
983 ci->c_retval = 1; 983 ci->c_retval = 1;
984 } else { 984 } else {
985 ci->c_noretval = 1; 985 ci->c_noretval = 1;
986 } 986 }
987 987
988 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) { 988 if (tn != NULL && funcsym->s_type->t_subt->t_tspec == VOID) {
989 /* void function %s cannot return value */ 989 /* void function %s cannot return value */
990 error(213, funcsym->s_name); 990 error(213, funcsym->s_name);
991 tfreeblk(); 991 tfreeblk();
992 tn = NULL; 992 tn = NULL;
993 } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) { 993 } else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) {
994 /* 994 /*
995 * Assume that the function has a return value only if it 995 * Assume that the function has a return value only if it
996 * is explicitly declared. 996 * is explicitly declared.
997 */ 997 */
998 if (!funcsym->s_rimpl) 998 if (!funcsym->s_rimpl)
999 /* function %s expects to return value */ 999 /* function %s expects to return value */
1000 warning(214, funcsym->s_name); 1000 warning(214, funcsym->s_name);
1001 } 1001 }
1002 1002
1003 if (tn != NULL) { 1003 if (tn != NULL) {
1004 1004
1005 /* Create a temporary node for the left side */ 1005 /* Create a temporary node for the left side */
1006 ln = tgetblk(sizeof (tnode_t)); 1006 ln = tgetblk(sizeof (tnode_t));
1007 ln->tn_op = NAME; 1007 ln->tn_op = NAME;
1008 ln->tn_type = tduptyp(funcsym->s_type->t_subt); 1008 ln->tn_type = tduptyp(funcsym->s_type->t_subt);
1009 ln->tn_type->t_const = 0; 1009 ln->tn_type->t_const = 0;
1010 ln->tn_lvalue = 1; 1010 ln->tn_lvalue = 1;
1011 ln->tn_sym = funcsym; /* better than nothing */ 1011 ln->tn_sym = funcsym; /* better than nothing */
1012 1012
1013 tn = build(RETURN, ln, tn); 1013 tn = build(RETURN, ln, tn);
1014 1014
1015 if (tn != NULL) { 1015 if (tn != NULL) {
1016 rn = tn->tn_right; 1016 rn = tn->tn_right;
1017 while ((op = rn->tn_op) == CVT || op == PLUS) 1017 while ((op = rn->tn_op) == CVT || op == PLUS)
1018 rn = rn->tn_left; 1018 rn = rn->tn_left;
1019 if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME && 1019 if (rn->tn_op == AMPER && rn->tn_left->tn_op == NAME &&
1020 rn->tn_left->tn_sym->s_scl == AUTO) { 1020 rn->tn_left->tn_sym->s_scl == AUTO) {
1021 /* %s returns pointer to automatic object */ 1021 /* %s returns pointer to automatic object */
1022 warning(302, funcsym->s_name); 1022 warning(302, funcsym->s_name);
1023 } 1023 }
1024 } 1024 }
1025 1025
1026 expr(tn, 1, 0, 1); 1026 expr(tn, 1, 0, 1);
1027 1027
1028 } else { 1028 } else {
1029 1029
1030 check_statement_reachable(); 1030 check_statement_reachable();
1031 1031
1032 } 1032 }
1033 1033
1034 reached = rchflg = 0; 1034 reached = rchflg = 0;
1035} 1035}
1036 1036
1037/* 1037/*
1038 * Do some cleanup after a global declaration or definition. 1038 * Do some cleanup after a global declaration or definition.
1039 * Especially remove information about unused lint comments. 1039 * Especially remove information about unused lint comments.
1040 */ 1040 */
1041void 1041void
1042global_clean_up_decl(int silent) 1042global_clean_up_decl(int silent)
1043{ 1043{
1044 pos_t cpos; 1044 pos_t cpos;
1045 1045
1046 cpos = curr_pos; 1046 cpos = curr_pos;
1047 1047
1048 if (nargusg != -1) { 1048 if (nargusg != -1) {
1049 if (!silent) { 1049 if (!silent) {
1050 curr_pos = argsused_pos; 1050 curr_pos = argsused_pos;
1051 /* must precede function definition: ** %s ** */ 1051 /* must precede function definition: ** %s ** */
1052 warning(282, "ARGSUSED"); 1052 warning(282, "ARGSUSED");
1053 } 1053 }
1054 nargusg = -1; 1054 nargusg = -1;
1055 } 1055 }
1056 if (nvararg != -1) { 1056 if (nvararg != -1) {
1057 if (!silent) { 1057 if (!silent) {
1058 curr_pos = vapos; 1058 curr_pos = vapos;
1059 /* must precede function definition: ** %s ** */ 1059 /* must precede function definition: ** %s ** */
1060 warning(282, "VARARGS"); 1060 warning(282, "VARARGS");
1061 } 1061 }
1062 nvararg = -1; 1062 nvararg = -1;
1063 } 1063 }
1064 if (prflstrg != -1) { 1064 if (prflstrg != -1) {
1065 if (!silent) { 1065 if (!silent) {
1066 curr_pos = printflike_pos; 1066 curr_pos = printflike_pos;
1067 /* must precede function definition: ** %s ** */ 1067 /* must precede function definition: ** %s ** */
1068 warning(282, "PRINTFLIKE"); 1068 warning(282, "PRINTFLIKE");
1069 } 1069 }
1070 prflstrg = -1; 1070 prflstrg = -1;
1071 } 1071 }
1072 if (scflstrg != -1) { 1072 if (scflstrg != -1) {
1073 if (!silent) { 1073 if (!silent) {
1074 curr_pos = scanflike_pos; 1074 curr_pos = scanflike_pos;
1075 /* must precede function definition: ** %s ** */ 1075 /* must precede function definition: ** %s ** */
1076 warning(282, "SCANFLIKE"); 1076 warning(282, "SCANFLIKE");
1077 } 1077 }
1078 scflstrg = -1; 1078 scflstrg = -1;
1079 } 1079 }
1080 1080
1081 curr_pos = cpos; 1081 curr_pos = cpos;
1082 1082
1083 dcs->d_asm = 0; 1083 dcs->d_asm = 0;
1084} 1084}
1085 1085
1086/* 1086/*
1087 * ARGSUSED comment 1087 * ARGSUSED comment
1088 * 1088 *
1089 * Only the first n arguments of the following function are checked 1089 * Only the first n arguments of the following function are checked
1090 * for usage. A missing argument is taken to be 0. 1090 * for usage. A missing argument is taken to be 0.
1091 */ 1091 */
1092void 1092void
1093argsused(int n) 1093argsused(int n)
1094{ 1094{
1095 1095
1096 if (n == -1) 1096 if (n == -1)
1097 n = 0; 1097 n = 0;
1098 1098
1099 if (dcs->d_ctx != EXTERN) { 1099 if (dcs->d_ctx != EXTERN) {
1100 /* must be outside function: ** %s ** */ 1100 /* must be outside function: ** %s ** */
1101 warning(280, "ARGSUSED"); 1101 warning(280, "ARGSUSED");
1102 return; 1102 return;
1103 } 1103 }
1104 if (nargusg != -1) { 1104 if (nargusg != -1) {
1105 /* duplicate use of ** %s ** */ 1105 /* duplicate use of ** %s ** */
1106 warning(281, "ARGSUSED"); 1106 warning(281, "ARGSUSED");
1107 } 1107 }
1108 nargusg = n; 1108 nargusg = n;
1109 argsused_pos = curr_pos; 1109 argsused_pos = curr_pos;
1110} 1110}
1111 1111
1112/* 1112/*
1113 * VARARGS comment 1113 * VARARGS comment
1114 * 1114 *
1115 * Causes lint2 to check only the first n arguments for compatibility 1115 * Causes lint2 to check only the first n arguments for compatibility
1116 * with the function definition. A missing argument is taken to be 0. 1116 * with the function definition. A missing argument is taken to be 0.
1117 */ 1117 */
1118void 1118void
1119varargs(int n) 1119varargs(int n)
1120{ 1120{
1121 1121
1122 if (n == -1) 1122 if (n == -1)
1123 n = 0; 1123 n = 0;
1124 1124
1125 if (dcs->d_ctx != EXTERN) { 1125 if (dcs->d_ctx != EXTERN) {
1126 /* must be outside function: ** %s ** */ 1126 /* must be outside function: ** %s ** */
1127 warning(280, "VARARGS"); 1127 warning(280, "VARARGS");
1128 return; 1128 return;
1129 } 1129 }
1130 if (nvararg != -1) { 1130 if (nvararg != -1) {
1131 /* duplicate use of ** %s ** */ 1131 /* duplicate use of ** %s ** */
1132 warning(281, "VARARGS"); 1132 warning(281, "VARARGS");
1133 } 1133 }
1134 nvararg = n; 1134 nvararg = n;
1135 vapos = curr_pos; 1135 vapos = curr_pos;
1136} 1136}
1137 1137
1138/* 1138/*
1139 * PRINTFLIKE comment 1139 * PRINTFLIKE comment
1140 * 1140 *
1141 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1141 * Check all arguments until the (n-1)-th as usual. The n-th argument is
1142 * used the check the types of remaining arguments. 1142 * used the check the types of remaining arguments.
1143 */ 1143 */
1144void 1144void
1145printflike(int n) 1145printflike(int n)
1146{ 1146{
1147 1147
1148 if (n == -1) 1148 if (n == -1)
1149 n = 0; 1149 n = 0;
1150 1150
1151 if (dcs->d_ctx != EXTERN) { 1151 if (dcs->d_ctx != EXTERN) {
1152 /* must be outside function: ** %s ** */ 1152 /* must be outside function: ** %s ** */
1153 warning(280, "PRINTFLIKE"); 1153 warning(280, "PRINTFLIKE");
1154 return; 1154 return;
1155 } 1155 }
1156 if (prflstrg != -1) { 1156 if (prflstrg != -1) {
1157 /* duplicate use of ** %s ** */ 1157 /* duplicate use of ** %s ** */
1158 warning(281, "PRINTFLIKE"); 1158 warning(281, "PRINTFLIKE");
1159 } 1159 }
1160 prflstrg = n; 1160 prflstrg = n;
1161 printflike_pos = curr_pos; 1161 printflike_pos = curr_pos;
1162} 1162}
1163 1163
1164/* 1164/*
1165 * SCANFLIKE comment 1165 * SCANFLIKE comment
1166 * 1166 *
1167 * Check all arguments until the (n-1)-th as usual. The n-th argument is 1167 * Check all arguments until the (n-1)-th as usual. The n-th argument is
1168 * used the check the types of remaining arguments. 1168 * used the check the types of remaining arguments.
1169 */ 1169 */
1170void 1170void
1171scanflike(int n) 1171scanflike(int n)
1172{ 1172{
1173 1173
1174 if (n == -1) 1174 if (n == -1)
1175 n = 0; 1175 n = 0;
1176 1176
1177 if (dcs->d_ctx != EXTERN) { 1177 if (dcs->d_ctx != EXTERN) {
1178 /* must be outside function: ** %s ** */ 1178 /* must be outside function: ** %s ** */
1179 warning(280, "SCANFLIKE"); 1179 warning(280, "SCANFLIKE");
1180 return; 1180 return;
1181 } 1181 }
1182 if (scflstrg != -1) { 1182 if (scflstrg != -1) {
1183 /* duplicate use of ** %s ** */ 1183 /* duplicate use of ** %s ** */
1184 warning(281, "SCANFLIKE"); 1184 warning(281, "SCANFLIKE");
1185 } 1185 }
1186 scflstrg = n; 1186 scflstrg = n;
1187 scanflike_pos = curr_pos; 1187 scanflike_pos = curr_pos;
1188} 1188}
1189 1189
1190/* 1190/*
1191 * Set the linenumber for a CONSTCOND comment. At this and the following 1191 * Set the linenumber for a CONSTCOND comment. At this and the following
1192 * line no warnings about constants in conditional contexts are printed. 1192 * line no warnings about constants in conditional contexts are printed.
1193 */ 1193 */
1194/* ARGSUSED */ 1194/* ARGSUSED */
1195void 1195void
1196constcond(int n) 1196constcond(int n)
1197{ 1197{
1198 1198
1199 constcond_flag = 1; 1199 constcond_flag = 1;
1200} 1200}
1201 1201
1202/* 1202/*
1203 * Suppress printing of "fallthrough on ..." warnings until next 1203 * Suppress printing of "fallthrough on ..." warnings until next
1204 * statement. 1204 * statement.
1205 */ 1205 */
1206/* ARGSUSED */ 1206/* ARGSUSED */
1207void 1207void
1208fallthru(int n) 1208fallthru(int n)
1209{ 1209{
1210 1210
1211 ftflg = 1; 1211 ftflg = 1;
1212} 1212}
1213 1213
1214/* 1214/*
1215 * Stop warnings about statements which cannot be reached. Also tells lint 1215 * Stop warnings about statements which cannot be reached. Also tells lint
1216 * that the following statements cannot be reached (e.g. after exit()). 1216 * that the following statements cannot be reached (e.g. after exit()).
1217 */ 1217 */
1218/* ARGSUSED */ 1218/* ARGSUSED */
1219void 1219void
1220notreach(int n) 1220notreach(int n)
1221{ 1221{
1222 1222
1223 reached = 0; 1223 reached = 0;
1224 rchflg = 1; 1224 rchflg = 1;
1225} 1225}
1226 1226
1227/* ARGSUSED */ 1227/* ARGSUSED */
1228void 1228void
1229lintlib(int n) 1229lintlib(int n)
1230{ 1230{
1231 1231
1232 if (dcs->d_ctx != EXTERN) { 1232 if (dcs->d_ctx != EXTERN) {
1233 /* must be outside function: ** %s ** */ 1233 /* must be outside function: ** %s ** */
1234 warning(280, "LINTLIBRARY"); 1234 warning(280, "LINTLIBRARY");
1235 return; 1235 return;
1236 } 1236 }
1237 llibflg = 1; 1237 llibflg = 1;
1238 vflag = 0; 1238 vflag = 0;
1239} 1239}
1240 1240
1241/* 1241/*
1242 * Suppress most warnings at the current and the following line. 1242 * Suppress most warnings at the current and the following line.
1243 */ 1243 */
1244/* ARGSUSED */ 1244/* ARGSUSED */
1245void 1245void
1246linted(int n) 1246linted(int n)
1247{ 1247{
1248 1248
1249#ifdef DEBUG 1249#ifdef DEBUG
1250 printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n); 1250 printf("%s, %d: lwarn = %d\n", curr_pos.p_file, curr_pos.p_line, n);
1251#endif 1251#endif
1252 lwarn = n; 1252 lwarn = n;
1253} 1253}
1254 1254
1255/* 1255/*
1256 * Suppress bitfield type errors on the current line. 1256 * Suppress bitfield type errors on the current line.
1257 */ 1257 */
1258/* ARGSUSED */ 1258/* ARGSUSED */
1259void 1259void
1260bitfieldtype(int n) 1260bitfieldtype(int n)
1261{ 1261{
1262 1262
1263#ifdef DEBUG 1263#ifdef DEBUG
1264 printf("%s, %d: bitfieldtype_ok = true\n", curr_pos.p_file, 1264 printf("%s, %d: bitfieldtype_ok = true\n", curr_pos.p_file,
1265 curr_pos.p_line); 1265 curr_pos.p_line);
1266#endif 1266#endif
1267 bitfieldtype_ok = true; 1267 bitfieldtype_ok = true;
1268} 1268}
1269 1269
1270/* 1270/*
1271 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle 1271 * PROTOLIB in conjunction with LINTLIBRARY can be used to handle
1272 * prototypes like function definitions. This is done if the argument 1272 * prototypes like function definitions. This is done if the argument
1273 * to PROTOLIB is nonzero. Otherwise prototypes are handled normally. 1273 * to PROTOLIB is nonzero. Otherwise prototypes are handled normally.
1274 */ 1274 */
1275void 1275void
1276protolib(int n) 1276protolib(int n)
1277{ 1277{
1278 1278
1279 if (dcs->d_ctx != EXTERN) { 1279 if (dcs->d_ctx != EXTERN) {
1280 /* must be outside function: ** %s ** */ 1280 /* must be outside function: ** %s ** */
1281 warning(280, "PROTOLIB"); 1281 warning(280, "PROTOLIB");
1282 return; 1282 return;
1283 } 1283 }
1284 plibflg = n == 0 ? 0 : 1; 1284 plibflg = n == 0 ? 0 : 1;
1285} 1285}
1286 1286
1287/* 1287/*
1288 * Set quadflg to nonzero which means that the next statement/declaration 1288 * Set quadflg to nonzero which means that the next statement/declaration
1289 * may use "long long" without an error or warning. 1289 * may use "long long" without an error or warning.
1290 */ 1290 */
1291/* ARGSUSED */ 1291/* ARGSUSED */
1292void 1292void
1293longlong(int n) 1293longlong(int n)
1294{ 1294{
1295 1295
1296 quadflg = 1; 1296 quadflg = 1;
1297} 1297}

cvs diff -r1.51 -r1.52 src/usr.bin/xlint/lint1/lint1.h (switch to unified diff)

--- src/usr.bin/xlint/lint1/lint1.h 2021/01/03 19:15:36 1.51
+++ src/usr.bin/xlint/lint1/lint1.h 2021/01/03 20:04:08 1.52
@@ -1,461 +1,461 @@ @@ -1,461 +1,461 @@
1/* $NetBSD: lint1.h,v 1.51 2021/01/03 19:15:36 rillig Exp $ */ 1/* $NetBSD: lint1.h,v 1.52 2021/01/03 20:04:08 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software 16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement: 17 * must display the following acknowledgement:
18 * This product includes software developed by Jochen Pohl for 18 * This product includes software developed by Jochen Pohl for
19 * The NetBSD Project. 19 * The NetBSD Project.
20 * 4. The name of the author may not be used to endorse or promote products 20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission. 21 * derived from this software without specific prior written permission.
22 * 22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#include "lint.h" 35#include "lint.h"
36#include "err-msgs.h" 36#include "err-msgs.h"
37#include "op.h" 37#include "op.h"
38 38
39/* 39/*
40 * XXX - Super conservative so that works for most systems, but we should 40 * XXX - Super conservative so that works for most systems, but we should
41 * not depend on the host settings but the target settings in determining 41 * not depend on the host settings but the target settings in determining
42 * the alignment. The only valid use for this is in mem1.c; uses in decl.c 42 * the alignment. The only valid use for this is in mem1.c; uses in decl.c
43 * are bogus. 43 * are bogus.
44 */ 44 */
45#ifndef WORST_ALIGN 45#ifndef WORST_ALIGN
46#ifdef _LP64 46#ifdef _LP64
47# define AVAL 15 47# define AVAL 15
48#else 48#else
49# define AVAL 7 49# define AVAL 7
50#endif 50#endif
51#define WORST_ALIGN(x) (((x) + AVAL) & ~AVAL) 51#define WORST_ALIGN(x) (((x) + AVAL) & ~AVAL)
52#endif 52#endif
53 53
54#define LWARN_BAD -3 54#define LWARN_BAD -3
55#define LWARN_ALL -2 55#define LWARN_ALL -2
56#define LWARN_NONE -1 56#define LWARN_NONE -1
57 57
58/* 58/*
59 * Describes the position of a declaration or anything else. 59 * Describes the position of a declaration or anything else.
60 */ 60 */
61typedef struct { 61typedef struct {
62 int p_line; 62 int p_line;
63 const char *p_file; 63 const char *p_file;
64 int p_uniq; /* uniquifier */ 64 int p_uniq; /* uniquifier */
65} pos_t; 65} pos_t;
66 66
67/* Copies curr_pos, keeping things unique. */ 67/* Copies curr_pos, keeping things unique. */
68#define UNIQUE_CURR_POS(pos) \ 68#define UNIQUE_CURR_POS(pos) \
69 do { \ 69 do { \
70 (pos) = curr_pos; \ 70 (pos) = curr_pos; \
71 curr_pos.p_uniq++; \ 71 curr_pos.p_uniq++; \
72 if (curr_pos.p_file == csrc_pos.p_file) \ 72 if (curr_pos.p_file == csrc_pos.p_file) \
73 csrc_pos.p_uniq++; \ 73 csrc_pos.p_uniq++; \
74 } while (/*CONSTCOND*/0) 74 } while (/*CONSTCOND*/0)
75 75
76/* 76/*
77 * Strings cannot be referenced to simply by a pointer to its first 77 * Strings cannot be referenced to simply by a pointer to its first
78 * char. This is because strings can contain NUL characters other than the 78 * char. This is because strings can contain NUL characters other than the
79 * trailing NUL. 79 * trailing NUL.
80 * 80 *
81 * Strings are stored with a trailing NUL. 81 * Strings are stored with a trailing NUL.
82 */ 82 */
83typedef struct strg { 83typedef struct strg {
84 tspec_t st_tspec; /* CHAR or WCHAR */ 84 tspec_t st_tspec; /* CHAR or WCHAR */
85 size_t st_len; /* length without trailing NUL */ 85 size_t st_len; /* length without trailing NUL */
86 union { 86 union {
87 u_char *_st_cp; 87 u_char *_st_cp;
88 wchar_t *_st_wcp; 88 wchar_t *_st_wcp;
89 } st_u; 89 } st_u;
90} strg_t; 90} strg_t;
91 91
92#define st_cp st_u._st_cp 92#define st_cp st_u._st_cp
93#define st_wcp st_u._st_wcp 93#define st_wcp st_u._st_wcp
94 94
95/* 95/*
96 * qualifiers (only for lex/yacc interface) 96 * qualifiers (only for lex/yacc interface)
97 */ 97 */
98typedef enum { 98typedef enum {
99 CONST, VOLATILE, RESTRICT, THREAD 99 CONST, VOLATILE, RESTRICT, THREAD
100} tqual_t; 100} tqual_t;
101 101
102/* 102/*
103 * Integer and floating point values are stored in this structure 103 * Integer and floating point values are stored in this structure
104 */ 104 */
105typedef struct { 105typedef struct {
106 tspec_t v_tspec; 106 tspec_t v_tspec;
107 int v_ansiu; /* set if an integer constant is 107 int v_ansiu; /* set if an integer constant is
108 unsigned in ANSI C */ 108 unsigned in ANSI C */
109 union { 109 union {
110 int64_t _v_quad; /* integers */ 110 int64_t _v_quad; /* integers */
111 ldbl_t _v_ldbl; /* floats */ 111 ldbl_t _v_ldbl; /* floats */
112 } v_u; 112 } v_u;
113} val_t; 113} val_t;
114 114
115#define v_quad v_u._v_quad 115#define v_quad v_u._v_quad
116#define v_ldbl v_u._v_ldbl 116#define v_ldbl v_u._v_ldbl
117 117
118/* 118/*
119 * Structures of type str_t uniqely identify structures. This can't 119 * Structures of type str_t uniqely identify structures. This can't
120 * be done in structures of type type_t, because these are copied 120 * be done in structures of type type_t, because these are copied
121 * if they must be modified. So it would not be possible to check 121 * if they must be modified. So it would not be possible to check
122 * if two structures are identical by comparing the pointers to 122 * if two structures are identical by comparing the pointers to
123 * the type structures. 123 * the type structures.
124 * 124 *
125 * The typename is used if the structure is unnamed to identify 125 * The typename is used if the structure is unnamed to identify
126 * the structure type in pass 2. 126 * the structure type in pass 2.
127 */ 127 */
128typedef struct { 128typedef struct {
129 u_int size; /* size in bit */ 129 u_int size; /* size in bit */
130 u_int align : 15; /* alignment in bit */ 130 u_int align : 15; /* alignment in bit */
131 bool sincompl : 1; /* set if incomplete type */ 131 bool sincompl : 1; /* set if incomplete type */
132 struct sym *memb; /* list of members */ 132 struct sym *memb; /* list of members */
133 struct sym *stag; /* symbol table entry of tag */ 133 struct sym *stag; /* symbol table entry of tag */
134 struct sym *stdef; /* symbol table entry of first typename */ 134 struct sym *stdef; /* symbol table entry of first typename */
135} str_t; 135} str_t;
136 136
137/* 137/*
138 * same as above for enums 138 * same as above for enums
139 */ 139 */
140typedef struct { 140typedef struct {
141 bool eincompl : 1; /* incomplete enum type */ 141 bool eincompl : 1; /* incomplete enum type */
142 struct sym *elem; /* list of enumerators */ 142 struct sym *elem; /* list of enumerators */
143 struct sym *etag; /* symbol table entry of tag */ 143 struct sym *etag; /* symbol table entry of tag */
144 struct sym *etdef; /* symbol table entry of first typename */ 144 struct sym *etdef; /* symbol table entry of first typename */
145} tenum_t; 145} tenum_t;
146 146
147/* 147/*
148 * Types are represented by concatenation of structures of type type_t 148 * Types are represented by concatenation of structures of type type_t
149 * via t_subt. 149 * via t_subt.
150 */ 150 */
151struct type { 151struct type {
152 tspec_t t_tspec; /* type specifier */ 152 tspec_t t_tspec; /* type specifier */
153 bool t_aincompl : 1; /* incomplete array type */ 153 bool t_aincompl : 1; /* incomplete array type */
154 bool t_const : 1; /* const modifier */ 154 bool t_const : 1; /* const modifier */
155 bool t_volatile : 1; /* volatile modifier */ 155 bool t_volatile : 1; /* volatile modifier */
156 bool t_proto : 1; /* function prototype (t_args valid) */ 156 bool t_proto : 1; /* function prototype (t_args valid) */
157 bool t_vararg : 1; /* prototype with ... */ 157 bool t_vararg : 1; /* prototype with ... */
158 bool t_typedef : 1; /* type defined with typedef */ 158 bool t_typedef : 1; /* type defined with typedef */
159 bool t_bitfield : 1; 159 bool t_bitfield : 1;
160 bool t_isenum : 1; /* type is (or was) enum (t_enum valid) */ 160 bool t_isenum : 1; /* type is (or was) enum (t_enum valid) */
161 bool t_packed : 1; 161 bool t_packed : 1;
162 union { 162 union {
163 int _t_dim; /* dimension */ 163 int _t_dim; /* dimension */
164 str_t *_t_str; /* struct/union tag */ 164 str_t *_t_str; /* struct/union tag */
165 tenum_t *_t_enum; /* enum tag */ 165 tenum_t *_t_enum; /* enum tag */
166 struct sym *_t_args; /* arguments (if t_proto) */ 166 struct sym *_t_args; /* arguments (if t_proto) */
167 } t_u; 167 } t_u;
168 struct { 168 struct {
169 u_int _t_flen : 8; /* length of bit-field */ 169 u_int _t_flen : 8; /* length of bit-field */
170 u_int _t_foffs : 24; /* offset of bit-field */ 170 u_int _t_foffs : 24; /* offset of bit-field */
171 } t_b; 171 } t_b;
172 struct type *t_subt; /* element type (arrays), return value 172 struct type *t_subt; /* element type (arrays), return value
173 (functions), or type pointer points to */ 173 (functions), or type pointer points to */
174}; 174};
175 175
176#define t_dim t_u._t_dim 176#define t_dim t_u._t_dim
177#define t_str t_u._t_str 177#define t_str t_u._t_str
178#define t_enum t_u._t_enum 178#define t_enum t_u._t_enum
179#define t_args t_u._t_args 179#define t_args t_u._t_args
180#define t_flen t_b._t_flen 180#define t_flen t_b._t_flen
181#define t_foffs t_b._t_foffs 181#define t_foffs t_b._t_foffs
182 182
183/* 183/*
184 * types of symbols 184 * types of symbols
185 */ 185 */
186typedef enum { 186typedef enum {
187 FVFT, /* variables, functions, type names, enums */ 187 FVFT, /* variables, functions, type names, enums */
188 FMEMBER, /* members of structs or unions */ 188 FMEMBER, /* members of structs or unions */
189 FTAG, /* tags */ 189 FTAG, /* tags */
190 FLABEL /* labels */ 190 FLABEL /* labels */
191} symt_t; 191} symt_t;
192 192
193/* 193/*
194 * storage classes 194 * storage classes
195 */ 195 */
196typedef enum { 196typedef enum {
197 NOSCL, 197 NOSCL,
198 EXTERN, /* external symbols (indep. of decl_t) */ 198 EXTERN, /* external symbols (indep. of decl_t) */
199 STATIC, /* static symbols (local and global) */ 199 STATIC, /* static symbols (local and global) */
200 AUTO, /* automatic symbols (except register) */ 200 AUTO, /* automatic symbols (except register) */
201 REG, /* register */ 201 REG, /* register */
202 TYPEDEF, /* typedef */ 202 TYPEDEF, /* typedef */
203 STRTAG, 203 STRTAG,
204 UNIONTAG, 204 UNIONTAG,
205 ENUMTAG, 205 ENUMTAG,
206 MOS, /* member of struct */ 206 MOS, /* member of struct */
207 MOU, /* member of union */ 207 MOU, /* member of union */
208 ENUMCON, /* enumerator, enum constant */ 208 ENUMCON, /* enumerator, enum constant */
209 ABSTRACT, /* abstract symbol (sizeof, casts, unnamed argument) */ 209 ABSTRACT, /* abstract symbol (sizeof, casts, unnamed argument) */
210 ARG, /* argument */ 210 ARG, /* argument */
211 PARG, /* used in declaration stack during prototype 211 PARG, /* used in declaration stack during prototype
212 declaration */ 212 declaration */
213 INLINE /* only used by the parser */ 213 INLINE /* only used by the parser */
214} scl_t; 214} scl_t;
215 215
216/* 216/*
217 * symbol table entry 217 * symbol table entry
218 */ 218 */
219typedef struct sym { 219typedef struct sym {
220 const char *s_name; 220 const char *s_name;
221 const char *s_rename; /* renamed symbol's given name */ 221 const char *s_rename; /* renamed symbol's given name */
222 pos_t s_def_pos; /* position of last (prototype) definition, 222 pos_t s_def_pos; /* position of last (prototype) definition,
223 prototype declaration, no-prototype-def., 223 prototype declaration, no-prototype-def.,
224 tentative definition or declaration, 224 tentative definition or declaration,
225 in this order */ 225 in this order */
226 pos_t s_set_pos; /* position of first initialisation */ 226 pos_t s_set_pos; /* position of first initialisation */
227 pos_t s_use_pos; /* position of first use */ 227 pos_t s_use_pos; /* position of first use */
228 symt_t s_kind; /* type of symbol */ 228 symt_t s_kind; /* type of symbol */
229 void *s_keyword; 229 void *s_keyword;
230 bool s_bitfield : 1; 230 bool s_bitfield : 1;
231 bool s_set : 1; /* variable set, label defined */ 231 bool s_set : 1; /* variable set, label defined */
232 bool s_used : 1; /* variable/label used */ 232 bool s_used : 1; /* variable/label used */
233 bool s_arg : 1; /* symbol is function argument */ 233 bool s_arg : 1; /* symbol is function argument */
234 bool s_reg : 1; /* symbol is register variable */ 234 bool s_reg : 1; /* symbol is register variable */
235 bool s_defarg : 1; /* undefined symbol in old style function 235 bool s_defarg : 1; /* undefined symbol in old style function
236 definition */ 236 definition */
237 bool s_rimpl : 1; /* return value of function implicit decl. */ 237 bool s_rimpl : 1; /* return value of function implicit decl. */
238 bool s_osdef : 1; /* symbol stems from old style function def. */ 238 bool s_osdef : 1; /* symbol stems from old style function def. */
239 bool s_inline : 1; /* true if this is an inline function */ 239 bool s_inline : 1; /* true if this is an inline function */
240 struct sym *s_ext_sym; /* for local declared external symbols pointer 240 struct sym *s_ext_sym; /* for local declared external symbols pointer
241 to external symbol with same name */ 241 to external symbol with same name */
242 def_t s_def; /* declared, tentative defined, defined */ 242 def_t s_def; /* declared, tentative defined, defined */
243 scl_t s_scl; /* storage class */ 243 scl_t s_scl; /* storage class */
244 int s_blklev; /* level of declaration, -1 if not in symbol 244 int s_blklev; /* level of declaration, -1 if not in symbol
245 table */ 245 table */
246 type_t *s_type; 246 type_t *s_type;
247 val_t s_value; /* value (if enum constant) */ 247 val_t s_value; /* value (if enum constant) */
248 union { 248 union {
249 str_t *_s_st; /* tag, if it is a struct/union member */ 249 str_t *_s_st; /* tag, if it is a struct/union member */
250 tenum_t *_s_et; /* tag, if it is an enumerator */ 250 tenum_t *_s_et; /* tag, if it is an enumerator */
251 tspec_t _s_tsp; /* type (only for keywords) */ 251 tspec_t _s_tsp; /* type (only for keywords) */
252 tqual_t _s_tqu; /* qualifier (only for keywords) */ 252 tqual_t _s_tqu; /* qualifier (only for keywords) */
253 struct sym *_s_args; /* arguments in old style function 253 struct sym *_s_args; /* arguments in old style function
254 definitions */ 254 definitions */
255 } u; 255 } u;
256 struct sym *s_link; /* next symbol with same hash value */ 256 struct sym *s_link; /* next symbol with same hash value */
257 struct sym **s_rlink; /* pointer to s_link of prev. symbol */ 257 struct sym **s_rlink; /* pointer to s_link of prev. symbol */
258 struct sym *s_next; /* next struct/union member, enumerator, 258 struct sym *s_next; /* next struct/union member, enumerator,
259 argument */ 259 argument */
260 struct sym *s_dlnxt; /* next symbol declared on same level */ 260 struct sym *s_dlnxt; /* next symbol declared on same level */
261} sym_t; 261} sym_t;
262 262
263#define s_styp u._s_st 263#define s_styp u._s_st
264#define s_etyp u._s_et 264#define s_etyp u._s_et
265#define s_tspec u._s_tsp 265#define s_tspec u._s_tsp
266#define s_tqual u._s_tqu 266#define s_tqual u._s_tqu
267#define s_args u._s_args 267#define s_args u._s_args
268 268
269/* 269/*
270 * Used to keep some information about symbols before they are entered 270 * Used to keep some information about symbols before they are entered
271 * into the symbol table. 271 * into the symbol table.
272 */ 272 */
273typedef struct sbuf { 273typedef struct sbuf {
274 const char *sb_name; /* name of symbol */ 274 const char *sb_name; /* name of symbol */
275 size_t sb_len; /* length (without '\0') */ 275 size_t sb_len; /* length (without '\0') */
276 int sb_hash; /* hash value */ 276 int sb_hash; /* hash value */
277 sym_t *sb_sym; /* symbol table entry */ 277 sym_t *sb_sym; /* symbol table entry */
278 struct sbuf *sb_next; /* for freelist */ 278 struct sbuf *sb_next; /* for freelist */
279} sbuf_t; 279} sbuf_t;
280 280
281 281
282/* 282/*
283 * tree node 283 * tree node
284 */ 284 */
285typedef struct tnode { 285typedef struct tnode {
286 op_t tn_op; /* operator */ 286 op_t tn_op; /* operator */
287 type_t *tn_type; /* type */ 287 type_t *tn_type; /* type */
288 bool tn_lvalue : 1; /* node is lvalue */ 288 bool tn_lvalue : 1; /* node is lvalue */
289 bool tn_cast : 1; /* if tn_op == CVT, it's an explicit cast */ 289 bool tn_cast : 1; /* if tn_op == CVT, it's an explicit cast */
290 bool tn_parenthesized : 1; 290 bool tn_parenthesized : 1;
291 union { 291 union {
292 struct { 292 struct {
293 struct tnode *_tn_left; /* (left) operand */ 293 struct tnode *_tn_left; /* (left) operand */
294 struct tnode *_tn_right; /* right operand */ 294 struct tnode *_tn_right; /* right operand */
295 } tn_s; 295 } tn_s;
296 sym_t *_tn_sym; /* symbol if op == NAME */ 296 sym_t *_tn_sym; /* symbol if op == NAME */
297 val_t *_tn_val; /* value if op == CON */ 297 val_t *_tn_val; /* value if op == CON */
298 strg_t *_tn_string; /* string if op == STRING */ 298 strg_t *_tn_string; /* string if op == STRING */
299 } tn_u; 299 } tn_u;
300} tnode_t; 300} tnode_t;
301 301
302#define tn_left tn_u.tn_s._tn_left 302#define tn_left tn_u.tn_s._tn_left
303#define tn_right tn_u.tn_s._tn_right 303#define tn_right tn_u.tn_s._tn_right
304#define tn_sym tn_u._tn_sym 304#define tn_sym tn_u._tn_sym
305#define tn_val tn_u._tn_val 305#define tn_val tn_u._tn_val
306#define tn_string tn_u._tn_string 306#define tn_string tn_u._tn_string
307 307
308/* 308/*
309 * For nested declarations a stack exists, which holds all information 309 * For nested declarations a stack exists, which holds all information
310 * needed for the current level. dcs points to the top element of this 310 * needed for the current level. dcs points to the top element of this
311 * stack. 311 * stack.
312 * 312 *
313 * ctx describes the context of the current declaration. Its value is 313 * ctx describes the context of the current declaration. Its value is
314 * one of 314 * one of
315 * EXTERN global declarations 315 * EXTERN global declarations
316 * MOS oder MOU declarations of struct or union members 316 * MOS oder MOU declarations of struct or union members
317 * ENUMCON declarations of enums 317 * ENUMCON declarations of enums
318 * ARG declaration of arguments in old style function definitions 318 * ARG declaration of arguments in old style function definitions
319 * PARG declaration of arguments in function prototypes 319 * PARG declaration of arguments in function prototypes
320 * AUTO declaration of local symbols 320 * AUTO declaration of local symbols
321 * ABSTRACT abstract declarations (sizeof, casts) 321 * ABSTRACT abstract declarations (sizeof, casts)
322 * 322 *
323 */ 323 */
324typedef struct dinfo { 324typedef struct dinfo {
325 tspec_t d_atyp; /* VOID, CHAR, INT, or COMPLEX */ 325 tspec_t d_atyp; /* VOID, CHAR, INT, or COMPLEX */
326 tspec_t d_cmod; /* FLOAT, or DOUBLE */ 326 tspec_t d_cmod; /* FLOAT, or DOUBLE */
327 tspec_t d_smod; /* SIGNED or UNSIGN */ 327 tspec_t d_smod; /* SIGNED or UNSIGN */
328 tspec_t d_lmod; /* SHORT, LONG or QUAD */ 328 tspec_t d_lmod; /* SHORT, LONG or QUAD */
329 scl_t d_scl; /* storage class */ 329 scl_t d_scl; /* storage class */
330 type_t *d_type; /* after deftyp() pointer to the type used 330 type_t *d_type; /* after deftyp() pointer to the type used
331 for all declarators */ 331 for all declarators */
332 sym_t *d_rdcsym; /* redeclared symbol */ 332 sym_t *d_rdcsym; /* redeclared symbol */
333 int d_offset; /* offset of next structure member */ 333 int d_offset; /* offset of next structure member */
334 int d_stralign; /* alignment required for current structure */ 334 int d_stralign; /* alignment required for current structure */
335 scl_t d_ctx; /* context of declaration */ 335 scl_t d_ctx; /* context of declaration */
336 bool d_const : 1; /* const in declaration specifiers */ 336 bool d_const : 1; /* const in declaration specifiers */
337 bool d_volatile : 1; /* volatile in declaration specifiers */ 337 bool d_volatile : 1; /* volatile in declaration specifiers */
338 bool d_inline : 1; /* inline in declaration specifiers */ 338 bool d_inline : 1; /* inline in declaration specifiers */
339 bool d_mscl : 1; /* multiple storage classes */ 339 bool d_mscl : 1; /* multiple storage classes */
340 bool d_terr : 1; /* invalid type combination */ 340 bool d_terr : 1; /* invalid type combination */
341 bool d_nedecl : 1; /* if at least one tag is declared */ 341 bool d_nedecl : 1; /* if at least one tag is declared */
342 bool d_vararg : 1; /* ... in in current function decl. */ 342 bool d_vararg : 1; /* ... in in current function decl. */
343 bool d_proto : 1; /* current function decl. is prototype */ 343 bool d_proto : 1; /* current function decl. is prototype */
344 bool d_notyp : 1; /* set if no type specifier was present */ 344 bool d_notyp : 1; /* set if no type specifier was present */
345 bool d_asm : 1; /* set if d_ctx == AUTO and asm() present */ 345 bool d_asm : 1; /* set if d_ctx == AUTO and asm() present */
346 bool d_packed : 1; 346 bool d_packed : 1;
347 bool d_used : 1; 347 bool d_used : 1;
348 type_t *d_tagtyp; /* tag during member declaration */ 348 type_t *d_tagtyp; /* tag during member declaration */
349 sym_t *d_fargs; /* list of arguments during function def. */ 349 sym_t *d_fargs; /* list of arguments during function def. */
350 pos_t d_fdpos; /* position of function definition */ 350 pos_t d_fdpos; /* position of function definition */
351 sym_t *d_dlsyms; /* first symbol declared at this level */ 351 sym_t *d_dlsyms; /* first symbol declared at this level */
352 sym_t **d_ldlsym; /* points to s_dlnxt in last symbol decl. 352 sym_t **d_ldlsym; /* points to s_dlnxt in last symbol decl.
353 at this level */ 353 at this level */
354 sym_t *d_fpsyms; /* symbols defined in prototype */ 354 sym_t *d_fpsyms; /* symbols defined in prototype */
355 struct dinfo *d_next; /* next level */ 355 struct dinfo *d_next; /* next level */
356} dinfo_t; 356} dinfo_t;
357 357
358/* 358/*
359 * Used to collect information about pointers and qualifiers in 359 * Used to collect information about pointers and qualifiers in
360 * declarators. 360 * declarators.
361 */ 361 */
362typedef struct pqinf { 362typedef struct pqinf {
363 int p_pcnt; /* number of asterisks */ 363 int p_pcnt; /* number of asterisks */
364 bool p_const : 1; 364 bool p_const : 1;
365 bool p_volatile : 1; 365 bool p_volatile : 1;
366 struct pqinf *p_next; 366 struct pqinf *p_next;
367} pqinf_t; 367} pqinf_t;
368 368
369/* 369/*
370 * Case values are stored in a list of type clst_t. 370 * Case values are stored in a list of type clst_t.
371 */ 371 */
372typedef struct clst { 372typedef struct clst {
373 val_t cl_val; 373 val_t cl_val;
374 struct clst *cl_next; 374 struct clst *cl_next;
375} clst_t; 375} clst_t;
376 376
377/* 377/*
378 * Used to keep information about nested control statements. 378 * Used to keep information about nested control statements.
379 */ 379 */
380typedef struct cstk { 380typedef struct control_statement {
381 int c_env; /* type of statement (T_IF, ...) */ 381 int c_env; /* type of statement (T_IF, ...) */
382 bool c_loop : 1; /* continue && break are valid */ 382 bool c_loop : 1; /* continue && break are valid */
383 bool c_switch : 1; /* case && break are valid */ 383 bool c_switch : 1; /* case && break are valid */
384 bool c_break : 1; /* loop/switch has break */ 384 bool c_break : 1; /* loop/switch has break */
385 bool c_cont : 1; /* loop has continue */ 385 bool c_cont : 1; /* loop has continue */
386 bool c_default : 1; /* switch has default */ 386 bool c_default : 1; /* switch has default */
387 bool c_infinite : 1; /* break condition always false 387 bool c_infinite : 1; /* break condition always false
388 (for (;;), while (1)) */ 388 (for (;;), while (1)) */
389 bool c_rchif : 1; /* end of if-branch reached */ 389 bool c_rchif : 1; /* end of if-branch reached */
390 bool c_noretval : 1; /* had "return;" */ 390 bool c_noretval : 1; /* had "return;" */
391 bool c_retval : 1; /* had "return (e);" */ 391 bool c_retval : 1; /* had "return (e);" */
392 type_t *c_swtype; /* type of switch expression */ 392 type_t *c_swtype; /* type of switch expression */
393 clst_t *c_clst; /* list of case values */ 393 clst_t *c_clst; /* list of case values */
394 struct mbl *c_fexprm; /* saved memory for end of loop 394 struct mbl *c_fexprm; /* saved memory for end of loop
395 expression in for() */ 395 expression in for() */
396 tnode_t *c_f3expr; /* end of loop expr in for() */ 396 tnode_t *c_f3expr; /* end of loop expr in for() */
397 pos_t c_fpos; /* position of end of loop expr */ 397 pos_t c_fpos; /* position of end of loop expr */
398 pos_t c_cfpos; /* same for csrc_pos */ 398 pos_t c_cfpos; /* same for csrc_pos */
399 struct cstk *c_next; /* outer control statement */ 399 struct control_statement *c_surrounding;
400} cstk_t; 400} cstk_t;
401 401
402typedef struct { 402typedef struct {
403 size_t lo; 403 size_t lo;
404 size_t hi; 404 size_t hi;
405} range_t; 405} range_t;
406 406
407#include "externs1.h" 407#include "externs1.h"
408 408
409#define ERR_SETSIZE 1024 409#define ERR_SETSIZE 1024
410#define __NERRBITS (sizeof(unsigned int)) 410#define __NERRBITS (sizeof(unsigned int))
411 411
412typedef struct err_set { 412typedef struct err_set {
413 unsigned int errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS]; 413 unsigned int errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS];
414} err_set; 414} err_set;
415 415
416#define ERR_SET(n, p) \ 416#define ERR_SET(n, p) \
417 ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS))) 417 ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS)))
418#define ERR_CLR(n, p) \ 418#define ERR_CLR(n, p) \
419 ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS))) 419 ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS)))
420#define ERR_ISSET(n, p) \ 420#define ERR_ISSET(n, p) \
421 ((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) 421 ((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS)))
422#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p))) 422#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
423 423
424#define LERROR(fmt, args...) lerror(__FILE__, __LINE__, fmt, ##args) 424#define LERROR(fmt, args...) lerror(__FILE__, __LINE__, fmt, ##args)
425 425
426#define lint_assert(cond) \ 426#define lint_assert(cond) \
427 do { \ 427 do { \
428 if (!(cond)) \ 428 if (!(cond)) \
429 assert_failed(__FILE__, __LINE__, __func__, #cond); \ 429 assert_failed(__FILE__, __LINE__, __func__, #cond); \
430 } while (/*CONSTCOND*/0) 430 } while (/*CONSTCOND*/0)
431 431
432#ifdef BLKDEBUG 432#ifdef BLKDEBUG
433#define ZERO 0xa5 433#define ZERO 0xa5
434#else 434#else
435#define ZERO 0 435#define ZERO 0
436#endif 436#endif
437 437
438extern err_set msgset; 438extern err_set msgset;
439 439
440 440
441#ifdef DEBUG 441#ifdef DEBUG
442# include "err-msgs.h" 442# include "err-msgs.h"
443 443
444/* ARGSUSED */ 444/* ARGSUSED */
445static inline void __attribute__((format(printf, 1, 2))) 445static inline void __attribute__((format(printf, 1, 2)))
446check_printf(const char *fmt, ...) 446check_printf(const char *fmt, ...)
447{ 447{
448} 448}
449 449
450# define wrap_check_printf(func, id, args...) \ 450# define wrap_check_printf(func, id, args...) \
451 do { \ 451 do { \
452 check_printf(__CONCAT(MSG_, id), ##args); \ 452 check_printf(__CONCAT(MSG_, id), ##args); \
453 (func)(id, ##args); \ 453 (func)(id, ##args); \
454 } while (/*CONSTCOND*/0) 454 } while (/*CONSTCOND*/0)
455 455
456# define error(id, args...) wrap_check_printf(error, id, ##args) 456# define error(id, args...) wrap_check_printf(error, id, ##args)
457# define warning(id, args...) wrap_check_printf(warning, id, ##args) 457# define warning(id, args...) wrap_check_printf(warning, id, ##args)
458# define message(id, args...) wrap_check_printf(message, id, ##args) 458# define message(id, args...) wrap_check_printf(message, id, ##args)
459# define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args) 459# define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args)
460# define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args) 460# define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args)
461#endif 461#endif