Module Name: src
Committed By: rillig
Date: Mon Dec 28 18:49:02 UTC 2020
Modified Files:
src/usr.bin/xlint/common: lint.h
src/usr.bin/xlint/lint1: decl.c emit1.c func.c init.c tree.c
src/usr.bin/xlint/lint2: chk.c
Log Message:
lint: rename tspec macros
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.71 -r1.72 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/xlint/lint1/emit1.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/xlint/lint1/init.c
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/xlint/lint1/tree.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint2/chk.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/lint.h
diff -u src/usr.bin/xlint/common/lint.h:1.15 src/usr.bin/xlint/common/lint.h:1.16
--- src/usr.bin/xlint/common/lint.h:1.15 Mon Dec 28 18:06:23 2020
+++ src/usr.bin/xlint/common/lint.h Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.h,v 1.15 2020/12/28 18:06:23 rillig Exp $ */
+/* $NetBSD: lint.h,v 1.16 2020/12/28 18:49:02 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -94,25 +94,25 @@ typedef struct {
if pflag is set */
tspec_t tt_styp; /* signed counterpart */
tspec_t tt_utyp; /* unsigned counterpart */
- u_int tt_isityp : 1; /* 1 if integer type */
- u_int tt_isutyp : 1; /* 1 if unsigned integer type */
- u_int tt_isftyp : 1; /* 1 if floating point type */
- u_int tt_isatyp : 1; /* 1 if arithmetic type */
- u_int tt_issclt : 1; /* 1 if scalar type */
- u_int tt_isctyp : 1; /* 1 if complex type */
+ u_int tt_is_int : 1; /* 1 if integer type */
+ u_int tt_is_uint : 1; /* 1 if unsigned integer type */
+ u_int tt_is_float : 1; /* 1 if floating point type */
+ u_int tt_is_arith : 1; /* 1 if arithmetic type */
+ u_int tt_is_scalar : 1; /* 1 if scalar type */
+ u_int tt_is_complex : 1; /* 1 if complex type */
const char *tt_name; /* name of the type */
} ttab_t;
-#define size(t) (ttab[t].tt_sz)
-#define psize(t) (ttab[t].tt_psz)
-#define styp(t) (ttab[t].tt_styp)
-#define utyp(t) (ttab[t].tt_utyp)
-#define isityp(t) (ttab[t].tt_isityp)
-#define isutyp(t) (ttab[t].tt_isutyp)
-#define isftyp(t) (ttab[t].tt_isftyp)
-#define isatyp(t) (ttab[t].tt_isatyp)
-#define isctyp(t) (ttab[t].tt_isctyp)
-#define issclt(t) (ttab[t].tt_issclt)
+#define size(t) (ttab[t].tt_sz)
+#define psize(t) (ttab[t].tt_psz)
+#define styp(t) (ttab[t].tt_styp)
+#define utyp(t) (ttab[t].tt_utyp)
+#define tspec_is_int(t) (ttab[t].tt_is_int)
+#define tspec_is_uint(t) (ttab[t].tt_is_uint)
+#define tspec_is_float(t) (ttab[t].tt_is_float)
+#define tspec_is_arith(t) (ttab[t].tt_is_arith)
+#define tspec_is_complex(t) (ttab[t].tt_is_complex)
+#define tspec_is_scalar(t) (ttab[t].tt_is_scalar)
extern ttab_t ttab[];
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.71 src/usr.bin/xlint/lint1/decl.c:1.72
--- src/usr.bin/xlint/lint1/decl.c:1.71 Tue Jun 2 21:10:07 2020
+++ src/usr.bin/xlint/lint1/decl.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.71 2020/06/02 21:10:07 christos Exp $ */
+/* $NetBSD: decl.c,v 1.72 2020/12/28 18:49:02 rillig 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: decl.c,v 1.71 2020/06/02 21:10:07 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.72 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <sys/param.h>
@@ -1142,7 +1142,7 @@ decl1str(sym_t *dsym)
* Integer types not dealt with above are
* okay only if BITFIELDTYPE is in effect.
*/
- if (bitfieldtype_ok == 0 || isityp(t) == 0) {
+ if (bitfieldtype_ok == 0 || tspec_is_int(t) == 0) {
/* illegal bit-field type */
warning(35);
sz = tp->t_flen;
Index: src/usr.bin/xlint/lint1/emit1.c
diff -u src/usr.bin/xlint/lint1/emit1.c:1.21 src/usr.bin/xlint/lint1/emit1.c:1.22
--- src/usr.bin/xlint/lint1/emit1.c:1.21 Mon Dec 28 12:52:45 2020
+++ src/usr.bin/xlint/lint1/emit1.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.21 2020/12/28 12:52:45 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.22 2020/12/28 18:49:02 rillig 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: emit1.c,v 1.21 2020/12/28 12:52:45 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.22 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <ctype.h>
@@ -442,7 +442,7 @@ outcall(tnode_t *tn, int rvused, int rvd
continue;
arg = arg->tn_left;
if (arg->tn_op == CON) {
- if (isityp(t = arg->tn_type->t_tspec)) {
+ if (tspec_is_int(t = arg->tn_type->t_tspec)) {
/*
* XXX it would probably be better to
* explicitly test the sign
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.26 src/usr.bin/xlint/lint1/func.c:1.27
--- src/usr.bin/xlint/lint1/func.c:1.26 Fri Aug 19 10:58:15 2016
+++ src/usr.bin/xlint/lint1/func.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.26 2016/08/19 10:58:15 christos Exp $ */
+/* $NetBSD: func.c,v 1.27 2020/12/28 18:49:02 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.26 2016/08/19 10:58:15 christos Exp $");
+__RCSID("$NetBSD: func.c,v 1.27 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <stdlib.h>
@@ -443,7 +443,7 @@ label(int typ, sym_t *sym, tnode_t *tn)
/* non-constant case expression */
error(197);
tn = NULL;
- } else if (tn != NULL && !isityp(tn->tn_type->t_tspec)) {
+ } else if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
/* non-integral case expression */
error(198);
tn = NULL;
@@ -482,7 +482,7 @@ label(int typ, sym_t *sym, tnode_t *tn)
if (cl->cl_val.v_quad == nv.v_quad)
break;
}
- if (cl != NULL && isutyp(nv.v_tspec)) {
+ if (cl != NULL && tspec_is_uint(nv.v_tspec)) {
/* duplicate case in switch, %lu */
error(200, (u_long)nv.v_quad);
} else if (cl != NULL) {
@@ -583,7 +583,7 @@ switch1(tnode_t *tn)
tn = cconv(tn);
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- if (tn != NULL && !isityp(tn->tn_type->t_tspec)) {
+ if (tn != NULL && !tspec_is_int(tn->tn_type->t_tspec)) {
/* switch expression must have integral type */
error(205);
tn = NULL;
@@ -693,7 +693,7 @@ while1(tnode_t *tn)
tn = cconv(tn);
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- if (tn != NULL && !issclt(tn->tn_type->t_tspec)) {
+ if (tn != NULL && !tspec_is_scalar(tn->tn_type->t_tspec)) {
/* controlling expressions must have scalar type */
error(204);
tn = NULL;
@@ -702,7 +702,7 @@ while1(tnode_t *tn)
pushctrl(T_WHILE);
cstk->c_loop = 1;
if (tn != NULL && tn->tn_op == CON) {
- if (isityp(tn->tn_type->t_tspec)) {
+ if (tspec_is_int(tn->tn_type->t_tspec)) {
cstk->c_infinite = tn->tn_val->v_quad != 0;
} else {
cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
@@ -766,14 +766,14 @@ do2(tnode_t *tn)
tn = cconv(tn);
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- if (tn != NULL && !issclt(tn->tn_type->t_tspec)) {
+ if (tn != NULL && !tspec_is_scalar(tn->tn_type->t_tspec)) {
/* controlling expressions must have scalar type */
error(204);
tn = NULL;
}
if (tn != NULL && tn->tn_op == CON) {
- if (isityp(tn->tn_type->t_tspec)) {
+ if (tspec_is_int(tn->tn_type->t_tspec)) {
cstk->c_infinite = tn->tn_val->v_quad != 0;
} else {
cstk->c_infinite = tn->tn_val->v_ldbl != 0.0;
@@ -831,7 +831,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t
tn2 = cconv(tn2);
if (tn2 != NULL)
tn2 = promote(NOOP, 0, tn2);
- if (tn2 != NULL && !issclt(tn2->tn_type->t_tspec)) {
+ if (tn2 != NULL && !tspec_is_scalar(tn2->tn_type->t_tspec)) {
/* controlling expressions must have scalar type */
error(204);
tn2 = NULL;
@@ -842,7 +842,7 @@ for1(tnode_t *tn1, tnode_t *tn2, tnode_t
if (tn2 == NULL) {
cstk->c_infinite = 1;
} else if (tn2->tn_op == CON) {
- if (isityp(tn2->tn_type->t_tspec)) {
+ if (tspec_is_int(tn2->tn_type->t_tspec)) {
cstk->c_infinite = tn2->tn_val->v_quad != 0;
} else {
cstk->c_infinite = tn2->tn_val->v_ldbl != 0.0;
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.28 src/usr.bin/xlint/lint1/init.c:1.29
--- src/usr.bin/xlint/lint1/init.c:1.28 Mon Dec 28 12:52:45 2020
+++ src/usr.bin/xlint/lint1/init.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.28 2020/12/28 12:52:45 rillig Exp $ */
+/* $NetBSD: init.c,v 1.29 2020/12/28 18:49:02 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.28 2020/12/28 12:52:45 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.29 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <stdlib.h>
@@ -281,7 +281,7 @@ pushinit(void)
if (istk->i_cnt <= 0)
LERROR("pushinit()");
- if (istk->i_type != NULL && issclt(istk->i_type->t_tspec))
+ if (istk->i_type != NULL && tspec_is_scalar(istk->i_type->t_tspec))
LERROR("pushinit()");
initstk = xcalloc(1, sizeof (istk_t));
@@ -431,7 +431,7 @@ nextinit(int brace)
DPRINTF(("%s(%d)\n", __func__, brace));
if (!brace) {
if (initstk->i_type == NULL &&
- !issclt(initstk->i_subt->t_tspec)) {
+ !tspec_is_scalar(initstk->i_subt->t_tspec)) {
/* {}-enclosed initializer required */
error(181);
}
@@ -442,13 +442,14 @@ nextinit(int brace)
if (!initerr)
testinit();
while (!initerr && (initstk->i_type == NULL ||
- !issclt(initstk->i_type->t_tspec))) {
+ !tspec_is_scalar(
+ initstk->i_type->t_tspec))) {
if (!initerr)
pushinit();
}
} else {
if (initstk->i_type != NULL &&
- issclt(initstk->i_type->t_tspec)) {
+ tspec_is_scalar(initstk->i_type->t_tspec)) {
/* invalid initializer */
error(176, tyname(buf, sizeof(buf), initstk->i_type));
initerr = 1;
@@ -477,7 +478,7 @@ initlbr(void)
if ((initsym->s_scl == AUTO || initsym->s_scl == REG) &&
initstk->i_nxt == NULL) {
- if (tflag && !issclt(initstk->i_subt->t_tspec))
+ if (tflag && !tspec_is_scalar(initstk->i_subt->t_tspec))
/* no automatic aggregate initialization in trad. C*/
warning(188);
}
@@ -572,7 +573,7 @@ mkinit(tnode_t *tn)
lt = ln->tn_type->t_tspec;
rt = tn->tn_type->t_tspec;
- if (!issclt(lt))
+ if (!tspec_is_scalar(lt))
LERROR("mkinit()");
if (!typeok(INIT, 0, ln, tn))
@@ -586,7 +587,7 @@ mkinit(tnode_t *tn)
expr(tn, 1, 0, 1);
trestor(tmem);
- if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) {
+ if (tspec_is_int(lt) && ln->tn_type->t_isfield && !tspec_is_int(rt)) {
/*
* Bit-fields can be initialized in trad. C only by integer
* constants.
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.89 src/usr.bin/xlint/lint1/tree.c:1.90
--- src/usr.bin/xlint/lint1/tree.c:1.89 Mon Dec 28 12:52:45 2020
+++ src/usr.bin/xlint/lint1/tree.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.89 2020/12/28 12:52:45 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.90 2020/12/28 18:49:02 rillig 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.89 2020/12/28 12:52:45 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.90 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <stdlib.h>
@@ -624,7 +624,7 @@ build(op_t op, tnode_t *ln, tnode_t *rn)
if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) {
if (mp->m_tctx) {
ntn = foldtst(ntn);
- } else if (isftyp(ntn->tn_type->t_tspec)) {
+ } else if (tspec_is_float(ntn->tn_type->t_tspec)) {
ntn = foldflt(ntn);
} else {
ntn = fold(ntn);
@@ -713,27 +713,30 @@ typeok(op_t op, int arg, tnode_t *ln, tn
}
if (mp->m_rqint) {
- /* integertypes required */
- if (!isityp(lt) || (mp->m_binary && !isityp(rt))) {
+ /* integer types required */
+ if (!tspec_is_int(lt) || (mp->m_binary && !tspec_is_int(rt))) {
incompat(op, lt, rt);
return (0);
}
} else if (mp->m_rqintcomp) {
- /* integertypes required */
- if ((!isityp(lt) && !isctyp(lt)) ||
- (mp->m_binary && (!isityp(rt) && !isctyp(rt)))) {
+ /* integer or complex types required */
+ if ((!tspec_is_int(lt) && !tspec_is_complex(lt)) ||
+ (mp->m_binary &&
+ (!tspec_is_int(rt) && !tspec_is_complex(rt)))) {
incompat(op, lt, rt);
return (0);
}
} else if (mp->m_rqsclt) {
/* scalar types required */
- if (!issclt(lt) || (mp->m_binary && !issclt(rt))) {
+ if (!tspec_is_scalar(lt) ||
+ (mp->m_binary && !tspec_is_scalar(rt))) {
incompat(op, lt, rt);
return (0);
}
} else if (mp->m_rqatyp) {
/* arithmetic types required */
- if (!isatyp(lt) || (mp->m_binary && !isatyp(rt))) {
+ if (!tspec_is_arith(lt) ||
+ (mp->m_binary && !tspec_is_arith(rt))) {
incompat(op, lt, rt);
return (0);
}
@@ -769,7 +772,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
/* Now we have an object we can create a pointer to */
break;
case ARROW:
- if (lt != PTR && !(tflag && isityp(lt))) {
+ if (lt != PTR && !(tflag && tspec_is_int(lt))) {
/* Without tflag we got already an error */
if (tflag)
/* unacceptabel operand of %s */
@@ -813,7 +816,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
/* %soperand of %s must be lvalue */
error(114, "", mp->m_name);
return (0);
- } else if (issclt(lt)) {
+ } else if (tspec_is_scalar(lt)) {
if (ltp->t_isfield) {
/* cannot take address of bit-field */
error(112);
@@ -840,14 +843,15 @@ typeok(op_t op, int arg, tnode_t *ln, tn
break;
case PLUS:
/* operands have scalar types (checked above) */
- if ((lt == PTR && !isityp(rt)) || (rt == PTR && !isityp(lt))) {
+ if ((lt == PTR && !tspec_is_int(rt)) ||
+ (rt == PTR && !tspec_is_int(lt))) {
incompat(op, lt, rt);
return (0);
}
break;
case MINUS:
/* operands have scalar types (checked above) */
- if (lt == PTR && (!isityp(rt) && rt != PTR)) {
+ if (lt == PTR && (!tspec_is_int(rt) && rt != PTR)) {
incompat(op, lt, rt);
return (0);
} else if (rt == PTR && lt != PTR) {
@@ -863,7 +867,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
break;
case SHR:
/* operands have integer types (checked above) */
- if (pflag && !isutyp(lt)) {
+ if (pflag && !tspec_is_uint(lt)) {
/*
* The left operand is signed. This means that
* the operation is (possibly) nonportable.
@@ -875,7 +879,8 @@ typeok(op_t op, int arg, tnode_t *ln, tn
} else if (ln->tn_val->v_quad < 0) {
warning(120);
}
- } else if (!tflag && !sflag && !isutyp(olt) && isutyp(ort)) {
+ } else if (!tflag && !sflag &&
+ !tspec_is_uint(olt) && tspec_is_uint(ort)) {
/*
* The left operand would become unsigned in
* traditional C.
@@ -885,7 +890,8 @@ typeok(op_t op, int arg, tnode_t *ln, tn
/* semantics of %s change in ANSI C; use ... */
warning(118, mp->m_name);
}
- } else if (!tflag && !sflag && !isutyp(olt) && !isutyp(ort) &&
+ } else if (!tflag && !sflag &&
+ !tspec_is_uint(olt) && !tspec_is_uint(ort) &&
psize(lt) < psize(rt)) {
/*
* In traditional C the left operand would be extended,
@@ -919,7 +925,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
}
shift:
if (rn->tn_op == CON) {
- if (!isutyp(rt) && rn->tn_val->v_quad < 0) {
+ if (!tspec_is_uint(rt) && rn->tn_val->v_quad < 0) {
/* negative shift */
warning(121);
} else if ((uint64_t)rn->tn_val->v_quad == (uint64_t)size(lt)) {
@@ -937,11 +943,13 @@ typeok(op_t op, int arg, tnode_t *ln, tn
* Accept some things which are allowed with EQ and NE,
* but not with ordered comparisons.
*/
- if (lt == PTR && ((rt == PTR && rst == VOID) || isityp(rt))) {
+ if (lt == PTR && ((rt == PTR && rst == VOID) ||
+ tspec_is_int(rt))) {
if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
break;
}
- if (rt == PTR && ((lt == PTR && lst == VOID) || isityp(lt))) {
+ if (rt == PTR && ((lt == PTR && lst == VOID) ||
+ tspec_is_int(lt))) {
if (ln->tn_op == CON && ln->tn_val->v_quad == 0)
break;
}
@@ -951,7 +959,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
case LE:
case GE:
if ((lt == PTR || rt == PTR) && lt != rt) {
- if (isityp(lt) || isityp(rt)) {
+ if (tspec_is_int(lt) || tspec_is_int(rt)) {
const char *lx = lt == PTR ?
"pointer" : "integer";
const char *rx = rt == PTR ?
@@ -969,7 +977,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
}
break;
case QUEST:
- if (!issclt(lt)) {
+ if (!tspec_is_scalar(lt)) {
/* first operand must have scalar type, op ? : */
error(170);
return (0);
@@ -980,8 +988,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
LERROR("typeok()");
break;
case COLON:
-
- if (isatyp(lt) && isatyp(rt))
+ if (tspec_is_arith(lt) && tspec_is_arith(rt))
break;
if (lt == STRUCT && rt == STRUCT && ltp->t_str == rtp->t_str)
@@ -990,16 +997,19 @@ typeok(op_t op, int arg, tnode_t *ln, tn
break;
/* combination of any pointer and 0, 0L or (void *)0 is ok */
- if (lt == PTR && ((rt == PTR && rst == VOID) || isityp(rt))) {
+ if (lt == PTR && ((rt == PTR && rst == VOID) ||
+ tspec_is_int(rt))) {
if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
break;
}
- if (rt == PTR && ((lt == PTR && lst == VOID) || isityp(lt))) {
+ if (rt == PTR && ((lt == PTR && lst == VOID) ||
+ tspec_is_int(lt))) {
if (ln->tn_op == CON && ln->tn_val->v_quad == 0)
break;
}
- if ((lt == PTR && isityp(rt)) || (isityp(lt) && rt == PTR)) {
+ if ((lt == PTR && tspec_is_int(rt)) ||
+ (tspec_is_int(lt) && rt == PTR)) {
const char *lx = lt == PTR ? "pointer" : "integer";
const char *rx = rt == PTR ? "pointer" : "integer";
tyname(lbuf, sizeof(lbuf), ltp);
@@ -1052,7 +1062,7 @@ typeok(op_t op, int arg, tnode_t *ln, tn
case ADDASS:
case SUBASS:
/* operands have scalar types (checked above) */
- if ((lt == PTR && !isityp(rt)) || rt == PTR) {
+ if ((lt == PTR && !tspec_is_int(rt)) || rt == PTR) {
incompat(op, lt, rt);
return (0);
}
@@ -1060,7 +1070,8 @@ typeok(op_t op, int arg, tnode_t *ln, tn
case SHLASS:
goto assign;
case SHRASS:
- if (pflag && !isutyp(lt) && !(tflag && isutyp(rt))) {
+ if (pflag && !tspec_is_uint(lt) &&
+ !(tflag && tspec_is_uint(rt))) {
/* bitwise operation on s.v. possibly nonportable */
warning(117);
}
@@ -1188,7 +1199,7 @@ asgntypok(op_t op, int arg, tnode_t *ln,
rst = (rstp = rtp->t_subt)->t_tspec;
mp = &modtab[op];
- if (isatyp(lt) && isatyp(rt))
+ if (tspec_is_arith(lt) && tspec_is_arith(rt))
return (1);
if ((lt == STRUCT || lt == UNION) && (rt == STRUCT || rt == UNION))
@@ -1196,7 +1207,7 @@ asgntypok(op_t op, int arg, tnode_t *ln,
return (ltp->t_str == rtp->t_str);
/* 0, 0L and (void *)0 may be assigned to any pointer */
- if (lt == PTR && ((rt == PTR && rst == VOID) || isityp(rt))) {
+ if (lt == PTR && ((rt == PTR && rst == VOID) || tspec_is_int(rt))) {
if (rn->tn_op == CON && rn->tn_val->v_quad == 0)
return (1);
}
@@ -1253,7 +1264,8 @@ asgntypok(op_t op, int arg, tnode_t *ln,
return (1);
}
- if ((lt == PTR && isityp(rt)) || (isityp(lt) && rt == PTR)) {
+ if ((lt == PTR && tspec_is_int(rt)) ||
+ (tspec_is_int(lt) && rt == PTR)) {
const char *lx = lt == PTR ? "pointer" : "integer";
const char *rx = rt == PTR ? "pointer" : "integer";
tyname(lbuf, sizeof(lbuf), ltp);
@@ -1408,7 +1420,8 @@ chkeop1(op_t op, int arg, tnode_t *ln, t
* consequently.
*/
if (!rn->tn_type->t_isenum && rn->tn_op == CON &&
- isityp(rn->tn_type->t_tspec) && rn->tn_val->v_quad == 0) {
+ tspec_is_int(rn->tn_type->t_tspec) &&
+ rn->tn_val->v_quad == 0) {
return;
}
/* initialisation of '%s' with '%s' */
@@ -1521,7 +1534,7 @@ promote(op_t op, int farg, tnode_t *tn)
t = tn->tn_type->t_tspec;
- if (!isatyp(t))
+ if (!tspec_is_arith(t))
return (tn);
if (!tflag) {
@@ -1537,7 +1550,7 @@ promote(op_t op, int farg, tnode_t *tn)
} else {
if (size(INT) != len)
LERROR("promote()");
- if (isutyp(t)) {
+ if (tspec_is_uint(t)) {
t = UINT;
} else {
t = INT;
@@ -1600,7 +1613,7 @@ balance(op_t op, tnode_t **lnp, tnode_t
lt = (*lnp)->tn_type->t_tspec;
rt = (*rnp)->tn_type->t_tspec;
- if (!isatyp(lt) || !isatyp(rt))
+ if (!tspec_is_arith(lt) || !tspec_is_arith(rt))
return;
if (!tflag) {
@@ -1634,8 +1647,8 @@ balance(op_t op, tnode_t **lnp, tnode_t
if (tl[i] == lt || tl[i] == rt)
break;
}
- if ((isutyp(lt) || isutyp(rt)) &&
- !isutyp(tl[i])) {
+ if ((tspec_is_uint(lt) || tspec_is_uint(rt)) &&
+ !tspec_is_uint(tl[i])) {
i--;
}
t = tl[i];
@@ -1643,13 +1656,13 @@ balance(op_t op, tnode_t **lnp, tnode_t
}
} else {
/* Keep unsigned in traditional C */
- u = isutyp(lt) || isutyp(rt);
+ u = tspec_is_uint(lt) || tspec_is_uint(rt);
for (i = 0; tl[i] != INT; i++) {
if (lt == tl[i] || rt == tl[i])
break;
}
t = tl[i];
- if (u && isityp(t) && !isutyp(t))
+ if (u && tspec_is_int(t) && !tspec_is_uint(t))
t = utyp(t);
}
@@ -1682,12 +1695,12 @@ convert(op_t op, int arg, type_t *tp, tn
if (!tflag && !sflag && op == FARG)
ptconv(arg, nt, ot, tp, tn);
- if (isityp(nt) && isityp(ot)) {
+ if (tspec_is_int(nt) && tspec_is_int(ot)) {
iiconv(op, arg, nt, ot, tp, tn);
- } else if (nt == PTR && ((ot == PTR && ost == VOID) || isityp(ot)) &&
- tn->tn_op == CON && tn->tn_val->v_quad == 0) {
+ } else if (nt == PTR && ((ot == PTR && ost == VOID) ||
+ tspec_is_int(ot)) && tn->tn_op == CON && tn->tn_val->v_quad == 0) {
/* 0, 0L and (void *)0 may be assigned to any pointer. */
- } else if (isityp(nt) && ot == PTR) {
+ } else if (tspec_is_int(nt) && ot == PTR) {
piconv(op, nt, tp, tn);
} else if (nt == PTR && ot == PTR) {
ppconv(op, tn, tp);
@@ -1723,7 +1736,7 @@ ptconv(int arg, tspec_t nt, tspec_t ot,
tnode_t *ptn;
char buf[64];
- if (!isatyp(nt) || !isatyp(ot))
+ if (!tspec_is_arith(nt) || !tspec_is_arith(ot))
return;
/*
@@ -1742,9 +1755,10 @@ ptconv(int arg, tspec_t nt, tspec_t ot,
if (nt == ot || (nt == ENUM && ot == INT))
return;
- if (isftyp(nt) != isftyp(ot) || psize(nt) != psize(ot)) {
+ if (tspec_is_float(nt) != tspec_is_float(ot) ||
+ psize(nt) != psize(ot)) {
/* representation and/or width change */
- if (!isityp(ot) || psize(ot) > psize(INT)) {
+ if (!tspec_is_int(ot) || psize(ot) > psize(INT)) {
/* conversion to '%s' due to prototype, arg #%d */
warning(259, tyname(buf, sizeof(buf), tp), arg);
}
@@ -1756,7 +1770,8 @@ ptconv(int arg, tspec_t nt, tspec_t ot,
* if they differ only in sign and the argument is a constant
* and the msb of the argument is not set, print no warning
*/
- if (ptn->tn_op == CON && isityp(nt) && styp(nt) == styp(ot) &&
+ if (ptn->tn_op == CON && tspec_is_int(nt) &&
+ styp(nt) == styp(ot) &&
msb(ptn->tn_val->v_quad, ot, -1) == 0) {
/* ok */
} else {
@@ -1781,7 +1796,8 @@ iiconv(op_t op, int arg, tspec_t nt, tsp
if (op == CVT)
return;
- if (Pflag && psize(nt) > psize(ot) && isutyp(nt) != isutyp(ot)) {
+ if (Pflag && psize(nt) > psize(ot) &&
+ tspec_is_uint(nt) != tspec_is_uint(ot)) {
/* conversion to %s may sign-extend incorrectly (, arg #%d) */
if (aflag && pflag) {
if (op == FARG) {
@@ -1993,18 +2009,18 @@ cvtcon(op_t op, int arg, type_t *tp, val
} else if (nt == LDOUBLE) {
nv->v_ldbl = v->v_ldbl;
} else {
- nv->v_quad = (nt == PTR || isutyp(nt)) ?
+ nv->v_quad = (nt == PTR || tspec_is_uint(nt)) ?
(int64_t)v->v_ldbl : (int64_t)v->v_ldbl;
}
} else {
if (nt == FLOAT) {
- nv->v_ldbl = (ot == PTR || isutyp(ot)) ?
+ nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ?
(float)(uint64_t)v->v_quad : (float)v->v_quad;
} else if (nt == DOUBLE) {
- nv->v_ldbl = (ot == PTR || isutyp(ot)) ?
+ nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ?
(double)(uint64_t)v->v_quad : (double)v->v_quad;
} else if (nt == LDOUBLE) {
- nv->v_ldbl = (ot == PTR || isutyp(ot)) ?
+ nv->v_ldbl = (ot == PTR || tspec_is_uint(ot)) ?
(ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad;
} else {
rchk = 1; /* Check for lost precision. */
@@ -2012,11 +2028,11 @@ cvtcon(op_t op, int arg, type_t *tp, val
}
}
- if (v->v_ansiu && isftyp(nt)) {
+ if (v->v_ansiu && tspec_is_float(nt)) {
/* ANSI C treats constant as unsigned */
warning(157);
v->v_ansiu = 0;
- } else if (v->v_ansiu && (isityp(nt) && !isutyp(nt) &&
+ } else if (v->v_ansiu && (tspec_is_int(nt) && !tspec_is_uint(nt) &&
psize(nt) > psize(ot))) {
/* ANSI C treats constant as unsigned */
warning(157);
@@ -2078,8 +2094,8 @@ cvtcon(op_t op, int arg, type_t *tp, val
/* const. truncated by conv., op %s */
warning(306, modtab[op].m_name);
}
- } else if ((nt != PTR && isutyp(nt)) &&
- (ot != PTR && !isutyp(ot)) && v->v_quad < 0) {
+ } else if ((nt != PTR && tspec_is_uint(nt)) &&
+ (ot != PTR && !tspec_is_uint(ot)) && v->v_quad < 0) {
if (op == ASSIGN) {
/* assignment of negative constant to ... */
warning(164);
@@ -2097,7 +2113,8 @@ cvtcon(op_t op, int arg, type_t *tp, val
}
} else if (nv->v_quad != v->v_quad && nsz <= osz &&
(v->v_quad & xmask) != 0 &&
- (isutyp(ot) || (v->v_quad & xmsk1) != xmsk1)) {
+ (tspec_is_uint(ot) ||
+ (v->v_quad & xmsk1) != xmsk1)) {
/*
* Loss of significant bit(s). All truncated bits
* of unsigned types or all truncated bits plus the
@@ -2323,7 +2340,7 @@ bldstr(op_t op, tnode_t *ln, tnode_t *rn
if (op == POINT) {
ln = bldamper(ln, 1);
} else if (ln->tn_type->t_tspec != PTR) {
- if (!tflag || !isityp(ln->tn_type->t_tspec))
+ if (!tflag || !tspec_is_int(ln->tn_type->t_tspec))
LERROR("bldstr()");
ln = convert(NOOP, 0, tincref(gettyp(VOID), PTR), ln);
}
@@ -2441,7 +2458,8 @@ bldplmi(op_t op, tnode_t *ln, tnode_t *r
type_t *tp;
/* If pointer and integer, then pointer to the lhs. */
- if (rn->tn_type->t_tspec == PTR && isityp(ln->tn_type->t_tspec)) {
+ if (rn->tn_type->t_tspec == PTR &&
+ tspec_is_int(ln->tn_type->t_tspec)) {
ntn = ln;
ln = rn;
rn = ntn;
@@ -2449,7 +2467,7 @@ bldplmi(op_t op, tnode_t *ln, tnode_t *r
if (ln->tn_type->t_tspec == PTR && rn->tn_type->t_tspec != PTR) {
- if (!isityp(rn->tn_type->t_tspec))
+ if (!tspec_is_int(rn->tn_type->t_tspec))
LERROR("bldplmi()");
ctn = plength(ln->tn_type);
@@ -2521,7 +2539,7 @@ bldcol(tnode_t *ln, tnode_t *rn)
* Arithmetic types are balanced, all other type combinations
* still need to be handled.
*/
- if (isatyp(lt) && isatyp(rt)) {
+ if (tspec_is_arith(lt) && tspec_is_arith(rt)) {
rtp = ln->tn_type;
} else if (lt == VOID || rt == VOID) {
rtp = gettyp(VOID);
@@ -2537,13 +2555,13 @@ bldcol(tnode_t *ln, tnode_t *rn)
return (NULL);
}
rtp = ln->tn_type;
- } else if (lt == PTR && isityp(rt)) {
+ } else if (lt == PTR && tspec_is_int(rt)) {
if (rt != pdt) {
rn = convert(NOOP, 0, gettyp(pdt), rn);
rt = pdt;
}
rtp = ln->tn_type;
- } else if (rt == PTR && isityp(lt)) {
+ } else if (rt == PTR && tspec_is_int(lt)) {
if (lt != pdt) {
ln = convert(NOOP, 0, gettyp(pdt), ln);
lt = pdt;
@@ -2593,7 +2611,7 @@ bldasgn(op_t op, tnode_t *ln, tnode_t *r
rt = rn->tn_type->t_tspec;
if ((op == ADDASS || op == SUBASS) && lt == PTR) {
- if (!isityp(rt))
+ if (!tspec_is_int(rt))
LERROR("bldasgn()");
ctn = plength(ln->tn_type);
if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
@@ -2732,7 +2750,7 @@ fold(tnode_t *tn)
v = xcalloc(1, sizeof (val_t));
v->v_tspec = t = tn->tn_type->t_tspec;
- utyp = t == PTR || isutyp(t);
+ utyp = t == PTR || tspec_is_uint(t);
ul = sl = tn->tn_left->tn_val->v_quad;
if (modtab[tn->tn_op].m_binary)
ur = sr = tn->tn_right->tn_val->v_quad;
@@ -2874,14 +2892,14 @@ foldtst(tnode_t *tn)
if (tn->tn_type->t_tspec != INT)
LERROR("foldtst()");
- if (isftyp(tn->tn_left->tn_type->t_tspec)) {
+ if (tspec_is_float(tn->tn_left->tn_type->t_tspec)) {
l = tn->tn_left->tn_val->v_ldbl != 0.0;
} else {
l = tn->tn_left->tn_val->v_quad != 0;
}
if (modtab[tn->tn_op].m_binary) {
- if (isftyp(tn->tn_right->tn_type->t_tspec)) {
+ if (tspec_is_float(tn->tn_right->tn_type->t_tspec)) {
r = tn->tn_right->tn_val->v_ldbl != 0.0;
} else {
r = tn->tn_right->tn_val->v_quad != 0;
@@ -2922,7 +2940,7 @@ foldflt(tnode_t *tn)
v = xcalloc(1, sizeof (val_t));
v->v_tspec = t = tn->tn_type->t_tspec;
- if (!isftyp(t))
+ if (!tspec_is_float(t))
LERROR("foldflt()");
if (t != tn->tn_left->tn_type->t_tspec)
@@ -3211,11 +3229,11 @@ cast(tnode_t *tn, type_t *tp)
/* improper cast of void expression */
error(148);
return (NULL);
- } else if (isityp(nt) && issclt(ot)) {
+ } else if (tspec_is_int(nt) && tspec_is_scalar(ot)) {
/* ok */
- } else if (isftyp(nt) && isatyp(ot)) {
+ } else if (tspec_is_float(nt) && tspec_is_arith(ot)) {
/* ok */
- } else if (nt == PTR && isityp(ot)) {
+ } else if (nt == PTR && tspec_is_int(ot)) {
/* ok */
} else if (nt == PTR && ot == PTR) {
if (!tp->t_subt->t_const && tn->tn_type->t_subt->t_const) {
@@ -3346,7 +3364,8 @@ chkfarg(type_t *ftp, tnode_t *args)
/* argument cannot have unknown size, arg #%d */
error(152, n);
return (NULL);
- } else if (isityp(at) && arg->tn_left->tn_type->t_isenum &&
+ } else if (tspec_is_int(at) &&
+ arg->tn_left->tn_type->t_isenum &&
incompl(arg->tn_left->tn_type)) {
/* argument cannot have unknown size, arg #%d */
warning(152, n);
@@ -3425,7 +3444,7 @@ constant(tnode_t *tn, int required)
if (tn->tn_op == CON) {
if (tn->tn_type->t_tspec != tn->tn_val->v_tspec)
LERROR("constant()");
- if (isityp(tn->tn_val->v_tspec)) {
+ if (tspec_is_int(tn->tn_val->v_tspec)) {
v->v_ansiu = tn->tn_val->v_ansiu;
v->v_quad = tn->tn_val->v_quad;
return (v);
@@ -3441,7 +3460,7 @@ constant(tnode_t *tn, int required)
else
c99ism(318);
- if (!isityp(v->v_tspec))
+ if (!tspec_is_int(v->v_tspec))
v->v_tspec = INT;
return (v);
@@ -3558,9 +3577,9 @@ displexpr(tnode_t *tn, int offs)
if (tn->tn_op == NAME) {
(void)printf("%s: %s ",
tn->tn_sym->s_name, scltoa(tn->tn_sym->s_scl));
- } else if (tn->tn_op == CON && isftyp(tn->tn_type->t_tspec)) {
+ } else if (tn->tn_op == CON && tspec_is_float(tn->tn_type->t_tspec)) {
(void)printf("%#g ", (double)tn->tn_val->v_ldbl);
- } else if (tn->tn_op == CON && isityp(tn->tn_type->t_tspec)) {
+ } else if (tn->tn_op == CON && tspec_is_int(tn->tn_type->t_tspec)) {
uq = tn->tn_val->v_quad;
(void)printf("0x %08lx %08lx ", (long)(uq >> 32) & 0xffffffffl,
(long)uq & 0xffffffffl);
@@ -3817,7 +3836,7 @@ chkaidx(tnode_t *tn, int amper)
elsz /= CHAR_BIT;
/* Change the unit of the index from bytes to element size. */
- if (isutyp(rn->tn_type->t_tspec)) {
+ if (tspec_is_uint(rn->tn_type->t_tspec)) {
con = (uint64_t)rn->tn_val->v_quad / elsz;
} else {
con = rn->tn_val->v_quad / elsz;
@@ -3825,7 +3844,7 @@ chkaidx(tnode_t *tn, int amper)
dim = ln->tn_left->tn_type->t_dim + (amper ? 1 : 0);
- if (!isutyp(rn->tn_type->t_tspec) && con < 0) {
+ if (!tspec_is_uint(rn->tn_type->t_tspec) && con < 0) {
/* array subscript cannot be negative: %ld */
warning(167, (long)con);
} else if (dim > 0 && (uint64_t)con >= (uint64_t)dim) {
@@ -3851,7 +3870,7 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *r
if (ln->tn_op != CON && rn->tn_op != CON)
return;
- if (!isityp(lt) || !isityp(rt))
+ if (!tspec_is_int(lt) || !tspec_is_int(rt))
return;
if ((hflag || pflag) && lt == CHAR && rn->tn_op == CON &&
@@ -3868,7 +3887,7 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *r
warning(230, mp->m_name);
return;
}
- if (isutyp(lt) && !isutyp(rt) &&
+ if (tspec_is_uint(lt) && !tspec_is_uint(rt) &&
rn->tn_op == CON && rn->tn_val->v_quad <= 0) {
if (rn->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
@@ -3881,7 +3900,7 @@ chkcomp(op_t op, tnode_t *ln, tnode_t *r
}
return;
}
- if (isutyp(rt) && !isutyp(lt) &&
+ if (tspec_is_uint(rt) && !tspec_is_uint(lt) &&
ln->tn_op == CON && ln->tn_val->v_quad <= 0) {
if (ln->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
@@ -3956,8 +3975,10 @@ conaddr(tnode_t *tn, sym_t **symp, ptrdi
case CVT:
t = tn->tn_type->t_tspec;
ot = tn->tn_left->tn_type->t_tspec;
- if ((!isityp(t) && t != PTR) || (!isityp(ot) && ot != PTR))
+ if ((!tspec_is_int(t) && t != PTR) ||
+ (!tspec_is_int(ot) && ot != PTR)) {
return (-1);
+ }
#ifdef notdef
/*
* consider:
Index: src/usr.bin/xlint/lint2/chk.c
diff -u src/usr.bin/xlint/lint2/chk.c:1.23 src/usr.bin/xlint/lint2/chk.c:1.24
--- src/usr.bin/xlint/lint2/chk.c:1.23 Tue Dec 26 17:02:19 2017
+++ src/usr.bin/xlint/lint2/chk.c Mon Dec 28 18:49:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: chk.c,v 1.23 2017/12/26 17:02:19 christos Exp $ */
+/* $NetBSD: chk.c,v 1.24 2020/12/28 18:49:02 rillig 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.23 2017/12/26 17:02:19 christos Exp $");
+__RCSID("$NetBSD: chk.c,v 1.24 2020/12/28 18:49:02 rillig Exp $");
#endif
#include <ctype.h>
@@ -495,7 +495,8 @@ chkau(hte_t *hte, int n, sym_t *def, sym
*/
t1 = arg1->t_tspec;
t2 = arg2->t_tspec;
- if (isityp(t1) && isityp(t2) && !arg1->t_isenum && !arg2->t_isenum) {
+ if (tspec_is_int(t1) && tspec_is_int(t2) &&
+ !arg1->t_isenum && !arg2->t_isenum) {
if (promote) {
/*
* XXX Here is a problem: Althrough it is possible to
@@ -573,7 +574,7 @@ chkau(hte_t *hte, int n, sym_t *def, sym
}
}
- } else if (t1 == PTR && isityp(t2)) {
+ } else if (t1 == PTR && tspec_is_int(t2)) {
for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
if (ai->a_num == n)
break;