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(1): eliminate ApplyModifiersState.tstr



details:   https://anonhg.NetBSD.org/src/rev/0a5eb190ff0a
branches:  trunk
changeset: 936281:0a5eb190ff0a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 24 07:24:21 2020 +0000

description:
make(1): eliminate ApplyModifiersState.tstr

This field always pointed to the beginning of the current modifier.
Therefore a better name is "mod", and there is no need to store it in the
shared state.

diffstat:

 usr.bin/make/var.c |  303 +++++++++++++++++++++++++---------------------------
 1 files changed, 148 insertions(+), 155 deletions(-)

diffs (truncated from 826 to 300 lines):

diff -r 7a427ef21ac2 -r 0a5eb190ff0a usr.bin/make/var.c
--- a/usr.bin/make/var.c        Fri Jul 24 06:12:21 2020 +0000
+++ b/usr.bin/make/var.c        Fri Jul 24 07:24:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.298 2020/07/23 20:24:22 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.299 2020/07/24 07:24:21 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.298 2020/07/23 20:24:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.299 2020/07/24 07:24:21 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.298 2020/07/23 20:24:22 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.299 2020/07/24 07:24:21 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2081,7 +2081,6 @@
 
     /* read-write */
     char *nstr;
-    const char *tstr;
     const char *start;
     const char *cp;            /* Secondary pointer into str (place marker
                                 * for tstr) */
@@ -2104,11 +2103,11 @@
 
 /* :@var@...${var}...@ */
 static Boolean
