[master] d6ed35e Support versioned symbols.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 20 10:49:09 UTC 2018


commit d6ed35e9cfed11e4a5e04f1bf43e8563b3f8feba
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 20 10:48:30 2018 +0000

    Support versioned symbols.

diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 9b2809e..1f2987f 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -166,13 +166,15 @@ returns = (
 # 'backend' means all methods tagged "B"
 # 'both' means all methods tagged "B" or "C"
 
-sp_variables = collections.OrderedDict()
+varprotos = {}
+
+def varproto(s):
+	if not s in varprotos:
+		fh.write(s + ";\n")
+		varprotos[s] = True
 
 class vardef(object):
 	def __init__(self, nam, typ, rd, wr, wu, vlo, vhi):
-		if nam in sp_variables:
-			return
-		sp_variables[nam] = self
 		self.nam = nam
 		self.typ = typ
 		self.rd = rd
@@ -181,6 +183,8 @@ class vardef(object):
 		self.vlo = vlo
 		self.vhi = vhi
 
+		self.emit()
+
 	def emit(self):
 		fh.write("\n")
 		fo.write("\n")
@@ -190,11 +194,11 @@ class vardef(object):
 		# fo.write("\t{ \"%s\", %s,\n" % (nm, self.typ))
 		fo.write("\tsym = VCC_MkSym(tl, \"%s\", " % self.nam)
 		if (self.typ == "HEADER"):
-			fo.write(" SYM_NONE);\n")
+			fo.write(" SYM_NONE, %d, %d);\n" % (self.vlo, self.vhi))
 			fo.write("\tAN(sym);\n");
 			fo.write("\tsym->wildcard = vcc_Var_Wildcard;\n")
 		else:
-			fo.write(" SYM_VAR);\n")
+			fo.write(" SYM_VAR, %d, %d);\n" % (self.vlo, self.vhi))
 		fo.write("\tAN(sym);\n")
 		fo.write("\tsym->type = %s;\n" % self.typ)
 		fo.write("\tsym->eval = vcc_Eval_Var;\n")
@@ -205,7 +209,7 @@ class vardef(object):
 			fo.write('";\n')
 		elif len(self.rd):
 			fo.write('\tsym->rname = "VRT_r_%s(ctx)";\n' % cnam)
-			fh.write("VCL_" + self.typ + " VRT_r_%s(VRT_CTX);\n" % cnam)
+			varproto("VCL_" + self.typ + " VRT_r_%s(VRT_CTX)" % cnam)
 		fo.write("\tsym->r_methods =\n")
 		restrict(fo, self.rd)
 		fo.write(";\n")
@@ -216,17 +220,18 @@ class vardef(object):
 			fo.write('";\n')
 		elif len(self.wr):
 			fo.write('\tsym->lname = "VRT_l_%s(ctx, ";\n' % cnam)
-			fh.write("void VRT_l_%s(VRT_CTX, " % cnam)
+			s = "void VRT_l_%s(VRT_CTX, " % cnam
 			if self.typ != "STRING" and self.typ != "BODY":
-				fh.write("VCL_" + self.typ + ");\n")
+				s += "VCL_" + self.typ + ")"
 			else:
-				fh.write(ctyp + ", ...);\n")
+				s += ctyp + ", ...)"
+			varproto(s);
 		fo.write("\tsym->w_methods =\n")
 		restrict(fo, self.wr)
 		fo.write(";\n")
 
 		if len(self.uns):
-			fh.write("void VRT_u_%s(VRT_CTX);\n" % cnam)
+			varproto("void VRT_u_%s(VRT_CTX)" % cnam)
 			fo.write('\tsym->uname = "VRT_u_%s(ctx)";\n' % cnam)
 		fo.write('\tsym->u_methods =\n')
 		restrict(fo, self.uns)
@@ -297,8 +302,6 @@ def parse_var_doc(fn):
 			m += 1
 		parse_var(l[n-2:m-1])
 
-parse_var_doc(join(buildroot, "doc/sphinx/reference/vcl_var.rst"))
-
 stv_variables = (
 	('free_space',	'BYTES',	"0.", 'storage.<name>.free_space', """
 	Free space available in the named stevedore. Only available for
@@ -722,11 +725,7 @@ vcc_Var_Init(struct vcc *tl)
 """)
 
 
-
-for i in sp_variables.values():
-	i.emit()
-
-# fo.write("\t{ NULL }\n};\n\n")
+parse_var_doc(join(buildroot, "doc/sphinx/reference/vcl_var.rst"))
 fo.write("}\n")
 
 for i in stv_variables:
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 5447e8c..8e61f27 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -364,7 +364,7 @@ vcc_act_synthetic(struct vcc *tl, struct token *t, struct symbol *sym)
 #define ACT(name, func, mask)						\
 	do {								\
 		const char pp[] = #name;				\
-		sym = VCC_MkSym(tl, pp, SYM_ACTION);			\
+		sym = VCC_MkSym(tl, pp, SYM_ACTION, VCL_LOW, VCL_HIGH);	\
 		AN(sym);						\
 		sym->action = func;					\
 		sym->action_mask = (mask);				\
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 758b7e7..69a2db9 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -739,7 +739,8 @@ VCC_New(void)
 	assert(tl->fh != NULL);
 
 	for (i = 1; i < VCL_MET_MAX; i++) {
-		sym = VCC_MkSym(tl, method_tab[i].name, SYM_SUB);
+		sym = VCC_MkSym(tl, method_tab[i].name,
+		    SYM_SUB, VCL_LOW, VCL_HIGH);
 		p = vcc_NewProc(tl, sym);
 		p->method = &method_tab[i];
 		VSB_printf(p->cname, "VGC_function_%s", p->method->name);
@@ -822,7 +823,7 @@ vcc_predef_vcl(struct vcc *vcc, const char *name)
 {
 	struct symbol *sym;
 
-	sym = VCC_MkSym(vcc, name, SYM_VCL);
+	sym = VCC_MkSym(vcc, name, SYM_VCL, VCL_LOW, VCL_HIGH);
 	AN(sym);
 	sym->type = VCL;
 	sym->r_methods = VCL_MET_RECV;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index bdbb3a6..7ae776c 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -338,7 +338,8 @@ void vcc_stevedore(struct vcc *vcc, const char *stv_name);
 
 /* vcc_symb.c */
 void VCC_PrintCName(struct vsb *vsb, const char *b, const char *e);
-struct symbol *VCC_MkSym(struct vcc *tl, const char *b, vcc_kind_t);
+struct symbol *VCC_MkSym(struct vcc *tl, const char *b, vcc_kind_t,
+    unsigned, unsigned);
 extern const char XREF_NONE[];
 extern const char XREF_DEF[];
 extern const char XREF_REF[];
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 520e6ed..f8e5d90 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1280,25 +1280,25 @@ vcc_Expr_Init(struct vcc *tl)
 {
 	struct symbol *sym;
 
-	sym = VCC_MkSym(tl, "regsub", SYM_FUNC);
+	sym = VCC_MkSym(tl, "regsub", SYM_FUNC, VCL_LOW, VCL_HIGH);
 	AN(sym);
 	sym->type = STRING;
 	sym->eval = vcc_Eval_Regsub;
 	sym->eval_priv = NULL;
 
-	sym = VCC_MkSym(tl, "regsuball", SYM_FUNC);
+	sym = VCC_MkSym(tl, "regsuball", SYM_FUNC, VCL_LOW, VCL_HIGH);
 	AN(sym);
 	sym->type = STRING;
 	sym->eval = vcc_Eval_Regsub;
 	sym->eval_priv = sym;
 
-	sym = VCC_MkSym(tl, "true", SYM_FUNC);
+	sym = VCC_MkSym(tl, "true", SYM_FUNC, VCL_LOW, VCL_HIGH);
 	AN(sym);
 	sym->type = BOOL;
 	sym->eval = vcc_Eval_BoolConst;
 	sym->eval_priv = sym;
 
-	sym = VCC_MkSym(tl, "false", SYM_FUNC);
+	sym = VCC_MkSym(tl, "false", SYM_FUNC, VCL_LOW, VCL_HIGH);
 	AN(sym);
 	sym->type = BOOL;
 	sym->eval = vcc_Eval_BoolConst;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 95b459f..0326298 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -430,5 +430,5 @@ vcc_Parse_Init(struct vcc *tl)
 	struct toplev *tp;
 
 	for (tp = toplev; tp->name != NULL; tp++)
-		AN(VCC_MkSym(tl, tp->name, SYM_NONE));
+		AN(VCC_MkSym(tl, tp->name, SYM_NONE, VCL_LOW, VCL_HIGH));
 }
diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c
index 06af8c7..a979708 100644
--- a/lib/libvcc/vcc_storage.c
+++ b/lib/libvcc/vcc_storage.c
@@ -84,7 +84,7 @@ vcc_stevedore(struct vcc *vcc, const char *stv_name)
 
 	CHECK_OBJ_NOTNULL(vcc, VCC_MAGIC);
 	bprintf(buf, "storage.%s", stv_name);
-	sym = VCC_MkSym(vcc, buf, SYM_VAR);
+	sym = VCC_MkSym(vcc, buf, SYM_VAR, VCL_LOW, VCL_40);
 	AN(sym);
 	sym->type = STEVEDORE;
 	sym->eval = vcc_Eval_Var;
@@ -94,7 +94,7 @@ vcc_stevedore(struct vcc *vcc, const char *stv_name)
 
 	for (sv = stvars; sv->name != NULL; sv++) {
 		bprintf(buf, "storage.%s.%s", stv_name, sv->name);
-		sym = VCC_MkSym(vcc, buf, SYM_VAR);
+		sym = VCC_MkSym(vcc, buf, SYM_VAR, VCL_LOW, VCL_40);
 		AN(sym);
 		sym->type = sv->type;
 		sym->eval = vcc_Eval_Var;
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index a039006..3d66e81 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -100,13 +100,15 @@ vcc_new_symbol(struct vcc *tl, const char *b, const char *e)
 
 static struct symbol *
 VCC_Symbol(struct vcc *tl, struct symbol *parent,
-    const char *b, const char *e, vcc_kind_t kind, int create)
+    const char *b, const char *e, vcc_kind_t kind,
+    int create, unsigned vlo, unsigned vhi)
 {
 	const char *q;
 	struct symbol *sym, *sym2 = NULL;
 	size_t l;
 	int i;
 
+	assert(vlo <= vhi);
 	if (tl->symbols == NULL)
 		tl->symbols = vcc_new_symbol(tl, "<root>", NULL);
 	if (parent == NULL)
@@ -128,6 +130,8 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
 	assert(l > 0);
 
 	VTAILQ_FOREACH(sym, &parent->children, list) {
+		if (sym->lorev > vhi || sym->hirev < vlo)
+			continue;
 		i = strncasecmp(sym->name, b, l);
 		if (i < 0)
 			continue;
@@ -159,17 +163,21 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
 			if (i > 0 || (i == 0 && l < sym->nlen))
 				break;
 		}
+		sym2->lorev = vlo;
+		sym2->hirev = vhi;
 		if (sym == NULL)
 			VTAILQ_INSERT_TAIL(&parent->children, sym2, list);
 		else
 			VTAILQ_INSERT_BEFORE(sym, sym2, list);
-		return (VCC_Symbol(tl, parent, b, e, kind, -1));
+		return (VCC_Symbol(tl, parent, b, e, kind, -1, vlo, vhi));
 	}
 	if (sym == NULL && create < 1)
 		return (sym);
 	if (sym == NULL) {
 		sym = vcc_new_symbol(tl, b, q);
 		sym->parent = parent;
+		sym->lorev = vlo;
+		sym->hirev = vhi;
 		if (sym2 != NULL)
 			VTAILQ_INSERT_BEFORE(sym2, sym, list);
 		else
@@ -180,7 +188,7 @@ VCC_Symbol(struct vcc *tl, struct symbol *parent,
 	if (q == e)
 		return (sym);
 	assert(*q == '.');
-	return (VCC_Symbol(tl, sym, ++q, e, kind, create));
+	return (VCC_Symbol(tl, sym, ++q, e, kind, create, vlo, vhi));
 }
 
 const char XREF_NONE[] = "xref_none";
@@ -206,7 +214,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
 	}
 
 	sym = VCC_Symbol(tl, NULL, tl->t->b, tl->t->e, kind,
-	    e == SYMTAB_CREATE ? 1 : 0);
+	    e == SYMTAB_CREATE ? 1 : 0, tl->syntax, tl->syntax);
 	if (sym == NULL && e == SYMTAB_NOERR)
 		return (sym);
 	if (sym == NULL) {
@@ -267,11 +275,12 @@ VCC_SymbolGet(struct vcc *tl, vcc_kind_t kind, const char *e, const char *x)
 }
 
 struct symbol *
-VCC_MkSym(struct vcc *tl, const char *b, vcc_kind_t kind)
+VCC_MkSym(struct vcc *tl, const char *b, vcc_kind_t kind,
+    unsigned vlo, unsigned vhi)
 {
 	struct symbol *sym;
 
-	sym = VCC_Symbol(tl, NULL, b, NULL, kind, 1);
+	sym = VCC_Symbol(tl, NULL, b, NULL, kind, 1, vlo, vhi);
 	sym->noref = 1;
 	return (sym);
 }
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 92ae8df..8b5d1e6 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -94,7 +94,7 @@ vcc_ParseImport(struct vcc *tl)
 	}
 
 	bprintf(fn, "%.*s", PF(mod));
-	msym = VCC_MkSym(tl, fn, SYM_VMOD);
+	msym = VCC_MkSym(tl, fn, SYM_VMOD, VCL_LOW, VCL_HIGH);
 	ERRCHK(tl);
 	AN(msym);
 	msym->def_b = t1;
@@ -223,7 +223,7 @@ vcc_ParseImport(struct vcc *tl)
 		p = *spec;
 		if (!strcmp(p, "$OBJ")) {
 			p += strlen(p) + 1;
-			sym = VCC_MkSym(tl, p, SYM_OBJECT);
+			sym = VCC_MkSym(tl, p, SYM_OBJECT, VCL_LOW, VCL_HIGH);
 			XXXAN(sym);
 			sym->extra = p;
 			sym->vmod = msym->name;
@@ -242,7 +242,7 @@ vcc_ParseImport(struct vcc *tl)
 			    p, PF(mod));
 		} else if (!strcmp(p, "$FUNC")) {
 			p += strlen(p) + 1;
-			sym = VCC_MkSym(tl, p, SYM_FUNC);
+			sym = VCC_MkSym(tl, p, SYM_FUNC, VCL_LOW, VCL_HIGH);
 			ERRCHK(tl);
 			AN(sym);
 			sym->action = vcc_Act_Call;
@@ -331,7 +331,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
 	while (*p != '\0') {
 		p += strlen(s_obj);
 		bprintf(buf2, "%s%s", sy1->name, p);
-		sy3 = VCC_MkSym(tl, buf2, SYM_FUNC);
+		sy3 = VCC_MkSym(tl, buf2, SYM_FUNC, VCL_LOW, VCL_HIGH);
 		AN(sy3);
 		sy3->action = vcc_Act_Call;
 		sy3->eval = vcc_Eval_SymFunc;
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 74f7aad..31d3bc6 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -338,8 +338,9 @@ vcc_xreftable(struct vcc *tl, const struct symbol *sym)
 	CHECK_OBJ_NOTNULL(sym, SYMBOL_MAGIC);
 	CHECK_OBJ_NOTNULL(sym->kind, KIND_MAGIC);
 	CHECK_OBJ_NOTNULL(sym->type, TYPE_MAGIC);
-	Fc(tl, 0, " * %-7s ", sym->kind->name);
+	Fc(tl, 0, " * %-8s ", sym->kind->name);
 	Fc(tl, 0, " %-9s ", sym->type->name);
+	Fc(tl, 0, " %2u %2u ", sym->lorev, sym->hirev);
 	vcc_pnam(tl, sym);
 	if (sym->wildcard != NULL)
 		Fc(tl, 0, "*");


More information about the varnish-commit mailing list