Skip to content

Commit af7599f

Browse files
smowtonpeterschrammel
authored andcommitted
Style call_graph
No functional changes.
1 parent 9bfa1ee commit af7599f

File tree

2 files changed

+95
-109
lines changed

2 files changed

+95
-109
lines changed

src/analyses/call_graph.cpp

+62-70
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ void call_grapht::output_dot(std::ostream &out) const
123123

124124

125125
void call_grapht::output_dot(
126-
goto_functionst const& functions,
127-
std::ostream &out
128-
) const
126+
goto_functionst const &functions,
127+
std::ostream &out) const
129128
{
130129
out << "digraph call_graph {\n";
131-
for (auto const& elem : functions.function_map)
130+
for(auto const &elem : functions.function_map)
132131
out << " \"" << elem.first << "\";\n";
133132
for(grapht::const_iterator it=graph.begin();
134133
it!=graph.end();
@@ -189,31 +188,29 @@ void call_grapht::output_xml(std::ostream &out) const
189188

190189

191190
call_grapht::call_edges_ranget
192-
call_grapht::out_edges(irep_idt const& caller) const
191+
call_grapht::out_edges(irep_idt const &caller) const
193192
{
194193
return graph.equal_range(caller);
195194
}
196195

197196

198197
void inverted_partial_topological_order(
199-
call_grapht const& call_graph,
200-
irep_idt const& start_function,
201-
std::unordered_set<irep_idt,dstring_hash>& processed_functions,
202-
std::vector<irep_idt>& output
203-
)
198+
call_grapht const &call_graph,
199+
irep_idt const &start_function,
200+
std::unordered_set<irep_idt, dstring_hash> &processed_functions,
201+
std::vector<irep_idt> &output)
204202
{
205-
if (processed_functions.count(start_function) != 0ULL)
203+
if(processed_functions.count(start_function) != 0ULL)
206204
return;
207205
processed_functions.insert(start_function);
208206
call_grapht::call_edges_ranget const range =
209-
call_graph.out_edges(start_function);
210-
for (auto it = range.first; it != range.second; ++it)
207+
call_graph.out_edges(start_function);
208+
for(auto it = range.first; it != range.second; ++it)
211209
inverted_partial_topological_order(
212-
call_graph,
213-
it->second,
214-
processed_functions,
215-
output
216-
);
210+
call_graph,
211+
it->second,
212+
processed_functions,
213+
output);
217214
output.push_back(start_function);
218215
}
219216

@@ -222,99 +219,94 @@ void get_inverted_topological_order(
222219
goto_functionst const& functions,
223220
std::vector<irep_idt>& output)
224221
{
225-
std::unordered_set<irep_idt,dstring_hash> processed;
226-
for (auto const& elem : functions.function_map)
222+
std::unordered_set<irep_idt, dstring_hash> processed;
223+
for(auto const &elem : functions.function_map)
227224
inverted_partial_topological_order(
228225
call_graph,
229226
elem.first,
230227
processed,
231228
output);
232229
}
233230

234-
bool exists_direct_call(
235-
call_grapht const& call_graph,
236-
irep_idt const& caller,
237-
irep_idt const& callee
238-
)
231+
bool exists_direct_call(
232+
call_grapht const &call_graph,
233+
irep_idt const &caller,
234+
irep_idt const &callee)
239235
{
240236
call_grapht::call_edges_ranget const range =
241-
call_graph.out_edges(caller);
242-
for (auto it = range.first; it != range.second; ++it)
243-
if (callee == it->second)
237+
call_graph.out_edges(caller);
238+
for(auto it = range.first; it != range.second; ++it)
239+
if(callee == it->second)
244240
return true;
245241
return false;
246242
}
247243

