Module Name:    src
Committed By:   rillig
Date:           Sun Oct 24 22:38:20 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: split kw_for_or_if_or_while into separate constants

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.97 -r1.98 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.153 src/usr.bin/indent/indent.c:1.154
--- src/usr.bin/indent/indent.c:1.153	Sun Oct 24 22:28:06 2021
+++ src/usr.bin/indent/indent.c	Sun Oct 24 22:38:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.153 2021/10/24 22:28:06 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.154 2021/10/24 22:38:20 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.153 2021/10/24 22:28:06 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.154 2021/10/24 22:38:20 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -248,8 +248,7 @@ search_brace_other(token_type ttype, boo
 	    /* "} else" */
 	    (ttype == tt_lex_else && code.e != code.s && code.e[-1] == '}')
 	    /* "else if" */
-	    || (ttype == keyword_for_if_while &&
-		*token.s == 'i' && last_else && opt.else_if);
+	    || (ttype == tt_lex_if && last_else && opt.else_if);
     if (remove_newlines)
 	*force_nl = false;
 
@@ -1437,13 +1436,21 @@ main_loop(void)
 					 * expression */
 	    goto copy_token;
 
-	case keyword_for_if_while:
+	case tt_lex_for:
 	    sp_sw = true;	/* the interesting stuff is done after the
-				 * expression is scanned */
-	    hd_type = *token.s == 'i' ? if_expr :
-		*token.s == 'w' ? while_expr : for_exprs;
+				 * expressions are scanned */
+	    hd_type = for_exprs;	/* remember the type of header for
+					 * later use by parser */
+	    goto copy_token;
 
-	    /* remember the type of header for later use by parser */
+	case tt_lex_if:
+	    sp_sw = true;
+	    hd_type = if_expr;
+	    goto copy_token;
+
+	case tt_lex_while:
+	    sp_sw = true;
+	    hd_type = while_expr;
 	    goto copy_token;
 
 	case tt_lex_do:

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.46 src/usr.bin/indent/indent.h:1.47
--- src/usr.bin/indent/indent.h:1.46	Sun Oct 24 22:28:06 2021
+++ src/usr.bin/indent/indent.h	Sun Oct 24 22:38:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.46 2021/10/24 22:28:06 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.47 2021/10/24 22:38:20 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -91,7 +91,9 @@ typedef enum token_type {
     preprocessing,		/* '#' */
     form_feed,
     decl,
-    keyword_for_if_while,	/* 'for', 'if' or 'while' */
+    tt_lex_for,
+    tt_lex_if,
+    tt_lex_while,
     tt_lex_do,
     tt_lex_else,
     if_expr,			/* 'if' '(' <expr> ')' */
@@ -225,7 +227,9 @@ enum keyword_kind {
     kw_sizeof,
     kw_struct_or_union_or_enum,
     kw_type,
-    kw_for_or_if_or_while,
+    kw_for,
+    kw_if,
+    kw_while,
     kw_do,
     kw_else,
     kw_switch,

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.97 src/usr.bin/indent/lexi.c:1.98
--- src/usr.bin/indent/lexi.c:1.97	Sun Oct 24 22:28:06 2021
+++ src/usr.bin/indent/lexi.c	Sun Oct 24 22:38:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.97 2021/10/24 22:28:06 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.98 2021/10/24 22:38:20 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.97 2021/10/24 22:28:06 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.98 2021/10/24 22:38:20 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -80,9 +80,9 @@ static const struct keyword {
     {"enum", kw_struct_or_union_or_enum},
     {"extern", kw_storage_class},
     {"float", kw_type},
-    {"for", kw_for_or_if_or_while},
+    {"for", kw_for},
     {"goto", kw_jump},
-    {"if", kw_for_or_if_or_while},
+    {"if", kw_if},
     {"imaginary", kw_type},
     {"inline", kw_inline_or_restrict},
     {"int", kw_type},
@@ -102,7 +102,7 @@ static const struct keyword {
     {"unsigned", kw_type},
     {"void", kw_type},
     {"volatile", kw_type},
-    {"while", kw_for_or_if_or_while}
+    {"while", kw_while}
 };
 
 static struct {
@@ -227,7 +227,7 @@ token_type_name(token_type ttype)
 	"case_label", "colon",
 	"semicolon", "lbrace", "rbrace", "ident", "comma",
 	"comment", "switch_expr", "preprocessing", "form_feed", "decl",
-	"keyword_for_if_while", "tt_lex_do", "tt_lex_else",
+	"tt_lex_for", "tt_lex_if", "tt_lex_while", "tt_lex_do", "tt_lex_else",
 	"if_expr", "while_expr", "for_exprs",
 	"stmt", "stmt_list", "tt_ps_else", "tt_ps_do", "do_stmt",
 	"if_expr_stmt", "if_expr_stmt_else", "period", "string_prefix",
@@ -449,8 +449,14 @@ lexi_alnum(struct parser_state *state)
 		break;
 	    return decl;
 
-	case kw_for_or_if_or_while:
-	    return keyword_for_if_while;
+	case kw_for:
+	    return tt_lex_for;
+
+	case kw_if:
+	    return tt_lex_if;
+
+	case kw_while:
+	    return tt_lex_while;
 
 	case kw_do:
 	    return tt_lex_do;

Reply via email to