Module Name: src
Committed By: rillig
Date: Sun Feb 13 12:09:19 UTC 2022
Modified Files:
src/usr.bin/indent: indent.c indent.h lexi.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.239 -r1.240 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.169 -r1.170 src/usr.bin/indent/lexi.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.239 src/usr.bin/indent/indent.c:1.240
--- src/usr.bin/indent/indent.c:1.239 Sun Nov 28 14:29:03 2021
+++ src/usr.bin/indent/indent.c Sun Feb 13 12:09:19 2022
@@ -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 @@ static char sccsid[] = "@(#)indent.c 5.1
#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 @@ process_lparen_or_lbracket(int decl_ind,
/* 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 @@ process_semicolon(bool *seen_case, int *
*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--;
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.108 src/usr.bin/indent/indent.h:1.109
--- src/usr.bin/indent/indent.h:1.108 Sat Feb 12 19:56:52 2022
+++ src/usr.bin/indent/indent.h Sun Feb 13 12:09:19 2022
@@ -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 @@ extern struct parser_state {
* 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 */
Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.169 src/usr.bin/indent/lexi.c:1.170
--- src/usr.bin/indent/lexi.c:1.169 Sat Feb 12 19:56:52 2022
+++ src/usr.bin/indent/lexi.c Sun Feb 13 12:09:19 2022
@@ -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 @@ static char sccsid[] = "@(#)lexi.c 8.1 (
#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_lexi(lexer_symbol lsym)
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 @@ lexi_alnum(void)
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) {