Commit 1a5ca1ef authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Dispatch function calls through sym->action

parent 63fb2ecb
......@@ -39,10 +39,9 @@
/*--------------------------------------------------------------------*/
static void
parse_call(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_call(struct vcc *tl, struct symbol *sym)
{
struct symbol *sym;
vcc_NextToken(tl);
ExpectErr(tl, ID);
......@@ -86,10 +85,9 @@ static const struct arith {
/*--------------------------------------------------------------------*/
static void
parse_set(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_set(struct vcc *tl, struct symbol *sym)
{
const struct symbol *sym;
const struct arith *ap;
const struct token *t;
vcc_type_t fmt;
......@@ -143,10 +141,9 @@ parse_set(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_unset(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_unset(struct vcc *tl, struct symbol *sym)
{
const struct symbol *sym;
const struct token *t;
/* XXX: Wrong, should use VCC_Expr(HEADER) */
......@@ -169,10 +166,11 @@ parse_unset(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_ban(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_ban(struct vcc *tl, struct symbol *sym)
{
(void)sym;
vcc_NextToken(tl);
ExpectErr(tl, '(');
......@@ -191,9 +189,11 @@ parse_ban(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_hash_data(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_hash_data(struct vcc *tl, struct symbol *sym)
{
(void)sym;
vcc_NextToken(tl);
SkipToken(tl, '(');
......@@ -287,12 +287,13 @@ parse_return_vcl(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_return(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_return(struct vcc *tl, struct symbol *sym)
{
unsigned hand;
const char *h;
(void)sym;
vcc_NextToken(tl);
AN(tl->curproc);
if (tl->t->tok == ';' && tl->curproc->method == NULL) {
......@@ -345,11 +346,12 @@ parse_return(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_synthetic(struct vcc *tl)
static void v_matchproto_(sym_act_f)
parse_synthetic(struct vcc *tl, struct symbol *sym)
{
vcc_NextToken(tl);
(void)sym;
ExpectErr(tl, '(');
ERRCHK(tl);
vcc_NextToken(tl);
......
......@@ -108,7 +108,7 @@ typedef void sym_expr_t(struct vcc *tl, struct expr **,
struct symbol *sym, vcc_type_t);
typedef void sym_wildcard_t(struct vcc *, struct symbol *, struct symbol *);
typedef void sym_act_f(struct vcc *tl);
typedef void sym_act_f(struct vcc *, struct symbol *);
struct symbol {
unsigned magic;
......@@ -279,7 +279,7 @@ char *TlDup(struct vcc *tl, const char *s);
/* vcc_expr.c */
void vcc_Expr(struct vcc *tl, vcc_type_t typ);
void vcc_Expr_Call(struct vcc *tl, struct symbol *sym);
sym_act_f vcc_ParseCall;
void vcc_Expr_Init(struct vcc *tl);
sym_expr_t vcc_Eval_Var;
sym_expr_t vcc_Eval_Handle;
......@@ -294,7 +294,7 @@ void vcc_Var_Init(struct vcc *);
/* vcc_parse.c */
void vcc_Parse(struct vcc *tl);
void vcc_ParseIf(struct vcc *tl);
sym_act_f vcc_ParseIf;
/* vcc_utils.c */
const char *vcc_regexp(struct vcc *tl);
......@@ -350,7 +350,7 @@ sym_wildcard_t vcc_Var_Wildcard;
/* vcc_vmod.c */
void vcc_ParseImport(struct vcc *tl);
void vcc_ParseNew(struct vcc *tl);
sym_act_f vcc_ParseNew;
/* vcc_xref.c */
void vcc_AddRef(struct vcc *, struct symbol *);
......
......@@ -1261,8 +1261,8 @@ vcc_Expr(struct vcc *tl, vcc_type_t fmt)
/*--------------------------------------------------------------------
*/
void
vcc_Expr_Call(struct vcc *tl, struct symbol *sym)
void v_matchproto_(sym_act_f)
vcc_ParseCall(struct vcc *tl, struct symbol *sym)
{
struct expr *e;
......@@ -1273,6 +1273,7 @@ vcc_Expr_Call(struct vcc *tl, struct symbol *sym)
vcc_Eval_SymFunc(tl, &e, sym, VOID);
if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e);
SkipToken(tl, ';');
VSB_cat(tl->fb, ";\n");
} else if (t1 != tl->t) {
vcc_ErrWhere2(tl, t1, tl->t);
......@@ -1290,11 +1291,13 @@ vcc_Expr_Init(struct vcc *tl)
sym = VCC_MkSym(tl, "regsub", SYM_FUNC);
AN(sym);
sym->action = vcc_ParseCall;
sym->eval = vcc_Eval_Regsub;
sym->eval_priv = NULL;
sym = VCC_MkSym(tl, "regsuball", SYM_FUNC);
AN(sym);
sym->action = vcc_ParseCall;
sym->eval = vcc_Eval_Regsub;
sym->eval_priv = sym;
......
......@@ -79,10 +79,11 @@ vcc_Conditional(struct vcc *tl)
* null
*/
void
vcc_ParseIf(struct vcc *tl)
void v_matchproto_(sym_act_f)
vcc_ParseIf(struct vcc *tl, struct symbol *sym)
{
(void)sym;
SkipToken(tl, ID);
Fb(tl, 1, "if ");
vcc_Conditional(tl);
......@@ -178,18 +179,14 @@ vcc_Compound(struct vcc *tl)
tl->err = 1;
return;
case ID:
sym = VCC_SymbolGet(tl, SYM_NONE, SYMTAB_NOERR, XREF_NONE);
sym = VCC_SymbolGet(tl, SYM_NONE, SYMTAB_NOERR,
XREF_NONE);
if (sym != NULL && sym->action != NULL) {
if (sym->action_mask != 0)
vcc_AddUses(tl, t, NULL,
sym->action_mask,
"Not a valid action");
sym->action(tl);
break;
}
if (sym != NULL && sym->kind == SYM_FUNC) {
vcc_Expr_Call(tl, sym);
SkipToken(tl, ';');
sym->action(tl, sym);
break;
}
/* FALLTHROUGH */
......
......@@ -245,6 +245,7 @@ vcc_ParseImport(struct vcc *tl)
sym = VCC_MkSym(tl, p, SYM_FUNC);
ERRCHK(tl);
AN(sym);
sym->action = vcc_ParseCall;
sym->vmod = msym->name;
sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
......@@ -265,8 +266,8 @@ vcc_ParseImport(struct vcc *tl)
Fh(tl, 0, "\n/* --- END VMOD %.*s --- */\n\n", PF(mod));
}
void
vcc_ParseNew(struct vcc *tl)
void v_matchproto_(sym_act_f)
vcc_ParseNew(struct vcc *tl, struct symbol *sym)
{
struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp;
......@@ -275,6 +276,7 @@ vcc_ParseNew(struct vcc *tl)
char buf1[128];
char buf2[128];
(void)sym;
vcc_NextToken(tl);
ExpectErr(tl, ID);
vcc_ExpectVid(tl, "VCL object");
......@@ -335,6 +337,7 @@ vcc_ParseNew(struct vcc *tl)
bprintf(buf2, "%s%s", sy1->name, p);
sy3 = VCC_MkSym(tl, buf2, SYM_FUNC);
AN(sy3);
sy3->action = vcc_ParseCall;
sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sy3->eval_priv = p;
......
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