10
10
11
11
#include < util/arith_tools.h>
12
12
#include < util/format_expr.h>
13
+ #include < util/json_irep.h>
14
+ #include < util/message.h>
13
15
#include < util/namespace.h>
14
16
#include < util/replace_expr.h>
15
17
#include < util/std_expr.h>
16
18
#include < util/std_types.h>
19
+ #include < util/ui_message.h>
17
20
18
21
#include < solvers/prop/prop.h>
19
22
26
29
arrayst::arrayst (
27
30
const namespacet &_ns,
28
31
propt &_prop,
29
- message_handlert &message_handler)
30
- : equalityt(_prop, message_handler), ns(_ns)
32
+ message_handlert &_message_handler,
33
+ bool _get_array_constraints)
34
+ : equalityt(_prop, _message_handler),
35
+ ns(_ns),
36
+ log(_message_handler),
37
+ message_handler(_message_handler)
31
38
{
32
39
lazy_arrays = false ; // will be set to true when --refine is used
33
40
incremental_cache = false ; // for incremental solving
41
+ // get_array_constraints is true when --show-array-constraints is used
42
+ get_array_constraints = _get_array_constraints;
34
43
}
35
44
36
45
void arrayst::record_array_index (const index_exprt &index)
@@ -365,6 +374,7 @@ void arrayst::add_array_Ackermann_constraints()
365
374
lazy_constraintt lazy (lazy_typet::ARRAY_ACKERMANN,
366
375
implies_exprt (literal_exprt (indices_equal_lit), values_equal));
367
376
add_array_constraint (lazy, true ); // added lazily
377
+ array_constraint_count[constraint_typet::ARRAY_ACKERMANN]++;
368
378
369
379
#if 0 // old code for adding, not significantly faster
370
380
prop.lcnf(!indices_equal_lit, convert(values_equal));
@@ -451,6 +461,7 @@ void arrayst::add_array_constraints_equality(
451
461
// equality constraints are not added lazily
452
462
// convert must be done to guarantee correct update of the index_set
453
463
prop.lcnf (!array_equality.l , convert (equality_expr));
464
+ array_constraint_count[constraint_typet::ARRAY_EQUALITY]++;
454
465
}
455
466
}
456
467
@@ -511,6 +522,7 @@ void arrayst::add_array_constraints(
511
522
lazy_constraintt lazy (lazy_typet::ARRAY_TYPECAST,
512
523
equal_exprt (index_expr1, index_expr2));
513
524
add_array_constraint (lazy, false ); // added immediately
525
+ array_constraint_count[constraint_typet::ARRAY_TYPECAST]++;
514
526
}
515
527
}
516
528
else if (expr.id ()==ID_index)
@@ -549,6 +561,7 @@ void arrayst::add_array_constraints_with(
549
561
lazy_constraintt lazy (
550
562
lazy_typet::ARRAY_WITH, equal_exprt (index_expr, value));
551
563
add_array_constraint (lazy, false ); // added immediately
564
+ array_constraint_count[constraint_typet::ARRAY_WITH]++;
552
565
553
566
updated_indices.insert (index );
554
567
}
@@ -582,7 +595,9 @@ void arrayst::add_array_constraints_with(
582
595
// add constraint
583
596
lazy_constraintt lazy (lazy_typet::ARRAY_WITH, or_exprt (equality_expr,
584
597
literal_exprt (guard_lit)));
598
+
585
599
add_array_constraint (lazy, false ); // added immediately
600
+ array_constraint_count[constraint_typet::ARRAY_WITH]++;
586
601
587
602
#if 0 // old code for adding, not significantly faster
588
603
{
@@ -678,6 +693,7 @@ void arrayst::add_array_constraints_array_of(
678
693
lazy_constraintt lazy (
679
694
lazy_typet::ARRAY_OF, equal_exprt (index_expr, expr.what ()));
680
695
add_array_constraint (lazy, false ); // added immediately
696
+ array_constraint_count[constraint_typet::ARRAY_OF]++;
681
697
}
682
698
}
683
699
@@ -713,6 +729,7 @@ void arrayst::add_array_constraints_array_constant(
713
729
lazy_constraintt lazy{lazy_typet::ARRAY_CONSTANT,
714
730
equal_exprt{index_expr, v}};
715
731
add_array_constraint (lazy, false ); // added immediately
732
+ array_constraint_count[constraint_typet::ARRAY_CONSTANT]++;
716
733
}
717
734
else
718
735
{
@@ -755,6 +772,7 @@ void arrayst::add_array_constraints_array_constant(
755
772
implies_exprt{index_constraint,
756
773
equal_exprt{index_expr, operands[range.first ]}}};
757
774
add_array_constraint (lazy, true ); // added lazily
775
+ array_constraint_count[constraint_typet::ARRAY_CONSTANT]++;
758
776
}
759
777
}
760
778
}
@@ -778,7 +796,9 @@ void arrayst::add_array_constraints_comprehension(
778
796
lazy_constraintt lazy (
779
797
lazy_typet::ARRAY_COMPREHENSION,
780
798
equal_exprt (index_expr, comprehension_body));
799
+
781
800
add_array_constraint (lazy, false ); // added immediately
801
+ array_constraint_count[constraint_typet::ARRAY_COMPREHENSION]++;
782
802
}
783
803
}
784
804
@@ -806,6 +826,7 @@ void arrayst::add_array_constraints_if(
806
826
or_exprt (literal_exprt (!cond_lit),
807
827
equal_exprt (index_expr1, index_expr2)));
808
828
add_array_constraint (lazy, false ); // added immediately
829
+ array_constraint_count[constraint_typet::ARRAY_IF]++;
809
830
810
831
#if 0 // old code for adding, not significantly faster
811
832
prop.lcnf(!cond_lit, convert(equal_exprt(index_expr1, index_expr2)));
@@ -825,9 +846,59 @@ void arrayst::add_array_constraints_if(
825
846
or_exprt (literal_exprt (cond_lit),
826
847
equal_exprt (index_expr1, index_expr2)));
827
848
add_array_constraint (lazy, false ); // added immediately
849
+ array_constraint_count[constraint_typet::ARRAY_IF]++;
828
850
829
851
#if 0 // old code for adding, not significantly faster
830
852
prop.lcnf(cond_lit, convert(equal_exprt(index_expr1, index_expr2)));
831
853
#endif
832
854
}
833
855
}
856
+
857
+ std::string arrayst::enum_to_string (constraint_typet type)
858
+ {
859
+ switch (type)
860
+ {
861
+ case constraint_typet::ARRAY_ACKERMANN:
862
+ return " arrayAckermann" ;
863
+ case constraint_typet::ARRAY_WITH:
864
+ return " arrayWith" ;
865
+ case constraint_typet::ARRAY_IF:
866
+ return " arrayIf" ;
867
+ case constraint_typet::ARRAY_OF:
868
+ return " arrayOf" ;
869
+ case constraint_typet::ARRAY_TYPECAST:
870
+ return " arrayTypecast" ;
871
+ case constraint_typet::ARRAY_CONSTANT:
872
+ return " arrayConstant" ;
873
+ case constraint_typet::ARRAY_COMPREHENSION:
874
+ return " arrayComprehension" ;
875
+ case constraint_typet::ARRAY_EQUALITY:
876
+ return " arrayEquality" ;
877
+ default :
878
+ UNREACHABLE;
879
+ }
880
+ }
881
+
882
+ void arrayst::display_array_constraint_count ()
883
+ {
884
+ json_objectt json_result;
885
+ json_objectt &json_array_theory =
886
+ json_result[" arrayConstraints" ].make_object ();
887
+
888
+ size_t num_constraints = 0 ;
889
+
890
+ array_constraint_countt::iterator it = array_constraint_count.begin ();
891
+ while (it != array_constraint_count.end ())
892
+ {
893
+ std::string contraint_type_string = enum_to_string (it->first );
894
+ json_array_theory[contraint_type_string] =
895
+ json_numbert (std::to_string (it->second ));
896
+
897
+ num_constraints += it->second ;
898
+ it++;
899
+ }
900
+
901
+ json_result[" numOfConstraints" ] =
902
+ json_numbert (std::to_string (num_constraints));
903
+ log .status () << " ,\n " << json_result;
904
+ }
0 commit comments