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