16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
17 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_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"
35 template <
typename T>
struct DenseMapInfo;
43 class IdentifierTable;
45 class MultiKeywordSelector;
63 unsigned ObjCOrBuiltinID :13;
67 bool IsFutureCompatKeyword : 1;
70 bool IsCPPOperatorKeyword : 1;
71 bool NeedsHandleIdentifier : 1;
74 bool ChangedAfterLoad : 1;
76 bool FEChangedAfterLoad : 1;
79 bool RevertedTokenID : 1;
84 bool IsModulesImport : 1;
89 llvm::StringMapEntry<IdentifierInfo*> *Entry;
99 template <std::
size_t StrLen>
100 bool isStr(
const char (&Str)[StrLen])
const {
109 if (Entry)
return Entry->getKeyData();
115 typedef std::pair<IdentifierInfo, const char*> actualtype;
116 return ((
const actualtype*)
this)->second;
122 if (Entry)
return Entry->getKeyLength();
128 typedef std::pair<IdentifierInfo, const char*> actualtype;
129 const char* p = ((
const actualtype*)
this)->second - 2;
130 return (((
unsigned) p[0]) | (((
unsigned) p[1]) << 8)) - 1;
144 if (HasMacro == Val)
return;
148 NeedsHandleIdentifier =
true;
151 RecomputeNeedsHandleIdentifier();
176 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
177 TokenID = tok::identifier;
178 RevertedTokenID =
true;
181 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
183 RevertedTokenID =
false;
198 return tok::objc_not_keyword;
225 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
226 &&
"ID too large for field!");
239 NeedsHandleIdentifier =
true;
241 RecomputeNeedsHandleIdentifier();
251 IsFutureCompatKeyword = Val;
253 NeedsHandleIdentifier =
true;
255 RecomputeNeedsHandleIdentifier();
263 NeedsHandleIdentifier =
true;
265 RecomputeNeedsHandleIdentifier();
274 IsCPPOperatorKeyword = Val;
307 return ChangedAfterLoad;
313 ChangedAfterLoad =
true;
319 return FEChangedAfterLoad;
325 FEChangedAfterLoad =
true;
337 NeedsHandleIdentifier =
true;
339 RecomputeNeedsHandleIdentifier();
349 NeedsHandleIdentifier =
true;
351 RecomputeNeedsHandleIdentifier();
379 void RecomputeNeedsHandleIdentifier() {
396 : II(II), OldValue(II ? II->isPoisoned() :
false) {
432 virtual StringRef
Next() = 0;
468 typedef llvm::StringMap<IdentifierInfo*, llvm::BumpPtrAllocator> HashTableTy;
469 HashTableTy HashTable;
481 ExternalLookup = IILookup;
486 return ExternalLookup;
490 return HashTable.getAllocator();
496 auto &Entry = *HashTable.insert(std::make_pair(
Name,
nullptr)).first;
502 if (ExternalLookup) {
503 II = ExternalLookup->
get(
Name);
521 II.TokenID = TokenCode;
522 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
533 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
548 if (Name.equals(
"import"))
559 unsigned size()
const {
return HashTable.size(); }
650 enum IdentifierInfoFlag {
655 ArgFlags = ZeroArg|OneArg
660 InfoPtr =
reinterpret_cast<uintptr_t>(II);
661 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
662 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
665 Selector(MultiKeywordSelector *SI) {
666 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
667 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
671 IdentifierInfo *getAsIdentifierInfo()
const {
672 if (getIdentifierInfoFlag() < MultiArg)
673 return reinterpret_cast<IdentifierInfo *
>(InfoPtr & ~ArgFlags);
677 MultiKeywordSelector *getMultiKeywordSelector()
const {
678 return reinterpret_cast<MultiKeywordSelector *
>(InfoPtr & ~ArgFlags);
681 unsigned getIdentifierInfoFlag()
const {
682 return InfoPtr & ArgFlags;
700 return InfoPtr == RHS.InfoPtr;
703 return InfoPtr != RHS.InfoPtr;
707 return reinterpret_cast<void*
>(InfoPtr);
711 bool isNull()
const {
return InfoPtr == 0; }
715 return getIdentifierInfoFlag() != ZeroArg;
719 return getIdentifierInfoFlag() == ZeroArg;
754 void print(llvm::raw_ostream &OS)
const;
758 return getMethodFamilyImpl(*
this);
762 return getStringFormatFamilyImpl(*
this);
830 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
832 #include "clang/Basic/OperatorKinds.def"
875 struct isPodLike<clang::Selector> {
static const bool value =
true; };
890 enum { NumLowBitsAvailable = 0 };
906 enum { NumLowBitsAvailable = 1 };
920 enum { NumLowBitsAvailable = 1 };
925 #endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
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)
IdentifierIterator & operator=(const IdentifierIterator &)=delete
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.
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
SelectorTable & operator=(const SelectorTable &)=delete
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)
bool isKeyword(const LangOptions &LangOpts) const
Return true if this token is a keyword in the specified language.
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)
__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)
IdentifierInfo & operator=(const IdentifierInfo &)=delete
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)
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...
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
static Selector getTombstoneMarker()
static Selector getEmptyMarker()
bool isCPlusPlusKeyword(const LangOptions &LangOpts) const
Return true if this token is a C++ keyword in the specified language.
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.
IdentifierIterator()=default