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: clean up a condition, add comments



details:   https://anonhg.NetBSD.org/src/rev/4a5348aa6747
branches:  trunk
changeset: 374792:4a5348aa6747
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 13 09:40:47 2023 +0000

description:
indent: clean up a condition, add comments

No functional change.

diffstat:

 tests/usr.bin/indent/label.c |   3 ++-
 usr.bin/indent/indent.c      |   9 ++++-----
 usr.bin/indent/indent.h      |  11 ++++++-----
 3 files changed, 12 insertions(+), 11 deletions(-)

diffs (86 lines):

diff -r e97ce234ef16 -r 4a5348aa6747 tests/usr.bin/indent/label.c
--- a/tests/usr.bin/indent/label.c      Sat May 13 09:27:49 2023 +0000
+++ b/tests/usr.bin/indent/label.c      Sat May 13 09:40:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */
+/*     $NetBSD: label.c,v 1.6 2023/05/13 09:40:47 rillig Exp $ */
 
 /* See FreeBSD r303489 */
 
@@ -21,6 +21,7 @@ void
 t(void)
 {
        switch (1)
+/* $ TODO: Move the '{' up to the ')'. */
        {
        case 1:                 /* test */
        case 2:                 /* test */
diff -r e97ce234ef16 -r 4a5348aa6747 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat May 13 09:27:49 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat May 13 09:40:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.257 2023/05/13 08:33:39 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.258 2023/05/13 09:40:47 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c  5.1
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.257 2023/05/13 08:33:39 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.258 2023/05/13 09:40:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -485,9 +485,8 @@ process_lparen_or_lbracket(void)
     debug_println("paren_indents[%d] is now %d",
        ps.nparen - 1, ps.paren[ps.nparen - 1].indent);
 
-    if (ps.spaced_expr_psym != psym_0
-           && ps.nparen == 1 && opt.extra_expr_indent
-           && ps.paren[0].indent < 2 * opt.indent_size) {
+    if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
+           && ps.nparen == 1 && ps.paren[0].indent < 2 * opt.indent_size) {
        ps.paren[0].indent = (short)(2 * opt.indent_size);
        debug_println("paren_indents[0] is now %d", ps.paren[0].indent);
     }
diff -r e97ce234ef16 -r 4a5348aa6747 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat May 13 09:27:49 2023 +0000
+++ b/usr.bin/indent/indent.h   Sat May 13 09:40:47 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.123 2023/05/13 09:27:49 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.124 2023/05/13 09:40:47 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -120,7 +120,7 @@ typedef enum parser_symbol {
     psym_if_expr,              /* 'if' '(' expr ')' */
     psym_if_expr_stmt,         /* 'if' '(' expr ')' stmt */
     psym_if_expr_stmt_else,    /* 'if' '(' expr ')' stmt 'else' */
-    psym_else,                 /* 'else' */
+    psym_else,                 /* 'else'; not stored on the stack */
     psym_switch_expr,          /* 'switch' '(' expr ')' */
     psym_do,                   /* 'do' */
     psym_do_stmt,              /* 'do' stmt */
@@ -184,8 +184,8 @@ extern struct options {
                                 * placed this many indentation levels to the
                                 * left of code */
     bool extra_expr_indent;    /* whether continuation lines from the
-                                * expression part of "if(e)", "while(e)",
-                                * "for(e;e;e)" should be indented an extra
+                                * expression part of "if (e)", "while (e)",
+                                * "for (e; e; e)" should be indented an extra
                                 * tab stop so that they don't conflict with
                                 * the code that follows */
     bool else_if;              /* whether else-if pairs should be handled
@@ -254,7 +254,8 @@ extern struct parser_state {
                                 * 1 of the unformatted input */
     bool next_col_1;
     bool next_unary;           /* whether the following operator should be
-                                * unary */
+                                * unary; is used in declarations for '*', as
+                                * well as in expressions */
 
     bool is_function_definition;
 



Home | Main Index | Thread Index | Old Index