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 non-zero ...
details: https://anonhg.NetBSD.org/src/rev/a1fa72b0fb94
branches: trunk
changeset: 949748:a1fa72b0fb94
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jan 15 23:43:51 2021 +0000
description:
lint: merge duplicate code for non-zero detection
diffstat:
usr.bin/xlint/lint1/func.c | 30 +++++++-----------------------
usr.bin/xlint/lint1/lint1.h | 19 ++++++++++++++++++-
usr.bin/xlint/lint1/tree.c | 25 ++++++-------------------
3 files changed, 31 insertions(+), 43 deletions(-)
diffs (154 lines):
diff -r 35f39f55d50c -r a1fa72b0fb94 usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c Fri Jan 15 23:19:33 2021 +0000
+++ b/usr.bin/xlint/lint1/func.c Fri Jan 15 23:43:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.57 2021/01/12 20:42:01 rillig Exp $ */
+/* $NetBSD: func.c,v 1.58 2021/01/15 23:43:51 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: func.c,v 1.57 2021/01/12 20:42:01 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.58 2021/01/15 23:43:51 rillig Exp $");
#endif
#include <stdlib.h>
@@ -725,13 +725,8 @@
pushctrl(T_WHILE);
cstmt->c_loop = 1;
- if (tn != NULL && tn->tn_op == CON) {
- if (is_integer(tn->tn_type->t_tspec)) {
- cstmt->c_infinite = tn->tn_val->v_quad != 0;
- } else {
- cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0;
- }
- }
+ if (tn != NULL && tn->tn_op == CON)
+ cstmt->c_infinite = is_nonzero(tn);
expr(tn, 0, 1, 1);
}
@@ -790,11 +785,7 @@
tn = check_controlling_expression(tn);
if (tn != NULL && tn->tn_op == CON) {
- if (is_integer(tn->tn_type->t_tspec)) {
- cstmt->c_infinite = tn->tn_val->v_quad != 0;
- } else {
- cstmt->c_infinite = tn->tn_val->v_ldbl != 0.0;
- }
+ cstmt->c_infinite = is_nonzero(tn);
if (!cstmt->c_infinite && cstmt->c_cont)
/* continue in 'do ... while (0)' loop */
error(323);
@@ -850,15 +841,8 @@
if (tn2 != NULL)
expr(tn2, 0, 1, 1);
- if (tn2 == NULL) {
- cstmt->c_infinite = 1;
- } else if (tn2->tn_op == CON) {
- if (is_integer(tn2->tn_type->t_tspec)) {
- cstmt->c_infinite = tn2->tn_val->v_quad != 0;
- } else {
- cstmt->c_infinite = tn2->tn_val->v_ldbl != 0.0;
- }
- }
+ cstmt->c_infinite =
+ tn2 == NULL || (tn2->tn_op == CON && is_nonzero(tn2));
/* Checking the reinitialisation expression is done in for2() */
diff -r 35f39f55d50c -r a1fa72b0fb94 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h Fri Jan 15 23:19:33 2021 +0000
+++ b/usr.bin/xlint/lint1/lint1.h Fri Jan 15 23:43:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.53 2021/01/04 22:26:50 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.54 2021/01/15 23:43:51 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -459,3 +459,20 @@
# define gnuism(id, args...) wrap_check_printf(gnuism, id, ##args)
# define c99ism(id, args...) wrap_check_printf(c99ism, id, ##args)
#endif
+
+static inline bool
+is_nonzero_val(tspec_t t, const val_t *val)
+{
+ return is_floating(t) ? val->v_ldbl != 0.0 : val->v_quad != 0;
+}
+
+static inline bool
+is_nonzero(const tnode_t *tn)
+{
+ /*
+ * XXX: It's strange that val_t doesn't know itself whether it
+ * holds a floating-point or an integer value.
+ */
+ lint_assert(tn->tn_op == CON);
+ return is_nonzero_val(tn->tn_type->t_tspec, tn->tn_val);
+}
diff -r 35f39f55d50c -r a1fa72b0fb94 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Fri Jan 15 23:19:33 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Fri Jan 15 23:43:51 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.152 2021/01/14 07:42:31 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.153 2021/01/15 23:43: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.152 2021/01/14 07:42:31 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.153 2021/01/15 23:43:51 rillig Exp $");
#endif
#include <float.h>
@@ -2234,9 +2234,7 @@
if (nt == BOOL) { /* C99 6.3.1.2 */
nv->v_ansiu = 0;
- nv->v_quad = ot == FLOAT || ot == DOUBLE || ot == LDOUBLE
- ? v->v_ldbl != 0.0
- : v->v_quad != 0;
+ nv->v_quad = is_nonzero_val(ot, v) ? 1 : 0;
return;
}
@@ -3142,26 +3140,15 @@
static tnode_t *
fold_test(tnode_t *tn)
{
- int l, r = 0;
+ bool l, r;
val_t *v;
v = xcalloc(1, sizeof (val_t));
v->v_tspec = tn->tn_type->t_tspec;
lint_assert(v->v_tspec == INT || (Tflag && v->v_tspec == BOOL));
- if (is_floating(tn->tn_left->tn_type->t_tspec)) {
- l = tn->tn_left->tn_val->v_ldbl != 0.0;
- } else {
- l = tn->tn_left->tn_val->v_quad != 0;
- }
-
- if (modtab[tn->tn_op].m_binary) {
- if (is_floating(tn->tn_right->tn_type->t_tspec)) {
- r = tn->tn_right->tn_val->v_ldbl != 0.0;
- } else {
- r = tn->tn_right->tn_val->v_quad != 0;
- }
- }
+ l = is_nonzero(tn->tn_left);
+ r = modtab[tn->tn_op].m_binary && is_nonzero(tn->tn_right);
switch (tn->tn_op) {
case NOT:
Home |
Main Index |
Thread Index |
Old Index