indent: fix indentation of struct declarations

This commit is contained in:
rillig 2023-05-23 16:53:57 +00:00
parent fe5b389b2f
commit e9b5780b33
3 changed files with 19 additions and 43 deletions

View File

@ -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
/*
* 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, CachedDir *dir)
}
//indent end
//indent run-equals-input
//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
@ -962,22 +953,6 @@ ch_isalpha(char ch)
//indent run-equals-input -i4 -di0
//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, ...)

View File

@ -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, ...)

View File

@ -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 */