Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint lint: clean up wchar_t and hash tables



details:   https://anonhg.NetBSD.org/src/rev/da85b8774075
branches:  trunk
changeset: 377389:da85b8774075
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 10 09:51:30 2023 +0000

description:
lint: clean up wchar_t and hash tables

diffstat:

 usr.bin/xlint/common/param.h |  17 ++---------------
 usr.bin/xlint/lint1/init.c   |   6 +++---
 usr.bin/xlint/lint1/lex.c    |  12 ++++++------
 usr.bin/xlint/lint1/tree.c   |   6 +++---
 usr.bin/xlint/lint2/hash.c   |  27 +++++++++------------------
 usr.bin/xlint/lint2/read.c   |  10 ++++------
 6 files changed, 27 insertions(+), 51 deletions(-)

diffs (273 lines):

diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/common/param.h
--- a/usr.bin/xlint/common/param.h      Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/common/param.h      Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: param.h,v 1.11 2023/06/09 15:36:31 rillig Exp $        */
+/*     $NetBSD: param.h,v 1.12 2023/07/10 09:51:30 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -32,19 +32,6 @@
  */
 
 /*
- * Sizes of hash tables
- * Should be primes. Possible primes are
- * 307, 401, 503, 601, 701, 809, 907, 1009, 1103, 1201, 1301, 1409, 1511.
- *
- * HSHSIZ1     symbol table 1st pass
- * HSHSIZ2     symbol table 2nd pass
- * THSHSIZ2    type table 2nd pass
- */
-#define        HSHSIZ1         503
-#define HSHSIZ2                1009
-#define        THSHSIZ2        1009
-
-/*
  * Pull in target-specific parameters.
  */
 #include "targparam.h"
@@ -52,4 +39,4 @@
 /*
  * Make sure this matches wchar_t.
  */
-#define WCHAR  INT
+#define WCHAR_TSPEC    INT
diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/lint1/init.c        Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.245 2023/07/10 09:51:30 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.244 2023/07/01 06:09:24 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.245 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -206,7 +206,7 @@ can_init_character_array(const type_t *l
 
        return rst == CHAR
            ? lst == CHAR || lst == UCHAR || lst == SCHAR
-           : lst == WCHAR;
+           : lst == WCHAR_TSPEC;
 }
 
 /*
diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.172 2023/07/09 12:15:07 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.173 2023/07/10 09:51:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: lex.c,v 1.172 2023/07/09 12:15:07 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.173 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -182,7 +182,7 @@ static const struct keyword {
  * The symbol table containing all keywords, identifiers and labels. The hash
  * entries are linked via sym_t.s_symtab_next.
  */
-static sym_t *symtab[HSHSIZ1];
+static sym_t *symtab[503];
 
 /*
  * The kind of the next expected symbol, to distinguish the namespaces of
@@ -202,7 +202,7 @@ hash(const char *s)
                v = (v << 4) + (unsigned char)*p;
                v ^= v >> 28;
        }
-       return v % HSHSIZ1;
+       return v % (sizeof(symtab) / sizeof(symtab[0]));
 }
 
 static void
@@ -247,7 +247,7 @@ static void
 symtab_remove_locals(void)
 {
 
-       for (size_t i = 0; i < HSHSIZ1; i++) {
+       for (size_t i = 0; i < sizeof(symtab) / sizeof(symtab[0]); i++) {
                for (sym_t *sym = symtab[i]; sym != NULL; ) {
                        sym_t *next = sym->s_symtab_next;
                        if (sym->s_block_level >= 1)
@@ -927,7 +927,7 @@ lex_wide_character_constant(void)
        }
 
        yylval.y_val = xcalloc(1, sizeof(*yylval.y_val));
-       yylval.y_val->v_tspec = WCHAR;
+       yylval.y_val->v_tspec = WCHAR_TSPEC;
        yylval.y_val->v_char_constant = true;
        yylval.y_val->u.integer = wc;
 
diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.558 2023/07/09 12:04:08 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.559 2023/07/10 09:51:30 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.558 2023/07/09 12:04:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.559 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -539,7 +539,7 @@ build_string(strg_t *strg)
 
        type_t *tp = expr_zero_alloc(sizeof(*tp));
        tp->t_tspec = ARRAY;
-       tp->t_subt = gettyp(strg->st_char ? CHAR : WCHAR);
+       tp->t_subt = gettyp(strg->st_char ? CHAR : WCHAR_TSPEC);
        tp->t_dim = (int)(len + 1);
 
        tnode_t *n = expr_alloc_tnode();
diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/lint2/hash.c
--- a/usr.bin/xlint/lint2/hash.c        Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/lint2/hash.c        Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hash.c,v 1.25 2023/06/09 13:03:49 rillig Exp $ */
+/*     $NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,13 +37,9 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: hash.c,v 1.25 2023/06/09 13:03:49 rillig Exp $");
+__RCSID("$NetBSD: hash.c,v 1.26 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
-/*
- * XXX Really need a generalized hash table package
- */
-
 #include <limits.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -51,21 +47,16 @@
 
 #include "lint2.h"
 
