Go to the documentation of this file.
15 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
20 #include "llvm/ADT/DenseMapInfo.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Allocator.h"
25 #include "llvm/Support/PointerLikeTypeTraits.h"
26 #include "llvm/Support/type_traits.h"
36 class DeclarationName;
37 class DeclarationNameTable;
40 class MultiKeywordSelector;
96 unsigned HasMacro : 1;
99 unsigned HadMacro : 1;
102 unsigned IsExtension : 1;
105 unsigned IsFutureCompatKeyword : 1;
108 unsigned IsPoisoned : 1;
111 unsigned IsCPPOperatorKeyword : 1;
115 unsigned NeedsHandleIdentifier : 1;
118 unsigned IsFromAST : 1;
122 unsigned ChangedAfterLoad : 1;
126 unsigned FEChangedAfterLoad : 1;
129 unsigned RevertedTokenID : 1;
133 unsigned OutOfDate : 1;
136 unsigned IsModulesImport : 1;
139 unsigned IsMangledOpenMPVariantName : 1;
142 unsigned IsDeprecatedMacro : 1;
145 unsigned IsRestrictExpansion : 1;
148 unsigned IsFinal : 1;
153 void *FETokenInfo =
nullptr;
155 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
158 : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(
false),
160 IsPoisoned(
false), IsCPPOperatorKeyword(
false),
161 NeedsHandleIdentifier(
false), IsFromAST(
false), ChangedAfterLoad(
false),
163 IsModulesImport(
false), IsMangledOpenMPVariantName(
false),
164 IsDeprecatedMacro(
false), IsRestrictExpansion(
false), IsFinal(
false) {}
175 template <std::
size_t StrLen>
176 bool isStr(
const char (&Str)[StrLen])
const {
177 return getLength() == StrLen-1 &&
178 memcmp(getNameStart(), Str, StrLen-1) == 0;
182 bool isStr(llvm::StringRef Str)
const {
183 llvm::StringRef ThisStr(getNameStart(), getLength());
184 return ThisStr == Str;
192 unsigned getLength()
const {
return Entry->getKeyLength(); }
196 return StringRef(getNameStart(), getLength());
205 if (HasMacro == Val)
return;
209 NeedsHandleIdentifier =
true;
217 IsDeprecatedMacro =
false;
218 IsRestrictExpansion =
false;
220 RecomputeNeedsHandleIdentifier();
233 if (IsDeprecatedMacro == Val)
235 IsDeprecatedMacro = Val;
237 NeedsHandleIdentifier =
true;
239 RecomputeNeedsHandleIdentifier();
245 if (IsRestrictExpansion == Val)
247 IsRestrictExpansion = Val;
249 NeedsHandleIdentifier =
true;
251 RecomputeNeedsHandleIdentifier();
273 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
274 TokenID = tok::identifier;
275 RevertedTokenID =
true;
278 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
280 RevertedTokenID =
false;
295 return tok::objc_not_keyword;
311 &&
"ID too large for field!");
324 NeedsHandleIdentifier =
true;
326 RecomputeNeedsHandleIdentifier();
336 IsFutureCompatKeyword = Val;
338 NeedsHandleIdentifier =
true;
340 RecomputeNeedsHandleIdentifier();
348 NeedsHandleIdentifier =
true;
350 RecomputeNeedsHandleIdentifier();
359 IsCPPOperatorKeyword = Val;
368 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
391 return ChangedAfterLoad;
397 ChangedAfterLoad =
true;
403 return FEChangedAfterLoad;
409 FEChangedAfterLoad =
true;
421 NeedsHandleIdentifier =
true;
423 RecomputeNeedsHandleIdentifier();
433 NeedsHandleIdentifier =
true;
435 RecomputeNeedsHandleIdentifier();
463 StringRef deuglifiedName()
const;
477 void RecomputeNeedsHandleIdentifier() {
478 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
479 isExtensionToken() || isFutureCompatKeyword() ||
480 isOutOfDate() || isModulesImport();
494 : II(II), OldValue(II ? II->isPoisoned() :
false) {
530 virtual StringRef Next() = 0;
566 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
567 HashTableTy HashTable;
582 ExternalLookup = IILookup;
587 return ExternalLookup;
591 return HashTable.getAllocator();
597 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
603 if (ExternalLookup) {
604 II = ExternalLookup->
get(Name);
622 II.TokenID = TokenCode;
623 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
634 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
649 if (Name.equals(
"import"))
660 unsigned size()
const {
return HashTable.size(); }
666 void PrintStats()
const;
757 enum IdentifierInfoFlag {
773 InfoPtr =
reinterpret_cast<uintptr_t>(II);
774 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
775 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
779 Selector(MultiKeywordSelector *SI) {
780 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
781 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
785 IdentifierInfo *getAsIdentifierInfo()
const {
786 if (getIdentifierInfoFlag() < MultiArg)
787 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
791 MultiKeywordSelector *getMultiKeywordSelector()
const {
792 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
795 unsigned getIdentifierInfoFlag()
const {
796 return InfoPtr & ArgFlags;
806 Selector() =
default;
811 return InfoPtr == RHS.InfoPtr;
814 return InfoPtr != RHS.InfoPtr;
818 return reinterpret_cast<void*
>(InfoPtr);
822 bool isNull()
const {
return InfoPtr == 0; }
826 return getIdentifierInfoFlag() != ZeroArg;
830 return getIdentifierInfoFlag() == ZeroArg;
837 bool isUnarySelector(StringRef Name)
const;
839 unsigned getNumArgs()
const;
854 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
864 StringRef getNameForSlot(
unsigned argIndex)
const;
871 void print(llvm::raw_ostream &OS)
const;
877 return getMethodFamilyImpl(*
this);
881 return getStringFormatFamilyImpl(*
this);
922 size_t getTotalMemory()
const;
983 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
987 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
989 ? (
unsigned)ObjCMultiArgSelector
990 : ExtraKindOrNumArgs);
996 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
997 "getNumArgs called but this is not an ObjC selector!");
998 return ExtraKindOrNumArgs - (
unsigned)ObjCMultiArgSelector;
1030 return P.getAsOpaquePtr();
1037 static constexpr
int NumLowBitsAvailable = 0;
1052 static constexpr
int NumLowBitsAvailable = 1;
1065 static constexpr
int NumLowBitsAvailable = 1;
1070 #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)