Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: disambiguate sym_t.s_value



details:   https://anonhg.NetBSD.org/src/rev/9d258eff973c
branches:  trunk
changeset: 365134:9d258eff973c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 09 15:43:41 2022 +0000

description:
lint: disambiguate sym_t.s_value

Having a single variable for 4 different purposes with different types
makes the code unnecessarily hard to follow.

No functional change.

diffstat:

 usr.bin/xlint/lint1/Makefile |   3 +--
 usr.bin/xlint/lint1/cgram.y  |   6 +++---
 usr.bin/xlint/lint1/ckbool.c |  12 ++++--------
 usr.bin/xlint/lint1/debug.c  |  27 ++++++++++++++++-----------
 usr.bin/xlint/lint1/decl.c   |  26 +++++++++++++-------------
 usr.bin/xlint/lint1/lex.c    |  16 ++++++++--------
 usr.bin/xlint/lint1/lint1.h  |  25 ++++++++++++++++---------
 usr.bin/xlint/lint1/tree.c   |  41 ++++++++++++++++++++++++++---------------
 8 files changed, 87 insertions(+), 69 deletions(-)

diffs (truncated from 429 to 300 lines):

diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.89 2022/04/09 14:50:18 rillig Exp $
+#      $NetBSD: Makefile,v 1.90 2022/04/09 15:43:41 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -58,7 +58,6 @@
 
 # Extra -UYYDEBUG since cgram.c contains 'int yydebug; if (yydebug)'.
 cgram.ln: cgram.c
-       : extra
        ${LINT} ${LINTFLAGS} \
            ${CPPFLAGS:C/-([IDUW]) */-\1/Wg:M-[IDUW]*} \
            -i -UYYDEBUG ${.IMPSRC}
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 15:43:41 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.390 2022/04/09 14:50:18 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.391 2022/04/09 15:43:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.390 2022/04/09 14:50:18 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.391 2022/04/09 15:43:41 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -114,7 +114,7 @@
 anonymize(sym_t *s)
 {
        for ( ; s != NULL; s = s->s_next)
-               s->u.s_sou_type = NULL;
+               s->u.s_member.sm_sou_type = NULL;
 }
 
 #if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.11 2022/04/09 14:50:18 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.12 2022/04/09 15:43:41 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckbool.c,v 1.11 2022/04/09 14:50:18 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.12 2022/04/09 15:43:41 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -243,18 +243,14 @@
        if (Tflag && strcmp(sym->s_name, "__lint_false") == 0) {
                sym->s_scl = BOOL_CONST;
                sym->s_type = gettyp(BOOL);
-               sym->s_value.v_tspec = BOOL;
-               sym->s_value.v_unsigned_since_c90 = false;
-               sym->s_value.v_quad = 0;
+               sym->u.s_bool_constant = false;
                return true;
        }
 
        if (Tflag && strcmp(sym->s_name, "__lint_true") == 0) {
                sym->s_scl = BOOL_CONST;
                sym->s_type = gettyp(BOOL);
-               sym->s_value.v_tspec = BOOL;
-               sym->s_value.v_unsigned_since_c90 = false;
-               sym->s_value.v_quad = 1;
+               sym->u.s_bool_constant = true;
                return true;
        }
 
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.13 2022/04/09 14:50:18 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.14 2022/04/09 15:43:41 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.13 2022/04/09 14:50:18 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.14 2022/04/09 15:43:41 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -271,14 +271,17 @@
                debug_printf(" used-at=%s:%d",
                    sym->s_use_pos.p_file, sym->s_use_pos.p_line);
 
