Author: Matthias Wippich
Date: 2026-07-28T18:52:44+10:00
New Revision: c6603cce864078da43741e36fb9586a6c72782fe

URL: 
https://github.com/llvm/llvm-project/commit/c6603cce864078da43741e36fb9586a6c72782fe
DIFF: 
https://github.com/llvm/llvm-project/commit/c6603cce864078da43741e36fb9586a6c72782fe.diff

LOG: [clang][NFC] generate TokenKey from tablegen (#210857)

Currently the enumerator constants of `TokenKey` are duplicated between
TokenKinds.h and Traits.td. This patch generates the `TokenKey` enum
from tablegen.

This is a followup patch for
https://github.com/llvm/llvm-project/pull/201491#discussion_r3567423553

Added: 
    

Modified: 
    clang/include/clang/Basic/TokenKinds.h
    clang/utils/TableGen/ClangTraitsEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/TokenKinds.h 
b/clang/include/clang/Basic/TokenKinds.h
index 89b2d43076511..1f1813e7a5cd2 100644
--- a/clang/include/clang/Basic/TokenKinds.h
+++ b/clang/include/clang/Basic/TokenKinds.h
@@ -23,40 +23,8 @@ namespace clang {
 
 /// Constants for TokenKinds.def
 enum TokenKey : unsigned {
-  KEYC99 = 0x1,
-  KEYCXX = 0x2,
-  KEYCXX11 = 0x4,
-  KEYGNU = 0x8,
-  KEYMS = 0x10,
-  BOOLSUPPORT = 0x20,
-  KEYALTIVEC = 0x40,
-  KEYNOCXX = 0x80,
-  KEYBORLAND = 0x100,
-  KEYOPENCLC = 0x200,
-  KEYC23 = 0x400,
-  KEYNOMS18 = 0x800,
-  KEYNOOPENCL = 0x1000,
-  WCHARSUPPORT = 0x2000,
-  HALFSUPPORT = 0x4000,
-  CHAR8SUPPORT = 0x8000,
-  KEYOBJC = 0x10000,
-  KEYZVECTOR = 0x20000,
-  KEYCOROUTINES = 0x40000,
-  KEYMODULES = 0x80000,
-  KEYCXX20 = 0x100000,
-  KEYOPENCLCXX = 0x200000,
-  KEYMSCOMPAT = 0x400000,
-  KEYSYCL = 0x800000,
-  KEYCUDA = 0x1000000,
-  KEYZOS = 0x2000000,
-  KEYHLSL = 0x4000000,
-  KEYFIXEDPOINT = 0x8000000,
-  KEYDEFERTS = 0x10000000,
-  KEYNOHLSL = 0x20000000,
-  KEYMAX = KEYNOHLSL, // The maximum key
-  KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
-  KEYALL = (KEYMAX | (KEYMAX - 1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
-           ~KEYNOHLSL // KEYNOMS18, KEYNOOPENCL, KEYNOHLSL excluded.
+#define EMIT_TOKENKEY
+#include "clang/Basic/Traits.inc"
 };
 
 namespace tok {

diff  --git a/clang/utils/TableGen/ClangTraitsEmitter.cpp 
b/clang/utils/TableGen/ClangTraitsEmitter.cpp
index 6ca0aa313f754..b94f82f8475d9 100644
--- a/clang/utils/TableGen/ClangTraitsEmitter.cpp
+++ b/clang/utils/TableGen/ClangTraitsEmitter.cpp
@@ -54,6 +54,12 @@ StringRef recordKindToMacro(const Record *R) {
   return Macro;
 }
 
+void emitTokenKey(const RecordKeeper &Records, raw_ostream &OS) {
+  for (const Record *R : getAllDerivedDefsInDeclOrder(Records, "TokenKey")) {
+    OS << "  " << R->getName() << " = " << R->getValueAsInt("Value") << ",\n";
+  }
+}
+
 void emitMacro(const Record *R, raw_ostream &OS) {
   OS << recordKindToMacro(R) << "(";
   if (R->isSubClassOf("TransformTypeTrait")) {
@@ -210,7 +216,10 @@ void emitStdNameCases(const RecordKeeper &Records, 
raw_ostream &OS) {
 
 void clang::EmitClangTraits(const RecordKeeper &Records, raw_ostream &OS) {
   emitSourceFileHeader("Type and expression traits", OS, Records);
-  OS << "#if defined(EMIT_ENUMS)\n";
+  OS << "#if defined(EMIT_TOKENKEY)\n";
+  emitTokenKey(Records, OS);
+
+  OS << "#elif defined(EMIT_ENUMS)\n";
   emitEnums(Records, OS);
 
   OS << "#elif defined(EMIT_ARRAYS)\n";
@@ -227,6 +236,7 @@ void clang::EmitClangTraits(const RecordKeeper &Records, 
raw_ostream &OS) {
 #undef EMIT_ARRAYS
 #undef EMIT_ENUMS
 #undef EMIT_STD_NAME_CASES
+#undef EMIT_TOKENKEY
 
 )";
 }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to