Factor out tyname() so that it can be used both by lint1 and lint2.
Since type_t is different between lint1.h and lint2.h include the appropriate file depending on the pass. Make the argument mismatch error print the type names of the types involved. Now that we have a tyname() function we can fix the rest of the pass2 warnings to be more explanatory, but not now.
This commit is contained in:
parent
fad5d2cf7a
commit
8b3f9b1455
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: externs.h,v 1.3 2003/10/21 23:58:53 christos Exp $ */
|
||||
/* $NetBSD: externs.h,v 1.4 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -41,6 +41,12 @@ extern int pflag;
|
||||
*/
|
||||
extern void inittyp(void);
|
||||
|
||||
/*
|
||||
* tyname.c
|
||||
*/
|
||||
extern const char *tyname(char *, size_t, type_t *);
|
||||
extern const char *basictyname(tspec_t);
|
||||
|
||||
/*
|
||||
* mem.c
|
||||
*/
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lint.h,v 1.8 2004/09/12 08:58:52 yamt Exp $ */
|
||||
/* $NetBSD: lint.h,v 1.9 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -124,4 +124,6 @@ typedef struct ob {
|
||||
char *o_nxt; /* next free byte in buffer */
|
||||
} ob_t;
|
||||
|
||||
typedef struct type type_t;
|
||||
|
||||
#include "externs.h"
|
||||
|
154
usr.bin/xlint/common/tyname.c
Normal file
154
usr.bin/xlint/common/tyname.c
Normal file
@ -0,0 +1,154 @@
|
||||
/*-
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: tyname.c,v 1.1 2005/04/07 16:28:40 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
|
||||
#include PASS
|
||||
|
||||
#ifndef LERROR
|
||||
#define LERROR(a) do { \
|
||||
(void)warnx("%s, %d: %s", __FILE__, __LINE__, (a)); \
|
||||
abort(); \
|
||||
} while (/*CONSTCOND*/0)
|
||||
#endif
|
||||
|
||||
const char *
|
||||
basictyname(tspec_t t)
|
||||
{
|
||||
switch (t) {
|
||||
case BOOL: return "_Bool";
|
||||
case CHAR: return "char";
|
||||
case UCHAR: return "unsigned char";
|
||||
case SCHAR: return "signed char";
|
||||
case SHORT: return "short";
|
||||
case USHORT: return "unsigned short";
|
||||
case INT: return "int";
|
||||
case UINT: return "unsigned int";
|
||||
case LONG: return "long";
|
||||
case ULONG: return "unsigned long";
|
||||
case QUAD: return "long long";
|
||||
case UQUAD: return "unsigned long long";
|
||||
case FLOAT: return "float";
|
||||
case DOUBLE: return "double";
|
||||
case LDOUBLE: return "long double";
|
||||
case PTR: return "pointer";
|
||||
case ENUM: return "enum";
|
||||
case STRUCT: return "struct";
|
||||
case UNION: return "union";
|
||||
case FUNC: return "function";
|
||||
case ARRAY: return "array";
|
||||
default:
|
||||
LERROR("basictyname()");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
tyname(char *buf, size_t bufsiz, type_t *tp)
|
||||
{
|
||||
tspec_t t;
|
||||
const char *s;
|
||||
char lbuf[64];
|
||||
|
||||
if ((t = tp->t_tspec) == INT && tp->t_isenum)
|
||||
t = ENUM;
|
||||
|
||||
s = basictyname(t);
|
||||
|
||||
|
||||
switch (t) {
|
||||
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 FUNC:
|
||||
(void)snprintf(buf, bufsiz, "%s", s);
|
||||
break;
|
||||
case PTR:
|
||||
(void)snprintf(buf, bufsiz, "%s to %s", s,
|
||||
tyname(lbuf, sizeof(lbuf), tp->t_subt));
|
||||
break;
|
||||
case ENUM:
|
||||
(void)snprintf(buf, bufsiz, "%s %s", s,
|
||||
#ifdef t_enum
|
||||
tp->t_enum->etag->s_name
|
||||
#else
|
||||
tp->t_tag->h_name
|
||||
#endif
|
||||
);
|
||||
break;
|
||||
case STRUCT:
|
||||
case UNION:
|
||||
(void)snprintf(buf, bufsiz, "%s %s", s,
|
||||
#ifdef t_str
|
||||
tp->t_str->stag->s_name
|
||||
#else
|
||||
tp->t_tag->h_name
|
||||
#endif
|
||||
);
|
||||
break;
|
||||
case ARRAY:
|
||||
(void)snprintf(buf, bufsiz, "%s of %s[%d]", s,
|
||||
tyname(lbuf, sizeof(lbuf), tp->t_subt), tp->t_dim);
|
||||
break;
|
||||
default:
|
||||
LERROR("tyname()");
|
||||
}
|
||||
return (buf);
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
# $NetBSD: Makefile,v 1.34 2003/10/21 10:01:22 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.35 2005/04/07 16:28:40 christos Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= lint1
|
||||
SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
|
||||
init.c emit.c emit1.c inittyp.c
|
||||
init.c emit.c emit1.c inittyp.c tyname.c
|
||||
MAN= lint.7
|
||||
YHEADER=
|
||||
|
||||
CPPFLAGS+= -I${.CURDIR} -I.
|
||||
CPPFLAGS+= -I${.CURDIR} -I. -DPASS=\"${PROG}.h\"
|
||||
|
||||
.if ${OBJECT_FMT} == "a.out"
|
||||
CPPFLAGS+= -DTARGET_OBJFMT_AOUT
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: externs1.h,v 1.20 2002/11/02 20:09:27 perry Exp $ */
|
||||
/* $NetBSD: externs1.h,v 1.21 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -197,8 +197,6 @@ extern int typeok(op_t, int, tnode_t *, tnode_t *);
|
||||
extern tnode_t *promote(op_t, int, tnode_t *);
|
||||
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
|
||||
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
|
||||
extern const char *tyname(char *, size_t, type_t *);
|
||||
extern const char *basictyname(tspec_t);
|
||||
extern tnode_t *bldszof(type_t *);
|
||||
extern tnode_t *cast(tnode_t *, type_t *);
|
||||
extern tnode_t *funcarg(tnode_t *, tnode_t *);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lint1.h,v 1.16 2002/10/21 22:44:08 christos Exp $ */
|
||||
/* $NetBSD: lint1.h,v 1.17 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
@ -133,7 +133,7 @@ typedef struct {
|
||||
* Types are represented by concatenation of structures of type type_t
|
||||
* via t_subt.
|
||||
*/
|
||||
typedef struct type {
|
||||
struct type {
|
||||
tspec_t t_tspec; /* type specifier */
|
||||
u_int t_aincompl : 1; /* incomplete array type */
|
||||
u_int t_const : 1; /* const modifier */
|
||||
@ -155,7 +155,7 @@ typedef struct type {
|
||||
} t_b;
|
||||
struct type *t_subt; /* element type (arrays), return value
|
||||
(functions), or type pointer points to */
|
||||
} type_t;
|
||||
};
|
||||
|
||||
#define t_dim t_u._t_dim
|
||||
#define t_str t_u._t_str
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tree.c,v 1.40 2005/01/02 17:59:47 christos Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.41 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: tree.c,v 1.40 2005/01/02 17:59:47 christos Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.41 2005/04/07 16:28:40 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
@ -2257,92 +2257,6 @@ conmemb(type_t *tp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
const char *
|
||||
basictyname(tspec_t t)
|
||||
{
|
||||
switch (t) {
|
||||
case BOOL: return "_Bool";
|
||||
case CHAR: return "char";
|
||||
case UCHAR: return "unsigned char";
|
||||
case SCHAR: return "signed char";
|
||||
case SHORT: return "short";
|
||||
case USHORT: return "unsigned short";
|
||||
case INT: return "int";
|
||||
case UINT: return "unsigned int";
|
||||
case LONG: return "long";
|
||||
case ULONG: return "unsigned long";
|
||||
case QUAD: return "long long";
|
||||
case UQUAD: return "unsigned long long";
|
||||
case FLOAT: return "float";
|
||||
case DOUBLE: return "double";
|
||||
case LDOUBLE: return "long double";
|
||||
case PTR: return "pointer";
|
||||
case ENUM: return "enum";
|
||||
case STRUCT: return "struct";
|
||||
case UNION: return "union";
|
||||
case FUNC: return "function";
|
||||
case ARRAY: return "array";
|
||||
default:
|
||||
LERROR("basictyname()");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
tyname(char *buf, size_t bufsiz, type_t *tp)
|
||||
{
|
||||
tspec_t t;
|
||||
const char *s;
|
||||
char lbuf[64];
|
||||
|
||||
if ((t = tp->t_tspec) == INT && tp->t_isenum)
|
||||
t = ENUM;
|
||||
|
||||
s = basictyname(t);
|
||||
|
||||
|
||||
switch (t) {
|
||||
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 FUNC:
|
||||
(void)snprintf(buf, bufsiz, "%s", s);
|
||||
break;
|
||||
case PTR:
|
||||
(void)snprintf(buf, bufsiz, "%s to %s", s,
|
||||
tyname(lbuf, sizeof(lbuf), tp->t_subt));
|
||||
break;
|
||||
case ENUM:
|
||||
(void)snprintf(buf, bufsiz, "%s %s", s,
|
||||
tp->t_enum->etag->s_name);
|
||||
break;
|
||||
case STRUCT:
|
||||
case UNION:
|
||||
(void)snprintf(buf, bufsiz, "%s %s", s,
|
||||
tp->t_str->stag->s_name);
|
||||
break;
|
||||
case ARRAY:
|
||||
(void)snprintf(buf, bufsiz, "%s of %s[%d]", s,
|
||||
tyname(lbuf, sizeof(lbuf), tp->t_subt), tp->t_dim);
|
||||
break;
|
||||
default:
|
||||
LERROR("tyname()");
|
||||
}
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new node for one of the operators POINT and ARROW.
|
||||
*/
|
||||
|
@ -1,12 +1,13 @@
|
||||
# $NetBSD: Makefile,v 1.15 2003/05/18 07:57:38 lukem Exp $
|
||||
# $NetBSD: Makefile,v 1.16 2005/04/07 16:28:40 christos Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= lint2
|
||||
SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c \
|
||||
inittyp.c
|
||||
inittyp.c tyname.c
|
||||
LINTFLAGS= -abehrz
|
||||
WFORMAT=1 # hopeless
|
||||
BINDIR= /usr/libexec
|
||||
CPPFLAGS+= -DPASS=\"${PROG}.h\" -I${.CURDIR}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: chk.c,v 1.17 2004/06/20 22:20:17 jmc Exp $ */
|
||||
/* $NetBSD: chk.c,v 1.18 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: chk.c,v 1.17 2004/06/20 22:20:17 jmc Exp $");
|
||||
__RCSID("$NetBSD: chk.c,v 1.18 2005/04/07 16:28:40 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
@ -447,6 +447,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
|
||||
tspec_t t1, t2;
|
||||
arginf_t *ai, *ai1;
|
||||
char *pos1;
|
||||
char tyname1[64], tyname2[64];
|
||||
|
||||
/*
|
||||
* If a function definition is available (def != NULL), we compair the
|
||||
@ -582,8 +583,11 @@ chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
|
||||
}
|
||||
|
||||
pos1 = xstrdup(mkpos(pos1p));
|
||||
/* %s, arg %d used inconsistently\t%s :: %s */
|
||||
msg(6, hte->h_name, n, pos1, mkpos(&call->f_pos));
|
||||
/* %s, arg %d used inconsistently\t%s[%s] :: %s[%s] */
|
||||
msg(6, hte->h_name, n, pos1,
|
||||
tyname(tyname1, sizeof(tyname1), arg1),
|
||||
mkpos(&call->f_pos),
|
||||
tyname(tyname2, sizeof(tyname2), arg2));
|
||||
free(pos1);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lint2.h,v 1.6 2001/05/28 12:40:38 lukem Exp $ */
|
||||
/* $NetBSD: lint2.h,v 1.7 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
@ -37,7 +37,7 @@
|
||||
/*
|
||||
* Types are described by structures of type type_t.
|
||||
*/
|
||||
typedef struct type {
|
||||
struct type {
|
||||
tspec_t t_tspec; /* type specifier */
|
||||
u_int t_const : 1; /* constant */
|
||||
u_int t_volatile : 1; /* volatile */
|
||||
@ -66,7 +66,7 @@ typedef struct type {
|
||||
} t_u;
|
||||
struct type *t_subt; /* indirected type (array element, pointed to
|
||||
type, type of return value) */
|
||||
} type_t;
|
||||
};
|
||||
|
||||
#define t_dim t_u._t_dim
|
||||
#define t_tag t_u._t_tag
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: msg.c,v 1.8 2004/06/20 22:20:17 jmc Exp $ */
|
||||
/* $NetBSD: msg.c,v 1.9 2005/04/07 16:28:40 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID) && !defined(lint)
|
||||
__RCSID("$NetBSD: msg.c,v 1.8 2004/06/20 22:20:17 jmc Exp $");
|
||||
__RCSID("$NetBSD: msg.c,v 1.9 2005/04/07 16:28:40 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@ -53,7 +53,7 @@ static const char *msgs[] = {
|
||||
"%s multiply defined \t%s :: %s", /* 3 */
|
||||
"%s value used inconsistently \t%s :: %s", /* 4 */
|
||||
"%s value declared inconsistently \t%s :: %s", /* 5 */
|
||||
"%s, arg %d used inconsistently \t%s :: %s", /* 6 */
|
||||
"%s, arg %d used inconsistently \t%s[%s] :: %s[%s]", /* 6 */
|
||||
"%s: variable # of args \t%s :: %s", /* 7 */
|
||||
"%s returns value which is always ignored", /* 8 */
|
||||
"%s returns value which is sometimes ignored", /* 9 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user