Commit 874841d8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Clean up and centralize specstring handling

parent 03ca4548
...@@ -139,10 +139,7 @@ struct symbol { ...@@ -139,10 +139,7 @@ struct symbol {
struct proc *proc; struct proc *proc;
unsigned nref, ndef; unsigned nref, ndef;
/* SYM_FUNC */
const char *cfunc;
const char *extra; const char *extra;
const char *args;
/* SYM_VAR */ /* SYM_VAR */
const char *rname; const char *rname;
...@@ -283,8 +280,8 @@ void vcc_Expr_Init(struct vcc *tl); ...@@ -283,8 +280,8 @@ void vcc_Expr_Init(struct vcc *tl);
sym_expr_t vcc_Eval_Var; sym_expr_t vcc_Eval_Var;
sym_expr_t vcc_Eval_Handle; sym_expr_t vcc_Eval_Handle;
sym_expr_t vcc_Eval_SymFunc; sym_expr_t vcc_Eval_SymFunc;
void vcc_Eval_Func(struct vcc *tl, const char *cfunc, const char *extra, void vcc_Eval_Func(struct vcc *tl, const char *spec,
const char *name, const char *args, const char *vmod); const char *extra, const struct symbol *sym);
enum symkind VCC_HandleKind(vcc_type_t fmt); enum symkind VCC_HandleKind(vcc_type_t fmt);
struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *, struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *,
vcc_type_t fmt, const char *str, ...); vcc_type_t fmt, const char *str, ...);
......
...@@ -581,33 +581,35 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa) ...@@ -581,33 +581,35 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa)
} }
static void static void
vcc_func(struct vcc *tl, struct expr **e, const char *cfunc, vcc_func(struct vcc *tl, struct expr **e, const char *spec,
const char *extra, const char *name, const char *args, const char *vmod) const char *extra, const struct symbol *sym)
{ {
vcc_type_t rfmt;
const char *args;
const char *cfunc;
const char *p; const char *p;
struct expr *e1; struct expr *e1;
struct func_arg *fa, *fa2; struct func_arg *fa, *fa2;
vcc_type_t rfmt;
VTAILQ_HEAD(,func_arg) head; VTAILQ_HEAD(,func_arg) head;
struct token *t1; struct token *t1;
AN(cfunc); rfmt = VCC_Type(spec);
AN(args); spec += strlen(spec) + 1;
AN(name); cfunc = spec;
spec += strlen(spec) + 1;
args = spec;
SkipToken(tl, '('); SkipToken(tl, '(');
p = args; p = args;
if (extra == NULL) if (extra == NULL)
extra = ""; extra = "";
rfmt = VCC_Type(p);
AN(rfmt); AN(rfmt);
p += strlen(p) + 1;
VTAILQ_INIT(&head); VTAILQ_INIT(&head);
while (*p != '\0') { while (*p != '\0') {
fa = calloc(sizeof *fa, 1); fa = calloc(sizeof *fa, 1);
AN(fa); AN(fa);
VTAILQ_INSERT_TAIL(&head, fa, list); VTAILQ_INSERT_TAIL(&head, fa, list);
if (!memcmp(p, "PRIV_", 5)) { 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 = ""; fa->name = "";
p += strlen(p) + 1; p += strlen(p) + 1;
continue; continue;
...@@ -703,14 +705,14 @@ vcc_func(struct vcc *tl, struct expr **e, const char *cfunc, ...@@ -703,14 +705,14 @@ vcc_func(struct vcc *tl, struct expr **e, const char *cfunc,
*/ */
void void
vcc_Eval_Func(struct vcc *tl, const char *cfunc, vcc_Eval_Func(struct vcc *tl, const char *spec,
const char *extra, const char *name, const char *args, const char *vmod) const char *extra, const struct symbol *sym)
{ {
struct expr *e = NULL; struct expr *e = NULL;
struct token *t1; struct token *t1;
t1 = tl->t; t1 = tl->t;
vcc_func(tl, &e, cfunc, extra, name, args, vmod); vcc_func(tl, &e, spec, extra, sym);
if (!tl->err) { if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e); vcc_expr_fmt(tl->fb, tl->indent, e);
VSB_cat(tl->fb, ";\n"); VSB_cat(tl->fb, ";\n");
...@@ -727,23 +729,14 @@ void __match_proto__(sym_expr_t) ...@@ -727,23 +729,14 @@ void __match_proto__(sym_expr_t)
vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym, vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym,
vcc_type_t fmt) vcc_type_t fmt)
{ {
const char *cfunc;
const char *args;
const char *p;
(void)fmt; (void)fmt;
assert(sym->kind == SYM_FUNC); assert(sym->kind == SYM_FUNC);
/* XXX */
AN(sym->eval_priv); 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); 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);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -222,7 +222,7 @@ vcc_ParseImport(struct vcc *tl) ...@@ -222,7 +222,7 @@ vcc_ParseImport(struct vcc *tl)
p += strlen(p) + 1; p += strlen(p) + 1;
sym = VCC_Symbol(tl, NULL, p, NULL, SYM_OBJECT, 1); sym = VCC_Symbol(tl, NULL, p, NULL, SYM_OBJECT, 1);
XXXAN(sym); XXXAN(sym);
sym->args = p; sym->extra = p;
sym->vmod = msym->name; sym->vmod = msym->name;
} else if (!strcmp(p, "$EVENT")) { } else if (!strcmp(p, "$EVENT")) {
p += strlen(p) + 1; p += strlen(p) + 1;
...@@ -246,10 +246,8 @@ vcc_ParseImport(struct vcc *tl) ...@@ -246,10 +246,8 @@ vcc_ParseImport(struct vcc *tl)
sym->eval = vcc_Eval_SymFunc; sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1; p += strlen(p) + 1;
sym->eval_priv = p; sym->eval_priv = p;
p += strlen(p) + 1;
sym->fmt = VCC_Type(p); sym->fmt = VCC_Type(p);
AN(sym->fmt); AN(sym->fmt);
p += strlen(p) + 1;
} else { } else {
VSB_printf(tl->sb, "Internal spec error (%s)\n", p); VSB_printf(tl->sb, "Internal spec error (%s)\n", p);
vcc_ErrWhere(tl, mod); vcc_ErrWhere(tl, mod);
...@@ -269,7 +267,7 @@ vcc_ParseNew(struct vcc *tl) ...@@ -269,7 +267,7 @@ vcc_ParseNew(struct vcc *tl)
{ {
struct symbol *sy1, *sy2, *sy3; struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp; struct inifin *ifp;
const char *p, *s_obj, *s_init, *s_struct, *s_fini; const char *p, *s_obj;
char buf1[128]; char buf1[128];
char buf2[128]; char buf2[128];
...@@ -297,41 +295,34 @@ vcc_ParseNew(struct vcc *tl) ...@@ -297,41 +295,34 @@ vcc_ParseNew(struct vcc *tl)
vcc_ErrWhere(tl, tl->t); vcc_ErrWhere(tl, tl->t);
return; return;
} }
XXXAN(sy2); vcc_NextToken(tl);
/*lint -save -e448 */ p = sy2->extra;
/* Split the first three args */
p = sy2->args;
s_obj = p; s_obj = p;
p += strlen(p) + 1; p += strlen(p) + 1;
s_struct = p; Fh(tl, 0, "static %s *vo_%s;\n\n", p, sy1->name);
p += strlen(p) + 1; 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') while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++; p++;
p += 3; 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') while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++; p++;
p += 3; p += 3;
Fh(tl, 0, "static %s *vo_%s;\n\n", s_struct, sy1->name); /* Instantiate symbols for the methods */
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, ';');
bprintf(buf1, ", vo_%s", sy1->name); bprintf(buf1, ", vo_%s", sy1->name);
/* Split the methods from the args */
while (*p != '\0') { while (*p != '\0') {
p += strlen(s_obj); p += strlen(s_obj);
bprintf(buf2, "%s%s", sy1->name, p); bprintf(buf2, "%s%s", sy1->name, p);
...@@ -340,7 +331,6 @@ vcc_ParseNew(struct vcc *tl) ...@@ -340,7 +331,6 @@ vcc_ParseNew(struct vcc *tl)
sy3->eval = vcc_Eval_SymFunc; sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1; p += strlen(p) + 1;
sy3->eval_priv = p; sy3->eval_priv = p;
p += strlen(p) + 1;
sy3->fmt = VCC_Type(p); sy3->fmt = VCC_Type(p);
sy3->extra = TlDup(tl, buf1); sy3->extra = TlDup(tl, buf1);
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0') while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
...@@ -348,5 +338,4 @@ vcc_ParseNew(struct vcc *tl) ...@@ -348,5 +338,4 @@ vcc_ParseNew(struct vcc *tl)
p += 3; p += 3;
} }
sy1->def_e = tl->t; sy1->def_e = tl->t;
/*lint -restore */
} }
...@@ -324,17 +324,16 @@ class prototype(object): ...@@ -324,17 +324,16 @@ class prototype(object):
l.append(i.ct) l.append(i.ct)
return ", ".join(l) return ", ".join(l)
def specstr(self, fo, p): def specstr(self, fo, cfunc, p):
p = indent(p, 4)
if self.retval == None: if self.retval == None:
fo.write(p + '"VOID\\0"\n') fo.write(p + '"VOID\\0"\n')
else: else:
self.retval.specstr(fo, p) self.retval.specstr(fo, p)
fo.write(p + '"' + cfunc + '\\0"\n')
p = indent(p, 4)
if self.args != None: if self.args != None:
p = indent(p, 4)
for i in self.args: for i in self.args:
i.specstr(fo, p) i.specstr(fo, p)
p = indent(p, -4)
fo.write(p + '"\\0"\n') fo.write(p + '"\\0"\n')
####################################################################### #######################################################################
...@@ -472,7 +471,7 @@ class s_event(stanza): ...@@ -472,7 +471,7 @@ class s_event(stanza):
fo.write("\t%s,\n" % self.event_func) fo.write("\t%s,\n" % self.event_func)
def specstr(self, fo): 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) self.vcc.modname)
class s_function(stanza): class s_function(stanza):
...@@ -502,13 +501,11 @@ class s_function(stanza): ...@@ -502,13 +501,11 @@ class s_function(stanza):
fo.write("\tvmod_" + self.proto.cname() + ",\n") fo.write("\tvmod_" + self.proto.cname() + ",\n")
def specstr(self, fo): 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)) (self.vcc.modname, self.proto.name))
fo.write('\t\t"Vmod_%s_Func.%s\\0"\n' % self.proto.specstr(fo, 'Vmod_%s_Func.%s' %
(self.vcc.modname, self.proto.cname())) (self.vcc.modname, self.proto.cname()), "\t ")
self.proto.specstr(fo, "\t\t") fo.write('\t "\\0",\n\n')
fo.write('\t"\\0",\n\n')
class s_object(stanza): class s_object(stanza):
def parse(self): def parse(self):
...@@ -589,28 +586,27 @@ class s_object(stanza): ...@@ -589,28 +586,27 @@ class s_object(stanza):
def specstr(self, fo): 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)) (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)) (self.vcc.modname, self.proto.name))
fo.write("\n") fo.write("\n")
fo.write('\t\t"Vmod_%s_Func.%s__init\\0"\n' % self.proto.specstr(fo, 'Vmod_%s_Func.%s__init' %
(self.vcc.modname, self.proto.name)) (self.vcc.modname, self.proto.name), '\t ')
self.proto.specstr(fo, '\t\t') fo.write('\t "\\0"\n\n')
fo.write('\t\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)) (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') fo.write('\t "\\0"\n\n')
fo.write('\t\t"\\0"\n\n')
for i in self.methods: for i in self.methods:
i.specstr(fo) i.specstr(fo)
fo.write('\t"\\0",\n\n') fo.write('\t "\\0",\n\n')
def dump(self): def dump(self):
super(s_object, self).dump() super(s_object, self).dump()
...@@ -632,11 +628,10 @@ class s_method(stanza): ...@@ -632,11 +628,10 @@ class s_method(stanza):
fo.write('\t' + "vmod_" + self.proto.cname() + ",\n") fo.write('\t' + "vmod_" + self.proto.cname() + ",\n")
def specstr(self, fo): 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)) (self.vcc.modname, self.proto.name))
fo.write('\t\t "Vmod_%s_Func.%s\\0"\n' % self.proto.specstr(fo, 'Vmod_%s_Func.%s' %
(self.vcc.modname, self.proto.cname())) (self.vcc.modname, self.proto.cname()), '\t\t')
self.proto.specstr(fo, '\t\t ')
fo.write('\t\t"\\0"\n\n') fo.write('\t\t"\\0"\n\n')
####################################################################### #######################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment