Module Name:    src
Committed By:   rillig
Date:           Mon May 15 13:33:20 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: opt_eei.c
        src/usr.bin/indent: indent.c indent.h io.c

Log Message:
indent: fix indentation of statements after controlling expression


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/opt_eei.c
cvs rdiff -u -r1.275 -r1.276 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.138 -r1.139 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/indent/io.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/opt_eei.c
diff -u src/tests/usr.bin/indent/opt_eei.c:1.11 src/tests/usr.bin/indent/opt_eei.c:1.12
--- src/tests/usr.bin/indent/opt_eei.c:1.11	Mon May 15 13:28:05 2023
+++ src/tests/usr.bin/indent/opt_eei.c	Mon May 15 13:33:19 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_eei.c,v 1.11 2023/05/15 13:28:05 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.12 2023/05/15 13:33:19 rillig Exp $ */
 
 /*
  * Tests for the options '-eei' and '-neei'.
@@ -183,7 +183,7 @@ b)
 	    cond
 	)
 	stmt(
-		arg
+	    arg
 	    );
 }
 //indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.275 src/usr.bin/indent/indent.c:1.276
--- src/usr.bin/indent/indent.c:1.275	Mon May 15 12:59:43 2023
+++ src/usr.bin/indent/indent.c	Mon May 15 13:33:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -348,7 +348,6 @@ maybe_break_line(lexer_symbol lsym)
 	diag(0, "Line broken");
     output_line();
     ps.force_nl = false;
-    ps.extra_expr_indent = false;
 }
 
 static void
@@ -436,7 +435,7 @@ process_lparen_or_lbracket(void)
     if (opt.extra_expr_indent && !opt.lineup_to_parens
 	    && ps.spaced_expr_psym != psym_0 && ps.nparen == 1
 	    && opt.continuation_indent == opt.indent_size)
-	ps.extra_expr_indent = true;
+	ps.extra_expr_indent = eei_yes;
 
     if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
 	    && ps.nparen == 1 && ps.paren[0].indent < 2 * opt.indent_size) {
@@ -484,6 +483,8 @@ unbalanced:
     buf_add_char(&code, token.st[0]);
 
     if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) {
+	if (ps.extra_expr_indent == eei_yes)
+	    ps.extra_expr_indent = eei_last;
 	ps.force_nl = true;
 	ps.next_unary = true;
 	ps.in_stmt_or_decl = false;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.138 src/usr.bin/indent/indent.h:1.139
--- src/usr.bin/indent/indent.h:1.138	Mon May 15 12:59:43 2023
+++ src/usr.bin/indent/indent.h	Mon May 15 13:33:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.138 2023/05/15 12:59:43 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.139 2023/05/15 13:33:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -308,7 +308,11 @@ extern struct parser_state {
     int di_stack[20];		/* a stack of structure indentation levels */
     bool tabs_to_var;		/* true if using tabs to indent to var name */
 
-    bool extra_expr_indent;
+    enum {
+	eei_no,
+	eei_yes,
+	eei_last
+    } extra_expr_indent;
 
     enum {
 	in_enum_no,		/* outside any 'enum { ... }' */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.168 src/usr.bin/indent/io.c:1.169
--- src/usr.bin/indent/io.c:1.168	Mon May 15 12:59:43 2023
+++ src/usr.bin/indent/io.c	Mon May 15 13:33:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -274,6 +274,8 @@ output_complete_line(char line_terminato
     ps.decl_on_line = ps.in_decl;	/* for proper comment indentation */
     ps.in_stmt_cont = ps.in_stmt_or_decl && !ps.in_decl;
     ps.decl_indent_done = false;
+    if (ps.extra_expr_indent == eei_last)
+	ps.extra_expr_indent = eei_no;
 
     lab.len = 0;
     code.len = 0;
@@ -338,7 +340,7 @@ compute_code_indent(void)
 	return compute_code_indent_lineup(base_ind);
     }
 
-    if (ps.extra_expr_indent)
+    if (ps.extra_expr_indent != eei_no)
 	return base_ind + 2 * opt.continuation_indent;
 
     if (2 * opt.continuation_indent == opt.indent_size)

Reply via email to