[master] 66e06b1 Unify the "I need an expression of _exactly_ this type" paths.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Dec 12 13:11:07 UTC 2017
commit 66e06b157ab94919716d3b6562441b68f0ef200c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Dec 12 11:44:26 2017 +0000
Unify the "I need an expression of _exactly_ this type" paths.
diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 1690a78..14875e6 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -81,7 +81,7 @@ varnish v1 -errvcl {Wrong enum value. Expected one of:} {
}
}
-varnish v1 -errvcl {Wrong argument type. Expected REAL. Got STRING.} {
+varnish v1 -errvcl {Expression has type STRING, expected REAL} {
import std;
sub vcl_deliver {
set resp.http.who = std.random("foo", "bar");
diff --git a/bin/varnishtest/tests/m00012.vtc b/bin/varnishtest/tests/m00012.vtc
index 294458c..33f25c7 100644
--- a/bin/varnishtest/tests/m00012.vtc
+++ b/bin/varnishtest/tests/m00012.vtc
@@ -9,7 +9,7 @@ varnish v1 -errvcl {BLOBs can only be used as arguments to VMOD functions.} {
}
}
-varnish v1 -errvcl {Wrong argument type. Expected BLOB. Got STRING.} {
+varnish v1 -errvcl {Expression has type STRING, expected BLOB} {
backend b1 {.host = "${bad_backend}";}
diff --git a/bin/varnishtest/tests/r01212.vtc b/bin/varnishtest/tests/r01212.vtc
index 0fc2634..236b459 100644
--- a/bin/varnishtest/tests/r01212.vtc
+++ b/bin/varnishtest/tests/r01212.vtc
@@ -1,6 +1,6 @@
varnishtest "#1212 - Vmod with HEADER argument given a STRING asserts the VCL compiler"
-varnish v1 -errvcl {Wrong argument type. Expected HEADER. Got STRING.} {
+varnish v1 -errvcl {Expression has type STRING, expected HEADER} {
import std;
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index b55f4ba..c99242e 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -276,8 +276,7 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym,
SkipToken(tl, '(');
vcc_expr0(tl, &e2, STRING);
- if (e2 == NULL)
- return;
+ ERRCHK(tl);
SkipToken(tl, ',');
ExpectErr(tl, CSTR);
@@ -289,8 +288,7 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym,
SkipToken(tl, ',');
vcc_expr0(tl, &e2, STRING);
- if (e2 == NULL)
- return;
+ ERRCHK(tl);
*e = vcc_expr_edit(STRING, "\v1,\n\v2)\v-", *e, e2);
SkipToken(tl, ')');
}
@@ -430,20 +428,7 @@ vcc_do_arg(struct vcc *tl, struct func_arg *fa)
} else {
vcc_expr0(tl, &e2, fa->type);
ERRCHK(tl);
- if (e2->fmt != fa->type) {
- VSB_printf(tl->sb, "Wrong argument type.");
- VSB_printf(tl->sb,
- " Expected %s.", vcc_utype(fa->type));
- VSB_printf(tl->sb, " Got %s.\n", vcc_utype(e2->fmt));
- vcc_ErrWhere2(tl, e2->t1, tl->t);
- return;
- }
assert(e2->fmt == fa->type);
- if (e2->fmt == STRING_LIST) {
- e2 = vcc_expr_edit(STRING_LIST,
- "\v+\n\v1,\nvrt_magic_string_end\v-",
- e2, NULL);
- }
fa->result = e2;
}
}
@@ -1176,12 +1161,12 @@ vcc_expr_cand(struct vcc *tl, struct expr **e, vcc_type_t fmt)
/*--------------------------------------------------------------------
* SYNTAX:
- * Expr0:
+ * Expr1:
* ExprCand { '||' ExprCand } *
*/
static void
-vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
+vcc_expr1(struct vcc *tl, struct expr **e, vcc_type_t fmt)
{
struct expr *e2;
struct token *tk;
@@ -1214,6 +1199,32 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
}
/*--------------------------------------------------------------------
+ * This function is the entry-point for getting an expression with
+ * a particular type, ready for inclusion in the VGC.
+ */
+
+static void
+vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
+{
+ struct token *t1;
+
+ assert(fmt != VOID);
+ t1 = tl->t;
+ vcc_expr1(tl, e, fmt);
+ ERRCHK(tl);
+ if (fmt != (*e)->fmt) {
+ VSB_printf(tl->sb, "Expression has type %s, expected %s\n",
+ vcc_utype((*e)->fmt), vcc_utype(fmt));
+ tl->err = 1;
+ }
+ if ((*e)->fmt == STRING_LIST)
+ *e = vcc_expr_edit(STRING_LIST,
+ "\v+\n\v1,\nvrt_magic_string_end\v-", *e, NULL);
+ if (tl->err)
+ vcc_ErrWhere2(tl, t1, tl->t);
+}
+
+/*--------------------------------------------------------------------
* This function parses and emits the C-code to evaluate an expression
*
* We know up front what kind of type we want the expression to be,
@@ -1223,29 +1234,13 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
void
vcc_Expr(struct vcc *tl, vcc_type_t fmt)
{
- struct expr *e;
- struct token *t1;
+ struct expr *e = NULL;
assert(fmt != VOID);
-
- t1 = tl->t;
vcc_expr0(tl, &e, fmt);
ERRCHK(tl);
- e->t1 = t1;
- if (!tl->err && fmt != e->fmt) {
- VSB_printf(tl->sb, "Expression has type %s, expected %s\n",
- vcc_utype(e->fmt), vcc_utype(fmt));
- tl->err = 1;
- }
- if (!tl->err) {
- if (e->fmt == STRING_LIST) {
- e = vcc_expr_edit(STRING_LIST,
- "\v+\n\v1,\nvrt_magic_string_end\v-", e, NULL);
- }
- vcc_expr_fmt(tl->fb, tl->indent, e);
- VSB_putc(tl->fb, '\n');
- } else if (t1 != tl->t)
- vcc_ErrWhere2(tl, t1, tl->t);
+ vcc_expr_fmt(tl->fb, tl->indent, e);
+ VSB_printf(tl->fb, "\n");
vcc_delete_expr(e);
}
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index e6d6e64..9a3344d 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -238,7 +238,7 @@ vcc_ParseImport(struct vcc *tl)
VSB_printf(ifp->fin,
"\t\t(void)%s(ctx, &vmod_priv_%.*s,\n"
"\t\t\t VCL_EVENT_DISCARD);\n", p, PF(mod));
- VSB_printf(ifp->event, "\t%s(ctx, &vmod_priv_%.*s, ev)",
+ VSB_printf(ifp->event, "%s(ctx, &vmod_priv_%.*s, ev)",
p, PF(mod));
} else if (!strcmp(p, "$FUNC")) {
p += strlen(p) + 1;
More information about the varnish-commit
mailing list