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 for_var_len to ExprLen



details:   https://anonhg.NetBSD.org/src/rev/c1c8bb4a6d73
branches:  trunk
changeset: 985630:c1c8bb4a6d73
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Sep 02 07:02:07 2021 +0000

description:
make: rename for_var_len to ExprLen

The text ${VAR} is not a variable, it's a variable expression.

No functional change.

diffstat:

 usr.bin/make/for.c                               |  42 +++++++++-------
 usr.bin/make/unit-tests/directive-for-escape.exp |  58 ++++++++++++------------
 usr.bin/make/unit-tests/directive-for-escape.mk  |  16 +++--
 3 files changed, 62 insertions(+), 54 deletions(-)

diffs (258 lines):

diff -r 1389fd9ecea3 -r c1c8bb4a6d73 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Thu Sep 02 06:29:56 2021 +0000
+++ b/usr.bin/make/for.c        Thu Sep 02 07:02:07 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: for.c,v 1.146 2021/09/02 06:29:56 rillig Exp $ */
+/*     $NetBSD: for.c,v 1.147 2021/09/02 07:02:07 rillig Exp $ */
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*     "@(#)for.c      8.1 (Berkeley) 6/6/93"  */
-MAKE_RCSID("$NetBSD: for.c,v 1.146 2021/09/02 06:29:56 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.147 2021/09/02 07:02:07 rillig Exp $");
 
 
 /* One of the variables to the left of the "in" in a .for loop. */
@@ -278,33 +278,33 @@
 
 
 static size_t
