File tree 3 files changed +33
-4
lines changed
3 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -1320,17 +1320,26 @@ void smt2_convt::convert_expr(const exprt &expr)
1320
1320
else if (expr.id ()==ID_unary_minus)
1321
1321
{
1322
1322
const unary_minus_exprt &unary_minus_expr = to_unary_minus_expr (expr);
1323
+ const auto &type = expr.type ();
1323
1324
1324
1325
if (
1325
- unary_minus_expr.type ().id () == ID_rational ||
1326
- unary_minus_expr.type ().id () == ID_integer ||
1327
- unary_minus_expr.type ().id () == ID_real)
1326
+ type.id () == ID_rational || type.id () == ID_integer ||
1327
+ type.id () == ID_real)
1328
1328
{
1329
1329
out << " (- " ;
1330
1330
convert_expr (unary_minus_expr.op ());
1331
1331
out << " )" ;
1332
1332
}
1333
- else if (unary_minus_expr.type ().id () == ID_floatbv)
1333
+ else if (type.id () == ID_range)
1334
+ {
1335
+ auto &range_type = to_range_type (type);
1336
+ PRECONDITION (type == unary_minus_expr.op ().type ());
1337
+ // turn -x into 0-x
1338
+ auto minus_expr =
1339
+ minus_exprt{range_type.zero_expr (), unary_minus_expr.op ()};
1340
+ convert_expr (minus_expr);
1341
+ }
1342
+ else if (type.id () == ID_floatbv)
1334
1343
{
1335
1344
// this has no rounding mode
1336
1345
if (use_FPA_theory)
Original file line number Diff line number Diff line change @@ -165,6 +165,23 @@ void bitvector_typet::width(const mp_integer &width)
165
165
set_width (numeric_cast_v<std::size_t >(width));
166
166
}
167
167
168
+ bool range_typet::includes (const mp_integer &singleton) const
169
+ {
170
+ return get_from () <= singleton && singleton <= get_to ();
171
+ }
172
+
173
+ constant_exprt range_typet::one_expr () const
174
+ {
175
+ PRECONDITION (includes (1 ));
176
+ return constant_exprt{ID_1, *this };
177
+ }
178
+
179
+ constant_exprt range_typet::zero_expr () const
180
+ {
181
+ PRECONDITION (includes (0 ));
182
+ return constant_exprt{ID_0, *this };
183
+ }
184
+
168
185
void range_typet::set_from (const mp_integer &from)
169
186
{
170
187
set (ID_from, integer2string (from));
Original file line number Diff line number Diff line change @@ -1012,6 +1012,9 @@ class range_typet:public typet
1012
1012
1013
1013
mp_integer get_from () const ;
1014
1014
mp_integer get_to () const ;
1015
+ bool includes (const mp_integer &) const ;
1016
+ constant_exprt zero_expr () const ;
1017
+ constant_exprt one_expr () const ;
1015
1018
1016
1019
void set_from (const mp_integer &_from);
1017
1020
void set_to (const mp_integer &to);
You can’t perform that action at this time.
0 commit comments