Module Name: src
Committed By: rillig
Date: Sun Sep 13 13:50:27 UTC 2020
Modified Files:
src/usr.bin/make: cond.c make.h nonints.h parse.c var.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/usr.bin/make/cond.c
cvs rdiff -u -r1.140 -r1.141 src/usr.bin/make/make.h
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.301 -r1.302 src/usr.bin/make/parse.c
cvs rdiff -u -r1.510 -r1.511 src/usr.bin/make/var.c
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.141 src/usr.bin/make/cond.c:1.142
--- src/usr.bin/make/cond.c:1.141 Sat Sep 12 18:19:50 2020
+++ src/usr.bin/make/cond.c Sun Sep 13 13:50:27 2020
@@ -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
/* 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;
* 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, Boole
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 *o
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 ch
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, B
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) 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 *inf
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 *inf
* 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;
Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.140 src/usr.bin/make/make.h:1.141
--- src/usr.bin/make/make.h:1.140 Sun Sep 13 06:15:29 2020
+++ src/usr.bin/make/make.h Sun Sep 13 13:50:27 2020
@@ -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 */
Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.116 src/usr.bin/make/nonints.h:1.117
--- src/usr.bin/make/nonints.h:1.116 Sat Sep 12 18:19:50 2020
+++ src/usr.bin/make/nonints.h Sun Sep 13 13:50:27 2020
@@ -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);
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.301 src/usr.bin/make/parse.c:1.302
--- src/usr.bin/make/parse.c:1.301 Sun Sep 13 13:25:07 2020
+++ src/usr.bin/make/parse.c Sun Sep 13 13:50:27 2020
@@ -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;
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.510 src/usr.bin/make/var.c:1.511
--- src/usr.bin/make/var.c:1.510 Sun Sep 13 09:35:09 2020
+++ src/usr.bin/make/var.c Sun Sep 13 13:50:27 2020
@@ -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, Ap
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)