[master] f94c703 Rework the VCC error reporting code in preparation of multi-token idents.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Jan 24 20:11:08 UTC 2018
commit f94c7034bc576233226664f744de72ca6abd0e1f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jan 24 20:10:09 2018 +0000
Rework the VCC error reporting code in preparation of multi-token idents.
diff --git a/bin/varnishtest/tests/e00030.vtc b/bin/varnishtest/tests/e00030.vtc
index eaa998a..f5b5f16 100644
--- a/bin/varnishtest/tests/e00030.vtc
+++ b/bin/varnishtest/tests/e00030.vtc
@@ -1,7 +1,7 @@
varnishtest "Test req_top.* in an ESI context"
varnish v1 -arg "-p feature=+esi_disable_xml_check" \
- -errvcl {Variable 'req_top.url' is read only.} {
+ -errvcl {Variable is read only.} {
sub vcl_recv {
set req_top.url = "/foo";
}
diff --git a/bin/varnishtest/tests/r00310.vtc b/bin/varnishtest/tests/r00310.vtc
index 9d0c431..c00e4c8 100644
--- a/bin/varnishtest/tests/r00310.vtc
+++ b/bin/varnishtest/tests/r00310.vtc
@@ -1,6 +1,6 @@
varnishtest "Test obj.http.x-cache in vcl_hit"
-varnish v1 -errvcl {Variable 'obj.http.x-cache' is read only.} {
+varnish v1 -errvcl {Variable is read only.} {
backend foo { .host = "127.0.0.1"; }
sub vcl_hit {
diff --git a/bin/varnishtest/tests/v00016.vtc b/bin/varnishtest/tests/v00016.vtc
index 0f9a4c8..29d96bd 100644
--- a/bin/varnishtest/tests/v00016.vtc
+++ b/bin/varnishtest/tests/v00016.vtc
@@ -52,14 +52,14 @@ varnish v1 -errvcl {Symbol not found: 'foo.bar'} {
}
}
-varnish v1 -errvcl {'bereq.first_byte_timeout': cannot be set} {
+varnish v1 -errvcl {Cannot be set in method 'vcl_pipe'} {
backend b { .host = "127.0.0.1"; }
sub vcl_pipe {
set bereq.first_byte_timeout = 10s;
}
}
-varnish v1 -errvcl {'bereq.between_bytes_timeout': cannot be set} {
+varnish v1 -errvcl {Cannot be set in method 'vcl_pipe'.} {
backend b { .host = "127.0.0.1"; }
sub vcl_pipe {
set bereq.between_bytes_timeout = 10s;
diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index 7c14f02..c9b6b6a 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -7,7 +7,7 @@ varnish v1 -vcl {
sub vcl_deliver { return(synth(resp.status, resp.reason)); }
}
-varnish v1 -errvcl {Variable 'now' is read only.} {
+varnish v1 -errvcl {Variable is read only.} {
backend b { .host = "127.0.0.1"; }
sub vcl_miss { set now = 1000; }
}
@@ -68,12 +68,12 @@ varnish v1 -errvcl {Symbol not found: 'mu' (expected type BOOL):} {
sub vcl_backend_response { set beresp.do_gzip = mu; }
}
-varnish v1 -errvcl {Variable 'beresp.do_gzip' cannot be unset} {
+varnish v1 -errvcl {Variable cannot be unset} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_response { unset beresp.do_gzip; }
}
-varnish v1 -errvcl {Variable 'bereq.body' cannot be set.} {
+varnish v1 -errvcl {Variable cannot be set.} {
backend b { .host = "127.0.0.1"; }
sub vcl_backend_fetch { set bereq.body = "foo"; }
}
@@ -119,7 +119,7 @@ varnish v1 -errvcl {Expected return action name.} {
}
# issue #936
-varnish v1 -errvcl {'synthetic': not a valid action in method 'vcl_recv'} {
+varnish v1 -errvcl {Not a valid action in method 'vcl_recv'} {
backend foo { .host = "127.0.0.1"; }
sub vcl_recv {
synthetic("XXX");
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index c720531..05f7c24 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -218,7 +218,7 @@ varnish v1 -errvcl {Function returns VOID} {
}
}
-varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} {
+varnish v1 -errvcl {Not available in method 'vcl_recv'.} {
import blob;
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
@@ -226,7 +226,7 @@ varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} {
}
}
-varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} {
+varnish v1 -errvcl {Not available in method 'vcl_hash'.} {
import blob;
backend b { .host = "127.0.0.1"; }
sub vcl_hash {
@@ -234,7 +234,7 @@ varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} {
}
}
-varnish v1 -errvcl {'beresp.status': Not available in method 'vcl_recv'.} {
+varnish v1 -errvcl {Not available in method 'vcl_recv'.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
set req.http.foo = 100 + beresp.status;
diff --git a/bin/varnishtest/tests/v00021.vtc b/bin/varnishtest/tests/v00021.vtc
index dcf25d1..7db8afd 100644
--- a/bin/varnishtest/tests/v00021.vtc
+++ b/bin/varnishtest/tests/v00021.vtc
@@ -1,11 +1,11 @@
varnishtest "VCL compiler coverage test: vcc_xref.c vcc_var.c vcc_symb.c"
-varnish v1 -errvcl {Variable 'obj.ttl' is read only.} {
+varnish v1 -errvcl {Variable is read only.} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { set obj.ttl = 1 w; }
}
-varnish v1 -errvcl {Variable 'obj.ttl' is read only.} {
+varnish v1 -errvcl {Variable is read only.} {
backend b { .host = "127.0.0.1"; }
sub foo { set obj.ttl = 1 w; }
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index e37cff5..8f61bad 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -89,28 +89,27 @@ parse_set(struct vcc *tl)
{
const struct symbol *sym;
const struct arith *ap;
+ const struct token *t;
vcc_type_t fmt;
vcc_NextToken(tl);
ExpectErr(tl, ID);
+ t = tl->t;
sym = VCC_SymbolGet(tl, SYM_VAR, "Unknown variable");
ERRCHK(tl);
+ vcc_NextToken(tl);
AN(sym);
if (sym->w_methods == 0) {
- VSB_printf(tl->sb, "Variable ");
- vcc_ErrToken(tl, tl->t);
+ vcc_ErrWhere2(tl, t, tl->t);
if (sym->r_methods != 0)
- VSB_printf(tl->sb, " is read only.");
+ VSB_printf(tl->sb, "Variable is read only.\n");
else
- VSB_printf(tl->sb, " cannot be set.");
- VSB_cat(tl->sb, "\nAt: ");
- vcc_ErrWhere(tl, tl->t);
+ VSB_printf(tl->sb, "Variable cannot be set.\n");
return;
}
- vcc_AddUses(tl, tl->t, sym->w_methods, "cannot be set");
+ vcc_AddUses(tl, t, tl->t, sym->w_methods, "Cannot be set");
Fb(tl, 1, "%s\n", sym->lname);
tl->indent += INDENT;
- vcc_NextToken(tl);
fmt = sym->fmt;
for (ap = arith; ap->type != VOID; ap++) {
if (ap->type != fmt)
@@ -144,24 +143,23 @@ static void
parse_unset(struct vcc *tl)
{
const struct symbol *sym;
+ const struct token *t;
/* XXX: Wrong, should use VCC_Expr(HEADER) */
vcc_NextToken(tl);
ExpectErr(tl, ID);
+ t = tl->t;
sym = VCC_SymbolGet(tl, SYM_VAR, "Unknown variable");
ERRCHK(tl);
+ vcc_NextToken(tl);
AN(sym);
if (sym->u_methods == 0) {
- VSB_printf(tl->sb, "Variable ");
- vcc_ErrToken(tl, tl->t);
- VSB_printf(tl->sb, " cannot be unset.");
- VSB_cat(tl->sb, "\nAt: ");
- vcc_ErrWhere(tl, tl->t);
+ vcc_ErrWhere2(tl, t, tl->t);
+ VSB_printf(tl->sb, "Variable cannot be unset.\n");
return;
}
- vcc_AddUses(tl, tl->t, sym->u_methods, "cannot be unset.");
+ vcc_AddUses(tl, t, tl->t, sym->u_methods, "Cannot be unset");
Fb(tl, 1, "%s;\n", sym->uname);
- vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/
@@ -401,8 +399,8 @@ vcc_ParseAction(struct vcc *tl)
for (atp = action_table; atp->name != NULL; atp++) {
if (vcc_IdIs(at, atp->name)) {
if (atp->bitmask != 0)
- vcc_AddUses(tl, at, atp->bitmask,
- "not a valid action");
+ vcc_AddUses(tl, at, NULL, atp->bitmask,
+ "Not a valid action");
atp->func(tl);
return (1);
}
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index c5a496e..cd96916 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -352,8 +352,8 @@ void VCC_XrefTable(struct vcc *);
void vcc_AddCall(struct vcc *);
void vcc_ProcAction(struct proc *p, unsigned action, struct token *t);
int vcc_CheckAction(struct vcc *tl);
-void vcc_AddUses(struct vcc *tl, const struct token *t, unsigned mask,
- const char *use);
+void vcc_AddUses(struct vcc *, const struct token *, const struct token *,
+ unsigned mask, const char *use);
int vcc_CheckUses(struct vcc *tl);
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0)
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 0919b7e..f1666e6 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -359,7 +359,7 @@ vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym,
(void)fmt;
assert(sym->kind == SYM_VAR);
- vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
+ vcc_AddUses(tl, tl->t, NULL, sym->r_methods, "Not available");
ERRCHK(tl);
*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
(*e)->constant = EXPR_VAR;
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index 856e550..894397d 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -104,7 +104,10 @@ vcc_icoord(struct vsb *vsb, const struct token *t, int tail)
} else
pos++;
}
- VSB_printf(vsb, "('%s' Line %u Pos %u)", t->src->name, lin, pos + 1);
+ VSB_printf(vsb, "(");
+ if (tail < 2)
+ VSB_printf(vsb, "'%s' Line %u ", t->src->name, lin);
+ VSB_printf(vsb, "Pos %u)", pos + 1);
}
/*--------------------------------------------------------------------*/
@@ -200,7 +203,7 @@ vcc_ErrWhere2(struct vcc *tl, const struct token *t, const struct token *t2)
if (l1 == l2) {
vcc_icoord(tl->sb, t, 0);
VSB_cat(tl->sb, " -- ");
- vcc_icoord(tl->sb, t2, 1);
+ vcc_icoord(tl->sb, t2, 2);
VSB_putc(tl->sb, '\n');
/* Two tokens on same line */
vcc_quoteline(tl, l1, t->src->e);
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index d6d5535..9ad4d67 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -47,13 +47,16 @@ struct proccall {
VTAILQ_ENTRY(proccall) list;
struct symbol *sym;
struct token *t;
+ struct proc *fm;
};
struct procuse {
VTAILQ_ENTRY(procuse) list;
- const struct token *t;
+ const struct token *t1;
+ const struct token *t2;
unsigned mask;
const char *use;
+ struct proc *fm;
};
/*--------------------------------------------------------------------
@@ -122,8 +125,8 @@ vcc_CheckReferences(struct vcc *tl)
*/
void
-vcc_AddUses(struct vcc *tl, const struct token *t, unsigned mask,
- const char *use)
+vcc_AddUses(struct vcc *tl, const struct token *t1, const struct token *t2,
+ unsigned mask, const char *use)
{
struct procuse *pu;
@@ -131,9 +134,13 @@ vcc_AddUses(struct vcc *tl, const struct token *t, unsigned mask,
return;
pu = TlAlloc(tl, sizeof *pu);
assert(pu != NULL);
- pu->t = t;
+ pu->t1 = t1;
+ pu->t2 = t2;
+ if (pu->t2 == NULL)
+ pu->t2 = VTAILQ_NEXT(t1, list);
pu->mask = mask;
pu->use = use;
+ pu->fm = tl->curproc;
VTAILQ_INSERT_TAIL(&tl->curproc->uses, pu, list);
}
@@ -147,6 +154,7 @@ vcc_AddCall(struct vcc *tl)
pc->sym = VCC_SymbolTok(tl, SYM_SUB, 1);
AN(pc->sym);
pc->t = tl->t;
+ pc->fm = tl->curproc;
VTAILQ_INSERT_TAIL(&tl->curproc->calls, pc, list);
}
@@ -286,19 +294,18 @@ vcc_CheckUseRecurse(struct vcc *tl, const struct proc *p,
pu = vcc_FindIllegalUse(p, m);
if (pu != NULL) {
- VSB_printf(tl->sb,
- "'%.*s': %s from method '%.*s'.\n",
- PF(pu->t), pu->use, PF(p->name));
- vcc_ErrWhere(tl, pu->t);
+ vcc_ErrWhere2(tl, pu->t1, pu->t2);
+ VSB_printf(tl->sb, "%s from method '%s'.\n",
+ pu->use, m->name);
VSB_printf(tl->sb, "\n...in subroutine \"%.*s\"\n",
- PF(p->name));
+ PF(pu->fm->name));
vcc_ErrWhere(tl, p->name);
return (1);
}
VTAILQ_FOREACH(pc, &p->calls, list) {
if (vcc_CheckUseRecurse(tl, pc->sym->proc, m)) {
- VSB_printf(tl->sb, "\n...called from \"%s\"\n",
- pc->sym->name);
+ VSB_printf(tl->sb, "\n...called from \"%.*s\"\n",
+ PF(pc->fm->name));
vcc_ErrWhere(tl, pc->t);
return (1);
}
@@ -318,10 +325,10 @@ vcc_checkuses(struct vcc *tl, const struct symbol *sym)
return;
pu = vcc_FindIllegalUse(p, p->method);
if (pu != NULL) {
- VSB_printf(tl->sb, "'%.*s': %s in method '%.*s'.",
- PF(pu->t), pu->use, PF(p->name));
+ vcc_ErrWhere2(tl, pu->t1, pu->t2);
+ VSB_printf(tl->sb, "%s in method '%.*s'.",
+ pu->use, PF(p->name));
VSB_cat(tl->sb, "\nAt: ");
- vcc_ErrWhere(tl, pu->t);
return;
}
if (vcc_CheckUseRecurse(tl, p, p->method)) {
More information about the varnish-commit
mailing list