Module Name: src
Committed By: rillig
Date: Tue Feb 14 21:08:00 UTC 2023
Modified Files:
src/usr.bin/make: arch.c cond.c make.h parse.c suff.c var.c
Log Message:
make: reduce complexity of evaluating expressions
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/usr.bin/make/arch.c
cvs rdiff -u -r1.343 -r1.344 src/usr.bin/make/cond.c
cvs rdiff -u -r1.311 -r1.312 src/usr.bin/make/make.h
cvs rdiff -u -r1.692 -r1.693 src/usr.bin/make/parse.c
cvs rdiff -u -r1.366 -r1.367 src/usr.bin/make/suff.c
cvs rdiff -u -r1.1041 -r1.1042 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/arch.c
diff -u src/usr.bin/make/arch.c:1.212 src/usr.bin/make/arch.c:1.213
--- src/usr.bin/make/arch.c:1.212 Wed Dec 7 10:28:48 2022
+++ src/usr.bin/make/arch.c Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.212 2022/12/07 10:28:48 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.213 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
#include "config.h"
/* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: arch.c,v 1.212 2022/12/07 10:28:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.213 2023/02/14 21:08:00 rillig Exp $");
typedef struct List ArchList;
typedef struct ListNode ArchListNode;
@@ -221,8 +221,7 @@ Arch_ParseArchive(char **pp, GNodeList *
bool isError;
/* XXX: is expanded twice: once here and once below */
- (void)Var_Parse(&nested_p, scope,
- VARE_UNDEFERR, &result);
+ result = Var_Parse(&nested_p, scope, VARE_UNDEFERR);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
@@ -260,8 +259,8 @@ Arch_ParseArchive(char **pp, GNodeList *
bool isError;
const char *nested_p = cp;
- (void)Var_Parse(&nested_p, scope,
- VARE_UNDEFERR, &result);
+ result = Var_Parse(&nested_p, scope,
+ VARE_UNDEFERR);
/* TODO: handle errors */
isError = result.str == var_Error;
FStr_Done(&result);
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.343 src/usr.bin/make/cond.c:1.344
--- src/usr.bin/make/cond.c:1.343 Tue Feb 14 20:49:09 2023
+++ src/usr.bin/make/cond.c Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -92,7 +92,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $");
/*
* Conditional expressions conform to this grammar:
@@ -235,8 +235,7 @@ ParseWord(const char **pp, bool doEval)
VarEvalMode emode = doEval
? VARE_UNDEFERR
: VARE_PARSE_ONLY;
- FStr nestedVal;
- (void)Var_Parse(&p, SCOPE_CMDLINE, emode, &nestedVal);
+ FStr nestedVal = Var_Parse(&p, SCOPE_CMDLINE, emode);
/* TODO: handle errors */
Buf_AddStr(&word, nestedVal.str);
FStr_Done(&nestedVal);
@@ -401,7 +400,7 @@ CondParser_StringExpr(CondParser *par, c
p = par->p;
atStart = p == start;
- (void)Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str);
+ *inout_str = Var_Parse(&p, SCOPE_CMDLINE, emode);
/* TODO: handle errors */
if (inout_str->str == var_Error) {
FStr_Done(inout_str);
@@ -675,8 +674,8 @@ CondParser_FuncCallEmpty(CondParser *par
return false;
cp--; /* Make cp[1] point to the '('. */
- (void)Var_Parse(&cp, SCOPE_CMDLINE,
- doEval ? VARE_WANTRES : VARE_PARSE_ONLY, &val);
+ val = Var_Parse(&cp, SCOPE_CMDLINE,
+ doEval ? VARE_WANTRES : VARE_PARSE_ONLY);
/* TODO: handle errors */
if (val.str == var_Error)
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.311 src/usr.bin/make/make.h:1.312
--- src/usr.bin/make/make.h:1.311 Thu Jan 26 20:48:17 2023
+++ src/usr.bin/make/make.h Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: make.h,v 1.311 2023/01/26 20:48:17 sjg Exp $ */
+/* $NetBSD: make.h,v 1.312 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -1017,7 +1017,7 @@ bool Var_Exists(GNode *, const char *) M
bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE;
FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
-VarParseResult Var_Parse(const char **, GNode *, VarEvalMode, FStr *);
+FStr Var_Parse(const char **, GNode *, VarEvalMode);
VarParseResult Var_Subst(const char *, GNode *, VarEvalMode, char **);
void Var_Expand(FStr *, GNode *, VarEvalMode);
void Var_Stats(void);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.692 src/usr.bin/make/parse.c:1.693
--- src/usr.bin/make/parse.c:1.692 Tue Jan 24 00:24:02 2023
+++ src/usr.bin/make/parse.c Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $");
/*
* A file being read.
@@ -897,10 +897,8 @@ ParseDependencyTargetWord(char **pp, con
* have been discovered in the initial Var_Subst and
* we wouldn't be here.
*/
- FStr val;
-
- (void)Var_Parse(&cp, SCOPE_CMDLINE,
- VARE_PARSE_ONLY, &val);
+ FStr val = Var_Parse(&cp, SCOPE_CMDLINE,
+ VARE_PARSE_ONLY);
FStr_Done(&val);
} else
cp++;
Index: src/usr.bin/make/suff.c
diff -u src/usr.bin/make/suff.c:1.366 src/usr.bin/make/suff.c:1.367
--- src/usr.bin/make/suff.c:1.366 Fri Mar 4 23:17:16 2022
+++ src/usr.bin/make/suff.c Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: suff.c,v 1.366 2022/03/04 23:17:16 sjg Exp $ */
+/* $NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
#include "dir.h"
/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.366 2022/03/04 23:17:16 sjg Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $");
typedef List SuffixList;
typedef ListNode SuffixListNode;
@@ -1312,9 +1312,7 @@ ExpandChildrenRegular(char *cp, GNode *p
} else if (*cp == '$') {
/* Skip over the variable expression. */
const char *nested_p = cp;
- FStr junk;
-
- (void)Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY, &junk);
+ FStr junk = Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY);
/* TODO: handle errors */
if (junk.str == var_Error) {
Parse_Error(PARSE_FATAL,
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.1041 src/usr.bin/make/var.c:1.1042
--- src/usr.bin/make/var.c:1.1041 Mon Feb 13 19:25:15 2023
+++ src/usr.bin/make/var.c Tue Feb 14 21:08:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.1041 2023/02/13 19:25:15 rillig Exp $ */
+/* $NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1041 2023/02/13 19:25:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $");
/*
* Variables are defined using one of the VAR=value assignments. Their
@@ -2145,10 +2145,8 @@ ParseModifierPartExpr(const char **pp, L
VarEvalMode emode)
{
const char *p = *pp;
- FStr nested_val;
-
- (void)Var_Parse(&p, ch->expr->scope,
- VarEvalMode_WithoutKeepDollar(emode), &nested_val);
+ FStr nested_val = Var_Parse(&p, ch->expr->scope,
+ VarEvalMode_WithoutKeepDollar(emode));
/* TODO: handle errors */
LazyBuf_AddStr(part, nested_val.str);
FStr_Done(&nested_val);
@@ -2500,11 +2498,8 @@ ParseModifier_Defined(const char **pp, M
/* Nested variable expression */
if (*p == '$') {
- FStr val;
-
- (void)Var_Parse(&p, ch->expr->scope,
- shouldEval ? ch->expr->emode : VARE_PARSE_ONLY,
- &val);
+ FStr val = Var_Parse(&p, ch->expr->scope,
+ shouldEval ? ch->expr->emode : VARE_PARSE_ONLY);
/* TODO: handle errors */
if (shouldEval)
LazyBuf_AddStr(buf, val.str);
@@ -3893,9 +3888,7 @@ ApplyModifiersIndirect(ModChain *ch, con
{
Expr *expr = ch->expr;
const char *p = *pp;
- FStr mods;
-
- (void)Var_Parse(&p, expr->scope, expr->emode, &mods);
+ FStr mods = Var_Parse(&p, expr->scope, expr->emode);
/* TODO: handle errors */
if (mods.str[0] != '\0' && !IsDelimiter(*p, ch)) {
@@ -4170,8 +4163,7 @@ ParseVarname(const char **pp, char start
/* A variable inside a variable, expand. */
if (*p == '$') {
- FStr nested_val;
- (void)Var_Parse(&p, scope, emode, &nested_val);
+ FStr nested_val = Var_Parse(&p, scope, emode);
/* TODO: handle errors */
LazyBuf_AddStr(buf, nested_val.str);
FStr_Done(&nested_val);
@@ -4212,7 +4204,7 @@ IsShortVarnameValid(char varname, const
static bool
ParseVarnameShort(char varname, const char **pp, GNode *scope,
VarEvalMode emode,
- VarParseResult *out_false_res, const char **out_false_val,
+ const char **out_false_val,
Var **out_true_var)
{
char name[2];
@@ -4221,7 +4213,6 @@ ParseVarnameShort(char varname, const ch
if (!IsShortVarnameValid(varname, *pp)) {
(*pp)++; /* only skip the '$' */
- *out_false_res = VPR_ERR;
*out_false_val = var_Error;
return false;
}
@@ -4244,22 +4235,8 @@ ParseVarnameShort(char varname, const ch
if (opts.strict && val == var_Error) {
Parse_Error(PARSE_FATAL,
"Variable \"%s\" is undefined", name);
- *out_false_res = VPR_ERR;
- *out_false_val = val;
- return false;
}
- /*
- * XXX: This looks completely wrong.
- *
- * If undefined expressions are not allowed, this should
- * rather be VPR_ERR instead of VPR_UNDEF, together with an
- * error message.
- *
- * If undefined expressions are allowed, this should rather
- * be VPR_UNDEF instead of VPR_OK.
- */
- *out_false_res = emode == VARE_UNDEFERR ? VPR_UNDEF : VPR_OK;
*out_false_val = val;
return false;
}
@@ -4498,23 +4475,23 @@ Var_Parse_FastLane(const char **pp, VarE
* point to some random character in the string, to the
* location of the parse error, or at the end of the
* string.
- * *out_val The value of the variable expression, never NULL.
- * *out_val var_Error if there was a parse error.
- * *out_val var_Error if the base variable of the expression was
+ * return The value of the variable expression, never NULL.
+ * return var_Error if there was a parse error.
+ * return var_Error if the base variable of the expression was
* undefined, emode is VARE_UNDEFERR, and none of
* the modifiers turned the undefined expression into a
* defined expression.
* XXX: It is not guaranteed that an error message has
* been printed.
- * *out_val varUndefined if the base variable of the expression
+ * return varUndefined if the base variable of the expression
* was undefined, emode was not VARE_UNDEFERR,
* and none of the modifiers turned the undefined
* expression into a defined expression.
* XXX: It is not guaranteed that an error message has
* been printed.
*/
-VarParseResult
-Var_Parse(const char **pp, GNode *scope, VarEvalMode emode, FStr *out_val)
+FStr
+Var_Parse(const char **pp, GNode *scope, VarEvalMode emode)
{
const char *p = *pp;
const char *const start = p;
@@ -4532,15 +4509,16 @@ Var_Parse(const char **pp, GNode *scope,
Var *v;
Expr expr = Expr_Literal(NULL, FStr_InitRefer(NULL), emode,
scope, DEF_REGULAR);
+ FStr val;
- if (Var_Parse_FastLane(pp, emode, out_val))
- return VPR_OK;
+ if (Var_Parse_FastLane(pp, emode, &val))
+ return val;
/* TODO: Reduce computations in parse-only mode. */
DEBUG2(VAR, "Var_Parse: %s (%s)\n", start, VarEvalMode_Name[emode]);
- *out_val = FStr_InitRefer(NULL);
+ val = FStr_InitRefer(NULL);
extramodifiers = NULL; /* extra modifiers to apply first */
dynamic = false;
@@ -4548,19 +4526,17 @@ Var_Parse(const char **pp, GNode *scope,
startc = p[1];
if (startc != '(' && startc != '{') {
- VarParseResult res;
- if (!ParseVarnameShort(startc, pp, scope, emode, &res,
- &out_val->str, &v))
- return res;
+ if (!ParseVarnameShort(startc, pp, scope, emode, &val.str, &v))
+ return val;
haveModifier = false;
p++;
} else {
VarParseResult res;
if (!ParseVarnameLong(&p, startc, scope, emode,
- pp, &res, out_val,
+ pp, &res, &val,
&endc, &v, &haveModifier, &extramodifiers,
&dynamic, &expr.defined))
- return res;
+ return val;
}
expr.name = v->name.str;
@@ -4642,8 +4618,7 @@ Var_Parse(const char **pp, GNode *scope,
VarFreeShortLived(v);
}
- *out_val = expr.value;
- return VPR_OK; /* XXX: Is not correct in all cases */
+ return expr.value;
}
static void
@@ -4662,9 +4637,7 @@ VarSubstExpr(const char **pp, Buffer *bu
{
const char *p = *pp;
const char *nested_p = p;
- FStr val;
-
- (void)Var_Parse(&nested_p, scope, emode, &val);
+ FStr val = Var_Parse(&nested_p, scope, emode);
/* TODO: handle errors */
if (val.str == var_Error || val.str == varUndefined) {