cprover
call_graph_helpers.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Function Call Graph Helpers
4 
5 Author: Chris Smowton, chris.smowton@diffblue.com
6 
7 \*******************************************************************/
8 
11 
12 #include "call_graph_helpers.h"
13 
18 static std::set<irep_idt> get_neighbours(
19  const call_grapht::directed_grapht &graph,
20  const irep_idt &function,
21  bool forwards)
22 {
23  std::set<irep_idt> result;
24  const auto &fnode = graph[*(graph.get_node_index(function))];
25  const auto &neighbours = forwards ? fnode.out : fnode.in;
26  for(const auto &succ_edge : neighbours)
27  result.insert(graph[succ_edge.first].function);
28  return result;
29 }
30 
31 std::set<irep_idt> get_callees(
32  const call_grapht::directed_grapht &graph, const irep_idt &function)
33 {
34  return get_neighbours(graph, function, true);
35 }
36 
37 std::set<irep_idt> get_callers(
38  const call_grapht::directed_grapht &graph, const irep_idt &function)
39 {
40  return get_neighbours(graph, function, false);
41 }
42 
49 static std::set<irep_idt> get_connected_functions(
50  const call_grapht::directed_grapht &graph,
51  const irep_idt &function,
52  bool forwards)
53 {
54  std::vector<call_grapht::directed_grapht::node_indext> connected_nodes =
55  graph.get_reachable(*(graph.get_node_index(function)), forwards);
56  std::set<irep_idt> result;
57  for(const auto i : connected_nodes)
58  result.insert(graph[i].function);
59  return result;
60 }
61 
62 std::set<irep_idt> get_reachable_functions(
63  const call_grapht::directed_grapht &graph, const irep_idt &function)
64 {
65  return get_connected_functions(graph, function, true);
66 }
67 
68 std::set<irep_idt> get_reaching_functions(
69  const call_grapht::directed_grapht &graph, const irep_idt &function)
70 {
71  return get_connected_functions(graph, function, false);
72 }
std::set< irep_idt > get_callers(const call_grapht::directed_grapht &graph, const irep_idt &function)
Get functions that call a given function.
static std::set< irep_idt > get_connected_functions(const call_grapht::directed_grapht &graph, const irep_idt &function, bool forwards)
Get either reachable functions or functions that can reach a given function.
static std::set< irep_idt > get_neighbours(const call_grapht::directed_grapht &graph, const irep_idt &function, bool forwards)
Get either callers or callees of a given function.
optionalt< node_indext > get_node_index(const irep_idt &function) const
Find the graph node by function name.
Definition: call_graph.cpp:293
const edgest & out(node_indext n) const
Definition: graph.h:193
std::set< irep_idt > get_reaching_functions(const call_grapht::directed_grapht &graph, const irep_idt &function)
Get functions that can reach a given function.
Directed graph representation of this call graph.
Definition: call_graph.h:117
std::set< irep_idt > get_reachable_functions(const call_grapht::directed_grapht &graph, const irep_idt &function)
Get functions reachable from a given function.
Function Call Graph Helpers.
std::set< irep_idt > get_callees(const call_grapht::directed_grapht &graph, const irep_idt &function)
Get functions directly callable from a given function.
std::vector< node_indext > get_reachable(node_indext src, bool forwards) const
Run depth-first search on the graph, starting from a single source node.
Definition: graph.h:503