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: add debugging output for the gramm...
details: https://anonhg.NetBSD.org/src/rev/4ace06a6e40f
branches: trunk
changeset: 984927:4ace06a6e40f
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 31 17:09:21 2021 +0000
description:
lint: add debugging output for the grammar tokens
No functional change outside debug mode.
diffstat:
usr.bin/xlint/lint1/Makefile | 4 +-
usr.bin/xlint/lint1/cgram.y | 58 ++++++++++++++++++++++++++++++++++++++++-
usr.bin/xlint/lint1/decl.c | 6 ++--
usr.bin/xlint/lint1/externs1.h | 3 +-
4 files changed, 63 insertions(+), 8 deletions(-)
diffs (156 lines):
diff -r 694c10f63e8a -r 4ace06a6e40f usr.bin/xlint/lint1/Makefile
--- a/usr.bin/xlint/lint1/Makefile Sat Jul 31 16:54:37 2021 +0000
+++ b/usr.bin/xlint/lint1/Makefile Sat Jul 31 17:09:21 2021 +0000
@@ -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 @@
CPPFLAGS+= -DIS_LINT1
CPPFLAGS+= -I${.CURDIR}
-CPPFLAGS+= ${DEBUG:D-DDEBUG}
+CPPFLAGS+= ${DEBUG:D-DDEBUG -DYYDEBUG}
COPTS.err.c+= ${${ACTIVE_CC} == "clang":? -Wno-format-nonliteral :}
diff -r 694c10f63e8a -r 4ace06a6e40f usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Jul 31 16:54:37 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Jul 31 17:09:21 2021 +0000
@@ -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 @@
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 @@
%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 @@
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)
{
diff -r 694c10f63e8a -r 4ace06a6e40f usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sat Jul 31 16:54:37 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sat Jul 31 17:09:21 2021 +0000
@@ -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 @@
}
/* 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[] = {
diff -r 694c10f63e8a -r 4ace06a6e40f usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Sat Jul 31 16:54:37 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Sat Jul 31 17:09:21 2021 +0000
@@ -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_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
Home |
Main Index |
Thread Index |
Old Index