cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
enum_encoding.cpp
Go to the documentation of this file.
1
// Author: Diffblue Ltd.
2
3
#include "
enum_encoding.h
"
4
5
#include <
util/c_types.h
>
6
#include <
util/expr_cast.h
>
7
#include <
util/namespace.h
>
8
9
#include <queue>
10
11
// Internal function to lower inner types of compound types (at the moment only
12
// arrays)
13
static
typet
encode
(
typet
type,
const
namespacet
&ns)
14
{
15
std::queue<typet *> work_queue;
16
work_queue.push(&type);
17
while
(!work_queue.empty())
18
{
19
typet
¤t = *work_queue.front();
20
work_queue.pop();
21
if
(
const
auto
c_enum_tag =
type_try_dynamic_cast<c_enum_tag_typet>
(current))
22
{
23
// Replace the type of the c_enum_tag with the underlying type of the enum
24
// it points to
25
current = ns.
follow_tag
(*c_enum_tag).underlying_type();
26
}
27
if
(
const
auto
array =
type_try_dynamic_cast<array_typet>
(current))
28
{
29
// Add the type of the array's elements to the queue to be explored
30
work_queue.push(&array->element_type());
31
}
32
}
33
return
type;
34
}
35
36
// Worklist algorithm to lower enum types of expr and its sub-expressions.
37
exprt
lower_enum
(
exprt
expr,
const
namespacet
&ns)
38
{
39
std::queue<exprt *> work_queue;
40
work_queue.push(&expr);
41
while
(!work_queue.empty())
42
{
43
exprt
¤t = *work_queue.front();
44
work_queue.pop();
45
46
// Replace the type of the expression node with the encoded one
47
current.
type
() =
encode
(current.
type
(), ns);
48
49
for
(
auto
&operand : current.
operands
())
50
work_queue.push(&operand);
51
}
52
return
expr;
53
}
c_types.h
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
namespace_baset::follow_tag
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition
namespace.cpp:49
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
typet
The type of an expression, extends irept.
Definition
type.h:29
encode
static typet encode(typet type, const namespacet &ns)
Definition
enum_encoding.cpp:13
lower_enum
exprt lower_enum(exprt expr, const namespacet &ns)
Function to lower expr and its sub-expressions containing enum types.
Definition
enum_encoding.cpp:37
enum_encoding.h
expr_cast.h
Templated functions to cast to specific exprt-derived classes.
type_try_dynamic_cast
auto type_try_dynamic_cast(TType &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TType >::type
Try to cast a reference to a generic typet to a specific derived class.
Definition
expr_cast.h:135
namespace.h
solvers
smt2_incremental
encoding
enum_encoding.cpp
Generated by
1.17.0