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



details:   https://anonhg.NetBSD.org/src/rev/4a066069ab06
branches:  trunk
changeset: 373325:4a066069ab06
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Feb 02 22:23:30 2023 +0000

description:
lint: clean up

In symtab_search, most of the conditions were redundant, so remove them.

In read_byte, using CHAR_MASK was conceptually wrong, as that constant
is from the target platform while the lexical analysis happens on the
host platform.  It was unnecessary as well, as a hypothetical host
platform with 36-bit chars might encode the characters from the basic
source character set as numbers higher than 0x0_0000_00ff.  Since lint
assumes that both the source character set as well as the execution
character set are the same and based on 8-bit bytes, nothing changes.

No functional change.

diffstat:

 usr.bin/xlint/lint1/emit1.c |   8 ++++----
 usr.bin/xlint/lint1/lex.c   |  13 +++++--------
 usr.bin/xlint/lint2/emit2.c |  18 ++++++++----------
 usr.bin/xlint/lint2/msg.c   |   6 ++----
 4 files changed, 19 insertions(+), 26 deletions(-)

diffs (162 lines):

diff -r 59140b52d0ec -r 4a066069ab06 usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Thu Feb 02 14:09:52 2023 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Thu Feb 02 22:23:30 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.64 2022/10/01 09:42:40 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.65 2023/02/02 22:23: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: emit1.c,v 1.64 2022/10/01 09:42:40 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.65 2023/02/02 22:23:30 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -75,14 +75,14 @@
  *     ()                      F
  *     (void)                  F 0
  *     (n parameters)          F n arg1 arg2 ... argn
- *     (n parameters, ...)     F n arg1 arg2 ... argn-1 E
+ *     (n parameters, ...)     F n arg1 arg2 ... argn E
  *     enum tag                e T tag_or_typename
  *     struct tag              s T tag_or_typename
  *     union tag               u T tag_or_typename
  *
  *     tag_or_typename         0 (obsolete)            no tag or type name
  *                             1 n tag                 tagged type
- *                             2 n typename            only type name
+ *                             2 n typename            only typedef name
  *                             3 line.file.uniq        anonymous types
  *
  * spaces are only for better readability
diff -r 59140b52d0ec -r 4a066069ab06 usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Thu Feb 02 14:09:52 2023 +0000
+++ b/usr.bin/xlint/lint1/lex.c Thu Feb 02 22:23:30 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.147 2023/01/29 13:57:35 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.148 2023/02/02 22:23: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.147 2023/01/29 13:57:35 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.148 2023/02/02 22:23:30 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -225,11 +225,9 @@
        for (sym_t *sym = symtab[h]; sym != NULL; sym = sym->s_symtab_next) {
                if (strcmp(sym->s_name, name) != 0)
                        continue;
-
-               const struct keyword *kw = sym->s_keyword;
-               if (kw != NULL || in_gcc_attribute)
-                       return sym;
-               if (kw == NULL && !in_gcc_attribute && sym->s_kind == symtyp)
+               if (sym->s_keyword != NULL ||
+                   sym->s_kind == symtyp ||
+                   in_gcc_attribute)
                        return sym;
        }
 
@@ -411,7 +409,6 @@
 
        if ((c = lex_input()) == EOF)
                return c;
-       c &= CHAR_MASK;
        if (c == '\0')
                return EOF;     /* lex returns 0 on EOF. */
        if (c == '\n')
diff -r 59140b52d0ec -r 4a066069ab06 usr.bin/xlint/lint2/emit2.c
--- a/usr.bin/xlint/lint2/emit2.c       Thu Feb 02 14:09:52 2023 +0000
+++ b/usr.bin/xlint/lint2/emit2.c       Thu Feb 02 22:23:30 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit2.c,v 1.29 2023/01/14 09:30:07 rillig Exp $ */
+/* $NetBSD: emit2.c,v 1.30 2023/02/02 22:23:30 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: emit2.c,v 1.29 2023/01/14 09:30:07 rillig Exp $");
+__RCSID("$NetBSD: emit2.c,v 1.30 2023/02/02 22:23:30 rillig Exp $");
 #endif
 
 #include "lint2.h"
@@ -57,12 +57,10 @@
        static const char tt[NTSPEC] = "???BCCCSSIILLQQDDDVTTTPAF?XXX";
        static const char ss[NTSPEC] = "???  su u u u us l sue   ?s l";
 #endif
-       int     na;
-       tspec_t ts;
-       type_t  **ap;
 
        while (tp != NULL) {
-               if ((ts = tp->t_tspec) == INT && tp->t_is_enum)
+               tspec_t ts = tp->t_tspec;
+               if (ts == INT && tp->t_is_enum)
                        ts = ENUM;
                if (!ch_isupper(tt[ts]))
                        errx(1, "internal error: outtype(%d)", ts);
@@ -96,13 +94,13 @@
                        } else
                                errx(1, "internal error: outtype");
                } else if (ts == FUNC && tp->t_args != NULL) {
-                       na = 0;
-                       for (ap = tp->t_args; *ap != NULL; ap++)
+                       int na = 0;
+                       for (type_t **ap = tp->t_args; *ap != NULL; ap++)
                                na++;
                        if (tp->t_vararg)
                                na++;
                        outint(na);
-                       for (ap = tp->t_args; *ap != NULL; ap++)
+                       for (type_t **ap = tp->t_args; *ap != NULL; ap++)
                                outtype(*ap);
                        if (tp->t_vararg)
                                outchar('E');
@@ -175,7 +173,7 @@
                return;
 
        /*
-        * If there is a definition, write it. Otherwise write a tentative
+        * If there is a definition, write it. Otherwise, write a tentative
         * definition. This is necessary because more than one tentative
         * definition is allowed (except with sflag).
         */
diff -r 59140b52d0ec -r 4a066069ab06 usr.bin/xlint/lint2/msg.c
--- a/usr.bin/xlint/lint2/msg.c Thu Feb 02 14:09:52 2023 +0000
+++ b/usr.bin/xlint/lint2/msg.c Thu Feb 02 22:23:30 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg.c,v 1.17 2022/05/20 21:18:55 rillig Exp $  */
+/*     $NetBSD: msg.c,v 1.18 2023/02/02 22:23:30 rillig Exp $  */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: msg.c,v 1.17 2022/05/20 21:18:55 rillig Exp $");
+__RCSID("$NetBSD: msg.c,v 1.18 2023/02/02 22:23:30 rillig Exp $");
 #endif
 
 #include <stdarg.h>
@@ -68,8 +68,6 @@
        "%s renamed multiple times  \t%s  ::  %s",                    /* 18 */
 };
 
-static const   char *lbasename(const char *);
-
 void
 msg(int n, ...)
 {



Home | Main Index | Thread Index | Old Index