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 formatting of 'do' statements



details:   https://anonhg.NetBSD.org/src/rev/7f586f741042
branches:  trunk
changeset: 376228:7f586f741042
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jun 05 09:41:40 2023 +0000

description:
indent: fix formatting of 'do' statements

diffstat:

 tests/usr.bin/indent/lsym_do.c |  20 +++-----------------
 usr.bin/indent/indent.c        |   5 +++--
 usr.bin/indent/io.c            |   7 ++++---
 3 files changed, 10 insertions(+), 22 deletions(-)

diffs (91 lines):

diff -r e74bc5b3a424 -r 7f586f741042 tests/usr.bin/indent/lsym_do.c
--- a/tests/usr.bin/indent/lsym_do.c    Mon Jun 05 09:10:31 2023 +0000
+++ b/tests/usr.bin/indent/lsym_do.c    Mon Jun 05 09:41:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_do.c,v 1.9 2023/06/05 08:22:00 rillig Exp $ */
+/* $NetBSD: lsym_do.c,v 1.10 2023/06/05 09:41:40 rillig Exp $ */
 
 /*
  * Tests for the token lsym_do, which represents the keyword 'do' that starts
@@ -131,25 +131,11 @@ variants(void)
 
        word
        do {
-       } while         (false);
+       } while (false);
 
 label: do {
        } while (false);
 }
 //indent end
 
-//indent run -sob
-{
-       /* */
-       do {
-       } while (false);
-// $ FIXME: This blank line is not optional and must be preserved.
-       word
-       do {
-// $ FIXME: The expression is indented too far to the right.
-       } while         (false);
-// $ FIXME: This blank line is not optional and must be preserved.
-label: do {
-       } while (false);
-}
-//indent end
+//indent run-equals-prev-output -sob
diff -r e74bc5b3a424 -r 7f586f741042 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon Jun 05 09:10:31 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon Jun 05 09:41:40 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.331 2023/06/05 09:10:31 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.332 2023/06/05 09:41:40 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.331 2023/06/05 09:10:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.332 2023/06/05 09:41:40 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -846,6 +846,7 @@ static void
 process_do(void)
 {
        ps.in_stmt_or_decl = false;
+       ps.in_decl = false;
 
        if (code.len > 0) {     /* make sure this starts a line */
                if (opt.verbose)
diff -r e74bc5b3a424 -r 7f586f741042 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Mon Jun 05 09:10:31 2023 +0000
+++ b/usr.bin/indent/io.c       Mon Jun 05 09:41:40 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.195 2023/06/05 07:23:03 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.195 2023/06/05 07:23:03 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.196 2023/06/05 09:41:40 rillig Exp $");
 
 #include <stdio.h>
 
@@ -169,7 +169,8 @@ want_blank_line(void)
 static bool
 is_blank_line_optional(void)
 {
-       if (out.prev_line_kind == lk_stmt_head)
+       if (out.prev_line_kind == lk_stmt_head
+           && ps.prev_lsym != lsym_semicolon)
                return wrote_newlines >= 1;
        if (ps.tos >= 2)
                return wrote_newlines >= 2;



Home | Main Index | Thread Index | Old Index