File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -2490,6 +2490,11 @@ void smt2_convt::convert_expr(const exprt &expr)
2490
2490
out << ' )' ;
2491
2491
}
2492
2492
}
2493
+ else if (expr.id () == ID_cond)
2494
+ {
2495
+ // use the lowering
2496
+ convert_expr (to_cond_expr (expr).lower ());
2497
+ }
2493
2498
else
2494
2499
INVARIANT_WITH_DIAGNOSTICS (
2495
2500
false ,
Original file line number Diff line number Diff line change @@ -260,3 +260,32 @@ exprt binding_exprt::instantiate(const variablest &new_variables) const
260
260
values.push_back (new_variable);
261
261
return instantiate (values);
262
262
}
263
+
264
+ exprt cond_exprt::lower () const
265
+ {
266
+ INVARIANT (
267
+ operands ().size () % 2 == 0 , " cond must have even number of operands" );
268
+
269
+ exprt result = nil_exprt ();
270
+
271
+ auto &operands = this ->operands ();
272
+
273
+ // functional version -- go backwards
274
+ for (std::size_t i = operands.size (); i != 0 ; i -= 2 )
275
+ {
276
+ INVARIANT (
277
+ i >= 2 ,
278
+ " since the number of operands is even if i is nonzero it must be "
279
+ " greater than two" );
280
+
281
+ const exprt &cond = operands[i - 2 ];
282
+ const exprt &value = operands[i - 1 ];
283
+
284
+ if (result.is_nil ())
285
+ result = value;
286
+ else
287
+ result = if_exprt{cond, value, std::move (result)};
288
+ }
289
+
290
+ return result;
291
+ }
Original file line number Diff line number Diff line change @@ -3491,6 +3491,9 @@ class cond_exprt : public multi_ary_exprt
3491
3491
operands ().push_back (condition);
3492
3492
operands ().push_back (value);
3493
3493
}
3494
+
3495
+ // a lowering to nested if_exprt
3496
+ exprt lower () const ;
3494
3497
};
3495
3498
3496
3499
template <>
You can’t perform that action at this time.
0 commit comments