Skip to content

Space and bracket pretty-printed ternary conditionals #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Nov 28, 2018

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.

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.
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: ca55615).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92815813

<< ':' << format(if_expr.false_case());
return os << "(" << format(if_expr.cond()) << " ? "
<< format(if_expr.true_case()) << " : "
<< format(if_expr.false_case()) << ")";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use '(' etc. for the single letters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (plus two other similar changes in the same file)

@tautschnig
Copy link
Collaborator

Shouldn't we properly do precedence instead, much like expr2ct does? As is, parentheses will also be introduced when not needed.

@kroening
Copy link
Member

I would add the parentheses for any use of ?: as subexpression. Precendences can be tough for the reader when they go beyond the ones we learn in primary school.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: d4d7af4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/92978446

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to stand in the way with my (poor) taste when it comes to places parentheses ;-)

@tautschnig tautschnig merged commit 549d138 into diffblue:develop Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants