Module Name:    src
Committed By:   rillig
Date:           Tue Jun 27 04:41:23 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: opt_badp.c
        src/usr.bin/indent: debug.c indent.c io.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/indent/opt_badp.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.386 -r1.387 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.231 -r1.232 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/opt_badp.c
diff -u src/tests/usr.bin/indent/opt_badp.c:1.15 src/tests/usr.bin/indent/opt_badp.c:1.16
--- src/tests/usr.bin/indent/opt_badp.c:1.15	Tue Jun 27 04:28:16 2023
+++ src/tests/usr.bin/indent/opt_badp.c	Tue Jun 27 04:41:23 2023
@@ -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

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.69 src/usr.bin/indent/debug.c:1.70
--- src/usr.bin/indent/debug.c:1.69	Mon Jun 26 20:03:09 2023
+++ src/usr.bin/indent/debug.c	Tue Jun 27 04:41:23 2023
@@ -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_enum(badp, badp_name);
 	debug_ps_bool(blank_line_after_decl);
+	debug_ps_enum(badp, badp_name);
 
 	state.heading = NULL;
 	debug_blank_line();

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.386 src/usr.bin/indent/indent.c:1.387
--- src/usr.bin/indent/indent.c:1.386	Mon Jun 26 20:03:09 2023
+++ src/usr.bin/indent/indent.c	Tue Jun 27 04:41:23 2023
@@ -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))

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.231 src/usr.bin/indent/io.c:1.232
--- src/usr.bin/indent/io.c:1.231	Mon Jun 26 20:03:09 2023
+++ src/usr.bin/indent/io.c	Tue Jun 27 04:41:23 2023
@@ -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;
 	}

Reply via email to