Commit 03ca4548 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Moving parsing of "new" to vcc_vmod.c where it belongs.

Minor simplifications.
parent ce467f20
......@@ -145,96 +145,6 @@ parse_unset(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
parse_new(struct vcc *tl)
{
struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp;
const char *p, *s_obj, *s_init, *s_struct, *s_fini;
char buf1[128];
char buf2[128];
vcc_NextToken(tl);
ExpectErr(tl, ID);
vcc_ExpectCid(tl, "VCL object");
ERRCHK(tl);
sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "XXX");
ERRCHK(tl);
/* We allow implicit use of VMOD objects: Pretend it's ref'ed */
sy1->nref++;
vcc_NextToken(tl);
ExpectErr(tl, '=');
vcc_NextToken(tl);
ExpectErr(tl, ID);
sy2 = VCC_SymbolTok(tl, NULL, tl->t, SYM_OBJECT, 0);
if (sy2 == NULL) {
VSB_printf(tl->sb, "Symbol not found: ");
vcc_ErrToken(tl, tl->t);
VSB_printf(tl->sb, " at ");
vcc_ErrWhere(tl, tl->t);
return;
}
XXXAN(sy2);
/*lint -save -e448 */
/* Split the first three args */
p = sy2->args;
s_obj = p;
p += strlen(p) + 1;
s_struct = p;
p += strlen(p) + 1;
s_init = p;
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
s_fini = p;
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, ';');
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);
sy3 = VCC_Symbol(tl, NULL, buf2, NULL, SYM_FUNC, 1);
AN(sy3);
sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sy3->cfunc = p;
p += strlen(p) + 1;
sy3->args = p;
sy3->extra = TlDup(tl, buf1);
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
}
sy1->def_e = tl->t;
/*lint -restore */
}
/*--------------------------------------------------------------------*/
static void
parse_ban(struct vcc *tl)
{
......@@ -375,7 +285,7 @@ static struct action_table {
{ "ban", parse_ban },
{ "call", parse_call },
{ "hash_data", parse_hash_data, VCL_MET_HASH },
{ "new", parse_new, VCL_MET_INIT},
{ "new", vcc_ParseNew, VCL_MET_INIT},
{ "return", parse_return },
{ "set", parse_set },
{ "synthetic", parse_synthetic,
......
......@@ -133,7 +133,7 @@ struct symbol {
vcc_type_t fmt;
sym_expr_t *eval;
void *eval_priv;
const void *eval_priv;
/* xref.c */
struct proc *proc;
......@@ -342,6 +342,7 @@ const struct symbol *vcc_FindVar(struct vcc *tl, const struct token *t,
/* vcc_vmod.c */
void vcc_ParseImport(struct vcc *tl);
void vcc_ParseNew(struct vcc *tl);
/* vcc_xref.c */
int vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type);
......
......@@ -727,16 +727,23 @@ 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->cfunc);
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);
AN(sym->args);
SkipToken(tl, ID);
vcc_func(tl, e, sym->cfunc, sym->extra, sym->name, sym->args,
sym->vmod);
vcc_func(tl, e, cfunc, sym->extra, sym->name, args, sym->vmod);
}
/*--------------------------------------------------------------------
......@@ -777,10 +784,6 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
kind = VCC_HandleKind(fmt);
if (kind != SYM_NONE)
sym = VCC_SymbolTok(tl, NULL, tl->t, kind, 0);
if (sym == NULL)
sym = VCC_SymbolTok(tl, NULL, tl->t, SYM_VAR, 0);
if (sym == NULL)
sym = VCC_SymbolTok(tl, NULL, tl->t, SYM_FUNC, 0);
if (sym == NULL)
sym = VCC_SymbolTok(tl, NULL, tl->t, SYM_NONE, 0);
if (sym == NULL || sym->eval == NULL) {
......
......@@ -245,9 +245,8 @@ vcc_ParseImport(struct vcc *tl)
sym->vmod = msym->name;
sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sym->cfunc = p;
sym->eval_priv = p;
p += strlen(p) + 1;
sym->args = p;
sym->fmt = VCC_Type(p);
AN(sym->fmt);
p += strlen(p) + 1;
......@@ -264,3 +263,90 @@ vcc_ParseImport(struct vcc *tl)
Fh(tl, 0, "\n%s\n", vmd->proto);
Fh(tl, 0, "\n/* --- END VMOD %.*s --- */\n\n", PF(mod));
}
void
vcc_ParseNew(struct vcc *tl)
{
struct symbol *sy1, *sy2, *sy3;
struct inifin *ifp;
const char *p, *s_obj, *s_init, *s_struct, *s_fini;
char buf1[128];
char buf2[128];
vcc_NextToken(tl);
ExpectErr(tl, ID);
vcc_ExpectCid(tl, "VCL object");
ERRCHK(tl);
sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "XXX");
ERRCHK(tl);
/* We allow implicit use of VMOD objects: Pretend it's ref'ed */
sy1->nref++;
vcc_NextToken(tl);
ExpectErr(tl, '=');
vcc_NextToken(tl);
ExpectErr(tl, ID);
sy2 = VCC_SymbolTok(tl, NULL, tl->t, SYM_OBJECT, 0);
if (sy2 == NULL) {
VSB_printf(tl->sb, "Symbol not found: ");
vcc_ErrToken(tl, tl->t);
VSB_printf(tl->sb, " at ");
vcc_ErrWhere(tl, tl->t);
return;
}
XXXAN(sy2);
/*lint -save -e448 */
/* Split the first three args */
p = sy2->args;
s_obj = p;
p += strlen(p) + 1;
s_struct = p;
p += strlen(p) + 1;
s_init = p;
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
p++;
p += 3;
s_fini = p;
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, ';');
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);
sy3 = VCC_Symbol(tl, NULL, buf2, NULL, SYM_FUNC, 1);
AN(sy3);
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')
p++;
p += 3;
}
sy1->def_e = tl->t;
/*lint -restore */
}
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