Module Name:    src
Committed By:   rillig
Date:           Fri Oct 29 23:48:50 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c lexi.c parse.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.178 src/usr.bin/indent/indent.c:1.179
--- src/usr.bin/indent/indent.c:1.178	Fri Oct 29 21:56:36 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 23:48:50 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ search_stmt_lookahead(lexer_symbol *lsym
     }
 
     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) {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.113 src/usr.bin/indent/lexi.c:1.114
--- src/usr.bin/indent/lexi.c:1.113	Fri Oct 29 21:31:29 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 23:48:50 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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_lexi(lexer_symbol lsym)
     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

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.46 src/usr.bin/indent/parse.c:1.47
--- src/usr.bin/indent/parse.c:1.46	Fri Oct 29 23:03:53 2021
+++ src/usr.bin/indent/parse.c	Fri Oct 29 23:48:50 2021
@@ -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 @@ decl_level(void)
 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 @@ parse(parser_symbol psym)
 	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 @@ parse(parser_symbol psym)
     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 @@ parse(parser_symbol psym)
 #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 @@ again:
 	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;
     }
 }

Reply via email to