Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,25 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let kind = AstKind::LogicalExpression(self.alloc(expr));
self.enter_node(kind);

/* cfg - condition basic block */
#[cfg(feature = "cfg")]
let (before_logical_graph_ix, start_of_condition_graph_ix) = control_flow!(self, |cfg| {
let before_logical_graph_ix = cfg.current_node_ix;
let start_of_condition_graph_ix = cfg.new_basic_block_normal();
(before_logical_graph_ix, start_of_condition_graph_ix)
});
/* cfg */

#[cfg(feature = "cfg")]
self.record_ast_nodes();
self.visit_expression(&expr.left);
#[cfg(feature = "cfg")]
let left_node_id = self.retrieve_recorded_ast_node();

/* cfg */
#[cfg(feature = "cfg")]
let (left_expr_end_ix, right_expr_start_ix) = control_flow!(self, |cfg| {
cfg.append_condition_to(start_of_condition_graph_ix, left_node_id);
let left_expr_end_ix = cfg.current_node_ix;
let right_expr_start_ix = cfg.new_basic_block_normal();
(left_expr_end_ix, right_expr_start_ix)
Expand All @@ -888,6 +902,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let right_expr_end_ix = cfg.current_node_ix;
let after_logical_expr_ix = cfg.new_basic_block_normal();

cfg.add_edge(before_logical_graph_ix, start_of_condition_graph_ix, EdgeType::Normal);
cfg.add_edge(left_expr_end_ix, right_expr_start_ix, EdgeType::Normal);
cfg.add_edge(left_expr_end_ix, after_logical_expr_ix, EdgeType::Normal);
cfg.add_edge(right_expr_end_ix, after_logical_expr_ix, EdgeType::Normal);
Expand All @@ -913,12 +928,36 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
self.current_reference_flags = ReferenceFlags::read_write();
}

/* cfg - condition basic block */
#[cfg(feature = "cfg")]
let (before_assignment_graph_ix, start_of_condition_graph_ix) =
control_flow!(self, |cfg| {
if expr.operator.is_logical() {
let before_assignment_graph_ix = cfg.current_node_ix;
let start_of_condition_graph_ix = cfg.new_basic_block_normal();
(Some(before_assignment_graph_ix), Some(start_of_condition_graph_ix))
} else {
(None, None)
}
});
/* cfg */

#[cfg(feature = "cfg")]
if expr.operator.is_logical() {
self.record_ast_nodes();
}
self.visit_assignment_target(&expr.left);
#[cfg(feature = "cfg")]
let target_node_id =
if expr.operator.is_logical() { self.retrieve_recorded_ast_node() } else { None };

/* cfg */
#[cfg(feature = "cfg")]
let cfg_ixs = control_flow!(self, |cfg| {
if expr.operator.is_logical() {
if let Some(condition_ix) = start_of_condition_graph_ix {
cfg.append_condition_to(condition_ix, target_node_id);
}
let target_end_ix = cfg.current_node_ix;
let expr_start_ix = cfg.new_basic_block_normal();
Some((target_end_ix, expr_start_ix))
Expand All @@ -936,6 +975,11 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
let expr_end_ix = cfg.current_node_ix;
let after_assignment_ix = cfg.new_basic_block_normal();

if let Some((before_ix, condition_ix)) =
before_assignment_graph_ix.zip(start_of_condition_graph_ix)
{
cfg.add_edge(before_ix, condition_ix, EdgeType::Normal);
}
cfg.add_edge(target_end_ix, expr_start_ix, EdgeType::Normal);
cfg.add_edge(target_end_ix, after_assignment_ix, EdgeType::Normal);
cfg.add_edge(expr_end_ix, after_assignment_ix, EdgeType::Normal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ bb1: {
}

bb2: {

condition
}

bb3: {
statement

}

bb4: {

statement
}

bb5: {
statement
condition
}

bb6: {
Expand All @@ -33,37 +33,61 @@ bb6: {

bb7: {
statement
}

bb8: {
condition
}

bb9: {

}

bb10: {
statement
statement
}

digraph {
0 [ label = "bb0" shape = box]
1 [ label = "bb1
ExpressionStatement" shape = box]
2 [ label = "bb2" shape = box]
3 [ label = "bb3
2 [ label = "bb2
Condition(IdentifierReference(x))" shape = box]
3 [ label = "bb3" shape = box]
4 [ label = "bb4
ExpressionStatement" shape = box]
4 [ label = "bb4" shape = box]
5 [ label = "bb5
ExpressionStatement" shape = box]
Condition(IdentifierReference(x))" shape = box]
6 [ label = "bb6" shape = box]
7 [ label = "bb7
ExpressionStatement" shape = box]
8 [ label = "bb8
Condition(IdentifierReference(x))" shape = box]
9 [ label = "bb9" shape = box]
10 [ label = "bb10
ExpressionStatement
ExpressionStatement" shape = box]
1 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
2 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
3 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
4 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
1 -> 2 [ label="Normal"]
1 -> 3 [ label="Normal"]
2 -> 3 [ label="Normal"]
4 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
5 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
2 -> 4 [ label="Normal"]
3 -> 4 [ label="Normal"]
3 -> 5 [ label="Normal"]
4 -> 5 [ label="Normal"]
5 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
6 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
7 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
4 -> 5 [ label="Normal"]
5 -> 6 [ label="Normal"]
5 -> 7 [ label="Normal"]
6 -> 7 [ label="Normal"]
8 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
9 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
10 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
7 -> 8 [ label="Normal"]
8 -> 9 [ label="Normal"]
8 -> 10 [ label="Normal"]
9 -> 10 [ label="Normal"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,69 +96,77 @@ bb22: {
}

bb23: {

condition
}

bb24: {
return

}

bb25: {

return
}

bb26: {

}

bb27: {
statement

}

bb28: {

statement
}

bb29: {
return
condition
}

bb30: {

}

bb31: {

return
}

bb32: {
statement

}

bb33: {

}

bb34: {
return
statement
}

bb35: {
statement

}

bb36: {

return
}

bb37: {
return
statement
}

bb38: {

}

bb39: {
return
}

bb40: {

}

digraph {
0 [ label = "bb0" shape = box]
1 [ label = "bb1
Expand Down Expand Up @@ -198,29 +206,33 @@ ExpressionStatement" shape = box]
return" shape = box]
22 [ label = "bb22
ExpressionStatement" shape = box]
23 [ label = "bb23" shape = box]
24 [ label = "bb24
23 [ label = "bb23
Condition(Function(f))" shape = box]
24 [ label = "bb24" shape = box]
25 [ label = "bb25
return" shape = box]
25 [ label = "bb25" shape = box]
26 [ label = "bb26" shape = box]
27 [ label = "bb27
27 [ label = "bb27" shape = box]
28 [ label = "bb28
ExpressionStatement" shape = box]
28 [ label = "bb28" shape = box]
29 [ label = "bb29
return" shape = box]
Condition(Function(<anonymous>))" shape = box]
30 [ label = "bb30" shape = box]
31 [ label = "bb31" shape = box]
32 [ label = "bb32
ExpressionStatement" shape = box]
31 [ label = "bb31
return" shape = box]
32 [ label = "bb32" shape = box]
33 [ label = "bb33" shape = box]
34 [ label = "bb34
return" shape = box]
35 [ label = "bb35
ExpressionStatement" shape = box]
36 [ label = "bb36" shape = box]
37 [ label = "bb37
35 [ label = "bb35" shape = box]
36 [ label = "bb36
return" shape = box]
37 [ label = "bb37
ExpressionStatement" shape = box]
38 [ label = "bb38" shape = box]
39 [ label = "bb39
return" shape = box]
40 [ label = "bb40" shape = box]
1 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
3 -> 2 [ label="Error(Implicit)", color=red, style=dashed]
1 -> 3 [ label="NewFunction"]
Expand Down Expand Up @@ -250,30 +262,34 @@ return" shape = box]
19 -> 21 [ label="NewFunction"]
22 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
19 -> 22 [ label="Normal"]
24 -> 23 [ label="Error(Implicit)", color=red, style=dashed]
22 -> 24 [ label="NewFunction"]
25 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
22 -> 25 [ label="Normal"]
23 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
25 -> 24 [ label="Error(Implicit)", color=red, style=dashed]
23 -> 25 [ label="NewFunction"]
26 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
23 -> 26 [ label="Normal"]
27 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
25 -> 26 [ label="Normal"]
25 -> 27 [ label="Normal"]
28 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
22 -> 23 [ label="Normal"]
26 -> 27 [ label="Normal"]
29 -> 28 [ label="Error(Implicit)", color=red, style=dashed]
27 -> 29 [ label="NewFunction"]
30 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
27 -> 30 [ label="Normal"]
31 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
26 -> 28 [ label="Normal"]
27 -> 28 [ label="Normal"]
29 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
31 -> 30 [ label="Error(Implicit)", color=red, style=dashed]
29 -> 31 [ label="NewFunction"]
32 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
30 -> 31 [ label="Normal"]
30 -> 32 [ label="Normal"]
31 -> 32 [ label="Normal"]
34 -> 33 [ label="Error(Implicit)", color=red, style=dashed]
32 -> 34 [ label="NewFunction"]
35 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
32 -> 35 [ label="Normal"]
37 -> 36 [ label="Error(Implicit)", color=red, style=dashed]
35 -> 37 [ label="NewFunction"]
38 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
35 -> 38 [ label="Normal"]
29 -> 32 [ label="Normal"]
33 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
34 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
28 -> 29 [ label="Normal"]
32 -> 33 [ label="Normal"]
32 -> 34 [ label="Normal"]
33 -> 34 [ label="Normal"]
36 -> 35 [ label="Error(Implicit)", color=red, style=dashed]
34 -> 36 [ label="NewFunction"]
37 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
34 -> 37 [ label="Normal"]
39 -> 38 [ label="Error(Implicit)", color=red, style=dashed]
37 -> 39 [ label="NewFunction"]
40 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
37 -> 40 [ label="Normal"]
}
Loading
Loading