Commit 12a16117 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Omit the separator in VCC functions extra arguments

Instead, the comma is emitted when there is indeed an extra argument.

This change was initially submitted in #3147 and is needed when the
extra argument may vary for a given symbol. More specifically, when
a method symbol may be shared by several instance symbols, it becomes
really difficult to find a spot where that extra comma might be added.

Removing it from the extra argument itself makes this easier once we
reach the point where method symbols are unique (per object) instead
of repeated (per instance).
parent 77d5d0f0
......@@ -465,7 +465,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
VTAILQ_HEAD(,func_arg) head;
struct token *t1;
const struct vjsn_val *vv, *vvp;
const char *sa;
const char *sa, *extra_sep;
char ssa[64];
int n;
......@@ -483,8 +483,13 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
}
vv = VTAILQ_NEXT(vv, list);
SkipToken(tl, '(');
if (extra == NULL)
if (extra == NULL) {
extra = "";
extra_sep = "";
} else {
AN(*extra);
extra_sep = ", ";
}
VTAILQ_INIT(&head);
for (;vv != NULL; vv = VTAILQ_NEXT(vv, list)) {
assert(vv->type == VJSN_ARRAY);
......@@ -570,10 +575,11 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
}
if (sa != NULL)
e1 = vcc_mk_expr(rfmt, "%s(ctx%s,\v+\n&(%s)\v+ {\n",
cfunc, extra, sa);
e1 = vcc_mk_expr(rfmt, "%s(ctx%s%s,\v+\n&(%s)\v+ {\n",
cfunc, extra_sep, extra, sa);
else
e1 = vcc_mk_expr(rfmt, "%s(ctx%s\v+", cfunc, extra);
e1 = vcc_mk_expr(rfmt, "%s(ctx%s%s\v+",
cfunc, extra_sep, extra);
n = 0;
VTAILQ_FOREACH_SAFE(fa, &head, list, fa2) {
n++;
......
......@@ -385,7 +385,6 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
struct inifin *ifp;
struct vsb *buf;
const struct vjsn_val *vv, *vf;
const char *p;
int null_ok = 0;
(void)sym;
......@@ -433,7 +432,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
buf = VSB_new_auto();
AN(buf);
VSB_printf(buf, ", &%s, \"%s\"", sy1->rname, sy1->name);
VSB_printf(buf, "&%s, \"%s\"", sy1->rname, sy1->name);
AZ(VSB_finish(buf));
vcc_Eval_Func(tl, vf, VSB_data(buf), sy2);
VSB_destroy(&buf);
......@@ -456,9 +455,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
/* Instantiate symbols for the methods */
buf = VSB_new_auto();
AN(buf);
VSB_printf(buf, ", %s", sy1->rname);
AZ(VSB_finish(buf));
p = TlDup(tl, VSB_data(buf));
while (vv != NULL) {
vf = VTAILQ_FIRST(&vv->children);
assert(vf->type == VJSN_STRING);
......@@ -472,7 +469,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
sy3 = VCC_MkSym(tl, VSB_data(buf), SYM_FUNC, VCL_LOW, VCL_HIGH);
AN(sy3);
func_sym(sy3, sy2->vmod_name, VTAILQ_NEXT(vf, list));
sy3->extra = p;
sy3->extra = sy1->rname;
vv = VTAILQ_NEXT(vv, list);
}
VSB_destroy(&buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment