Module Name: src
Committed By: rillig
Date: Fri May 12 22:38:47 UTC 2023
Modified Files:
src/usr.bin/indent: indent.c indent.h parse.c
Log Message:
indent: rename placeholder symbol for parser stack
No functional change outside debug mode.
To generate a diff of this commit:
cvs rdiff -u -r1.255 -r1.256 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.121 -r1.122 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/parse.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.255 src/usr.bin/indent/indent.c:1.256
--- src/usr.bin/indent/indent.c:1.255 Fri May 12 15:36:02 2023
+++ src/usr.bin/indent/indent.c Fri May 12 22:38:47 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.255 2023/05/12 15:36:02 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.256 2023/05/12 22:38:47 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.255 2023/05/12 15:36:02 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.256 2023/05/12 22:38:47 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -485,7 +485,7 @@ process_lparen_or_lbracket(void)
debug_println("paren_indents[%d] is now %d",
ps.nparen - 1, ps.paren[ps.nparen - 1].indent);
- if (ps.spaced_expr_psym != psym_semicolon
+ if (ps.spaced_expr_psym != psym_0
&& ps.nparen == 1 && opt.extra_expr_indent
&& ps.paren[0].indent < 2 * opt.indent_size) {
ps.paren[0].indent = (short)(2 * opt.indent_size);
@@ -497,7 +497,7 @@ process_lparen_or_lbracket(void)
* this is a kluge to make sure that declarations will be aligned
* right if proc decl has an explicit type on it, i.e. "int a(x) {..."
*/
- parse(psym_semicolon); /* I said this was a kluge... */
+ parse(psym_0);
ps.init_or_struct = false;
}
@@ -528,12 +528,12 @@ process_rparen_or_rbracket(void)
*code.e++ = token.s[0];
- if (ps.spaced_expr_psym != psym_semicolon && ps.nparen == 0) {
+ if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) {
ps.force_nl = true;
ps.next_unary = true;
ps.in_stmt_or_decl = false;
parse(ps.spaced_expr_psym);
- ps.spaced_expr_psym = psym_semicolon;
+ ps.spaced_expr_psym = psym_0;
}
}
@@ -651,17 +651,17 @@ process_semicolon(void)
*/
diag(1, "Unbalanced parentheses");
ps.nparen = 0;
- if (ps.spaced_expr_psym != psym_semicolon) {
+ if (ps.spaced_expr_psym != psym_0) {
parse(ps.spaced_expr_psym);
- ps.spaced_expr_psym = psym_semicolon;
+ ps.spaced_expr_psym = psym_0;
}
}
*code.e++ = ';';
ps.want_blank = true;
ps.in_stmt_or_decl = ps.nparen > 0;
- if (ps.spaced_expr_psym == psym_semicolon) {
- parse(psym_semicolon); /* let parser know about end of stmt */
+ if (ps.spaced_expr_psym == psym_0) {
+ parse(psym_0); /* let parser know about end of stmt */
ps.force_nl = true;
}
}
@@ -696,9 +696,9 @@ process_lbrace(void)
if (ps.nparen > 0) {
diag(1, "Unbalanced parentheses");
ps.nparen = 0;
- if (ps.spaced_expr_psym != psym_semicolon) {
+ if (ps.spaced_expr_psym != psym_0) {
parse(ps.spaced_expr_psym);
- ps.spaced_expr_psym = psym_semicolon;
+ ps.spaced_expr_psym = psym_0;
ps.ind_level = ps.ind_level_follow;
}
}
@@ -735,7 +735,7 @@ process_rbrace(void)
if (ps.nparen > 0) { /* check for unclosed if, for, else. */
diag(1, "Unbalanced parentheses");
ps.nparen = 0;
- ps.spaced_expr_psym = psym_semicolon;
+ ps.spaced_expr_psym = psym_0;
}
ps.just_saw_decl = 0;
@@ -849,12 +849,12 @@ process_ident(lexer_symbol lsym)
ps.want_blank = false;
}
- } else if (ps.spaced_expr_psym != psym_semicolon && ps.nparen == 0) {
+ } else if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) {
ps.force_nl = true;
ps.next_unary = true;
ps.in_stmt_or_decl = false;
parse(ps.spaced_expr_psym);
- ps.spaced_expr_psym = psym_semicolon;
+ ps.spaced_expr_psym = psym_0;
}
}
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.121 src/usr.bin/indent/indent.h:1.122
--- src/usr.bin/indent/indent.h:1.121 Fri May 12 10:53:33 2023
+++ src/usr.bin/indent/indent.h Fri May 12 22:38:47 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.121 2023/05/12 10:53:33 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.122 2023/05/12 22:38:47 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -110,7 +110,7 @@ typedef enum lexer_symbol {
} lexer_symbol;
typedef enum parser_symbol {
- psym_semicolon, /* rather a placeholder than a semicolon */
+ psym_0, /* a placeholder */
psym_lbrace,
psym_rbrace,
psym_decl,
@@ -337,7 +337,7 @@ extern struct parser_state {
parser_symbol spaced_expr_psym; /* the parser symbol to be shifted
* after the parenthesized expression
* from a 'for', 'if', 'switch' or
- * 'while'; or psym_semicolon */
+ * 'while'; or psym_0 */
int quest_level; /* when this is positive, we have seen a '?'
* without the matching ':' in a '?:'
Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.52 src/usr.bin/indent/parse.c:1.53
--- src/usr.bin/indent/parse.c:1.52 Fri May 12 22:36:15 2023
+++ src/usr.bin/indent/parse.c Fri May 12 22:38:47 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.52 2023/05/12 22:36:15 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.53 2023/05/12 22:38:47 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)parse.c 8.1
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: parse.c,v 1.52 2023/05/12 22:36:15 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.53 2023/05/12 22:38:47 rillig Exp $");
#else
__FBSDID("$FreeBSD: head/usr.bin/indent/parse.c 337651 2018-08-11 19:20:06Z pstef $");
#endif
@@ -60,7 +60,7 @@ const char *
psym_name(parser_symbol psym)
{
static const char *const name[] = {
- "semicolon",
+ "0",
"lbrace",
"rbrace",
"decl",
@@ -221,7 +221,7 @@ parse(parser_symbol psym)
ps.ind_level_follow += (int)opt.case_indent + 1;
break;
- case psym_semicolon: /* a simple statement */
+ case psym_0: /* a simple statement */
break_comma = false; /* don't break after comma in a declaration */
ps.s_sym[++ps.tos] = psym_stmt;
ps.s_ind_level[ps.tos] = ps.ind_level;