Skip to content

Commit d3caae1

Browse files
authored
[clang] Refactor clang's keyword enable/disable mechanism to allow lldb to re-use it (#165323)
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 ebeb36b commit d3caae1

File tree

2 files changed

+52
-54
lines changed

2 files changed

+52
-54
lines changed

clang/include/clang/Basic/IdentifierTable.h

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

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

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 1 addition & 54 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
@@ -220,9 +169,7 @@ static KeywordStatus getKeywordStatusHelper(const LangOptions &LangOpts,
220169
}
221170
}
222171

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

0 commit comments

Comments
 (0)