Skip to content

Commit e620dae

Browse files
committed
replace_symbolt: hide {expr,type}_map
Values should only be added via insert. Add expr_map access functions as some code still does access the expr_map.
1 parent 18d08bf commit e620dae

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ bool constant_propagator_domaint::valuest::is_constant(const exprt &expr) const
292292
return false;
293293

294294
if(expr.id()==ID_symbol)
295-
if(replace_const.expr_map.find(to_symbol_expr(expr).get_identifier())==
296-
replace_const.expr_map.end())
295+
if(!replace_const.replaces_symbol(to_symbol_expr(expr).get_identifier()))
297296
return false;
298297

299298
if(expr.id()==ID_index)
@@ -331,8 +330,7 @@ bool constant_propagator_domaint::valuest::is_constant_address_of(
331330
/// Do not call this when iterating over replace_const.expr_map!
332331
bool constant_propagator_domaint::valuest::set_to_top(const irep_idt &id)
333332
{
334-
replace_symbolt::expr_mapt::size_type n_erased=
335-
replace_const.expr_map.erase(id);
333+
const auto n_erased = replace_const.erase(id);
336334

337335
INVARIANT(n_erased==0 || !is_bottom, "bottom should have no elements at all");
338336

@@ -345,7 +343,7 @@ void constant_propagator_domaint::valuest::set_dirty_to_top(
345343
const namespacet &ns)
346344
{
347345
typedef replace_symbolt::expr_mapt expr_mapt;
348-
expr_mapt &expr_map=replace_const.expr_map;
346+
expr_mapt &expr_map = replace_const.get_expr_map();
349347

350348
for(expr_mapt::iterator it=expr_map.begin();
351349
it!=expr_map.end();)
@@ -371,19 +369,19 @@ void constant_propagator_domaint::valuest::output(
371369
if(is_bottom)
372370
{
373371
out << " bottom\n";
374-
DATA_INVARIANT(replace_const.expr_map.empty(),
372+
DATA_INVARIANT(is_empty(),
375373
"If the domain is bottom, the map must be empty");
376374
return;
377375
}
378376

379377
INVARIANT(!is_bottom, "Have handled bottom");
380-
if(replace_const.expr_map.empty())
378+
if(is_empty())
381379
{
382380
out << "top\n";
383381
return;
384382
}
385383

386-
for(const auto &p : replace_const.expr_map)
384+
for(const auto &p : replace_const.get_expr_map())
387385
{
388386
out << ' ' << p.first << "=" << from_expr(ns, p.first, p.second) << '\n';
389387
}
@@ -418,20 +416,21 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src)
418416

419417
bool changed=false;
420418

421-
replace_symbolt::expr_mapt &expr_map=replace_const.expr_map;
422-
const replace_symbolt::expr_mapt &src_expr_map=src.replace_const.expr_map;
423-
424419
// handle top
425-
if(src_expr_map.empty())
420+
if(src.is_empty())
426421
{
427422
// change if it was not top
428-
changed=!expr_map.empty();
423+
changed = !is_empty();
429424

430425
set_to_top();
431426

432427
return changed;
433428
}
434429

430+
replace_symbolt::expr_mapt &expr_map = replace_const.get_expr_map();
431+
const replace_symbolt::expr_mapt &src_expr_map =
432+
src.replace_const.get_expr_map();
433+
435434
// remove those that are
436435
// - different in src
437436
// - do not exist in src
@@ -476,12 +475,12 @@ bool constant_propagator_domaint::valuest::meet(const valuest &src)
476475

477476
bool changed=false;
478477

479-
for(const auto &m : src.replace_const.expr_map)
478+
for(const auto &m : src.replace_const.get_expr_map())
480479
{
481-
replace_symbolt::expr_mapt::iterator
482-
c_it=replace_const.expr_map.find(m.first);
480+
replace_symbolt::expr_mapt::const_iterator c_it =
481+
replace_const.get_expr_map().find(m.first);
483482

484-
if(c_it!=replace_const.expr_map.end())
483+
if(c_it != replace_const.get_expr_map().end())
485484
{
486485
if(c_it->second!=m.second)
487486
{

src/analyses/constant_propagator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class constant_propagator_domaint:public ai_domain_baset
108108

109109
void set_to(const irep_idt &lhs, const exprt &rhs)
110110
{
111-
replace_const.expr_map[lhs]=rhs;
111+
replace_const.get_expr_map()[lhs] = rhs;
112112
is_bottom=false;
113113
}
114114

@@ -132,7 +132,7 @@ class constant_propagator_domaint:public ai_domain_baset
132132

133133
bool is_empty() const
134134
{
135-
return replace_const.expr_map.empty();
135+
return replace_const.empty();
136136
}
137137

138138
void output(std::ostream &out, const namespacet &ns) const;

src/goto-programs/link_goto_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static bool link_functions(
140140
rename_symbols_in_function(dest_it->second, final_id, macro_application);
141141
}
142142

143-
if(!object_type_updates.expr_map.empty())
143+
if(!object_type_updates.empty())
144144
{
145145
Forall_goto_functions(dest_it, dest_functions)
146146
Forall_goto_program_instructions(iit, dest_it->second.body)

src/util/replace_symbol.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919

2020
#include <unordered_map>
2121

22+
/// Replace expression or type symbols by an expression or type, respectively.
2223
class replace_symbolt
2324
{
2425
public:
@@ -79,9 +80,31 @@ class replace_symbolt
7980
return expr_map.empty() && type_map.empty();
8081
}
8182

83+
std::size_t erase(const irep_idt &id)
84+
{
85+
return expr_map.erase(id) + type_map.erase(id);
86+
}
87+
88+
bool replaces_symbol(const irep_idt &id) const
89+
{
90+
return expr_map.find(id) != expr_map.end() ||
91+
type_map.find(id) != type_map.end();
92+
}
93+
8294
replace_symbolt();
8395
virtual ~replace_symbolt();
8496

97+
const expr_mapt &get_expr_map() const
98+
{
99+
return expr_map;
100+
}
101+
102+
expr_mapt &get_expr_map()
103+
{
104+
return expr_map;
105+
}
106+
107+
protected:
85108
expr_mapt expr_map;
86109
type_mapt type_map;
87110

0 commit comments

Comments
 (0)