diff options
author | David Greene <greened@obbligato.org> | 2011-07-29 19:06:58 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2011-07-29 19:06:58 +0000 |
commit | cd0bc905d2c100edbf2f65ac7f1d58353fb1728c (patch) | |
tree | 4b0af220de71b60a6a4b8667e3ace829a33d51a1 /utils/TableGen | |
parent | 1619560521c46ecee0ef2d0c651ed18feb57df97 (diff) | |
download | external_llvm-cd0bc905d2c100edbf2f65ac7f1d58353fb1728c.zip external_llvm-cd0bc905d2c100edbf2f65ac7f1d58353fb1728c.tar.gz external_llvm-cd0bc905d2c100edbf2f65ac7f1d58353fb1728c.tar.bz2 |
Add a std::string Wrapper for TableGen
Create a std::string wrapper for use as a DenseMap key. DenseMap is
not safe in generate with strings, so this wrapper indicates that only
strings guaranteed not to have certain values should be used in the
DenseMap.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136481 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/Record.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 3aaaa87..0144344 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -20,6 +20,52 @@ using namespace llvm; //===----------------------------------------------------------------------===// +// std::string wrapper for DenseMap purposes +//===----------------------------------------------------------------------===// + +/// TableGenStringKey - This is a wrapper for std::string suitable for +/// using as a key to a DenseMap. Because there isn't a particularly +/// good way to indicate tombstone or empty keys for strings, we want +/// to wrap std::string to indicate that this is a "special" string +/// not expected to take on certain values (those of the tombstone and +/// empty keys). This makes things a little safer as it clarifies +/// that DenseMap is really not appropriate for general strings. + +class TableGenStringKey { +public: + TableGenStringKey(const std::string &str) : data(str) {} + TableGenStringKey(const char *str) : data(str) {} + + const std::string &str() const { return data; } + +private: + std::string data; +}; + +/// Specialize DenseMapInfo for TableGenStringKey. +namespace llvm { + +template<> struct DenseMapInfo<TableGenStringKey> { + static inline TableGenStringKey getEmptyKey() { + TableGenStringKey Empty("<<<EMPTY KEY>>>"); + return Empty; + } + static inline TableGenStringKey getTombstoneKey() { + TableGenStringKey Tombstone("<<<TOMBSTONE KEY>>>"); + return Tombstone; + } + static unsigned getHashValue(const TableGenStringKey& Val) { + return HashString(Val.str()); + } + static bool isEqual(const TableGenStringKey& LHS, + const TableGenStringKey& RHS) { + return LHS.str() == RHS.str(); + } +}; + +} + +//===----------------------------------------------------------------------===// // Type implementations //===----------------------------------------------------------------------===// |