[master] 874841d Clean up and centralize specstring handling
Poul-Henning Kamp
phk at FreeBSD.org
Wed Jun 8 20:59:06 CEST 2016
commit 874841d86d348795004cad9ff88b26b8b6694ce7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jun 8 18:57:43 2016 +0000
Clean up and centralize specstring handling
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 84ec643..b6c8f37 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -139,10 +139,7 @@ struct symbol {
struct proc *proc;
unsigned nref, ndef;
- /* SYM_FUNC */
- const char *cfunc;
const char *extra;
- const char *args;
/* SYM_VAR */
const char *rname;
@@ -283,8 +280,8 @@ void vcc_Expr_Init(struct vcc *tl);
sym_expr_t vcc_Eval_Var;
sym_expr_t vcc_Eval_Handle;
sym_expr_t vcc_Eval_SymFunc;
-void vcc_Eval_Func(struct vcc *tl, const char *cfunc, const char *extra,
- const char *name, const char *args, const char *vmod);
+void vcc_Eval_Func(struct vcc *tl, const char *spec,
+ const char *extra, const struct symbol *sym);
enum symkind VCC_HandleKind(vcc_type_t fmt);
struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *,
vcc_type_t fmt, const char *str, ...);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index ff30a74..f5b7391 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -581,33 +581,35 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa)
}
static void
-vcc_func(struct vcc *tl, struct expr **e, const char *cfunc,
- const char *extra, const char *name, const char *args, const char *vmod)
+vcc_func(struct vcc *tl, struct expr **e, const char *spec,
+ const char *extra, const struct symbol *sym)
{
+ vcc_type_t rfmt;
+ const char *args;
+ const char *cfunc;
const char *p;
struct expr *e1;
struct func_arg *fa, *fa2;
- vcc_type_t rfmt;
VTAILQ_HEAD(,func_arg) head;
struct token *t1;
- AN(cfunc);
- AN(args);
- AN(name);
+ rfmt = VCC_Type(spec);
+ spec += strlen(spec) + 1;
+ cfunc = spec;
+ spec += strlen(spec) + 1;
+ args = spec;
SkipToken(tl, '(');
p = args;
if (extra == NULL)
extra = "";
- rfmt = VCC_Type(p);
AN(rfmt);
- p += strlen(p) + 1;
VTAILQ_INIT(&head);
while (*p != '\0') {
fa = calloc(sizeof *fa, 1);
AN(fa);
VTAILQ_INSERT_TAIL(&head, fa, list);
if (!memcmp(p, "PRIV_", 5)) {
- fa->result = vcc_priv_arg(tl, p, name, vmod);
+ fa->result = vcc_priv_arg(tl, p, sym->name, sym->vmod);
fa->name = "";
p += strlen(p) + 1;
continue;
@@ -703,14 +705,14 @@ vcc_func(struct vcc *tl, struct expr **e, const char *cfunc,
*/
void
-vcc_Eval_Func(struct vcc *tl, const char *cfunc,
- const char *extra, const char *name, const char *args, const char *vmod)
+vcc_Eval_Func(struct vcc *tl, const char *spec,
+ const char *extra, const struct symbol *sym)
{
struct expr *e = NULL;
struct token *t1;
t1 = tl->t;
- vcc_func(tl, &e, cfunc, extra, name, args, vmod);
+ vcc_func(tl, &e, spec, extra, sym);
if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e);
VSB_cat(tl->fb, ";\n");
@@ -727,23 +729,14 @@ void __match_proto__(sym_expr_t)
vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym,
vcc_type_t fmt)
{
- const char *cfunc;
- const char *args;
- const char *p;
(void)fmt;
assert(sym->kind == SYM_FUNC);
- /* XXX */
AN(sym->eval_priv);
- AZ(sym->args);
- AZ(sym->cfunc);
- p = sym->eval_priv;
- cfunc = p;
- p += strlen(p) + 1;
- args = p;
- AN(sym->name);
+
SkipToken(tl, ID);
- vcc_func(tl, e, cfunc, sym->extra, sym->name, args, sym->vmod);
+ assert(sym->fmt == VCC_Type(sym->eval_priv));
+ vcc_func(tl, e, sym->eval_priv, sym->extra, sym);
}
/*--------------------------------------------------------------------
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 2e6f128..cf7fa91 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -222,7 +222,7 @@ vcc_ParseImport(struct vcc *tl)
p += strlen(p) + 1;
sym = VCC_Symbol(tl, NULL, p, NULL, SYM_OBJECT, 1);
XXXAN(sym);
- sym->args = p;
+ sym->extra = p;
sym->vmod = msym->name;
} else if (!strcmp(p, "$EVENT")) {
p += strlen(p) + 1;
@@ -246,10 +246,8 @@ vcc_ParseImport(struct vcc *tl)
sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sym->eval_priv = p;
- p += strlen(p) + 1;
sym->fmt = VCC_Type(p);
AN(sym->fmt);
- p += strlen(p) + 1;
} else {
VSB_printf(tl->sb, "Internal spec error (%s)\n", p);
vcc_ErrWhere(tl, mod);
@@ -269,7 +267,7 @@ vcc_ParseNew(struct vcc *tl)
{
struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp;
- const char *p, *s_obj, *s_init, *s_struct, *s_fini;
+ const char *p, *s_obj;
char buf1[128];
char buf2[128];
@@ -297,41 +295,34 @@ vcc_ParseNew(struct vcc *tl)
vcc_ErrWhere(tl, tl->t);
return;
}
- XXXAN(sy2);
+ vcc_NextToken(tl);
- /*lint -save -e448 */
- /* Split the first three args */
- p = sy2->args;
+ p = sy2->extra;
s_obj = p;
p += strlen(p) + 1;
- s_struct = p;
+ Fh(tl, 0, "static %s *vo_%s;\n\n", p, sy1->name);
p += strlen(p) + 1;
- s_init = p;
+ bprintf(buf1, ", &vo_%s, \"%s\"", sy1->name, sy1->name);
+ vcc_Eval_Func(tl, p, buf1, sy2);
+ ExpectErr(tl, ';');
+
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
- s_fini = p;
+ ifp = New_IniFin(tl);
+ p += strlen(p) + 1;
+ VSB_printf(ifp->fin, "\t\t%s(&vo_%s);", p, sy1->name);
+
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
- Fh(tl, 0, "static %s *vo_%s;\n\n", s_struct, sy1->name);
-
- vcc_NextToken(tl);
-
- bprintf(buf1, ", &vo_%s, \"%s\"", sy1->name, sy1->name);
- vcc_Eval_Func(tl, s_init, buf1, sy2->name, s_init + strlen(s_init) + 1,
- sy2->vmod);
- ifp = New_IniFin(tl);
- VSB_printf(ifp->fin, "\t\t%s(&vo_%s);", s_fini, sy1->name);
- ExpectErr(tl, ';');
-
+ /* Instantiate symbols for the methods */
bprintf(buf1, ", vo_%s", sy1->name);
- /* Split the methods from the args */
while (*p != '\0') {
p += strlen(s_obj);
bprintf(buf2, "%s%s", sy1->name, p);
@@ -340,7 +331,6 @@ vcc_ParseNew(struct vcc *tl)
sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sy3->eval_priv = p;
- p += strlen(p) + 1;
sy3->fmt = VCC_Type(p);
sy3->extra = TlDup(tl, buf1);
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
@@ -348,5 +338,4 @@ vcc_ParseNew(struct vcc *tl)
p += 3;
}
sy1->def_e = tl->t;
- /*lint -restore */
}
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 9525f2d..9228e82 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -324,17 +324,16 @@ class prototype(object):
l.append(i.ct)
return ", ".join(l)
- def specstr(self, fo, p):
- p = indent(p, 4)
+ def specstr(self, fo, cfunc, p):
if self.retval == None:
fo.write(p + '"VOID\\0"\n')
else:
self.retval.specstr(fo, p)
+ fo.write(p + '"' + cfunc + '\\0"\n')
+ p = indent(p, 4)
if self.args != None:
- p = indent(p, 4)
for i in self.args:
i.specstr(fo, p)
- p = indent(p, -4)
fo.write(p + '"\\0"\n')
#######################################################################
@@ -472,7 +471,7 @@ class s_event(stanza):
fo.write("\t%s,\n" % self.event_func)
def specstr(self, fo):
- fo.write('\t"$EVENT\\0"\n\t "Vmod_%s_Func._event",\n' %
+ fo.write('\t"$EVENT\\0"\n\t "Vmod_%s_Func._event",\n\n' %
self.vcc.modname)
class s_function(stanza):
@@ -502,13 +501,11 @@ class s_function(stanza):
fo.write("\tvmod_" + self.proto.cname() + ",\n")
def specstr(self, fo):
- fo.write('\t"$FUNC\\0"\n\t "%s.%s\\0"\n' %
+ fo.write('\t"$FUNC\\0"\t"%s.%s\\0"\n\n' %
(self.vcc.modname, self.proto.name))
- fo.write('\t\t"Vmod_%s_Func.%s\\0"\n' %
- (self.vcc.modname, self.proto.cname()))
- self.proto.specstr(fo, "\t\t")
-
- fo.write('\t"\\0",\n\n')
+ self.proto.specstr(fo, 'Vmod_%s_Func.%s' %
+ (self.vcc.modname, self.proto.cname()), "\t ")
+ fo.write('\t "\\0",\n\n')
class s_object(stanza):
def parse(self):
@@ -589,28 +586,27 @@ class s_object(stanza):
def specstr(self, fo):
- fo.write('\t"$OBJ\\0"\n\t "%s.%s\\0"\n' %
+ fo.write('\t"$OBJ\\0"\t"%s.%s\\0"\n\n' %
(self.vcc.modname, self.proto.name))
- fo.write('\t\t"struct vmod_%s_%s\\0"\n' %
+ fo.write('\t "struct vmod_%s_%s\\0"\n' %
(self.vcc.modname, self.proto.name))
fo.write("\n")
- fo.write('\t\t"Vmod_%s_Func.%s__init\\0"\n' %
- (self.vcc.modname, self.proto.name))
- self.proto.specstr(fo, '\t\t')
- fo.write('\t\t"\\0"\n\n')
+ self.proto.specstr(fo, 'Vmod_%s_Func.%s__init' %
+ (self.vcc.modname, self.proto.name), '\t ')
+ fo.write('\t "\\0"\n\n')
- fo.write('\t\t"Vmod_%s_Func.%s__fini\\0"\n' %
+ fo.write('\t "VOID\\0"\n')
+ fo.write('\t "Vmod_%s_Func.%s__fini\\0"\n' %
(self.vcc.modname, self.proto.name))
- fo.write('\t\t "VOID\\0"\n')
- fo.write('\t\t "\\0"\n')
- fo.write('\t\t"\\0"\n\n')
+ fo.write('\t\t"\\0"\n')
+ fo.write('\t "\\0"\n\n')
for i in self.methods:
i.specstr(fo)
- fo.write('\t"\\0",\n\n')
+ fo.write('\t "\\0",\n\n')
def dump(self):
super(s_object, self).dump()
@@ -632,11 +628,10 @@ class s_method(stanza):
fo.write('\t' + "vmod_" + self.proto.cname() + ",\n")
def specstr(self, fo):
- fo.write('\t\t"%s.%s\\0"\n' %
+ fo.write('\t "%s.%s\\0"\n' %
(self.vcc.modname, self.proto.name))
- fo.write('\t\t "Vmod_%s_Func.%s\\0"\n' %
- (self.vcc.modname, self.proto.cname()))
- self.proto.specstr(fo, '\t\t ')
+ self.proto.specstr(fo, 'Vmod_%s_Func.%s' %
+ (self.vcc.modname, self.proto.cname()), '\t\t')
fo.write('\t\t"\\0"\n\n')
#######################################################################
More information about the varnish-commit
mailing list