Module Name: src
Committed By: rillig
Date: Sun Aug 22 21:27:15 UTC 2021
Modified Files:
src/usr.bin/xlint/lint1: debug.c lint1.h tree.c
Log Message:
lint: merge duplicate code for binary operator
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.345 -r1.346 src/usr.bin/xlint/lint1/tree.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/lint1/debug.c
diff -u src/usr.bin/xlint/lint1/debug.c:1.2 src/usr.bin/xlint/lint1/debug.c:1.3
--- src/usr.bin/xlint/lint1/debug.c:1.2 Sun Aug 1 19:11:54 2021
+++ src/usr.bin/xlint/lint1/debug.c Sun Aug 22 21:27:15 2021
@@ -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_node(const tnode_t *tn)
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();
}
Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.122 src/usr.bin/xlint/lint1/lint1.h:1.123
--- src/usr.bin/xlint/lint1/lint1.h:1.122 Sun Aug 22 13:01:47 2021
+++ src/usr.bin/xlint/lint1/lint1.h Sun Aug 22 21:27:15 2021
@@ -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 @@ is_nonzero(const tnode_t *tn)
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)
{
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.345 src/usr.bin/xlint/lint1/tree.c:1.346
--- src/usr.bin/xlint/lint1/tree.c:1.345 Sun Aug 22 21:17:04 2021
+++ src/usr.bin/xlint/lint1/tree.c Sun Aug 22 21:27:15 2021
@@ -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 @@ fold(tnode_t *tn)
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 @@ fold(tnode_t *tn)
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 @@ fold_test(tnode_t *tn)
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 @@ fold_float(tnode_t *tn)
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 @@ check_precedence_confusion(tnode_t *tn)
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)