Module Name: src Committed By: rillig Date: Mon Jan 25 19:05:39 UTC 2021
Modified Files: src/usr.bin/make: for.c src/usr.bin/make/unit-tests: directive-for-escape.exp directive-for-escape.mk varmod-ifelse.mk Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.135 -r1.136 src/usr.bin/make/for.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-for-escape.exp \ src/usr.bin/make/unit-tests/directive-for-escape.mk cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/varmod-ifelse.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/for.c diff -u src/usr.bin/make/for.c:1.135 src/usr.bin/make/for.c:1.136 --- src/usr.bin/make/for.c:1.135 Tue Jan 19 20:51:46 2021 +++ src/usr.bin/make/for.c Mon Jan 25 19:05:39 2021 @@ -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 @@ typedef struct ForVar { 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 @@ typedef struct For { * 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 @@ ForAddVar(For *f, const char *name, size } static void -For_Free(For *f) +ForLoop_Free(ForLoop *f) { Buf_Destroy(&f->body, TRUE); @@ -138,7 +135,7 @@ IsEndfor(const char *p) int For_Eval(const char *line) { - For *f; + ForLoop *f; const char *p; p = line + 1; /* skip the '.' */ @@ -173,7 +170,7 @@ For_Eval(const char *line) 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 @@ For_Eval(const char *line) 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 @@ done: } /* - * 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 @@ Buf_AddEscaped(Buffer *cmds, const char * 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 @@ SubstVarLong(For *f, const char **pp, co * 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 @@ found: * 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 @@ ForSubstBody(For *f) 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 @@ ForSubstBody(For *f) 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 @@ ForReadMore(void *v_arg, size_t *out_len void For_Run(int lineno) { - For *f = accumFor; + ForLoop *f = accumFor; accumFor = NULL; if (f->items.len == 0) { @@ -496,7 +493,7 @@ For_Run(int lineno) * Nothing to expand - possibly due to an earlier syntax * error. */ - For_Free(f); + ForLoop_Free(f); return; } Index: src/usr.bin/make/unit-tests/directive-for-escape.exp diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.5 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.6 --- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.5 Sun Jan 24 19:48:11 2021 +++ src/usr.bin/make/unit-tests/directive-for-escape.exp Mon Jan 25 19:05:39 2021 @@ -58,7 +58,7 @@ For: loop body: . 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} Index: src/usr.bin/make/unit-tests/directive-for-escape.mk diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.5 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.6 --- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.5 Sun Jan 24 19:48:11 2021 +++ src/usr.bin/make/unit-tests/directive-for-escape.mk Mon Jan 25 19:05:39 2021 @@ -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 @@ i,= comma . 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 Index: src/usr.bin/make/unit-tests/varmod-ifelse.mk diff -u src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.8 src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.9 --- src/usr.bin/make/unit-tests/varmod-ifelse.mk:1.8 Thu Dec 10 16:47:42 2020 +++ src/usr.bin/make/unit-tests/varmod-ifelse.mk Mon Jan 25 19:05:39 2021 @@ -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 @@ COND:= ${${UNDEF} == "":?bad-assign:bad- # 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"