Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint Centralize the initialization/declaration of t...



details:   https://anonhg.NetBSD.org/src/rev/f19257b8c5d2
branches:  trunk
changeset: 520847:f19257b8c5d2
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Jan 18 21:01:38 2002 +0000

description:
Centralize the initialization/declaration of the ttab.

diffstat:

 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(-)

diffs (truncated from 477 to 300 lines):

diff -r aac49002b7ce -r f19257b8c5d2 usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h    Fri Jan 18 20:39:17 2002 +0000
+++ b/usr.bin/xlint/common/externs.h    Fri Jan 18 21:01:38 2002 +0000
@@ -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
@@ -32,6 +32,16 @@
  */
 
 /*
+ * main[12].c
+ */
+extern int     pflag;
+
+/*
+ * inittyp.c
+ */
+extern void    inittyp(void);
+
+/*
  * mem.c
  */
 extern void    *xmalloc(size_t);
diff -r aac49002b7ce -r f19257b8c5d2 usr.bin/xlint/common/inittyp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/xlint/common/inittyp.c    Fri Jan 18 21:01:38 2002 +0000
@@ -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;
+       }
+}
diff -r aac49002b7ce -r f19257b8c5d2 usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Fri Jan 18 20:39:17 2002 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Fri Jan 18 21:01:38 2002 +0000
@@ -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}
diff -r aac49002b7ce -r f19257b8c5d2 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Jan 18 20:39:17 2002 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Jan 18 21:01:38 2002 +0000
@@ -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 @@
 
 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 @@
 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 @@
        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;



Home | Main Index | Thread Index | Old Index