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();
392 const char *Name = getNameStart();
393 return Name[0] ==
'_' &&
395 (Name[1] >=
'A' && Name[1] <=
'Z' && !doubleUnderscoreOnly));
410 void RecomputeNeedsHandleIdentifier() {
411 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
412 isExtensionToken() || isFutureCompatKeyword() ||
413 isOutOfDate() || isModulesImport();
427 : II(II), OldValue(II ? II->isPoisoned() :
false) {
463 virtual StringRef Next() = 0;
499 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
500 HashTableTy HashTable;
515 ExternalLookup = IILookup;
520 return ExternalLookup;
524 return HashTable.getAllocator();
530 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
536 if (ExternalLookup) {
537 II = ExternalLookup->
get(Name);
555 II.TokenID = TokenCode;
556 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
567 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
582 if (Name.equals(
"import"))
593 unsigned size()
const {
return HashTable.size(); }
599 void PrintStats()
const;
690 enum IdentifierInfoFlag {
706 InfoPtr =
reinterpret_cast<uintptr_t>(II);
707 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
708 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
713 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
714 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
719 if (getIdentifierInfoFlag() < MultiArg)
728 unsigned getIdentifierInfoFlag()
const {
729 return InfoPtr & ArgFlags;
744 return InfoPtr == RHS.InfoPtr;
747 return InfoPtr != RHS.InfoPtr;
751 return reinterpret_cast<void*
>(InfoPtr);
755 bool isNull()
const {
return InfoPtr == 0; }
759 return getIdentifierInfoFlag() != ZeroArg;
763 return getIdentifierInfoFlag() == ZeroArg;
770 bool isUnarySelector(StringRef Name)
const;
772 unsigned getNumArgs()
const;
787 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
797 StringRef getNameForSlot(
unsigned argIndex)
const;
804 void print(llvm::raw_ostream &OS)
const;
810 return getMethodFamilyImpl(*
this);
814 return getStringFormatFamilyImpl(*
this);
855 size_t getTotalMemory()
const;
872 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
916 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
920 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
921 (unsigned)ObjCMultiArgSelector
922 ? (
unsigned)ObjCMultiArgSelector
923 : ExtraKindOrNumArgs);
929 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
930 "getNumArgs called but this is not an ObjC selector!");
931 return ExtraKindOrNumArgs - (unsigned)ObjCMultiArgSelector;
970 enum { NumLowBitsAvailable = 0 };
985 enum { NumLowBitsAvailable = 1 };
998 enum { NumLowBitsAvailable = 1 };
1003 #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)
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
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)
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.
bool isReservedName(bool doubleUnderscoreOnly=false) const
Determine whether this is a name reserved for the implementation (C99 7.1.3, C++ [lib.global.names]).
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.
iterator find(StringRef Name) const
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.