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: split CTCONST into BOOL_CONST and ...



details:   https://anonhg.NetBSD.org/src/rev/63a32054147d
branches:  trunk
changeset: 365133:63a32054147d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 09 14:50:18 2022 +0000

description:
lint: split CTCONST into BOOL_CONST and ENUM_CONST

Having a unified compile-time constant "storage class" made the code
more difficult to understand.

No functional change.

diffstat:

 usr.bin/xlint/lint1/Makefile |   9 ++++++++-
 usr.bin/xlint/lint1/cgram.y  |   6 +++---
 usr.bin/xlint/lint1/ckbool.c |   8 ++++----
 usr.bin/xlint/lint1/debug.c  |   7 ++++---
 usr.bin/xlint/lint1/decl.c   |  22 ++++++++++++----------
 usr.bin/xlint/lint1/lint1.h  |   5 +++--
 usr.bin/xlint/lint1/tree.c   |   6 +++---
 7 files changed, 37 insertions(+), 26 deletions(-)

diffs (232 lines):

diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile      Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/Makefile      Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.88 2021/12/21 15:27:19 roy Exp $
+#      $NetBSD: Makefile,v 1.89 2022/04/09 14:50:18 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -56,6 +56,13 @@
            -e 1q \
            ${.ALLSRC} > ${.TARGET}
 
+# 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}
+
 ${MAN}:                makeman ${LINT1:./%=%} Makefile ${MAN}.date
        ${_MKTARGET_CREATE}
        ${HOST_SH} ${.ALLSRC:M*makeman} "$$(cat ${.ALLSRC:M*.date})" ${LINT1} -m >${.TARGET}
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 14:50:18 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.389 2022/04/09 13:38:17 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.390 2022/04/09 14:50:18 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.389 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.390 2022/04/09 14:50:18 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1069,7 +1069,7 @@
 enum:                          /* helper for C99 6.7.2.2 */
          T_ENUM {
                symtyp = FTAG;
-               begin_declaration_level(CTCONST);
+               begin_declaration_level(ENUM_CONST);
          }
        ;
 
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/ckbool.c
--- a/usr.bin/xlint/lint1/ckbool.c      Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/ckbool.c      Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.10 2021/12/22 15:36:37 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.11 2022/04/09 14:50:18 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.10 2021/12/22 15:36:37 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.11 2022/04/09 14:50:18 rillig Exp $");
 #endif
 
 #include <string.h>
@@ -241,7 +241,7 @@
 fallback_symbol_strict_bool(sym_t *sym)
 {
        if (Tflag && strcmp(sym->s_name, "__lint_false") == 0) {
-               sym->s_scl = CTCONST; /* close enough */
+               sym->s_scl = BOOL_CONST;
                sym->s_type = gettyp(BOOL);
                sym->s_value.v_tspec = BOOL;
                sym->s_value.v_unsigned_since_c90 = false;
@@ -250,7 +250,7 @@
        }
 
        if (Tflag && strcmp(sym->s_name, "__lint_true") == 0) {
-               sym->s_scl = CTCONST; /* close enough */
+               sym->s_scl = BOOL_CONST;
                sym->s_type = gettyp(BOOL);
                sym->s_value.v_tspec = BOOL;
                sym->s_value.v_unsigned_since_c90 = false;
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.12 2022/04/09 13:38:17 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.13 2022/04/09 14:50:18 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.12 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.13 2022/04/09 14:50:18 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -191,7 +191,8 @@
                "enum",
                "member-of-struct",
                "member-of-union",
-               "compile-time-constant",
+               "bool-constant",
+               "enum-constant",
                "abstract",
                "old-style-function-argument",
                "prototype-argument",
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.271 2022/04/09 13:38:17 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.272 2022/04/09 14:50:18 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.271 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.272 2022/04/09 14:50:18 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -603,7 +603,7 @@
        switch (di->d_ctx) {
        case MOS:
        case MOU:
-       case CTCONST:
+       case ENUM_CONST:
                /*
                 * Symbols declared in (nested) structs or enums are
                 * part of the next level (they are removed from the
@@ -1923,7 +1923,7 @@
                }
                sym = pushdown(sym);
        }
-       sym->s_scl = CTCONST;
+       sym->s_scl = ENUM_CONST;
        sym->s_type = dcs->d_tagtyp;
        sym->s_value.v_tspec = INT;
        sym->s_value.v_quad = val;
@@ -2115,7 +2115,8 @@
 {
        sym_t   *rsym;
 
-       if ((rsym = dcs->d_redeclared_symbol)->s_scl == CTCONST) {
+       rsym = dcs->d_redeclared_symbol;
+       if (rsym->s_scl == ENUM_CONST) {
                /* redeclaration of %s */
                error(27, dsym->s_name);
                print_previous_declaration(-1, rsym);
@@ -3275,18 +3276,19 @@
 static void
 check_global_variable(const sym_t *sym)
 {
-
-       if (sym->s_scl == TYPEDEF || sym->s_scl == CTCONST)
+       scl_t scl = sym->s_scl;
+
+       if (scl == TYPEDEF || scl == BOOL_CONST || scl == ENUM_CONST)
                return;
 
-       if (sym->s_scl == NOSCL)
+       if (scl == NOSCL)
                return;         /* May be caused by a syntax error. */
 
-       lint_assert(sym->s_scl == EXTERN || sym->s_scl == STATIC);
+       lint_assert(scl == EXTERN || scl == STATIC);
 
        check_global_variable_size(sym);
 
-       if (sym->s_scl == STATIC)
+       if (scl == STATIC)
                check_static_global_variable(sym);
 }
 
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.145 2022/04/09 13:38:17 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.146 2022/04/09 14:50:18 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -203,7 +203,8 @@
        ENUM_TAG,
        MOS,            /* member of struct */
        MOU,            /* member of union */
-       CTCONST,        /* enumerator, enum constant or bool constant */
+       BOOL_CONST,
+       ENUM_CONST,
        ABSTRACT,       /* abstract symbol (sizeof, casts, unnamed argument) */
        OLD_STYLE_ARG,  /* old-style function argument declarations */
        PROTO_ARG,      /* used in declaration stack during prototype
diff -r 4651ec9c71a2 -r 63a32054147d usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sat Apr 09 14:38:47 2022 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sat Apr 09 14:50:18 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.420 2022/04/09 13:38:17 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.421 2022/04/09 14:50:18 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.420 2022/04/09 13:38:17 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.421 2022/04/09 14:50:18 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -279,7 +279,7 @@
 
        n = expr_alloc_tnode();
        n->tn_type = sym->s_type;
-       if (sym->s_scl == CTCONST) {
+       if (sym->s_scl == BOOL_CONST || sym->s_scl == ENUM_CONST) {
                n->tn_op = CON;
                n->tn_val = expr_zero_alloc(sizeof(*n->tn_val));
                *n->tn_val = sym->s_value;



Home | Main Index | Thread Index | Old Index