-for_var_len(const char *var)
+ExprLen(const char *expr)
 {
-       char ch, var_start, var_end;
+       char ch, expr_open, expr_close;
        int depth;
        size_t len;
 
-       var_start = *var;
-       if (var_start == '\0')
+       expr_open = expr[0];
+       if (expr_open == '\0')
                /* just escape the $ */
                return 0;
 
-       if (var_start == '(')
-               var_end = ')';
-       else if (var_start == '{')
-               var_end = '}';
+       if (expr_open == '(')
+               expr_close = ')';
+       else if (expr_open == '{')
+               expr_close = '}';
        else
                return 1;       /* Single char variable */
 
        depth = 1;
-       for (len = 1; (ch = var[len++]) != '\0';) {
-               if (ch == var_start)
+       for (len = 1; (ch = expr[len++]) != '\0';) {
+               if (ch == expr_open)
                        depth++;
-               else if (ch == var_end && --depth == 0)
+               else if (ch == expr_close && --depth == 0)
                        return len;
        }
 
-       /* Variable end not found, escape the $ */
+       /* Expression end not found, escape the $ */
        return 0;
 }
 
@@ -345,8 +345,12 @@
         * :U processing, see ApplyModifier_Defined. */
        while ((ch = *item++) != '\0') {
                if (ch == '$') {
-                       size_t len = for_var_len(item);
+                       size_t len = ExprLen(item);
                        if (len != 0) {
+                               /*
+                                * XXX: Should a '\' be added here?
+                                * See directive-for-escape.mk, ExprLen.
+                                */
                                Buf_AddBytes(cmds, item - 1, len + 1);
                                item += len;
                                continue;
@@ -427,8 +431,10 @@
        return;
 
 found:
+       Buf_AddBytesBetween(&f->curBody, *inout_mark, p);
+       *inout_mark = p + 1;
+
        /* Replace $<ch> with ${:U<value>} */
-       Buf_AddBytesBetween(&f->curBody, *inout_mark, p), *inout_mark = p + 1;
        Buf_AddStr(&f->curBody, "{:U");
        Buf_AddEscaped(&f->curBody, f->items.words[f->sub_next + i], '}');
        Buf_AddByte(&f->curBody, '}');
@@ -444,8 +450,8 @@
  * defined, see unit-tests/varname-empty.mk for more details.
  *
  * The detection of substitutions of the loop control variables is naive.
- * Many of the modifiers use '\' to escape '$' (not '$'), so it is possible
- * to contrive a makefile where an unwanted substitution happens.
+ * Many of the modifiers use '\$' instead of '$$' to escape '$', so it is
+ * possible to contrive a makefile where an unwanted substitution happens.
  */
 static void
 ForLoop_SubstBody(ForLoop *f)
diff -r 1389fd9ecea3 -r c1c8bb4a6d73 usr.bin/make/unit-tests/directive-for-escape.exp
--- a/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Sep 02 06:29:56 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.exp  Thu Sep 02 07:02:07 2021 +0000
@@ -11,45 +11,45 @@
 For: end for 1
 For: loop body:
 .  info ${:U\$}
-make: "directive-for-escape.mk" line 41: $
+make: "directive-for-escape.mk" line 43: $
 For: loop body:
 .  info ${:U${V}}
-make: "directive-for-escape.mk" line 41: value
+make: "directive-for-escape.mk" line 43: value
 For: loop body:
 .  info ${:U${V:=-with-modifier}}
-make: "directive-for-escape.mk" line 41: value-with-modifier
+make: "directive-for-escape.mk" line 43: value-with-modifier
 For: loop body:
 .  info ${:U$(V)}
-make: "directive-for-escape.mk" line 41: value
+make: "directive-for-escape.mk" line 43: value
 For: loop body:
 .  info ${:U$(V:=-with-modifier)}
-make: "directive-for-escape.mk" line 41: value-with-modifier
+make: "directive-for-escape.mk" line 43: value-with-modifier
 For: end for 1
 For: loop body:
 .  info ${:U\${UNDEF\:U\\$\\$}
-make: "directive-for-escape.mk" line 55: ${UNDEF:U\$
+make: "directive-for-escape.mk" line 57: ${UNDEF:U\$
 For: loop body:
 .  info ${:U{{\}\}}
-make: "directive-for-escape.mk" line 55: {{}}
+make: "directive-for-escape.mk" line 57: {{}}
 For: loop body:
 .  info ${:Uend\}}
-make: "directive-for-escape.mk" line 55: end}
+make: "directive-for-escape.mk" line 57: end}
 For: end for 1
 For: loop body:
 .  info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end}
-make: "directive-for-escape.mk" line 67: begin<fallback>end
+make: "directive-for-escape.mk" line 69: begin<fallback>end
 For: end for 1
 For: loop body:
 .  info ${:U\$}
-make: "directive-for-escape.mk" line 75: $
+make: "directive-for-escape.mk" line 77: $
 For: end for 1
 For: loop body:
 .  info ${NUMBERS} ${:Ureplaced}
-make: "directive-for-escape.mk" line 83: one two three replaced
+make: "directive-for-escape.mk" line 85: one two three replaced
 For: end for 1
 For: loop body:
 .  info ${:Ureplaced}
-make: "directive-for-escape.mk" line 93: replaced
+make: "directive-for-escape.mk" line 95: replaced
 For: end for 1
 For: loop body:
 .  info .        $$i: ${:Uinner}
@@ -62,31 +62,31 @@
 .  info .     $${i2}: ${i2}
 .  info .     $${i,}: ${i,}
 .  info .  adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
-make: "directive-for-escape.mk" line 101: .        $i: inner
-make: "directive-for-escape.mk" line 102: .      ${i}: inner
-make: "directive-for-escape.mk" line 103: .   ${i:M*}: inner
-make: "directive-for-escape.mk" line 104: .      $(i): inner
-make: "directive-for-escape.mk" line 105: .   $(i:M*): inner
-make: "directive-for-escape.mk" line 106: . ${i${:U}}: outer
-make: "directive-for-escape.mk" line 107: .    ${i\}}: inner}
-make: "directive-for-escape.mk" line 108: .     ${i2}: two
-make: "directive-for-escape.mk" line 109: .     ${i,}: comma
-make: "directive-for-escape.mk" line 110: .  adjacent: innerinnerinnerinner
+make: "directive-for-escape.mk" line 103: .        $i: inner
+make: "directive-for-escape.mk" line 104: .      ${i}: inner
+make: "directive-for-escape.mk" line 105: .   ${i:M*}: inner
+make: "directive-for-escape.mk" line 106: .      $(i): inner
+make: "directive-for-escape.mk" line 107: .   $(i:M*): inner
+make: "directive-for-escape.mk" line 108: . ${i${:U}}: outer
+make: "directive-for-escape.mk" line 109: .    ${i\}}: inner}
+make: "directive-for-escape.mk" line 110: .     ${i2}: two
+make: "directive-for-escape.mk" line 111: .     ${i,}: comma
+make: "directive-for-escape.mk" line 112: .  adjacent: innerinnerinnerinner
 For: end for 1
 For: loop body:
 .  info eight $$$$$$$$ and no cents.
 .  info eight ${:Udollar}${:Udollar}${:Udollar}${:Udollar} and no cents.
