Module Name: src
Committed By: rillig
Date: Fri Jun 2 15:07:46 UTC 2023
Modified Files:
src/tests/usr.bin/indent: lsym_while.c psym_stmt_list.c
psym_while_expr.c
src/usr.bin/indent: indent.c
Log Message:
indent: force each statement on a new line
Previously, '{} while (cond)' was kept on a single line, even though the
'while' was independent of the '{}'.
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_while.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_stmt_list.c \
src/tests/usr.bin/indent/psym_while_expr.c
cvs rdiff -u -r1.314 -r1.315 src/usr.bin/indent/indent.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/lsym_while.c
diff -u src/tests/usr.bin/indent/lsym_while.c:1.5 src/tests/usr.bin/indent/lsym_while.c:1.6
--- src/tests/usr.bin/indent/lsym_while.c:1.5 Sat May 13 06:52:48 2023
+++ src/tests/usr.bin/indent/lsym_while.c Fri Jun 2 15:07:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_while.c,v 1.5 2023/05/13 06:52:48 rillig Exp $ */
+/* $NetBSD: lsym_while.c,v 1.6 2023/06/02 15:07:46 rillig Exp $ */
/*
* Tests for the token 'lsym_while', which represents the keyword 'while' that
@@ -44,7 +44,7 @@ void
function(void)
{
{
-/* $ FIXME: The '} while' is misleading. */
- } while (0);
+ }
+ while (0);
}
//indent end
Index: src/tests/usr.bin/indent/psym_stmt_list.c
diff -u src/tests/usr.bin/indent/psym_stmt_list.c:1.4 src/tests/usr.bin/indent/psym_stmt_list.c:1.5
--- src/tests/usr.bin/indent/psym_stmt_list.c:1.4 Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/psym_stmt_list.c Fri Jun 2 15:07:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: psym_stmt_list.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: psym_stmt_list.c,v 1.5 2023/06/02 15:07:46 rillig Exp $ */
/*
* Tests for the parser symbol psym_stmt_list, which represents a list of
@@ -41,7 +41,7 @@ void
return_after_rbrace(void)
{
{
-// $ FIXME: The 'return' must go in a separate line.
- } return;
+ }
+ return;
}
//indent end
Index: src/tests/usr.bin/indent/psym_while_expr.c
diff -u src/tests/usr.bin/indent/psym_while_expr.c:1.4 src/tests/usr.bin/indent/psym_while_expr.c:1.5
--- src/tests/usr.bin/indent/psym_while_expr.c:1.4 Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/psym_while_expr.c Fri Jun 2 15:07:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: psym_while_expr.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: psym_while_expr.c,v 1.5 2023/06/02 15:07:46 rillig Exp $ */
/*
* Tests for the parser symbol psym_while_expr, which represents the keyword
@@ -38,11 +38,10 @@ function(void)
} while (cond);
if (cmd)
- /* $ XXX: Where does the code say that ';' stays on the same line? */
while (cond);
{
- /* $ FIXME: the '}' must be on a line of its own. */
- } while (cond);
+ }
+ while (cond);
}
//indent end
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.314 src/usr.bin/indent/indent.c:1.315
--- src/usr.bin/indent/indent.c:1.314 Fri Jun 2 14:34:14 2023
+++ src/usr.bin/indent/indent.c Fri Jun 2 15:07:46 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.314 2023/06/02 14:34:14 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.315 2023/06/02 15:07:46 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.314 2023/06/02 14:34:14 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.315 2023/06/02 15:07:46 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -829,6 +829,11 @@ process_rbrace(void)
out.line_kind = lk_func_end;
parse(psym_rbrace);
+
+ if (!ps.init_or_struct
+ && ps.s_sym[ps.tos] != psym_do_stmt
+ && ps.s_sym[ps.tos] != psym_if_expr_stmt)
+ ps.force_nl = true;
}
static void