Skip to content

Commit eac449d

Browse files
authored
Merge pull request #4342 from tautschnig/cleanup-add_object
Simplify the interface to goto_symex_statet::add_object
2 parents 9a8dab9 + aa7207c commit eac449d

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,14 +773,16 @@ void goto_symex_statet::print_backtrace(std::ostream &out) const
773773
}
774774
}
775775

776-
void goto_symex_statet::add_object(
777-
ssa_exprt &ssa,
778-
std::size_t l1_index,
776+
ssa_exprt goto_symex_statet::add_object(
777+
const symbol_exprt &expr,
778+
std::function<std::size_t(const irep_idt &)> index_generator,
779779
const namespacet &ns)
780780
{
781781
framet &frame = call_stack().top();
782782

783+
ssa_exprt ssa = rename_ssa<L0>(ssa_exprt{expr}, ns);
783784
const irep_idt l0_name = ssa.get_identifier();
785+
const std::size_t l1_index = index_generator(l0_name);
784786

785787
// save old L1 name, if any
786788
auto existing_or_new_entry = level1.current_names.emplace(
@@ -797,4 +799,6 @@ void goto_symex_statet::add_object(
797799
ssa = rename_ssa<L1>(std::move(ssa), ns);
798800
const bool inserted = frame.local_objects.insert(ssa.get_identifier()).second;
799801
INVARIANT(inserted, "l1_name expected to be unique by construction");
802+
803+
return ssa;
800804
}

src/goto-symex/goto_symex_state.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_GOTO_SYMEX_GOTO_SYMEX_STATE_H
1313
#define CPROVER_GOTO_SYMEX_GOTO_SYMEX_STATE_H
1414

15+
#include <functional>
1516
#include <memory>
1617
#include <unordered_set>
1718

@@ -140,10 +141,16 @@ class goto_symex_statet final : public goto_statet
140141
return threads[source.thread_nr].call_stack;
141142
}
142143

143-
/// Create a new instance of the L0-renamed object \p ssa. As part of this,
144-
/// turn \p ssa into an L1-renamed SSA expression. When doing so, use
145-
/// \p l1_index as the L1 index, which must not previously have been used.
146-
void add_object(ssa_exprt &ssa, std::size_t l1_index, const namespacet &ns);
144+
/// Instantiate the object \p expr. An instance of an object is an L1-renamed
145+
/// SSA expression such that its L1-index has not previously been used.
146+
/// \param expr: Symbol to be instantiated
147+
/// \param index_generator: A function to produce a new index for a given name
148+
/// \param ns: A namespace
149+
/// \return L1-renamed SSA expression
150+
ssa_exprt add_object(
151+
const symbol_exprt &expr,
152+
std::function<std::size_t(const irep_idt &)> index_generator,
153+
const namespacet &ns);
147154

148155
void print_backtrace(std::ostream &) const;
149156

src/goto-symex/symex_decl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
3737
// each declaration introduces a new object, which we record as a fresh L1
3838
// index
3939

40-
ssa_exprt ssa = state.rename_ssa<L0>(ssa_exprt{expr}, ns);
4140
// We use "1" as the first level-1 index, which is in line with doing so for
4241
// level-2 indices (but it's an arbitrary choice, we have just always been
4342
// doing it this way).
44-
const std::size_t fresh_l1_index =
45-
path_storage.get_unique_index(ssa.get_identifier(), 1);
46-
state.add_object(ssa, fresh_l1_index, ns);
43+
ssa_exprt ssa = state.add_object(
44+
expr,
45+
[this](const irep_idt &l0_name) {
46+
return path_storage.get_unique_index(l0_name, 1);
47+
},
48+
ns);
4749
const irep_idt &l1_identifier = ssa.get_identifier();
4850

4951
// rename type to L2

src/goto-symex/symex_function_call.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,11 @@ static void locality(
399399

400400
for(const auto &param : goto_function.parameter_identifiers)
401401
{
402-
// get L0 name
403-
ssa_exprt ssa =
404-
state.rename_ssa<L0>(ssa_exprt{ns.lookup(param).symbol_expr()}, ns);
405-
406-
const std::size_t fresh_l1_index =
407-
path_storage.get_unique_index(ssa.get_identifier(), frame_nr);
408-
state.add_object(ssa, fresh_l1_index, ns);
402+
(void)state.add_object(
403+
ns.lookup(param).symbol_expr(),
404+
[&path_storage, &frame_nr](const irep_idt &l0_name) {
405+
return path_storage.get_unique_index(l0_name, frame_nr);
406+
},
407+
ns);
409408
}
410409
}

0 commit comments

Comments
 (0)