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: reduce complexity of evaluating expressions



details:   https://anonhg.NetBSD.org/src/rev/4c1e4135371b
branches:  trunk
changeset: 373529:4c1e4135371b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Feb 14 21:08:00 2023 +0000

description:
make: reduce complexity of evaluating expressions

No functional change.

diffstat:

 usr.bin/make/arch.c  |  11 +++---
 usr.bin/make/cond.c  |  13 +++----
 usr.bin/make/make.h  |   4 +-
 usr.bin/make/parse.c |  10 ++---
 usr.bin/make/suff.c  |   8 +---
 usr.bin/make/var.c   |  79 +++++++++++++++++----------------------------------
 6 files changed, 46 insertions(+), 79 deletions(-)

diffs (truncated from 367 to 300 lines):

diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/arch.c
--- a/usr.bin/make/arch.c       Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/arch.c       Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arch.c,v 1.212 2022/12/07 10:28:48 rillig Exp $        */
+/*     $NetBSD: arch.c,v 1.213 2023/02/14 21:08:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -126,7 +126,7 @@
 #include "config.h"
 
 /*     "@(#)arch.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: arch.c,v 1.212 2022/12/07 10:28:48 rillig Exp $");
+MAKE_RCSID("$NetBSD: arch.c,v 1.213 2023/02/14 21:08:00 rillig Exp $");
 
 typedef struct List ArchList;
 typedef struct ListNode ArchListNode;
@@ -221,8 +221,7 @@
                        bool isError;
 
                        /* XXX: is expanded twice: once here and once below */
-                       (void)Var_Parse(&nested_p, scope,
-                           VARE_UNDEFERR, &result);
+                       result = Var_Parse(&nested_p, scope, VARE_UNDEFERR);
                        /* TODO: handle errors */
                        isError = result.str == var_Error;
                        FStr_Done(&result);
@@ -260,8 +259,8 @@
                                bool isError;
                                const char *nested_p = cp;
 
-                               (void)Var_Parse(&nested_p, scope,
-                                   VARE_UNDEFERR, &result);
+                               result = Var_Parse(&nested_p, scope,
+                                   VARE_UNDEFERR);
                                /* TODO: handle errors */
                                isError = result.str == var_Error;
                                FStr_Done(&result);
diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/cond.c       Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -92,7 +92,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.343 2023/02/14 20:49:09 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $");
 
 /*
  * Conditional expressions conform to this grammar:
@@ -235,8 +235,7 @@
                        VarEvalMode emode = doEval
                            ? VARE_UNDEFERR
                            : VARE_PARSE_ONLY;
-                       FStr nestedVal;
-                       (void)Var_Parse(&p, SCOPE_CMDLINE, emode, &nestedVal);
+                       FStr nestedVal = Var_Parse(&p, SCOPE_CMDLINE, emode);
                        /* TODO: handle errors */
                        Buf_AddStr(&word, nestedVal.str);
                        FStr_Done(&nestedVal);
@@ -401,7 +400,7 @@
 
        p = par->p;
        atStart = p == start;
