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"
38class DeclarationNameTable;
41class 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;
293 if (ObjCOrBuiltinID < tok::NUM_OBJC_KEYWORDS)
296 return tok::objc_not_keyword;
304 if (ObjCOrBuiltinID >= tok::NUM_OBJC_KEYWORDS)
305 return ObjCOrBuiltinID - tok::NUM_OBJC_KEYWORDS;
310 ObjCOrBuiltinID = ID + tok::NUM_OBJC_KEYWORDS;
311 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
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) {
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;
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;
946 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
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;
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Defines the Diagnostic IDs-related interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static std::string getName(const CallEvent &Call)
Defines the clang::TokenKind enum and support functions.
The name of a declaration.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Provides lookups to, and iteration over, IdentiferInfo objects.
virtual ~IdentifierInfoLookup()
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
One of these records is kept for each identifier that is lexed.
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier.
IdentifierInfo(const IdentifierInfo &)=delete
IdentifierInfo(IdentifierInfo &&)=delete
bool isModulesImport() const
Determine whether this is the contextual keyword import.
void revertIdentifierToTokenID(tok::TokenKind TK)
unsigned getLength() const
Efficiently return the length of this identifier info.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
void setIsExtensionToken(bool Val)
void setIsRestrictExpansion(bool Val)
void setFETokenInfo(void *T)
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
bool isCPlusPlusOperatorKeyword() const
IdentifierInfo & operator=(const IdentifierInfo &)=delete
void setIsDeprecatedMacro(bool Val)
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
void setMangledOpenMPVariantName(bool I)
Set whether this is the mangled name of an OpenMP variant.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
void setIsFinal(bool Val)
IdentifierInfo & operator=(IdentifierInfo &&)=delete
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
bool isPoisoned() const
Return true if this token has been poisoned.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
bool isMangledOpenMPVariantName() const
Determine whether this is the mangled name of an OpenMP variant.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source.
void setHasMacroDefinition(bool Val)
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
unsigned getObjCOrBuiltinID() const
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
void setObjCOrBuiltinID(unsigned ID)
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
void setBuiltinID(unsigned ID)
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
bool isDeprecatedMacro() const
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void setIsFutureCompatKeyword(bool Val)
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void * getFETokenInfo() const
Get and set FETokenInfo.
StringRef getName() const
Return the actual identifier string.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension.
bool isRestrictExpansion() const
An iterator that walks over all of the known identifiers in the lookup table.
virtual StringRef Next()=0
Retrieve the next string in the identifier table and advances the iterator for the following string.
IdentifierIterator & operator=(const IdentifierIterator &)=delete
IdentifierIterator(const IdentifierIterator &)=delete
virtual ~IdentifierIterator()
IdentifierIterator()=default
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
iterator find(StringRef Name) const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfo & get(StringRef Name, tok::TokenKind TokenCode)
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
HashTableTy::const_iterator iterator
HashTableTy::const_iterator const_iterator
llvm::BumpPtrAllocator & getAllocator()
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
An RAII object for [un]poisoning an identifier within a scope.
~PoisonIdentifierRAIIObject()
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
This table allows us to fully hide how we implement multi-keyword caching.
SelectorTable(const SelectorTable &)=delete
SelectorTable & operator=(const SelectorTable &)=delete
Selector getNullarySelector(IdentifierInfo *ID)
Selector getUnarySelector(IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
Selector()=default
The default ctor should only be used when creating data structures that will contain selectors.
static Selector getEmptyMarker()
static Selector getTombstoneMarker()
void * getAsOpaquePtr() const
bool isKeywordSelector() const
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
bool isUnarySelector() const
bool operator!=(Selector RHS) const
bool isNull() const
Determine whether this is the empty selector.
ObjCStringFormatFamily getStringFormatFamily() const
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
static constexpr int ObjCOrBuiltinIDBits
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
@ ObjCMethodFamilyBitWidth
ObjCMethodFamily
A family of Objective-C methods.
@ OMF_None
No particular method family.
@ InvalidObjCMethodFamily
@ IdentifierInfoAlignment
ObjCInstanceTypeFamily
A family of Objective-C methods.
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
llvm::StringRef getAsString(SyncScope S)
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
@ StartsWithDoubleUnderscore
@ StartsWithUnderscoreFollowedByCapitalLetter
@ ContainsDoubleUnderscore
@ StartsWithUnderscoreAtGlobalScope
@ StartsWithUnderscoreAndIsExternC
YAML serialization mapping.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
static clang::Selector getEmptyKey()
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
static clang::Selector getTombstoneKey()
static void * getAsVoidPointer(clang::IdentifierInfo *P)
static clang::IdentifierInfo * getFromVoidPointer(void *P)
static clang::Selector getFromVoidPointer(const void *P)
static const void * getAsVoidPointer(clang::Selector P)
static const void * getAsVoidPointer(const clang::IdentifierInfo *P)
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)