Module Name:    src
Committed By:   rillig
Date:           Fri Jun 11 14:42:52 UTC 2021

Modified Files:
        src/usr.bin/make: cond.c

Log Message:
make: clean up function names and documentation for conditions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.265 -r1.266 src/usr.bin/make/cond.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.265 src/usr.bin/make/cond.c:1.266
--- src/usr.bin/make/cond.c:1.265	Fri Jun 11 14:37:51 2021
+++ src/usr.bin/make/cond.c	Fri Jun 11 14:42:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $	*/
+/*	$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -95,7 +95,7 @@
 #include "dir.h"
 
 /*	"@(#)cond.c	8.2 (Berkeley) 1/2/94"	*/
-MAKE_RCSID("$NetBSD: cond.c,v 1.265 2021/06/11 14:37:51 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.266 2021/06/11 14:42:52 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -467,12 +467,13 @@ CondParser_StringExpr(CondParser *par, c
 }
 
 /*
- * Parse a string from a variable reference or an optionally quoted
- * string.  This is called for the lhs and rhs of string comparisons.
+ * Parse a string from a variable expression or an optionally quoted
+ * string.  This is called for the left-hand and right-hand sides of
+ * comparisons.
  *
  * Results:
  *	Returns the string, absent any quotes, or NULL on error.
- *	Sets out_quoted if the string was quoted.
+ *	Sets out_quoted if the leaf was a quoted string literal.
  */
 static void
 CondParser_Leaf(CondParser *par, bool doEval, bool strictLHS,
@@ -540,7 +541,7 @@ CondParser_Leaf(CondParser *par, bool do
 got_str:
 	str = FStr_InitOwn(buf.data);
 cleanup:
-	Buf_DoneData(&buf);
+	Buf_DoneData(&buf);	/* XXX: memory leak on failure? */
 	*out_str = str;
 }
 
@@ -824,11 +825,11 @@ CondParser_FuncCall(CondParser *par, boo
 }
 
 /*
- * Parse a function call, a number, a variable expression or a string
- * literal.
+ * Parse a comparison such as '${VAR} == "value"', or a simple leaf without
+ * operator, which is a number, a variable expression or a string literal.
  */
 static Token
-CondParser_LeafToken(CondParser *par, bool doEval)
+CondParser_ComparisonOrLeaf(CondParser *par, bool doEval)
 {
 	Token t;
 	char *arg = NULL;
@@ -849,6 +850,10 @@ CondParser_LeafToken(CondParser *par, bo
 	 * syntax would be invalid if we did "defined(a)" - so instead treat
 	 * as an expression.
 	 */
+	/*
+	 * XXX: Is it possible to have a variable expression evaluated twice
+	 *  at this point?
+	 */
 	arglen = ParseFuncArg(par, &cp, doEval, NULL, &arg);
 	cp1 = cp;
 	cpp_skip_whitespace(&cp1);
@@ -930,7 +935,7 @@ CondParser_Token(CondParser *par, bool d
 	default:
 		if (CondParser_FuncCall(par, doEval, &t))
 			return t;
-		return CondParser_LeafToken(par, doEval);
+		return CondParser_ComparisonOrLeaf(par, doEval);
 	}
 }
 

Reply via email to