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 
14 {
15  const std::size_t width = boolbv_width(expr.type());
16  const exprt::operandst &operands = expr.operands();
17 
18  if(operands.empty() && width == 0)
19  return bvt();
20 
21  if(expr.type().id()==ID_array)
22  {
24  expr.has_operands(),
25  "the bit width being nonzero implies that the array has a nonzero size "
26  "in which case the array shall have operands");
27  const exprt::operandst &operands=expr.operands();
28  const std::size_t op_width = width / operands.size();
29 
30  bvt bv;
31  bv.reserve(width);
32 
33  forall_expr(it, operands)
34  {
35  const bvt &tmp = convert_bv(*it, op_width);
36 
37  forall_literals(it2, tmp)
38  bv.push_back(*it2);
39  }
40 
41  return bv;
42  }
43 
44  return conversion_failed(expr);
45 }
boolbv_widtht boolbv_width
Definition: boolbv.h:92
#define forall_expr(it, expr)
Definition: expr.h:31
typet & type()
Return the type of the expression.
Definition: expr.h:68
virtual const bvt & convert_bv(const exprt &expr, const optionalt< std::size_t > expected_width=nullopt)
Definition: boolbv.cpp:112
#define forall_literals(it, bv)
Definition: literal.h:202
const irep_idt & id() const
Definition: irep.h:259
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:110
bool has_operands() const
Return true if there is at least one operand.
Definition: expr.h:75
std::vector< exprt > operandst
Definition: expr.h:57
virtual bvt convert_array(const exprt &expr)
Base class for all expressions.
Definition: expr.h:54
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions, goto_programs, exprts, etc.
Definition: invariant.h:485
operandst & operands()
Definition: expr.h:78
std::vector< literalt > bvt
Definition: literal.h:200