Module Name: src Committed By: rillig Date: Sat Dec 11 10:41:31 UTC 2021
Modified Files: src/usr.bin/make: cond.c var.c src/usr.bin/make/unit-tests: cond-func-empty.mk Log Message: make: inline ParseEmptyArg into CondParser_FuncCallEmpty No functional change. To generate a diff of this commit: cvs rdiff -u -r1.294 -r1.295 src/usr.bin/make/cond.c cvs rdiff -u -r1.970 -r1.971 src/usr.bin/make/var.c cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/unit-tests/cond-func-empty.mk 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.294 src/usr.bin/make/cond.c:1.295 --- src/usr.bin/make/cond.c:1.294 Sat Dec 11 10:28:59 2021 +++ src/usr.bin/make/cond.c Sat Dec 11 10:41:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.294 2021/12/11 10:28:59 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.295 2021/12/11 10:41:31 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.294 2021/12/11 10:28:59 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.295 2021/12/11 10:41:31 rillig Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -563,7 +563,10 @@ EvalNotEmpty(CondParser *par, const char /* For .if ${...}, check for non-empty string. This is different from * the evaluation function from that .if variant, which would test * whether a variable of the given name were defined. */ - /* XXX: Whitespace should count as empty, just as in ParseEmptyArg. */ + /* + * XXX: Whitespace should count as empty, just as in + * CondParser_FuncCallEmpty. + */ if (par->plain) return value[0] != '\0'; @@ -715,17 +718,26 @@ done_lhs: * The argument to empty() is a variable name, optionally followed by * variable modifiers. */ -static Token -ParseEmptyArg(const char **pp, bool doEval) +static bool +CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token) { - FStr val; + const char *cp = par->p; Token tok; + FStr val; + + if (!is_token(cp, "empty", 5)) + return false; + cp += 5; + + cpp_skip_whitespace(&cp); + if (*cp != '(') + return false; - (*pp)--; /* Make (*pp)[1] point to the '('. */ - (void)Var_Parse(pp, SCOPE_CMDLINE, + cp--; /* Make cp[1] point to the '('. */ + (void)Var_Parse(&cp, SCOPE_CMDLINE, doEval ? VARE_WANTRES : VARE_PARSE_ONLY, &val); /* TODO: handle errors */ - /* If successful, *pp points beyond the closing ')' now. */ + /* If successful, cp points beyond the closing ')' now. */ if (val.str == var_Error) tok = TOK_ERROR; @@ -735,24 +747,6 @@ ParseEmptyArg(const char **pp, bool doEv } FStr_Done(&val); - return tok; -} - -static bool -CondParser_FuncCallEmpty(CondParser *par, bool doEval, Token *out_token) -{ - Token tok; - const char *cp = par->p; - - if (!is_token(cp, "empty", 5)) - return false; - cp += 5; - - cpp_skip_whitespace(&cp); - if (*cp != '(') - return false; - - tok = ParseEmptyArg(&cp, doEval); if (tok == TOK_FALSE && !doEval) tok = TOK_TRUE; *out_token = tok; Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.970 src/usr.bin/make/var.c:1.971 --- src/usr.bin/make/var.c:1.970 Thu Dec 9 20:27:01 2021 +++ src/usr.bin/make/var.c Sat Dec 11 10:41:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.970 2021/12/09 20:27:01 rillig Exp $ */ +/* $NetBSD: var.c,v 1.971 2021/12/11 10:41:31 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -140,7 +140,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.970 2021/12/09 20:27:01 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.971 2021/12/11 10:41:31 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -4517,9 +4517,9 @@ Var_Parse_FastLane(const char **pp, VarE * * Input: * *pp The string to parse. - * When parsing a condition in ParseEmptyArg, it may also - * point to the "y" of "empty(VARNAME:Modifiers)", which - * is syntactically the same. + * In CondParser_FuncCallEmpty, it may also point to the + * "y" of "empty(VARNAME:Modifiers)", which is + * syntactically the same. * scope The scope for finding variables * emode Controls the exact details of parsing and evaluation * Index: src/usr.bin/make/unit-tests/cond-func-empty.mk diff -u src/usr.bin/make/unit-tests/cond-func-empty.mk:1.15 src/usr.bin/make/unit-tests/cond-func-empty.mk:1.16 --- src/usr.bin/make/unit-tests/cond-func-empty.mk:1.15 Sat Dec 11 09:53:53 2021 +++ src/usr.bin/make/unit-tests/cond-func-empty.mk Sat Dec 11 10:41:31 2021 @@ -1,4 +1,4 @@ -# $NetBSD: cond-func-empty.mk,v 1.15 2021/12/11 09:53:53 rillig Exp $ +# $NetBSD: cond-func-empty.mk,v 1.16 2021/12/11 10:41:31 rillig Exp $ # # Tests for the empty() function in .if conditions, which tests a variable # expression for emptiness. @@ -89,9 +89,9 @@ WORD= word # Now the variable named " " gets a non-empty value, which demonstrates that # neither leading nor trailing spaces are trimmed in the argument of the # function. If the spaces were trimmed, the variable name would be "" and -# that variable is indeed undefined. Since ParseEmptyArg calls Var_Parse -# without VARE_UNDEFERR, the value of the undefined variable is returned as an -# empty string. +# that variable is indeed undefined. Since CondParser_FuncCallEmpty calls +# Var_Parse without VARE_UNDEFERR, the value of the undefined variable is +# returned as an empty string. ${:U }= space .if empty( ) . error @@ -126,8 +126,8 @@ ${:U }= space # # If everything goes well, the argument expands to "WORD", and that variable # is defined at the beginning of this file. The surrounding 'W' and 'D' -# ensure that ParseEmptyArg keeps track of the parsing position, both before -# and after the call to Var_Parse. +# ensure that CondParser_FuncCallEmpty keeps track of the parsing position, +# both before and after the call to Var_Parse. .if empty(W${:UOR}D) . error .endif