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 cast expressions
details: https://anonhg.NetBSD.org/src/rev/68028da8d534
branches: trunk
changeset: 376409:68028da8d534
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 16 14:26:26 2023 +0000
description:
indent: improve heuristics for cast expressions
diffstat:
tests/usr.bin/indent/lsym_rparen_or_rbracket.c | 19 ++++++++-----------
usr.bin/indent/indent.c | 10 ++++++----
2 files changed, 14 insertions(+), 15 deletions(-)
diffs (72 lines):
diff -r b96cdd23ead6 -r 68028da8d534 tests/usr.bin/indent/lsym_rparen_or_rbracket.c
--- a/tests/usr.bin/indent/lsym_rparen_or_rbracket.c Fri Jun 16 14:12:10 2023 +0000
+++ b/tests/usr.bin/indent/lsym_rparen_or_rbracket.c Fri Jun 16 14:26:26 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.7 2023/06/16 14:12:10 rillig Exp $ */
+/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.8 2023/06/16 14:26:27 rillig Exp $ */
/*
* Tests for the token lsym_rparen_or_lbracket, which represents ')' or ']',
@@ -56,7 +56,13 @@ int a = array[
//indent end
+/*
+ * Cast expressions and compound expressions, taken from lint and make.
+ */
//indent input
+// This ')' is not a cast.
+char *Buf_DoneData(Buffer *) MAKE_ATTR_USE;
+
{
dcs_align((u_int)dcs);
mpools.pools[i] = (memory_pool){NULL, 0, 0};
@@ -64,13 +70,4 @@ int a = array[
}
//indent end
-//indent run -ci4 -di0 -nlp
-{
- dcs_align((u_int)dcs);
-// $ FIXME: Don't add newlines.
- mpools.pools[i] = (memory_pool) {
- NULL, 0, 0
- };
- list_add(l, (const char[3]){'-', (char)c, '\0'});
-}
-//indent end
+//indent run-equals-input -ci4 -di0 -nlp
diff -r b96cdd23ead6 -r 68028da8d534 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Jun 16 14:12:10 2023 +0000
+++ b/usr.bin/indent/indent.c Fri Jun 16 14:26:26 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.376 2023/06/16 14:12:10 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.377 2023/06/16 14:26:26 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.376 2023/06/16 14:12:10 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.377 2023/06/16 14:26:26 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -622,11 +622,13 @@ rparen_is_cast(bool paren_cast)
{
if (ps.in_func_def_params)
return false;
+ if (ps.line_has_decl && !ps.in_init)
+ return false;
if (ps.prev_lsym == lsym_unary_op)
return true;
- if (ps.line_has_decl && !ps.in_init)
+ if (ps.spaced_expr_psym != psym_0 && ps.paren.len == 0)
return false;
- return paren_cast || ch_isalpha(inp_p[0]);
+ return paren_cast || ch_isalpha(inp_p[0]) || inp_p[0] == '{';
}
static void
Home |
Main Index |
Thread Index |
Old Index