Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: replace LERROR with lint_assert



details:   https://anonhg.NetBSD.org/src/rev/a0b1f4956510
branches:  trunk
changeset: 958279:a0b1f4956510
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Dec 30 12:22:51 2020 +0000

description:
lint: replace LERROR with lint_assert

This removes the redundancy of mentioning the function name in the error
message.  This redundancy had been correct in all but 2 cases:
build_real_imag and tsize.

diffstat:

 usr.bin/xlint/lint1/tree.c |  148 +++++++++++++++++---------------------------
 1 files changed, 58 insertions(+), 90 deletions(-)

diffs (truncated from 398 to 300 lines):

diff -r 23ae5836c2cd -r a0b1f4956510 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Wed Dec 30 11:56:10 2020 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Wed Dec 30 12:22:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.106 2020/12/30 11:56:10 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.107 2020/12/30 12:22: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.106 2020/12/30 11:56:10 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.107 2020/12/30 12:22:51 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -595,8 +595,7 @@
                break;
        default:
                rtp = mp->m_logical ? gettyp(INT) : ln->tn_type;
-               if (!mp->m_binary && rn != NULL)
-                       LERROR("build()");
+               lint_assert(mp->m_binary || rn == NULL);
                ntn = new_tnode(op, rtp, ln, rn);
                break;
        }
@@ -703,14 +702,12 @@
 
        mp = &modtab[op];
 
-       if ((ltp = ln->tn_type) == NULL)
-               LERROR("typeok()");
+       lint_assert((ltp = ln->tn_type) != NULL);
 
        if ((lt = ltp->t_tspec) == PTR)
                lst = (lstp = ltp->t_subt)->t_tspec;
        if (mp->m_binary) {
-               if ((rtp = rn->tn_type) == NULL)
-                       LERROR("typeok()");
+               lint_assert((rtp = rn->tn_type) != NULL);
                if ((rt = rtp->t_tspec) == PTR)
                        rst = (rstp = rtp->t_subt)->t_tspec;
        }
@@ -984,8 +981,7 @@
                }
                while (rn->tn_op == CVT)
                        rn = rn->tn_left;
-               if (rn->tn_op != COLON)
-                       LERROR("typeok()");
+               lint_assert(rn->tn_op == COLON);
                break;
        case COLON:
                if (tspec_is_arith(lt) && tspec_is_arith(rt))
@@ -1505,13 +1501,10 @@
 #endif
        case STAR:
        case FSEL:
-               if (ln->tn_type->t_tspec == PTR) {
-                       t = ln->tn_type->t_subt->t_tspec;
-                       if (t != FUNC && t != VOID)
-                               ntn->tn_lvalue = 1;
-               } else {
-                       LERROR("new_tnode()");
-               }
+               lint_assert(ln->tn_type->t_tspec == PTR);
+               t = ln->tn_type->t_subt->t_tspec;
+               if (t != FUNC && t != VOID)
+                       ntn->tn_lvalue = 1;
                break;
        default:
                break;
