Module Name:    src
Committed By:   rillig
Date:           Sun Dec 27 10:53:23 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c nonints.h var.c

Log Message:
make(1): clean up VarParseResult constants

The many constants were invented because at that time I didn't quite
understand the actual outcomes of Var_Parse that need to be
distinguished.  There are only a few:

(1) Errors, whether they are parse errors, or evaluation errors or
    undefined variables.  The old constants VPR_PARSE_MSG and
    VPR_UNDEF_MSG are merged into VPR_ERR.

(2) Undefined expressions in a situation in which they are allowed.
    Previously the documentation for VPR_UNDEF_SILENT talked about
    undefined expressions in situations where they were not allowed.
    That case is fully covered by VPR_ERR instead.

(3) Errors that are silently ignored.  These are probably bugs.

(4) Everything went fine, the expression has a defined value.


To generate a diff of this commit:
cvs rdiff -u -r1.231 -r1.232 src/usr.bin/make/cond.c
cvs rdiff -u -r1.183 -r1.184 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.766 -r1.767 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.231 src/usr.bin/make/cond.c:1.232
--- src/usr.bin/make/cond.c:1.231	Wed Dec 23 13:50:54 2020
+++ src/usr.bin/make/cond.c	Sun Dec 27 10:53:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.231 2020/12/23 13:50:54 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.232 2020/12/27 10:53:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.231 2020/12/23 13:50:54 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.232 2020/12/27 10:53:23 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -452,7 +452,7 @@ CondParser_String(CondParser *par, Boole
 			    &str);
 			/* TODO: handle errors */
 			if (str.str == var_Error) {
-				if (parseResult & VPR_ANY_MSG)
+				if (parseResult == VPR_ERR)
 					par->printedError = TRUE;
 				/*
 				 * XXX: Can there be any situation in which

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.183 src/usr.bin/make/nonints.h:1.184
--- src/usr.bin/make/nonints.h:1.183	Sun Dec 27 10:09:53 2020
+++ src/usr.bin/make/nonints.h	Sun Dec 27 10:53:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nonints.h,v 1.183 2020/12/27 10:09:53 rillig Exp $	*/
+/*	$NetBSD: nonints.h,v 1.184 2020/12/27 10:53:23 rillig Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -316,67 +316,29 @@ typedef enum VarSetFlags {
 	VAR_SET_READONLY	= 1 << 1
 } VarSetFlags;
 
-/* The state of error handling returned by Var_Parse.
- *
- * As of 2020-09-13, this bitset looks quite bloated,
- * with all the constants doubled.
- *
- * Its purpose is to first document the existing behavior,
- * and then migrate away from the SILENT constants, step by step,
- * as these are not suited for reliable, consistent error handling
- * and reporting. */
+/* The state of error handling returned by Var_Parse. */
 typedef enum VarParseResult {
 
 	/* Both parsing and evaluation succeeded. */
-	VPR_OK		= 0x0000,
-
-	/* See if a message has already been printed for this error. */
-	VPR_ANY_MSG		= 0x0001,
-
-	/*
-	 * Parsing failed.
-	 * No error message has been printed yet.
-	 * Deprecated, migrate to VPR_PARSE_MSG instead.
-	 */
-	VPR_PARSE_SILENT	= 0x0002,
-
-	/*
-	 * Parsing failed.
-	 * An error message has already been printed.
-	 */
-	VPR_PARSE_MSG	= VPR_PARSE_SILENT | VPR_ANY_MSG,
+	VPR_OK,
 
-	/*
-	 * Parsing succeeded.
-	 * During evaluation, VARE_UNDEFERR was set and there was an undefined
-	 * variable.
-	 * No error message has been printed yet.
-	 * Deprecated, migrate to VPR_UNDEF_MSG instead.
-	 */
-	VPR_UNDEF_SILENT	= 0x0004,
+	/* Parsing or evaluating failed, with an error message. */
+	VPR_ERR,
 
-	/*
-	 * Parsing succeeded.
-	 * During evaluation, VARE_UNDEFERR was set and there was an undefined
-	 * variable.
-	 * An error message has already been printed.
-	 */
-	VPR_UNDEF_MSG	= VPR_UNDEF_SILENT | VPR_ANY_MSG,
+	/* deprecated */
+	VPR_ERR_SILENT,
 
 	/*
-	 * Parsing succeeded.
-	 * Evaluation failed.
-	 * No error message has been printed yet.
-	 * Deprecated, migrate to VPR_EVAL_MSG instead.
-	 */
-	VPR_EVAL_SILENT	= 0x0006,
-
-	/*
-	 * Parsing succeeded.
-	 * Evaluation failed.
-	 * An error message has already been printed.
+	 * Parsing succeeded, undefined expressions are allowed and the
+	 * expression was still undefined after applying all modifiers.
+	 * No error message is printed in this case.
+	 *
+	 * Some callers handle this case differently, so return this
+	 * information to them, for now.
+	 *
+	 * TODO: Replace this with a new flag VARE_KEEP_UNDEFINED.
 	 */
-	VPR_EVAL_MSG	= VPR_EVAL_SILENT | VPR_ANY_MSG
+	VPR_UNDEF
 
 } VarParseResult;
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.766 src/usr.bin/make/var.c:1.767
--- src/usr.bin/make/var.c:1.766	Sun Dec 27 10:09:53 2020
+++ src/usr.bin/make/var.c	Sun Dec 27 10:53:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.766 2020/12/27 10:09:53 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.766 2020/12/27 10:09:53 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.767 2020/12/27 10:53:23 rillig Exp $");
 
 typedef enum VarFlags {
 	VAR_NONE	= 0,
@@ -2098,7 +2098,7 @@ ParseModifierPartSubst(
 		Error("Unfinished modifier for %s ('%c' missing)",
 		    st->var->name.str, delim);
 		*out_part = NULL;
-		return VPR_PARSE_MSG;
+		return VPR_ERR;
 	}
 
 	*pp = ++p;
@@ -3754,8 +3754,10 @@ ValidShortVarname(char varname, const ch
 		return VPR_OK;
 	}
 
-	if (!opts.strict)
-		return VPR_PARSE_SILENT;
+	if (!opts.strict) {
+		/* XXX: Should rather be a parse error with error message. */
+		return VPR_ERR_SILENT;
+	}
 
 	if (varname == '$')
 		Parse_Error(PARSE_FATAL,
@@ -3766,7 +3768,7 @@ ValidShortVarname(char varname, const ch
 		Parse_Error(PARSE_FATAL,
 		    "Invalid variable name '%c', at \"%s\"", varname, start);
 
-	return VPR_PARSE_MSG;
+	return VPR_ERR;
 }
 
 /* Parse a single-character variable name such as $V or $@.
@@ -3805,11 +3807,21 @@ ParseVarnameShort(char startc, const cha
 		if (opts.strict && *out_FALSE_val == var_Error) {
 			Parse_Error(PARSE_FATAL,
 			    "Variable \"%s\" is undefined", name);
-			*out_FALSE_res = VPR_UNDEF_MSG;
+			*out_FALSE_res = VPR_ERR;
 			return FALSE;
 		}
-		*out_FALSE_res =
-		    eflags & VARE_UNDEFERR ? VPR_UNDEF_SILENT : VPR_OK;
+
+		/*
+		 * 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 = eflags & VARE_UNDEFERR ? VPR_UNDEF : VPR_OK;
 		return FALSE;
 	}
 
@@ -3864,13 +3876,13 @@ EvalUndefined(Boolean dynamic, const cha
 		    "Variable \"%s\" is undefined", varname);
 		free(varname);
 		*out_val = FStr_InitRefer(var_Error);
-		return VPR_UNDEF_MSG;
+		return VPR_ERR;
 	}
 
 	if (eflags & VARE_UNDEFERR) {
 		free(varname);
 		*out_val = FStr_InitRefer(var_Error);
-		return VPR_UNDEF_SILENT;
+		return VPR_UNDEF;	/* XXX: Should be VPR_ERR instead. */
 	}
 
 	free(varname);
@@ -3923,7 +3935,7 @@ ParseVarnameLong(
 		free(varname);
 		*out_FALSE_pp = p;
 		*out_FALSE_val = FStr_InitRefer(var_Error);
-		*out_FALSE_res = VPR_PARSE_MSG;
+		*out_FALSE_res = VPR_ERR;
 		return FALSE;
 	}
 

Reply via email to