Skip to content

[clang][NFC] Use "notable" for "interesting" identifiers in IdentifierInfo #81542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 48 additions & 56 deletions clang/include/clang/Basic/IdentifierTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,28 @@ using IdentifierLocPair = std::pair<IdentifierInfo *, SourceLocation>;
/// of a pointer to one of these classes.
enum { IdentifierInfoAlignment = 8 };

static constexpr int ObjCOrBuiltinIDBits = 16;
static constexpr int InterestingIdentifierBits = 16;

/// The "layout" of ObjCOrBuiltinID is:
/// The "layout" of InterestingIdentifier is:
/// - ObjCKeywordKind enumerators
/// - InterestingIdentifierKind enumerators
/// - NotableIdentifierKind enumerators
/// - Builtin::ID enumerators
/// - NonSpecialIdentifier
enum class ObjCKeywordOrInterestingOrBuiltin {
/// - NotInterestingIdentifier
enum class InterestingIdentifier {
#define OBJC_AT_KEYWORD(X) objc_##X,
#include "clang/Basic/TokenKinds.def"
NUM_OBJC_KEYWORDS,

#define INTERESTING_IDENTIFIER(X) X,
#define NOTABLE_IDENTIFIER(X) X,
#include "clang/Basic/TokenKinds.def"
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS,
NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS,

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

NonSpecialIdentifier = 65534
NotInterestingIdentifier = 65534
};

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

LLVM_PREFERRED_TYPE(ObjCKeywordOrInterestingOrBuiltin)
unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
LLVM_PREFERRED_TYPE(InterestingIdentifier)
unsigned InterestingIdentifierID : InterestingIdentifierBits;

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

IdentifierInfo()
: TokenID(tok::identifier),
ObjCOrBuiltinID(llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier)),
InterestingIdentifierID(llvm::to_underlying(
InterestingIdentifier::NotInterestingIdentifier)),
HasMacro(false), HadMacro(false), IsExtension(false),
IsFutureCompatKeyword(false), IsPoisoned(false),
IsCPPOperatorKeyword(false), NeedsHandleIdentifier(false),
Expand Down Expand Up @@ -341,71 +341,63 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
///
/// For example, 'class' will return tok::objc_class if ObjC is enabled.
tok::ObjCKeywordKind getObjCKeywordID() const {
assert(0 == llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
auto Value =
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
if (Value < ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS)
return static_cast<tok::ObjCKeywordKind>(ObjCOrBuiltinID);
assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
if (Value < InterestingIdentifier::NUM_OBJC_KEYWORDS)
return static_cast<tok::ObjCKeywordKind>(InterestingIdentifierID);
return tok::objc_not_keyword;
}
void setObjCKeywordID(tok::ObjCKeywordKind ID) {
assert(0 == llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::objc_not_keyword));
ObjCOrBuiltinID = ID;
assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
InterestingIdentifierID = ID;
assert(getObjCKeywordID() == ID && "ID too large for field!");
}

/// Return a value indicating whether this is a builtin function.
unsigned getBuiltinID() const {
auto Value =
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
if (Value > ObjCKeywordOrInterestingOrBuiltin::
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS &&
Value != ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier) {
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
if (Value >
InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS &&
Value != InterestingIdentifier::NotInterestingIdentifier) {
auto FirstBuiltin =
llvm::to_underlying(ObjCKeywordOrInterestingOrBuiltin::NotBuiltin);
return static_cast<Builtin::ID>(ObjCOrBuiltinID - FirstBuiltin);
llvm::to_underlying(InterestingIdentifier::NotBuiltin);
return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
}
return Builtin::ID::NotBuiltin;
}
void setBuiltinID(unsigned ID) {
assert(ID != Builtin::ID::NotBuiltin);
auto FirstBuiltin =
llvm::to_underlying(ObjCKeywordOrInterestingOrBuiltin::NotBuiltin);
ObjCOrBuiltinID = ID + FirstBuiltin;
auto FirstBuiltin = llvm::to_underlying(InterestingIdentifier::NotBuiltin);
InterestingIdentifierID = ID + FirstBuiltin;
assert(getBuiltinID() == ID && "ID too large for field!");
}
void clearBuiltinID() {
ObjCOrBuiltinID = llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::NonSpecialIdentifier);
}