-make: "directive-for-escape.mk" line 118: eight $$$$ and no cents.
-make: "directive-for-escape.mk" line 119: eight dollardollardollardollar and no cents.
-make: "directive-for-escape.mk" line 128: eight  and no cents.
+make: "directive-for-escape.mk" line 120: eight $$$$ and no cents.
+make: "directive-for-escape.mk" line 121: eight dollardollardollardollar and no cents.
+make: "directive-for-escape.mk" line 130: eight  and no cents.
 For: end for 1
-make: "directive-for-escape.mk" line 135: newline in .for value
-make: "directive-for-escape.mk" line 135: newline in .for value
+make: "directive-for-escape.mk" line 137: newline in .for value
+make: "directive-for-escape.mk" line 137: newline in .for value
 For: loop body:
 .  info short: ${:U" "}
 .  info long: ${:U" "}
-make: "directive-for-escape.mk" line 136: short: " "
-make: "directive-for-escape.mk" line 137: long: " "
+make: "directive-for-escape.mk" line 138: short: " "
+make: "directive-for-escape.mk" line 139: long: " "
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
diff -r 1389fd9ecea3 -r c1c8bb4a6d73 usr.bin/make/unit-tests/directive-for-escape.mk
--- a/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Sep 02 06:29:56 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.mk   Thu Sep 02 07:02:07 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.10 2021/06/25 16:10:07 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.11 2021/09/02 07:02:08 rillig Exp $
 #
 # Test escaping of special characters in the iteration values of a .for loop.
 # These values get expanded later using the :U variable modifier, and this
@@ -29,19 +29,21 @@
 .  info ${chars}
 .endfor
 
-# Cover the code in for_var_len.
+# Cover the code in ExprLen.
 #
 # XXX: It is unexpected that the variable V gets expanded in the loop body.
-# The double '$$' should prevent exactly this.  Probably nobody was
-# adventurous enough to use literal dollar signs in the values of a .for
+# The double '$$' should intuitively prevent exactly this.  Probably nobody
+# was adventurous enough to use literal dollar signs in the values of a .for
 # loop.
+#
+# See for.c, function ExprLen.
 V=             value
 VALUES=                $$ $${V} $${V:=-with-modifier} $$(V) $$(V:=-with-modifier)
 .for i in ${VALUES}
 .  info $i
 .endfor
 
-# Try to cover the code for nested '{}' in for_var_len, without success.
+# Try to cover the code for nested '{}' in ExprLen, without success.
 #
 # The value of the variable VALUES is not meant to be a variable expression.
 # Instead, it is meant to represent literal text, the only escaping mechanism
@@ -55,9 +57,9 @@
 .  info $i
 .endfor
 
-# Second try to cover the code for nested '{}' in for_var_len.
+# Second try to cover the code for nested '{}' in ExprLen.
 #
-# XXX: It is wrong that for_var_len requires the braces to be balanced.
+# XXX: It is wrong that ExprLen requires the braces to be balanced.
 # Each variable modifier has its own inconsistent way of parsing nested
 # variable expressions, braces and parentheses.  (Compare ':M', ':S', and
 # ':D' for details.)  The only sensible thing to do is therefore to let



Home | Main Index | Thread Index | Old Index