r5229 - trunk/varnish-cache/lib/libvcl
phk at varnish-cache.org
phk at varnish-cache.org
Tue Sep 21 20:45:59 CEST 2010
Author: phk
Date: 2010-09-21 20:45:59 +0200 (Tue, 21 Sep 2010)
New Revision: 5229
Modified:
trunk/varnish-cache/lib/libvcl/vcc_expr.c
Log:
Improve type-check error messages.
Make TIME - TIME = DURATION work
Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c 2010-09-21 18:18:41 UTC (rev 5228)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c 2010-09-21 18:45:59 UTC (rev 5229)
@@ -643,8 +643,14 @@
case INT: f2 = INT; break;
case DURATION: f2 = REAL; break;
default:
+ if (tl->t->tok != '*' && tl->t->tok != '/')
+ return;
+ vsb_printf(tl->sb, "Operator %.*s not possible on type %s.\n",
+ PF(tl->t), vcc_Type(f2));
+ vcc_ErrWhere(tl, tl->t);
return;
}
+
while (tl->t->tok == '*' || tl->t->tok == '/') {
tk = tl->t;
vcc_NextToken(tl);
@@ -702,20 +708,34 @@
switch(f2) {
case INT: break;
- case TIME: f2 = DURATION; break;
- case DURATION: f2 = DURATION; break;
+ case TIME: break;
+ case DURATION: break;
default:
+ if (tl->t->tok != '+' && tl->t->tok != '-')
+ return;
+ vsb_printf(tl->sb, "Operator %.*s not possible on type %s.\n",
+ PF(tl->t), vcc_Type(f2));
+ vcc_ErrWhere(tl, tl->t);
return;
}
while (tl->t->tok == '+' || tl->t->tok == '-') {
+ if (f2 == TIME && tl->t->tok == '+')
+ f2 = DURATION;
tk = tl->t;
vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, f2);
- assert(e2->fmt == f2);
ERRCHK(tl);
+ if (e2->fmt != f2) {
+ vsb_printf(tl->sb, "%s %.*s %s not possible.\n",
+ vcc_Type((*e)->fmt), PF(tk), vcc_Type(e2->fmt));
+ vcc_ErrWhere2(tl, tk, tl->t);
+ return;
+ }
if (tk->tok == '+')
*e = vcc_expr_edit(f2, "(\v1+\v2)", *e, e2);
+ else if (f2 == TIME && e2->fmt == TIME)
+ *e = vcc_expr_edit(DURATION, "(\v1-\v2)", *e, e2);
else
*e = vcc_expr_edit(f2, "(\v1-\v2)", *e, e2);
}
More information about the varnish-commit
mailing list