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): clean up API for evaluating conditions



details:   https://anonhg.NetBSD.org/src/rev/95925c43c1ab
branches:  trunk
changeset: 954922:95925c43c1ab
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Sep 13 13:50:27 2020 +0000

description:
make(1): clean up API for evaluating conditions

There was no need to make struct If publicly visible.

There was no need to have parameters in the public API that were passed
the same constants all the time.

The former function names had not been distinctive.

diffstat:

 usr.bin/make/cond.c    |  37 +++++++++++++++++++++----------------
 usr.bin/make/make.h    |   4 ++--
 usr.bin/make/nonints.h |   8 +++-----
 usr.bin/make/parse.c   |  10 +++++-----
 usr.bin/make/var.c     |   8 ++++----
 5 files changed, 35 insertions(+), 32 deletions(-)

diffs (250 lines):

diff -r 026bf00bc8f4 -r 95925c43c1ab usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sun Sep 13 13:31:36 2020 +0000
+++ b/usr.bin/make/cond.c       Sun Sep 13 13:50:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.141 2020/09/12 18:19:50 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.142 2020/09/13 13:50:27 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.141 2020/09/12 18:19:50 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.142 2020/09/13 13:50:27 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.141 2020/09/12 18:19:50 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.142 2020/09/13 13:50:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -85,9 +85,9 @@
 /* Handling of conditionals in a makefile.
  *
  * Interface:
- *     Cond_Eval       Evaluate the conditional in the passed line.
+ *     Cond_EvalLine   Evaluate the conditional in the passed line.
  *
- *     Cond_EvalExpression
+ *     Cond_EvalCondition
  *                     Evaluate the conditional in the passed line, which
  *                     is either the argument of one of the .if directives
  *                     or the condition in a :?true:false variable modifier.
@@ -165,8 +165,8 @@
  * In strict mode, the lhs must be a variable expression or a string literal
  * in quotes. In non-strict mode it may also be an unquoted string literal.
  *
- * TRUE when Cond_EvalExpression is called from Cond_Eval (.if etc)
- * FALSE when Cond_EvalExpression is called from var.c:ApplyModifiers
+ * TRUE when CondEvalExpression is called from Cond_EvalLine (.if etc)
+ * FALSE when CondEvalExpression is called from ApplyModifier_IfElse
  * since lhs is already expanded and we cannot tell if
  * it was a variable reference or not.
  */
@@ -281,7 +281,7 @@
     if (func != NULL && *cp++ != ')') {
        Parse_Error(PARSE_WARNING, "Missing closing parenthesis for %s()",
                    func);
-       /* The PARSE_FATAL is done as a follow-up by Cond_EvalExpression. */
+       /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */
        return 0;
     }
 
@@ -565,14 +565,14 @@
     case '!':
        if (op[1] != '=') {
            Parse_Error(PARSE_WARNING, "Unknown operator");
-           /* The PARSE_FATAL is done as a follow-up by Cond_EvalExpression. */
+           /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */
            return TOK_ERROR;
        }
        return lhs != rhs;
     case '=':
        if (op[1] != '=') {
            Parse_Error(PARSE_WARNING, "Unknown operator");
-           /* The PARSE_FATAL is done as a follow-up by Cond_EvalExpression. */
+           /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */
            return TOK_ERROR;
        }
        return lhs == rhs;
@@ -590,7 +590,7 @@
     if (!((op[0] == '!' || op[0] == '=') && op[1] == '=')) {
        Parse_Error(PARSE_WARNING,
                    "String comparison operator must be either == or !=");
-       /* The PARSE_FATAL is done as a follow-up by Cond_EvalExpression. */
+       /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */
        return TOK_ERROR;
     }
 
@@ -670,7 +670,7 @@
 
     if (par->p[0] == '\0') {
        Parse_Error(PARSE_WARNING, "Missing right-hand-side of operator");
-       /* The PARSE_FATAL is done as a follow-up by Cond_EvalExpression. */
+       /* The PARSE_FATAL is done as a follow-up by CondEvalExpression. */
        goto done;
     }
 
@@ -1018,8 +1018,8 @@
  *
  *     (*value) is set to the boolean value of the condition
  */
