#include <string>
namespace llvm {
+ class APFloat;
/// This folding set used for two purposes:
/// 1. Given information about a node we want to create, look up the unique
unsigned NumNodes;
public:
- FoldingSetImpl(unsigned Log2InitSize = 6);
+ explicit FoldingSetImpl(unsigned Log2InitSize = 6);
virtual ~FoldingSetImpl();
// Forward declaration.
void AddPointer(const void *Ptr);
void AddInteger(signed I);
void AddInteger(unsigned I);
+ void AddInteger(int64_t I);
void AddInteger(uint64_t I);
void AddFloat(float F);
void AddDouble(double D);
+ void AddAPFloat(const APFloat& apf);
void AddString(const std::string &String);
/// ComputeHash - Compute a strong hash value for this NodeID, used to
typedef FoldingSetImpl::Node FoldingSetNode;
typedef FoldingSetImpl::NodeID FoldingSetNodeID;
+template<class T> class FoldingSetIterator;
+
//===----------------------------------------------------------------------===//
/// FoldingSet - This template class is used to instantiate a specialized
/// implementation of the folding set to the node class T. T must be a
///
template<class T> class FoldingSet : public FoldingSetImpl {
private:
- /// GetNodeProfile - Each instantiatation of the FoldingSet
+ /// GetNodeProfile - Each instantiatation of the FoldingSet needs to provide a
+ /// way to convert nodes into a unique specifier.
virtual void GetNodeProfile(NodeID &ID, Node *N) const {
T *TN = static_cast<T *>(N);
TN->Profile(ID);
}
public:
- FoldingSet(unsigned Log2InitSize = 6)
+ explicit FoldingSet(unsigned Log2InitSize = 6)
: FoldingSetImpl(Log2InitSize)
{}
+
+ typedef FoldingSetIterator<T> iterator;
+ iterator begin() { return iterator(Buckets); }
+ iterator end() { return iterator(Buckets+NumBuckets); }
+
+ typedef FoldingSetIterator<const T> const_iterator;
+ const_iterator begin() const { return const_iterator(Buckets); }
+ const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
/// GetOrInsertNode - If there is an existing simple Node exactly
/// equal to the specified node, return it. Otherwise, insert 'N' and
/// return it. If not, return the insertion token that will make insertion
/// faster.
T *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) {
- return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID,
- InsertPos));
+ return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID, InsertPos));
+ }
+};
+
+//===----------------------------------------------------------------------===//
+/// FoldingSetIteratorImpl - This is the common iterator support shared by all
+/// folding sets, which knows how to walk the folding set hash table.
+class FoldingSetIteratorImpl {
+protected:
+ FoldingSetNode *NodePtr;
+ FoldingSetIteratorImpl(void **Bucket);
+ void advance();
+
+public:
+ bool operator==(const FoldingSetIteratorImpl &RHS) const {
+ return NodePtr == RHS.NodePtr;
+ }
+ bool operator!=(const FoldingSetIteratorImpl &RHS) const {
+ return NodePtr != RHS.NodePtr;
+ }
+};
+
+
+template<class T>
+class FoldingSetIterator : public FoldingSetIteratorImpl {
+public:
+ FoldingSetIterator(void **Bucket) : FoldingSetIteratorImpl(Bucket) {}
+
+ T &operator*() const {
+ return *static_cast<T*>(NodePtr);
+ }
+
+ T *operator->() const {
+ return static_cast<T*>(NodePtr);
+ }
+
+ inline FoldingSetIterator& operator++() { // Preincrement
+ advance();
+ return *this;
+ }
+ FoldingSetIterator operator++(int) { // Postincrement
+ FoldingSetIterator tmp = *this; ++*this; return tmp;
}
};