@@ -253,7 +253,7 @@ bvt boolbvt::convert_bitvector(const exprt &expr)
253
253
return convert_bitvector (expr.op0 ());
254
254
}
255
255
else if (expr.id ()==ID_abs)
256
- return convert_abs (expr);
256
+ return convert_abs (to_abs_expr ( expr) );
257
257
else if (expr.id () == ID_bswap)
258
258
return convert_bswap (to_bswap_expr (expr));
259
259
else if (expr.id ()==ID_byte_extract_little_endian ||
@@ -433,13 +433,7 @@ bvt boolbvt::convert_function_application(
433
433
434
434
literalt boolbvt::convert_rest (const exprt &expr)
435
435
{
436
- if (expr.type ().id ()!=ID_bool)
437
- {
438
- error () << " boolbvt::convert_rest got non-boolean operand: "
439
- << expr.pretty () << eom;
440
- throw 0 ;
441
- }
442
-
436
+ PRECONDITION (expr.type ().id () == ID_bool);
443
437
const exprt::operandst &operands=expr.operands ();
444
438
445
439
if (expr.id ()==ID_typecast)
@@ -451,9 +445,7 @@ literalt boolbvt::convert_rest(const exprt &expr)
451
445
return convert_verilog_case_equality (to_binary_relation_expr (expr));
452
446
else if (expr.id ()==ID_notequal)
453
447
{
454
- if (expr.operands ().size ()!=2 )
455
- throw " notequal expects two operands" ;
456
-
448
+ DATA_INVARIANT (expr.operands ().size () == 2 , " notequal expects two operands" );
457
449
return !convert_equality (equal_exprt (expr.op0 (), expr.op1 ()));
458
450
}
459
451
else if (expr.id ()==ID_ieee_float_equal ||
@@ -480,57 +472,37 @@ literalt boolbvt::convert_rest(const exprt &expr)
480
472
else if (expr.id ()==ID_index)
481
473
{
482
474
bvt bv=convert_index (to_index_expr (expr));
483
-
484
- if (bv.size ()!=1 )
485
- throw " convert_index returned non-bool bitvector" ;
486
-
475
+ CHECK_RETURN (bv.size () == 1 );
487
476
return bv[0 ];
488
477
}
489
478
else if (expr.id ()==ID_member)
490
479
{
491
480
bvt bv=convert_member (to_member_expr (expr));
492
-
493
- if (bv.size ()!=1 )
494
- throw " convert_member returned non-bool bitvector" ;
495
-
481
+ CHECK_RETURN (bv.size () == 1 );
496
482
return bv[0 ];
497
483
}
498
484
else if (expr.id ()==ID_case)
499
485
{
500
486
bvt bv=convert_case (expr);
501
-
502
- if (bv.size ()!=1 )
503
- throw " convert_case returned non-bool bitvector" ;
504
-
487
+ CHECK_RETURN (bv.size () == 1 );
505
488
return bv[0 ];
506
489
}
507
490
else if (expr.id ()==ID_cond)
508
491
{
509
492
bvt bv=convert_cond (expr);
510
-
511
- if (bv.size ()!=1 )
512
- throw " convert_cond returned non-bool bitvector" ;
513
-
493
+ CHECK_RETURN (bv.size () == 1 );
514
494
return bv[0 ];
515
495
}
516
496
else if (expr.id ()==ID_sign)
517
497
{
518
- if (expr.operands ().size ()!=1 )
519
- throw " sign expects one operand" ;
520
-
498
+ DATA_INVARIANT (expr.operands ().size () == 1 , " sign expects one operand" );
521
499
const bvt &bv=convert_bv (operands[0 ]);
522
-
523
- if (bv.empty ())
524
- throw " sign operator takes one non-empty operand" ;
525
-
526
- if (operands[0 ].type ().id ()==ID_signedbv)
500
+ CHECK_RETURN (!bv.empty ());
501
+ const irep_idt type_id = operands[0 ].type ().id ();
502
+ if (type_id == ID_signedbv || type_id == ID_fixedbv || type_id == ID_floatbv)
527
503
return bv[bv.size ()-1 ];
528
- else if (operands[ 0 ]. type (). id ()== ID_unsignedbv)
504
+ if (type_id == ID_unsignedbv)
529
505
return const_literal (false );
530
- else if (operands[0 ].type ().id ()==ID_fixedbv)
531
- return bv[bv.size ()-1 ];
532
- else if (operands[0 ].type ().id ()==ID_floatbv)
533
- return bv[bv.size ()-1 ];
534
506
}
535
507
else if (expr.id ()==ID_reduction_or || expr.id ()==ID_reduction_and ||
536
508
expr.id ()==ID_reduction_nor || expr.id ()==ID_reduction_nand ||
@@ -542,64 +514,53 @@ literalt boolbvt::convert_rest(const exprt &expr)
542
514
return convert_overflow (expr);
543
515
else if (expr.id ()==ID_isnan)
544
516
{
545
- if (expr.operands ().size ()!=1 )
546
- throw " isnan expects one operand" ;
547
-
517
+ DATA_INVARIANT (expr.operands ().size () == 1 , " isnan expects one operand" );
548
518
const bvt &bv=convert_bv (operands[0 ]);
549
519
550
520
if (expr.op0 ().type ().id ()==ID_floatbv)
551
521
{
552
522
float_utilst float_utils (prop, to_floatbv_type (expr.op0 ().type ()));
553
523
return float_utils.is_NaN (bv);
554
524
}
555
- else if (expr.op0 ().type ().id ()== ID_fixedbv)
525
+ else if (expr.op0 ().type ().id () == ID_fixedbv)
556
526
return const_literal (false );
557
527
}
558
528
else if (expr.id ()==ID_isfinite)
559
529
{
560
- if (expr.operands ().size ()!=1 )
561
- throw " isfinite expects one operand" ;
562
-
530
+ DATA_INVARIANT (expr.operands ().size () == 1 , " isfinite expects one operand" );
563
531
const bvt &bv=convert_bv (operands[0 ]);
564
-
565
532
if (expr.op0 ().type ().id ()==ID_floatbv)
566
533
{
567
534
float_utilst float_utils (prop, to_floatbv_type (expr.op0 ().type ()));
568
535
return prop.land (
569
536
!float_utils.is_infinity (bv),
570
537
!float_utils.is_NaN (bv));
571
538
}
572
- else if (expr.op0 ().type ().id ()== ID_fixedbv)
539
+ else if (expr.op0 ().type ().id () == ID_fixedbv)
573
540
return const_literal (true );
574
541
}
575
542
else if (expr.id ()==ID_isinf)
576
543
{
577
- if (expr.operands ().size ()!=1 )
578
- throw " isinf expects one operand" ;
579
-
544
+ DATA_INVARIANT (expr.operands ().size () == 1 , " isinf expects one operand" );
580
545
const bvt &bv=convert_bv (operands[0 ]);
581
-
582
546
if (expr.op0 ().type ().id ()==ID_floatbv)
583
547
{
584
548
float_utilst float_utils (prop, to_floatbv_type (expr.op0 ().type ()));
585
549
return float_utils.is_infinity (bv);
586
550
}
587
- else if (expr.op0 ().type ().id ()== ID_fixedbv)
551
+ else if (expr.op0 ().type ().id () == ID_fixedbv)
588
552
return const_literal (false );
589
553
}
590
554
else if (expr.id ()==ID_isnormal)
591
555
{
592
- if (expr.operands ().size ()!=1 )
593
- throw " isnormal expects one operand" ;
594
-
595
- const bvt &bv=convert_bv (operands[0 ]);
596
-
556
+ DATA_INVARIANT (expr.operands ().size () == 1 , " isnormal expects one operand" );
597
557
if (expr.op0 ().type ().id ()==ID_floatbv)
598
558
{
559
+ const bvt &bv = convert_bv (operands[0 ]);
599
560
float_utilst float_utils (prop, to_floatbv_type (expr.op0 ().type ()));
600
561
return float_utils.is_normal (bv);
601
562
}
602
- else if (expr.op0 ().type ().id ()== ID_fixedbv)
563
+ else if (expr.op0 ().type ().id () == ID_fixedbv)
603
564
return const_literal (true );
604
565
}
605
566
@@ -699,17 +660,16 @@ void boolbvt::print_assignment(std::ostream &out) const
699
660
out << pair.first << " =" << pair.second .get_value (prop) << ' \n ' ;
700
661
}
701
662
702
- void boolbvt::build_offset_map (const struct_typet &src, offset_mapt &dest )
663
+ boolbvt::offset_mapt boolbvt::build_offset_map (const struct_typet &src)
703
664
{
704
- const struct_typet::componentst &components=
705
- src.components ();
706
-
707
- dest.resize (components.size ());
708
- std::size_t offset=0 ;
709
- for (std::size_t i=0 ; i<components.size (); i++)
665
+ const struct_typet::componentst &components = src.components ();
666
+ offset_mapt dest;
667
+ dest.reserve (components.size ());
668
+ std::size_t offset = 0 ;
669
+ for (const auto &comp : components)
710
670
{
711
- std::size_t comp_width=boolbv_width (components[i].type ());
712
- dest[i]=offset;
713
- offset+=comp_width;
671
+ dest.push_back (offset);
672
+ offset += boolbv_width (comp.type ());
714
673
}
674
+ return dest;
715
675
}
0 commit comments