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 'blank line above first statement...



details:   https://anonhg.NetBSD.org/src/rev/99bcefd51726
branches:  trunk
changeset: 376644:99bcefd51726
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 27 04:41:23 2023 +0000

description:
indent: fix 'blank line above first statement in function body'

diffstat:

 tests/usr.bin/indent/opt_badp.c |  15 ++++++---------
 usr.bin/indent/debug.c          |   6 +++---
 usr.bin/indent/indent.c         |   6 +++---
 usr.bin/indent/io.c             |  10 ++++------
 4 files changed, 16 insertions(+), 21 deletions(-)

diffs (147 lines):

diff -r e23e6ec1c455 -r 99bcefd51726 tests/usr.bin/indent/opt_badp.c
--- a/tests/usr.bin/indent/opt_badp.c   Tue Jun 27 04:28:16 2023 +0000
+++ b/tests/usr.bin/indent/opt_badp.c   Tue Jun 27 04:41:23 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_badp.c,v 1.15 2023/06/27 04:28:16 rillig Exp $ */
+/* $NetBSD: opt_badp.c,v 1.16 2023/06/27 04:41:23 rillig Exp $ */
 
 /*
  * Tests for the options '-badp' and '-nbadp'.
@@ -226,7 +226,7 @@ f(void)
 }
 //indent end
 
-//indent run -di0
+//indent run -di0 -badp
 void
 f(void)
 {
@@ -235,7 +235,7 @@ f(void)
                {3, 4},
        };
        int decl2 = 5;
-// $ FIXME: Add blank line here.
+
        stmt;
 }
 //indent end
@@ -243,7 +243,8 @@ f(void)
 
 /*
  * Due to its limited lookahead, indent cannot know whether the comment is
- * followed by a declaration or a statement.
+ * followed by a declaration or a statement, so it assumes that the comment is
+ * part of the declaration block.
  */
 //indent input
 void f(void) {
@@ -259,11 +260,9 @@ void
 f(void)
 {
        int             decl1;
-// $ FIXME: No blank line here.
-
        /* comment */
        int             decl2;
-// $ FIXME: Add blank line here.
+
        stmt;
 }
 //indent end
@@ -281,8 +280,6 @@ f(void)
        int             decl;
 
        stmt1;
-// $ FIXME: Remove this blank line.
-
        stmt2;
 }
 //indent end
diff -r e23e6ec1c455 -r 99bcefd51726 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Tue Jun 27 04:28:16 2023 +0000
+++ b/usr.bin/indent/debug.c    Tue Jun 27 04:41:23 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.69 2023/06/26 20:03:09 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.70 2023/06/27 04:41:23 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.69 2023/06/26 20:03:09 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.70 2023/06/27 04:41:23 rillig Exp $");
 
 #include <stdarg.h>
 #include <string.h>
@@ -378,8 +378,8 @@ debug_parser_state(void)
        debug_ps_bool(break_after_comma);
        debug_ps_bool(want_newline);
        debug_ps_enum(declaration, declaration_name);
+       debug_ps_bool(blank_line_after_decl);
        debug_ps_enum(badp, badp_name);
-       debug_ps_bool(blank_line_after_decl);
 
        state.heading = NULL;
        debug_blank_line();
diff -r e23e6ec1c455 -r 99bcefd51726 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Jun 27 04:28:16 2023 +0000
+++ b/usr.bin/indent/indent.c   Tue Jun 27 04:41:23 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.386 2023/06/26 20:03:09 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.387 2023/06/27 04:41:23 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.386 2023/06/26 20:03:09 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.387 2023/06/27 04:41:23 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -357,7 +357,7 @@ update_ps_badp(lexer_symbol lsym)
        if (lsym == lsym_lbrace && ps.lbrace_kind == psym_lbrace_block
            && ps.psyms.len == 3)
                ps.badp = badp_seen_lbrace;
-       if (lsym == lsym_rbrace && ps.decl_level == 0)
+       if (lsym == lsym_rbrace && !ps.in_decl)
                ps.badp = badp_none;
        if (lsym == lsym_type && ps.paren.len == 0
            && (ps.badp == badp_seen_lbrace || ps.badp == badp_yes))
diff -r e23e6ec1c455 -r 99bcefd51726 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Tue Jun 27 04:28:16 2023 +0000
+++ b/usr.bin/indent/io.c       Tue Jun 27 04:41:23 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.231 2023/06/26 20:03:09 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.232 2023/06/27 04:41:23 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.231 2023/06/26 20:03:09 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.232 2023/06/27 04:41:23 rillig Exp $");
 
 #include <stdio.h>
 
@@ -171,12 +171,10 @@ want_blank_line(void)
        debug_println("%s: %s -> %s", __func__,
            line_kind_name[out.prev_line_kind], line_kind_name[out.line_kind]);
 
-       if (ps.blank_line_after_decl && ps.declaration == decl_no
+       if (((ps.blank_line_after_decl && ps.declaration == decl_no)
+           || ps.badp == badp_yes)
            && (lab.len > 0 || code.len > 0)) {
                ps.blank_line_after_decl = false;
-               return true;
-       }
-       if (ps.badp == badp_yes) {
                ps.badp = badp_none;
                return true;
        }



Home | Main Index | Thread Index | Old Index