Module Name:    src
Committed By:   rillig
Date:           Fri Jun  9 10:24:56 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: psym_stmt.c
        src/usr.bin/indent: debug.c indent.c indent.h

Log Message:
indent: don't treat function call expressions as cast expressions


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/psym_stmt.c
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.344 -r1.345 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/indent/indent.h

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/psym_stmt.c
diff -u src/tests/usr.bin/indent/psym_stmt.c:1.5 src/tests/usr.bin/indent/psym_stmt.c:1.6
--- src/tests/usr.bin/indent/psym_stmt.c:1.5	Fri Jun  9 09:45:55 2023
+++ src/tests/usr.bin/indent/psym_stmt.c	Fri Jun  9 10:24:55 2023
@@ -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

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.41 src/usr.bin/indent/debug.c:1.42
--- src/usr.bin/indent/debug.c:1.41	Fri Jun  9 08:10:58 2023
+++ src/usr.bin/indent/debug.c	Fri Jun  9 10:24:55 2023
@@ -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);

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.344 src/usr.bin/indent/indent.c:1.345
--- src/usr.bin/indent/indent.c:1.344	Fri Jun  9 08:16:06 2023
+++ src/usr.bin/indent/indent.c	Fri Jun  9 10:24:55 2023
@@ -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;
 	}

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.180 src/usr.bin/indent/indent.h:1.181
--- src/usr.bin/indent/indent.h:1.180	Fri Jun  9 08:10:58 2023
+++ src/usr.bin/indent/indent.h	Fri Jun  9 10:24:55 2023
@@ -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 */
 

Reply via email to