File tree Expand file tree Collapse file tree 3 files changed +19
-14
lines changed Expand file tree Collapse file tree 3 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -70,17 +70,10 @@ void show_symbol_table_plain(
70
70
{
71
71
out << ' \n ' << " Symbols:" << ' \n ' << ' \n ' ;
72
72
73
- // we want to sort alphabetically
74
- std::vector<std::string> symbols;
75
- symbols.reserve (symbol_table.symbols .size ());
76
-
77
- for (const auto &symbol_pair : symbol_table.symbols )
78
- symbols.push_back (id2string (symbol_pair.first ));
79
- std::sort (symbols.begin (), symbols.end ());
80
-
81
73
const namespacet ns (symbol_table);
82
74
83
- for (const irep_idt &id : symbols)
75
+ // we want to sort alphabetically
76
+ for (const irep_idt &id : symbol_table.sorted_symbol_names ())
84
77
{
85
78
const symbolt &symbol=ns.lookup (id);
86
79
Original file line number Diff line number Diff line change @@ -33,22 +33,30 @@ bool symbol_table_baset::remove(const irep_idt &name)
33
33
return false ;
34
34
}
35
35
36
- // / Print the contents of the symbol table.
37
- // / \param out: The ostream to direct output to.
38
- void symbol_table_baset::show (std::ostream &out) const
36
+ std::vector<irep_idt> symbol_table_baset::sorted_symbol_names () const
39
37
{
40
38
std::vector<irep_idt> sorted_names;
41
39
sorted_names.reserve (symbols.size ());
40
+
42
41
for (const auto &elem : symbols)
43
42
sorted_names.push_back (elem.first );
43
+
44
44
std::sort (
45
45
sorted_names.begin (),
46
46
sorted_names.end (),
47
- [](const irep_idt &a, const irep_idt &b) { return a.compare (b); });
47
+ [](const irep_idt &a, const irep_idt &b) { return a.compare (b) < 0 ; });
48
+
49
+ return sorted_names;
50
+ }
51
+
52
+ // / Print the contents of the symbol table.
53
+ // / \param out: The ostream to direct output to.
54
+ void symbol_table_baset::show (std::ostream &out) const
55
+ {
48
56
out << " \n "
49
57
<< " Symbols:"
50
58
<< " \n " ;
51
- for (const auto &name : sorted_names )
59
+ for (const auto &name : sorted_symbol_names () )
52
60
out << symbols.at (name);
53
61
}
54
62
Original file line number Diff line number Diff line change @@ -136,6 +136,10 @@ class symbol_table_baset
136
136
137
137
void show (std::ostream &out) const ;
138
138
139
+ // / Build and return a lexicographically sorted vector of symbol names from
140
+ // / all symbols stored in this symbol table.
141
+ std::vector<irep_idt> sorted_symbol_names () const ;
142
+
139
143
class iteratort
140
144
{
141
145
private:
You can’t perform that action at this time.
0 commit comments