Module Name:    src
Committed By:   rillig
Date:           Sat Jun 10 06:52:36 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: lsym_case_label.c opt_bc.c
        src/usr.bin/indent: indent.c

Log Message:
indent: fix token classification in declarations

As a side effect, indent handles _Generic from C11 properly now, at
least in -nlp mode.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_case_label.c
cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_bc.c
cvs rdiff -u -r1.349 -r1.350 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_case_label.c
diff -u src/tests/usr.bin/indent/lsym_case_label.c:1.8 src/tests/usr.bin/indent/lsym_case_label.c:1.9
--- src/tests/usr.bin/indent/lsym_case_label.c:1.8	Sun Jun  4 18:58:30 2023
+++ src/tests/usr.bin/indent/lsym_case_label.c	Sat Jun 10 06:52:35 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.8 2023/06/04 18:58:30 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.9 2023/06/10 06:52:35 rillig Exp $ */
 
 /*
  * Tests for the tokens lsym_case and lsym_default, which represent the
@@ -92,22 +92,12 @@ const char *type_name = _Generic(
 // $ XXX: It's strange to align the arguments at the parenthesis even though
 // $ XXX: the first argument is already on a separate line.
 				 ' ',
-// $ TODO: indent the type names
-int:				 "character constants have type 'int'",
-char:				 "character constants have type 'char'",
-default:
-// $ TODO: remove the newline after 'default:'
-				 "character constants have some other type"
+				 int: "character constants have type 'int'",
+// $ FIXME: The indentation is not sensible in any way.
+			       char: "character constants have type 'char'",
+// $ FIXME: The indentation is not sensible in any way.
+			 default: "character constants have some other type"
 );
 //indent end
 
-//indent run -di0 -nlp
-const char *type_name = _Generic(
-	' ',
-// $ TODO: indent the type names
-int:	"character constants have type 'int'",
-char:	"character constants have type 'char'",
-default:
-	"character constants have some other type"
-);
-//indent end
+//indent run-equals-input -di0 -nlp

Index: src/tests/usr.bin/indent/opt_bc.c
diff -u src/tests/usr.bin/indent/opt_bc.c:1.9 src/tests/usr.bin/indent/opt_bc.c:1.10
--- src/tests/usr.bin/indent/opt_bc.c:1.9	Sat Jun 10 06:38:21 2023
+++ src/tests/usr.bin/indent/opt_bc.c	Sat Jun 10 06:52:35 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bc.c,v 1.9 2023/06/10 06:38:21 rillig Exp $ */
+/* $NetBSD: opt_bc.c,v 1.10 2023/06/10 06:52:35 rillig Exp $ */
 
 /*
  * Tests for the options '-bc' and '-nbc'.
@@ -105,8 +105,8 @@ int		d;
 
 
 /*
- * A '(' at the top level is taken to start a function definition, leaving
- * variable declaration mode.
+ * Before 2023-06-10, a '(' at the top level started a function definition,
+ * leaving variable declaration mode.
  */
 //indent input
 int a = 1, b = 2;
@@ -116,6 +116,6 @@ int a = (1), b = 2;
 //indent run -bc
 int		a = 1,
 		b = 2;
-// $ FIXME: Missing line break.
-int		a = (1), b = 2;
+int		a = (1),
+		b = 2;
 //indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.349 src/usr.bin/indent/indent.c:1.350
--- src/usr.bin/indent/indent.c:1.349	Sat Jun 10 06:38:21 2023
+++ src/usr.bin/indent/indent.c	Sat Jun 10 06:52:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.349 2023/06/10 06:38:21 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.350 2023/06/10 06:52:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.349 2023/06/10 06:38:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.350 2023/06/10 06:52:35 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -531,9 +531,8 @@ process_lparen(void)
 	if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0)
 		ps.extra_expr_indent = eei_maybe;
 
-	if (ps.in_var_decl && ps.psyms.top <= 2) {
-		/* A kludge to correctly align function definitions. */
-		parse(psym_stmt);
+	if (ps.in_var_decl && ps.psyms.top <= 2 && !ps.in_init) {
+		parse(psym_stmt);	/* prepare for function definition */
 		ps.in_var_decl = false;
 	}
 
@@ -841,7 +840,7 @@ static void
 process_colon_other(void)
 {
 	buf_add_char(&code, ':');
-	ps.want_blank = false;
+	ps.want_blank = ps.decl_level == 0;
 }
 
 static void

Reply via email to