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: clean up redundant and verbose code



details:   https://anonhg.NetBSD.org/src/rev/2673f774c761
branches:  trunk
changeset: 377496:2673f774c761
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 14 09:20:23 2023 +0000

description:
lint: clean up redundant and verbose code

diffstat:

 usr.bin/xlint/lint1/decl.c |  18 +++++++++---------
 usr.bin/xlint/lint1/tree.c |  23 +++++++----------------
 2 files changed, 16 insertions(+), 25 deletions(-)

diffs (125 lines):

diff -r 9e1acf477b06 -r 2673f774c761 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Jul 14 09:04:08 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Jul 14 09:20:23 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.356 2023/07/14 09:20:23 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.355 2023/07/13 23:27:20 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.356 2023/07/14 09:20:23 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -104,7 +104,6 @@ initdecl(void)
                                ttab[i].tt_rank_value =
                                    ttab[i].tt_size_in_bits;
                }
-               ttab[BOOL].tt_rank_kind = RK_INTEGER;
                ttab[BOOL].tt_rank_value = 1;
        }
 
@@ -607,7 +606,7 @@ void
 dcs_begin_type(void)
 {
 
-       debug_step("%s", __func__);
+       debug_enter();
        dcs->d_abstract_type = NO_TSPEC;
        dcs->d_complex_mod = NO_TSPEC;
        dcs->d_sign_mod = NO_TSPEC;
@@ -711,7 +710,6 @@ void
 dcs_end_type(void)
 {
 
-       debug_step("%s", __func__);
        dcs_merge_declaration_specifiers();
 
        if (dcs->d_multiple_storage_classes) {
@@ -743,6 +741,8 @@ dcs_end_type(void)
                dcs->d_type->t_const |= dcs->d_qual.tq_const;
                dcs->d_type->t_volatile |= dcs->d_qual.tq_volatile;
        }
+
+       debug_leave();
 }
 
 /*
@@ -1148,10 +1148,10 @@ add_type_qualifiers(type_qualifiers *dst
                /* duplicate '%s' */
                warning(10, "volatile");
 
-       dst->tq_const = dst->tq_const || src.tq_const;
-       dst->tq_restrict = dst->tq_restrict || src.tq_restrict;
-       dst->tq_volatile = dst->tq_volatile || src.tq_volatile;
-       dst->tq_atomic = dst->tq_atomic || src.tq_atomic;
+       dst->tq_const = dst->tq_const | src.tq_const;
+       dst->tq_restrict = dst->tq_restrict | src.tq_restrict;
+       dst->tq_volatile = dst->tq_volatile | src.tq_volatile;
+       dst->tq_atomic = dst->tq_atomic | src.tq_atomic;
 }
 
 qual_ptr *
diff -r 9e1acf477b06 -r 2673f774c761 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Jul 14 09:04:08 2023 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Jul 14 09:20:23 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.565 2023/07/14 09:04:08 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.566 2023/07/14 09:20:23 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.565 2023/07/14 09:04:08 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.566 2023/07/14 09:20:23 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -358,8 +358,7 @@ build_op(op_t op, bool sys, type_t *type
        if (op == INDIR || op == FSEL) {
                lint_assert(ln->tn_type->t_tspec == PTR);
                tspec_t t = ln->tn_type->t_subt->t_tspec;
-               if (t != FUNC && t != VOID)
-                       ntn->tn_lvalue = true;
+               ntn->tn_lvalue = t != FUNC && t != VOID;
        }
 
        return ntn;
@@ -937,11 +936,7 @@ build_struct_access(op_t op, bool sys, t
        lint_assert(rn->tn_op == NAME);
        lint_assert(is_member(rn->tn_sym));
 
-       /*
-        * Remember if the left operand is an lvalue (structure members
-        * are lvalues if and only if the structure itself is an lvalue).
-        */
-       bool nolval = op == POINT && !ln->tn_lvalue;
+       bool lvalue = op == ARROW || ln->tn_lvalue;
 
        if (op == POINT) {
                ln = build_address(sys, ln, true);
@@ -959,13 +954,9 @@ build_struct_access(op_t op, bool sys, t
        if (ln->tn_op == CON)
                ntn = fold(ntn);
 
-       if (rn->tn_type->t_bitfield) {
-               ntn = build_op(FSEL, sys, ntn->tn_type->t_subt, ntn, NULL);
-       } else {
-               ntn = build_op(INDIR, sys, ntn->tn_type->t_subt, ntn, NULL);
-       }
-
-       if (nolval)
+       op_t nop = rn->tn_type->t_bitfield ? FSEL : INDIR;
+       ntn = build_op(nop, sys, ntn->tn_type->t_subt, ntn, NULL);
+       if (!lvalue)
                ntn->tn_lvalue = false;
 
        return ntn;



Home | Main Index | Thread Index | Old Index