Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: fix debug output



details:   https://anonhg.NetBSD.org/src/rev/cced9a4ab10f
branches:  trunk
changeset: 376336:cced9a4ab10f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 10 20:37:12 2023 +0000

description:
indent: fix debug output

When the parser state was first printed, there were unintended diff
markers.  Treat the previous lexer symbol like the other parts of the
parser state, as omitting it from the diff output is confusing.

diffstat:

 usr.bin/indent/debug.c  |  13 ++++++-------
 usr.bin/indent/indent.c |   8 ++++----
 2 files changed, 10 insertions(+), 11 deletions(-)

diffs (90 lines):

diff -r d1a48874f0fa -r cced9a4ab10f usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Sat Jun 10 18:46:42 2023 +0000
+++ b/usr.bin/indent/debug.c    Sat Jun 10 20:37:12 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.52 2023/06/10 20:37:12 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.52 2023/06/10 20:37:12 rillig Exp $");
 
 #include <stdarg.h>
 #include <string.h>
@@ -233,7 +233,7 @@ debug_buffers(void)
 static void
 write_ps_bool(const char *name, bool prev, bool curr)
 {
-       if (curr != prev) {
+       if (!state.ps_first && curr != prev) {
                char diff = " -+x"[(prev ? 1 : 0) + (curr ? 2 : 0)];
                debug_println("        [%c]  ps.%s", diff, name);
        } else if (config.full_parser_state || state.ps_first)
@@ -243,7 +243,7 @@ write_ps_bool(const char *name, bool pre
 static void
 write_ps_int(const char *name, int prev, int curr)
 {
-       if (curr != prev)
+       if (!state.ps_first && curr != prev)
                debug_println(" %3d -> %3d  ps.%s", prev, curr, name);
        else if (config.full_parser_state || state.ps_first)
                debug_println("        %3d  ps.%s", curr, name);
@@ -252,7 +252,7 @@ write_ps_int(const char *name, int prev,
 static void
 write_ps_enum(const char *name, const char *prev, const char *curr)
 {
-       if (strcmp(prev, curr) != 0)
+       if (!state.ps_first && strcmp(prev, curr) != 0)
                debug_println(" %3s -> %3s  ps.%s", prev, curr, name);
        else if (config.full_parser_state || state.ps_first)
                debug_println(" %10s  ps.%s", curr, name);
@@ -327,10 +327,9 @@ void
 debug_parser_state(void)
 {
        debug_blank_line();
-       debug_println("             ps.prev_lsym = %s",
-           lsym_name[ps.prev_lsym]);
 
        state.heading = "token classification";
+       debug_ps_enum(prev_lsym, lsym_name);
        debug_ps_bool(in_stmt_or_decl);
        debug_ps_bool(in_decl);
        debug_ps_bool(in_var_decl);
diff -r d1a48874f0fa -r cced9a4ab10f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Jun 10 18:46:42 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat Jun 10 20:37:12 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.356 2023/06/10 20:37:12 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.356 2023/06/10 20:37:12 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -1060,12 +1060,12 @@ indent(void)
 
                process_lsym(lsym);
 
-               debug_parser_state();
-
                if (lsym != lsym_preprocessing
                    && lsym != lsym_newline
                    && lsym != lsym_comment)
                        ps.prev_lsym = lsym;
+
+               debug_parser_state();
        }
 }
 



Home | Main Index | Thread Index | Old Index