Module Name: src
Committed By: rillig
Date: Sat Jul 31 17:09:21 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: Makefile cgram.y decl.c externs1.h
Log Message:
lint: add debugging output for the grammar tokens
No functional change outside debug mode.
To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r1.351 -r1.352 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/xlint/lint1/externs1.h
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.80 src/usr.bin/xlint/lint1/Makefile:1.81
--- src/usr.bin/xlint/lint1/Makefile:1.80 Sun Jul 25 22:14:36 2021
+++ src/usr.bin/xlint/lint1/Makefile Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.80 2021/07/25 22:14:36 rillig Exp $
+# $NetBSD: Makefile,v 1.81 2021/07/31 17:09:21 rillig Exp $
.include <bsd.own.mk>
@@ -22,7 +22,7 @@ LOBJS.${PROG}+= ${SRCS:M*.l:.l=.ln}
CPPFLAGS+= -DIS_LINT1
CPPFLAGS+= -I${.CURDIR}
-CPPFLAGS+= ${DEBUG:D-DDEBUG}
+CPPFLAGS+= ${DEBUG:D-DDEBUG -DYYDEBUG}
COPTS.err.c+= ${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :}
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.351 src/usr.bin/xlint/lint1/cgram.y:1.352
--- src/usr.bin/xlint/lint1/cgram.y:1.351 Tue Jul 27 05:52:53 2021
+++ src/usr.bin/xlint/lint1/cgram.y Sat Jul 31 17:09:21 2021
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.351 2021/07/27 05:52:53 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 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.351 2021/07/27 05:52:53 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.352 2021/07/31 17:09:21 rillig Exp $");
#endif
#include <limits.h>
@@ -122,6 +122,13 @@ anonymize(sym_t *s)
s->s_styp = NULL;
}
+#if defined(YYDEBUG) && (defined(YYBYACC) || defined(YYBISON))
+#define YYSTYPE_TOSTRING cgram_to_string
+#endif
+#if defined(YYDEBUG) && defined(YYBISON)
+#define YYPRINT cgram_print
+#endif
+
%}
%expect 150
@@ -349,6 +356,12 @@ anonymize(sym_t *s)
%type <y_tnode> do_while_expr
%type <y_sym> func_declarator
+%{
+#if defined(YYDEBUG) && defined(YYBISON)
+static void cgram_print(FILE *, int, YYSTYPE);
+#endif
+%}
+
%%
program:
@@ -2116,6 +2129,47 @@ yyerror(const char *msg)
return 0;
}
+#if (defined(YYDEBUG) && YYDEBUG > 0 && defined(YYBYACC)) \
+ || (defined(YYDEBUG) && defined(YYBISON))
+static const char *
+cgram_to_string(int token, YYSTYPE val)
+{
+ static const char *tqual_name[] = {
+ "const", "volatile", "restrict", "_Thread_local"
+ };
+
+ switch (token) {
+ case T_INCDEC:
+ case T_MULTIPLICATIVE:
+ case T_ADDITIVE:
+ case T_SHIFT:
+ case T_RELATIONAL:
+ case T_EQUALITY:
+ case T_OPASSIGN:
+ return modtab[val.y_op].m_name;
+ case T_SCLASS:
+ return scl_name(val.y_scl);
+ case T_TYPE:
+ case T_STRUCT_OR_UNION:
+ return tspec_name(val.y_tspec);
+ case T_QUAL:
+ return tqual_name[val.y_tqual];
+ case T_NAME:
+ return val.y_name->sb_name;
+ default:
+ return "<none>";
+ }
+}
+#endif
+
+#if defined(YYDEBUG) && defined(YYBISON)
+static void
+cgram_print(FILE *output, int token, YYSTYPE val)
+{
+ fprintf(output, "%s", cgram_to_string(token, val));
+}
+#endif
+
static void
cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
{
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.211 src/usr.bin/xlint/lint1/decl.c:1.212
--- src/usr.bin/xlint/lint1/decl.c:1.211 Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/decl.c Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.211 2021/07/31 11:03:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 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.211 2021/07/31 11:03:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.212 2021/07/31 17:09:21 rillig Exp $");
#endif
#include <sys/param.h>
@@ -134,7 +134,7 @@ initdecl(void)
}
/* Return the name of the "storage class" in the wider sense. */
-static const char *
+const char *
scl_name(scl_t scl)
{
static const char *const names[] = {
Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.122 src/usr.bin/xlint/lint1/externs1.h:1.123
--- src/usr.bin/xlint/lint1/externs1.h:1.122 Sat Jul 31 11:03:04 2021
+++ src/usr.bin/xlint/lint1/externs1.h Sat Jul 31 17:09:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.122 2021/07/31 11:03:04 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.123 2021/07/31 17:09:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -198,6 +198,7 @@ extern void check_usage_sym(bool, sym_t
extern void check_global_symbols(void);
extern void print_previous_declaration(int, const sym_t *);
extern int to_int_constant(tnode_t *, bool);
+extern const char *scl_name(scl_t);
/*
* tree.c