Module Name:    src
Committed By:   rillig
Date:           Sun Nov  8 16:58:34 UTC 2020

Modified Files:
        src/usr.bin/make: nonints.h parse.c var.c
        src/usr.bin/make/unit-tests: varname-dot-shell.exp

Log Message:
make(1): rename VARE_ASSIGN to VARE_KEEP_DOLLAR

The other flags in VarEvalFlags already describe their effects, not the
place where they are used.  It's more important to know the effect.

Only a single unit test had to be adjusted.  This probably means that
there are too few tests where the special effects of VARE_KEEP_DOLLAR
come into play.  It could also mean that the effects are so simple and
obvious that they don't need any debug log, but that's not the case.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.434 -r1.435 src/usr.bin/make/parse.c
cvs rdiff -u -r1.676 -r1.677 src/usr.bin/make/var.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/varname-dot-shell.exp

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/nonints.h
diff -u src/usr.bin/make/nonints.h:1.158 src/usr.bin/make/nonints.h:1.159
--- src/usr.bin/make/nonints.h:1.158	Sun Nov  8 09:15:19 2020
+++ src/usr.bin/make/nonints.h	Sun Nov  8 16:58:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.158 2020/11/08 09:15:19 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.159 2020/11/08 16:58:33 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -215,16 +215,28 @@ void Var_End(void);
 
 typedef enum VarEvalFlags {
     VARE_NONE		= 0,
-    /* Treat undefined variables as errors. */
-    VARE_UNDEFERR	= 1 << 0,
-    /* Expand and evaluate variables during parsing. */
-    VARE_WANTRES	= 1 << 1,
-    /* In an assignment using the ':=' operator, keep '$$' as '$$' instead
-     * of reducing it to a single '$'.
+
+    /* Expand and evaluate variables during parsing.
+     *
+     * TODO: Document what Var_Parse and Var_Subst return when this flag
+     * is not set. */
+    VARE_WANTRES	= 1 << 0,
+
+    /* Treat undefined variables as errors.
+     * Must only be used in combination with VARE_WANTRES. */
+    VARE_UNDEFERR	= 1 << 1,
+
+    /* Keep '$$' as '$$' instead of reducing it to a single '$'.
+     *
+     * Used in variable assignments using the ':=' operator.  It allows
+     * multiple such assignments to be chained without accidentally expanding
+     * '$$file' to '$file' in the first assignment and interpreting it as
+     * '${f}' followed by 'ile' in the next assignment.
      *
-     * See also preserveUndefined, which preserves subexpressions based on
-     * undefined variables; maybe that can be converted to a flag as well. */
-    VARE_ASSIGN		= 1 << 2
+     * See also preserveUndefined, which preserves subexpressions that are
+     * based on undefined variables; maybe that can be converted to a flag
+     * as well. */
+    VARE_KEEP_DOLLAR	= 1 << 2
 } VarEvalFlags;
 
 typedef enum VarSetFlags {

Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.434 src/usr.bin/make/parse.c:1.435
--- src/usr.bin/make/parse.c:1.434	Sun Nov  8 15:07:37 2020
+++ src/usr.bin/make/parse.c	Sun Nov  8 16:58:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.434 2020/11/08 15:07:37 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.435 2020/11/08 16:58:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.434 2020/11/08 15:07:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.435 2020/11/08 16:58:33 rillig Exp $");
 
 /* types and constants */
 
@@ -1923,7 +1923,7 @@ VarAssign_EvalSubst(const char *name, co
     if (!Var_Exists(name, ctxt))
 	Var_Set(name, "", ctxt);
 
-    (void)Var_Subst(uvalue, ctxt, VARE_WANTRES|VARE_ASSIGN, &evalue);
+    (void)Var_Subst(uvalue, ctxt, VARE_WANTRES|VARE_KEEP_DOLLAR, &evalue);
     /* TODO: handle errors */
     preserveUndefined = savedPreserveUndefined;
     avalue = evalue;

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.676 src/usr.bin/make/var.c:1.677
--- src/usr.bin/make/var.c:1.676	Sun Nov  8 15:07:37 2020
+++ src/usr.bin/make/var.c	Sun Nov  8 16:58:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.676 2020/11/08 15:07:37 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.677 2020/11/08 16:58:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.676 2020/11/08 15:07:37 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.677 2020/11/08 16:58:33 rillig Exp $");
 
 #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1)
 #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2)
@@ -138,7 +138,7 @@ MAKE_RCSID("$NetBSD: var.c,v 1.676 2020/
 #define VAR_DEBUG4(fmt, arg1, arg2, arg3, arg4) DEBUG4(VAR, fmt, arg1, arg2, arg3, arg4)
 
 ENUM_FLAGS_RTTI_3(VarEvalFlags,
-		  VARE_UNDEFERR, VARE_WANTRES, VARE_ASSIGN);
+		  VARE_UNDEFERR, VARE_WANTRES, VARE_KEEP_DOLLAR);
 
 /*
  * This lets us tell if we have replaced the original environ
@@ -1922,7 +1922,7 @@ ParseModifierPart(
 	    const char *nested_p = p;
 	    const char *nested_val;
 	    void *nested_val_freeIt;
-	    VarEvalFlags nested_eflags = eflags & ~(unsigned)VARE_ASSIGN;
+	    VarEvalFlags nested_eflags = eflags & ~(unsigned)VARE_KEEP_DOLLAR;
 
 	    (void)Var_Parse(&nested_p, st->ctxt, nested_eflags,
 			    &nested_val, &nested_val_freeIt);
@@ -2980,7 +2980,8 @@ ok:
 
     delim = st->startc == '(' ? ')' : '}';
     /* TODO: Add test for using the ::= modifier in a := assignment line.
-     * Probably st->eflags should be passed down without VARE_ASSIGN here. */
+     * Probably st->eflags should be passed down without VARE_KEEP_DOLLAR
+     * here. */
     res = ParseModifierPart(pp, delim, st->eflags, st, &val, NULL, NULL, NULL);
     if (res != VPR_OK)
 	return AMR_CLEANUP;
@@ -3946,9 +3947,7 @@ Var_Parse(const char **pp, GNode *ctxt, 
  *			expanded.
  *	ctxt		The context in which to start searching for
  *			variables.  The other contexts are searched as well.
- *	eflags		VARE_UNDEFERR	if undefineds are an error
- *			VARE_WANTRES	if we actually want the result
- *			VARE_ASSIGN	if we are in a := assignment
+ *	eflags		Special effects during expansion.
  */
 VarParseResult
 Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags, char **out_res)
@@ -3966,7 +3965,7 @@ Var_Subst(const char *str, GNode *ctxt, 
     while (*p != '\0') {
 	if (p[0] == '$' && p[1] == '$') {
 	    /* A dollar sign may be escaped with another dollar sign. */
-	    if (save_dollars && (eflags & VARE_ASSIGN))
+	    if (save_dollars && (eflags & VARE_KEEP_DOLLAR))
 		Buf_AddByte(&buf, '$');
 	    Buf_AddByte(&buf, '$');
 	    p += 2;

Index: src/usr.bin/make/unit-tests/varname-dot-shell.exp
diff -u src/usr.bin/make/unit-tests/varname-dot-shell.exp:1.7 src/usr.bin/make/unit-tests/varname-dot-shell.exp:1.8
--- src/usr.bin/make/unit-tests/varname-dot-shell.exp:1.7	Fri Oct 30 16:09:56 2020
+++ src/usr.bin/make/unit-tests/varname-dot-shell.exp	Sun Nov  8 16:58:34 2020
@@ -1,6 +1,6 @@
 ParseReadLine (10): 'ORIG_SHELL:=	${.SHELL}'
 Global:ORIG_SHELL = 
-Var_Parse: ${.SHELL} with VARE_WANTRES|VARE_ASSIGN
+Var_Parse: ${.SHELL} with VARE_WANTRES|VARE_KEEP_DOLLAR
 Global:delete .SHELL (not found)
 Command:.SHELL = (details omitted)
 Global:ORIG_SHELL = (details omitted)

Reply via email to