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: split kw_for_or_if_or_while into sepa...



details:   https://anonhg.NetBSD.org/src/rev/80785ce34da3
branches:  trunk
changeset: 990052:80785ce34da3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 24 22:38:20 2021 +0000

description:
indent: split kw_for_or_if_or_while into separate constants

No functional change.

diffstat:

 usr.bin/indent/indent.c |  25 ++++++++++++++++---------
 usr.bin/indent/indent.h |  10 +++++++---
 usr.bin/indent/lexi.c   |  22 ++++++++++++++--------
 3 files changed, 37 insertions(+), 20 deletions(-)

diffs (151 lines):

diff -r 662be84f918b -r 80785ce34da3 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sun Oct 24 22:28:06 2021 +0000
+++ b/usr.bin/indent/indent.c   Sun Oct 24 22:38:20 2021 +0000
@@ -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 @@
 
 #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 @@
            /* "} 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 @@
                                         * 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:
diff -r 662be84f918b -r 80785ce34da3 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sun Oct 24 22:28:06 2021 +0000
+++ b/usr.bin/indent/indent.h   Sun Oct 24 22:38:20 2021 +0000
@@ -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 @@
     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 @@
     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,
diff -r 662be84f918b -r 80785ce34da3 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sun Oct 24 22:28:06 2021 +0000
+++ b/usr.bin/indent/lexi.c     Sun Oct 24 22:38:20 2021 +0000
@@ -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 @@
 
 #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 @@
     {"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 @@
     {"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 @@
        "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 @@
                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;



Home | Main Index | Thread Index | Old Index