diff options
author | Mark Murray <markm@FreeBSD.org> | 2002-03-03 15:12:50 +0000 |
---|---|---|
committer | Mark Murray <markm@FreeBSD.org> | 2002-03-03 15:12:50 +0000 |
commit | f84f50e683160fa66939b97b2b1eaadf37effa21 (patch) | |
tree | fbbab8c077a40ec926aa302ea9349a790feb7896 /usr.bin/xlint/lint1/decl.c | |
parent | 95f78da7d8e915c6f18b34170611f9e8d836cce8 (diff) | |
download | src-f84f50e683160fa66939b97b2b1eaadf37effa21.tar.gz src-f84f50e683160fa66939b97b2b1eaadf37effa21.zip |
Merge conflicts, fix Makefiles and remove (re)moved file(s).
Notes
Notes:
svn path=/head/; revision=91592
Diffstat (limited to 'usr.bin/xlint/lint1/decl.c')
-rw-r--r-- | usr.bin/xlint/lint1/decl.c | 522 |
1 files changed, 218 insertions, 304 deletions
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 143840b1707b..e59fe67dfc33 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,6 +1,7 @@ -/* $NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $ */ +/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -31,10 +32,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $"); #endif +__FBSDID("$FreeBSD$"); #include <sys/param.h> #include <limits.h> @@ -45,9 +47,6 @@ static const char rcsid[] = const char *unnamed = "<unnamed>"; -/* contains various information and classification on types */ -ttab_t ttab[NTSPEC]; - /* shared type structures for arithmtic types and void */ static type_t *typetab; @@ -60,107 +59,33 @@ int enumval; */ dinfo_t *dcs; -static type_t *tdeferr __P((type_t *, tspec_t)); -static void settdsym __P((type_t *, sym_t *)); -static tspec_t mrgtspec __P((tspec_t, tspec_t)); -static void align __P((int, int)); -static sym_t *newtag __P((sym_t *, scl_t, int, int)); -static int eqargs __P((type_t *, type_t *, int *)); -static int mnoarg __P((type_t *, int *)); -static int chkosdef __P((sym_t *, sym_t *)); -static int chkptdecl __P((sym_t *, sym_t *)); -static sym_t *nsfunc __P((sym_t *, sym_t *)); -static void osfunc __P((sym_t *, sym_t *)); -static void ledecl __P((sym_t *)); -static int chkinit __P((sym_t *)); -static void chkausg __P((int, sym_t *)); -static void chkvusg __P((int, sym_t *)); -static void chklusg __P((sym_t *)); -static void chktusg __P((sym_t *)); -static void chkglvar __P((sym_t *)); -static void glchksz __P((sym_t *)); +static type_t *tdeferr(type_t *, tspec_t); +static void settdsym(type_t *, sym_t *); +static tspec_t mrgtspec(tspec_t, tspec_t); +static void align(int, int); +static sym_t *newtag(sym_t *, scl_t, int, int); +static int eqargs(type_t *, type_t *, int *); +static int mnoarg(type_t *, int *); +static int chkosdef(sym_t *, sym_t *); +static int chkptdecl(sym_t *, sym_t *); +static sym_t *nsfunc(sym_t *, sym_t *); +static void osfunc(sym_t *, sym_t *); +static void ledecl(sym_t *); +static int chkinit(sym_t *); +static void chkausg(int, sym_t *); +static void chkvusg(int, sym_t *); +static void chklusg(sym_t *); +static void chktusg(sym_t *); +static void chkglvar(sym_t *); +static void glchksz(sym_t *); /* * initializes all global vars used in declarations */ void -initdecl() -{ - int i; - static struct { - tspec_t it_tspec; - ttab_t it_ttab; - } ittab[] = { - { SIGNED, { 0, 0, - SIGNED, UNSIGN, - 0, 0, 0, 0, 0, "signed" } }, - { UNSIGN, { 0, 0, - SIGNED, UNSIGN, - 0, 0, 0, 0, 0, "unsigned" } }, - { CHAR, { CHAR_BIT, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "char" } }, - { SCHAR, { CHAR_BIT, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "signed char" } }, - { UCHAR, { CHAR_BIT, CHAR_BIT, - SCHAR, UCHAR, - 1, 1, 0, 1, 1, "unsigned char" } }, - { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 0, 0, 1, 1, "short" } }, - { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 1, 0, 1, 1, "unsigned short" } }, - { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, - INT, UINT, - 1, 0, 0, 1, 1, "int" } }, - { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, - INT, UINT, - 1, 1, 0, 1, 1, "unsigned int" } }, - { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, - LONG, ULONG, - 1, 0, 0, 1, 1, "long" } }, - { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, - LONG, ULONG, - 1, 1, 0, 1, 1, "unsigned long" } }, - { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, - QUAD, UQUAD, - 1, 0, 0, 1, 1, "long long" } }, - { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, - QUAD, UQUAD, - 1, 1, 0, 1, 1, "unsigned long long" } }, - { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, - FLOAT, FLOAT, - 0, 0, 1, 1, 1, "float" } }, - { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, - DOUBLE, DOUBLE, - 0, 0, 1, 1, 1, "double" } }, - { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, - LDOUBLE, LDOUBLE, - 0, 0, 1, 1, 1, "long double" } }, - { VOID, { -1, -1, - VOID, VOID, - 0, 0, 0, 0, 0, "void" } }, - { STRUCT, { -1, -1, - STRUCT, STRUCT, - 0, 0, 0, 0, 0, "struct" } }, - { UNION, { -1, -1, - UNION, UNION, - 0, 0, 0, 0, 0, "union" } }, - { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, - ENUM, ENUM, - 1, 0, 0, 1, 1, "enum" } }, - { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, - PTR, PTR, - 0, 1, 0, 0, 1, "pointer" } }, - { ARRAY, { -1, -1, - ARRAY, ARRAY, - 0, 0, 0, 0, 0, "array" } }, - { FUNC, { -1, -1, - FUNC, FUNC, - 0, 0, 0, 0, 0, "function" } }, - }; +initdecl(void) +{ + int i; /* declaration stack */ if ((dcs = calloc(1, sizeof (dinfo_t))) == NULL) @@ -169,13 +94,8 @@ initdecl() dcs->d_ldlsym = &dcs->d_dlsyms; /* type information and classification */ - for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++) - STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab); - if (!pflag) { - for (i = 0; i < NTSPEC; i++) - ttab[i].tt_psz = ttab[i].tt_sz; - } - + inittyp(); + /* shared type structures */ if ((typetab = calloc(NTSPEC, sizeof (type_t))) == NULL) nomem(); @@ -211,15 +131,14 @@ initdecl() * if it is to be modified (adding qualifiers or anything else). */ type_t * -gettyp(t) - tspec_t t; +gettyp(tspec_t t) { + return (&typetab[t]); } type_t * -duptyp(tp) - const type_t *tp; +duptyp(const type_t *tp) { type_t *ntp; @@ -233,8 +152,7 @@ duptyp(tp) * allocated memory should be freed after the expr). */ type_t * -tduptyp(tp) - const type_t *tp; +tduptyp(const type_t *tp) { type_t *ntp; @@ -248,8 +166,7 @@ tduptyp(tp) * struct, union or enum type. */ int -incompl(tp) - type_t *tp; +incompl(type_t *tp) { tspec_t t; @@ -270,9 +187,7 @@ incompl(tp) * types. */ void -setcompl(tp, ic) - type_t *tp; - int ic; +setcompl(type_t *tp, int ic) { tspec_t t; @@ -293,9 +208,9 @@ setcompl(tp, ic) * storage classes. */ void -addscl(sc) - scl_t sc; +addscl(scl_t sc) { + if (sc == INLINE) { if (dcs->d_inline) /* duplicate '%s' */ @@ -330,8 +245,7 @@ addscl(sc) * struct/union/enum tag. */ void -addtype(tp) - type_t *tp; +addtype(type_t *tp) { tspec_t t; @@ -397,7 +311,7 @@ addtype(tp) /* remeber specifiers "signed" and "unsigned" in dcs->d_smod */ if (dcs->d_smod != NOTSPEC) /* - * more then one "signed" and/or "unsigned"; print + * more than one "signed" and/or "unsigned"; print * an error in deftyp() */ dcs->d_terr = 1; @@ -414,7 +328,7 @@ addtype(tp) } else { /* * remember specifiers "void", "char", "int", "float" or - * "double" int dcs->d_atyp + * "double" int dcs->d_atyp */ if (dcs->d_atyp != NOTSPEC) /* more than one, print error in deftyp() */ @@ -428,9 +342,7 @@ addtype(tp) * and other specifiers (except struct, union, enum, typedef name) */ static type_t * -tdeferr(td, t) - type_t *td; - tspec_t t; +tdeferr(type_t *td, tspec_t t) { tspec_t t2; @@ -482,7 +394,30 @@ tdeferr(td, t) } break; /* LINTED (enumeration values not handled in switch) */ - default: + case NOTSPEC: + case USHORT: + case UCHAR: + case SCHAR: + case CHAR: + case FUNC: + case ARRAY: + case PTR: + case ENUM: + case UNION: + case STRUCT: + case VOID: + case LDOUBLE: + case DOUBLE: + case FLOAT: + case UQUAD: + case QUAD: + case ULONG: + case UINT: + case INT: + break; + + case NTSPEC: /* this value unused */ + break; } /* Anything other is not accepted. */ @@ -496,14 +431,12 @@ tdeferr(td, t) * or enum tag if the typedef name is the first defined for this tag. * * If the tag is unnamed, the typdef name is used for identification - * of this tag in lint2. Although its possible that more then one typedef + * of this tag in lint2. Although its possible that more than one typedef * name is defined for one tag, the first name defined should be unique * if the tag is unnamed. */ static void -settdsym(tp, sym) - type_t *tp; - sym_t *sym; +settdsym(type_t *tp, sym_t *sym) { tspec_t t; @@ -521,13 +454,13 @@ settdsym(tp, sym) * (and not the declarator) in the top element of the declaration stack. * Also detect multiple qualifiers of the same kind. - * The rememberd qualifier is used by deftyp() to construct the type + * The remembered qualifier is used by deftyp() to construct the type * for all declarators. */ void -addqual(q) - tqual_t q; +addqual(tqual_t q) { + if (q == CONST) { if (dcs->d_const) { /* duplicate "%s" */ @@ -550,8 +483,7 @@ addqual(q) * argument declaration lists ...) */ void -pushdecl(sc) - scl_t sc; +pushdecl(scl_t sc) { dinfo_t *di; @@ -571,7 +503,7 @@ pushdecl(sc) * Go back to previous declaration level */ void -popdecl() +popdecl(void) { dinfo_t *di; @@ -656,7 +588,7 @@ popdecl() * global declarations/definitions. */ void -setasm() +setasm(void) { dinfo_t *di; @@ -669,8 +601,9 @@ setasm() * will be used by the next declaration */ void -clrtyp() +clrtyp(void) { + dcs->d_atyp = dcs->d_smod = dcs->d_lmod = NOTSPEC; dcs->d_scl = NOSCL; dcs->d_type = NULL; @@ -688,7 +621,7 @@ clrtyp() * context. */ void -deftyp() +deftyp(void) { tspec_t t, s, l; type_t *tp; @@ -804,9 +737,9 @@ deftyp() * Merge type specifiers (char, ..., long long, signed, unsigned). */ static tspec_t -mrgtspec(t, s) - tspec_t t, s; +mrgtspec(tspec_t t, tspec_t s) { + if (s == SIGNED || s == UNSIGN) { if (t == CHAR) { t = s == SIGNED ? SCHAR : UCHAR; @@ -832,17 +765,18 @@ mrgtspec(t, s) * if name is not NULL. */ int -length(tp, name) - type_t *tp; - const char *name; +length(type_t *tp, const char *name) { int elem, elsz; elem = 1; - while (tp->t_tspec == ARRAY) { + while (tp && tp->t_tspec == ARRAY) { elem *= tp->t_dim; tp = tp->t_subt; } + if (tp == NULL) + return -1; + switch (tp->t_tspec) { case FUNC: /* compiler takes size of function */ @@ -875,15 +809,17 @@ length(tp, name) * Get the alignment of the given Type in bits. */ int -getbound(tp) - type_t *tp; +getbound(type_t *tp) { int a; tspec_t t; - while (tp->t_tspec == ARRAY) + while (tp && tp->t_tspec == ARRAY) tp = tp->t_subt; + if (tp == NULL) + return -1; + if ((t = tp->t_tspec) == STRUCT || t == UNION) { a = tp->t_str->align; } else if (t == FUNC) { @@ -907,8 +843,7 @@ getbound(tp) * struct/union/enum elements and parameters. */ sym_t * -lnklst(l1, l2) - sym_t *l1, *l2; +lnklst(sym_t *l1, sym_t *l2) { sym_t *l; @@ -930,8 +865,7 @@ lnklst(l1, l2) * - void types other than type of function or pointer */ void -chktyp(sym) - sym_t *sym; +chktyp(sym_t *sym) { tspec_t to, t; type_t **tpp, *tp; @@ -1023,12 +957,12 @@ chktyp(sym) * Process the declarator of a struct/union element. */ sym_t * -decl1str(dsym) - sym_t *dsym; +decl1str(sym_t *dsym) { type_t *tp; tspec_t t; - int sz, o, len; + int sz, len; + int o = 0; /* Appease gcc */ scl_t sc; if ((sc = dsym->s_scl) != MOS && sc != MOU) @@ -1058,25 +992,38 @@ decl1str(dsym) */ if (t == CHAR || t == UCHAR || t == SCHAR || t == SHORT || t == USHORT || t == ENUM) { - if (sflag) { - /* bit-field type '%s' invalid in ANSI C */ - warning(273, tyname(tp)); - } else if (pflag) { - /* nonportable bit-field type */ - warning(34); + if (bitfieldtype_ok == 0) { + if (sflag) { + /* + * bit-field type '%s' invalid in + * ANSI C + */ + warning(273, tyname(tp)); + } else if (pflag) { + /* nonportable bit-field type */ + warning(34); + } } } else if (t == INT && dcs->d_smod == NOTSPEC) { - if (pflag) { + if (pflag && bitfieldtype_ok == 0) { /* nonportable bit-field type */ warning(34); } } else if (t != INT && t != UINT) { - /* illegal bit-field type */ - error(35); - sz = tp->t_flen; - dsym->s_type = tp = duptyp(gettyp(t = INT)); - if ((tp->t_flen = sz) > size(t)) - tp->t_flen = size(t); + /* + * Non-integer types are always illegal for + * bitfields, regardless of BITFIELDTYPE. + * Integer types not dealt with above are + * okay only if BITFIELDTYPE is in effect. + */ + if (bitfieldtype_ok == 0 || isityp(t) == 0) { + /* illegal bit-field type */ + error(35); + sz = tp->t_flen; + dsym->s_type = tp = duptyp(gettyp(t = INT)); + if ((tp->t_flen = sz) > size(t)) + tp->t_flen = size(t); + } } if ((len = tp->t_flen) < 0 || len > size(t)) { /* illegal bit-field size */ @@ -1132,6 +1079,12 @@ decl1str(dsym) chkfdef(dsym, 0); + /* + * Clear the BITFIELDTYPE indicator after processing each + * structure element. + */ + bitfieldtype_ok = 0; + return (dsym); } @@ -1141,8 +1094,7 @@ decl1str(dsym) * al contains the required alignment, len the length of a bit-field. */ static void -align(al, len) - int al, len; +align(int al, int len) { int no; @@ -1153,7 +1105,7 @@ align(al, len) */ if (al > dcs->d_stralign) dcs->d_stralign = al; - + no = (dcs->d_offset + (al - 1)) & ~(al - 1); if (len == 0 || dcs->d_offset + len > no) dcs->d_offset = no; @@ -1163,16 +1115,15 @@ align(al, len) * Remember the width of the field in its type structure. */ sym_t * -bitfield(dsym, len) - sym_t *dsym; - int len; +bitfield(sym_t *dsym, int len) { + if (dsym == NULL) { dsym = getblk(sizeof (sym_t)); dsym->s_name = unnamed; dsym->s_kind = FMOS; dsym->s_scl = MOS; - dsym->s_type = gettyp(INT); + dsym->s_type = gettyp(UINT); dsym->s_blklev = -1; } dsym->s_type = duptyp(dsym->s_type); @@ -1189,14 +1140,14 @@ bitfield(dsym, len) * will be at the top of the list. */ pqinf_t * -mergepq(p1, p2) - pqinf_t *p1, *p2; +mergepq(pqinf_t *p1, pqinf_t *p2) { pqinf_t *p; if (p2->p_pcnt != 0) { /* left '*' at the end of the list */ - for (p = p2; p->p_nxt != NULL; p = p->p_nxt) ; + for (p = p2; p->p_nxt != NULL; p = p->p_nxt) + continue; p->p_nxt = p1; return (p2); } else { @@ -1228,16 +1179,16 @@ mergepq(p1, p2) * declarator. The new type extension is inserted between both. */ sym_t * -addptr(decl, pi) - sym_t *decl; - pqinf_t *pi; +addptr(sym_t *decl, pqinf_t *pi) { type_t **tpp, *tp; pqinf_t *npi; tpp = &decl->s_type; - while (*tpp != dcs->d_type) + while (*tpp && *tpp != dcs->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; while (pi != NULL) { *tpp = tp = getblk(sizeof (type_t)); @@ -1257,15 +1208,15 @@ addptr(decl, pi) * n is the specified dimension */ sym_t * -addarray(decl, dim, n) - sym_t *decl; - int dim, n; +addarray(sym_t *decl, int dim, int n) { type_t **tpp, *tp; tpp = &decl->s_type; - while (*tpp != dcs->d_type) + while (*tpp && *tpp != dcs->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; *tpp = tp = getblk(sizeof (type_t)); tp->t_tspec = ARRAY; @@ -1288,8 +1239,7 @@ addarray(decl, dim, n) } sym_t * -addfunc(decl, args) - sym_t *decl, *args; +addfunc(sym_t *decl, sym_t *args) { type_t **tpp, *tp; @@ -1319,8 +1269,10 @@ addfunc(decl, args) } tpp = &decl->s_type; - while (*tpp != dcs->d_nxt->d_type) + while (*tpp && *tpp != dcs->d_nxt->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; *tpp = tp = getblk(sizeof (type_t)); tp->t_tspec = FUNC; @@ -1337,8 +1289,7 @@ addfunc(decl, args) */ /* ARGSUSED */ static sym_t * -nsfunc(decl, args) - sym_t *decl, *args; +nsfunc(sym_t *decl, sym_t *args) { sym_t *arg, *sym; scl_t sc; @@ -1376,9 +1327,9 @@ nsfunc(decl, args) * Called for old style function declarations. */ static void -osfunc(decl, args) - sym_t *decl, *args; +osfunc(sym_t *decl, sym_t *args) { + /* * Remember list of params only if this is really seams to be * a function definition. @@ -1387,7 +1338,7 @@ osfunc(decl, args) decl->s_type == dcs->d_nxt->d_type) { /* * We assume that this becomes a function definition. If - * we are wrong, its corrected in chkfdef(). + * we are wrong, its corrected in chkfdef(). */ if (args != NULL) { decl->s_osdef = 1; @@ -1406,10 +1357,9 @@ osfunc(decl, args) * error message. */ void -chkfdef(sym, msg) - sym_t *sym; - int msg; +chkfdef(sym_t *sym, int msg) { + if (sym->s_osdef) { if (msg) { /* incomplete or misplaced function definition */ @@ -1428,10 +1378,9 @@ chkfdef(sym, msg) * s_def and s_reg are valid after dname(). */ sym_t * -dname(sym) - sym_t *sym; +dname(sym_t *sym) { - scl_t sc; + scl_t sc = NOSCL; if (sym->s_scl == NOSCL) { dcs->d_rdcsym = NULL; @@ -1494,7 +1443,7 @@ dname(sym) * XXX somewhat ugly because we dont know whether * this is AUTO or EXTERN (functions). If we are * wrong it must be corrected in decl1loc(), where - * we have the neccessary type information. + * we have the necessary type information. */ sc = AUTO; sym->s_def = DEF; @@ -1527,9 +1476,9 @@ dname(sym) * definition. */ sym_t * -iname(sym) - sym_t *sym; +iname(sym_t *sym) { + if (sym->s_scl != NOSCL) { if (blklev == sym->s_blklev) { /* redeclaration of formal parameter %s */ @@ -1556,12 +1505,9 @@ iname(sym) * semi is 1 if the following token is T_SEMI */ type_t * -mktag(tag, kind, decl, semi) - sym_t *tag; - tspec_t kind; - int decl, semi; +mktag(sym_t *tag, tspec_t kind, int decl, int semi) { - scl_t scl; + scl_t scl = NOSCL; type_t *tp; if (kind == STRUCT) { @@ -1595,7 +1541,7 @@ mktag(tag, kind, decl, semi) } else { tag = getblk(sizeof (sym_t)); tag->s_name = unnamed; - STRUCT_ASSIGN(tag->s_dpos, curr_pos); + UNIQUE_CURR_POS(tag->s_dpos); tag->s_kind = FTAG; tag->s_scl = scl; tag->s_blklev = -1; @@ -1627,11 +1573,9 @@ mktag(tag, kind, decl, semi) * semi is 1 if T_SEMI follows */ static sym_t * -newtag(tag, scl, decl, semi) - sym_t *tag; - scl_t scl; - int decl, semi; +newtag(sym_t *tag, scl_t scl, int decl, int semi) { + if (tag->s_blklev < blklev) { if (semi) { /* "struct a;" */ @@ -1646,7 +1590,7 @@ newtag(tag, scl, decl, semi) } dcs->d_nxt->d_nedecl = 1; } else if (decl) { - /* "struct a { ..." */ + /* "struct a { ... } " */ if (hflag) /* redefinition hides earlier one: %s */ warning(43, tag->s_name); @@ -1682,8 +1626,7 @@ newtag(tag, scl, decl, semi) } const char * -scltoa(sc) - scl_t sc; +scltoa(scl_t sc) { const char *s; @@ -1706,9 +1649,7 @@ scltoa(sc) * tp points to the type of the, tag, fmem to the list of members/enums. */ type_t * -compltag(tp, fmem) - type_t *tp; - sym_t *fmem; +compltag(type_t *tp, sym_t *fmem) { tspec_t t; str_t *sp; @@ -1750,13 +1691,12 @@ compltag(tp, fmem) * * sym points to the enumerator * val is the value of the enumerator - * impl is 1 if the the value of the enumerator was not explicit specified. + * impl is 1 if the value of the enumerator was not explicit specified. */ sym_t * -ename(sym, val, impl) - sym_t *sym; - int val, impl; +ename(sym_t *sym, int val, int impl) { + if (sym->s_scl) { if (sym->s_blklev == blklev) { /* no hflag, because this is illegal!!! */ @@ -1797,9 +1737,7 @@ ename(sym, val, impl) * Process a single external declarator. */ void -decl1ext(dsym, initflg) - sym_t *dsym; - int initflg; +decl1ext(sym_t *dsym, int initflg) { int warn, rval, redec; sym_t *rdsym; @@ -1855,7 +1793,7 @@ decl1ext(dsym, initflg) } if (!redec && !isredec(dsym, (warn = 0, &warn))) { - + if (warn) { /* redeclaration of %s */ (*(sflag ? error : warning))(27, dsym->s_name); @@ -1901,7 +1839,7 @@ decl1ext(dsym, initflg) compltyp(dsym, rdsym); } - + rmsym(rdsym); } @@ -1918,9 +1856,9 @@ decl1ext(dsym, initflg) * the same symbol. */ void -cpuinfo(sym, rdsym) - sym_t *sym, *rdsym; +cpuinfo(sym_t *sym, sym_t *rdsym) { + sym->s_spos = rdsym->s_spos; sym->s_upos = rdsym->s_upos; sym->s_set = rdsym->s_set; @@ -1933,9 +1871,7 @@ cpuinfo(sym, rdsym) * a warning. */ int -isredec(dsym, warn) - sym_t *dsym; - int *warn; +isredec(sym_t *dsym, int *warn) { sym_t *rsym; @@ -2014,9 +1950,7 @@ isredec(dsym, warn) * compatible with a prototype */ int -eqtype(tp1, tp2, ignqual, promot, warn) - type_t *tp1, *tp2; - int ignqual, promot, *warn; +eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn) { tspec_t t; @@ -2082,9 +2016,7 @@ eqtype(tp1, tp2, ignqual, promot, warn) * Compares the parameter types of two prototypes. */ static int -eqargs(tp1, tp2, warn) - type_t *tp1, *tp2; - int *warn; +eqargs(type_t *tp1, type_t *tp2, int *warn) { sym_t *a1, *a2; @@ -2118,9 +2050,7 @@ eqargs(tp1, tp2, warn) * is applied on it */ static int -mnoarg(tp, warn) - type_t *tp; - int *warn; +mnoarg(type_t *tp, int *warn) { sym_t *arg; tspec_t t; @@ -2145,8 +2075,7 @@ mnoarg(tp, warn) * a previous old style function definition. */ static int -chkosdef(rdsym, dsym) - sym_t *rdsym, *dsym; +chkosdef(sym_t *rdsym, sym_t *dsym) { sym_t *args, *pargs, *arg, *parg; int narg, nparg, n; @@ -2207,8 +2136,7 @@ chkosdef(rdsym, dsym) * be duplicated. */ void -compltyp(dsym, ssym) - sym_t *dsym, *ssym; +compltyp(sym_t *dsym, sym_t *ssym) { type_t **dstp, *src; type_t *dst; @@ -2242,9 +2170,7 @@ compltyp(dsym, ssym) * Completes the declaration of a single argument. */ sym_t * -decl1arg(sym, initflg) - sym_t *sym; - int initflg; +decl1arg(sym_t *sym, int initflg) { tspec_t t; @@ -2308,7 +2234,7 @@ decl1arg(sym, initflg) * prototype. */ void -cluparg() +cluparg(void) { sym_t *args, *arg, *pargs, *parg; int narg, nparg, n, msg; @@ -2422,7 +2348,7 @@ cluparg() /* from now the prototype is valid */ funcsym->s_osdef = 0; funcsym->s_args = NULL; - + } } @@ -2433,8 +2359,7 @@ cluparg() * Returns 1 if the position of the previous declaration should be reported. */ static int -chkptdecl(arg, parg) - sym_t *arg, *parg; +chkptdecl(sym_t *arg, sym_t *parg) { type_t *tp, *ptp; int warn, msg; @@ -2467,10 +2392,9 @@ chkptdecl(arg, parg) * Completes a single local declaration/definition. */ void -decl1loc(dsym, initflg) - sym_t *dsym; - int initflg; +decl1loc(sym_t *dsym, int initflg) { + /* Correct a mistake done in dname(). */ if (dsym->s_type->t_tspec == FUNC) { dsym->s_def = DECL; @@ -2575,7 +2499,7 @@ decl1loc(dsym, initflg) if (hflag) /* declaration hides earlier one: %s */ warning(95, dsym->s_name); - + } if (dcs->d_rdcsym->s_blklev == blklev) { @@ -2609,8 +2533,7 @@ decl1loc(dsym, initflg) * Processes (re)declarations of external Symbols inside blocks. */ static void -ledecl(dsym) - sym_t *dsym; +ledecl(sym_t *dsym) { int eqt, warn; sym_t *esym; @@ -2665,8 +2588,7 @@ ledecl(dsym) * detected. */ static int -chkinit(sym) - sym_t *sym; +chkinit(sym_t *sym) { int err; @@ -2697,7 +2619,7 @@ chkinit(sym) * Create a symbole for an abstract declaration. */ sym_t * -aname() +aname(void) { sym_t *sym; @@ -2725,8 +2647,9 @@ aname() * Removes anything which has nothing to do on global level. */ void -globclup() +globclup(void) { + while (dcs->d_nxt != NULL) popdecl(); @@ -2745,9 +2668,9 @@ globclup() * Process an abstract type declaration */ sym_t * -decl1abs(sym) - sym_t *sym; +decl1abs(sym_t *sym) { + chkfdef(sym, 1); chktyp(sym); return (sym); @@ -2757,9 +2680,9 @@ decl1abs(sym) * Checks size after declarations of variables and their initialisation. */ void -chksz(dsym) - sym_t *dsym; +chksz(sym_t *dsym) { + /* * check size only for symbols which are defined and no function and * not typedef name @@ -2786,12 +2709,12 @@ chksz(dsym) * Mark an object as set if it is not already */ void -setsflg(sym) - sym_t *sym; +setsflg(sym_t *sym) { + if (!sym->s_set) { sym->s_set = 1; - STRUCT_ASSIGN(sym->s_spos, curr_pos); + UNIQUE_CURR_POS(sym->s_spos); } } @@ -2799,13 +2722,12 @@ setsflg(sym) * Mark an object as used if it is not already */ void -setuflg(sym, fcall, szof) - sym_t *sym; - int fcall, szof; +setuflg(sym_t *sym, int fcall, int szof) { + if (!sym->s_used) { sym->s_used = 1; - STRUCT_ASSIGN(sym->s_upos, curr_pos); + UNIQUE_CURR_POS(sym->s_upos); } /* * for function calls another record is written @@ -2823,8 +2745,7 @@ setuflg(sym, fcall, szof) * with s_dlnxt) if these are not used or only set. */ void -chkusage(di) - dinfo_t *di; +chkusage(dinfo_t *di) { sym_t *sym; int mknowarn; @@ -2844,9 +2765,7 @@ chkusage(di) * only set. */ void -chkusg1(novar, sym) - int novar; - sym_t *sym; +chkusg1(int novar, sym_t *sym) { pos_t cpos; @@ -2871,10 +2790,9 @@ chkusg1(novar, sym) } static void -chkausg(novar, arg) - int novar; - sym_t *arg; +chkausg(int novar, sym_t *arg) { + if (!arg->s_set) lerror("chkausg() 1"); @@ -2889,9 +2807,7 @@ chkausg(novar, arg) } static void -chkvusg(novar, sym) - int novar; - sym_t *sym; +chkvusg(int novar, sym_t *sym) { scl_t sc; sym_t *xsym; @@ -2958,9 +2874,9 @@ chkvusg(novar, sym) } static void -chklusg(lab) - sym_t *lab; +chklusg(sym_t *lab) { + if (blklev != 1 || lab->s_blklev != 1) lerror("chklusg() 1"); @@ -2976,9 +2892,9 @@ chklusg(lab) } static void -chktusg(sym) - sym_t *sym; +chktusg(sym_t *sym) { + if (!incompl(sym->s_type)) return; @@ -3014,7 +2930,7 @@ chktusg(sym) * - static symbols which are never used */ void -chkglsyms() +chkglsyms(void) { sym_t *sym; pos_t cpos; @@ -3041,12 +2957,12 @@ chkglsyms() } static void -chkglvar(sym) - sym_t *sym; +chkglvar(sym_t *sym) { + if (sym->s_scl == TYPEDEF || sym->s_scl == ENUMCON) return; - + if (sym->s_scl != EXTERN && sym->s_scl != STATIC) lerror("chkglvar() 1"); @@ -3088,13 +3004,13 @@ chkglvar(sym) } static void -glchksz(sym) - sym_t *sym; +glchksz(sym_t *sym) { + if (sym->s_def == TDEF) { if (sym->s_type->t_tspec == FUNC) /* - * this can happen if an syntax error occured + * this can happen if an syntax error occurred * after a function declaration */ return; @@ -3115,9 +3031,7 @@ glchksz(sym) * Prints information about location of previous definition/declaration. */ void -prevdecl(msg, psym) - int msg; - sym_t *psym; +prevdecl(int msg, sym_t *psym) { pos_t cpos; |