Skip to content

Commit

Permalink
feat: add is_cyclic API to the CFG.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed May 28, 2024
1 parent a79dcea commit 2052b4c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/oxc_semantic/src/control_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::operator::{
};
use petgraph::{
stable_graph::NodeIndex,
visit::{Dfs, Walker},
visit::{depth_first_search, Dfs, DfsEvent, Walker},
Graph,
};

Expand Down Expand Up @@ -204,6 +204,14 @@ impl ControlFlowGraph {
})
.any(|x| x == to)
}

pub fn is_cyclic(&self, node: BasicBlockId) -> bool {
depth_first_search(&self.graph, Some(node), |event| match event {
DfsEvent::BackEdge(_, id) if id == node => Err(()),
_ => Ok(()),
})
.is_err()
}
}

pub enum StatementControlFlowType {
Expand Down

0 comments on commit 2052b4c

Please sign in to comment.