Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make: shorten function names, clean up comments



details:   https://anonhg.NetBSD.org/src/rev/0484f1d8c543
branches:  trunk
changeset: 376105:0484f1d8c543
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 01 07:44:10 2023 +0000

description:
make: shorten function names, clean up comments

No functional change.

diffstat:

 usr.bin/make/buf.c                         |   6 ++--
 usr.bin/make/buf.h                         |   4 +-
 usr.bin/make/cond.c                        |  18 ++++++++--------
 usr.bin/make/for.c                         |  33 +++++++++++++++--------------
 usr.bin/make/make.h                        |   4 +-
 usr.bin/make/unit-tests/cond-cmp-unary.exp |   2 +-
 usr.bin/make/unit-tests/cond-cmp-unary.mk  |  10 ++++----
 usr.bin/make/var.c                         |  33 ++++++++++++++---------------
 8 files changed, 55 insertions(+), 55 deletions(-)

diffs (truncated from 436 to 300 lines):

diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/buf.c
--- a/usr.bin/make/buf.c        Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/buf.c        Thu Jun 01 07:44:10 2023 +0000
@@ -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));
 }
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/buf.h
--- a/usr.bin/make/buf.h        Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/buf.h        Thu Jun 01 07:44:10 2023 +0000
@@ -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 *);
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/cond.c       Thu Jun 01 07:44:10 2023 +0000
@@ -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;
        }
 
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/for.c
--- a/usr.bin/make/for.c        Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/for.c        Thu Jun 01 07:44:10 2023 +0000
@@ -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);
 }
 
 /*
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/make.h       Thu Jun 01 07:44:10 2023 +0000
@@ -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 *);
 
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/unit-tests/cond-cmp-unary.exp
--- a/usr.bin/make/unit-tests/cond-cmp-unary.exp        Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-unary.exp        Thu Jun 01 07:44:10 2023 +0000
@@ -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
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/unit-tests/cond-cmp-unary.mk
--- a/usr.bin/make/unit-tests/cond-cmp-unary.mk Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/unit-tests/cond-cmp-unary.mk Thu Jun 01 07:44:10 2023 +0000
@@ -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
diff -r dfa3472467a3 -r 0484f1d8c543 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Thu Jun 01 07:27:30 2023 +0000
+++ b/usr.bin/make/var.c        Thu Jun 01 07:44:10 2023 +0000



Home | Main Index | Thread Index | Old Index