Module Name:    src
Committed By:   rillig
Date:           Sun Feb 28 02:29:29 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_210.exp msg_245.exp
        src/usr.bin/xlint/common: tyname.c

Log Message:
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'.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_210.exp
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_245.exp
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/xlint/common/tyname.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_210.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_210.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_210.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_210.exp:1.4	Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.exp	Sun Feb 28 02:29:28 2021
@@ -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]

Index: src/tests/usr.bin/xlint/lint1/msg_245.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_245.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_245.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_245.exp:1.3	Sun Feb 28 02:00:06 2021
+++ src/tests/usr.bin/xlint/lint1/msg_245.exp	Sun Feb 28 02:29:28 2021
@@ -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]

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.31 src/usr.bin/xlint/common/tyname.c:1.32
--- src/usr.bin/xlint/common/tyname.c:1.31	Sun Feb 21 14:19:27 2021
+++ src/usr.bin/xlint/common/tyname.c	Sun Feb 28 02:29:28 2021
@@ -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 @@ type_name_of_function(buffer *buf, const
 	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 @@ type_name(const type_t *tp)
 		buf_add(&buf, "const ");
 	if (tp->t_volatile)
 		buf_add(&buf, "volatile ");
+
 	buf_add(&buf, tspec_name(t));
 
 	switch (t) {
@@ -337,30 +372,11 @@ type_name(const type_t *tp)
 		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 ");

Reply via email to