Commit 7912df11 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Start to make symbols carry their own evaluation function around



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5479 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent da2cdbf3
......@@ -38,6 +38,9 @@
struct acl_e;
struct proc;
struct expr;
struct vcc;
struct symbol;
enum var_type {
#define VCC_TYPE(foo) foo,
......@@ -75,6 +78,9 @@ enum symkind {
#undef VCC_SYMB
};
typedef void sym_expr_t(struct vcc *tl, struct expr **e,
const struct symbol *sym);
struct symbol {
unsigned magic;
#define SYMBOL_MAGIC 0x3368c9fb
......@@ -92,6 +98,8 @@ struct symbol {
struct proc *proc;
sym_expr_t *eval;
const char *cfunc;
const char *args;
const struct var *var;
......@@ -231,6 +239,7 @@ 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);
sym_expr_t vcc_Expr_Func;
/* vcc_dir_dns.c */
parsedirector_f vcc_ParseDnsDirector;
......@@ -246,7 +255,7 @@ char *vcc_regexp(struct vcc *tl);
int vcc_StringVal(struct vcc *tl);
void vcc_ExpectedStringval(struct vcc *tl);
/* vcc_symbol */
/* vcc_symb.c */
struct symbol *VCC_AddSymbolStr(struct vcc *tl, const char *name, enum symkind);
struct symbol *VCC_GetSymbolTok(struct vcc *tl, const struct token *tok,
enum symkind);
......
......@@ -402,11 +402,6 @@ hack_regsub(struct vcc *tl, struct expr **e, int all)
/*--------------------------------------------------------------------
*/
#if 0
#define VCC_TYPE(a) case a: return(#a);
#include "vcc_types.h"
#undef VCC_TYPE
#endif
static enum var_type
vcc_arg_type(const char **p)
......@@ -421,8 +416,8 @@ vcc_arg_type(const char **p)
/*--------------------------------------------------------------------
*/
static void
vcc_expr_call(struct vcc *tl, struct expr **e, const struct symbol *sym)
void
vcc_Expr_Func(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
const char *p, *q, *r;
struct expr *e1;
......@@ -561,6 +556,12 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
return;
}
AN(sym);
if (sym->eval != NULL) {
sym->eval(tl, &e1, sym);
ERRCHK(tl);
*e = e1;
return;
}
switch(sym->kind) {
case SYM_VAR:
......@@ -573,9 +574,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
vcc_NextToken(tl);
break;
case SYM_FUNC:
vcc_expr_call(tl, &e1, sym);
ERRCHK(tl);
*e = e1;
ErrInternal(tl);
return;
case SYM_PROC:
vsb_printf(tl->sb,
......@@ -1036,7 +1035,7 @@ vcc_Expr_Call(struct vcc *tl, const struct symbol *sym)
t1 = tl->t;
e = vcc_new_expr();
vcc_expr_call(tl, &e, sym);
vcc_Expr_Func(tl, &e, sym);
if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e);
vsb_cat(tl->fb, ";\n");
......
......@@ -155,6 +155,7 @@ vcc_ParseImport(struct vcc *tl)
sym = VCC_AddSymbolStr(tl, p, SYM_FUNC);
ERRCHK(tl);
AN(sym);
sym->eval = vcc_Expr_Func;
p += strlen(p) + 1;
sym->cfunc = p;
p += strlen(p) + 1;
......
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