]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - dfg/DFGAdjacencyList.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / dfg / DFGAdjacencyList.h
index e2b096bf4c665dd8112fb2b6811aee002d854e6b..d3f925d4b1a011a7b0fb9db39a503a52d82f1cfa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -41,11 +41,12 @@ public:
         Fixed,
         Variable
     };
-
+    
+    enum { Size = 3 };
+    
+    AdjacencyList() { }
+    
     AdjacencyList(Kind kind)
-#if !ASSERT_DISABLED
-        : m_kind(kind)
-#endif
     {
         if (kind == Variable) {
             m_words[0].m_encodedWord = UINT_MAX;
@@ -53,19 +54,13 @@ public:
         }
     }
     
-    AdjacencyList(Kind kind, NodeIndex child1, NodeIndex child2, NodeIndex child3)
-#if !ASSERT_DISABLED
-        : m_kind(Fixed)
-#endif
+    AdjacencyList(Kind kind, Edge child1, Edge child2, Edge child3)
     {
         ASSERT_UNUSED(kind, kind == Fixed);
         initialize(child1, child2, child3);
     }
     
     AdjacencyList(Kind kind, unsigned firstChild, unsigned numChildren)
-#if !ASSERT_DISABLED
-        : m_kind(Variable)
-#endif
     {
         ASSERT_UNUSED(kind, kind == Variable);
         setFirstChild(firstChild);
@@ -74,22 +69,19 @@ public:
     
     const Edge& child(unsigned i) const
     {
-        ASSERT(i < 3);
-        ASSERT(m_kind == Fixed);
+        ASSERT(i < Size);
         return m_words[i];
     }    
     
     Edge& child(unsigned i)
     {
-        ASSERT(i < 3);
-        ASSERT(m_kind == Fixed);
+        ASSERT(i < Size);
         return m_words[i];
     }
     
     void setChild(unsigned i, Edge nodeUse)
     {
-        ASSERT(i < 30);
-        ASSERT(m_kind == Fixed);
+        ASSERT(i < Size);
         m_words[i] = nodeUse;
     }
     
@@ -114,38 +106,44 @@ public:
         child(2) = child3;
     }
     
-    void initialize(NodeIndex child1, NodeIndex child2, NodeIndex child3)
+    void initialize(Node* child1 = 0, Node* child2 = 0, Node* child3 = 0)
     {
         initialize(Edge(child1), Edge(child2), Edge(child3));
     }
+    
+    void reset()
+    {
+        initialize();
+    }
+    
+    // Call this if you wish to remove an edge and the node treats the list of children.
+    void removeEdge(unsigned edgeIndex)
+    {
+        for (unsigned i = edgeIndex; i < Size - 1; ++i)
+            setChild(i, child(i + 1));
+        setChild(Size - 1, Edge());
+    }
 
     unsigned firstChild() const
     {
-        ASSERT(m_kind == Variable);
         return m_words[0].m_encodedWord;
     }
     void setFirstChild(unsigned firstChild)
     {
-        ASSERT(m_kind == Variable);
         m_words[0].m_encodedWord = firstChild;
     }
     
     unsigned numChildren() const
     {
-        ASSERT(m_kind == Variable);
         return m_words[1].m_encodedWord;
     }
     void setNumChildren(unsigned numChildren)
     {
-        ASSERT(m_kind == Variable);
         m_words[1].m_encodedWord = numChildren;
     }
     
 private:
-    Edge m_words[3];
-#if !ASSERT_DISABLED
-    Kind m_kind;
-#endif
+    Edge m_words[Size];
 };
 
 } } // namespace JSC::DFG