Module Name: src
Committed By: rillig
Date: Thu Feb 2 22:23:30 UTC 2023
Modified Files:
src/usr.bin/xlint/lint1: emit1.c lex.c
src/usr.bin/xlint/lint2: emit2.c msg.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.147 -r1.148 src/usr.bin/xlint/lint1/lex.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/lint2/emit2.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/lint2/msg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.64 src/usr.bin/xlint/lint1/emit1.c:1.65
--- src/usr.bin/xlint/lint1/emit1.c:1.64 Sat Oct 1 09:42:40 2022
+++ src/usr.bin/xlint/lint1/emit1.c Thu Feb 2 22:23:30 2023
@@ -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 @@ static void outfstrg(strg_t *);
* () 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
Index: src/usr.bin/xlint/lint1/lex.c
diff -u src/usr.bin/xlint/lint1/lex.c:1.147 src/usr.bin/xlint/lint1/lex.c:1.148
--- src/usr.bin/xlint/lint1/lex.c:1.147 Sun Jan 29 13:57:35 2023
+++ src/usr.bin/xlint/lint1/lex.c Thu Feb 2 22:23:30 2023
@@ -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 @@ symtab_search(const char *name)
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 @@ read_byte(void)
if ((c = lex_input()) == EOF)
return c;
- c &= CHAR_MASK;
if (c == '\0')
return EOF; /* lex returns 0 on EOF. */
if (c == '\n')
Index: src/usr.bin/xlint/lint2/emit2.c
diff -u src/usr.bin/xlint/lint2/emit2.c:1.29 src/usr.bin/xlint/lint2/emit2.c:1.30
--- src/usr.bin/xlint/lint2/emit2.c:1.29 Sat Jan 14 09:30:07 2023
+++ src/usr.bin/xlint/lint2/emit2.c Thu Feb 2 22:23:30 2023
@@ -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 @@ outtype(type_t *tp)
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 @@ outtype(type_t *tp)
} 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 @@ dumpname(hte_t *hte)
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).
*/
Index: src/usr.bin/xlint/lint2/msg.c
diff -u src/usr.bin/xlint/lint2/msg.c:1.17 src/usr.bin/xlint/lint2/msg.c:1.18
--- src/usr.bin/xlint/lint2/msg.c:1.17 Fri May 20 21:18:55 2022
+++ src/usr.bin/xlint/lint2/msg.c Thu Feb 2 22:23:30 2023
@@ -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 @@ static const char *msgs[] = {
"%s renamed multiple times \t%s :: %s", /* 18 */
};
-static const char *lbasename(const char *);
-
void
msg(int n, ...)
{