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 continuation lines...
details: https://anonhg.NetBSD.org/src/rev/df78e9790b57
branches: trunk
changeset: 376314:df78e9790b57
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jun 10 08:17:04 2023 +0000
description:
indent: fix indentation of continuation lines in initializers
diffstat:
tests/usr.bin/indent/fmt_expr.c | 44 ++++++++++++++++++++-----
tests/usr.bin/indent/lsym_lparen_or_lbracket.c | 4 +-
tests/usr.bin/indent/opt_ci.c | 10 +----
tests/usr.bin/indent/opt_lpl.c | 12 ++----
usr.bin/indent/indent.c | 23 ++-----------
usr.bin/indent/io.c | 8 ++--
6 files changed, 51 insertions(+), 50 deletions(-)
diffs (209 lines):
diff -r e424cb388407 -r df78e9790b57 tests/usr.bin/indent/fmt_expr.c
--- a/tests/usr.bin/indent/fmt_expr.c Sat Jun 10 07:53:00 2023 +0000
+++ b/tests/usr.bin/indent/fmt_expr.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_expr.c,v 1.6 2023/06/09 11:22:31 rillig Exp $ */
+/* $NetBSD: fmt_expr.c,v 1.7 2023/06/10 08:17:04 rillig Exp $ */
/*
* Tests for all kinds of expressions that are not directly related to unary
@@ -18,15 +18,6 @@
println((const char[3]){'-', c, '\0'});
x = ((struct point){0, 0}).x;
- // XXX: GCC statement expressions are not supported yet.
- int var =
- (
- {
- 1
- }
- )
- ;
-
for (ln = gnodes->first; ln != NULL; ln = ln->next)
// $ FIXME: No space after the cast.
*(GNode **) Vector_Push(&vec) = ln->datum;
@@ -34,3 +25,36 @@
//indent end
//indent run-equals-input
+
+
+/*
+ * GCC statement expressions are not supported yet.
+ */
+//indent input
+{
+ int var = ({1});
+ int var = ({
+ 1
+ });
+ int var = ({
+ int decl = 1;
+ stmt;
+ });
+}
+//indent end
+
+//indent run -di0
+error: Standard Input:7: Unbalanced parentheses
+warning: Standard Input:9: Extra ')'
+{
+ int var = ({1});
+ int var = ({
+ 1
+ });
+ int var = ({
+ int decl = 1;
+ stmt;
+ });
+}
+exit 1
+//indent end
diff -r e424cb388407 -r df78e9790b57 tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sat Jun 10 07:53:00 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.15 2023/06/08 20:55:22 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.16 2023/06/10 08:17:04 rillig Exp $ */
/*
* Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -289,7 +289,7 @@ cover_want_blank_before_lparen(void)
{
/* ps.prev_lsym can never be 'newline'. */
int newline =
- (3);
+ (3);
int lparen_or_lbracket = a[(3)];
int rparen_or_rbracket = a[3](5);
diff -r e424cb388407 -r df78e9790b57 tests/usr.bin/indent/opt_ci.c
--- a/tests/usr.bin/indent/opt_ci.c Sat Jun 10 07:53:00 2023 +0000
+++ b/tests/usr.bin/indent/opt_ci.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.10 2023/06/09 06:36:58 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.11 2023/06/10 08:17:04 rillig Exp $ */
/*
* Tests for the option '-ci', which controls the indentation of continuation
@@ -238,10 +238,4 @@ function(void)
}
//indent end
-//indent run -ldi0 -ci4
-{
- size_t last_word_len = com.len
-/* $ FIXME: The '-' must be indented by 4 spaces. */
- - (size_t)(last_blank + 1);
-}
-//indent end
+//indent run-equals-input -ldi0 -ci4
diff -r e424cb388407 -r df78e9790b57 tests/usr.bin/indent/opt_lpl.c
--- a/tests/usr.bin/indent/opt_lpl.c Sat Jun 10 07:53:00 2023 +0000
+++ b/tests/usr.bin/indent/opt_lpl.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lpl.c,v 1.7 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_lpl.c,v 1.8 2023/06/10 08:17:04 rillig Exp $ */
/*
* Tests for the options '-lpl' and '-nlpl'.
@@ -46,13 +46,11 @@ example(void)
int sum1 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21;
int sum2 = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21);
-/* $ XXX: There should be at least _some_ indentation for the */
-/* $ continuation lines. */
int sum3 = 1 + 2 + 3 + 4 + 5 +
- 6 + 7 + 8 + 9 + 10 +
- 11 + 12 + 13 + 14 + 15 +
- 16 + 17 + 18 + 19 + 20 +
- 21;
+ 6 + 7 + 8 + 9 + 10 +
+ 11 + 12 + 13 + 14 + 15 +
+ 16 + 17 + 18 + 19 + 20 +
+ 21;
int sum4 = (1 + 2 + 3 + 4 + 5 +
6 + 7 + 8 + 9 + 10 +
11 + 12 + 13 + 14 + 15 +
diff -r e424cb388407 -r df78e9790b57 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Jun 10 07:53:00 2023 +0000
+++ b/usr.bin/indent/indent.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.351 2023/06/10 07:42:41 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.352 2023/06/10 08:17:04 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.351 2023/06/10 07:42:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.352 2023/06/10 08:17:04 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -776,21 +776,6 @@ process_postfix_op(void)
}
static void
-process_question(void)
-{
- ps.quest_level++;
- if (code.len == 0)
- ps.in_stmt_cont = true; // XXX: should be unnecessary.
-}
-
-static void
-process_colon_question(void)
-{
- if (code.len == 0)
- ps.in_stmt_cont = true; // XXX: should be unnecessary.
-}
-
-static void
process_comma(void)
{
ps.want_blank = code.len > 0; /* only put blank after comma if comma
@@ -985,8 +970,8 @@ process_lsym(lexer_symbol lsym)
case lsym_unary_op: process_unary_op(); break;
case lsym_postfix_op: process_postfix_op(); break;
case lsym_binary_op: goto copy_token;
- case lsym_question: process_question(); goto copy_token;
- case lsym_colon_question: process_colon_question(); goto copy_token;
+ case lsym_question: ps.quest_level++; goto copy_token;
+ case lsym_colon_question: goto copy_token;
case lsym_colon_label: process_colon_label(); break;
case lsym_colon_other: process_colon_other(); break;
case lsym_comma: process_comma(); break;
diff -r e424cb388407 -r df78e9790b57 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat Jun 10 07:53:00 2023 +0000
+++ b/usr.bin/indent/io.c Sat Jun 10 08:17:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.212 2023/06/10 07:53:00 rillig Exp $ */
+/* $NetBSD: io.c,v 1.213 2023/06/10 08:17:04 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.212 2023/06/10 07:53:00 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.213 2023/06/10 08:17:04 rillig Exp $");
#include <stdio.h>
@@ -383,9 +383,9 @@ output_line(void)
ps.line_has_decl = ps.in_decl;
ps.line_has_func_def = false;
- // XXX: don't reset in_stmt_cont here; see process_colon_question.
ps.in_stmt_cont = ps.in_stmt_or_decl
- && !ps.in_decl && ps.init_level == 0;
+ && (!ps.in_decl || ps.in_init)
+ && ps.init_level == 0;
ps.decl_indent_done = false;
if (ps.extra_expr_indent == eei_last)
ps.extra_expr_indent = eei_no;
Home |
Main Index |
Thread Index |
Old Index