CBMC
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  for(const auto &op : operands)
36  {
37  const bvt &tmp = convert_bv(op, op_width);
38 
39  bv.insert(bv.end(), tmp.begin(), tmp.end());
40  }
41 
42  return bv;
43  }
44 
45  return conversion_failed(expr);
46 }
virtual bvt convert_array(const exprt &expr)
Flatten array.
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
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:102
Base class for all expressions.
Definition: expr.h:56
std::vector< exprt > operandst
Definition: expr.h:58
bool has_operands() const
Return true if there is at least one operand.
Definition: expr.h:91
typet & type()
Return the type of the expression.
Definition: expr.h:84
operandst & operands()
Definition: expr.h:94
const irep_idt & id() const
Definition: irep.h:388
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