Module Name: src Committed By: rillig Date: Mon Jun 5 14:22:26 UTC 2023
Modified Files: src/usr.bin/indent: debug.c indent.h Log Message: indent: sync debug output with parser state To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/debug.c cvs rdiff -u -r1.174 -r1.175 src/usr.bin/indent/indent.h 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/indent/debug.c diff -u src/usr.bin/indent/debug.c:1.34 src/usr.bin/indent/debug.c:1.35 --- src/usr.bin/indent/debug.c:1.34 Sun Jun 4 20:51:19 2023 +++ src/usr.bin/indent/debug.c Mon Jun 5 14:22:26 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.34 2023/06/04 20:51:19 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.35 2023/06/05 14:22:26 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: debug.c,v 1.34 2023/06/04 20:51:19 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.35 2023/06/05 14:22:26 rillig Exp $"); #include <stdarg.h> @@ -129,6 +129,12 @@ const char *const line_kind_name[] = { "case/default", }; +static const char *const extra_expr_indent_name[] = { + "no", + "yes", + "last", +}; + static const char *const decl_ptr_name[] = { "start", "word", @@ -290,51 +296,58 @@ debug_parser_state(void) static struct parser_state prev_ps; debug_blank_line(); - debug_println(" ps.prev_lsym = %s", - lsym_name[ps.prev_lsym]); - debug_ps_bool(curr_col_1); - debug_ps_bool(next_col_1); - debug_ps_bool(next_unary); - debug_ps_bool(is_function_definition); - debug_ps_bool(want_blank); - debug_ps_bool(break_after_comma); - debug_ps_bool(force_nl); - debug_ps_int(line_start_nparen); - debug_ps_int(nparen); - debug_ps_paren(&prev_ps); - - debug_ps_int(comment_delta); - debug_ps_int(n_comment_delta); - debug_ps_int(com_ind); + debug_println(" ps.prev_lsym = %s", lsym_name[ps.prev_lsym]); + debug_println("token classification"); + debug_ps_int(quest_level); + debug_ps_bool(is_function_definition); debug_ps_bool(block_init); debug_ps_int(block_init_level); debug_ps_bool(init_or_struct); + debug_ps_bool(decl_on_line); + debug_ps_bool(in_stmt_or_decl); + debug_ps_bool(in_decl); + debug_ps_bool(in_func_def_params); + debug_ps_bool(seen_case); + debug_ps_enum(spaced_expr_psym, psym_name); + debug_ps_enum(lbrace_kind, psym_name); + debug_println("indentation of statements and declarations"); debug_ps_int(ind_level); debug_ps_int(ind_level_follow); - + debug_ps_bool(in_stmt_cont); debug_ps_int(decl_level); debug_ps_di_stack(&prev_ps); - debug_ps_bool(decl_on_line); - debug_ps_bool(in_decl); - debug_ps_enum(declaration, declaration_name); - debug_ps_bool(blank_line_after_decl); - debug_ps_bool(in_func_def_params); - debug_ps_enum(lbrace_kind, psym_name); - debug_ps_enum(decl_ptr, decl_ptr_name); debug_ps_bool(decl_indent_done); debug_ps_int(decl_ind); debug_ps_bool(tabs_to_var); + debug_ps_enum(extra_expr_indent, extra_expr_indent_name); - debug_ps_bool(in_stmt_or_decl); - debug_ps_bool(in_stmt_cont); - debug_ps_bool(seen_case); + // The parser symbol stack is printed in debug_parse_stack instead. - // The debug output for the parser symbols is done in 'parse' instead. + debug_println("spacing inside a statement or declaration"); + debug_ps_bool(next_unary); + debug_ps_bool(want_blank); + debug_ps_int(line_start_nparen); + debug_ps_int(nparen); + debug_ps_paren(&prev_ps); + debug_ps_enum(decl_ptr, decl_ptr_name); + + debug_println("horizontal spacing for comments"); + debug_ps_int(comment_delta); + debug_ps_int(n_comment_delta); + debug_ps_int(com_ind); + + debug_println("vertical spacing"); + debug_ps_bool(break_after_comma); + debug_ps_bool(force_nl); + debug_ps_enum(declaration, declaration_name); + debug_ps_bool(blank_line_after_decl); + + debug_println("comments"); + debug_ps_bool(curr_col_1); + debug_ps_bool(next_col_1); - debug_ps_enum(spaced_expr_psym, psym_name); - debug_ps_int(quest_level); debug_blank_line(); prev_ps = ps; @@ -345,7 +358,7 @@ debug_parse_stack(const char *situation) { printf("parse stack %s:", situation); for (int i = 0; i <= ps.tos; ++i) - printf(" %s %d", psym_name[ps.s_sym[i]], ps.s_ind_level[i]); + printf(" %d %s", ps.s_ind_level[i], psym_name[ps.s_sym[i]]); printf("\n"); } #endif Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.174 src/usr.bin/indent/indent.h:1.175 --- src/usr.bin/indent/indent.h:1.174 Mon Jun 5 12:05:01 2023 +++ src/usr.bin/indent/indent.h Mon Jun 5 14:22:26 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.174 2023/06/05 12:05:01 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.175 2023/06/05 14:22:26 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -373,6 +373,7 @@ extern struct parser_state { * are currently open; used to indent the * remaining lines of the statement, * initializer or declaration */ + paren_level_props paren[20]; enum { dp_start, /* the beginning of a declaration */ dp_word, /* seen a type name */ @@ -381,7 +382,6 @@ extern struct parser_state { } decl_ptr; /* detects declarations like 'typename *x', to * prevent the '*' from being interpreted as a * binary operator */ - paren_level_props paren[20]; /* Horizontal spacing for comments */