From 81a86a8f727090253714e6893f60affa01c30153 Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 18 Jan 2002 21:01:38 +0000 Subject: [PATCH] Centralize the initialization/declaration of the ttab. --- usr.bin/xlint/common/externs.h | 12 ++- usr.bin/xlint/common/inittyp.c | 134 +++++++++++++++++++++++++++++++++ usr.bin/xlint/lint1/Makefile | 4 +- usr.bin/xlint/lint1/decl.c | 90 +--------------------- usr.bin/xlint/lint1/externs1.h | 3 +- usr.bin/xlint/lint2/Makefile | 5 +- usr.bin/xlint/lint2/chk.c | 96 +---------------------- usr.bin/xlint/lint2/externs2.h | 3 +- 8 files changed, 158 insertions(+), 189 deletions(-) create mode 100644 usr.bin/xlint/common/inittyp.c diff --git a/usr.bin/xlint/common/externs.h b/usr.bin/xlint/common/externs.h index 89be4d18c14d..ac69c4ba8dcf 100644 --- a/usr.bin/xlint/common/externs.h +++ b/usr.bin/xlint/common/externs.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs.h,v 1.1 2002/01/18 20:39:23 thorpej Exp $ */ +/* $NetBSD: externs.h,v 1.2 2002/01/18 21:01:38 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,6 +31,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * main[12].c + */ +extern int pflag; + +/* + * inittyp.c + */ +extern void inittyp(void); + /* * mem.c */ diff --git a/usr.bin/xlint/common/inittyp.c b/usr.bin/xlint/common/inittyp.c new file mode 100644 index 000000000000..0f6e861341c8 --- /dev/null +++ b/usr.bin/xlint/common/inittyp.c @@ -0,0 +1,134 @@ +/* $NetBSD: inittyp.c,v 1.1 2002/01/18 21:01:38 thorpej Exp $ */ + +/* + * Copyright (c) 1994, 1995 Jochen Pohl + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jochen Pohl for + * The NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: inittyp.c,v 1.1 2002/01/18 21:01:38 thorpej Exp $"); +#endif + +#include +#include +#include +#include + +#include "lint.h" + +/* various type information */ +ttab_t ttab[NTSPEC]; + +void +inittyp(void) +{ + int i; + static const struct { + tspec_t it_tspec; + ttab_t it_ttab; + } ittab[NTSPEC] = { + { SIGNED, { 0, 0, + SIGNED, UNSIGN, + 0, 0, 0, 0, 0, "signed" } }, + { UNSIGN, { 0, 0, + SIGNED, UNSIGN, + 0, 0, 0, 0, 0, "unsigned" } }, + { CHAR, { CHAR_SIZE, CHAR_BIT, + SCHAR, UCHAR, + 1, 0, 0, 1, 1, "char" } }, + { SCHAR, { CHAR_SIZE, CHAR_BIT, + SCHAR, UCHAR, + 1, 0, 0, 1, 1, "signed char" } }, + { UCHAR, { CHAR_SIZE, CHAR_BIT, + SCHAR, UCHAR, + 1, 1, 0, 1, 1, "unsigned char" } }, + { SHORT, { SHORT_SIZE, 2 * CHAR_BIT, + SHORT, USHORT, + 1, 0, 0, 1, 1, "short" } }, + { USHORT, { SHORT_SIZE, 2 * CHAR_BIT, + SHORT, USHORT, + 1, 1, 0, 1, 1, "unsigned short" } }, + { INT, { INT_SIZE, 3 * CHAR_BIT, + INT, UINT, + 1, 0, 0, 1, 1, "int" } }, + { UINT, { INT_SIZE, 3 * CHAR_BIT, + INT, UINT, + 1, 1, 0, 1, 1, "unsigned int" } }, + { LONG, { LONG_SIZE, 4 * CHAR_BIT, + LONG, ULONG, + 1, 0, 0, 1, 1, "long" } }, + { ULONG, { LONG_SIZE, 4 * CHAR_BIT, + LONG, ULONG, + 1, 1, 0, 1, 1, "unsigned long" } }, + { QUAD, { QUAD_SIZE, 8 * CHAR_BIT, + QUAD, UQUAD, + 1, 0, 0, 1, 1, "long long" } }, + { UQUAD, { QUAD_SIZE, 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, { PTR_SIZE, 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; + } +} diff --git a/usr.bin/xlint/lint1/Makefile b/usr.bin/xlint/lint1/Makefile index f0887b1787e5..a0d0470d3959 100644 --- a/usr.bin/xlint/lint1/Makefile +++ b/usr.bin/xlint/lint1/Makefile @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.22 2001/12/19 18:10:40 tv Exp $ +# $NetBSD: Makefile,v 1.23 2002/01/18 21:01:39 thorpej Exp $ .include 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 + init.c emit.c emit1.c inittyp.c MAN= lint.7 LDADD+= -ll DPADD+= ${LIBL} diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index f4d1bf1dad86..6d73624740f6 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $NetBSD: decl.c,v 1.28 2002/01/03 05:37:39 thorpej Exp $ */ +/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #ifndef lint -__RCSID("$NetBSD: decl.c,v 1.28 2002/01/03 05:37:39 thorpej Exp $"); +__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $"); #endif #include @@ -46,9 +46,6 @@ __RCSID("$NetBSD: decl.c,v 1.28 2002/01/03 05:37:39 thorpej Exp $"); const char *unnamed = ""; -/* contains various information and classification on types */ -ttab_t ttab[NTSPEC]; - /* shared type structures for arithmtic types and void */ static type_t *typetab; @@ -87,81 +84,7 @@ static void glchksz(sym_t *); void initdecl(void) { - 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_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "char" } }, - { SCHAR, { CHAR_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "signed char" } }, - { UCHAR, { CHAR_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 1, 0, 1, 1, "unsigned char" } }, - { SHORT, { SHORT_SIZE, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 0, 0, 1, 1, "short" } }, - { USHORT, { SHORT_SIZE, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 1, 0, 1, 1, "unsigned short" } }, - { INT, { INT_SIZE, 3 * CHAR_BIT, - INT, UINT, - 1, 0, 0, 1, 1, "int" } }, - { UINT, { INT_SIZE, 3 * CHAR_BIT, - INT, UINT, - 1, 1, 0, 1, 1, "unsigned int" } }, - { LONG, { LONG_SIZE, 4 * CHAR_BIT, - LONG, ULONG, - 1, 0, 0, 1, 1, "long" } }, - { ULONG, { LONG_SIZE, 4 * CHAR_BIT, - LONG, ULONG, - 1, 1, 0, 1, 1, "unsigned long" } }, - { QUAD, { QUAD_SIZE, 8 * CHAR_BIT, - QUAD, UQUAD, - 1, 0, 0, 1, 1, "long long" } }, - { UQUAD, { QUAD_SIZE, 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, { PTR_SIZE, 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" } }, - }; + int i; /* declaration stack */ dcs = xcalloc(1, sizeof (dinfo_t)); @@ -169,12 +92,7 @@ initdecl(void) 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)); diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 39979a3d083f..219ab950eb0f 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.12 2002/01/03 04:25:15 thorpej Exp $ */ +/* $NetBSD: externs1.h,v 1.13 2002/01/18 21:01:39 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -42,7 +42,6 @@ extern int eflag; extern int Fflag; extern int gflag; extern int hflag; -extern int pflag; extern int rflag; extern int sflag; extern int tflag; diff --git a/usr.bin/xlint/lint2/Makefile b/usr.bin/xlint/lint2/Makefile index d3a0729220c1..95309942817e 100644 --- a/usr.bin/xlint/lint2/Makefile +++ b/usr.bin/xlint/lint2/Makefile @@ -1,7 +1,8 @@ -# $NetBSD: Makefile,v 1.12 2002/01/18 20:39:32 thorpej Exp $ +# $NetBSD: Makefile,v 1.13 2002/01/18 21:01:39 thorpej Exp $ PROG= lint2 -SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c +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 diff --git a/usr.bin/xlint/lint2/chk.c b/usr.bin/xlint/lint2/chk.c index 40d4411284ef..97c50db21f82 100644 --- a/usr.bin/xlint/lint2/chk.c +++ b/usr.bin/xlint/lint2/chk.c @@ -1,4 +1,4 @@ -/* $NetBSD: chk.c,v 1.13 2002/01/18 20:14:32 thorpej Exp $ */ +/* $NetBSD: chk.c,v 1.14 2002/01/18 21:01:39 thorpej Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -34,7 +34,7 @@ #include #ifndef lint -__RCSID("$NetBSD: chk.c,v 1.13 2002/01/18 20:14:32 thorpej Exp $"); +__RCSID("$NetBSD: chk.c,v 1.14 2002/01/18 21:01:39 thorpej Exp $"); #endif #include @@ -44,10 +44,6 @@ __RCSID("$NetBSD: chk.c,v 1.13 2002/01/18 20:14:32 thorpej Exp $"); #include "lint2.h" -/* various type information */ -ttab_t ttab[NTSPEC]; - - static void chkund(hte_t *); static void chkdnu(hte_t *); static void chkdnud(hte_t *); @@ -70,94 +66,6 @@ static int eqargs(type_t *, type_t *, int *); static int mnoarg(type_t *, int *); -void -inittyp(void) -{ - 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_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "char" } }, - { SCHAR, { CHAR_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 0, 0, 1, 1, "signed char" } }, - { UCHAR, { CHAR_SIZE, CHAR_BIT, - SCHAR, UCHAR, - 1, 1, 0, 1, 1, "unsigned char" } }, - { SHORT, { SHORT_SIZE, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 0, 0, 1, 1, "short" } }, - { USHORT, { SHORT_SIZE, 2 * CHAR_BIT, - SHORT, USHORT, - 1, 1, 0, 1, 1, "unsigned short" } }, - { INT, { INT_SIZE, 3 * CHAR_BIT, - INT, UINT, - 1, 0, 0, 1, 1, "int" } }, - { UINT, { INT_SIZE, 3 * CHAR_BIT, - INT, UINT, - 1, 1, 0, 1, 1, "unsigned int" } }, - { LONG, { LONG_SIZE, 4 * CHAR_BIT, - LONG, ULONG, - 1, 0, 0, 1, 1, "long" } }, - { ULONG, { LONG_SIZE, 4 * CHAR_BIT, - LONG, ULONG, - 1, 1, 0, 1, 1, "unsigned long" } }, - { QUAD, { QUAD_SIZE, 8 * CHAR_BIT, - QUAD, UQUAD, - 1, 0, 0, 1, 1, "long long" } }, - { UQUAD, { QUAD_SIZE, 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, { PTR_SIZE, 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; - } -} - - /* * If there is a symbol named "main", mark it as used. */ diff --git a/usr.bin/xlint/lint2/externs2.h b/usr.bin/xlint/lint2/externs2.h index a940447b8e42..04525b9f8ca9 100644 --- a/usr.bin/xlint/lint2/externs2.h +++ b/usr.bin/xlint/lint2/externs2.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs2.h,v 1.7 2001/05/28 12:40:38 lukem Exp $ */ +/* $NetBSD: externs2.h,v 1.8 2002/01/18 21:01:39 thorpej Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -39,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;