Fri Jun 16 12:55:57 2023 UTC ()
indent: improve heuristics for casts


(rillig)
diff -r1.8 -r1.9 src/tests/usr.bin/indent/fmt_expr.c
diff -r1.10 -r1.11 src/tests/usr.bin/indent/lsym_unary_op.c
diff -r1.374 -r1.375 src/usr.bin/indent/indent.c

cvs diff -r1.8 -r1.9 src/tests/usr.bin/indent/fmt_expr.c (expand / switch to context diff)
--- src/tests/usr.bin/indent/fmt_expr.c 2023/06/14 17:07:32 1.8
+++ src/tests/usr.bin/indent/fmt_expr.c 2023/06/16 12:55:57 1.9
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_expr.c,v 1.8 2023/06/14 17:07:32 rillig Exp $ */
+/* $NetBSD: fmt_expr.c,v 1.9 2023/06/16 12:55:57 rillig Exp $ */
 
 /*
  * Tests for all kinds of expressions that are not directly related to unary
@@ -19,8 +19,7 @@
 	x = ((struct point){0, 0}).x;
 
 	for (ln = gnodes->first; ln != NULL; ln = ln->next)
-// $ FIXME: No space after the cast.
-		*(GNode **) Vector_Push(&vec) = ln->datum;
+		*(GNode **)Vector_Push(&vec) = ln->datum;
 }
 //indent end
 

cvs diff -r1.10 -r1.11 src/tests/usr.bin/indent/lsym_unary_op.c (expand / switch to context diff)
--- src/tests/usr.bin/indent/lsym_unary_op.c 2023/06/08 21:18:54 1.10
+++ src/tests/usr.bin/indent/lsym_unary_op.c 2023/06/16 12:55:57 1.11
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.10 2023/06/08 21:18:54 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.11 2023/06/16 12:55:57 rillig Exp $ */
 
 /*
  * Tests for the token lsym_unary_op, which represents a unary operator.
@@ -85,17 +85,10 @@
  */
 //indent input
 {
-sbuf_t *sb = *(sbuf_t **)sp;
-return (int)(a * (float)b);
-a = (2 * b == c);
-}
-//indent end
-
-//indent run -di0
-{
-// $ FIXME: Wrong spacing after the cast.
-	sbuf_t *sb = *(sbuf_t **) sp;
+	sbuf_t *sb = *(sbuf_t **)sp;
 	return (int)(a * (float)b);
 	a = (2 * b == c);
 }
 //indent end
+
+//indent run-equals-input -di0

cvs diff -r1.374 -r1.375 src/usr.bin/indent/indent.c (expand / switch to context diff)
--- src/usr.bin/indent/indent.c 2023/06/16 12:30:45 1.374
+++ src/usr.bin/indent/indent.c 2023/06/16 12:55:57 1.375
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.374 2023/06/16 12:30:45 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.375 2023/06/16 12:55:57 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.374 2023/06/16 12:30:45 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.375 2023/06/16 12:55:57 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -627,6 +627,8 @@
 	    && ps.paren.item[--ps.paren.len].cast == cast_maybe
 	    && !ps.in_func_def_params
 	    && !(ps.line_has_decl && !ps.in_init);
+	if (ps.prev_lsym == lsym_unary_op)
+		ps.prev_paren_was_cast = true;
 	if (ps.prev_paren_was_cast) {
 		ps.next_unary = true;
 		ps.want_blank = opt.space_after_cast;