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 indentation of struct declarations



details:   https://anonhg.NetBSD.org/src/rev/7dab0b461bce
branches:  trunk
changeset: 375968:7dab0b461bce
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue May 23 16:53:57 2023 +0000

description:
indent: fix indentation of struct declarations

diffstat:

 tests/usr.bin/indent/fmt_decl.c |  51 ++++++++++------------------------------
 usr.bin/indent/debug.c          |   6 ++--
 usr.bin/indent/indent.c         |   5 ++-
 3 files changed, 19 insertions(+), 43 deletions(-)

diffs (173 lines):

diff -r 52c9fed0eb31 -r 7dab0b461bce tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Tue May 23 12:12:29 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Tue May 23 16:53:57 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.45 2023/05/23 06:43:19 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.46 2023/05/23 16:53:57 rillig Exp $     */
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -602,7 +602,8 @@ ToToken(bool cond)
 
 
 /*
- * Indent gets easily confused by unknown type names in struct declarations.
+ * Before indent.c 1.309 from 2023-05-23, indent easily got confused by unknown
+ * type names in struct declarations, as a ';' did not finish a declaration.
  */
 //indent input
 typedef struct OpenDirs {
@@ -611,20 +612,14 @@ typedef struct OpenDirs {
 }              OpenDirs;
 //indent end
 
-/* FIXME: The word 'HashTable' must not be aligned like a member name. */
-//indent run
-typedef struct OpenDirs {
-       CachedDirList   list;
-                       HashTable /* of CachedDirListNode */ table;
-}              OpenDirs;
-//indent end
+//indent run-equals-input -THashTable
 
-//indent run-equals-input -THashTable
+//indent run-equals-input
 
 
 /*
- * Indent gets easily confused by unknown type names, even in declarations
- * that are syntactically unambiguous.
+ * Before lexi.c 1.153 from 2021-11-25, indent easily got confused by unknown
+ * type names, even in declarations that are syntactically unambiguous.
  */
 //indent input
 static CachedDir *dot = NULL;
@@ -632,14 +627,12 @@ static CachedDir *dot = NULL;
 
 //indent run-equals-input -TCachedDir
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
 /*
- * Before lexi.c 1.156 from 2021-11-25, indent easily got confused by unknown
- * type names in declarations and generated 'HashEntry * he' with an extra
- * space.
+ * Before lexi.c 1.153 from 2021-11-25, indent easily got confused by unknown
+ * type names in declarations.
  */
 //indent input
 static CachedDir *
@@ -648,7 +641,6 @@ CachedDir_New(const char *name)
 }
 //indent end
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
@@ -697,15 +689,15 @@ CachedDir_Assign(CachedDir **var, Cached
 }
 //indent end
 
-//indent run-equals-input
+//indent run-equals-input -TCachedDir
 
-//indent run-equals-input -TCachedDir
+//indent run-equals-input
 
 
 /*
  * Before lexi.c 1.153 from 2021-11-25, all initializer expressions after the
- * first one were indented as if they would be statement continuations. This
- * was because the token 'Shell' was identified as a word, not as a type name.
+ * first one were indented as if they were statement continuations. This was
+ * caused by the token 'Shell' being identified as a word, not as a type name.
  */
 //indent input
 static Shell   shells[] = {
@@ -716,7 +708,6 @@ static Shell        shells[] = {
 };
 //indent end
 
-/* Since lexi.c 1.153 from 2021-11-25. */
 //indent run-equals-input
 
 
@@ -963,22 +954,6 @@ ch_isalpha(char ch)
 
 
 //indent input
-struct {
-       void *list;
-       Table /* comment */ table;
-} var;
-//indent end
-
-//indent run -di0
-struct {
-       void *list;
-// $ FIXME: Wrong indentation, as 'Table' starts a new declaration.
-            Table /* comment */ table;
-} var;
-//indent end
-
-
-//indent input
 void __printflike(1, 2)
 debug_printf(const char *fmt, ...)
 {
diff -r 52c9fed0eb31 -r 7dab0b461bce usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Tue May 23 12:12:29 2023 +0000
+++ b/usr.bin/indent/debug.c    Tue May 23 16:53:57 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.22 2023/05/23 12:12:29 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -134,7 +134,7 @@ static const char *const decl_ptr_name[]
        "other",
 };
 
-static unsigned wrote_newlines;
+static unsigned wrote_newlines = 1;
 
 void
 debug_printf(const char *fmt, ...)
diff -r 52c9fed0eb31 -r 7dab0b461bce usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue May 23 12:12:29 2023 +0000
+++ b/usr.bin/indent/indent.c   Tue May 23 16:53:57 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.309 2023/05/23 16:53:57 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.308 2023/05/23 12:12:29 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.309 2023/05/23 16:53:57 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -687,6 +687,7 @@ process_semicolon(void)
        buf_add_char(&code, ';');
        ps.want_blank = true;
        ps.in_stmt_or_decl = ps.nparen > 0;
+       ps.decl_ind = 0;
 
        if (ps.spaced_expr_psym == psym_0) {
                parse(psym_0);  /* let parser know about end of stmt */



Home | Main Index | Thread Index | Old Index