Module Name:    src
Committed By:   rillig
Date:           Fri Dec 10 19:47:20 UTC 2021

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

Log Message:
make: simplify parsing of '||' in conditions

Previously, the grammar said 'Or -> Or || And', while the code looked
more like 'Or -> And || Or'.  Make the code look like the grammar and
keep track of the resulting value of the condition explicitly.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 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.284 src/usr.bin/make/cond.c:1.285
--- src/usr.bin/make/cond.c:1.284	Thu Dec  9 23:02:46 2021
+++ src/usr.bin/make/cond.c	Fri Dec 10 19:47:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.284 2021/12/09 23:02:46 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.285 2021/12/10 19:47:20 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,12 +95,11 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.284 2021/12/09 23:02:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.285 2021/12/10 19:47:20 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
- *	Or -> And
- *	Or -> Or '||' And
+ *	Or -> And ('||' And)*
  *	And -> Term
  *	And -> And '&&' Term
  *	Term -> Function '(' Argument ')'
@@ -1002,27 +1001,23 @@ CondParser_And(CondParser *par, bool doE
 }
 
 /*
- * Or -> And
- * Or -> Or '||' And
+ * Or -> And ('||' And)*
  */
 static CondResult
 CondParser_Or(CondParser *par, bool doEval)
 {
-	CondResult res;
+	CondResult res, rhs;
 	Token op;
 
-	res = CondParser_And(par, doEval);
-	if (res == CR_ERROR)
-		return CR_ERROR;
-
-	op = CondParser_Token(par, doEval);
-	if (op == TOK_OR) {
-		if (res == CR_FALSE)
-			return CondParser_Or(par, doEval);
-		if (CondParser_Or(par, false) == CR_ERROR)
+	res = CR_FALSE;
+	do {
+		if ((rhs = CondParser_And(par, doEval)) == CR_ERROR)
 			return CR_ERROR;
-		return res;
-	}
+		if (rhs == CR_TRUE) {
+			res = CR_TRUE;
+			doEval = false;
+		}
+	} while ((op = CondParser_Token(par, doEval)) == TOK_OR);
 
 	CondParser_PushBack(par, op);
 	return res;

Reply via email to