This commit is contained in:
dholland 2008-11-16 07:06:37 +00:00
parent 855e61a2e0
commit 3c6470e287
6 changed files with 77 additions and 76 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.38 2008/04/25 22:18:34 christos Exp $
# $NetBSD: Makefile,v 1.39 2008/11/16 07:06:37 dholland Exp $
.include <bsd.own.mk>
@ -6,6 +6,7 @@ PROG= lint1
SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
init.c emit.c emit1.c inittyp.c tyname.c print.c
MAN= lint.7
WARNS= 4
YHEADER=
CFLAGS+=-g

View File

@ -1,5 +1,5 @@
%{
/* $NetBSD: cgram.y,v 1.41 2008/04/25 22:18:34 christos Exp $ */
/* $NetBSD: cgram.y,v 1.42 2008/11/16 07:06:37 dholland Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: cgram.y,v 1.41 2008/04/25 22:18:34 christos Exp $");
__RCSID("$NetBSD: cgram.y,v 1.42 2008/11/16 07:06:37 dholland Exp $");
#endif
#include <stdlib.h>
@ -1759,7 +1759,7 @@ identifier:
/* ARGSUSED */
int
yyerror(char *msg)
yyerror(const char *msg)
{
error(249, yytext);
if (++sytxerr >= 5)
@ -1836,7 +1836,7 @@ toicon(tnode_t *tn, int required)
}
static void
idecl(sym_t *decl, int initflg, sbuf_t *rename)
idecl(sym_t *decl, int initflg, sbuf_t *renaming)
{
char *s;
@ -1845,31 +1845,31 @@ idecl(sym_t *decl, int initflg, sbuf_t *rename)
switch (dcs->d_ctx) {
case EXTERN:
if (rename != NULL) {
if (renaming != NULL) {
if (decl->s_rename != NULL)
LERROR("idecl()");
s = getlblk(1, rename->sb_len + 1);
(void)memcpy(s, rename->sb_name, rename->sb_len + 1);
s = getlblk(1, renaming->sb_len + 1);
(void)memcpy(s, renaming->sb_name, renaming->sb_len + 1);
decl->s_rename = s;
freeyyv(&rename, T_NAME);
freeyyv(&renaming, T_NAME);
}
decl1ext(decl, initflg);
break;
case ARG:
if (rename != NULL) {
if (renaming != NULL) {
/* symbol renaming can't be used on function arguments */
error(310);
freeyyv(&rename, T_NAME);
freeyyv(&renaming, T_NAME);
break;
}
(void)decl1arg(decl, initflg);
break;
case AUTO:
if (rename != NULL) {
if (renaming != NULL) {
/* symbol renaming can't be used on automatic variables */
error(311);
freeyyv(&rename, T_NAME);
freeyyv(&renaming, T_NAME);
break;
}
decl1loc(decl, initflg);

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.43 2008/09/27 20:04:24 dholland Exp $ */
/* $NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: decl.c,v 1.43 2008/09/27 20:04:24 dholland Exp $");
__RCSID("$NetBSD: decl.c,v 1.44 2008/11/16 07:06:37 dholland Exp $");
#endif
#include <sys/param.h>
@ -1793,7 +1793,7 @@ ename(sym_t *sym, int val, int impl)
void
decl1ext(sym_t *dsym, int initflg)
{
int warn, rval, redec;
int dowarn, rval, redec;
sym_t *rdsym;
chkfdef(dsym, 1);
@ -1846,9 +1846,9 @@ decl1ext(sym_t *dsym, int initflg)
redec = 0;
}
if (!redec && !isredec(dsym, (warn = 0, &warn))) {
if (!redec && !isredec(dsym, (dowarn = 0, &dowarn))) {
if (warn) {
if (dowarn) {
/* redeclaration of %s */
(*(sflag ? error : warning))(27, dsym->s_name);
prevdecl(-1, rdsym);
@ -1925,7 +1925,7 @@ cpuinfo(sym_t *sym, sym_t *rdsym)
* a warning.
*/
int
isredec(sym_t *dsym, int *warn)
isredec(sym_t *dsym, int *dowarn)
{
sym_t *rsym;
@ -1953,7 +1953,7 @@ isredec(sym_t *dsym, int *warn)
prevdecl(-1, rsym);
return(1);
}
if (!eqtype(rsym->s_type, dsym->s_type, 0, 0, warn)) {
if (!eqtype(rsym->s_type, dsym->s_type, 0, 0, dowarn)) {
/* redeclaration of %s */
error(27, dsym->s_name);
prevdecl(-1, rsym);
@ -2000,11 +2000,11 @@ isredec(sym_t *dsym, int *warn)
* ignqual ignore qualifiers of type; used for function params
* 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
* *dowarn set to 1 if an old style function declaration is not
* compatible with a prototype
*/
int
eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn)
eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *dowarn)
{
tspec_t t;
@ -2046,13 +2046,13 @@ eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn)
/* dont check prototypes for traditional */
if (t == FUNC && !tflag) {
if (tp1->t_proto && tp2->t_proto) {
if (!eqargs(tp1, tp2, warn))
if (!eqargs(tp1, tp2, dowarn))
return (0);
} else if (tp1->t_proto) {
if (!mnoarg(tp1, warn))
if (!mnoarg(tp1, dowarn))
return (0);
} else if (tp2->t_proto) {
if (!mnoarg(tp2, warn))
if (!mnoarg(tp2, dowarn))
return (0);
}
}
@ -2070,7 +2070,7 @@ eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn)
* Compares the parameter types of two prototypes.
*/
static int
eqargs(type_t *tp1, type_t *tp2, int *warn)
eqargs(type_t *tp1, type_t *tp2, int *dowarn)
{
sym_t *a1, *a2;
@ -2082,7 +2082,7 @@ eqargs(type_t *tp1, type_t *tp2, int *warn)
while (a1 != NULL && a2 != NULL) {
if (eqtype(a1->s_type, a2->s_type, 1, 0, warn) == 0)
if (eqtype(a1->s_type, a2->s_type, 1, 0, dowarn) == 0)
return (0);
a1 = a1->s_nxt;
@ -2104,21 +2104,21 @@ eqargs(type_t *tp1, type_t *tp2, int *warn)
* is applied on it
*/
static int
mnoarg(type_t *tp, int *warn)
mnoarg(type_t *tp, int *dowarn)
{
sym_t *arg;
tspec_t t;
if (tp->t_vararg) {
if (warn != NULL)
*warn = 1;
if (dowarn != NULL)
*dowarn = 1;
}
for (arg = tp->t_args; arg != NULL; arg = arg->s_nxt) {
if ((t = arg->s_type->t_tspec) == FLOAT ||
t == CHAR || t == SCHAR || t == UCHAR ||
t == SHORT || t == USHORT) {
if (warn != NULL)
*warn = 1;
if (dowarn != NULL)
*dowarn = 1;
}
}
return (1);
@ -2133,7 +2133,7 @@ chkosdef(sym_t *rdsym, sym_t *dsym)
{
sym_t *args, *pargs, *arg, *parg;
int narg, nparg, n;
int warn, msg;
int dowarn, msg;
args = rdsym->s_args;
pargs = dsym->s_type->t_args;
@ -2156,12 +2156,12 @@ chkosdef(sym_t *rdsym, sym_t *dsym)
parg = pargs;
n = 1;
while (narg--) {
warn = 0;
dowarn = 0;
/*
* If it does not match due to promotion and sflag is
* not set we print only a warning.
*/
if (!eqtype(arg->s_type, parg->s_type, 1, 1, &warn) || warn) {
if (!eqtype(arg->s_type, parg->s_type, 1, 1, &dowarn) || dowarn) {
/* prototype does not match old-style def., arg #%d */
error(299, n);
msg = 1;
@ -2416,16 +2416,16 @@ static int
chkptdecl(sym_t *arg, sym_t *parg)
{
type_t *tp, *ptp;
int warn, msg;
int dowarn, msg;
tp = arg->s_type;
ptp = parg->s_type;
msg = 0;
warn = 0;
dowarn = 0;
if (!eqtype(tp, ptp, 1, 1, &warn)) {
if (eqtype(tp, ptp, 1, 0, &warn)) {
if (!eqtype(tp, ptp, 1, 1, &dowarn)) {
if (eqtype(tp, ptp, 1, 0, &dowarn)) {
/* type does not match prototype: %s */
msg = gnuism(58, arg->s_name);
} else {
@ -2433,7 +2433,7 @@ chkptdecl(sym_t *arg, sym_t *parg)
error(58, arg->s_name);
msg = 1;
}
} else if (warn) {
} else if (dowarn) {
/* type does not match prototype: %s */
(*(sflag ? error : warning))(58, arg->s_name);
msg = 1;
@ -2589,7 +2589,7 @@ decl1loc(sym_t *dsym, int initflg)
static void
ledecl(sym_t *dsym)
{
int eqt, warn;
int eqt, dowarn;
sym_t *esym;
/* look for a symbol with the same name */
@ -2612,10 +2612,10 @@ ledecl(sym_t *dsym)
return;
}
warn = 0;
eqt = eqtype(esym->s_type, dsym->s_type, 0, 0, &warn);
dowarn = 0;
eqt = eqtype(esym->s_type, dsym->s_type, 0, 0, &dowarn);
if (!eqt || warn) {
if (!eqt || dowarn) {
if (esym->s_scl == EXTERN) {
/* inconsistent redeclaration of extern: %s */
warning(90, dsym->s_name);
@ -2644,29 +2644,29 @@ ledecl(sym_t *dsym)
static int
chkinit(sym_t *sym)
{
int err;
int erred;
err = 0;
erred = 0;
if (sym->s_type->t_tspec == FUNC) {
/* cannot initialize function: %s */
error(24, sym->s_name);
err = 1;
erred = 1;
} else if (sym->s_scl == TYPEDEF) {
/* cannot initialize typedef: %s */
error(25, sym->s_name);
err = 1;
erred = 1;
} else if (sym->s_scl == EXTERN && sym->s_def == DECL) {
/* cannot initialize "extern" declaration: %s */
if (dcs->d_ctx == EXTERN) {
warning(26, sym->s_name);
} else {
error(26, sym->s_name);
err = 1;
erred = 1;
}
}
return (err);
return (erred);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.23 2008/07/31 15:21:34 christos Exp $ */
/* $NetBSD: externs1.h,v 1.24 2008/11/16 07:06:37 dholland Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -62,7 +62,7 @@ extern int blklev;
extern int mblklev;
extern int yydebug;
extern int yyerror(char *);
extern int yyerror(const char *);
extern int yyparse(void);
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: func.c,v 1.23 2008/07/25 18:33:53 dsl Exp $ */
/* $NetBSD: func.c,v 1.24 2008/11/16 07:06:37 dholland Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: func.c,v 1.23 2008/07/25 18:33:53 dsl Exp $");
__RCSID("$NetBSD: func.c,v 1.24 2008/11/16 07:06:37 dholland Exp $");
#endif
#include <stdlib.h>
@ -210,7 +210,7 @@ chkreach(void)
void
funcdef(sym_t *fsym)
{
int n, warn;
int n, dowarn;
sym_t *arg, *sym, *rdsym;
funcsym = fsym;
@ -285,14 +285,14 @@ funcdef(sym_t *fsym)
if ((rdsym = dcs->d_rdcsym) != NULL) {
if (!isredec(fsym, (warn = 0, &warn))) {
if (!isredec(fsym, (dowarn = 0, &dowarn))) {
/*
* Print nothing if the newly defined function
* is defined in old style. A better warning will
* be printed in cluparg().
*/
if (warn && !fsym->s_osdef) {
if (dowarn && !fsym->s_osdef) {
/* redeclaration of %s */
(*(sflag ? error : warning))(27, fsym->s_name);
prevdecl(-1, rdsym);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tree.c,v 1.53 2008/09/27 02:30:46 matt Exp $ */
/* $NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: tree.c,v 1.53 2008/09/27 02:30:46 matt Exp $");
__RCSID("$NetBSD: tree.c,v 1.54 2008/11/16 07:06:37 dholland Exp $");
#endif
#include <stdlib.h>
@ -214,7 +214,7 @@ initmtab(void)
"INIT" } },
{ FARG, { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,
"FARG" } },
{ NOOP }
{ NOOP, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, NULL } }
};
int i;
@ -3292,14 +3292,14 @@ parg( int n, /* pos of arg */
tnode_t *tn) /* argument */
{
tnode_t *ln;
int warn;
int dowarn;
ln = xcalloc(1, sizeof (tnode_t));
ln->tn_type = tduptyp(tp);
ln->tn_type->t_const = 0;
ln->tn_lvalue = 1;
if (typeok(FARG, n, ln, tn)) {
if (!eqtype(tp, tn->tn_type, 1, 0, (warn = 0, &warn)) || warn)
if (!eqtype(tp, tn->tn_type, 1, 0, (dowarn = 0, &dowarn)) || dowarn)
tn = convert(FARG, n, tp, tn);
}
free(ln);
@ -3367,7 +3367,7 @@ constant(tnode_t *tn, int required)
* for the expression.
*/
void
expr(tnode_t *tn, int vctx, int tctx, int freeblk)
expr(tnode_t *tn, int vctx, int tctx, int dofreeblk)
{
if (tn == NULL && nerr == 0)
@ -3404,7 +3404,7 @@ expr(tnode_t *tn, int vctx, int tctx, int freeblk)
displexpr(tn, 0);
/* free the tree memory */
if (freeblk)
if (dofreeblk)
tfreeblk();
}
@ -3935,7 +3935,7 @@ precconf(tnode_t *tn)
op_t lop, rop = NOOP;
int lparn, rparn = 0;
mod_t *mp;
int warn;
int dowarn;
if (!hflag)
return;
@ -3956,22 +3956,22 @@ precconf(tnode_t *tn)
rop = rn->tn_op;
}
warn = 0;
dowarn = 0;
switch (tn->tn_op) {
case SHL:
case SHR:
if (!lparn && (lop == PLUS || lop == MINUS)) {
warn = 1;
dowarn = 1;
} else if (!rparn && (rop == PLUS || rop == MINUS)) {
warn = 1;
dowarn = 1;
}
break;
case LOGOR:
if (!lparn && lop == LOGAND) {
warn = 1;
dowarn = 1;
} else if (!rparn && rop == LOGAND) {
warn = 1;
dowarn = 1;
}
break;
case AND:
@ -3979,16 +3979,16 @@ precconf(tnode_t *tn)
case OR:
if (!lparn && lop != tn->tn_op) {
if (lop == PLUS || lop == MINUS) {
warn = 1;
dowarn = 1;
} else if (lop == AND || lop == XOR) {
warn = 1;
dowarn = 1;
}
}
if (!warn && !rparn && rop != tn->tn_op) {
if (!dowarn && !rparn && rop != tn->tn_op) {
if (rop == PLUS || rop == MINUS) {
warn = 1;
dowarn = 1;
} else if (rop == AND || rop == XOR) {
warn = 1;
dowarn = 1;
}
}
break;
@ -4052,7 +4052,7 @@ precconf(tnode_t *tn)
break;
}
if (warn) {
if (dowarn) {
/* precedence confusion possible: parenthesize! */
warning(169);
}