Go to the documentation of this file.
15 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
21 #include "llvm/ADT/DenseMapInfo.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/Allocator.h"
26 #include "llvm/Support/PointerLikeTypeTraits.h"
27 #include "llvm/Support/type_traits.h"
37 class DeclarationName;
38 class DeclarationNameTable;
41 class MultiKeywordSelector;
97 unsigned HasMacro : 1;
100 unsigned HadMacro : 1;
103 unsigned IsExtension : 1;
106 unsigned IsFutureCompatKeyword : 1;
109 unsigned IsPoisoned : 1;
112 unsigned IsCPPOperatorKeyword : 1;
116 unsigned NeedsHandleIdentifier : 1;
119 unsigned IsFromAST : 1;
123 unsigned ChangedAfterLoad : 1;
127 unsigned FEChangedAfterLoad : 1;
130 unsigned RevertedTokenID : 1;
134 unsigned OutOfDate : 1;
137 unsigned IsModulesImport : 1;
140 unsigned IsMangledOpenMPVariantName : 1;
143 unsigned IsDeprecatedMacro : 1;
146 unsigned IsRestrictExpansion : 1;
149 unsigned IsFinal : 1;
154 void *FETokenInfo =
nullptr;
156 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
159 : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(
false),
161 IsPoisoned(
false), IsCPPOperatorKeyword(
false),
162 NeedsHandleIdentifier(
false), IsFromAST(
false), ChangedAfterLoad(
false),
164 IsModulesImport(
false), IsMangledOpenMPVariantName(
false),
165 IsDeprecatedMacro(
false), IsRestrictExpansion(
false), IsFinal(
false) {}
176 template <std::
size_t StrLen>
177 bool isStr(
const char (&Str)[StrLen])
const {
178 return getLength() == StrLen-1 &&
179 memcmp(getNameStart(), Str, StrLen-1) == 0;
183 bool isStr(llvm::StringRef Str)
const {
184 llvm::StringRef ThisStr(getNameStart(), getLength());
185 return ThisStr == Str;
193 unsigned getLength()
const {
return Entry->getKeyLength(); }
197 return StringRef(getNameStart(), getLength());
206 if (HasMacro == Val)
return;
210 NeedsHandleIdentifier =
true;
218 IsDeprecatedMacro =
false;
219 IsRestrictExpansion =
false;
221 RecomputeNeedsHandleIdentifier();
234 if (IsDeprecatedMacro == Val)
236 IsDeprecatedMacro = Val;
238 NeedsHandleIdentifier =
true;
240 RecomputeNeedsHandleIdentifier();
246 if (IsRestrictExpansion == Val)
248 IsRestrictExpansion = Val;
250 NeedsHandleIdentifier =
true;
252 RecomputeNeedsHandleIdentifier();
274 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
275 TokenID = tok::identifier;
276 RevertedTokenID =
true;
279 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
281 RevertedTokenID =
false;
296 return tok::objc_not_keyword;
312 &&
"ID too large for field!");
325 NeedsHandleIdentifier =
true;
327 RecomputeNeedsHandleIdentifier();
337 IsFutureCompatKeyword = Val;
339 NeedsHandleIdentifier =
true;
341 RecomputeNeedsHandleIdentifier();
349 NeedsHandleIdentifier =
true;
351 RecomputeNeedsHandleIdentifier();
360 IsCPPOperatorKeyword = Val;
369 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
392 return ChangedAfterLoad;
398 ChangedAfterLoad =
true;
404 return FEChangedAfterLoad;
410 FEChangedAfterLoad =
true;
422 NeedsHandleIdentifier =
true;
424 RecomputeNeedsHandleIdentifier();
434 NeedsHandleIdentifier =
true;
436 RecomputeNeedsHandleIdentifier();
464 StringRef deuglifiedName()
const;
478 void RecomputeNeedsHandleIdentifier() {
479 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
480 isExtensionToken() || isFutureCompatKeyword() ||
481 isOutOfDate() || isModulesImport();
495 : II(II), OldValue(II ? II->isPoisoned() :
false) {
531 virtual StringRef Next() = 0;
567 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
568 HashTableTy HashTable;
583 ExternalLookup = IILookup;
588 return ExternalLookup;
592 return HashTable.getAllocator();
598 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
604 if (ExternalLookup) {
605 II = ExternalLookup->
get(Name);
623 II.TokenID = TokenCode;
624 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
635 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
650 if (Name.equals(
"import"))
661 unsigned size()
const {
return HashTable.size(); }
667 void PrintStats()
const;
764 enum IdentifierInfoFlag {
780 InfoPtr =
reinterpret_cast<uintptr_t>(II);
781 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
782 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
786 Selector(MultiKeywordSelector *SI) {
787 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
788 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
792 IdentifierInfo *getAsIdentifierInfo()
const {
793 if (getIdentifierInfoFlag() < MultiArg)
794 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
798 MultiKeywordSelector *getMultiKeywordSelector()
const {
799 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
802 unsigned getIdentifierInfoFlag()
const {
803 return InfoPtr & ArgFlags;
813 Selector() =
default;
818 return InfoPtr == RHS.InfoPtr;
821 return InfoPtr != RHS.InfoPtr;
825 return reinterpret_cast<void*
>(InfoPtr);
829 bool isNull()
const {
return InfoPtr == 0; }
833 return getIdentifierInfoFlag() != ZeroArg;
837 return getIdentifierInfoFlag() == ZeroArg;
844 bool isUnarySelector(StringRef Name)
const;
846 unsigned getNumArgs()
const;
861 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
871 StringRef getNameForSlot(
unsigned argIndex)
const;
878 void print(llvm::raw_ostream &OS)
const;
884 return getMethodFamilyImpl(*
this);
888 return getStringFormatFamilyImpl(*
this);
929 size_t getTotalMemory()
const;
990 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
994 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
996 ? (
unsigned)ObjCMultiArgSelector
997 : ExtraKindOrNumArgs);
1003 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
1004 "getNumArgs called but this is not an ObjC selector!");
1005 return ExtraKindOrNumArgs - (
unsigned)ObjCMultiArgSelector;
1037 return P.getAsOpaquePtr();
1044 static constexpr
int NumLowBitsAvailable = 0;
1059 static constexpr
int NumLowBitsAvailable = 1;
1072 static constexpr
int NumLowBitsAvailable = 1;
1077 #endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
YAML serialization mapping.
iterator find(StringRef Name) const
@ StartsWithUnderscoreAtGlobalScope
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
ObjCMethodFamily
A family of Objective-C methods.
void revertIdentifierToTokenID(tok::TokenKind TK)
static clang::Selector getTombstoneKey()
HashTableTy::const_iterator const_iterator
HashTableTy::const_iterator iterator
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
@ OMF_None
No particular method family.
static constexpr int ObjCOrBuiltinIDBits
IdentifierInfo & get(StringRef Name, tok::TokenKind TokenCode)
~PoisonIdentifierRAIIObject()
void setIsFinal(bool Val)
void setHasMacroDefinition(bool Val)
ObjCInstanceTypeFamily
A family of Objective-C methods.
bool isUnarySelector() const
static clang::IdentifierInfo * getFromVoidPointer(void *P)
@ StartsWithUnderscoreAndIsExternC
@ ContainsDoubleUnderscore
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool isCPlusPlusOperatorKeyword() const
The name of a declaration.
static clang::Selector getEmptyKey()
@ StartsWithUnderscoreFollowedByCapitalLetter
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
llvm::StringRef getAsString(SyncScope S)
@ InvalidObjCMethodFamily
ObjCStringFormatFamily getStringFormatFamily() const
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
void setIsFutureCompatKeyword(bool Val)
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)
unsigned getLength() const
Efficiently return the length of this identifier info.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
bool operator!=(Selector RHS) const
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
This table allows us to fully hide how we implement multi-keyword caching.
An iterator that walks over all of the known identifiers in the lookup table.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
static std::string getName(const CallEvent &Call)
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setFETokenInfo(void *T)
void setIsDeprecatedMacro(bool Val)
llvm::BumpPtrAllocator & getAllocator()
@ ObjCMethodFamilyBitWidth
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
static const void * getAsVoidPointer(const clang::IdentifierInfo *P)
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
bool isRestrictExpansion() const
bool isPoisoned() const
Return true if this token has been poisoned.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
bool isMangledOpenMPVariantName() const
Determine whether this is the mangled name of an OpenMP variant.
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
void setIsRestrictExpansion(bool Val)
static clang::Selector getFromVoidPointer(const void *P)
One of these records is kept for each identifier that is lexed.
static Selector getEmptyMarker()
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier.
unsigned getObjCOrBuiltinID() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
An RAII object for [un]poisoning an identifier within a scope.
Selector getNullarySelector(IdentifierInfo *ID)
Selector getUnarySelector(IdentifierInfo *ID)
void setMangledOpenMPVariantName(bool I)
Set whether this is the mangled name of an OpenMP variant.
static const void * getAsVoidPointer(clang::Selector P)
StringRef getName() const
Return the actual identifier string.
bool isNull() const
Determine whether this is the empty selector.
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
void * getFETokenInfo() const
Get and set FETokenInfo.
Smart pointer class that efficiently represents Objective-C method names.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Implements an efficient mapping from strings to IdentifierInfo nodes.
bool isKeywordSelector() const
void setBuiltinID(unsigned ID)
Provides lookups to, and iteration over, IdentiferInfo objects.
bool isModulesImport() const
Determine whether this is the contextual keyword import.
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source.
static void * getAsVoidPointer(clang::IdentifierInfo *P)
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
static Selector getTombstoneMarker()
void setObjCOrBuiltinID(unsigned ID)
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
void * getAsOpaquePtr() const
@ IdentifierInfoAlignment
bool isDeprecatedMacro() const
@ StartsWithDoubleUnderscore
void setIsExtensionToken(bool Val)