[master] 3b6b1124f vcc: New SYM_ALIAS kind for deprecated symbols

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Feb 22 15:12:05 UTC 2022


commit 3b6b1124fcae042b81aca6c9597ae53a240e1732
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Jan 7 09:42:19 2022 +0100

    vcc: New SYM_ALIAS kind for deprecated symbols
    
    Aliases are a new strictly internal kind of symbols with zero runtime
    cost. They resolve implicitly to the destination symbol, even when they
    are created.
    
    This should facilitate renaming things in the future. One thing we
    could do is to have libvcc warn about deprecated aliases (subject to
    a new vcc_err_alias parameter too) to make this visible not just in
    the documentation.

diff --git a/include/tbl/symbol_kind.h b/include/tbl/symbol_kind.h
index 40dfbfdd8..c1f29fa98 100644
--- a/include/tbl/symbol_kind.h
+++ b/include/tbl/symbol_kind.h
@@ -33,6 +33,7 @@
 
 VCC_KIND(NONE,		none)
 VCC_KIND(RESERVED,	reserved)
+VCC_KIND(ALIAS,		alias)
 VCC_KIND(ACL,		acl)
 VCC_KIND(ACTION,	action)
 VCC_KIND(BACKEND,	backend)
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 76b2cab73..1663ba92d 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -384,6 +384,7 @@ vcc_kind_t VCC_HandleKind(vcc_type_t fmt);
 void VCC_PrintCName(struct vsb *vsb, const char *b, const char *e);
 struct symbol *VCC_MkSym(struct vcc *tl, const char *b, vcc_ns_t, vcc_kind_t,
     int, int);
+struct symbol *VCC_MkSymAlias(struct vcc *tl, const char *, const char *);
 
 struct symxref { const char *name; };
 extern const struct symxref XREF_NONE[1];
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 34736072b..1478509ed 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -320,6 +320,14 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind,
 			break;
 		tn = tn1;
 	}
+	if (sym != NULL && sym->kind == SYM_ALIAS) {
+		assert(ns == SYM_MAIN);
+		st = vcc_symtab_str(tl->syms[ns->id], sym->eval_priv, NULL, ID);
+		AN(st);
+		st2 = st;
+		sym = vcc_sym_in_tab(tl, st, SYM_NONE, sym->lorev, sym->hirev);
+		AN(sym);
+	}
 	if (sym != NULL && sym->kind == SYM_VMOD && e->partial)
 		e = SYMTAB_EXISTING;
 	if (sym != NULL && e->partial) {
@@ -450,6 +458,29 @@ VCC_MkSym(struct vcc *tl, const char *b, vcc_ns_t ns, vcc_kind_t kind,
 	return (sym);
 }
 
+struct symbol *
+VCC_MkSymAlias(struct vcc *tl, const char *alias, const char *name)
+{
+	struct symbol *sym_alias, *sym;
+	struct symtab *st;
+
+	AN(tl);
+	AN(alias);
+	AN(name);
+
+	st = vcc_symtab_str(tl->syms[SYM_MAIN->id], name, NULL, ID);
+	AN(st);
+	sym = vcc_sym_in_tab(tl, st, SYM_NONE, VCL_LOW, VCL_HIGH);
+	AN(sym);
+	assert(sym->kind != SYM_ALIAS);
+	sym_alias = VCC_MkSym(tl, alias, SYM_MAIN, SYM_ALIAS, sym->lorev,
+	    sym->hirev);
+	AN(sym_alias);
+	sym_alias->eval_priv = strdup(name);
+	AN(sym_alias->eval_priv);
+	return (sym);
+}
+
 static void
 vcc_walksymbols(struct vcc *tl, const struct symtab *root,
     symwalk_f *func, vcc_kind_t kind)


More information about the varnish-commit mailing list