CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
expr_query.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Unit test utilities
4
5Author: 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
17
18#include <util/expr_cast.h>
19
22template <typename T = exprt>
24{
25 static_assert(
26 std::is_base_of<exprt, T>::value,
27 "T should inherit from exprt");
28
29public:
30 explicit expr_queryt(T e) : value(std::move(e))
31 {
32 }
33
34 template <typename targett>
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
53private:
55};
56
58{
59 return expr_queryt<exprt>(std::move(e));
60}
61
62#endif // CPROVER_TESTING_UTILS_EXPR_QUERY_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Wrapper for std::optional<exprt> with useful method for queries to be used in unit tests.
Definition expr_query.h:24
T get() const
Definition expr_query.h:48
expr_queryt(T e)
Definition expr_query.h:30
expr_queryt< targett > as() const
Definition expr_query.h:35
expr_queryt< exprt > operator[](const std::size_t i) const
Definition expr_query.h:42
Base class for all expressions.
Definition expr.h:56
Templated functions to cast to specific exprt-derived classes.
expr_queryt< exprt > make_query(exprt e)
Definition expr_query.h:57
STL namespace.