16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 17 #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" 37 class DeclarationName;
38 class DeclarationNameTable;
41 class MultiKeywordSelector;
67 unsigned ObjCOrBuiltinID : 13;
70 unsigned HasMacro : 1;
73 unsigned HadMacro : 1;
76 unsigned IsExtension : 1;
79 unsigned IsFutureCompatKeyword : 1;
82 unsigned IsPoisoned : 1;
85 unsigned IsCPPOperatorKeyword : 1;
89 unsigned NeedsHandleIdentifier : 1;
92 unsigned IsFromAST : 1;
96 unsigned ChangedAfterLoad : 1;
100 unsigned FEChangedAfterLoad : 1;
103 unsigned RevertedTokenID : 1;
107 unsigned OutOfDate : 1;
110 unsigned IsModulesImport : 1;
115 void *FETokenInfo =
nullptr;
117 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
120 : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(
false),
122 IsPoisoned(
false), IsCPPOperatorKeyword(
false),
123 NeedsHandleIdentifier(
false), IsFromAST(
false), ChangedAfterLoad(
false),
125 IsModulesImport(
false) {}
136 template <std::
size_t StrLen>
137 bool isStr(
const char (&Str)[StrLen])
const {
138 return getLength() == StrLen-1 &&
139 memcmp(getNameStart(), Str, StrLen-1) == 0;
143 bool isStr(llvm::StringRef Str)
const {
144 llvm::StringRef ThisStr(getNameStart(), getLength());
145 return ThisStr == Str;
153 unsigned getLength()
const {
return Entry->getKeyLength(); }
157 return StringRef(getNameStart(), getLength());
166 if (HasMacro == Val)
return;
170 NeedsHandleIdentifier =
true;
173 RecomputeNeedsHandleIdentifier();
198 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
199 TokenID = tok::identifier;
200 RevertedTokenID =
true;
203 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
205 RevertedTokenID =
false;
220 return tok::objc_not_keyword;
247 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
248 &&
"ID too large for field!");
261 NeedsHandleIdentifier =
true;
263 RecomputeNeedsHandleIdentifier();
273 IsFutureCompatKeyword = Val;
275 NeedsHandleIdentifier =
true;
277 RecomputeNeedsHandleIdentifier();
285 NeedsHandleIdentifier =
true;
287 RecomputeNeedsHandleIdentifier();
296 IsCPPOperatorKeyword = Val;
305 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
328 return ChangedAfterLoad;
334 ChangedAfterLoad =
true;
340 return FEChangedAfterLoad;
346 FEChangedAfterLoad =
true;
358 NeedsHandleIdentifier =
true;
360 RecomputeNeedsHandleIdentifier();
370 NeedsHandleIdentifier =
true;
372 RecomputeNeedsHandleIdentifier();
400 void RecomputeNeedsHandleIdentifier() {
401 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
402 isExtensionToken() || isFutureCompatKeyword() ||
403 isOutOfDate() || isModulesImport();
417 : II(II), OldValue(II ? II->isPoisoned() :
false) {
453 virtual StringRef Next() = 0;
489 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
490 HashTableTy HashTable;
505 ExternalLookup = IILookup;
510 return ExternalLookup;
514 return HashTable.getAllocator();
520 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
526 if (ExternalLookup) {
527 II = ExternalLookup->
get(Name);
545 II.TokenID = TokenCode;
546 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
557 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
572 if (Name.equals(
"import"))
583 unsigned size()
const {
return HashTable.size(); }
587 void PrintStats()
const;
678 enum IdentifierInfoFlag {
694 InfoPtr =
reinterpret_cast<uintptr_t>(II);
695 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
696 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
701 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
702 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
707 if (getIdentifierInfoFlag() < MultiArg)
716 unsigned getIdentifierInfoFlag()
const {
717 return InfoPtr & ArgFlags;
732 return InfoPtr == RHS.InfoPtr;
735 return InfoPtr != RHS.InfoPtr;
739 return reinterpret_cast<void*
>(InfoPtr);
743 bool isNull()
const {
return InfoPtr == 0; }
747 return getIdentifierInfoFlag() != ZeroArg;
751 return getIdentifierInfoFlag() == ZeroArg;
754 unsigned getNumArgs()
const;
769 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
779 StringRef getNameForSlot(
unsigned argIndex)
const;
786 void print(llvm::raw_ostream &OS)
const;
792 return getMethodFamilyImpl(*
this);
796 return getStringFormatFamilyImpl(*
this);
837 size_t getTotalMemory()
const;
854 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
898 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
902 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
903 (unsigned)ObjCMultiArgSelector
904 ? (
unsigned)ObjCMultiArgSelector
905 : ExtraKindOrNumArgs);
911 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
912 "getNumArgs called but this is not an ObjC selector!");
913 return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector;
955 enum { NumLowBitsAvailable = 0 };
970 enum { NumLowBitsAvailable = 1 };
983 enum { NumLowBitsAvailable = 1 };
988 #endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
~PoisonIdentifierRAIIObject()
Smart pointer class that efficiently represents Objective-C method names.
void * getAsOpaquePtr() const
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)
void revertIdentifierToTokenID(tok::TokenKind TK)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
static clang::Selector getEmptyKey()
void setIsExtensionToken(bool Val)
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
static clang::Selector getFromVoidPointer(const void *P)
std::string getName(ArrayRef< StringRef > Parts) const
Get the platform-specific name separator.
Selector getUnarySelector(IdentifierInfo *ID)
One of these records is kept for each identifier that is lexed.
This table allows us to fully hide how we implement multi-keyword caching.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
HashTableTy::const_iterator const_iterator
void setHasMacroDefinition(bool Val)
ObjCMethodFamily
A family of Objective-C methods.
bool isCPlusPlusOperatorKeyword() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
bool isUnarySelector() const
void setIsFutureCompatKeyword(bool Val)
Selector getNullarySelector(IdentifierInfo *ID)
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
bool hasRevertedBuiltin() const
True if setNotBuiltin() was called.
static clang::Selector getTombstoneKey()
void revertBuiltin()
Revert the identifier to a non-builtin identifier.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool operator!=(Selector RHS) const
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
HashTableTy::const_iterator iterator
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
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...
One of these variable length records is kept for each selector containing more than one keyword...
ObjCStringFormatFamily getStringFormatFamily() const
llvm::StringRef getAsString(SyncScope S)
Implements an efficient mapping from strings to IdentifierInfo nodes.
void setFETokenInfo(void *T)
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
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.
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
ObjCInstanceTypeFamily
A family of Objective-C methods.
static const void * getAsVoidPointer(clang::Selector P)
An iterator that walks over all of the known identifiers in the lookup table.
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
__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)
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
static void * getAsVoidPointer(clang::IdentifierInfo *P)
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
static clang::IdentifierInfo * getFromVoidPointer(void *P)
llvm::BumpPtrAllocator & getAllocator()
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
bool isPoisoned() const
Return true if this token has been poisoned.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
StringRef getName() const
Return the actual identifier string.
unsigned getObjCOrBuiltinID() const
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Dataflow Directional Tag Classes.
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier...
The name of a declaration.
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension...
bool isKeywordSelector() const
void * getFETokenInfo() const
Get and set FETokenInfo.
static Selector getTombstoneMarker()
static Selector getEmptyMarker()
void setBuiltinID(unsigned ID)
Defines the clang::TokenKind enum and support functions.
No particular method family.
static const void * getAsVoidPointer(const clang::IdentifierInfo *P)
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source...
bool isNull() const
Determine whether this is the empty selector.
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 isModulesImport() const
Determine whether this is the contextual keyword import.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
void setObjCOrBuiltinID(unsigned ID)
An RAII object for [un]poisoning an identifier within a scope.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.