-ApplyModifier_Loop(ApplyModifiersState *st) {
+ApplyModifier_Loop(const char *mod, ApplyModifiersState *st) {
     ModifyWord_LoopArgs args;
 
     args.ctx = st->ctxt;
-    st->cp = ++st->tstr;
+    st->cp = mod + 1;
     char delim = '@';
     args.tvar = ParseModifierPart(st->ctxt, &st->cp, delim,
                                  st->eflags | VARE_NOSUBST,
@@ -2142,14 +2141,14 @@
 
 /* :Ddefined or :Uundefined */
 static void
-ApplyModifier_Defined(ApplyModifiersState *st)
+ApplyModifier_Defined(const char *mod, ApplyModifiersState *st)
 {
     Buffer buf;                        /* Buffer for patterns */
     VarEvalFlags neflags;
 
     if (st->eflags & VARE_WANTRES) {
        Boolean wantres;
-       if (*st->tstr == 'U')
+       if (*mod == 'U')
            wantres = ((st->v->flags & VAR_JUNK) != 0);
        else
            wantres = ((st->v->flags & VAR_JUNK) == 0);
@@ -2167,7 +2166,7 @@
      * The result is left in the Buffer buf.
      */
     Buf_Init(&buf, 0);
-    for (st->cp = st->tstr + 1;
+    for (st->cp = mod + 1;
         *st->cp != st->endc && *st->cp != ':' && *st->cp != '\0';
         st->cp++) {
        if (*st->cp == '\\' &&
@@ -2207,20 +2206,20 @@
 
 /* :gmtime */
 static Boolean
-ApplyModifier_Gmtime(ApplyModifiersState *st)
+ApplyModifier_Gmtime(const char *mod, ApplyModifiersState *st)
 {
     time_t utc;
     char *ep;
 
-    st->cp = st->tstr + 1;     /* make sure it is set */
-    if (!STRMOD_MATCHX(st->tstr, "gmtime", 6))
+    st->cp = mod + 1;          /* make sure it is set */
+    if (!STRMOD_MATCHX(mod, "gmtime", 6))
        return FALSE;
-    if (st->tstr[6] == '=') {
-       utc = strtoul(&st->tstr[7], &ep, 10);
+    if (mod[6] == '=') {
+       utc = strtoul(mod + 7, &ep, 10);
        st->cp = ep;
     } else {
        utc = 0;
-       st->cp = st->tstr + 6;
+       st->cp = mod + 6;
     }
     st->newStr = VarStrftime(st->nstr, 1, utc);
     st->termc = *st->cp;
@@ -2229,21 +2228,21 @@
 
 /* :localtime */
 static Boolean
-ApplyModifier_Localtime(ApplyModifiersState *st)
+ApplyModifier_Localtime(const char *mod, ApplyModifiersState *st)
 {
     time_t utc;
     char *ep;
 
-    st->cp = st->tstr + 1;     /* make sure it is set */
-    if (!STRMOD_MATCHX(st->tstr, "localtime", 9))
+    st->cp = mod + 1;  /* make sure it is set */
+    if (!STRMOD_MATCHX(mod, "localtime", 9))
        return FALSE;
 
-    if (st->tstr[9] == '=') {
-       utc = strtoul(&st->tstr[10], &ep, 10);
+    if (mod[9] == '=') {
+       utc = strtoul(mod + 10, &ep, 10);
        st->cp = ep;
     } else {
        utc = 0;
-       st->cp = st->tstr + 9;
+       st->cp = mod + 9;
     }
     st->newStr = VarStrftime(st->nstr, 0, utc);
     st->termc = *st->cp;
@@ -2252,26 +2251,24 @@
 
 /* :hash */
 static Boolean
-ApplyModifier_Hash(ApplyModifiersState *st)
+ApplyModifier_Hash(const char *mod, ApplyModifiersState *st)
 {
-    st->cp = st->tstr + 1;     /* make sure it is set */
-    if (!STRMOD_MATCH(st->tstr, "hash", 4))
+    st->cp = mod + 1;  /* make sure it is set */
+    if (!STRMOD_MATCH(mod, "hash", 4))
        return FALSE;
     st->newStr = VarHash(st->nstr);
-    st->cp = st->tstr + 4;
+    st->cp = mod + 4;
     st->termc = *st->cp;
     return TRUE;
 }
 
 /* :P */
 static void
-ApplyModifier_Path(ApplyModifiersState *st)
+ApplyModifier_Path(const char *mod, ApplyModifiersState *st)
 {
-    GNode *gn;
-
     if ((st->v->flags & VAR_JUNK) != 0)
        st->v->flags |= VAR_KEEP;
-    gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
+    GNode *gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
     if (gn == NULL || gn->type & OP_NOPATH) {
        st->newStr = NULL;
     } else if (gn->path) {
@@ -2281,15 +2278,15 @@
     }
     if (!st->newStr)
        st->newStr = bmake_strdup(st->v->name);
-    st->cp = ++st->tstr;
-    st->termc = *st->tstr;
+    st->cp = mod + 1;
+    st->termc = *st->cp;
 }
 
 /* :!cmd! */
 static Boolean
-ApplyModifier_Exclam(ApplyModifiersState *st)
+ApplyModifier_Exclam(const char *mod, ApplyModifiersState *st)
 {
-    st->cp = ++st->tstr;
+    st->cp = mod + 1;
     char delim = '!';
     char *cmd = ParseModifierPart(st->ctxt, &st->cp, delim, st->eflags,
                                  NULL, NULL, NULL);
@@ -2316,21 +2313,21 @@
 
 /* :range */
 static Boolean
-ApplyModifier_Range(ApplyModifiersState *st)
+ApplyModifier_Range(const char *mod, ApplyModifiersState *st)
 {
     int n;
     char *ep;
 
-    st->cp = st->tstr + 1;     /* make sure it is set */
-    if (!STRMOD_MATCHX(st->tstr, "range", 5))
+    st->cp = mod + 1;  /* make sure it is set */
+    if (!STRMOD_MATCHX(mod, "range", 5))
        return FALSE;
 
-    if (st->tstr[5] == '=') {
-       n = strtoul(&st->tstr[6], &ep, 10);
+    if (mod[5] == '=') {
+       n = strtoul(mod + 6, &ep, 10);
        st->cp = ep;
     } else {
        n = 0;
-       st->cp = st->tstr + 5;
+       st->cp = mod + 5;
     }
     st->newStr = VarRange(st->nstr, n);
     st->termc = *st->cp;
@@ -2339,7 +2336,7 @@
 
 /* :Mpattern or :Npattern */
 static void
-ApplyModifier_Match(ApplyModifiersState *st)
+ApplyModifier_Match(const char *mod, ApplyModifiersState *st)
 {
     Boolean copy = FALSE;      /* pattern should be, or has been, copied */
     Boolean needSubst = FALSE;
@@ -2349,7 +2346,7 @@
      * XXX This will likely not work right if $() and ${} are intermixed.
      */
     int nest = 1;
-    for (st->cp = st->tstr + 1;
+    for (st->cp = mod + 1;
         *st->cp != '\0' && !(*st->cp == ':' && nest == 1);
         st->cp++) {
        if (*st->cp == '\\' &&
@@ -2378,13 +2375,13 @@
        /*
         * Need to compress the \:'s out of the pattern, so
         * allocate enough room to hold the uncompressed
-        * pattern (note that st->cp started at st->tstr+1, so
-        * st->cp - st->tstr takes the null byte into account) and
+        * pattern (note that st->cp started at mod+1, so
+        * st->cp - mod takes the null byte into account) and
         * compress the pattern into the space.
         */
-       pattern = bmake_malloc(st->cp - st->tstr);
+       pattern = bmake_malloc(st->cp - mod);
        char *cp2;
-       for (cp2 = pattern, st->cp = st->tstr + 1;
+       for (cp2 = pattern, st->cp = mod + 1;
             st->cp < endpat;
             st->cp++, cp2++) {
            if ((*st->cp == '\\') && (st->cp+1 < endpat) &&
@@ -2399,7 +2396,7 @@
         * Either Var_Subst or ModifyWords will need a
         * nul-terminated string soon, so construct one now.
         */
-       pattern = bmake_strndup(st->tstr+1, endpat - (st->tstr + 1));
+       pattern = bmake_strndup(mod + 1, endpat - (mod + 1));
     }
     if (needSubst) {
        /* pattern contains embedded '$', so use Var_Subst to expand it. */
@@ -2410,7 +2407,7 @@
     if (DEBUG(VAR))
        fprintf(debug_file, "Pattern[%s] for [%s] is [%s]\n",
            st->v->name, st->nstr, pattern);
-    ModifyWordsCallback callback = st->tstr[0] == 'M'
+    ModifyWordsCallback callback = mod[0] == 'M'
        ? ModifyWord_Match : ModifyWord_NoMatch;
     st->newStr = ModifyWords(st->ctxt, &st->parsestate, st->nstr,
                             callback, pattern);
@@ -2419,24 +2416,24 @@
 
 /* :S,from,to, */
 static Boolean
-ApplyModifier_Subst(ApplyModifiersState *st)
+ApplyModifier_Subst(const char * const mod, ApplyModifiersState *st)
 {
     ModifyWord_SubstArgs args;
     Var_Parse_State tmpparsestate = st->parsestate;
-    char delim = st->tstr[1];
-    st->tstr += 2;
+    char delim = mod[1];
+
+    st->cp = mod + 2;
 
     /*
      * If pattern begins with '^', it is anchored to the
      * start of the word -- skip over it and flag pattern.
      */
     args.pflags = 0;
-    if (*st->tstr == '^') {
+    if (*st->cp == '^') {
        args.pflags |= VARP_ANCHOR_START;
-       st->tstr++;
+       st->cp++;
     }
 
-    st->cp = st->tstr;
     char *lhs = ParseModifierPart(st->ctxt, &st->cp, delim, st->eflags,
                                  &args.pflags, &args.lhsLen, NULL);
     if (lhs == NULL) {
@@ -2486,16 +2483,15 @@
 
 /* :C,from,to, */
 static Boolean
-ApplyModifier_Regex(ApplyModifiersState *st)



Home | Main Index | Thread Index | Old Index