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 formatting of declarations with p...
details: https://anonhg.NetBSD.org/src/rev/a67b0a996ad4
branches: trunk
changeset: 376125:a67b0a996ad4
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jun 02 11:43:07 2023 +0000
description:
indent: fix formatting of declarations with preprocessing lines
diffstat:
tests/usr.bin/indent/opt_bc.c | 15 ++++++++++-----
usr.bin/indent/debug.c | 5 +++--
usr.bin/indent/indent.c | 15 ++++++++-------
usr.bin/indent/indent.h | 7 ++++---
usr.bin/indent/parse.c | 13 +++++--------
5 files changed, 30 insertions(+), 25 deletions(-)
diffs (194 lines):
diff -r 0a4cbf587a72 -r a67b0a996ad4 tests/usr.bin/indent/opt_bc.c
--- a/tests/usr.bin/indent/opt_bc.c Fri Jun 02 11:26:21 2023 +0000
+++ b/tests/usr.bin/indent/opt_bc.c Fri Jun 02 11:43:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bc.c,v 1.7 2023/06/02 11:26:21 rillig Exp $ */
+/* $NetBSD: opt_bc.c,v 1.8 2023/06/02 11:43:07 rillig Exp $ */
/*
* Tests for the options '-bc' and '-nbc'.
@@ -65,6 +65,11 @@ double a, b, c;
//indent end
+/*
+ * Before indent.c 1.311 from 2023-06-02, indent formatted the two '#if'
+ * branches differently and merged the 'b, c' with the preceding preprocessing
+ * line.
+ */
//indent input
int a,
#if 0
@@ -81,16 +86,16 @@ int a,
c;
int d;
#else
-// $ FIXME: The '#else' branch must be indented like the '#if' branch.
- b, c;
+ b,
+ c;
int d;
#endif
//indent end
//indent run -nbc
int a,
-// $ FIXME: 'b, c' must not be merged into the preprocessing line.
-#if 0 b, c;
+#if 0
+ b, c;
int d;
#else
b, c;
diff -r 0a4cbf587a72 -r a67b0a996ad4 usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Fri Jun 02 11:26:21 2023 +0000
+++ b/usr.bin/indent/debug.c Fri Jun 02 11:43:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.24 2023/06/02 11:43:07 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.23 2023/05/23 16:53:57 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.24 2023/06/02 11:43:07 rillig Exp $");
#include <stdarg.h>
@@ -296,6 +296,7 @@ debug_parser_state(void)
debug_ps_bool(next_unary);
debug_ps_bool(is_function_definition);
debug_ps_bool(want_blank);
+ debug_ps_bool(break_after_comma);
debug_ps_bool(force_nl);
debug_ps_int(line_start_nparen);
debug_ps_int(nparen);
diff -r 0a4cbf587a72 -r a67b0a996ad4 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Jun 02 11:26:21 2023 +0000
+++ b/usr.bin/indent/indent.c Fri Jun 02 11:43:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.310 2023/05/23 18:16:28 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.311 2023/06/02 11:43:07 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.310 2023/05/23 18:16:28 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.311 2023/06/02 11:43:07 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -81,7 +81,6 @@ struct buffer code;
struct buffer com;
bool found_err;
-bool break_comma;
float case_ind;
bool had_eof;
int line_no = 1;
@@ -450,9 +449,11 @@ move_com_to_code(lexer_symbol lsym)
static void
process_newline(void)
{
- if (ps.prev_token == lsym_comma && ps.nparen == 0 && !ps.block_init &&
- !opt.break_after_comma && break_comma &&
- com.len == 0)
+ if (ps.prev_token == lsym_comma
+ && ps.nparen == 0 && !ps.block_init
+ && !opt.break_after_comma && ps.break_after_comma
+ && lab.len == 0 /* for preprocessing lines */
+ && com.len == 0)
goto stay_in_line;
output_line();
@@ -947,7 +948,7 @@ process_comma(void)
if (ps.block_init_level <= 0)
ps.block_init = false;
int typical_varname_length = 8;
- if (break_comma && (opt.break_after_comma ||
+ if (ps.break_after_comma && (opt.break_after_comma ||
ind_add(compute_code_indent(), code.st, code.len)
>= opt.max_line_length - typical_varname_length))
ps.force_nl = true;
diff -r 0a4cbf587a72 -r a67b0a996ad4 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Jun 02 11:26:21 2023 +0000
+++ b/usr.bin/indent/indent.h Fri Jun 02 11:43:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.159 2023/05/23 12:12:29 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.160 2023/06/02 11:43:07 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -235,8 +235,6 @@ extern struct options {
} opt;
extern bool found_err;
-extern bool break_comma; /* when true and not in parentheses, break
- * after a comma */
extern float case_ind; /* indentation level to be used for a "case n:"
*/
extern bool had_eof; /* whether input is exhausted */
@@ -393,6 +391,9 @@ extern struct parser_state {
/* Vertical spacing */
+ bool break_after_comma; /* whether to add a newline after the next
+ * comma; used in declarations but not in
+ * initializer lists */
bool force_nl; /* whether the next token is forced to go to a
* new line; used after 'if (expr)' and in
* similar situations; tokens like '{' may
diff -r 0a4cbf587a72 -r a67b0a996ad4 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c Fri Jun 02 11:26:21 2023 +0000
+++ b/usr.bin/indent/parse.c Fri Jun 02 11:43:07 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.62 2023/05/23 12:12:29 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.63 2023/06/02 11:43:07 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: parse.c,v 1.62 2023/05/23 12:12:29 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.63 2023/06/02 11:43:07 rillig Exp $");
#include <err.h>
@@ -79,8 +79,7 @@ parse(parser_symbol psym)
if (ps.s_sym[ps.tos] == psym_decl)
break; /* only put one declaration onto stack */
- break_comma = true; /* while in a declaration, force a
- * newline after comma */
+ ps.break_after_comma = true;
ps.s_sym[++ps.tos] = psym_decl;
ps.s_ind_level[ps.tos] = ps.ind_level_follow;
@@ -105,8 +104,7 @@ parse(parser_symbol psym)
break;
case psym_lbrace:
- break_comma = false; /* don't break comma in an initializer
- * list */
+ ps.break_after_comma = false;
if (ps.s_sym[ps.tos] == psym_stmt
|| ps.s_sym[ps.tos] == psym_decl
|| ps.s_sym[ps.tos] == psym_stmt_list)
@@ -178,8 +176,7 @@ parse(parser_symbol psym)
break;
case psym_0: /* a simple statement */
- break_comma = false; /* don't break after comma in a
- * declaration */
+ ps.break_after_comma = false;
ps.s_sym[++ps.tos] = psym_stmt;
ps.s_ind_level[ps.tos] = ps.ind_level;
break;
Home |
Main Index |
Thread Index |
Old Index