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: merge duplicate code for binary op...



details:   https://anonhg.NetBSD.org/src/rev/7ddc3ad289ea
branches:  trunk
changeset: 1023082:7ddc3ad289ea
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Aug 22 21:27:15 2021 +0000

description:
lint: merge duplicate code for binary operator

No functional change.

diffstat:

 usr.bin/xlint/lint1/debug.c |   6 +++---
 usr.bin/xlint/lint1/lint1.h |   8 +++++++-
 usr.bin/xlint/lint1/tree.c  |  17 ++++++++---------
 3 files changed, 18 insertions(+), 13 deletions(-)

diffs (117 lines):

diff -r 53dbbcb95a22 -r 7ddc3ad289ea usr.bin/xlint/lint1/debug.c
--- a/usr.bin/xlint/lint1/debug.c       Sun Aug 22 21:17:04 2021 +0000
+++ b/usr.bin/xlint/lint1/debug.c       Sun Aug 22 21:27:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.2 2021/08/01 19:11:54 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.3 2021/08/22 21:27:15 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: debug.c,v 1.2 2021/08/01 19:11:54 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.3 2021/08/22 21:27:15 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -151,7 +151,7 @@
 
                debug_indent_inc();
                debug_node(tn->tn_left);
-               if (modtab[op].m_binary || tn->tn_right != NULL)
+               if (is_binary(tn) || tn->tn_right != NULL)
                        debug_node(tn->tn_right);
                debug_indent_dec();
        }
diff -r 53dbbcb95a22 -r 7ddc3ad289ea usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Sun Aug 22 21:17:04 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Sun Aug 22 21:27:15 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.122 2021/08/22 13:01:47 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.123 2021/08/22 21:27:15 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -552,6 +552,12 @@
        return tn != NULL && tn->tn_op == CON && is_nonzero_val(tn->tn_val);
 }
 
+static inline bool
+is_binary(const tnode_t *tn)
+{
+       return modtab[tn->tn_op].m_binary;
+}
+
 static inline uint64_t
 bit(unsigned i)
 {
diff -r 53dbbcb95a22 -r 7ddc3ad289ea usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Aug 22 21:17:04 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Aug 22 21:27:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.345 2021/08/22 21:17:04 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.346 2021/08/22 21:27:15 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.345 2021/08/22 21:17:04 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.346 2021/08/22 21:27:15 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3033,7 +3033,7 @@
        t = tn->tn_left->tn_type->t_tspec;
        utyp = !is_integer(t) || is_uinteger(t);
        ul = sl = tn->tn_left->tn_val->v_quad;
-       if (modtab[tn->tn_op].m_binary)
+       if (is_binary(tn))
                ur = sr = tn->tn_right->tn_val->v_quad;
 
        mask = value_bits(size_in_bits(t));
@@ -3157,7 +3157,7 @@
        cn = build_constant(tn->tn_type, v);
        if (tn->tn_left->tn_system_dependent)
                cn->tn_system_dependent = true;
-       if (modtab[tn->tn_op].m_binary && tn->tn_right->tn_system_dependent)
+       if (is_binary(tn) && tn->tn_right->tn_system_dependent)
                cn->tn_system_dependent = true;
 
        return cn;
@@ -3178,7 +3178,7 @@
        lint_assert(v->v_tspec == INT || (Tflag && v->v_tspec == BOOL));
 
        l = constant_is_nonzero(tn->tn_left);
-       r = modtab[tn->tn_op].m_binary && constant_is_nonzero(tn->tn_right);
+       r = is_binary(tn) && constant_is_nonzero(tn->tn_right);
 
        switch (tn->tn_op) {
        case NOT:
@@ -3216,11 +3216,10 @@
 
        lint_assert(is_floating(t));
        lint_assert(t == tn->tn_left->tn_type->t_tspec);
-       lint_assert(!modtab[tn->tn_op].m_binary ||
-           t == tn->tn_right->tn_type->t_tspec);
+       lint_assert(!is_binary(tn) || t == tn->tn_right->tn_type->t_tspec);
 
        lv = tn->tn_left->tn_val->v_ldbl;
-       if (modtab[tn->tn_op].m_binary)
+       if (is_binary(tn))
                rv = tn->tn_right->tn_val->v_ldbl;
 
        switch (tn->tn_op) {
@@ -4334,7 +4333,7 @@
 
        debug_node(tn);
 
-       lint_assert(modtab[tn->tn_op].m_binary);
+       lint_assert(is_binary(tn));
        for (ln = tn->tn_left; ln->tn_op == CVT; ln = ln->tn_left)
                continue;
        for (rn = tn->tn_right; rn->tn_op == CVT; rn = rn->tn_left)



Home | Main Index | Thread Index | Old Index