Skip to content

Commit 8321a10

Browse files
author
Daniel Kroening
authored
Merge pull request #3165 from diffblue/goto_functions_message
use a separate message for show_goto_functions() for the console
2 parents 2490725 + 4fcde9a commit 8321a10

6 files changed

+80
-51
lines changed

src/goto-programs/goto_functions.cpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,7 @@ Date: June 2003
1313

1414
#include "goto_functions.h"
1515

16-
void goto_functionst::output(
17-
const namespacet &ns,
18-
std::ostream &out) const
19-
{
20-
for(const auto &fun : function_map)
21-
{
22-
if(fun.second.body_available())
23-
{
24-
out << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
25-
26-
const symbolt &symbol=ns.lookup(fun.first);
27-
out << symbol.display_name() << " /* " << symbol.name << " */\n";
28-
fun.second.body.output(ns, symbol.name, out);
29-
30-
out << std::flush;
31-
}
32-
}
33-
}
16+
#include <algorithm>
3417

3518
void goto_functionst::compute_location_numbers()
3619
{
@@ -73,3 +56,44 @@ void goto_functionst::compute_loop_numbers()
7356
func.second.body.compute_loop_numbers();
7457
}
7558
}
59+
60+
/// returns a vector of the iterators in alphabetical order
61+
std::vector<goto_functionst::function_mapt::const_iterator>
62+
goto_functionst::sorted() const
63+
{
64+
std::vector<function_mapt::const_iterator> result;
65+
66+
result.reserve(function_map.size());
67+
68+
for(auto it = function_map.begin(); it != function_map.end(); it++)
69+
result.push_back(it);
70+
71+
std::sort(
72+
result.begin(),
73+
result.end(),
74+
[](function_mapt::const_iterator a, function_mapt::const_iterator b) {
75+
return id2string(a->first) < id2string(b->first);
76+
});
77+
78+
return result;
79+
}
80+
81+
/// returns a vector of the iterators in alphabetical order
82+
std::vector<goto_functionst::function_mapt::iterator> goto_functionst::sorted()
83+
{
84+
std::vector<function_mapt::iterator> result;
85+
86+
result.reserve(function_map.size());
87+
88+
for(auto it = function_map.begin(); it != function_map.end(); it++)
89+
result.push_back(it);
90+
91+
std::sort(
92+
result.begin(),
93+
result.end(),
94+
[](function_mapt::iterator a, function_mapt::iterator b) {
95+
return id2string(a->first) < id2string(b->first);
96+
});
97+
98+
return result;
99+
}

src/goto-programs/goto_functions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class goto_functionst
7272
function_map.clear();
7373
}
7474

75-
void output(
76-
const namespacet &ns,
77-
std::ostream &out) const;
78-
7975
void compute_location_numbers();
8076
void compute_location_numbers(goto_programt &);
8177
void compute_loop_numbers();
@@ -118,6 +114,9 @@ class goto_functionst
118114
for(const auto &fun : other.function_map)
119115
function_map[fun.first].copy_from(fun.second);
120116
}
117+
118+
std::vector<function_mapt::const_iterator> sorted() const;
119+
std::vector<function_mapt::iterator> sorted();
121120
};
122121

123122
#define Forall_goto_functions(it, functions) \

src/goto-programs/goto_model.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ class goto_modelt : public abstract_goto_modelt
3737
goto_functions.clear();
3838
}
3939

40-
void output(std::ostream &out) const
41-
{
42-
namespacet ns(symbol_table);
43-
goto_functions.output(ns, out);
44-
}
45-
4640
goto_modelt()
4741
{
4842
}

src/goto-programs/show_goto_functions.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Author: Peter Schrammel
1111

1212
#include "show_goto_functions.h"
1313

14-
#include <iostream>
15-
1614
#include <util/xml.h>
1715
#include <util/json.h>
1816
#include <util/json_expr.h>
@@ -52,24 +50,32 @@ void show_goto_functions(
5250
break;
5351

5452
case ui_message_handlert::uit::PLAIN:
55-
if(list_only)
5653
{
57-
for(const auto &fun : goto_functions.function_map)
54+
// sort alphabetically
55+
const auto sorted = goto_functions.sorted();
56+
57+
for(const auto &fun : sorted)
5858
{
59-
const symbolt &symbol = ns.lookup(fun.first);
60-
msg.status() << '\n'
61-
<< symbol.display_name() << " /* " << symbol.name
62-
<< (fun.second.body_available() ? ""
63-
: ", body not available")
64-
<< " */";
65-
}
59+
const symbolt &symbol = ns.lookup(fun->first);
60+
const bool has_body = fun->second.body_available();
6661

67-
msg.status() << messaget::eom;
68-
}
69-
else
70-
{
71-
goto_functions.output(ns, msg.status());
72-
msg.status() << messaget::eom;
62+
if(list_only)
63+
{
64+
msg.status() << '\n'
65+
<< symbol.display_name() << " /* " << symbol.name
66+
<< (has_body ? "" : ", body not available") << " */";
67+
msg.status() << messaget::eom;
68+
}
69+
else if(has_body)
70+
{
71+
msg.status() << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
72+
73+
msg.status() << messaget::bold << symbol.display_name()
74+
<< messaget::reset << " /* " << symbol.name << " */\n";
75+
fun->second.body.output(ns, symbol.name, msg.status());
76+
msg.status() << messaget::eom;
77+
}
78+
}
7379
}
7480

7581
break;

src/goto-programs/show_goto_functions_json.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ json_objectt show_goto_functions_jsont::convert(
4141
{
4242
json_arrayt json_functions;
4343
const json_irept no_comments_irep_converter(false);
44-
for(const auto &function_entry : goto_functions.function_map)
44+
45+
const auto sorted = goto_functions.sorted();
46+
47+
for(const auto &function_entry : sorted)
4548
{
46-
const irep_idt &function_name=function_entry.first;
47-
const goto_functionst::goto_functiont &function=function_entry.second;
49+
const irep_idt &function_name = function_entry->first;
50+
const goto_functionst::goto_functiont &function = function_entry->second;
4851

4952
json_objectt &json_function=
5053
json_functions.push_back(jsont()).make_object();

src/goto-programs/show_goto_functions_xml.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ xmlt show_goto_functions_xmlt::convert(
4343
const goto_functionst &goto_functions)
4444
{
4545
xmlt xml_functions=xmlt("functions");
46-
for(const auto &function_entry : goto_functions.function_map)
46+
47+
const auto sorted = goto_functions.sorted();
48+
49+
for(const auto &function_entry : sorted)
4750
{
48-
const irep_idt &function_name=function_entry.first;
49-
const goto_functionst::goto_functiont &function=function_entry.second;
51+
const irep_idt &function_name = function_entry->first;
52+
const goto_functionst::goto_functiont &function = function_entry->second;
5053

5154
xmlt &xml_function=xml_functions.new_element("function");
5255
xml_function.set_attribute("name", id2string(function_name));

0 commit comments

Comments
 (0)