Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint lint: rename members and access macros of the ...
details: https://anonhg.NetBSD.org/src/rev/b1f6661a8f3e
branches: trunk
changeset: 981129:b1f6661a8f3e
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Feb 28 18:51:51 2021 +0000
description:
lint: rename members and access macros of the basic types
Having the measurement unit in the variable name prevents accidental
confusion between bits and bytes, especially since usually the word
'size' means the size in bytes, while 'width' means the size in bits, at
least for integer types.
No functional change.
diffstat:
usr.bin/xlint/common/inittyp.c | 12 ++++---
usr.bin/xlint/common/lint.h | 12 +++---
usr.bin/xlint/lint1/decl.c | 21 +++++++------
usr.bin/xlint/lint1/lex.c | 8 ++--
usr.bin/xlint/lint1/tree.c | 66 ++++++++++++++++++++++-------------------
5 files changed, 63 insertions(+), 56 deletions(-)
diffs (truncated from 407 to 300 lines):
diff -r 0183889633bd -r b1f6661a8f3e usr.bin/xlint/common/inittyp.c
--- a/usr.bin/xlint/common/inittyp.c Sun Feb 28 18:17:08 2021 +0000
+++ b/usr.bin/xlint/common/inittyp.c Sun Feb 28 18:51:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inittyp.c,v 1.19 2021/02/20 19:10:37 rillig Exp $ */
+/* $NetBSD: inittyp.c,v 1.20 2021/02/28 18:51:51 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: inittyp.c,v 1.19 2021/02/20 19:10:37 rillig Exp $");
+__RCSID("$NetBSD: inittyp.c,v 1.20 2021/02/28 18:51:51 rillig Exp $");
#endif
#include <limits.h>
@@ -125,8 +125,9 @@
DCOMPLEX, DCOMPLEX,
0, 0, 1, 1, 1, 1, "double _Complex" } },
/*
- * XXX: with -p, LCOMPLEX.tt_psz != 2 * LDOUBLE.tt_psz.
- * This may or may not have been intentional.
+ * XXX: with -p, LCOMPLEX.tt_portable_size_in_bits !=
+ * 2 * LDOUBLE.tt_portable_size_in_bits.
+ * This may or may not have been intentional.
*/
{ LCOMPLEX, { LDOUBLE_SIZE * 2, 64 * 2,
LCOMPLEX, LCOMPLEX,
@@ -158,7 +159,8 @@
ttab[ittab[i].it_tspec] = ittab[i].it_ttab;
if (!pflag) {
for (i = 0; i < NTSPEC; i++)
- ttab[i].tt_psz = ttab[i].tt_sz;
+ ttab[i].tt_portable_size_in_bits =
+ ttab[i].tt_size_in_bits;
}
if (Tflag) {
ttab[BOOL].tt_is_integer = false;
diff -r 0183889633bd -r b1f6661a8f3e usr.bin/xlint/common/lint.h
--- a/usr.bin/xlint/common/lint.h Sun Feb 28 18:17:08 2021 +0000
+++ b/usr.bin/xlint/common/lint.h Sun Feb 28 18:51:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.h,v 1.25 2021/01/16 02:40:02 rillig Exp $ */
+/* $NetBSD: lint.h,v 1.26 2021/02/28 18:51:51 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -92,9 +92,9 @@
* size of types, name and classification
*/
typedef struct {
- size_t tt_sz; /* size in bits */
- size_t tt_psz; /* size, different from tt_sz
- if pflag is set */
+ size_t tt_size_in_bits;
+ size_t tt_portable_size_in_bits; /* different from tt_size_in_bits
+ * if pflag is set */
tspec_t tt_signed_counterpart;
tspec_t tt_unsigned_counterpart;
bool tt_is_integer : 1; /* integer type */
@@ -106,8 +106,8 @@
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 size_in_bits(t) (ttab[t].tt_size_in_bits)
+#define portable_size_in_bits(t) (ttab[t].tt_portable_size_in_bits)
#define signed_type(t) (ttab[t].tt_signed_counterpart)
#define unsigned_type(t) (ttab[t].tt_unsigned_counterpart)
#define is_integer(t) (ttab[t].tt_is_integer)
diff -r 0183889633bd -r b1f6661a8f3e usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c Sun Feb 28 18:17:08 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c Sun Feb 28 18:51:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.142 2021/02/28 03:14:44 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.143 2021/02/28 18:51:51 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.142 2021/02/28 03:14:44 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.143 2021/02/28 18:51:51 rillig Exp $");
#endif
#include <sys/param.h>
@@ -917,7 +917,7 @@
}
/* FALLTHROUGH */
default:
- elsz = size(tp->t_tspec);
+ elsz = size_in_bits(tp->t_tspec);
if (elsz <= 0)
LERROR("length(%d)", elsz);
break;
@@ -944,7 +944,7 @@
error(14);
a = WORST_ALIGN(1) * CHAR_SIZE;
} else {
- if ((a = size(t)) == 0) {
+ if ((a = size_in_bits(t)) == 0) {
a = CHAR_SIZE;
} else if (a > WORST_ALIGN(1) * CHAR_SIZE) {
a = WORST_ALIGN(1) * CHAR_SIZE;
@@ -1115,19 +1115,19 @@
warning(35, type_name(tp));
int sz = tp->t_flen;
dsym->s_type = tp = duptyp(gettyp(t = INT));
- if ((tp->t_flen = sz) > size(t))
- tp->t_flen = size(t);
+ if ((tp->t_flen = sz) > size_in_bits(t))
+ tp->t_flen = size_in_bits(t);
}
}
- if (tp->t_flen < 0 || tp->t_flen > (ssize_t)size(t)) {
+ if (tp->t_flen < 0 || tp->t_flen > (ssize_t)size_in_bits(t)) {
/* illegal bit-field size: %d */
error(36, tp->t_flen);
- tp->t_flen = size(t);
+ tp->t_flen = size_in_bits(t);
} else if (tp->t_flen == 0 && dsym->s_name != unnamed) {
/* zero size bit-field */
error(37);
- tp->t_flen = size(t);
+ tp->t_flen = size_in_bits(t);
}
if (dsym->s_scl == MOU) {
/* illegal use of bit-field */
@@ -1194,7 +1194,8 @@
}
if (dsym->s_bitfield) {
align(alignment_in_bits(tp), tp->t_flen);
- dsym->s_value.v_quad = (dcs->d_offset / size(t)) * size(t);
+ dsym->s_value.v_quad =
+ (dcs->d_offset / size_in_bits(t)) * size_in_bits(t);
tp->t_foffs = dcs->d_offset - (int)dsym->s_value.v_quad;
dcs->d_offset += tp->t_flen;
} else {
diff -r 0183889633bd -r b1f6661a8f3e usr.bin/xlint/lint1/lex.c
--- a/usr.bin/xlint/lint1/lex.c Sun Feb 28 18:17:08 2021 +0000
+++ b/usr.bin/xlint/lint1/lex.c Sun Feb 28 18:51:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lex.c,v 1.9 2021/02/22 15:09:50 rillig Exp $ */
+/* $NetBSD: lex.c,v 1.10 2021/02/28 18:51:51 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: lex.c,v 1.9 2021/02/22 15:09:50 rillig Exp $");
+__RCSID("$NetBSD: lex.c,v 1.10 2021/02/28 18:51:51 rillig Exp $");
#endif
#include <ctype.h>
@@ -681,7 +681,7 @@
{
if (len <= 0)
- len = size(t);
+ len = size_in_bits(t);
return (q & qbmasks[len - 1]) != 0 ? 1 : 0;
}
@@ -693,7 +693,7 @@
{
if (len <= 0)
- len = size(t);
+ len = size_in_bits(t);
if (t == PTR || is_uinteger(t) || !sign(q, t, len)) {
q &= qlmasks[len];
diff -r 0183889633bd -r b1f6661a8f3e usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Feb 28 18:17:08 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Feb 28 18:51:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.227 2021/02/28 03:59:28 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.228 2021/02/28 18:51:51 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.227 2021/02/28 03:59:28 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.228 2021/02/28 18:51:51 rillig Exp $");
#endif
#include <float.h>
@@ -903,7 +903,7 @@
warning(118, mp->m_name);
}
} else if (!tflag && !sflag && !is_uinteger(olt) && !is_uinteger(ort) &&
- psize(lt) < psize(rt)) {
+ portable_size_in_bits(lt) < portable_size_in_bits(rt)) {
/*
* In traditional C the left operand would be extended,
* possibly with 1, and then shifted.
@@ -927,7 +927,7 @@
* width of the right operand. For SHL this may result in
* different results.
*/
- if (psize(lt) < psize(rt)) {
+ if (portable_size_in_bits(lt) < portable_size_in_bits(rt)) {
/*
* XXX If both operands are constant, make sure
* that there is really a difference between
@@ -946,10 +946,12 @@
if (!is_uinteger(rt) && rn->tn_val->v_quad < 0) {
/* negative shift */
warning(121);
- } else if ((uint64_t)rn->tn_val->v_quad == (uint64_t)size(lt)) {
+ } else if ((uint64_t)rn->tn_val->v_quad ==
+ (uint64_t)size_in_bits(lt)) {
/* shift equal to size of object */
warning(267);
- } else if ((uint64_t)rn->tn_val->v_quad > (uint64_t)size(lt)) {
+ } else if ((uint64_t)rn->tn_val->v_quad >
+ (uint64_t)size_in_bits(lt)) {
/* shift greater than size of object */
warning(122);
}
@@ -1883,10 +1885,10 @@
*/
if (tn->tn_type->t_bitfield) {
len = tn->tn_type->t_flen;
- if (size(INT) > len) {
+ if (size_in_bits(INT) > len) {
t = INT;
} else {
- lint_assert(len == size(INT));
+ lint_assert(len == size_in_bits(INT));
if (is_uinteger(t)) {
t = UINT;
} else {
@@ -1894,11 +1896,11 @@
}
}
} else if (t == CHAR || t == UCHAR || t == SCHAR) {
- t = (size(CHAR) < size(INT) || t != UCHAR) ?
- INT : UINT;
+ t = (size_in_bits(CHAR) < size_in_bits(INT)
+ || t != UCHAR) ? INT : UINT;
} else if (t == SHORT || t == USHORT) {
- t = (size(SHORT) < size(INT) || t == SHORT) ?
- INT : UINT;
+ t = (size_in_bits(SHORT) < size_in_bits(INT)
+ || t == SHORT) ? INT : UINT;
} else if (t == ENUM) {
t = INT;
} else if (farg && t == FLOAT) {
@@ -1978,9 +1980,9 @@
* If type A has more bits than type B it should
* be able to hold all possible values of type B.
*/
- if (size(lt) > size(rt)) {
+ if (size_in_bits(lt) > size_in_bits(rt)) {
t = lt;
- } else if (size(lt) < size(rt)) {
+ } else if (size_in_bits(lt) < size_in_bits(rt)) {
t = rt;
} else {
for (i = 3; tl[i] != INT; i++) {
@@ -2097,9 +2099,10 @@
return;
if (is_floating(nt) != is_floating(ot) ||
- psize(nt) != psize(ot)) {
+ portable_size_in_bits(nt) != portable_size_in_bits(ot)) {
/* representation and/or width change */
- if (!is_integer(ot) || psize(ot) > psize(INT)) {
+ if (!is_integer(ot) ||
+ portable_size_in_bits(ot) > portable_size_in_bits(INT)) {
/* argument #%d is converted from '%s' to '%s' ... */
warning(259,
arg, type_name(tn->tn_type), type_name(tp));
@@ -2140,7 +2143,7 @@
if (op == CVT)
return;
- if (Pflag && psize(nt) > psize(ot) &&
+ if (Pflag && portable_size_in_bits(nt) > portable_size_in_bits(ot) &&
is_uinteger(nt) != is_uinteger(ot)) {
if (aflag > 0 && pflag) {
if (op == FARG) {
@@ -2153,7 +2156,7 @@
}
}
- if (Pflag && psize(nt) > psize(ot)) {
+ if (Pflag && portable_size_in_bits(nt) > portable_size_in_bits(ot)) {
Home |
Main Index |
Thread Index |
Old Index