Skip to content

Commit 75a09b5

Browse files
Replace nondet_count by a functor
1 parent 17b87d3 commit 75a09b5

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/goto-symex/goto_symex.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/simplify_expr.h>
1515

16-
unsigned goto_symext::nondet_count=0;
1716
unsigned goto_symext::dynamic_counter=0;
1817

1918
void goto_symext::do_simplify(exprt &expr)
@@ -22,7 +21,7 @@ void goto_symext::do_simplify(exprt &expr)
2221
simplify(expr, ns);
2322
}
2423

25-
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count)
24+
nondet_symbol_exprt symex_nondet_generatort::operator()(typet &type)
2625
{
2726
irep_idt identifier = "symex::nondet" + std::to_string(nondet_count++);
2827
nondet_symbol_exprt new_expr(identifier, type);

src/goto-symex/goto_symex.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ class namespacet;
3838
class side_effect_exprt;
3939
class typecast_exprt;
4040

41+
/// Functor generating fresh nondet symbols
42+
class symex_nondet_generatort
43+
{
44+
public:
45+
nondet_symbol_exprt operator()(typet &type);
46+
47+
private:
48+
unsigned nondet_count = 0;
49+
};
50+
4151
/// \brief The main class for the forward symbolic simulator
4252
///
4353
/// Higher-level architectural information on symbolic execution is
@@ -399,7 +409,7 @@ class goto_symext
399409
virtual void symex_input(statet &, const codet &);
400410
virtual void symex_output(statet &, const codet &);
401411

402-
static unsigned nondet_count;
412+
symex_nondet_generatort build_symex_nondet;
403413
static unsigned dynamic_counter;
404414

405415
void rewrite_quantifiers(exprt &, statet &);
@@ -449,8 +459,6 @@ class goto_symext
449459
}
450460
};
451461

452-
nondet_symbol_exprt build_symex_nondet(typet &type, unsigned &nondet_count);
453-
454462
void symex_transition(goto_symext::statet &state);
455463

456464
void symex_transition(

src/goto-symex/symex_clean_expr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,26 @@ static void adjust_byte_extract_rec(exprt &expr, const namespacet &ns)
135135
}
136136
}
137137

138-
static void replace_nondet(exprt &expr, unsigned &nondet_count)
138+
static void
139+
replace_nondet(exprt &expr, symex_nondet_generatort &build_symex_nondet)
139140
{
140141
if(expr.id() == ID_side_effect && expr.get(ID_statement) == ID_nondet)
141142
{
142-
nondet_symbol_exprt new_expr =
143-
build_symex_nondet(expr.type(), nondet_count);
143+
nondet_symbol_exprt new_expr = build_symex_nondet(expr.type());
144144
new_expr.add_source_location() = expr.source_location();
145145
expr.swap(new_expr);
146146
}
147147
else
148148
Forall_operands(it, expr)
149-
replace_nondet(*it, nondet_count);
149+
replace_nondet(*it, build_symex_nondet);
150150
}
151151

152152
void goto_symext::clean_expr(
153153
exprt &expr,
154154
statet &state,
155155
const bool write)
156156
{
157-
replace_nondet(expr, nondet_count);
157+
replace_nondet(expr, build_symex_nondet);
158158
dereference(expr, state, write);
159159

160160
// make sure all remaining byte extract operations use the root

0 commit comments

Comments
 (0)