Skip to content

Commit 323de35

Browse files
committed
Make boolbv_mapt::get_literals return a bvt
This avoids callers creating a bvt just so that get_literals can copy its own bvt into the caller's bvt.
1 parent e055247 commit 323de35

File tree

5 files changed

+13
-22
lines changed

5 files changed

+13
-22
lines changed

src/solvers/flattening/boolbv.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,10 @@ bvt boolbvt::convert_symbol(const exprt &expr)
377377
const typet &type=expr.type();
378378
std::size_t width=boolbv_width(type);
379379

380-
bvt bv;
381-
bv.resize(width);
382-
383380
const irep_idt &identifier = expr.get(ID_identifier);
384381
CHECK_RETURN(!identifier.empty());
385382

386-
map.get_literals(identifier, type, bv);
383+
bvt bv = map.get_literals(identifier, type, width);
387384

388385
INVARIANT_WITH_DIAGNOSTICS(
389386
std::all_of(

src/solvers/flattening/boolbv_index.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ bvt boolbvt::convert_index(const index_exprt &expr)
5757
final_array.id() == ID_symbol || final_array.id() == ID_nondet_symbol)
5858
{
5959
std::size_t width = boolbv_width(array_type);
60-
bvt unused(width);
61-
map.get_literals(final_array.get(ID_identifier), array_type, unused);
60+
(void)map.get_literals(
61+
final_array.get(ID_identifier), array_type, width);
6262
}
6363

6464
// make sure we have the index in the cache
@@ -77,8 +77,7 @@ bvt boolbvt::convert_index(const index_exprt &expr)
7777
if(array.id() == ID_symbol || array.id() == ID_nondet_symbol)
7878
{
7979
std::size_t width = boolbv_width(array_type);
80-
bvt unused(width);
81-
map.get_literals(array.get(ID_identifier), array_type, unused);
80+
(void)map.get_literals(array.get(ID_identifier), array_type, width);
8281
}
8382

8483
// make sure we have the index in the cache

src/solvers/flattening/boolbv_map.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ void boolbv_mapt::show(std::ostream &out) const
3838
out << pair.first << "=" << pair.second.get_value(prop) << '\n';
3939
}
4040

41-
void boolbv_mapt::get_literals(
41+
const bvt &boolbv_mapt::get_literals(
4242
const irep_idt &identifier,
4343
const typet &type,
44-
bvt &literals)
44+
std::size_t width)
4545
{
4646
std::pair<mappingt::iterator, bool> result=
4747
mapping.insert(std::pair<irep_idt, map_entryt>(
@@ -52,9 +52,9 @@ void boolbv_mapt::get_literals(
5252
if(result.second)
5353
{ // actually inserted
5454
map_entry.type=type;
55-
map_entry.literal_map.reserve(literals.size());
55+
map_entry.literal_map.reserve(width);
5656

57-
for(std::size_t bit = 0; bit < literals.size(); ++bit)
57+
for(std::size_t bit = 0; bit < width; ++bit)
5858
{
5959
map_entry.literal_map.push_back(prop.new_variable());
6060

@@ -66,10 +66,10 @@ void boolbv_mapt::get_literals(
6666
}
6767

6868
INVARIANT(
69-
map_entry.literal_map.size() == literals.size(),
69+
map_entry.literal_map.size() == width,
7070
"number of literals in the literal map shall equal the bitvector width");
7171

72-
literals = map_entry.literal_map;
72+
return map_entry.literal_map;
7373
}
7474

7575
void boolbv_mapt::set_literals(

src/solvers/flattening/boolbv_map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class boolbv_mapt
3737

3838
void show(std::ostream &out) const;
3939

40-
void get_literals(
40+
const bvt &get_literals(
4141
const irep_idt &identifier,
4242
const typet &type,
43-
bvt &literals);
43+
std::size_t width);
4444

4545
void set_literals(
4646
const irep_idt &identifier,

src/solvers/flattening/bv_pointers.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,7 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
231231
const irep_idt &identifier=to_symbol_expr(expr).get_identifier();
232232
const typet &type=expr.type();
233233

234-
bvt bv;
235-
bv.resize(bits);
236-
237-
map.get_literals(identifier, type, bv);
238-
239-
return bv;
234+
return map.get_literals(identifier, type, bits);
240235
}
241236
else if(expr.id()==ID_nondet_symbol)
242237
{

0 commit comments

Comments
 (0)