-/* pointer to hash table, initialized in inithash() */
+#define HTAB_BUCKETS           1009
+
 static hte_t   **htab;
 
-/*
- * Initialize hash table.
- */
 hte_t **
 htab_new(void)
 {
-       return xcalloc(HSHSIZ2, sizeof(*htab_new()));
+       return xcalloc(HTAB_BUCKETS, sizeof(*htab_new()));
 }
 
-/*
- * Compute hash value from a string.
- */
 static unsigned int
 hash(const char *s)
 {
@@ -77,7 +68,7 @@ hash(const char *s)
                v = (v << 4) + (unsigned char)*p;
                v ^= v >> 28;
        }
-       return v % HSHSIZ2;
+       return v % HTAB_BUCKETS;
 }
 
 /*
@@ -163,7 +154,7 @@ symtab_forall(void (*action)(hte_t *))
        hte_t *hte;
        hte_t **table = htab;
 
-       for (i = 0; i < HSHSIZ2; i++) {
+       for (i = 0; i < HTAB_BUCKETS; i++) {
                for (hte = table[i]; hte != NULL; hte = hte->h_link)
                        action(hte);
        }
@@ -178,7 +169,7 @@ symtab_forall_sorted(void (*action)(hte_
        size_t i;
        hte_t **table = htab;
 
-       for (i = 0; i < HSHSIZ2; i++)
+       for (i = 0; i < HTAB_BUCKETS; i++)
                for (hte = table[i]; hte != NULL; hte = hte->h_link)
                        hte_list_add(&sorted, hte);
 
@@ -202,7 +193,7 @@ void
        if (table == NULL)
                err(1, "_destroyhash called on main hash table");
 
-       for (i = 0; i < HSHSIZ2; i++) {
+       for (i = 0; i < HTAB_BUCKETS; i++) {
                for (hte = table[i]; hte != NULL; hte = nexthte) {
                        free(__UNCONST(hte->h_name));
                        nexthte = hte->h_link;
diff -r b3a0e6735d68 -r da85b8774075 usr.bin/xlint/lint2/read.c
--- a/usr.bin/xlint/lint2/read.c        Mon Jul 10 08:55:44 2023 +0000
+++ b/usr.bin/xlint/lint2/read.c        Mon Jul 10 09:51:30 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.83 2023/07/08 11:18:16 rillig Exp $ */
+/* $NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: read.c,v 1.83 2023/07/08 11:18:16 rillig Exp $");
+__RCSID("$NetBSD: read.c,v 1.84 2023/07/10 09:51:30 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -81,7 +81,7 @@ typedef struct thtab {
        unsigned short th_idx;
        struct thtab *th_next;
 } thtab_t;
-static thtab_t **thtab;                /* hash table */
+static thtab_t *thtab[1009];           /* hash table */
 type_t **tlst;                         /* array for indexed access */
 static size_t  tlstlen;                /* length of tlst */
 
@@ -226,8 +226,6 @@ readfile(const char *name)
                flines = xcalloc(nfnames, sizeof(*flines));
        if (tlstlen == 0)
                tlst = xcalloc(tlstlen = 256, sizeof(*tlst));
-       if (thtab == NULL)
-               thtab = xcalloc(THSHSIZ2, sizeof(*thtab));
 
        renametab = htab_new();
 
@@ -993,7 +991,7 @@ thash(const char *s, size_t len)
                v = (v << sizeof(v)) + (unsigned char)*s++;
                v ^= v >> (sizeof(v) * CHAR_BIT - sizeof(v));
        }
-       return v % THSHSIZ2;
+       return v % (sizeof(thtab) / sizeof(thtab[0]));
 }
 
 /*



Home | Main Index | Thread Index | Old Index