summaryrefslogtreecommitdiffstats
path: root/usr.bin/xlint/lint1/decl.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/xlint/lint1/decl.c')
-rw-r--r--usr.bin/xlint/lint1/decl.c521
1 files changed, 218 insertions, 303 deletions
diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c
index fa023b7..a77a561 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,8 +32,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $";
+#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
#include <sys/param.h>
@@ -44,9 +46,6 @@ static char rcsid[] = "$NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $";
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;
@@ -59,107 +58,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 */
dcs = xcalloc(1, sizeof (dinfo_t));
@@ -167,13 +92,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 */
typetab = xcalloc(NTSPEC, sizeof (type_t));
for (i = 0; i < NTSPEC; i++)
@@ -208,15 +128,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;
@@ -230,8 +149,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;
@@ -245,8 +163,7 @@ tduptyp(tp)
* struct, union or enum type.
*/
int
-incompl(tp)
- type_t *tp;
+incompl(type_t *tp)
{
tspec_t t;
@@ -267,9 +184,7 @@ incompl(tp)
* types.
*/
void
-setcompl(tp, ic)
- type_t *tp;
- int ic;
+setcompl(type_t *tp, int ic)
{
tspec_t t;
@@ -290,9 +205,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' */
@@ -327,8 +242,7 @@ addscl(sc)
* struct/union/enum tag.
*/
void
-addtype(tp)
- type_t *tp;
+addtype(type_t *tp)
{
tspec_t t;
@@ -394,7 +308,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;
@@ -411,7 +325,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() */
@@ -425,9 +339,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;
@@ -479,6 +391,30 @@ tdeferr(td, t)
}
break;
/* LINTED (enumeration values not handled in switch) */
+ 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. */
@@ -492,14 +428,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;
@@ -517,13 +451,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" */
@@ -546,8 +480,7 @@ addqual(q)
* argument declaration lists ...)
*/
void
-pushdecl(sc)
- scl_t sc;
+pushdecl(scl_t sc)
{
dinfo_t *di;
@@ -566,7 +499,7 @@ pushdecl(sc)
* Go back to previous declaration level
*/
void
-popdecl()
+popdecl(void)
{
dinfo_t *di;
@@ -651,7 +584,7 @@ popdecl()
* global declarations/definitions.
*/
void
-setasm()
+setasm(void)
{
dinfo_t *di;
@@ -664,8 +597,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;
@@ -683,7 +617,7 @@ clrtyp()
* context.
*/
void
-deftyp()
+deftyp(void)
{
tspec_t t, s, l;
type_t *tp;
@@ -799,9 +733,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;
@@ -827,17 +761,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 */
@@ -870,15 +805,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) {
@@ -902,8 +839,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;
@@ -925,8 +861,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;
@@ -1018,12 +953,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)
@@ -1053,25 +988,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 */
@@ -1127,6 +1075,12 @@ decl1str(dsym)
chkfdef(dsym, 0);
+ /*
+ * Clear the BITFIELDTYPE indicator after processing each
+ * structure element.
+ */
+ bitfieldtype_ok = 0;
+
return (dsym);
}
@@ -1136,8 +1090,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;
@@ -1148,7 +1101,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;
@@ -1158,16 +1111,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);
@@ -1184,14 +1136,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 {
@@ -1223,16 +1175,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));
@@ -1252,15 +1204,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;
@@ -1283,8 +1235,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;
@@ -1314,8 +1265,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;
@@ -1332,8 +1285,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;
@@ -1371,9 +1323,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.
@@ -1382,7 +1334,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;
@@ -1401,10 +1353,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 */
@@ -1423,10 +1374,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;
@@ -1489,7 +1439,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;
@@ -1522,9 +1472,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 */
@@ -1551,12 +1501,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) {
@@ -1590,7 +1537,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;
@@ -1622,11 +1569,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;" */
@@ -1641,7 +1586,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);
@@ -1677,8 +1622,7 @@ newtag(tag, scl, decl, semi)
}
const char *
-scltoa(sc)
- scl_t sc;
+scltoa(scl_t sc)
{
const char *s;
@@ -1701,9 +1645,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;
@@ -1745,13 +1687,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!!! */
@@ -1792,9 +1733,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;
@@ -1850,7 +1789,7 @@ decl1ext(dsym, initflg)
}
if (!redec && !isredec(dsym, (warn = 0, &warn))) {
-
+
if (warn) {
/* redeclaration of %s */
(*(sflag ? error : warning))(27, dsym->s_name);
@@ -1896,7 +1835,7 @@ decl1ext(dsym, initflg)
compltyp(dsym, rdsym);
}
-
+
rmsym(rdsym);
}
@@ -1913,9 +1852,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;
@@ -1928,9 +1867,7 @@ cpuinfo(sym, rdsym)
* a warning.
*/
int
-isredec(dsym, warn)
- sym_t *dsym;
- int *warn;
+isredec(sym_t *dsym, int *warn)
{
sym_t *rsym;
@@ -2003,15 +1940,13 @@ isredec(dsym, warn)
* Checks if two types are compatible. Returns 0 if not, otherwise 1.
*
* ignqual ignore qualifiers of type; used for function params
- * promot promote left type; used for comparision of params of
+ * promot promote left type; used for comparison of params of
* old style function definitions with params of prototypes.
* *warn set to 1 if an old style function declaration is not
* 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;
@@ -2077,9 +2012,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;
@@ -2113,9 +2046,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;
@@ -2140,8 +2071,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;
@@ -2202,8 +2132,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;
@@ -2237,9 +2166,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;
@@ -2303,7 +2230,7 @@ decl1arg(sym, initflg)
* prototype.
*/
void
-cluparg()
+cluparg(void)
{
sym_t *args, *arg, *pargs, *parg;
int narg, nparg, n, msg;
@@ -2417,7 +2344,7 @@ cluparg()
/* from now the prototype is valid */
funcsym->s_osdef = 0;
funcsym->s_args = NULL;
-
+
}
}
@@ -2428,8 +2355,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;
@@ -2462,10 +2388,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;
@@ -2570,7 +2495,7 @@ decl1loc(dsym, initflg)
if (hflag)
/* declaration hides earlier one: %s */
warning(95, dsym->s_name);
-
+
}
if (dcs->d_rdcsym->s_blklev == blklev) {
@@ -2604,8 +2529,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;
@@ -2660,8 +2584,7 @@ ledecl(dsym)
* detected.
*/
static int
-chkinit(sym)
- sym_t *sym;
+chkinit(sym_t *sym)
{
int err;
@@ -2692,7 +2615,7 @@ chkinit(sym)
* Create a symbole for an abstract declaration.
*/
sym_t *
-aname()
+aname(void)
{
sym_t *sym;
@@ -2720,8 +2643,9 @@ aname()
* Removes anything which has nothing to do on global level.
*/
void
-globclup()
+globclup(void)
{
+
while (dcs->d_nxt != NULL)
popdecl();
@@ -2740,9 +2664,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);
@@ -2752,9 +2676,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
@@ -2781,12 +2705,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);
}
}
@@ -2794,13 +2718,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
@@ -2818,8 +2741,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;
@@ -2839,9 +2761,7 @@ chkusage(di)
* only set.
*/
void
-chkusg1(novar, sym)
- int novar;
- sym_t *sym;
+chkusg1(int novar, sym_t *sym)
{
pos_t cpos;
@@ -2866,10 +2786,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");
@@ -2884,9 +2803,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;
@@ -2953,9 +2870,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");
@@ -2971,9 +2888,9 @@ chklusg(lab)
}
static void
-chktusg(sym)
- sym_t *sym;
+chktusg(sym_t *sym)
{
+
if (!incompl(sym->s_type))
return;
@@ -3009,7 +2926,7 @@ chktusg(sym)
* - static symbols which are never used
*/
void
-chkglsyms()
+chkglsyms(void)
{
sym_t *sym;
pos_t cpos;
@@ -3036,12 +2953,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");
@@ -3083,13 +3000,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;
@@ -3110,9 +3027,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;
OpenPOWER on IntegriCloud