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 {
104 if (Entry)
return Entry->getKeyData();
110 using actualtype = std::pair<IdentifierInfo, const char *>;
112 return ((
const actualtype*)
this)->second;
117 if (Entry)
return Entry->getKeyLength();
123 using actualtype = std::pair<IdentifierInfo, const char *>;
125 const char* p = ((
const actualtype*)
this)->second - 2;
126 return (((
unsigned) p[0]) | (((
unsigned) p[1]) << 8)) - 1;
140 if (HasMacro == Val)
return;
144 NeedsHandleIdentifier =
true;
147 RecomputeNeedsHandleIdentifier();
172 assert(TokenID != tok::identifier &&
"Already at tok::identifier");
173 TokenID = tok::identifier;
174 RevertedTokenID =
true;
177 assert(TokenID == tok::identifier &&
"Should be at tok::identifier");
179 RevertedTokenID =
false;
194 return tok::objc_not_keyword;
221 assert(ObjCOrBuiltinID -
unsigned(tok::NUM_OBJC_KEYWORDS) == ID
222 &&
"ID too large for field!");
235 NeedsHandleIdentifier =
true;
237 RecomputeNeedsHandleIdentifier();
247 IsFutureCompatKeyword = Val;
249 NeedsHandleIdentifier =
true;
251 RecomputeNeedsHandleIdentifier();
259 NeedsHandleIdentifier =
true;
261 RecomputeNeedsHandleIdentifier();
270 IsCPPOperatorKeyword = Val;
303 return ChangedAfterLoad;
309 ChangedAfterLoad =
true;
315 return FEChangedAfterLoad;
321 FEChangedAfterLoad =
true;
333 NeedsHandleIdentifier =
true;
335 RecomputeNeedsHandleIdentifier();
345 NeedsHandleIdentifier =
true;
347 RecomputeNeedsHandleIdentifier();
375 void RecomputeNeedsHandleIdentifier() {
428 virtual StringRef Next() = 0;
464 using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
465 HashTableTy HashTable;
477 ExternalLookup = IILookup;
482 return ExternalLookup;
486 return HashTable.getAllocator();
492 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
498 if (ExternalLookup) {
499 II = ExternalLookup->
get(Name);
517 II.TokenID = TokenCode;
518 assert(II.TokenID == (
unsigned) TokenCode &&
"TokenCode too large");
529 auto &Entry = *HashTable.insert(std::make_pair(Name,
nullptr)).first;
544 if (Name.equals(
"import"))
555 unsigned size()
const {
return HashTable.size(); }
559 void PrintStats()
const;
646 enum IdentifierInfoFlag {
651 ArgFlags = ZeroArg|OneArg
658 InfoPtr =
reinterpret_cast<uintptr_t>(II);
659 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
660 assert(nArgs < 2 &&
"nArgs not equal to 0/1");
665 InfoPtr =
reinterpret_cast<uintptr_t>(SI);
666 assert((InfoPtr & ArgFlags) == 0 &&
"Insufficiently aligned IdentifierInfo");
671 if (getIdentifierInfoFlag() < MultiArg)
680 unsigned getIdentifierInfoFlag()
const {
681 return InfoPtr & ArgFlags;
699 return InfoPtr == RHS.InfoPtr;
702 return InfoPtr != RHS.InfoPtr;
706 return reinterpret_cast<void*
>(InfoPtr);
710 bool isNull()
const {
return InfoPtr == 0; }
714 return getIdentifierInfoFlag() != ZeroArg;
718 return getIdentifierInfoFlag() == ZeroArg;
721 unsigned getNumArgs()
const;
736 IdentifierInfo *getIdentifierInfoForSlot(
unsigned argIndex)
const;
746 StringRef getNameForSlot(
unsigned argIndex)
const;
753 void print(llvm::raw_ostream &OS)
const;
757 return getMethodFamilyImpl(*
this);
761 return getStringFormatFamilyImpl(*
this);
802 size_t getTotalMemory()
const;
831 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 833 #include "clang/Basic/OperatorKinds.def" 888 enum { NumLowBitsAvailable = 0 };
903 enum { NumLowBitsAvailable = 1 };
916 enum { NumLowBitsAvailable = 1 };
921 #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.
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)
const FunctionProtoType * T
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.
__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.