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: rename rwcode to keyword_kind, variou...



details:   https://anonhg.NetBSD.org/src/rev/a993c1b36bff
branches:  trunk
changeset: 987472:a993c1b36bff
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Sep 27 16:56:35 2021 +0000

description:
indent: rename rwcode to keyword_kind, various cleanup

No idea what the 'rw' in 'rwcode' meant, it had been imported that way
28 years ago. Since rwcode specifies the kind of a keyword, the prefix
'kw_' makes sense.

No functional change.

diffstat:

 usr.bin/indent/indent.c       |   10 +-
 usr.bin/indent/indent_codes.h |    4 +-
 usr.bin/indent/indent_globs.h |   32 ++++----
 usr.bin/indent/lexi.c         |  146 ++++++++++++++++++++---------------------
 4 files changed, 95 insertions(+), 97 deletions(-)

diffs (truncated from 361 to 300 lines):

diff -r 231db89545f6 -r a993c1b36bff usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Mon Sep 27 16:52:15 2021 +0000
+++ b/usr.bin/indent/indent.c   Mon Sep 27 16:56:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.88 2021/09/26 21:23:31 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.89 2021/09/27 16:56:35 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.88 2021/09/26 21:23:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.89 2021/09/27 16:56:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -577,8 +577,8 @@
     } else if (ps.want_blank &&
            ((ps.last_token != ident && ps.last_token != funcname) ||
            opt.proc_calls_space ||
-           (ps.keyword == rw_sizeof ? opt.blank_after_sizeof :
-           ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
+           (ps.keyword == kw_sizeof ? opt.blank_after_sizeof :
+           ps.keyword != kw_0 && ps.keyword != kw_offsetof)))
        *code.e++ = ' ';
     ps.want_blank = false;
     *code.e++ = token.s[0];
@@ -603,7 +603,7 @@
                                 * initialization */
     }
     /* parenthesized type following sizeof or offsetof is not a cast */
-    if (ps.keyword == rw_offsetof || ps.keyword == rw_sizeof)
+    if (ps.keyword == kw_offsetof || ps.keyword == kw_sizeof)
        ps.not_cast_mask |= 1 << ps.p_l_follow;
 }
 
diff -r 231db89545f6 -r a993c1b36bff usr.bin/indent/indent_codes.h
--- a/usr.bin/indent/indent_codes.h     Mon Sep 27 16:52:15 2021 +0000
+++ b/usr.bin/indent/indent_codes.h     Mon Sep 27 16:56:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_codes.h,v 1.11 2021/03/09 19:23:08 rillig Exp $ */
+/*     $NetBSD: indent_codes.h,v 1.12 2021/09/27 16:56:35 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -54,7 +54,7 @@
     semicolon,
     lbrace,
     rbrace,
-    ident,
+    ident,                     /* identifier, constant or string */
     comma,
     comment,
     switch_expr,               /* 'switch' '(' <expr> ')' */
diff -r 231db89545f6 -r a993c1b36bff usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Mon Sep 27 16:52:15 2021 +0000
+++ b/usr.bin/indent/indent_globs.h     Mon Sep 27 16:56:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_globs.h,v 1.40 2021/09/26 21:32:58 rillig Exp $ */
+/*     $NetBSD: indent_globs.h,v 1.41 2021/09/27 16:56:35 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -155,20 +155,20 @@
                                 * are printed */
 } opt;
 
