Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: distinguish between storage class ...



details:   https://anonhg.NetBSD.org/src/rev/9524896f9132
branches:  trunk
changeset: 365154:9524896f9132
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 09 23:41:22 2022 +0000

description:
lint: distinguish between storage class and declaration kind

These types overlap but are not the same.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  20 ++++----
 usr.bin/xlint/lint1/debug.c    |  25 +++++++++--
 usr.bin/xlint/lint1/decl.c     |  87 +++++++++++++++++++++--------------------
 usr.bin/xlint/lint1/externs1.h |   5 +-
 usr.bin/xlint/lint1/func.c     |  18 ++++----
 usr.bin/xlint/lint1/lex.c      |   6 +-
 usr.bin/xlint/lint1/lint1.h    |  32 +++++++--------
 usr.bin/xlint/lint1/tree.c     |   6 +-
 8 files changed, 108 insertions(+), 91 deletions(-)

diffs (truncated from 678 to 300 lines):

diff -r 0a00fe15dbad -r 9524896f9132 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 23:39:18 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Apr 09 23:41:22 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.392 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.392 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.393 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -920,7 +920,7 @@
 struct_or_union:               /* C99 6.7.2.1 */
          T_STRUCT_OR_UNION {
                symtyp = FTAG;
-               begin_declaration_level($1 == STRUCT ? MOS : MOU);
+               begin_declaration_level($1 == STRUCT ? DK_MOS : DK_MOU);
                dcs->d_offset_in_bits = 0;
                dcs->d_sou_align_in_bits = CHAR_SIZE;
                $$ = $1;
@@ -1069,7 +1069,7 @@
 enum:                          /* helper for C99 6.7.2.2 */
          T_ENUM {
                symtyp = FTAG;
-               begin_declaration_level(ENUM_CONST);
+               begin_declaration_level(DK_ENUM_CONST);
          }
        ;
 
@@ -1329,7 +1329,7 @@
 id_list_lparen:
          T_LPAREN {
                block_level++;
-               begin_declaration_level(PROTO_ARG);
+               begin_declaration_level(DK_PROTO_ARG);
          }
        ;
 
@@ -1380,7 +1380,7 @@
 /* XXX: C99 requires an additional specifier-qualifier-list. */
 type_name:                     /* C99 6.7.6 */
          {
-               begin_declaration_level(ABSTRACT);
+               begin_declaration_level(DK_ABSTRACT);
          } abstract_declaration {
                end_declaration_level();
                $$ = $2->s_type;
@@ -1460,7 +1460,7 @@
 abstract_decl_lparen:          /* specific to lint */
          T_LPAREN {
                block_level++;
-               begin_declaration_level(PROTO_ARG);
+               begin_declaration_level(DK_PROTO_ARG);
          }
        ;
 
@@ -1674,7 +1674,7 @@
          T_LBRACE {
                block_level++;
                mem_block_level++;
-               begin_declaration_level(AUTO);
+               begin_declaration_level(DK_AUTO);
          }
        ;
 
@@ -1824,7 +1824,7 @@
 
 for_start:                     /* see C99 6.8.5 */
          T_FOR T_LPAREN {
-               begin_declaration_level(AUTO);
+               begin_declaration_level(DK_AUTO);
                block_level++;
          }
        ;
@@ -1960,7 +1960,7 @@
                }
                funcdef($1);
                block_level++;
-               begin_declaration_level(OLD_STYLE_ARG);
+               begin_declaration_level(DK_OLD_STYLE_ARG);
                if (lwarn == LWARN_NONE)
                        $1->s_used = true;
          } arg_declaration_list_opt {
diff -r 0a00fe15dbad -r 9524896f9132 usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sat Apr 09 23:39:18 2022 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sat Apr 09 23:41:22 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.16 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.17 2022/04/09 23:41:22 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.16 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.17 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -177,6 +177,23 @@
 }
 
 const char *
