decl.c (80284) | decl.c (91592) |
---|---|
1/* $NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $ */ | 1/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */ |
2 3/* | 2 3/* |
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
|
4 * Copyright (c) 1994, 1995 Jochen Pohl 5 * All Rights Reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 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 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 | 5 * Copyright (c) 1994, 1995 Jochen Pohl 6 * All Rights Reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 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 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 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 |
34#ifndef lint 35static const char rcsid[] = 36 "$FreeBSD: head/usr.bin/xlint/lint1/decl.c 80284 2001-07-24 14:02:07Z obrien $"; | 35#include <sys/cdefs.h> 36#if defined(__RCSID) && !defined(lint) 37__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $"); |
37#endif | 38#endif |
39__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/decl.c 91592 2002-03-03 15:12:50Z markm $"); |
|
38 39#include <sys/param.h> 40#include <limits.h> 41#include <stdlib.h> 42#include <string.h> 43 44#include "lint1.h" 45 46const char *unnamed = "<unnamed>"; 47 | 40 41#include <sys/param.h> 42#include <limits.h> 43#include <stdlib.h> 44#include <string.h> 45 46#include "lint1.h" 47 48const char *unnamed = "<unnamed>"; 49 |
48/* contains various information and classification on types */ 49ttab_t ttab[NTSPEC]; 50 | |
51/* shared type structures for arithmtic types and void */ 52static type_t *typetab; 53 54/* value of next enumerator during declaration of enum types */ 55int enumval; 56 57/* 58 * pointer to top element of a stack which contains informations local 59 * to nested declarations 60 */ 61dinfo_t *dcs; 62 | 50/* shared type structures for arithmtic types and void */ 51static type_t *typetab; 52 53/* value of next enumerator during declaration of enum types */ 54int enumval; 55 56/* 57 * pointer to top element of a stack which contains informations local 58 * to nested declarations 59 */ 60dinfo_t *dcs; 61 |
63static type_t *tdeferr __P((type_t *, tspec_t)); 64static void settdsym __P((type_t *, sym_t *)); 65static tspec_t mrgtspec __P((tspec_t, tspec_t)); 66static void align __P((int, int)); 67static sym_t *newtag __P((sym_t *, scl_t, int, int)); 68static int eqargs __P((type_t *, type_t *, int *)); 69static int mnoarg __P((type_t *, int *)); 70static int chkosdef __P((sym_t *, sym_t *)); 71static int chkptdecl __P((sym_t *, sym_t *)); 72static sym_t *nsfunc __P((sym_t *, sym_t *)); 73static void osfunc __P((sym_t *, sym_t *)); 74static void ledecl __P((sym_t *)); 75static int chkinit __P((sym_t *)); 76static void chkausg __P((int, sym_t *)); 77static void chkvusg __P((int, sym_t *)); 78static void chklusg __P((sym_t *)); 79static void chktusg __P((sym_t *)); 80static void chkglvar __P((sym_t *)); 81static void glchksz __P((sym_t *)); | 62static type_t *tdeferr(type_t *, tspec_t); 63static void settdsym(type_t *, sym_t *); 64static tspec_t mrgtspec(tspec_t, tspec_t); 65static void align(int, int); 66static sym_t *newtag(sym_t *, scl_t, int, int); 67static int eqargs(type_t *, type_t *, int *); 68static int mnoarg(type_t *, int *); 69static int chkosdef(sym_t *, sym_t *); 70static int chkptdecl(sym_t *, sym_t *); 71static sym_t *nsfunc(sym_t *, sym_t *); 72static void osfunc(sym_t *, sym_t *); 73static void ledecl(sym_t *); 74static int chkinit(sym_t *); 75static void chkausg(int, sym_t *); 76static void chkvusg(int, sym_t *); 77static void chklusg(sym_t *); 78static void chktusg(sym_t *); 79static void chkglvar(sym_t *); 80static void glchksz(sym_t *); |
82 83/* 84 * initializes all global vars used in declarations 85 */ 86void | 81 82/* 83 * initializes all global vars used in declarations 84 */ 85void |
87initdecl() | 86initdecl(void) |
88{ | 87{ |
89 int i; 90 static struct { 91 tspec_t it_tspec; 92 ttab_t it_ttab; 93 } ittab[] = { 94 { SIGNED, { 0, 0, 95 SIGNED, UNSIGN, 96 0, 0, 0, 0, 0, "signed" } }, 97 { UNSIGN, { 0, 0, 98 SIGNED, UNSIGN, 99 0, 0, 0, 0, 0, "unsigned" } }, 100 { CHAR, { CHAR_BIT, CHAR_BIT, 101 SCHAR, UCHAR, 102 1, 0, 0, 1, 1, "char" } }, 103 { SCHAR, { CHAR_BIT, CHAR_BIT, 104 SCHAR, UCHAR, 105 1, 0, 0, 1, 1, "signed char" } }, 106 { UCHAR, { CHAR_BIT, CHAR_BIT, 107 SCHAR, UCHAR, 108 1, 1, 0, 1, 1, "unsigned char" } }, 109 { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, 110 SHORT, USHORT, 111 1, 0, 0, 1, 1, "short" } }, 112 { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, 113 SHORT, USHORT, 114 1, 1, 0, 1, 1, "unsigned short" } }, 115 { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 116 INT, UINT, 117 1, 0, 0, 1, 1, "int" } }, 118 { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, 119 INT, UINT, 120 1, 1, 0, 1, 1, "unsigned int" } }, 121 { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, 122 LONG, ULONG, 123 1, 0, 0, 1, 1, "long" } }, 124 { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, 125 LONG, ULONG, 126 1, 1, 0, 1, 1, "unsigned long" } }, 127 { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, 128 QUAD, UQUAD, 129 1, 0, 0, 1, 1, "long long" } }, 130 { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, 131 QUAD, UQUAD, 132 1, 1, 0, 1, 1, "unsigned long long" } }, 133 { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, 134 FLOAT, FLOAT, 135 0, 0, 1, 1, 1, "float" } }, 136 { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, 137 DOUBLE, DOUBLE, 138 0, 0, 1, 1, 1, "double" } }, 139 { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, 140 LDOUBLE, LDOUBLE, 141 0, 0, 1, 1, 1, "long double" } }, 142 { VOID, { -1, -1, 143 VOID, VOID, 144 0, 0, 0, 0, 0, "void" } }, 145 { STRUCT, { -1, -1, 146 STRUCT, STRUCT, 147 0, 0, 0, 0, 0, "struct" } }, 148 { UNION, { -1, -1, 149 UNION, UNION, 150 0, 0, 0, 0, 0, "union" } }, 151 { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 152 ENUM, ENUM, 153 1, 0, 0, 1, 1, "enum" } }, 154 { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, 155 PTR, PTR, 156 0, 1, 0, 0, 1, "pointer" } }, 157 { ARRAY, { -1, -1, 158 ARRAY, ARRAY, 159 0, 0, 0, 0, 0, "array" } }, 160 { FUNC, { -1, -1, 161 FUNC, FUNC, 162 0, 0, 0, 0, 0, "function" } }, 163 }; | 88 int i; |
164 165 /* declaration stack */ 166 if ((dcs = calloc(1, sizeof (dinfo_t))) == NULL) 167 nomem(); 168 dcs->d_ctx = EXTERN; 169 dcs->d_ldlsym = &dcs->d_dlsyms; 170 171 /* type information and classification */ | 89 90 /* declaration stack */ 91 if ((dcs = calloc(1, sizeof (dinfo_t))) == NULL) 92 nomem(); 93 dcs->d_ctx = EXTERN; 94 dcs->d_ldlsym = &dcs->d_dlsyms; 95 96 /* type information and classification */ |
172 for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++) 173 STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab); 174 if (!pflag) { 175 for (i = 0; i < NTSPEC; i++) 176 ttab[i].tt_psz = ttab[i].tt_sz; 177 } 178 | 97 inittyp(); 98 |
179 /* shared type structures */ 180 if ((typetab = calloc(NTSPEC, sizeof (type_t))) == NULL) 181 nomem(); 182 for (i = 0; i < NTSPEC; i++) 183 typetab[i].t_tspec = NOTSPEC; 184 typetab[CHAR].t_tspec = CHAR; 185 typetab[SCHAR].t_tspec = SCHAR; 186 typetab[UCHAR].t_tspec = UCHAR; --- 19 unchanged lines hidden (view full) --- 206 207/* 208 * Returns a shared type structure vor arithmetic types and void. 209 * 210 * It's important do duplicate this structure (using duptyp() or tdupdyp()) 211 * if it is to be modified (adding qualifiers or anything else). 212 */ 213type_t * | 99 /* shared type structures */ 100 if ((typetab = calloc(NTSPEC, sizeof (type_t))) == NULL) 101 nomem(); 102 for (i = 0; i < NTSPEC; i++) 103 typetab[i].t_tspec = NOTSPEC; 104 typetab[CHAR].t_tspec = CHAR; 105 typetab[SCHAR].t_tspec = SCHAR; 106 typetab[UCHAR].t_tspec = UCHAR; --- 19 unchanged lines hidden (view full) --- 126 127/* 128 * Returns a shared type structure vor arithmetic types and void. 129 * 130 * It's important do duplicate this structure (using duptyp() or tdupdyp()) 131 * if it is to be modified (adding qualifiers or anything else). 132 */ 133type_t * |
214gettyp(t) 215 tspec_t t; | 134gettyp(tspec_t t) |
216{ | 135{ |
136 |
|
217 return (&typetab[t]); 218} 219 220type_t * | 137 return (&typetab[t]); 138} 139 140type_t * |
221duptyp(tp) 222 const type_t *tp; | 141duptyp(const type_t *tp) |
223{ 224 type_t *ntp; 225 226 ntp = getblk(sizeof (type_t)); 227 STRUCT_ASSIGN(*ntp, *tp); 228 return (ntp); 229} 230 231/* 232 * Use tduptyp() instead of duptyp() inside expressions (if the 233 * allocated memory should be freed after the expr). 234 */ 235type_t * | 142{ 143 type_t *ntp; 144 145 ntp = getblk(sizeof (type_t)); 146 STRUCT_ASSIGN(*ntp, *tp); 147 return (ntp); 148} 149 150/* 151 * Use tduptyp() instead of duptyp() inside expressions (if the 152 * allocated memory should be freed after the expr). 153 */ 154type_t * |
236tduptyp(tp) 237 const type_t *tp; | 155tduptyp(const type_t *tp) |
238{ 239 type_t *ntp; 240 241 ntp = tgetblk(sizeof (type_t)); 242 STRUCT_ASSIGN(*ntp, *tp); 243 return (ntp); 244} 245 246/* 247 * Returns 1 if the argument is void or an incomplete array, 248 * struct, union or enum type. 249 */ 250int | 156{ 157 type_t *ntp; 158 159 ntp = tgetblk(sizeof (type_t)); 160 STRUCT_ASSIGN(*ntp, *tp); 161 return (ntp); 162} 163 164/* 165 * Returns 1 if the argument is void or an incomplete array, 166 * struct, union or enum type. 167 */ 168int |
251incompl(tp) 252 type_t *tp; | 169incompl(type_t *tp) |
253{ 254 tspec_t t; 255 256 if ((t = tp->t_tspec) == VOID) { 257 return (1); 258 } else if (t == ARRAY) { 259 return (tp->t_aincompl); 260 } else if (t == STRUCT || t == UNION) { --- 4 unchanged lines hidden (view full) --- 265 return (0); 266} 267 268/* 269 * Set the flag for (in)complete array, struct, union or enum 270 * types. 271 */ 272void | 170{ 171 tspec_t t; 172 173 if ((t = tp->t_tspec) == VOID) { 174 return (1); 175 } else if (t == ARRAY) { 176 return (tp->t_aincompl); 177 } else if (t == STRUCT || t == UNION) { --- 4 unchanged lines hidden (view full) --- 182 return (0); 183} 184 185/* 186 * Set the flag for (in)complete array, struct, union or enum 187 * types. 188 */ 189void |
273setcompl(tp, ic) 274 type_t *tp; 275 int ic; | 190setcompl(type_t *tp, int ic) |
276{ 277 tspec_t t; 278 279 if ((t = tp->t_tspec) == ARRAY) { 280 tp->t_aincompl = ic; 281 } else if (t == STRUCT || t == UNION) { 282 tp->t_str->sincompl = ic; 283 } else { --- 4 unchanged lines hidden (view full) --- 288} 289 290/* 291 * Remember the storage class of the current declaration in dcs->d_scl 292 * (the top element of the declaration stack) and detect multiple 293 * storage classes. 294 */ 295void | 191{ 192 tspec_t t; 193 194 if ((t = tp->t_tspec) == ARRAY) { 195 tp->t_aincompl = ic; 196 } else if (t == STRUCT || t == UNION) { 197 tp->t_str->sincompl = ic; 198 } else { --- 4 unchanged lines hidden (view full) --- 203} 204 205/* 206 * Remember the storage class of the current declaration in dcs->d_scl 207 * (the top element of the declaration stack) and detect multiple 208 * storage classes. 209 */ 210void |
296addscl(sc) 297 scl_t sc; | 211addscl(scl_t sc) |
298{ | 212{ |
213 |
|
299 if (sc == INLINE) { 300 if (dcs->d_inline) 301 /* duplicate '%s' */ 302 warning(10, "inline"); 303 dcs->d_inline = 1; 304 return; 305 } 306 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC || --- 18 unchanged lines hidden (view full) --- 325 * deftyp() to build the type used for all declarators in this 326 * declaration. 327 * 328 * Is tp->t_typedef 1, the type comes from a previously defined typename. 329 * Otherwise it comes from a type specifier (int, long, ...) or a 330 * struct/union/enum tag. 331 */ 332void | 214 if (sc == INLINE) { 215 if (dcs->d_inline) 216 /* duplicate '%s' */ 217 warning(10, "inline"); 218 dcs->d_inline = 1; 219 return; 220 } 221 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC || --- 18 unchanged lines hidden (view full) --- 240 * deftyp() to build the type used for all declarators in this 241 * declaration. 242 * 243 * Is tp->t_typedef 1, the type comes from a previously defined typename. 244 * Otherwise it comes from a type specifier (int, long, ...) or a 245 * struct/union/enum tag. 246 */ 247void |
333addtype(tp) 334 type_t *tp; | 248addtype(type_t *tp) |
335{ 336 tspec_t t; 337 338 if (tp->t_typedef) { 339 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC || 340 dcs->d_lmod != NOTSPEC || dcs->d_smod != NOTSPEC) { 341 /* 342 * something like "typedef int a; int a b;" --- 49 unchanged lines hidden (view full) --- 392 return; 393 } 394 395 /* now it can be only a combination of arithmetic types and void */ 396 if (t == SIGNED || t == UNSIGN) { 397 /* remeber specifiers "signed" and "unsigned" in dcs->d_smod */ 398 if (dcs->d_smod != NOTSPEC) 399 /* | 249{ 250 tspec_t t; 251 252 if (tp->t_typedef) { 253 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC || 254 dcs->d_lmod != NOTSPEC || dcs->d_smod != NOTSPEC) { 255 /* 256 * something like "typedef int a; int a b;" --- 49 unchanged lines hidden (view full) --- 306 return; 307 } 308 309 /* now it can be only a combination of arithmetic types and void */ 310 if (t == SIGNED || t == UNSIGN) { 311 /* remeber specifiers "signed" and "unsigned" in dcs->d_smod */ 312 if (dcs->d_smod != NOTSPEC) 313 /* |
400 * more then one "signed" and/or "unsigned"; print | 314 * more than one "signed" and/or "unsigned"; print |
401 * an error in deftyp() 402 */ 403 dcs->d_terr = 1; 404 dcs->d_smod = t; 405 } else if (t == SHORT || t == LONG || t == QUAD) { 406 /* 407 * remember specifiers "short", "long" and "long long" in 408 * dcs->d_lmod 409 */ 410 if (dcs->d_lmod != NOTSPEC) 411 /* more than one, print error in deftyp() */ 412 dcs->d_terr = 1; 413 dcs->d_lmod = t; 414 } else { 415 /* 416 * remember specifiers "void", "char", "int", "float" or | 315 * an error in deftyp() 316 */ 317 dcs->d_terr = 1; 318 dcs->d_smod = t; 319 } else if (t == SHORT || t == LONG || t == QUAD) { 320 /* 321 * remember specifiers "short", "long" and "long long" in 322 * dcs->d_lmod 323 */ 324 if (dcs->d_lmod != NOTSPEC) 325 /* more than one, print error in deftyp() */ 326 dcs->d_terr = 1; 327 dcs->d_lmod = t; 328 } else { 329 /* 330 * remember specifiers "void", "char", "int", "float" or |
417 * "double" int dcs->d_atyp | 331 * "double" int dcs->d_atyp |
418 */ 419 if (dcs->d_atyp != NOTSPEC) 420 /* more than one, print error in deftyp() */ 421 dcs->d_terr = 1; 422 dcs->d_atyp = t; 423 } 424} 425 426/* 427 * called if a list of declaration specifiers contains a typedef name 428 * and other specifiers (except struct, union, enum, typedef name) 429 */ 430static type_t * | 332 */ 333 if (dcs->d_atyp != NOTSPEC) 334 /* more than one, print error in deftyp() */ 335 dcs->d_terr = 1; 336 dcs->d_atyp = t; 337 } 338} 339 340/* 341 * called if a list of declaration specifiers contains a typedef name 342 * and other specifiers (except struct, union, enum, typedef name) 343 */ 344static type_t * |
431tdeferr(td, t) 432 type_t *td; 433 tspec_t t; | 345tdeferr(type_t *td, tspec_t t) |
434{ 435 tspec_t t2; 436 437 t2 = td->t_tspec; 438 439 switch (t) { 440 case SIGNED: 441 case UNSIGN: --- 35 unchanged lines hidden (view full) --- 477 td = gettyp(LDOUBLE); 478 } 479 td = duptyp(td); 480 td->t_typedef = 1; 481 return (td); 482 } 483 break; 484 /* LINTED (enumeration values not handled in switch) */ | 346{ 347 tspec_t t2; 348 349 t2 = td->t_tspec; 350 351 switch (t) { 352 case SIGNED: 353 case UNSIGN: --- 35 unchanged lines hidden (view full) --- 389 td = gettyp(LDOUBLE); 390 } 391 td = duptyp(td); 392 td->t_typedef = 1; 393 return (td); 394 } 395 break; 396 /* LINTED (enumeration values not handled in switch) */ |
485 default: | 397 case NOTSPEC: 398 case USHORT: 399 case UCHAR: 400 case SCHAR: 401 case CHAR: 402 case FUNC: 403 case ARRAY: 404 case PTR: 405 case ENUM: 406 case UNION: 407 case STRUCT: 408 case VOID: 409 case LDOUBLE: 410 case DOUBLE: 411 case FLOAT: 412 case UQUAD: 413 case QUAD: 414 case ULONG: 415 case UINT: 416 case INT: 417 break; 418 419 case NTSPEC: /* this value unused */ 420 break; |
486 } 487 488 /* Anything other is not accepted. */ 489 490 dcs->d_terr = 1; 491 return (td); 492} 493 494/* 495 * Remember the symbol of a typedef name (2nd arg) in a struct, union 496 * or enum tag if the typedef name is the first defined for this tag. 497 * 498 * If the tag is unnamed, the typdef name is used for identification | 421 } 422 423 /* Anything other is not accepted. */ 424 425 dcs->d_terr = 1; 426 return (td); 427} 428 429/* 430 * Remember the symbol of a typedef name (2nd arg) in a struct, union 431 * or enum tag if the typedef name is the first defined for this tag. 432 * 433 * If the tag is unnamed, the typdef name is used for identification |
499 * of this tag in lint2. Although its possible that more then one typedef | 434 * of this tag in lint2. Although its possible that more than one typedef |
500 * name is defined for one tag, the first name defined should be unique 501 * if the tag is unnamed. 502 */ 503static void | 435 * name is defined for one tag, the first name defined should be unique 436 * if the tag is unnamed. 437 */ 438static void |
504settdsym(tp, sym) 505 type_t *tp; 506 sym_t *sym; | 439settdsym(type_t *tp, sym_t *sym) |
507{ 508 tspec_t t; 509 510 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 511 if (tp->t_str->stdef == NULL) 512 tp->t_str->stdef = sym; 513 } else if (t == ENUM) { 514 if (tp->t_enum->etdef == NULL) 515 tp->t_enum->etdef = sym; 516 } 517} 518 519/* 520 * Remember a qualifier which is part of the declaration specifiers 521 * (and not the declarator) in the top element of the declaration stack. 522 * Also detect multiple qualifiers of the same kind. 523 | 440{ 441 tspec_t t; 442 443 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 444 if (tp->t_str->stdef == NULL) 445 tp->t_str->stdef = sym; 446 } else if (t == ENUM) { 447 if (tp->t_enum->etdef == NULL) 448 tp->t_enum->etdef = sym; 449 } 450} 451 452/* 453 * Remember a qualifier which is part of the declaration specifiers 454 * (and not the declarator) in the top element of the declaration stack. 455 * Also detect multiple qualifiers of the same kind. 456 |
524 * The rememberd qualifier is used by deftyp() to construct the type | 457 * The remembered qualifier is used by deftyp() to construct the type |
525 * for all declarators. 526 */ 527void | 458 * for all declarators. 459 */ 460void |
528addqual(q) 529 tqual_t q; | 461addqual(tqual_t q) |
530{ | 462{ |
463 |
|
531 if (q == CONST) { 532 if (dcs->d_const) { 533 /* duplicate "%s" */ 534 warning(10, "const"); 535 } 536 dcs->d_const = 1; 537 } else { 538 if (q != VOLATILE) --- 6 unchanged lines hidden (view full) --- 545 } 546} 547 548/* 549 * Go to the next declaration level (structs, nested structs, blocks, 550 * argument declaration lists ...) 551 */ 552void | 464 if (q == CONST) { 465 if (dcs->d_const) { 466 /* duplicate "%s" */ 467 warning(10, "const"); 468 } 469 dcs->d_const = 1; 470 } else { 471 if (q != VOLATILE) --- 6 unchanged lines hidden (view full) --- 478 } 479} 480 481/* 482 * Go to the next declaration level (structs, nested structs, blocks, 483 * argument declaration lists ...) 484 */ 485void |
553pushdecl(sc) 554 scl_t sc; | 486pushdecl(scl_t sc) |
555{ 556 dinfo_t *di; 557 558 if (dflag) 559 (void)printf("pushdecl(%d)\n", (int)sc); 560 561 /* put a new element on the declaration stack */ 562 if ((di = calloc(1, sizeof (dinfo_t))) == NULL) 563 nomem(); 564 di->d_nxt = dcs; 565 dcs = di; 566 di->d_ctx = sc; 567 di->d_ldlsym = &di->d_dlsyms; 568} 569 570/* 571 * Go back to previous declaration level 572 */ 573void | 487{ 488 dinfo_t *di; 489 490 if (dflag) 491 (void)printf("pushdecl(%d)\n", (int)sc); 492 493 /* put a new element on the declaration stack */ 494 if ((di = calloc(1, sizeof (dinfo_t))) == NULL) 495 nomem(); 496 di->d_nxt = dcs; 497 dcs = di; 498 di->d_ctx = sc; 499 di->d_ldlsym = &di->d_dlsyms; 500} 501 502/* 503 * Go back to previous declaration level 504 */ 505void |
574popdecl() | 506popdecl(void) |
575{ 576 dinfo_t *di; 577 578 if (dflag) 579 (void)printf("popdecl(%d)\n", (int)dcs->d_ctx); 580 581 if (dcs->d_nxt == NULL) 582 lerror("popdecl() 1"); --- 68 unchanged lines hidden (view full) --- 651 * because these structs are freed at the end of the compound statement. 652 * But it must be cleard in the outermost dinfo struct, which has 653 * context EXTERN. This could be done in clrtyp() and would work for 654 * C, but not for C++ (due to mixed statements and declarations). Thus 655 * we clear it in glclup(), which is used to do some cleanup after 656 * global declarations/definitions. 657 */ 658void | 507{ 508 dinfo_t *di; 509 510 if (dflag) 511 (void)printf("popdecl(%d)\n", (int)dcs->d_ctx); 512 513 if (dcs->d_nxt == NULL) 514 lerror("popdecl() 1"); --- 68 unchanged lines hidden (view full) --- 583 * because these structs are freed at the end of the compound statement. 584 * But it must be cleard in the outermost dinfo struct, which has 585 * context EXTERN. This could be done in clrtyp() and would work for 586 * C, but not for C++ (due to mixed statements and declarations). Thus 587 * we clear it in glclup(), which is used to do some cleanup after 588 * global declarations/definitions. 589 */ 590void |
659setasm() | 591setasm(void) |
660{ 661 dinfo_t *di; 662 663 for (di = dcs; di != NULL; di = di->d_nxt) 664 di->d_asm = 1; 665} 666 667/* 668 * Clean all elements of the top element of declaration stack which 669 * will be used by the next declaration 670 */ 671void | 592{ 593 dinfo_t *di; 594 595 for (di = dcs; di != NULL; di = di->d_nxt) 596 di->d_asm = 1; 597} 598 599/* 600 * Clean all elements of the top element of declaration stack which 601 * will be used by the next declaration 602 */ 603void |
672clrtyp() | 604clrtyp(void) |
673{ | 605{ |
606 |
|
674 dcs->d_atyp = dcs->d_smod = dcs->d_lmod = NOTSPEC; 675 dcs->d_scl = NOSCL; 676 dcs->d_type = NULL; 677 dcs->d_const = dcs->d_volatile = 0; 678 dcs->d_inline = 0; 679 dcs->d_mscl = dcs->d_terr = 0; 680 dcs->d_nedecl = 0; 681 dcs->d_notyp = 0; 682} 683 684/* 685 * Create a type structure from the informations gathered in 686 * the declaration stack. 687 * Complain about storage classes which are not possible in current 688 * context. 689 */ 690void | 607 dcs->d_atyp = dcs->d_smod = dcs->d_lmod = NOTSPEC; 608 dcs->d_scl = NOSCL; 609 dcs->d_type = NULL; 610 dcs->d_const = dcs->d_volatile = 0; 611 dcs->d_inline = 0; 612 dcs->d_mscl = dcs->d_terr = 0; 613 dcs->d_nedecl = 0; 614 dcs->d_notyp = 0; 615} 616 617/* 618 * Create a type structure from the informations gathered in 619 * the declaration stack. 620 * Complain about storage classes which are not possible in current 621 * context. 622 */ 623void |
691deftyp() | 624deftyp(void) |
692{ 693 tspec_t t, s, l; 694 type_t *tp; 695 scl_t scl; 696 697 t = dcs->d_atyp; /* CHAR, INT, FLOAT, DOUBLE, VOID */ 698 s = dcs->d_smod; /* SIGNED, UNSIGNED */ 699 l = dcs->d_lmod; /* SHORT, LONG, QUAD */ --- 99 unchanged lines hidden (view full) --- 799 dcs->d_type->t_volatile |= dcs->d_volatile; 800 } 801} 802 803/* 804 * Merge type specifiers (char, ..., long long, signed, unsigned). 805 */ 806static tspec_t | 625{ 626 tspec_t t, s, l; 627 type_t *tp; 628 scl_t scl; 629 630 t = dcs->d_atyp; /* CHAR, INT, FLOAT, DOUBLE, VOID */ 631 s = dcs->d_smod; /* SIGNED, UNSIGNED */ 632 l = dcs->d_lmod; /* SHORT, LONG, QUAD */ --- 99 unchanged lines hidden (view full) --- 732 dcs->d_type->t_volatile |= dcs->d_volatile; 733 } 734} 735 736/* 737 * Merge type specifiers (char, ..., long long, signed, unsigned). 738 */ 739static tspec_t |
807mrgtspec(t, s) 808 tspec_t t, s; | 740mrgtspec(tspec_t t, tspec_t s) |
809{ | 741{ |
742 |
|
810 if (s == SIGNED || s == UNSIGN) { 811 if (t == CHAR) { 812 t = s == SIGNED ? SCHAR : UCHAR; 813 } else if (t == SHORT) { 814 t = s == SIGNED ? SHORT : USHORT; 815 } else if (t == INT) { 816 t = s == SIGNED ? INT : UINT; 817 } else if (t == LONG) { --- 9 unchanged lines hidden (view full) --- 827/* 828 * Return the length of a type in bit. 829 * 830 * Printing a message if the outhermost dimension of an array is 0 must 831 * be done by the caller. All other problems are reported by length() 832 * if name is not NULL. 833 */ 834int | 743 if (s == SIGNED || s == UNSIGN) { 744 if (t == CHAR) { 745 t = s == SIGNED ? SCHAR : UCHAR; 746 } else if (t == SHORT) { 747 t = s == SIGNED ? SHORT : USHORT; 748 } else if (t == INT) { 749 t = s == SIGNED ? INT : UINT; 750 } else if (t == LONG) { --- 9 unchanged lines hidden (view full) --- 760/* 761 * Return the length of a type in bit. 762 * 763 * Printing a message if the outhermost dimension of an array is 0 must 764 * be done by the caller. All other problems are reported by length() 765 * if name is not NULL. 766 */ 767int |
835length(tp, name) 836 type_t *tp; 837 const char *name; | 768length(type_t *tp, const char *name) |
838{ 839 int elem, elsz; 840 841 elem = 1; | 769{ 770 int elem, elsz; 771 772 elem = 1; |
842 while (tp->t_tspec == ARRAY) { | 773 while (tp && tp->t_tspec == ARRAY) { |
843 elem *= tp->t_dim; 844 tp = tp->t_subt; 845 } | 774 elem *= tp->t_dim; 775 tp = tp->t_subt; 776 } |
777 if (tp == NULL) 778 return -1; 779 |
|
846 switch (tp->t_tspec) { 847 case FUNC: 848 /* compiler takes size of function */ 849 lerror("%s", msgs[12]); 850 /* NOTREACHED */ 851 case STRUCT: 852 case UNION: 853 if (incompl(tp) && name != NULL) { --- 16 unchanged lines hidden (view full) --- 870 } 871 return (elem * elsz); 872} 873 874/* 875 * Get the alignment of the given Type in bits. 876 */ 877int | 780 switch (tp->t_tspec) { 781 case FUNC: 782 /* compiler takes size of function */ 783 lerror("%s", msgs[12]); 784 /* NOTREACHED */ 785 case STRUCT: 786 case UNION: 787 if (incompl(tp) && name != NULL) { --- 16 unchanged lines hidden (view full) --- 804 } 805 return (elem * elsz); 806} 807 808/* 809 * Get the alignment of the given Type in bits. 810 */ 811int |
878getbound(tp) 879 type_t *tp; | 812getbound(type_t *tp) |
880{ 881 int a; 882 tspec_t t; 883 | 813{ 814 int a; 815 tspec_t t; 816 |
884 while (tp->t_tspec == ARRAY) | 817 while (tp && tp->t_tspec == ARRAY) |
885 tp = tp->t_subt; 886 | 818 tp = tp->t_subt; 819 |
820 if (tp == NULL) 821 return -1; 822 |
|
887 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 888 a = tp->t_str->align; 889 } else if (t == FUNC) { 890 /* compiler takes alignment of function */ 891 error(14); 892 a = ALIGN(1) * CHAR_BIT; 893 } else { 894 if ((a = size(t)) == 0) { --- 7 unchanged lines hidden (view full) --- 902 return (a); 903} 904 905/* 906 * Concatenate two lists of symbols by s_nxt. Used by declarations of 907 * struct/union/enum elements and parameters. 908 */ 909sym_t * | 823 if ((t = tp->t_tspec) == STRUCT || t == UNION) { 824 a = tp->t_str->align; 825 } else if (t == FUNC) { 826 /* compiler takes alignment of function */ 827 error(14); 828 a = ALIGN(1) * CHAR_BIT; 829 } else { 830 if ((a = size(t)) == 0) { --- 7 unchanged lines hidden (view full) --- 838 return (a); 839} 840 841/* 842 * Concatenate two lists of symbols by s_nxt. Used by declarations of 843 * struct/union/enum elements and parameters. 844 */ 845sym_t * |
910lnklst(l1, l2) 911 sym_t *l1, *l2; | 846lnklst(sym_t *l1, sym_t *l2) |
912{ 913 sym_t *l; 914 915 if ((l = l1) == NULL) 916 return (l2); 917 while (l1->s_nxt != NULL) 918 l1 = l1->s_nxt; 919 l1->s_nxt = l2; --- 5 unchanged lines hidden (view full) --- 925 * message if it is not. 926 * 927 * Invalid types are: 928 * - arrays of incomlete types or functions 929 * - functions returning arrays or functions 930 * - void types other than type of function or pointer 931 */ 932void | 847{ 848 sym_t *l; 849 850 if ((l = l1) == NULL) 851 return (l2); 852 while (l1->s_nxt != NULL) 853 l1 = l1->s_nxt; 854 l1->s_nxt = l2; --- 5 unchanged lines hidden (view full) --- 860 * message if it is not. 861 * 862 * Invalid types are: 863 * - arrays of incomlete types or functions 864 * - functions returning arrays or functions 865 * - void types other than type of function or pointer 866 */ 867void |
933chktyp(sym) 934 sym_t *sym; | 868chktyp(sym_t *sym) |
935{ 936 tspec_t to, t; 937 type_t **tpp, *tp; 938 939 tpp = &sym->s_type; 940 to = NOTSPEC; 941 while ((tp = *tpp) != NULL) { 942 t = tp->t_tspec; --- 75 unchanged lines hidden (view full) --- 1018 to = t; 1019 } 1020} 1021 1022/* 1023 * Process the declarator of a struct/union element. 1024 */ 1025sym_t * | 869{ 870 tspec_t to, t; 871 type_t **tpp, *tp; 872 873 tpp = &sym->s_type; 874 to = NOTSPEC; 875 while ((tp = *tpp) != NULL) { 876 t = tp->t_tspec; --- 75 unchanged lines hidden (view full) --- 952 to = t; 953 } 954} 955 956/* 957 * Process the declarator of a struct/union element. 958 */ 959sym_t * |
1026decl1str(dsym) 1027 sym_t *dsym; | 960decl1str(sym_t *dsym) |
1028{ 1029 type_t *tp; 1030 tspec_t t; | 961{ 962 type_t *tp; 963 tspec_t t; |
1031 int sz, o, len; | 964 int sz, len; 965 int o = 0; /* Appease gcc */ |
1032 scl_t sc; 1033 1034 if ((sc = dsym->s_scl) != MOS && sc != MOU) 1035 lerror("decl1str() 1"); 1036 1037 if (dcs->d_rdcsym != NULL) { 1038 if ((sc = dcs->d_rdcsym->s_scl) != MOS && sc != MOU) 1039 /* should be ensured by storesym() */ --- 13 unchanged lines hidden (view full) --- 1053 /* 1054 * bit field 1055 * 1056 * only unsigned und signed int are protable bit-field types 1057 *(at least in ANSI C, in traditional C only unsigned int) 1058 */ 1059 if (t == CHAR || t == UCHAR || t == SCHAR || 1060 t == SHORT || t == USHORT || t == ENUM) { | 966 scl_t sc; 967 968 if ((sc = dsym->s_scl) != MOS && sc != MOU) 969 lerror("decl1str() 1"); 970 971 if (dcs->d_rdcsym != NULL) { 972 if ((sc = dcs->d_rdcsym->s_scl) != MOS && sc != MOU) 973 /* should be ensured by storesym() */ --- 13 unchanged lines hidden (view full) --- 987 /* 988 * bit field 989 * 990 * only unsigned und signed int are protable bit-field types 991 *(at least in ANSI C, in traditional C only unsigned int) 992 */ 993 if (t == CHAR || t == UCHAR || t == SCHAR || 994 t == SHORT || t == USHORT || t == ENUM) { |
1061 if (sflag) { 1062 /* bit-field type '%s' invalid in ANSI C */ 1063 warning(273, tyname(tp)); 1064 } else if (pflag) { 1065 /* nonportable bit-field type */ 1066 warning(34); | 995 if (bitfieldtype_ok == 0) { 996 if (sflag) { 997 /* 998 * bit-field type '%s' invalid in 999 * ANSI C 1000 */ 1001 warning(273, tyname(tp)); 1002 } else if (pflag) { 1003 /* nonportable bit-field type */ 1004 warning(34); 1005 } |
1067 } 1068 } else if (t == INT && dcs->d_smod == NOTSPEC) { | 1006 } 1007 } else if (t == INT && dcs->d_smod == NOTSPEC) { |
1069 if (pflag) { | 1008 if (pflag && bitfieldtype_ok == 0) { |
1070 /* nonportable bit-field type */ 1071 warning(34); 1072 } 1073 } else if (t != INT && t != UINT) { | 1009 /* nonportable bit-field type */ 1010 warning(34); 1011 } 1012 } else if (t != INT && t != UINT) { |
1074 /* illegal bit-field type */ 1075 error(35); 1076 sz = tp->t_flen; 1077 dsym->s_type = tp = duptyp(gettyp(t = INT)); 1078 if ((tp->t_flen = sz) > size(t)) 1079 tp->t_flen = size(t); | 1013 /* 1014 * Non-integer types are always illegal for 1015 * bitfields, regardless of BITFIELDTYPE. 1016 * Integer types not dealt with above are 1017 * okay only if BITFIELDTYPE is in effect. 1018 */ 1019 if (bitfieldtype_ok == 0 || isityp(t) == 0) { 1020 /* illegal bit-field type */ 1021 error(35); 1022 sz = tp->t_flen; 1023 dsym->s_type = tp = duptyp(gettyp(t = INT)); 1024 if ((tp->t_flen = sz) > size(t)) 1025 tp->t_flen = size(t); 1026 } |
1080 } 1081 if ((len = tp->t_flen) < 0 || len > size(t)) { 1082 /* illegal bit-field size */ 1083 error(36); 1084 tp->t_flen = size(t); 1085 } else if (len == 0 && dsym->s_name != unnamed) { 1086 /* zero size bit-field */ 1087 error(37); --- 39 unchanged lines hidden (view full) --- 1127 } 1128 if (dcs->d_ctx == MOU) { 1129 if (o > dcs->d_offset) 1130 dcs->d_offset = o; 1131 } 1132 1133 chkfdef(dsym, 0); 1134 | 1027 } 1028 if ((len = tp->t_flen) < 0 || len > size(t)) { 1029 /* illegal bit-field size */ 1030 error(36); 1031 tp->t_flen = size(t); 1032 } else if (len == 0 && dsym->s_name != unnamed) { 1033 /* zero size bit-field */ 1034 error(37); --- 39 unchanged lines hidden (view full) --- 1074 } 1075 if (dcs->d_ctx == MOU) { 1076 if (o > dcs->d_offset) 1077 dcs->d_offset = o; 1078 } 1079 1080 chkfdef(dsym, 0); 1081 |
1082 /* 1083 * Clear the BITFIELDTYPE indicator after processing each 1084 * structure element. 1085 */ 1086 bitfieldtype_ok = 0; 1087 |
|
1135 return (dsym); 1136} 1137 1138/* 1139 * Aligns next structure element as required. 1140 * 1141 * al contains the required alignment, len the length of a bit-field. 1142 */ 1143static void | 1088 return (dsym); 1089} 1090 1091/* 1092 * Aligns next structure element as required. 1093 * 1094 * al contains the required alignment, len the length of a bit-field. 1095 */ 1096static void |
1144align(al, len) 1145 int al, len; | 1097align(int al, int len) |
1146{ 1147 int no; 1148 1149 /* 1150 * The alignment of the current element becomes the alignment of 1151 * the struct/union if it is larger than the current alignment 1152 * of the struct/union. 1153 */ 1154 if (al > dcs->d_stralign) 1155 dcs->d_stralign = al; | 1098{ 1099 int no; 1100 1101 /* 1102 * The alignment of the current element becomes the alignment of 1103 * the struct/union if it is larger than the current alignment 1104 * of the struct/union. 1105 */ 1106 if (al > dcs->d_stralign) 1107 dcs->d_stralign = al; |
1156 | 1108 |
1157 no = (dcs->d_offset + (al - 1)) & ~(al - 1); 1158 if (len == 0 || dcs->d_offset + len > no) 1159 dcs->d_offset = no; 1160} 1161 1162/* 1163 * Remember the width of the field in its type structure. 1164 */ 1165sym_t * | 1109 no = (dcs->d_offset + (al - 1)) & ~(al - 1); 1110 if (len == 0 || dcs->d_offset + len > no) 1111 dcs->d_offset = no; 1112} 1113 1114/* 1115 * Remember the width of the field in its type structure. 1116 */ 1117sym_t * |
1166bitfield(dsym, len) 1167 sym_t *dsym; 1168 int len; | 1118bitfield(sym_t *dsym, int len) |
1169{ | 1119{ |
1120 |
|
1170 if (dsym == NULL) { 1171 dsym = getblk(sizeof (sym_t)); 1172 dsym->s_name = unnamed; 1173 dsym->s_kind = FMOS; 1174 dsym->s_scl = MOS; | 1121 if (dsym == NULL) { 1122 dsym = getblk(sizeof (sym_t)); 1123 dsym->s_name = unnamed; 1124 dsym->s_kind = FMOS; 1125 dsym->s_scl = MOS; |
1175 dsym->s_type = gettyp(INT); | 1126 dsym->s_type = gettyp(UINT); |
1176 dsym->s_blklev = -1; 1177 } 1178 dsym->s_type = duptyp(dsym->s_type); 1179 dsym->s_type->t_isfield = 1; 1180 dsym->s_type->t_flen = len; 1181 dsym->s_field = 1; 1182 return (dsym); 1183} 1184 1185/* 1186 * Collect informations about a sequence of asterisks and qualifiers 1187 * in a list of type pqinf_t. 1188 * Qualifiers refer always to the left asterisk. The rightmost asterisk 1189 * will be at the top of the list. 1190 */ 1191pqinf_t * | 1127 dsym->s_blklev = -1; 1128 } 1129 dsym->s_type = duptyp(dsym->s_type); 1130 dsym->s_type->t_isfield = 1; 1131 dsym->s_type->t_flen = len; 1132 dsym->s_field = 1; 1133 return (dsym); 1134} 1135 1136/* 1137 * Collect informations about a sequence of asterisks and qualifiers 1138 * in a list of type pqinf_t. 1139 * Qualifiers refer always to the left asterisk. The rightmost asterisk 1140 * will be at the top of the list. 1141 */ 1142pqinf_t * |
1192mergepq(p1, p2) 1193 pqinf_t *p1, *p2; | 1143mergepq(pqinf_t *p1, pqinf_t *p2) |
1194{ 1195 pqinf_t *p; 1196 1197 if (p2->p_pcnt != 0) { 1198 /* left '*' at the end of the list */ | 1144{ 1145 pqinf_t *p; 1146 1147 if (p2->p_pcnt != 0) { 1148 /* left '*' at the end of the list */ |
1199 for (p = p2; p->p_nxt != NULL; p = p->p_nxt) ; | 1149 for (p = p2; p->p_nxt != NULL; p = p->p_nxt) 1150 continue; |
1200 p->p_nxt = p1; 1201 return (p2); 1202 } else { 1203 if (p2->p_const) { 1204 if (p1->p_const) { 1205 /* duplicate %s */ 1206 warning(10, "const"); 1207 } --- 15 unchanged lines hidden (view full) --- 1223 * Followint 3 functions extend the type of a declarator with 1224 * pointer, function and array types. 1225 * 1226 * The current type is the Type built by deftyp() (dcs->d_type) and 1227 * pointer, function and array types already added for this 1228 * declarator. The new type extension is inserted between both. 1229 */ 1230sym_t * | 1151 p->p_nxt = p1; 1152 return (p2); 1153 } else { 1154 if (p2->p_const) { 1155 if (p1->p_const) { 1156 /* duplicate %s */ 1157 warning(10, "const"); 1158 } --- 15 unchanged lines hidden (view full) --- 1174 * Followint 3 functions extend the type of a declarator with 1175 * pointer, function and array types. 1176 * 1177 * The current type is the Type built by deftyp() (dcs->d_type) and 1178 * pointer, function and array types already added for this 1179 * declarator. The new type extension is inserted between both. 1180 */ 1181sym_t * |
1231addptr(decl, pi) 1232 sym_t *decl; 1233 pqinf_t *pi; | 1182addptr(sym_t *decl, pqinf_t *pi) |
1234{ 1235 type_t **tpp, *tp; 1236 pqinf_t *npi; 1237 1238 tpp = &decl->s_type; | 1183{ 1184 type_t **tpp, *tp; 1185 pqinf_t *npi; 1186 1187 tpp = &decl->s_type; |
1239 while (*tpp != dcs->d_type) | 1188 while (*tpp && *tpp != dcs->d_type) |
1240 tpp = &(*tpp)->t_subt; | 1189 tpp = &(*tpp)->t_subt; |
1190 if (*tpp == NULL) 1191 return decl; |
|
1241 1242 while (pi != NULL) { 1243 *tpp = tp = getblk(sizeof (type_t)); 1244 tp->t_tspec = PTR; 1245 tp->t_const = pi->p_const; 1246 tp->t_volatile = pi->p_volatile; 1247 *(tpp = &tp->t_subt) = dcs->d_type; 1248 npi = pi->p_nxt; 1249 free(pi); 1250 pi = npi; 1251 } 1252 return (decl); 1253} 1254 1255/* 1256 * If a dimension was specified, dim is 1, otherwise 0 1257 * n is the specified dimension 1258 */ 1259sym_t * | 1192 1193 while (pi != NULL) { 1194 *tpp = tp = getblk(sizeof (type_t)); 1195 tp->t_tspec = PTR; 1196 tp->t_const = pi->p_const; 1197 tp->t_volatile = pi->p_volatile; 1198 *(tpp = &tp->t_subt) = dcs->d_type; 1199 npi = pi->p_nxt; 1200 free(pi); 1201 pi = npi; 1202 } 1203 return (decl); 1204} 1205 1206/* 1207 * If a dimension was specified, dim is 1, otherwise 0 1208 * n is the specified dimension 1209 */ 1210sym_t * |
1260addarray(decl, dim, n) 1261 sym_t *decl; 1262 int dim, n; | 1211addarray(sym_t *decl, int dim, int n) |
1263{ 1264 type_t **tpp, *tp; 1265 1266 tpp = &decl->s_type; | 1212{ 1213 type_t **tpp, *tp; 1214 1215 tpp = &decl->s_type; |
1267 while (*tpp != dcs->d_type) | 1216 while (*tpp && *tpp != dcs->d_type) |
1268 tpp = &(*tpp)->t_subt; | 1217 tpp = &(*tpp)->t_subt; |
1218 if (*tpp == NULL) 1219 return decl; |
|
1269 1270 *tpp = tp = getblk(sizeof (type_t)); 1271 tp->t_tspec = ARRAY; 1272 tp->t_subt = dcs->d_type; 1273 tp->t_dim = n; 1274 1275 if (n < 0) { 1276 /* zero or negative array dimension */ --- 6 unchanged lines hidden (view full) --- 1283 /* is incomplete type */ 1284 setcompl(tp, 1); 1285 } 1286 1287 return (decl); 1288} 1289 1290sym_t * | 1220 1221 *tpp = tp = getblk(sizeof (type_t)); 1222 tp->t_tspec = ARRAY; 1223 tp->t_subt = dcs->d_type; 1224 tp->t_dim = n; 1225 1226 if (n < 0) { 1227 /* zero or negative array dimension */ --- 6 unchanged lines hidden (view full) --- 1234 /* is incomplete type */ 1235 setcompl(tp, 1); 1236 } 1237 1238 return (decl); 1239} 1240 1241sym_t * |
1291addfunc(decl, args) 1292 sym_t *decl, *args; | 1242addfunc(sym_t *decl, sym_t *args) |
1293{ 1294 type_t **tpp, *tp; 1295 1296 if (dcs->d_proto) { 1297 if (tflag) 1298 /* function prototypes are illegal in traditional C */ 1299 warning(270); 1300 args = nsfunc(decl, args); --- 13 unchanged lines hidden (view full) --- 1314 */ 1315 if (dcs->d_nxt->d_ctx == EXTERN && 1316 decl->s_type == dcs->d_nxt->d_type) { 1317 dcs->d_nxt->d_fpsyms = dcs->d_dlsyms; 1318 dcs->d_nxt->d_fargs = args; 1319 } 1320 1321 tpp = &decl->s_type; | 1243{ 1244 type_t **tpp, *tp; 1245 1246 if (dcs->d_proto) { 1247 if (tflag) 1248 /* function prototypes are illegal in traditional C */ 1249 warning(270); 1250 args = nsfunc(decl, args); --- 13 unchanged lines hidden (view full) --- 1264 */ 1265 if (dcs->d_nxt->d_ctx == EXTERN && 1266 decl->s_type == dcs->d_nxt->d_type) { 1267 dcs->d_nxt->d_fpsyms = dcs->d_dlsyms; 1268 dcs->d_nxt->d_fargs = args; 1269 } 1270 1271 tpp = &decl->s_type; |
1322 while (*tpp != dcs->d_nxt->d_type) | 1272 while (*tpp && *tpp != dcs->d_nxt->d_type) |
1323 tpp = &(*tpp)->t_subt; | 1273 tpp = &(*tpp)->t_subt; |
1274 if (*tpp == NULL) 1275 return decl; |
|
1324 1325 *tpp = tp = getblk(sizeof (type_t)); 1326 tp->t_tspec = FUNC; 1327 tp->t_subt = dcs->d_nxt->d_type; 1328 if ((tp->t_proto = dcs->d_proto) != 0) 1329 tp->t_args = args; 1330 tp->t_vararg = dcs->d_vararg; 1331 1332 return (decl); 1333} 1334 1335/* 1336 * Called for new style function declarations. 1337 */ 1338/* ARGSUSED */ 1339static sym_t * | 1276 1277 *tpp = tp = getblk(sizeof (type_t)); 1278 tp->t_tspec = FUNC; 1279 tp->t_subt = dcs->d_nxt->d_type; 1280 if ((tp->t_proto = dcs->d_proto) != 0) 1281 tp->t_args = args; 1282 tp->t_vararg = dcs->d_vararg; 1283 1284 return (decl); 1285} 1286 1287/* 1288 * Called for new style function declarations. 1289 */ 1290/* ARGSUSED */ 1291static sym_t * |
1340nsfunc(decl, args) 1341 sym_t *decl, *args; | 1292nsfunc(sym_t *decl, sym_t *args) |
1342{ 1343 sym_t *arg, *sym; 1344 scl_t sc; 1345 int n; 1346 1347 /* 1348 * Declarations of structs/unions/enums in param lists are legal, 1349 * but senseless. --- 21 unchanged lines hidden (view full) --- 1371 /* return NULL if first param is VOID */ 1372 return (args != NULL && args->s_type->t_tspec != VOID ? args : NULL); 1373} 1374 1375/* 1376 * Called for old style function declarations. 1377 */ 1378static void | 1293{ 1294 sym_t *arg, *sym; 1295 scl_t sc; 1296 int n; 1297 1298 /* 1299 * Declarations of structs/unions/enums in param lists are legal, 1300 * but senseless. --- 21 unchanged lines hidden (view full) --- 1322 /* return NULL if first param is VOID */ 1323 return (args != NULL && args->s_type->t_tspec != VOID ? args : NULL); 1324} 1325 1326/* 1327 * Called for old style function declarations. 1328 */ 1329static void |
1379osfunc(decl, args) 1380 sym_t *decl, *args; | 1330osfunc(sym_t *decl, sym_t *args) |
1381{ | 1331{ |
1332 |
|
1382 /* 1383 * Remember list of params only if this is really seams to be 1384 * a function definition. 1385 */ 1386 if (dcs->d_nxt->d_ctx == EXTERN && 1387 decl->s_type == dcs->d_nxt->d_type) { 1388 /* 1389 * We assume that this becomes a function definition. If | 1333 /* 1334 * Remember list of params only if this is really seams to be 1335 * a function definition. 1336 */ 1337 if (dcs->d_nxt->d_ctx == EXTERN && 1338 decl->s_type == dcs->d_nxt->d_type) { 1339 /* 1340 * We assume that this becomes a function definition. If |
1390 * we are wrong, its corrected in chkfdef(). | 1341 * we are wrong, its corrected in chkfdef(). |
1391 */ 1392 if (args != NULL) { 1393 decl->s_osdef = 1; 1394 decl->s_args = args; 1395 } 1396 } else { 1397 if (args != NULL) 1398 /* function prototype parameters must have types */ 1399 warning(62); 1400 } 1401} 1402 1403/* 1404 * Lists of Identifiers in functions declarations are allowed only if 1405 * its also a function definition. If this is not the case, print a 1406 * error message. 1407 */ 1408void | 1342 */ 1343 if (args != NULL) { 1344 decl->s_osdef = 1; 1345 decl->s_args = args; 1346 } 1347 } else { 1348 if (args != NULL) 1349 /* function prototype parameters must have types */ 1350 warning(62); 1351 } 1352} 1353 1354/* 1355 * Lists of Identifiers in functions declarations are allowed only if 1356 * its also a function definition. If this is not the case, print a 1357 * error message. 1358 */ 1359void |
1409chkfdef(sym, msg) 1410 sym_t *sym; 1411 int msg; | 1360chkfdef(sym_t *sym, int msg) |
1412{ | 1361{ |
1362 |
|
1413 if (sym->s_osdef) { 1414 if (msg) { 1415 /* incomplete or misplaced function definition */ 1416 error(22); 1417 } 1418 sym->s_osdef = 0; 1419 sym->s_args = NULL; 1420 } 1421} 1422 1423/* 1424 * Process the name in a declarator. 1425 * If the symbol does already exists, a new one is created. 1426 * The symbol becomes one of the storage classes EXTERN, STATIC, AUTO or 1427 * TYPEDEF. 1428 * s_def and s_reg are valid after dname(). 1429 */ 1430sym_t * | 1363 if (sym->s_osdef) { 1364 if (msg) { 1365 /* incomplete or misplaced function definition */ 1366 error(22); 1367 } 1368 sym->s_osdef = 0; 1369 sym->s_args = NULL; 1370 } 1371} 1372 1373/* 1374 * Process the name in a declarator. 1375 * If the symbol does already exists, a new one is created. 1376 * The symbol becomes one of the storage classes EXTERN, STATIC, AUTO or 1377 * TYPEDEF. 1378 * s_def and s_reg are valid after dname(). 1379 */ 1380sym_t * |
1431dname(sym) 1432 sym_t *sym; | 1381dname(sym_t *sym) |
1433{ | 1382{ |
1434 scl_t sc; | 1383 scl_t sc = NOSCL; |
1435 1436 if (sym->s_scl == NOSCL) { 1437 dcs->d_rdcsym = NULL; 1438 } else if (sym->s_defarg) { 1439 sym->s_defarg = 0; 1440 dcs->d_rdcsym = NULL; 1441 } else { 1442 dcs->d_rdcsym = sym; --- 46 unchanged lines hidden (view full) --- 1489 sym->s_def = DEF; 1490 break; 1491 case AUTO: 1492 if ((sc = dcs->d_scl) == NOSCL) { 1493 /* 1494 * XXX somewhat ugly because we dont know whether 1495 * this is AUTO or EXTERN (functions). If we are 1496 * wrong it must be corrected in decl1loc(), where | 1384 1385 if (sym->s_scl == NOSCL) { 1386 dcs->d_rdcsym = NULL; 1387 } else if (sym->s_defarg) { 1388 sym->s_defarg = 0; 1389 dcs->d_rdcsym = NULL; 1390 } else { 1391 dcs->d_rdcsym = sym; --- 46 unchanged lines hidden (view full) --- 1438 sym->s_def = DEF; 1439 break; 1440 case AUTO: 1441 if ((sc = dcs->d_scl) == NOSCL) { 1442 /* 1443 * XXX somewhat ugly because we dont know whether 1444 * this is AUTO or EXTERN (functions). If we are 1445 * wrong it must be corrected in decl1loc(), where |
1497 * we have the neccessary type information. | 1446 * we have the necessary type information. |
1498 */ 1499 sc = AUTO; 1500 sym->s_def = DEF; 1501 } else if (sc == AUTO || sc == STATIC || sc == TYPEDEF) { 1502 sym->s_def = DEF; 1503 } else if (sc == REG) { 1504 sym->s_reg = 1; 1505 sc = AUTO; --- 16 unchanged lines hidden (view full) --- 1522 return (sym); 1523} 1524 1525/* 1526 * Process a name in the list of formal params in an old style function 1527 * definition. 1528 */ 1529sym_t * | 1447 */ 1448 sc = AUTO; 1449 sym->s_def = DEF; 1450 } else if (sc == AUTO || sc == STATIC || sc == TYPEDEF) { 1451 sym->s_def = DEF; 1452 } else if (sc == REG) { 1453 sym->s_reg = 1; 1454 sc = AUTO; --- 16 unchanged lines hidden (view full) --- 1471 return (sym); 1472} 1473 1474/* 1475 * Process a name in the list of formal params in an old style function 1476 * definition. 1477 */ 1478sym_t * |
1530iname(sym) 1531 sym_t *sym; | 1479iname(sym_t *sym) |
1532{ | 1480{ |
1481 |
|
1533 if (sym->s_scl != NOSCL) { 1534 if (blklev == sym->s_blklev) { 1535 /* redeclaration of formal parameter %s */ 1536 error(21, sym->s_name); 1537 if (!sym->s_defarg) 1538 lerror("iname()"); 1539 } 1540 sym = pushdown(sym); --- 10 unchanged lines hidden (view full) --- 1551 * 1552 * tag points to the symbol table entry of the tag 1553 * kind is the kind of the tag (STRUCT/UNION/ENUM) 1554 * decl is 1 if the type of the tag will be completed in this declaration 1555 * (the following token is T_LBRACE) 1556 * semi is 1 if the following token is T_SEMI 1557 */ 1558type_t * | 1482 if (sym->s_scl != NOSCL) { 1483 if (blklev == sym->s_blklev) { 1484 /* redeclaration of formal parameter %s */ 1485 error(21, sym->s_name); 1486 if (!sym->s_defarg) 1487 lerror("iname()"); 1488 } 1489 sym = pushdown(sym); --- 10 unchanged lines hidden (view full) --- 1500 * 1501 * tag points to the symbol table entry of the tag 1502 * kind is the kind of the tag (STRUCT/UNION/ENUM) 1503 * decl is 1 if the type of the tag will be completed in this declaration 1504 * (the following token is T_LBRACE) 1505 * semi is 1 if the following token is T_SEMI 1506 */ 1507type_t * |
1559mktag(tag, kind, decl, semi) 1560 sym_t *tag; 1561 tspec_t kind; 1562 int decl, semi; | 1508mktag(sym_t *tag, tspec_t kind, int decl, int semi) |
1563{ | 1509{ |
1564 scl_t scl; | 1510 scl_t scl = NOSCL; |
1565 type_t *tp; 1566 1567 if (kind == STRUCT) { 1568 scl = STRTAG; 1569 } else if (kind == UNION) { 1570 scl = UNIONTAG; 1571 } else if (kind == ENUM) { 1572 scl = ENUMTAG; --- 17 unchanged lines hidden (view full) --- 1590 tag->s_scl = scl; 1591 tag->s_type = tp = getblk(sizeof (type_t)); 1592 } else { 1593 tp = tag->s_type; 1594 } 1595 } else { 1596 tag = getblk(sizeof (sym_t)); 1597 tag->s_name = unnamed; | 1511 type_t *tp; 1512 1513 if (kind == STRUCT) { 1514 scl = STRTAG; 1515 } else if (kind == UNION) { 1516 scl = UNIONTAG; 1517 } else if (kind == ENUM) { 1518 scl = ENUMTAG; --- 17 unchanged lines hidden (view full) --- 1536 tag->s_scl = scl; 1537 tag->s_type = tp = getblk(sizeof (type_t)); 1538 } else { 1539 tp = tag->s_type; 1540 } 1541 } else { 1542 tag = getblk(sizeof (sym_t)); 1543 tag->s_name = unnamed; |
1598 STRUCT_ASSIGN(tag->s_dpos, curr_pos); | 1544 UNIQUE_CURR_POS(tag->s_dpos); |
1599 tag->s_kind = FTAG; 1600 tag->s_scl = scl; 1601 tag->s_blklev = -1; 1602 tag->s_type = tp = getblk(sizeof (type_t)); 1603 dcs->d_nxt->d_nedecl = 1; 1604 } 1605 1606 if (tp->t_tspec == NOTSPEC) { --- 15 unchanged lines hidden (view full) --- 1622} 1623 1624/* 1625 * Checks all possible cases of tag redeclarations. 1626 * decl is 1 if T_LBRACE follows 1627 * semi is 1 if T_SEMI follows 1628 */ 1629static sym_t * | 1545 tag->s_kind = FTAG; 1546 tag->s_scl = scl; 1547 tag->s_blklev = -1; 1548 tag->s_type = tp = getblk(sizeof (type_t)); 1549 dcs->d_nxt->d_nedecl = 1; 1550 } 1551 1552 if (tp->t_tspec == NOTSPEC) { --- 15 unchanged lines hidden (view full) --- 1568} 1569 1570/* 1571 * Checks all possible cases of tag redeclarations. 1572 * decl is 1 if T_LBRACE follows 1573 * semi is 1 if T_SEMI follows 1574 */ 1575static sym_t * |
1630newtag(tag, scl, decl, semi) 1631 sym_t *tag; 1632 scl_t scl; 1633 int decl, semi; | 1576newtag(sym_t *tag, scl_t scl, int decl, int semi) |
1634{ | 1577{ |
1578 |
|
1635 if (tag->s_blklev < blklev) { 1636 if (semi) { 1637 /* "struct a;" */ 1638 if (!tflag) { 1639 if (!sflag) 1640 /* decl. introduces new type ... */ 1641 warning(44, scltoa(scl), tag->s_name); 1642 tag = pushdown(tag); 1643 } else if (tag->s_scl != scl) { 1644 /* base type is really "%s %s" */ 1645 warning(45, scltoa(tag->s_scl), tag->s_name); 1646 } 1647 dcs->d_nxt->d_nedecl = 1; 1648 } else if (decl) { | 1579 if (tag->s_blklev < blklev) { 1580 if (semi) { 1581 /* "struct a;" */ 1582 if (!tflag) { 1583 if (!sflag) 1584 /* decl. introduces new type ... */ 1585 warning(44, scltoa(scl), tag->s_name); 1586 tag = pushdown(tag); 1587 } else if (tag->s_scl != scl) { 1588 /* base type is really "%s %s" */ 1589 warning(45, scltoa(tag->s_scl), tag->s_name); 1590 } 1591 dcs->d_nxt->d_nedecl = 1; 1592 } else if (decl) { |
1649 /* "struct a { ..." */ | 1593 /* "struct a { ... } " */ |
1650 if (hflag) 1651 /* redefinition hides earlier one: %s */ 1652 warning(43, tag->s_name); 1653 tag = pushdown(tag); 1654 dcs->d_nxt->d_nedecl = 1; 1655 } else if (tag->s_scl != scl) { 1656 /* base type is really "%s %s" */ 1657 warning(45, scltoa(tag->s_scl), tag->s_name); --- 19 unchanged lines hidden (view full) --- 1677 } else if (semi || decl) { 1678 dcs->d_nxt->d_nedecl = 1; 1679 } 1680 } 1681 return (tag); 1682} 1683 1684const char * | 1594 if (hflag) 1595 /* redefinition hides earlier one: %s */ 1596 warning(43, tag->s_name); 1597 tag = pushdown(tag); 1598 dcs->d_nxt->d_nedecl = 1; 1599 } else if (tag->s_scl != scl) { 1600 /* base type is really "%s %s" */ 1601 warning(45, scltoa(tag->s_scl), tag->s_name); --- 19 unchanged lines hidden (view full) --- 1621 } else if (semi || decl) { 1622 dcs->d_nxt->d_nedecl = 1; 1623 } 1624 } 1625 return (tag); 1626} 1627 1628const char * |
1685scltoa(sc) 1686 scl_t sc; | 1629scltoa(scl_t sc) |
1687{ 1688 const char *s; 1689 1690 switch (sc) { 1691 case EXTERN: s = "extern"; break; 1692 case STATIC: s = "static"; break; 1693 case AUTO: s = "auto"; break; 1694 case REG: s = "register"; break; --- 6 unchanged lines hidden (view full) --- 1701 return (s); 1702} 1703 1704/* 1705 * Completes the type of a tag in a struct/union/enum declaration. 1706 * tp points to the type of the, tag, fmem to the list of members/enums. 1707 */ 1708type_t * | 1630{ 1631 const char *s; 1632 1633 switch (sc) { 1634 case EXTERN: s = "extern"; break; 1635 case STATIC: s = "static"; break; 1636 case AUTO: s = "auto"; break; 1637 case REG: s = "register"; break; --- 6 unchanged lines hidden (view full) --- 1644 return (s); 1645} 1646 1647/* 1648 * Completes the type of a tag in a struct/union/enum declaration. 1649 * tp points to the type of the, tag, fmem to the list of members/enums. 1650 */ 1651type_t * |
1709compltag(tp, fmem) 1710 type_t *tp; 1711 sym_t *fmem; | 1652compltag(type_t *tp, sym_t *fmem) |
1712{ 1713 tspec_t t; 1714 str_t *sp; 1715 int n; 1716 sym_t *mem; 1717 1718 /* from now a complete type */ 1719 setcompl(tp, 0); --- 25 unchanged lines hidden (view full) --- 1745 return (tp); 1746} 1747 1748/* 1749 * Processes the name of an enumerator in en enum declaration. 1750 * 1751 * sym points to the enumerator 1752 * val is the value of the enumerator | 1653{ 1654 tspec_t t; 1655 str_t *sp; 1656 int n; 1657 sym_t *mem; 1658 1659 /* from now a complete type */ 1660 setcompl(tp, 0); --- 25 unchanged lines hidden (view full) --- 1686 return (tp); 1687} 1688 1689/* 1690 * Processes the name of an enumerator in en enum declaration. 1691 * 1692 * sym points to the enumerator 1693 * val is the value of the enumerator |
1753 * impl is 1 if the the value of the enumerator was not explicit specified. | 1694 * impl is 1 if the value of the enumerator was not explicit specified. |
1754 */ 1755sym_t * | 1695 */ 1696sym_t * |
1756ename(sym, val, impl) 1757 sym_t *sym; 1758 int val, impl; | 1697ename(sym_t *sym, int val, int impl) |
1759{ | 1698{ |
1699 |
|
1760 if (sym->s_scl) { 1761 if (sym->s_blklev == blklev) { 1762 /* no hflag, because this is illegal!!! */ 1763 if (sym->s_arg) { 1764 /* enumeration constant hides parameter: %s */ 1765 warning(57, sym->s_name); 1766 } else { 1767 /* redeclaration of %s */ --- 24 unchanged lines hidden (view full) --- 1792 enumval = val + 1; 1793 return (sym); 1794} 1795 1796/* 1797 * Process a single external declarator. 1798 */ 1799void | 1700 if (sym->s_scl) { 1701 if (sym->s_blklev == blklev) { 1702 /* no hflag, because this is illegal!!! */ 1703 if (sym->s_arg) { 1704 /* enumeration constant hides parameter: %s */ 1705 warning(57, sym->s_name); 1706 } else { 1707 /* redeclaration of %s */ --- 24 unchanged lines hidden (view full) --- 1732 enumval = val + 1; 1733 return (sym); 1734} 1735 1736/* 1737 * Process a single external declarator. 1738 */ 1739void |
1800decl1ext(dsym, initflg) 1801 sym_t *dsym; 1802 int initflg; | 1740decl1ext(sym_t *dsym, int initflg) |
1803{ 1804 int warn, rval, redec; 1805 sym_t *rdsym; 1806 1807 chkfdef(dsym, 1); 1808 1809 chktyp(dsym); 1810 --- 39 unchanged lines hidden (view full) --- 1850 */ 1851 if (rdsym->s_osdef && dsym->s_type->t_proto) { 1852 redec = chkosdef(rdsym, dsym); 1853 } else { 1854 redec = 0; 1855 } 1856 1857 if (!redec && !isredec(dsym, (warn = 0, &warn))) { | 1741{ 1742 int warn, rval, redec; 1743 sym_t *rdsym; 1744 1745 chkfdef(dsym, 1); 1746 1747 chktyp(dsym); 1748 --- 39 unchanged lines hidden (view full) --- 1788 */ 1789 if (rdsym->s_osdef && dsym->s_type->t_proto) { 1790 redec = chkosdef(rdsym, dsym); 1791 } else { 1792 redec = 0; 1793 } 1794 1795 if (!redec && !isredec(dsym, (warn = 0, &warn))) { |
1858 | 1796 |
1859 if (warn) { 1860 /* redeclaration of %s */ 1861 (*(sflag ? error : warning))(27, dsym->s_name); 1862 prevdecl(-1, rdsym); 1863 } 1864 1865 /* 1866 * Overtake the rememberd params if the new symbol --- 29 unchanged lines hidden (view full) --- 1896 1897 /* once a function is inline, it remains inline */ 1898 if (rdsym->s_inline) 1899 dsym->s_inline = 1; 1900 1901 compltyp(dsym, rdsym); 1902 1903 } | 1797 if (warn) { 1798 /* redeclaration of %s */ 1799 (*(sflag ? error : warning))(27, dsym->s_name); 1800 prevdecl(-1, rdsym); 1801 } 1802 1803 /* 1804 * Overtake the rememberd params if the new symbol --- 29 unchanged lines hidden (view full) --- 1834 1835 /* once a function is inline, it remains inline */ 1836 if (rdsym->s_inline) 1837 dsym->s_inline = 1; 1838 1839 compltyp(dsym, rdsym); 1840 1841 } |
1904 | 1842 |
1905 rmsym(rdsym); 1906 } 1907 1908 if (dsym->s_scl == TYPEDEF) { 1909 dsym->s_type = duptyp(dsym->s_type); 1910 dsym->s_type->t_typedef = 1; 1911 settdsym(dsym->s_type, dsym); 1912 } 1913 1914} 1915 1916/* 1917 * Copies informations about usage into a new symbol table entry of 1918 * the same symbol. 1919 */ 1920void | 1843 rmsym(rdsym); 1844 } 1845 1846 if (dsym->s_scl == TYPEDEF) { 1847 dsym->s_type = duptyp(dsym->s_type); 1848 dsym->s_type->t_typedef = 1; 1849 settdsym(dsym->s_type, dsym); 1850 } 1851 1852} 1853 1854/* 1855 * Copies informations about usage into a new symbol table entry of 1856 * the same symbol. 1857 */ 1858void |
1921cpuinfo(sym, rdsym) 1922 sym_t *sym, *rdsym; | 1859cpuinfo(sym_t *sym, sym_t *rdsym) |
1923{ | 1860{ |
1861 |
|
1924 sym->s_spos = rdsym->s_spos; 1925 sym->s_upos = rdsym->s_upos; 1926 sym->s_set = rdsym->s_set; 1927 sym->s_used = rdsym->s_used; 1928} 1929 1930/* 1931 * Prints an error and returns 1 if a symbol is redeclared/redefined. 1932 * Otherwise returns 0 and, in some cases of minor problems, prints 1933 * a warning. 1934 */ 1935int | 1862 sym->s_spos = rdsym->s_spos; 1863 sym->s_upos = rdsym->s_upos; 1864 sym->s_set = rdsym->s_set; 1865 sym->s_used = rdsym->s_used; 1866} 1867 1868/* 1869 * Prints an error and returns 1 if a symbol is redeclared/redefined. 1870 * Otherwise returns 0 and, in some cases of minor problems, prints 1871 * a warning. 1872 */ 1873int |
1936isredec(dsym, warn) 1937 sym_t *dsym; 1938 int *warn; | 1874isredec(sym_t *dsym, int *warn) |
1939{ 1940 sym_t *rsym; 1941 1942 if ((rsym = dcs->d_rdcsym)->s_scl == ENUMCON) { 1943 /* redeclaration of %s */ 1944 error(27, dsym->s_name); 1945 prevdecl(-1, rsym); 1946 return (1); --- 62 unchanged lines hidden (view full) --- 2009 * 2010 * ignqual ignore qualifiers of type; used for function params 2011 * promot promote left type; used for comparison of params of 2012 * old style function definitions with params of prototypes. 2013 * *warn set to 1 if an old style function declaration is not 2014 * compatible with a prototype 2015 */ 2016int | 1875{ 1876 sym_t *rsym; 1877 1878 if ((rsym = dcs->d_rdcsym)->s_scl == ENUMCON) { 1879 /* redeclaration of %s */ 1880 error(27, dsym->s_name); 1881 prevdecl(-1, rsym); 1882 return (1); --- 62 unchanged lines hidden (view full) --- 1945 * 1946 * ignqual ignore qualifiers of type; used for function params 1947 * promot promote left type; used for comparison of params of 1948 * old style function definitions with params of prototypes. 1949 * *warn set to 1 if an old style function declaration is not 1950 * compatible with a prototype 1951 */ 1952int |
2017eqtype(tp1, tp2, ignqual, promot, warn) 2018 type_t *tp1, *tp2; 2019 int ignqual, promot, *warn; | 1953eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn) |
2020{ 2021 tspec_t t; 2022 2023 while (tp1 != NULL && tp2 != NULL) { 2024 2025 t = tp1->t_tspec; 2026 if (promot) { 2027 if (t == FLOAT) { --- 49 unchanged lines hidden (view full) --- 2077 2078 return (tp1 == tp2); 2079} 2080 2081/* 2082 * Compares the parameter types of two prototypes. 2083 */ 2084static int | 1954{ 1955 tspec_t t; 1956 1957 while (tp1 != NULL && tp2 != NULL) { 1958 1959 t = tp1->t_tspec; 1960 if (promot) { 1961 if (t == FLOAT) { --- 49 unchanged lines hidden (view full) --- 2011 2012 return (tp1 == tp2); 2013} 2014 2015/* 2016 * Compares the parameter types of two prototypes. 2017 */ 2018static int |
2085eqargs(tp1, tp2, warn) 2086 type_t *tp1, *tp2; 2087 int *warn; | 2019eqargs(type_t *tp1, type_t *tp2, int *warn) |
2088{ 2089 sym_t *a1, *a2; 2090 2091 if (tp1->t_vararg != tp2->t_vararg) 2092 return (0); 2093 2094 a1 = tp1->t_args; 2095 a2 = tp2->t_args; --- 17 unchanged lines hidden (view full) --- 2113 * and old style function declaration. 2114 * This is the case if following conditions are met: 2115 * 1. the prototype must have a fixed number of parameters 2116 * 2. no parameter is of type float 2117 * 3. no parameter is converted to another type if integer promotion 2118 * is applied on it 2119 */ 2120static int | 2020{ 2021 sym_t *a1, *a2; 2022 2023 if (tp1->t_vararg != tp2->t_vararg) 2024 return (0); 2025 2026 a1 = tp1->t_args; 2027 a2 = tp2->t_args; --- 17 unchanged lines hidden (view full) --- 2045 * and old style function declaration. 2046 * This is the case if following conditions are met: 2047 * 1. the prototype must have a fixed number of parameters 2048 * 2. no parameter is of type float 2049 * 3. no parameter is converted to another type if integer promotion 2050 * is applied on it 2051 */ 2052static int |
2121mnoarg(tp, warn) 2122 type_t *tp; 2123 int *warn; | 2053mnoarg(type_t *tp, int *warn) |
2124{ 2125 sym_t *arg; 2126 tspec_t t; 2127 2128 if (tp->t_vararg) { 2129 if (warn != NULL) 2130 *warn = 1; 2131 } --- 8 unchanged lines hidden (view full) --- 2140 return (1); 2141} 2142 2143/* 2144 * Compares a prototype declaration with the remembered arguments of 2145 * a previous old style function definition. 2146 */ 2147static int | 2054{ 2055 sym_t *arg; 2056 tspec_t t; 2057 2058 if (tp->t_vararg) { 2059 if (warn != NULL) 2060 *warn = 1; 2061 } --- 8 unchanged lines hidden (view full) --- 2070 return (1); 2071} 2072 2073/* 2074 * Compares a prototype declaration with the remembered arguments of 2075 * a previous old style function definition. 2076 */ 2077static int |
2148chkosdef(rdsym, dsym) 2149 sym_t *rdsym, *dsym; | 2078chkosdef(sym_t *rdsym, sym_t *dsym) |
2150{ 2151 sym_t *args, *pargs, *arg, *parg; 2152 int narg, nparg, n; 2153 int warn, msg; 2154 2155 args = rdsym->s_args; 2156 pargs = dsym->s_type->t_args; 2157 --- 44 unchanged lines hidden (view full) --- 2202 * 2203 * Following lines are legal: 2204 * "typedef a[]; a b; a b[10]; a c; a c[20];" 2205 * "typedef ft(); ft f; f(int); ft g; g(long);" 2206 * This means that, if a type is completed, the type structure must 2207 * be duplicated. 2208 */ 2209void | 2079{ 2080 sym_t *args, *pargs, *arg, *parg; 2081 int narg, nparg, n; 2082 int warn, msg; 2083 2084 args = rdsym->s_args; 2085 pargs = dsym->s_type->t_args; 2086 --- 44 unchanged lines hidden (view full) --- 2131 * 2132 * Following lines are legal: 2133 * "typedef a[]; a b; a b[10]; a c; a c[20];" 2134 * "typedef ft(); ft f; f(int); ft g; g(long);" 2135 * This means that, if a type is completed, the type structure must 2136 * be duplicated. 2137 */ 2138void |
2210compltyp(dsym, ssym) 2211 sym_t *dsym, *ssym; | 2139compltyp(sym_t *dsym, sym_t *ssym) |
2212{ 2213 type_t **dstp, *src; 2214 type_t *dst; 2215 2216 dstp = &dsym->s_type; 2217 src = ssym->s_type; 2218 2219 while ((dst = *dstp) != NULL) { --- 17 unchanged lines hidden (view full) --- 2237 src = src->t_subt; 2238 } 2239} 2240 2241/* 2242 * Completes the declaration of a single argument. 2243 */ 2244sym_t * | 2140{ 2141 type_t **dstp, *src; 2142 type_t *dst; 2143 2144 dstp = &dsym->s_type; 2145 src = ssym->s_type; 2146 2147 while ((dst = *dstp) != NULL) { --- 17 unchanged lines hidden (view full) --- 2165 src = src->t_subt; 2166 } 2167} 2168 2169/* 2170 * Completes the declaration of a single argument. 2171 */ 2172sym_t * |
2245decl1arg(sym, initflg) 2246 sym_t *sym; 2247 int initflg; | 2173decl1arg(sym_t *sym, int initflg) |
2248{ 2249 tspec_t t; 2250 2251 chkfdef(sym, 1); 2252 2253 chktyp(sym); 2254 2255 if (dcs->d_rdcsym != NULL && dcs->d_rdcsym->s_blklev == blklev) { --- 47 unchanged lines hidden (view full) --- 2303/* 2304 * Does some checks for lint directives which apply to functions. 2305 * Processes arguments in old style function definitions which default 2306 * to int. 2307 * Checks compatiblility of old style function definition with previous 2308 * prototype. 2309 */ 2310void | 2174{ 2175 tspec_t t; 2176 2177 chkfdef(sym, 1); 2178 2179 chktyp(sym); 2180 2181 if (dcs->d_rdcsym != NULL && dcs->d_rdcsym->s_blklev == blklev) { --- 47 unchanged lines hidden (view full) --- 2229/* 2230 * Does some checks for lint directives which apply to functions. 2231 * Processes arguments in old style function definitions which default 2232 * to int. 2233 * Checks compatiblility of old style function definition with previous 2234 * prototype. 2235 */ 2236void |
2311cluparg() | 2237cluparg(void) |
2312{ 2313 sym_t *args, *arg, *pargs, *parg; 2314 int narg, nparg, n, msg; 2315 tspec_t t; 2316 2317 args = funcsym->s_args; 2318 pargs = funcsym->s_type->t_args; 2319 --- 97 unchanged lines hidden (view full) --- 2417 } 2418 if (msg) 2419 /* prototype declaration */ 2420 prevdecl(285, dcs->d_rdcsym); 2421 2422 /* from now the prototype is valid */ 2423 funcsym->s_osdef = 0; 2424 funcsym->s_args = NULL; | 2238{ 2239 sym_t *args, *arg, *pargs, *parg; 2240 int narg, nparg, n, msg; 2241 tspec_t t; 2242 2243 args = funcsym->s_args; 2244 pargs = funcsym->s_type->t_args; 2245 --- 97 unchanged lines hidden (view full) --- 2343 } 2344 if (msg) 2345 /* prototype declaration */ 2346 prevdecl(285, dcs->d_rdcsym); 2347 2348 /* from now the prototype is valid */ 2349 funcsym->s_osdef = 0; 2350 funcsym->s_args = NULL; |
2425 | 2351 |
2426 } 2427 2428} 2429 2430/* 2431 * Checks compatibility of an old style function definition with a previous 2432 * prototype declaration. 2433 * Returns 1 if the position of the previous declaration should be reported. 2434 */ 2435static int | 2352 } 2353 2354} 2355 2356/* 2357 * Checks compatibility of an old style function definition with a previous 2358 * prototype declaration. 2359 * Returns 1 if the position of the previous declaration should be reported. 2360 */ 2361static int |
2436chkptdecl(arg, parg) 2437 sym_t *arg, *parg; | 2362chkptdecl(sym_t *arg, sym_t *parg) |
2438{ 2439 type_t *tp, *ptp; 2440 int warn, msg; 2441 2442 tp = arg->s_type; 2443 ptp = parg->s_type; 2444 2445 msg = 0; --- 16 unchanged lines hidden (view full) --- 2462 2463 return (msg); 2464} 2465 2466/* 2467 * Completes a single local declaration/definition. 2468 */ 2469void | 2363{ 2364 type_t *tp, *ptp; 2365 int warn, msg; 2366 2367 tp = arg->s_type; 2368 ptp = parg->s_type; 2369 2370 msg = 0; --- 16 unchanged lines hidden (view full) --- 2387 2388 return (msg); 2389} 2390 2391/* 2392 * Completes a single local declaration/definition. 2393 */ 2394void |
2470decl1loc(dsym, initflg) 2471 sym_t *dsym; 2472 int initflg; | 2395decl1loc(sym_t *dsym, int initflg) |
2473{ | 2396{ |
2397 |
|
2474 /* Correct a mistake done in dname(). */ 2475 if (dsym->s_type->t_tspec == FUNC) { 2476 dsym->s_def = DECL; 2477 if (dcs->d_scl == NOSCL) 2478 dsym->s_scl = EXTERN; 2479 } 2480 2481 if (dsym->s_type->t_tspec == FUNC) { --- 88 unchanged lines hidden (view full) --- 2570 } 2571 } 2572 2573 } else if (dcs->d_rdcsym->s_blklev < blklev) { 2574 2575 if (hflag) 2576 /* declaration hides earlier one: %s */ 2577 warning(95, dsym->s_name); | 2398 /* Correct a mistake done in dname(). */ 2399 if (dsym->s_type->t_tspec == FUNC) { 2400 dsym->s_def = DECL; 2401 if (dcs->d_scl == NOSCL) 2402 dsym->s_scl = EXTERN; 2403 } 2404 2405 if (dsym->s_type->t_tspec == FUNC) { --- 88 unchanged lines hidden (view full) --- 2494 } 2495 } 2496 2497 } else if (dcs->d_rdcsym->s_blklev < blklev) { 2498 2499 if (hflag) 2500 /* declaration hides earlier one: %s */ 2501 warning(95, dsym->s_name); |
2578 | 2502 |
2579 } 2580 2581 if (dcs->d_rdcsym->s_blklev == blklev) { 2582 2583 /* redeclaration of %s */ 2584 error(27, dsym->s_name); 2585 rmsym(dcs->d_rdcsym); 2586 --- 17 unchanged lines hidden (view full) --- 2604 * which may follow. 2605 */ 2606} 2607 2608/* 2609 * Processes (re)declarations of external Symbols inside blocks. 2610 */ 2611static void | 2503 } 2504 2505 if (dcs->d_rdcsym->s_blklev == blklev) { 2506 2507 /* redeclaration of %s */ 2508 error(27, dsym->s_name); 2509 rmsym(dcs->d_rdcsym); 2510 --- 17 unchanged lines hidden (view full) --- 2528 * which may follow. 2529 */ 2530} 2531 2532/* 2533 * Processes (re)declarations of external Symbols inside blocks. 2534 */ 2535static void |
2612ledecl(dsym) 2613 sym_t *dsym; | 2536ledecl(sym_t *dsym) |
2614{ 2615 int eqt, warn; 2616 sym_t *esym; 2617 2618 /* look for a symbol with the same name */ 2619 esym = dcs->d_rdcsym; 2620 while (esym != NULL && esym->s_blklev != 0) { 2621 while ((esym = esym->s_link) != NULL) { --- 38 unchanged lines hidden (view full) --- 2660} 2661 2662/* 2663 * Print an error or a warning if the symbol cant be initialized due 2664 * to type/storage class. Returnvalue is 1 if an error has been 2665 * detected. 2666 */ 2667static int | 2537{ 2538 int eqt, warn; 2539 sym_t *esym; 2540 2541 /* look for a symbol with the same name */ 2542 esym = dcs->d_rdcsym; 2543 while (esym != NULL && esym->s_blklev != 0) { 2544 while ((esym = esym->s_link) != NULL) { --- 38 unchanged lines hidden (view full) --- 2583} 2584 2585/* 2586 * Print an error or a warning if the symbol cant be initialized due 2587 * to type/storage class. Returnvalue is 1 if an error has been 2588 * detected. 2589 */ 2590static int |
2668chkinit(sym) 2669 sym_t *sym; | 2591chkinit(sym_t *sym) |
2670{ 2671 int err; 2672 2673 err = 0; 2674 2675 if (sym->s_type->t_tspec == FUNC) { 2676 /* cannot initialize function: %s */ 2677 error(24, sym->s_name); --- 14 unchanged lines hidden (view full) --- 2692 2693 return (err); 2694} 2695 2696/* 2697 * Create a symbole for an abstract declaration. 2698 */ 2699sym_t * | 2592{ 2593 int err; 2594 2595 err = 0; 2596 2597 if (sym->s_type->t_tspec == FUNC) { 2598 /* cannot initialize function: %s */ 2599 error(24, sym->s_name); --- 14 unchanged lines hidden (view full) --- 2614 2615 return (err); 2616} 2617 2618/* 2619 * Create a symbole for an abstract declaration. 2620 */ 2621sym_t * |
2700aname() | 2622aname(void) |
2701{ 2702 sym_t *sym; 2703 2704 if (dcs->d_ctx != ABSTRACT && dcs->d_ctx != PARG) 2705 lerror("aname()"); 2706 2707 sym = getblk(sizeof (sym_t)); 2708 --- 11 unchanged lines hidden (view full) --- 2720 2721 return (sym); 2722} 2723 2724/* 2725 * Removes anything which has nothing to do on global level. 2726 */ 2727void | 2623{ 2624 sym_t *sym; 2625 2626 if (dcs->d_ctx != ABSTRACT && dcs->d_ctx != PARG) 2627 lerror("aname()"); 2628 2629 sym = getblk(sizeof (sym_t)); 2630 --- 11 unchanged lines hidden (view full) --- 2642 2643 return (sym); 2644} 2645 2646/* 2647 * Removes anything which has nothing to do on global level. 2648 */ 2649void |
2728globclup() | 2650globclup(void) |
2729{ | 2651{ |
2652 |
|
2730 while (dcs->d_nxt != NULL) 2731 popdecl(); 2732 2733 cleanup(); 2734 blklev = 0; 2735 mblklev = 0; 2736 2737 /* 2738 * remove all informations about pending lint directives without 2739 * warnings. 2740 */ 2741 glclup(1); 2742} 2743 2744/* 2745 * Process an abstract type declaration 2746 */ 2747sym_t * | 2653 while (dcs->d_nxt != NULL) 2654 popdecl(); 2655 2656 cleanup(); 2657 blklev = 0; 2658 mblklev = 0; 2659 2660 /* 2661 * remove all informations about pending lint directives without 2662 * warnings. 2663 */ 2664 glclup(1); 2665} 2666 2667/* 2668 * Process an abstract type declaration 2669 */ 2670sym_t * |
2748decl1abs(sym) 2749 sym_t *sym; | 2671decl1abs(sym_t *sym) |
2750{ | 2672{ |
2673 |
|
2751 chkfdef(sym, 1); 2752 chktyp(sym); 2753 return (sym); 2754} 2755 2756/* 2757 * Checks size after declarations of variables and their initialisation. 2758 */ 2759void | 2674 chkfdef(sym, 1); 2675 chktyp(sym); 2676 return (sym); 2677} 2678 2679/* 2680 * Checks size after declarations of variables and their initialisation. 2681 */ 2682void |
2760chksz(dsym) 2761 sym_t *dsym; | 2683chksz(sym_t *dsym) |
2762{ | 2684{ |
2685 |
|
2763 /* 2764 * check size only for symbols which are defined and no function and 2765 * not typedef name 2766 */ 2767 if (dsym->s_def != DEF) 2768 return; 2769 if (dsym->s_scl == TYPEDEF) 2770 return; --- 10 unchanged lines hidden (view full) --- 2781 } 2782 } 2783} 2784 2785/* 2786 * Mark an object as set if it is not already 2787 */ 2788void | 2686 /* 2687 * check size only for symbols which are defined and no function and 2688 * not typedef name 2689 */ 2690 if (dsym->s_def != DEF) 2691 return; 2692 if (dsym->s_scl == TYPEDEF) 2693 return; --- 10 unchanged lines hidden (view full) --- 2704 } 2705 } 2706} 2707 2708/* 2709 * Mark an object as set if it is not already 2710 */ 2711void |
2789setsflg(sym) 2790 sym_t *sym; | 2712setsflg(sym_t *sym) |
2791{ | 2713{ |
2714 |
|
2792 if (!sym->s_set) { 2793 sym->s_set = 1; | 2715 if (!sym->s_set) { 2716 sym->s_set = 1; |
2794 STRUCT_ASSIGN(sym->s_spos, curr_pos); | 2717 UNIQUE_CURR_POS(sym->s_spos); |
2795 } 2796} 2797 2798/* 2799 * Mark an object as used if it is not already 2800 */ 2801void | 2718 } 2719} 2720 2721/* 2722 * Mark an object as used if it is not already 2723 */ 2724void |
2802setuflg(sym, fcall, szof) 2803 sym_t *sym; 2804 int fcall, szof; | 2725setuflg(sym_t *sym, int fcall, int szof) |
2805{ | 2726{ |
2727 |
|
2806 if (!sym->s_used) { 2807 sym->s_used = 1; | 2728 if (!sym->s_used) { 2729 sym->s_used = 1; |
2808 STRUCT_ASSIGN(sym->s_upos, curr_pos); | 2730 UNIQUE_CURR_POS(sym->s_upos); |
2809 } 2810 /* 2811 * for function calls another record is written 2812 * 2813 * XXX Should symbols used in sizeof() treated as used or not? 2814 * Probably not, because there is no sense to declare an 2815 * external variable only to get their size. 2816 */ 2817 if (!fcall && !szof && sym->s_kind == FVFT && sym->s_scl == EXTERN) 2818 outusg(sym); 2819} 2820 2821/* 2822 * Prints warnings for a list of variables and labels (concatenated 2823 * with s_dlnxt) if these are not used or only set. 2824 */ 2825void | 2731 } 2732 /* 2733 * for function calls another record is written 2734 * 2735 * XXX Should symbols used in sizeof() treated as used or not? 2736 * Probably not, because there is no sense to declare an 2737 * external variable only to get their size. 2738 */ 2739 if (!fcall && !szof && sym->s_kind == FVFT && sym->s_scl == EXTERN) 2740 outusg(sym); 2741} 2742 2743/* 2744 * Prints warnings for a list of variables and labels (concatenated 2745 * with s_dlnxt) if these are not used or only set. 2746 */ 2747void |
2826chkusage(di) 2827 dinfo_t *di; | 2748chkusage(dinfo_t *di) |
2828{ 2829 sym_t *sym; 2830 int mknowarn; 2831 2832 /* for this warnings LINTED has no effect */ 2833 mknowarn = nowarn; 2834 nowarn = 0; 2835 2836 for (sym = di->d_dlsyms; sym != NULL; sym = sym->s_dlnxt) 2837 chkusg1(di->d_asm, sym); 2838 2839 nowarn = mknowarn; 2840} 2841 2842/* 2843 * Prints a warning for a single variable or label if it is not used or 2844 * only set. 2845 */ 2846void | 2749{ 2750 sym_t *sym; 2751 int mknowarn; 2752 2753 /* for this warnings LINTED has no effect */ 2754 mknowarn = nowarn; 2755 nowarn = 0; 2756 2757 for (sym = di->d_dlsyms; sym != NULL; sym = sym->s_dlnxt) 2758 chkusg1(di->d_asm, sym); 2759 2760 nowarn = mknowarn; 2761} 2762 2763/* 2764 * Prints a warning for a single variable or label if it is not used or 2765 * only set. 2766 */ 2767void |
2847chkusg1(novar, sym) 2848 int novar; 2849 sym_t *sym; | 2768chkusg1(int novar, sym_t *sym) |
2850{ 2851 pos_t cpos; 2852 2853 if (sym->s_blklev == -1) 2854 return; 2855 2856 STRUCT_ASSIGN(cpos, curr_pos); 2857 --- 8 unchanged lines hidden (view full) --- 2866 } else if (sym->s_kind == FTAG) { 2867 chktusg(sym); 2868 } 2869 2870 STRUCT_ASSIGN(curr_pos, cpos); 2871} 2872 2873static void | 2769{ 2770 pos_t cpos; 2771 2772 if (sym->s_blklev == -1) 2773 return; 2774 2775 STRUCT_ASSIGN(cpos, curr_pos); 2776 --- 8 unchanged lines hidden (view full) --- 2785 } else if (sym->s_kind == FTAG) { 2786 chktusg(sym); 2787 } 2788 2789 STRUCT_ASSIGN(curr_pos, cpos); 2790} 2791 2792static void |
2874chkausg(novar, arg) 2875 int novar; 2876 sym_t *arg; | 2793chkausg(int novar, sym_t *arg) |
2877{ | 2794{ |
2795 |
|
2878 if (!arg->s_set) 2879 lerror("chkausg() 1"); 2880 2881 if (novar) 2882 return; 2883 2884 if (!arg->s_used && vflag) { 2885 STRUCT_ASSIGN(curr_pos, arg->s_dpos); 2886 /* argument %s unused in function %s */ 2887 warning(231, arg->s_name, funcsym->s_name); 2888 } 2889} 2890 2891static void | 2796 if (!arg->s_set) 2797 lerror("chkausg() 1"); 2798 2799 if (novar) 2800 return; 2801 2802 if (!arg->s_used && vflag) { 2803 STRUCT_ASSIGN(curr_pos, arg->s_dpos); 2804 /* argument %s unused in function %s */ 2805 warning(231, arg->s_name, funcsym->s_name); 2806 } 2807} 2808 2809static void |
2892chkvusg(novar, sym) 2893 int novar; 2894 sym_t *sym; | 2810chkvusg(int novar, sym_t *sym) |
2895{ 2896 scl_t sc; 2897 sym_t *xsym; 2898 2899 if (blklev == 0 || sym->s_blklev == 0) 2900 lerror("chkvusg() 1"); 2901 2902 /* errors in expressions easily cause lots of these warnings */ --- 50 unchanged lines hidden (view full) --- 2953 xsym->s_set = 1; 2954 STRUCT_ASSIGN(xsym->s_spos, sym->s_spos); 2955 } 2956 } 2957 } 2958} 2959 2960static void | 2811{ 2812 scl_t sc; 2813 sym_t *xsym; 2814 2815 if (blklev == 0 || sym->s_blklev == 0) 2816 lerror("chkvusg() 1"); 2817 2818 /* errors in expressions easily cause lots of these warnings */ --- 50 unchanged lines hidden (view full) --- 2869 xsym->s_set = 1; 2870 STRUCT_ASSIGN(xsym->s_spos, sym->s_spos); 2871 } 2872 } 2873 } 2874} 2875 2876static void |
2961chklusg(lab) 2962 sym_t *lab; | 2877chklusg(sym_t *lab) |
2963{ | 2878{ |
2879 |
|
2964 if (blklev != 1 || lab->s_blklev != 1) 2965 lerror("chklusg() 1"); 2966 2967 if (lab->s_set && !lab->s_used) { 2968 STRUCT_ASSIGN(curr_pos, lab->s_spos); 2969 /* label %s unused in function %s */ 2970 warning(192, lab->s_name, funcsym->s_name); 2971 } else if (!lab->s_set) { 2972 STRUCT_ASSIGN(curr_pos, lab->s_upos); 2973 /* undefined label %s */ 2974 warning(23, lab->s_name); 2975 } 2976} 2977 2978static void | 2880 if (blklev != 1 || lab->s_blklev != 1) 2881 lerror("chklusg() 1"); 2882 2883 if (lab->s_set && !lab->s_used) { 2884 STRUCT_ASSIGN(curr_pos, lab->s_spos); 2885 /* label %s unused in function %s */ 2886 warning(192, lab->s_name, funcsym->s_name); 2887 } else if (!lab->s_set) { 2888 STRUCT_ASSIGN(curr_pos, lab->s_upos); 2889 /* undefined label %s */ 2890 warning(23, lab->s_name); 2891 } 2892} 2893 2894static void |
2979chktusg(sym) 2980 sym_t *sym; | 2895chktusg(sym_t *sym) |
2981{ | 2896{ |
2897 |
|
2982 if (!incompl(sym->s_type)) 2983 return; 2984 2985 /* complain alwasy about incomplet tags declared inside blocks */ 2986 if (!zflag || dcs->d_ctx != EXTERN) 2987 return; 2988 2989 STRUCT_ASSIGN(curr_pos, sym->s_dpos); --- 19 unchanged lines hidden (view full) --- 3009 * Called after the entire translation unit has been parsed. 3010 * Changes tentative definitions in definitions. 3011 * Performs some tests on global Symbols. Detected Problems are: 3012 * - defined variables of incomplete type 3013 * - constant variables which are not initialized 3014 * - static symbols which are never used 3015 */ 3016void | 2898 if (!incompl(sym->s_type)) 2899 return; 2900 2901 /* complain alwasy about incomplet tags declared inside blocks */ 2902 if (!zflag || dcs->d_ctx != EXTERN) 2903 return; 2904 2905 STRUCT_ASSIGN(curr_pos, sym->s_dpos); --- 19 unchanged lines hidden (view full) --- 2925 * Called after the entire translation unit has been parsed. 2926 * Changes tentative definitions in definitions. 2927 * Performs some tests on global Symbols. Detected Problems are: 2928 * - defined variables of incomplete type 2929 * - constant variables which are not initialized 2930 * - static symbols which are never used 2931 */ 2932void |
3017chkglsyms() | 2933chkglsyms(void) |
3018{ 3019 sym_t *sym; 3020 pos_t cpos; 3021 3022 if (blklev != 0 || dcs->d_nxt != NULL) 3023 norecover(); 3024 3025 STRUCT_ASSIGN(cpos, curr_pos); --- 10 unchanged lines hidden (view full) --- 3036 lerror("chkglsyms() 1"); 3037 } 3038 } 3039 3040 STRUCT_ASSIGN(curr_pos, cpos); 3041} 3042 3043static void | 2934{ 2935 sym_t *sym; 2936 pos_t cpos; 2937 2938 if (blklev != 0 || dcs->d_nxt != NULL) 2939 norecover(); 2940 2941 STRUCT_ASSIGN(cpos, curr_pos); --- 10 unchanged lines hidden (view full) --- 2952 lerror("chkglsyms() 1"); 2953 } 2954 } 2955 2956 STRUCT_ASSIGN(curr_pos, cpos); 2957} 2958 2959static void |
3044chkglvar(sym) 3045 sym_t *sym; | 2960chkglvar(sym_t *sym) |
3046{ | 2961{ |
2962 |
|
3047 if (sym->s_scl == TYPEDEF || sym->s_scl == ENUMCON) 3048 return; | 2963 if (sym->s_scl == TYPEDEF || sym->s_scl == ENUMCON) 2964 return; |
3049 | 2965 |
3050 if (sym->s_scl != EXTERN && sym->s_scl != STATIC) 3051 lerror("chkglvar() 1"); 3052 3053 glchksz(sym); 3054 3055 if (sym->s_scl == STATIC) { 3056 if (sym->s_type->t_tspec == FUNC) { 3057 if (sym->s_used && sym->s_def != DEF) { --- 25 unchanged lines hidden (view full) --- 3083 STRUCT_ASSIGN(curr_pos, sym->s_dpos); 3084 /* const object %s should have initializer */ 3085 warning(227, sym->s_name); 3086 } 3087 } 3088} 3089 3090static void | 2966 if (sym->s_scl != EXTERN && sym->s_scl != STATIC) 2967 lerror("chkglvar() 1"); 2968 2969 glchksz(sym); 2970 2971 if (sym->s_scl == STATIC) { 2972 if (sym->s_type->t_tspec == FUNC) { 2973 if (sym->s_used && sym->s_def != DEF) { --- 25 unchanged lines hidden (view full) --- 2999 STRUCT_ASSIGN(curr_pos, sym->s_dpos); 3000 /* const object %s should have initializer */ 3001 warning(227, sym->s_name); 3002 } 3003 } 3004} 3005 3006static void |
3091glchksz(sym) 3092 sym_t *sym; | 3007glchksz(sym_t *sym) |
3093{ | 3008{ |
3009 |
|
3094 if (sym->s_def == TDEF) { 3095 if (sym->s_type->t_tspec == FUNC) 3096 /* | 3010 if (sym->s_def == TDEF) { 3011 if (sym->s_type->t_tspec == FUNC) 3012 /* |
3097 * this can happen if an syntax error occured | 3013 * this can happen if an syntax error occurred |
3098 * after a function declaration 3099 */ 3100 return; 3101 STRUCT_ASSIGN(curr_pos, sym->s_dpos); 3102 if (length(sym->s_type, sym->s_name) == 0 && 3103 sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) { 3104 /* empty array declaration: %s */ 3105 if (tflag || (sym->s_scl == EXTERN && !sflag)) { --- 4 unchanged lines hidden (view full) --- 3110 } 3111 } 3112} 3113 3114/* 3115 * Prints information about location of previous definition/declaration. 3116 */ 3117void | 3014 * after a function declaration 3015 */ 3016 return; 3017 STRUCT_ASSIGN(curr_pos, sym->s_dpos); 3018 if (length(sym->s_type, sym->s_name) == 0 && 3019 sym->s_type->t_tspec == ARRAY && sym->s_type->t_dim == 0) { 3020 /* empty array declaration: %s */ 3021 if (tflag || (sym->s_scl == EXTERN && !sflag)) { --- 4 unchanged lines hidden (view full) --- 3026 } 3027 } 3028} 3029 3030/* 3031 * Prints information about location of previous definition/declaration. 3032 */ 3033void |
3118prevdecl(msg, psym) 3119 int msg; 3120 sym_t *psym; | 3034prevdecl(int msg, sym_t *psym) |
3121{ 3122 pos_t cpos; 3123 3124 if (!rflag) 3125 return; 3126 3127 STRUCT_ASSIGN(cpos, curr_pos); 3128 STRUCT_ASSIGN(curr_pos, psym->s_dpos); 3129 if (msg != -1) { 3130 message(msg, psym->s_name); 3131 } else if (psym->s_def == DEF || psym->s_def == TDEF) { 3132 /* previous definition of %s */ 3133 message(261, psym->s_name); 3134 } else { 3135 /* previous declaration of %s */ 3136 message(260, psym->s_name); 3137 } 3138 STRUCT_ASSIGN(curr_pos, cpos); 3139} | 3035{ 3036 pos_t cpos; 3037 3038 if (!rflag) 3039 return; 3040 3041 STRUCT_ASSIGN(cpos, curr_pos); 3042 STRUCT_ASSIGN(curr_pos, psym->s_dpos); 3043 if (msg != -1) { 3044 message(msg, psym->s_name); 3045 } else if (psym->s_def == DEF || psym->s_def == TDEF) { 3046 /* previous definition of %s */ 3047 message(261, psym->s_name); 3048 } else { 3049 /* previous declaration of %s */ 3050 message(260, psym->s_name); 3051 } 3052 STRUCT_ASSIGN(curr_pos, cpos); 3053} |