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(1): rename struct For to struct ForLoop
details: https://anonhg.NetBSD.org/src/rev/8948c450ef02
branches: trunk
changeset: 958943:8948c450ef02
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jan 25 19:05:39 2021 +0000
description:
make(1): rename struct For to struct ForLoop
This removes the ambiguity whether For_Free is meant to be a
module-exported function or a local function associate with that struct.
Rename the affected functions as well.
diffstat:
usr.bin/make/for.c | 51 +++++++++++------------
usr.bin/make/unit-tests/directive-for-escape.exp | 2 +-
usr.bin/make/unit-tests/directive-for-escape.mk | 4 +-
usr.bin/make/unit-tests/varmod-ifelse.mk | 4 +-
4 files changed, 29 insertions(+), 32 deletions(-)
diffs (226 lines):
diff -r 5a560f5b19fa -r 8948c450ef02 usr.bin/make/for.c
--- a/usr.bin/make/for.c Mon Jan 25 17:18:55 2021 +0000
+++ b/usr.bin/make/for.c Mon Jan 25 19:05:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.135 2021/01/19 20:51:46 rillig Exp $ */
+/* $NetBSD: for.c,v 1.136 2021/01/25 19:05:39 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.135 2021/01/19 20:51:46 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.136 2021/01/25 19:05:39 rillig Exp $");
static int forLevel = 0; /* Nesting level */
@@ -68,10 +68,7 @@
size_t nameLen;
} ForVar;
-/*
- * State of a for loop.
- */
-typedef struct For {
+typedef struct ForLoop {
Buffer body; /* Unexpanded body of the loop */
Vector /* of ForVar */ vars; /* Iteration variables */
Words items; /* Substitution items */
@@ -81,12 +78,12 @@
* only ${V} and $(V). */
Boolean short_var;
unsigned int sub_next; /* Where to continue iterating */
-} For;
+} ForLoop;
-static For *accumFor; /* Loop being accumulated */
+static ForLoop *accumFor; /* Loop being accumulated */
static void
-ForAddVar(For *f, const char *name, size_t len)
+ForLoop_AddVar(ForLoop *f, const char *name, size_t len)
{
ForVar *var = Vector_Push(&f->vars);
var->name = bmake_strldup(name, len);
@@ -94,7 +91,7 @@
}
static void
-For_Free(For *f)
+ForLoop_Free(ForLoop *f)
{
Buf_Destroy(&f->body, TRUE);
@@ -138,7 +135,7 @@
int
For_Eval(const char *line)
{
- For *f;
+ ForLoop *f;
const char *p;
p = line + 1; /* skip the '.' */
@@ -173,7 +170,7 @@
cpp_skip_whitespace(&p);
if (*p == '\0') {
Parse_Error(PARSE_FATAL, "missing `in' in for");
- For_Free(f);
+ ForLoop_Free(f);
return -1;
}
@@ -191,13 +188,13 @@
if (len == 1)
f->short_var = TRUE;
- ForAddVar(f, p, len);
+ ForLoop_AddVar(f, p, len);
p += len;
}
if (f->vars.len == 0) {
Parse_Error(PARSE_FATAL, "no iteration variables in for");
- For_Free(f);
+ ForLoop_Free(f);
return -1;
}
@@ -243,7 +240,7 @@
}
/*
- * Add another line to a .for loop.
+ * Add another line to the .for loop that is being built up.
* Returns FALSE when the matching .endfor is reached.
*/
Boolean
@@ -356,8 +353,8 @@
* expression like ${i} or ${i:...} or $(i) or $(i:...) with ":Uvalue".
*/
static void
-SubstVarLong(For *f, const char **pp, const char *bodyEnd, char endc,
- const char **inout_mark)
+ForLoop_SubstVarLong(ForLoop *f, const char **pp, const char *bodyEnd,
+ char endc, const char **inout_mark)
{
size_t i;
const char *p = *pp;
@@ -397,7 +394,7 @@
* variable expressions like $i with their ${:U...} expansion.
*/
static void
-SubstVarShort(For *f, const char *p, const char **inout_mark)
+ForLoop_SubstVarShort(ForLoop *f, const char *p, const char **inout_mark)
{
const char ch = *p;
ForVar *vars;
@@ -437,7 +434,7 @@
* to contrive a makefile where an unwanted substitution happens.
*/
static void
-ForSubstBody(For *f)
+ForLoop_SubstBody(ForLoop *f)
{
const char *p, *bodyEnd;
const char *mark; /* where the last replacement left off */
@@ -449,10 +446,10 @@
for (p = mark; (p = strchr(p, '$')) != NULL;) {
if (p[1] == '{' || p[1] == '(') {
p += 2;
- SubstVarLong(f, &p, bodyEnd, p[-1] == '{' ? '}' : ')',
- &mark);
+ ForLoop_SubstVarLong(f, &p, bodyEnd,
+ p[-1] == '{' ? '}' : ')', &mark);
} else if (p[1] != '\0') {
- SubstVarShort(f, p + 1, &mark);
+ ForLoop_SubstVarShort(f, p + 1, &mark);
p += 2;
} else
break;
@@ -468,15 +465,15 @@
static char *
ForReadMore(void *v_arg, size_t *out_len)
{
- For *f = v_arg;
+ ForLoop *f = v_arg;
if (f->sub_next == f->items.len) {
/* No more iterations */
- For_Free(f);
+ ForLoop_Free(f);
return NULL;
}
- ForSubstBody(f);
+ ForLoop_SubstBody(f);
DEBUG1(FOR, "For: loop body:\n%s", f->curBody.data);
f->sub_next += (unsigned int)f->vars.len;
@@ -488,7 +485,7 @@
void
For_Run(int lineno)
{
- For *f = accumFor;
+ ForLoop *f = accumFor;
accumFor = NULL;
if (f->items.len == 0) {
@@ -496,7 +493,7 @@
* Nothing to expand - possibly due to an earlier syntax
* error.
*/
- For_Free(f);
+ ForLoop_Free(f);
return;
}
diff -r 5a560f5b19fa -r 8948c450ef02 usr.bin/make/unit-tests/directive-for-escape.exp
--- a/usr.bin/make/unit-tests/directive-for-escape.exp Mon Jan 25 17:18:55 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.exp Mon Jan 25 19:05:39 2021 +0000
@@ -58,7 +58,7 @@
. info . $$(i): $(:Uinner)
. info . $$(i:M*): $(:Uinner:M*)
. info . $${i$${:U}}: ${i${:U}}
-. info . $${i\}}: ${:Uinner\}} # XXX: unclear why SubstVarLong needs this
+. info . $${i\}}: ${:Uinner\}} # XXX: unclear why ForLoop_SubstVarLong needs this
. info . $${i2}: ${i2}
. info . $${i,}: ${i,}
. info . adjacent: ${:Uinner}${:Uinner}${:Uinner:M*}${:Uinner}
diff -r 5a560f5b19fa -r 8948c450ef02 usr.bin/make/unit-tests/directive-for-escape.mk
--- a/usr.bin/make/unit-tests/directive-for-escape.mk Mon Jan 25 17:18:55 2021 +0000
+++ b/usr.bin/make/unit-tests/directive-for-escape.mk Mon Jan 25 19:05:39 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.5 2021/01/24 19:48:11 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.6 2021/01/25 19:05:39 rillig Exp $
#
# Test escaping of special characters in the iteration values of a .for loop.
# These values get expanded later using the :U variable modifier, and this
@@ -103,7 +103,7 @@
. info . $$(i): $(i)
. info . $$(i:M*): $(i:M*)
. info . $${i$${:U}}: ${i${:U}}
-. info . $${i\}}: ${i\}} # XXX: unclear why SubstVarLong needs this
+. info . $${i\}}: ${i\}} # XXX: unclear why ForLoop_SubstVarLong needs this
. info . $${i2}: ${i2}
. info . $${i,}: ${i,}
. info . adjacent: $i${i}${i:M*}$i
diff -r 5a560f5b19fa -r 8948c450ef02 usr.bin/make/unit-tests/varmod-ifelse.mk
--- a/usr.bin/make/unit-tests/varmod-ifelse.mk Mon Jan 25 17:18:55 2021 +0000
+++ b/usr.bin/make/unit-tests/varmod-ifelse.mk Mon Jan 25 19:05:39 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: varmod-ifelse.mk,v 1.8 2020/12/10 16:47:42 rillig Exp $
+# $NetBSD: varmod-ifelse.mk,v 1.9 2021/01/25 19:05:39 rillig Exp $
#
# Tests for the ${cond:?then:else} variable modifier, which evaluates either
# the then-expression or the else-expression, depending on the condition.
@@ -103,7 +103,7 @@
# This hack does not work for variables from .for loops since these are
# expanded at parse time to their corresponding ${:Uvalue} expressions.
# Making the '$' of the '${VAR}' expression indirect hides this expression
-# from the parser of the .for loop body. See SubstVarLong.
+# from the parser of the .for loop body. See ForLoop_SubstVarLong.
.MAKEFLAGS: -dc
VAR= value
.if ${ ${:U\$}{VAR} == value :?ok:bad} != "ok"
Home |
Main Index |
Thread Index |
Old Index