cprover
boolbv_complex.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  std::size_t width=boolbv_width(expr.type());
16 
17  if(width==0)
18  return conversion_failed(expr);
19 
21  expr.type().id() == ID_complex,
22  "complex expression shall have complex type");
23 
24  bvt bv;
25  bv.reserve(width);
26 
27  const exprt::operandst &operands = expr.operands();
28  std::size_t op_width = width / operands.size();
29 
30  forall_expr(it, operands)
31  {
32  const bvt &tmp = convert_bv(*it, op_width);
33 
34  forall_literals(it2, tmp)
35  bv.push_back(*it2);
36  }
37 
38  return bv;
39 }
40 
42 {
43  std::size_t width=boolbv_width(expr.type());
44 
45  if(width==0)
46  return conversion_failed(expr);
47 
48  bvt bv = convert_bv(expr.op(), width * 2);
49 
50  bv.resize(width); // chop
51 
52  return bv;
53 }
54 
56 {
57  std::size_t width=boolbv_width(expr.type());
58 
59  if(width==0)
60  return conversion_failed(expr);
61 
62  bvt bv = convert_bv(expr.op(), width * 2);
63 
64  bv.erase(bv.begin(), bv.begin()+width);
65 
66  return bv;
67 }
bvt
std::vector< literalt > bvt
Definition: literal.h:201
boolbvt::convert_complex
virtual bvt convert_complex(const complex_exprt &expr)
Definition: boolbv_complex.cpp:13
complex_real_exprt
Real part of the expression describing a complex number.
Definition: std_expr.h:1740
invariant.h
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::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
boolbvt::convert_complex_real
virtual bvt convert_complex_real(const complex_real_exprt &expr)
Definition: boolbv_complex.cpp:41
irept::id
const irep_idt & id() const
Definition: irep.h:418
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:55
complex_exprt
Complex constructor from a pair of numbers.
Definition: std_expr.h:1672
unary_exprt::op
const exprt & op() const
Definition: std_expr.h:281
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
complex_imag_exprt
Imaginary part of the expression describing a complex number.
Definition: std_expr.h:1785
boolbv.h
exprt::operands
operandst & operands()
Definition: expr.h:95
forall_expr
#define forall_expr(it, expr)
Definition: expr.h:29
boolbvt::convert_complex_imag
virtual bvt convert_complex_imag(const complex_imag_exprt &expr)
Definition: boolbv_complex.cpp:55