pub fn callees_of<'a>(
cpg: &'a CodePropertyGraph,
func_name: &str,
) -> Vec<(&'a Node, &'a Node)>Expand description
For a given function name, returns all functions it directly calls.
Each returned tuple contains the callee node and the call‑site node.
The function first locates the caller by name, collects all
NodeKind::CallSite nodes inside its AST subtree, and follows
outgoing Edge::Call edges.
§Examples
use icb_graph::graph::{CodePropertyGraph, Node, Edge};
use icb_graph::query::callees_of;
use icb_common::NodeKind;
let mut cpg = CodePropertyGraph::new();
let foo = cpg.graph.add_node(Node {
kind: NodeKind::Function,
name: Some("foo".into()),
usr: Some("foo".into()),
start_line: 1,
end_line: 2,
});
let bar = cpg.graph.add_node(Node {
kind: NodeKind::Function,
name: Some("bar".into()),
usr: Some("bar".into()),
start_line: 5,
end_line: 6,
});
let call = cpg.graph.add_node(Node {
kind: NodeKind::CallSite,
name: Some("bar".into()),
usr: None,
start_line: 2,
end_line: 2,
});
cpg.graph.add_edge(foo, call, Edge::AstChild);
cpg.graph.add_edge(call, bar, Edge::Call);
let callees = callees_of(&cpg, "foo");
assert_eq!(callees.len(), 1);
assert_eq!(callees[0].0.name.as_deref(), Some("bar"));