Module Name:    src
Committed By:   rillig
Date:           Fri Dec 10 23:33:05 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c

Log Message:
make: remove recursion from CondParser_And

No functional change intended.  Before cond.c 1.286 from today, there
would have been the functional change that in malformed conditions, the
extra expression would not be evaluated.  Now that CondParser_Token is
always called with doEval == false, there is no change in behavior to be
expected.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/usr.bin/make/cond.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.287 src/usr.bin/make/cond.c:1.288
--- src/usr.bin/make/cond.c:1.287	Fri Dec 10 23:19:59 2021
+++ src/usr.bin/make/cond.c	Fri Dec 10 23:33:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.287 2021/12/10 23:19:59 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.288 2021/12/10 23:33:05 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,13 +95,12 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.287 2021/12/10 23:19:59 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.288 2021/12/10 23:33:05 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
  *	Or -> And ('||' And)*
- *	And -> Term
- *	And -> And '&&' Term
+ *	And -> Term ('&&' Term)*
  *	Term -> Function '(' Argument ')'
  *	Term -> Leaf Operator Leaf
  *	Term -> Leaf
@@ -974,27 +973,23 @@ CondParser_Term(CondParser *par, bool do
 }
 
 /*
- * And -> Term
- * And -> And '&&' Term
+ * And -> Term ('&&' Term)*
  */
 static CondResult
 CondParser_And(CondParser *par, bool doEval)
 {
-	CondResult res;
+	CondResult res, rhs;
 	Token op;
 
-	res = CondParser_Term(par, doEval);
-	if (res == CR_ERROR)
-		return CR_ERROR;
-
-	op = CondParser_Token(par, false);
-	if (op == TOK_AND) {
-		if (res == CR_TRUE)
-			return CondParser_And(par, doEval);
-		if (CondParser_And(par, false) == CR_ERROR)
+	res = CR_TRUE;
+	do {
+		if ((rhs = CondParser_Term(par, doEval)) == CR_ERROR)
 			return CR_ERROR;
-		return res;
-	}
+		if (rhs == CR_FALSE) {
+			res = CR_FALSE;
+			doEval = false;
+		}
+	} while ((op = CondParser_Token(par, false)) == TOK_AND);
 
 	CondParser_PushBack(par, op);
 	return res;

Reply via email to