Skip to content

Commit ca55615

Browse files
committed
Space and bracket pretty-printed ternary conditionals
At the moment we get e.g. y == x == z?1:2, this changes that to y == (x == z ? 1 : 2) which makes the precedence clearer and spaces the operator more cleanly.
1 parent 9cf2bfb commit ca55615

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/util/format_expr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,9 @@ std::ostream &format_rec(std::ostream &os, const exprt &expr)
299299
else if(id == ID_if)
300300
{
301301
const auto &if_expr = to_if_expr(expr);
302-
return os << format(if_expr.cond()) << '?' << format(if_expr.true_case())
303-
<< ':' << format(if_expr.false_case());
302+
return os << "(" << format(if_expr.cond()) << " ? "
303+
<< format(if_expr.true_case()) << " : "
304+
<< format(if_expr.false_case()) << ")";
304305
}
305306
else if(id == ID_code)
306307
{

0 commit comments

Comments
 (0)