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)
2476
2476
out << ' )' ;
2477
2477
}
2478
2478
}
2479
+ else if (expr.id () == ID_cond)
2480
+ {
2481
+ // use the lowering
2482
+ convert_expr (to_cond_expr (expr).lower ());
2483
+ }
2479
2484
else
2480
2485
INVARIANT_WITH_DIAGNOSTICS (
2481
2486
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 @@ -3364,6 +3364,9 @@ class cond_exprt : public multi_ary_exprt
3364
3364
operands ().push_back (condition);
3365
3365
operands ().push_back (value);
3366
3366
}
3367
+
3368
+ // a lowering to nested if_exprt
3369
+ exprt lower () const ;
3367
3370
};
3368
3371
3369
3372
template <>
You can’t perform that action at this time.
0 commit comments