Skip to content

Commit 6bc86e1

Browse files
authored
Merge pull request diffblue#222 from diffblue/feature/lexicographical_ordered_dump_of_functions_and_symbols
SEC-41 : Added lexicographical order to textual dump of functions and symbols.
2 parents a73ee46 + 56b0b26 commit 6bc86e1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/goto-programs/goto_functions_template.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: June 2003
1616

1717
#include <ostream>
1818
#include <cassert>
19+
#include <algorithm>
1920

2021
#include <util/std_types.h>
2122
#include <util/symbol.h>
@@ -166,8 +167,18 @@ void goto_functions_templatet<bodyT>::output(
166167
const namespacet &ns,
167168
std::ostream &out) const
168169
{
170+
std::vector<irep_idt> sorted_names;
171+
sorted_names.reserve(function_map.size());
169172
for(const auto &fun : function_map)
170-
{
173+
sorted_names.push_back(fun.first);
174+
std::sort(
175+
sorted_names.begin(),
176+
sorted_names.end(),
177+
[](const irep_idt &a, const irep_idt &b)
178+
{ return as_string(a)<as_string(b); });
179+
for(const auto &name : sorted_names)
180+
{
181+
const auto &fun=*function_map.find(name);
171182
if(fun.second.body_available())
172183
{
173184
out << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n";

src/util/symbol_table.cpp

+12-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

@@ -80,10 +81,18 @@ bool symbol_tablet::remove(const irep_idt &name)
8081
/// \param out: The ostream to direct output to
8182
void symbol_tablet::show(std::ostream &out) const
8283
{
84+
std::vector<irep_idt> sorted_names;
85+
sorted_names.reserve(symbols.size());
86+
for(const auto &elem : symbols)
87+
sorted_names.push_back(elem.first);
88+
std::sort(
89+
sorted_names.begin(),
90+
sorted_names.end(),
91+
[](const irep_idt &a, const irep_idt &b)
92+
{ return as_string(a)<as_string(b); });
8393
out << "\n" << "Symbols:" << "\n";
84-
85-
forall_symbols(it, symbols)
86-
out << it->second;
94+
for(const auto &name : sorted_names)
95+
out << symbols.at(name);
8796
}
8897

8998
/// Print the contents of the symbol table

0 commit comments

Comments
 (0)