This is an archive of the discontinued LLVM Phabricator instance.

Formatter: Get bit tests in ifs right, such as "if (a & b)"
ClosedPublic

Authored by thakis on Jan 16 2013, 9:05 PM.

Details

Reviewers
djasper
Summary

It's generally not possible to know if 'a' '*' 'b' is a multiplication expression or a variable declaration with a purely lexer-based approach. The formatter currently uses a heuristic that classifies this token sequence as a multiplication in rhs contexts (after '=' or 'return') and as a declaration else.

Because of this, it gets bit tests in ifs, such as "if (a & b)" wrong. However, declarations in ifs always have to be followed by '=', so this patch changes the formatter to classify '&' as an operator if it's at the start of an if statement.

Diff Detail

Event Timeline

thakis updated this revision to Unknown Object (????).Jan 16 2013, 9:08 PM

(comment fix)

thakis updated this revision to Unknown Object (????).Jan 16 2013, 9:09 PM

(comment fix for real, hopefully)

djasper accepted this revision.Jan 17 2013, 8:54 AM

This looks good in general. In future, we will want to extend this e.g. if we know that we are in a call expression..

thakis closed this revision.Jan 17 2013, 9:18 AM

r172731, thanks!