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



details:   https://anonhg.NetBSD.org/src/rev/3939ff42c5fb
branches:  trunk
changeset: 1024018:3939ff42c5fb
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 07 21:38:25 2021 +0000

description:
indent: remove redundant comments

No functional change.

diffstat:

 usr.bin/indent/indent.c     |  36 +++++++++++++++++-------------------
 usr.bin/indent/io.c         |  14 ++++----------
 usr.bin/indent/parse.c      |  31 ++++++++++---------------------
 usr.bin/indent/pr_comment.c |  11 +++++------
 4 files changed, 36 insertions(+), 56 deletions(-)

diffs (300 lines):

diff -r 2b99d22553c1 -r 3939ff42c5fb usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Oct 07 21:16:36 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Oct 07 21:38:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.115 2021/10/07 21:16:36 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 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.115 2021/10/07 21:16:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -427,9 +427,8 @@
 {
     found_err = false;
 
-    ps.p_stack[0] = stmt;      /* this is the parser's stack */
-    ps.last_nl = true;         /* this is true if the last thing scanned was
-                                * a newline */
+    ps.p_stack[0] = stmt;
+    ps.last_nl = true;
     ps.last_token = semicolon;
     buf_init(&com);
     buf_init(&lab);
@@ -597,7 +596,7 @@
 static void
 process_form_feed(void)
 {
-    ps.use_ff = true;          /* a form feed is treated much like a newline */
+    ps.use_ff = true;
     dump_line();
     ps.want_blank = false;
 }
@@ -610,7 +609,7 @@
        dump_line();
        ps.want_blank = false;
     }
-    ++line_no;                 /* keep track of input line number */
+    ++line_no;
 }
 
 static bool
@@ -901,9 +900,8 @@
        ps.in_decl = false;
     }
     *decl_ind = 0;
-    parse(lbrace);             /* let parser know about this */
-    if (ps.want_blank)         /* put a blank before '{' if '{' is not at
-                                * start of line */
+    parse(lbrace);
+    if (ps.want_blank)
        *code.e++ = ' ';
     ps.want_blank = false;
     *code.e++ = '{';
@@ -1290,41 +1288,41 @@
            process_rparen_or_rbracket(&sp_sw, &force_nl, hd_type);
            break;
 
-       case unary_op:          /* this could be any unary operation */
+       case unary_op:
            process_unary_op(decl_ind, tabs_to_var);
            break;
 
-       case binary_op:         /* any binary operation */
+       case binary_op:
            process_binary_op();
            break;
 
-       case postfix_op:        /* got a trailing ++ or -- */
+       case postfix_op:
            process_postfix_op();
            break;
 
-       case question:          /* got a ? */
+       case question:
            process_question(&seen_quest);
            break;
 
        case case_label:        /* got word 'case' or 'default' */
-           seen_case = true;   /* so we can process the later colon properly */
+           seen_case = true;
            goto copy_token;
 
-       case colon:             /* got a ':' */
+       case colon:
            process_colon(&seen_quest, &force_nl, &seen_case);
            break;
 
-       case semicolon:         /* got a ';' */
+       case semicolon:
            process_semicolon(&seen_case, &seen_quest, decl_ind, tabs_to_var,
                &sp_sw, hd_type, &force_nl);
            break;
 
-       case lbrace:            /* got a '{' */
+       case lbrace:
            process_lbrace(&force_nl, &sp_sw, hd_type, di_stack,
                (int)nitems(di_stack), &decl_ind);
            break;
 
-       case rbrace:            /* got a '}' */
+       case rbrace:
            process_rbrace(&sp_sw, &decl_ind, di_stack);
            break;
 
diff -r 2b99d22553c1 -r 3939ff42c5fb usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Oct 07 21:16:36 2021 +0000
+++ b/usr.bin/indent/io.c       Thu Oct 07 21:38:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.76 2021/10/07 21:38:25 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.76 2021/10/07 21:38:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -257,14 +257,8 @@
        && token.s < token.e && isspace((unsigned char)token.s[0]))
        output_range(token.s, token.e);
 
-    ps.decl_on_line = ps.in_decl;      /* if we are in the middle of a
-                                        * declaration, remember that fact for
-                                        * proper comment indentation */
-    ps.ind_stmt = ps.in_stmt && !ps.in_decl;   /* next line should be
-                                                * indented if we have not
-                                                * completed this stmt and if
-                                                * we are not in the middle of
-                                                * a declaration */
+    ps.decl_on_line = ps.in_decl;      /* for proper comment indentation */
+    ps.ind_stmt = ps.in_stmt && !ps.in_decl;
     ps.use_ff = false;
     ps.dumped_decl_indent = false;
     *(lab.e = lab.s) = '\0';   /* reset buffers */
diff -r 2b99d22553c1 -r 3939ff42c5fb usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Thu Oct 07 21:16:36 2021 +0000
+++ b/usr.bin/indent/parse.c    Thu Oct 07 21:38:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.29 2021/10/05 06:55:24 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.30 2021/10/07 21:38:25 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -70,9 +70,7 @@
        reduce();               /* see if this allows any reduction */
     }
 
-
-    switch (ttype) {           /* go on and figure out what to do with the
-                                * input */
+    switch (ttype) {
 
     case decl:                 /* scanned a declaration word */
        ps.search_brace = opt.btype_2;
@@ -84,8 +82,7 @@
            ps.p_stack[++ps.tos] = decl;
            ps.il[ps.tos] = ps.ind_level_follow;
 
-           if (opt.ljust_decl) {       /* only do if we want left justified
-                                        * declarations */
+           if (opt.ljust_decl) {
                ps.ind_level = 0;
                for (int i = ps.tos - 1; i > 0; --i)
                    if (ps.p_stack[i] == decl)
@@ -99,15 +96,14 @@
     case if_expr:              /* 'if' '(' <expr> ')' */
        if (ps.p_stack[ps.tos] == if_expr_stmt_else && opt.else_if) {
            /*
-            * Note that the stack pointer here is decremented, effectively
-            * reducing "else if" to "if". This saves a lot of stack space in
+            * Reduce "else if" to "if". This saves a lot of stack space in
             * case of a long "if-else-if ... else-if" sequence.
             */
            ps.ind_level_follow = ps.il[ps.tos--];
        }
        /* the rest is the same as for keyword_do and for_exprs */
        /* FALLTHROUGH */
-    case keyword_do:           /* 'do' */
+    case keyword_do:
     case for_exprs:            /* 'for' (...) */
        ps.p_stack[++ps.tos] = ttype;
        ps.il[ps.tos] = ps.ind_level = ps.ind_level_follow;
@@ -115,7 +111,7 @@
        ps.search_brace = opt.btype_2;
        break;
 
-    case lbrace:               /* scanned { */
+    case lbrace:
        break_comma = false;    /* don't break comma in an initial list */
        if (ps.p_stack[ps.tos] == stmt || ps.p_stack[ps.tos] == decl
                || ps.p_stack[ps.tos] == stmt_list)
@@ -123,9 +119,6 @@
                                 * group or a declaration */
        else {
            if (code.s == code.e) {
-               /*
-                * only do this if there is nothing on the line
-                */
                --ps.ind_level;
                /*
                 * it is a group as part of a while, for, etc.
@@ -166,16 +159,14 @@
        else {
            ps.ind_level = ps.il[ps.tos];       /* indentation for else should
                                                 * be same as for if */
-           ps.ind_level_follow = ps.ind_level + 1;     /* everything following
-                                                        * should be 1 level
-                                                        * deeper */
+           ps.ind_level_follow = ps.ind_level + 1;
            ps.p_stack[ps.tos] = if_expr_stmt_else;
            /* remember if with else */
            ps.search_brace = opt.btype_2 | opt.else_if;
        }
        break;
 
-    case rbrace:               /* scanned a } */
+    case rbrace:
        /* stack should have <lbrace> <stmt> or <lbrace> <stmt_list> */
        if (ps.tos > 0 && ps.p_stack[ps.tos - 1] == lbrace) {
            ps.ind_level = ps.ind_level_follow = ps.il[--ps.tos];
@@ -203,12 +194,10 @@
        ps.il[ps.tos] = ps.ind_level;
        break;
 
-    default:                   /* this is an error */
+    default:
        diag(1, "Unknown code to parser");
        return;
-
-
-    }                          /* end of switch */
+    }
 
     if (ps.tos >= STACKSIZE - 1)
        errx(1, "Parser stack overflow");
diff -r 2b99d22553c1 -r 3939ff42c5fb usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Thu Oct 07 21:16:36 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Thu Oct 07 21:38:25 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.53 2021/10/05 19:58:38 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.54 2021/10/07 21:38:25 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.53 2021/10/05 19:58:38 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.54 2021/10/07 21:38:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -211,7 +211,6 @@
            check_size_comment(3);
            if (!ps.box_com) {  /* in a text comment, break the line here */
                ps.use_ff = true;
-               /* fix so dump_line uses a form feed */
                dump_line();
                last_blank = -1;
                if (!ps.box_com && opt.star_comment_cont)
@@ -230,7 +229,7 @@
                ++line_no;
                goto end_of_comment;
            }
-           if (had_eof) {      /* check for unexpected eof */
+           if (had_eof) {
                printf("Unterminated comment\n");
                dump_line();
                return;
@@ -255,7 +254,7 @@
                    *com.e++ = ' ';
                last_blank = com.e - 1 - com.buf;
            }
-           ++line_no;          /* keep track of input line number */
+           ++line_no;
            if (!ps.box_com) {
                int asterisks_to_skip = 1;
                do {            /* flush any blanks and/or tabs at start of
@@ -274,7 +273,7 @@
        case '*':
            inbuf_skip();
            check_size_comment(4);
-           if (*buf_ptr == '/') {      /* end of the comment */
+           if (*buf_ptr == '/') {
        end_of_comment:
                inbuf_skip();
                if (break_delim) {



Home | Main Index | Thread Index | Old Index