Skip to content

Commit

Permalink
Mark catch vars as used automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 3, 2024
1 parent 2b541b2 commit efcca25
Showing 1 changed file with 49 additions and 14 deletions.
63 changes: 49 additions & 14 deletions src/analyzer/stmt/try_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::{
function_analysis_data::FunctionAnalysisData, scope_analyzer::ScopeAnalyzer,
statements_analyzer::StatementsAnalyzer,
};
use hakana_reflection_info::data_flow::node::DataFlowNode;
use hakana_reflection_info::data_flow::graph::GraphKind;
use hakana_reflection_info::data_flow::node::{DataFlowNode, DataFlowNodeId, DataFlowNodeKind};
use hakana_reflection_info::data_flow::path::PathKind;
use hakana_reflection_info::VarId;
use hakana_type::{combine_union_types, get_named_object};
use oxidized::aast;
Expand Down Expand Up @@ -178,20 +180,53 @@ pub(crate) fn analyze(
analysis_data,
);

let new_parent_node = DataFlowNode::get_for_variable_source(
VarId(
statements_analyzer
.get_interner()
.get(catch_var_id)
.unwrap(),
),
statements_analyzer.get_hpos(&catch.1 .0),
false,
true,
false,
);
let new_parent_node = if analysis_data.data_flow_graph.kind == GraphKind::FunctionBody {
DataFlowNode::get_for_variable_source(
VarId(
statements_analyzer
.get_interner()
.get(catch_var_id)
.unwrap(),
),
statements_analyzer.get_hpos(&catch.1 .0),
false,
true,
false,
)
} else {
DataFlowNode::get_for_lvar(
VarId(
statements_analyzer
.get_interner()
.get(catch_var_id)
.unwrap(),
),
statements_analyzer.get_hpos(&catch.1 .0),
)
};

analysis_data
.data_flow_graph
.add_node(new_parent_node.clone());

if analysis_data.data_flow_graph.kind == GraphKind::FunctionBody {
let pos = statements_analyzer.get_hpos(&catch.1 .0);

let assignment_node = DataFlowNode {
id: DataFlowNodeId::UnlabelledSink(pos.file_path, pos.start_offset, pos.end_offset),
kind: DataFlowNodeKind::VariableUseSink { pos },
};

analysis_data.data_flow_graph.add_node(new_parent_node.clone());
analysis_data.data_flow_graph.add_path(
&new_parent_node,
&assignment_node,
PathKind::Default,
vec![],
vec![],
);

analysis_data.data_flow_graph.add_node(assignment_node);
}

catch_type.parent_nodes.push(new_parent_node);

Expand Down

0 comments on commit efcca25

Please sign in to comment.