-       (void)Var_Parse(&p, SCOPE_CMDLINE, emode, inout_str);
+       *inout_str = Var_Parse(&p, SCOPE_CMDLINE, emode);
        /* TODO: handle errors */
        if (inout_str->str == var_Error) {
                FStr_Done(inout_str);
@@ -675,8 +674,8 @@
                return false;
 
        cp--;                   /* Make cp[1] point to the '('. */
-       (void)Var_Parse(&cp, SCOPE_CMDLINE,
-           doEval ? VARE_WANTRES : VARE_PARSE_ONLY, &val);
+       val = Var_Parse(&cp, SCOPE_CMDLINE,
+           doEval ? VARE_WANTRES : VARE_PARSE_ONLY);
        /* TODO: handle errors */
 
        if (val.str == var_Error)
diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/make.h
--- a/usr.bin/make/make.h       Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/make.h       Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.311 2023/01/26 20:48:17 sjg Exp $   */
+/*     $NetBSD: make.h,v 1.312 2023/02/14 21:08:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -1017,7 +1017,7 @@
 bool Var_ExistsExpand(GNode *, const char *) MAKE_ATTR_USE;
 FStr Var_Value(GNode *, const char *) MAKE_ATTR_USE;
 const char *GNode_ValueDirect(GNode *, const char *) MAKE_ATTR_USE;
-VarParseResult Var_Parse(const char **, GNode *, VarEvalMode, FStr *);
+FStr Var_Parse(const char **, GNode *, VarEvalMode);
 VarParseResult Var_Subst(const char *, GNode *, VarEvalMode, char **);
 void Var_Expand(FStr *, GNode *, VarEvalMode);
 void Var_Stats(void);
diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/parse.c      Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 sjg Exp $  */
+/*     $NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -105,7 +105,7 @@
 #include "pathnames.h"
 
 /*     "@(#)parse.c    8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.692 2023/01/24 00:24:02 sjg Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.693 2023/02/14 21:08:00 rillig Exp $");
 
 /*
  * A file being read.
@@ -897,10 +897,8 @@
                         * have been discovered in the initial Var_Subst and
                         * we wouldn't be here.
                         */
-                       FStr val;
-
-                       (void)Var_Parse(&cp, SCOPE_CMDLINE,
-                           VARE_PARSE_ONLY, &val);
+                       FStr val = Var_Parse(&cp, SCOPE_CMDLINE,
+                           VARE_PARSE_ONLY);
                        FStr_Done(&val);
                } else
                        cp++;
diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/suff.c
--- a/usr.bin/make/suff.c       Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/suff.c       Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: suff.c,v 1.366 2022/03/04 23:17:16 sjg Exp $   */
+/*     $NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -115,7 +115,7 @@
 #include "dir.h"
 
 /*     "@(#)suff.c     8.4 (Berkeley) 3/21/94" */
-MAKE_RCSID("$NetBSD: suff.c,v 1.366 2022/03/04 23:17:16 sjg Exp $");
+MAKE_RCSID("$NetBSD: suff.c,v 1.367 2023/02/14 21:08:00 rillig Exp $");
 
 typedef List SuffixList;
 typedef ListNode SuffixListNode;
