Commit 2dbe1505 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add support for calling VMOD-procedures as actions in compound statements.

A procedure is simply a function which returns VOID.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5205 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2a70111e
......@@ -434,6 +434,7 @@ vcc_ParseAction(struct vcc *tl)
{
struct token *at;
struct action_table *atp;
const struct symbol *sym;
at = tl->t;
assert (at->tok == ID);
......@@ -443,8 +444,13 @@ vcc_ParseAction(struct vcc *tl)
vcc_AddUses(tl, at, atp->bitmask,
"not a valid action");
atp->func(tl);
return(1);
return (1);
}
}
sym = VCC_FindSymbol(tl, tl->t);
if (sym != NULL && sym->kind == SYM_PROC) {
vcc_Expr_Call(tl, sym);
return (1);
}
return (0);
}
......@@ -242,6 +242,7 @@ void vcc_TimeVal(struct vcc *tl, double *);
unsigned vcc_UintVal(struct vcc *tl);
double vcc_DoubleVal(struct vcc *tl);
void vcc_Expr(struct vcc *tl, enum var_type typ);
void vcc_Expr_Call(struct vcc *tl, const struct symbol *sym);
/* vcc_dir_dns.c */
parsedirector_f vcc_ParseDnsDirector;
......
......@@ -453,6 +453,15 @@ vcc_expr_call(struct vcc *tl, struct expr **e, const struct symbol *sym)
} else {
vcc_expr0(tl, &e1, fmt);
ERRCHK(tl);
if (e1->fmt != fmt) {
vsb_printf(tl->sb, "Wrong argument type.");
vsb_printf(tl->sb, " Expected %s.",
vcc_Type(fmt));
vsb_printf(tl->sb, " Got %s.\n",
vcc_Type(e1->fmt));
vcc_ErrWhere2(tl, e1->t1, tl->t);
return;
}
assert(e1->fmt == fmt);
if (e1->fmt == STRING_LIST) {
e1 = vcc_expr_edit(STRING_LIST,
......@@ -560,7 +569,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
vcc_ErrWhere(tl, tl->t);
return;
default:
vsb_printf(tl->sb, "Wrong kind of symbol.\n");
vsb_printf(tl->sb, "Symbol is not a function.\n");
vcc_ErrWhere(tl, tl->t);
return;
}
......@@ -921,3 +930,26 @@ vcc_Expr(struct vcc *tl, enum var_type fmt)
}
vcc_delete_expr(e);
}
/*--------------------------------------------------------------------
*/
void
vcc_Expr_Call(struct vcc *tl, const struct symbol *sym)
{
struct expr *e;
struct token *t1;
t1 = tl->t;
e = vcc_new_expr();
vcc_expr_call(tl, &e, sym);
if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e);
vsb_cat(tl->fb, ";\n");
} else if (t1 != tl->t) {
vcc_ErrWhere2(tl, t1, tl->t);
}
vcc_delete_expr(e);
}
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