CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boolbv_array_of.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: 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
17{
19 expr.type().id() == ID_array, "array_of expression shall have array type");
20
21 const array_typet &array_type = expr.type();
22
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
33
34 const bvt &tmp = convert_bv(expr.what());
35
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}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
Array constructor from single element.
Definition std_expr.h:1558
const array_typet & type() const
Definition std_expr.h:1565
exprt & what()
Definition std_expr.h:1575
Arrays with given size.
Definition std_types.h:807
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:39
bool is_unbounded_array(const typet &type) const override
Definition boolbv.cpp:538
virtual bvt convert_array_of(const array_of_exprt &expr)
Flatten arrays constructed from a single element.
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:94
virtual std::size_t boolbv_width(const typet &type) const
Definition boolbv.h:103
Base class for all expressions.
Definition expr.h:56
std::vector< literalt > bvt
Definition literal.h:201
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition invariant.h:534
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
Definition std_expr.h:3172
Pre-defined types.