Skip to content

Commit f221e49

Browse files
committed
Revert "[lldb] Re-use clang's keyword enable/disable mechanism in CPlusPlusNameParser.cpp"
This is just to allow me to separate the clang and lldb parts without breaking the github PR's comment history
1 parent 0275d00 commit f221e49

File tree

3 files changed

+59
-63
lines changed

3 files changed

+59
-63
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,55 +46,6 @@ class LangOptions;
4646
class MultiKeywordSelector;
4747
class SourceLocation;
4848

49-
enum TokenKey : unsigned {
50-
KEYC99 = 0x1,
51-
KEYCXX = 0x2,
52-
KEYCXX11 = 0x4,
53-
KEYGNU = 0x8,
54-
KEYMS = 0x10,
55-
BOOLSUPPORT = 0x20,
56-
KEYALTIVEC = 0x40,
57-
KEYNOCXX = 0x80,
58-
KEYBORLAND = 0x100,
59-
KEYOPENCLC = 0x200,
60-
KEYC23 = 0x400,
61-
KEYNOMS18 = 0x800,
62-
KEYNOOPENCL = 0x1000,
63-
WCHARSUPPORT = 0x2000,
64-
HALFSUPPORT = 0x4000,
65-
CHAR8SUPPORT = 0x8000,
66-
KEYOBJC = 0x10000,
67-
KEYZVECTOR = 0x20000,
68-
KEYCOROUTINES = 0x40000,
69-
KEYMODULES = 0x80000,
70-
KEYCXX20 = 0x100000,
71-
KEYOPENCLCXX = 0x200000,
72-
KEYMSCOMPAT = 0x400000,
73-
KEYSYCL = 0x800000,
74-
KEYCUDA = 0x1000000,
75-
KEYZOS = 0x2000000,
76-
KEYNOZOS = 0x4000000,
77-
KEYHLSL = 0x8000000,
78-
KEYFIXEDPOINT = 0x10000000,
79-
KEYMAX = KEYFIXEDPOINT, // The maximum key
80-
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
81-
KEYALL = (KEYMAX | (KEYMAX - 1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
82-
~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are excluded.
83-
};
84-
85-
/// How a keyword is treated in the selected standard. This enum is ordered
86-
/// intentionally so that the value that 'wins' is the most 'permissive'.
87-
enum KeywordStatus {
88-
KS_Unknown, // Not yet calculated. Used when figuring out the status.
89-
KS_Disabled, // Disabled
90-
KS_Future, // Is a keyword in future standard
91-
KS_Extension, // Is an extension
92-
KS_Enabled, // Enabled
93-
};
94-
95-
KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
96-
unsigned Flags);
97-
9849
enum class ReservedIdentifierStatus {
9950
NotReserved = 0,
10051
StartsWithUnderscoreAtGlobalScope,

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,57 @@ IdentifierTable::IdentifierTable(const LangOptions &LangOpts,
7777
// Language Keyword Implementation
7878
//===----------------------------------------------------------------------===//
7979

80+
// Constants for TokenKinds.def
81+
namespace {
82+
83+
enum TokenKey : unsigned {
84+
KEYC99 = 0x1,
85+
KEYCXX = 0x2,
86+
KEYCXX11 = 0x4,
87+
KEYGNU = 0x8,
88+
KEYMS = 0x10,
89+
BOOLSUPPORT = 0x20,
90+
KEYALTIVEC = 0x40,
91+
KEYNOCXX = 0x80,
92+
KEYBORLAND = 0x100,
93+
KEYOPENCLC = 0x200,
94+
KEYC23 = 0x400,
95+
KEYNOMS18 = 0x800,
96+
KEYNOOPENCL = 0x1000,
97+
WCHARSUPPORT = 0x2000,
98+
HALFSUPPORT = 0x4000,
99+
CHAR8SUPPORT = 0x8000,
100+
KEYOBJC = 0x10000,
101+
KEYZVECTOR = 0x20000,
102+
KEYCOROUTINES = 0x40000,
103+
KEYMODULES = 0x80000,
104+
KEYCXX20 = 0x100000,
105+
KEYOPENCLCXX = 0x200000,
106+
KEYMSCOMPAT = 0x400000,
107+
KEYSYCL = 0x800000,
108+
KEYCUDA = 0x1000000,
109+
KEYZOS = 0x2000000,
110+
KEYNOZOS = 0x4000000,
111+
KEYHLSL = 0x8000000,
112+
KEYFIXEDPOINT = 0x10000000,
113+
KEYMAX = KEYFIXEDPOINT, // The maximum key
114+
KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
115+
KEYALL = (KEYMAX | (KEYMAX - 1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
116+
~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are excluded.
117+
};
118+
119+
/// How a keyword is treated in the selected standard. This enum is ordered
120+
/// intentionally so that the value that 'wins' is the most 'permissive'.
121+
enum KeywordStatus {
122+
KS_Unknown, // Not yet calculated. Used when figuring out the status.
123+
KS_Disabled, // Disabled
124+
KS_Future, // Is a keyword in future standard
125+
KS_Extension, // Is an extension
126+
KS_Enabled, // Enabled
127+
};
128+
129+
} // namespace
130+
80131
// This works on a single TokenKey flag and checks the LangOpts to get the
81132
// KeywordStatus based exclusively on this flag, so that it can be merged in
82133
// getKeywordStatus. Most should be enabled/disabled, but some might imply
@@ -171,7 +222,7 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
171222

172223
/// Translates flags as specified in TokenKinds.def into keyword status
173224
/// in the given language standard.
174-
KeywordStatus clang::getKeywordStatus(const LangOptions &LangOpts,
225+
static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,
175226
unsigned Flags) {
176227
// KEYALL means always enabled, so special case this one.
177228
if (Flags == KEYALL) return KS_Enabled;

lldb/source/Plugins/Language/CPlusPlus/CPlusPlusNameParser.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,9 @@ CPlusPlusNameParser::ParseFullNameImpl() {
719719
}
720720
start_position.Remove();
721721
return result;
722+
} else {
723+
return std::nullopt;
722724
}
723-
return std::nullopt;
724725
}
725726

726727
llvm::StringRef CPlusPlusNameParser::GetTextForRange(const Range &range) {
@@ -754,19 +755,12 @@ static const clang::LangOptions &GetLangOptions() {
754755
return g_options;
755756
}
756757

757-
static const llvm::StringMap<tok::TokenKind> GetKeywordsMap() {
758-
using namespace clang;
759-
llvm::StringMap<tok::TokenKind> g_map;
760-
761-
auto LangOpts = GetLangOptions();
762-
763-
KeywordStatus AddResult;
764-
#define KEYWORD(NAME, FLAGS) \
765-
AddResult = getKeywordStatus(LangOpts, FLAGS); \
766-
if (AddResult != KS_Disabled) \
767-
g_map[llvm::StringRef(#NAME)] = tok::kw_##NAME;
758+
static const llvm::StringMap<tok::TokenKind> &GetKeywordsMap() {
759+
static llvm::StringMap<tok::TokenKind> g_map{
760+
#define KEYWORD(Name, Flags) {llvm::StringRef(#Name), tok::kw_##Name},
768761
#include "clang/Basic/TokenKinds.def"
769762
#undef KEYWORD
763+
};
770764
return g_map;
771765
}
772766

@@ -775,7 +769,7 @@ void CPlusPlusNameParser::ExtractTokens() {
775769
return;
776770
clang::Lexer lexer(clang::SourceLocation(), GetLangOptions(), m_text.data(),
777771
m_text.data(), m_text.data() + m_text.size());
778-
const auto kw_map = GetKeywordsMap();
772+
const auto &kw_map = GetKeywordsMap();
779773
clang::Token token;
780774
for (lexer.LexFromRawLexer(token); !token.is(clang::tok::eof);
781775
lexer.LexFromRawLexer(token)) {

0 commit comments

Comments
 (0)