/*
- * 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
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;
}
}
- 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);
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;
}
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