15#ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
16#define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
23#include "llvm/ADT/DenseMapInfo.h"
24#include "llvm/ADT/FoldingSet.h"
25#include "llvm/ADT/PointerIntPair.h"
26#include "llvm/ADT/PointerUnion.h"
27#include "llvm/ADT/SmallString.h"
28#include "llvm/ADT/StringMap.h"
29#include "llvm/ADT/StringRef.h"
30#include "llvm/Support/Allocator.h"
31#include "llvm/Support/PointerLikeTypeTraits.h"
32#include "llvm/Support/type_traits.h"
145#define OBJC_AT_KEYWORD(X) objc_##X,
146#include "clang/Basic/TokenKinds.def"
149#define NOTABLE_IDENTIFIER(X) X,
150#include "clang/Basic/TokenKinds.def"
154#define GET_BUILTIN_ENUMERATORS
155#include "clang/Basic/Builtins.inc"
156#undef GET_BUILTIN_ENUMERATORS
168class alignas(IdentifierInfoAlignment) IdentifierInfo {
173 unsigned TokenID : 9;
179 LLVM_PREFERRED_TYPE(
bool)
180 unsigned HasMacro : 1;
183 LLVM_PREFERRED_TYPE(
bool)
184 unsigned HadMacro : 1;
187 LLVM_PREFERRED_TYPE(
bool)
188 unsigned IsExtension : 1;
191 LLVM_PREFERRED_TYPE(
bool)
192 unsigned IsFutureCompatKeyword : 1;
195 LLVM_PREFERRED_TYPE(
bool)
196 unsigned IsPoisoned : 1;
199 LLVM_PREFERRED_TYPE(
bool)
200 unsigned IsCPPOperatorKeyword : 1;
204 LLVM_PREFERRED_TYPE(
bool)
205 unsigned NeedsHandleIdentifier : 1;
208 LLVM_PREFERRED_TYPE(
bool)
209 unsigned IsFromAST : 1;
213 LLVM_PREFERRED_TYPE(
bool)
214 unsigned ChangedAfterLoad : 1;
218 LLVM_PREFERRED_TYPE(
bool)
219 unsigned FEChangedAfterLoad : 1;
222 LLVM_PREFERRED_TYPE(
bool)
223 unsigned RevertedTokenID : 1;
227 LLVM_PREFERRED_TYPE(
bool)
228 unsigned OutOfDate : 1;
231 LLVM_PREFERRED_TYPE(
bool)
232 unsigned IsModulesImport : 1;
235 LLVM_PREFERRED_TYPE(
bool)
236 unsigned IsMangledOpenMPVariantName : 1;
239 LLVM_PREFERRED_TYPE(
bool)
240 unsigned IsDeprecatedMacro : 1;
243 LLVM_PREFERRED_TYPE(
bool)
244 unsigned IsRestrictExpansion : 1;
247 LLVM_PREFERRED_TYPE(
bool)
248 unsigned IsFinal : 1;
251 LLVM_PREFERRED_TYPE(
bool)
252 unsigned IsKeywordInCpp : 1;
257 void *FETokenInfo =
nullptr;
259 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
262 : TokenID(
tok::identifier),
263 InterestingIdentifierID(
llvm::to_underlying(
266 IsFutureCompatKeyword(
false), IsPoisoned(
false),
267 IsCPPOperatorKeyword(
false), NeedsHandleIdentifier(
false),
270 IsMangledOpenMPVariantName(
false), IsDeprecatedMacro(
false),
275 IdentifierInfo &
operator=(
const IdentifierInfo &) =
delete;
282 template <std::
size_t StrLen>
283 bool isStr(
const char (&Str)[StrLen])
const {
289 bool isStr(llvm::StringRef Str)
const {
291 return ThisStr == Str;
299 unsigned getLength()
const {
return Entry->getKeyLength(); }
312 if (HasMacro == Val)
return;
316 NeedsHandleIdentifier =
true;
324 IsDeprecatedMacro =
false;
325 IsRestrictExpansion =
false;
327 RecomputeNeedsHandleIdentifier();
340 if (IsDeprecatedMacro == Val)
342 IsDeprecatedMacro = Val;
344 NeedsHandleIdentifier =
true;
346 RecomputeNeedsHandleIdentifier();
352 if (IsRestrictExpansion == Val)
354 IsRestrictExpansion = Val;
356 NeedsHandleIdentifier =
true;
358 RecomputeNeedsHandleIdentifier();
380 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
381 TokenID = tok::identifier;
382 RevertedTokenID =
true;
385 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
387 RevertedTokenID =
false;
399 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
403 return tok::objc_not_keyword;
406 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
407 InterestingIdentifierID = ID;
419 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
426 InterestingIdentifierID = ID + FirstBuiltin;
427 assert(
getBuiltinID() == ID &&
"ID too large for field!");
430 InterestingIdentifierID =
439 auto FirstNotableIdentifier =
442 FirstNotableIdentifier);
444 return tok::not_notable;
447 assert(ID != tok::not_notable);
448 auto FirstNotableIdentifier =
450 InterestingIdentifierID = ID + FirstNotableIdentifier;
464 NeedsHandleIdentifier =
true;
466 RecomputeNeedsHandleIdentifier();
476 IsFutureCompatKeyword = Val;
478 NeedsHandleIdentifier =
true;
480 RecomputeNeedsHandleIdentifier();
488 NeedsHandleIdentifier =
true;
490 RecomputeNeedsHandleIdentifier();
499 IsCPPOperatorKeyword = Val;
512 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
536 return ChangedAfterLoad;
542 ChangedAfterLoad =
true;
548 return FEChangedAfterLoad;
554 FEChangedAfterLoad =
true;
566 NeedsHandleIdentifier =
true;
568 RecomputeNeedsHandleIdentifier();
578 NeedsHandleIdentifier =
true;
580 RecomputeNeedsHandleIdentifier();
612 StringRef deuglifiedName()
const;
629 void RecomputeNeedsHandleIdentifier() {
630 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
631 isExtensionToken() || isFutureCompatKeyword() ||
632 isOutOfDate() || isModulesImport();
646 : II(II), OldValue(II ? II->isPoisoned() :
false) {
648 II->setIsPoisoned(NewValue);
653 II->setIsPoisoned(OldValue);
718 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
719 HashTableTy HashTable;
734 ExternalLookup = IILookup;
739 return ExternalLookup;
743 return HashTable.getAllocator();
749 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
755 if (ExternalLookup) {
756 II = ExternalLookup->get(Name);
774 II.TokenID = TokenCode;
775 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
786 auto &Entry = *HashTable.try_emplace(Name).first;
801 if (Name ==
"import")
812 unsigned size()
const {
return HashTable.size(); }
818 void PrintStats()
const;
958 "getNumArgs called but this is not an ObjC selector!");
969class alignas(IdentifierInfoAlignment) MultiKeywordSelector
971 public llvm::FoldingSetNode {
978 assert((nKeys > 1) &&
"not a multi-keyword selector");
983 for (
unsigned i = 0; i != nKeys; ++i)
988 std::string getName()
const;
990 using DeclarationNameExtra::getNumArgs;
1003 assert(i <
getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
1009 ID.AddInteger(NumArgs);
1010 for (
unsigned i = 0; i != NumArgs; ++i)
1011 ID.AddPointer(ArgTys[i]);
1031 enum IdentifierInfoFlag {
1054 llvm::PointerIntPair<
1055 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1059 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
1060 InfoPtr.setPointerAndInt(II, nArgs + 1);
1063 Selector(MultiKeywordSelector *SI) {
1067 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1070 const IdentifierInfo *getAsIdentifierInfo()
const {
1071 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1074 MultiKeywordSelector *getMultiKeywordSelector()
const {
1075 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1078 unsigned getIdentifierInfoFlag()
const {
1079 unsigned new_flags = InfoPtr.getInt();
1083 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1084 new_flags |= MultiArg;
1097 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1102 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1105 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1111 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1122 bool isUnarySelector(StringRef Name)
const;
1124 unsigned getNumArgs()
const;
1139 const IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1149 StringRef getNameForSlot(
unsigned argIndex)
const;
1156 void print(llvm::raw_ostream &OS)
const;
1162 return getMethodFamilyImpl(*
this);
1166 return getStringFormatFamilyImpl(*
this);
1207 size_t getTotalMemory()
const;
1224 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1242 return Loc ==
X.Loc && II ==
X.II;
1246 return Loc !=
X.Loc || II !=
X.II;
Defines enum values for all the target-independent builtin functions.
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 &ASTCtx, QualType Ty)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TokenKind enum and support functions.
The name of a declaration.
Provides lookups to, and iteration over, IdentiferInfo objects.
virtual ~IdentifierInfoLookup()
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
virtual IdentifierIterator * getIdentifiers()
Retrieve an iterator into the set of all identifiers known to this identifier lookup source.
One of these records is kept for each identifier that is lexed.
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
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.
friend class IdentifierTable
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool IsKeywordInCPlusPlus() const
Return true if this identifier would be a keyword in C++ mode.
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
void setNotableIdentifierID(unsigned ID)
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.
void setHandleIdentifierCase(bool Val=true)
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
void setIsKeywordInCPlusPlus(bool Val=true)
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.
tok::NotableIdentifierKind getNotableIdentifierID() const
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
bool operator!=(const IdentifierLoc &X) const
SourceLocation getLoc() const
bool operator==(const IdentifierLoc &X) const
void setIdentifierInfo(IdentifierInfo *Ident)
void setLoc(SourceLocation L)
IdentifierInfo * getIdentifierInfo() const
IdentifierLoc(SourceLocation L, IdentifierInfo *Ident)
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierTable(IdentifierInfoLookup *ExternalLookup=nullptr)
Create the identifier table.
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
const IdentifierInfo *const * keyword_iterator
MultiKeywordSelector(unsigned nKeys, const IdentifierInfo **IIV)
void Profile(llvm::FoldingSetNodeID &ID)
static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys, unsigned NumArgs)
keyword_iterator keyword_begin() const
const IdentifierInfo * getIdentifierInfoForSlot(unsigned i) const
~PoisonIdentifierRAIIObject()
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
This table allows us to fully hide how we implement multi-keyword caching.
SelectorTable(const SelectorTable &)=delete
Selector getNullarySelector(const IdentifierInfo *ID)
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Selector getUnarySelector(const IdentifierInfo *ID)
SelectorTable & operator=(const SelectorTable &)=delete
Smart pointer class that efficiently represents Objective-C method names.
friend class DeclarationName
friend class SelectorTable
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
Encodes a location in the source.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
NotableIdentifierKind
Provides a namespace for notable identifers such as float_t and double_t.
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
The JSON file list parser is used to communicate input to InstallAPI.
TokenKey
Constants for TokenKinds.def.
@ ObjCMethodFamilyBitWidth
KeywordStatus getKeywordStatus(const LangOptions &LangOpts, unsigned Flags)
Translates flags as specified in TokenKinds.def into keyword status in the given language standard.
bool isReservedInAllContexts(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved in all contexts.
@ InvalidObjCMethodFamily
InterestingIdentifier
The "layout" of InterestingIdentifier is:
@ NUM_OBJC_KEYWORDS_AND_NOTABLE_IDENTIFIERS
@ NotInterestingIdentifier
ObjCMethodFamily
A family of Objective-C methods.
@ OMF_None
No particular method family.
const FunctionProtoType * T
ObjCInstanceTypeFamily
A family of Objective-C methods.
ReservedLiteralSuffixIdStatus
@ NotStartsWithUnderscore
static constexpr int InterestingIdentifierBits
KeywordStatus
How a keyword is treated in the selected standard.
bool isReservedAtGlobalScope(ReservedIdentifierStatus Status)
Determine whether an identifier is reserved for use as a name at global scope.
llvm::StringRef getAsString(SyncScope S)
@ IdentifierInfoAlignment
@ StartsWithDoubleUnderscore
@ StartsWithUnderscoreFollowedByCapitalLetter
@ ContainsDoubleUnderscore
@ StartsWithUnderscoreAtGlobalScope
@ StartsWithUnderscoreAndIsExternC
Diagnostic wrappers for TextAPI types for error reporting.
__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 constexpr int NumLowBitsAvailable
static const void * getAsVoidPointer(clang::Selector P)