Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
2d7f4abe
Commit
2d7f4abe
authored
Jun 08, 2016
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve compiler typechecking and error reporting.
parent
c1e52e95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
51 deletions
+62
-51
v00020.vtc
bin/varnishtest/tests/v00020.vtc
+8
-0
vcc_expr.c
lib/libvcc/vcc_expr.c
+53
-51
vcc_types.c
lib/libvcc/vcc_types.c
+1
-0
No files found.
bin/varnishtest/tests/v00020.vtc
View file @
2d7f4abe
...
...
@@ -304,3 +304,11 @@ varnish v1 -errvcl {Name of ACL, 'foo-bar', contains illegal character '-'} {
varnish v1 -errvcl {Expected 'from path ...'} {
import std to;
}
varnish v1 -errvcl {INT * BLOB not possible.} {
import debug;
backend b { .host = "127.0.0.1"; }
sub vcl_deliver {
set resp.status = 100 * debug.str2blob("a");
}
}
lib/libvcc/vcc_expr.c
View file @
2d7f4abe
...
...
@@ -378,23 +378,15 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
AN
(
fmt
==
STRING
||
fmt
==
STRING_LIST
);
p
=
(
*
e
)
->
fmt
->
tostring
;
if
(
p
==
NULL
&&
(
*
e
)
->
fmt
==
INT
)
{
if
(
vcc_isconst
(
*
e
))
{
p
=
"
\"\v
1
\"
"
;
constant
=
EXPR_CONST
;
}
else
{
p
=
"VRT_INT_string(ctx,
\v
1)"
;
}
}
else
if
(
p
==
NULL
&&
(
*
e
)
->
fmt
==
BLOB
)
{
if
(
p
==
NULL
&&
(
*
e
)
->
fmt
==
BLOB
)
{
VSB_printf
(
tl
->
sb
,
"Wrong use of BLOB value.
\n
"
"BLOBs can only be used as arguments to VMOD"
" functions.
\n
"
);
vcc_ErrWhere2
(
tl
,
(
*
e
)
->
t1
,
tl
->
t
);
return
;
}
else
{
AN
(
p
);
}
AN
(
p
);
if
(
*
p
!=
'\0'
)
{
*
e
=
vcc_expr_edit
(
fmt
,
p
,
*
e
,
NULL
);
(
*
e
)
->
constant
=
constant
;
...
...
@@ -912,6 +904,13 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_NextToken
(
tl
);
vcc_expr4
(
tl
,
&
e2
,
f2
);
ERRCHK
(
tl
);
if
(
e2
->
fmt
->
multype
==
NULL
)
{
VSB_printf
(
tl
->
sb
,
"%s %.*s %s not possible.
\n
"
,
f2
->
name
,
PF
(
tk
),
e2
->
fmt
->
name
);
vcc_ErrWhere
(
tl
,
tk
);
return
;
}
assert
(
e2
->
fmt
==
f2
);
if
(
tk
->
tok
==
'*'
)
*
e
=
vcc_expr_edit
(
f3
,
"(
\v
1*
\v
2)"
,
*
e
,
e2
);
...
...
@@ -947,10 +946,8 @@ vcc_expr_string_add(struct vcc *tl, struct expr **e, struct expr *e2)
vcc_expr_mul
(
tl
,
&
e2
,
STRING
);
}
ERRCHK
(
tl
);
if
(
e2
->
fmt
!=
STRING
&&
e2
->
fmt
!=
STRING_LIST
)
{
if
(
e2
->
fmt
!=
STRING
&&
e2
->
fmt
!=
STRING_LIST
)
vcc_expr_tostring
(
tl
,
&
e2
,
f2
);
ERRCHK
(
tl
);
}
ERRCHK
(
tl
);
assert
(
e2
->
fmt
==
STRING
||
e2
->
fmt
==
STRING_LIST
);
...
...
@@ -996,41 +993,46 @@ vcc_expr_add(struct vcc *tl, struct expr **e, vcc_type_t fmt)
else
vcc_expr_mul
(
tl
,
&
e2
,
f2
);
ERRCHK
(
tl
);
if
(
tk
->
tok
==
'-'
&&
(
*
e
)
->
fmt
==
TIME
&&
e2
->
fmt
==
TIME
)
{
/* OK */
}
else
if
((
*
e
)
->
fmt
==
TIME
&&
e2
->
fmt
==
DURATION
)
{
f2
=
TIME
;
/* OK */
}
else
if
((
*
e
)
->
fmt
==
BYTES
&&
e2
->
fmt
==
BYTES
)
{
/* OK */
}
else
if
((
*
e
)
->
fmt
==
INT
&&
e2
->
fmt
==
INT
)
{
/* OK */
}
else
if
((
*
e
)
->
fmt
==
REAL
&&
e2
->
fmt
==
REAL
)
{
/* OK */
}
else
if
((
*
e
)
->
fmt
==
DURATION
&&
e2
->
fmt
==
DURATION
)
{
/* OK */
}
else
if
(
tk
->
tok
==
'+'
&&
(
*
e
)
->
fmt
==
STRING
&&
e2
->
fmt
==
STRING
)
{
vcc_expr_string_add
(
tl
,
e
,
e2
);
return
;
}
else
if
(
tk
->
tok
==
'+'
&&
(
fmt
==
STRING
||
fmt
==
STRING_LIST
))
{
/* Time to fold and add as string */
vcc_expr_tostring
(
tl
,
e
,
STRING
);
vcc_expr_string_add
(
tl
,
e
,
e2
);
return
;
}
else
{
VSB_printf
(
tl
->
sb
,
"%s %.*s %s not possible.
\n
"
,
(
*
e
)
->
fmt
->
name
,
PF
(
tk
),
e2
->
fmt
->
name
);
vcc_ErrWhere2
(
tl
,
tk
,
tl
->
t
);
return
;
#define ADD_OK(op, a, b, c) \
if (tk->tok == op[0] && (*e)->fmt == a && e2->fmt == b) { \
*e = vcc_expr_edit(c, "(\v1" op "\v2)", *e, e2); \
continue; \
} \
ADD_OK
(
"-"
,
TIME
,
TIME
,
DURATION
);
ADD_OK
(
"+"
,
TIME
,
DURATION
,
TIME
);
ADD_OK
(
"-"
,
TIME
,
DURATION
,
TIME
);
ADD_OK
(
"+"
,
DURATION
,
DURATION
,
DURATION
);
ADD_OK
(
"-"
,
DURATION
,
DURATION
,
DURATION
);
ADD_OK
(
"+"
,
BYTES
,
BYTES
,
BYTES
);
ADD_OK
(
"-"
,
BYTES
,
BYTES
,
BYTES
);
ADD_OK
(
"+"
,
INT
,
INT
,
INT
);
ADD_OK
(
"-"
,
INT
,
INT
,
INT
);
ADD_OK
(
"+"
,
REAL
,
REAL
,
REAL
);
ADD_OK
(
"-"
,
REAL
,
REAL
,
REAL
);
#undef ADD_OK
if
(
tk
->
tok
==
'+'
)
{
if
((
*
e
)
->
fmt
==
STRING
&&
e2
->
fmt
==
STRING
)
{
vcc_expr_string_add
(
tl
,
e
,
e2
);
return
;
}
if
(
fmt
==
STRING
||
fmt
==
STRING_LIST
)
{
/* Time to fold and add as string */
if
((
*
e
)
->
fmt
!=
fmt
)
vcc_expr_tostring
(
tl
,
e
,
fmt
);
vcc_expr_string_add
(
tl
,
e
,
e2
);
return
;
}
}
if
(
tk
->
tok
==
'+'
)
*
e
=
vcc_expr_edit
(
f2
,
"(
\v
1+
\v
2)"
,
*
e
,
e2
);
else
if
(
f2
==
TIME
&&
e2
->
fmt
==
TIME
)
*
e
=
vcc_expr_edit
(
DURATION
,
"(
\v
1-
\v
2)"
,
*
e
,
e2
);
else
*
e
=
vcc_expr_edit
(
f2
,
"(
\v
1-
\v
2)"
,
*
e
,
e2
);
VSB_printf
(
tl
->
sb
,
"%s %.*s %s not possible.
\n
"
,
(
*
e
)
->
fmt
->
name
,
PF
(
tk
),
e2
->
fmt
->
name
);
vcc_ErrWhere2
(
tl
,
tk
,
tl
->
t
);
return
;
}
}
...
...
@@ -1246,8 +1248,8 @@ vcc_expr_cand(struct vcc *tl, struct expr **e, vcc_type_t fmt)
ERRCHK
(
tl
);
if
(
e2
->
fmt
!=
BOOL
)
{
VSB_printf
(
tl
->
sb
,
"'&&' must be followed by BOOL,
found "
);
VSB_printf
(
tl
->
sb
,
"
%s.
\n
"
,
e2
->
fmt
->
name
);
"'&&' must be followed by BOOL,
"
" found
%s.
\n
"
,
e2
->
fmt
->
name
);
vcc_ErrWhere2
(
tl
,
tk
,
tl
->
t
);
return
;
}
...
...
@@ -1280,8 +1282,8 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
ERRCHK
(
tl
);
if
(
e2
->
fmt
!=
BOOL
)
{
VSB_printf
(
tl
->
sb
,
"'||' must be followed by BOOL,
found "
);
VSB_printf
(
tl
->
sb
,
"
%s.
\n
"
,
e2
->
fmt
->
name
);
"'||' must be followed by BOOL,
"
" found
%s.
\n
"
,
e2
->
fmt
->
name
);
vcc_ErrWhere2
(
tl
,
tk
,
tl
->
t
);
return
;
}
...
...
lib/libvcc/vcc_types.c
View file @
2d7f4abe
...
...
@@ -100,6 +100,7 @@ const struct type INT[1] = {{
.
magic
=
0xfae932d9
,
.
name
=
"INT"
,
.
multype
=
INT
,
.
tostring
=
"VRT_INT_string(ctx,
\v
1)"
,
}};
const
struct
type
IP
[
1
]
=
{{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment