2016-06-09 15:49:07 -07:00
|
|
|
use super::indexed_vec::Idx;
|
|
|
|
|
|
|
|
pub mod dominators;
|
2018-07-01 17:06:00 -04:00
|
|
|
pub mod implementation;
|
2016-06-09 15:49:07 -07:00
|
|
|
pub mod iterate;
|
|
|
|
mod reference;
|
2018-07-02 10:40:03 -04:00
|
|
|
pub mod scc;
|
2019-06-11 13:40:24 -04:00
|
|
|
pub mod vec_graph;
|
2016-06-09 15:49:07 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test;
|
|
|
|
|
2018-07-01 16:54:01 -04:00
|
|
|
pub trait DirectedGraph {
|
2016-06-09 15:49:07 -07:00
|
|
|
type Node: Idx;
|
2018-07-01 16:54:01 -04:00
|
|
|
}
|
2016-06-09 15:49:07 -07:00
|
|
|
|
2018-07-01 16:54:01 -04:00
|
|
|
pub trait WithNumNodes: DirectedGraph {
|
2016-06-09 15:49:07 -07:00
|
|
|
fn num_nodes(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2019-06-11 13:40:24 -04:00
|
|
|
pub trait WithNumEdges: DirectedGraph {
|
|
|
|
fn num_edges(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2018-07-01 16:54:01 -04:00
|
|
|
pub trait WithSuccessors: DirectedGraph
|
|
|
|
where
|
|
|
|
Self: for<'graph> GraphSuccessors<'graph, Item = <Self as DirectedGraph>::Node>,
|
|
|
|
{
|
|
|
|
fn successors<'graph>(
|
|
|
|
&'graph self,
|
|
|
|
node: Self::Node,
|
|
|
|
) -> <Self as GraphSuccessors<'graph>>::Iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait GraphSuccessors<'graph> {
|
2016-06-09 15:49:07 -07:00
|
|
|
type Item;
|
2016-10-20 00:25:19 +05:30
|
|
|
type Iter: Iterator<Item = Self::Item>;
|
2016-06-09 15:49:07 -07:00
|
|
|
}
|
|
|
|
|
2018-07-01 16:54:01 -04:00
|
|
|
pub trait WithPredecessors: DirectedGraph
|
|
|
|
where
|
|
|
|
Self: for<'graph> GraphPredecessors<'graph, Item = <Self as DirectedGraph>::Node>,
|
|
|
|
{
|
|
|
|
fn predecessors<'graph>(
|
|
|
|
&'graph self,
|
|
|
|
node: Self::Node,
|
|
|
|
) -> <Self as GraphPredecessors<'graph>>::Iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait GraphPredecessors<'graph> {
|
2016-06-09 15:49:07 -07:00
|
|
|
type Item;
|
2016-10-20 00:25:19 +05:30
|
|
|
type Iter: Iterator<Item = Self::Item>;
|
|
|
|
}
|
2018-07-01 16:54:01 -04:00
|
|
|
|
|
|
|
pub trait WithStartNode: DirectedGraph {
|
|
|
|
fn start_node(&self) -> Self::Node;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait ControlFlowGraph:
|
|
|
|
DirectedGraph + WithStartNode + WithPredecessors + WithStartNode + WithSuccessors + WithNumNodes
|
|
|
|
{
|
|
|
|
// convenient trait
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> ControlFlowGraph for T
|
|
|
|
where
|
|
|
|
T: DirectedGraph
|
|
|
|
+ WithStartNode
|
|
|
|
+ WithPredecessors
|
|
|
|
+ WithStartNode
|
|
|
|
+ WithSuccessors
|
|
|
|
+ WithNumNodes,
|
|
|
|
{
|
|
|
|
}
|