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: don't treat function call expressions...



details:   https://anonhg.NetBSD.org/src/rev/1e9f66a82d57
branches:  trunk
changeset: 376290:1e9f66a82d57
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 09 10:24:55 2023 +0000

description:
indent: don't treat function call expressions as cast expressions

diffstat:

 tests/usr.bin/indent/psym_stmt.c |   8 +++-----
 usr.bin/indent/debug.c           |   5 +++--
 usr.bin/indent/indent.c          |  13 +++++--------
 usr.bin/indent/indent.h          |   3 ++-
 4 files changed, 13 insertions(+), 16 deletions(-)

diffs (112 lines):

diff -r f86d61866e45 -r 1e9f66a82d57 tests/usr.bin/indent/psym_stmt.c
--- a/tests/usr.bin/indent/psym_stmt.c  Fri Jun 09 09:49:07 2023 +0000
+++ b/tests/usr.bin/indent/psym_stmt.c  Fri Jun 09 10:24:55 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: psym_stmt.c,v 1.5 2023/06/09 09:45:55 rillig Exp $ */
+/* $NetBSD: psym_stmt.c,v 1.6 2023/06/09 10:24:55 rillig Exp $ */
 
 /*
  * Tests for the parser symbol psym_stmt, which represents a statement on the
@@ -28,14 +28,12 @@ function(void)
 //indent run-equals-input
 
 
+// Ensure that '(something) {' is not treated as a cast expression.
 //indent input
 {
        TAILQ_FOREACH(a, b, c) {
                a =
-// $ FIXME: The 'b' must be indented as a continuation.
-// $ The '{' in line 2 sets ps.block_init though, even though it does not
-// $ follow a '='.
-               b;
+                   b;
        }
 }
 //indent end
diff -r f86d61866e45 -r 1e9f66a82d57 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Fri Jun 09 09:49:07 2023 +0000
+++ b/usr.bin/indent/debug.c    Fri Jun 09 10:24:55 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.41 2023/06/09 08:10:58 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.42 2023/06/09 10:24:55 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.41 2023/06/09 08:10:58 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.42 2023/06/09 10:24:55 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -306,6 +306,7 @@ debug_parser_state(void)
        debug_ps_bool(seen_case);
        debug_ps_enum(spaced_expr_psym, psym_name);
        debug_ps_enum(lbrace_kind, psym_name);
+       debug_ps_bool(prev_paren_was_cast);
 
        debug_println("indentation of statements and declarations");
        debug_ps_int(ind_level);
diff -r f86d61866e45 -r 1e9f66a82d57 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Jun 09 09:49:07 2023 +0000
+++ b/usr.bin/indent/indent.c   Fri Jun 09 10:24:55 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.344 2023/06/09 08:16:06 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.345 2023/06/09 10:24:55 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.344 2023/06/09 08:16:06 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.345 2023/06/09 10:24:55 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -507,9 +507,10 @@ process_rparen(void)
        }
 
        enum paren_level_cast cast = ps.paren[--ps.nparen].cast;
-       if (ps.decl_on_line && !ps.block_init)
+       if (ps.in_func_def_params || (ps.decl_on_line && !ps.block_init))
                cast = cast_no;
 
+       ps.prev_paren_was_cast = cast == cast_maybe;
        if (cast == cast_maybe) {
                ps.next_unary = true;
                ps.want_blank = opt.space_after_cast;
@@ -669,11 +670,7 @@ process_semicolon(void)
 static void
 process_lbrace(void)
 {
-       parser_symbol psym = ps.psyms.sym[ps.psyms.top];
-       if (ps.prev_lsym == lsym_rparen
-           && ps.psyms.top >= 2
-           && !(psym == psym_for_exprs || psym == psym_if_expr
-               || psym == psym_switch_expr || psym == psym_while_expr)) {
+       if (ps.prev_lsym == lsym_rparen && ps.prev_paren_was_cast) {
                ps.block_init = true;
                ps.init_or_struct = true;
        }
diff -r f86d61866e45 -r 1e9f66a82d57 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Jun 09 09:49:07 2023 +0000
+++ b/usr.bin/indent/indent.h   Fri Jun 09 10:24:55 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.180 2023/06/09 08:10:58 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.181 2023/06/09 10:24:55 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -331,6 +331,7 @@ extern struct parser_state {
                                         * 'while'; or psym_0 */
        parser_symbol lbrace_kind;      /* the kind of brace to be pushed to
                                         * the parser symbol stack next */
+       bool prev_paren_was_cast;
 
        /* Indentation of statements and declarations */
 



Home | Main Index | Thread Index | Old Index