cprover
boolbv_array.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/invariant.h>
12 
17 {
18  const std::size_t width = boolbv_width(expr.type());
19  const exprt::operandst &operands = expr.operands();
20 
21  if(operands.empty() && width == 0)
22  return bvt();
23 
24  if(expr.type().id()==ID_array)
25  {
27  expr.has_operands(),
28  "the bit width being nonzero implies that the array has a nonzero size "
29  "in which case the array shall have operands");
30  const std::size_t op_width = width / operands.size();
31 
32  bvt bv;
33  bv.reserve(width);
34 
35  forall_expr(it, operands)
36  {
37  const bvt &tmp = convert_bv(*it, op_width);
38 
39  forall_literals(it2, tmp)
40  bv.push_back(*it2);
41  }
42 
43  return bv;
44  }
45 
46  return conversion_failed(expr);
47 }
bvt
std::vector< literalt > bvt
Definition: literal.h:201
invariant.h
exprt
Base class for all expressions.
Definition: expr.h:53
forall_literals
#define forall_literals(it, bv)
Definition: literal.h:203
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
boolbvt::convert_array
virtual bvt convert_array(const exprt &expr)
Flatten array.
Definition: boolbv_array.cpp:16
boolbvt::boolbv_width
boolbv_widtht boolbv_width
Definition: boolbv.h:95
boolbvt::conversion_failed
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:113
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:511
exprt::has_operands
bool has_operands() const
Return true if there is at least one operand.
Definition: expr.h:92
irept::id
const irep_idt & id() const
Definition: irep.h:418
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:55
boolbvt::convert_bv
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Convert expression to vector of literalts, using an internal cache to speed up conversion if availabl...
Definition: boolbv.cpp:119
boolbv.h
exprt::operands
operandst & operands()
Definition: expr.h:95
forall_expr
#define forall_expr(it, expr)
Definition: expr.h:29