+declaration_kind_name(declaration_kind dk)
+{
+       static const char *const name[] = {
+               "extern",
+               "member-of-struct",
+               "member-of-union",
+               "enum-constant",
+               "old-style-function-argument",
+               "prototype-argument",
+               "auto",
+               "abstract",
+       };
+
+       return name[dk];
+}
+
+const char *
 scl_name(scl_t scl)
 {
        static const char *const name[] = {
@@ -191,8 +208,6 @@
                "enum",
                "member-of-struct",
                "member-of-union",
-               "bool-constant",
-               "enum-constant",
                "abstract",
                "old-style-function-argument",
                "prototype-argument",
@@ -308,7 +323,7 @@
 {
 
        debug_print_indent();
-       debug_printf("dinfo: %s", scl_name(d->d_ctx));
+       debug_printf("dinfo: %s", declaration_kind_name(d->d_kind));
        if (d->d_scl != NOSCL)
                debug_printf(" %s", scl_name(d->d_scl));
        if (d->d_type != NULL) {
diff -r 0a00fe15dbad -r 9524896f9132 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Sat Apr 09 23:39:18 2022 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Sat Apr 09 23:41:22 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.275 2022/04/09 21:19:52 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.275 2022/04/09 21:19:52 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.276 2022/04/09 23:41:22 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -95,7 +95,7 @@
 
        /* declaration stack */
        dcs = xcalloc(1, sizeof(*dcs));
-       dcs->d_ctx = EXTERN;
+       dcs->d_kind = DK_EXTERN;
        dcs->d_ldlsym = &dcs->d_dlsyms;
 
        /* type information and classification */
@@ -574,7 +574,7 @@
  * argument declaration lists ...)
  */
 void
-begin_declaration_level(scl_t sc)
+begin_declaration_level(declaration_kind dk)
 {
        dinfo_t *di;
 
@@ -582,9 +582,9 @@
        di = xcalloc(1, sizeof(*di));
        di->d_enclosing = dcs;
        dcs = di;
-       di->d_ctx = sc;
+       di->d_kind = dk;
        di->d_ldlsym = &di->d_dlsyms;
-       debug_step("%s(%s)", __func__, scl_name(sc));
+       debug_step("%s(%s)", __func__, declaration_kind_name(dk));
 }
 
 /*
@@ -595,15 +595,15 @@
 {
        dinfo_t *di;
 
-       debug_step("%s(%s)", __func__, scl_name(dcs->d_ctx));
+       debug_step("%s(%s)", __func__, declaration_kind_name(dcs->d_kind));
 
        lint_assert(dcs->d_enclosing != NULL);
        di = dcs;
        dcs = di->d_enclosing;
-       switch (di->d_ctx) {
-       case MOS:
-       case MOU:
-       case ENUM_CONST:
+       switch (di->d_kind) {
+       case DK_MOS:
+       case DK_MOU:
+       case DK_ENUM_CONST:
                /*
                 * Symbols declared in (nested) structs or enums are
                 * part of the next level (they are removed from the
@@ -613,7 +613,7 @@
                if ((*dcs->d_ldlsym = di->d_dlsyms) != NULL)
                        dcs->d_ldlsym = di->d_ldlsym;
                break;
-       case OLD_STYLE_ARG:
+       case DK_OLD_STYLE_ARG:
                /*
                 * All symbols in dcs->d_dlsyms are introduced in old style
                 * argument declarations (it's not clean, but possible).
@@ -626,7 +626,7 @@
                        dcs->d_func_proto_syms = di->d_dlsyms;
                }
                break;
-       case ABSTRACT:
+       case DK_ABSTRACT:
                /*
                 * casts and sizeof
                 * Append all symbols declared in the abstract declaration
@@ -638,15 +638,15 @@
                if ((*dcs->d_ldlsym = di->d_dlsyms) != NULL)
                        dcs->d_ldlsym = di->d_ldlsym;
                break;
-       case AUTO:
+       case DK_AUTO:
                /* check usage of local vars */
                check_usage(di);
                /* FALLTHROUGH */
-       case PROTO_ARG:
+       case DK_PROTO_ARG:
                /* usage of arguments will be checked by funcend() */
                rmsyms(di->d_dlsyms);
                break;
-       case EXTERN:
+       case DK_EXTERN:
                /* there is nothing after external declarations */
                /* FALLTHROUGH */
        default:
@@ -707,13 +707,14 @@
 static void
 dcs_adjust_storage_class(void)
 {
-       if (dcs->d_ctx == EXTERN) {
+       if (dcs->d_kind == DK_EXTERN) {
                if (dcs->d_scl == REG || dcs->d_scl == AUTO) {
                        /* illegal storage class */
                        error(8);
                        dcs->d_scl = NOSCL;
                }
-       } else if (dcs->d_ctx == OLD_STYLE_ARG || dcs->d_ctx == PROTO_ARG) {
+       } else if (dcs->d_kind == DK_OLD_STYLE_ARG ||
+                  dcs->d_kind == DK_PROTO_ARG) {
                if (dcs->d_scl != NOSCL && dcs->d_scl != REG) {
                        /* only register valid as formal parameter storage... */
                        error(9);
@@ -1004,14 +1005,14 @@
 #endif
                        }
                } else if (to == NOTSPEC && t == VOID) {
-                       if (dcs->d_ctx == PROTO_ARG) {
+                       if (dcs->d_kind == DK_PROTO_ARG) {
                                if (sym->s_scl != ABSTRACT) {
                                        lint_assert(sym->s_name != unnamed);
                                        /* void parameter cannot have ... */
                                        error(61, sym->s_name);
                                        *tpp = gettyp(INT);
                                }
-                       } else if (dcs->d_ctx == ABSTRACT) {
+                       } else if (dcs->d_kind == DK_ABSTRACT) {
                                /* ok */
                        } else if (sym->s_scl != TYPEDEF) {
                                /* void type for '%s' */
@@ -1160,7 +1161,7 @@
                }
        }
 
-       if (dcs->d_ctx == MOU) {
+       if (dcs->d_kind == DK_MOU) {
                o = dcs->d_offset_in_bits;
                dcs->d_offset_in_bits = 0;
        }



Home | Main Index | Thread Index | Old Index