15 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 16 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 20 #include "llvm/ADT/DenseMapInfo.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" 25 #include "llvm/Support/PointerLikeTypeTraits.h" 26 #include "llvm/Support/type_traits.h" 36 class DeclarationName;
37 class DeclarationNameTable;
40 class MultiKeywordSelector;
66 unsigned ObjCOrBuiltinID : 13;
69 unsigned HasMacro : 1;
72 unsigned HadMacro : 1;
75 unsigned IsExtension : 1;
78 unsigned IsFutureCompatKeyword : 1;
81 unsigned IsPoisoned : 1;
84 unsigned IsCPPOperatorKeyword : 1;
88 unsigned NeedsHandleIdentifier : 1;
91 unsigned IsFromAST : 1;
95 unsigned ChangedAfterLoad : 1;
99 unsigned FEChangedAfterLoad : 1;
102 unsigned RevertedTokenID : 1;
106 unsigned OutOfDate : 1;
109 unsigned IsModulesImport : 1;
114 void *FETokenInfo =
nullptr;
116 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
119 : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(
false),
121 IsPoisoned(
false), IsCPPOperatorKeyword(
false),
122 NeedsHandleIdentifier(
false), IsFromAST(
false), ChangedAfterLoad(
false),
124 IsModulesImport(
false) {}
135 template <std::
size_t StrLen>
136 bool isStr(
const char (&Str)[StrLen])
const {
137 return getLength() == StrLen-1 &&
138 memcmp(getNameStart(), Str, StrLen-1) == 0;
142 bool isStr(llvm::StringRef Str)
const {
143 llvm::StringRef ThisStr(getNameStart(), getLength());
144 return ThisStr == Str;
152 unsigned getLength()
const {
return Entry->getKeyLength(); }
156 return StringRef(getNameStart(), getLength());
165 if (HasMacro == Val)
return;
169 NeedsHandleIdentifier =
true;
172 RecomputeNeedsHandleIdentifier();
197 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
198 TokenID = tok::identifier;
199 RevertedTokenID =
true;
202 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
204 RevertedTokenID =
false;
219 return tok::objc_not_keyword;
246 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
247 &&
"ID too large for field!");
260 NeedsHandleIdentifier =
true;
262 RecomputeNeedsHandleIdentifier();
272 IsFutureCompatKeyword = Val;
274 NeedsHandleIdentifier =
true;
276 RecomputeNeedsHandleIdentifier();
284 NeedsHandleIdentifier =
true;
286 RecomputeNeedsHandleIdentifier();
295 IsCPPOperatorKeyword = Val;
304 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
327 return ChangedAfterLoad;
333 ChangedAfterLoad =
true;
339 return FEChangedAfterLoad;
345 FEChangedAfterLoad =
true;
357 NeedsHandleIdentifier =
true;
359 RecomputeNeedsHandleIdentifier();
369 NeedsHandleIdentifier =
true;
371 RecomputeNeedsHandleIdentifier();
399 void RecomputeNeedsHandleIdentifier() {
400 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
401 isExtensionToken() || isFutureCompatKeyword() ||
402 isOutOfDate() || isModulesImport();
416 : II(II), OldValue(II ? II->isPoisoned() :
false) {
452 virtual StringRef Next() = 0;
488 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
489 HashTableTy HashTable;
504 ExternalLookup = IILookup;
509 return ExternalLookup;
513 return HashTable.getAllocator();
519 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
525 if (ExternalLookup) {
526 II = ExternalLookup->
get(Name);
544 II.TokenID = TokenCode;
545 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
556 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
571 if (Name.equals(
"import"))
582 unsigned size()
const {
return HashTable.size(); }
586 void PrintStats()
const;
677 enum IdentifierInfoFlag {
693 InfoPtr =
reinterpret_cast<uintptr_t>(II);
694 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
695 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
700 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
701 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
706 if (getIdentifierInfoFlag() < MultiArg)
715 unsigned getIdentifierInfoFlag()
const {
716 return InfoPtr & ArgFlags;
731 return InfoPtr == RHS.InfoPtr;
734 return InfoPtr != RHS.InfoPtr;
738 return reinterpret_cast<void*
>(InfoPtr);
742 bool isNull()
const {
return InfoPtr == 0; }
746 return getIdentifierInfoFlag() != ZeroArg;
750 return getIdentifierInfoFlag() == ZeroArg;
753 unsigned getNumArgs()
const;
768 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
778 StringRef getNameForSlot(
unsigned argIndex)
const;
785 void print(llvm::raw_ostream &OS)
const;
791 return getMethodFamilyImpl(*
this);
795 return getStringFormatFamilyImpl(*
this);
836 size_t getTotalMemory()
const;
853 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
897 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
901 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
902 (unsigned)ObjCMultiArgSelector
903 ? (
unsigned)ObjCMultiArgSelector
904 : ExtraKindOrNumArgs);
910 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
911 "getNumArgs called but this is not an ObjC selector!");
912 return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector;
951 enum { NumLowBitsAvailable = 0 };
966 enum { NumLowBitsAvailable = 1 };
979 enum { NumLowBitsAvailable = 1 };
984 #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)
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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)
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.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
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.
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.
static std::string getName(const CallEvent &Call)
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.