cprover
boolbv_abs.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/std_types.h>
12 
13 #include "boolbv_type.h"
14 
15 #include "../floatbv/float_utils.h"
16 
18 {
19  std::size_t width=boolbv_width(expr.type());
20 
21  if(width==0)
22  return conversion_failed(expr);
23 
24  const exprt::operandst &operands=expr.operands();
25 
26  if(operands.size()!=1)
27  throw "abs takes one operand";
28 
29  const exprt &op0=expr.op0();
30 
31  const bvt &op_bv=convert_bv(op0);
32 
33  if(op0.type()!=expr.type())
34  return conversion_failed(expr);
35 
36  bvtypet bvtype=get_bvtype(expr.type());
37 
38  if(bvtype==bvtypet::IS_FIXED ||
39  bvtype==bvtypet::IS_SIGNED ||
40  bvtype==bvtypet::IS_UNSIGNED)
41  {
42  return bv_utils.absolute_value(op_bv);
43  }
44  else if(bvtype==bvtypet::IS_FLOAT)
45  {
46  float_utilst float_utils(prop, to_floatbv_type(expr.type()));
47  return float_utils.abs(op_bv);
48  }
49 
50  return conversion_failed(expr);
51 }
virtual bvt convert_abs(const exprt &expr)
Definition: boolbv_abs.cpp:17
bv_utilst bv_utils
Definition: boolbv.h:93
exprt & op0()
Definition: expr.h:84
boolbv_widtht boolbv_width
Definition: boolbv.h:90
typet & type()
Definition: expr.h:60
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a generic typet to a floatbv_typet.
Definition: std_types.h:1286
virtual const bvt & convert_bv(const exprt &expr)
Definition: boolbv.cpp:115
void conversion_failed(const exprt &expr, bvt &bv)
Definition: boolbv.h:108
bvt absolute_value(const bvt &op)
Definition: bv_utils.cpp:754
bvtypet get_bvtype(const typet &type)
Definition: boolbv_type.cpp:12
bvtypet
Definition: boolbv_type.h:16
std::vector< exprt > operandst
Definition: expr.h:49
API to type classes.
Base class for all expressions.
Definition: expr.h:46
bvt abs(const bvt &)
operandst & operands()
Definition: expr.h:70
std::vector< literalt > bvt
Definition: literal.h:197