make: rename Var_Set to Var_SetExpand

After doing the textual renaming across all files, I added a new
function Var_Set that does not expand the variable name.  I then undid
the renaming for all calls where the variable name cannot ever contain a
dollar sign.  I omitted the word "Expand" from the textual references in
the unit tests and in the debug logging messages since the focus is
usually on the "Set" part, not on the "Expand".

No functional change.
This commit is contained in:
rillig 2021-02-04 19:00:45 +00:00
parent b3b412abe7
commit 8660931fea
3 changed files with 26 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nonints.h,v 1.196 2021/02/03 15:08:17 rillig Exp $ */
/* $NetBSD: nonints.h,v 1.197 2021/02/04 19:00:45 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -374,6 +374,7 @@ void Var_Undef(const char *);
void Global_Set(const char *, const char *);
void Global_SetExpand(const char *, const char *);
void Var_Set(const char *, const char *, GNode *);
void Var_SetExpand(const char *, const char *, GNode *);
void Var_SetWithFlags(const char *, const char *, GNode *, VarSetFlags);
void Var_Append(const char *, const char *, GNode *);
void Var_AppendExpand(const char *, const char *, GNode *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: parse.c,v 1.543 2021/02/03 14:33:09 rillig Exp $ */
/* $NetBSD: parse.c,v 1.544 2021/02/04 19:00:45 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -109,7 +109,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: parse.c,v 1.543 2021/02/03 14:33:09 rillig Exp $");
MAKE_RCSID("$NetBSD: parse.c,v 1.544 2021/02/04 19:00:45 rillig Exp $");
/* types and constants */
@ -1898,13 +1898,13 @@ VarAssign_EvalSubst(const char *name, const char *uvalue, GNode *ctxt,
* apart from making the debug log longer.
*/
if (!Var_ExistsExpand(name, ctxt))
Var_Set(name, "", ctxt);
Var_SetExpand(name, "", ctxt);
(void)Var_Subst(uvalue, ctxt,
VARE_WANTRES | VARE_KEEP_DOLLAR | VARE_KEEP_UNDEF, &evalue);
/* TODO: handle errors */
Var_Set(name, evalue, ctxt);
Var_SetExpand(name, evalue, ctxt);
*out_avalue = FStr_InitOwn(evalue);
}
@ -1927,7 +1927,7 @@ VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt,
}
cmdOut = Cmd_Exec(cmd.str, &errfmt);
Var_Set(name, cmdOut, ctxt);
Var_SetExpand(name, cmdOut, ctxt);
*out_avalue = FStr_InitOwn(cmdOut);
if (errfmt != NULL)
@ -1964,7 +1964,7 @@ VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue,
return FALSE;
/* Normal assignment -- just do it. */
Var_Set(name, uvalue, ctxt);
Var_SetExpand(name, uvalue, ctxt);
}
*out_TRUE_avalue = avalue;

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.797 2021/02/03 15:08:17 rillig Exp $ */
/* $NetBSD: var.c,v 1.798 2021/02/04 19:00:45 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -80,7 +80,9 @@
*
* Var_End Clean up the module.
*
* Var_Set Set the value of the variable, creating it if
* Var_Set
* Var_SetExpand
* Set the value of the variable, creating it if
* necessary.
*
* Var_Append
@ -137,7 +139,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
MAKE_RCSID("$NetBSD: var.c,v 1.797 2021/02/03 15:08:17 rillig Exp $");
MAKE_RCSID("$NetBSD: var.c,v 1.798 2021/02/04 19:00:45 rillig Exp $");
typedef enum VarFlags {
VAR_NONE = 0,
@ -1026,6 +1028,12 @@ Var_SetWithFlags(const char *name, const char *val, GNode *ctxt,
FStr_Done(&varname);
}
void
Var_Set(const char *name, const char *val, GNode *ctxt)
{
SetVar(name, val, ctxt, VAR_SET_NONE);
}
/*
* Set the variable name to the value val in the given context.
*
@ -1038,7 +1046,7 @@ Var_SetWithFlags(const char *name, const char *val, GNode *ctxt,
* ctxt context in which to set it
*/
void
Var_Set(const char *name, const char *val, GNode *ctxt)
Var_SetExpand(const char *name, const char *val, GNode *ctxt)
{
Var_SetWithFlags(name, val, ctxt, VAR_SET_NONE);
}
@ -1052,7 +1060,7 @@ Global_Set(const char *name, const char *value)
void
Global_SetExpand(const char *name, const char *value)
{
Var_Set(name, value, VAR_GLOBAL);
Var_SetExpand(name, value, VAR_GLOBAL);
}
/*
@ -3282,6 +3290,7 @@ ok:
(*pp)--;
/* XXX: Expanding the variable name at this point sounds wrong. */
if (st->eflags & VARE_WANTRES) {
switch (op[0]) {
case '+':
@ -3293,7 +3302,8 @@ ok:
if (errfmt != NULL)
Error(errfmt, val);
else
Var_Set(st->var->name.str, cmd_output, ctxt);
Var_SetExpand(st->var->name.str, cmd_output,
ctxt);
free(cmd_output);
break;
}
@ -3302,7 +3312,7 @@ ok:
break;
/* FALLTHROUGH */
default:
Var_Set(st->var->name.str, val, ctxt);
Var_SetExpand(st->var->name.str, val, ctxt);
break;
}
}
@ -3326,7 +3336,7 @@ ApplyModifier_Remember(const char **pp, const char *val,
if (mod[1] == '=') {
size_t n = strcspn(mod + 2, ":)}");
char *name = bmake_strldup(mod + 2, n);
Var_Set(name, val, st->ctxt);
Var_SetExpand(name, val, st->ctxt);
free(name);
*pp = mod + 2 + n;
} else {