Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint lint: clean up and move 'sametype'



details:   https://anonhg.NetBSD.org/src/rev/8ea6302611fe
branches:  trunk
changeset: 1022724:8ea6302611fe
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 03 17:44:58 2021 +0000

description:
lint: clean up and move 'sametype'

This function is only used by lint1.  That's good since the lint2 code
was completely broken, as it would regard any two struct types as being
the same.

Remove the large switch statement since it is unlikely that there will
be new type derivations in C anytime soon.

No functional change.

diffstat:

 usr.bin/xlint/common/emit.c    |   5 +-
 usr.bin/xlint/common/externs.h |   3 +-
 usr.bin/xlint/common/tyname.c  |  72 ++---------------------------------------
 usr.bin/xlint/lint1/tree.c     |  34 ++++++++++++++++++-
 4 files changed, 39 insertions(+), 75 deletions(-)

diffs (200 lines):

diff -r c78eb55d8477 -r 8ea6302611fe usr.bin/xlint/common/emit.c
--- a/usr.bin/xlint/common/emit.c       Tue Aug 03 17:27:48 2021 +0000
+++ b/usr.bin/xlint/common/emit.c       Tue Aug 03 17:44:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emit.c,v 1.11 2021/03/27 11:08:00 rillig Exp $ */
+/*     $NetBSD: emit.c,v 1.12 2021/08/03 17:44:58 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,10 +37,9 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit.c,v 1.11 2021/03/27 11:08:00 rillig Exp $");
+__RCSID("$NetBSD: emit.c,v 1.12 2021/08/03 17:44:58 rillig Exp $");
 #endif
 
-#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 
diff -r c78eb55d8477 -r 8ea6302611fe usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h    Tue Aug 03 17:27:48 2021 +0000
+++ b/usr.bin/xlint/common/externs.h    Tue Aug 03 17:44:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs.h,v 1.17 2021/08/01 18:13:53 rillig Exp $      */
+/*     $NetBSD: externs.h,v 1.18 2021/08/03 17:44:58 rillig Exp $      */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -47,7 +47,6 @@
  * tyname.c
  */
 extern const char *type_name(const type_t *);
-extern bool    sametype(const type_t *, const type_t *);
 extern const   char *tspec_name(tspec_t);
 
 /*
diff -r c78eb55d8477 -r 8ea6302611fe usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Tue Aug 03 17:27:48 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Tue Aug 03 17:44:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.43 2021/07/02 18:22:09 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.44 2021/08/03 17:44:58 rillig Exp $       */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.43 2021/07/02 18:22:09 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.44 2021/08/03 17:44:58 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -59,7 +59,7 @@
 
 /* A tree of strings. */
 typedef struct name_tree_node {
-       char *ntn_name;
+       const char *ntn_name;
        struct name_tree_node *ntn_less;
        struct name_tree_node *ntn_greater;
 } name_tree_node;
@@ -85,7 +85,7 @@
        return n;
 }
 
-/* Return the canonical instance of the string, with unlimited life time. */
+/* Return the canonical instance of the string, with unlimited lifetime. */
 static const char *
 intern(const char *name)
 {
@@ -189,70 +189,6 @@
        }
 }
 
-bool
-sametype(const type_t *t1, const type_t *t2)
-{
-       tspec_t t;
-
-       if (t1->t_tspec != t2->t_tspec)
-               return false;
-
-       /* Ignore const/volatile */
-
-       switch (t = t1->t_tspec) {
-       case BOOL:
-       case CHAR:
-       case UCHAR:
-       case SCHAR:
-       case SHORT:
-       case USHORT:
-       case INT:
-       case UINT:
-       case LONG:
-       case ULONG:
-       case QUAD:
-       case UQUAD:
-#ifdef INT128_SIZE
-       case INT128:
-       case UINT128:
-#endif
-       case FLOAT:
-       case DOUBLE:
-       case LDOUBLE:
-       case VOID:
-       case FUNC:
-       case COMPLEX:
-       case FCOMPLEX:
-       case DCOMPLEX:
-       case LCOMPLEX:
-               return true;
-       case ARRAY:
-               if (t1->t_dim != t2->t_dim)
-                       return false;
-               /*FALLTHROUGH*/
-       case PTR:
-               return sametype(t1->t_subt, t2->t_subt);
-       case ENUM:
-#ifdef t_enum
-               return strcmp(t1->t_enum->en_tag->s_name,
-                   t2->t_enum->en_tag->s_name) == 0;
-#else
-               return true;
-#endif
-       case STRUCT:
-       case UNION:
-#ifdef t_str
-               return strcmp(t1->t_str->sou_tag->s_name,
-                   t2->t_str->sou_tag->s_name) == 0;
-#else
-               return true;
-#endif
-       default:
-               INTERNAL_ERROR("tyname(%d)", t);
-               return false;
-       }
-}
-
 static void
 type_name_of_function(buffer *buf, const type_t *tp)
 {
diff -r c78eb55d8477 -r 8ea6302611fe usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Aug 03 17:27:48 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Aug 03 17:44:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.326 2021/08/01 19:11:54 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.327 2021/08/03 17:44:59 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.326 2021/08/01 19:11:54 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.327 2021/08/03 17:44:59 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -102,6 +102,36 @@
        return modtab[op].m_name;
 }
 
+static bool
+sametype(const type_t *t1, const type_t *t2)
+{
+
+       /* Maybe this can be merged into 'eqtype'. */
+
+       if (t1->t_tspec != t2->t_tspec)
+               return false;
+
+       /* Ignore const/volatile */
+
+       switch (t1->t_tspec) {
+       case ARRAY:
+               if (t1->t_dim != t2->t_dim)
+                       return false;
+               /*FALLTHROUGH*/
+       case PTR:
+               return sametype(t1->t_subt, t2->t_subt);
+       case ENUM:
+               return strcmp(t1->t_enum->en_tag->s_name,
+                   t2->t_enum->en_tag->s_name) == 0;
+       case STRUCT:
+       case UNION:
+               return strcmp(t1->t_str->sou_tag->s_name,
+                   t2->t_str->sou_tag->s_name) == 0;
+       default:
+               return true;
+       }
+}
+
 /* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */
 type_t *
 derive_type(type_t *tp, tspec_t t)



Home | Main Index | Thread Index | Old Index