15#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16#define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
21#include "llvm/ADT/DenseMapInfo.h"
22#include "llvm/ADT/FoldingSet.h"
23#include "llvm/ADT/PointerIntPair.h"
24#include "llvm/ADT/PointerUnion.h"
25#include "llvm/ADT/SmallString.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/Support/Allocator.h"
29#include "llvm/Support/PointerLikeTypeTraits.h"
30#include "llvm/Support/type_traits.h"
41class DeclarationNameTable;
44class MultiKeywordSelector;
114 unsigned TokenID : 9;
122 LLVM_PREFERRED_TYPE(
bool)
123 unsigned HasMacro : 1;
126 LLVM_PREFERRED_TYPE(
bool)
127 unsigned HadMacro : 1;
130 LLVM_PREFERRED_TYPE(
bool)
131 unsigned IsExtension : 1;
134 LLVM_PREFERRED_TYPE(
bool)
135 unsigned IsFutureCompatKeyword : 1;
138 LLVM_PREFERRED_TYPE(
bool)
139 unsigned IsPoisoned : 1;
142 LLVM_PREFERRED_TYPE(
bool)
143 unsigned IsCPPOperatorKeyword : 1;
147 LLVM_PREFERRED_TYPE(
bool)
148 unsigned NeedsHandleIdentifier : 1;
151 LLVM_PREFERRED_TYPE(
bool)
152 unsigned IsFromAST : 1;
156 LLVM_PREFERRED_TYPE(
bool)
157 unsigned ChangedAfterLoad : 1;
161 LLVM_PREFERRED_TYPE(
bool)
162 unsigned FEChangedAfterLoad : 1;
165 LLVM_PREFERRED_TYPE(
bool)
166 unsigned RevertedTokenID : 1;
170 LLVM_PREFERRED_TYPE(
bool)
171 unsigned OutOfDate : 1;
174 LLVM_PREFERRED_TYPE(
bool)
175 unsigned IsModulesImport : 1;
178 LLVM_PREFERRED_TYPE(
bool)
179 unsigned IsMangledOpenMPVariantName : 1;
182 LLVM_PREFERRED_TYPE(
bool)
183 unsigned IsDeprecatedMacro : 1;
186 LLVM_PREFERRED_TYPE(
bool)
187 unsigned IsRestrictExpansion : 1;
190 LLVM_PREFERRED_TYPE(
bool)
191 unsigned IsFinal : 1;
196 void *FETokenInfo =
nullptr;
198 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
201 : TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(
false),
203 IsPoisoned(
false), IsCPPOperatorKeyword(
false),
204 NeedsHandleIdentifier(
false), IsFromAST(
false), ChangedAfterLoad(
false),
206 IsModulesImport(
false), IsMangledOpenMPVariantName(
false),
207 IsDeprecatedMacro(
false), IsRestrictExpansion(
false), IsFinal(
false) {}
218 template <std::
size_t StrLen>
219 bool isStr(
const char (&Str)[StrLen])
const {
220 return getLength() == StrLen-1 &&
221 memcmp(getNameStart(), Str, StrLen-1) == 0;
225 bool isStr(llvm::StringRef Str)
const {
226 llvm::StringRef ThisStr(getNameStart(), getLength());
227 return ThisStr == Str;
235 unsigned getLength()
const {
return Entry->getKeyLength(); }
239 return StringRef(getNameStart(), getLength());
248 if (HasMacro == Val)
return;
252 NeedsHandleIdentifier =
true;
260 IsDeprecatedMacro =
false;
261 IsRestrictExpansion =
false;
263 RecomputeNeedsHandleIdentifier();
276 if (IsDeprecatedMacro == Val)
278 IsDeprecatedMacro = Val;
280 NeedsHandleIdentifier =
true;
282 RecomputeNeedsHandleIdentifier();
288 if (IsRestrictExpansion == Val)
290 IsRestrictExpansion = Val;
292 NeedsHandleIdentifier =
true;
294 RecomputeNeedsHandleIdentifier();
316 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
317 TokenID = tok::identifier;
318 RevertedTokenID =
true;
321 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
323 RevertedTokenID =
false;
336 "hard-coding this assumption to simplify code");
340 return tok::objc_not_keyword;
356 assert(getBuiltinID() ==
ID &&
"ID too large for field!");
366 return tok::not_interesting;
369 assert(
ID != tok::not_interesting);
371 assert(getInterestingIdentifierID() ==
ID &&
"ID too large for field!");
384 NeedsHandleIdentifier =
true;
386 RecomputeNeedsHandleIdentifier();
396 IsFutureCompatKeyword = Val;
398 NeedsHandleIdentifier =
true;
400 RecomputeNeedsHandleIdentifier();
408 NeedsHandleIdentifier =
true;
410 RecomputeNeedsHandleIdentifier();
419 IsCPPOperatorKeyword = Val;
428 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
451 return ChangedAfterLoad;
457 ChangedAfterLoad =
true;
463 return FEChangedAfterLoad;
469 FEChangedAfterLoad =
true;
481 NeedsHandleIdentifier =
true;
483 RecomputeNeedsHandleIdentifier();
493 NeedsHandleIdentifier =
true;
495 RecomputeNeedsHandleIdentifier();
527 StringRef deuglifiedName()
const;
529 return getLength() == 1 && getNameStart()[0] ==
'_';
544 void RecomputeNeedsHandleIdentifier() {
545 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
546 isExtensionToken() || isFutureCompatKeyword() ||
547 isOutOfDate() || isModulesImport();
561 : II(II), OldValue(II ? II->isPoisoned() :
false) {
633 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
634 HashTableTy HashTable;
649 ExternalLookup = IILookup;
654 return ExternalLookup;
658 return HashTable.getAllocator();
664 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
670 if (ExternalLookup) {
671 II = ExternalLookup->
get(Name);
689 II.TokenID = TokenCode;
690 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
701 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
716 if (Name.equals(
"import"))
727 unsigned size()
const {
return HashTable.size(); }
733 void PrintStats()
const;
859 : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
863 return static_cast<ExtraKind>(ExtraKindOrNumArgs >
865 ? (
unsigned)ObjCMultiArgSelector
866 : ExtraKindOrNumArgs);
872 assert(ExtraKindOrNumArgs >= (
unsigned)ObjCMultiArgSelector &&
873 "getNumArgs called but this is not an ObjC selector!");
874 return ExtraKindOrNumArgs - (
unsigned)ObjCMultiArgSelector;
886 public llvm::FoldingSetNode {
892 : DeclarationNameExtra(nKeys) {
893 assert((nKeys > 1) &&
"not a multi-keyword selector");
897 for (
unsigned i = 0; i != nKeys; ++i)
904 using DeclarationNameExtra::getNumArgs;
913 return keyword_begin() + getNumArgs();
917 assert(i < getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
918 return keyword_begin()[i];
923 ID.AddInteger(NumArgs);
924 for (
unsigned i = 0; i != NumArgs; ++i)
925 ID.AddPointer(ArgTys[i]);
929 Profile(
ID, keyword_begin(), getNumArgs());
945 enum IdentifierInfoFlag {
968 llvm::PointerIntPair<
969 llvm::PointerUnion<IdentifierInfo *, MultiKeywordSelector *>, 2>
973 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
974 InfoPtr.setPointerAndInt(II, nArgs + 1);
977 Selector(MultiKeywordSelector *SI) {
981 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
984 IdentifierInfo *getAsIdentifierInfo()
const {
985 return InfoPtr.getPointer().dyn_cast<IdentifierInfo *>();
988 MultiKeywordSelector *getMultiKeywordSelector()
const {
989 return InfoPtr.getPointer().get<MultiKeywordSelector *>();
992 unsigned getIdentifierInfoFlag()
const {
993 unsigned new_flags = InfoPtr.getInt();
997 if (InfoPtr.getPointer().is<MultiKeywordSelector *>())
998 new_flags |= MultiArg;
1011 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1016 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1019 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1025 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1036 bool isUnarySelector(StringRef Name)
const;
1038 unsigned getNumArgs()
const;
1053 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1063 StringRef getNameForSlot(
unsigned argIndex)
const;
1070 void print(llvm::raw_ostream &OS)
const;
1076 return getMethodFamilyImpl(*
this);
1080 return getStringFormatFamilyImpl(*
this);
1121 size_t getTotalMemory()
const;
1138 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1167 return P.getAsOpaquePtr();
1174 static constexpr int NumLowBitsAvailable = 0;
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Defines the Diagnostic IDs-related interfaces.
static void print(llvm::raw_ostream &OS, const T &V, ASTContext &, QualType)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static std::string getName(const CallEvent &Call)
Defines the clang::TokenKind enum and support functions.
The name of a declaration.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Provides lookups to, and iteration over, IdentiferInfo objects.
virtual ~IdentifierInfoLookup()
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
One of these records is kept for each identifier that is lexed.
tok::InterestingIdentifierKind getInterestingIdentifierID() const
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier.
IdentifierInfo(const IdentifierInfo &)=delete
IdentifierInfo(IdentifierInfo &&)=delete
void setInterestingIdentifierID(unsigned ID)
bool isModulesImport() const
Determine whether this is the contextual keyword import.
void revertIdentifierToTokenID(tok::TokenKind TK)
unsigned getLength() const
Efficiently return the length of this identifier info.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
void setIsExtensionToken(bool Val)
void setIsRestrictExpansion(bool Val)
void setFETokenInfo(void *T)
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
bool isCPlusPlusOperatorKeyword() const
IdentifierInfo & operator=(const IdentifierInfo &)=delete
void setIsDeprecatedMacro(bool Val)
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
void setMangledOpenMPVariantName(bool I)
Set whether this is the mangled name of an OpenMP variant.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
void setIsFinal(bool Val)
IdentifierInfo & operator=(IdentifierInfo &&)=delete
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
bool isPoisoned() const
Return true if this token has been poisoned.
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
bool isMangledOpenMPVariantName() const
Determine whether this is the mangled name of an OpenMP variant.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source.
void setHasMacroDefinition(bool Val)
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
unsigned getObjCOrBuiltinID() const
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
void setObjCOrBuiltinID(unsigned ID)
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
void setBuiltinID(unsigned ID)
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
bool isDeprecatedMacro() const
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void setIsFutureCompatKeyword(bool Val)
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void * getFETokenInfo() const
Get and set FETokenInfo.
bool isPlaceholder() const
StringRef getName() const
Return the actual identifier string.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension.
bool isRestrictExpansion() const
An iterator that walks over all of the known identifiers in the lookup table.
virtual StringRef Next()=0
Retrieve the next string in the identifier table and advances the iterator for the following string.
IdentifierIterator & operator=(const IdentifierIterator &)=delete
IdentifierIterator(const IdentifierIterator &)=delete
virtual ~IdentifierIterator()
IdentifierIterator()=default
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
iterator find(StringRef Name) const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfo & get(StringRef Name, tok::TokenKind TokenCode)
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
HashTableTy::const_iterator iterator
HashTableTy::const_iterator const_iterator
llvm::BumpPtrAllocator & getAllocator()
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
One of these variable length records is kept for each selector containing more than one keyword.
keyword_iterator keyword_end() const
IdentifierInfo *const * keyword_iterator
void Profile(llvm::FoldingSetNodeID &ID)
IdentifierInfo * getIdentifierInfoForSlot(unsigned i) const
static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys, unsigned NumArgs)
keyword_iterator keyword_begin() const
MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV)
An RAII object for [un]poisoning an identifier within a scope.
~PoisonIdentifierRAIIObject()
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
This table allows us to fully hide how we implement multi-keyword caching.
SelectorTable(const SelectorTable &)=delete
SelectorTable & operator=(const SelectorTable &)=delete
Selector getNullarySelector(IdentifierInfo *ID)
Selector getUnarySelector(IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
Selector()=default
The default ctor should only be used when creating data structures that will contain selectors.
static Selector getEmptyMarker()
static Selector getTombstoneMarker()
void * getAsOpaquePtr() const
bool isKeywordSelector() const
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
bool isUnarySelector() const
bool operator!=(Selector RHS) const
bool isNull() const
Determine whether this is the empty selector.
ObjCStringFormatFamily getStringFormatFamily() const
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
InterestingIdentifierKind
Provides a namespace for interesting identifers such as float_t and double_t.
@ NUM_INTERESTING_IDENTIFIERS
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
static constexpr int ObjCOrBuiltinIDBits
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
@ IdentifierInfoAlignment
static constexpr int LastObjCKeywordID
ObjCMethodFamily
A family of Objective-C methods.
@ OMF_None
No particular method family.
@ ObjCMethodFamilyBitWidth
ObjCInstanceTypeFamily
A family of Objective-C methods.
static constexpr int LastInterestingIdentifierID
ReservedLiteralSuffixIdStatus
@ NotStartsWithUnderscore
static constexpr int FirstBuiltinID
@ InvalidObjCMethodFamily
static constexpr int FirstObjCKeywordID
The "layout" of ObjCOrBuiltinID is:
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
llvm::StringRef getAsString(SyncScope S)
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
@ StartsWithDoubleUnderscore
@ StartsWithUnderscoreFollowedByCapitalLetter
@ ContainsDoubleUnderscore
@ StartsWithUnderscoreAtGlobalScope
@ StartsWithUnderscoreAndIsExternC
static constexpr int FirstInterestingIdentifierID
YAML serialization mapping.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
static clang::Selector getEmptyKey()
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
static clang::Selector getTombstoneKey()
static clang::Selector getFromVoidPointer(const void *P)
static const void * getAsVoidPointer(clang::Selector P)