mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
improvement(semantic/cfg): better control flow for DoWhileStatements. (#3452)
similar to #3451
This commit is contained in:
parent
0012094188
commit
91c999546c
2 changed files with 11 additions and 14 deletions
|
|
@ -649,6 +649,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
|||
self.visit_statement(&stmt.body);
|
||||
|
||||
/* cfg - condition basic block */
|
||||
let after_body_graph_ix = self.cfg.current_node_ix;
|
||||
let start_of_condition_graph_ix = self.cfg.new_basic_block();
|
||||
/* cfg */
|
||||
|
||||
|
|
@ -659,18 +660,14 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
|
|||
|
||||
let end_do_while_graph_ix = self.cfg.new_basic_block();
|
||||
|
||||
// before do while to start of condition basic block
|
||||
self.cfg.add_edge(
|
||||
before_do_while_stmt_graph_ix,
|
||||
start_of_condition_graph_ix,
|
||||
EdgeType::Normal,
|
||||
);
|
||||
// before do while to start of body basic block
|
||||
self.cfg.add_edge(before_do_while_stmt_graph_ix, start_body_graph_ix, EdgeType::Normal);
|
||||
// body of do-while to start of condition
|
||||
self.cfg.add_edge(start_body_graph_ix, start_of_condition_graph_ix, EdgeType::Backedge);
|
||||
self.cfg.add_edge(after_body_graph_ix, start_of_condition_graph_ix, EdgeType::Normal);
|
||||
// end of condition to after do while
|
||||
self.cfg.add_edge(end_of_condition_graph_ix, end_do_while_graph_ix, EdgeType::Normal);
|
||||
// end of condition to after start of body
|
||||
self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Normal);
|
||||
self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Backedge);
|
||||
|
||||
self.cfg.restore_state(
|
||||
&statement_state,
|
||||
|
|
|
|||
|
|
@ -26,18 +26,18 @@ digraph {
|
|||
2 -> 3 [ label = Normal ]
|
||||
4 -> 5 [ label = Unreachable , style = "dotted" ]
|
||||
4 -> 5 [ label = Normal ]
|
||||
3 -> 6 [ label = Normal ]
|
||||
4 -> 6 [ label = Backedge ]
|
||||
3 -> 4 [ label = Normal ]
|
||||
5 -> 6 [ label = Normal ]
|
||||
6 -> 7 [ label = Normal ]
|
||||
6 -> 4 [ label = Normal ]
|
||||
6 -> 4 [ label = Backedge ]
|
||||
7 -> 8 [ label = Unreachable , style = "dotted" ]
|
||||
2 -> 9 [ label = Normal ]
|
||||
10 -> 11 [ label = Unreachable , style = "dotted" ]
|
||||
10 -> 11 [ label = Normal ]
|
||||
9 -> 12 [ label = Normal ]
|
||||
10 -> 12 [ label = Backedge ]
|
||||
9 -> 10 [ label = Normal ]
|
||||
11 -> 12 [ label = Normal ]
|
||||
12 -> 13 [ label = Normal ]
|
||||
12 -> 10 [ label = Normal ]
|
||||
12 -> 10 [ label = Backedge ]
|
||||
13 -> 14 [ label = Normal ]
|
||||
0 -> 15 [ label = Normal ]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue