Skip to content

Commit 22df291

Browse files
author
Daniel Kroening
committed
cleanup array theory solver
1 parent 71e973c commit 22df291

File tree

2 files changed

+50
-136
lines changed

2 files changed

+50
-136
lines changed

src/solvers/flattening/arrays.cpp

Lines changed: 50 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ void arrayst::collect_arrays(const exprt &a)
123123
collect_arrays(a.op0());
124124

125125
// make sure this shows as an application
126-
index_exprt index_expr;
127-
index_expr.type()=array_type.subtype();
128-
index_expr.array()=a.op0();
129-
index_expr.index()=a.op1();
126+
index_exprt index_expr(a.op0(), a.op1(), array_type.subtype());
130127
record_array_index(index_expr);
131128
}
132129
else if(a.id()==ID_update) // TODO: is this obsolete?
@@ -146,10 +143,7 @@ void arrayst::collect_arrays(const exprt &a)
146143

147144
#if 0
148145
// make sure this shows as an application
149-
index_exprt index_expr;
150-
index_expr.type()=array_type.subtype();
151-
index_expr.array()=a.op0();
152-
index_expr.index()=a.op1();
146+
index_exprt index_expr(a.op0(), a.op1(), array_type.subtype());
153147
record_array_index(index_expr);
154148
#endif
155149
}
@@ -273,14 +267,11 @@ void arrayst::add_array_constraints()
273267
}
274268

275269
// add constraints for equalities
276-
for(array_equalitiest::const_iterator it=
277-
array_equalities.begin();
278-
it!=array_equalities.end();
279-
it++)
270+
for(const auto &equality : array_equalities)
280271
{
281-
add_array_constraints(
282-
index_map[arrays.find_number(it->f1)],
283-
*it);
272+
add_array_constraints_equality(
273+
index_map[arrays.find_number(equality.f1)],
274+
equality);
284275

285276
// update_index_map should not be necessary here
286277
}
@@ -334,10 +325,8 @@ void arrayst::add_array_Ackermann_constraints()
334325

335326
if(indices_equal_lit!=const_literal(false))
336327
{
337-
index_exprt index_expr1;
338-
index_expr1.type()=ns.follow(arrays[i].type()).subtype();
339-
index_expr1.array()=arrays[i];
340-
index_expr1.index()=*i1;
328+
const typet &subtype=ns.follow(arrays[i].type()).subtype();
329+
index_exprt index_expr1(arrays[i], *i1, subtype);
341330

342331
index_exprt index_expr2=index_expr1;
343332
index_expr2.index()=*i2;
@@ -388,52 +377,39 @@ void arrayst::update_index_map(bool update_all)
388377
}
389378
else
390379
{
391-
for(std::set<std::size_t>::const_iterator
392-
it=update_indices.begin();
393-
it!=update_indices.end(); it++)
394-
update_index_map(*it);
380+
for(const auto &index : update_indices)
381+
update_index_map(index);
382+
395383
update_indices.clear();
396384
}
397385

398386
#ifdef DEBUG
399387
// print index sets
400-
for(index_mapt::const_iterator
401-
i1=index_map.begin();
402-
i1!=index_map.end();
403-
i1++)
404-
for(index_sett::const_iterator
405-
i2=i1->second.begin();
406-
i2!=i1->second.end();
407-
i2++)
408-
std::cout << "Index set (" << i1->first << " = "
409-
<< arrays.find_number(i1->first) << " = "
410-
<< from_expr(ns, "", arrays[arrays.find_number(i1->first)])
388+
for(const auto &index_entry : index_map)
389+
for(const auto &index : index_entry.second)
390+
std::cout << "Index set (" << index_entry.first << " = "
391+
<< arrays.find_number(index_entry.first) << " = "
392+
<< from_expr(ns, "",
393+
arrays[arrays.find_number(index_entry.first)])
411394
<< "): "
412-
<< from_expr(ns, "", *i2) << '\n';
395+
<< from_expr(ns, "", index) << '\n';
413396
std::cout << "-----\n";
414397
#endif
415398
}
416399

