@@ -95,21 +95,26 @@ std::string inv_object_storet::build_string(const exprt &expr) const
95
95
// we ignore some casts
96
96
if (expr.id ()==ID_typecast)
97
97
{
98
- assert (expr. operands (). size ()== 1 );
98
+ const auto &typecast_expr = to_typecast_expr (expr);
99
99
100
- if (expr.type ().id ()==ID_signedbv ||
101
- expr.type ().id ()==ID_unsignedbv)
100
+ if (
101
+ typecast_expr.type ().id () == ID_signedbv ||
102
+ typecast_expr.type ().id () == ID_unsignedbv)
102
103
{
103
- if (expr.op0 ().type ().id ()==ID_signedbv ||
104
- expr.op0 ().type ().id ()==ID_unsignedbv)
104
+ const typet &op_type = typecast_expr.op ().type ();
105
+
106
+ if (op_type.id () == ID_signedbv || op_type.id () == ID_unsignedbv)
105
107
{
106
- if (to_bitvector_type (expr.type ()).get_width ()>=
107
- to_bitvector_type (expr.op0 ().type ()).get_width ())
108
- return build_string (expr.op0 ());
108
+ if (
109
+ to_bitvector_type (typecast_expr.type ()).get_width () >=
110
+ to_bitvector_type (op_type).get_width ())
111
+ {
112
+ return build_string (typecast_expr.op ());
113
+ }
109
114
}
110
- else if (expr. op0 (). type (). id ()== ID_bool)
115
+ else if (op_type. id () == ID_bool)
111
116
{
112
- return build_string (expr. op0 ());
117
+ return build_string (typecast_expr. op ());
113
118
}
114
119
}
115
120
}
@@ -137,8 +142,8 @@ std::string inv_object_storet::build_string(const exprt &expr) const
137
142
138
143
if (expr.id ()==ID_member)
139
144
{
140
- assert (expr. operands (). size ()== 1 );
141
- return build_string (expr. op0 ())+ " . " + expr.get_string (ID_component_name);
145
+ return build_string ( to_member_expr (expr). compound ()) + " . " +
146
+ expr.get_string (ID_component_name);
142
147
}
143
148
144
149
if (expr.id ()==ID_symbol)
@@ -158,8 +163,7 @@ bool invariant_sett::get_object(
158
163
bool inv_object_storet::is_constant_address (const exprt &expr)
159
164
{
160
165
if (expr.id ()==ID_address_of)
161
- if (expr.operands ().size ()==1 )
162
- return is_constant_address_rec (expr.op0 ());
166
+ return is_constant_address_rec (to_address_of_expr (expr).object ());
163
167
164
168
return false ;
165
169
}
@@ -169,15 +173,12 @@ bool inv_object_storet::is_constant_address_rec(const exprt &expr)
169
173
if (expr.id ()==ID_symbol)
170
174
return true ;
171
175
else if (expr.id ()==ID_member)
172
- {
173
- assert (expr.operands ().size ()==1 );
174
- return is_constant_address_rec (expr.op0 ());
175
- }
176
+ return is_constant_address_rec (to_member_expr (expr).compound ());
176
177
else if (expr.id ()==ID_index)
177
178
{
178
- assert (expr. operands (). size ()== 2 );
179
- if (expr. op1 ().is_constant ())
180
- return is_constant_address_rec (expr. op0 ());
179
+ const auto &index_expr = to_index_expr (expr);
180
+ if (index_expr. index ().is_constant ())
181
+ return is_constant_address_rec (index_expr. array ());
181
182
}
182
183
183
184
return false ;
@@ -429,14 +430,14 @@ void invariant_sett::strengthen_rec(const exprt &expr)
429
430
else if (expr.id ()==ID_le ||
430
431
expr.id ()==ID_lt)
431
432
{
432
- assert (expr. operands (). size ()== 2 );
433
+ const auto &rel = to_binary_relation_expr (expr);
433
434
434
435
// special rule: x <= (a & b)
435
436
// implies: x<=a && x<=b
436
437
437
- if (expr .op1 ().id ()== ID_bitand)
438
+ if (rel .op1 ().id () == ID_bitand)
438
439
{
439
- const exprt &bitand_op=expr .op1 ();
440
+ const exprt &bitand_op = rel .op1 ();
440
441
441
442
forall_operands (it, bitand_op)
442
443
{
@@ -450,12 +451,11 @@ void invariant_sett::strengthen_rec(const exprt &expr)
450
451
451
452
std::pair<unsigned , unsigned > p;
452
453
453
- if (get_object (expr.op0 (), p.first ) ||
454
- get_object (expr.op1 (), p.second ))
454
+ if (get_object (rel.op0 (), p.first ) || get_object (rel.op1 (), p.second ))
455
455
return ;
456
456
457
- const auto i0 = numeric_cast<mp_integer>(expr .op0 ());
458
- const auto i1 = numeric_cast<mp_integer>(expr .op1 ());
457
+ const auto i0 = numeric_cast<mp_integer>(rel .op0 ());
458
+ const auto i1 = numeric_cast<mp_integer>(rel .op1 ());
459
459
460
460
if (expr.id ()==ID_le)
461
461
{
@@ -483,9 +483,9 @@ void invariant_sett::strengthen_rec(const exprt &expr)
483
483
}
484
484
else if (expr.id ()==ID_equal)
485
485
{
486
- assert (expr. operands (). size ()== 2 );
486
+ const auto &equal_expr = to_equal_expr (expr);
487
487
488
- const typet &op_type= ns->follow (expr .op0 ().type ());
488
+ const typet &op_type = ns->follow (equal_expr .op0 ().type ());
489
489
490
490
if (op_type.id ()==ID_struct)
491
491
{
@@ -495,9 +495,9 @@ void invariant_sett::strengthen_rec(const exprt &expr)
495
495
for (const auto &comp : struct_type.components ())
496
496
{
497
497
const member_exprt lhs_member_expr (
498
- expr .op0 (), comp.get_name (), comp.type ());
498
+ equal_expr .op0 (), comp.get_name (), comp.type ());
499
499
const member_exprt rhs_member_expr (
500
- expr .op1 (), comp.get_name (), comp.type ());
500
+ equal_expr .op1 (), comp.get_name (), comp.type ());
501
501
502
502
const equal_exprt equality (lhs_member_expr, rhs_member_expr);
503
503
@@ -511,48 +511,51 @@ void invariant_sett::strengthen_rec(const exprt &expr)
511
511
// special rule: x = (a & b)
512
512
// implies: x<=a && x<=b
513
513
514
- if (expr .op1 ().id ()== ID_bitand)
514
+ if (equal_expr .op1 ().id () == ID_bitand)
515
515
{
516
- const exprt &bitand_op=expr .op1 ();
516
+ const exprt &bitand_op = equal_expr .op1 ();
517
517
518
518
forall_operands (it, bitand_op)
519
519
{
520
- exprt tmp (expr );
520
+ exprt tmp (equal_expr );
521
521
tmp.op1 ()=*it;
522
522
tmp.id (ID_le);
523
523
strengthen_rec (tmp);
524
524
}
525
525
526
526
return ;
527
527
}
528
- else if (expr .op0 ().id ()== ID_bitand)
528
+ else if (equal_expr .op0 ().id () == ID_bitand)
529
529
{
530
- exprt tmp (expr );
530
+ exprt tmp (equal_expr );
531
531
std::swap (tmp.op0 (), tmp.op1 ());
532
532
strengthen_rec (tmp);
533
533
return ;
534
534
}
535
535
536
536
// special rule: x = (type) y
537
- if (expr .op1 ().id ()== ID_typecast)
537
+ if (equal_expr .op1 ().id () == ID_typecast)
538
538
{
539
- assert (expr .op1 (). operands (). size ()== 1 );
540
- add_type_bounds (expr .op0 (), expr. op1 (). op0 ().type ());
539
+ const auto &typecast_expr = to_typecast_expr (equal_expr .op1 ());
540
+ add_type_bounds (equal_expr .op0 (), typecast_expr. op ().type ());
541
541
}
542
- else if (expr .op0 ().id ()== ID_typecast)
542
+ else if (equal_expr .op0 ().id () == ID_typecast)
543
543
{
544
- assert (expr .op0 (). operands (). size ()== 1 );
545
- add_type_bounds (expr .op1 (), expr. op0 (). op0 ().type ());
544
+ const auto &typecast_expr = to_typecast_expr (equal_expr .op0 ());
545
+ add_type_bounds (equal_expr .op1 (), typecast_expr. op ().type ());
546
546
}
547
547
548
548
std::pair<unsigned , unsigned > p, s;
549
549
550
- if (get_object (expr.op0 (), p.first ) ||
551
- get_object (expr.op1 (), p.second ))
550
+ if (
551
+ get_object (equal_expr.op0 (), p.first ) ||
552
+ get_object (equal_expr.op1 (), p.second ))
553
+ {
552
554
return ;
555
+ }
553
556
554
- const auto i0 = numeric_cast<mp_integer>(expr .op0 ());
555
- const auto i1 = numeric_cast<mp_integer>(expr .op1 ());
557
+ const auto i0 = numeric_cast<mp_integer>(equal_expr .op0 ());
558
+ const auto i1 = numeric_cast<mp_integer>(equal_expr .op1 ());
556
559
if (i0.has_value ())
557
560
add_bounds (p.second , boundst (*i0));
558
561
else if (i1.has_value ())
@@ -569,13 +572,16 @@ void invariant_sett::strengthen_rec(const exprt &expr)
569
572
}
570
573
else if (expr.id ()==ID_notequal)
571
574
{
572
- assert (expr. operands (). size ()== 2 );
575
+ const auto ¬equal_expr = to_notequal_expr (expr);
573
576
574
577
std::pair<unsigned , unsigned > p;
575
578
576
- if (get_object (expr.op0 (), p.first ) ||
577
- get_object (expr.op1 (), p.second ))
579
+ if (
580
+ get_object (notequal_expr.op0 (), p.first ) ||
581
+ get_object (notequal_expr.op1 (), p.second ))
582
+ {
578
583
return ;
584
+ }
579
585
580
586
// check if this is a contradiction
581
587
if (has_eq (p))
@@ -629,19 +635,19 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
629
635
expr.id ()==ID_equal ||
630
636
expr.id ()==ID_notequal)
631
637
{
632
- assert (expr. operands (). size ()== 2 );
638
+ const auto &rel = to_binary_relation_expr (expr);
633
639
634
640
std::pair<unsigned , unsigned > p;
635
641
636
- bool ob0= get_object (expr .op0 (), p.first );
637
- bool ob1= get_object (expr .op1 (), p.second );
642
+ bool ob0 = get_object (rel .op0 (), p.first );
643
+ bool ob1 = get_object (rel .op1 (), p.second );
638
644
639
645
if (ob0 || ob1)
640
646
return tvt::unknown ();
641
647
642
648
tvt r;
643
649
644
- if (expr .id ()== ID_le)
650
+ if (rel .id () == ID_le)
645
651
{
646
652
r=is_le (p);
647
653
if (!r.is_unknown ())
@@ -653,7 +659,7 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
653
659
654
660
return b0<=b1;
655
661
}
656
- else if (expr .id ()== ID_lt)
662
+ else if (rel .id () == ID_lt)
657
663
{
658
664
r=is_lt (p);
659
665
if (!r.is_unknown ())
@@ -665,9 +671,9 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
665
671
666
672
return b0<b1;
667
673
}
668
- else if (expr .id ()== ID_equal)
674
+ else if (rel .id () == ID_equal)
669
675
return is_eq (p);
670
- else if (expr .id ()== ID_notequal)
676
+ else if (rel .id () == ID_notequal)
671
677
return is_ne (p);
672
678
else
673
679
UNREACHABLE;
@@ -717,10 +723,9 @@ void invariant_sett::nnf(exprt &expr, bool negate)
717
723
}
718
724
else if (expr.id ()==ID_not)
719
725
{
720
- assert (expr.operands ().size ()==1 );
721
- nnf (expr.op0 (), !negate);
726
+ nnf (to_not_expr (expr).op (), !negate);
722
727
exprt tmp;
723
- tmp.swap (expr. op0 ());
728
+ tmp.swap (to_not_expr ( expr). op ());
724
729
expr.swap (tmp);
725
730
}
726
731
else if (expr.id ()==ID_and)
@@ -741,14 +746,15 @@ void invariant_sett::nnf(exprt &expr, bool negate)
741
746
}
742
747
else if (expr.id ()==ID_typecast)
743
748
{
744
- assert (expr. operands (). size ()== 1 );
749
+ const auto &typecast_expr = to_typecast_expr (expr);
745
750
746
- if (expr.op0 ().type ().id ()==ID_unsignedbv ||
747
- expr.op0 ().type ().id ()==ID_signedbv)
751
+ if (
752
+ typecast_expr.op ().type ().id () == ID_unsignedbv ||
753
+ typecast_expr.op ().type ().id () == ID_signedbv)
748
754
{
749
755
equal_exprt tmp;
750
- tmp.lhs ()=expr. op0 ();
751
- tmp.rhs ()= from_integer (0 , expr. op0 ().type ());
756
+ tmp.lhs () = typecast_expr. op ();
757
+ tmp.rhs () = from_integer (0 , typecast_expr. op ().type ());
752
758
nnf (tmp, !negate);
753
759
expr.swap (tmp);
754
760
}
0 commit comments