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"
144#define OBJC_AT_KEYWORD(X) objc_##X,
145#include "clang/Basic/TokenKinds.def"
148#define NOTABLE_IDENTIFIER(X) X,
149#include "clang/Basic/TokenKinds.def"
153#define GET_BUILTIN_ENUMERATORS
154#include "clang/Basic/Builtins.inc"
155#undef GET_BUILTIN_ENUMERATORS
167class alignas(IdentifierInfoAlignment) IdentifierInfo {
172 unsigned TokenID : 9;
178 LLVM_PREFERRED_TYPE(
bool)
179 unsigned HasMacro : 1;
182 LLVM_PREFERRED_TYPE(
bool)
183 unsigned HadMacro : 1;
186 LLVM_PREFERRED_TYPE(
bool)
187 unsigned IsExtension : 1;
190 LLVM_PREFERRED_TYPE(
bool)
191 unsigned IsFutureCompatKeyword : 1;
194 LLVM_PREFERRED_TYPE(
bool)
195 unsigned IsPoisoned : 1;
198 LLVM_PREFERRED_TYPE(
bool)
199 unsigned IsCPPOperatorKeyword : 1;
203 LLVM_PREFERRED_TYPE(
bool)
204 unsigned NeedsHandleIdentifier : 1;
207 LLVM_PREFERRED_TYPE(
bool)
208 unsigned IsFromAST : 1;
212 LLVM_PREFERRED_TYPE(
bool)
213 unsigned ChangedAfterLoad : 1;
217 LLVM_PREFERRED_TYPE(
bool)
218 unsigned FEChangedAfterLoad : 1;
221 LLVM_PREFERRED_TYPE(
bool)
222 unsigned RevertedTokenID : 1;
226 LLVM_PREFERRED_TYPE(
bool)
227 unsigned OutOfDate : 1;
230 LLVM_PREFERRED_TYPE(
bool)
231 unsigned IsModulesImport : 1;
234 LLVM_PREFERRED_TYPE(
bool)
235 unsigned IsMangledOpenMPVariantName : 1;
238 LLVM_PREFERRED_TYPE(
bool)
239 unsigned IsDeprecatedMacro : 1;
242 LLVM_PREFERRED_TYPE(
bool)
243 unsigned IsRestrictExpansion : 1;
246 LLVM_PREFERRED_TYPE(
bool)
247 unsigned IsFinal : 1;
250 LLVM_PREFERRED_TYPE(
bool)
251 unsigned IsKeywordInCpp : 1;
256 void *FETokenInfo =
nullptr;
258 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
261 : TokenID(
tok::identifier),
262 InterestingIdentifierID(
llvm::to_underlying(
265 IsFutureCompatKeyword(
false), IsPoisoned(
false),
266 IsCPPOperatorKeyword(
false), NeedsHandleIdentifier(
false),
269 IsMangledOpenMPVariantName(
false), IsDeprecatedMacro(
false),
274 IdentifierInfo &
operator=(
const IdentifierInfo &) =
delete;
281 template <std::
size_t StrLen>
282 bool isStr(
const char (&Str)[StrLen])
const {
288 bool isStr(llvm::StringRef Str)
const {
290 return ThisStr == Str;
298 unsigned getLength()
const {
return Entry->getKeyLength(); }
311 if (HasMacro == Val)
return;
315 NeedsHandleIdentifier =
true;
323 IsDeprecatedMacro =
false;
324 IsRestrictExpansion =
false;
326 RecomputeNeedsHandleIdentifier();
339 if (IsDeprecatedMacro == Val)
341 IsDeprecatedMacro = Val;
343 NeedsHandleIdentifier =
true;
345 RecomputeNeedsHandleIdentifier();
351 if (IsRestrictExpansion == Val)
353 IsRestrictExpansion = Val;
355 NeedsHandleIdentifier =
true;
357 RecomputeNeedsHandleIdentifier();
379 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
380 TokenID = tok::identifier;
381 RevertedTokenID =
true;
384 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
386 RevertedTokenID =
false;
398 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
402 return tok::objc_not_keyword;
405 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
406 InterestingIdentifierID = ID;
418 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
425 InterestingIdentifierID = ID + FirstBuiltin;
426 assert(
getBuiltinID() == ID &&
"ID too large for field!");
429 InterestingIdentifierID =
438 auto FirstNotableIdentifier =
441 FirstNotableIdentifier);
443 return tok::not_notable;
446 assert(ID != tok::not_notable);
447 auto FirstNotableIdentifier =
449 InterestingIdentifierID = ID + FirstNotableIdentifier;
463 NeedsHandleIdentifier =
true;
465 RecomputeNeedsHandleIdentifier();
475 IsFutureCompatKeyword = Val;
477 NeedsHandleIdentifier =
true;
479 RecomputeNeedsHandleIdentifier();
487 NeedsHandleIdentifier =
true;
489 RecomputeNeedsHandleIdentifier();
498 IsCPPOperatorKeyword = Val;
511 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
535 return ChangedAfterLoad;
541 ChangedAfterLoad =
true;
547 return FEChangedAfterLoad;
553 FEChangedAfterLoad =
true;
565 NeedsHandleIdentifier =
true;
567 RecomputeNeedsHandleIdentifier();
577 NeedsHandleIdentifier =
true;
579 RecomputeNeedsHandleIdentifier();
611 StringRef deuglifiedName()
const;
628 void RecomputeNeedsHandleIdentifier() {
629 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
630 isExtensionToken() || isFutureCompatKeyword() ||
631 isOutOfDate() || isModulesImport();
645 : II(II), OldValue(II ? II->isPoisoned() :
false) {
647 II->setIsPoisoned(NewValue);
652 II->setIsPoisoned(OldValue);
717 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
718 HashTableTy HashTable;
733 ExternalLookup = IILookup;
738 return ExternalLookup;
742 return HashTable.getAllocator();
748 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
754 if (ExternalLookup) {
755 II = ExternalLookup->get(Name);
773 II.TokenID = TokenCode;
774 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
785 auto &Entry = *HashTable.try_emplace(Name).first;
800 if (Name ==
"import")
811 unsigned size()
const {
return HashTable.size(); }
817 void PrintStats()
const;
957 "getNumArgs called but this is not an ObjC selector!");
968class alignas(IdentifierInfoAlignment) MultiKeywordSelector
970 public llvm::FoldingSetNode {
977 assert((nKeys > 1) &&
"not a multi-keyword selector");
982 for (
unsigned i = 0; i != nKeys; ++i)
987 std::string getName()
const;
989 using DeclarationNameExtra::getNumArgs;
1002 assert(i <
getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
1008 ID.AddInteger(NumArgs);
1009 for (
unsigned i = 0; i != NumArgs; ++i)
1010 ID.AddPointer(ArgTys[i]);
1030 enum IdentifierInfoFlag {
1053 llvm::PointerIntPair<
1054 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1058 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
1059 InfoPtr.setPointerAndInt(II, nArgs + 1);
1062 Selector(MultiKeywordSelector *SI) {
1066 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1069 const IdentifierInfo *getAsIdentifierInfo()
const {
1070 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1073 MultiKeywordSelector *getMultiKeywordSelector()
const {
1074 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1077 unsigned getIdentifierInfoFlag()
const {
1078 unsigned new_flags = InfoPtr.getInt();
1082 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1083 new_flags |= MultiArg;
1096 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1101 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1104 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1110 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1121 bool isUnarySelector(StringRef Name)
const;
1123 unsigned getNumArgs()
const;
1138 const IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1148 StringRef getNameForSlot(
unsigned argIndex)
const;
1155 void print(llvm::raw_ostream &OS)
const;
1161 return getMethodFamilyImpl(*
this);
1165 return getStringFormatFamilyImpl(*
this);
1206 size_t getTotalMemory()
const;
1223 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1241 return Loc ==
X.Loc && II ==
X.II;
1245 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)