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): rename local functions for parsing con...



details:   https://anonhg.NetBSD.org/src/rev/e4cdb73bdd85
branches:  trunk
changeset: 1013732:e4cdb73bdd85
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Sep 04 21:08:44 2020 +0000

description:
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.

diffstat:

 usr.bin/make/cond.c                        |  56 ++++++++++++++++-------------
 usr.bin/make/unit-tests/cond-func-empty.mk |   4 +-
 2 files changed, 33 insertions(+), 27 deletions(-)

diffs (145 lines):

diff -r 7f7503574839 -r e4cdb73bdd85 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Fri Sep 04 20:51:01 2020 +0000
+++ b/usr.bin/make/cond.c       Fri Sep 04 21:08:44 2020 +0000
@@ -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 = t;
 }
 
-/*-
- * Parse the argument of a built-in function.
+/* Parse the argument of a built-in function.
+ *
+ * Arguments:
+ *     *linePtr initially points to the '(', upon successful return points
+ *     beyond the ')'.
+ *
+ *     *out_arg receives the argument as string.
  *
- * Results:
- *     The length of the argument.
- *     *argPtr receives the argument as string.
- *     *linePtr is updated to point behind the ')' of the function call.
- */
+ *     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 @@
         * 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 @@
        cp++;
     }
 
-    *argPtr = Buf_GetAll(&buf, &argLen);
+    *out_arg = Buf_GetAll(&buf, &argLen);
     Buf_Destroy(&buf, FALSE);
 
     while (*cp == ' ' || *cp == '\t') {
@@ -673,8 +679,8 @@
 }
 
 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 @@
 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 @@
        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 @@
      * 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 == '!')
diff -r 7f7503574839 -r e4cdb73bdd85 usr.bin/make/unit-tests/cond-func-empty.mk
--- a/usr.bin/make/unit-tests/cond-func-empty.mk        Fri Sep 04 20:51:01 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-func-empty.mk        Fri Sep 04 21:08:44 2020 +0000
@@ -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 @@
 # 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



Home | Main Index | Thread Index | Old Index