Module Name: src
Committed By: rillig
Date: Sun Nov 8 19:24:19 UTC 2020
Modified Files:
src/usr.bin/make: cond.c var.c
Log Message:
make(1): clean up VarEvalFlags in the calls to Var_Parse and Var_Subst
There are only 3 flags, and some combinations don't even make sense.
VARE_UNDEFERR only makes sense if combined with VARE_WANTRES. If the
latter is not set, the variable expressions are only parsed, without
asking whether they are defined or not. Therefore, VARE_UNDEFERR cannot
have any effect in that case.
VARE_KEEP_DOLLAR is actively ignored by ParseModifierPart. In cases
where VARE_WANTRES is not set, this means that VARE_NONE can be passed,
which is easier to grasp than any bitset operations. This also gets rid
of a few type casts from enum to unsigned int that were necessary to
pass WARNS=6.
To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/usr.bin/make/cond.c
cvs rdiff -u -r1.680 -r1.681 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.185 src/usr.bin/make/cond.c:1.186
--- src/usr.bin/make/cond.c:1.185 Sat Nov 7 20:39:56 2020
+++ src/usr.bin/make/cond.c Sun Nov 8 19:24:19 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.185 2020/11/07 20:39:56 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.186 2020/11/08 19:24:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.185 2020/11/07 20:39:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.186 2020/11/08 19:24:19 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -248,7 +248,8 @@ ParseFuncArg(const char **pp, Boolean do
* though perhaps we should...
*/
void *nestedVal_freeIt;
- VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0);
+ VarEvalFlags eflags = doEval ? VARE_WANTRES | VARE_UNDEFERR
+ : VARE_NONE;
const char *nestedVal;
(void)Var_Parse(&p, VAR_CMDLINE, eflags, &nestedVal,
&nestedVal_freeIt);
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.680 src/usr.bin/make/var.c:1.681
--- src/usr.bin/make/var.c:1.680 Sun Nov 8 18:27:14 2020
+++ src/usr.bin/make/var.c Sun Nov 8 19:24:19 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.680 2020/11/08 18:27:14 rillig Exp $ */
+/* $NetBSD: var.c,v 1.681 2020/11/08 19:24:19 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.680 2020/11/08 18:27:14 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.681 2020/11/08 19:24:19 rillig Exp $");
#define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
#define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -2068,13 +2068,12 @@ ApplyModifier_Loop(const char **pp, Appl
{
struct ModifyWord_LoopArgs args;
char prev_sep;
- VarEvalFlags eflags = st->eflags & ~(unsigned)VARE_WANTRES;
VarParseResult res;
args.ctx = st->ctxt;
(*pp)++; /* Skip the first '@' */
- res = ParseModifierPart(pp, '@', eflags, st,
+ res = ParseModifierPart(pp, '@', VARE_NONE, st,
&args.tvar, NULL, NULL, NULL);
if (res != VPR_OK)
return AMR_CLEANUP;
@@ -2086,12 +2085,12 @@ ApplyModifier_Loop(const char **pp, Appl
return AMR_CLEANUP;
}
- res = ParseModifierPart(pp, '@', eflags, st,
+ res = ParseModifierPart(pp, '@', VARE_NONE, st,
&args.str, NULL, NULL, NULL);
if (res != VPR_OK)
return AMR_CLEANUP;
- args.eflags = st->eflags & (VARE_UNDEFERR | VARE_WANTRES);
+ args.eflags = st->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
prev_sep = st->sep;
st->sep = ' '; /* XXX: should be st->sep for consistency */
st->newVal = ModifyWords(st->val, ModifyWord_Loop, &args,
@@ -2110,11 +2109,10 @@ ApplyModifier_Defined(const char **pp, A
Buffer buf;
const char *p;
- VarEvalFlags eflags = st->eflags & ~(unsigned)VARE_WANTRES;
- if (st->eflags & VARE_WANTRES) {
+ VarEvalFlags eflags = VARE_NONE;
+ if (st->eflags & VARE_WANTRES)
if ((**pp == 'D') == !(st->exprFlags & VEF_UNDEF))
- eflags |= VARE_WANTRES;
- }
+ eflags = st->eflags;
Buf_Init(&buf);
p = *pp + 1;
@@ -2873,16 +2871,16 @@ ApplyModifier_IfElse(const char **pp, Ap
VarParseResult res;
Boolean value = FALSE;
- VarEvalFlags then_eflags = st->eflags & ~(unsigned)VARE_WANTRES;
- VarEvalFlags else_eflags = st->eflags & ~(unsigned)VARE_WANTRES;
+ VarEvalFlags then_eflags = VARE_NONE;
+ VarEvalFlags else_eflags = VARE_NONE;
int cond_rc = COND_PARSE; /* anything other than COND_INVALID */
if (st->eflags & VARE_WANTRES) {
cond_rc = Cond_EvalCondition(st->v->name, &value);
if (cond_rc != COND_INVALID && value)
- then_eflags |= VARE_WANTRES;
+ then_eflags = st->eflags;
if (cond_rc != COND_INVALID && !value)
- else_eflags |= VARE_WANTRES;
+ else_eflags = st->eflags;
}
(*pp)++; /* skip past the '?' */