248-
bool exists_direct_or_indirect_call(
249-
call_grapht const& call_graph,
250-
irep_idt const& caller,
251-
irep_idt const& callee,
252-
std::unordered_set<irep_idt,dstring_hash>& ignored_functions
253-
)
244+
bool exists_direct_or_indirect_call(
245+
call_grapht const &call_graph,
246+
irep_idt const &caller,
247+
irep_idt const &callee,
248+
std::unordered_set<irep_idt, dstring_hash> &ignored_functions)
254249
{
255-
if (ignored_functions.count(caller) != 0UL)
250+
if(ignored_functions.count(caller) != 0UL)
256251
return false;
257252
ignored_functions.insert(caller);
258-
if (exists_direct_call(call_graph,caller,callee))
253+
if(exists_direct_call(call_graph, caller, callee))
259254
return ignored_functions.count(callee) == 0UL;
260255
call_grapht::call_edges_ranget const range =
261-
call_graph.out_edges(caller);
262-
for (auto it = range.first; it != range.second; ++it)
263-
if (exists_direct_or_indirect_call(
256+
call_graph.out_edges(caller);
257+
for(auto it = range.first; it != range.second; ++it)
258+
if(exists_direct_or_indirect_call(
264259
call_graph,
265260
it->second,
266261
callee,
267-
ignored_functions
268-
))
262+
ignored_functions))
269263
return true;
270264
return false;
271265
}
272266

273-
bool exists_direct_or_indirect_call(
274-
call_grapht const& call_graph,
275-
irep_idt const& caller,
276-
irep_idt const& callee
277-
)
267+
bool exists_direct_or_indirect_call(
268+
call_grapht const &call_graph,
269+
irep_idt const &caller,
270+
irep_idt const &callee)
278271
{
279-
std::unordered_set<irep_idt,dstring_hash> ignored;
280-
return exists_direct_or_indirect_call(call_graph,caller,callee,ignored);
272+
std::unordered_set<irep_idt, dstring_hash> ignored;
273+
return exists_direct_or_indirect_call(call_graph, caller, callee, ignored);
281274
}
282275

283276
void compute_inverted_call_graph(
284-
call_grapht const& original_call_graph,
285-
call_grapht& output_inverted_call_graph
286-
)
277+
call_grapht const &original_call_graph,
278+
call_grapht &output_inverted_call_graph)
287279
{
288280
assert(output_inverted_call_graph.graph.empty());
289-
for (auto const& elem : original_call_graph.graph)
290-
output_inverted_call_graph.add(elem.second,elem.first);
281+
for(auto const &elem : original_call_graph.graph)
282+
output_inverted_call_graph.add(elem.second, elem.first);
291283
}
292284

293285
void find_leaves_bellow_function(
294-
call_grapht const& call_graph,
295-
irep_idt const& function,
296-
std::unordered_set<irep_idt,dstring_hash>& to_avoid,
297-
std::unordered_set<irep_idt,dstring_hash>& output
298-
)
286+
call_grapht const &call_graph,
287+
irep_idt const &function,
288+
std::unordered_set<irep_idt, dstring_hash> &to_avoid,
289+
std::unordered_set<irep_idt, dstring_hash> &output)
299290
{
300-
if (to_avoid.count(function) != 0UL)
291+
if(to_avoid.count(function) != 0UL)
301292
return;
302293
to_avoid.insert(function);
303294
call_grapht::call_edges_ranget const range =
304-
call_graph.out_edges(function);
305-
if (range.first == range.second)
295+
call_graph.out_edges(function);
296+
if(range.first == range.second)
306297
output.insert(function);
307298
else
308-
for (auto it = range.first; it != range.second; ++it)
309-
find_leaves_bellow_function(call_graph,it->second,to_avoid,output);
299+
{
300+
for(auto it = range.first; it != range.second; ++it)
301+
find_leaves_bellow_function(call_graph, it->second, to_avoid, output);
302+
}
310303
}
311304

312-
void find_leaves_bellow_function(
313-
call_grapht const& call_graph,
314-
irep_idt const& function,
315-
std::unordered_set<irep_idt,dstring_hash>& output
316-
)
305+
void find_leaves_below_function(
306+
call_grapht const &call_graph,
307+
irep_idt const &function,
308+
std::unordered_set<irep_idt, dstring_hash> &output)
317309
{
318-
std::unordered_set<irep_idt,dstring_hash> to_avoid;
319-
find_leaves_bellow_function(call_graph,function,to_avoid,output);
310+
std::unordered_set<irep_idt, dstring_hash> to_avoid;
311+
find_leaves_bellow_function(call_graph, function, to_avoid, output);
320312
}

src/analyses/call_graph.h

+33-39
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ class call_grapht
5151
* function. So, an iterator to any such element is actually an iterator to
5252
* an edge of the call graph.
5353
*/
54-
typedef grapht::const_iterator call_edge_iteratort;
54+
typedef grapht::const_iterator call_edge_iteratort;
5555

