[master] 3a214e62a vcc: Centralize the global prefix in the type
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Jun 1 13:50:07 UTC 2021
commit 3a214e62abc544768134e8ed7ff7dd2d50eeb48c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed May 12 19:32:58 2021 +0200
vcc: Centralize the global prefix in the type
This is as far declaring symbols goes, because we can still find
hard-coded prefixes in other places. Having them in the types could
actually help centralize them for good, but this is a minimal change
for the purpose of referencing global symbols before they are defined.
Refs #3555
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index 64dcc03ab..4ae7bb6a5 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -701,7 +701,7 @@ vcc_ParseAcl(struct vcc *tl)
vcc_ExpectVid(tl, "ACL");
ERRCHK(tl);
- sym = VCC_HandleSymbol(tl, ACL, ACL_SYMBOL_PREFIX);
+ sym = VCC_HandleSymbol(tl, ACL);
ERRCHK(tl);
AN(sym);
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 60fbdfa7b..70e805504 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -61,7 +61,7 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
if (sym->kind == SYM_SUB) {
vcc_AddCall(tl, t0, sym);
- VCC_GlobalSymbol(sym, SUB, "VGC_function");
+ VCC_GlobalSymbol(sym, SUB);
Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname);
SkipToken(tl, ';');
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index ac1c9e1f4..4fac23c20 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -316,7 +316,7 @@ vcc_ParseProbe(struct vcc *tl)
vcc_ParseProbeSpec(tl, NULL, &p);
tl->default_probe = p;
} else {
- sym = VCC_HandleSymbol(tl, PROBE, "vgc_probe");
+ sym = VCC_HandleSymbol(tl, PROBE);
ERRCHK(tl);
AN(sym);
vcc_ParseProbeSpec(tl, sym, NULL);
@@ -612,7 +612,7 @@ vcc_ParseBackend(struct vcc *tl)
dn = "vgc_backend_default";
tl->default_director = dn;
} else {
- sym = VCC_HandleSymbol(tl, BACKEND, "vgc_backend");
+ sym = VCC_HandleSymbol(tl, BACKEND);
ERRCHK(tl);
AN(sym);
dn = sym->rname;
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 517dab5a6..c01e01094 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -115,6 +115,7 @@ struct type {
const char *name;
const struct vcc_method *methods;
+ const char *global_pfx;
const char *tostring;
vcc_type_t multype;
int stringform;
@@ -354,8 +355,8 @@ sym_expr_t vcc_Eval_SymFunc;
sym_expr_t vcc_Eval_TypeMethod;
void vcc_Eval_Func(struct vcc *, const struct vjsn_val *,
const char *, struct symbol *);
-void VCC_GlobalSymbol(struct symbol *, vcc_type_t fmt, const char *pfx);
-struct symbol *VCC_HandleSymbol(struct vcc *, vcc_type_t , const char *);
+void VCC_GlobalSymbol(struct symbol *, vcc_type_t fmt);
+struct symbol *VCC_HandleSymbol(struct vcc *, vcc_type_t);
void VCC_SymName(struct vsb *, const struct symbol *);
/* vcc_obj.c */
@@ -476,5 +477,3 @@ const char *vcc_MarkPriv(struct vcc *, struct procprivhead *,
do { vcc__Expect(a, b, __LINE__); ERRCHK(a);} while (0)
#define SkipToken(a, b) \
do { vcc__Expect(a, b, __LINE__); ERRCHK(a); vcc_NextToken(a); } while (0)
-
-#define ACL_SYMBOL_PREFIX "vrt_acl"
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 7d8d82926..4a5728bf6 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -1117,7 +1117,7 @@ cmp_acl(struct vcc *tl, struct expr **e, const struct cmps *cp)
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_ACL, SYMTAB_CREATE, XREF_REF);
ERRCHK(tl);
AN(sym);
- VCC_GlobalSymbol(sym, ACL, ACL_SYMBOL_PREFIX);
+ VCC_GlobalSymbol(sym, ACL);
bprintf(buf, "%sVRT_acl_match(ctx, %s, \v1)", cp->emit, sym->rname);
*e = vcc_expr_edit(tl, BOOL, buf, *e, NULL);
}
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 432d5681b..cd9832569 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -256,7 +256,7 @@ vcc_ParseFunction(struct vcc *tl)
}
return;
}
- VCC_GlobalSymbol(sym, SUB, "VGC_function");
+ VCC_GlobalSymbol(sym, SUB);
p = vcc_NewProc(tl, sym);
p->name = t;
VSB_printf(p->cname, "%s", sym->lname);
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index e2cda32b3..8ace651a8 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -85,6 +85,7 @@ VCC_HandleKind(vcc_type_t fmt)
if (fmt == STEVEDORE) return (SYM_STEVEDORE);
if (fmt == SUB) return (SYM_SUB);
if (fmt == INSTANCE) return (SYM_INSTANCE);
+ AZ(fmt->global_pfx);
return (SYM_NONE);
}
@@ -460,16 +461,17 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, vcc_ns_t ns, vcc_kind_t kind)
}
void
-VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type, const char *pfx)
+VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type)
{
struct vsb *vsb;
CHECK_OBJ_NOTNULL(sym, SYMBOL_MAGIC);
- AN(pfx);
+ AN(type);
+ AN(type->global_pfx);
vsb = VSB_new_auto();
AN(vsb);
- VSB_printf(vsb, "%s_", pfx);
+ VSB_printf(vsb, "%s_", type->global_pfx);
VCC_PrintCName(vsb, sym->name, NULL);
AZ(VSB_finish(vsb));
sym->lname = strdup(VSB_data(vsb));
@@ -499,7 +501,7 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type, const char *pfx)
}
struct symbol *
-VCC_HandleSymbol(struct vcc *tl, vcc_type_t fmt, const char *pfx)
+VCC_HandleSymbol(struct vcc *tl, vcc_type_t fmt)
{
struct symbol *sym;
vcc_kind_t kind;
@@ -541,7 +543,7 @@ VCC_HandleSymbol(struct vcc *tl, vcc_type_t fmt, const char *pfx)
return (NULL);
AN(sym);
AZ(sym->ndef);
- VCC_GlobalSymbol(sym, fmt, pfx);
+ VCC_GlobalSymbol(sym, fmt);
sym->ndef = 1;
if (sym->def_b == NULL)
sym->def_b = t;
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index fc3c01cd6..7557e520e 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -57,6 +57,7 @@ struct vcc_method {
const struct type ACL[1] = {{
.magic = TYPE_MAGIC,
.name = "ACL",
+ .global_pfx = "vrt_acl",
.tostring = "((\v1)->name)",
}};
@@ -70,6 +71,7 @@ const struct type BACKEND[1] = {{
.magic = TYPE_MAGIC,
.name = "BACKEND",
.methods = backend_methods,
+ .global_pfx = "vgc_backend",
.tostring = "VRT_BACKEND_string(\v1)",
}};
@@ -124,6 +126,7 @@ const struct type HTTP[1] = {{
const struct type INSTANCE[1] = {{
.magic = TYPE_MAGIC,
.name = "INSTANCE",
+ .global_pfx = "vo",
}};
const struct type INT[1] = {{
@@ -142,6 +145,7 @@ const struct type IP[1] = {{
const struct type PROBE[1] = {{
.magic = TYPE_MAGIC,
.name = "PROBE",
+ .global_pfx = "vgc_probe",
}};
const struct type REAL[1] = {{
@@ -207,6 +211,7 @@ const struct type STRING_LIST[1] = {{
const struct type SUB[1] = {{
.magic = TYPE_MAGIC,
.name = "SUB",
+ .global_pfx = "VGC_function",
}};
const struct type TIME[1] = {{
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 361357b32..8c676096f 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -474,7 +474,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
ExpectErr(tl, ID);
vcc_ExpectVid(tl, "VCL object");
ERRCHK(tl);
- isym = VCC_HandleSymbol(tl, INSTANCE, "vo");
+ isym = VCC_HandleSymbol(tl, INSTANCE);
ERRCHK(tl);
AN(isym);
isym->noref = 1;
More information about the varnish-commit
mailing list