-CondEvalResult
-Cond_EvalExpression(const struct If *info, const char *cond, Boolean *value,
+static CondEvalResult
+CondEvalExpression(const struct If *info, const char *cond, Boolean *value,
                    int eprint, Boolean strictLHS)
 {
     static const struct If *dflt_info;
@@ -1052,6 +1052,11 @@
     return rval;
 }
 
+CondEvalResult
+Cond_EvalCondition(const char *cond, Boolean *out_value)
+{
+       return CondEvalExpression(NULL, cond, out_value, 0, FALSE);
+}
 
 /* Evaluate the conditional in the passed line. The line looks like this:
  *     .<cond-type> <expr>
@@ -1075,7 +1080,7 @@
  *                     or because the condition could not be evaluated
  */
 CondEvalResult
-Cond_Eval(const char *line)
+Cond_EvalLine(const char *line)
 {
     enum { MAXIF = 128 };      /* maximum depth of .if'ing */
     enum { MAXIF_BUMP = 32 };  /* how much to grow by */
@@ -1208,7 +1213,7 @@
     }
 
     /* And evaluate the conditional expression */
-    if (Cond_EvalExpression(ifp, line, &value, 1, TRUE) == COND_INVALID) {
+    if (CondEvalExpression(ifp, line, &value, 1, TRUE) == COND_INVALID) {
        /* Syntax error in conditional, error message already output. */
        /* Skip everything to matching .endif */
        cond_state[cond_depth] = SKIP_TO_ELSE;
diff -r 026bf00bc8f4 -r 95925c43c1ab usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sun Sep 13 13:31:36 2020 +0000
+++ b/usr.bin/make/make.h       Sun Sep 13 13:50:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.140 2020/09/13 06:15:29 rillig Exp $        */
+/*     $NetBSD: make.h,v 1.141 2020/09/13 13:50:27 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -378,7 +378,7 @@
 #define PARSE_FATAL    1
 
 /*
- * Values returned by Cond_Eval.
+ * Values returned by Cond_EvalLine and Cond_EvalCondition.
  */
 typedef enum {
     COND_PARSE,                        /* Parse the next lines */
diff -r 026bf00bc8f4 -r 95925c43c1ab usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sun Sep 13 13:31:36 2020 +0000
+++ b/usr.bin/make/nonints.h    Sun Sep 13 13:50:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.116 2020/09/12 18:19:50 rillig Exp $     */
+/*     $NetBSD: nonints.h,v 1.117 2020/09/13 13:50:27 rillig Exp $     */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -90,10 +90,8 @@
 int Compat_Make(GNode *, GNode *);
 
 /* cond.c */
-struct If;
-CondEvalResult Cond_EvalExpression(const struct If *, const char *,
-                                  Boolean *, int, Boolean);
-CondEvalResult Cond_Eval(const char *);
+CondEvalResult Cond_EvalCondition(const char *, Boolean *);
+CondEvalResult Cond_EvalLine(const char *);
 void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void);
 
diff -r 026bf00bc8f4 -r 95925c43c1ab usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sun Sep 13 13:31:36 2020 +0000
+++ b/usr.bin/make/parse.c      Sun Sep 13 13:50:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.301 2020/09/13 13:25:07 rillig Exp $       */
+/*     $NetBSD: parse.c,v 1.302 2020/09/13 13:50:27 rillig Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.301 2020/09/13 13:25:07 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.302 2020/09/13 13:50:27 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.301 2020/09/13 13:25:07 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.302 2020/09/13 13:50:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2774,12 +2774,12 @@
         * The line might be a conditional. Ask the conditional module
         * about it and act accordingly
         */
-       switch (Cond_Eval(line)) {
+       switch (Cond_EvalLine(line)) {
        case COND_SKIP:
            /* Skip to next conditional that evaluates to COND_PARSE.  */
            do {
                line = ParseGetLine(PARSE_SKIP, &lineLength);
-           } while (line && Cond_Eval(line) != COND_PARSE);
+           } while (line && Cond_EvalLine(line) != COND_PARSE);
            if (line == NULL)
                break;
            continue;
diff -r 026bf00bc8f4 -r 95925c43c1ab usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sun Sep 13 13:31:36 2020 +0000
+++ b/usr.bin/make/var.c        Sun Sep 13 13:50:27 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.510 2020/09/13 09:35:09 martin Exp $ */
+/*     $NetBSD: var.c,v 1.511 2020/09/13 13:50:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.510 2020/09/13 09:35:09 martin Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.511 2020/09/13 13:50:27 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.510 2020/09/13 09:35:09 martin Exp $");
+__RCSID("$NetBSD: var.c,v 1.511 2020/09/13 13:50:27 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2723,7 +2723,7 @@
 
     int cond_rc = COND_PARSE;  /* anything other than COND_INVALID */
     if (st->eflags & VARE_WANTRES) {
-       cond_rc = Cond_EvalExpression(NULL, st->v->name, &value, 0, FALSE);
+       cond_rc = Cond_EvalCondition(st->v->name, &value);
        if (cond_rc != COND_INVALID && value)
            then_eflags |= VARE_WANTRES;
        if (cond_rc != COND_INVALID && !value)



Home | Main Index | Thread Index | Old Index