Centralize the initialization/declaration of the ttab.

This commit is contained in:
thorpej 2002-01-18 21:01:38 +00:00
parent 41d48940fa
commit 81a86a8f72
8 changed files with 158 additions and 189 deletions

View File

@ -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
*/

View File

@ -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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: inittyp.c,v 1.1 2002/01/18 21:01:38 thorpej Exp $");
#endif
#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#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;
}
}

View File

@ -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 <bsd.own.mk>
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}

View File

@ -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 <sys/cdefs.h>
#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 <sys/param.h>
@ -46,9 +46,6 @@ __RCSID("$NetBSD: decl.c,v 1.28 2002/01/03 05:37:39 thorpej Exp $");
const char *unnamed = "<unnamed>";
/* contains various information and classification on types */
ttab_t ttab[NTSPEC];
/* shared type structures for arithmtic types and void */
static type_t *typetab;
@ -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));

View File

@ -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;

View File

@ -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

View File

@ -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 <sys/cdefs.h>
#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 <stdlib.h>
@ -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.
*/

View File

@ -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;