tok::InterestingIdentifierKind getInterestingIdentifierID() const {
auto Value =
static_cast<ObjCKeywordOrInterestingOrBuiltin>(ObjCOrBuiltinID);
if (Value > ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS &&
Value < ObjCKeywordOrInterestingOrBuiltin::
NUM_OBJC_KEYWORDS_AND_INTERESTING_IDENTIFIERS) {
auto FirstInterestingIdentifier =
1 + llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS);
return static_cast<tok::InterestingIdentifierKind>(
ObjCOrBuiltinID - FirstInterestingIdentifier);
InterestingIdentifierID =
llvm::to_underlying(InterestingIdentifier::NotInterestingIdentifier);
}

tok::NotableIdentifierKind getNotableIdentifierID() const {
auto Value = static_cast<InterestingIdentifier>(InterestingIdentifierID);
if (Value > InterestingIdentifier::NUM_OBJC_KEYWORDS &&
Value <
InterestingIdentifier::NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS) {
auto FirstNotableIdentifier =
1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
return static_cast<tok::NotableIdentifierKind>(InterestingIdentifierID -
FirstNotableIdentifier);
}
return tok::not_interesting;
return tok::not_notable;
}
void setInterestingIdentifierID(unsigned ID) {
assert(ID != tok::not_interesting);
auto FirstInterestingIdentifier =
1 + llvm::to_underlying(
ObjCKeywordOrInterestingOrBuiltin::NUM_OBJC_KEYWORDS);
ObjCOrBuiltinID = ID + FirstInterestingIdentifier;
assert(getInterestingIdentifierID() == ID && "ID too large for field!");
void setNotableIdentifierID(unsigned ID) {
assert(ID != tok::not_notable);
auto FirstNotableIdentifier =
1 + llvm::to_underlying(InterestingIdentifier::NUM_OBJC_KEYWORDS);
InterestingIdentifierID = ID + FirstNotableIdentifier;
assert(getNotableIdentifierID() == ID && "ID too large for field!");
}

unsigned getObjCOrBuiltinID() const { return ObjCOrBuiltinID; }
void setObjCOrBuiltinID(unsigned ID) { ObjCOrBuiltinID = ID; }
unsigned getObjCOrBuiltinID() const { return InterestingIdentifierID; }
void setObjCOrBuiltinID(unsigned ID) { InterestingIdentifierID = ID; }

/// get/setExtension - Initialize information about whether or not this
/// language token is an extension. This controls extension warnings, and is
Expand Down
22 changes: 11 additions & 11 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
#ifndef PRAGMA_ANNOTATION
#define PRAGMA_ANNOTATION(X) ANNOTATION(X)
#endif
#ifndef INTERESTING_IDENTIFIER
#define INTERESTING_IDENTIFIER(X)
#ifndef NOTABLE_IDENTIFIER
#define NOTABLE_IDENTIFIER(X)
#endif

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -808,15 +808,15 @@ OBJC_AT_KEYWORD(import)
OBJC_AT_KEYWORD(available)

//===----------------------------------------------------------------------===//
// Interesting identifiers.
// Notable identifiers.
//===----------------------------------------------------------------------===//
INTERESTING_IDENTIFIER(not_interesting)
INTERESTING_IDENTIFIER(FILE)
INTERESTING_IDENTIFIER(jmp_buf)
INTERESTING_IDENTIFIER(sigjmp_buf)
INTERESTING_IDENTIFIER(ucontext_t)
INTERESTING_IDENTIFIER(float_t)
INTERESTING_IDENTIFIER(double_t)
NOTABLE_IDENTIFIER(not_notable)
NOTABLE_IDENTIFIER(FILE)
NOTABLE_IDENTIFIER(jmp_buf)
NOTABLE_IDENTIFIER(sigjmp_buf)
NOTABLE_IDENTIFIER(ucontext_t)
NOTABLE_IDENTIFIER(float_t)
NOTABLE_IDENTIFIER(double_t)

// TODO: What to do about context-sensitive keywords like:
// bycopy/byref/in/inout/oneway/out?
Expand Down Expand Up @@ -1011,4 +1011,4 @@ ANNOTATION(repl_input_end)
#undef TOK
#undef C99_KEYWORD
#undef C23_KEYWORD
#undef INTERESTING_IDENTIFIER
#undef NOTABLE_IDENTIFIER
8 changes: 4 additions & 4 deletions clang/include/clang/Basic/TokenKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ enum ObjCKeywordKind {
NUM_OBJC_KEYWORDS
};

/// Provides a namespace for interesting identifers such as float_t and
/// Provides a namespace for notable identifers such as float_t and
/// double_t.
enum InterestingIdentifierKind {
#define INTERESTING_IDENTIFIER(X) X,
enum NotableIdentifierKind {
#define NOTABLE_IDENTIFIER(X) X,
#include "clang/Basic/TokenKinds.def"
NUM_INTERESTING_IDENTIFIERS
NUM_NOTABLE_IDENTIFIERS
};

/// Defines the possible values of an on-off-switch (C99 6.10.6p2).
Expand Down
18 changes: 9 additions & 9 deletions clang/lib/Basic/IdentifierTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace clang;
// A check to make sure the ObjCOrBuiltinID has sufficient room to store the
// largest possible target/aux-target combination. If we exceed this, we likely
// need to just change the ObjCOrBuiltinIDBits value in IdentifierTable.h.
static_assert(2 * LargestBuiltinID < (2 << (ObjCOrBuiltinIDBits - 1)),
static_assert(2 * LargestBuiltinID < (2 << (InterestingIdentifierBits - 1)),
"Insufficient ObjCOrBuiltinID Bits");

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -280,13 +280,13 @@ static void AddObjCKeyword(StringRef Name,
Table.get(Name).setObjCKeywordID(ObjCID);
}

static void AddInterestingIdentifier(StringRef Name,
tok::InterestingIdentifierKind BTID,
IdentifierTable &Table) {
// Don't add 'not_interesting' identifier.
if (BTID != tok::not_interesting) {
static void AddNotableIdentifier(StringRef Name,
tok::NotableIdentifierKind BTID,
IdentifierTable &Table) {
// Don't add 'not_notable' identifier.
if (BTID != tok::not_notable) {
IdentifierInfo &Info = Table.get(Name, tok::identifier);
Info.setInterestingIdentifierID(BTID);
Info.setNotableIdentifierID(BTID);
}
}

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

#define TESTING_KEYWORD(NAME, FLAGS)
#include "clang/Basic/TokenKinds.def"
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6839,21 +6839,21 @@ Sema::ActOnTypedefNameDecl(Scope *S, DeclContext *DC, TypedefNameDecl *NewTD,
if (IdentifierInfo *II = NewTD->getIdentifier())
if (!NewTD->isInvalidDecl() &&
NewTD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
switch (II->getInterestingIdentifierID()) {
case tok::InterestingIdentifierKind::FILE:
switch (II->getNotableIdentifierID()) {
case tok::NotableIdentifierKind::FILE:
Context.setFILEDecl(NewTD);
break;
case tok::InterestingIdentifierKind::jmp_buf:
case tok::NotableIdentifierKind::jmp_buf:
Context.setjmp_bufDecl(NewTD);
break;
case tok::InterestingIdentifierKind::sigjmp_buf:
case tok::NotableIdentifierKind::sigjmp_buf:
Context.setsigjmp_bufDecl(NewTD);
break;
case tok::InterestingIdentifierKind::ucontext_t:
case tok::NotableIdentifierKind::ucontext_t:
Context.setucontext_tDecl(NewTD);
break;
case tok::InterestingIdentifierKind::float_t:
case tok::InterestingIdentifierKind::double_t:
case tok::NotableIdentifierKind::float_t:
case tok::NotableIdentifierKind::double_t:
NewTD->addAttr(AvailableOnlyInDefaultEvalMethodAttr::Create(Context));
break;
default:
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,7 @@ ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) {
static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II,
bool IsModule) {
bool IsInteresting =
II.getInterestingIdentifierID() !=
tok::InterestingIdentifierKind::not_interesting ||
II.getNotableIdentifierID() != tok::NotableIdentifierKind::not_notable ||
II.getBuiltinID() != Builtin::ID::NotBuiltin ||
II.getObjCKeywordID() != tok::ObjCKeywordKind::objc_not_keyword;
return II.hadMacroDefinition() || II.isPoisoned() ||
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3599,8 +3599,8 @@ class ASTIdentifierTableTrait {
bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) {
II->getObjCOrBuiltinID();
bool IsInteresting =
II->getInterestingIdentifierID() !=
tok::InterestingIdentifierKind::not_interesting ||
II->getNotableIdentifierID() !=
tok::NotableIdentifierKind::not_notable ||
II->getBuiltinID() != Builtin::ID::NotBuiltin ||
II->getObjCKeywordID() != tok::ObjCKeywordKind::objc_not_keyword;
if (MacroOffset || II->isPoisoned() || (!IsModule && IsInteresting) ||
Expand Down