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"
107#define OBJC_AT_KEYWORD(X) objc_##X,
108#include "clang/Basic/TokenKinds.def"
111#define NOTABLE_IDENTIFIER(X) X,
112#include "clang/Basic/TokenKinds.def"
116#define GET_BUILTIN_ENUMERATORS
117#include "clang/Basic/Builtins.inc"
118#undef GET_BUILTIN_ENUMERATORS
130class alignas(IdentifierInfoAlignment) IdentifierInfo {
135 unsigned TokenID : 9;
141 LLVM_PREFERRED_TYPE(
bool)
142 unsigned HasMacro : 1;
145 LLVM_PREFERRED_TYPE(
bool)
146 unsigned HadMacro : 1;
149 LLVM_PREFERRED_TYPE(
bool)
150 unsigned IsExtension : 1;
153 LLVM_PREFERRED_TYPE(
bool)
154 unsigned IsFutureCompatKeyword : 1;
157 LLVM_PREFERRED_TYPE(
bool)
158 unsigned IsPoisoned : 1;
161 LLVM_PREFERRED_TYPE(
bool)
162 unsigned IsCPPOperatorKeyword : 1;
166 LLVM_PREFERRED_TYPE(
bool)
167 unsigned NeedsHandleIdentifier : 1;
170 LLVM_PREFERRED_TYPE(
bool)
171 unsigned IsFromAST : 1;
175 LLVM_PREFERRED_TYPE(
bool)
176 unsigned ChangedAfterLoad : 1;
180 LLVM_PREFERRED_TYPE(
bool)
181 unsigned FEChangedAfterLoad : 1;
184 LLVM_PREFERRED_TYPE(
bool)
185 unsigned RevertedTokenID : 1;
189 LLVM_PREFERRED_TYPE(
bool)
190 unsigned OutOfDate : 1;
193 LLVM_PREFERRED_TYPE(
bool)
194 unsigned IsModulesImport : 1;
197 LLVM_PREFERRED_TYPE(
bool)
198 unsigned IsModulesDecl : 1;
201 LLVM_PREFERRED_TYPE(
bool)
202 unsigned IsMangledOpenMPVariantName : 1;
205 LLVM_PREFERRED_TYPE(
bool)
206 unsigned IsDeprecatedMacro : 1;
209 LLVM_PREFERRED_TYPE(
bool)
210 unsigned IsRestrictExpansion : 1;
213 LLVM_PREFERRED_TYPE(
bool)
214 unsigned IsFinal : 1;
217 LLVM_PREFERRED_TYPE(
bool)
218 unsigned IsKeywordInCpp : 1;
223 void *FETokenInfo =
nullptr;
225 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
228 : TokenID(
tok::identifier),
229 InterestingIdentifierID(
llvm::to_underlying(
232 IsFutureCompatKeyword(
false), IsPoisoned(
false),
233 IsCPPOperatorKeyword(
false), NeedsHandleIdentifier(
false),
236 IsModulesDecl(
false), IsMangledOpenMPVariantName(
false),
238 IsKeywordInCpp(
false) {}
242 IdentifierInfo &
operator=(
const IdentifierInfo &) =
delete;
249 template <std::
size_t StrLen>
250 bool isStr(
const char (&Str)[StrLen])
const {
256 bool isStr(llvm::StringRef Str)
const {
258 return ThisStr == Str;
266 unsigned getLength()
const {
return Entry->getKeyLength(); }
279 if (HasMacro == Val)
return;
283 NeedsHandleIdentifier =
true;
291 IsDeprecatedMacro =
false;
292 IsRestrictExpansion =
false;
294 RecomputeNeedsHandleIdentifier();
307 if (IsDeprecatedMacro == Val)
309 IsDeprecatedMacro = Val;
311 NeedsHandleIdentifier =
true;
313 RecomputeNeedsHandleIdentifier();
319 if (IsRestrictExpansion == Val)
321 IsRestrictExpansion = Val;
323 NeedsHandleIdentifier =
true;
325 RecomputeNeedsHandleIdentifier();
347 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
348 TokenID = tok::identifier;
349 RevertedTokenID =
true;
352 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
354 RevertedTokenID =
false;
366 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
370 return tok::objc_not_keyword;
373 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
374 InterestingIdentifierID = ID;
386 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
393 InterestingIdentifierID = ID + FirstBuiltin;
394 assert(
getBuiltinID() == ID &&
"ID too large for field!");
397 InterestingIdentifierID =
406 auto FirstNotableIdentifier =
409 FirstNotableIdentifier);
411 return tok::not_notable;
414 assert(ID != tok::not_notable);
415 auto FirstNotableIdentifier =
417 InterestingIdentifierID = ID + FirstNotableIdentifier;
431 NeedsHandleIdentifier =
true;
433 RecomputeNeedsHandleIdentifier();
443 IsFutureCompatKeyword = Val;
445 NeedsHandleIdentifier =
true;
447 RecomputeNeedsHandleIdentifier();
455 NeedsHandleIdentifier =
true;
457 RecomputeNeedsHandleIdentifier();
466 IsCPPOperatorKeyword = Val;
479 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
503 return ChangedAfterLoad;
509 ChangedAfterLoad =
true;
515 return FEChangedAfterLoad;
521 FEChangedAfterLoad =
true;
533 NeedsHandleIdentifier =
true;
535 RecomputeNeedsHandleIdentifier();
543 IsModulesImport = Val;
545 NeedsHandleIdentifier =
true;
547 RecomputeNeedsHandleIdentifier();
557 NeedsHandleIdentifier =
true;
559 RecomputeNeedsHandleIdentifier();
591 StringRef deuglifiedName()
const;
608 void RecomputeNeedsHandleIdentifier() {
609 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
610 isExtensionToken() || isFutureCompatKeyword() ||
611 isOutOfDate() || isImportKeyword();
625 : II(II), OldValue(II ? II->isPoisoned() :
false) {
627 II->setIsPoisoned(NewValue);
632 II->setIsPoisoned(OldValue);
697 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
698 HashTableTy HashTable;
713 ExternalLookup = IILookup;
718 return ExternalLookup;
722 return HashTable.getAllocator();
728 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
734 if (ExternalLookup) {
735 II = ExternalLookup->get(Name);
753 II.TokenID = TokenCode;
754 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
765 auto &Entry = *HashTable.try_emplace(Name).first;
780 if (Name ==
"import")
782 else if (Name ==
"module")
792 unsigned size()
const {
return HashTable.size(); }
798 void PrintStats()
const;
938 "getNumArgs called but this is not an ObjC selector!");
949class alignas(IdentifierInfoAlignment) MultiKeywordSelector
951 public llvm::FoldingSetNode {
958 assert((nKeys > 1) &&
"not a multi-keyword selector");
963 for (
unsigned i = 0; i != nKeys; ++i)
968 std::string getName()
const;
970 using DeclarationNameExtra::getNumArgs;
983 assert(i <
getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
989 ID.AddInteger(NumArgs);
990 for (
unsigned i = 0; i != NumArgs; ++i)
991 ID.AddPointer(ArgTys[i]);
1011 enum IdentifierInfoFlag {
1034 llvm::PointerIntPair<
1035 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1039 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
1040 InfoPtr.setPointerAndInt(II, nArgs + 1);
1043 Selector(MultiKeywordSelector *SI) {
1047 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1050 const IdentifierInfo *getAsIdentifierInfo()
const {
1051 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1054 MultiKeywordSelector *getMultiKeywordSelector()
const {
1055 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1058 unsigned getIdentifierInfoFlag()
const {
1059 unsigned new_flags = InfoPtr.getInt();
1063 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1064 new_flags |= MultiArg;
1077 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1082 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1085 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1091 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1102 bool isUnarySelector(StringRef Name)
const;
1104 unsigned getNumArgs()
const;
1119 const IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1129 StringRef getNameForSlot(
unsigned argIndex)
const;
1136 void print(llvm::raw_ostream &OS)
const;
1142 return getMethodFamilyImpl(*
this);
1146 return getStringFormatFamilyImpl(*
this);
1179 size_t getTotalMemory()
const;
1196 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1214 return Loc ==
X.Loc && II ==
X.II;
1218 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, const Context &Ctx, 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.
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.
@ 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 unsigned getHashValue(clang::Selector S)
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
static clang::Selector getFromVoidPointer(const void *P)
static constexpr int NumLowBitsAvailable
static const void * getAsVoidPointer(clang::Selector P)