Module Name: src
Committed By: rillig
Date: Fri Jun 16 12:55:57 UTC 2023
Modified Files:
src/tests/usr.bin/indent: fmt_expr.c lsym_unary_op.c
src/usr.bin/indent: indent.c
Log Message:
indent: improve heuristics for casts
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/fmt_expr.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/lsym_unary_op.c
cvs rdiff -u -r1.374 -r1.375 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/fmt_expr.c
diff -u src/tests/usr.bin/indent/fmt_expr.c:1.8 src/tests/usr.bin/indent/fmt_expr.c:1.9
--- src/tests/usr.bin/indent/fmt_expr.c:1.8 Wed Jun 14 17:07:32 2023
+++ src/tests/usr.bin/indent/fmt_expr.c Fri Jun 16 12:55:57 2023
@@ -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
Index: src/tests/usr.bin/indent/lsym_unary_op.c
diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.10 src/tests/usr.bin/indent/lsym_unary_op.c:1.11
--- src/tests/usr.bin/indent/lsym_unary_op.c:1.10 Thu Jun 8 21:18:54 2023
+++ src/tests/usr.bin/indent/lsym_unary_op.c Fri Jun 16 12:55:57 2023
@@ -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 @@ unary_operators(void)
*/
//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
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.374 src/usr.bin/indent/indent.c:1.375
--- src/usr.bin/indent/indent.c:1.374 Fri Jun 16 12:30:45 2023
+++ src/usr.bin/indent/indent.c Fri Jun 16 12:55:57 2023
@@ -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 @@ process_rparen(void)
&& 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;