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 spacing in for loop with declarat...



details:   https://anonhg.NetBSD.org/src/rev/967e9c59768c
branches:  trunk
changeset: 375332:967e9c59768c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 08:56:39 2023 +0000

description:
indent: fix spacing in for loop with declaration (since 2022-02-13)

diffstat:

 tests/usr.bin/indent/psym_for_exprs.c |  45 +++++++++-------------------------
 usr.bin/indent/indent.c               |   5 ++-
 2 files changed, 15 insertions(+), 35 deletions(-)

diffs (88 lines):

diff -r 56b4b51bb345 -r 967e9c59768c tests/usr.bin/indent/psym_for_exprs.c
--- a/tests/usr.bin/indent/psym_for_exprs.c     Mon May 15 08:22:23 2023 +0000
+++ b/tests/usr.bin/indent/psym_for_exprs.c     Mon May 15 08:56:39 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: psym_for_exprs.c,v 1.5 2023/05/15 08:22:23 rillig Exp $ */
+/* $NetBSD: psym_for_exprs.c,v 1.6 2023/05/15 08:56:39 rillig Exp $ */
 
 /*
  * Tests for the parser state psym_for_exprs, which represents the state after
@@ -10,41 +10,20 @@
 void
 for_loops(void)
 {
-       for (int i = 0; i < 10; i++)
-               printf("%d * %d = %d\n", i, 7, i * 7);
+       int i;
 
-       for (int i = 0; i < 10; i++) {
+       for (i = 0; i < 10; i++)
+               printf("%d * %d = %d\n", i, 7, i * 7);
+       for (i = 0; i < 10; i++) {
                printf("%d * %d = %d\n", i, 7, i * 7);
        }
+
+       for (int j = 0; j < 10; j++)
+               printf("%d * %d = %d\n", j, 7, j * 7);
+       for (int j = 0; j < 10; j++) {
+               printf("%d * %d = %d\n", j, 7, j * 7);
+       }
 }
 //indent end
 
-//indent run
-void
-for_loops(void)
-{
-       for (int i = 0; i < 10; i++)
-               printf("%d * %d = %d\n", i, 7, i * 7);
-
-       /* $ FIXME: Add space between ')' and '{'. */
-       for (int i = 0; i < 10; i++){
-               printf("%d * %d = %d\n", i, 7, i * 7);
-       }
-}
-//indent end
-
-
-/*
- * Since C99, the first expression of a 'for' loop may be a declaration, not
- * only an expression.
- */
-//indent input
-void
-small_scope(void)
-{
-       for (int i = 0; i < 3; i++)
-               stmt();
-}
-//indent end
-
-//indent run-equals-input
+//indent run-equals-input -ldi0
diff -r 56b4b51bb345 -r 967e9c59768c usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon May 15 08:22:23 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon May 15 08:56:39 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.271 2023/05/15 08:11:27 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.272 2023/05/15 08:56:39 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.271 2023/05/15 08:11:27 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.272 2023/05/15 08:56:39 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -483,6 +483,7 @@ unbalanced:
        ps.in_stmt_or_decl = false;
        parse(ps.spaced_expr_psym);
        ps.spaced_expr_psym = psym_0;
+       ps.want_blank = true;
     }
 }
 



Home | Main Index | Thread Index | Old Index