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: use prev/curr/next to refer to the cu...
details: https://anonhg.NetBSD.org/src/rev/8910f03aba3e
branches: trunk
changeset: 990514:8910f03aba3e
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Oct 29 17:50:37 2021 +0000
description:
indent: use prev/curr/next to refer to the current token
The word 'last' just didn't match with 'next'.
No functional change.
diffstat:
tests/usr.bin/indent/token_comment.c | 4 ++--
tests/usr.bin/indent/token_lparen.c | 6 +++---
usr.bin/indent/indent.c | 22 +++++++++++-----------
usr.bin/indent/indent.h | 15 ++++++++-------
usr.bin/indent/lexi.c | 35 +++++++++++++++++------------------
usr.bin/indent/pr_comment.c | 14 +++++++-------
6 files changed, 48 insertions(+), 48 deletions(-)
diffs (truncated from 338 to 300 lines):
diff -r 49092737abef -r 8910f03aba3e tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c Fri Oct 29 17:41:56 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c Fri Oct 29 17:50:37 2021 +0000
@@ -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
diff -r 49092737abef -r 8910f03aba3e tests/usr.bin/indent/token_lparen.c
--- a/tests/usr.bin/indent/token_lparen.c Fri Oct 29 17:41:56 2021 +0000
+++ b/tests/usr.bin/indent/token_lparen.c Fri Oct 29 17:50:37 2021 +0000
@@ -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 @@
#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)
{
- /* ps.last_token can never be 'newline'. */
+ /* ps.prev_token can never be 'newline'. */
int newline =
(3);
diff -r 49092737abef -r 8910f03aba3e usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Oct 29 17:41:56 2021 +0000
+++ b/usr.bin/indent/indent.c Fri Oct 29 17:50:37 2021 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
{
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 @@
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 @@
{
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 @@
}
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 @@
*code.e = '\0';
if (lsym != lsym_comment && lsym != lsym_newline &&
lsym != lsym_preprocessing)
- ps.last_token = lsym;
+ ps.prev_token = lsym;
}
}
diff -r 49092737abef -r 8910f03aba3e usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Oct 29 17:41:56 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Oct 29 17:50:37 2021 +0000
@@ -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 @@
#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
diff -r 49092737abef -r 8910f03aba3e usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Fri Oct 29 17:41:56 2021 +0000
+++ b/usr.bin/indent/lexi.c Fri Oct 29 17:50:37 2021 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
diff -r 49092737abef -r 8910f03aba3e usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Fri Oct 29 17:41:56 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Fri Oct 29 17:50:37 2021 +0000
@@ -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 @@
#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 @@
/* 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;
Home |
Main Index |
Thread Index |
Old Index