Skip to content

Commit 33f4480

Browse files
Use sharing_mapt for abstract environment
1 parent 8cce1c5 commit 33f4480

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);
@@ -483,9 +483,9 @@ bool abstract_environmentt::merge(const abstract_environmentt &env)
483483
// For each element in the intersection of map and env.map merge
484484
// If the result of the merge is top, remove from the map
485485
bool modified=false;
486-
for(const auto &entry : env.map)
486+
for(const auto &entry : env.map.get_view())
487487
{
488-
if(map.find(entry.first)!=map.end())
488+
if(map.has_key(entry.first))
489489
{
490490
bool object_modified=false;
491491
abstract_object_pointert new_object=
@@ -626,10 +626,10 @@ void abstract_environmentt::output(
626626
{
627627
out << "{\n";
628628

629-
for(const auto &entry : map)
629+
for(const auto &entry : map.get_view())
630630
{
631631
out << entry.first.get_identifier()
632-
<< " (" << ") -> ";
632+
<< " () -> ";
633633
entry.second->output(out, ai, ns);
634634
out << "\n";
635635
}
@@ -650,9 +650,9 @@ Function: abstract_environmentt::verify
650650

651651
bool abstract_environmentt::verify() const
652652
{
653-
for(const auto &entry : map)
653+
for(const auto &entry : map.get_view())
654654
{
655-
if(!entry.second)
655+
if(entry.second == nullptr)
656656
{
657657
return false;
658658
}
@@ -712,21 +712,21 @@ std::vector<symbol_exprt> abstract_environmentt::modified_symbols(
712712
{
713713
// Find all symbols who have different write locations in each map
714714
std::vector<symbol_exprt> symbols_diff;
715-
for (const auto &entry : first.map)
715+
for (const auto &entry : first.map.get_view())
716716
{
717-
const auto &second_entry = second.map.find(entry.first);
718-
if (second_entry != second.map.end())
717+
const auto second_entry = second.map.const_find(entry.first);
718+
if (second_entry.second)
719719
{
720-
if(second_entry->second->has_been_modified(entry.second))
720+
if(second_entry.first->has_been_modified(entry.second))
721721
symbols_diff.push_back(entry.first);
722722
}
723723
}
724724

725725
// Add any symbols that are only in the second map
726-
for(const auto &entry : second.map)
726+
for(const auto &entry : second.map.get_view())
727727
{
728-
const auto &second_entry = first.map.find(entry.first);
729-
if (second_entry==first.map.end())
728+
const auto &second_entry = first.map.const_find(entry.first);
729+
if (!second_entry.second)
730730
{
731731
symbols_diff.push_back(entry.first);
732732
}

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)