Permalink
Browse files

Unify handling of emitted functions.

  • Loading branch information...
bsdphk committed Dec 6, 2017
1 parent f7860ad commit 4e1699f6b0046d358c0d60d733a2b9479634d5d3
Showing with 29 additions and 23 deletions.
  1. +2 −2 lib/libvcc/vcc_action.c
  2. +21 −13 lib/libvcc/vcc_compile.c
  3. +1 −0 lib/libvcc/vcc_compile.h
  4. +5 −8 lib/libvcc/vcc_parse.c
View
@@ -286,8 +286,8 @@ parse_return(struct vcc *tl)
const char *h;
vcc_NextToken(tl);
if (tl->t->tok == ';' && tl->fb == tl->fc) {
/* fb == fc means we're in a subroutine */
AN(tl->curproc);
if (tl->t->tok == ';' && tl->curproc->method == NULL) {
Fb(tl, 1, "return;\n");
return;
}
View
@@ -107,10 +107,25 @@ vcc_NewProc(struct vcc *tl, struct symbol *sym)
VTAILQ_INSERT_TAIL(&tl->procs, p, list);
p->body = VSB_new_auto();
AN(p->body);
p->cname = VSB_new_auto();
AN(p->cname);
sym->proc = p;
return (p);
}
static void
vcc_EmitProc(struct vcc *tl, struct proc *p)
{
AZ(VSB_finish(p->cname));
AZ(VSB_finish(p->body));
Fh(tl, 1, "vcl_func_f %s;\n", VSB_data(p->cname));
Fc(tl, 1, "\nvoid v_matchproto_(vcl_func_f)\n");
Fc(tl, 1, "%s(VRT_CTX)\n", VSB_data(p->cname));
Fc(tl, 1, "{\n%s}\n", VSB_data(p->body));
VSB_destroy(&p->body);
VSB_destroy(&p->cname);
}
/*--------------------------------------------------------------------*/
struct inifin *
@@ -625,20 +640,12 @@ vcc_CompileSource(struct vcc *tl, struct source *sp)
/* Emit method functions */
Fh(tl, 1, "\n");
VTAILQ_FOREACH(p, &tl->procs, list) {
VTAILQ_FOREACH(p, &tl->procs, list)
if (p->method == NULL)
continue;
Fh(tl, 1,
"void v_matchproto_(vcl_func_f) "
"VGC_function_%s(VRT_CTX);\n",
p->method->name);
Fc(tl, 1, "\nvoid v_matchproto_(vcl_func_f)\n");
Fc(tl, 1, "VGC_function_%s(VRT_CTX)\n",
p->method->name);
AZ(VSB_finish(p->body));
Fc(tl, 1, "{\n%s}\n", VSB_data(p->body));
VSB_destroy(&p->body);
}
vcc_EmitProc(tl, p);
VTAILQ_FOREACH(p, &tl->procs, list)
if (p->method != NULL)
vcc_EmitProc(tl, p);
EmitInitFini(tl);
@@ -729,6 +736,7 @@ VCC_New(void)
method_tab[i].name, NULL, SYM_SUB, 1);
p = vcc_NewProc(tl, sym);
p->method = &method_tab[i];
VSB_printf(p->cname, "VGC_function_%s", p->method->name);
}
tl->sb = VSB_new_auto();
AN(tl->sb);
View
@@ -159,6 +159,7 @@ struct proc {
unsigned called;
unsigned active;
struct token *return_tok[VCL_RET_MAX];
struct vsb *cname;
struct vsb *body;
};
View
@@ -236,10 +236,7 @@ vcc_ParseFunction(struct vcc *tl)
VCC_GlobalSymbol(sym, SUB, "VGC_function");
p = vcc_NewProc(tl, sym);
p->name = tl->t;
tl->fb = tl->fc;
Fh(tl, 0, "void %s(VRT_CTX);\n", sym->rname);
Fc(tl, 1, "\nvoid v_matchproto_(vcl_func_t)\n");
Fc(tl, 1, "%s(VRT_CTX)\n", sym->rname);
VSB_printf(p->cname, "%s", sym->rname);
} else if (p->method == NULL) {
VSB_printf(tl->sb, "Function '%s' redefined\n", sym->name);
vcc_ErrWhere(tl, tl->t);
@@ -254,12 +251,12 @@ vcc_ParseFunction(struct vcc *tl)
(void)vcc_AddRef(tl, tl->t, SYM_SUB);
p->name = tl->t;
}
tl->fb = p->body;
Fb(tl, 1, " /* ... from ");
vcc_Coord(tl, tl->fb, NULL);
Fb(tl, 0, " */\n");
}
CHECK_OBJ_NOTNULL(p, PROC_MAGIC);
tl->fb = p->body;
Fb(tl, 1, " /* ... from ");
vcc_Coord(tl, p->body, NULL);
Fb(tl, 0, " */\n");
tl->curproc = p;
vcc_NextToken(tl);
tl->indent += INDENT;

0 comments on commit 4e1699f

Please sign in to comment.