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: inline member access macros for sym_t



details:   https://anonhg.NetBSD.org/src/rev/784d9d9f2458
branches:  trunk
changeset: 365130:784d9d9f2458
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 09 13:38:17 2022 +0000

description:
lint: inline member access macros for sym_t

Having the 'u.' explicitly in the code serves as a reminder that these
members are only defined under certain conditions.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y |   6 +++---
 usr.bin/xlint/lint1/debug.c |  17 +++++++++--------
 usr.bin/xlint/lint1/decl.c  |  31 +++++++++++++++++--------------
 usr.bin/xlint/lint1/func.c  |   6 +++---
 usr.bin/xlint/lint1/lex.c   |  12 ++++++------
 usr.bin/xlint/lint1/lint1.h |  17 ++++++-----------
 usr.bin/xlint/lint1/tree.c  |  14 +++++++-------
 7 files changed, 51 insertions(+), 52 deletions(-)

diffs (truncated from 342 to 300 lines):

diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 13:38:17 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.388 2022/03/09 00:20:48 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.389 2022/04/09 13:38:17 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.388 2022/03/09 00:20:48 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.389 2022/04/09 13:38:17 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -114,7 +114,7 @@
 anonymize(sym_t *s)
 {
        for ( ; s != NULL; s = s->s_next)
-               s->s_sou_type = NULL;
+               s->u.s_sou_type = NULL;
 }
 
 #if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Apr 09 13:38:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.11 2022/04/02 14:28:30 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.12 2022/04/09 13:38:17 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.11 2022/04/02 14:28:30 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.12 2022/04/09 13:38:17 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -275,9 +275,9 @@
                debug_printf(" value=%d", (int)sym->s_value.v_quad);
 
        if ((sym->s_scl == MOS || sym->s_scl == MOU) &&
-           sym->s_sou_type != NULL) {
-               const char *tag = sym->s_sou_type->sou_tag->s_name;
-               const sym_t *def = sym->s_sou_type->sou_first_typedef;
+           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;
                if (tag == unnamed && def != NULL)
                        debug_printf(" sou='typedef %s'", def->s_name);
                else
@@ -287,12 +287,13 @@
        if (sym->s_keyword != NULL) {
                int t = (int)sym->s_value.v_quad;
                if (t == T_TYPE || t == T_STRUCT_OR_UNION)
-                       debug_printf(" %s", tspec_name(sym->s_tspec));
+                       debug_printf(" %s", tspec_name(sym->u.s_tspec));
                else if (t == T_QUAL)
-                       debug_printf(" %s", tqual_name(sym->s_tqual));
+                       debug_printf(" %s", tqual_name(sym->u.s_qualifier));
        }
 
-       debug_word(sym->s_osdef && sym->s_args != NULL, "old-style-args");
+       debug_word(sym->s_osdef && sym->u.s_old_style_args != NULL,
+           "old-style-args");
 
        debug_printf("%s", suffix);
 }
diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 09 13:38:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.270 2022/04/09 13:22:05 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.271 2022/04/09 13:38:17 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.270 2022/04/09 13:22:05 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.271 2022/04/09 13:38:17 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1130,7 +1130,8 @@
                lint_assert(dcs->d_redeclared_symbol->s_scl == MOS ||
                    dcs->d_redeclared_symbol->s_scl == MOU);
 
-               if (dsym->s_sou_type == dcs->d_redeclared_symbol->s_sou_type) {
+               if (dsym->u.s_sou_type ==
+                   dcs->d_redeclared_symbol->u.s_sou_type) {
                        /* duplicate member name: %s */
                        error(33, dsym->s_name);
                        rmsym(dcs->d_redeclared_symbol);
@@ -1521,7 +1522,7 @@
                 */
                if (args != NULL) {
                        decl->s_osdef = true;
-                       decl->s_args = args;
+                       decl->u.s_old_style_args = args;
                }
        } else {
                if (args != NULL)
@@ -1545,7 +1546,7 @@
                        error(22);
                }
                sym->s_osdef = false;
-               sym->s_args = NULL;
+               sym->u.s_old_style_args = NULL;
        }
 }
 
@@ -1574,7 +1575,7 @@
        case MOS:
        case MOU:
                /* Set parent */
-               sym->s_sou_type = dcs->d_tagtyp->t_str;
+               sym->u.s_sou_type = dcs->d_tagtyp->t_str;
                sym->s_def = DEF;
                sym->s_value.v_tspec = INT;
                sc = dcs->d_ctx;
