Go to the documentation of this file.
19 expr.
id() == ID_plus || expr.
id() == ID_minus ||
20 expr.
id() ==
"no-overflow-plus" || expr.
id() ==
"no-overflow-minus");
24 if(type.
id()!=ID_unsignedbv &&
25 type.
id()!=ID_signedbv &&
26 type.
id()!=ID_fixedbv &&
27 type.
id()!=ID_floatbv &&
28 type.
id()!=ID_range &&
29 type.
id()!=ID_complex &&
42 "operator " + expr.
id_string() +
" takes at least one operand");
46 op0.
type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
50 bool subtract=(expr.
id()==ID_minus ||
51 expr.
id()==
"no-overflow-minus");
53 bool no_overflow=(expr.
id()==
"no-overflow-plus" ||
54 expr.
id()==
"no-overflow-minus");
56 typet arithmetic_type =
57 (type.
id() == ID_vector || type.
id() == ID_complex) ? type.
subtype() : type;
60 (arithmetic_type.
id()==ID_signedbv ||
64 for(exprt::operandst::const_iterator
65 it=operands.begin()+1;
66 it!=operands.end(); it++)
69 it->type() == type,
"add/sub with mixed types:\n" + expr.
pretty());
73 if(type.
id()==ID_vector || type.
id()==ID_complex)
77 INVARIANT(sub_width != 0,
"vector elements shall have nonzero bit width");
79 width % sub_width == 0,
80 "total vector bit width shall be a multiple of the element bit width");
82 std::size_t size=width/sub_width;
85 for(std::size_t i=0; i<size; i++)
88 tmp_op.resize(sub_width);
90 for(std::size_t j=0; j<tmp_op.size(); j++)
92 const std::size_t index = i * sub_width + j;
93 INVARIANT(index < op.size(),
"bit index shall be within bounds");
94 tmp_op[j] = op[index];
98 tmp_result.resize(sub_width);
100 for(std::size_t j=0; j<tmp_result.size(); j++)
102 const std::size_t index = i * sub_width + j;
103 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
104 tmp_result[j] = bv[index];
111 tmp_result=float_utils.
add_sub(tmp_result, tmp_op, subtract);
117 tmp_result.size() == sub_width,
118 "applying the add/sub operation shall not change the bitwidth");
120 for(std::size_t j=0; j<tmp_result.size(); j++)
122 const std::size_t index = i * sub_width + j;
123 INVARIANT(index < bv.size(),
"bit index shall be within bounds");
124 bv[index] = tmp_result[j];
128 else if(type.
id()==ID_floatbv)
132 bv=float_utils.
add_sub(bv, op, subtract);
const typet & subtype() const
virtual bvt add_sub(const bvt &src1, const bvt &src2, bool subtract)
The type of an expression, extends irept.
std::vector< literalt > bvt
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
Base class for all expressions.
virtual bvt convert_add_sub(const exprt &expr)
typet & type()
Return the type of the expression.
boolbv_widtht boolbv_width
void conversion_failed(const exprt &expr, bvt &bv)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
const std::string & id_string() const
const irep_idt & id() const
std::vector< exprt > operandst
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...
bvt add_sub(const bvt &op0, const bvt &op1, bool subtract)
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
bvt add_sub_no_overflow(const bvt &op0, const bvt &op1, bool subtract, representationt rep)
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.