Module Name: src Committed By: rillig Date: Sun Jul 30 22:27:21 UTC 2023
Modified Files: src/usr.bin/xlint/lint1: debug.c externs1.h init.c lex.c Log Message: lint: in debug mode, default to indenting the debug log Only the 'parsing' lines are not indented, as line breaks are independent from the structure of the code. To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/lint1/debug.c cvs rdiff -u -r1.202 -r1.203 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.249 -r1.250 src/usr.bin/xlint/lint1/init.c cvs rdiff -u -r1.188 -r1.189 src/usr.bin/xlint/lint1/lex.c 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/debug.c diff -u src/usr.bin/xlint/lint1/debug.c:1.57 src/usr.bin/xlint/lint1/debug.c:1.58 --- src/usr.bin/xlint/lint1/debug.c:1.57 Sun Jul 30 08:58:54 2023 +++ src/usr.bin/xlint/lint1/debug.c Sun Jul 30 22:27:21 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.57 2023/07/30 08:58:54 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.58 2023/07/30 22:27:21 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -35,10 +35,11 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: debug.c,v 1.57 2023/07/30 08:58:54 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.58 2023/07/30 22:27:21 rillig Exp $"); #endif #include <stdlib.h> +#include <string.h> #include "lint1.h" #include "cgram.h" @@ -47,6 +48,7 @@ __RCSID("$NetBSD: debug.c,v 1.57 2023/07 #ifdef DEBUG static int debug_indentation = 0; +static bool did_indentation; static FILE * @@ -59,21 +61,36 @@ debug_file(void) return yflag ? stderr : stdout; } +static void +debug_vprintf(const char *fmt, va_list va) +{ + + if (!did_indentation) { + did_indentation = true; + fprintf(debug_file(), "%s%*s", + yflag ? "| " : "", 2 * debug_indentation, ""); + } + + (void)vfprintf(debug_file(), fmt, va); + + did_indentation = strchr(fmt, '\n') == NULL; +} + void debug_printf(const char *fmt, ...) { va_list va; va_start(va, fmt); - (void)vfprintf(debug_file(), fmt, va); + debug_vprintf(fmt, va); va_end(va); } void -debug_print_indent(void) +debug_skip_indent(void) { - debug_printf("%s%*s", yflag ? "| " : "", 2 * debug_indentation, ""); + did_indentation = true; } void @@ -96,11 +113,10 @@ debug_step(const char *fmt, ...) { va_list va; - debug_print_indent(); va_start(va, fmt); - (void)vfprintf(debug_file(), fmt, va); + debug_vprintf(fmt, va); va_end(va); - fprintf(debug_file(), "\n"); + debug_printf("\n"); } void @@ -165,7 +181,6 @@ debug_node(const tnode_t *tn) // NOLINT( } op = tn->tn_op; - debug_print_indent(); debug_printf("'%s'", op == CVT && !tn->tn_cast ? "convert" : op_name(op)); if (op == NAME) @@ -339,8 +354,6 @@ void debug_sym(const char *prefix, const sym_t *sym, const char *suffix) { - if (suffix[0] == '\n') - debug_print_indent(); debug_printf("%s%s", prefix, sym->s_name); if (sym->s_type != NULL) debug_printf(" type='%s'", type_name(sym->s_type)); @@ -403,14 +416,16 @@ debug_sym(const char *prefix, const sym_ debug_word(sym->s_osdef && sym->u.s_old_style_args != NULL, "old-style-args"); - debug_printf("%s", suffix); + if (strcmp(suffix, "\n") == 0) + debug_printf("\n"); + else + debug_printf("%s", suffix); } static void debug_decl_level(const decl_level *dl) { - debug_print_indent(); debug_printf("decl_level: %s", decl_level_kind_name(dl->d_kind)); if (dl->d_scl != NOSCL) debug_printf(" %s", scl_name(dl->d_scl)); Index: src/usr.bin/xlint/lint1/externs1.h diff -u src/usr.bin/xlint/lint1/externs1.h:1.202 src/usr.bin/xlint/lint1/externs1.h:1.203 --- src/usr.bin/xlint/lint1/externs1.h:1.202 Sat Jul 29 07:49:14 2023 +++ src/usr.bin/xlint/lint1/externs1.h Sun Jul 30 22:27:21 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.202 2023/07/29 07:49:14 rillig Exp $ */ +/* $NetBSD: externs1.h,v 1.203 2023/07/30 22:27:21 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -142,7 +142,7 @@ void debug_type(const type_t *); void debug_sym(const char *, const sym_t *, const char *); void debug_symtab(void); void debug_printf(const char *fmt, ...) __printflike(1, 2); -void debug_print_indent(void); +void debug_skip_indent(void); void debug_indent_inc(void); void debug_indent_dec(void); void debug_enter_func(const char *); @@ -158,7 +158,7 @@ void debug_leave_func(const char *); #define debug_node(tn) debug_noop() #define debug_type(tp) debug_noop() #define debug_printf(...) debug_noop() -#define debug_print_indent() debug_noop() +#define debug_skip_indent() debug_noop() #define debug_indent_inc() debug_noop() #define debug_indent_dec() debug_noop() #define debug_enter() debug_noop() Index: src/usr.bin/xlint/lint1/init.c diff -u src/usr.bin/xlint/lint1/init.c:1.249 src/usr.bin/xlint/lint1/init.c:1.250 --- src/usr.bin/xlint/lint1/init.c:1.249 Fri Jul 21 06:02:07 2023 +++ src/usr.bin/xlint/lint1/init.c Sun Jul 30 22:27:21 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.249 2023/07/21 06:02:07 rillig Exp $ */ +/* $NetBSD: init.c,v 1.250 2023/07/30 22:27:21 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: init.c,v 1.249 2023/07/21 06:02:07 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.250 2023/07/30 22:27:21 rillig Exp $"); #endif #include <stdlib.h> @@ -408,7 +408,6 @@ designation_debug(const designation *dn) return; } - debug_print_indent(); debug_printf("designation: "); for (size_t i = 0; i < dn->dn_len; i++) designator_debug(dn->dn_items + i); @@ -711,7 +710,6 @@ initialization_debug(const initializatio const brace_level *bl; size_t i = 0; for (bl = in->in_brace_level; bl != NULL; bl = bl->bl_enclosing) { - debug_print_indent(); debug_printf("brace level %zu: ", i); brace_level_debug(bl); i++; Index: src/usr.bin/xlint/lint1/lex.c diff -u src/usr.bin/xlint/lint1/lex.c:1.188 src/usr.bin/xlint/lint1/lex.c:1.189 --- src/usr.bin/xlint/lint1/lex.c:1.188 Sat Jul 15 13:35:24 2023 +++ src/usr.bin/xlint/lint1/lex.c Sun Jul 30 22:27:21 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lex.c,v 1.188 2023/07/15 13:35:24 rillig Exp $ */ +/* $NetBSD: lex.c,v 1.189 2023/07/30 22:27:21 rillig Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -38,7 +38,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) -__RCSID("$NetBSD: lex.c,v 1.188 2023/07/15 13:35:24 rillig Exp $"); +__RCSID("$NetBSD: lex.c,v 1.189 2023/07/30 22:27:21 rillig Exp $"); #endif #include <ctype.h> @@ -1280,6 +1280,7 @@ lex_next_line(void) { curr_pos.p_line++; curr_pos.p_uniq = 0; + debug_skip_indent(); debug_printf("parsing %s:%d\n", curr_pos.p_file, curr_pos.p_line); if (curr_pos.p_file == csrc_pos.p_file) { csrc_pos.p_line++;