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 IsModulesDecl : 1;
239 LLVM_PREFERRED_TYPE(
bool)
240 unsigned IsMangledOpenMPVariantName : 1;
243 LLVM_PREFERRED_TYPE(
bool)
244 unsigned IsDeprecatedMacro : 1;
247 LLVM_PREFERRED_TYPE(
bool)
248 unsigned IsRestrictExpansion : 1;
251 LLVM_PREFERRED_TYPE(
bool)
252 unsigned IsFinal : 1;
255 LLVM_PREFERRED_TYPE(
bool)
256 unsigned IsKeywordInCpp : 1;
261 void *FETokenInfo =
nullptr;
263 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
266 : TokenID(
tok::identifier),
267 InterestingIdentifierID(
llvm::to_underlying(
270 IsFutureCompatKeyword(
false), IsPoisoned(
false),
271 IsCPPOperatorKeyword(
false), NeedsHandleIdentifier(
false),
274 IsModulesDecl(
false), IsMangledOpenMPVariantName(
false),
276 IsKeywordInCpp(
false) {}
280 IdentifierInfo &
operator=(
const IdentifierInfo &) =
delete;
287 template <std::
size_t StrLen>
288 bool isStr(
const char (&Str)[StrLen])
const {
294 bool isStr(llvm::StringRef Str)
const {
296 return ThisStr == Str;
304 unsigned getLength()
const {
return Entry->getKeyLength(); }
317 if (HasMacro == Val)
return;
321 NeedsHandleIdentifier =
true;
329 IsDeprecatedMacro =
false;
330 IsRestrictExpansion =
false;
332 RecomputeNeedsHandleIdentifier();
345 if (IsDeprecatedMacro == Val)
347 IsDeprecatedMacro = Val;
349 NeedsHandleIdentifier =
true;
351 RecomputeNeedsHandleIdentifier();
357 if (IsRestrictExpansion == Val)
359 IsRestrictExpansion = Val;
361 NeedsHandleIdentifier =
true;
363 RecomputeNeedsHandleIdentifier();
385 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
386 TokenID = tok::identifier;
387 RevertedTokenID =
true;
390 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
392 RevertedTokenID =
false;
404 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
408 return tok::objc_not_keyword;
411 assert(0 == llvm::to_underlying(InterestingIdentifier::objc_not_keyword));
412 InterestingIdentifierID = ID;
424 return static_cast<Builtin::ID>(InterestingIdentifierID - FirstBuiltin);
431 InterestingIdentifierID = ID + FirstBuiltin;
432 assert(
getBuiltinID() == ID &&
"ID too large for field!");
435 InterestingIdentifierID =
444 auto FirstNotableIdentifier =
447 FirstNotableIdentifier);
449 return tok::not_notable;
452 assert(ID != tok::not_notable);
453 auto FirstNotableIdentifier =
455 InterestingIdentifierID = ID + FirstNotableIdentifier;
469 NeedsHandleIdentifier =
true;
471 RecomputeNeedsHandleIdentifier();
481 IsFutureCompatKeyword = Val;
483 NeedsHandleIdentifier =
true;
485 RecomputeNeedsHandleIdentifier();
493 NeedsHandleIdentifier =
true;
495 RecomputeNeedsHandleIdentifier();
504 IsCPPOperatorKeyword = Val;
517 bool isCPlusPlusKeyword(
const LangOptions &LangOpts)
const;
541 return ChangedAfterLoad;
547 ChangedAfterLoad =
true;
553 return FEChangedAfterLoad;
559 FEChangedAfterLoad =
true;
571 NeedsHandleIdentifier =
true;
573 RecomputeNeedsHandleIdentifier();
581 IsModulesImport = Val;
583 NeedsHandleIdentifier =
true;
585 RecomputeNeedsHandleIdentifier();
595 NeedsHandleIdentifier =
true;
597 RecomputeNeedsHandleIdentifier();
629 StringRef deuglifiedName()
const;
646 void RecomputeNeedsHandleIdentifier() {
647 NeedsHandleIdentifier = isPoisoned() || hasMacroDefinition() ||
648 isExtensionToken() || isFutureCompatKeyword() ||
649 isOutOfDate() || isImportKeyword();
663 : II(II), OldValue(II ? II->isPoisoned() :
false) {
665 II->setIsPoisoned(NewValue);
670 II->setIsPoisoned(OldValue);
735 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
736 HashTableTy HashTable;
751 ExternalLookup = IILookup;
756 return ExternalLookup;
760 return HashTable.getAllocator();
766 auto &Entry = *HashTable.try_emplace(Name,
nullptr).first;
772 if (ExternalLookup) {
773 II = ExternalLookup->get(Name);
791 II.TokenID = TokenCode;
792 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
803 auto &Entry = *HashTable.try_emplace(Name).first;
818 if (Name ==
"import")
820 else if (Name ==
"module")
830 unsigned size()
const {
return HashTable.size(); }
836 void PrintStats()
const;
976 "getNumArgs called but this is not an ObjC selector!");
987class alignas(IdentifierInfoAlignment) MultiKeywordSelector
989 public llvm::FoldingSetNode {
996 assert((nKeys > 1) &&
"not a multi-keyword selector");
1001 for (
unsigned i = 0; i != nKeys; ++i)
1002 KeyInfo[i] = IIV[i];
1006 std::string getName()
const;
1008 using DeclarationNameExtra::getNumArgs;
1021 assert(i <
getNumArgs() &&
"getIdentifierInfoForSlot(): illegal index");
1027 ID.AddInteger(NumArgs);
1028 for (
unsigned i = 0; i != NumArgs; ++i)
1029 ID.AddPointer(ArgTys[i]);
1049 enum IdentifierInfoFlag {
1072 llvm::PointerIntPair<
1073 llvm::PointerUnion<const IdentifierInfo *, MultiKeywordSelector *>, 2>
1077 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
1078 InfoPtr.setPointerAndInt(II, nArgs + 1);
1081 Selector(MultiKeywordSelector *SI) {
1085 InfoPtr.setPointerAndInt(SI, MultiArg & 0b11);
1088 const IdentifierInfo *getAsIdentifierInfo()
const {
1089 return dyn_cast_if_present<const IdentifierInfo *>(InfoPtr.getPointer());
1092 MultiKeywordSelector *getMultiKeywordSelector()
const {
1093 return cast<MultiKeywordSelector *>(InfoPtr.getPointer());
1096 unsigned getIdentifierInfoFlag()
const {
1097 unsigned new_flags = InfoPtr.getInt();
1101 if (isa<MultiKeywordSelector *>(InfoPtr.getPointer()))
1102 new_flags |= MultiArg;
1115 InfoPtr.setFromOpaqueValue(
reinterpret_cast<void *
>(
V));
1120 return InfoPtr.getOpaqueValue() == RHS.InfoPtr.getOpaqueValue();
1123 return InfoPtr.getOpaqueValue() != RHS.InfoPtr.getOpaqueValue();
1129 bool isNull()
const {
return InfoPtr.getOpaqueValue() ==
nullptr; }
1140 bool isUnarySelector(StringRef Name)
const;
1142 unsigned getNumArgs()
const;
1157 const IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
1167 StringRef getNameForSlot(
unsigned argIndex)
const;
1174 void print(llvm::raw_ostream &OS)
const;
1180 return getMethodFamilyImpl(*
this);
1184 return getStringFormatFamilyImpl(*
this);
1225 size_t getTotalMemory()
const;
1242 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
1260 return Loc ==
X.Loc && II ==
X.II;
1264 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.
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)