Module Name:    src
Committed By:   rillig
Date:           Sat Jun 10 08:17:04 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: fmt_expr.c lsym_lparen_or_lbracket.c opt_ci.c
            opt_lpl.c
        src/usr.bin/indent: indent.c io.c

Log Message:
indent: fix indentation of continuation lines in initializers


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/fmt_expr.c
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_ci.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_lpl.c
cvs rdiff -u -r1.351 -r1.352 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.212 -r1.213 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/fmt_expr.c
diff -u src/tests/usr.bin/indent/fmt_expr.c:1.6 src/tests/usr.bin/indent/fmt_expr.c:1.7
--- src/tests/usr.bin/indent/fmt_expr.c:1.6	Fri Jun  9 11:22:31 2023
+++ src/tests/usr.bin/indent/fmt_expr.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_expr.c,v 1.6 2023/06/09 11:22:31 rillig Exp $ */
+/* $NetBSD: fmt_expr.c,v 1.7 2023/06/10 08:17:04 rillig Exp $ */
 
 /*
  * Tests for all kinds of expressions that are not directly related to unary
@@ -18,15 +18,6 @@
 	println((const char[3]){'-', c, '\0'});
 	x = ((struct point){0, 0}).x;
 
-	// XXX: GCC statement expressions are not supported yet.
-	int		var =
-	(
-	 {
-	 1
-	 }
-	)
-		       ;
-
 	for (ln = gnodes->first; ln != NULL; ln = ln->next)
 // $ FIXME: No space after the cast.
 		*(GNode **) Vector_Push(&vec) = ln->datum;
@@ -34,3 +25,36 @@
 //indent end
 
 //indent run-equals-input
+
+
+/*
+ * GCC statement expressions are not supported yet.
+ */
+//indent input
+{
+	int var = ({1});
+	int var = ({
+		1
+	});
+	int var = ({
+		int decl = 1;
+		stmt;
+	});
+}
+//indent end
+
+//indent run -di0
+error: Standard Input:7: Unbalanced parentheses
+warning: Standard Input:9: Extra ')'
+{
+	int var = ({1});
+	int var = ({
+		   1
+		   });
+	int var = ({
+		   int decl = 1;
+		stmt;
+	});
+}
+exit 1
+//indent end

Index: src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.15 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.16
--- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.15	Thu Jun  8 20:55:22 2023
+++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.15 2023/06/08 20:55:22 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.16 2023/06/10 08:17:04 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -289,7 +289,7 @@ cover_want_blank_before_lparen(void)
 {
 	/* ps.prev_lsym can never be 'newline'. */
 	int newline =
-	(3);
+		(3);
 
 	int lparen_or_lbracket = a[(3)];
 	int rparen_or_rbracket = a[3](5);

Index: src/tests/usr.bin/indent/opt_ci.c
diff -u src/tests/usr.bin/indent/opt_ci.c:1.10 src/tests/usr.bin/indent/opt_ci.c:1.11
--- src/tests/usr.bin/indent/opt_ci.c:1.10	Fri Jun  9 06:36:58 2023
+++ src/tests/usr.bin/indent/opt_ci.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.10 2023/06/09 06:36:58 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.11 2023/06/10 08:17:04 rillig Exp $ */
 
 /*
  * Tests for the option '-ci', which controls the indentation of continuation
@@ -238,10 +238,4 @@ function(void)
 }
 //indent end
 
-//indent run -ldi0 -ci4
-{
-	size_t last_word_len = com.len
-/* $ FIXME: The '-' must be indented by 4 spaces. */
-	- (size_t)(last_blank + 1);
-}
-//indent end
+//indent run-equals-input -ldi0 -ci4

Index: src/tests/usr.bin/indent/opt_lpl.c
diff -u src/tests/usr.bin/indent/opt_lpl.c:1.7 src/tests/usr.bin/indent/opt_lpl.c:1.8
--- src/tests/usr.bin/indent/opt_lpl.c:1.7	Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/opt_lpl.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lpl.c,v 1.7 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_lpl.c,v 1.8 2023/06/10 08:17:04 rillig Exp $ */
 
 /*
  * Tests for the options '-lpl' and '-nlpl'.
@@ -46,13 +46,11 @@ example(void)
 	int		sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
 	int		sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
 
-/* $ XXX: There should be at least _some_ indentation for the */
-/* $ continuation lines. */
 	int		sum3 = 1 + 2 + 3 + 4 + 5 +
-	6 + 7 + 8 + 9 + 10 +
-	11 + 12 + 13 + 14 + 15 +
-	16 + 17 + 18 + 19 + 20 +
-	21;
+		6 + 7 + 8 + 9 + 10 +
+		11 + 12 + 13 + 14 + 15 +
+		16 + 17 + 18 + 19 + 20 +
+		21;
 	int		sum4 = (1 + 2 + 3 + 4 + 5 +
 				6 + 7 + 8 + 9 + 10 +
 				11 + 12 + 13 + 14 + 15 +

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.351 src/usr.bin/indent/indent.c:1.352
--- src/usr.bin/indent/indent.c:1.351	Sat Jun 10 07:42:41 2023
+++ src/usr.bin/indent/indent.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.351 2023/06/10 07:42:41 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.352 2023/06/10 08:17:04 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.351 2023/06/10 07:42:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.352 2023/06/10 08:17:04 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -776,21 +776,6 @@ process_postfix_op(void)
 }
 
 static void
-process_question(void)
-{
-	ps.quest_level++;
-	if (code.len == 0)
-		ps.in_stmt_cont = true;	// XXX: should be unnecessary.
-}
-
-static void
-process_colon_question(void)
-{
-	if (code.len == 0)
-		ps.in_stmt_cont = true;	// XXX: should be unnecessary.
-}
-
-static void
 process_comma(void)
 {
 	ps.want_blank = code.len > 0;	/* only put blank after comma if comma
@@ -985,8 +970,8 @@ process_lsym(lexer_symbol lsym)
 	case lsym_unary_op:	process_unary_op();	break;
 	case lsym_postfix_op:	process_postfix_op();	break;
 	case lsym_binary_op:				goto copy_token;
-	case lsym_question:	process_question();	goto copy_token;
-	case lsym_colon_question: process_colon_question(); goto copy_token;
+	case lsym_question:	ps.quest_level++;	goto copy_token;
+	case lsym_colon_question:			goto copy_token;
 	case lsym_colon_label:	process_colon_label();	break;
 	case lsym_colon_other:	process_colon_other();	break;
 	case lsym_comma:	process_comma();	break;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.212 src/usr.bin/indent/io.c:1.213
--- src/usr.bin/indent/io.c:1.212	Sat Jun 10 07:53:00 2023
+++ src/usr.bin/indent/io.c	Sat Jun 10 08:17:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.212 2023/06/10 07:53:00 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.213 2023/06/10 08:17:04 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.212 2023/06/10 07:53:00 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.213 2023/06/10 08:17:04 rillig Exp $");
 
 #include <stdio.h>
 
@@ -383,9 +383,9 @@ output_line(void)
 
 	ps.line_has_decl = ps.in_decl;
 	ps.line_has_func_def = false;
-	// XXX: don't reset in_stmt_cont here; see process_colon_question.
 	ps.in_stmt_cont = ps.in_stmt_or_decl
-	    && !ps.in_decl && ps.init_level == 0;
+	    && (!ps.in_decl || ps.in_init)
+	    && ps.init_level == 0;
 	ps.decl_indent_done = false;
 	if (ps.extra_expr_indent == eei_last)
 		ps.extra_expr_indent = eei_no;

Reply via email to