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: save some memory



details:   https://anonhg.NetBSD.org/src/rev/b0912c53a713
branches:  trunk
changeset: 1023069:b0912c53a713
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 22 13:01:47 2021 +0000

description:
lint: save some memory

Before lint1.h 1.47 from 2021-01-02, adjacent bit-field struct members
shared storage.  Restore that using smaller types.

No functional change.

diffstat:

 usr.bin/xlint/lint1/lex.c   |  45 +++++++++++++++++++--------------------------
 usr.bin/xlint/lint1/lint1.h |   6 +++---
 usr.bin/xlint/lint2/lint2.h |   4 ++--
 3 files changed, 24 insertions(+), 31 deletions(-)

diffs (140 lines):

diff -r 1f32c8a76de4 -r b0912c53a713 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Aug 22 12:32:13 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Aug 22 13:01:47 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.65 2021/08/19 21:13:58 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.66 2021/08/22 13:01:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: lex.c,v 1.65 2021/08/19 21:13:58 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.66 2021/08/22 13:01:47 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -100,7 +100,8 @@
 #define kwdef(name, token, scl, tspec, tqual,  c89, c99, gcc, attr, deco) \
        { \
                name, token, scl, tspec, tqual, \
-               (c89) > 0, (c99) > 0, (gcc) > 0, (attr) > 0, deco, \
+               (c89) > 0, (c99) > 0, (gcc) > 0, (attr) > 0, \
+               ((deco) & 1) != 0, ((deco) & 2) != 0, ((deco) & 4) != 0, \
        }
 #define kwdef_token(name, token,               c89, c99, gcc, attr, deco) \
        kwdef(name, token, 0, 0, 0,             c89, c99, gcc, attr, deco)
@@ -130,7 +131,9 @@
        bool    kw_c99 : 1;     /* C99 keyword */
        bool    kw_gcc : 1;     /* GCC keyword */
        bool    kw_attr : 1;    /* GCC attribute, keyword */
-       u_int   kw_deco : 3;    /* 1 = name, 2 = __name, 4 = __name__ */
+       bool    kw_plain : 1;   /* 'name' */
+       bool    kw_leading : 1; /* '__name' */
+       bool    kw_both : 1;    /* '__name__' */
 } kwtab[] = {
        kwdef_gcc_attr( "alias",        T_AT_ALIAS),
        kwdef_keyword(  "_Alignas",     T_ALIGNAS),
@@ -282,33 +285,20 @@
 
 
 static void
-add_keyword(const struct kwtab *kw, u_int deco)
+add_keyword(const struct kwtab *kw, bool leading, bool trailing)
 {
        sym_t *sym;
        char buf[256];
        const char *name;
 
-       if ((kw->kw_deco & deco) == 0)
-               return;
-
-       switch (deco) {
-       case 1:
+       if (!leading && !trailing) {
                name = kw->kw_name;
-               break;
-       case 2:
-               snprintf(buf, sizeof(buf), "__%s", kw->kw_name);
-               name = strdup(buf);
-               break;
-       default:
-               lint_assert(deco == 4);
-               snprintf(buf, sizeof(buf), "__%s__", kw->kw_name);
-               name = strdup(buf);
-               break;
+       } else {
+               snprintf(buf, sizeof(buf), "%s%s%s",
+                   leading ? "__" : "", kw->kw_name, trailing ? "__" : "");
+               name = xstrdup(buf);
        }
 
-       if (name == NULL)
-               err(1, "Can't init symbol table");
-
        sym = getblk(sizeof(*sym));
        sym->s_name = name;
        sym->s_keyword = kw;
@@ -340,9 +330,12 @@
                        continue;
                if (kw->kw_gcc && !gflag)
                        continue;
-               add_keyword(kw, 1);
-               add_keyword(kw, 2);
-               add_keyword(kw, 4);
+               if (kw->kw_plain)
+                       add_keyword(kw, false, false);
+               if (kw->kw_leading)
+                       add_keyword(kw, true, false);
+               if (kw->kw_both)
+                       add_keyword(kw, true, true);
        }
 }
 
diff -r 1f32c8a76de4 -r b0912c53a713 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Aug 22 12:32:13 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Aug 22 13:01:47 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.121 2021/08/01 08:03:43 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.122 2021/08/22 13:01:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -135,7 +135,7 @@
  */
 typedef        struct {
        u_int   sou_size_in_bits;
-       u_int   sou_align_in_bits : 15;
+       u_short sou_align_in_bits;
        bool    sou_incomplete : 1;
        struct  sym *sou_first_member;
        struct  sym *sou_tag;
@@ -362,7 +362,7 @@
                                   for all declarators */
        sym_t   *d_redeclared_symbol;
        u_int   d_offset;       /* offset of next structure member */
-       u_int   d_sou_align_in_bits; /* alignment required for current
+       u_short d_sou_align_in_bits; /* alignment required for current
                                 * structure */
        scl_t   d_ctx;          /* context of declaration */
        bool    d_const : 1;    /* const in declaration specifiers */
diff -r 1f32c8a76de4 -r b0912c53a713 usr.bin/xlint/lint2/lint2.h
--- a/usr.bin/xlint/lint2/lint2.h       Sun Aug 22 12:32:13 2021 +0000
+++ b/usr.bin/xlint/lint2/lint2.h       Sun Aug 22 13:01:47 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint2.h,v 1.15 2021/08/22 12:15:37 rillig Exp $ */
+/* $NetBSD: lint2.h,v 1.16 2021/08/22 13:01:47 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -115,7 +115,7 @@
        struct {
                pos_t   s_pos;          /* pos of def./decl. */
 #ifndef lint
-               u_int   s_def : 3;      /* DECL, TDEF or DEF */
+               u_char  s_def;          /* DECL, TDEF or DEF */
 #else
                def_t   s_def;
 #endif



Home | Main Index | Thread Index | Old Index