Module Name: src
Committed By: rillig
Date: Sun Jan 3 15:55:18 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_124.exp
src/usr.bin/xlint/common: tyname.c
Log Message:
lint: add detailed type information for functions
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_124.exp
cvs rdiff -u -r1.20 -r1.21 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_124.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_124.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_124.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_124.exp:1.3 Sun Jan 3 15:51:16 2021
+++ src/tests/usr.bin/xlint/lint1/msg_124.exp Sun Jan 3 15:55:18 2021
@@ -1,3 +1,3 @@
-msg_124.c(16): warning: illegal pointer combination (pointer to function) and (pointer to int), op p = p [124]
-msg_124.c(17): warning: illegal pointer combination (pointer to function) and (pointer to int), op p = p [124]
-msg_124.c(18): warning: illegal pointer combination (pointer to function) and (pointer to int), op p = p [124]
+msg_124.c(16): warning: illegal pointer combination (pointer to function(int) returning void) and (pointer to int), op p = p [124]
+msg_124.c(17): warning: illegal pointer combination (pointer to function(pointer to function(int) returning void) returning pointer to function(int) returning void) and (pointer to int), op p = p [124]
+msg_124.c(18): warning: illegal pointer combination (pointer to function(pointer to const char, ...) returning int) and (pointer to int), op p = p [124]
Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.20 src/usr.bin/xlint/common/tyname.c:1.21
--- src/usr.bin/xlint/common/tyname.c:1.20 Sat Jan 2 03:49:25 2021
+++ src/usr.bin/xlint/common/tyname.c Sun Jan 3 15:55:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tyname.c,v 1.20 2021/01/02 03:49:25 rillig Exp $ */
+/* $NetBSD: tyname.c,v 1.21 2021/01/03 15:55:18 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.20 2021/01/02 03:49:25 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.21 2021/01/03 15:55:18 rillig Exp $");
#endif
#include <limits.h>
@@ -256,6 +256,37 @@ sametype(const type_t *t1, const type_t
}
}
+static void
+type_name_of_function(buffer *buf, const type_t *tp)
+{
+ const char *sep = "";
+
+ buf_add(buf, "(");
+ if (tp->t_proto) {
+#ifdef t_enum /* lint1 */
+ sym_t *arg;
+
+ for (arg = tp->t_args; arg != NULL; arg = arg->s_next) {
+ buf_add(buf, sep), sep = ", ";
+ buf_add(buf, type_name(arg->s_type));
+ }
+#else /* lint2 */
+ type_t **argtype;
+
+ for (argtype = tp->t_args; *argtype != NULL; argtype++) {
+ buf_add(buf, sep), sep = ", ";
+ buf_add(buf, type_name(*argtype));
+ }
+#endif
+ }
+ if (tp->t_vararg) {
+ buf_add(buf, sep), sep = ", ";
+ buf_add(buf, "...");
+ }
+ buf_add(buf, ") returning ");
+ buf_add(buf, type_name(tp->t_subt));
+}
+
const char *
type_name(const type_t *tp)
{
@@ -301,7 +332,6 @@ type_name(const type_t *tp)
case DOUBLE:
case LDOUBLE:
case VOID:
- case FUNC:
case COMPLEX:
case FCOMPLEX:
case DCOMPLEX:
@@ -339,8 +369,12 @@ type_name(const type_t *tp)
buf_add_int(&buf, tp->t_dim);
buf_add(&buf, "]");
break;
+ case FUNC:
+ type_name_of_function(&buf, tp);
+ break;
+
default:
- LERROR("tyname(%d)", t);
+ LERROR("type_name(%d)", t);
}
name = intern(buf.data);