Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make: simplify parsing of '||' in conditions
details: https://anonhg.NetBSD.org/src/rev/f5b1e6ee3096
branches: trunk
changeset: 1027545:f5b1e6ee3096
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Dec 10 19:47:20 2021 +0000
description:
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.
diffstat:
usr.bin/make/cond.c | 31 +++++++++++++------------------
1 files changed, 13 insertions(+), 18 deletions(-)
diffs (62 lines):
diff -r 335ae400ba74 -r f5b1e6ee3096 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c Fri Dec 10 19:30:05 2021 +0000
+++ b/usr.bin/make/cond.c Fri Dec 10 19:47:20 2021 +0000
@@ -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 @@
}
/*
- * 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;
Home |
Main Index |
Thread Index |
Old Index