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: add detailed type information for...



details:   https://anonhg.NetBSD.org/src/rev/51a46b4161a8
branches:  trunk
changeset: 949156:51a46b4161a8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jan 03 15:55:18 2021 +0000

description:
lint: add detailed type information for functions

diffstat:

 tests/usr.bin/xlint/lint1/msg_124.exp |   6 ++--
 usr.bin/xlint/common/tyname.c         |  42 +++++++++++++++++++++++++++++++---
 2 files changed, 41 insertions(+), 7 deletions(-)

diffs (88 lines):

diff -r d17483899ae4 -r 51a46b4161a8 tests/usr.bin/xlint/lint1/msg_124.exp
--- a/tests/usr.bin/xlint/lint1/msg_124.exp     Sun Jan 03 15:51:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_124.exp     Sun Jan 03 15:55:18 2021 +0000
@@ -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]
diff -r d17483899ae4 -r 51a46b4161a8 usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c     Sun Jan 03 15:51:16 2021 +0000
+++ b/usr.bin/xlint/common/tyname.c     Sun Jan 03 15:55:18 2021 +0000
@@ -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 @@
        }
 }
 
+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 @@
        case DOUBLE:
        case LDOUBLE:
        case VOID:
-       case FUNC:
        case COMPLEX:
        case FCOMPLEX:
        case DCOMPLEX:
@@ -339,8 +369,12 @@
                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);



Home | Main Index | Thread Index | Old Index