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;
170 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
172 RevertedTokenID =
false;
187 return tok::objc_not_keyword;
215 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
216 &&
"ID too large for field!");
229 NeedsHandleIdentifier = 1;
231 RecomputeNeedsHandleIdentifier();
241 IsFutureCompatKeyword = Val;
243 NeedsHandleIdentifier = 1;
245 RecomputeNeedsHandleIdentifier();
253 NeedsHandleIdentifier = 1;
255 RecomputeNeedsHandleIdentifier();
264 IsCPPOperatorKeyword = Val;
266 NeedsHandleIdentifier = 1;
268 RecomputeNeedsHandleIdentifier();
297 return ChangedAfterLoad;
303 ChangedAfterLoad =
true;
315 NeedsHandleIdentifier =
true;
317 RecomputeNeedsHandleIdentifier();
327 NeedsHandleIdentifier =
true;
329 RecomputeNeedsHandleIdentifier();
344 void RecomputeNeedsHandleIdentifier() {
345 NeedsHandleIdentifier =
361 : II(II), OldValue(II ? II->isPoisoned() :
false) {
398 virtual StringRef
Next() = 0;
434 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
435 HashTableTy HashTable;
447 ExternalLookup = IILookup;
452 return ExternalLookup;
456 return HashTable.getAllocator();
462 auto &Entry = *HashTable.insert(std::make_pair(
Name,
nullptr)).first;
468 if (ExternalLookup) {
469 II = ExternalLookup->
get(
Name);
487 II.TokenID = TokenCode;
488 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
499 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
514 if (Name.equals(
"import"))
525 unsigned size()
const {
return HashTable.size(); }
616 enum IdentifierInfoFlag {
621 ArgFlags = ZeroArg|OneArg
626 InfoPtr =
reinterpret_cast<uintptr_t
>(II);
627 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
628 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
631 Selector(MultiKeywordSelector *SI) {
632 InfoPtr =
reinterpret_cast<uintptr_t
>(SI);
633 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
637 IdentifierInfo *getAsIdentifierInfo()
const {
638 if (getIdentifierInfoFlag() < MultiArg)
639 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
642 MultiKeywordSelector *getMultiKeywordSelector()
const {
643 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
646 unsigned getIdentifierInfoFlag()
const {
647 return InfoPtr & ArgFlags;
665 return InfoPtr == RHS.InfoPtr;
668 return InfoPtr != RHS.InfoPtr;
671 return reinterpret_cast<void*
>(InfoPtr);
675 bool isNull()
const {
return InfoPtr == 0; }
679 return getIdentifierInfoFlag() != ZeroArg;
682 return getIdentifierInfoFlag() == ZeroArg;
717 void print(llvm::raw_ostream &OS)
const;
721 return getMethodFamilyImpl(*
this);
725 return getStringFormatFamilyImpl(*
this);
791 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
793 #include "clang/Basic/OperatorKinds.def"
833 struct isPodLike<clang::Selector> {
static const bool value =
true; };
846 enum { NumLowBitsAvailable = 0 };
860 enum { NumLowBitsAvailable = 1 };
872 enum { NumLowBitsAvailable = 1 };
bool isPoisoned() const
Return true if this token has been poisoned.
void AddKeywords(const LangOptions &LangOpts)
AddKeywords - Add all keywords to the symbol table.
~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.
void revertIdentifierToTokenID(tok::TokenKind TK)
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)
One of these records is kept for each identifier that is lexed.
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.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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
If this is a source-language token (e.g.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
static clang::Selector getTombstoneKey()
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
void revertBuiltin()
Revert the identifier to a non-builtin identifier.
detail::InMemoryDirectory::const_iterator I
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)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
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)
setIsPoisoned - Mark this identifier as poisoned.
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)
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
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 hasRevertedBuiltin() const
True if setNotBuiltin() was called.
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)
Selector()
The default ctor should only be used when creating data structures that will contain selectors...
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.
HashTableTy::const_iterator iterator
virtual ~IdentifierInfoLookup()
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
static __inline__ uint32_t volatile uint32_t * p
DeclarationName - The name of a declaration.
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension...
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...
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
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.
T * getFETokenInfo() const
getFETokenInfo/setFETokenInfo - The language front-end is allowed to associate arbitrary metadata wit...
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.