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: fix token classification in declarations



details:   https://anonhg.NetBSD.org/src/rev/542443b97c1b
branches:  trunk
changeset: 376306:542443b97c1b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 10 06:52:35 2023 +0000

description:
indent: fix token classification in declarations

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

diffstat:

 tests/usr.bin/indent/lsym_case_label.c |  24 +++++++-----------------
 tests/usr.bin/indent/opt_bc.c          |  10 +++++-----
 usr.bin/indent/indent.c                |  11 +++++------
 3 files changed, 17 insertions(+), 28 deletions(-)

diffs (106 lines):

diff -r 01eca2e0eac1 -r 542443b97c1b tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Sat Jun 10 06:38:20 2023 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Sat Jun 10 06:52:35 2023 +0000
@@ -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
diff -r 01eca2e0eac1 -r 542443b97c1b tests/usr.bin/indent/opt_bc.c
--- a/tests/usr.bin/indent/opt_bc.c     Sat Jun 10 06:38:20 2023 +0000
+++ b/tests/usr.bin/indent/opt_bc.c     Sat Jun 10 06:52:35 2023 +0000
@@ -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
diff -r 01eca2e0eac1 -r 542443b97c1b usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Jun 10 06:38:20 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat Jun 10 06:52:35 2023 +0000
@@ -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



Home | Main Index | Thread Index | Old Index