[master] 77d5d0f08 Align symbol table columns in the generated C code
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Dec 11 12:15:08 UTC 2019
commit 77d5d0f08af9a53f8171d915115f70dd96ba4543
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Dec 2 11:46:14 2019 +0100
Align symbol table columns in the generated C code
At the end of the VGC we output the contents of the symbol table inside
a C comment. It might look like this:
/*
* Symbol Table
*
* reserved VOID 41 41 acl
* reserved VOID 41 41 backend
* action VOID 40 41 ban
* var HTTP 0 99 bereq
* var BACKEND 0 99 bereq.backend
* [...]
*/
All columns are currently aligned because we know all the native VCL
types and only the last column with the symbol names has unpredictable
and arbitrary entries lengths.
However, considering the following snippet:
new fb = directors.fallback();
The involved symbols will look like:
object VOID 41 41 directors.fallback
instance INSTANCE 41 41 fb
func VOID 40 41 fb.add_backend
func BACKEND 40 41 fb.backend
func VOID 40 41 fb.remove_backend
In the future VMOD objects will likely grow their own types and for the
same snippet we may have this instead:
object directors.fallback 41 41 directors.fallback
method VOID 40 41 directors.fallback.add_backend
method BACKEND 40 41 directors.fallback.backend
method VOID 40 41 directors.fallback.remove_backend
instance directors.fallback 41 41 fb
This change was initially submitted as part of #3147, but was considered
trivial and fast-track-able by PHK.
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index fbabf77ce..271f787fd 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -322,6 +322,21 @@ vcc_CheckUses(struct vcc *tl)
/*---------------------------------------------------------------------*/
+static int sym_type_len = 0;
+
+static void v_matchproto_(symwalk_f)
+vcc_xreftable_len(struct vcc *tl, const struct symbol *sym)
+{
+ int len;
+
+ (void)tl;
+ CHECK_OBJ_NOTNULL(sym, SYMBOL_MAGIC);
+ CHECK_OBJ_NOTNULL(sym->type, TYPE_MAGIC);
+ len = strlen(sym->type->name);
+ if (sym_type_len < len)
+ sym_type_len = len;
+}
+
static void v_matchproto_(symwalk_f)
vcc_xreftable(struct vcc *tl, const struct symbol *sym)
{
@@ -330,7 +345,7 @@ vcc_xreftable(struct vcc *tl, const struct symbol *sym)
CHECK_OBJ_NOTNULL(sym->kind, KIND_MAGIC);
CHECK_OBJ_NOTNULL(sym->type, TYPE_MAGIC);
Fc(tl, 0, " * %-8s ", sym->kind->name);
- Fc(tl, 0, " %-9s ", sym->type->name);
+ Fc(tl, 0, " %-*s ", sym_type_len, sym->type->name);
Fc(tl, 0, " %2u %2u ", sym->lorev, sym->hirev);
VCC_SymName(tl->fc, sym);
if (sym->wildcard != NULL)
@@ -343,6 +358,7 @@ VCC_XrefTable(struct vcc *tl)
{
Fc(tl, 0, "\n/*\n * Symbol Table\n *\n");
+ VCC_WalkSymbols(tl, vcc_xreftable_len, SYM_NONE);
VCC_WalkSymbols(tl, vcc_xreftable, SYM_NONE);
Fc(tl, 0, "*/\n\n");
}
More information about the varnish-commit
mailing list