@@ -123,10 +123,7 @@ void arrayst::collect_arrays(const exprt &a)
123
123
collect_arrays (a.op0 ());
124
124
125
125
// 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 ());
130
127
record_array_index (index_expr);
131
128
}
132
129
else if (a.id ()==ID_update) // TODO: is this obsolete?
@@ -146,10 +143,7 @@ void arrayst::collect_arrays(const exprt &a)
146
143
147
144
#if 0
148
145
// 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());
153
147
record_array_index(index_expr);
154
148
#endif
155
149
}
@@ -273,14 +267,11 @@ void arrayst::add_array_constraints()
273
267
}
274
268
275
269
// 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)
280
271
{
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 );
284
275
285
276
// update_index_map should not be necessary here
286
277
}
@@ -334,10 +325,8 @@ void arrayst::add_array_Ackermann_constraints()
334
325
335
326
if (indices_equal_lit!=const_literal (false ))
336
327
{
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);
341
330
342
331
index_exprt index_expr2=index_expr1;
343
332
index_expr2.index ()=*i2;
@@ -388,52 +377,39 @@ void arrayst::update_index_map(bool update_all)
388
377
}
389
378
else
390
379
{
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
+
395
383
update_indices.clear ();
396
384
}
397
385
398
386
#ifdef DEBUG
399
387
// 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 )])
411
394
<< " ): "
412
- << from_expr (ns, " " , *i2 ) << ' \n ' ;
395
+ << from_expr (ns, " " , index ) << ' \n ' ;
413
396
std::cout << " -----\n " ;
414
397
#endif
415
398
}
416
399
417
- void arrayst::add_array_constraints (
400
+ void arrayst::add_array_constraints_equality (
418
401
const index_sett &index_set,
419
402
const array_equalityt &array_equality)
420
403
{
421
404
// add constraints x=y => x[i]=y[i]
422
405
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)
427
407
{
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);
432
410
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);
437
413
438
414
assert (index_expr1.type ()==index_expr2.type ());
439
415
@@ -485,20 +461,11 @@ void arrayst::add_array_constraints(
485
461
assert (expr.operands ().size ()==1 );
486
462
487
463
// 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)
492
465
{
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);
502
469
503
470
assert (index_expr1.type ()==index_expr2.type ());
504
471
@@ -528,10 +495,7 @@ void arrayst::add_array_constraints_with(
528
495
const exprt &value=expr.new_value ();
529
496
530
497
{
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 ());
535
499
536
500
if (index_expr.type ()!=value.type ())
537
501
{
@@ -547,13 +511,8 @@ void arrayst::add_array_constraints_with(
547
511
// use other array index applications for "else" case
548
512
// add constraint x[I]=y[I] for I!=i
549
513
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)
554
515
{
555
- exprt other_index=*it;
556
-
557
516
if (other_index!=index)
558
517
{
559
518
// we first build the guard
@@ -565,15 +524,9 @@ void arrayst::add_array_constraints_with(
565
524
566
525
if (guard_lit!=const_literal (true ))
567
526
{
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);
577
530
578
531
assert (index_expr1.type ()==index_expr2.type ());
579
532
@@ -612,10 +565,7 @@ void arrayst::add_array_constraints_update(
612
565
const exprt &value=expr.new_value();
613
566
614
567
{
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());
619
569
620
570
if(index_expr.type()!=value.type())
621
571
{
@@ -629,13 +579,8 @@ void arrayst::add_array_constraints_update(
629
579
// use other array index applications for "else" case
630
580
// add constraint x[I]=y[I] for I!=i
631
581
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)
636
583
{
637
- exprt other_index=*it;
638
-
639
584
if(other_index!=index)
640
585
{
641
586
// we first build the guard
@@ -647,15 +592,9 @@ void arrayst::add_array_constraints_update(
647
592
648
593
if(guard_lit!=const_literal(true))
649
594
{
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);
659
598
660
599
assert(index_expr1.type()==index_expr2.type());
661
600
@@ -683,15 +622,10 @@ void arrayst::add_array_constraints_array_of(
683
622
// get other array index applications
684
623
// and add constraint x[i]=v
685
624
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)
690
626
{
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);
695
629
696
630
assert (base_type_eq (index_expr.type (), expr.op0 ().type (), ns));
697
631
@@ -715,20 +649,11 @@ void arrayst::add_array_constraints_if(
715
649
716
650
// first do true case
717
651
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)
722
653
{
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);
732
657
733
658
assert (index_expr1.type ()==index_expr2.type ());
734
659
@@ -744,20 +669,11 @@ void arrayst::add_array_constraints_if(
744
669
}
745
670
746
671
// 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);
761
677
762
678
assert (index_expr1.type ()==index_expr2.type ());
763
679
0 commit comments