summaryrefslogtreecommitdiff
path: root/usr.bin/make
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2020-09-13 13:50:27 +0000
committerrillig <rillig@NetBSD.org>2020-09-13 13:50:27 +0000
commit2d3dc5e3fa4f3a22f1bf2f9204941e67a3ec0140 (patch)
tree317024640dbff9353dd0222578a27576882198f3 /usr.bin/make
parentac703db2e55008253a31cc41dc39e650cd4e29ad (diff)
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 (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/cond.c37
-rw-r--r--usr.bin/make/make.h4
-rw-r--r--usr.bin/make/nonints.h8
-rw-r--r--usr.bin/make/parse.c10
-rw-r--r--usr.bin/make/var.c8
5 files changed, 35 insertions, 32 deletions
diff --git a/usr.bin/make/cond.c b/usr.bin/make/cond.c
index 793f4c8b739..973de609f09 100644
--- a/usr.bin/make/cond.c
+++ b/usr.bin/make/cond.c
@@ -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 @@ __RCSID("$NetBSD: cond.c,v 1.141 2020/09/12 18:19:50 rillig Exp $");
/* 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 @@ static unsigned int cond_min_depth = 0; /* depth at makefile open */
* 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 @@ ParseFuncArg(const char **linePtr, Boolean doEval, const char *func,
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 @@ EvalCompareNum(double lhs, const char *op, double 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;
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 @@ EvalCompareStr(const char *lhs, const char *op, const char *rhs)
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 @@ CondParser_Comparison(CondParser *par, Boolean doEval)
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 @@ CondParser_Eval(CondParser *par, Boolean *value)
*
* (*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 @@ Cond_EvalExpression(const struct If *info, const char *cond, Boolean *value,
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 @@ Cond_EvalExpression(const struct If *info, const char *cond, Boolean *value,
* 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 @@ Cond_Eval(const char *line)
}
/* 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 --git a/usr.bin/make/make.h b/usr.bin/make/make.h
index a437a5e628a..01b9eb9ebc3 100644
--- a/usr.bin/make/make.h
+++ b/usr.bin/make/make.h
@@ -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 @@ typedef struct GNode {
#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 --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h
index bd8ae17f012..e1e1bdc0191 100644
--- a/usr.bin/make/nonints.h
+++ b/usr.bin/make/nonints.h
@@ -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 @@ void Compat_Run(Lst);
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 --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index c128b4ba230..0e4831822b9 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -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 @@ ParseReadLine(void)
* 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 --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 9ebb3ccc847..7deb7f1431c 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -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 @@ ApplyModifier_IfElse(const char **pp, ApplyModifiersState *st)
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)