Skip to content

Commit d8f00f0

Browse files
committed
show_goto_functions: sort alphabetically
1 parent 5841c2a commit d8f00f0

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

src/goto-programs/goto_functions.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,44 @@ void goto_functionst::compute_loop_numbers()
7373
func.second.body.compute_loop_numbers();
7474
}
7575
}
76+
77+
/// returns a vector of the iterators in alphabetical order
78+
std::vector<goto_functionst::function_mapt::const_iterator>
79+
goto_functionst::sorted() const
80+
{
81+
std::vector<function_mapt::const_iterator> result;
82+
83+
result.reserve(function_map.size());
84+
85+
for(auto it = function_map.begin(); it != function_map.end(); it++)
86+
result.push_back(it);
87+
88+
std::sort(
89+
result.begin(),
90+
result.end(),
91+
[](function_mapt::const_iterator a, function_mapt::const_iterator b) {
92+
return id2string(a->first) < id2string(b->first);
93+
});
94+
95+
return result;
96+
}
97+
98+
/// returns a vector of the iterators in alphabetical order
99+
std::vector<goto_functionst::function_mapt::iterator> goto_functionst::sorted()
100+
{
101+
std::vector<function_mapt::iterator> result;
102+
103+
result.reserve(function_map.size());
104+
105+
for(auto it = function_map.begin(); it != function_map.end(); it++)
106+
result.push_back(it);
107+
108+
std::sort(
109+
result.begin(),
110+
result.end(),
111+
[](function_mapt::iterator a, function_mapt::iterator b) {
112+
return id2string(a->first) < id2string(b->first);
113+
});
114+
115+
return result;
116+
}

src/goto-programs/goto_functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class goto_functionst
118118
for(const auto &fun : other.function_map)
119119
function_map[fun.first].copy_from(fun.second);
120120
}
121+
122+
std::vector<function_mapt::const_iterator> sorted() const;
123+
std::vector<function_mapt::iterator> sorted();
121124
};
122125

123126
#define Forall_goto_functions(it, functions) \

src/goto-programs/show_goto_functions.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ void show_goto_functions(
5151

5252
case ui_message_handlert::uit::PLAIN:
5353
{
54-
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)
5558
{
56-
const symbolt &symbol = ns.lookup(fun.first);
57-
const bool has_body = fun.second.body_available();
59+
const symbolt &symbol = ns.lookup(fun->first);
60+
const bool has_body = fun->second.body_available();
5861

5962
if(list_only)
6063
{
@@ -67,10 +70,9 @@ void show_goto_functions(
6770
{
6871
msg.status() << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";
6972

70-
const symbolt &symbol = ns.lookup(fun.first);
7173
msg.status() << messaget::bold << symbol.display_name()
7274
<< messaget::reset << " /* " << symbol.name << " */\n";
73-
fun.second.body.output(ns, symbol.name, msg.status());
75+
fun->second.body.output(ns, symbol.name, msg.status());
7476
msg.status() << messaget::eom;
7577
}
7678
}

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)