This is an archive of the discontinued LLVM Phabricator instance.

Keep the IdentifierInfo in the Token for alternative operator keyword
ClosedPublic

Authored by ogoffart on Jul 8 2017, 11:20 AM.

Details

Summary

The goal of this commit is to fix clang-format so it does not merge tokens when
using the alternative spelling keywords. (eg: "not foo" should not become "notfoo")

The problem is that Preprocessor::HandleIdentifier used to drop the identifier info
from the token for these keyword. This means the first condition of
TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for
the spelling in that condition, but I think it is better to keep the IdentifierInfo
and handle the operator keyword explicitly when needed. That actually leads to simpler
code, and probably slightly more efficient as well.

Another side effect of this change is that __identifier(and) will now work as
one would expect, removing a FIXME from the MicrosoftExtensions.cpp test

Diff Detail

Repository
rL LLVM

Event Timeline

ogoffart created this revision.Jul 8 2017, 11:20 AM
ogoffart edited the summary of this revision. (Show Details)Jul 8 2017, 2:17 PM
erichkeane edited edge metadata.

My interaction with this is as a submitter for Melanie, so hopefully she can validate that this doesn't break anything subtle. To me it DOES seem like a good approach, however Richard likely has a better idea about it, so I want to give him a bit of time before accepting.

rsmith edited edge metadata.Jul 9 2017, 7:03 PM

It looks like there are fewer special cases with this direction then our present one, though I worry that they'll be less obvious. On the whole, this seems like a improvement.

lib/Lex/PPExpressions.cpp
242 ↗(On Diff #105744)

I'm concerned that this will do the wrong thing for a keyword operator that is not permitted in a pp expression, like and_eq. It seems safer to revert this change and instead add a isCPlusPlusOperatorKeyword check to the "if" condition above.

ogoffart marked an inline comment as done.Jul 10 2017, 12:44 AM
ogoffart added inline comments.
lib/Lex/PPExpressions.cpp
242 ↗(On Diff #105744)

Well spotted. I kept this code in the default: so true and false are handled separatly, but added a condition for isCPlusPlusOperatorKeyword, and an additional test.

ogoffart updated this revision to Diff 105815.Jul 10 2017, 12:46 AM
ogoffart marked an inline comment as done.

Added check for "#if and_eq"

ogoffart updated this revision to Diff 105816.Jul 10 2017, 12:50 AM
This revision was automatically updated to reflect the committed changes.