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 debug logging to the parser



details:   https://anonhg.NetBSD.org/src/rev/e71ce18a46f4
branches:  trunk
changeset: 1017522:e71ce18a46f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Dec 30 01:02:38 2020 +0000

description:
lint: add debug logging to the parser

Even with -DDEBUG and -DYYDEBUG, the debug output is not detailed enough
to clearly see what happens.

Add some custom debug logging to the parser, mainly for demonstration
purposes, and also to find out how to fix the test d_struct_init_nested.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diffs (57 lines):

diff -r f0c7a0893afa -r e71ce18a46f4 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Tue Dec 29 23:12:48 2020 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Wed Dec 30 01:02:38 2020 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.116 2020/12/29 17:29:31 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.117 2020/12/30 01:02:38 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.116 2020/12/29 17:29:31 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.117 2020/12/30 01:02:38 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -102,10 +102,12 @@
        } else
                CLRWFLGS(file, line);
 }
+#define cgram_debug(fmt, args...) printf("cgram_debug: " fmt "\n", ##args)
 #else
 #define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD
 #define SAVE(f, l)     olwarn = lwarn
 #define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn))
+#define cgram_debug(fmt, args...) (void)0
 #endif
 
 /* unbind the anonymous struct members from the struct */
@@ -1315,7 +1317,11 @@
        ;
 
 initializer:
-         init_assign_expr
+         {
+               cgram_debug("begin initializer");
+         } init_assign_expr {
+               cgram_debug("end initializer");
+         }
        ;
 
 init_assign_expr:
@@ -2018,9 +2024,11 @@
 identifier:
          T_NAME {
                $$ = $1;
+               cgram_debug("name '%s'", $$->sb_name);
          }
        | T_TYPENAME {
                $$ = $1;
+               cgram_debug("typename '%s'", $$->sb_name);
          }
        ;
 



Home | Main Index | Thread Index | Old Index