cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_struct.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module:
4
5
Author: Daniel Kroening, kroening@kroening.com
6
7
\*******************************************************************/
8
9
#include "
boolbv.h
"
10
11
#include <
util/namespace.h
>
12
13
bvt
boolbvt::convert_struct
(
const
struct_exprt
&expr)
14
{
15
const
struct_typet
&struct_type =
16
expr.
type
().
id
() == ID_struct_tag
17
?
ns
.follow_tag(
to_struct_tag_type
(expr.
type
()))
18
:
to_struct_type
(expr.
type
());
19
20
std::size_t width=
boolbv_width
(struct_type);
21
22
const
struct_typet::componentst
&components=struct_type.
components
();
23
24
DATA_INVARIANT_WITH_DIAGNOSTICS
(
25
expr.
operands
().size() == components.size(),
26
"number of operands of a struct expression shall equal the number of"
27
"components as indicated by its type"
,
28
expr.
find_source_location
());
29
30
bvt
bv;
31
bv.resize(width);
32
33
std::size_t bit_idx = 0;
34
35
exprt::operandst::const_iterator op_it=expr.
operands
().begin();
36
for
(
const
auto
&comp : components)
37
{
38
const
typet
&subtype=comp.type();
39
const
exprt
&op=*op_it;
40
41
DATA_INVARIANT_WITH_DIAGNOSTICS
(
42
subtype == op.
type
(),
43
"type of a struct expression operand shall equal the type of the "
44
"corresponding struct component"
,
45
expr.
find_source_location
(),
46
subtype.
pretty
(),
47
op.
type
().
pretty
());
48
49
std::size_t subtype_width=
boolbv_width
(subtype);
50
51
if
(subtype_width!=0)
52
{
53
const
bvt
&op_bv =
convert_bv
(op, subtype_width);
54
55
INVARIANT
(
56
bit_idx + op_bv.size() <= width,
"bit index shall be within bounds"
);
57
58
for
(
const
auto
&bit : op_bv)
59
{
60
bv[bit_idx] = bit;
61
bit_idx++;
62
}
63
}
64
65
++op_it;
66
}
67
68
INVARIANT
(
69
bit_idx == width,
"all bits in the bitvector shall have been assigned"
);
70
71
return
bv;
72
}
boolbv.h
arrayst::ns
const namespacet & ns
Definition
arrays.h:63
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const std::optional< std::size_t > expected_width={})
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition
boolbv.cpp:40
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition
boolbv.h:106
boolbvt::convert_struct
virtual bvt convert_struct(const struct_exprt &expr)
Definition
boolbv_struct.cpp:13
exprt
Base class for all expressions.
Definition
expr.h:57
exprt::find_source_location
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition
expr.cpp:68
exprt::type
typet & type()
Return the type of the expression.
Definition
expr.h:85
exprt::operands
operandst & operands()
Definition
expr.h:95
irept::pretty
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Definition
irep.cpp:482
irept::id
const irep_idt & id() const
Definition
irep.h:388
struct_exprt
Struct constructor from list of elements.
Definition
std_expr.h:1810
struct_typet
Structure type, corresponds to C style structs.
Definition
std_types.h:231
struct_union_typet::components
const componentst & components() const
Definition
std_types.h:147
struct_union_typet::componentst
std::vector< componentt > componentst
Definition
std_types.h:140
typet
The type of an expression, extends irept.
Definition
type.h:29
bvt
std::vector< literalt > bvt
Definition
literal.h:201
namespace.h
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
DATA_INVARIANT_WITH_DIAGNOSTICS
#define DATA_INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Definition
invariant.h:535
to_struct_type
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
Definition
std_types.h:308
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition
std_types.h:518
solvers
flattening
boolbv_struct.cpp
Generated by
1.17.0