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: remove redundant comments, remove pun...



details:   https://anonhg.NetBSD.org/src/rev/05212caad84f
branches:  trunk
changeset: 990535:05212caad84f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 29 23:48:50 2021 +0000

description:
indent: remove redundant comments, remove punctuation from debug log

The comment about 'null stmt' between braces probably meant 'no
statements between braces'.

The comments at psym_switch_expr only repeated what the code says or had
been outdated 29 years ago already since opt.case_indent does not have
to be 'one level down'.

In the debug log, the quotes around the symbol names are not necessary
after a ':'. The parse stack also does not need this much punctuation.

Reducing a do-while loop to nothing instead of a statement saves a few
CPU cycles. It works because after each lbrace, a stmt is pushed to the
parser stack. This stmt can only ever be reduced to a stmt_list but
never be removed.

diffstat:

 usr.bin/indent/indent.c |   5 +++--
 usr.bin/indent/lexi.c   |   6 +++---
 usr.bin/indent/parse.c  |  12 ++++--------
 3 files changed, 10 insertions(+), 13 deletions(-)

diffs (109 lines):

diff -r 952aebad8adb -r 05212caad84f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 29 23:23:33 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 29 23:48:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.179 2021/10/29 23:48:50 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.178 2021/10/29 21:56:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.179 2021/10/29 23:48:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -342,6 +342,7 @@
     }
 
     struct parser_state backup_ps = ps;
+    debug_println("made backup of parser state");
     *lsym = lexi();
     if (*lsym == lsym_newline || *lsym == lsym_form_feed ||
        *lsym == lsym_comment || ps.search_stmt) {
diff -r 952aebad8adb -r 05212caad84f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Oct 29 23:23:33 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Oct 29 23:48:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.114 2021/10/29 23:48:50 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.113 2021/10/29 21:31:29 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.114 2021/10/29 23:48:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -318,7 +318,7 @@
     debug_print_buf("label", &lab);
     debug_print_buf("code", &code);
     debug_print_buf("comment", &com);
-    debug_printf("lexi returns '%s'", lsym_name(lsym));
+    debug_printf("lexi: %s", lsym_name(lsym));
     debug_vis_range(" \"", token.s, token.e, "\"\n");
 
     // prev_token
diff -r 952aebad8adb -r 05212caad84f usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Fri Oct 29 23:23:33 2021 +0000
+++ b/usr.bin/indent/parse.c    Fri Oct 29 23:48:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.46 2021/10/29 23:03:53 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.47 2021/10/29 23:48:50 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -101,7 +101,7 @@
 void
 parse(parser_symbol psym)
 {
-    debug_println("parse token: '%s'", psym_name(psym));
+    debug_println("parse token: %s", psym_name(psym));
 
     if (psym != psym_else) {
        while (ps.s_sym[ps.tos] == psym_if_expr_stmt) {
@@ -168,7 +168,6 @@
        ps.s_sym[++ps.tos] = psym_lbrace;
        ps.s_ind_level[ps.tos] = ps.ind_level;
        ps.s_sym[++ps.tos] = psym_stmt;
-       /* allow null stmt between braces */
        ps.s_ind_level[ps.tos] = ps.ind_level_follow;
        break;
 
@@ -213,11 +212,8 @@
     case psym_switch_expr:
        ps.s_sym[++ps.tos] = psym_switch_expr;
        ps.s_case_ind_level[ps.tos] = case_ind;
-       /* save current case indent level */
        ps.s_ind_level[ps.tos] = ps.ind_level_follow;
-       /* cases should be one level deeper than the switch */
        case_ind = (float)ps.ind_level_follow + opt.case_indent;
-       /* statements should be two levels deeper */
        ps.ind_level_follow += (int)opt.case_indent + 1;
        ps.search_stmt = opt.brace_same_line;
        break;
@@ -241,7 +237,7 @@
 #ifdef debug
     printf("parse stack:");
     for (int i = 1; i <= ps.tos; ++i)
-       printf(" ('%s' at %d)", psym_name(ps.s_sym[i]), ps.s_ind_level[i]);
+       printf(" %s %d", psym_name(ps.s_sym[i]), ps.s_ind_level[i]);
     if (ps.tos == 0)
        printf(" empty");
     printf("\n");
@@ -322,7 +318,7 @@
        goto again;
     if (ps.s_sym[ps.tos] == psym_while_expr &&
            ps.s_sym[ps.tos - 1] == psym_do_stmt) {
-       ps.tos -= 2;            /* XXX: why not reduce to stmt? */
+       ps.tos -= 2;
        goto again;
     }
 }



Home | Main Index | Thread Index | Old Index