awk: rename temp variables, no code changes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-07-01 16:02:16 +02:00
parent d7354df169
commit 1573487e21

@ -1775,14 +1775,14 @@ static node *mk_splitter(const char *s, tsplitter *spl)
static regex_t *as_regex(node *op, regex_t *preg) static regex_t *as_regex(node *op, regex_t *preg)
{ {
int cflags; int cflags;
var *v; var *tmpvar;
const char *s; const char *s;
if ((op->info & OPCLSMASK) == OC_REGEXP) { if ((op->info & OPCLSMASK) == OC_REGEXP) {
return icase ? op->r.ire : op->l.re; return icase ? op->r.ire : op->l.re;
} }
v = nvalloc(1); tmpvar = nvalloc(1);
s = getvar_s(evaluate(op, v)); s = getvar_s(evaluate(op, tmpvar));
cflags = icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED; cflags = icase ? REG_EXTENDED | REG_ICASE : REG_EXTENDED;
/* Testcase where REG_EXTENDED fails (unpaired '{'): /* Testcase where REG_EXTENDED fails (unpaired '{'):
@ -1794,7 +1794,7 @@ static regex_t *as_regex(node *op, regex_t *preg)
cflags &= ~REG_EXTENDED; cflags &= ~REG_EXTENDED;
xregcomp(preg, s, cflags); xregcomp(preg, s, cflags);
} }
nvfree(v, 1); nvfree(tmpvar, 1);
return preg; return preg;
} }
@ -2243,12 +2243,12 @@ static char *awk_printf(node *n, int *len)
const char *s1; const char *s1;
int i, j, incr, bsize; int i, j, incr, bsize;
char c, c1; char c, c1;
var *v, *arg; var *tmpvar, *arg;
v = nvalloc(1); tmpvar = nvalloc(1);
//TODO: above, to avoid allocating a single temporary var, take a pointer //TODO: above, to avoid allocating a single temporary var, take a pointer
//to a temporary that our caller (evaluate()) already has? //to a temporary that our caller (evaluate()) already has?
fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v))); fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), tmpvar)));
i = 0; i = 0;
while (*f) { while (*f) {
@ -2268,7 +2268,7 @@ static char *awk_printf(node *n, int *len)
f++; f++;
c1 = *f; c1 = *f;
*f = '\0'; *f = '\0';
arg = evaluate(nextarg(&n), v); arg = evaluate(nextarg(&n), tmpvar);
j = i; j = i;
if (c == 'c' || !c) { if (c == 'c' || !c) {
@ -2289,7 +2289,7 @@ static char *awk_printf(node *n, int *len)
} }
free(fmt); free(fmt);
nvfree(v, 1); nvfree(tmpvar, 1);
b = xrealloc(b, i + 1); b = xrealloc(b, i + 1);
b[i] = '\0'; b[i] = '\0';
#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS #if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
@ -2429,7 +2429,7 @@ static NOINLINE var *exec_builtin(node *op, var *res)
{ {
#define tspl (G.exec_builtin__tspl) #define tspl (G.exec_builtin__tspl)
var *tv; var *tmpvars;
node *an[4]; node *an[4];
var *av[4]; var *av[4];
const char *as[4]; const char *as[4];
@ -2441,7 +2441,12 @@ static NOINLINE var *exec_builtin(node *op, var *res)
time_t tt; time_t tt;
int i, l, ll, n; int i, l, ll, n;
tv = nvalloc(4); tmpvars = nvalloc(4);
#define TMPVAR0 (tmpvars)
#define TMPVAR1 (tmpvars + 1)
#define TMPVAR2 (tmpvars + 2)
#define TMPVAR3 (tmpvars + 3)
#define TMPVAR(i) (tmpvars + (i))
isr = info = op->info; isr = info = op->info;
op = op->l.n; op = op->l.n;
@ -2449,7 +2454,7 @@ static NOINLINE var *exec_builtin(node *op, var *res)
for (i = 0; i < 4 && op; i++) { for (i = 0; i < 4 && op; i++) {
an[i] = nextarg(&op); an[i] = nextarg(&op);
if (isr & 0x09000000) if (isr & 0x09000000)
av[i] = evaluate(an[i], &tv[i]); av[i] = evaluate(an[i], TMPVAR(i));
if (isr & 0x08000000) if (isr & 0x08000000)
as[i] = getvar_s(av[i]); as[i] = getvar_s(av[i]);
isr >>= 1; isr >>= 1;
@ -2474,7 +2479,7 @@ static NOINLINE var *exec_builtin(node *op, var *res)
if (nargs > 2) { if (nargs > 2) {
spl = (an[2]->info & OPCLSMASK) == OC_REGEXP ? spl = (an[2]->info & OPCLSMASK) == OC_REGEXP ?
an[2] : mk_splitter(getvar_s(evaluate(an[2], &tv[2])), &tspl); an[2] : mk_splitter(getvar_s(evaluate(an[2], TMPVAR2)), &tspl);
} else { } else {
spl = &fsplitter.n; spl = &fsplitter.n;
} }
@ -2617,7 +2622,13 @@ static NOINLINE var *exec_builtin(node *op, var *res)
break; break;
} }
nvfree(tv, 4); nvfree(tmpvars, 4);
#undef TMPVAR0
#undef TMPVAR1
#undef TMPVAR2
#undef TMPVAR3
#undef TMPVAR
return res; return res;
#undef tspl #undef tspl
} }
@ -2636,14 +2647,16 @@ static var *evaluate(node *op, var *res)
#define seed (G.evaluate__seed) #define seed (G.evaluate__seed)
#define sreg (G.evaluate__sreg) #define sreg (G.evaluate__sreg)
var *v1; var *tmpvars;
#define TMPVAR0 (tmpvars)
#define TMPVAR1 (tmpvars + 1)
if (!op) if (!op)
return setvar_s(res, NULL); return setvar_s(res, NULL);
debug_printf_eval("entered %s()\n", __func__); debug_printf_eval("entered %s()\n", __func__);
v1 = nvalloc(2); tmpvars = nvalloc(2);
while (op) { while (op) {
struct { struct {
@ -2683,7 +2696,7 @@ static var *evaluate(node *op, var *res)
} }
if (op1->r.n) { /* array ref? */ if (op1->r.n) { /* array ref? */
const char *s; const char *s;
s = getvar_s(evaluate(op1->r.n, v1)); s = getvar_s(evaluate(op1->r.n, TMPVAR0));
hash_remove(iamarray(v), s); hash_remove(iamarray(v), s);
} else { } else {
clear_array(iamarray(v)); clear_array(iamarray(v));
@ -2693,7 +2706,7 @@ static var *evaluate(node *op, var *res)
/* execute inevitable things */ /* execute inevitable things */
if (opinfo & OF_RES1) if (opinfo & OF_RES1)
L.v = evaluate(op1, v1); L.v = evaluate(op1, TMPVAR0);
if (opinfo & OF_STR1) { if (opinfo & OF_STR1) {
L.s = getvar_s(L.v); L.s = getvar_s(L.v);
debug_printf_eval("L.s:'%s'\n", L.s); debug_printf_eval("L.s:'%s'\n", L.s);
@ -2710,7 +2723,7 @@ static var *evaluate(node *op, var *res)
* (Seen trying to evaluate "$444 $44444") * (Seen trying to evaluate "$444 $44444")
*/ */
if (opinfo & OF_RES2) { if (opinfo & OF_RES2) {
R.v = evaluate(op->r.n, v1+1); R.v = evaluate(op->r.n, TMPVAR1);
//TODO: L.v may be invalid now, set L.v to NULL to catch bugs? //TODO: L.v may be invalid now, set L.v to NULL to catch bugs?
//L.v = NULL; //L.v = NULL;
} }
@ -2793,7 +2806,7 @@ static var *evaluate(node *op, var *res)
fputs(getvar_s(intvar[F0]), F); fputs(getvar_s(intvar[F0]), F);
} else { } else {
for (;;) { for (;;) {
var *v = evaluate(nextarg(&op1), v1); var *v = evaluate(nextarg(&op1), TMPVAR0);
if (v->type & VF_NUMBER) { if (v->type & VF_NUMBER) {
fmt_num(g_buf, MAXVARFMT, getvar_s(intvar[OFMT]), fmt_num(g_buf, MAXVARFMT, getvar_s(intvar[OFMT]),
getvar_i(v), TRUE); getvar_i(v), TRUE);
@ -2892,7 +2905,7 @@ static var *evaluate(node *op, var *res)
/* if source is a temporary string, jusk relink it to dest */ /* if source is a temporary string, jusk relink it to dest */
//Disabled: if R.v is numeric but happens to have cached R.v->string, //Disabled: if R.v is numeric but happens to have cached R.v->string,
//then L.v ends up being a string, which is wrong //then L.v ends up being a string, which is wrong
// if (R.v == v1+1 && R.v->string) { // if (R.v == TMPVAR1 && R.v->string) {
// res = setvar_p(L.v, R.v->string); // res = setvar_p(L.v, R.v->string);
// R.v->string = NULL; // R.v->string = NULL;
// } else { // } else {
@ -2908,7 +2921,7 @@ static var *evaluate(node *op, var *res)
break; break;
case XC( OC_FUNC ): { case XC( OC_FUNC ): {
var *tv, *sv_fnargs; var *argvars, *sv_fnargs;
const char *sv_progname; const char *sv_progname;
int nargs, i; int nargs, i;
@ -2919,10 +2932,10 @@ static var *evaluate(node *op, var *res)
/* The body might be empty, still has to eval the args */ /* The body might be empty, still has to eval the args */
nargs = op->r.f->nargs; nargs = op->r.f->nargs;
tv = nvalloc(nargs); argvars = nvalloc(nargs);
i = 0; i = 0;
while (op1) { while (op1) {
var *arg = evaluate(nextarg(&op1), v1); var *arg = evaluate(nextarg(&op1), TMPVAR0);
if (i == nargs) { if (i == nargs) {
/* call with more arguments than function takes. /* call with more arguments than function takes.
* (gawk warns: "warning: function 'f' called with more arguments than declared"). * (gawk warns: "warning: function 'f' called with more arguments than declared").
@ -2930,18 +2943,18 @@ static var *evaluate(node *op, var *res)
clrvar(arg); clrvar(arg);
continue; continue;
} }
copyvar(&tv[i], arg); copyvar(&argvars[i], arg);
tv[i].type |= VF_CHILD; argvars[i].type |= VF_CHILD;
tv[i].x.parent = arg; argvars[i].x.parent = arg;
i++; i++;
} }
sv_fnargs = fnargs; sv_fnargs = fnargs;
sv_progname = g_progname; sv_progname = g_progname;
fnargs = tv; fnargs = argvars;
res = evaluate(op->r.f->body.first, res); res = evaluate(op->r.f->body.first, res);
nvfree(fnargs, nargs); nvfree(argvars, nargs);
g_progname = sv_progname; g_progname = sv_progname;
fnargs = sv_fnargs; fnargs = sv_fnargs;
@ -3266,7 +3279,10 @@ static var *evaluate(node *op, var *res)
break; break;
} /* while (op) */ } /* while (op) */
nvfree(v1, 2); nvfree(tmpvars, 2);
#undef TMPVAR0
#undef TMPVAR1
debug_printf_eval("returning from %s(): %p\n", __func__, res); debug_printf_eval("returning from %s(): %p\n", __func__, res);
return res; return res;
#undef fnargs #undef fnargs