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 FEChangedAfterLoad : 1;
68 bool RevertedTokenID : 1;
73 bool IsModulesImport : 1;
78 llvm::StringMapEntry<IdentifierInfo*> *Entry;
92 template <std::
size_t StrLen>
93 bool isStr(
const char (&Str)[StrLen])
const {
101 if (Entry)
return Entry->getKeyData();
107 typedef std::pair<IdentifierInfo, const char*> actualtype;
108 return ((
const actualtype*)
this)->second;
114 if (Entry)
return Entry->getKeyLength();
120 typedef std::pair<IdentifierInfo, const char*> actualtype;
121 const char* p = ((
const actualtype*)
this)->second - 2;
122 return (((
unsigned) p[0]) | (((
unsigned) p[1]) << 8)) - 1;
136 if (HasMacro == Val)
return;
140 NeedsHandleIdentifier = 1;
143 RecomputeNeedsHandleIdentifier();
168 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
169 TokenID = tok::identifier;
170 RevertedTokenID =
true;
173 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
175 RevertedTokenID =
false;
190 return tok::objc_not_keyword;
218 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
219 &&
"ID too large for field!");
232 NeedsHandleIdentifier = 1;
234 RecomputeNeedsHandleIdentifier();
244 IsFutureCompatKeyword = Val;
246 NeedsHandleIdentifier = 1;
248 RecomputeNeedsHandleIdentifier();
256 NeedsHandleIdentifier = 1;
258 RecomputeNeedsHandleIdentifier();
267 IsCPPOperatorKeyword = Val;
269 NeedsHandleIdentifier = 1;
271 RecomputeNeedsHandleIdentifier();
300 return ChangedAfterLoad;
306 ChangedAfterLoad =
true;
312 return FEChangedAfterLoad;
318 FEChangedAfterLoad =
true;
330 NeedsHandleIdentifier =
true;
332 RecomputeNeedsHandleIdentifier();
342 NeedsHandleIdentifier =
true;
344 RecomputeNeedsHandleIdentifier();
359 void RecomputeNeedsHandleIdentifier() {
360 NeedsHandleIdentifier =
376 : II(II), OldValue(II ? II->isPoisoned() :
false) {
413 virtual StringRef
Next() = 0;
449 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
450 HashTableTy HashTable;
462 ExternalLookup = IILookup;
467 return ExternalLookup;
471 return HashTable.getAllocator();
477 auto &Entry = *HashTable.insert(std::make_pair(
Name,
nullptr)).first;
483 if (ExternalLookup) {
484 II = ExternalLookup->
get(
Name);
502 II.TokenID = TokenCode;
503 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
514 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
529 if (Name.equals(
"import"))
540 unsigned size()
const {
return HashTable.size(); }
631 enum IdentifierInfoFlag {
636 ArgFlags = ZeroArg|OneArg
641 InfoPtr =
reinterpret_cast<uintptr_t>(II);
642 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
643 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
646 Selector(MultiKeywordSelector *SI) {
647 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
648 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
652 IdentifierInfo *getAsIdentifierInfo()
const {
653 if (getIdentifierInfoFlag() < MultiArg)
654 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
657 MultiKeywordSelector *getMultiKeywordSelector()
const {
658 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
661 unsigned getIdentifierInfoFlag()
const {
662 return InfoPtr & ArgFlags;
680 return InfoPtr == RHS.InfoPtr;
683 return InfoPtr != RHS.InfoPtr;
686 return reinterpret_cast<void*
>(InfoPtr);
690 bool isNull()
const {
return InfoPtr == 0; }
694 return getIdentifierInfoFlag() != ZeroArg;
697 return getIdentifierInfoFlag() == ZeroArg;
732 void print(llvm::raw_ostream &OS)
const;
736 return getMethodFamilyImpl(*
this);
740 return getStringFormatFamilyImpl(*
this);
806 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
808 #include "clang/Basic/OperatorKinds.def"
848 struct isPodLike<clang::Selector> {
static const bool value =
true; };
861 enum { NumLowBitsAvailable = 0 };
875 enum { NumLowBitsAvailable = 1 };
887 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.
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
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...
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...
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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.
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
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.
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.