Skip to content

Commit

Permalink
Ensure hooks only run once
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 29, 2024
1 parent f22ee04 commit 0e19a66
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
35 changes: 20 additions & 15 deletions src/analyzer/expr/call/argument_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,26 @@ pub(crate) fn check_argument_matches(

let config = statements_analyzer.get_config();

for hook in &config.hooks {
hook.after_argument_analysis(
analysis_data,
AfterArgAnalysisData {
functionlike_id,
statements_analyzer,
context,
arg_value_type: &arg_value_type,
arg,
param_type: &param_type,
argument_offset,
function_call_pos,
function_name_pos,
},
);
if !analysis_data.after_arg_hook_called.insert((
arg.1.pos().start_offset() as u32,
arg.1.pos().end_offset() as u32,
)) {
for hook in &config.hooks {
hook.after_argument_analysis(
analysis_data,
AfterArgAnalysisData {
functionlike_id,
statements_analyzer,
context,
arg_value_type: &arg_value_type,
arg,
param_type: &param_type,
argument_offset,
function_call_pos,
function_name_pos,
},
);
}
}

self::verify_type(
Expand Down
23 changes: 14 additions & 9 deletions src/analyzer/expression_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,20 @@ pub(crate) fn analyze(
aast::Expr_::Package(_) => todo!(),
}

for hook in &statements_analyzer.get_config().hooks {
hook.after_expr_analysis(
analysis_data,
AfterExprAnalysisData {
statements_analyzer,
expr,
context,
},
);
if !analysis_data.after_expr_hook_called.insert((
expr.pos().start_offset() as u32,
expr.pos().end_offset() as u32,
)) {
for hook in &statements_analyzer.get_config().hooks {
hook.after_expr_analysis(
analysis_data,
AfterExprAnalysisData {
statements_analyzer,
expr,
context,
},
);
}
}

Ok(())
Expand Down
4 changes: 4 additions & 0 deletions src/analyzer/function_analysis_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub struct FunctionAnalysisData {
pub matched_ignore_positions: FxHashSet<(u32, u32)>,
pub type_variable_bounds: FxHashMap<String, (Vec<TemplateBound>, Vec<TemplateBound>)>,
pub migrate_function: Option<bool>,
pub after_expr_hook_called: FxHashSet<(u32, u32)>,
pub after_arg_hook_called: FxHashSet<(u32, u32)>,
}

impl FunctionAnalysisData {
Expand Down Expand Up @@ -81,6 +83,8 @@ impl FunctionAnalysisData {
issue_counts: FxHashMap::default(),
type_variable_bounds: FxHashMap::default(),
migrate_function: None,
after_arg_hook_called: FxHashSet::default(),
after_expr_hook_called: FxHashSet::default(),
}
}

Expand Down

0 comments on commit 0e19a66

Please sign in to comment.