This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add isKeyword function.
ClosedPublic

Authored by hokein on Oct 5 2020, 1:04 AM.

Details

Summary

This will be used in rename for doing basic name validation.

Diff Detail

Event Timeline

hokein created this revision.Oct 5 2020, 1:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2020, 1:04 AM
hokein requested review of this revision.Oct 5 2020, 1:04 AM
sammccall accepted this revision.Oct 5 2020, 2:00 AM
sammccall added inline comments.
clang-tools-extra/clangd/SourceCode.cpp
638

this builds a pretty decent sized hashtable for each call, because LangOpts isn't constant.

We could consider exposing getKeywordStatus from IdentifierTable.h, then we could build a StringMap<TokenKind> (once, statically) and then call getKeywordStatus to apply the per-langopts logic.
In fact that StringMap might also be generally nice to expose in TokenKinds.h... as long as there are no conflicts.

Or we could have cache map from LangOpts to IdentifierTable, since we won't see many sets in practice.

Or maybe it doesn't matter, I suppose!

clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
794

demonstrate some sensitivity to langopts?

e.g. set CPlusPlus20 to true then check co_await

This revision is now accepted and ready to land.Oct 5 2020, 2:00 AM
hokein updated this revision to Diff 296168.Oct 5 2020, 6:09 AM
hokein marked an inline comment as done.

address code comments.

clang-tools-extra/clangd/SourceCode.cpp
638

Or maybe it doesn't matter, I suppose!

this is my impression as well, there are ~120 keywords for C++, I think the number is not too big.

This revision was landed with ongoing or failed builds.Oct 5 2020, 6:12 AM
This revision was automatically updated to reflect the committed changes.