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: clean up



details:   https://anonhg.NetBSD.org/src/rev/9093ba91a030
branches:  trunk
changeset: 376127:9093ba91a030
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 02 13:59:33 2023 +0000

description:
indent: clean up

Only print the 'token' buffer in debug mode if it is interesting, group
the blocks in handling of '(' tokens by topic, remove obsolete comment
from test.

diffstat:

 tests/usr.bin/indent/opt_sob.c |   6 +-----
 usr.bin/indent/debug.c         |   7 +++----
 usr.bin/indent/indent.c        |  18 +++++++++---------
 usr.bin/indent/indent.h        |   4 +++-
 4 files changed, 16 insertions(+), 19 deletions(-)

diffs (138 lines):

diff -r b3f488bf872a -r 9093ba91a030 tests/usr.bin/indent/opt_sob.c
--- a/tests/usr.bin/indent/opt_sob.c    Fri Jun 02 12:08:26 2023 +0000
+++ b/tests/usr.bin/indent/opt_sob.c    Fri Jun 02 13:59:33 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sob.c,v 1.8 2023/05/23 06:18:00 rillig Exp $ */
+/* $NetBSD: opt_sob.c,v 1.9 2023/06/02 13:59:33 rillig Exp $ */
 
 /*
  * Tests for the options '-sob' and '-nsob'.
@@ -11,10 +11,6 @@
  * The option '-nsob' keeps optional blank lines as is.
  */
 
-/*
- * FIXME: There are lots of 'optional blank lines' here that should be
- *  swallowed.
- */
 //indent input
 void           function_declaration(void);
 
diff -r b3f488bf872a -r 9093ba91a030 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Fri Jun 02 12:08:26 2023 +0000
+++ b/usr.bin/indent/debug.c    Fri Jun 02 13:59:33 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.24 2023/06/02 11:43:07 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.25 2023/06/02 13:59:33 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.24 2023/06/02 11:43:07 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.25 2023/06/02 13:59:33 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -189,7 +189,7 @@ debug_vis_range(const char *prefix, cons
        debug_printf("%s", suffix);
 }
 
-static void
+void
 debug_print_buf(const char *name, const struct buffer *buf)
 {
        if (buf->len > 0) {
@@ -201,7 +201,6 @@ debug_print_buf(const char *name, const 
 void
 debug_buffers(void)
 {
-       debug_print_buf("token", &token);
        debug_print_buf("label", &lab);
        debug_print_buf("code", &code);
        debug_print_buf("comment", &com);
diff -r b3f488bf872a -r 9093ba91a030 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Jun 02 12:08:26 2023 +0000
+++ b/usr.bin/indent/indent.c   Fri Jun 02 13:59:33 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.311 2023/06/02 11:43:07 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.312 2023/06/02 13:59:33 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.311 2023/06/02 11:43:07 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.312 2023/06/02 13:59:33 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -521,18 +521,11 @@ process_lparen_or_lbracket(void)
        ps.want_blank = false;
        buf_add_char(&code, token.st[0]);
 
-       int indent = ind_add(0, code.st, code.len);
-       enum paren_level_cast cast = cast_unknown;
-
        if (opt.extra_expr_indent && !opt.lineup_to_parens
            && ps.spaced_expr_psym != psym_0 && ps.nparen == 1
            && opt.continuation_indent == opt.indent_size)
                ps.extra_expr_indent = eei_yes;
 
-       if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
-           && ps.nparen == 1 && indent < 2 * opt.indent_size)
-               indent = 2 * opt.indent_size;
-
        if (ps.init_or_struct && *token.st == '(' && ps.tos <= 2) {
                /* this is a kluge to make sure that declarations will be
                 * aligned right if proc decl has an explicit type on it, i.e.
@@ -541,6 +534,12 @@ process_lparen_or_lbracket(void)
                ps.init_or_struct = false;
        }
 
+       int indent = ind_add(0, code.st, code.len);
+       if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
+           && ps.nparen == 1 && indent < 2 * opt.indent_size)
+               indent = 2 * opt.indent_size;
+
+       enum paren_level_cast cast = cast_unknown;
        if (ps.prev_token == lsym_offsetof || ps.prev_token == lsym_sizeof
            || ps.is_function_definition)
                cast = cast_no;
@@ -1185,6 +1184,7 @@ indent(void)
 
                debug_blank_line();
                debug_printf("line %d: %s", line_no, lsym_name[lsym]);
+               debug_print_buf("token", &token);
                debug_buffers();
                debug_blank_line();
 
diff -r b3f488bf872a -r 9093ba91a030 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Jun 02 12:08:26 2023 +0000
+++ b/usr.bin/indent/indent.h   Fri Jun 02 13:59:33 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.160 2023/06/02 11:43:07 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.161 2023/06/02 13:59:33 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -445,6 +445,7 @@ void debug_blank_line(void);
 void debug_vis_range(const char *, const char *, size_t, const char *);
 void debug_parser_state(void);
 void debug_parse_stack(const char *);
+void debug_print_buf(const char *, const struct buffer *);
 void debug_buffers(void);
 extern const char *const lsym_name[];
 extern const char *const psym_name[];
@@ -458,6 +459,7 @@ extern const char *const line_kind_name[
 #define        debug_vis_range(prefix, s, e, suffix) debug_noop()
 #define        debug_parser_state() debug_noop()
 #define        debug_parse_stack(situation) debug_noop()
+#define debug_print_buf(name, buf) debug_noop()
 #define        debug_buffers() debug_noop()
 #endif
 



Home | Main Index | Thread Index | Old Index