This is an archive of the discontinued LLVM Phabricator instance.

[clang][lexer] adds a way for tokens to track their physical spelling
AbandonedPublic

Authored by cjdb on Aug 2 2021, 9:54 AM.

Details

Reviewers
aaron.ballman
Summary

Tokens don't currently have a way to track their source-based spelling,
which makes implementing some warnings difficult.

This patch is the basis for two independent warnings, and should be
a non-functional change.

Diff Detail

Event Timeline

cjdb requested review of this revision.Aug 2 2021, 9:54 AM
cjdb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2021, 9:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

A few questions, also for @aaron.ballman

Can we have a "isDigraph" flag instead of keeping a pointer for the spelling?

Do we maybe want to promote and etc to proper keywords and maybe add functions to check isAndOrAmpAmp ? so that we can in the future make void f(auto and) ill-formed in the committee?
This second solution is more long term and maybe the patch is good enough as an intermediate step

clang/lib/Lex/Lexer.cpp
3594

Did you intend to remove these?

You should always be able to go back to the token's spelling through the SourceManager object. Is there a reason why SourceManager::getCharacterData() is insufficient? I'm a bit worried about adding another pointer to Token because we sometimes store these in containers (like we do for cached tokens), so the overhead might be noticeable (or it might not, I don't know).

cjdb abandoned this revision.Aug 2 2021, 11:14 AM

You should always be able to go back to the token's spelling through the SourceManager object. Is there a reason why SourceManager::getCharacterData() is insufficient? I'm a bit worried about adding another pointer to Token because we sometimes store these in containers (like we do for cached tokens), so the overhead might be noticeable (or it might not, I don't know).

I found it very strange that there wasn't already a way for me to do this. Thanks, I've abandoned this patch and will adjust the dependents accordingly.