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 add a type comparison function.
details: https://anonhg.NetBSD.org/src/rev/d14553deebfc
branches: trunk
changeset: 347246:d14553deebfc
user: christos <christos%NetBSD.org@localhost>
date: Fri Aug 19 10:18:11 2016 +0000
description:
add a type comparison function.
diffstat:
usr.bin/xlint/common/externs.h | 5 +-
usr.bin/xlint/common/tyname.c | 66 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 66 insertions(+), 5 deletions(-)
diffs (107 lines):
diff -r 97107d96b791 -r d14553deebfc usr.bin/xlint/common/externs.h
--- a/usr.bin/xlint/common/externs.h Fri Aug 19 10:05:35 2016 +0000
+++ b/usr.bin/xlint/common/externs.h Fri Aug 19 10:18:11 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs.h,v 1.5 2014/04/17 18:52:03 christos Exp $ */
+/* $NetBSD: externs.h,v 1.6 2016/08/19 10:18:11 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -44,7 +44,8 @@
/*
* tyname.c
*/
-extern const char *tyname(char *, size_t, type_t *);
+extern const char *tyname(char *, size_t, const type_t *);
+extern int sametype(const type_t *, const type_t *);
extern const char *basictyname(tspec_t);
/*
diff -r 97107d96b791 -r d14553deebfc usr.bin/xlint/common/tyname.c
--- a/usr.bin/xlint/common/tyname.c Fri Aug 19 10:05:35 2016 +0000
+++ b/usr.bin/xlint/common/tyname.c Fri Aug 19 10:18:11 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tyname.c,v 1.11 2012/06/20 18:50:11 christos Exp $ */
+/* $NetBSD: tyname.c,v 1.12 2016/08/19 10:18:11 christos 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.11 2012/06/20 18:50:11 christos Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.12 2016/08/19 10:18:11 christos Exp $");
#endif
#include <limits.h>
@@ -88,8 +88,68 @@
}
}
+int
+sametype(const type_t *t1, const type_t *t2)
+{
+ tspec_t t;
+
+ if (t1->t_tspec != t2->t_tspec)
+ return 0;
+
+ /* Ignore const/void */
+
+ 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:
+ case FLOAT:
+ case DOUBLE:
+ case LDOUBLE:
+ case VOID:
+ case FUNC:
+ case COMPLEX:
+ case FCOMPLEX:
+ case DCOMPLEX:
+ case LCOMPLEX:
+ return 1;
+ case ARRAY:
+ if (t1->t_dim != t2->t_dim)
+ return 0;
+ /*FALLTHROUGH*/
+ case PTR:
+ return sametype(t1->t_subt, t2->t_subt);
+ case ENUM:
+#ifdef t_enum
+ return strcmp(t1->t_enum->etag->s_name,
+ t2->t_enum->etag->s_name) == 0;
+#else
+ return 1;
+#endif
+ case STRUCT:
+ case UNION:
+#ifdef t_str
+ return strcmp(t1->t_str->stag->s_name,
+ t2->t_str->stag->s_name) == 0;
+#else
+ return 1;
+#endif
+ default:
+ LERROR("tyname(%d)", t);
+ return 0;
+ }
+}
+
const char *
-tyname(char *buf, size_t bufsiz, type_t *tp)
+tyname(char *buf, size_t bufsiz, const type_t *tp)
{
tspec_t t;
const char *s;
Home |
Main Index |
Thread Index |
Old Index