[master] 4e1699f Unify handling of emitted functions.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Dec 6 13:06:12 UTC 2017
commit 4e1699f6b0046d358c0d60d733a2b9479634d5d3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Dec 6 13:04:49 2017 +0000
Unify handling of emitted functions.
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 2c9b046..69adcec 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -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;
}
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index 53fc9b9..e46c09e 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -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);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 7f09b47..074e66c 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -159,6 +159,7 @@ struct proc {
unsigned called;
unsigned active;
struct token *return_tok[VCL_RET_MAX];
+ struct vsb *cname;
struct vsb *body;
};
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 13615cd..94e6279 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -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;
More information about the varnish-commit
mailing list