[clang] [clang] Refactor `IdentifierInfo::ObjcOrBuiltinID` (PR #71709)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 9 00:23:59 PST 2023


================
@@ -86,19 +87,26 @@ enum { IdentifierInfoAlignment = 8 };
 static constexpr int ObjCOrBuiltinIDBits = 16;
 
 /// The "layout" of ObjCOrBuiltinID is:
-///  - The first value (0) represents "not a special identifier".
-///  - The next (NUM_OBJC_KEYWORDS - 1) values represent ObjCKeywordKinds (not
-///    including objc_not_keyword).
-///  - The next (NUM_INTERESTING_IDENTIFIERS - 1) values represent
-///    InterestingIdentifierKinds (not including not_interesting).
-///  - The rest of the values represent builtin IDs (not including NotBuiltin).
-static constexpr int FirstObjCKeywordID = 1;
-static constexpr int LastObjCKeywordID =
-    FirstObjCKeywordID + tok::NUM_OBJC_KEYWORDS - 2;
-static constexpr int FirstInterestingIdentifierID = LastObjCKeywordID + 1;
-static constexpr int LastInterestingIdentifierID =
-    FirstInterestingIdentifierID + tok::NUM_INTERESTING_IDENTIFIERS - 2;
-static constexpr int FirstBuiltinID = LastInterestingIdentifierID + 1;
+///  - ObjCKeywordKind enumerators
+///  - InterestingIdentifierKind enumerators
+///  - Builtin::ID enumerators
+///  - NonSpecialIdentifier
+enum class ObjCKeywordOrInterestingOrBuiltin {
+#define OBJC_AT_KEYWORD(X) objc_##X,
+#include "clang/Basic/TokenKinds.def"
+  NUM_OBJC_KEYWORDS,
----------------
Endilll wrote:

Not just this enumerator, but all OjbC keywords and interesting identifiers. I consider this a feature, actually, because debuggers would show enumerator name that both makes sense and useful while displaying `ObjCOrBuiltinID` bit-fields. Having `ObjCKeywordOrInterestingOrBuiltin` as a scoped enum should prevent name collisions with any other enum. enumeratrion

https://github.com/llvm/llvm-project/pull/71709


More information about the cfe-commits mailing list