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: split debug output into paragraphs
details: https://anonhg.NetBSD.org/src/rev/52c9fed0eb31
branches: trunk
changeset: 375967:52c9fed0eb31
user: rillig <rillig%NetBSD.org@localhost>
date: Tue May 23 12:12:29 2023 +0000
description:
indent: split debug output into paragraphs
The paragraphs separate the different processing steps: getting a token
from the lexer, processing the token, updating the parser state, sending
a finished line to the output.
diffstat:
usr.bin/indent/debug.c | 48 +++++++++++++++++++++++-------------------------
usr.bin/indent/indent.c | 13 +++++++++++--
usr.bin/indent/indent.h | 8 +++++---
usr.bin/indent/io.c | 6 +++---
usr.bin/indent/lexi.c | 9 +++------
usr.bin/indent/parse.c | 5 +++--
6 files changed, 48 insertions(+), 41 deletions(-)
diffs (281 lines):
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/debug.c Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.21 2023/05/23 06:35:01 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.21 2023/05/23 06:35:01 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $");
#include <stdarg.h>
@@ -134,6 +134,8 @@ static const char *const decl_ptr_name[]
"other",
};
+static unsigned wrote_newlines;
+
void
debug_printf(const char *fmt, ...)
{
@@ -143,6 +145,7 @@ debug_printf(const char *fmt, ...)
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
+ wrote_newlines = 0;
}
void
@@ -155,6 +158,14 @@ debug_println(const char *fmt, ...)
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
+ wrote_newlines = fmt[0] == '\0' ? wrote_newlines + 1 : 1;
+}
+
+void
+debug_blank_line(void)
+{
+ while (wrote_newlines < 2)
+ debug_println("");
}
void
@@ -182,26 +193,19 @@ static void
debug_print_buf(const char *name, const struct buffer *buf)
{
if (buf->len > 0) {
- debug_printf("%s ", name);
- debug_vis_range("\"", buf->st, buf->len, "\"\n");
+ debug_printf(" %s ", name);
+ debug_vis_range("\"", buf->st, buf->len, "\"");
}
}
void
debug_buffers(void)
{
- if (lab.len > 0) {
- debug_printf(" label ");
- debug_vis_range("\"", lab.st, lab.len, "\"");
- }
- if (code.len > 0) {
- debug_printf(" code ");
- debug_vis_range("\"", code.st, code.len, "\"");
- }
- if (com.len > 0) {
- debug_printf(" comment ");
- debug_vis_range("\"", com.st, com.len, "\"");
- }
+ debug_print_buf("token", &token);
+ debug_print_buf("label", &lab);
+ debug_print_buf("code", &code);
+ debug_print_buf("comment", &com);
+ debug_println("");
}
#define debug_ps_bool(name) \
@@ -280,18 +284,11 @@ debug_ps_di_stack(const struct parser_st
}
void
-debug_parser_state(lexer_symbol lsym)
+debug_parser_state(void)
{
static struct parser_state prev_ps;
- debug_println("");
- debug_printf("line %d: %s", line_no, lsym_name[lsym]);
- debug_vis_range(" \"", token.st, token.len, "\"\n");
-
- debug_print_buf("label", &lab);
- debug_print_buf("code", &code);
- debug_print_buf("comment", &com);
-
+ debug_blank_line();
debug_println(" ps.prev_token = %s",
lsym_name[ps.prev_token]);
debug_ps_bool(curr_col_1);
@@ -337,6 +334,7 @@ debug_parser_state(lexer_symbol lsym)
debug_ps_enum(spaced_expr_psym, psym_name);
debug_ps_int(quest_level);
+ debug_blank_line();
prev_ps = ps;
}
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/indent.c Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.307 2023/05/23 11:37:23 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.307 2023/05/23 11:37:23 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -1146,9 +1146,16 @@ process_lsym(lexer_symbol lsym)
static int
indent(void)
{
+ debug_parser_state();
+
for (;;) { /* loop until we reach eof */
lexer_symbol lsym = lexi();
+ debug_blank_line();
+ debug_printf("line %d: %s", line_no, lsym_name[lsym]);
+ debug_buffers();
+ debug_blank_line();
+
if (lsym == lsym_eof)
return process_eof();
@@ -1173,6 +1180,8 @@ indent(void)
process_lsym(lsym);
+ debug_parser_state();
+
if (lsym != lsym_comment && lsym != lsym_newline &&
lsym != lsym_preprocessing)
ps.prev_token = lsym;
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/indent.h Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.158 2023/05/23 06:35:01 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.159 2023/05/23 12:12:29 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -440,8 +440,9 @@ extern struct output_state {
#ifdef debug
void debug_printf(const char *, ...) __printflike(1, 2);
void debug_println(const char *, ...) __printflike(1, 2);
+void debug_blank_line(void);
void debug_vis_range(const char *, const char *, size_t, const char *);
-void debug_parser_state(lexer_symbol);
+void debug_parser_state(void);
void debug_parse_stack(const char *);
void debug_buffers(void);
extern const char *const lsym_name[];
@@ -452,8 +453,9 @@ extern const char *const line_kind_name[
#define debug_noop() do { } while (false)
#define debug_printf(fmt, ...) debug_noop()
#define debug_println(fmt, ...) debug_noop()
+#define debug_blank_line() debug_noop()
#define debug_vis_range(prefix, s, e, suffix) debug_noop()
-#define debug_parser_state(lsym) debug_noop()
+#define debug_parser_state() debug_noop()
#define debug_parse_stack(situation) debug_noop()
#define debug_buffers() debug_noop()
#endif
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/io.c Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.185 2023/05/22 10:28:59 rillig Exp $ */
+/* $NetBSD: io.c,v 1.186 2023/05/23 12:12:29 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.185 2023/05/22 10:28:59 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.186 2023/05/23 12:12:29 rillig Exp $");
#include <stdio.h>
@@ -255,9 +255,9 @@ output_line_comment(int ind)
void
output_line(void)
{
+ debug_blank_line();
debug_printf("%s", __func__);
debug_buffers();
- debug_println("");
ps.is_function_definition = false;
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/lexi.c Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.204 2023/05/23 06:35:01 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.205 2023/05/23 12:12:29 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.204 2023/05/23 06:35:01 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.205 2023/05/23 12:12:29 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -547,10 +547,8 @@ lexi(void)
}
lexer_symbol alnum_lsym = lexi_alnum();
- if (alnum_lsym != lsym_eof) {
- debug_parser_state(alnum_lsym);
+ if (alnum_lsym != lsym_eof)
return alnum_lsym;
- }
/* Scan a non-alphanumeric token */
@@ -682,7 +680,6 @@ lexi(void)
ps.next_unary = next_unary;
- debug_parser_state(lsym);
return lsym;
}
diff -r 70095adf38ae -r 52c9fed0eb31 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c Tue May 23 12:05:10 2023 +0000
+++ b/usr.bin/indent/parse.c Tue May 23 12:12:29 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.61 2023/05/18 05:33:27 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.62 2023/05/23 12:12:29 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: parse.c,v 1.61 2023/05/18 05:33:27 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.62 2023/05/23 12:12:29 rillig Exp $");
#include <err.h>
@@ -63,6 +63,7 @@ decl_level(void)
void
parse(parser_symbol psym)
{
+ debug_blank_line();
debug_println("parse token: %s", psym_name[psym]);
if (psym != psym_else) {
Home |
Main Index |
Thread Index |
Old Index