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 struct CallGraph {
12 pub fn_calls: HashMap<DefId, Vec<DefId>>, }
14
15pub struct CallGraphDisplay<'a, 'tcx> {
16 pub graph: &'a CallGraph,
17 pub tcx: TyCtxt<'tcx>,
18}
19
20impl<'a, 'tcx> fmt::Display for CallGraphDisplay<'a, 'tcx> {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 writeln!(f, "CallGraph:")?;
23 for (caller, callees) in &self.graph.fn_calls {
24 let caller_name = self.tcx.def_path_str(*caller);
25 writeln!(f, " {} calls:", caller_name)?;
26 for callee in callees {
27 let callee_name = self.tcx.def_path_str(*callee);
28 writeln!(f, " -> {}", callee_name)?;
29 }
30 }
31 Ok(())
32 }
33}
34
35pub trait CallGraphAnalysis: Analysis {
37 fn get_callgraph(&mut self) -> CallGraph;
39}