Mon Mar 15 11:41:07 2021 UTC ()
make: rename VARE_NONE to VARE_PARSE_ONLY

The name 'NONE' described the bit pattern, which was not useful to
understand its meaning.  Omitting VARE_WANTRES only parses the
expression, without evaluating any part of it.

No functional change, not even in debug mode since Enum_FlagsToString
always returns "none" for all-bits-unset.


(rillig)
diff -r1.257 -r1.258 src/usr.bin/make/cond.c
diff -r1.203 -r1.204 src/usr.bin/make/nonints.h
diff -r1.550 -r1.551 src/usr.bin/make/parse.c
diff -r1.346 -r1.347 src/usr.bin/make/suff.c
diff -r1.883 -r1.884 src/usr.bin/make/var.c

cvs diff -r1.257 -r1.258 src/usr.bin/make/cond.c (expand / switch to unified diff)

--- src/usr.bin/make/cond.c 2021/02/22 23:21:33 1.257
+++ src/usr.bin/make/cond.c 2021/03/15 11:41:07 1.258
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cond.c,v 1.257 2021/02/22 23:21:33 rillig Exp $ */ 1/* $NetBSD: cond.c,v 1.258 2021/03/15 11:41:07 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -85,27 +85,27 @@ @@ -85,27 +85,27 @@
85 * Cond_restore_depth 85 * Cond_restore_depth
86 * Save and restore the nesting of the conditions, at 86 * Save and restore the nesting of the conditions, at
87 * the start and end of including another makefile, to 87 * the start and end of including another makefile, to
88 * ensure that in each makefile the conditional 88 * ensure that in each makefile the conditional
89 * directives are well-balanced. 89 * directives are well-balanced.
90 */ 90 */
91 91
92#include <errno.h> 92#include <errno.h>
93 93
94#include "make.h" 94#include "make.h"
95#include "dir.h" 95#include "dir.h"
96 96
97/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ 97/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
98MAKE_RCSID("$NetBSD: cond.c,v 1.257 2021/02/22 23:21:33 rillig Exp $"); 98MAKE_RCSID("$NetBSD: cond.c,v 1.258 2021/03/15 11:41:07 rillig Exp $");
99 99
100/* 100/*
101 * The parsing of conditional expressions is based on this grammar: 101 * The parsing of conditional expressions is based on this grammar:
102 * Or -> And '||' Or 102 * Or -> And '||' Or
103 * Or -> And 103 * Or -> And
104 * And -> Term '&&' And 104 * And -> Term '&&' And
105 * And -> Term 105 * And -> Term
106 * Term -> Function '(' Argument ')' 106 * Term -> Function '(' Argument ')'
107 * Term -> Leaf Operator Leaf 107 * Term -> Leaf Operator Leaf
108 * Term -> Leaf 108 * Term -> Leaf
109 * Term -> '(' Or ')' 109 * Term -> '(' Or ')'
110 * Term -> '!' Term 110 * Term -> '!' Term
111 * Leaf -> "string" 111 * Leaf -> "string"
@@ -256,27 +256,27 @@ ParseFuncArg(CondParser *par, const char @@ -256,27 +256,27 @@ ParseFuncArg(CondParser *par, const char
256 if ((ch == '&' || ch == '|') && paren_depth == 0) 256 if ((ch == '&' || ch == '|') && paren_depth == 0)
257 break; 257 break;
258 if (*p == '$') { 258 if (*p == '$') {
259 /* 259 /*
260 * Parse the variable expression and install it as 260 * Parse the variable expression and install it as
261 * part of the argument if it's valid. We tell 261 * part of the argument if it's valid. We tell
262 * Var_Parse to complain on an undefined variable, 262 * Var_Parse to complain on an undefined variable,
263 * (XXX: but Var_Parse ignores that request) 263 * (XXX: but Var_Parse ignores that request)
264 * so we don't need to do it. Nor do we return an 264 * so we don't need to do it. Nor do we return an
265 * error, though perhaps we should. 265 * error, though perhaps we should.
266 */ 266 */
267 VarEvalFlags eflags = doEval 267 VarEvalFlags eflags = doEval
268 ? VARE_WANTRES | VARE_UNDEFERR 268 ? VARE_WANTRES | VARE_UNDEFERR
269 : VARE_NONE; 269 : VARE_PARSE_ONLY;
270 FStr nestedVal; 270 FStr nestedVal;
271 (void)Var_Parse(&p, SCOPE_CMDLINE, eflags, &nestedVal); 271 (void)Var_Parse(&p, SCOPE_CMDLINE, eflags, &nestedVal);
272 /* TODO: handle errors */ 272 /* TODO: handle errors */
273 Buf_AddStr(&argBuf, nestedVal.str); 273 Buf_AddStr(&argBuf, nestedVal.str);
274 FStr_Done(&nestedVal); 274 FStr_Done(&nestedVal);
275 continue; 275 continue;
276 } 276 }
277 if (ch == '(') 277 if (ch == '(')
278 paren_depth++; 278 paren_depth++;
279 else if (ch == ')' && --paren_depth < 0) 279 else if (ch == ')' && --paren_depth < 0)
280 break; 280 break;
281 Buf_AddByte(&argBuf, *p); 281 Buf_AddByte(&argBuf, *p);
282 p++; 282 p++;
@@ -412,27 +412,27 @@ is_separator(char ch) @@ -412,27 +412,27 @@ is_separator(char ch)
412static Boolean 412static Boolean
413CondParser_StringExpr(CondParser *par, const char *start, 413CondParser_StringExpr(CondParser *par, const char *start,
414 Boolean const doEval, Boolean const quoted, 414 Boolean const doEval, Boolean const quoted,
415 Buffer *buf, FStr *const inout_str) 415 Buffer *buf, FStr *const inout_str)
416{ 416{
417 VarEvalFlags eflags; 417 VarEvalFlags eflags;
418 const char *nested_p; 418 const char *nested_p;
419 Boolean atStart; 419 Boolean atStart;
420 VarParseResult parseResult; 420 VarParseResult parseResult;
421 421
422 /* if we are in quotes, an undefined variable is ok */ 422 /* if we are in quotes, an undefined variable is ok */
423 eflags = doEval && !quoted ? VARE_WANTRES | VARE_UNDEFERR 423 eflags = doEval && !quoted ? VARE_WANTRES | VARE_UNDEFERR
424 : doEval ? VARE_WANTRES 424 : doEval ? VARE_WANTRES
425 : VARE_NONE; 425 : VARE_PARSE_ONLY;
426 426
427 nested_p = par->p; 427 nested_p = par->p;
428 atStart = nested_p == start; 428 atStart = nested_p == start;
429 parseResult = Var_Parse(&nested_p, SCOPE_CMDLINE, eflags, inout_str); 429 parseResult = Var_Parse(&nested_p, SCOPE_CMDLINE, eflags, inout_str);
430 /* TODO: handle errors */ 430 /* TODO: handle errors */
431 if (inout_str->str == var_Error) { 431 if (inout_str->str == var_Error) {
432 if (parseResult == VPR_ERR) { 432 if (parseResult == VPR_ERR) {
433 /* 433 /*
434 * FIXME: Even if an error occurs, there is no 434 * FIXME: Even if an error occurs, there is no
435 * guarantee that it is reported. 435 * guarantee that it is reported.
436 * 436 *
437 * See cond-token-plain.mk $$$$$$$$. 437 * See cond-token-plain.mk $$$$$$$$.
438 */ 438 */
@@ -730,28 +730,28 @@ done_lhs: @@ -730,28 +730,28 @@ done_lhs:
730/*ARGSUSED*/ 730/*ARGSUSED*/
731static size_t 731static size_t
732ParseEmptyArg(CondParser *par MAKE_ATTR_UNUSED, const char **pp, 732ParseEmptyArg(CondParser *par MAKE_ATTR_UNUSED, const char **pp,
733 Boolean doEval, const char *func MAKE_ATTR_UNUSED, 733 Boolean doEval, const char *func MAKE_ATTR_UNUSED,
734 char **out_arg) 734 char **out_arg)
735{ 735{
736 FStr val; 736 FStr val;
737 size_t magic_res; 737 size_t magic_res;
738 738
739 /* We do all the work here and return the result as the length */ 739 /* We do all the work here and return the result as the length */
740 *out_arg = NULL; 740 *out_arg = NULL;
741 741
742 (*pp)--; /* Make (*pp)[1] point to the '('. */ 742 (*pp)--; /* Make (*pp)[1] point to the '('. */
743 (void)Var_Parse(pp, SCOPE_CMDLINE, doEval ? VARE_WANTRES : VARE_NONE, 743 (void)Var_Parse(pp, SCOPE_CMDLINE,
744 &val); 744 doEval ? VARE_WANTRES : VARE_PARSE_ONLY, &val);
745 /* TODO: handle errors */ 745 /* TODO: handle errors */
746 /* If successful, *pp points beyond the closing ')' now. */ 746 /* If successful, *pp points beyond the closing ')' now. */
747 747
748 if (val.str == var_Error) { 748 if (val.str == var_Error) {
749 FStr_Done(&val); 749 FStr_Done(&val);
750 return (size_t)-1; 750 return (size_t)-1;
751 } 751 }
752 752
753 /* 753 /*
754 * A variable is empty when it just contains spaces... 754 * A variable is empty when it just contains spaces...
755 * 4/15/92, christos 755 * 4/15/92, christos
756 */ 756 */
757 cpp_skip_whitespace(&val.str); 757 cpp_skip_whitespace(&val.str);

cvs diff -r1.203 -r1.204 src/usr.bin/make/Attic/nonints.h (expand / switch to unified diff)

--- src/usr.bin/make/Attic/nonints.h 2021/02/14 21:32:58 1.203
+++ src/usr.bin/make/Attic/nonints.h 2021/03/15 11:41:07 1.204
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nonints.h,v 1.203 2021/02/14 21:32:58 rillig Exp $ */ 1/* $NetBSD: nonints.h,v 1.204 2021/03/15 11:41:07 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -283,27 +283,27 @@ void Targ_PrintCmds(GNode *); @@ -283,27 +283,27 @@ void Targ_PrintCmds(GNode *);
283void Targ_PrintNode(GNode *, int); 283void Targ_PrintNode(GNode *, int);
284void Targ_PrintNodes(GNodeList *, int); 284void Targ_PrintNodes(GNodeList *, int);
285const char *Targ_FmtTime(time_t); 285const char *Targ_FmtTime(time_t);
286void Targ_PrintType(int); 286void Targ_PrintType(int);
287void Targ_PrintGraph(int); 287void Targ_PrintGraph(int);
288void Targ_Propagate(void); 288void Targ_Propagate(void);
289const char *GNodeMade_Name(GNodeMade); 289const char *GNodeMade_Name(GNodeMade);
290 290
291/* var.c */ 291/* var.c */
292void Var_Init(void); 292void Var_Init(void);
293void Var_End(void); 293void Var_End(void);
294 294
295typedef enum VarEvalFlags { 295typedef enum VarEvalFlags {
296 VARE_NONE = 0, 296 VARE_PARSE_ONLY = 0,
297 297
298 /* 298 /*
299 * Expand and evaluate variables during parsing. 299 * Expand and evaluate variables during parsing.
300 * 300 *
301 * TODO: Document what Var_Parse and Var_Subst return when this flag 301 * TODO: Document what Var_Parse and Var_Subst return when this flag
302 * is not set. 302 * is not set.
303 */ 303 */
304 VARE_WANTRES = 1 << 0, 304 VARE_WANTRES = 1 << 0,
305 305
306 /* 306 /*
307 * Treat undefined variables as errors. 307 * Treat undefined variables as errors.
308 * Must only be used in combination with VARE_WANTRES. 308 * Must only be used in combination with VARE_WANTRES.
309 */ 309 */

cvs diff -r1.550 -r1.551 src/usr.bin/make/parse.c (expand / switch to unified diff)

--- src/usr.bin/make/parse.c 2021/02/22 23:21:33 1.550
+++ src/usr.bin/make/parse.c 2021/03/15 11:41:07 1.551
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parse.c,v 1.550 2021/02/22 23:21:33 rillig Exp $ */ 1/* $NetBSD: parse.c,v 1.551 2021/03/15 11:41:07 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -99,27 +99,27 @@ @@ -99,27 +99,27 @@
99 99
100#include <sys/types.h> 100#include <sys/types.h>
101#include <sys/stat.h> 101#include <sys/stat.h>
102#include <errno.h> 102#include <errno.h>
103#include <stdarg.h> 103#include <stdarg.h>
104#include <stdint.h> 104#include <stdint.h>
105 105
106#include "make.h" 106#include "make.h"
107#include "dir.h" 107#include "dir.h"
108#include "job.h" 108#include "job.h"
109#include "pathnames.h" 109#include "pathnames.h"
110 110
111/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ 111/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
112MAKE_RCSID("$NetBSD: parse.c,v 1.550 2021/02/22 23:21:33 rillig Exp $"); 112MAKE_RCSID("$NetBSD: parse.c,v 1.551 2021/03/15 11:41:07 rillig Exp $");
113 113
114/* types and constants */ 114/* types and constants */
115 115
116/* 116/*
117 * Structure for a file being read ("included file") 117 * Structure for a file being read ("included file")
118 */ 118 */
119typedef struct IFile { 119typedef struct IFile {
120 char *fname; /* name of file (relative? absolute?) */ 120 char *fname; /* name of file (relative? absolute?) */
121 Boolean fromForLoop; /* simulated .include by the .for loop */ 121 Boolean fromForLoop; /* simulated .include by the .for loop */
122 int lineno; /* current line number in file */ 122 int lineno; /* current line number in file */
123 int first_lineno; /* line number of start of text */ 123 int first_lineno; /* line number of start of text */
124 unsigned int cond_depth; /* 'if' nesting when file opened */ 124 unsigned int cond_depth; /* 'if' nesting when file opened */
125 Boolean depending; /* state of doing_depend on EOF */ 125 Boolean depending; /* state of doing_depend on EOF */
@@ -1032,28 +1032,28 @@ ParseDependencyTargetWord(const char **p @@ -1032,28 +1032,28 @@ ParseDependencyTargetWord(const char **p
1032 if (*cp == '$') { 1032 if (*cp == '$') {
1033 /* 1033 /*
1034 * Must be a dynamic source (would have been expanded 1034 * Must be a dynamic source (would have been expanded
1035 * otherwise), so call the Var module to parse the 1035 * otherwise), so call the Var module to parse the
1036 * puppy so we can safely advance beyond it. 1036 * puppy so we can safely advance beyond it.
1037 * 1037 *
1038 * There should be no errors in this, as they would 1038 * There should be no errors in this, as they would
1039 * have been discovered in the initial Var_Subst and 1039 * have been discovered in the initial Var_Subst and
1040 * we wouldn't be here. 1040 * we wouldn't be here.
1041 */ 1041 */
1042 const char *nested_p = cp; 1042 const char *nested_p = cp;
1043 FStr nested_val; 1043 FStr nested_val;
1044 1044
1045 (void)Var_Parse(&nested_p, SCOPE_CMDLINE, VARE_NONE, 1045 (void)Var_Parse(&nested_p, SCOPE_CMDLINE,
1046 &nested_val); 1046 VARE_PARSE_ONLY, &nested_val);
1047 /* TODO: handle errors */ 1047 /* TODO: handle errors */
1048 FStr_Done(&nested_val); 1048 FStr_Done(&nested_val);
1049 cp += nested_p - cp; 1049 cp += nested_p - cp;
1050 } else 1050 } else
1051 cp++; 1051 cp++;
1052 } 1052 }
1053 1053
1054 *pp = cp; 1054 *pp = cp;
1055} 1055}
1056 1056
1057/* Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER. */ 1057/* Handle special targets like .PATH, .DEFAULT, .BEGIN, .ORDER. */
1058static void 1058static void
1059ParseDoDependencyTargetSpecial(ParseSpecial *inout_specType, 1059ParseDoDependencyTargetSpecial(ParseSpecial *inout_specType,
@@ -1864,27 +1864,27 @@ Parse_IsVar(const char *p, VarAssign *ou @@ -1864,27 +1864,27 @@ Parse_IsVar(const char *p, VarAssign *ou
1864 return FALSE; 1864 return FALSE;
1865} 1865}
1866 1866
1867/* 1867/*
1868 * Check for syntax errors such as unclosed expressions or unknown modifiers. 1868 * Check for syntax errors such as unclosed expressions or unknown modifiers.
1869 */ 1869 */
1870static void 1870static void
1871VarCheckSyntax(VarAssignOp type, const char *uvalue, GNode *scope) 1871VarCheckSyntax(VarAssignOp type, const char *uvalue, GNode *scope)
1872{ 1872{
1873 if (opts.strict) { 1873 if (opts.strict) {
1874 if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) { 1874 if (type != VAR_SUBST && strchr(uvalue, '$') != NULL) {
1875 char *expandedValue; 1875 char *expandedValue;
1876 1876
1877 (void)Var_Subst(uvalue, scope, VARE_NONE, 1877 (void)Var_Subst(uvalue, scope, VARE_PARSE_ONLY,
1878 &expandedValue); 1878 &expandedValue);
1879 /* TODO: handle errors */ 1879 /* TODO: handle errors */
1880 free(expandedValue); 1880 free(expandedValue);
1881 } 1881 }
1882 } 1882 }
1883} 1883}
1884 1884
1885static void 1885static void
1886VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue, 1886VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue,
1887 FStr *out_avalue) 1887 FStr *out_avalue)
1888{ 1888{
1889 char *evalue; 1889 char *evalue;
1890 1890

cvs diff -r1.346 -r1.347 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2021/02/23 15:56:29 1.346
+++ src/usr.bin/make/suff.c 2021/03/15 11:41:07 1.347
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.346 2021/02/23 15:56:29 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.347 2021/03/15 11:41:07 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -104,27 +104,27 @@ @@ -104,27 +104,27 @@
104 * Suff_FindDeps Find implicit sources for and the location of 104 * Suff_FindDeps Find implicit sources for and the location of
105 * a target based on its suffix. Returns the 105 * a target based on its suffix. Returns the
106 * bottom-most node added to the graph or NULL 106 * bottom-most node added to the graph or NULL
107 * if the target had no implicit sources. 107 * if the target had no implicit sources.
108 * 108 *
109 * Suff_FindPath Return the appropriate path to search in order to 109 * Suff_FindPath Return the appropriate path to search in order to
110 * find the node. 110 * find the node.
111 */ 111 */
112 112
113#include "make.h" 113#include "make.h"
114#include "dir.h" 114#include "dir.h"
115 115
116/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */ 116/* "@(#)suff.c 8.4 (Berkeley) 3/21/94" */
117MAKE_RCSID("$NetBSD: suff.c,v 1.346 2021/02/23 15:56:29 rillig Exp $"); 117MAKE_RCSID("$NetBSD: suff.c,v 1.347 2021/03/15 11:41:07 rillig Exp $");
118 118
119typedef List SuffixList; 119typedef List SuffixList;
120typedef ListNode SuffixListNode; 120typedef ListNode SuffixListNode;
121 121
122typedef List CandidateList; 122typedef List CandidateList;
123typedef ListNode CandidateListNode; 123typedef ListNode CandidateListNode;
124 124
125/* The defined suffixes, such as '.c', '.o', '.l'. */ 125/* The defined suffixes, such as '.c', '.o', '.l'. */
126static SuffixList sufflist = LST_INIT; 126static SuffixList sufflist = LST_INIT;
127#ifdef CLEANUP 127#ifdef CLEANUP
128/* The suffixes to be cleaned up at the end. */ 128/* The suffixes to be cleaned up at the end. */
129static SuffixList suffClean = LST_INIT; 129static SuffixList suffClean = LST_INIT;
130#endif 130#endif
@@ -1299,27 +1299,27 @@ ExpandChildrenRegular(char *cp, GNode *p @@ -1299,27 +1299,27 @@ ExpandChildrenRegular(char *cp, GNode *p
1299 * add it, skip any further spaces. 1299 * add it, skip any further spaces.
1300 */ 1300 */
1301 *cp++ = '\0'; 1301 *cp++ = '\0';
1302 gn = Targ_GetNode(start); 1302 gn = Targ_GetNode(start);
1303 Lst_Append(members, gn); 1303 Lst_Append(members, gn);
1304 pp_skip_hspace(&cp); 1304 pp_skip_hspace(&cp);
1305 /* Continue at the next non-space. */ 1305 /* Continue at the next non-space. */
1306 start = cp; 1306 start = cp;
1307 } else if (*cp == '$') { 1307 } else if (*cp == '$') {
1308 /* Skip over the variable expression. */ 1308 /* Skip over the variable expression. */
1309 const char *nested_p = cp; 1309 const char *nested_p = cp;
1310 FStr junk; 1310 FStr junk;
1311 1311
1312 (void)Var_Parse(&nested_p, pgn, VARE_NONE, &junk); 1312 (void)Var_Parse(&nested_p, pgn, VARE_PARSE_ONLY, &junk);
1313 /* TODO: handle errors */ 1313 /* TODO: handle errors */
1314 if (junk.str == var_Error) { 1314 if (junk.str == var_Error) {
1315 Parse_Error(PARSE_FATAL, 1315 Parse_Error(PARSE_FATAL,
1316 "Malformed variable expression at \"%s\"", 1316 "Malformed variable expression at \"%s\"",
1317 cp); 1317 cp);
1318 cp++; 1318 cp++;
1319 } else { 1319 } else {
1320 cp += nested_p - cp; 1320 cp += nested_p - cp;
1321 } 1321 }
1322 1322
1323 FStr_Done(&junk); 1323 FStr_Done(&junk);
1324 } else if (cp[0] == '\\' && cp[1] != '\0') { 1324 } else if (cp[0] == '\\' && cp[1] != '\0') {
1325 /* Escaped something -- skip over it. */ 1325 /* Escaped something -- skip over it. */

cvs diff -r1.883 -r1.884 src/usr.bin/make/var.c (expand / switch to unified diff)

--- src/usr.bin/make/var.c 2021/03/14 20:23:29 1.883
+++ src/usr.bin/make/var.c 2021/03/15 11:41:07 1.884
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: var.c,v 1.883 2021/03/14 20:23:29 rillig Exp $ */ 1/* $NetBSD: var.c,v 1.884 2021/03/15 11:41:07 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -130,27 +130,27 @@ @@ -130,27 +130,27 @@
130#include <regex.h> 130#include <regex.h>
131#endif 131#endif
132#include <errno.h> 132#include <errno.h>
133#include <inttypes.h> 133#include <inttypes.h>
134#include <limits.h> 134#include <limits.h>
135#include <time.h> 135#include <time.h>
136 136
137#include "make.h" 137#include "make.h"
138#include "dir.h" 138#include "dir.h"
139#include "job.h" 139#include "job.h"
140#include "metachar.h" 140#include "metachar.h"
141 141
142/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ 142/* "@(#)var.c 8.3 (Berkeley) 3/19/94" */
143MAKE_RCSID("$NetBSD: var.c,v 1.883 2021/03/14 20:23:29 rillig Exp $"); 143MAKE_RCSID("$NetBSD: var.c,v 1.884 2021/03/15 11:41:07 rillig Exp $");
144 144
145typedef enum VarFlags { 145typedef enum VarFlags {
146 VFL_NONE = 0, 146 VFL_NONE = 0,
147 147
148 /* 148 /*
149 * The variable's value is currently being used by Var_Parse or 149 * The variable's value is currently being used by Var_Parse or
150 * Var_Subst. This marker is used to avoid endless recursion. 150 * Var_Subst. This marker is used to avoid endless recursion.
151 */ 151 */
152 VFL_IN_USE = 1 << 0, 152 VFL_IN_USE = 1 << 0,
153 153
154 /* 154 /*
155 * The variable comes from the environment. 155 * The variable comes from the environment.
156 * These variables are not registered in any GNode, therefore they 156 * These variables are not registered in any GNode, therefore they
@@ -2398,38 +2398,38 @@ done: @@ -2398,38 +2398,38 @@ done:
2398 2398
2399/* :@var@...${var}...@ */ 2399/* :@var@...${var}...@ */
2400static ApplyModifierResult 2400static ApplyModifierResult
2401ApplyModifier_Loop(const char **pp, ApplyModifiersState *st) 2401ApplyModifier_Loop(const char **pp, ApplyModifiersState *st)
2402{ 2402{
2403 Expr *expr = st->expr; 2403 Expr *expr = st->expr;
2404 struct ModifyWord_LoopArgs args; 2404 struct ModifyWord_LoopArgs args;
2405 char prev_sep; 2405 char prev_sep;
2406 VarParseResult res; 2406 VarParseResult res;
2407 2407
2408 args.scope = expr->scope; 2408 args.scope = expr->scope;
2409 2409
2410 (*pp)++; /* Skip the first '@' */ 2410 (*pp)++; /* Skip the first '@' */
2411 res = ParseModifierPart(pp, '@', VARE_NONE, st, &args.tvar); 2411 res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, st, &args.tvar);
2412 if (res != VPR_OK) 2412 if (res != VPR_OK)
2413 return AMR_CLEANUP; 2413 return AMR_CLEANUP;
2414 if (opts.strict && strchr(args.tvar, '$') != NULL) { 2414 if (opts.strict && strchr(args.tvar, '$') != NULL) {
2415 Parse_Error(PARSE_FATAL, 2415 Parse_Error(PARSE_FATAL,
2416 "In the :@ modifier of \"%s\", the variable name \"%s\" " 2416 "In the :@ modifier of \"%s\", the variable name \"%s\" "
2417 "must not contain a dollar.", 2417 "must not contain a dollar.",
2418 expr->var->name.str, args.tvar); 2418 expr->var->name.str, args.tvar);
2419 return AMR_CLEANUP; 2419 return AMR_CLEANUP;
2420 } 2420 }
2421 2421
2422 res = ParseModifierPart(pp, '@', VARE_NONE, st, &args.str); 2422 res = ParseModifierPart(pp, '@', VARE_PARSE_ONLY, st, &args.str);
2423 if (res != VPR_OK) 2423 if (res != VPR_OK)
2424 return AMR_CLEANUP; 2424 return AMR_CLEANUP;
2425 2425
2426 if (!(expr->eflags & VARE_WANTRES)) 2426 if (!(expr->eflags & VARE_WANTRES))
2427 goto done; 2427 goto done;
2428 2428
2429 args.eflags = expr->eflags & ~(unsigned)VARE_KEEP_DOLLAR; 2429 args.eflags = expr->eflags & ~(unsigned)VARE_KEEP_DOLLAR;
2430 prev_sep = st->sep; 2430 prev_sep = st->sep;
2431 st->sep = ' '; /* XXX: should be st->sep for consistency */ 2431 st->sep = ' '; /* XXX: should be st->sep for consistency */
2432 ModifyWords(st, ModifyWord_Loop, &args, st->oneBigWord); 2432 ModifyWords(st, ModifyWord_Loop, &args, st->oneBigWord);
2433 st->sep = prev_sep; 2433 st->sep = prev_sep;
2434 /* XXX: Consider restoring the previous variable instead of deleting. */ 2434 /* XXX: Consider restoring the previous variable instead of deleting. */
2435 /* 2435 /*
@@ -2442,27 +2442,27 @@ done: @@ -2442,27 +2442,27 @@ done:
2442 free(args.tvar); 2442 free(args.tvar);
2443 free(args.str); 2443 free(args.str);
2444 return AMR_OK; 2444 return AMR_OK;
2445} 2445}
2446 2446
2447/* :Ddefined or :Uundefined */ 2447/* :Ddefined or :Uundefined */
2448static ApplyModifierResult 2448static ApplyModifierResult
2449ApplyModifier_Defined(const char **pp, ApplyModifiersState *st) 2449ApplyModifier_Defined(const char **pp, ApplyModifiersState *st)
2450{ 2450{
2451 Expr *expr = st->expr; 2451 Expr *expr = st->expr;
2452 Buffer buf; 2452 Buffer buf;
2453 const char *p; 2453 const char *p;
2454 2454
2455 VarEvalFlags eflags = VARE_NONE; 2455 VarEvalFlags eflags = VARE_PARSE_ONLY;
2456 if (expr->eflags & VARE_WANTRES) 2456 if (expr->eflags & VARE_WANTRES)
2457 if ((**pp == 'D') == (expr->defined == DEF_REGULAR)) 2457 if ((**pp == 'D') == (expr->defined == DEF_REGULAR))
2458 eflags = expr->eflags; 2458 eflags = expr->eflags;
2459 2459
2460 Buf_Init(&buf); 2460 Buf_Init(&buf);
2461 p = *pp + 1; 2461 p = *pp + 1;
2462 while (!IsDelimiter(*p, st) && *p != '\0') { 2462 while (!IsDelimiter(*p, st) && *p != '\0') {
2463 2463
2464 /* XXX: This code is similar to the one in Var_Parse. 2464 /* XXX: This code is similar to the one in Var_Parse.
2465 * See if the code can be merged. 2465 * See if the code can be merged.
2466 * See also ApplyModifier_Match and ParseModifierPart. */ 2466 * See also ApplyModifier_Match and ParseModifierPart. */
2467 2467
2468 /* Escaped delimiter or other special character */ 2468 /* Escaped delimiter or other special character */
@@ -3282,28 +3282,28 @@ ApplyModifier_Order(const char **pp, App @@ -3282,28 +3282,28 @@ ApplyModifier_Order(const char **pp, App
3282 3282
3283 return AMR_OK; 3283 return AMR_OK;
3284} 3284}
3285 3285
3286/* :? then : else */ 3286/* :? then : else */
3287static ApplyModifierResult 3287static ApplyModifierResult
3288ApplyModifier_IfElse(const char **pp, ApplyModifiersState *st) 3288ApplyModifier_IfElse(const char **pp, ApplyModifiersState *st)
3289{ 3289{
3290 Expr *expr = st->expr; 3290 Expr *expr = st->expr;
3291 char *then_expr, *else_expr; 3291 char *then_expr, *else_expr;
3292 VarParseResult res; 3292 VarParseResult res;
3293 3293
3294 Boolean value = FALSE; 3294 Boolean value = FALSE;
3295 VarEvalFlags then_eflags = VARE_NONE; 3295 VarEvalFlags then_eflags = VARE_PARSE_ONLY;
3296 VarEvalFlags else_eflags = VARE_NONE; 3296 VarEvalFlags else_eflags = VARE_PARSE_ONLY;
3297 3297
3298 int cond_rc = COND_PARSE; /* anything other than COND_INVALID */ 3298 int cond_rc = COND_PARSE; /* anything other than COND_INVALID */
3299 if (expr->eflags & VARE_WANTRES) { 3299 if (expr->eflags & VARE_WANTRES) {
3300 cond_rc = Cond_EvalCondition(expr->var->name.str, &value); 3300 cond_rc = Cond_EvalCondition(expr->var->name.str, &value);
3301 if (cond_rc != COND_INVALID && value) 3301 if (cond_rc != COND_INVALID && value)
3302 then_eflags = expr->eflags; 3302 then_eflags = expr->eflags;
3303 if (cond_rc != COND_INVALID && !value) 3303 if (cond_rc != COND_INVALID && !value)
3304 else_eflags = expr->eflags; 3304 else_eflags = expr->eflags;
3305 } 3305 }
3306 3306
3307 (*pp)++; /* skip past the '?' */ 3307 (*pp)++; /* skip past the '?' */
3308 res = ParseModifierPart(pp, ':', then_eflags, st, &then_expr); 3308 res = ParseModifierPart(pp, ':', then_eflags, st, &then_expr);
3309 if (res != VPR_OK) 3309 if (res != VPR_OK)