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
commit00e098c5ce6a724945a528315cbc5930ca968809 (patch)
treebc7f0719c379d1d86f71e454dd9d9005e27f50b9 /usr.bin/xlint/lint2
parent8a5493bf2a39dade2b865aae9bb0888c4752f0ba (diff)
parenta9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53 (diff)
downloadFreeBSD-src-00e098c5ce6a724945a528315cbc5930ca968809.zip
FreeBSD-src-00e098c5ce6a724945a528315cbc5930ca968809.tar.gz
This commit was generated by cvs2svn to compensate for changes in r91586,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'usr.bin/xlint/lint2')
-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/msg.c40
7 files changed, 298 insertions, 313 deletions
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/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);
}
-
OpenPOWER on IntegriCloud