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"
146#define OBJC_AT_KEYWORD(X) objc_##X,
147#include "clang/Basic/TokenKinds.def"
150#define NOTABLE_IDENTIFIER(X) X,
151#include "clang/Basic/TokenKinds.def"
155#define GET_BUILTIN_ENUMERATORS
156#include "clang/Basic/Builtins.inc"
157#undef GET_BUILTIN_ENUMERATORS
169class alignas(IdentifierInfoAlignment) IdentifierInfo {
174 unsigned TokenID : 9;
180 LLVM_PREFERRED_TYPE(
bool)
181 unsigned HasMacro : 1;
184 LLVM_PREFERRED_TYPE(
bool)
185 unsigned HadMacro : 1;
188 LLVM_PREFERRED_TYPE(
bool)
189 unsigned IsExtension : 1;
192 LLVM_PREFERRED_TYPE(
bool)
193 unsigned IsFutureCompatKeyword : 1;
196 LLVM_PREFERRED_TYPE(
bool)
197 unsigned IsPoisoned : 1;
200 LLVM_PREFERRED_TYPE(
bool)
201 unsigned IsCPPOperatorKeyword : 1;
205 LLVM_PREFERRED_TYPE(
bool)
206 unsigned NeedsHandleIdentifier : 1;
209 LLVM_PREFERRED_TYPE(
bool)
210 unsigned IsFromAST : 1;
214 LLVM_PREFERRED_TYPE(
bool)
215 unsigned ChangedAfterLoad : 1;
219 LLVM_PREFERRED_TYPE(
bool)
220 unsigned FEChangedAfterLoad : 1;
223 LLVM_PREFERRED_TYPE(
bool)
224 unsigned RevertedTokenID : 1;
228 LLVM_PREFERRED_TYPE(
bool)
229 unsigned OutOfDate : 1;
232 LLVM_PREFERRED_TYPE(
bool)
233 unsigned IsModulesImport : 1;
236 LLVM_PREFERRED_TYPE(
bool)
237 unsigned IsModulesDecl : 1;
240 LLVM_PREFERRED_TYPE(
bool)
241 unsigned IsMangledOpenMPVariantName : 1;
244 LLVM_PREFERRED_TYPE(
bool)
245 unsigned IsDeprecatedMacro : 1;
248 LLVM_PREFERRED_TYPE(
bool)
249 unsigned IsRestrictExpansion : 1;
252 LLVM_PREFERRED_TYPE(
bool)
253 unsigned IsFinal : 1;
256 LLVM_PREFERRED_TYPE(
bool)
257 unsigned IsKeywordInCpp : 1;
262 void *FETokenInfo =
nullptr;
264 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
267 : TokenID(
tok::identifier),
268 InterestingIdentifierID(
llvm::to_underlying(
271 IsFutureCompatKeyword(
false), IsPoisoned(
false),
272 IsCPPOperatorKeyword(
false), NeedsHandleIdentifier(
false),
275 IsModulesDecl(
false), IsMangledOpenMPVariantName(
false),
277 IsKeywordInCpp(
false) {}
281 IdentifierInfo &
operator=(
const IdentifierInfo &) =
delete;
288 template <std::
size_t StrLen>
289 bool isStr(
const char (&Str)[StrLen])
const {
295 bool isStr(llvm::StringRef Str)
const {
297 return ThisStr == Str;
305 unsigned getLength()
const {
return Entry->getKeyLength(); }
318 if (HasMacro == Val)
return;
322 NeedsHandleIdentifier =
true;
330 IsDeprecatedMacro =
false;
331 IsRestrictExpansion =
false;
333 RecomputeNeedsHandleIdentifier();
346 if (IsDeprecatedMacro == Val)
348 IsDeprecatedMacro = Val;
350 NeedsHandleIdentifier =
true;
352 RecomputeNeedsHandleIdentifier();
358 if (IsRestrictExpansion == Val)
360 IsRestrictExpansion = Val;
362 NeedsHandleIdentifier =
true;
364 RecomputeNeedsHandleIdentifier();
386 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
387 TokenID = tok::identifier;
388 RevertedTokenID =
true;
391 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
393 RevertedTokenID =
false;
405 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
409 return tok::objc_not_keyword;
412 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
413 InterestingIdentifierID = ID;
425 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
432 InterestingIdentifierID = ID + FirstBuiltin;
433 assert(
getBuiltinID() == ID &&
"ID too large for field!");
436 InterestingIdentifierID =
445 auto FirstNotableIdentifier =
448 FirstNotableIdentifier);
450 return tok::not_notable;
453 assert(ID != tok::not_notable);
454 auto FirstNotableIdentifier =
456 InterestingIdentifierID = ID + FirstNotableIdentifier;
470 NeedsHandleIdentifier =
true;
472 RecomputeNeedsHandleIdentifier();
482 IsFutureCompatKeyword = Val;
484 NeedsHandleIdentifier =
true;
486 RecomputeNeedsHandleIdentifier();
494 NeedsHandleIdentifier =
true;
496 RecomputeNeedsHandleIdentifier();
505 IsCPPOperatorKeyword = Val;
518 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
542 return ChangedAfterLoad;
548 ChangedAfterLoad =
true;
554 return FEChangedAfterLoad;
560 FEChangedAfterLoad =
true;
572 NeedsHandleIdentifier =
true;
574 RecomputeNeedsHandleIdentifier();
582 IsModulesImport = Val;
584 NeedsHandleIdentifier =
true;
586 RecomputeNeedsHandleIdentifier();
596 NeedsHandleIdentifier =
true;
598 RecomputeNeedsHandleIdentifier();
630 StringRef deuglifiedName()
const;
647 void RecomputeNeedsHandleIdentifier() {
648 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
649 isExtensionToken() || isFutureCompatKeyword() ||
650 isOutOfDate() || isImportKeyword();
664 : II(II), OldValue(II ? II->isPoisoned() :
false) {
666 II->setIsPoisoned(NewValue);
671 II->setIsPoisoned(OldValue);
736 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
737 HashTableTy HashTable;
752 ExternalLookup = IILookup;
757 return ExternalLookup;
761 return HashTable.getAllocator();
767 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
773 if (ExternalLookup) {
774 II = ExternalLookup->get(Name);
792 II.TokenID = TokenCode;
793 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
804 auto &Entry = *HashTable.try_emplace(Name).first;
819 if (Name ==
"import")
821 else if (Name ==
"module")
831 unsigned size()
const {
return HashTable.size(); }
837 void PrintStats()
const;
977 "getNumArgs called but this is not an ObjC selector!");
988class alignas(IdentifierInfoAlignment) MultiKeywordSelector
990 public llvm::FoldingSetNode {
997 assert((nKeys > 1) &&
"not a multi-keyword selector");
1002 for (
unsigned i = 0; i != nKeys; ++i)
1003 KeyInfo[i] = IIV[i];
1007 std::string getName()
const;
1009 using DeclarationNameExtra::getNumArgs;
1022 assert(i <
getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
1028 ID.AddInteger(NumArgs);
1029 for (
unsigned i = 0; i != NumArgs; ++i)
1030 ID.AddPointer(ArgTys[i]);
1050 enum IdentifierInfoFlag {
1073 llvm::PointerIntPair<
1074 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1078 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
1079 InfoPtr.setPointerAndInt(II, nArgs + 1);
1082 Selector(MultiKeywordSelector *SI) {
1086 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1089 const IdentifierInfo *getAsIdentifierInfo()
const {
1090 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1093 MultiKeywordSelector *getMultiKeywordSelector()
const {
1094 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1097 unsigned getIdentifierInfoFlag()
const {
1098 unsigned new_flags = InfoPtr.getInt();
1102 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1103 new_flags |= MultiArg;
1116 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1121 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1124 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1130 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1141 bool isUnarySelector(StringRef Name)
const;
1143 unsigned getNumArgs()
const;
1158 const IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1168 StringRef getNameForSlot(
unsigned argIndex)
const;
1175 void print(llvm::raw_ostream &OS)
const;
1181 return getMethodFamilyImpl(*
this);
1185 return getStringFormatFamilyImpl(*
this);
1226 size_t getTotalMemory()
const;
1243 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1261 return Loc ==
X.Loc && II ==
X.II;
1265 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
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.
bool isModuleKeyword() const
Determine whether this is the contextual keyword module.
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)
void setModuleKeyword(bool Val)
Set whether this identifier is the contextual keyword module.
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.
bool isImportKeyword() const
Determine whether this is the contextual keyword import.
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.
void setKeywordImport(bool Val)
Set whether this identifier is the contextual keyword import.
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.
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)