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 @@ -2476,6 +2476,11 @@ void smt2_convt::convert_expr(const exprt &expr)
24762476 out << ' )' ;
24772477 }
24782478 }
2479+ else if (expr.id () == ID_cond)
2480+ {
2481+ // use the lowering
2482+ convert_expr (to_cond_expr (expr).lower ());
2483+ }
24792484 else
24802485 INVARIANT_WITH_DIAGNOSTICS (
24812486 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 @@ -3364,6 +3364,9 @@ class cond_exprt : public multi_ary_exprt
33643364 operands ().push_back (condition);
33653365 operands ().push_back (value);
33663366 }
3367+
3368+ // a lowering to nested if_exprt
3369+ exprt lower () const ;
33673370};
33683371
33693372template <>
You can’t perform that action at this time.
0 commit comments