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: rename ApplyModifiersState to ModChain
details: https://anonhg.NetBSD.org/src/rev/9624eb2b084e
branches: trunk
changeset: 953673:9624eb2b084e
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Mar 15 20:00:50 2021 +0000
description:
make: rename ApplyModifiersState to ModChain
The new name accurately describes the structural element that holds such
properties as the separator character and whether the expression value
is considered a single word. The old name ApplyModifiersState was too
long and was meant as a placeholder anyway, when I introduced it in
var.c 1.236 from 2020-07-03.
diffstat:
usr.bin/make/unit-tests/varmod-indirect.mk | 4 +-
usr.bin/make/var.c | 422 ++++++++++++++--------------
2 files changed, 213 insertions(+), 213 deletions(-)
diffs (truncated from 1265 to 300 lines):
diff -r d05aa224a332 -r 9624eb2b084e usr.bin/make/unit-tests/varmod-indirect.mk
--- a/usr.bin/make/unit-tests/varmod-indirect.mk Mon Mar 15 19:48:51 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-indirect.mk Mon Mar 15 20:00:50 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-indirect.mk,v 1.8 2021/02/14 17:47:33 rillig Exp $
+# $NetBSD: varmod-indirect.mk,v 1.9 2021/03/15 20:00:50 rillig Exp $
#
# Tests for indirect variable modifiers, such as in ${VAR:${M_modifiers}}.
# These can be used for very basic purposes like converting a string to either
@@ -221,7 +221,7 @@
# the ':M' since that is not part of the text from the indirect modifier.
#
# Implementation detail: when ApplyModifiersIndirect calls ApplyModifiers
-# (which creates a new ApplyModifiersState containing a fresh separator),
+# (which creates a new ModChain containing a fresh separator),
# the outer separator character is not passed by reference to the inner
# evaluation, therefore the scope of the inner separator ends after applying
# the modifier ':ts*'.
diff -r d05aa224a332 -r 9624eb2b084e usr.bin/make/var.c
--- a/usr.bin/make/var.c Mon Mar 15 19:48:51 2021 +0000
+++ b/usr.bin/make/var.c Mon Mar 15 20:00:50 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.890 2021/03/15 19:15:04 rillig Exp $ */
+/* $NetBSD: var.c,v 1.891 2021/03/15 20:00:50 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -140,7 +140,7 @@
#include "metachar.h"
/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.890 2021/03/15 19:15:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.891 2021/03/15 20:00:50 rillig Exp $");
typedef enum VarFlags {
VFL_NONE = 0,
@@ -1831,7 +1831,7 @@
for (i = 0; i < words.len; i++) {
if (i != 0) {
- /* XXX: Use st->sep instead of ' ', for consistency. */
+ /* XXX: Use ch->sep instead of ' ', for consistency. */
Buf_AddByte(&buf, ' ');
}
Buf_AddStr(&buf, words.words[i]);
@@ -1978,7 +1978,7 @@
*
* If parsing succeeds, the parsing position *pp is updated to point to the
* first character following the modifier, which typically is either ':' or
- * st->endc. The modifier doesn't have to check for this delimiter character,
+ * ch->endc. The modifier doesn't have to check for this delimiter character,
* this is done by ApplyModifiers.
*
* XXX: As of 2020-11-15, some modifiers such as :S, :C, :P, :L do not
@@ -2012,7 +2012,7 @@
* Some modifiers such as ':sh' or '::=' have noticeable side effects though.
*
* Evaluating the modifier usually takes the current value of the variable
- * expression from st->expr->value, or the variable name from st->var->name
+ * expression from ch->expr->value, or the variable name from ch->var->name
* and stores the result back in expr->value via Expr_SetValueOwn or
* Expr_SetValueRefer.
*
@@ -2079,7 +2079,7 @@
*
* See varmod-indirect.mk.
*/
-typedef struct ApplyModifiersState {
+typedef struct ModChain {
Expr *expr;
/* '\0' or '{' or '(' */
const char startc;
@@ -2093,7 +2093,7 @@
* big word, possibly containing spaces.
*/
Boolean oneBigWord;
-} ApplyModifiersState;
+} ModChain;
static void
Expr_Define(Expr *expr)
@@ -2148,7 +2148,7 @@
const char **pp,
char delim,
VarEvalFlags eflags,
- ApplyModifiersState *st,
+ ModChain *ch,
char **out_part,
/* Optionally stores the length of the returned string, just to save
* another strlen call. */
@@ -2204,7 +2204,7 @@
VarEvalFlags nested_eflags = eflags;
nested_eflags.keepDollar = FALSE;
- (void)Var_Parse(&nested_p, st->expr->scope,
+ (void)Var_Parse(&nested_p, ch->expr->scope,
nested_eflags, &nested_val);
/* TODO: handle errors */
Buf_AddStr(&buf, nested_val.str);
@@ -2255,7 +2255,7 @@
if (*p != delim) {
*pp = p;
Error("Unfinished modifier for \"%s\" ('%c' missing)",
- st->expr->var->name.str, delim);
+ ch->expr->var->name.str, delim);
*out_part = NULL;
return VPR_ERR;
}
@@ -2288,35 +2288,35 @@
char delim,
/* Flags for evaluating nested variables. */
VarEvalFlags eflags,
- ApplyModifiersState *st,
+ ModChain *ch,
char **out_part
)
{
- return ParseModifierPartSubst(pp, delim, eflags, st, out_part,
+ return ParseModifierPartSubst(pp, delim, eflags, ch, out_part,
NULL, NULL, NULL);
}
MAKE_INLINE Boolean
-IsDelimiter(char ch, const ApplyModifiersState *st)
+IsDelimiter(char c, const ModChain *ch)
{
- return ch == ':' || ch == st->endc;
+ return c == ':' || c == ch->endc;
}
/* Test whether mod starts with modname, followed by a delimiter. */
MAKE_INLINE Boolean
-ModMatch(const char *mod, const char *modname, const ApplyModifiersState *st)
+ModMatch(const char *mod, const char *modname, const ModChain *ch)
{
size_t n = strlen(modname);
- return strncmp(mod, modname, n) == 0 && IsDelimiter(mod[n], st);
+ return strncmp(mod, modname, n) == 0 && IsDelimiter(mod[n], ch);
}
/* Test whether mod starts with modname, followed by a delimiter or '='. */
MAKE_INLINE Boolean
-ModMatchEq(const char *mod, const char *modname, const ApplyModifiersState *st)
+ModMatchEq(const char *mod, const char *modname, const ModChain *ch)
{
size_t n = strlen(modname);
return strncmp(mod, modname, n) == 0 &&
- (IsDelimiter(mod[n], st) || mod[n] == '=');
+ (IsDelimiter(mod[n], ch) || mod[n] == '=');
}
static Boolean
@@ -2387,18 +2387,18 @@
* result back in the expression.
*/
static void
-ModifyWords(ApplyModifiersState *st,
+ModifyWords(ModChain *ch,
ModifyWordProc modifyWord, void *modifyWord_args,
Boolean oneBigWord)
{
- Expr *expr = st->expr;
+ Expr *expr = ch->expr;
const char *val = expr->value.str;
SepBuf result;
Words words;
size_t i;
if (oneBigWord) {
- SepBuf_Init(&result, st->sep);
+ SepBuf_Init(&result, ch->sep);
modifyWord(val, &result, modifyWord_args);
goto done;
}
@@ -2408,7 +2408,7 @@
DEBUG2(VAR, "ModifyWords: split \"%s\" into %u words\n",
val, (unsigned)words.len);
- SepBuf_Init(&result, st->sep);
+ SepBuf_Init(&result, ch->sep);
for (i = 0; i < words.len; i++) {
modifyWord(words.words[i], &result, modifyWord_args);
if (result.buf.len > 0)
@@ -2423,9 +2423,9 @@
/* :@var@...${var}...@ */
static ApplyModifierResult
-ApplyModifier_Loop(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Loop(const char **pp, ModChain *ch)
{
- Expr *expr = st->expr;
+ Expr *expr = ch->expr;
struct ModifyWord_LoopArgs args;
char prev_sep;
VarParseResult res;
@@ -2433,7 +2433,7 @@
args.scope = expr->scope;
(*pp)++; /* Skip the first '@' */
- res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, st, &args.tvar);
+ res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, ch, &args.tvar);
if (res != VPR_OK)
return AMR_CLEANUP;
if (opts.strict && strchr(args.tvar, '$') != NULL) {
@@ -2444,7 +2444,7 @@
return AMR_CLEANUP;
}
- res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, st, &args.str);
+ res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, ch, &args.str);
if (res != VPR_OK)
return AMR_CLEANUP;
@@ -2453,10 +2453,10 @@
args.eflags = expr->eflags;
args.eflags.keepDollar = FALSE;
- prev_sep = st->sep;
- st->sep = ' '; /* XXX: should be st->sep for consistency */
- ModifyWords(st, ModifyWord_Loop, &args, st->oneBigWord);
- st->sep = prev_sep;
+ prev_sep = ch->sep;
+ ch->sep = ' '; /* XXX: should be ch->sep for consistency */
+ ModifyWords(ch, ModifyWord_Loop, &args, ch->oneBigWord);
+ ch->sep = prev_sep;
/* XXX: Consider restoring the previous variable instead of deleting. */
/*
* XXX: The variable name should not be expanded here, see
@@ -2472,9 +2472,9 @@
/* :Ddefined or :Uundefined */
static ApplyModifierResult
-ApplyModifier_Defined(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Defined(const char **pp, ModChain *ch)
{
- Expr *expr = st->expr;
+ Expr *expr = ch->expr;
Buffer buf;
const char *p;
@@ -2485,7 +2485,7 @@
Buf_Init(&buf);
p = *pp + 1;
- while (!IsDelimiter(*p, st) && *p != '\0') {
+ while (!IsDelimiter(*p, ch) && *p != '\0') {
/* XXX: This code is similar to the one in Var_Parse.
* See if the code can be merged.
@@ -2495,7 +2495,7 @@
/* See Buf_AddEscaped in for.c. */
if (*p == '\\') {
char c = p[1];
- if (IsDelimiter(c, st) || c == '$' || c == '\\') {
+ if (IsDelimiter(c, ch) || c == '$' || c == '\\') {
Buf_AddByte(&buf, c);
p += 2;
continue;
@@ -2532,9 +2532,9 @@
/* :L */
static ApplyModifierResult
-ApplyModifier_Literal(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Literal(const char **pp, ModChain *ch)
{
- Expr *expr = st->expr;
+ Expr *expr = ch->expr;
(*pp)++;
@@ -2567,12 +2567,12 @@
/* :gmtime */
static ApplyModifierResult
-ApplyModifier_Gmtime(const char **pp, ApplyModifiersState *st)
+ApplyModifier_Gmtime(const char **pp, ModChain *ch)
{
time_t utc;
const char *mod = *pp;
- if (!ModMatchEq(mod, "gmtime", st))
+ if (!ModMatchEq(mod, "gmtime", ch))
return AMR_UNKNOWN;
if (mod[6] == '=') {
@@ -2588,21 +2588,21 @@
*pp = mod + 6;
}
- if (st->expr->eflags.wantRes)
- Expr_SetValueOwn(st->expr,
- VarStrftime(st->expr->value.str, TRUE, utc));
+ if (ch->expr->eflags.wantRes)
+ Expr_SetValueOwn(ch->expr,
+ VarStrftime(ch->expr->value.str, TRUE, utc));
return AMR_OK;
}
/* :localtime */
Home |
Main Index |
Thread Index |
Old Index