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
71a5a718
Commit
71a5a718
authored
Sep 20, 2013
by
Martin Blix Grydeland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement numerical tests by macros to eliminate code duplication.
parent
d0fba007
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
72 deletions
+20
-72
vsl_query.c
lib/libvarnishapi/vsl_query.c
+20
-72
No files found.
lib/libvarnishapi/vsl_query.c
View file @
71a5a718
...
...
@@ -53,6 +53,20 @@ struct vslq_query {
struct
vex
*
vex
;
};
#define VSLQ_TEST_NUMOP(TYPE, PRE_LHS, OP, PRE_RHS) \
switch (TYPE) { \
case VEX_INT: \
if (PRE_LHS##_int OP PRE_RHS##_int) \
return (1); \
return (0); \
case VEX_FLOAT: \
if (PRE_LHS##_float OP PRE_RHS##_float) \
return (1); \
return (0); \
default: \
WRONG("Wrong RHS type"); \
}
static
int
vslq_test_rec
(
const
struct
vex
*
vex
,
const
struct
VSLC_ptr
*
rec
)
{
...
...
@@ -100,83 +114,17 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
/* Compare */
switch
(
vex
->
tok
)
{
case
T_EQ
:
/* == */
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
==
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
==
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
==
,
rhs
->
val
);
case
T_NEQ
:
/* != */
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
!=
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
!=
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
!=
,
rhs
->
val
);
case
'<'
:
/* < */
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
<
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
<
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
<
,
rhs
->
val
);
case
'>'
:
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
>
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
>
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
>
,
rhs
->
val
);
case
T_LEQ
:
/* <= */
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
<=
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
<=
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
<=
,
rhs
->
val
);
case
T_GEQ
:
/* >= */
switch
(
rhs
->
type
)
{
case
VEX_INT
:
if
(
lhs_int
>=
rhs
->
val_int
)
return
(
1
);
return
(
0
);
case
VEX_FLOAT
:
if
(
lhs_float
>=
rhs
->
val_float
)
return
(
1
);
return
(
0
);
default:
WRONG
(
"Wrong RHS type"
);
}
VSLQ_TEST_NUMOP
(
rhs
->
type
,
lhs
,
>=
,
rhs
->
val
);
case
T_SEQ
:
/* eq */
assert
(
rhs
->
type
==
VEX_STRING
);
if
(
!
strcmp
(
lhs_string
,
rhs
->
val_string
))
...
...
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