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: change parser_state.cast_mask to 0-ba...



details:   https://anonhg.NetBSD.org/src/rev/750810fe1720
branches:  trunk
changeset: 361533:750810fe1720
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 13 12:09:19 2022 +0000

description:
indent: change parser_state.cast_mask to 0-based indexing

Having 1-based indexing was completely unexpected, and it didn't match
the 0-based indexing of parser_state.paren_indents.

No functional change.

diffstat:

 usr.bin/indent/indent.c |  16 ++++++++--------
 usr.bin/indent/indent.h |   6 +++---
 usr.bin/indent/lexi.c   |  10 +++++-----
 3 files changed, 16 insertions(+), 16 deletions(-)

diffs (112 lines):

diff -r 432647769b99 -r 750810fe1720 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Feb 13 12:04:37 2022 +0000
+++ b/usr.bin/indent/indent.c   Sun Feb 13 12:09:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.239 2021/11/28 14:29:03 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.240 2022/02/13 12:09:19 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.239 2021/11/28 14:29:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.240 2022/02/13 12:09:19 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -721,19 +721,19 @@
 
     /* parenthesized type following sizeof or offsetof is not a cast */
     if (ps.prev_token == lsym_offsetof || ps.prev_token == lsym_sizeof)
-       ps.not_cast_mask |= 1 << ps.p_l_follow;
+       ps.not_cast_mask0 |= 1 << (ps.p_l_follow - 1);
 }
 
 static void
 process_rparen_or_rbracket(bool *spaced_expr, bool *force_nl, stmt_head hd)
 {
-    if ((ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) != 0) {
+    if ((ps.cast_mask0 & (1 << (ps.p_l_follow - 1)) & ~ps.not_cast_mask0) != 0) {
        ps.next_unary = true;
-       ps.cast_mask &= (1 << ps.p_l_follow) - 1;
+       ps.cast_mask0 &= (1 << (ps.p_l_follow - 1)) - 1;
        ps.want_blank = opt.space_after_cast;
     } else
        ps.want_blank = true;
-    ps.not_cast_mask &= (1 << ps.p_l_follow) - 1;
+    ps.not_cast_mask0 &= (1 << (ps.p_l_follow - 1)) - 1;
 
     if (ps.p_l_follow > 0)
        ps.p_l_follow--;
@@ -855,8 +855,8 @@
     *quest_level = 0;
     if (ps.prev_token == lsym_rparen_or_rbracket)
        ps.in_func_def_params = false;
-    ps.cast_mask = 0;
-    ps.not_cast_mask = 0;
+    ps.cast_mask0 = 0;
+    ps.not_cast_mask0 = 0;
     ps.block_init = false;
     ps.block_init_level = 0;
     ps.just_saw_decl--;
diff -r 432647769b99 -r 750810fe1720 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sun Feb 13 12:04:37 2022 +0000
+++ b/usr.bin/indent/indent.h   Sun Feb 13 12:09:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.108 2022/02/12 19:56:52 rillig Exp $      */
+/*     $NetBSD: indent.h,v 1.109 2022/02/13 12:09:19 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -272,9 +272,9 @@
                                 * level of parentheses or brackets, relative
                                 * to the enclosing statement; if negative,
                                 * reflected at -1 */
-    int cast_mask;             /* indicates which close parentheses
+    int cast_mask0;            /* indicates which close parentheses
                                 * potentially close off casts */
-    int not_cast_mask;         /* indicates which close parentheses
+    int not_cast_mask0;                /* indicates which close parentheses
                                 * definitely close off something else than
                                 * casts */
 
diff -r 432647769b99 -r 750810fe1720 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sun Feb 13 12:04:37 2022 +0000
+++ b/usr.bin/indent/lexi.c     Sun Feb 13 12:09:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.169 2022/02/12 19:56:52 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.170 2022/02/13 12:09:19 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.169 2022/02/12 19:56:52 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.170 2022/02/13 12:09:19 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -293,8 +293,8 @@
            debug_printf(" %d", ps.paren_indents[i]);
        debug_println("");
     }
-    debug_ps_int(cast_mask);
-    debug_ps_int(not_cast_mask);
+    debug_ps_int(cast_mask0);
+    debug_ps_int(not_cast_mask0);
 
     debug_ps_int(comment_delta);
     debug_ps_int(n_comment_delta);
@@ -556,7 +556,7 @@
 found_typename:
        if (ps.p_l_follow > 0) {
            /* inside parentheses: cast, param list, offsetof or sizeof */
-           ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.not_cast_mask;
+           ps.cast_mask0 |= (1 << (ps.p_l_follow - 1)) & ~ps.not_cast_mask0;
        }
        if (ps.prev_token != lsym_period && ps.prev_token != lsym_unary_op) {
            if (kw != NULL && kw->lsym == lsym_tag) {



Home | Main Index | Thread Index | Old Index