417-
void arrayst::add_array_constraints(
400+
void arrayst::add_array_constraints_equality(
418401
const index_sett &index_set,
419402
const array_equalityt &array_equality)
420403
{
421404
// add constraints x=y => x[i]=y[i]
422405

423-
for(index_sett::const_iterator
424-
it=index_set.begin();
425-
it!=index_set.end();
426-
it++)
406+
for(const auto &index : index_set)
427407
{
428-
index_exprt index_expr1;
429-
index_expr1.type()=ns.follow(array_equality.f1.type()).subtype();
430-
index_expr1.array()=array_equality.f1;
431-
index_expr1.index()=*it;
408+
const typet &subtype1=ns.follow(array_equality.f1.type()).subtype();
409+
index_exprt index_expr1(array_equality.f1, index, subtype1);
432410

433-
index_exprt index_expr2;
434-
index_expr2.type()=ns.follow(array_equality.f2.type()).subtype();
435-
index_expr2.array()=array_equality.f2;
436-
index_expr2.index()=*it;
411+
const typet &subtype2=ns.follow(array_equality.f2.type()).subtype();
412+
index_exprt index_expr2(array_equality.f2, index, subtype2);
437413

438414
assert(index_expr1.type()==index_expr2.type());
439415

@@ -485,20 +461,11 @@ void arrayst::add_array_constraints(
485461
assert(expr.operands().size()==1);
486462

487463
// add a[i]=b[i]
488-
for(index_sett::const_iterator
489-
it=index_set.begin();
490-
it!=index_set.end();
491-
it++)
464+
for(const auto &index : index_set)
492465
{
493-
index_exprt index_expr1;
494-
index_expr1.type()=ns.follow(expr.type()).subtype();
495-
index_expr1.array()=expr;
496-
index_expr1.index()=*it;
497-
498-
index_exprt index_expr2;
499-
index_expr2.type()=ns.follow(expr.type()).subtype();
500-
index_expr2.array()=expr.op0();
501-
index_expr2.index()=*it;
466+
const typet &subtype=ns.follow(expr.type()).subtype();
467+
index_exprt index_expr1(expr, index, subtype);
468+
index_exprt index_expr2(expr.op0(), index, subtype);
502469

503470
assert(index_expr1.type()==index_expr2.type());
504471

@@ -528,10 +495,7 @@ void arrayst::add_array_constraints_with(
528495
const exprt &value=expr.new_value();
529496

530497
{
531-
index_exprt index_expr;
532-
index_expr.type()=ns.follow(expr.type()).subtype();
533-
index_expr.array()=expr;
534-
index_expr.index()=index;
498+
index_exprt index_expr(expr, index, ns.follow(expr.type()).subtype());
535499

536500
if(index_expr.type()!=value.type())
537501
{
@@ -547,13 +511,8 @@ void arrayst::add_array_constraints_with(
547511
// use other array index applications for "else" case
548512
// add constraint x[I]=y[I] for I!=i
549513

550-
for(index_sett::const_iterator
551-
it=index_set.begin();
552-
it!=index_set.end();
553-
it++)
514+
for(auto other_index : index_set)
554515
{
555-
exprt other_index=*it;
556-
557516
if(other_index!=index)
558517
{
559518
// we first build the guard
@@ -565,15 +524,9 @@ void arrayst::add_array_constraints_with(
565524

566525
if(guard_lit!=const_literal(true))
567526
{
568-
index_exprt index_expr1;
569-
index_expr1.type()=ns.follow(expr.type()).subtype();
570-
index_expr1.array()=expr;
571-
index_expr1.index()=other_index;
572-
573-
index_exprt index_expr2;
574-
index_expr2.type()=ns.follow(expr.type()).subtype();
575-
index_expr2.array()=expr.op0();
576-
index_expr2.index()=other_index;
527+
typet subtype=ns.follow(expr.type()).subtype();
528+
index_exprt index_expr1(expr, other_index, subtype);
529+
index_exprt index_expr2(expr.op0(), other_index, subtype);
577530

578531
assert(index_expr1.type()==index_expr2.type());
579532

@@ -612,10 +565,7 @@ void arrayst::add_array_constraints_update(
612565
const exprt &value=expr.new_value();
613566

614567
{
615-
index_exprt index_expr;
616-
index_expr.type()=ns.follow(expr.type()).subtype();
617-
index_expr.array()=expr;
618-
index_expr.index()=index;
568+
index_exprt index_expr(expr, index, ns.follow(expr.type()).subtype());
619569

620570
if(index_expr.type()!=value.type())
621571
{
@@ -629,13 +579,8 @@ void arrayst::add_array_constraints_update(
629579
// use other array index applications for "else" case
630580
// add constraint x[I]=y[I] for I!=i
631581

632-
for(index_sett::const_iterator
633-
it=index_set.begin();
634-
it!=index_set.end();
635-
it++)
582+
for(auto other_index : index_set)
636583
{
637-
exprt other_index=*it;
638-
639584
if(other_index!=index)
640585
{
641586
// we first build the guard
@@ -647,15 +592,9 @@ void arrayst::add_array_constraints_update(
647592

648593
if(guard_lit!=const_literal(true))
649594
{
650-
index_exprt index_expr1;
651-
index_expr1.type()=ns.follow(expr.type()).subtype();
652-
index_expr1.array()=expr;
653-
index_expr1.index()=other_index;
654-
655-
index_exprt index_expr2;
656-
index_expr2.type()=ns.follow(expr.type()).subtype();
657-
index_expr2.array()=expr.op0();
658-
index_expr2.index()=other_index;
595+
const typet &subtype=ns.follow(expr.type()).subtype();
596+
index_exprt index_expr1(expr, other_index, subtype);
597+
index_exprt index_expr2(expr.op0(), other_index, subtype);
659598

660599
assert(index_expr1.type()==index_expr2.type());
661600

@@ -683,15 +622,10 @@ void arrayst::add_array_constraints_array_of(
683622
// get other array index applications
684623
// and add constraint x[i]=v
685624

686-
for(index_sett::const_iterator
687-
it=index_set.begin();
688-
it!=index_set.end();
689-
it++)
625+
for(const auto &index : index_set)
690626
{
691-
index_exprt index_expr;
692-
index_expr.type()=ns.follow(expr.type()).subtype();
693-
index_expr.array()=expr;
694-
index_expr.index()=*it;
627+
const typet &subtype=ns.follow(expr.type()).subtype();
628+
index_exprt index_expr(expr, index, subtype);
695629

696630
assert(base_type_eq(index_expr.type(), expr.op0().type(), ns));
697631

@@ -715,20 +649,11 @@ void arrayst::add_array_constraints_if(
715649

716650
// first do true case
717651

718-
for(index_sett::const_iterator
719-
it=index_set.begin();
720-
it!=index_set.end();
721-
it++)
652+
for(const auto &index : index_set)
722653
{
723-
index_exprt index_expr1;
724-
index_expr1.type()=ns.follow(expr.type()).subtype();
725-
index_expr1.array()=expr;
726-
index_expr1.index()=*it;
727-
728-
index_exprt index_expr2;
729-
index_expr2.type()=ns.follow(expr.type()).subtype();
730-
index_expr2.array()=expr.true_case();
731-
index_expr2.index()=*it;
654+
const typet subtype=ns.follow(expr.type()).subtype();
655+
index_exprt index_expr1(expr, index, subtype);
656+
index_exprt index_expr2(expr.true_case(), index, subtype);
732657

733658
assert(index_expr1.type()==index_expr2.type());
734659

@@ -744,20 +669,11 @@ void arrayst::add_array_constraints_if(
744669
}
745670

746671
// now the false case
747-
for(index_sett::const_iterator
748-
it=index_set.begin();
749-
it!=index_set.end();
750-
it++)
751-
{
752-
index_exprt index_expr1;
753-
index_expr1.type()=ns.follow(expr.type()).subtype();
754-
index_expr1.array()=expr;
755-
index_expr1.index()=*it;
756-
757-
index_exprt index_expr2;
758-
index_expr2.type()=ns.follow(expr.type()).subtype();
759-
index_expr2.array()=expr.false_case();
760-
index_expr2.index()=*it;
672+
for(const auto &index : index_set)
673+
{
674+
const typet subtype=ns.follow(expr.type()).subtype();
675+
index_exprt index_expr1(expr, index, subtype);
676+
index_exprt index_expr2(expr.false_case(), index, subtype);
761677

762678
assert(index_expr1.type()==index_expr2.type());
763679

src/solvers/flattening/arrays.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ class arrayst:public equalityt
105105
const index_sett &index_set, const array_equalityt &array_equality);
106106
void add_array_constraints(
107107
const index_sett &index_set, const exprt &expr);
108-
void add_array_constraints(
109-
const index_sett &index_set, const array_equalityt &array_equality);
110108
void add_array_constraints_if(
111109
const index_sett &index_set, const if_exprt &exprt);
112110
void add_array_constraints_with(

0 commit comments

Comments
 (0)