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 749b956
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 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
4 changes: 2 additions & 2 deletions src/analyzer/expr/echo_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hakana_reflection_info::functionlike_parameter::FunctionLikeParameter;
use hakana_reflection_info::t_atomic::TAtomic;
use hakana_reflection_info::t_union::TUnion;
use hakana_reflection_info::{StrId, EFFECT_IMPURE};
use hakana_type::{get_arraykey, get_mixed_any};
use hakana_type::get_mixed_any;
use oxidized::ast_defs::Pos;
use oxidized::{aast, ast_defs};

Expand All @@ -24,7 +24,7 @@ pub(crate) fn analyze(
analysis_data: &mut FunctionAnalysisData,
context: &mut ScopeContext,
) -> Result<(), AnalysisError> {
let mut echo_param = FunctionLikeParameter::new(
let echo_param = FunctionLikeParameter::new(
"var".to_string(),
HPos::new(call_pos, *statements_analyzer.get_file_path(), None),
HPos::new(call_pos, *statements_analyzer.get_file_path(), None),
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 749b956

Please sign in to comment.