Skip to content

Commit 5027569

Browse files
authored
[clang][NFC] Use "notable" for "interesting" identifiers in IdentifierInfo (#81542)
This patch expands notion of "interesting" in `IdentifierInto` it to also cover ObjC keywords and builtins, which matches notion of "interesting" in serialization layer. What was previously "interesting" in `IdentifierInto` is now called "notable". Beyond clearing confusion between serialization and the rest of the compiler, it also resolved a naming problem: ObjC keywords, notable identifiers, and builtin IDs are all stored in the same bit-field. Now we can use "interesting" to name it and its corresponding type, instead of `ObjCKeywordOrInterestingOrBuiltin` abomination.
1 parent debca7e commit 5027569

File tree

7 files changed

+82
-91
lines changed

7 files changed

+82
-91
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,28 @@ using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
8484
/// of a pointer to one of these classes.
8585
enum { IdentifierInfoAlignment = 8 };
8686

87-
static constexpr int ObjCOrBuiltinIDBits = 16;
87+
static constexpr int InterestingIdentifierBits = 16;
8888

89-
/// The "layout" of ObjCOrBuiltinID is:
89+
/// The "layout" of InterestingIdentifier is:
9090
/// - ObjCKeywordKind enumerators
91-
/// - InterestingIdentifierKind enumerators
91+
/// - NotableIdentifierKind enumerators
9292
/// - Builtin::ID enumerators
93-
/// - NonSpecialIdentifier
94-
enum class ObjCKeywordOrInterestingOrBuiltin {
93+
/// - NotInterestingIdentifier
94+
enum class InterestingIdentifier {
9595
#define OBJC_AT_KEYWORD(X) objc_##X,
9696
#include "clang/Basic/TokenKinds.def"
9797
NUM_OBJC_KEYWORDS,
9898

99-
#define INTERESTING_IDENTIFIER(X) X,
99+
#define NOTABLE_IDENTIFIER(X) X,
100100
#include "clang/Basic/TokenKinds.def"
101-
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS,
101+
NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS,
102102

103103
NotBuiltin,
104104
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
105105
#include "clang/Basic/Builtins.inc"
106106
FirstTSBuiltin,
107107

108-
NonSpecialIdentifier = 65534
108+
NotInterestingIdentifier = 65534
109109
};
110110

111111
/// One of these records is kept for each identifier that
@@ -121,8 +121,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
121121
LLVM_PREFERRED_TYPE(tok::TokenKind)
122122
unsigned TokenID : 9;
123123

124-
LLVM_PREFERRED_TYPE(ObjCKeywordOrInterestingOrBuiltin)
125-
unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
124+
LLVM_PREFERRED_TYPE(InterestingIdentifier)
125+
unsigned InterestingIdentifierID : InterestingIdentifierBits;
126126

127127
// True if there is a #define for this.
128128
LLVM_PREFERRED_TYPE(bool)
@@ -205,8 +205,8 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
205205

206206
IdentifierInfo()
207207
: TokenID(tok::identifier),
208-
ObjCOrBuiltinID(llvm::to_underlying(
209-
ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier)),
208+
InterestingIdentifierID(llvm::to_underlying(
209+
InterestingIdentifier::NotInterestingIdentifier)),
210210
HasMacro(false), HadMacro(false), IsExtension(false),
211211
IsFutureCompatKeyword(false), IsPoisoned(false),
212212
IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
@@ -341,71 +341,63 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
341341
///
342342
/// For example, 'class' will return tok::objc_class if ObjC is enabled.
343343
tok::ObjCKeywordKind getObjCKeywordID() const {
344-
assert(0 == llvm::to_underlying(
345-
ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
346-
auto Value =
347-
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
348-
if (Value < ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS)
349-
return static_cast<tok::ObjCKeywordKind>(ObjCOrBuiltinID);
344+
assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
345+
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
346+
if (Value < InterestingIdentifier::NUM_OBJC_KEYWORDS)
347+
return static_cast<tok::ObjCKeywordKind>(InterestingIdentifierID);
350348
return tok::objc_not_keyword;
351349
}
352350
void setObjCKeywordID(tok::ObjCKeywordKind ID) {
353-
assert(0 == llvm::to_underlying(
354-
ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
355-
ObjCOrBuiltinID = ID;
351+
assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
352+
InterestingIdentifierID = ID;
356353
assert(getObjCKeywordID() == ID && "ID too large for field!");
357354
}
358355

359356
/// Return a value indicating whether this is a builtin function.
360357
unsigned getBuiltinID() const {
361-
auto Value =
362-
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
363-
if (Value > ObjCKeywordOrInterestingOrBuiltin::
364-
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS &&
365-
Value != ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier) {
358+
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
359+
if (Value >
360+
InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS &&
361+
Value != InterestingIdentifier::NotInterestingIdentifier) {
366362
auto FirstBuiltin =
367-
llvm::to_underlying(ObjCKeywordOrInterestingOrBuiltin::NotBuiltin);
368-
return static_cast<Builtin::ID>(ObjCOrBuiltinID - FirstBuiltin);
363+
llvm::to_underlying(InterestingIdentifier::NotBuiltin);
364+
return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
369365
}
370366
return Builtin::ID::NotBuiltin;
371367
}
372368
void setBuiltinID(unsigned ID) {
373369
assert(ID != Builtin::ID::NotBuiltin);
374-
auto FirstBuiltin =
375-
llvm::to_underlying(ObjCKeywordOrInterestingOrBuiltin::NotBuiltin);
376-
ObjCOrBuiltinID = ID + FirstBuiltin;
370+
auto FirstBuiltin = llvm::to_underlying(InterestingIdentifier::NotBuiltin);
371+
InterestingIdentifierID = ID + FirstBuiltin;
377372
assert(getBuiltinID() == ID && "ID too large for field!");
378373
}
379374
void clearBuiltinID() {
380-
ObjCOrBuiltinID = llvm::to_underlying(
381-
ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier);
382-
}
383-
384-
tok::InterestingIdentifierKind getInterestingIdentifierID() const {
385-
auto Value =
386-
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
387-
if (Value > ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS &&
388-
Value < ObjCKeywordOrInterestingOrBuiltin::
389-
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS) {
390-
auto FirstInterestingIdentifier =
391-
1 + llvm::to_underlying(
392-
ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS);
393-
return static_cast<tok::InterestingIdentifierKind>(
394-
ObjCOrBuiltinID - FirstInterestingIdentifier);
375+
InterestingIdentifierID =
376+
llvm::to_underlying(InterestingIdentifier::NotInterestingIdentifier);
377+
}
378+
379+
tok::NotableIdentifierKind getNotableIdentifierID() const {
380+
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
381+
if (Value > InterestingIdentifier::NUM_OBJC_KEYWORDS &&
382+
Value <
383+
InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS) {
384+
auto FirstNotableIdentifier =
385+
1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
386+
return static_cast<tok::NotableIdentifierKind>(InterestingIdentifierID -
387+
FirstNotableIdentifier);
395388
}
396-
return tok::not_interesting;
389+
return tok::not_notable;
397390
}
398-
void setInterestingIdentifierID(unsigned ID) {
399-
assert(ID != tok::not_interesting);
400-
auto FirstInterestingIdentifier =
401-
1 + llvm::to_underlying(
402-
ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS);
403-
ObjCOrBuiltinID = ID + FirstInterestingIdentifier;
404-
assert(getInterestingIdentifierID() == ID && "ID too large for field!");
391+
void setNotableIdentifierID(unsigned ID) {
392+
assert(ID != tok::not_notable);
393+
auto FirstNotableIdentifier =
394+
1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
395+
InterestingIdentifierID = ID + FirstNotableIdentifier;
396+
assert(getNotableIdentifierID() == ID && "ID too large for field!");
405397
}
406398

407-
unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
408-
void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
399+
unsigned getObjCOrBuiltinID() const { return InterestingIdentifierID; }
400+
void setObjCOrBuiltinID(unsigned ID) { InterestingIdentifierID = ID; }
409401

410402
/// get/setExtension - Initialize information about whether or not this
411403
/// language token is an extension. This controls extension warnings, and is

clang/include/clang/Basic/TokenKinds.def

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
#ifndef PRAGMA_ANNOTATION
8686
#define PRAGMA_ANNOTATION(X) ANNOTATION(X)
8787
#endif
88-
#ifndef INTERESTING_IDENTIFIER
89-
#define INTERESTING_IDENTIFIER(X)
88+
#ifndef NOTABLE_IDENTIFIER
89+
#define NOTABLE_IDENTIFIER(X)
9090
#endif
9191

9292
//===----------------------------------------------------------------------===//
@@ -808,15 +808,15 @@ OBJC_AT_KEYWORD(import)
808808
OBJC_AT_KEYWORD(available)
809809

810810
//===----------------------------------------------------------------------===//
811-
// Interesting identifiers.
811+
// Notable identifiers.
812812
//===----------------------------------------------------------------------===//
813-
INTERESTING_IDENTIFIER(not_interesting)
814-
INTERESTING_IDENTIFIER(FILE)
815-
INTERESTING_IDENTIFIER(jmp_buf)
816-
INTERESTING_IDENTIFIER(sigjmp_buf)
817-
INTERESTING_IDENTIFIER(ucontext_t)
818-
INTERESTING_IDENTIFIER(float_t)
819-
INTERESTING_IDENTIFIER(double_t)
813+
NOTABLE_IDENTIFIER(not_notable)
814+
NOTABLE_IDENTIFIER(FILE)
815+
NOTABLE_IDENTIFIER(jmp_buf)
816+
NOTABLE_IDENTIFIER(sigjmp_buf)
817+
NOTABLE_IDENTIFIER(ucontext_t)
818+
NOTABLE_IDENTIFIER(float_t)
819+
NOTABLE_IDENTIFIER(double_t)
820820

821821
// TODO: What to do about context-sensitive keywords like:
822822
// bycopy/byref/in/inout/oneway/out?
@@ -1011,4 +1011,4 @@ ANNOTATION(repl_input_end)
10111011
#undef TOK
10121012
#undef C99_KEYWORD
10131013
#undef C23_KEYWORD
1014-
#undef INTERESTING_IDENTIFIER
1014+
#undef NOTABLE_IDENTIFIER

clang/include/clang/Basic/TokenKinds.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ enum ObjCKeywordKind {
4444
NUM_OBJC_KEYWORDS
4545
};
4646

47-
/// Provides a namespace for interesting identifers such as float_t and
47+
/// Provides a namespace for notable identifers such as float_t and
4848
/// double_t.
49-
enum InterestingIdentifierKind {
50-
#define INTERESTING_IDENTIFIER(X) X,
49+
enum NotableIdentifierKind {
50+
#define NOTABLE_IDENTIFIER(X) X,
5151
#include "clang/Basic/TokenKinds.def"
52-
NUM_INTERESTING_IDENTIFIERS
52+
NUM_NOTABLE_IDENTIFIERS
5353
};
5454

5555
/// Defines the possible values of an on-off-switch (C99 6.10.6p2).

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ using namespace clang;
3636
// A check to make sure the ObjCOrBuiltinID has sufficient room to store the
3737
// largest possible target/aux-target combination. If we exceed this, we likely
3838
// need to just change the ObjCOrBuiltinIDBits value in IdentifierTable.h.
39-
static_assert(2 * LargestBuiltinID < (2 << (ObjCOrBuiltinIDBits - 1)),
39+
static_assert(2 * LargestBuiltinID < (2 << (InterestingIdentifierBits - 1)),
4040
"Insufficient ObjCOrBuiltinID Bits");
4141

4242
//===----------------------------------------------------------------------===//
@@ -280,13 +280,13 @@ static void AddObjCKeyword(StringRef Name,
280280
Table.get(Name).setObjCKeywordID(ObjCID);
281281
}
282282

283-
static void AddInterestingIdentifier(StringRef Name,
284-
tok::InterestingIdentifierKind BTID,
285-
IdentifierTable &Table) {
286-
// Don't add 'not_interesting' identifier.
287-
if (BTID != tok::not_interesting) {
283+
static void AddNotableIdentifier(StringRef Name,
284+
tok::NotableIdentifierKind BTID,
285+
IdentifierTable &Table) {
286+
// Don't add 'not_notable' identifier.
287+
if (BTID != tok::not_notable) {
288288
IdentifierInfo &Info = Table.get(Name, tok::identifier);
289-
Info.setInterestingIdentifierID(BTID);
289+
Info.setNotableIdentifierID(BTID);
290290
}
291291
}
292292

@@ -306,8 +306,8 @@ void IdentifierTable::AddKeywords(const LangOptions &LangOpts) {
306306
#define OBJC_AT_KEYWORD(NAME) \
307307
if (LangOpts.ObjC) \
308308
AddObjCKeyword(StringRef(#NAME), tok::objc_##NAME, *this);
309-
#define INTERESTING_IDENTIFIER(NAME) \
310-
AddInterestingIdentifier(StringRef(#NAME), tok::NAME, *this);
309+
#define NOTABLE_IDENTIFIER(NAME) \
310+
AddNotableIdentifier(StringRef(#NAME), tok::NAME, *this);
311311

312312
#define TESTING_KEYWORD(NAME, FLAGS)
313313
#include "clang/Basic/TokenKinds.def"

clang/lib/Sema/SemaDecl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,21 +6842,21 @@ Sema::ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *NewTD,
68426842
if (IdentifierInfo *II = NewTD->getIdentifier())
68436843
if (!NewTD->isInvalidDecl() &&
68446844
NewTD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
6845-
switch (II->getInterestingIdentifierID()) {
6846-
case tok::InterestingIdentifierKind::FILE:
6845+
switch (II->getNotableIdentifierID()) {
6846+
case tok::NotableIdentifierKind::FILE:
68476847
Context.setFILEDecl(NewTD);
68486848
break;
6849-
case tok::InterestingIdentifierKind::jmp_buf:
6849+
case tok::NotableIdentifierKind::jmp_buf:
68506850
Context.setjmp_bufDecl(NewTD);
68516851
break;
6852-
case tok::InterestingIdentifierKind::sigjmp_buf:
6852+
case tok::NotableIdentifierKind::sigjmp_buf:
68536853
Context.setsigjmp_bufDecl(NewTD);
68546854
break;
6855-
case tok::InterestingIdentifierKind::ucontext_t:
6855+
case tok::NotableIdentifierKind::ucontext_t:
68566856
Context.setucontext_tDecl(NewTD);
68576857
break;
6858-
case tok::InterestingIdentifierKind::float_t:
6859-
case tok::InterestingIdentifierKind::double_t:
6858+
case tok::NotableIdentifierKind::float_t:
6859+
case tok::NotableIdentifierKind::double_t:
68606860
NewTD->addAttr(AvailableOnlyInDefaultEvalMethodAttr::Create(Context));
68616861
break;
68626862
default:

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,7 @@ ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) {
988988
static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II,
989989
bool IsModule) {
990990
bool IsInteresting =
991-
II.getInterestingIdentifierID() !=
992-
tok::InterestingIdentifierKind::not_interesting ||
991+
II.getNotableIdentifierID() != tok::NotableIdentifierKind::not_notable ||
993992
II.getBuiltinID() != Builtin::ID::NotBuiltin ||
994993
II.getObjCKeywordID() != tok::ObjCKeywordKind::objc_not_keyword;
995994
return II.hadMacroDefinition() || II.isPoisoned() ||

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3599,8 +3599,8 @@ class ASTIdentifierTableTrait {
35993599
bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) {
36003600
II->getObjCOrBuiltinID();
36013601
bool IsInteresting =
3602-
II->getInterestingIdentifierID() !=
3603-
tok::InterestingIdentifierKind::not_interesting ||
3602+
II->getNotableIdentifierID() !=
3603+
tok::NotableIdentifierKind::not_notable ||
36043604
II->getBuiltinID() != Builtin::ID::NotBuiltin ||
36053605
II->getObjCKeywordID() != tok::ObjCKeywordKind::objc_not_keyword;
36063606
if (MacroOffset || II->isPoisoned() || (!IsModule && IsInteresting) ||

0 commit comments

Comments
 (0)