16 #ifndef LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 17 #define LLVM_CLANG_BASIC_IDENTIFIERTABLE_H 21 #include "llvm/ADT/DenseMapInfo.h" 22 #include "llvm/ADT/SmallString.h" 23 #include "llvm/ADT/StringMap.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/Support/Allocator.h" 26 #include "llvm/Support/PointerLikeTypeTraits.h" 27 #include "llvm/Support/type_traits.h" 39 class MultiKeywordSelector;
57 unsigned ObjCOrBuiltinID :13;
61 bool IsFutureCompatKeyword : 1;
64 bool IsCPPOperatorKeyword : 1;
65 bool NeedsHandleIdentifier : 1;
68 bool ChangedAfterLoad : 1;
70 bool FEChangedAfterLoad : 1;
73 bool RevertedTokenID : 1;
78 bool IsModulesImport : 1;
83 void *FETokenInfo =
nullptr;
85 llvm::StringMapEntry<IdentifierInfo *> *Entry =
nullptr;
95 template <std::
size_t StrLen>
96 bool isStr(
const char (&Str)[StrLen])
const {
102 bool isStr(llvm::StringRef Str)
const {
104 return ThisStr == Str;
110 if (Entry)
return Entry->getKeyData();
116 using actualtype = std::pair<IdentifierInfo, const char *>;
118 return ((
const actualtype*)
this)->second;
123 if (Entry)
return Entry->getKeyLength();
129 using actualtype = std::pair<IdentifierInfo, const char *>;
131 const char* p = ((
const actualtype*)
this)->second - 2;
132 return (((
unsigned) p[0]) | (((
unsigned) p[1]) << 8)) - 1;
146 if (HasMacro == Val)
return;
150 NeedsHandleIdentifier =
true;
153 RecomputeNeedsHandleIdentifier();
178 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
179 TokenID = tok::identifier;
180 RevertedTokenID =
true;
183 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
185 RevertedTokenID =
false;
200 return tok::objc_not_keyword;
227 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
228 &&
"ID too large for field!");
241 NeedsHandleIdentifier =
true;
243 RecomputeNeedsHandleIdentifier();
253 IsFutureCompatKeyword = Val;
255 NeedsHandleIdentifier =
true;
257 RecomputeNeedsHandleIdentifier();
265 NeedsHandleIdentifier =
true;
267 RecomputeNeedsHandleIdentifier();
276 IsCPPOperatorKeyword = Val;
309 return ChangedAfterLoad;
315 ChangedAfterLoad =
true;
321 return FEChangedAfterLoad;
327 FEChangedAfterLoad =
true;
339 NeedsHandleIdentifier =
true;
341 RecomputeNeedsHandleIdentifier();
351 NeedsHandleIdentifier =
true;
353 RecomputeNeedsHandleIdentifier();
381 void RecomputeNeedsHandleIdentifier() {
434 virtual StringRef Next() = 0;
470 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
471 HashTableTy HashTable;
486 ExternalLookup = IILookup;
491 return ExternalLookup;
495 return HashTable.getAllocator();
501 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
507 if (ExternalLookup) {
508 II = ExternalLookup->
get(Name);
526 II.TokenID = TokenCode;
527 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
538 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
553 if (Name.equals(
"import"))
564 unsigned size()
const {
return HashTable.size(); }
568 void PrintStats()
const;
657 enum IdentifierInfoFlag {
662 ArgFlags = ZeroArg|OneArg
669 InfoPtr =
reinterpret_cast<uintptr_t>(II);
670 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
671 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
676 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
677 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
682 if (getIdentifierInfoFlag() < MultiArg)
691 unsigned getIdentifierInfoFlag()
const {
692 return InfoPtr & ArgFlags;
710 return InfoPtr == RHS.InfoPtr;
713 return InfoPtr != RHS.InfoPtr;
717 return reinterpret_cast<void*
>(InfoPtr);
721 bool isNull()
const {
return InfoPtr == 0; }
725 return getIdentifierInfoFlag() != ZeroArg;
729 return getIdentifierInfoFlag() == ZeroArg;
732 unsigned getNumArgs()
const;
747 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
757 StringRef getNameForSlot(
unsigned argIndex)
const;
764 void print(llvm::raw_ostream &OS)
const;
770 return getMethodFamilyImpl(*
this);
774 return getStringFormatFamilyImpl(*
this);
815 size_t getTotalMemory()
const;
832 static std::string getPropertyNameFromSetterSelector(
Selector Sel);
847 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 849 #include "clang/Basic/OperatorKinds.def" 904 enum { NumLowBitsAvailable = 0 };
919 enum { NumLowBitsAvailable = 1 };
932 enum { NumLowBitsAvailable = 1 };
937 #endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H
~PoisonIdentifierRAIIObject()
Smart pointer class that efficiently represents Objective-C method names.
void * getAsOpaquePtr() const
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
static const clang::IdentifierInfo * getFromVoidPointer(const void *P)
void revertIdentifierToTokenID(tok::TokenKind TK)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
void setModulesImport(bool I)
Set whether this identifier is the contextual keyword import.
static clang::Selector getEmptyKey()
void setIsExtensionToken(bool Val)
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
friend class IdentifierTable
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
static clang::Selector getFromVoidPointer(const void *P)
Selector getUnarySelector(IdentifierInfo *ID)
One of these records is kept for each identifier that is lexed.
This table allows us to fully hide how we implement multi-keyword caching.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
T * getFETokenInfo() const
getFETokenInfo/setFETokenInfo - The language front-end is allowed to associate arbitrary metadata wit...
HashTableTy::const_iterator const_iterator
void setHasMacroDefinition(bool Val)
ObjCMethodFamily
A family of Objective-C methods.
bool isCPlusPlusOperatorKeyword() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
virtual IdentifierInfo * get(StringRef Name)=0
Return the IdentifierInfo for the specified named identifier.
bool isUnarySelector() const
void setIsFutureCompatKeyword(bool Val)
Selector getNullarySelector(IdentifierInfo *ID)
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
IdentifierInfoLookup * getExternalIdentifierLookup() const
Retrieve the external identifier lookup object, if any.
bool hasRevertedBuiltin() const
True if setNotBuiltin() was called.
static clang::Selector getTombstoneKey()
bool isCPlusPlusKeyword(const LangOptions &LangOpts) const
Return true if this token is a C++ keyword in the specified language.
void revertBuiltin()
Revert the identifier to a non-builtin identifier.
unsigned getLength() const
Efficiently return the length of this identifier info.
bool operator!=(Selector RHS) const
static bool isEqual(clang::Selector LHS, clang::Selector RHS)
HashTableTy::const_iterator iterator
bool hasChangedSinceDeserialization() const
Determine whether this identifier has changed since it was loaded from an AST file.
IdentifierInfo & getOwn(StringRef Name)
Gets an IdentifierInfo for the given name without consulting external sources.
Provides lookups to, and iteration over, IdentiferInfo objects.
void setIsCPlusPlusOperatorKeyword(bool Val=true)
isCPlusPlusOperatorKeyword/setIsCPlusPlusOperatorKeyword controls whether this identifier is a C++ al...
MultiKeywordSelector - One of these variable length records is kept for each selector containing more...
ObjCStringFormatFamily getStringFormatFamily() const
llvm::StringRef getAsString(SyncScope S)
Implements an efficient mapping from strings to IdentifierInfo nodes.
void setFETokenInfo(void *T)
tok::ObjCKeywordKind getObjCKeywordID() const
Return the Objective-C keyword ID for the this identifier.
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line...
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
bool hasFETokenInfoChangedSinceDeserialization() const
Determine whether the frontend token information for this identifier has changed since it was loaded ...
bool operator==(Selector RHS) const
operator==/!= - Indicate whether the specified selectors are identical.
ObjCInstanceTypeFamily
A family of Objective-C methods.
static const void * getAsVoidPointer(clang::Selector P)
An iterator that walks over all of the known identifiers in the lookup table.
bool isStr(llvm::StringRef Str) const
Return true if this is the identifier for the specified StringRef.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
ObjCKeywordKind
Provides a namespace for Objective-C keywords which start with an '@'.
void setObjCKeywordID(tok::ObjCKeywordKind ID)
bool isKeyword(const LangOptions &LangOpts) const
Return true if this token is a keyword in the specified language.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
static void * getAsVoidPointer(clang::IdentifierInfo *P)
PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue)
ObjCMethodFamily getMethodFamily() const
Derive the conventional family of this method.
IdentifierInfo & operator=(const IdentifierInfo &)=delete
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
static clang::IdentifierInfo * getFromVoidPointer(void *P)
llvm::BumpPtrAllocator & getAllocator()
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
bool isPoisoned() const
Return true if this token has been poisoned.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
bool operator<(const IdentifierInfo &RHS) const
Provide less than operator for lexicographical sorting.
StringRef getName() const
Return the actual identifier string.
unsigned getObjCOrBuiltinID() const
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Dataflow Directional Tag Classes.
std::pair< IdentifierInfo *, SourceLocation > IdentifierLocPair
A simple pair of identifier info and location.
bool isHandleIdentifierCase() const
Return true if the Preprocessor::HandleIdentifier must be called on a token of this identifier...
DeclarationName - The name of a declaration.
bool isExtensionToken() const
get/setExtension - Initialize information about whether or not this language token is an extension...
bool isKeywordSelector() const
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
static Selector getTombstoneMarker()
static Selector getEmptyMarker()
void setBuiltinID(unsigned ID)
Defines the clang::TokenKind enum and support functions.
No particular method family.
static const void * getAsVoidPointer(const clang::IdentifierInfo *P)
bool hasRevertedTokenIDToIdentifier() const
True if revertTokenIDToIdentifier() was called.
void setOutOfDate(bool OOD)
Set whether the information for this identifier is out of date with respect to the external source...
bool isNull() const
Determine whether this is the empty selector.
void revertTokenIDToIdentifier()
Revert TokenID to tok::identifier; used for GNU libstdc++ 4.2 compatibility.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
bool isModulesImport() const
Determine whether this is the contextual keyword import.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
void setExternalIdentifierLookup(IdentifierInfoLookup *IILookup)
Set the external identifier lookup mechanism.
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
void setObjCOrBuiltinID(unsigned ID)
An RAII object for [un]poisoning an identifier within a scope.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.