Made 'FoldingSetNodeID' a proper class instead of a nested class in
authorTed Kremenek <kremenek@apple.com>
Sat, 19 Jan 2008 04:22:50 +0000 (04:22 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 19 Jan 2008 04:22:50 +0000 (04:22 +0000)
'FoldingSetNodeImpl' (previously 'FoldingSetNodeID' was a typedef of
'FoldingSetNodeImpl::NodeID').

Why?  Clients can now easily forward declare 'FoldingSetNodeID' without having
to include FoldingSet.h.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46187 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/FoldingSet.h
lib/Support/FoldingSet.cpp

index da1f16c60b3df64e0bbe520550ec127f970a54f9..e626b6e62eedeaf4f947393a6a4b271274b88018 100644 (file)
@@ -96,8 +96,9 @@ namespace llvm {
 ///    bool WasRemoved = RemoveNode(N);
 ///
 /// The result indicates whether the node existed in the folding set.
-
-
+  
+class FoldingSetNodeID;
+  
 //===----------------------------------------------------------------------===//
 /// FoldingSetImpl - Implements the folding set functionality.  The main
 /// structure is an array of buckets.  Each bucket is indexed by the hash of
@@ -123,49 +124,6 @@ public:
   explicit FoldingSetImpl(unsigned Log2InitSize = 6);
   virtual ~FoldingSetImpl();
   
-  // Forward declaration.
-  class Node;
-
-  //===--------------------------------------------------------------------===//
-  /// NodeID - This class is used to gather all the unique data bits of a
-  /// node.  When all the bits are gathered this class is used to produce a
-  /// hash value for the node.  
-  ///
-  class NodeID {
-    /// Bits - Vector of all the data bits that make the node unique.
-    /// Use a SmallVector to avoid a heap allocation in the common case.
-    SmallVector<unsigned, 32> Bits;
-    
-  public:
-    NodeID() {}
-    
-    /// getRawData - Return the ith entry in the Bits data.
-    ///
-    unsigned getRawData(unsigned i) const {
-      return Bits[i];
-    }
-    
-    /// Add* - Add various data types to Bit data.
-    ///
-    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 
-    /// lookup the node in the FoldingSetImpl.
-    unsigned ComputeHash() const;
-    
-    /// operator== - Used to compare two nodes to each other.
-    ///
-    bool operator==(const NodeID &RHS) const;
-  };
-
   //===--------------------------------------------------------------------===//
   /// Node - This class is used to maintain the singly linked bucket list in
   /// a folding set.
@@ -196,7 +154,7 @@ public:
   /// FindNodeOrInsertPos - Look up the node specified by ID.  If it exists,
   /// return it.  If not, return the insertion token that will make insertion
   /// faster.
-  Node *FindNodeOrInsertPos(const NodeID &ID, void *&InsertPos);
+  Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
   
   /// InsertNode - Insert the specified node into the folding set, knowing that
   /// it is not already in the folding set.  InsertPos must be obtained from 
@@ -216,13 +174,51 @@ protected:
 
   /// GetNodeProfile - Instantiations of the FoldingSet template implement
   /// this function to gather data bits for the given node.
-  virtual void GetNodeProfile(NodeID &ID, Node *N) const = 0;
+  virtual void GetNodeProfile(FoldingSetNodeID &ID, Node *N) const = 0;
 };
 
-// Convenience types to hide the implementation of the folding set.
-typedef FoldingSetImpl::Node FoldingSetNode;
-typedef FoldingSetImpl::NodeID FoldingSetNodeID;
+//===--------------------------------------------------------------------===//
+/// FoldingSetNodeID - This class is used to gather all the unique data bits of
+/// a node.  When all the bits are gathered this class is used to produce a
+/// hash value for the node.  
+///
+class FoldingSetNodeID {
+  /// Bits - Vector of all the data bits that make the node unique.
+  /// Use a SmallVector to avoid a heap allocation in the common case.
+  SmallVector<unsigned, 32> Bits;
+  
+public:
+  FoldingSetNodeID() {}
+  
+  /// getRawData - Return the ith entry in the Bits data.
+  ///
+  unsigned getRawData(unsigned i) const {
+    return Bits[i];
+  }
+  
+  /// Add* - Add various data types to Bit data.
+  ///
+  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 FoldingSetNodeID, used
+  ///  to lookup the node in the FoldingSetImpl.
+  unsigned ComputeHash() const;
+  
+  /// operator== - Used to compare two nodes to each other.
+  ///
+  bool operator==(const FoldingSetNodeID &RHS) const;
+};  
 
+// Convenience type to hide the implementation of the folding set.
+typedef FoldingSetImpl::Node FoldingSetNode;
 template<class T> class FoldingSetIterator;
 
 //===----------------------------------------------------------------------===//
@@ -247,7 +243,7 @@ template<class T> class FoldingSet : public FoldingSetImpl {
 private:
   /// 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 {
+  virtual void GetNodeProfile(FoldingSetNodeID &ID, Node *N) const {
     T *TN = static_cast<T *>(N);
     FoldingSetTrait<T>::Profile(*TN,ID);
   }
index ff7fa71c036f40cd342e4519d65ded8d2e881f34..753eb240be80bd11bef43b5ab40899ee76b3e408 100644 (file)
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
-// FoldingSetImpl::NodeID Implementation
+// FoldingSetNodeID Implementation
 
 /// Add* - Add various data types to Bit data.
 ///
-void FoldingSetImpl::NodeID::AddPointer(const void *Ptr) {
+void FoldingSetNodeID::AddPointer(const void *Ptr) {
   // Note: this adds pointers to the hash using sizes and endianness that
   // depend on the host.  It doesn't matter however, because hashing on
   // pointer values in inherently unstable.  Nothing  should depend on the 
@@ -35,35 +35,35 @@ void FoldingSetImpl::NodeID::AddPointer(const void *Ptr) {
   if (sizeof(intptr_t) > sizeof(unsigned))
     Bits.push_back(unsigned(uint64_t(PtrI) >> 32));
 }
-void FoldingSetImpl::NodeID::AddInteger(signed I) {
+void FoldingSetNodeID::AddInteger(signed I) {
   Bits.push_back(I);
 }
-void FoldingSetImpl::NodeID::AddInteger(unsigned I) {
+void FoldingSetNodeID::AddInteger(unsigned I) {
   Bits.push_back(I);
 }
-void FoldingSetImpl::NodeID::AddInteger(int64_t I) {
+void FoldingSetNodeID::AddInteger(int64_t I) {
   AddInteger((uint64_t)I);
 }
-void FoldingSetImpl::NodeID::AddInteger(uint64_t I) {
+void FoldingSetNodeID::AddInteger(uint64_t I) {
   Bits.push_back(unsigned(I));
   
   // If the integer is small, encode it just as 32-bits.
   if ((uint64_t)(int)I != I)
     Bits.push_back(unsigned(I >> 32));
 }
-void FoldingSetImpl::NodeID::AddFloat(float F) {
+void FoldingSetNodeID::AddFloat(float F) {
   Bits.push_back(FloatToBits(F));
 }
-void FoldingSetImpl::NodeID::AddDouble(double D) {
+void FoldingSetNodeID::AddDouble(double D) {
  AddInteger(DoubleToBits(D));
 }
-void FoldingSetImpl::NodeID::AddAPFloat(const APFloat& apf) {
+void FoldingSetNodeID::AddAPFloat(const APFloat& apf) {
   APInt api = apf.convertToAPInt();
   const uint64_t *p = api.getRawData();
   for (unsigned i=0; i<api.getNumWords(); i++)
     AddInteger(*p++);
 }
-void FoldingSetImpl::NodeID::AddString(const std::string &String) {
+void FoldingSetNodeID::AddString(const std::string &String) {
   unsigned Size = String.size();
   Bits.push_back(Size);
   if (!Size) return;
@@ -100,9 +100,9 @@ void FoldingSetImpl::NodeID::AddString(const std::string &String) {
   Bits.push_back(V);
 }
 
-/// ComputeHash - Compute a strong hash value for this NodeID, used to 
+/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used to 
 /// lookup the node in the FoldingSetImpl.
-unsigned FoldingSetImpl::NodeID::ComputeHash() const {
+unsigned FoldingSetNodeID::ComputeHash() const {
   // This is adapted from SuperFastHash by Paul Hsieh.
   unsigned Hash = Bits.size();
   for (const unsigned *BP = &Bits[0], *E = BP+Bits.size(); BP != E; ++BP) {
@@ -125,7 +125,7 @@ unsigned FoldingSetImpl::NodeID::ComputeHash() const {
 
 /// operator== - Used to compare two nodes to each other.
 ///
-bool FoldingSetImpl::NodeID::operator==(const FoldingSetImpl::NodeID &RHS)const{
+bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{
   if (Bits.size() != RHS.Bits.size()) return false;
   return memcmp(&Bits[0], &RHS.Bits[0], Bits.size()*sizeof(Bits[0])) == 0;
 }
@@ -158,7 +158,7 @@ static void **GetBucketPtr(void *NextInBucketPtr) {
 
 /// GetBucketFor - Hash the specified node ID and return the hash bucket for
 /// the specified ID.
-static void **GetBucketFor(const FoldingSetImpl::NodeID &ID,
+static void **GetBucketFor(const FoldingSetNodeID &ID,
                            void **Buckets, unsigned NumBuckets) {
   // NumBuckets is always a power of 2.
   unsigned BucketNum = ID.ComputeHash() & (NumBuckets-1);
@@ -209,7 +209,7 @@ void FoldingSetImpl::GrowHashTable() {
       NodeInBucket->SetNextInBucket(0);
 
       // Insert the node into the new bucket, after recomputing the hash.
-      NodeID ID;
+      FoldingSetNodeID ID;
       GetNodeProfile(ID, NodeInBucket);
       InsertNode(NodeInBucket, GetBucketFor(ID, Buckets, NumBuckets));
     }
@@ -221,7 +221,7 @@ void FoldingSetImpl::GrowHashTable() {
 /// FindNodeOrInsertPos - Look up the node specified by ID.  If it exists,
 /// return it.  If not, return the insertion token that will make insertion
 /// faster.
-FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const NodeID &ID,
+FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
                                                           void *&InsertPos) {
   void **Bucket = GetBucketFor(ID, Buckets, NumBuckets);
   void *Probe = *Bucket;
@@ -229,7 +229,7 @@ FoldingSetImpl::Node *FoldingSetImpl::FindNodeOrInsertPos(const NodeID &ID,
   InsertPos = 0;
   
   while (Node *NodeInBucket = GetNextPtr(Probe)) {
-    NodeID OtherID;
+    FoldingSetNodeID OtherID;
     GetNodeProfile(OtherID, NodeInBucket);
     if (OtherID == ID)
       return NodeInBucket;
@@ -250,7 +250,7 @@ void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
   // Do we need to grow the hashtable?
   if (NumNodes+1 > NumBuckets*2) {
     GrowHashTable();
-    NodeID ID;
+    FoldingSetNodeID ID;
     GetNodeProfile(ID, N);
     InsertPos = GetBucketFor(ID, Buckets, NumBuckets);
   }
@@ -317,7 +317,7 @@ bool FoldingSetImpl::RemoveNode(Node *N) {
 /// equal to the specified node, return it.  Otherwise, insert 'N' and it
 /// instead.
 FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
-  NodeID ID;
+  FoldingSetNodeID ID;
   GetNodeProfile(ID, N);
   void *IP;
   if (Node *E = FindNodeOrInsertPos(ID, IP))