2016-06-09 15:49:07 -07:00
|
|
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
#[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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
{
|
|
|
|
}
|