5656
/**
5757
* Since a call graph is implemented as a multimap, we use ranges
5858
* of call graph edges to represent out-edges from a node (a function)
5959
*/
60-
typedef std::pair<call_edge_iteratort,call_edge_iteratort> call_edges_ranget;
60+
typedef
61+
std::pair<call_edge_iteratort, call_edge_iteratort> call_edges_ranget;
6162

6263
/**
6364
* It returns a range of edges represented by a pair of iterators. The
@@ -105,65 +106,58 @@ Typical usage:
105106
// Let's assume there is 'goto_modelt GM' and 'call_grapht CG'
106107
std::vector<irep_idt> result; // Here we will store the topological order.
107108
{
108-
std::unordered_set<irep_idt,dstring_hash> processed;
109+
std::unordered_set<irep_idt, dstring_hash> processed;
109110
for (auto const& elem : GM.goto_functions.function_map)
110-
partial_topological_order(CG,elem.first,processed,result);
111+
partial_topological_order(CG, elem.first, processed, result);
111112
// Now we reverse the result to get the classic (partial)
112113
// topological order instead of the inverted one.
113-
std::reverse(result.begin(),result.end());
114+
std::reverse(result.begin(), result.end());
114115
}
115116
std::cout << "A (partial) topological order of my call graph is: ";
116117
for (irep_idt const& fn_name : result)
117118
std::cout << fn_name << ", ";
118119
119120
\*******************************************************************/
120121
void inverted_partial_topological_order(
121-
call_grapht const& call_graph,
122-
irep_idt const& start_function,
123-
std::unordered_set<irep_idt,dstring_hash>& processed_functions,
124-
std::vector<irep_idt>& output
125-
);
122+
call_grapht const &call_graph,
123+
irep_idt const &start_function,
124+
std::unordered_set<irep_idt, dstring_hash> &processed_functions,
125+
std::vector<irep_idt> &output);
126126

127127
void get_inverted_topological_order(
128128
call_grapht const& call_graph,
129129
goto_functionst const& functions,
130130
std::vector<irep_idt>& output);
131131

132132
bool exists_direct_call(
133-
call_grapht const& call_graph,
134-
irep_idt const& caller,
135-
irep_idt const& callee
136-
);
133+
call_grapht const &call_graph,
134+
irep_idt const &caller,
135+
irep_idt const &callee);
137136

138137
bool exists_direct_or_indirect_call(
139-
call_grapht const& call_graph,
140-
irep_idt const& caller,
141-
irep_idt const& callee,
142-
std::unordered_set<irep_idt,dstring_hash>& ignored_functions
143-
);
138+
call_grapht const &call_graph,
139+
irep_idt const &caller,
140+
irep_idt const &callee,
141+
std::unordered_set<irep_idt, dstring_hash> &ignored_functions);
144142

145143
bool exists_direct_or_indirect_call(
146-
call_grapht const& call_graph,
147-
irep_idt const& caller,
148-
irep_idt const& callee
149-
);
144+
call_grapht const &call_graph,
145+
irep_idt const &caller,
146+
irep_idt const &callee);
150147

151148
void compute_inverted_call_graph(
152-
call_grapht const& original_call_graph,
153-
call_grapht& output_inverted_call_graph
154-
);
155-
156-
void find_leaves_bellow_function(
157-
call_grapht const& call_graph,
158-
irep_idt const& function,
159-
std::unordered_set<irep_idt,dstring_hash>& to_avoid,
160-
std::unordered_set<irep_idt,dstring_hash>& output
161-
);
162-
163-
void find_leaves_bellow_function(
164-
call_grapht const& call_graph,
165-
irep_idt const& function,
166-
std::unordered_set<irep_idt,dstring_hash>& output
167-
);
149+
call_grapht const &original_call_graph,
150+
call_grapht &output_inverted_call_graph);
151+
152+
void find_leaves_below_function(
153+
call_grapht const &call_graph,
154+
irep_idt const &function,
155+
std::unordered_set<irep_idt, dstring_hash> &to_avoid,
156+
std::unordered_set<irep_idt, dstring_hash> &output);
157+
158+
void find_leaves_below_function(
159+
call_grapht const &call_graph,
160+
irep_idt const &function,
161+
std::unordered_set<irep_idt, dstring_hash> &output);
168162

169163
#endif // CPROVER_ANALYSES_CALL_GRAPH_H

0 commit comments

Comments
 (0)