@@ -1550,8 +1543,7 @@
                        if (size(INT) > len) {
                                t = INT;
                        } else {
-                               if (size(INT) != len)
-                                       LERROR("promote()");
+                               lint_assert(len == size(INT));
                                if (tspec_is_uint(t)) {
                                        t = UINT;
                                } else {
@@ -1987,11 +1979,10 @@
                case LCOMPLEX:
                        max = LDBL_MAX;         min = -LDBL_MAX;        break;
                default:
-                       LERROR("cvtcon()");
+                       lint_assert(0);
                }
                if (v->v_ldbl > max || v->v_ldbl < min) {
-                       if (nt == LDOUBLE)
-                               LERROR("cvtcon()");
+                       lint_assert(nt != LDOUBLE);
                        if (op == FARG) {
                                /* conv. of %s to %s is out of rng., arg #%d */
                                warning(295,
@@ -2245,8 +2236,8 @@
 {
        tspec_t lt, rt;
 
-       if (ltp->t_tspec != PTR || rtp->t_tspec != PTR)
-               LERROR("warn_incompatible_pointers()");
+       lint_assert(ltp->t_tspec == PTR);
+       lint_assert(rtp->t_tspec == PTR);
 
        lt = ltp->t_subt->t_tspec;
        rt = rtp->t_subt->t_tspec;
@@ -2278,10 +2269,9 @@
 merge_qualifiers(type_t **tpp, type_t *tp1, type_t *tp2)
 {
 
-       if ((*tpp)->t_tspec != PTR ||
-           tp1->t_tspec != PTR || tp2->t_tspec != PTR) {
-               LERROR("merge_qualifiers()");
-       }
+       lint_assert((*tpp)->t_tspec == PTR);
+       lint_assert(tp1->t_tspec == PTR);
+       lint_assert(tp2->t_tspec == PTR);
 
        if ((*tpp)->t_subt->t_const ==
            (tp1->t_subt->t_const | tp2->t_subt->t_const) &&
@@ -2308,8 +2298,8 @@
        sym_t   *m;
        tspec_t t;
 
-       if ((t = tp->t_tspec) != STRUCT && t != UNION)
-               LERROR("has_constant_member()");
+       lint_assert((t = tp->t_tspec) == STRUCT || t == UNION);
+
        for (m = tp->t_str->memb; m != NULL; m = m->s_next) {
                tp = m->s_type;
                if (tp->t_const)
@@ -2331,12 +2321,9 @@
        tnode_t *ntn, *ctn;
        int     nolval;
 
-       if (rn->tn_op != NAME)
-               LERROR("build_struct_access()");
-       if (rn->tn_sym->s_value.v_tspec != INT)
-               LERROR("build_struct_access()");
-       if (rn->tn_sym->s_scl != MOS && rn->tn_sym->s_scl != MOU)
-               LERROR("build_struct_access()");
+       lint_assert(rn->tn_op == NAME);
+       lint_assert(rn->tn_sym->s_value.v_tspec == INT);
+       lint_assert(rn->tn_sym->s_scl == MOS || rn->tn_sym->s_scl == MOU);
 
        /*
         * Remember if the left operand is an lvalue (structure members
@@ -2347,8 +2334,8 @@
        if (op == POINT) {
                ln = build_ampersand(ln, 1);
        } else if (ln->tn_type->t_tspec != PTR) {
-               if (!tflag || !tspec_is_int(ln->tn_type->t_tspec))
-                       LERROR("build_struct_access()");
+               lint_assert(tflag);
+               lint_assert(tspec_is_int(ln->tn_type->t_tspec));
                ln = convert(NOOP, 0, tincref(gettyp(VOID), PTR), ln);
        }
 
@@ -2382,8 +2369,7 @@
 {
        tnode_t *cn, *ntn;
 
-       if (ln == NULL)
-               LERROR("build_prepost_incdec()");
+       lint_assert(ln != NULL);
 
        if (ln->tn_type->t_tspec == PTR) {
                cn = plength(ln->tn_type);
@@ -2404,8 +2390,7 @@
        tnode_t *cn, *ntn;
        char buf[64];
 
-       if (ln == NULL)
-               LERROR("build_prepost_incdec()");
+       lint_assert(ln != NULL);
 
        switch (ln->tn_type->t_tspec) {
        case LCOMPLEX:
@@ -2474,8 +2459,7 @@
 
        if (ln->tn_type->t_tspec == PTR && rn->tn_type->t_tspec != PTR) {
 
-               if (!tspec_is_int(rn->tn_type->t_tspec))
-                       LERROR("build_plus_minus()");
+               lint_assert(tspec_is_int(rn->tn_type->t_tspec));
 
                ctn = plength(ln->tn_type);
                if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
@@ -2487,8 +2471,8 @@
 
        } else if (rn->tn_type->t_tspec == PTR) {
 
-               if (ln->tn_type->t_tspec != PTR || op != MINUS)
-                       LERROR("build_plus_minus()");
+               lint_assert(ln->tn_type->t_tspec == PTR);
+               lint_assert(op == MINUS);
 #if PTRDIFF_IS_LONG
                tp = gettyp(LONG);
 #else
@@ -2552,10 +2536,8 @@
                rtp = gettyp(VOID);
        } else if (lt == STRUCT || lt == UNION) {
                /* Both types must be identical. */
-               if (rt != STRUCT && rt != UNION)
-                       LERROR("build_colon()");
-               if (ln->tn_type->t_str != rn->tn_type->t_str)
-                       LERROR("build_colon()");
+               lint_assert(rt == STRUCT || rt == UNION);
+               lint_assert(ln->tn_type->t_str == rn->tn_type->t_str);
                if (incompl(ln->tn_type)) {
                        /* unknown operand size, op %s */
                        error(138, modtab[COLON].m_name);
@@ -2575,18 +2557,16 @@
                }
                rtp = rn->tn_type;
        } else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) {
-               if (rt != PTR)
-                       LERROR("build_colon()");
+               lint_assert(rt == PTR);
                rtp = rn->tn_type;
                merge_qualifiers(&rtp, ln->tn_type, rn->tn_type);
        } else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) {
-               if (lt != PTR)
-                       LERROR("build_colon()");
+               lint_assert(lt == PTR);
                rtp = ln->tn_type;
                merge_qualifiers(&rtp, ln->tn_type, rn->tn_type);
        } else {
-               if (lt != PTR || rt != PTR)
-                       LERROR("build_colon()");
+               lint_assert(lt == PTR);
+               lint_assert(rt == PTR);
                /*
                 * XXX For now we simply take the left type. This is
                 * probably wrong, if one type contains a function prototype
@@ -2611,15 +2591,14 @@
        tspec_t lt, rt;
        tnode_t *ntn, *ctn;
 
-       if (ln == NULL || rn == NULL)
-               LERROR("build_assignment()");
+       lint_assert(ln != NULL);
+       lint_assert(rn != NULL);
 
        lt = ln->tn_type->t_tspec;
        rt = rn->tn_type->t_tspec;
 
        if ((op == ADDASS || op == SUBASS) && lt == PTR) {
-               if (!tspec_is_int(rt))
-                       LERROR("build_assignment()");
+               lint_assert(tspec_is_int(rt));
                ctn = plength(ln->tn_type);
                if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
                        rn = convert(NOOP, 0, ctn->tn_type, rn);
@@ -2629,8 +2608,8 @@
        }
 
        if ((op == ASSIGN || op == RETURN) && (lt == STRUCT || rt == STRUCT)) {
-               if (rt != lt || ln->tn_type->t_str != rn->tn_type->t_str)
-                       LERROR("build_assignment()");
+               lint_assert(lt == rt);
+               lint_assert(ln->tn_type->t_str == rn->tn_type->t_str);
                if (incompl(ln->tn_type)) {
                        if (op == RETURN) {
                                /* cannot return incomplete type */
@@ -2673,8 +2652,7 @@
        int     elem, elsz;
        tspec_t st;
 
-       if (tp->t_tspec != PTR)
-               LERROR("plength()");
+       lint_assert(tp->t_tspec == PTR);
        tp = tp->t_subt;
 
        elem = 1;
@@ -2710,8 +2688,8 @@
                if ((elsz = size(tp->t_tspec)) == 0) {
                        /* cannot do pointer arithmetic on operand of ... */
                        error(136);
-               } else if (elsz == -1) {
-                       LERROR("plength()");
+               } else {
+                       lint_assert(elsz != -1);
                }
                break;
        }
@@ -2867,7 +2845,7 @@
                q = utyp ? (int64_t)(ul | ur) : sl | sr;
                break;
        default:
-               LERROR("fold()");
+               lint_assert(0);
        }
 
        /* XXX does not work for quads. */
@@ -2896,8 +2874,7 @@
 
        v = xcalloc(1, sizeof (val_t));



Home | Main Index | Thread Index | Old Index