Skip to content

Commit cdbac8c

Browse files
Sort output of symbol_tablet::show
1 parent 2ef1c94 commit cdbac8c

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/util/symbol_table.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "symbol_table.h"
44

55
#include <ostream>
6+
#include <algorithm>
67
#include <util/invariant.h>
78

89
/// Add a new symbol to the symbol table
@@ -142,10 +143,20 @@ void symbol_tablet::erase(const symbolst::const_iterator &entry)
142143
/// \param out: The ostream to direct output to
143144
void symbol_tablet::show(std::ostream &out) const
144145
{
146+
std::vector<irep_idt> sorted_names;
147+
sorted_names.reserve(symbols.size());
148+
for(const auto &elem : symbols)
149+
sorted_names.push_back(elem.first);
150+
std::sort(
151+
sorted_names.begin(),
152+
sorted_names.end(),
153+
[](const irep_idt &a, const irep_idt &b)
154+
{
155+
return as_string(a) < as_string(b);
156+
});
145157
out << "\n" << "Symbols:" << "\n";
146-
147-
forall_symbols(it, symbols)
148-
out << it->second;
158+
for(const auto &name : sorted_names)
159+
out << symbols.at(name);
149160
}
150161

151162
/// Print the contents of the symbol table

0 commit comments

Comments
 (0)