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)
24902490 out << ' )' ;
24912491 }
24922492 }
2493+ else if (expr.id () == ID_cond)
2494+ {
2495+ // use the lowering
2496+ convert_expr (to_cond_expr (expr).lower ());
2497+ }
24932498 else
24942499 INVARIANT_WITH_DIAGNOSTICS (
24952500 false ,
Original file line number Diff line number Diff line change @@ -260,3 +260,32 @@ exprt binding_exprt::instantiate(const variablest &new_variables) const
260260 values.push_back (new_variable);
261261 return instantiate (values);
262262}
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
34913491 operands ().push_back (condition);
34923492 operands ().push_back (value);
34933493 }
3494+
3495+ // a lowering to nested if_exprt
3496+ exprt lower () const ;
34943497};
34953498
34963499template <>
You can’t perform that action at this time.
0 commit comments