-       if (sym->s_type != NULL &&
-           (sym->s_type->t_is_enum || sym->s_type->t_tspec == BOOL))
-               debug_printf(" value=%d", (int)sym->s_value.v_quad);
+       if (sym->s_type != NULL && sym->s_type->t_is_enum)
+               debug_printf(" value=%d", sym->u.s_enum_constant);
+       if (sym->s_type != NULL && sym->s_type->t_tspec == BOOL)
+               debug_printf(" value=%s",
+                   sym->u.s_bool_constant ? "true" : "false");
 
        if ((sym->s_scl == MOS || sym->s_scl == MOU) &&
-           sym->u.s_sou_type != NULL) {
-               const char *tag = sym->u.s_sou_type->sou_tag->s_name;
-               const sym_t *def = sym->u.s_sou_type->sou_first_typedef;
+           sym->u.s_member.sm_sou_type != NULL) {
+               struct_or_union *sou_type = sym->u.s_member.sm_sou_type;
+               const char *tag = sou_type->sou_tag->s_name;
+               const sym_t *def = sou_type->sou_first_typedef;
                if (tag == unnamed && def != NULL)
                        debug_printf(" sou='typedef %s'", def->s_name);
                else
@@ -286,11 +289,13 @@
        }
 
        if (sym->s_keyword != NULL) {
-               int t = (int)sym->s_value.v_quad;
+               int t = sym->u.s_keyword.sk_token;
                if (t == T_TYPE || t == T_STRUCT_OR_UNION)
-                       debug_printf(" %s", tspec_name(sym->u.s_tspec));
+                       debug_printf(" %s",
+                           tspec_name(sym->u.s_keyword.sk_tspec));
                else if (t == T_QUAL)
-                       debug_printf(" %s", tqual_name(sym->u.s_qualifier));
+                       debug_printf(" %s",
+                           tqual_name(sym->u.s_keyword.sk_qualifier));
        }
 
        debug_word(sym->s_osdef && sym->u.s_old_style_args != NULL,
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.272 2022/04/09 14:50:18 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.273 2022/04/09 15:43:41 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: decl.c,v 1.272 2022/04/09 14:50:18 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.273 2022/04/09 15:43:41 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1130,8 +1130,8 @@
                lint_assert(dcs->d_redeclared_symbol->s_scl == MOS ||
                    dcs->d_redeclared_symbol->s_scl == MOU);
 
-               if (dsym->u.s_sou_type ==
-                   dcs->d_redeclared_symbol->u.s_sou_type) {
+               if (dsym->u.s_member.sm_sou_type ==
+                   dcs->d_redeclared_symbol->u.s_member.sm_sou_type) {
                        /* duplicate member name: %s */
                        error(33, dsym->s_name);
                        rmsym(dcs->d_redeclared_symbol);
@@ -1168,13 +1168,14 @@
        }
        if (dsym->s_bitfield) {
                align(alignment_in_bits(tp), tp->t_flen);
-               dsym->s_value.v_quad =
+               dsym->u.s_member.sm_offset_in_bits =
                    dcs->d_offset - dcs->d_offset % size_in_bits(t);
-               tp->t_foffs = dcs->d_offset - (int)dsym->s_value.v_quad;
+               tp->t_foffs =
+                   dcs->d_offset - dsym->u.s_member.sm_offset_in_bits;
                dcs->d_offset += tp->t_flen;
        } else {
                align(alignment_in_bits(tp), 0);
-               dsym->s_value.v_quad = dcs->d_offset;
+               dsym->u.s_member.sm_offset_in_bits = dcs->d_offset;
                dcs->d_offset += sz;
        }
        if (dcs->d_ctx == MOU) {
@@ -1575,9 +1576,9 @@
        case MOS:
        case MOU:
                /* Set parent */
-               sym->u.s_sou_type = dcs->d_tagtyp->t_str;
+               sym->u.s_member.sm_sou_type = dcs->d_tagtyp->t_str;
                sym->s_def = DEF;
-               sym->s_value.v_tspec = INT;
+               /* XXX: Where is sym->u.s_member.sm_offset_in_bits set? */
                sc = dcs->d_ctx;
                break;
        case EXTERN:
@@ -1858,8 +1859,8 @@
        n = 0;
        for (mem = fmem; mem != NULL; mem = mem->s_next) {
                /* bind anonymous members to the structure */
-               if (mem->u.s_sou_type == NULL) {
-                       mem->u.s_sou_type = sp;
+               if (mem->u.s_member.sm_sou_type == NULL) {
+                       mem->u.s_member.sm_sou_type = sp;
                        if (mem->s_type->t_bitfield) {
                                sp->sou_size_in_bits += bitfieldsize(&mem);
                                if (mem == NULL)
@@ -1925,8 +1926,7 @@
        }
        sym->s_scl = ENUM_CONST;
        sym->s_type = dcs->d_tagtyp;
-       sym->s_value.v_tspec = INT;
-       sym->s_value.v_quad = val;
+       sym->u.s_enum_constant = val;
        if (impl && val == TARG_INT_MIN) {
                /* overflow in enumeration values: %s */
                warning(48, sym->s_name);
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.116 2022/04/09 13:38:17 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.117 2022/04/09 15:43:41 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.116 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.117 2022/04/09 15:43:41 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -393,13 +393,13 @@
        sym = block_zero_alloc(sizeof(*sym));
        sym->s_name = name;
        sym->s_keyword = kw;
-       sym->s_value.v_quad = kw->kw_token;
+       sym->u.s_keyword.sk_token = kw->kw_token;
        if (kw->kw_token == T_TYPE || kw->kw_token == T_STRUCT_OR_UNION) {
-               sym->u.s_tspec = kw->kw_tspec;
+               sym->u.s_keyword.sk_tspec = kw->kw_tspec;
        } else if (kw->kw_token == T_SCLASS) {
                sym->s_scl = kw->kw_scl;
        } else if (kw->kw_token == T_QUAL) {
-               sym->u.s_qualifier = kw->kw_tqual;
+               sym->u.s_keyword.sk_qualifier = kw->kw_tqual;
        }
 
        symtab_add(sym);
@@ -454,12 +454,12 @@
 {
        int     t;
 
-       if ((t = (int)sym->s_value.v_quad) == T_SCLASS) {
+       if ((t = sym->u.s_keyword.sk_token) == T_SCLASS) {
                yylval.y_scl = sym->s_scl;
        } else if (t == T_TYPE || t == T_STRUCT_OR_UNION) {
-               yylval.y_tspec = sym->u.s_tspec;
+               yylval.y_tspec = sym->u.s_keyword.sk_tspec;
        } else if (t == T_QUAL) {
-               yylval.y_tqual = sym->u.s_qualifier;
+               yylval.y_tqual = sym->u.s_keyword.sk_qualifier;
        }
        return t;
 }
diff -r 63a32054147d -r 9d258eff973c usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 14:50:18 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 15:43:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.146 2022/04/09 14:50:18 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.147 2022/04/09 15:43:41 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -244,14 +244,21 @@
        int     s_block_level;  /* level of declaration, -1 if not in symbol
                                   table */
        type_t  *s_type;
-       val_t   s_value;        /* value (if enum or bool constant) */
        union {
-               /* XXX: what is the difference to s_type->t_str? */
-               struct_or_union *s_sou_type;
-               tspec_t s_tspec;        /* type (only for keywords) */
-               tqual_t s_qualifier;    /* qualifier (only for keywords) */
-               struct  sym *s_old_style_args; /* arguments in old style
-                                       * function definitions */
+               bool s_bool_constant;
+               int s_enum_constant;    /* XXX: should be TARG_INT */
+               struct {
+                       /* XXX: what is the difference to s_type->t_str? */
+                       struct_or_union *sm_sou_type;



Home | Main Index | Thread Index | Old Index