cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
boolbv_array_of.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/arith_tools.h
>
12
#include <
util/invariant.h
>
13
#include <
util/std_types.h
>
14
16
bvt
boolbvt::convert_array_of
(
const
array_of_exprt
&expr)
17
{
18
DATA_INVARIANT
(
19
expr.
type
().
id
() == ID_array,
"array_of expression shall have array type"
);
20
21
const
array_typet
&array_type = expr.
type
();
22
23
if
(
is_unbounded_array
(array_type))
24
return
conversion_failed
(expr);
25
26
std::size_t width=
boolbv_width
(array_type);
27
if
(width == 0)
28
return
bvt
{};
29
30
const
exprt
&array_size=array_type.
size
();
31
32
const
auto
size =
numeric_cast_v<mp_integer>
(
to_constant_expr
(array_size));
33
34
const
bvt
&tmp =
convert_bv
(expr.
what
());
35
36
INVARIANT
(
37
size * tmp.size() == width,
38
"total array bit width shall equal the number of elements times the "
39
"element bit with"
);
40
41
bvt
bv;
42
bv.resize(width);
43
44
auto
b_it = tmp.begin();
45
46
for
(
auto
&b : bv)
47
{
48
b = *b_it;
49
50
b_it++;
51
52
if
(b_it == tmp.end())
53
b_it = tmp.begin();
54
}
55
56
return
bv;
57
}
arith_tools.h
numeric_cast_v
Target numeric_cast_v(const mp_integer &arg)
Convert an mp_integer to integral type Target An invariant will fail if the conversion is not possibl...
Definition
arith_tools.h:135
boolbv.h
array_of_exprt
Array constructor from single element.
Definition
std_expr.h:1502
array_of_exprt::type
const array_typet & type() const
Definition
std_expr.h:1509
array_of_exprt::what
exprt & what()
Definition
std_expr.h:1519
array_typet
Arrays with given size.
Definition
std_types.h:807
array_typet::size
const exprt & size() const
Definition
std_types.h:840
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::is_unbounded_array
bool is_unbounded_array(const typet &type) const override
Definition
boolbv.cpp:543
boolbvt::convert_array_of
virtual bvt convert_array_of(const array_of_exprt &expr)
Flatten arrays constructed from a single element.
Definition
boolbv_array_of.cpp:16
boolbvt::conversion_failed
bvt conversion_failed(const exprt &expr)
Print that the expression of x has failed conversion, then return a vector of x's width.
Definition
boolbv.cpp:95
boolbvt::boolbv_width
virtual std::size_t boolbv_width(const typet &type) const
Definition
boolbv.h:106
exprt
Base class for all expressions.
Definition
expr.h:57
irept::id
const irep_idt & id() const
Definition
irep.h:388
bvt
std::vector< literalt > bvt
Definition
literal.h:201
invariant.h
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition
invariant.h:534
INVARIANT
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition
invariant.h:423
to_constant_expr
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
Definition
std_expr.h:3068
std_types.h
Pre-defined types.
solvers
flattening
boolbv_array_of.cpp
Generated by
1.17.0