diff options
Diffstat (limited to 'include/clang/Basic/IdentifierTable.h')
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index f9dec7917a..3001d0b1b0 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -18,16 +18,26 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/TokenKinds.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Allocator.h" #include <cassert> +#include <cstddef> +#include <cstdint> +#include <cstring> +#include <new> #include <string> +#include <utility> namespace llvm { + template <typename T> struct DenseMapInfo; -} + +} // end namespace llvm namespace clang { + class LangOptions; class IdentifierInfo; class IdentifierTable; @@ -38,13 +48,14 @@ namespace clang { /// \brief A simple pair of identifier info and location. typedef std::pair<IdentifierInfo*, SourceLocation> IdentifierLocPair; - /// One of these records is kept for each identifier that /// is lexed. This contains information about whether the token was \#define'd, /// is a language keyword, or if it is a front-end token of some sort (e.g. a /// variable or function name). The preprocessor keeps this information in a /// set, and all tok::identifier tokens have a pointer to one of these. class IdentifierInfo { + friend class IdentifierTable; + unsigned TokenID : 9; // Front-end token ID or tok::identifier. // Objective-C keyword ('protocol' in '@protocol') or builtin (__builtin_inf). // First NUM_OBJC_KEYWORDS values are for Objective-C, the remaining values @@ -77,21 +88,18 @@ class IdentifierInfo { void *FETokenInfo; // Managed by the language front-end. llvm::StringMapEntry<IdentifierInfo*> *Entry; - IdentifierInfo(const IdentifierInfo&) = delete; - void operator=(const IdentifierInfo&) = delete; - - friend class IdentifierTable; - public: IdentifierInfo(); - + IdentifierInfo(const IdentifierInfo &) = delete; + IdentifierInfo &operator=(const IdentifierInfo &) = delete; /// \brief Return true if this is the identifier for the specified string. /// /// This is intended to be used for string literals only: II->isStr("foo"). template <std::size_t StrLen> bool isStr(const char (&Str)[StrLen]) const { - return getLength() == StrLen-1 && !memcmp(getNameStart(), Str, StrLen-1); + return getLength() == StrLen-1 && + memcmp(getNameStart(), Str, StrLen-1) == 0; } /// \brief Return the beginning of the actual null-terminated string for this @@ -137,7 +145,7 @@ public: HasMacro = Val; if (Val) { - NeedsHandleIdentifier = 1; + NeedsHandleIdentifier = true; HadMacro = true; } else { RecomputeNeedsHandleIdentifier(); @@ -228,7 +236,7 @@ public: void setIsExtensionToken(bool Val) { IsExtension = Val; if (Val) - NeedsHandleIdentifier = 1; + NeedsHandleIdentifier = true; else RecomputeNeedsHandleIdentifier(); } @@ -242,7 +250,7 @@ public: void setIsFutureCompatKeyword(bool Val) { IsFutureCompatKeyword = Val; if (Val) - NeedsHandleIdentifier = 1; + NeedsHandleIdentifier = true; else RecomputeNeedsHandleIdentifier(); } @@ -252,7 +260,7 @@ public: void setIsPoisoned(bool Value = true) { IsPoisoned = Value; if (Value) - NeedsHandleIdentifier = 1; + NeedsHandleIdentifier = true; else RecomputeNeedsHandleIdentifier(); } @@ -265,7 +273,7 @@ public: void setIsCPlusPlusOperatorKeyword(bool Val = true) { IsCPPOperatorKeyword = Val; if (Val) - NeedsHandleIdentifier = 1; + NeedsHandleIdentifier = true; else RecomputeNeedsHandleIdentifier(); } @@ -370,6 +378,7 @@ private: class PoisonIdentifierRAIIObject { IdentifierInfo *const II; const bool OldValue; + public: PoisonIdentifierRAIIObject(IdentifierInfo *II, bool NewValue) : II(II), OldValue(II ? II->isPoisoned() : false) { @@ -394,14 +403,13 @@ public: /// operation. Subclasses of this iterator type will provide the /// actual functionality. class IdentifierIterator { -private: - IdentifierIterator(const IdentifierIterator &) = delete; - void operator=(const IdentifierIterator &) = delete; - protected: - IdentifierIterator() { } + IdentifierIterator() = default; public: + IdentifierIterator(const IdentifierIterator &) = delete; + IdentifierIterator &operator=(const IdentifierIterator &) = delete; + virtual ~IdentifierIterator(); /// \brief Retrieve the next string in the identifier table and @@ -536,7 +544,7 @@ public: iterator begin() const { return HashTable.begin(); } iterator end() const { return HashTable.end(); } - unsigned size() const { return HashTable.size(); } + unsigned size() const { return HashTable.size(); } /// \brief Print some statistics to stderr that indicate how well the /// hashing is doing. @@ -653,6 +661,7 @@ class Selector { return reinterpret_cast<IdentifierInfo *>(InfoPtr & ~ArgFlags); return nullptr; } + MultiKeywordSelector *getMultiKeywordSelector() const { return reinterpret_cast<MultiKeywordSelector *>(InfoPtr & ~ArgFlags); } @@ -681,6 +690,7 @@ public: bool operator!=(Selector RHS) const { return InfoPtr != RHS.InfoPtr; } + void *getAsOpaquePtr() const { return reinterpret_cast<void*>(InfoPtr); } @@ -692,12 +702,13 @@ public: bool isKeywordSelector() const { return getIdentifierInfoFlag() != ZeroArg; } + bool isUnarySelector() const { return getIdentifierInfoFlag() == ZeroArg; } + unsigned getNumArgs() const; - /// \brief Retrieve the identifier at a given position in the selector. /// /// Note that the identifier pointer returned may be NULL. Clients that only @@ -742,6 +753,7 @@ public: static Selector getEmptyMarker() { return Selector(uintptr_t(-1)); } + static Selector getTombstoneMarker() { return Selector(uintptr_t(-2)); } @@ -753,10 +765,11 @@ public: /// multi-keyword caching. class SelectorTable { void *Impl; // Actually a SelectorTableImpl - SelectorTable(const SelectorTable &) = delete; - void operator=(const SelectorTable &) = delete; + public: SelectorTable(); + SelectorTable(const SelectorTable &) = delete; + SelectorTable &operator=(const SelectorTable &) = delete; ~SelectorTable(); /// \brief Can create any sort of selector. @@ -825,6 +838,7 @@ public: } // end namespace clang namespace llvm { + /// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and /// DenseSets. template <> @@ -832,6 +846,7 @@ struct DenseMapInfo<clang::Selector> { static inline clang::Selector getEmptyKey() { return clang::Selector::getEmptyMarker(); } + static inline clang::Selector getTombstoneKey() { return clang::Selector::getTombstoneMarker(); } @@ -854,9 +869,11 @@ public: static inline const void *getAsVoidPointer(clang::Selector P) { return P.getAsOpaquePtr(); } + static inline clang::Selector getFromVoidPointer(const void *P) { return clang::Selector(reinterpret_cast<uintptr_t>(P)); } + enum { NumLowBitsAvailable = 0 }; }; @@ -868,9 +885,11 @@ public: static inline void *getAsVoidPointer(clang::IdentifierInfo* P) { return P; } + static inline clang::IdentifierInfo *getFromVoidPointer(void *P) { return static_cast<clang::IdentifierInfo*>(P); } + enum { NumLowBitsAvailable = 1 }; }; @@ -880,11 +899,14 @@ public: static inline const void *getAsVoidPointer(const clang::IdentifierInfo* P) { return P; } + static inline const clang::IdentifierInfo *getFromVoidPointer(const void *P) { return static_cast<const clang::IdentifierInfo*>(P); } + enum { NumLowBitsAvailable = 1 }; }; -} // end namespace llvm -#endif +} // end namespace llvm + +#endif // LLVM_CLANG_BASIC_IDENTIFIERTABLE_H |