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: improve heuristics for casts
details: https://anonhg.NetBSD.org/src/rev/c886fb0d13a8
branches: trunk
changeset: 376406:c886fb0d13a8
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 16 12:55:57 2023 +0000
description:
indent: improve heuristics for casts
diffstat:
tests/usr.bin/indent/fmt_expr.c | 5 ++---
tests/usr.bin/indent/lsym_unary_op.c | 15 ++++-----------
usr.bin/indent/indent.c | 6 ++++--
3 files changed, 10 insertions(+), 16 deletions(-)
diffs (76 lines):
diff -r 3fc808acab40 -r c886fb0d13a8 tests/usr.bin/indent/fmt_expr.c
--- a/tests/usr.bin/indent/fmt_expr.c Fri Jun 16 12:30:45 2023 +0000
+++ b/tests/usr.bin/indent/fmt_expr.c Fri Jun 16 12:55:57 2023 +0000
@@ -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
diff -r 3fc808acab40 -r c886fb0d13a8 tests/usr.bin/indent/lsym_unary_op.c
--- a/tests/usr.bin/indent/lsym_unary_op.c Fri Jun 16 12:30:45 2023 +0000
+++ b/tests/usr.bin/indent/lsym_unary_op.c Fri Jun 16 12:55:57 2023 +0000
@@ -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
diff -r 3fc808acab40 -r c886fb0d13a8 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Jun 16 12:30:45 2023 +0000
+++ b/usr.bin/indent/indent.c Fri Jun 16 12:55:57 2023 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index