Module Name: src Committed By: christos Date: Fri Aug 19 10:18:11 UTC 2016
Modified Files: src/usr.bin/xlint/common: externs.h tyname.c Log Message: add a type comparison function. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/xlint/common/externs.h cvs rdiff -u -r1.11 -r1.12 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/usr.bin/xlint/common/externs.h diff -u src/usr.bin/xlint/common/externs.h:1.5 src/usr.bin/xlint/common/externs.h:1.6 --- src/usr.bin/xlint/common/externs.h:1.5 Thu Apr 17 14:52:03 2014 +++ src/usr.bin/xlint/common/externs.h Fri Aug 19 06:18:11 2016 @@ -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 @@ extern void inittyp(void); /* * 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); /* Index: src/usr.bin/xlint/common/tyname.c diff -u src/usr.bin/xlint/common/tyname.c:1.11 src/usr.bin/xlint/common/tyname.c:1.12 --- src/usr.bin/xlint/common/tyname.c:1.11 Wed Jun 20 14:50:11 2012 +++ src/usr.bin/xlint/common/tyname.c Fri Aug 19 06:18:11 2016 @@ -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 @@ basictyname(tspec_t t) } } +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;