Module Name:    src
Committed By:   rillig
Date:           Fri Sep  4 21:08:44 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c
        src/usr.bin/make/unit-tests: cond-func-empty.mk

Log Message:
make(1): rename local functions for parsing conditions

The word "get" implies a cheap operation without side effects.  Parsing
instead has lots of side effects, even if it's only that the parsing
position is updated.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/make/cond.c
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/cond-func-empty.mk

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/cond.c
diff -u src/usr.bin/make/cond.c:1.111 src/usr.bin/make/cond.c:1.112
--- src/usr.bin/make/cond.c:1.111	Fri Sep  4 20:51:01 2020
+++ src/usr.bin/make/cond.c	Fri Sep  4 21:08:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.112 2020/09/04 21:08:44 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.112 2020/09/04 21:08:44 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c	8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.111 2020/09/04 20:51:01 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.112 2020/09/04 21:08:44 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -170,18 +170,24 @@ CondPushBack(Token t)
     condPushBack = t;
 }
 
-/*-
- * Parse the argument of a built-in function.
+/* Parse the argument of a built-in function.
  *
- * Results:
- *	The length of the argument.
- *	*argPtr receives the argument as string.
- *	*linePtr is updated to point behind the ')' of the function call.
- */
+ * Arguments:
+ *	*linePtr initially points to the '(', upon successful return points
+ *	beyond the ')'.
+ *
+ *	*out_arg receives the argument as string.
+ *
+ *	func says whether the argument belongs to an actual function, or
+ *	whether the parsed argument is passed to the default function.
+ *
+ *	XXX: This is ambiguous for the empty() function since its argument is
+ *	parsed differently.
+ *
+ * Return the length of the argument. */
 static int
-CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
-	   const char *func)
-{
+ParseFuncArg(Boolean doEval, const char **linePtr, char **out_arg,
+	     const char *func) {
     const char *cp;
     Buffer buf;
     int paren_depth;
@@ -200,7 +206,7 @@ CondGetArg(Boolean doEval, const char **
 	 * than hitting the user with a warning message every time s/he uses
 	 * the word 'make' or 'defined' at the beginning of a symbol...
 	 */
-	*argPtr = NULL;
+	*out_arg = NULL;
 	return 0;
     }
 
@@ -243,7 +249,7 @@ CondGetArg(Boolean doEval, const char **
 	cp++;
     }
 
-    *argPtr = Buf_GetAll(&buf, &argLen);
+    *out_arg = Buf_GetAll(&buf, &argLen);
     Buf_Destroy(&buf, FALSE);
 
     while (*cp == ' ' || *cp == '\t') {
@@ -673,8 +679,8 @@ done:
 }
 
 static int
-get_mpt_arg(Boolean doEval, const char **linePtr, char **argPtr,
-	    const char *func MAKE_ATTR_UNUSED)
+ParseEmptyArg(Boolean doEval, const char **linePtr, char **argPtr,
+	      const char *func MAKE_ATTR_UNUSED)
 {
     void *val_freeIt;
     const char *val;
@@ -708,7 +714,7 @@ get_mpt_arg(Boolean doEval, const char *
 static Boolean
 CondDoEmpty(int arglen, const char *arg MAKE_ATTR_UNUSED)
 {
-    /* Magic values ahead, see get_mpt_arg. */
+    /* Magic values ahead, see ParseEmptyArg. */
     return arglen == 1;
 }
 
@@ -721,12 +727,12 @@ compare_function(Boolean doEval)
 	int (*fn_getarg)(Boolean, const char **, char **, const char *);
 	Boolean (*fn_proc)(int, const char *);
     } fn_defs[] = {
-	{ "defined",  7, CondGetArg,  CondDoDefined },
-	{ "make",     4, CondGetArg,  CondDoMake },
-	{ "exists",   6, CondGetArg,  CondDoExists },
-	{ "empty",    5, get_mpt_arg, CondDoEmpty },
-	{ "target",   6, CondGetArg,  CondDoTarget },
-	{ "commands", 8, CondGetArg,  CondDoCommands },
+	{ "defined",  7, ParseFuncArg,  CondDoDefined },
+	{ "make",     4, ParseFuncArg,  CondDoMake },
+	{ "exists",   6, ParseFuncArg,  CondDoExists },
+	{ "empty",    5, ParseEmptyArg, CondDoEmpty },
+	{ "target",   6, ParseFuncArg,  CondDoTarget },
+	{ "commands", 8, ParseFuncArg,  CondDoCommands },
 	{ NULL,       0, NULL, NULL },
     };
     const struct fn_def *fn_def;
@@ -771,7 +777,7 @@ compare_function(Boolean doEval)
      * would be invalid if we did "defined(a)" - so instead treat as an
      * expression.
      */
-    arglen = CondGetArg(doEval, &cp, &arg, NULL);
+    arglen = ParseFuncArg(doEval, &cp, &arg, NULL);
     for (cp1 = cp; isspace((unsigned char)*cp1); cp1++)
 	continue;
     if (*cp1 == '=' || *cp1 == '!')

Index: src/usr.bin/make/unit-tests/cond-func-empty.mk
diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.5 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.6
--- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.5	Fri Sep  4 20:51:01 2020
+++ src/usr.bin/make/unit-tests/cond-func-empty.mk	Fri Sep  4 21:08:44 2020
@@ -1,4 +1,4 @@
-# $NetBSD: cond-func-empty.mk,v 1.5 2020/09/04 20:51:01 rillig Exp $
+# $NetBSD: cond-func-empty.mk,v 1.6 2020/09/04 21:08:44 rillig Exp $
 #
 # Tests for the empty() function in .if conditions, which tests a variable
 # expression for emptiness.
@@ -90,7 +90,7 @@ WORD=	word
 # Now the variable named " " gets a non-empty value, which demonstrates that
 # neither leading nor trailing spaces are trimmed in the argument of the
 # function.  If the spaces were trimmed, the variable name would be "" and
-# that variable is indeed undefined.  Since get_mpt_arg calls Var_Parse
+# that variable is indeed undefined.  Since ParseEmptyArg calls Var_Parse
 # without VARE_UNDEFERR, the value of the undefined variable is returned as
 # an empty string.
 ${:U }=	space

Reply via email to