Module Name:    src
Committed By:   rillig
Date:           Wed Dec 29 04:50:56 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c nonints.h var.c

Log Message:
make: remove redundant parameter for evaluating conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.309 -r1.310 src/usr.bin/make/cond.c
cvs rdiff -u -r1.223 -r1.224 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.989 -r1.990 src/usr.bin/make/var.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/make/cond.c
diff -u src/usr.bin/make/cond.c:1.309 src/usr.bin/make/cond.c:1.310
--- src/usr.bin/make/cond.c:1.309	Wed Dec 29 04:41:38 2021
+++ src/usr.bin/make/cond.c	Wed Dec 29 04:50:56 2021
@@ -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.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)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:
@@ -982,7 +982,7 @@ CondParser_Or(CondParser *par, bool doEv
 }
 
 static CondEvalResult
-CondParser_Eval(CondParser *par, bool *out_value)
+CondParser_Eval(CondParser *par)
 {
 	CondResult res;
 
@@ -995,8 +995,7 @@ CondParser_Eval(CondParser *par, bool *o
 	if (CondParser_Token(par, false) != TOK_EOF)
 		return COND_INVALID;
 
-	*out_value = res == CR_TRUE;
-	return COND_PARSE;
+	return res;
 }
 
 /*
@@ -1011,7 +1010,7 @@ CondParser_Eval(CondParser *par, bool *o
  *	*out_value	is set to the boolean value of the condition
  */
 static CondEvalResult
-CondEvalExpression(const char *cond, bool *out_value, bool plain,
+CondEvalExpression(const char *cond, bool plain,
 		   bool (*evalBare)(const char *), bool negate,
 		   bool eprint, bool leftUnquotedOK)
 {
@@ -1028,7 +1027,7 @@ CondEvalExpression(const char *cond, boo
 	par.curr = TOK_NONE;
 	par.printedError = false;
 
-	rval = CondParser_Eval(&par, out_value);
+	rval = CondParser_Eval(&par);
 
 	if (rval == COND_INVALID && eprint && !par.printedError)
 		Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", cond);
@@ -1041,9 +1040,9 @@ CondEvalExpression(const char *cond, boo
  * ${"${VAR}" == value:?yes:no}.
  */
 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);
 }
 
@@ -1150,7 +1149,7 @@ Cond_EvalLine(const char *line)
 	bool (*evalBare)(const char *);
 	bool negate;
 	bool isElif;
-	bool value;
+	CondResult res;
 	IfState state;
 	const char *p = line;
 
@@ -1275,8 +1274,8 @@ Cond_EvalLine(const char *line)
 	}
 
 	/* And evaluate the conditional expression */
-	if (CondEvalExpression(p, &value, plain, evalBare, negate,
-	    true, false) == COND_INVALID) {
+	res = CondEvalExpression(p, plain, evalBare, negate, true, false);
+	if (res == COND_INVALID) {
 		/*
 		 * Syntax error in conditional, error message already output.
 		 */
@@ -1286,7 +1285,7 @@ Cond_EvalLine(const char *line)
 		return COND_SKIP;
 	}
 
-	if (!value) {
+	if (res == COND_SKIP) {
 		cond_states[cond_depth] = IFS_INITIAL;
 		return COND_SKIP;
 	}

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.223 src/usr.bin/make/nonints.h:1.224
--- src/usr.bin/make/nonints.h:1.223	Tue Dec 28 01:11:36 2021
+++ src/usr.bin/make/nonints.h	Wed Dec 29 04:50:56 2021
@@ -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
@@ -91,7 +91,7 @@ void Compat_Run(GNodeList *);
 void Compat_Make(GNode *, GNode *);
 
 /* 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;
 void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void) MAKE_ATTR_USE;

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.989 src/usr.bin/make/var.c:1.990
--- src/usr.bin/make/var.c:1.989	Wed Dec 15 13:03:33 2021
+++ src/usr.bin/make/var.c	Wed Dec 29 04:50:56 2021
@@ -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
@@ -140,7 +140,7 @@
 #include "metachar.h"
 
 /*	"@(#)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
@@ -3451,16 +3451,15 @@ ApplyModifier_IfElse(const char **pp, Mo
 	LazyBuf thenBuf;
 	LazyBuf elseBuf;
 
-	bool value = false;
 	VarEvalMode then_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)) {
-		cond_rc = Cond_EvalCondition(expr->name, &value);
-		if (cond_rc != COND_INVALID && value)
+		cond_rc = Cond_EvalCondition(expr->name);
+		if (cond_rc == CR_TRUE)
 			then_emode = expr->emode;
-		if (cond_rc != COND_INVALID && !value)
+		if (cond_rc == CR_FALSE)
 			else_emode = expr->emode;
 	}
 
@@ -3477,7 +3476,7 @@ ApplyModifier_IfElse(const char **pp, Mo
 
 	(*pp)--;		/* Go back to the ch->endc. */
 
-	if (cond_rc == COND_INVALID) {
+	if (cond_rc == CR_ERROR) {
 		Substring thenExpr = LazyBuf_Get(&thenBuf);
 		Substring elseExpr = LazyBuf_Get(&elseBuf);
 		Error("Bad conditional expression '%s' in '%s?%.*s:%.*s'",
@@ -3492,7 +3491,7 @@ ApplyModifier_IfElse(const char **pp, Mo
 	if (!Expr_ShouldEval(expr)) {
 		LazyBuf_Done(&thenBuf);
 		LazyBuf_Done(&elseBuf);
-	} else if (value) {
+	} else if (cond_rc == CR_TRUE) {
 		Expr_SetValue(expr, LazyBuf_DoneGet(&thenBuf));
 		LazyBuf_Done(&elseBuf);
 	} else {

Reply via email to