Skip to content

Commit 7af1e87

Browse files
committed
[clang] Refactor clang's keyword enable/disable mechanism to allow lldb to re-use it
lldb's CPlusPlusNameParser is currently identifying keywords using it's own map implemented using clang/Basic/TokenKinds.def. However, it does not respect the language options so identifiers can incorrectly determined to be keywords when using languages in which they are not keywords. Rather than implement the logic to enable/disable keywords in both projects it makes sense for lldb to use clang's implementation. See #164284 for more information
1 parent f221e49 commit 7af1e87

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,55 @@ 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+
4998
enum class ReservedIdentifierStatus {
5099
NotReserved = 0,
51100
StartsWithUnderscoreAtGlobalScope,

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -77,57 +77,6 @@ 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-
13180
// This works on a single TokenKey flag and checks the LangOpts to get the
13281
// KeywordStatus based exclusively on this flag, so that it can be merged in
13382
// getKeywordStatus. Most should be enabled/disabled, but some might imply
@@ -222,7 +171,7 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
222171

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

0 commit comments

Comments
 (0)