Module Name: src
Committed By: rillig
Date: Fri Oct 29 17:50:38 UTC 2021
Modified Files:
src/tests/usr.bin/indent: token_comment.c token_lparen.c
src/usr.bin/indent: indent.c indent.h lexi.c pr_comment.c
Log Message:
indent: use prev/curr/next to refer to the current token
The word 'last' just didn't match with 'next'.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/token_comment.c \
src/tests/usr.bin/indent/token_lparen.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/pr_comment.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.8 src/tests/usr.bin/indent/token_comment.c:1.9
--- src/tests/usr.bin/indent/token_comment.c:1.8 Tue Oct 26 21:37:27 2021
+++ src/tests/usr.bin/indent/token_comment.c Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.8 2021/10/26 21:37:27 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.9 2021/10/29 17:50:37 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -41,7 +41,7 @@
* - with varying opt.comment_column (-c0, -c1, -c33, -c80)
* - with varying opt.decl_comment_column (-cd0, -cd1, -cd20, -cd33, -cd80)
* - with/without ps.decl_on_line
- * - with/without ps.last_nl
+ * - with/without ps.prev_newline
*
* - very long comments that overflow the buffer 'com'
* - comments that come from save_com
Index: src/tests/usr.bin/indent/token_lparen.c
diff -u src/tests/usr.bin/indent/token_lparen.c:1.8 src/tests/usr.bin/indent/token_lparen.c:1.9
--- src/tests/usr.bin/indent/token_lparen.c:1.8 Fri Oct 29 16:54:51 2021
+++ src/tests/usr.bin/indent/token_lparen.c Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_lparen.c,v 1.8 2021/10/29 16:54:51 rillig Exp $ */
+/* $NetBSD: token_lparen.c,v 1.9 2021/10/29 17:50:37 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -100,7 +100,7 @@ int array[] = {
#indent input
void cover_want_blank_before_lparen(void)
{
- /* ps.last_token can never be 'newline'. */
+ /* ps.prev_token can never be 'newline'. */
int newline =
(3);
@@ -146,7 +146,7 @@ void cover_want_blank_before_lparen(void
void
cover_want_blank_before_lparen(void)
{
- /* ps.last_token can never be 'newline'. */
+ /* ps.prev_token can never be 'newline'. */
int newline =
(3);
Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.170 src/usr.bin/indent/indent.c:1.171
--- src/usr.bin/indent/indent.c:1.170 Fri Oct 29 17:32:22 2021
+++ src/usr.bin/indent/indent.c Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.170 2021/10/29 17:32:22 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 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.170 2021/10/29 17:32:22 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.171 2021/10/29 17:50:37 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -450,8 +450,8 @@ main_init_globals(void)
found_err = false;
ps.s_sym[0] = psym_stmt;
- ps.last_nl = true;
- ps.last_token = lsym_semicolon;
+ ps.prev_newline = true;
+ ps.prev_token = lsym_semicolon;
buf_init(&com);
buf_init(&lab);
buf_init(&code);
@@ -690,7 +690,7 @@ process_form_feed(void)
static void
process_newline(void)
{
- if (ps.last_token == lsym_comma && ps.p_l_follow == 0 && !ps.block_init &&
+ if (ps.prev_token == lsym_comma && ps.p_l_follow == 0 && !ps.block_init &&
!opt.break_after_comma && break_comma &&
com.s == com.e)
goto stay_in_line;
@@ -707,9 +707,9 @@ want_blank_before_lparen(void)
{
if (!ps.want_blank)
return false;
- if (ps.last_token == lsym_rparen_or_rbracket)
+ if (ps.prev_token == lsym_rparen_or_rbracket)
return false;
- if (ps.last_token != lsym_ident && ps.last_token != lsym_funcname)
+ if (ps.prev_token != lsym_ident && ps.prev_token != lsym_funcname)
return true;
if (opt.proc_calls_space)
return true;
@@ -881,7 +881,7 @@ process_semicolon(bool *seen_case, int *
ps.init_or_struct = false;
*seen_case = false; /* these will only need resetting in an error */
*quest_level = 0;
- if (ps.last_token == lsym_rparen_or_rbracket)
+ if (ps.prev_token == lsym_rparen_or_rbracket)
ps.in_parameter_declaration = false;
ps.cast_mask = 0;
ps.not_cast_mask = 0;
@@ -1079,7 +1079,7 @@ process_type(int *decl_ind, bool *tabs_t
{
parse(psym_decl); /* let the parser worry about indentation */
- if (ps.last_token == lsym_rparen_or_rbracket && ps.tos <= 1) {
+ if (ps.prev_token == lsym_rparen_or_rbracket && ps.tos <= 1) {
if (code.s != code.e) {
dump_line();
ps.want_blank = false;
@@ -1093,7 +1093,7 @@ process_type(int *decl_ind, bool *tabs_t
}
ps.init_or_struct = /* maybe */ true;
- ps.in_decl = ps.decl_on_line = ps.last_token != lsym_typedef;
+ ps.in_decl = ps.decl_on_line = ps.prev_token != lsym_typedef;
if (ps.decl_nest <= 0)
ps.just_saw_decl = 2;
@@ -1505,7 +1505,7 @@ main_loop(void)
*code.e = '\0';
if (lsym != lsym_comment && lsym != lsym_newline &&
lsym != lsym_preprocessing)
- ps.last_token = lsym;
+ ps.prev_token = lsym;
}
}
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.59 src/usr.bin/indent/indent.h:1.60
--- src/usr.bin/indent/indent.h:1.59 Fri Oct 29 17:41:56 2021
+++ src/usr.bin/indent/indent.h Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.59 2021/10/29 17:41:56 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.60 2021/10/29 17:50:37 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -272,13 +272,14 @@ extern bool inhibit_formatting; /* true
#define STACKSIZE 256
extern struct parser_state {
- /* TODO: rename to prev_token */
- lexer_symbol last_token;
- /* TODO: rename to prev_newline */
- bool last_nl; /* whether the last thing scanned was a
+ /*
+ * TODO: Double-check that the word 'prev' in the following variables
+ * means exactly the same thing.
+ */
+ lexer_symbol prev_token;
+ bool prev_newline; /* whether the last thing scanned was a
* newline */
- /* TODO: rename to prev_col_1 */
- bool col_1; /* whether the last token started in column 1 */
+ bool prev_col_1; /* whether the last token started in column 1 */
enum keyword_kind prev_keyword;
enum keyword_kind curr_keyword;
bool next_unary; /* whether the following operator should be
Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.109 src/usr.bin/indent/lexi.c:1.110
--- src/usr.bin/indent/lexi.c:1.109 Fri Oct 29 16:59:35 2021
+++ src/usr.bin/indent/lexi.c Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.109 2021/10/29 16:59:35 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.110 2021/10/29 17:50:37 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.109 2021/10/29 16:59:35 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.110 2021/10/29 17:50:37 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -399,9 +399,9 @@ probably_typename(void)
goto maybe;
return false;
maybe:
- return ps.last_token == lsym_semicolon ||
- ps.last_token == lsym_lbrace ||
- ps.last_token == lsym_rbrace;
+ return ps.prev_token == lsym_semicolon ||
+ ps.prev_token == lsym_lbrace ||
+ ps.prev_token == lsym_rbrace;
}
static int
@@ -456,13 +456,13 @@ lexi_alnum(void)
while (is_hspace(inbuf_peek()))
inbuf_skip();
- if (ps.last_token == lsym_tag && ps.p_l_follow == 0) {
+ if (ps.prev_token == lsym_tag && ps.p_l_follow == 0) {
ps.next_unary = true;
return lsym_type;
}
/* Operator after identifier is binary unless last token was 'struct'. */
- ps.next_unary = ps.last_token == lsym_tag;
+ ps.next_unary = ps.prev_token == lsym_tag;
const struct keyword *kw = bsearch(token.s, keywords,
array_length(keywords), sizeof(keywords[0]), cmp_keyword_by_name);
@@ -491,8 +491,8 @@ lexi_alnum(void)
/* inside parentheses: cast, param list, offsetof or sizeof */
ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.not_cast_mask;
}
- if (ps.last_token == lsym_period ||
- ps.last_token == lsym_unary_op)
+ if (ps.prev_token == lsym_period ||
+ ps.prev_token == lsym_unary_op)
break;
if (kw != NULL && kw->kind == kw_struct_or_union_or_enum)
return lsym_tag;
@@ -546,7 +546,7 @@ not_proc:;
return lsym_type;
}
- if (ps.last_token == lsym_type) /* if this is a declared variable,
+ if (ps.prev_token == lsym_type) /* if this is a declared variable,
* then following sign is unary */
ps.next_unary = true; /* will make "int a -1" work */
@@ -558,13 +558,13 @@ lexer_symbol
lexi(void)
{
token.e = token.s;
- ps.col_1 = ps.last_nl;
- ps.last_nl = false;
+ ps.prev_col_1 = ps.prev_newline;
+ ps.prev_newline = false;
ps.prev_keyword = ps.curr_keyword;
ps.curr_keyword = kw_0;
while (is_hspace(*inp.s)) {
- ps.col_1 = false;
+ ps.prev_col_1 = false;
inbuf_skip();
}
@@ -585,7 +585,7 @@ lexi(void)
switch (*token.s) {
case '\n':
unary_delim = ps.next_unary;
- ps.last_nl = true; /* remember that we just had a newline */
+ ps.prev_newline = true;
/* if data has been exhausted, the newline is a dummy. */
lsym = had_eof ? lsym_eof : lsym_newline;
break;
@@ -639,8 +639,7 @@ lexi(void)
case '\f':
unary_delim = ps.next_unary;
- ps.last_nl = true; /* remember this, so we can set 'ps.col_1'
- * right */
+ ps.prev_newline = true;
lsym = lsym_form_feed;
break;
@@ -661,8 +660,8 @@ lexi(void)
if (*inp.s == token.s[0]) { /* ++, -- */
*token.e++ = *inp.s++;
- if (ps.last_token == lsym_ident ||
- ps.last_token == lsym_rparen_or_rbracket) {
+ if (ps.prev_token == lsym_ident ||
+ ps.prev_token == lsym_rparen_or_rbracket) {
lsym = ps.next_unary ? lsym_unary_op : lsym_postfix_op;
unary_delim = false;
}
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.87 src/usr.bin/indent/pr_comment.c:1.88
--- src/usr.bin/indent/pr_comment.c:1.87 Tue Oct 26 21:37:27 2021
+++ src/usr.bin/indent/pr_comment.c Fri Oct 29 17:50:37 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.88 2021/10/29 17:50:37 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.87 2021/10/26 21:37:27 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.88 2021/10/29 17:50:37 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -136,7 +136,7 @@ process_comment(void)
/* Figure where to align and how to treat the comment */
- if (ps.col_1 && !opt.format_col1_comments) {
+ if (ps.prev_col_1 && !opt.format_col1_comments) {
may_wrap = false;
break_delim = false;
com_ind = 0;
@@ -214,7 +214,7 @@ process_comment(void)
com.e = com.s + 2;
*com.e = '\0';
if (opt.blanklines_before_block_comments &&
- ps.last_token != lsym_lbrace)
+ ps.prev_token != lsym_lbrace)
blank_line_before = true;
dump_line();
com.e = com.s = t;
@@ -250,7 +250,7 @@ process_comment(void)
}
last_blank = -1;
- if (!may_wrap || ps.last_nl) { /* if this is a boxed comment,
+ if (!may_wrap || ps.prev_newline) { /* if this is a boxed comment,
* we handle the newline */
if (com.s == com.e)
com_add_char(' ');
@@ -263,7 +263,7 @@ process_comment(void)
com_add_delim();
} else {
- ps.last_nl = true;
+ ps.prev_newline = true;
if (!is_hspace(com.e[-1]))
com_add_char(' ');
last_blank = com.e - 1 - com.buf;
@@ -330,7 +330,7 @@ process_comment(void)
break;
}
- ps.last_nl = false;
+ ps.prev_newline = false;
if (now_len <= adj_max_line_length || !may_wrap)
break;