r5479 - trunk/varnish-cache/lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Wed Oct 27 21:40:08 CEST 2010


Author: phk
Date: 2010-10-27 21:40:08 +0200 (Wed, 27 Oct 2010)
New Revision: 5479

Modified:
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_expr.c
   trunk/varnish-cache/lib/libvcl/vcc_vmod.c
Log:
Start to make symbols carry their own evaluation function around



Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-10-27 18:48:40 UTC (rev 5478)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-10-27 19:40:08 UTC (rev 5479)
@@ -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 @@
 #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 proc			*proc;
 
+	sym_expr_t			*eval;
+
 	const char			*cfunc;
 	const char			*args;
 	const struct var		*var;
@@ -231,6 +239,7 @@
 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 @@
 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);

Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-10-27 18:48:40 UTC (rev 5478)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-10-27 19:40:08 UTC (rev 5479)
@@ -402,11 +402,6 @@
 
 /*--------------------------------------------------------------------
  */
-#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 @@
 /*--------------------------------------------------------------------
  */
 
-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 @@
 			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_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 @@
 
 	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");

Modified: trunk/varnish-cache/lib/libvcl/vcc_vmod.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-10-27 18:48:40 UTC (rev 5478)
+++ trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-10-27 19:40:08 UTC (rev 5479)
@@ -155,6 +155,7 @@
 			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;




More information about the varnish-commit mailing list