-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Re-use clang's keyword enable/disable mechanism in CPlusPlusNameParser.cpp #164284
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
e1175e6
0275d00
f221e49
7af1e87
e03585e
8e0c1a7
2c7391f
af4a46f
6a80842
b836bc6
3acac96
72e9d76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,9 +719,8 @@ CPlusPlusNameParser::ParseFullNameImpl() { | |
| } | ||
| start_position.Remove(); | ||
| return result; | ||
| } else { | ||
| return std::nullopt; | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| llvm::StringRef CPlusPlusNameParser::GetTextForRange(const Range &range) { | ||
|
|
@@ -755,12 +754,19 @@ static const clang::LangOptions &GetLangOptions() { | |
| return g_options; | ||
| } | ||
|
|
||
| static const llvm::StringMap<tok::TokenKind> &GetKeywordsMap() { | ||
| static llvm::StringMap<tok::TokenKind> g_map{ | ||
| #define KEYWORD(Name, Flags) {llvm::StringRef(#Name), tok::kw_##Name}, | ||
| static const llvm::StringMap<tok::TokenKind> GetKeywordsMap() { | ||
| using namespace clang::TokenKeyEnumerators; | ||
| llvm::StringMap<tok::TokenKind> g_map; | ||
|
|
||
| auto LangOpts = GetLangOptions(); | ||
|
|
||
| clang::KeywordStatus AddResult; | ||
| #define KEYWORD(NAME, FLAGS) \ | ||
| AddResult = getKeywordStatus(LangOpts, FLAGS); \ | ||
| if (AddResult != clang::KS_Disabled) \ | ||
| g_map[llvm::StringRef(#NAME)] = tok::kw_##NAME; | ||
| #include "clang/Basic/TokenKinds.def" | ||
| #undef KEYWORD | ||
| }; | ||
| return g_map; | ||
| } | ||
|
|
||
|
|
@@ -769,7 +775,7 @@ void CPlusPlusNameParser::ExtractTokens() { | |
| return; | ||
| clang::Lexer lexer(clang::SourceLocation(), GetLangOptions(), m_text.data(), | ||
| m_text.data(), m_text.data() + m_text.size()); | ||
| const auto &kw_map = GetKeywordsMap(); | ||
| const auto kw_map = GetKeywordsMap(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit unfortunate we have to reconstruct this Why can't we construct the map statically? The
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll see if I can measure it. I doubt it's noticeable for interactive use but it might add up in scripts
At the moment they don't but I think that's a bug so I didn't add the call_once wrapper to it. I think they ought to depend on the active stack frame. For example: Along the same lines, if you have a C++20 frame call an OpenCL frame, this (admittedly contrived) example |
||
| clang::Token token; | ||
| for (lexer.LexFromRawLexer(token); !token.is(clang::tok::eof); | ||
| lexer.LexFromRawLexer(token)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the Clang changes in a separate PR. I don't think you need the
inline namespaceeither. Can we just follow the convention of the otherenums in this header?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind splitting it but that PR won't make sense without the context of this PR
The reason we need the
inline namespaceis because of this code:I can't reference
FLAGSasclang::FLAGSbecause some of theKEYWORD()declaration's in TokenKinds.def are the|of multiple values such asBOOLSUPPORT|KEYC23and I'd need the namespace to appear on each identifier.enum classis ruled out for the same reason, andenum classcombined withusing enum ...requires C++20 and therefore can't be used.inline namespaceallows lldb to import them withusing namespace ...for use as bare names without changing how clang uses themThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a huge preference. Typically we split out cross-project changes into separate PRs. It makes the area maintainers more likely to review it in time (just based filtering email subjects) and has the benefit of making the main non-NFC PR smaller. You can always just reference this PR as a motivating example.
Can't we just do
using namespace clanginside that LLDB function then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separated out the clang portion into #165323. The commits are still in this PR as it's a dependency for this to work
I've switched it to
using namespace clang. I assume lldb is generally not doing that because of name collisions and wanting to know when it's using other components but this is at least scoped to a small function so it should still be fine from that perspective