mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixup! Implementation of Lengauer-Tarjan algorithm to find dominators
This commit is contained in:
parent
83583f3448
commit
66b95967e6
@ -95,7 +95,7 @@ public:
|
||||
// @note for a vertex ``_v``, the _v’s inclusion in the set of dominators of ``_v`` is implicit.
|
||||
std::vector<Vertex> dominatorsOf(Vertex _v)
|
||||
{
|
||||
assert(m_vertex.size() > 0);
|
||||
solAssert(m_vertex.size() > 0);
|
||||
// The entry node always dominates all other nodes
|
||||
std::vector<Vertex> dominators = std::vector<Vertex>{m_vertex[0]};
|
||||
|
||||
@ -112,8 +112,8 @@ public:
|
||||
}
|
||||
|
||||
void buildDominatorTree() {
|
||||
assert(m_vertex.size() > 0);
|
||||
assert(m_immediateDominator.size() > 0);
|
||||
solAssert(m_vertex.size() > 0);
|
||||
solAssert(m_immediateDominator.size() > 0);
|
||||
|
||||
//Ignoring the entry node since no one dominates it.
|
||||
for (size_t i = 1; i < m_immediateDominator.size(); ++i)
|
||||
@ -129,7 +129,7 @@ public:
|
||||
size_t _v
|
||||
)
|
||||
{
|
||||
assert(_ancestor[_v] != std::numeric_limits<size_t>::max());
|
||||
solAssert(_ancestor[_v] != std::numeric_limits<size_t>::max());
|
||||
size_t u = _ancestor[_v];
|
||||
if (_ancestor[u] != std::numeric_limits<size_t>::max())
|
||||
{
|
||||
@ -142,7 +142,7 @@ public:
|
||||
|
||||
std::vector<size_t> lengauerTarjanDominator(Vertex _entry, size_t numVertices)
|
||||
{
|
||||
assert(numVertices > 0);
|
||||
solAssert(numVertices > 0);
|
||||
// semi(w): The dfs index of the semidominator of ``w``.
|
||||
std::vector<size_t> semi(numVertices, std::numeric_limits<size_t>::max());
|
||||
// parent(w): The index of the vertex which is the parent of ``w`` in the spanning
|
||||
|
@ -16,6 +16,8 @@
|
||||
*/
|
||||
#include <libyul/backends/evm/Dominator.h>
|
||||
|
||||
#include <test/libsolidity/util/SoltestErrors.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace solidity::yul;
|
||||
@ -64,14 +66,14 @@ protected:
|
||||
std::map<std::string, size_t> _expectedDFSIndices
|
||||
)
|
||||
{
|
||||
assert(_edges.size() > 0);
|
||||
soltestAssert(_edges.size() > 0);
|
||||
|
||||
ImmediateDominatorTest* graph = new ImmediateDominatorTest();
|
||||
for (std::string v: _vertices)
|
||||
graph->vertices.insert(make_pair(v, new Vertex{v, std::vector<Vertex*>{}}));
|
||||
graph->entry = graph->vertices[_vertices[0]];
|
||||
|
||||
assert(_vertices.size() > 0 && _vertices.size() == graph->vertices.size());
|
||||
soltestAssert(_vertices.size() > 0 && _vertices.size() == graph->vertices.size());
|
||||
|
||||
graph->numVertices = _vertices.size();
|
||||
for (auto [from, to]: _edges)
|
||||
|
Loading…
Reference in New Issue
Block a user