rapx/analysis/core/callgraph/
mod.rs1pub mod default;
2pub mod visitor;
3
4use crate::Analysis;
5use rustc_hir::def_id::DefId;
6use rustc_middle::ty::TyCtxt;
7use std::{collections::HashMap, fmt};
8
9pub type FnCallMap = HashMap<DefId, Vec<DefId>>; pub struct FnCallDisplay<'a, 'tcx> {
12 pub fn_calls: &'a FnCallMap,
13 pub tcx: TyCtxt<'tcx>,
14}
15
16impl<'a, 'tcx> fmt::Display for FnCallDisplay<'a, 'tcx> {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 writeln!(f, "CallGraph:")?;
19 for (caller, callees) in self.fn_calls {
20 let caller_name = self.tcx.def_path_str(*caller);
21 writeln!(f, " {} calls:", caller_name)?;
22 for callee in callees {
23 let callee_name = self.tcx.def_path_str(*callee);
24 writeln!(f, " -> {}", callee_name)?;
25 }
26 }
27 Ok(())
28 }
29}
30
31pub trait CallGraphAnalysis: Analysis {
33 fn get_fn_calls(&self) -> FnCallMap;
35}