Module Name: src
Committed By: rillig
Date: Wed Jun 15 18:29:21 UTC 2022
Modified Files:
src/usr.bin/xlint/lint1: ckbool.c externs1.h func.c op.h tree.c
Log Message:
lint: rename mod_t.m_requires_bool to m_compares_with_zero
The operators NOT, LOGAND, LOGOR and QUEST only require _Bool in strict
bool mode, in default mode they accept any scalar expression and compare
it with zero. The new names are more accurate.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.161 -r1.162 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.139 -r1.140 src/usr.bin/xlint/lint1/func.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/xlint/lint1/op.h
cvs rdiff -u -r1.452 -r1.453 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/ckbool.c
diff -u src/usr.bin/xlint/lint1/ckbool.c:1.16 src/usr.bin/xlint/lint1/ckbool.c:1.17
--- src/usr.bin/xlint/lint1/ckbool.c:1.16 Wed Jun 15 18:11:02 2022
+++ src/usr.bin/xlint/lint1/ckbool.c Wed Jun 15 18:29:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: ckbool.c,v 1.16 2022/06/15 18:11:02 rillig Exp $ */
+/* $NetBSD: ckbool.c,v 1.17 2022/06/15 18:29:21 rillig Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: ckbool.c,v 1.16 2022/06/15 18:11:02 rillig Exp $");
+__RCSID("$NetBSD: ckbool.c,v 1.17 2022/06/15 18:29:21 rillig Exp $");
#endif
#include <string.h>
@@ -158,9 +158,9 @@ typeok_scalar_strict_bool(op_t op, const
!typeok_strict_bool_binary_compatible(op, arg, ln, lt, rn, rt))
return false;
- if (mp->m_requires_bool) {
+ if (mp->m_compares_with_zero) {
bool binary = mp->m_binary;
- bool lbool = is_typeok_bool_operand(ln);
+ bool lbool = is_typeok_bool_compares_with_zero(ln);
bool ok = true;
if (!binary && !lbool) {
@@ -173,7 +173,8 @@ typeok_scalar_strict_bool(op_t op, const
error(331, op_name(op), tspec_name(lt));
ok = false;
}
- if (binary && op != QUEST && !is_typeok_bool_operand(rn)) {
+ if (binary && op != QUEST &&
+ !is_typeok_bool_compares_with_zero(rn)) {
/* right operand of '%s' must be bool, not '%s' */
error(332, op_name(op), tspec_name(rt));
ok = false;
@@ -212,7 +213,7 @@ typeok_scalar_strict_bool(op_t op, const
* argument with 0.
*/
bool
-is_typeok_bool_operand(const tnode_t *tn)
+is_typeok_bool_compares_with_zero(const tnode_t *tn)
{
tspec_t t;
Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.161 src/usr.bin/xlint/lint1/externs1.h:1.162
--- src/usr.bin/xlint/lint1/externs1.h:1.161 Wed Jun 15 18:06:51 2022
+++ src/usr.bin/xlint/lint1/externs1.h Wed Jun 15 18:29:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.161 2022/06/15 18:06:51 rillig Exp $ */
+/* $NetBSD: externs1.h,v 1.162 2022/06/15 18:29:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -250,7 +250,7 @@ extern tnode_t *build_binary(tnode_t *,
extern tnode_t *build_unary(op_t, bool, tnode_t *);
extern tnode_t *build_member_access(tnode_t *, op_t, bool, sbuf_t *);
extern tnode_t *cconv(tnode_t *);
-extern bool is_typeok_bool_operand(const tnode_t *);
+extern bool is_typeok_bool_compares_with_zero(const tnode_t *);
extern bool typeok(op_t, int, const tnode_t *, const tnode_t *);
extern tnode_t *promote(op_t, bool, tnode_t *);
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.139 src/usr.bin/xlint/lint1/func.c:1.140
--- src/usr.bin/xlint/lint1/func.c:1.139 Sat Jun 11 12:23:59 2022
+++ src/usr.bin/xlint/lint1/func.c Wed Jun 15 18:29:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: func.c,v 1.139 2022/06/11 12:23:59 rillig Exp $ */
+/* $NetBSD: func.c,v 1.140 2022/06/15 18:29:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.139 2022/06/11 12:23:59 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.140 2022/06/15 18:29:21 rillig Exp $");
#endif
#include <stdlib.h>
@@ -621,7 +621,7 @@ check_controlling_expression(tnode_t *tn
return NULL;
}
- if (tn != NULL && Tflag && !is_typeok_bool_operand(tn)) {
+ if (tn != NULL && Tflag && !is_typeok_bool_compares_with_zero(tn)) {
/* controlling expression must be bool, not '%s' */
error(333, tspec_name(tn->tn_type->t_tspec));
}
Index: src/usr.bin/xlint/lint1/op.h
diff -u src/usr.bin/xlint/lint1/op.h:1.19 src/usr.bin/xlint/lint1/op.h:1.20
--- src/usr.bin/xlint/lint1/op.h:1.19 Sat Apr 16 22:21:10 2022
+++ src/usr.bin/xlint/lint1/op.h Wed Jun 15 18:29:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: op.h,v 1.19 2022/04/16 22:21:10 rillig Exp $ */
+/* $NetBSD: op.h,v 1.20 2022/06/15 18:29:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -34,13 +34,13 @@
#include <stdbool.h>
/*
- * Various information about operators
+ * Various information about operators; see ops.def.
*/
typedef struct {
bool m_binary: 1;
bool m_returns_bool: 1;
bool m_takes_bool: 1;
- bool m_requires_bool: 1;
+ bool m_compares_with_zero: 1;
bool m_requires_integer: 1;
bool m_requires_integer_or_complex: 1;
bool m_requires_arith: 1;
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.452 src/usr.bin/xlint/lint1/tree.c:1.453
--- src/usr.bin/xlint/lint1/tree.c:1.452 Mon May 30 08:14:52 2022
+++ src/usr.bin/xlint/lint1/tree.c Wed Jun 15 18:29:21 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.452 2022/05/30 08:14:52 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.453 2022/06/15 18:29:21 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.452 2022/05/30 08:14:52 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.453 2022/06/15 18:29:21 rillig Exp $");
#endif
#include <float.h>
@@ -726,7 +726,7 @@ build_binary(tnode_t *ln, op_t op, bool
* Apply class conversions to the left operand, but only if its
* value is needed or it is compared with zero.
*/
- if (mp->m_value_context || mp->m_requires_bool)
+ if (mp->m_value_context || mp->m_compares_with_zero)
ln = cconv(ln);
/*
* The right operand is almost always in a test or value context,
@@ -745,7 +745,7 @@ build_binary(tnode_t *ln, op_t op, bool
if (mp->m_comparison)
check_integer_comparison(op, ln, rn);
- if (mp->m_value_context || mp->m_requires_bool)
+ if (mp->m_value_context || mp->m_compares_with_zero)
ln = promote(op, false, ln);
if (mp->m_binary && op != ARROW && op != POINT &&
op != ASSIGN && op != RETURN && op != INIT) {
@@ -854,7 +854,7 @@ build_binary(tnode_t *ln, op_t op, bool
* it is compared with zero and if this operand is a constant.
*/
if (hflag && !constcond_flag &&
- mp->m_requires_bool &&
+ mp->m_compares_with_zero &&
(ln->tn_op == CON ||
((mp->m_binary && op != QUEST) && rn->tn_op == CON)) &&
/* XXX: rn->tn_system_dependent should be checked as well */
@@ -866,7 +866,7 @@ build_binary(tnode_t *ln, op_t op, bool
/* Fold if the operator requires it */
if (mp->m_fold_constant_operands) {
if (ln->tn_op == CON && (!mp->m_binary || rn->tn_op == CON)) {
- if (mp->m_requires_bool) {
+ if (mp->m_compares_with_zero) {
ntn = fold_bool(ntn);
} else if (is_floating(ntn->tn_type->t_tspec)) {
ntn = fold_float(ntn);
@@ -4392,7 +4392,7 @@ check_expr_misc(const tnode_t *tn, bool
return;
cvctx = mp->m_value_context;
- ccond = mp->m_requires_bool;
+ ccond = mp->m_compares_with_zero;
eq = mp->m_warn_if_operand_eq &&
!ln->tn_parenthesized &&
rn != NULL && !rn->tn_parenthesized;