@@ -13,22 +13,22 @@ Author: Daniel Kroening, kroening@kroening.com
1313
1414#include < util/xml.h>
1515
16- #include < goto-programs/ goto_model.h>
16+ #include " goto_model.h"
1717
1818// / Create empty call graph
1919// / \param collect_callsites: if true, then each added graph edge will have
2020// / the calling instruction recorded in `callsites` map.
21- call_grapht::call_grapht (bool collect_callsites):
22- collect_callsites(collect_callsites)
21+ call_grapht::call_grapht (bool collect_callsites)
22+ : collect_callsites(collect_callsites)
2323{
2424}
2525
2626// / Create complete call graph
2727// / \param goto_model: model to search for callsites
2828// / \param collect_callsites: if true, then each added graph edge will have
2929// / the calling instruction recorded in `callsites` map.
30- call_grapht::call_grapht (const goto_modelt &goto_model, bool collect_callsites):
31- call_grapht(goto_model.goto_functions, collect_callsites)
30+ call_grapht::call_grapht (const goto_modelt &goto_model, bool collect_callsites)
31+ : call_grapht(goto_model.goto_functions, collect_callsites)
3232{
3333}
3434
@@ -37,8 +37,9 @@ call_grapht::call_grapht(const goto_modelt &goto_model, bool collect_callsites):
3737// / \param collect_callsites: if true, then each added graph edge will have
3838// / the calling instruction recorded in `callsites` map.
3939call_grapht::call_grapht (
40- const goto_functionst &goto_functions, bool collect_callsites):
41- collect_callsites(collect_callsites)
40+ const goto_functionst &goto_functions,
41+ bool collect_callsites)
42+ : collect_callsites(collect_callsites)
4243{
4344 for (const auto &gf_entry : goto_functions.function_map )
4445 {
@@ -75,15 +76,15 @@ static void forall_callsites(
7576call_grapht::call_grapht (
7677 const goto_functionst &goto_functions,
7778 const irep_idt &root,
78- bool collect_callsites):
79- collect_callsites(collect_callsites)
79+ bool collect_callsites)
80+ : collect_callsites(collect_callsites)
8081{
8182 std::stack<irep_idt, std::vector<irep_idt>> pending_stack;
8283 pending_stack.push (root);
8384
8485 while (!pending_stack.empty ())
8586 {
86- irep_idt function= pending_stack.top ();
87+ irep_idt function = pending_stack.top ();
8788 pending_stack.pop ();
8889
8990 nodes.insert (function);
@@ -97,13 +98,11 @@ call_grapht::call_grapht(
9798
9899 forall_callsites (
99100 goto_program,
100- [&](goto_programt::const_targett i_it, const irep_idt &callee)
101- {
101+ [&](goto_programt::const_targett i_it, const irep_idt &callee) {
102102 add (function, callee, i_it);
103- if (edges.find (callee)== edges.end ())
103+ if (edges.find (callee) == edges.end ())
104104 pending_stack.push (callee);
105- }
106- ); // NOLINT
105+ }); // NOLINT
107106 }
108107}
109108
@@ -115,30 +114,23 @@ call_grapht::call_grapht(
115114call_grapht::call_grapht (
116115 const goto_modelt &goto_model,
117116 const irep_idt &root,
118- bool collect_callsites):
119- call_grapht(goto_model.goto_functions, root, collect_callsites)
117+ bool collect_callsites)
118+ : call_grapht(goto_model.goto_functions, root, collect_callsites)
120119{
121120}
122121
123- void call_grapht::add (
124- const irep_idt &function,
125- const goto_programt &body)
122+ void call_grapht::add (const irep_idt &function, const goto_programt &body)
126123{
127124 forall_callsites (
128- body,
129- [&](goto_programt::const_targett i_it, const irep_idt &callee)
130- {
125+ body, [&](goto_programt::const_targett i_it, const irep_idt &callee) {
131126 add (function, callee, i_it);
132- }
133- ); // NOLINT
127+ }); // NOLINT
134128}
135129
136130// / Add edge
137131// / \param caller: caller function
138132// / \param callee: callee function
139- void call_grapht::add (
140- const irep_idt &caller,
141- const irep_idt &callee)
133+ void call_grapht::add (const irep_idt &caller, const irep_idt &callee)
142134{
143135 edges.insert ({caller, callee});
144136 nodes.insert (caller);
@@ -181,19 +173,18 @@ class function_indicest
181173public:
182174 std::unordered_map<irep_idt, node_indext> function_indices;
183175
184- explicit function_indicest (call_grapht::directed_grapht &graph):
185- graph(graph)
176+ explicit function_indicest (call_grapht::directed_grapht &graph) : graph(graph)
186177 {
187178 }
188179
189180 node_indext operator [](const irep_idt &function)
190181 {
191- auto findit= function_indices.insert ({function, 0 });
182+ auto findit = function_indices.insert ({function, 0 });
192183 if (findit.second )
193184 {
194- node_indext new_index= graph.add_node ();
195- findit.first ->second = new_index;
196- graph[new_index].function = function;
185+ node_indext new_index = graph.add_node ();
186+ findit.first ->second = new_index;
187+ graph[new_index].function = function;
197188 }
198189 return findit.first ->second ;
199190 }
@@ -218,19 +209,19 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
218209
219210 for (const auto &edge : edges)
220211 {
221- auto a_index= function_indices[edge.first ];
222- auto b_index= function_indices[edge.second ];
212+ auto a_index = function_indices[edge.first ];
213+ auto b_index = function_indices[edge.second ];
223214 // Check then create the edge like this to avoid copying the callsites
224215 // set once per parallel edge, which could be costly if there are many.
225216 if (!ret.has_edge (a_index, b_index))
226217 {
227218 ret.add_edge (a_index, b_index);
228219 if (collect_callsites)
229- ret[a_index].out [b_index].callsites = callsites.at (edge);
220+ ret[a_index].out [b_index].callsites = callsites.at (edge);
230221 }
231222 }
232223
233- ret.nodes_by_name = std::move (function_indices.function_indices );
224+ ret.nodes_by_name = std::move (function_indices.function_indices );
234225 return ret;
235226}
236227
@@ -241,14 +232,14 @@ call_grapht::directed_grapht call_grapht::get_directed_graph() const
241232std::string call_grapht::format_callsites (const edget &edge) const
242233{
243234 PRECONDITION (collect_callsites);
244- std::string ret= " {" ;
235+ std::string ret = " {" ;
245236 for (const locationt &loc : callsites.at (edge))
246237 {
247- if (ret.size ()> 1 )
248- ret+= " , " ;
249- ret+= std::to_string (loc->location_number );
238+ if (ret.size () > 1 )
239+ ret += " , " ;
240+ ret += std::to_string (loc->location_number );
250241 }
251- ret+= ' }' ;
242+ ret += ' }' ;
252243 return ret;
253244}
254245
@@ -285,7 +276,7 @@ void call_grapht::output_xml(std::ostream &out) const
285276 // to the first interested XML user.
286277 if (collect_callsites)
287278 out << " <!-- XML call-graph representation does not document callsites yet."
288- " If you need this, edit call_grapht::output_xml -->\n " ;
279+ " If you need this, edit call_grapht::output_xml -->\n " ;
289280 for (const auto &edge : edges)
290281 {
291282 out << " <call_graph_edge caller=\" " ;
@@ -299,8 +290,8 @@ void call_grapht::output_xml(std::ostream &out) const
299290std::optional<std::size_t >
300291call_grapht::directed_grapht::get_node_index (const irep_idt &function) const
301292{
302- auto findit= nodes_by_name.find (function);
303- if (findit== nodes_by_name.end ())
293+ auto findit = nodes_by_name.find (function);
294+ if (findit == nodes_by_name.end ())
304295 return std::optional<node_indext>();
305296 else
306297 return findit->second ;
0 commit comments