Skip to content

Commit 549d138

Browse files
authored
Merge pull request #3474 from smowton/smowton/feature/improve-ternary-printing
Space and bracket pretty-printed ternary conditionals
2 parents a6e0660 + d4d7af4 commit 549d138

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/util/format_expr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ std::ostream &format_rec(std::ostream &os, const exprt &expr)
241241
id == ID_byte_extract_little_endian || id == ID_byte_extract_big_endian)
242242
{
243243
const auto &byte_extract_expr = to_byte_extract_expr(expr);
244-
return os << id << "(" << format(byte_extract_expr.op()) << ", "
244+
return os << id << '(' << format(byte_extract_expr.op()) << ", "
245245
<< format(byte_extract_expr.offset()) << ", "
246246
<< format(byte_extract_expr.type()) << ')';
247247
}
248248
else if(id == ID_byte_update_little_endian || id == ID_byte_update_big_endian)
249249
{
250250
const auto &byte_update_expr = to_byte_update_expr(expr);
251-
return os << id << "(" << format(byte_update_expr.op()) << ", "
251+
return os << id << '(' << format(byte_update_expr.op()) << ", "
252252
<< format(byte_update_expr.offset()) << ", "
253253
<< format(byte_update_expr.value()) << ", "
254254
<< format(byte_update_expr.type()) << ')';
@@ -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)