16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
17 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/StringRef.h"
27 template <
typename T>
struct DenseMapInfo;
33 class IdentifierTable;
35 class MultiKeywordSelector;
52 unsigned ObjCOrBuiltinID :13;
56 bool IsFutureCompatKeyword : 1;
59 bool IsCPPOperatorKeyword : 1;
60 bool NeedsHandleIdentifier : 1;
63 bool ChangedAfterLoad : 1;
65 bool RevertedTokenID : 1;
70 bool IsModulesImport : 1;
75 llvm::StringMapEntry<IdentifierInfo*> *Entry;
89 template <std::
size_t StrLen>
90 bool isStr(
const char (&Str)[StrLen])
const {
98 if (Entry)
return Entry->getKeyData();
104 typedef std::pair<IdentifierInfo, const char*> actualtype;
105 return ((
const actualtype*)
this)->second;
111 if (Entry)
return Entry->getKeyLength();
117 typedef std::pair<IdentifierInfo, const char*> actualtype;
118 const char*
p = ((
const actualtype*)
this)->second - 2;
119 return (((
unsigned) p[0]) | (((
unsigned) p[1]) << 8)) - 1;
133 if (HasMacro == Val)
return;
137 NeedsHandleIdentifier = 1;
140 RecomputeNeedsHandleIdentifier();
165 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
166 TokenID = tok::identifier;
167 RevertedTokenID =
true;
182 return tok::objc_not_keyword;
198 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
199 &&
"ID too large for field!");
212 NeedsHandleIdentifier = 1;
214 RecomputeNeedsHandleIdentifier();
224 IsFutureCompatKeyword = Val;
226 NeedsHandleIdentifier = 1;
228 RecomputeNeedsHandleIdentifier();
236 NeedsHandleIdentifier = 1;
238 RecomputeNeedsHandleIdentifier();
247 IsCPPOperatorKeyword = Val;
249 NeedsHandleIdentifier = 1;
251 RecomputeNeedsHandleIdentifier();
280 return ChangedAfterLoad;
286 ChangedAfterLoad =
true;
298 NeedsHandleIdentifier =
true;
300 RecomputeNeedsHandleIdentifier();
310 NeedsHandleIdentifier =
true;
312 RecomputeNeedsHandleIdentifier();
327 void RecomputeNeedsHandleIdentifier() {
328 NeedsHandleIdentifier =
344 : II(II), OldValue(II ? II->isPoisoned() :
false) {
381 virtual StringRef
Next() = 0;
417 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
418 HashTableTy HashTable;
430 ExternalLookup = IILookup;
435 return ExternalLookup;
439 return HashTable.getAllocator();
445 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
451 if (ExternalLookup) {
452 II = ExternalLookup->
get(Name);
470 II.TokenID = TokenCode;
471 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
482 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
497 if (Name.equals(
"import"))
508 unsigned size()
const {
return HashTable.size(); }
599 enum IdentifierInfoFlag {
604 ArgFlags = ZeroArg|OneArg
609 InfoPtr =
reinterpret_cast<uintptr_t
>(II);
610 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
611 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
614 Selector(MultiKeywordSelector *SI) {
615 InfoPtr =
reinterpret_cast<uintptr_t
>(SI);
616 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
620 IdentifierInfo *getAsIdentifierInfo()
const {
621 if (getIdentifierInfoFlag() < MultiArg)
622 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
625 MultiKeywordSelector *getMultiKeywordSelector()
const {
626 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
629 unsigned getIdentifierInfoFlag()
const {
630 return InfoPtr & ArgFlags;
648 return InfoPtr == RHS.InfoPtr;
651 return InfoPtr != RHS.InfoPtr;
654 return reinterpret_cast<void*
>(InfoPtr);
658 bool isNull()
const {
return InfoPtr == 0; }
662 return getIdentifierInfoFlag() != ZeroArg;
665 return getIdentifierInfoFlag() == ZeroArg;
700 void print(llvm::raw_ostream &OS)
const;
704 return getMethodFamilyImpl(*
this);
708 return getStringFormatFamilyImpl(*
this);
774 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
776 #include "clang/Basic/OperatorKinds.def"
816 struct isPodLike<clang::Selector> {
static const bool value =
true; };
829 enum { NumLowBitsAvailable = 0 };
843 enum { NumLowBitsAvailable = 1 };
855 enum { NumLowBitsAvailable = 1 };
bool isPoisoned() const
Return true if this token has been poisoned.
void AddKeywords(const LangOptions &LangOpts)
~PoisonIdentifierRAIIObject()
Smart pointer class that efficiently represents Objective-C method names.
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
static const void * getAsVoidPointer(clang::Selector P)
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
static clang::Selector getEmptyKey()
void setIsExtensionToken(bool Val)
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
size_t getTotalMemory() const
Return the total amount of memory allocated for managing selectors.
ObjCStringFormatFamily getStringFormatFamily() const
unsigned getLength() const
Efficiently return the length of this identifier info.
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
void * getAsOpaquePtr() const
virtual IdentifierIterator * getIdentifiers()
Retrieve an iterator into the set of all identifiers known to this identifier lookup source...
bool isModulesImport() const
Determine whether this is the contextual keyword import.
Selector getUnarySelector(IdentifierInfo *ID)
static ObjCInstanceTypeFamily getInstTypeMethodFamily(Selector sel)
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
This table allows us to fully hide how we implement multi-keyword caching.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
void setHasMacroDefinition(bool Val)
ObjCMethodFamily
A family of Objective-C methods.
bool isKeywordSelector() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isNull() const
Determine whether this is the empty selector.
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
void setIsFutureCompatKeyword(bool Val)
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
static Selector constructSetterSelector(IdentifierTable &Idents, SelectorTable &SelTable, const IdentifierInfo *Name)
Return the default setter selector for the given identifier.
Selector getNullarySelector(IdentifierInfo *ID)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
tok::TokenKind getTokenID() const
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
bool isFutureCompatKeyword() const
static clang::Selector getTombstoneKey()
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
unsigned getObjCOrBuiltinID() const
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
bool isCPlusPlusOperatorKeyword() const
bool operator!=(Selector RHS) const
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
Provides lookups to, and iteration over, IdentiferInfo objects.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
ID
Defines the set of possible language-specific address spaces.
bool isUnarySelector() const
StringRef getName() const
Return the actual identifier string.
unsigned getNumArgs() const
virtual StringRef Next()=0
Retrieve the next string in the identifier table and advances the iterator for the following string...
Implements an efficient mapping from strings to IdentifierInfo nodes.
void setFETokenInfo(void *T)
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
void setIsPoisoned(bool Value=true)
ObjCInstanceTypeFamily
A family of Objective-C methods.
An iterator that walks over all of the known identifiers in the lookup table.
static const void * getAsVoidPointer(const clang::IdentifierInfo *P)
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier...
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
HashTableTy::const_iterator const_iterator
static clang::IdentifierInfo * getFromVoidPointer(void *P)
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
llvm::BumpPtrAllocator & getAllocator()
static clang::Selector getFromVoidPointer(const void *P)
bool isKeyword(const LangOptions &LangOpts)
Return true if this token is a keyword in the specified language.
IdentifierTable(const LangOptions &LangOpts, IdentifierInfoLookup *externalLookup=nullptr)
Create the identifier table, populating it with info about the language keywords for the language spe...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
virtual ~IdentifierIterator()
std::string getAsString() const
Derive the full selector name (e.g. "foo:bar:") and return it as an std::string.
HashTableTy::const_iterator iterator
virtual ~IdentifierInfoLookup()
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
void RevertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
static __inline__ uint32_t volatile uint32_t * p
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)
bool isExtensionToken() const
static Selector getTombstoneMarker()
static Selector getEmptyMarker()
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
void setBuiltinID(unsigned ID)
void PrintStats() const
Print some statistics to stderr that indicate how well the hashing is doing.
Defines the clang::TokenKind enum and support functions.
No particular method family.
bool hasRevertedTokenIDToIdentifier() const
True if RevertTokenIDToIdentifier() was called.
static void * getAsVoidPointer(clang::IdentifierInfo *P)
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source...
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment. In this case there should b...
T * getFETokenInfo() const
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
void setObjCOrBuiltinID(unsigned ID)
An RAII object for [un]poisoning an identifier within a scope.
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.