@@ -1857,8 +1858,8 @@
        n = 0;
        for (mem = fmem; mem != NULL; mem = mem->s_next) {
                /* bind anonymous members to the structure */
-               if (mem->s_sou_type == NULL) {
-                       mem->s_sou_type = sp;
+               if (mem->u.s_sou_type == NULL) {
+                       mem->u.s_sou_type = sp;
                        if (mem->s_type->t_bitfield) {
                                sp->sou_size_in_bits += bitfieldsize(&mem);
                                if (mem == NULL)
@@ -1993,8 +1994,9 @@
 
                /*
                 * If the old symbol stems from an old style function
-                * definition, we have remembered the params in rdsym->s_args
-                * and compare them with the params of the prototype.
+                * definition, we have remembered the params in
+                * rdsym->s_old_style_args and compare them with the params
+                * of the prototype.
                 */
                if (rdsym->s_osdef && dsym->s_type->t_proto) {
                        redec = check_old_style_definition(rdsym, dsym);
@@ -2021,7 +2023,8 @@
                         */
                        if (rdsym->s_osdef && !dsym->s_type->t_proto) {
                                dsym->s_osdef = rdsym->s_osdef;
-                               dsym->s_args = rdsym->s_args;
+                               dsym->u.s_old_style_args =
+                                   rdsym->u.s_old_style_args;
                                dsym->s_def_pos = rdsym->s_def_pos;
                        }
 
@@ -2347,7 +2350,7 @@
        int     narg, nparg, n;
        bool    dowarn, msg;
 
-       args = rdsym->s_args;
+       args = rdsym->u.s_old_style_args;
        pargs = dsym->s_type->t_args;
 
        msg = false;
@@ -2576,7 +2579,7 @@
        int narg, nparg;
        bool msg;
 
-       args = funcsym->s_args;
+       args = funcsym->u.s_old_style_args;
        pargs = funcsym->s_type->t_args;
 
        /*
@@ -2627,7 +2630,7 @@
 
                /* from now on the prototype is valid */
                funcsym->s_osdef = false;
-               funcsym->s_args = NULL;
+               funcsym->u.s_old_style_args = NULL;
        }
 }
 
diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/func.c        Sat Apr 09 13:38:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.130 2022/04/02 20:12:46 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.131 2022/04/09 13:38:17 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.130 2022/04/02 20:12:46 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.131 2022/04/09 13:38:17 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -248,7 +248,7 @@
         * style function definition or only an old style declaration,
         * if there are no arguments inside the argument list ("f()").
         */
-       if (!fsym->s_type->t_proto && fsym->s_args == NULL)
+       if (!fsym->s_type->t_proto && fsym->u.s_old_style_args == NULL)
                fsym->s_osdef = true;
 
        check_type(fsym);
diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sat Apr 09 13:38:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.115 2022/04/02 14:28:30 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.116 2022/04/09 13:38:17 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.115 2022/04/02 14:28:30 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.116 2022/04/09 13:38:17 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -395,11 +395,11 @@
        sym->s_keyword = kw;
        sym->s_value.v_quad = kw->kw_token;
        if (kw->kw_token == T_TYPE || kw->kw_token == T_STRUCT_OR_UNION) {
-               sym->s_tspec = kw->kw_tspec;
+               sym->u.s_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->s_tqual = kw->kw_tqual;
+               sym->u.s_qualifier = kw->kw_tqual;
        }
 
        symtab_add(sym);
@@ -457,9 +457,9 @@
        if ((t = (int)sym->s_value.v_quad) == T_SCLASS) {
                yylval.y_scl = sym->s_scl;
        } else if (t == T_TYPE || t == T_STRUCT_OR_UNION) {
-               yylval.y_tspec = sym->s_tspec;
+               yylval.y_tspec = sym->u.s_tspec;
        } else if (t == T_QUAL) {
-               yylval.y_tqual = sym->s_tqual;
+               yylval.y_tqual = sym->u.s_qualifier;
        }
        return t;
 }
diff -r 891a129c76a5 -r 784d9d9f2458 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 13:38:15 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 13:38:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.144 2022/04/02 22:15:57 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.145 2022/04/09 13:38:17 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -246,11 +246,11 @@
        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_st;
-               tspec_t _s_tsp; /* type (only for keywords) */
-               tqual_t _s_tqu; /* qualifier (only for keywords) */
-               struct  sym *_s_args; /* arguments in old style function
-                                        definitions */
+               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 */
        } u;
        struct  sym *s_symtab_next;     /* next symbol with same hash value */
        struct  sym **s_symtab_ref;     /* pointer to s_symtab_next of the
@@ -261,11 +261,6 @@
                                         * level */
 } sym_t;
 
-#define        s_sou_type      u._s_st
-#define        s_tspec u._s_tsp
-#define        s_tqual u._s_tqu
-#define        s_args  u._s_args
-
 /*
  * Used to keep some information about symbols before they are entered
  * into the symbol table.



Home | Main Index | Thread Index | Old Index