[master] 5a4d3be Collapse the variables fully into symbols

Poul-Henning Kamp phk at FreeBSD.org
Thu May 19 10:00:09 CEST 2016


commit 5a4d3be3a6fcc52b629aba77597db6517e898662
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 19 00:12:29 2016 +0000

    Collapse the variables fully into symbols

diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 8e62d2d..425b993 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -82,26 +82,26 @@ static const struct arith {
 static void
 parse_set(struct vcc *tl)
 {
-	const struct var *vp;
+	const struct symbol *sym;
 	const struct arith *ap;
 	enum var_type fmt;
 
 	vcc_NextToken(tl);
 	ExpectErr(tl, ID);
-	vp = vcc_FindVar(tl, tl->t, 1, "cannot be set");
+	sym = vcc_FindVar(tl, tl->t, 1, "cannot be set");
 	ERRCHK(tl);
-	assert(vp != NULL);
-	Fb(tl, 1, "%s\n", vp->lname);
+	assert(sym != NULL);
+	Fb(tl, 1, "%s\n", sym->lname);
 	tl->indent += INDENT;
 	vcc_NextToken(tl);
-	fmt = vp->fmt;
+	fmt = sym->fmt;
 	for (ap = arith; ap->type != VOID; ap++) {
 		if (ap->type != fmt)
 			continue;
 		if (ap->oper != tl->t->tok)
 			continue;
 		if (ap->oper != '=')
-			Fb(tl, 1, "%s %c ", vp->rname, *tl->t->b);
+			Fb(tl, 1, "%s %c ", sym->rname, *tl->t->b);
 		vcc_NextToken(tl);
 		fmt = ap->want;
 		break;
@@ -124,22 +124,22 @@ parse_set(struct vcc *tl)
 static void
 parse_unset(struct vcc *tl)
 {
-	const struct var *vp;
+	const struct symbol *sym;
 
 	/* XXX: Wrong, should use VCC_Expr(HEADER) */
 	vcc_NextToken(tl);
 	ExpectErr(tl, ID);
-	vp = vcc_FindVar(tl, tl->t, 1, "cannot be unset");
+	sym = vcc_FindVar(tl, tl->t, 1, "cannot be unset");
 	ERRCHK(tl);
-	assert(vp != NULL);
-	if (vp->fmt != HEADER) {
+	assert(sym != NULL);
+	if (sym->fmt != HEADER) {
 		VSB_printf(tl->sb,
 		    "Only HTTP header variables can be unset.\n");
 		vcc_ErrWhere(tl, tl->t);
 		return;
 	}
 	ERRCHK(tl);
-	Fb(tl, 1, "%svrt_magic_string_unset);\n", vp->lname);
+	Fb(tl, 1, "%svrt_magic_string_unset);\n", sym->lname);
 	vcc_NextToken(tl);
 }
 
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index a9657e6..fc5ccc1 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -609,7 +609,6 @@ vcc_NewVcc(const struct vcp *vcp)
 	ALLOC_OBJ(tl, VCC_MAGIC);
 	AN(tl);
 	tl->param = vcp;
-	tl->vars = vcc_vars;
 	VTAILQ_INIT(&tl->symbols);
 	VTAILQ_INIT(&tl->inifin);
 	VTAILQ_INIT(&tl->membits);
@@ -702,17 +701,20 @@ vcc_CompileSource(const struct vcp * const vcp, struct vsb *sb,
 		sym2->nref = 1;
 	}
 
-	for (v = tl->vars; v->name != NULL; v++) {
+	for (v = vcc_vars; v->name != NULL; v++) {
 		if (v->fmt == HEADER) {
 			sym = VCC_AddSymbolStr(tl, v->name, SYM_WILDCARD);
 			sym->wildcard = vcc_Var_Wildcard;
+			sym->wildcard_priv = v;
 		} else {
 			sym = VCC_AddSymbolStr(tl, v->name, SYM_VAR);
 		}
-		sym->var = v;
 		sym->fmt = v->fmt;
 		sym->eval = vcc_Eval_Var;
 		sym->r_methods = v->r_methods;
+		sym->rname = v->rname;
+		sym->w_methods = v->w_methods;
+		sym->lname = v->lname;
 	}
 
 	sym = VCC_AddSymbolStr(tl, "storage.", SYM_WILDCARD);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 6d6b7da..d02029d 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -118,6 +118,7 @@ struct symbol {
 	char				*name;
 	unsigned			nlen;
 	sym_wildcard_t			*wildcard;
+	const void			*wildcard_priv;
 	enum symkind			kind;
 
 	const struct token		*def_b, *def_e;
@@ -137,8 +138,10 @@ struct symbol {
 	const char			*args;
 
 	/* SYM_VAR */
-	const struct var		*var;
+	const char			*rname;
 	unsigned			r_methods;
+	const char			*lname;
+	unsigned			w_methods;
 };
 
 VTAILQ_HEAD(tokenhead, token);
@@ -176,7 +179,6 @@ struct vcc {
 	/* Parameter/Template section */
 	const struct vcp	*param;
 
-	const struct var	*vars;
 	VTAILQ_HEAD(, symbol)	symbols;
 
 	struct inifinhead	inifin;
@@ -340,7 +342,7 @@ void vcc_AddToken(struct vcc *tl, unsigned tok, const char *b,
 
 /* vcc_var.c */
 sym_wildcard_t vcc_Var_Wildcard;
-const struct var *vcc_FindVar(struct vcc *tl, const struct token *t,
+const struct symbol *vcc_FindVar(struct vcc *tl, const struct token *t,
     int wr_access, const char *use);
 
 /* vcc_vmod.c */
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index d043d21..506f196 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -524,15 +524,12 @@ void __match_proto__(sym_expr_t)
 vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym,
     enum var_type fmt)
 {
-	const struct var *vp;
 
 	(void)fmt;
 	assert(sym->kind == SYM_VAR);
 	vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
-	vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
 	ERRCHK(tl);
-	assert(vp != NULL);
-	*e = vcc_mk_expr(vp->fmt, "%s", vp->rname);
+	*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
 	vcc_NextToken(tl);
 }
 
diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c
index 2c3f81c..efc4f11 100644
--- a/lib/libvcc/vcc_storage.c
+++ b/lib/libvcc/vcc_storage.c
@@ -139,10 +139,12 @@ vcc_Stv_Wildcard(struct vcc *tl, const struct token *t,
 
 	sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
 	AN(sym);
-	sym->var = v;
 	sym->fmt = v->fmt;
 	sym->eval = vcc_Eval_Var;
 	sym->r_methods = v->r_methods;
+	sym->rname = v->rname;
+	sym->w_methods = v->w_methods;
+	sym->lname = v->lname;
 
 	return (sym);
 }
diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c
index 4b03269..6bd5dec 100644
--- a/lib/libvcc/vcc_var.c
+++ b/lib/libvcc/vcc_var.c
@@ -47,7 +47,7 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
 	const char *p, *leaf;
 	struct vsb *vsb;
 
-	vh = wc->var;
+	vh = wc->wildcard_priv;
 	assert(vh->fmt == HEADER);
 
 	v = TlAlloc(tl, sizeof *v);
@@ -83,29 +83,26 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
 
 	sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
 	AN(sym);
-	sym->var = v;
 	sym->fmt = v->fmt;
 	sym->eval = vcc_Eval_Var;
 	sym->r_methods = v->r_methods;
+	sym->rname = v->rname;
+	sym->w_methods = v->w_methods;
+	sym->lname = v->lname;
 	return (sym);
 }
 
 /*--------------------------------------------------------------------*/
 
-const struct var *
+const struct symbol *
 vcc_FindVar(struct vcc *tl, const struct token *t, int wr_access,
     const char *use)
 {
-	const struct var *v;
 	const struct symbol *sym;
 
-	AN(tl->vars);
 	sym = VCC_FindSymbol(tl, t, SYM_VAR);
 	if (sym != NULL) {
-		v = sym->var;
-		AN(v);
-
-		if (wr_access && v->w_methods == 0) {
+		if (wr_access && sym->w_methods == 0) {
 			VSB_printf(tl->sb, "Variable ");
 			vcc_ErrToken(tl, t);
 			VSB_printf(tl->sb, " is read only.");
@@ -113,8 +110,8 @@ vcc_FindVar(struct vcc *tl, const struct token *t, int wr_access,
 			vcc_ErrWhere(tl, t);
 			return (NULL);
 		} else if (wr_access) {
-			vcc_AddUses(tl, t, v->w_methods, use);
-		} else if (v->r_methods == 0) {
+			vcc_AddUses(tl, t, sym->w_methods, use);
+		} else if (sym->r_methods == 0) {
 			VSB_printf(tl->sb, "Variable ");
 			vcc_ErrToken(tl, t);
 			VSB_printf(tl->sb, " is write only.");
@@ -122,9 +119,9 @@ vcc_FindVar(struct vcc *tl, const struct token *t, int wr_access,
 			vcc_ErrWhere(tl, t);
 			return (NULL);
 		} else {
-			vcc_AddUses(tl, t, v->r_methods, use);
+			vcc_AddUses(tl, t, sym->r_methods, use);
 		}
-		return (v);
+		return (sym);
 	}
 	VSB_printf(tl->sb, "Unknown variable ");
 	vcc_ErrToken(tl, t);



More information about the varnish-commit mailing list