Module Name: src Committed By: rillig Date: Thu Jun 1 07:44:11 UTC 2023
Modified Files: src/usr.bin/make: buf.c buf.h cond.c for.c make.h var.c src/usr.bin/make/unit-tests: cond-cmp-unary.exp cond-cmp-unary.mk Log Message: make: shorten function names, clean up comments No functional change. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/usr.bin/make/buf.c cvs rdiff -u -r1.47 -r1.48 src/usr.bin/make/buf.h cvs rdiff -u -r1.344 -r1.345 src/usr.bin/make/cond.c cvs rdiff -u -r1.174 -r1.175 src/usr.bin/make/for.c cvs rdiff -u -r1.319 -r1.320 src/usr.bin/make/make.h cvs rdiff -u -r1.1054 -r1.1055 src/usr.bin/make/var.c cvs rdiff -u -r1.2 -r1.3 src/usr.bin/make/unit-tests/cond-cmp-unary.exp cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/cond-cmp-unary.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/buf.c diff -u src/usr.bin/make/buf.c:1.55 src/usr.bin/make/buf.c:1.56 --- src/usr.bin/make/buf.c:1.55 Sat Jan 8 17:25:19 2022 +++ src/usr.bin/make/buf.c Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.55 2022/01/08 17:25:19 rillig Exp $ */ +/* $NetBSD: buf.c,v 1.56 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -75,7 +75,7 @@ #include "make.h" /* "@(#)buf.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: buf.c,v 1.55 2022/01/08 17:25:19 rillig Exp $"); +MAKE_RCSID("$NetBSD: buf.c,v 1.56 2023/06/01 07:44:10 rillig Exp $"); /* Make space in the buffer for adding at least 16 more bytes. */ void @@ -106,7 +106,7 @@ Buf_AddBytes(Buffer *buf, const char *by /* Add the bytes between start and end to the buffer. */ void -Buf_AddBytesBetween(Buffer *buf, const char *start, const char *end) +Buf_AddRange(Buffer *buf, const char *start, const char *end) { Buf_AddBytes(buf, start, (size_t)(end - start)); } Index: src/usr.bin/make/buf.h diff -u src/usr.bin/make/buf.h:1.47 src/usr.bin/make/buf.h:1.48 --- src/usr.bin/make/buf.h:1.47 Sat Jan 8 17:25:19 2022 +++ src/usr.bin/make/buf.h Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.h,v 1.47 2022/01/08 17:25:19 rillig Exp $ */ +/* $NetBSD: buf.h,v 1.48 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -116,7 +116,7 @@ Buf_EndsWith(const Buffer *buf, char ch) } void Buf_AddBytes(Buffer *, const char *, size_t); -void Buf_AddBytesBetween(Buffer *, const char *, const char *); +void Buf_AddRange(Buffer *, const char *, const char *); void Buf_AddStr(Buffer *, const char *); void Buf_AddInt(Buffer *, int); void Buf_AddFlag(Buffer *, bool, const char *); Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.344 src/usr.bin/make/cond.c:1.345 --- src/usr.bin/make/cond.c:1.344 Tue Feb 14 21:08:00 2023 +++ src/usr.bin/make/cond.c Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.345 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -92,7 +92,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.344 2023/02/14 21:08:00 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.345 2023/06/01 07:44:10 rillig Exp $"); /* * Conditional expressions conform to this grammar: @@ -136,10 +136,10 @@ typedef struct CondParser { /* * The plain '.if ${VAR}' evaluates to true if the value of the - * expression has length > 0. The other '.if' variants delegate - * to evalBare instead, for example '.ifdef ${VAR}' is equivalent to - * '.if defined(${VAR})', checking whether the variable named by the - * expression '${VAR}' is defined. + * expression has length > 0 and is not numerically zero. The other + * '.if' variants delegate to evalBare instead, for example '.ifdef + * ${VAR}' is equivalent to '.if defined(${VAR})', checking whether + * the variable named by the expression '${VAR}' is defined. */ bool plain; @@ -338,7 +338,7 @@ FuncCommands(const char *node) } /* - * Convert the string into a floating-point number. Accepted formats are + * Convert the string to a floating point number. Accepted formats are * base-10 integer, base-16 integer and finite floating point numbers. */ static bool @@ -507,7 +507,7 @@ return_str: * ".if 0". */ static bool -EvalNotEmpty(CondParser *par, const char *value, bool quoted) +EvalTruthy(CondParser *par, const char *value, bool quoted) { double num; @@ -631,7 +631,7 @@ CondParser_Comparison(CondParser *par, b if (!CondParser_ComparisonOp(par, &op)) { /* Unknown operator, compare against an empty string or 0. */ - t = ToToken(doEval && EvalNotEmpty(par, lhs.str, lhsQuoted)); + t = ToToken(doEval && EvalTruthy(par, lhs.str, lhsQuoted)); goto done_lhs; } Index: src/usr.bin/make/for.c diff -u src/usr.bin/make/for.c:1.174 src/usr.bin/make/for.c:1.175 --- src/usr.bin/make/for.c:1.174 Tue May 9 19:43:12 2023 +++ src/usr.bin/make/for.c Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.174 2023/05/09 19:43:12 rillig Exp $ */ +/* $NetBSD: for.c,v 1.175 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -58,7 +58,7 @@ #include "make.h" /* "@(#)for.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: for.c,v 1.174 2023/05/09 19:43:12 rillig Exp $"); +MAKE_RCSID("$NetBSD: for.c,v 1.175 2023/06/01 07:44:10 rillig Exp $"); typedef struct ForLoop { @@ -115,7 +115,7 @@ ForLoop_Free(ForLoop *f) } char * -ForLoop_Details(ForLoop *f) +ForLoop_Details(const ForLoop *f) { size_t i, n; const char **vars; @@ -133,7 +133,7 @@ ForLoop_Details(ForLoop *f) Buf_AddStr(&buf, ", "); Buf_AddStr(&buf, vars[i]); Buf_AddStr(&buf, " = "); - Buf_AddBytesBetween(&buf, items[i].start, items[i].end); + Buf_AddRange(&buf, items[i].start, items[i].end); } return Buf_DoneData(&buf); } @@ -351,7 +351,7 @@ NeedsEscapes(Substring value, char endc) } /* - * While expanding the body of a .for loop, write the item in the ${:U...} + * While expanding the body of a .for loop, write the item as a ${:U...} * expression, escaping characters as needed. The result is later unescaped * by ApplyModifier_Defined. */ @@ -362,7 +362,7 @@ AddEscaped(Buffer *cmds, Substring item, char ch; if (!NeedsEscapes(item, endc)) { - Buf_AddBytesBetween(cmds, item.start, item.end); + Buf_AddRange(cmds, item.start, item.end); return; } @@ -392,7 +392,7 @@ AddEscaped(Buffer *cmds, Substring item, } /* - * When expanding the body of a .for loop, replace the variable name of an + * While expanding the body of a .for loop, replace the variable name of an * expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue". */ static void @@ -401,12 +401,12 @@ ForLoop_SubstVarLong(ForLoop *f, unsigne { size_t i; const char *start = *pp; - const char **vars = Vector_Get(&f->vars, 0); + const char **varnames = Vector_Get(&f->vars, 0); for (i = 0; i < f->vars.len; i++) { const char *p = start; - if (!cpp_skip_string(&p, vars[i])) + if (!cpp_skip_string(&p, varnames[i])) continue; /* XXX: why test for backslash here? */ if (*p != ':' && *p != endc && *p != '\\') @@ -416,7 +416,7 @@ ForLoop_SubstVarLong(ForLoop *f, unsigne * Found a variable match. Skip over the variable name and * instead add ':U<value>' to the current body. */ - Buf_AddBytesBetween(body, *inout_mark, start); + Buf_AddRange(body, *inout_mark, start); Buf_AddStr(body, ":U"); AddEscaped(body, f->items.words[firstItem + i], endc); @@ -427,7 +427,7 @@ ForLoop_SubstVarLong(ForLoop *f, unsigne } /* - * When expanding the body of a .for loop, replace single-character + * While expanding the body of a .for loop, replace single-character * variable expressions like $i with their ${:U...} expansion. */ static void @@ -451,7 +451,7 @@ ForLoop_SubstVarShort(ForLoop *f, unsign return; found: - Buf_AddBytesBetween(body, *inout_mark, p); + Buf_AddRange(body, *inout_mark, p); *inout_mark = p + 1; /* Replace $<ch> with ${:U<value>} */ @@ -465,13 +465,14 @@ found: * replacing the expressions for the iteration variables on the way. * * Using variable expressions ensures that the .for loop can't generate - * syntax, and that the later parsing will still see a variable. - * This code assumes that the variable with the empty name will never be - * defined, see unit-tests/varname-empty.mk for more details. + * syntax, and that the later parsing will still see an expression. + * This code assumes that the variable with the empty name is never defined, + * see unit-tests/varname-empty.mk. * * The detection of substitutions of the loop control variables is naive. * Many of the modifiers use '\$' instead of '$$' to escape '$', so it is * possible to contrive a makefile where an unwanted substitution happens. + * See unit-tests/directive-for-escape.mk. */ static void ForLoop_SubstBody(ForLoop *f, unsigned int firstItem, Buffer *body) @@ -497,7 +498,7 @@ ForLoop_SubstBody(ForLoop *f, unsigned i break; } - Buf_AddBytesBetween(body, mark, end); + Buf_AddRange(body, mark, end); } /* Index: src/usr.bin/make/make.h diff -u src/usr.bin/make/make.h:1.319 src/usr.bin/make/make.h:1.320 --- src/usr.bin/make/make.h:1.319 Tue Mar 28 14:39:31 2023 +++ src/usr.bin/make/make.h Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.319 2023/03/28 14:39:31 rillig Exp $ */ +/* $NetBSD: make.h,v 1.320 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -820,7 +820,7 @@ int For_Eval(const char *) MAKE_ATTR_USE bool For_Accum(const char *, int *) MAKE_ATTR_USE; void For_Run(unsigned, unsigned); bool For_NextIteration(struct ForLoop *, Buffer *); -char *ForLoop_Details(struct ForLoop *); +char *ForLoop_Details(const struct ForLoop *); void ForLoop_Free(struct ForLoop *); void For_Break(struct ForLoop *); Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1054 src/usr.bin/make/var.c:1.1055 --- src/usr.bin/make/var.c:1.1054 Wed May 10 18:22:33 2023 +++ src/usr.bin/make/var.c Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1054 2023/05/10 18:22:33 sjg Exp $ */ +/* $NetBSD: var.c,v 1.1055 2023/06/01 07:44:10 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -139,7 +139,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1054 2023/05/10 18:22:33 sjg Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1055 2023/06/01 07:44:10 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -1314,7 +1314,7 @@ SepBuf_AddBytes(SepBuf *buf, const char } static void -SepBuf_AddBytesBetween(SepBuf *buf, const char *start, const char *end) +SepBuf_AddRange(SepBuf *buf, const char *start, const char *end) { SepBuf_AddBytes(buf, start, (size_t)(end - start)); } @@ -1328,7 +1328,7 @@ SepBuf_AddStr(SepBuf *buf, const char *s static void SepBuf_AddSubstring(SepBuf *buf, Substring sub) { - SepBuf_AddBytesBetween(buf, sub.start, sub.end); + SepBuf_AddRange(buf, sub.start, sub.end); } static char * @@ -1385,7 +1385,7 @@ ModifyWord_Suffix(Substring word, SepBuf { const char *lastDot = Substring_LastIndex(word, '.'); if (lastDot != NULL) - SepBuf_AddBytesBetween(buf, lastDot + 1, word.end); + SepBuf_AddRange(buf, lastDot + 1, word.end); } /* @@ -1400,7 +1400,7 @@ ModifyWord_Root(Substring word, SepBuf * lastDot = Substring_LastIndex(word, '.'); end = lastDot != NULL ? lastDot : word.end; - SepBuf_AddBytesBetween(buf, word.start, end); + SepBuf_AddRange(buf, word.start, end); } /* @@ -1463,9 +1463,9 @@ ModifyWord_SysVSubst(Substring word, Sep percent = args->lhsPercent ? strchr(rhs.str, '%') : NULL; if (percent != NULL) - SepBuf_AddBytesBetween(buf, rhs.str, percent); + SepBuf_AddRange(buf, rhs.str, percent); if (percent != NULL || !args->lhsPercent) - SepBuf_AddBytesBetween(buf, + SepBuf_AddRange(buf, word.start + Substring_Length(args->lhsPrefix), word.end - Substring_Length(args->lhsSuffix)); SepBuf_AddStr(buf, percent != NULL ? percent + 1 : rhs.str); @@ -1522,7 +1522,7 @@ ModifyWord_Subst(Substring word, SepBuf /* :S,^prefix,replacement, or :S,^whole$,replacement, */ SepBuf_AddSubstring(buf, args->rhs); - SepBuf_AddBytesBetween(buf, word.start + lhsLen, wordEnd); + SepBuf_AddRange(buf, word.start + lhsLen, wordEnd); args->matched = true; return; } @@ -1534,7 +1534,7 @@ ModifyWord_Subst(Substring word, SepBuf goto nosub; /* :S,suffix$,replacement, */ - SepBuf_AddBytesBetween(buf, word.start, wordEnd - lhsLen); + SepBuf_AddRange(buf, word.start, wordEnd - lhsLen); SepBuf_AddSubstring(buf, args->rhs); args->matched = true; return; @@ -1545,7 +1545,7 @@ ModifyWord_Subst(Substring word, SepBuf /* unanchored case, may match more than once */ while ((match = Substring_Find(word, args->lhs)) != NULL) { - SepBuf_AddBytesBetween(buf, word.start, match); + SepBuf_AddRange(buf, word.start, match); SepBuf_AddSubstring(buf, args->rhs); args->matched = true; word.start = match + lhsLen; @@ -1581,7 +1581,7 @@ RegexReplaceBackref(char ref, SepBuf *bu if (opts.strict) Error("No match for subexpression \\%u", n); } else { - SepBuf_AddBytesBetween(buf, + SepBuf_AddRange(buf, wp + (size_t)m[n].rm_so, wp + (size_t)m[n].rm_eo); } @@ -1605,7 +1605,7 @@ RegexReplace(Substring replace, SepBuf * ch_isdigit(rp[1])) RegexReplaceBackref(*++rp, buf, wp, m, nsub); else if (*rp == '&') { - SepBuf_AddBytesBetween(buf, + SepBuf_AddRange(buf, wp + (size_t)m[0].rm_so, wp + (size_t)m[0].rm_eo); } else @@ -1646,7 +1646,7 @@ again: if (xrv != REG_NOMATCH) VarREError(xrv, &args->re, "Unexpected regex error"); no_match: - SepBuf_AddBytesBetween(buf, wp, word.end); + SepBuf_AddRange(buf, wp, word.end); return; ok: @@ -1801,8 +1801,7 @@ SubstringWords_JoinFree(SubstringWords w */ Buf_AddByte(&buf, ' '); } - Buf_AddBytesBetween(&buf, - words.words[i].start, words.words[i].end); + Buf_AddRange(&buf, words.words[i].start, words.words[i].end); } SubstringWords_Free(words); @@ -4735,7 +4734,7 @@ VarSubstPlain(const char **pp, Buffer *r for (p++; *p != '$' && *p != '\0'; p++) continue; - Buf_AddBytesBetween(res, start, p); + Buf_AddRange(res, start, p); *pp = p; } Index: src/usr.bin/make/unit-tests/cond-cmp-unary.exp diff -u src/usr.bin/make/unit-tests/cond-cmp-unary.exp:1.2 src/usr.bin/make/unit-tests/cond-cmp-unary.exp:1.3 --- src/usr.bin/make/unit-tests/cond-cmp-unary.exp:1.2 Wed Nov 11 07:30:11 2020 +++ src/usr.bin/make/unit-tests/cond-cmp-unary.exp Thu Jun 1 07:44:10 2023 @@ -1,2 +1,2 @@ -make: "cond-cmp-unary.mk" line 53: This is only reached because of a bug in EvalNotEmpty. +make: "cond-cmp-unary.mk" line 53: This is only reached because of a bug in EvalTruthy. exit status 0 Index: src/usr.bin/make/unit-tests/cond-cmp-unary.mk diff -u src/usr.bin/make/unit-tests/cond-cmp-unary.mk:1.3 src/usr.bin/make/unit-tests/cond-cmp-unary.mk:1.4 --- src/usr.bin/make/unit-tests/cond-cmp-unary.mk:1.3 Thu Sep 8 05:43:20 2022 +++ src/usr.bin/make/unit-tests/cond-cmp-unary.mk Thu Jun 1 07:44:10 2023 @@ -1,4 +1,4 @@ -# $NetBSD: cond-cmp-unary.mk,v 1.3 2022/09/08 05:43:20 rillig Exp $ +# $NetBSD: cond-cmp-unary.mk,v 1.4 2023/06/01 07:44:10 rillig Exp $ # # Tests for unary comparisons in .if conditions, that is, comparisons with # a single operand. If the operand is a number, it is compared to zero, @@ -26,8 +26,8 @@ # The empty string may come from a variable expression. # -# XXX: As of 2020-11-11, this empty string is interpreted "as a number" in -# EvalNotEmpty, which is plain wrong. The bug is in TryParseNumber. +# XXX: As of 2023-06-01, this empty string is interpreted "as a number" in +# EvalTruthy, which is plain wrong. The bug is in TryParseNumber. .if ${:U} . error .endif @@ -45,12 +45,12 @@ # A string of whitespace should evaluate to false. # -# XXX: As of 2020-11-11, the implementation in EvalNotEmpty does not skip +# XXX: As of 2023-06-01, the implementation in EvalTruthy does not skip # whitespace before testing for the end. This was probably an oversight in # a commit from 1992-04-15 saying "A variable is empty when it just contains # spaces". .if ${:U } -. info This is only reached because of a bug in EvalNotEmpty. +. info This is only reached because of a bug in EvalTruthy. .else . error .endif