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 statements after c...



details:   https://anonhg.NetBSD.org/src/rev/83a906425057
branches:  trunk
changeset: 375348:83a906425057
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 13:33:19 2023 +0000

description:
indent: fix indentation of statements after controlling expression

diffstat:

 tests/usr.bin/indent/opt_eei.c |  4 ++--
 usr.bin/indent/indent.c        |  9 +++++----
 usr.bin/indent/indent.h        |  8 ++++++--
 usr.bin/indent/io.c            |  8 +++++---
 4 files changed, 18 insertions(+), 11 deletions(-)

diffs (120 lines):

diff -r 6eef49449d2e -r 83a906425057 tests/usr.bin/indent/opt_eei.c
--- a/tests/usr.bin/indent/opt_eei.c    Mon May 15 13:28:05 2023 +0000
+++ b/tests/usr.bin/indent/opt_eei.c    Mon May 15 13:33:19 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_eei.c,v 1.11 2023/05/15 13:28:05 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.12 2023/05/15 13:33:19 rillig Exp $ */
 
 /*
  * Tests for the options '-eei' and '-neei'.
@@ -183,7 +183,7 @@ b)
            cond
        )
        stmt(
-               arg
+           arg
            );
 }
 //indent end
diff -r 6eef49449d2e -r 83a906425057 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon May 15 13:28:05 2023 +0000
+++ b/usr.bin/indent/indent.c   Mon May 15 13:33:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.275 2023/05/15 12:59:43 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.276 2023/05/15 13:33:19 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -348,7 +348,6 @@ maybe_break_line(lexer_symbol lsym)
        diag(0, "Line broken");
     output_line();
     ps.force_nl = false;
-    ps.extra_expr_indent = false;
 }
 
 static void
@@ -436,7 +435,7 @@ process_lparen_or_lbracket(void)
     if (opt.extra_expr_indent && !opt.lineup_to_parens
            && ps.spaced_expr_psym != psym_0 && ps.nparen == 1
            && opt.continuation_indent == opt.indent_size)
-       ps.extra_expr_indent = true;
+       ps.extra_expr_indent = eei_yes;
 
     if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
            && ps.nparen == 1 && ps.paren[0].indent < 2 * opt.indent_size) {
@@ -484,6 +483,8 @@ unbalanced:
     buf_add_char(&code, token.st[0]);
 
     if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) {
+       if (ps.extra_expr_indent == eei_yes)
+           ps.extra_expr_indent = eei_last;
        ps.force_nl = true;
        ps.next_unary = true;
        ps.in_stmt_or_decl = false;
diff -r 6eef49449d2e -r 83a906425057 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Mon May 15 13:28:05 2023 +0000
+++ b/usr.bin/indent/indent.h   Mon May 15 13:33:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.138 2023/05/15 12:59:43 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.139 2023/05/15 13:33:19 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -308,7 +308,11 @@ extern struct parser_state {
     int di_stack[20];          /* a stack of structure indentation levels */
     bool tabs_to_var;          /* true if using tabs to indent to var name */
 
-    bool extra_expr_indent;
+    enum {
+       eei_no,
+       eei_yes,
+       eei_last
+    } extra_expr_indent;
 
     enum {
        in_enum_no,             /* outside any 'enum { ... }' */
diff -r 6eef49449d2e -r 83a906425057 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Mon May 15 13:28:05 2023 +0000
+++ b/usr.bin/indent/io.c       Mon May 15 13:33:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $  */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.168 2023/05/15 12:59:43 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.169 2023/05/15 13:33:19 rillig Exp $");
 
 #include <stdio.h>
 #include <string.h>
@@ -274,6 +274,8 @@ output_complete_line(char line_terminato
     ps.decl_on_line = ps.in_decl;      /* for proper comment indentation */
     ps.in_stmt_cont = ps.in_stmt_or_decl && !ps.in_decl;
     ps.decl_indent_done = false;
+    if (ps.extra_expr_indent == eei_last)
+       ps.extra_expr_indent = eei_no;
 
     lab.len = 0;
     code.len = 0;
@@ -338,7 +340,7 @@ compute_code_indent(void)
        return compute_code_indent_lineup(base_ind);
     }
 
-    if (ps.extra_expr_indent)
+    if (ps.extra_expr_indent != eei_no)
        return base_ind + 2 * opt.continuation_indent;
 
     if (2 * opt.continuation_indent == opt.indent_size)



Home | Main Index | Thread Index | Old Index