@@ -1312,9 +1312,7 @@
                } else if (*cp == '$') {
                        /* Skip over the variable expression. */
                        const char *nested_p = cp;
-                       FStr junk;
-
-                       (void)Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY, &junk);
+                       FStr junk = Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY);
                        /* TODO: handle errors */
                        if (junk.str == var_Error) {
                                Parse_Error(PARSE_FATAL,
diff -r 5b3fae86284b -r 4c1e4135371b usr.bin/make/var.c
--- a/usr.bin/make/var.c        Tue Feb 14 20:49:09 2023 +0000
+++ b/usr.bin/make/var.c        Tue Feb 14 21:08:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.1041 2023/02/13 19:25:15 rillig Exp $        */
+/*     $NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -139,7 +139,7 @@
 #include "metachar.h"
 
 /*     "@(#)var.c      8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.1041 2023/02/13 19:25:15 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.1042 2023/02/14 21:08:00 rillig Exp $");
 
 /*
  * Variables are defined using one of the VAR=value assignments.  Their
@@ -2145,10 +2145,8 @@
                      VarEvalMode emode)
 {
        const char *p = *pp;
-       FStr nested_val;
-
-       (void)Var_Parse(&p, ch->expr->scope,
-           VarEvalMode_WithoutKeepDollar(emode), &nested_val);
+       FStr nested_val = Var_Parse(&p, ch->expr->scope,
+           VarEvalMode_WithoutKeepDollar(emode));
        /* TODO: handle errors */
        LazyBuf_AddStr(part, nested_val.str);
        FStr_Done(&nested_val);
@@ -2500,11 +2498,8 @@
 
                /* Nested variable expression */
                if (*p == '$') {
-                       FStr val;
-
-                       (void)Var_Parse(&p, ch->expr->scope,
-                           shouldEval ? ch->expr->emode : VARE_PARSE_ONLY,
-                           &val);
+                       FStr val = Var_Parse(&p, ch->expr->scope,
+                           shouldEval ? ch->expr->emode : VARE_PARSE_ONLY);
                        /* TODO: handle errors */
                        if (shouldEval)
                                LazyBuf_AddStr(buf, val.str);
@@ -3893,9 +3888,7 @@
 {
        Expr *expr = ch->expr;
        const char *p = *pp;
-       FStr mods;
-
-       (void)Var_Parse(&p, expr->scope, expr->emode, &mods);
+       FStr mods = Var_Parse(&p, expr->scope, expr->emode);
        /* TODO: handle errors */
 
        if (mods.str[0] != '\0' && !IsDelimiter(*p, ch)) {
@@ -4170,8 +4163,7 @@
 
                /* A variable inside a variable, expand. */
                if (*p == '$') {
-                       FStr nested_val;
-                       (void)Var_Parse(&p, scope, emode, &nested_val);
+                       FStr nested_val = Var_Parse(&p, scope, emode);
                        /* TODO: handle errors */
                        LazyBuf_AddStr(buf, nested_val.str);
                        FStr_Done(&nested_val);
@@ -4212,7 +4204,7 @@
 static bool
 ParseVarnameShort(char varname, const char **pp, GNode *scope,
                  VarEvalMode emode,
-                 VarParseResult *out_false_res, const char **out_false_val,
+                 const char **out_false_val,
                  Var **out_true_var)
 {
        char name[2];
@@ -4221,7 +4213,6 @@
 
        if (!IsShortVarnameValid(varname, *pp)) {
                (*pp)++;        /* only skip the '$' */
-               *out_false_res = VPR_ERR;
                *out_false_val = var_Error;
                return false;
        }
@@ -4244,22 +4235,8 @@
        if (opts.strict && val == var_Error) {
                Parse_Error(PARSE_FATAL,
                    "Variable \"%s\" is undefined", name);
-               *out_false_res = VPR_ERR;
-               *out_false_val = val;
-               return false;
        }
 
-       /*
-        * XXX: This looks completely wrong.
-        *
-        * If undefined expressions are not allowed, this should
-        * rather be VPR_ERR instead of VPR_UNDEF, together with an
-        * error message.
-        *
-        * If undefined expressions are allowed, this should rather
-        * be VPR_UNDEF instead of VPR_OK.
-        */
-       *out_false_res = emode == VARE_UNDEFERR ? VPR_UNDEF : VPR_OK;
        *out_false_val = val;
        return false;
 }
@@ -4498,23 +4475,23 @@
  *                     point to some random character in the string, to the
  *                     location of the parse error, or at the end of the
  *                     string.
- *     *out_val        The value of the variable expression, never NULL.
- *     *out_val        var_Error if there was a parse error.
- *     *out_val        var_Error if the base variable of the expression was
+ *     return          The value of the variable expression, never NULL.
+ *     return          var_Error if there was a parse error.
+ *     return          var_Error if the base variable of the expression was
  *                     undefined, emode is VARE_UNDEFERR, and none of
  *                     the modifiers turned the undefined expression into a
  *                     defined expression.
  *                     XXX: It is not guaranteed that an error message has
  *                     been printed.
- *     *out_val        varUndefined if the base variable of the expression
+ *     return          varUndefined if the base variable of the expression
  *                     was undefined, emode was not VARE_UNDEFERR,
  *                     and none of the modifiers turned the undefined
  *                     expression into a defined expression.
  *                     XXX: It is not guaranteed that an error message has
  *                     been printed.
  */
-VarParseResult
-Var_Parse(const char **pp, GNode *scope, VarEvalMode emode, FStr *out_val)
+FStr
+Var_Parse(const char **pp, GNode *scope, VarEvalMode emode)
 {
        const char *p = *pp;



Home | Main Index | Thread Index | Old Index