Skip to content

Commit

Permalink
Re-run custom analysis inside loops
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Apr 23, 2024
1 parent 28e72df commit 7602033
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/analyzer/custom_hook.rs
Expand Up @@ -19,6 +19,7 @@ pub struct AfterExprAnalysisData<'a> {
pub context: &'a ScopeContext,
pub expr: &'a aast::Expr<(), ()>,
pub statements_analyzer: &'a StatementsAnalyzer<'a>,
pub already_called: bool,
}

pub struct AfterStmtAnalysisData<'a> {
Expand Down Expand Up @@ -52,6 +53,7 @@ pub struct AfterArgAnalysisData<'a> {
pub functionlike_id: &'a FunctionLikeIdentifier,
pub param_type: &'a TUnion,
pub statements_analyzer: &'a StatementsAnalyzer<'a>,
pub already_called: bool,
}

pub trait InternalHook {
Expand Down
37 changes: 19 additions & 18 deletions src/analyzer/expr/call/argument_analyzer.rs
Expand Up @@ -55,26 +55,27 @@ pub(crate) fn check_argument_matches(

let config = statements_analyzer.get_config();

if analysis_data.after_arg_hook_called.insert((
let newly_called = 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,
},
);
}
));

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,
already_called: !newly_called,
},
);
}

self::verify_type(
Expand Down
25 changes: 13 additions & 12 deletions src/analyzer/expression_analyzer.rs
Expand Up @@ -563,20 +563,21 @@ pub(crate) fn analyze(
aast::Expr_::Package(_) => todo!(),
}

if analysis_data.after_expr_hook_called.insert((
let newly_called = 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,
},
);
}
));

for hook in &statements_analyzer.get_config().hooks {
hook.after_expr_analysis(
analysis_data,
AfterExprAnalysisData {
statements_analyzer,
expr,
context,
already_called: !newly_called,
},
);
}

analysis_data.applicable_fixme_start = expr.pos().end_offset() as u32;
Expand Down
13 changes: 6 additions & 7 deletions src/analyzer/function_analysis_data.rs
Expand Up @@ -193,14 +193,17 @@ impl FunctionAnalysisData {
return false;
}

self.can_output_issue(issue)
}

fn can_output_issue(&mut self, issue: &Issue) -> bool {
*self.issue_counts.entry(issue.kind.clone()).or_insert(0) += 1;

if let Some(issue_filter) = &self.issue_filter {
if !issue_filter.contains(&issue.kind) {
return false;
}
}

true
}

Expand Down Expand Up @@ -387,12 +390,8 @@ impl FunctionAnalysisData {
self.add_issue_fixme(&issue);
}

*self.issue_counts.entry(issue.kind.clone()).or_insert(0) += 1;

if let Some(issue_filter) = &self.issue_filter {
if !issue_filter.contains(&issue.kind) {
return;
}
if !self.can_output_issue(&issue) {
return;
}

self.add_issue(issue);
Expand Down

0 comments on commit 7602033

Please sign in to comment.