CBMC
expr_query.h
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Unit test utilities
4
5
Author: Romain Brenguier, romain.brenguier@diffblue.com
6
7
\*******************************************************************/
8
12
13
#ifndef CPROVER_TESTING_UTILS_EXPR_QUERY_H
14
#define CPROVER_TESTING_UTILS_EXPR_QUERY_H
15
16
#include <
testing-utils/use_catch.h
>
17
18
#include <
util/expr_cast.h
>
19
22
template
<
typename
T = exprt>
23
class
expr_queryt
24
{
25
static_assert(
26
std::is_base_of<exprt, T>::value,
27
"T should inherit from exprt"
);
28
29
public
:
30
explicit
expr_queryt
(T e) :
value
(std::move(e))
31
{
32
}
33
34
template
<
typename
targett>
35
expr_queryt<targett>
as
()
const
36
{
37
auto
result = expr_try_dynamic_cast<targett>(
static_cast<
exprt
>
(
value
));
38
REQUIRE(result);
39
return
expr_queryt<targett>
(*result);
40
}
41
42
expr_queryt<exprt>
operator[]
(
const
std::size_t i)
const
43
{
44
REQUIRE(
value
.operands().size() > i);
45
return
expr_queryt<exprt>
(
value
.operands()[i]);
46
}
47
48
T
get
()
const
49
{
50
return
value
;
51
}
52
53
private
:
54
T
value
;
55
};
56
57
inline
expr_queryt<exprt>
make_query
(
exprt
e)
58
{
59
return
expr_queryt<exprt>
(std::move(e));
60
}
61
62
#endif // CPROVER_TESTING_UTILS_EXPR_QUERY_H
make_query
expr_queryt< exprt > make_query(exprt e)
Definition:
expr_query.h:57
exprt
Base class for all expressions.
Definition:
expr.h:55
expr_queryt::get
T get() const
Definition:
expr_query.h:48
expr_queryt::as
expr_queryt< targett > as() const
Definition:
expr_query.h:35
expr_queryt::operator[]
expr_queryt< exprt > operator[](const std::size_t i) const
Definition:
expr_query.h:42
expr_queryt
Wrapper for optionalt<exprt> with useful method for queries to be used in unit tests.
Definition:
expr_query.h:23
use_catch.h
expr_cast.h
Templated functions to cast to specific exprt-derived classes.
expr_queryt::value
T value
Definition:
expr_query.h:54
expr_queryt::expr_queryt
expr_queryt(T e)
Definition:
expr_query.h:30
unit
testing-utils
expr_query.h
Generated by
1.8.17