[7.6] abc04dea0 vcc: refactor passing the function's cname to argument expressions
Walid Boudebouda
walid.boudebouda at gmail.com
Mon May 12 15:29:05 UTC 2025
commit abc04dea042fe9cc65264f14357e02308342025d
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Dec 4 13:21:44 2024 +0100
vcc: refactor passing the function's cname to argument expressions
We had (ab)used the cname member of struct func_arg to pass the name of the
function to have it available for constructing the C name for enum arguments.
Make this explicit
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 7475053aa..15f03626f 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -453,20 +453,20 @@ struct func_arg {
VTAILQ_ENTRY(func_arg) list;
};
-static void
-vcc_do_enum(struct vcc *tl, struct func_arg *fa, int len, const char *ptr)
+static struct expr *
+vcc_do_enum(struct vcc *tl, const char *cfunc, int len, const char *ptr)
{
const char *r;
(void)tl;
- r = strchr(fa->cname, '.');
+ r = strchr(cfunc, '.');
AN(r);
- fa->result = vcc_mk_expr(VOID, "*%.*s.enum_%.*s",
- (int)(r - fa->cname), fa->cname, len, ptr);
+ return (vcc_mk_expr(VOID, "*%.*s.enum_%.*s",
+ (int)(r - cfunc), cfunc, len, ptr));
}
static void
-vcc_do_arg(struct vcc *tl, struct func_arg *fa)
+vcc_do_arg(struct vcc *tl, const char *cfunc, struct func_arg *fa)
{
struct expr *e2;
struct vjsn_val *vv;
@@ -485,7 +485,7 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa)
vcc_ErrWhere(tl, tl->t);
return;
}
- vcc_do_enum(tl, fa, PF(tl->t));
+ fa->result = vcc_do_enum(tl, cfunc, PF(tl->t));
SkipToken(tl, ID);
} else {
if (fa->type == SUB)
@@ -551,7 +551,6 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
assert(vjsn_is_array(vv));
fa = calloc(1, sizeof *fa);
AN(fa);
- fa->cname = cfunc;
VTAILQ_INSERT_TAIL(&head, fa, list);
vvp = VTAILQ_FIRST(&vv->children);
@@ -594,7 +593,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
if (t1->tok == '=')
break;
}
- vcc_do_arg(tl, fa);
+ vcc_do_arg(tl, cfunc, fa);
if (tl->err)
VSB_printf(tl->sb, "Expected argument: %s %s\n\n",
fa->type->name,
@@ -626,7 +625,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
}
vcc_NextToken(tl);
SkipToken(tl, '=');
- vcc_do_arg(tl, fa);
+ vcc_do_arg(tl, cfunc, fa);
ERRCHK(tl);
if (tl->t->tok == ')')
break;
@@ -649,7 +648,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
e1 = vcc_expr_edit(tl, e1->fmt, ssa, e1, NULL);
}
if (fa->result == NULL && fa->type == ENUM && fa->val != NULL)
- vcc_do_enum(tl, fa, strlen(fa->val), fa->val);
+ fa->result = vcc_do_enum(tl, cfunc, strlen(fa->val), fa->val);
if (fa->result == NULL && fa->val != NULL)
fa->result = vcc_mk_expr(fa->type, "%s", fa->val);
if (fa->result != NULL && sa != NULL) {
More information about the varnish-commit
mailing list