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.
This commit is contained in:
rillig 2022-06-15 18:29:21 +00:00
parent 511ec7d9fa
commit f5a7e97688
5 changed files with 22 additions and 21 deletions

View File

@ -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 mod_t *mp, int arg,
!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 mod_t *mp, int arg,
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 mod_t *mp, int arg,
* 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;

View File

@ -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 *, op_t, bool, 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 *);

View File

@ -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));
}

View File

@ -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;

View File

@ -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 sys, tnode_t *rn)
* 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 sys, tnode_t *rn)
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 sys, tnode_t *rn)
* 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 sys, tnode_t *rn)
/* 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 vctx, bool cond,
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;