File tree 5 files changed +65
-11
lines changed 5 files changed +65
-11
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ Date: June 2003
13
13
14
14
#include " goto_functions.h"
15
15
16
+ #include < algorithm>
17
+
16
18
void goto_functionst::compute_location_numbers ()
17
19
{
18
20
unused_location_number = 0 ;
@@ -54,3 +56,44 @@ void goto_functionst::compute_loop_numbers()
54
56
func.second .body .compute_loop_numbers ();
55
57
}
56
58
}
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
+ }
Original file line number Diff line number Diff line change @@ -114,6 +114,9 @@ class goto_functionst
114
114
for (const auto &fun : other.function_map )
115
115
function_map[fun.first ].copy_from (fun.second );
116
116
}
117
+
118
+ std::vector<function_mapt::const_iterator> sorted () const ;
119
+ std::vector<function_mapt::iterator> sorted ();
117
120
};
118
121
119
122
#define Forall_goto_functions (it, functions ) \
Original file line number Diff line number Diff line change @@ -51,10 +51,13 @@ void show_goto_functions(
51
51
52
52
case ui_message_handlert::uit::PLAIN:
53
53
{
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)
55
58
{
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 ();
58
61
59
62
if (list_only)
60
63
{
@@ -67,10 +70,9 @@ void show_goto_functions(
67
70
{
68
71
msg.status () << " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n " ;
69
72
70
- const symbolt &symbol = ns.lookup (fun.first );
71
73
msg.status () << messaget::bold << symbol.display_name ()
72
74
<< 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 ());
74
76
msg.status () << messaget::eom;
75
77
}
76
78
}
Original file line number Diff line number Diff line change @@ -41,10 +41,13 @@ json_objectt show_goto_functions_jsont::convert(
41
41
{
42
42
json_arrayt json_functions;
43
43
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)
45
48
{
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 ;
48
51
49
52
json_objectt &json_function=
50
53
json_functions.push_back (jsont ()).make_object ();
Original file line number Diff line number Diff line change @@ -43,10 +43,13 @@ xmlt show_goto_functions_xmlt::convert(
43
43
const goto_functionst &goto_functions)
44
44
{
45
45
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)
47
50
{
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 ;
50
53
51
54
xmlt &xml_function=xml_functions.new_element (" function" );
52
55
xml_function.set_attribute (" name" , id2string (function_name));
You can’t perform that action at this time.
0 commit comments