r5482 - trunk/varnish-cache/lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Wed Oct 27 23:03:12 CEST 2010


Author: phk
Date: 2010-10-27 23:03:12 +0200 (Wed, 27 Oct 2010)
New Revision: 5482

Modified:
   trunk/varnish-cache/lib/libvcl/vcc_backend.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_expr.c
Log:
Turn backends into self evaluating symbols



Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c	2010-10-27 20:51:27 UTC (rev 5481)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2010-10-27 21:03:12 UTC (rev 5482)
@@ -676,6 +676,22 @@
 }
 
 /*--------------------------------------------------------------------
+ * Tell rest of compiler about a backend
+ */
+
+static void
+vcc_DefBackend(struct vcc *tl, const struct token *nm)
+{
+	struct symbol *sym;
+
+	sym = VCC_GetSymbolTok(tl, nm, SYM_BACKEND);
+	AN(sym);
+	sym->fmt = BACKEND;
+	sym->eval = vcc_Expr_Backend;
+	sym->ndef++;
+}
+
+/*--------------------------------------------------------------------
  * Parse a plain backend aka a simple director
  */
 
@@ -687,7 +703,7 @@
 
 	h = TlAlloc(tl, sizeof *h);
 	h->name = tl->t_dir;
-	vcc_AddDef(tl, tl->t_dir, SYM_BACKEND);
+	vcc_DefBackend(tl, tl->t_dir);
 	sprintf(vgcname, "_%.*s", PF(h->name));
 	h->vgcname = TlAlloc(tl, strlen(vgcname) + 1);
 	strcpy(h->vgcname, vgcname);
@@ -735,7 +751,7 @@
 		tl->t_policy = t_first;
 		vcc_ParseSimpleDirector(tl);
 	} else {
-		vcc_AddDef(tl, tl->t_dir, SYM_BACKEND);
+		vcc_DefBackend(tl, tl->t_dir);
 		ExpectErr(tl, ID);		/* ID: policy */
 		tl->t_policy = tl->t;
 		vcc_NextToken(tl);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-10-27 20:51:27 UTC (rev 5481)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-10-27 21:03:12 UTC (rev 5482)
@@ -78,7 +78,7 @@
 #undef VCC_SYMB
 };
 
-typedef void sym_expr_t(struct vcc *tl, struct expr **e,
+typedef void sym_expr_t(struct vcc *tl, struct expr * const *e,
     const struct symbol *sym);
 
 struct symbol {
@@ -241,6 +241,7 @@
 void vcc_Expr_Call(struct vcc *tl, const struct symbol *sym);
 sym_expr_t vcc_Expr_Var;
 sym_expr_t vcc_Expr_Func;
+sym_expr_t vcc_Expr_Backend;
 
 /* vcc_dir_dns.c */
 parsedirector_f vcc_ParseDnsDirector;

Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-10-27 20:51:27 UTC (rev 5481)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-10-27 21:03:12 UTC (rev 5482)
@@ -417,8 +417,23 @@
  */
 
 void
-vcc_Expr_Var(struct vcc *tl, struct expr **e, const struct symbol *sym)
+vcc_Expr_Backend(struct vcc *tl, struct expr * const *e, const struct symbol *sym)
 {
+
+	assert(sym->kind == SYM_BACKEND);
+
+	vcc_ExpectCid(tl);
+	vcc_AddRef(tl, tl->t, SYM_BACKEND);
+	vsb_printf((*e)->vsb, "VGCDIR(_%.*s)", PF(tl->t));
+	(*e)->fmt = BACKEND;
+	vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------
+ */
+void
+vcc_Expr_Var(struct vcc *tl, struct expr * const *e, const struct symbol *sym)
+{
 	const struct var *vp;
 
 	assert(sym->kind == SYM_VAR);
@@ -429,18 +444,16 @@
 	vsb_printf((*e)->vsb, "%s", vp->rname);
 	(*e)->fmt = vp->fmt;
 	vcc_NextToken(tl);
-	vsb_finish((*e)->vsb);
-	AZ(vsb_overflowed((*e)->vsb));
 }
 
 /*--------------------------------------------------------------------
  */
 
 void
-vcc_Expr_Func(struct vcc *tl, struct expr **e, const struct symbol *sym)
+vcc_Expr_Func(struct vcc *tl, struct expr * const *e, const struct symbol *sym)
 {
 	const char *p, *q, *r;
-	struct expr *e1;
+	struct expr *e1, *e2;
 	enum var_type fmt;
 	char buf[32];
 
@@ -450,10 +463,11 @@
 	SkipToken(tl, ID);
 	SkipToken(tl, '(');
 	p = sym->args;
-	(*e)->fmt = vcc_arg_type(&p);
-	vsb_printf((*e)->vsb, "%s(sp, \v+", sym->cfunc);
-	vsb_finish((*e)->vsb);
-	AZ(vsb_overflowed((*e)->vsb));
+	e2 = vcc_new_expr();
+	e2->fmt = vcc_arg_type(&p);
+	vsb_printf(e2->vsb, "%s(sp, \v+", sym->cfunc);
+	vsb_finish(e2->vsb);
+	AZ(vsb_overflowed(e2->vsb));
 	q = "\v1\n\v2";
 	while (*p != '\0') {
 		e1 = NULL;
@@ -496,11 +510,13 @@
 			if (*p != '\0')
 				SkipToken(tl, ',');
 		}
-		*e = vcc_expr_edit((*e)->fmt, q, *e, e1);
+		e2 = vcc_expr_edit(e2->fmt, q, e2, e1);
 		q = "\v1,\n\v2";
 	}
 	SkipToken(tl, ')');
-	*e = vcc_expr_edit((*e)->fmt, "\v1\n)\v-", *e, NULL);
+	e2 = vcc_expr_edit(e2->fmt, "\v1\n)\v-", e2, NULL);
+	(*e)->fmt = e2->fmt;
+	vsb_cat((*e)->vsb, vsb_data(e2->vsb));
 }
 
 /*--------------------------------------------------------------------
@@ -516,7 +532,6 @@
 {
 	struct expr *e1, *e2;
 	const struct symbol *sym;
-	const struct var *vp;
 	double d;
 
 	*e = NULL;
@@ -553,14 +568,6 @@
 			e1->fmt = BOOL;
 			break;
 		}
-		if (fmt == BACKEND) {
-			vcc_ExpectCid(tl);
-			vcc_AddRef(tl, tl->t, SYM_BACKEND);
-			vsb_printf(e1->vsb, "VGCDIR(_%.*s)", PF(tl->t));
-			e1->fmt = BACKEND;
-			vcc_NextToken(tl);
-			break;
-		}
 		/*
 		 * XXX: what if var and func/proc had same name ?
 		 * XXX: look for SYM_VAR first for consistency ?
@@ -578,8 +585,7 @@
 		if (sym->eval != NULL) {
 			sym->eval(tl, &e1, sym);
 			ERRCHK(tl);
-			*e = e1;
-			return;
+			break;
 		}
 
 		switch(sym->kind) {
@@ -1049,6 +1055,8 @@
 	t1 = tl->t;
 	e = vcc_new_expr();
 	vcc_Expr_Func(tl, &e, sym);
+	vsb_finish(e->vsb);
+	AZ(vsb_overflowed(e->vsb));
 	if (!tl->err) {
 		vcc_expr_fmt(tl->fb, tl->indent, e);
 		vsb_cat(tl->fb, ";\n");




More information about the varnish-commit mailing list