Module Name: src Committed By: rillig Date: Fri Jun 16 11:48:32 UTC 2023
Modified Files: src/tests/usr.bin/indent: opt_bap.c src/usr.bin/indent: debug.c indent.c indent.h io.c Log Message: indent: don't force a blank line between '}' and preprocessing line To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_bap.c cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/debug.c cvs rdiff -u -r1.372 -r1.373 src/usr.bin/indent/indent.c cvs rdiff -u -r1.199 -r1.200 src/usr.bin/indent/indent.h cvs rdiff -u -r1.226 -r1.227 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/opt_bap.c diff -u src/tests/usr.bin/indent/opt_bap.c:1.9 src/tests/usr.bin/indent/opt_bap.c:1.10 --- src/tests/usr.bin/indent/opt_bap.c:1.9 Tue May 23 06:18:00 2023 +++ src/tests/usr.bin/indent/opt_bap.c Fri Jun 16 11:48:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bap.c,v 1.9 2023/05/23 06:18:00 rillig Exp $ */ +/* $NetBSD: opt_bap.c,v 1.10 2023/06/16 11:48:32 rillig Exp $ */ /* * Tests for the options '-bap' and '-nbap' ("blank line after procedure @@ -113,6 +113,10 @@ example(void) //indent run-equals-input -bap +/* + * A preprocessing line after the end of a function body does not force a blank + * line, as these lines are not a different syntactic layer. + */ //indent input #if 0 void @@ -123,17 +127,20 @@ f(void) #endif //indent end -//indent run -bacc -bap -#if 0 -void -f(void) +//indent run-equals-input -bacc -bap + + +/* + * Do not add a blank line between the end of a function body and an '#undef', + * as this is a common way to undefine a function-local macro. + */ +//indent input +#define replace { } -// $ The following blank line may be considered optional, as it precedes a -// $ preprocessing line. In that case, the -bap option would only apply to -// $ elements on the same syntactic level, such as function definitions and -// $ other declarations. - -#else -#endif +#undef replace //indent end + +//indent run-equals-input -bap + +//indent run-equals-input -bap -bacc Index: src/usr.bin/indent/debug.c diff -u src/usr.bin/indent/debug.c:1.63 src/usr.bin/indent/debug.c:1.64 --- src/usr.bin/indent/debug.c:1.63 Fri Jun 16 11:27:49 2023 +++ src/usr.bin/indent/debug.c Fri Jun 16 11:48:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.63 2023/06/16 11:27:49 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.64 2023/06/16 11:48:32 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: debug.c,v 1.63 2023/06/16 11:27:49 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.64 2023/06/16 11:48:32 rillig Exp $"); #include <stdarg.h> #include <string.h> @@ -125,6 +125,7 @@ const char *const line_kind_name[] = { "blank", "#if", "#endif", + "#other", "stmt head", "}", "block comment", Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.372 src/usr.bin/indent/indent.c:1.373 --- src/usr.bin/indent/indent.c:1.372 Thu Jun 15 11:27:36 2023 +++ src/usr.bin/indent/indent.c Fri Jun 16 11:48:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.372 2023/06/15 11:27:36 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.373 2023/06/16 11:48:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: indent.c,v 1.372 2023/06/15 11:27:36 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.373 2023/06/16 11:48:32 rillig Exp $"); #include <sys/param.h> #include <err.h> @@ -527,21 +527,23 @@ process_preprocessing(void) sizeof(ifdef.item[0]) * ifdef.cap)); } parser_state_back_up(ifdef.item + ifdef.len++); - out.line_kind = lk_if; + out.line_kind = lk_pre_if; } else if (dir_len >= 2 && memcmp(dir, "el", 2) == 0) { if (ifdef.len == 0) diag(1, "Unmatched #%.*s", (int)dir_len, dir); else parser_state_restore(ifdef.item + ifdef.len - 1); + out.line_kind = lk_pre_other; } else if (dir_len == 5 && memcmp(dir, "endif", 5) == 0) { if (ifdef.len == 0) diag(1, "Unmatched #endif"); else parser_state_free(ifdef.item + --ifdef.len); - out.line_kind = lk_endif; - } + out.line_kind = lk_pre_endif; + } else + out.line_kind = lk_pre_other; } static void Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.199 src/usr.bin/indent/indent.h:1.200 --- src/usr.bin/indent/indent.h:1.199 Fri Jun 16 11:27:49 2023 +++ src/usr.bin/indent/indent.h Fri Jun 16 11:48:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.199 2023/06/16 11:27:49 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.200 2023/06/16 11:48:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -410,8 +410,9 @@ extern struct output_state { enum line_kind { lk_other, lk_blank, - lk_if, /* #if, #ifdef, #ifndef */ - lk_endif, /* #endif */ + lk_pre_if, /* #if, #ifdef, #ifndef */ + lk_pre_endif, /* #endif */ + lk_pre_other, /* #else, #elif, #define, #undef */ lk_stmt_head, /* the ')' of an incomplete statement such as * 'if (expr)' or 'for (expr; expr; expr)' */ lk_func_end, /* the last '}' of a function body */ Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.226 src/usr.bin/indent/io.c:1.227 --- src/usr.bin/indent/io.c:1.226 Fri Jun 16 11:27:49 2023 +++ src/usr.bin/indent/io.c Fri Jun 16 11:48:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.226 2023/06/16 11:27:49 rillig Exp $ */ +/* $NetBSD: io.c,v 1.227 2023/06/16 11:48:32 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: io.c,v 1.226 2023/06/16 11:27:49 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.227 2023/06/16 11:48:32 rillig Exp $"); #include <stdio.h> @@ -176,14 +176,15 @@ want_blank_line(void) return true; } if (opt.blank_line_around_conditional_compilation) { - if (out.prev_line_kind != lk_if && out.line_kind == lk_if) + if (out.prev_line_kind != lk_pre_if + && out.line_kind == lk_pre_if) return true; - if (out.prev_line_kind == lk_endif - && out.line_kind != lk_endif) + if (out.prev_line_kind == lk_pre_endif + && out.line_kind != lk_pre_endif) return true; } if (opt.blank_line_after_proc && out.prev_line_kind == lk_func_end - && out.line_kind != lk_endif) + && out.line_kind != lk_pre_endif && out.line_kind != lk_pre_other) return true; if (opt.blank_line_before_block_comment && out.line_kind == lk_block_comment)