Skip to content

Commit 3d30a80

Browse files
authored
Merge pull request #4 from hannes-steffenhagen-diffblue/ae_sharing_map_rebase
Use sharing_mapt for abstract environment
2 parents ada033c + 33f4480 commit 3d30a80

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

src/analyses/variable-sensitivity/abstract_enviroment.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ abstract_object_pointert abstract_environmentt::eval(
5252
if(simplified_id==ID_symbol)
5353
{
5454
const symbol_exprt &symbol(to_symbol_expr(simplified_expr));
55-
const auto &symbol_entry=map.find(symbol);
56-
if(symbol_entry==map.cend())
55+
const auto &symbol_entry=map.const_find(symbol);
56+
if(!symbol_entry.second)
5757
{
5858
return abstract_object_factory(simplified_expr.type(), ns, true);
5959
}
6060
else
6161
{
62-
abstract_object_pointert found_symbol_value=symbol_entry->second;
62+
abstract_object_pointert found_symbol_value=symbol_entry.first;
6363
return found_symbol_value;
6464
}
6565
}
@@ -191,7 +191,7 @@ bool abstract_environmentt::assign(
191191
{
192192
INVARIANT(s.id()==ID_symbol, "Have a symbol or a stack");
193193
const symbol_exprt &symbol_expr(to_symbol_expr(s));
194-
if(map.find(symbol_expr)==map.end())
194+
if(!map.has_key(symbol_expr))
195195
{
196196
lhs_value=abstract_object_factory(
197197
symbol_expr.type(), ns, true, false);
@@ -486,9 +486,9 @@ bool abstract_environmentt::merge(const abstract_environmentt &env)
486486
// For each element in the intersection of map and env.map merge
487487
// If the result of the merge is top, remove from the map
488488
bool modified=false;
489-
for(const auto &entry : env.map)
489+
for(const auto &entry : env.map.get_view())
490490
{
491-
if(map.find(entry.first)!=map.end())
491+
if(map.has_key(entry.first))
492492
{
493493
bool object_modified=false;
494494
abstract_object_pointert new_object=
@@ -629,10 +629,10 @@ void abstract_environmentt::output(
629629
{
630630
out << "{\n";
631631

632-
for(const auto &entry : map)
632+
for(const auto &entry : map.get_view())
633633
{
634634
out << entry.first.get_identifier()
635-
<< " (" << ") -> ";
635+
<< " () -> ";
636636
entry.second->output(out, ai, ns);
637637
out << "\n";
638638
}
@@ -653,9 +653,9 @@ Function: abstract_environmentt::verify
653653

654654
bool abstract_environmentt::verify() const
655655
{
656-
for(const auto &entry : map)
656+
for(const auto &entry : map.get_view())
657657
{
658-
if(!entry.second)
658+
if(entry.second == nullptr)
659659
{
660660
return false;
661661
}
@@ -715,21 +715,21 @@ std::vector<symbol_exprt> abstract_environmentt::modified_symbols(
715715
{
716716
// Find all symbols who have different write locations in each map
717717
std::vector<symbol_exprt> symbols_diff;
718-
for (const auto &entry : first.map)
718+
for (const auto &entry : first.map.get_view())
719719
{
720-
const auto &second_entry = second.map.find(entry.first);
721-
if (second_entry != second.map.end())
720+
const auto second_entry = second.map.const_find(entry.first);
721+
if (second_entry.second)
722722
{
723-
if(second_entry->second->has_been_modified(entry.second))
723+
if(second_entry.first->has_been_modified(entry.second))
724724
symbols_diff.push_back(entry.first);
725725
}
726726
}
727727

728728
// Add any symbols that are only in the second map
729-
for(const auto &entry : second.map)
729+
for(const auto &entry : second.map.get_view())
730730
{
731-
const auto &second_entry = first.map.find(entry.first);
732-
if (second_entry==first.map.end())
731+
const auto &second_entry = first.map.const_find(entry.first);
732+
if (!second_entry.second)
733733
{
734734
symbols_diff.push_back(entry.first);
735735
}

src/analyses/variable-sensitivity/abstract_enviroment.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <util/std_expr.h>
1919
#include <util/message.h>
2020
#include <analyses/variable-sensitivity/abstract_object.h>
21+
#include <util/sharing_map.h>
2122

2223
class abstract_environmentt
2324
{
@@ -80,7 +81,7 @@ class abstract_environmentt
8081
const exprt &e, const namespacet &ns) const;
8182

8283
typedef symbol_exprt map_keyt;
83-
std::map<map_keyt, abstract_object_pointert> map;
84+
sharing_mapt<map_keyt, abstract_object_pointert> map;
8485

8586
private:
8687
abstract_object_pointert abstract_object_factory(

src/util/sharing_map.h

+11
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ class sharing_mapt
128128

129129
const_find_type find(const key_type &k) const;
130130

131+
const_find_type const_find(const key_type &k) const
132+
{
133+
return find(k);
134+
}
135+
131136
mapped_type &at(
132137
const key_type &k,
133138
const tvt &key_exists=tvt::unknown());
@@ -197,6 +202,12 @@ class sharing_mapt
197202
typedef std::vector<delta_view_itemt> delta_viewt;
198203

199204
void get_view(viewt &view) const;
205+
viewt get_view() const
206+
{
207+
viewt result;
208+
get_view(result);
209+
return result;
210+
}
200211

201212
void get_delta_view(
202213
const self_type &other,

src/util/std_expr.h

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ class symbol_exprt:public exprt
135135
}
136136
};
137137

138+
namespace std {
139+
template<> struct hash<::symbol_exprt>
140+
{
141+
size_t operator()(const ::symbol_exprt& sym)
142+
{
143+
return irep_id_hash()(sym.get_identifier());
144+
}
145+
};
146+
}
147+
138148
/*! \brief Expression to hold a symbol (variable)
139149
*/
140150
class decorated_symbol_exprt:public symbol_exprt

0 commit comments

Comments
 (0)