Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/common lint: output precise type information f...



details:   https://anonhg.NetBSD.org/src/rev/1d6a8f701f61
branches:  trunk
changeset: 953167:1d6a8f701f61
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 02:29:28 2021 +0000

description:
lint: output precise type information for struct/union/enum

Previously, 'typedef enum { E } name' was output as 'name', which
omitted the information that this was an enum type.  Now it is output as
'enum typedef name'.

Previously, 'typedef struct { int member; } name' was output as 'struct
<unnamed>', which omitted the typedef name.  Now it is output as 'struct
typedef name'.

diffstat:

 tests/usr.bin/xlint/lint1/msg_210.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_245.exp |   2 +-
 usr.bin/xlint/common/tyname.c         |  62 ++++++++++++++++++++++------------
 3 files changed, 41 insertions(+), 25 deletions(-)

diffs (115 lines):

diff -r e98caf0905e4 -r 1d6a8f701f61 tests/usr.bin/xlint/lint1/msg_210.exp
--- a/tests/usr.bin/xlint/lint1/msg_210.exp     Sun Feb 28 02:00:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_210.exp     Sun Feb 28 02:29:28 2021 +0000
@@ -1,2 +1,2 @@
 msg_210.c(23): warning: enum type mismatch between 'enum A' and 'enum B' in initialization [210]
-msg_210.c(25): warning: enum type mismatch between 'C' and 'D' in initialization [210]
+msg_210.c(25): warning: enum type mismatch between 'enum typedef C' and 'enum typedef D' in initialization [210]
diff -r e98caf0905e4 -r 1d6a8f701f61 tests/usr.bin/xlint/lint1/msg_245.exp
--- a/tests/usr.bin/xlint/lint1/msg_245.exp     Sun Feb 28 02:00:05 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_245.exp     Sun Feb 28 02:29:28 2021 +0000
@@ -1,3 +1,3 @@
 msg_245.c(29): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct only_tag' [245]
-msg_245.c(30): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct <unnamed>' [245]
+msg_245.c(30): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct typedef only_typedef' [245]
 msg_245.c(31): warning: incompatible structure pointers: 'pointer to struct tag_and_typedef_tag' '==' 'pointer to struct <unnamed>' [245]
diff -r e98caf0905e4 -r 1d6a8f701f61 usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sun Feb 28 02:00:05 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sun Feb 28 02:29:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tyname.c,v 1.31 2021/02/21 14:19:27 rillig Exp $       */
+/*     $NetBSD: tyname.c,v 1.32 2021/02/28 02:29:28 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.31 2021/02/21 14:19:27 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.32 2021/02/28 02:29:28 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -280,6 +280,40 @@
        buf_add(buf, type_name(tp->t_subt));
 }
 
+static void
+type_name_of_struct_or_union(buffer *buf, const type_t *tp)
+{
+       buf_add(buf, " ");
+#ifdef t_str
+       if (tp->t_str->sou_tag->s_name == unnamed &&
+           tp->t_str->sou_first_typedef != NULL) {
+               buf_add(buf, "typedef ");
+               buf_add(buf, tp->t_str->sou_first_typedef->s_name);
+       } else {
+               buf_add(buf, tp->t_str->sou_tag->s_name);
+       }
+#else
+       buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
+#endif
+}
+
+static void
+type_name_of_enum(buffer *buf, const type_t *tp)
+{
+       buf_add(buf, " ");
+#ifdef t_enum
+       if (tp->t_enum->en_tag->s_name == unnamed &&
+           tp->t_enum->en_first_typedef != NULL) {
+               buf_add(buf, "typedef ");
+               buf_add(buf, tp->t_enum->en_first_typedef->s_name);
+       } else {
+               buf_add(buf, tp->t_enum->en_tag->s_name);
+       }
+#else
+       buf_add(buf, tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
+#endif
+}
+
 const char *
 type_name(const type_t *tp)
 {
@@ -302,6 +336,7 @@
                buf_add(&buf, "const ");
        if (tp->t_volatile)
                buf_add(&buf, "volatile ");
+
        buf_add(&buf, tspec_name(t));
 
        switch (t) {
@@ -337,30 +372,11 @@
                buf_add(&buf, type_name(tp->t_subt));
                break;
        case ENUM:
-#ifdef t_enum
-               if (tp->t_enum->en_tag->s_name == unnamed &&
-                   tp->t_enum->en_first_typedef != NULL) {
-                       buf.len -= strlen(tspec_name(t));
-                       buf_add(&buf, tp->t_enum->en_first_typedef->s_name);
-               } else {
-                       buf_add(&buf, " ");
-                       buf_add(&buf, tp->t_enum->en_tag->s_name);
-               }
-#else
-               buf_add(&buf, " ");
-               buf_add(&buf,
-                   tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
-#endif
+               type_name_of_enum(&buf, tp);
                break;
        case STRUCT:
        case UNION:
-               buf_add(&buf, " ");
-#ifdef t_str
-               buf_add(&buf, tp->t_str->sou_tag->s_name);
-#else
-               buf_add(&buf,
-                   tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
-#endif
+               type_name_of_struct_or_union(&buf, tp);
                break;
        case ARRAY:
                buf_add(&buf, " of ");



Home | Main Index | Thread Index | Old Index