Module Name: src Committed By: rillig Date: Fri Jun 16 14:26:27 UTC 2023
Modified Files: src/tests/usr.bin/indent: lsym_rparen_or_rbracket.c src/usr.bin/indent: indent.c Log Message: indent: improve heuristics for cast expressions To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c cvs rdiff -u -r1.376 -r1.377 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/lsym_rparen_or_rbracket.c diff -u src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.7 src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.8 --- src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.7 Fri Jun 16 14:12:10 2023 +++ src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c Fri Jun 16 14:26:27 2023 @@ -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 Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.376 src/usr.bin/indent/indent.c:1.377 --- src/usr.bin/indent/indent.c:1.376 Fri Jun 16 14:12:10 2023 +++ src/usr.bin/indent/indent.c Fri Jun 16 14:26:26 2023 @@ -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