summaryrefslogtreecommitdiffstats
path: root/usr.bin/xlint/lint2
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2002-03-03 13:17:00 +0000
committermarkm <markm@FreeBSD.org>2002-03-03 13:17:00 +0000
commita9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53 (patch)
tree9ca989e7577c4407884daecc9836097ae6fccce0 /usr.bin/xlint/lint2
parent97ea65b2cb83e7b5b2c4afcacc3a185482457c2a (diff)
downloadFreeBSD-src-a9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53.zip
FreeBSD-src-a9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53.tar.gz
Import of NetBSD's (x)lint, snapshotted at 2002-3-3.
Diffstat (limited to 'usr.bin/xlint/lint2')
-rw-r--r--usr.bin/xlint/lint2/Makefile21
-rw-r--r--usr.bin/xlint/lint2/chk.c302
-rw-r--r--usr.bin/xlint/lint2/emit2.c103
-rw-r--r--usr.bin/xlint/lint2/externs2.h36
-rw-r--r--usr.bin/xlint/lint2/hash.c79
-rw-r--r--usr.bin/xlint/lint2/lint2.h25
-rw-r--r--usr.bin/xlint/lint2/main2.c26
-rw-r--r--usr.bin/xlint/lint2/mem2.c18
-rw-r--r--usr.bin/xlint/lint2/msg.c40
-rw-r--r--usr.bin/xlint/lint2/read.c278
10 files changed, 504 insertions, 424 deletions
diff --git a/usr.bin/xlint/lint2/Makefile b/usr.bin/xlint/lint2/Makefile
index 0e7d405..60f7886 100644
--- a/usr.bin/xlint/lint2/Makefile
+++ b/usr.bin/xlint/lint2/Makefile
@@ -1,13 +1,14 @@
-# $NetBSD: Makefile,v 1.2 1995/07/03 21:24:39 cgd Exp $
+# $NetBSD: Makefile,v 1.12 2002/01/18 20:39:32 thorpej Exp $
-.PATH: ${.CURDIR}/../lint1
-
-PROG= lint2
-SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c
-NOMAN=
-CFLAGS+=-I${.CURDIR}/../lint1
-LINTFLAGS=-abehrz
-
-BINDIR= /usr/libexec
+PROG= lint2
+SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c \
+ inittyp.c
+NOMAN= # defined
+LINTFLAGS= -abehrz
+WFORMAT=1 # hopeless
+BINDIR= /usr/libexec
+.ifndef HOSTPROG
.include <bsd.prog.mk>
+.endif
+
diff --git a/usr.bin/xlint/lint2/chk.c b/usr.bin/xlint/lint2/chk.c
index 0aac852..46923f9 100644
--- a/usr.bin/xlint/lint2/chk.c
+++ b/usr.bin/xlint/lint2/chk.c
@@ -1,6 +1,7 @@
-/* $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $ */
+/* $NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -31,138 +32,44 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $");
#endif
-#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
-#include <err.h>
+#include <stdlib.h>
#include "lint2.h"
-/* various type information */
-ttab_t ttab[NTSPEC];
-
-
-static void chkund __P((hte_t *));
-static void chkdnu __P((hte_t *));
-static void chkdnud __P((hte_t *));
-static void chkmd __P((hte_t *));
-static void chkvtui __P((hte_t *, sym_t *, sym_t *));
-static void chkvtdi __P((hte_t *, sym_t *, sym_t *));
-static void chkfaui __P((hte_t *, sym_t *, sym_t *));
-static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *,
- fcall_t *, fcall_t *, type_t *, type_t *));
-static void chkrvu __P((hte_t *, sym_t *));
-static void chkadecl __P((hte_t *, sym_t *, sym_t *));
-static void printflike __P((hte_t *,fcall_t *, int,
- const char *, type_t **));
-static void scanflike __P((hte_t *, fcall_t *, int,
- const char *, type_t **));
-static void badfmt __P((hte_t *, fcall_t *));
-static void inconarg __P((hte_t *, fcall_t *, int));
-static void tofewarg __P((hte_t *, fcall_t *));
-static void tomanyarg __P((hte_t *, fcall_t *));
-static int eqtype __P((type_t *, type_t *, int, int, int, int *));
-static int eqargs __P((type_t *, type_t *, int *));
-static int mnoarg __P((type_t *, int *));
-
-
-void
-inittyp()
-{
- 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" } },
- };
-
- 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;
- }
-}
+static void chkund(hte_t *);
+static void chkdnu(hte_t *);
+static void chkdnud(hte_t *);
+static void chkmd(hte_t *);
+static void chkvtui(hte_t *, sym_t *, sym_t *);
+static void chkvtdi(hte_t *, sym_t *, sym_t *);
+static void chkfaui(hte_t *, sym_t *, sym_t *);
+static void chkau(hte_t *, int, sym_t *, sym_t *, pos_t *,
+ fcall_t *, fcall_t *, type_t *, type_t *);
+static void chkrvu(hte_t *, sym_t *);
+static void chkadecl(hte_t *, sym_t *, sym_t *);
+static void printflike(hte_t *,fcall_t *, int, const char *, type_t **);
+static void scanflike(hte_t *, fcall_t *, int, const char *, type_t **);
+static void badfmt(hte_t *, fcall_t *);
+static void inconarg(hte_t *, fcall_t *, int);
+static void tofewarg(hte_t *, fcall_t *);
+static void tomanyarg(hte_t *, fcall_t *);
+static int eqtype(type_t *, type_t *, int, int, int, int *);
+static int eqargs(type_t *, type_t *, int *);
+static int mnoarg(type_t *, int *);
/*
* If there is a symbol named "main", mark it as used.
*/
void
-mainused()
+mainused(void)
{
hte_t *hte;
@@ -174,8 +81,7 @@ mainused()
* Performs all tests for a single name
*/
void
-chkname(hte)
- hte_t *hte;
+chkname(hte_t *hte)
{
sym_t *sym, *def, *pdecl, *decl;
@@ -220,8 +126,7 @@ chkname(hte)
* Print a warning if the name has been used, but not defined.
*/
static void
-chkund(hte)
- hte_t *hte;
+chkund(hte_t *hte)
{
fcall_t *fcall;
usym_t *usym;
@@ -242,8 +147,7 @@ chkund(hte)
* Print a warning if the name has been defined, but never used.
*/
static void
-chkdnu(hte)
- hte_t *hte;
+chkdnu(hte_t *hte)
{
sym_t *sym;
@@ -260,33 +164,33 @@ chkdnu(hte)
}
/*
- * Print a warning if the name has been declared, but is not used
+ * Print a warning if the variable has been declared, but is not used
* or defined.
*/
static void
-chkdnud(hte)
- hte_t *hte;
+chkdnud(hte_t *hte)
{
sym_t *sym;
if (hte->h_syms == NULL || hte->h_used || hte->h_def)
return;
-
- if ((sym = hte->h_syms) != NULL) {
- if (sym->s_def != DECL)
- errx(1, "internal error: chkdnud() 1");
- /* %s declared( %s ), but never used or defined */
- msg(2, hte->h_name, mkpos(&sym->s_pos));
- }
+
+ sym = hte->h_syms;
+ if (TP(sym->s_type)->t_tspec == FUNC)
+ return;
+
+ if (sym->s_def != DECL)
+ errx(1, "internal error: chkdnud() 1");
+ /* %s declared( %s ), but never used or defined */
+ msg(2, hte->h_name, mkpos(&sym->s_pos));
}
/*
- * Print a warning if there is more then one definition for
+ * Print a warning if there is more than one definition for
* this name.
*/
static void
-chkmd(hte)
- hte_t *hte;
+chkmd(hte_t *hte)
{
sym_t *sym, *def1;
char *pos1;
@@ -323,9 +227,7 @@ chkmd(hte)
* call as it's done for function arguments.
*/
static void
-chkvtui(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkvtui(hte_t *hte, sym_t *def, sym_t *decl)
{
fcall_t *call;
char *pos1;
@@ -386,9 +288,7 @@ chkvtui(hte, def, decl)
* types of return values are tested.
*/
static void
-chkvtdi(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkvtdi(hte_t *hte, sym_t *def, sym_t *decl)
{
sym_t *sym;
type_t *tp1, *tp2;
@@ -427,12 +327,10 @@ chkvtdi(hte, def, decl)
* of the same function.
*/
static void
-chkfaui(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkfaui(hte_t *hte, sym_t *def, sym_t *decl)
{
type_t *tp1, *tp2, **ap1, **ap2;
- pos_t *pos1p;
+ pos_t *pos1p = NULL;
fcall_t *calls, *call, *call1;
int n, as;
char *pos1;
@@ -442,7 +340,7 @@ chkfaui(hte, def, decl)
return;
/*
- * If we find a function definition, we use this for comparision,
+ * If we find a function definition, we use this for comparison,
* otherwise the first prototype we can find. If there is no
* definition or prototype declaration, the first function call
* is used.
@@ -537,13 +435,8 @@ chkfaui(hte, def, decl)
*
*/
static void
-chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
- hte_t *hte;
- int n;
- sym_t *def, *decl;
- pos_t *pos1p;
- fcall_t *call1, *call;
- type_t *arg1, *arg2;
+chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
+ fcall_t *call1, fcall_t *call, type_t *arg1, type_t *arg2)
{
/* LINTED (automatic hides external declaration: warn) */
int promote, asgn, warn;
@@ -577,7 +470,7 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
/*
* Other lint implementations print warnings as soon as the type
* of an argument does not match exactly the expected type. The
- * result are lots of warnings which are really not neccessary.
+ * result are lots of warnings which are really not necessary.
* We print a warning only if
* (0) at least one type is not an interger type and types differ
* (1) hflag is set and types differ
@@ -670,11 +563,16 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
}
}
- } else if (t1 == PTR && isityp(t2) && psize(t1) == psize(t2)) {
+ } else if (t1 == PTR && isityp(t2)) {
for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
if (ai->a_num == n)
break;
}
+ /*
+ * Vendor implementations of lint (e.g. HP-UX, Digital UNIX)
+ * don't care about the size of the integer argument,
+ * only whether or not it is zero. We do the same.
+ */
if (ai != NULL && ai->a_zero)
return;
}
@@ -690,17 +588,12 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
* string fmt.
*/
static void
-printflike(hte, call, n, fmt, ap)
- hte_t *hte;
- fcall_t *call;
- int n;
- const char *fmt;
- type_t **ap;
+printflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int fwidth, prec, left, sign, space, alt, zero;
- tspec_t sz, t1, t2;
+ tspec_t sz, t1, t2 = NOTSPEC;
type_t *tp;
fp = fmt;
@@ -920,18 +813,13 @@ printflike(hte, call, n, fmt, ap)
* string fmt.
*/
static void
-scanflike(hte, call, n, fmt, ap)
- hte_t *hte;
- fcall_t *call;
- int n;
- const char *fmt;
- type_t **ap;
+scanflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int noasgn, fwidth;
- tspec_t sz, t1, t2;
- type_t *tp;
+ tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC;
+ type_t *tp = NULL;
fp = fmt;
fc = *fp++;
@@ -955,7 +843,7 @@ scanflike(hte, call, n, fmt, ap)
noasgn = 1;
fc = *fp++;
}
-
+
if (isdigit(fc)) {
fwidth = 1;
do { fc = *fp++; } while (isdigit(fc));
@@ -1116,38 +1004,33 @@ scanflike(hte, call, n, fmt, ap)
}
static void
-badfmt(hte, call)
- hte_t *hte;
- fcall_t *call;
+badfmt(hte_t *hte, fcall_t *call)
{
+
/* %s: malformed format string\t%s */
msg(13, hte->h_name, mkpos(&call->f_pos));
}
static void
-inconarg(hte, call, n)
- hte_t *hte;
- fcall_t *call;
- int n;
+inconarg(hte_t *hte, fcall_t *call, int n)
{
+
/* %s, arg %d inconsistent with format\t%s(%d) */
msg(14, hte->h_name, n, mkpos(&call->f_pos));
}
static void
-tofewarg(hte, call)
- hte_t *hte;
- fcall_t *call;
+tofewarg(hte_t *hte, fcall_t *call)
{
+
/* %s: too few args for format \t%s */
msg(15, hte->h_name, mkpos(&call->f_pos));
}
static void
-tomanyarg(hte, call)
- hte_t *hte;
- fcall_t *call;
+tomanyarg(hte_t *hte, fcall_t *call)
{
+
/* %s: too many args for format \t%s */
msg(16, hte->h_name, mkpos(&call->f_pos));
}
@@ -1158,9 +1041,7 @@ tomanyarg(hte, call)
* or return values which are always or sometimes ignored.
*/
static void
-chkrvu(hte, def)
- hte_t *hte;
- sym_t *def;
+chkrvu(hte_t *hte, sym_t *def)
{
fcall_t *call;
int used, ignored;
@@ -1176,7 +1057,7 @@ chkrvu(hte, def)
/* function has return value */
used = ignored = 0;
for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
- used |= call->f_rused;
+ used |= call->f_rused || call->f_rdisc;
ignored |= !call->f_rused && !call->f_rdisc;
}
/*
@@ -1208,9 +1089,7 @@ chkrvu(hte, def)
* Print warnings for inconsistent argument declarations.
*/
static void
-chkadecl(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkadecl(hte_t *hte, sym_t *def, sym_t *decl)
{
/* LINTED (automatic hides external declaration: warn) */
int osdef, eq, warn, n;
@@ -1280,8 +1159,8 @@ chkadecl(hte, def, decl)
*
* ignqual if set, ignore qualifiers of outhermost type; used for
* function arguments
- * promote if set, promote left type before comparision; used for
- * comparisions of arguments with parameters of old style
+ * promote if set, promote left type before comparison; used for
+ * comparisons of arguments with parameters of old style
* definitions
* asgn left indirected type must have at least the same qualifiers
* like right indirected type (for assignments and function
@@ -1290,9 +1169,7 @@ chkadecl(hte, def, decl)
* an incompatible prototype declaration
*/
static int
-eqtype(tp1, tp2, ignqual, promot, asgn, warn)
- type_t *tp1, *tp2;
- int ignqual, promot, asgn, *warn;
+eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *warn)
{
tspec_t t, to;
int indir;
@@ -1322,7 +1199,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
return (1);
}
-
+
if (t != tp2->t_tspec) {
/*
* Give pointer to types which differ only in
@@ -1339,6 +1216,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
+ } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
+ return (tp1->t_uniqpos.p_line ==
+ tp2->t_uniqpos.p_line &&
+ tp1->t_uniqpos.p_file ==
+ tp2->t_uniqpos.p_file &&
+ tp1->t_uniqpos.p_uniq ==
+ tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@@ -1366,6 +1250,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
+ } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
+ return (tp1->t_uniqpos.p_line ==
+ tp2->t_uniqpos.p_line &&
+ tp1->t_uniqpos.p_file ==
+ tp2->t_uniqpos.p_file &&
+ tp1->t_uniqpos.p_uniq ==
+ tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@@ -1404,9 +1295,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
* Compares arguments of two prototypes
*/
static int
-eqargs(tp1, tp2, warn)
- type_t *tp1, *tp2;
- int *warn;
+eqargs(type_t *tp1, type_t *tp2, int *warn)
{
type_t **a1, **a2;
@@ -1440,9 +1329,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)
{
type_t **arg;
tspec_t t;
@@ -1459,4 +1346,3 @@ mnoarg(tp, warn)
}
return (1);
}
-
diff --git a/usr.bin/xlint/lint2/emit2.c b/usr.bin/xlint/lint2/emit2.c
index 82527b5..1b4510f 100644
--- a/usr.bin/xlint/lint2/emit2.c
+++ b/usr.bin/xlint/lint2/emit2.c
@@ -1,6 +1,7 @@
-/* $NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $ */
+/* $NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -31,24 +32,23 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: emit2.c,v 1.8 2002/01/21 19:49:52 tv Exp $");
#endif
-#include <err.h>
-
#include "lint2.h"
-static void outtype __P((type_t *));
-static void outdef __P((hte_t *, sym_t *));
-static void dumpname __P((hte_t *));
+static void outtype(type_t *);
+static void outdef(hte_t *, sym_t *);
+static void dumpname(hte_t *);
+static void outfiles(void);
/*
* Write type into the output buffer.
*/
static void
-outtype(tp)
- type_t *tp;
+outtype(type_t *tp)
{
int t, s, na;
tspec_t ts;
@@ -105,9 +105,15 @@ outtype(tp)
} else if (tp->t_istynam) {
outint(2);
outname(tp->t_tynam->h_name);
- } else {
- outint(0);
- }
+ } else if (tp->t_isuniqpos) {
+ outint(3);
+ outint(tp->t_uniqpos.p_line);
+ outchar('.');
+ outint(tp->t_uniqpos.p_file);
+ outchar('.');
+ outint(tp->t_uniqpos.p_uniq);
+ } else
+ errx(1, "internal error: outtype() 2");
} else if (ts == FUNC && tp->t_args != NULL) {
na = 0;
for (ap = tp->t_args; *ap != NULL; ap++)
@@ -128,10 +134,9 @@ outtype(tp)
* Write a definition.
*/
static void
-outdef(hte, sym)
- hte_t *hte;
- sym_t *sym;
+outdef(hte_t *hte, sym_t *sym)
{
+
/* reset output buffer */
outclr();
@@ -180,8 +185,7 @@ outdef(hte, sym)
* Write the first definition of a name into the lint library.
*/
static void
-dumpname(hte)
- hte_t *hte;
+dumpname(hte_t *hte)
{
sym_t *sym, *def;
@@ -191,7 +195,7 @@ dumpname(hte)
/*
* If there is a definition, write it. Otherwise write a tentative
- * definition. This is neccessary because more than one tentative
+ * definition. This is necessary because more than one tentative
* definition is allowed (except with sflag).
*/
def = NULL;
@@ -213,8 +217,7 @@ dumpname(hte)
* Write a new lint library.
*/
void
-outlib(name)
- const char *name;
+outlib(const char *name)
{
/* Open of output file and initialisation of the output buffer */
outopen(name);
@@ -228,9 +231,67 @@ outlib(name)
outchar('s');
outstrg(name);
+ /*
+ * print the names of all files references by unnamed
+ * struct/union/enum declarations.
+ */
+ outfiles();
+
/* write all definitions with external linkage */
forall(dumpname);
/* close the output */
outclose();
}
+
+/*
+ * Write out the name of a file referenced by a type.
+ */
+struct outflist {
+ short ofl_num;
+ struct outflist *ofl_next;
+};
+static struct outflist *outflist;
+
+int
+addoutfile(short num)
+{
+ struct outflist *ofl, **pofl;
+ int i;
+
+ ofl = outflist;
+ pofl = &outflist;
+ i = 1; /* library is 0 */
+
+ while (ofl != NULL) {
+ if (ofl->ofl_num == num)
+ break;
+
+ pofl = &ofl->ofl_next;
+ ofl = ofl->ofl_next;
+ i++;
+ }
+
+ if (ofl == NULL) {
+ ofl = *pofl = xmalloc(sizeof (struct outflist));
+ ofl->ofl_num = num;
+ ofl->ofl_next = NULL;
+ }
+ return (i);
+}
+
+static void
+outfiles(void)
+{
+ struct outflist *ofl;
+ int i;
+
+ for (ofl = outflist, i = 1; ofl != NULL; ofl = ofl->ofl_next, i++) {
+ /* reset output buffer */
+ outclr();
+
+ outint(i);
+ outchar('s');
+ outstrg(fnames[ofl->ofl_num]);
+ }
+}
diff --git a/usr.bin/xlint/lint2/externs2.h b/usr.bin/xlint/lint2/externs2.h
index 2e65e53..3b6f03a 100644
--- a/usr.bin/xlint/lint2/externs2.h
+++ b/usr.bin/xlint/lint2/externs2.h
@@ -1,6 +1,7 @@
-/* $NetBSD: externs2.h,v 1.2 1995/07/03 21:24:46 cgd Exp $ */
+/* $NetBSD: externs2.h,v 1.7 2001/05/28 12:40:38 lukem Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -38,7 +39,6 @@ extern int xflag;
extern int uflag;
extern int Cflag;
extern const char *libname;
-extern int pflag;
extern int sflag;
extern int tflag;
extern int Hflag;
@@ -49,9 +49,14 @@ extern int Fflag;
/*
* hash.c
*/
-extern void inithash __P((void));
-extern hte_t *hsearch __P((const char *, int));
-extern void forall __P((void (*)(hte_t *)));
+extern void _inithash(hte_t ***);
+extern hte_t *_hsearch(hte_t **, const char *, int);
+extern void _forall(hte_t **, void (*)(hte_t *));
+extern void _destroyhash(hte_t **);
+
+#define inithash() _inithash(NULL);
+#define hsearch(a, b) _hsearch(NULL, (a), (b))
+#define forall(a) _forall(NULL, (a))
/*
* read.c
@@ -59,29 +64,30 @@ extern void forall __P((void (*)(hte_t *)));
extern const char **fnames;
extern type_t **tlst;
-extern void readfile __P((const char *));
-extern void mkstatic __P((hte_t *));
+extern void readfile(const char *);
+extern void mkstatic(hte_t *);
/*
* mem2.c
*/
-extern void initmem __P((void));
-extern void *xalloc __P((size_t));
+extern void initmem(void);
+extern void *xalloc(size_t);
/*
* chk.c
*/
-extern void inittyp __P((void));
-extern void mainused __P((void));
-extern void chkname __P((hte_t *));
+extern void inittyp(void);
+extern void mainused(void);
+extern void chkname(hte_t *);
/*
* msg.c
*/
-extern void msg __P((int, ...));
-extern const char *mkpos __P((pos_t *));
+extern void msg(int, ...);
+extern const char *mkpos(pos_t *);
/*
* emit2.c
*/
-extern void outlib __P((const char *));
+extern void outlib(const char *);
+extern int addoutfile(short);
diff --git a/usr.bin/xlint/lint2/hash.c b/usr.bin/xlint/lint2/hash.c
index 7901802..fac7358 100644
--- a/usr.bin/xlint/lint2/hash.c
+++ b/usr.bin/xlint/lint2/hash.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.c,v 1.2 1995/07/03 21:24:47 cgd Exp $ */
+/* $NetBSD: hash.c,v 1.7 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -31,36 +31,45 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: hash.c,v 1.2 1995/07/03 21:24:47 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: hash.c,v 1.7 2002/01/21 19:49:52 tv Exp $");
#endif
+/*
+ * XXX Really need a generalized hash table package
+ */
+
+#include <limits.h>
#include <stddef.h>
+#include <stdlib.h>
#include <string.h>
-#include <limits.h>
#include "lint2.h"
/* pointer to hash table, initialized in inithash() */
static hte_t **htab;
-static int hash __P((const char *));
+static int hash(const char *);
/*
* Initialize hash table.
*/
void
-inithash()
+_inithash(hte_t ***tablep)
{
- htab = xcalloc(HSHSIZ2, sizeof (hte_t *));
+
+ if (tablep == NULL)
+ tablep = &htab;
+
+ *tablep = xcalloc(HSHSIZ2, sizeof (hte_t *));
}
/*
* Compute hash value from a string.
*/
static int
-hash(s)
- const char *s;
+hash(const char *s)
{
u_int v;
const u_char *us;
@@ -78,15 +87,16 @@ hash(s)
* given name exists and mknew is set, create a new one.
*/
hte_t *
-hsearch(s, mknew)
- const char *s;
- int mknew;
+_hsearch(hte_t **table, const char *s, int mknew)
{
int h;
hte_t *hte;
+ if (table == NULL)
+ table = htab;
+
h = hash(s);
- for (hte = htab[h]; hte != NULL; hte = hte->h_link) {
+ for (hte = table[h]; hte != NULL; hte = hte->h_link) {
if (strcmp(hte->h_name, s) == 0)
break;
}
@@ -95,13 +105,20 @@ hsearch(s, mknew)
return (hte);
/* create a new hte */
- hte = xalloc(sizeof (hte_t));
+ hte = xmalloc(sizeof (hte_t));
hte->h_name = xstrdup(s);
+ hte->h_used = 0;
+ hte->h_def = 0;
+ hte->h_static = 0;
+ hte->h_syms = NULL;
hte->h_lsym = &hte->h_syms;
+ hte->h_calls = NULL;
hte->h_lcall = &hte->h_calls;
+ hte->h_usyms = NULL;
hte->h_lusym = &hte->h_usyms;
- hte->h_link = htab[h];
- htab[h] = hte;
+ hte->h_link = table[h];
+ hte->h_hte = NULL;
+ table[h] = hte;
return (hte);
}
@@ -110,14 +127,38 @@ hsearch(s, mknew)
* Call function f for each name in the hash table.
*/
void
-forall(f)
- void (*f) __P((hte_t *));
+_forall(hte_t **table, void (*f)(hte_t *))
{
int i;
hte_t *hte;
+ if (table == NULL)
+ table = htab;
+
for (i = 0; i < HSHSIZ2; i++) {
- for (hte = htab[i]; hte != NULL; hte = hte->h_link)
+ for (hte = table[i]; hte != NULL; hte = hte->h_link)
(*f)(hte);
}
}
+
+/*
+ * Free all contents of the hash table that this module allocated.
+ */
+void
+_destroyhash(hte_t **table)
+{
+ int i;
+ hte_t *hte, *nexthte;
+
+ if (table == NULL)
+ err(1, "_destroyhash called on main hash table");
+
+ for (i = 0; i < HSHSIZ2; i++) {
+ for (hte = table[i]; hte != NULL; hte = nexthte) {
+ free((void *)hte->h_name);
+ nexthte = hte->h_link;
+ free(hte);
+ }
+ }
+ free(table);
+}
diff --git a/usr.bin/xlint/lint2/lint2.h b/usr.bin/xlint/lint2/lint2.h
index 0ade110..75f9dc9 100644
--- a/usr.bin/xlint/lint2/lint2.h
+++ b/usr.bin/xlint/lint2/lint2.h
@@ -1,6 +1,7 @@
-/* $NetBSD: lint2.h,v 1.2 1995/07/03 21:24:49 cgd Exp $ */
+/* $NetBSD: lint2.h,v 1.5 2000/06/14 06:49:23 cgd Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -45,6 +46,7 @@ typedef struct type {
u_int t_proto : 1; /* this is a prototype */
u_int t_istag : 1; /* tag with _t_tag valid */
u_int t_istynam : 1; /* tag with _t_tynam valid */
+ u_int t_isuniqpos : 1; /* tag with _t_uniqpos valid */
union {
int _t_dim; /* if the type is an ARRAY than this
is the dimension of the array. */
@@ -52,6 +54,13 @@ typedef struct type {
t_isenum, STRUCT or UNION */
struct hte *_t_tynam; /* hash table entry of typename if
t_isenum, STRUCT or UNION */
+ struct {
+ int p_line;
+ short p_file;
+ int p_uniq;
+ } _t_uniqpos; /* unique position, for untagged
+ untyped STRUCTs, UNIONS, and ENUMs,
+ if t_isuniqpos */
struct type **_t_args; /* list of argument types if this
is a prototype */
} t_u;
@@ -59,10 +68,11 @@ typedef struct type {
type, type of return value) */
} type_t;
-#define t_dim t_u._t_dim
-#define t_tag t_u._t_tag
-#define t_tynam t_u._t_tynam
-#define t_args t_u._t_args
+#define t_dim t_u._t_dim
+#define t_tag t_u._t_tag
+#define t_tynam t_u._t_tynam
+#define t_uniqpos t_u._t_uniqpos
+#define t_args t_u._t_args
/*
* argument information
@@ -90,7 +100,7 @@ typedef struct {
u_short p_line; /* line number in p_src */
u_short p_isrc; /* index of (included) file */
u_short p_iline; /* line number in p_iline */
-} pos_t;
+} pos_t;
/*
* Used for definitions and declarations
@@ -107,7 +117,7 @@ typedef struct sym {
u_int s_def : 3; /* DECL, TDEF or DEF */
#else
def_t s_def;
-#endif
+#endif
u_int s_rval : 1; /* function has return value */
u_int s_osdef : 1; /* old style function definition */
u_int s_static : 1; /* symbol is static */
@@ -169,6 +179,7 @@ typedef struct hte {
usym_t *h_usyms; /* usage info */
usym_t **h_lusym; /* points to u_nxt of last usage info */
struct hte *h_link; /* next hte with same hash function */
+ struct hte *h_hte; /* pointer to other htes (for renames */
} hte_t;
/* maps type indices into pointers to type structs */
diff --git a/usr.bin/xlint/lint2/main2.c b/usr.bin/xlint/lint2/main2.c
index 171344a..71e8c10 100644
--- a/usr.bin/xlint/lint2/main2.c
+++ b/usr.bin/xlint/lint2/main2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $ */
+/* $NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: main2.c,v 1.2 1995/07/03 21:24:53 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: main2.c,v 1.5 2001/11/21 19:14:26 wiz Exp $");
#endif
#include <stdio.h>
@@ -58,7 +59,7 @@ const char *libname;
int pflag;
/*
- * warnings for (tentative) definitions of the same name in more then
+ * warnings for (tentative) definitions of the same name in more than
* one translation unit
*/
int sflag;
@@ -83,13 +84,12 @@ int Fflag;
*/
const char **libs;
-static void usage __P((void));
+static void usage(void);
+int main(int, char *[]);
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int c, i;
size_t len;
@@ -133,8 +133,9 @@ main(argc, argv)
Fflag = 1;
break;
case 'l':
- for (i = 0; libs[i] != NULL; i++) ;
- libs = xrealloc(libs, (i + 2) * sizeof (char *));
+ for (i = 0; libs[i] != NULL; i++)
+ continue;
+ libs = xrealloc(libs, (i + 2) * sizeof (char *));
libs[i] = xstrdup(optarg);
libs[i + 1] = NULL;
break;
@@ -142,7 +143,7 @@ main(argc, argv)
usage();
}
}
-
+
argc -= optind;
argv += optind;
@@ -181,10 +182,9 @@ main(argc, argv)
}
static void
-usage()
+usage(void)
{
(void)fprintf(stderr,
"usage: lint2 -hpstxuHF -Clib -l lib ... src1 ...\n");
exit(1);
}
-
diff --git a/usr.bin/xlint/lint2/mem2.c b/usr.bin/xlint/lint2/mem2.c
index 06d7491..87d5a1b 100644
--- a/usr.bin/xlint/lint2/mem2.c
+++ b/usr.bin/xlint/lint2/mem2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $ */
+/* $NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -31,8 +31,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
#endif
#include <sys/param.h>
@@ -40,7 +41,6 @@ static char rcsid[] = "$NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $";
#include <sys/mman.h>
#include <unistd.h>
#include <string.h>
-#include <err.h>
#include "lint2.h"
@@ -54,7 +54,7 @@ static size_t nxtfree;
static void *mbuf;
void
-initmem()
+initmem(void)
{
int pgsz;
@@ -70,13 +70,13 @@ initmem()
* need never to be freed.
*/
void *
-xalloc(sz)
- size_t sz;
+xalloc(size_t sz)
{
void *ptr;
int prot, flags;
- sz = ALIGN(sz);
+ /* Align to at least 8 bytes. */
+ sz = (sz + 7) & ~7L;
if (nxtfree + sz > mblklen) {
/* use mmap() instead of malloc() to avoid malloc overhead. */
prot = PROT_READ | PROT_WRITE;
@@ -84,8 +84,6 @@ xalloc(sz)
mbuf = mmap(NULL, mblklen, prot, flags, -1, (off_t)0);
if (mbuf == (void *)-1)
err(1, "can't map memory");
- if (ALIGN((u_long)mbuf) != (u_long)mbuf)
- errx(1, "mapped address is not aligned");
(void)memset(mbuf, 0, mblklen);
nxtfree = 0;
}
diff --git a/usr.bin/xlint/lint2/msg.c b/usr.bin/xlint/lint2/msg.c
index c55ba96..b4a6a31 100644
--- a/usr.bin/xlint/lint2/msg.c
+++ b/usr.bin/xlint/lint2/msg.c
@@ -1,4 +1,4 @@
-/* $NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd Exp $ */
+/* $NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -31,22 +31,17 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: msg.c,v 1.2 1995/07/03 21:24:56 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: msg.c,v 1.6 2002/01/21 19:49:52 tv Exp $");
#endif
-#include <string.h>
-
#include <stdio.h>
-#ifdef __STDC__
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+#include <string.h>
#include "lint2.h"
-
static const char *msgs[] = {
"%s used( %s ), but not defined", /* 0 */
"%s defined( %s ), but never used", /* 1 */
@@ -66,29 +61,17 @@ static const char *msgs[] = {
"%s: too few args for format \t%s", /* 15 */
"%s: too many args for format \t%s", /* 16 */
"%s function value must be declared before use \t%s :: %s",/* 17 */
+ "%s renamed multiple times \t%s :: %s", /* 18 */
};
-static const char *basename __P((const char *));
+static const char *lbasename(const char *);
-#ifdef __STDC__
void
msg(int n, ...)
{
-#else
-void
-msg(va_alist)
- va_dcl
- int n;
-{
-#endif
va_list ap;
-#ifdef __STDC__
va_start(ap, n);
-#else
- va_start(ap);
- n = va_arg(ap, int);
-#endif
(void)vprintf(msgs[n], ap);
(void)printf("\n");
@@ -100,8 +83,7 @@ msg(va_alist)
* Return a pointer to the last component of a path.
*/
static const char *
-basename(path)
- const char *path;
+lbasename(const char *path)
{
const char *cp, *cp1, *cp2;
@@ -122,8 +104,7 @@ basename(path)
* Create a string which describes a position in a source file.
*/
const char *
-mkpos(posp)
- pos_t *posp;
+mkpos(pos_t *posp)
{
size_t len;
const char *fn;
@@ -140,7 +121,7 @@ mkpos(posp)
}
qm = !Hflag && posp->p_src != posp->p_isrc;
- len = strlen(fn = basename(fnames[src]));
+ len = strlen(fn = lbasename(fnames[src]));
len += 3 * sizeof (u_short) + 4;
if (len > blen)
@@ -154,4 +135,3 @@ mkpos(posp)
return (buf);
}
-
diff --git a/usr.bin/xlint/lint2/read.c b/usr.bin/xlint/lint2/read.c
index daffe1e..d3e8f9e 100644
--- a/usr.bin/xlint/lint2/read.c
+++ b/usr.bin/xlint/lint2/read.c
@@ -1,6 +1,7 @@
-/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */
+/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -31,16 +32,16 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $");
#endif
+#include <ctype.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <err.h>
#include "lint2.h"
@@ -78,33 +79,34 @@ static thtab_t **thtab; /* hash table */
type_t **tlst; /* array for indexed access */
static size_t tlstlen; /* length of tlst */
+static hte_t **renametab;
+
/* index of current C source file (as spezified at the command line) */
static int csrcfile;
-static void inperr __P((void));
-static void setsrc __P((const char *));
-static void setfnid __P((int, const char *));
-static void funccall __P((pos_t *, const char *));
-static void decldef __P((pos_t *, const char *));
-static void usedsym __P((pos_t *, const char *));
-static u_short inptype __P((const char *, const char **));
-static int gettlen __P((const char *, const char **));
-static u_short findtype __P((const char *, size_t, int));
-static u_short storetyp __P((type_t *, const char *, size_t, int));
-static int thash __P((const char *, size_t));
-static char *inpqstrg __P((const char *, const char **));
-static const char *inpname __P((const char *, const char **));
-static int getfnidx __P((const char *));
+static void inperr(void);
+static void setsrc(const char *);
+static void setfnid(int, const char *);
+static void funccall(pos_t *, const char *);
+static void decldef(pos_t *, const char *);
+static void usedsym(pos_t *, const char *);
+static u_short inptype(const char *, const char **);
+static int gettlen(const char *, const char **);
+static u_short findtype(const char *, size_t, int);
+static u_short storetyp(type_t *, const char *, size_t, int);
+static int thash(const char *, size_t);
+static char *inpqstrg(const char *, const char **);
+static const char *inpname(const char *, const char **);
+static int getfnidx(const char *);
void
-readfile(name)
- const char *name;
+readfile(const char *name)
{
FILE *inp;
size_t len;
const char *cp;
- char *line, *eptr, rt;
+ char *line, *eptr, rt = '\0';
int cline, isrc, iline;
pos_t pos;
@@ -117,6 +119,8 @@ readfile(name)
if (thtab == NULL)
thtab = xcalloc(THSHSIZ2, sizeof (thtab_t));
+ _inithash(&renametab);
+
srcfile = getfnidx(name);
if ((inp = fopen(name, "r")) == NULL)
@@ -193,6 +197,8 @@ readfile(name)
}
+ _destroyhash(renametab);
+
if (ferror(inp))
err(1, "read error on %s", name);
@@ -201,8 +207,9 @@ readfile(name)
static void
-inperr()
+inperr(void)
{
+
errx(1, "input file error: %s", fnames[srcfile]);
}
@@ -211,23 +218,22 @@ inperr()
* currently read.
*/
static void
-setsrc(cp)
- const char *cp;
+setsrc(const char *cp)
{
+
csrcfile = getfnidx(cp);
}
/*
* setfnid() gets as input an index as used in an input file and the
- * associated file name. If neccessary, it creates a new lint2 file
+ * associated file name. If necessary, it creates a new lint2 file
* name index for this file name and creates the mapping of the index
* as used in the input file to the index used in lint2.
*/
static void
-setfnid(fid, cp)
- int fid;
- const char *cp;
+setfnid(int fid, const char *cp)
{
+
if (fid == -1)
inperr();
@@ -249,15 +255,14 @@ setfnid(fid, cp)
* Process a function call record (c-record).
*/
static void
-funccall(posp, cp)
- pos_t *posp;
- const char *cp;
+funccall(pos_t *posp, const char *cp)
{
arginf_t *ai, **lai;
char c, *eptr;
int rused, rdisc;
hte_t *hte;
fcall_t *fcall;
+ const char *name;
fcall = xalloc(sizeof (fcall_t));
STRUCT_ASSIGN(fcall->f_pos, *posp);
@@ -311,7 +316,14 @@ funccall(posp, cp)
fcall->f_rdisc = rdisc;
/* read name of function */
- hte = hsearch(inpname(cp, &cp), 1);
+ name = inpname(cp, &cp);
+
+ /* first look it up in the renaming table, then in the normal table */
+ hte = _hsearch(renametab, name, 0);
+ if (hte != NULL)
+ hte = hte->h_hte;
+ else
+ hte = hsearch(name, 1);
hte->h_used = 1;
fcall->f_type = inptype(cp, &cp);
@@ -327,14 +339,13 @@ funccall(posp, cp)
* Process a declaration or definition (d-record).
*/
static void
-decldef(posp, cp)
- pos_t *posp;
- const char *cp;
+decldef(pos_t *posp, const char *cp)
{
sym_t *symp, sym;
- char c, *ep;
- int used;
- hte_t *hte;
+ char c, *ep, *pos1;
+ int used, renamed;
+ hte_t *hte, *renamehte = NULL;
+ const char *name, *rename;
(void)memset(&sym, 0, sizeof (sym));
STRUCT_ASSIGN(sym.s_pos, *posp);
@@ -412,8 +423,35 @@ decldef(posp, cp)
}
}
- /* read symbol name */
- hte = hsearch(inpname(cp, &cp), 1);
+ /* read symbol name, doing renaming if necessary */
+ name = inpname(cp, &cp);
+ renamed = 0;
+ if (*cp == 'r') {
+ cp++;
+ name = xstrdup(name);
+ rename = inpname(cp, &cp);
+
+ /* enter it and see if it's already been renamed */
+ renamehte = _hsearch(renametab, name, 1);
+ if (renamehte->h_hte == NULL) {
+ hte = hsearch(rename, 1);
+ renamehte->h_hte = hte;
+ renamed = 1;
+ } else if (strcmp((hte = renamehte->h_hte)->h_name, rename)) {
+ pos1 = xstrdup(mkpos(&renamehte->h_syms->s_pos));
+ /* %s renamed multiple times\t%s :: %s */
+ msg(18, name, pos1, mkpos(&sym.s_pos));
+ free(pos1);
+ }
+ free((char *)name);
+ } else {
+ /* it might be a previously-done rename */
+ hte = _hsearch(renametab, name, 0);
+ if (hte != NULL)
+ hte = hte->h_hte;
+ else
+ hte = hsearch(name, 1);
+ }
hte->h_used |= used;
if (sym.s_def == DEF || sym.s_def == TDEF)
hte->h_def = 1;
@@ -449,6 +487,10 @@ decldef(posp, cp)
}
*hte->h_lsym = symp;
hte->h_lsym = &symp->s_nxt;
+
+ /* XXX hack so we can remember where a symbol was renamed */
+ if (renamed)
+ renamehte->h_syms = symp;
}
if (*cp != '\0')
@@ -459,12 +501,11 @@ decldef(posp, cp)
* Read an u-record (emited by lint1 if a symbol was used).
*/
static void
-usedsym(posp, cp)
- pos_t *posp;
- const char *cp;
+usedsym(pos_t *posp, const char *cp)
{
usym_t *usym;
hte_t *hte;
+ const char *name;
usym = xalloc(sizeof (usym_t));
STRUCT_ASSIGN(usym->u_pos, *posp);
@@ -473,7 +514,12 @@ usedsym(posp, cp)
if (*cp++ != 'x')
inperr();
- hte = hsearch(inpname(cp, &cp), 1);
+ name = inpname(cp, &cp);
+ hte = _hsearch(renametab, name, 0);
+ if (hte != NULL)
+ hte = hte->h_hte;
+ else
+ hte = hsearch(name, 1);
hte->h_used = 1;
*hte->h_lusym = usym;
@@ -484,13 +530,12 @@ usedsym(posp, cp)
* Read a type and return the index of this type.
*/
static u_short
-inptype(cp, epp)
- const char *cp, **epp;
+inptype(const char *cp, const char **epp)
{
char c, s, *eptr;
const char *ep;
type_t *tp;
- int narg, i, osdef;
+ int narg, i, osdef = 0;
size_t tlen;
u_short tidx;
int h;
@@ -600,8 +645,6 @@ inptype(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
- case '0':
- break;
case '1':
tp->t_istag = 1;
tp->t_tag = hsearch(inpname(cp, &cp), 1);
@@ -610,9 +653,42 @@ inptype(cp, epp)
tp->t_istynam = 1;
tp->t_tynam = hsearch(inpname(cp, &cp), 1);
break;
+ case '3':
+ tp->t_isuniqpos = 1;
+ tp->t_uniqpos.p_line = strtol(cp, &eptr, 10);
+ cp = eptr;
+ cp++;
+ /* xlate to 'global' file name. */
+ tp->t_uniqpos.p_file =
+ addoutfile(inpfns[strtol(cp, &eptr, 10)]);
+ cp = eptr;
+ cp++;
+ tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10);
+ cp = eptr;
+ break;
}
break;
- /* LINTED (enumeration value(s) not handled in switch) */
+ case LONG:
+ case VOID:
+ case LDOUBLE:
+ case DOUBLE:
+ case FLOAT:
+ case UQUAD:
+ case QUAD:
+ case ULONG:
+ case UINT:
+ case INT:
+ case USHORT:
+ case SHORT:
+ case UCHAR:
+ case SCHAR:
+ case CHAR:
+ case UNSIGN:
+ case SIGNED:
+ case NOTSPEC:
+ break;
+ case NTSPEC:
+ abort();
}
*epp = cp;
@@ -623,8 +699,7 @@ inptype(cp, epp)
* Get the length of a type string.
*/
static int
-gettlen(cp, epp)
- const char *cp, **epp;
+gettlen(const char *cp, const char **epp)
{
const char *cp1;
char c, s, *eptr;
@@ -769,19 +844,56 @@ gettlen(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
- case '0':
- break;
case '1':
(void)inpname(cp, &cp);
break;
case '2':
(void)inpname(cp, &cp);
break;
+ case '3':
+ /* unique position: line.file.uniquifier */
+ (void)strtol(cp, &eptr, 10);
+ if (cp == eptr)
+ inperr();
+ cp = eptr;
+ if (*cp++ != '.')
+ inperr();
+ (void)strtol(cp, &eptr, 10);
+ if (cp == eptr)
+ inperr();
+ cp = eptr;
+ if (*cp++ != '.')
+ inperr();
+ (void)strtol(cp, &eptr, 10);
+ if (cp == eptr)
+ inperr();
+ cp = eptr;
+ break;
default:
inperr();
}
break;
- /* LINTED (enumeration value(s) not handled in switch) */
+ case FLOAT:
+ case USHORT:
+ case SHORT:
+ case UCHAR:
+ case SCHAR:
+ case CHAR:
+ case UNSIGN:
+ case SIGNED:
+ case NOTSPEC:
+ case INT:
+ case UINT:
+ case DOUBLE:
+ case LDOUBLE:
+ case VOID:
+ case ULONG:
+ case QUAD:
+ case UQUAD:
+ case LONG:
+ break;
+ case NTSPEC:
+ abort();
}
*epp = cp;
@@ -792,10 +904,7 @@ gettlen(cp, epp)
* Search a type by it's type string.
*/
static u_short
-findtype(cp, len, h)
- const char *cp;
- size_t len;
- int h;
+findtype(const char *cp, size_t len, int h)
{
thtab_t *thte;
@@ -814,14 +923,9 @@ findtype(cp, len, h)
* if we read the same type string from the input file.
*/
static u_short
-storetyp(tp, cp, len, h)
- type_t *tp;
- const char *cp;
- size_t len;
- int h;
+storetyp(type_t *tp, const char *cp, size_t len, int h)
{
- /* 0 ist reserved */
- static u_int tidx = 1;
+ static u_int tidx = 1; /* 0 is reserved */
thtab_t *thte;
char *name;
@@ -854,9 +958,7 @@ storetyp(tp, cp, len, h)
* Hash function for types
*/
static int
-thash(s, len)
- const char *s;
- size_t len;
+thash(const char *s, size_t len)
{
u_int v;
@@ -872,8 +974,7 @@ thash(s, len)
* Read a string enclosed by "". This string may contain quoted chars.
*/
static char *
-inpqstrg(src, epp)
- const char *src, **epp;
+inpqstrg(const char *src, const char **epp)
{
char *strg, *dst;
size_t slen;
@@ -899,11 +1000,7 @@ inpqstrg(src, epp)
c = '\t';
break;
case 'v':
-#ifdef __STDC__
c = '\v';
-#else
- c = '\013';
-#endif
break;
case 'b':
c = '\b';
@@ -915,11 +1012,7 @@ inpqstrg(src, epp)
c = '\f';
break;
case 'a':
-#ifdef __STDC__
c = '\a';
-#else
- c = '\007';
-#endif
break;
case '\\':
c = '\\';
@@ -964,8 +1057,7 @@ inpqstrg(src, epp)
* Read the name of a symbol in static memory.
*/
static const char *
-inpname(cp, epp)
- const char *cp, **epp;
+inpname(const char *cp, const char **epp)
{
static char *buf;
static size_t blen = 0;
@@ -980,7 +1072,7 @@ inpname(cp, epp)
buf = xrealloc(buf, blen = len + 1);
for (i = 0; i < len; i++) {
c = *cp++;
- if (!isalnum(c) && c != '_')
+ if (!isalnum((unsigned char)c) && c != '_')
inperr();
buf[i] = c;
}
@@ -995,8 +1087,7 @@ inpname(cp, epp)
* a new entry and return the index of the newly created entry.
*/
static int
-getfnidx(fn)
- const char *fn;
+getfnidx(const char *fn)
{
int i;
@@ -1022,8 +1113,7 @@ getfnidx(fn)
* Separate symbols with static and external linkage.
*/
void
-mkstatic(hte)
- hte_t *hte;
+mkstatic(hte_t *hte)
{
sym_t *sym1, **symp, *sym;
fcall_t **callp, *call;
@@ -1067,16 +1157,22 @@ mkstatic(hte)
* XXX this entry should be put at the beginning of the list to
* avoid to process the same symbol twice.
*/
- for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) ;
- nhte->h_link = xalloc(sizeof (hte_t));
+ for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link)
+ continue;
+ nhte->h_link = xmalloc(sizeof (hte_t));
nhte = nhte->h_link;
nhte->h_name = hte->h_name;
- nhte->h_static = 1;
nhte->h_used = 1;
nhte->h_def = 1; /* error in lint1 */
+ nhte->h_static = 1;
+ nhte->h_syms = NULL;
nhte->h_lsym = &nhte->h_syms;
+ nhte->h_calls = NULL;
nhte->h_lcall = &nhte->h_calls;
+ nhte->h_usyms = NULL;
nhte->h_lusym = &nhte->h_usyms;
+ nhte->h_link = NULL;
+ nhte->h_hte = NULL;
/*
* move all symbols used in this translation unit into the new
OpenPOWER on IntegriCloud