-enum rwcode {
-    rw_0,
-    rw_offsetof,
-    rw_sizeof,
-    rw_struct_or_union_or_enum,
-    rw_type,
-    rw_for_or_if_or_while,
-    rw_do_or_else,
-    rw_switch,
-    rw_case_or_default,
-    rw_jump,
-    rw_storage_class,
-    rw_typedef,
-    rw_inline_or_restrict
+enum keyword_kind {
+    kw_0,
+    kw_offsetof,
+    kw_sizeof,
+    kw_struct_or_union_or_enum,
+    kw_type,
+    kw_for_or_if_or_while,
+    kw_do_or_else,
+    kw_switch,
+    kw_case_or_default,
+    kw_jump,
+    kw_storage_class,
+    kw_typedef,
+    kw_inline_or_restrict
 };
 
 
@@ -251,7 +251,7 @@
     bool       want_blank;     /* whether the following token should
                                 * be prefixed by a blank. (Said prefixing is
                                 * ignored in some cases.) */
-    enum rwcode keyword;       /* the type of a keyword or 0 */
+    enum keyword_kind keyword;
     bool       dumped_decl_indent;
     bool       in_parameter_declaration;
     int         tos;           /* pointer to top of stack */
diff -r 231db89545f6 -r a993c1b36bff usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Mon Sep 27 16:52:15 2021 +0000
+++ b/usr.bin/indent/lexi.c     Mon Sep 27 16:56:35 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.61 2021/09/26 21:23:31 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.62 2021/09/27 16:56:35 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,16 +43,14 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.61 2021/09/26 21:23:31 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.62 2021/09/27 16:56:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
 
 #include <assert.h>
-#include <err.h>
 #include <stdio.h>
 #include <ctype.h>
-#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
@@ -60,52 +58,52 @@
 #include "indent.h"
 
 /* must be sorted alphabetically, is used in binary search */
-static const struct special {
-    const char *rwd;
-    enum rwcode rwcode;
-} specials[] = {
-    {"_Bool", rw_type},
-    {"_Complex", rw_type},
-    {"_Imaginary", rw_type},
-    {"auto", rw_storage_class},
-    {"bool", rw_type},
-    {"break", rw_jump},
-    {"case", rw_case_or_default},
-    {"char", rw_type},
-    {"complex", rw_type},
-    {"const", rw_type},
-    {"continue", rw_jump},
-    {"default", rw_case_or_default},
-    {"do", rw_do_or_else},
-    {"double", rw_type},
-    {"else", rw_do_or_else},
-    {"enum", rw_struct_or_union_or_enum},
-    {"extern", rw_storage_class},
-    {"float", rw_type},
-    {"for", rw_for_or_if_or_while},
-    {"global", rw_type},
-    {"goto", rw_jump},
-    {"if", rw_for_or_if_or_while},
-    {"imaginary", rw_type},
-    {"inline", rw_inline_or_restrict},
-    {"int", rw_type},
-    {"long", rw_type},
-    {"offsetof", rw_offsetof},
-    {"register", rw_storage_class},
-    {"restrict", rw_inline_or_restrict},
-    {"return", rw_jump},
-    {"short", rw_type},
-    {"signed", rw_type},
-    {"sizeof", rw_sizeof},
-    {"static", rw_storage_class},
-    {"struct", rw_struct_or_union_or_enum},
-    {"switch", rw_switch},
-    {"typedef", rw_typedef},
-    {"union", rw_struct_or_union_or_enum},
-    {"unsigned", rw_type},
-    {"void", rw_type},
-    {"volatile", rw_type},
-    {"while", rw_for_or_if_or_while}
+static const struct keyword {
+    const char *name;
+    enum keyword_kind kind;
+} keywords[] = {
+    {"_Bool", kw_type},
+    {"_Complex", kw_type},
+    {"_Imaginary", kw_type},
+    {"auto", kw_storage_class},
+    {"bool", kw_type},
+    {"break", kw_jump},
+    {"case", kw_case_or_default},
+    {"char", kw_type},
+    {"complex", kw_type},
+    {"const", kw_type},
+    {"continue", kw_jump},
+    {"default", kw_case_or_default},
+    {"do", kw_do_or_else},
+    {"double", kw_type},
+    {"else", kw_do_or_else},
+    {"enum", kw_struct_or_union_or_enum},
+    {"extern", kw_storage_class},
+    {"float", kw_type},
+    {"for", kw_for_or_if_or_while},
+    {"global", kw_type},
+    {"goto", kw_jump},
+    {"if", kw_for_or_if_or_while},
+    {"imaginary", kw_type},
+    {"inline", kw_inline_or_restrict},
+    {"int", kw_type},
+    {"long", kw_type},
+    {"offsetof", kw_offsetof},
+    {"register", kw_storage_class},
+    {"restrict", kw_inline_or_restrict},
+    {"return", kw_jump},
+    {"short", kw_type},
+    {"signed", kw_type},
+    {"sizeof", kw_sizeof},
+    {"static", kw_storage_class},
+    {"struct", kw_struct_or_union_or_enum},
+    {"switch", kw_switch},
+    {"typedef", kw_typedef},
+    {"union", kw_struct_or_union_or_enum},
+    {"unsigned", kw_type},
+    {"void", kw_type},
+    {"volatile", kw_type},
+    {"while", kw_for_or_if_or_while}
 };
 
 static const char **typenames;
@@ -204,13 +202,13 @@
 }
 
 static int
-compare_special_array(const void *key, const void *elem)
+cmp_keyword_by_name(const void *key, const void *elem)
 {
-    return strcmp(key, ((const struct special *)elem)->rwd);
+    return strcmp(key, ((const struct keyword *)elem)->name);
 }
 
 static int
-compare_string_array(const void *key, const void *elem)
+cmp_type_by_name(const void *key, const void *elem)
 {
     return strcmp(key, *((const char *const *)elem));
 }
@@ -231,7 +229,7 @@
        "storage_class", "funcname", "type_def", "keyword_struct_union_enum"
     };
 
-    assert(0 <= ttype && ttype < sizeof name / sizeof name[0]);
+    assert(0 <= ttype && ttype < nitems(name));
 
     return name[ttype];
 }
@@ -362,7 +360,7 @@
     if (isalnum((unsigned char)*buf_ptr) ||
        *buf_ptr == '_' || *buf_ptr == '$' ||
        (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
-       struct special *p;
+       struct keyword *kw;
 
        if (isdigit((unsigned char)*buf_ptr) ||
            (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
@@ -378,7 +376,7 @@
 
        while (*buf_ptr == ' ' || *buf_ptr == '\t')     /* get rid of blanks */
            inbuf_next();
-       state->keyword = rw_0;
+       state->keyword = kw_0;
 
        if (state->last_token == keyword_struct_union_enum &&
                state->p_l_follow == 0) {
@@ -390,55 +388,55 @@
         */
        state->last_u_d = (state->last_token == keyword_struct_union_enum);
 
-       p = bsearch(token.s, specials, sizeof specials / sizeof specials[0],
-           sizeof specials[0], compare_special_array);
-       if (p == NULL) {        /* not a special keyword... */
+       kw = bsearch(token.s, keywords, nitems(keywords),
+           sizeof(keywords[0]), cmp_keyword_by_name);
+       if (kw == NULL) {
            char *u;
 
            /* ... so maybe a type_t or a typedef */
            if ((opt.auto_typedefs && ((u = strrchr(token.s, '_')) != NULL) &&
                    strcmp(u, "_t") == 0) || (typename_top >= 0 &&
                    bsearch(token.s, typenames, (size_t)typename_top + 1,
-                       sizeof typenames[0], compare_string_array) != NULL)) {
-               state->keyword = rw_type;
+                       sizeof(typenames[0]), cmp_type_by_name) != NULL)) {
+               state->keyword = kw_type;
                state->last_u_d = true;



Home | Main Index | Thread Index | Old Index