Module Name: src
Committed By: rillig
Date: Sat Apr 9 14:50:18 UTC 2022
Modified Files:
src/usr.bin/xlint/lint1: Makefile cgram.y ckbool.c debug.c decl.c
lint1.h tree.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.389 -r1.390 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.271 -r1.272 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.145 -r1.146 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.420 -r1.421 src/usr.bin/xlint/lint1/tree.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/Makefile
diff -u src/usr.bin/xlint/lint1/Makefile:1.88 src/usr.bin/xlint/lint1/Makefile:1.89
--- src/usr.bin/xlint/lint1/Makefile:1.88 Tue Dec 21 15:27:19 2021
+++ src/usr.bin/xlint/lint1/Makefile Sat Apr 9 14:50:18 2022
@@ -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 @@ ${MAN}.date: err.c
-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}
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.389 src/usr.bin/xlint/lint1/cgram.y:1.390
--- src/usr.bin/xlint/lint1/cgram.y:1.389 Sat Apr 9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/cgram.y Sat Apr 9 14:50:18 2022
@@ -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_specifier: /* C99 6.7.2.2 */
enum: /* helper for C99 6.7.2.2 */
T_ENUM {
symtyp = FTAG;
- begin_declaration_level(CTCONST);
+ begin_declaration_level(ENUM_CONST);
}
;
Index: src/usr.bin/xlint/lint1/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.10 src/usr.bin/xlint/lint1/ckbool.c:1.11
--- src/usr.bin/xlint/lint1/ckbool.c:1.10 Wed Dec 22 15:36:37 2021
+++ src/usr.bin/xlint/lint1/ckbool.c Sat Apr 9 14:50:18 2022
@@ -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 @@ bool
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 @@ fallback_symbol_strict_bool(sym_t *sym)
}
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;
Index: src/usr.bin/xlint/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.12 src/usr.bin/xlint/lint1/debug.c:1.13
--- src/usr.bin/xlint/lint1/debug.c:1.12 Sat Apr 9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/debug.c Sat Apr 9 14:50:18 2022
@@ -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 @@ scl_name(scl_t scl)
"enum",
"member-of-struct",
"member-of-union",
- "compile-time-constant",
+ "bool-constant",
+ "enum-constant",
"abstract",
"old-style-function-argument",
"prototype-argument",
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.271 src/usr.bin/xlint/lint1/decl.c:1.272
--- src/usr.bin/xlint/lint1/decl.c:1.271 Sat Apr 9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/decl.c Sat Apr 9 14:50:18 2022
@@ -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 @@ end_declaration_level(void)
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 @@ enumeration_constant(sym_t *sym, int val
}
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 @@ check_redeclaration(sym_t *dsym, bool *d
{
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 @@ check_static_global_variable(const sym_t
static void
check_global_variable(const sym_t *sym)
{
+ scl_t scl = sym->s_scl;
- if (sym->s_scl == TYPEDEF || sym->s_scl == CTCONST)
+ 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);
}
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.145 src/usr.bin/xlint/lint1/lint1.h:1.146
--- src/usr.bin/xlint/lint1/lint1.h:1.145 Sat Apr 9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/lint1.h Sat Apr 9 14:50:18 2022
@@ -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 @@ typedef enum {
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
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.420 src/usr.bin/xlint/lint1/tree.c:1.421
--- src/usr.bin/xlint/lint1/tree.c:1.420 Sat Apr 9 13:38:17 2022
+++ src/usr.bin/xlint/lint1/tree.c Sat Apr 9 14:50:18 2022
@@ -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 @@ build_name(sym_t *sym, bool is_funcname)
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;