Commit ac6cf0fd authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Split the parameters for the VCC compiler into a separate structure

for more clarity, before we start hacking VCC further.
parent 17190673
......@@ -64,7 +64,7 @@ unsigned mgt_vcc_err_unref;
unsigned mgt_vcc_allow_inline_c;
unsigned mgt_vcc_unsafe_path;
static struct vcc *vcc;
static struct vcp *vcp;
#define VGC_SRC "vgc.c"
#define VGC_LIB "vgc.so"
......@@ -94,12 +94,12 @@ run_vcc(void *priv)
sb = VSB_new_auto();
XXXAN(sb);
VCC_VCL_dir(vcc, mgt_vcl_dir);
VCC_VMOD_dir(vcc, mgt_vmod_dir);
VCC_Err_Unref(vcc, mgt_vcc_err_unref);
VCC_Allow_InlineC(vcc, mgt_vcc_allow_inline_c);
VCC_Unsafe_Path(vcc, mgt_vcc_unsafe_path);
csrc = VCC_Compile(vcc, sb, vp->src);
VCP_VCL_dir(vcp, mgt_vcl_dir);
VCP_VMOD_dir(vcp, mgt_vmod_dir);
VCP_Err_Unref(vcp, mgt_vcc_err_unref);
VCP_Allow_InlineC(vcp, mgt_vcc_allow_inline_c);
VCP_Unsafe_Path(vcp, mgt_vcc_unsafe_path);
csrc = VCC_Compile(vcp, sb, vp->src);
AZ(VSB_finish(sb));
if (VSB_len(sb))
printf("%s", VSB_data(sb));
......@@ -318,7 +318,7 @@ void
mgt_vcc_init(void)
{
vcc = VCC_New();
AN(vcc);
VCC_Builtin_VCL(vcc, builtin_vcl);
vcp = VCP_New();
AN(vcp);
VCP_Builtin_VCL(vcp, builtin_vcl);
}
......@@ -30,12 +30,12 @@
struct vcc;
struct vcc *VCC_New(void);
void VCC_Builtin_VCL(struct vcc *, const char *str);
void VCC_VCL_dir(struct vcc *, const char *str);
void VCC_VMOD_dir(struct vcc *, const char *str);
void VCC_Err_Unref(struct vcc *tl, unsigned u);
void VCC_Allow_InlineC(struct vcc *tl, unsigned u);
void VCC_Unsafe_Path(struct vcc *tl, unsigned u);
struct vcp *VCP_New(void);
void VCP_Builtin_VCL(struct vcp *, const char *str);
void VCP_VCL_dir(struct vcp *, const char *str);
void VCP_VMOD_dir(struct vcp *, const char *str);
void VCP_Err_Unref(struct vcp *tl, unsigned u);
void VCP_Allow_InlineC(struct vcp *tl, unsigned u);
void VCP_Unsafe_Path(struct vcp *tl, unsigned u);
char *VCC_Compile(const struct vcc *, struct vsb *sb, const char *b);
char *VCC_Compile(const struct vcp *, struct vsb *sb, const char *b);
......@@ -364,7 +364,7 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon)
Fh(tl, 0, "\t\tVRT_acl_log(ctx, \"NO_FAM %s\");\n", acln);
Fh(tl, 0, "\t\treturn(0);\n");
Fh(tl, 0, "\t}\n\n");
if (!tl->err_unref && !anon ) {
if (!tl->param->err_unref && !anon ) {
ifp = New_IniFin(tl);
VSB_printf(ifp->ini,
"\tif (0) match_acl_named_%s(0, 0);\n", acln);
......
......@@ -450,16 +450,16 @@ vcc_destroy_source(struct source *sp)
/*--------------------------------------------------------------------*/
static struct source *
vcc_file_source(const struct vcc *tl, struct vsb *sb, const char *fn)
vcc_file_source(const struct vcp * const vcp, struct vsb *sb, const char *fn)
{
char *f;
struct source *sp;
if (!tl->unsafe_path && strchr(fn, '/') != NULL) {
if (!vcp->unsafe_path && strchr(fn, '/') != NULL) {
VSB_printf(sb, "Include path is unsafe '%s'\n", fn);
return (NULL);
}
f = VFIL_readfile(tl->vcl_dir, fn, NULL);
f = VFIL_readfile(vcp->vcl_dir, fn, NULL);
if (f == NULL) {
VSB_printf(sb, "Cannot read file '%s': %s\n",
fn, strerror(errno));
......@@ -500,7 +500,7 @@ vcc_resolve_includes(struct vcc *tl)
return;
}
sp = vcc_file_source(tl, tl->sb, t1->dec);
sp = vcc_file_source(tl->param, tl->sb, t1->dec);
if (sp == NULL) {
vcc_ErrWhere(tl, t1);
return;
......@@ -522,24 +522,16 @@ vcc_resolve_includes(struct vcc *tl)
/*--------------------------------------------------------------------*/
static struct vcc *
vcc_NewVcc(const struct vcc *tl0)
vcc_NewVcc(const struct vcp *vcp)
{
struct vcc *tl;
int i;
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
ALLOC_OBJ(tl, VCC_MAGIC);
AN(tl);
if (tl0 != NULL) {
REPLACE(tl->builtin_vcl, tl0->builtin_vcl);
REPLACE(tl->vcl_dir, tl0->vcl_dir);
REPLACE(tl->vmod_dir, tl0->vmod_dir);
tl->vars = tl0->vars;
tl->err_unref = tl0->err_unref;
tl->allow_inline_c = tl0->allow_inline_c;
tl->unsafe_path = tl0->unsafe_path;
} else {
tl->err_unref = 1;
}
tl->param = vcp;
tl->vars = vcc_vars;
VTAILQ_INIT(&tl->symbols);
VTAILQ_INIT(&tl->inifin);
VTAILQ_INIT(&tl->membits);
......@@ -606,7 +598,8 @@ vcc_DestroyTokenList(struct vcc *tl, char *ret)
*/
static char *
vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
vcc_CompileSource(const struct vcp * const vcp, struct vsb *sb,
struct source *sp)
{
struct vcc *tl;
struct symbol *sym;
......@@ -616,7 +609,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
char *of;
int i;
tl = vcc_NewVcc(tl0);
tl = vcc_NewVcc(vcp);
tl->sb = sb;
vcc_Expr_Init(tl);
......@@ -649,7 +642,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
return (vcc_DestroyTokenList(tl, NULL));
/* Register and lex the builtin VCL */
sp = vcc_new_source(tl->builtin_vcl, NULL, "Builtin");
sp = vcc_new_source(tl->param->builtin_vcl, NULL, "Builtin");
assert(sp != NULL);
VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++;
......@@ -759,7 +752,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
*/
char *
VCC_Compile(const struct vcc *tl, struct vsb *sb, const char *b)
VCC_Compile(const struct vcp *vcp, struct vsb *sb, const char *b)
{
struct source *sp;
char *r;
......@@ -767,7 +760,7 @@ VCC_Compile(const struct vcc *tl, struct vsb *sb, const char *b)
sp = vcc_new_source(b, NULL, "input");
if (sp == NULL)
return (NULL);
r = vcc_CompileSource(tl, sb, sp);
r = vcc_CompileSource(vcp, sb, sp);
return (r);
}
......@@ -775,16 +768,15 @@ VCC_Compile(const struct vcc *tl, struct vsb *sb, const char *b)
* Allocate a compiler instance
*/
struct vcc *
VCC_New(void)
struct vcp *
VCP_New(void)
{
struct vcc *tl;
struct vcp *vcp;
tl = vcc_NewVcc(NULL);
ALLOC_OBJ(vcp, VCP_MAGIC);
AN(vcp);
tl->vars = vcc_vars;
return (tl);
return (vcp);
}
/*--------------------------------------------------------------------
......@@ -792,11 +784,11 @@ VCC_New(void)
*/
void
VCC_Builtin_VCL(struct vcc *tl, const char *str)
VCP_Builtin_VCL(struct vcp *vcp, const char *str)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
REPLACE(tl->builtin_vcl, str);
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
REPLACE(vcp->builtin_vcl, str);
}
/*--------------------------------------------------------------------
......@@ -804,11 +796,11 @@ VCC_Builtin_VCL(struct vcc *tl, const char *str)
*/
void
VCC_VCL_dir(struct vcc *tl, const char *str)
VCP_VCL_dir(struct vcp *vcp, const char *str)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
REPLACE(tl->vcl_dir, str);
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
REPLACE(vcp->vcl_dir, str);
}
/*--------------------------------------------------------------------
......@@ -816,11 +808,11 @@ VCC_VCL_dir(struct vcc *tl, const char *str)
*/
void
VCC_VMOD_dir(struct vcc *tl, const char *str)
VCP_VMOD_dir(struct vcp *vcp, const char *str)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
REPLACE(tl->vmod_dir, str);
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
REPLACE(vcp->vmod_dir, str);
}
/*--------------------------------------------------------------------
......@@ -828,25 +820,25 @@ VCC_VMOD_dir(struct vcc *tl, const char *str)
*/
void
VCC_Err_Unref(struct vcc *tl, unsigned u)
VCP_Err_Unref(struct vcp *vcp, unsigned u)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
tl->err_unref = u;
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
vcp->err_unref = u;
}
void
VCC_Allow_InlineC(struct vcc *tl, unsigned u)
VCP_Allow_InlineC(struct vcp *vcp, unsigned u)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
tl->allow_inline_c = u;
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
vcp->allow_inline_c = u;
}
void
VCC_Unsafe_Path(struct vcc *tl, unsigned u)
VCP_Unsafe_Path(struct vcp *vcp, unsigned u)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
tl->unsafe_path = u;
CHECK_OBJ_NOTNULL(vcp, VCP_MAGIC);
vcp->unsafe_path = u;
}
......@@ -155,14 +155,24 @@ struct inifin {
VTAILQ_HEAD(inifinhead, inifin);
struct vcc {
struct vcp {
unsigned magic;
#define VCC_MAGIC 0x24ad719d
#define VCP_MAGIC 0xd90acfbc
/* Parameter/Template section */
char *builtin_vcl;
char *vcl_dir;
char *vmod_dir;
unsigned err_unref;
unsigned allow_inline_c;
unsigned unsafe_path;
};
struct vcc {
unsigned magic;
#define VCC_MAGIC 0x24ad719d
/* Parameter/Template section */
const struct vcp *param;
const struct var *vars;
VTAILQ_HEAD(, symbol) symbols;
......@@ -202,9 +212,6 @@ struct vcc {
unsigned unique;
unsigned err_unref;
unsigned allow_inline_c;
unsigned unsafe_path;
};
struct var {
......
......@@ -160,7 +160,7 @@ vcc_Compound(struct vcc *tl)
Fb(tl, 1, "}\n");
return;
case CSRC:
if (tl->allow_inline_c) {
if (tl->param->allow_inline_c) {
Fb(tl, 1, "%.*s\n",
(int) (tl->t->e - (tl->t->b + 2)),
tl->t->b + 1);
......@@ -357,7 +357,7 @@ vcc_Parse(struct vcc *tl)
ERRCHK(tl);
switch (tl->t->tok) {
case CSRC:
if (tl->allow_inline_c) {
if (tl->param->allow_inline_c) {
Fc(tl, 0, "%.*s\n",
(int) (tl->t->e - (tl->t->b + 4)),
tl->t->b + 2);
......
......@@ -85,7 +85,7 @@ vcc_ParseImport(struct vcc *tl)
sym->def_e = tl->t;
if (tl->t->tok == ID) {
if (!tl->unsafe_path) {
if (!tl->param->unsafe_path) {
VSB_printf(tl->sb,
"'import ... from path ...' not allowed.\nAt:");
vcc_ErrToken(tl, tl->t);
......@@ -102,7 +102,7 @@ vcc_ParseImport(struct vcc *tl)
bprintf(fn, "%s", tl->t->dec);
vcc_NextToken(tl);
} else {
bprintf(fn, "%s/libvmod_%.*s.so", tl->vmod_dir, PF(mod));
bprintf(fn, "%s/libvmod_%.*s.so", tl->param->vmod_dir, PF(mod));
}
SkipToken(tl, ';');
......
......@@ -108,7 +108,7 @@ vcc_checkref(struct vcc *tl, const struct symbol *sym)
VSB_printf(tl->sb, "Unused %s %.*s, defined:\n",
VCC_SymKind(tl, sym), PF(sym->def_b));
vcc_ErrWhere(tl, sym->def_b);
if (!tl->err_unref) {
if (!tl->param->err_unref) {
VSB_printf(tl->sb, "(That was just a warning)\n");
tl->err = 0;
}
......@@ -289,7 +289,7 @@ vcc_checkaction2(struct vcc *tl, const struct symbol *sym)
return;
VSB_printf(tl->sb, "Function unused\n");
vcc_ErrWhere(tl, p->name);
if (!tl->err_unref) {
if (!tl->param->err_unref) {
VSB_printf(tl->sb, "(That was just a warning)\n");
tl->err = 0;
}
......
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