make: remove redundant parameter for evaluating conditions
No functional change.
This commit is contained in:
parent
bcf936b8fd
commit
3a10c88e96
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: cond.c,v 1.309 2021/12/29 04:41:38 rillig Exp $ */
|
/* $NetBSD: cond.c,v 1.310 2021/12/29 04:50:56 rillig Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
|
|
||||||
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
|
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
|
||||||
MAKE_RCSID("$NetBSD: cond.c,v 1.309 2021/12/29 04:41:38 rillig Exp $");
|
MAKE_RCSID("$NetBSD: cond.c,v 1.310 2021/12/29 04:50:56 rillig Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The parsing of conditional expressions is based on this grammar:
|
* The parsing of conditional expressions is based on this grammar:
|
||||||
|
@ -982,7 +982,7 @@ CondParser_Or(CondParser *par, bool doEval)
|
||||||
}
|
}
|
||||||
|
|
||||||
static CondEvalResult
|
static CondEvalResult
|
||||||
CondParser_Eval(CondParser *par, bool *out_value)
|
CondParser_Eval(CondParser *par)
|
||||||
{
|
{
|
||||||
CondResult res;
|
CondResult res;
|
||||||
|
|
||||||
|
@ -995,8 +995,7 @@ CondParser_Eval(CondParser *par, bool *out_value)
|
||||||
if (CondParser_Token(par, false) != TOK_EOF)
|
if (CondParser_Token(par, false) != TOK_EOF)
|
||||||
return COND_INVALID;
|
return COND_INVALID;
|
||||||
|
|
||||||
*out_value = res == CR_TRUE;
|
return res;
|
||||||
return COND_PARSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1011,7 +1010,7 @@ CondParser_Eval(CondParser *par, bool *out_value)
|
||||||
* *out_value is set to the boolean value of the condition
|
* *out_value is set to the boolean value of the condition
|
||||||
*/
|
*/
|
||||||
static CondEvalResult
|
static CondEvalResult
|
||||||
CondEvalExpression(const char *cond, bool *out_value, bool plain,
|
CondEvalExpression(const char *cond, bool plain,
|
||||||
bool (*evalBare)(const char *), bool negate,
|
bool (*evalBare)(const char *), bool negate,
|
||||||
bool eprint, bool leftUnquotedOK)
|
bool eprint, bool leftUnquotedOK)
|
||||||
{
|
{
|
||||||
|
@ -1028,7 +1027,7 @@ CondEvalExpression(const char *cond, bool *out_value, bool plain,
|
||||||
par.curr = TOK_NONE;
|
par.curr = TOK_NONE;
|
||||||
par.printedError = false;
|
par.printedError = false;
|
||||||
|
|
||||||
rval = CondParser_Eval(&par, out_value);
|
rval = CondParser_Eval(&par);
|
||||||
|
|
||||||
if (rval == COND_INVALID && eprint && !par.printedError)
|
if (rval == COND_INVALID && eprint && !par.printedError)
|
||||||
Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", cond);
|
Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", cond);
|
||||||
|
@ -1041,9 +1040,9 @@ CondEvalExpression(const char *cond, bool *out_value, bool plain,
|
||||||
* ${"${VAR}" == value:?yes:no}.
|
* ${"${VAR}" == value:?yes:no}.
|
||||||
*/
|
*/
|
||||||
CondEvalResult
|
CondEvalResult
|
||||||
Cond_EvalCondition(const char *cond, bool *out_value)
|
Cond_EvalCondition(const char *cond)
|
||||||
{
|
{
|
||||||
return CondEvalExpression(cond, out_value, true,
|
return CondEvalExpression(cond, true,
|
||||||
FuncDefined, false, false, true);
|
FuncDefined, false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1150,7 +1149,7 @@ Cond_EvalLine(const char *line)
|
||||||
bool (*evalBare)(const char *);
|
bool (*evalBare)(const char *);
|
||||||
bool negate;
|
bool negate;
|
||||||
bool isElif;
|
bool isElif;
|
||||||
bool value;
|
CondResult res;
|
||||||
IfState state;
|
IfState state;
|
||||||
const char *p = line;
|
const char *p = line;
|
||||||
|
|
||||||
|
@ -1275,8 +1274,8 @@ Cond_EvalLine(const char *line)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And evaluate the conditional expression */
|
/* And evaluate the conditional expression */
|
||||||
if (CondEvalExpression(p, &value, plain, evalBare, negate,
|
res = CondEvalExpression(p, plain, evalBare, negate, true, false);
|
||||||
true, false) == COND_INVALID) {
|
if (res == COND_INVALID) {
|
||||||
/*
|
/*
|
||||||
* Syntax error in conditional, error message already output.
|
* Syntax error in conditional, error message already output.
|
||||||
*/
|
*/
|
||||||
|
@ -1286,7 +1285,7 @@ Cond_EvalLine(const char *line)
|
||||||
return COND_SKIP;
|
return COND_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!value) {
|
if (res == COND_SKIP) {
|
||||||
cond_states[cond_depth] = IFS_INITIAL;
|
cond_states[cond_depth] = IFS_INITIAL;
|
||||||
return COND_SKIP;
|
return COND_SKIP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: nonints.h,v 1.223 2021/12/28 01:11:36 rillig Exp $ */
|
/* $NetBSD: nonints.h,v 1.224 2021/12/29 04:50:56 rillig Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1989, 1990, 1993
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -91,7 +91,7 @@ void Compat_Run(GNodeList *);
|
||||||
void Compat_Make(GNode *, GNode *);
|
void Compat_Make(GNode *, GNode *);
|
||||||
|
|
||||||
/* cond.c */
|
/* cond.c */
|
||||||
CondEvalResult Cond_EvalCondition(const char *, bool *) MAKE_ATTR_USE;
|
CondEvalResult Cond_EvalCondition(const char *) MAKE_ATTR_USE;
|
||||||
CondEvalResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
|
CondEvalResult Cond_EvalLine(const char *) MAKE_ATTR_USE;
|
||||||
void Cond_restore_depth(unsigned int);
|
void Cond_restore_depth(unsigned int);
|
||||||
unsigned int Cond_save_depth(void) MAKE_ATTR_USE;
|
unsigned int Cond_save_depth(void) MAKE_ATTR_USE;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: var.c,v 1.989 2021/12/15 13:03:33 rillig Exp $ */
|
/* $NetBSD: var.c,v 1.990 2021/12/29 04:50:56 rillig Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1989, 1990, 1993
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
#include "metachar.h"
|
#include "metachar.h"
|
||||||
|
|
||||||
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
|
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
|
||||||
MAKE_RCSID("$NetBSD: var.c,v 1.989 2021/12/15 13:03:33 rillig Exp $");
|
MAKE_RCSID("$NetBSD: var.c,v 1.990 2021/12/29 04:50:56 rillig Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables are defined using one of the VAR=value assignments. Their
|
* Variables are defined using one of the VAR=value assignments. Their
|
||||||
|
@ -3451,16 +3451,15 @@ ApplyModifier_IfElse(const char **pp, ModChain *ch)
|
||||||
LazyBuf thenBuf;
|
LazyBuf thenBuf;
|
||||||
LazyBuf elseBuf;
|
LazyBuf elseBuf;
|
||||||
|
|
||||||
bool value = false;
|
|
||||||
VarEvalMode then_emode = VARE_PARSE_ONLY;
|
VarEvalMode then_emode = VARE_PARSE_ONLY;
|
||||||
VarEvalMode else_emode = VARE_PARSE_ONLY;
|
VarEvalMode else_emode = VARE_PARSE_ONLY;
|
||||||
|
|
||||||
CondEvalResult cond_rc = COND_PARSE; /* just not COND_INVALID */
|
CondEvalResult cond_rc = CR_TRUE; /* just not CR_ERROR */
|
||||||
if (Expr_ShouldEval(expr)) {
|
if (Expr_ShouldEval(expr)) {
|
||||||
cond_rc = Cond_EvalCondition(expr->name, &value);
|
cond_rc = Cond_EvalCondition(expr->name);
|
||||||
if (cond_rc != COND_INVALID && value)
|
if (cond_rc == CR_TRUE)
|
||||||
then_emode = expr->emode;
|
then_emode = expr->emode;
|
||||||
if (cond_rc != COND_INVALID && !value)
|
if (cond_rc == CR_FALSE)
|
||||||
else_emode = expr->emode;
|
else_emode = expr->emode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3477,7 +3476,7 @@ ApplyModifier_IfElse(const char **pp, ModChain *ch)
|
||||||
|
|
||||||
(*pp)--; /* Go back to the ch->endc. */
|
(*pp)--; /* Go back to the ch->endc. */
|
||||||
|
|
||||||
if (cond_rc == COND_INVALID) {
|
if (cond_rc == CR_ERROR) {
|
||||||
Substring thenExpr = LazyBuf_Get(&thenBuf);
|
Substring thenExpr = LazyBuf_Get(&thenBuf);
|
||||||
Substring elseExpr = LazyBuf_Get(&elseBuf);
|
Substring elseExpr = LazyBuf_Get(&elseBuf);
|
||||||
Error("Bad conditional expression '%s' in '%s?%.*s:%.*s'",
|
Error("Bad conditional expression '%s' in '%s?%.*s:%.*s'",
|
||||||
|
@ -3492,7 +3491,7 @@ ApplyModifier_IfElse(const char **pp, ModChain *ch)
|
||||||
if (!Expr_ShouldEval(expr)) {
|
if (!Expr_ShouldEval(expr)) {
|
||||||
LazyBuf_Done(&thenBuf);
|
LazyBuf_Done(&thenBuf);
|
||||||
LazyBuf_Done(&elseBuf);
|
LazyBuf_Done(&elseBuf);
|
||||||
} else if (value) {
|
} else if (cond_rc == CR_TRUE) {
|
||||||
Expr_SetValue(expr, LazyBuf_DoneGet(&thenBuf));
|
Expr_SetValue(expr, LazyBuf_DoneGet(&thenBuf));
|
||||||
LazyBuf_Done(&elseBuf);
|
LazyBuf_Done(&elseBuf);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue