Fix some null checks to actually test the part that needs checking.
[oota-llvm.git] / include / llvm / Analysis / ET-Forest.h
index 892a0b5f880e94b2627a2ea3d9fc9ecd98538231..8bd5e447bca6db63e5c5712e377776a6a667cbff 100644 (file)
@@ -30,6 +30,7 @@
 #define LLVM_ANALYSIS_ETFOREST_H
 
 #include <cassert>
+#include <cstdlib>
 
 namespace llvm {
 class ETNode;
@@ -49,6 +50,7 @@ public:
     Depth(0), Min(0), MinOccurrence(this) {};
 
   void setParent(ETOccurrence *n) {
+    assert(n != this && "Trying to set parent to ourselves");
     Parent = n;
   }
 
@@ -128,7 +130,8 @@ public:
 
 class ETNode {
 public:
-  ETNode(void *d) : data(d), Father(NULL), Left(NULL),
+  ETNode(void *d) : data(d), DFSNumIn(-1), DFSNumOut(-1),
+                    Father(NULL), Left(NULL),
                     Right(NULL), Son(NULL), ParentOcc(NULL) {   
     RightmostOcc = new ETOccurrence(this);
   };
@@ -138,6 +141,7 @@ public:
   // removeFromForest()
   ~ETNode() {
     delete RightmostOcc;
+    delete ParentOcc;
   }
 
   void removeFromForest() {
@@ -247,16 +251,7 @@ public:
     return this->Below(other);
   }
 
-  void assignDFSNumber(int &num) {
-    DFSNumIn = num++;
-    
-    if (Son) {
-      Son->assignDFSNumber(num);
-      for (ETNode *son = Son->Right; son != Son; son = son->Right)
-        son->assignDFSNumber(num);
-    }
-    DFSNumOut = num++;
-  }
+  void assignDFSNumber (int);
   
   bool hasFather() const {
     return Father != NULL;
@@ -280,12 +275,20 @@ public:
     return DFSNumOut;
   }
 
+  const ETNode *getSon() const {
+    return Son;
+  }
+  
+  const ETNode *getBrother() const {
+    return Left;
+  }
+
  private:
   // Data represented by the node
   void *data;
 
   // DFS Numbers
-  unsigned DFSNumIn, DFSNumOut;
+  int DFSNumIn, DFSNumOut;
 
   // Father
   ETNode *Father;