@@ -313,24 +313,26 @@ exprt smt2_parsert::function_application(
313
313
return nil_exprt ();
314
314
}
315
315
316
- exprt smt2_parsert::cast_bv_to_signed (const exprt &expr )
316
+ exprt::operandst smt2_parsert::cast_bv_to_signed (const exprt::operandst &op )
317
317
{
318
- if (expr.type ().id ()==ID_signedbv) // no need to cast
319
- return expr;
318
+ exprt::operandst result = op;
320
319
321
- if ( expr. type (). id ()!=ID_unsignedbv )
320
+ for ( auto & expr : result )
322
321
{
323
- error () << " expected unsigned bitvector" << eom;
324
- return expr;
322
+ if (expr.type ().id () == ID_signedbv) // no need to cast
323
+ {
324
+ }
325
+ else if (expr.type ().id () != ID_unsignedbv)
326
+ {
327
+ error () << " expected unsigned bitvector" << eom;
328
+ }
329
+ else
330
+ {
331
+ const auto width = to_unsignedbv_type (expr.type ()).get_width ();
332
+ expr = typecast_exprt (expr, signedbv_typet (width));
333
+ }
325
334
}
326
335
327
- auto width=to_unsignedbv_type (expr.type ()).get_width ();
328
- signedbv_typet signed_type (width);
329
-
330
- typecast_exprt result (expr, signed_type);
331
- result.op0 ()=expr;
332
- result.type ()=signed_type;
333
-
334
336
return result;
335
337
}
336
338
@@ -345,17 +347,11 @@ exprt smt2_parsert::cast_bv_to_unsigned(const exprt &expr)
345
347
return expr;
346
348
}
347
349
348
- auto width=to_signedbv_type (expr.type ()).get_width ();
349
- unsignedbv_typet unsigned_type (width);
350
-
351
- typecast_exprt result (expr, unsigned_type);
352
- result.op0 ()=expr;
353
- result.type ()=unsigned_type;
354
-
355
- return result;
350
+ const auto width=to_signedbv_type (expr.type ()).get_width ();
351
+ return typecast_exprt (expr, unsignedbv_typet (width));
356
352
}
357
353
358
- exprt smt2_parsert::multi_ary (irep_idt id, exprt::operandst &op)
354
+ exprt smt2_parsert::multi_ary (irep_idt id, const exprt::operandst &op)
359
355
{
360
356
if (op.empty ())
361
357
{
@@ -377,12 +373,12 @@ exprt smt2_parsert::multi_ary(irep_idt id, exprt::operandst &op)
377
373
}
378
374
379
375
exprt result (id, op[0 ].type ());
380
- result.operands (). swap (op) ;
376
+ result.operands () = op ;
381
377
return result;
382
378
}
383
379
}
384
380
385
- exprt smt2_parsert::binary_predicate (irep_idt id, exprt::operandst &op)
381
+ exprt smt2_parsert::binary_predicate (irep_idt id, const exprt::operandst &op)
386
382
{
387
383
if (op.size ()!=2 )
388
384
{
@@ -404,7 +400,7 @@ exprt smt2_parsert::binary_predicate(irep_idt id, exprt::operandst &op)
404
400
}
405
401
}
406
402
407
- exprt smt2_parsert::unary (irep_idt id, exprt::operandst &op)
403
+ exprt smt2_parsert::unary (irep_idt id, const exprt::operandst &op)
408
404
{
409
405
if (op.size ()!=1 )
410
406
{
@@ -415,7 +411,7 @@ exprt smt2_parsert::unary(irep_idt id, exprt::operandst &op)
415
411
return unary_exprt (id, op[0 ], op[0 ].type ());
416
412
}
417
413
418
- exprt smt2_parsert::binary (irep_idt id, exprt::operandst &op)
414
+ exprt smt2_parsert::binary (irep_idt id, const exprt::operandst &op)
419
415
{
420
416
if (op.size ()!=2 )
421
417
{
@@ -510,45 +506,35 @@ exprt smt2_parsert::function_application()
510
506
}
511
507
else if (id==" bvsle" )
512
508
{
513
- op[0 ]=cast_bv_to_signed (op[0 ]);
514
- op[1 ]=cast_bv_to_signed (op[1 ]);
515
- return binary_predicate (ID_le, op);
509
+ return binary_predicate (ID_le, cast_bv_to_signed (op));
516
510
}
517
511
else if (id==" bvuge" )
518
512
{
519
513
return binary_predicate (ID_ge, op);
520
514
}
521
515
else if (id==" bvsge" )
522
516
{
523
- op[0 ]=cast_bv_to_signed (op[0 ]);
524
- op[1 ]=cast_bv_to_signed (op[1 ]);
525
- return binary_predicate (ID_ge, op);
517
+ return binary_predicate (ID_ge, cast_bv_to_signed (op));
526
518
}
527
519
else if (id==" bvult" )
528
520
{
529
521
return binary_predicate (ID_lt, op);
530
522
}
531
523
else if (id==" bvslt" )
532
524
{
533
- op[0 ]=cast_bv_to_signed (op[0 ]);
534
- op[1 ]=cast_bv_to_signed (op[1 ]);
535
- return binary_predicate (ID_lt, op);
525
+ return binary_predicate (ID_lt, cast_bv_to_signed (op));
536
526
}
537
527
else if (id==" bvugt" )
538
528
{
539
529
return binary_predicate (ID_gt, op);
540
530
}
541
531
else if (id==" bvsgt" )
542
532
{
543
- op[0 ]=cast_bv_to_signed (op[0 ]);
544
- op[1 ]=cast_bv_to_signed (op[1 ]);
545
- return binary_predicate (ID_gt, op);
533
+ return binary_predicate (ID_gt, cast_bv_to_signed (op));
546
534
}
547
535
else if (id==" bvashr" )
548
536
{
549
- op[0 ]=cast_bv_to_signed (op[0 ]);
550
- op[1 ]=cast_bv_to_signed (op[1 ]);
551
- return cast_bv_to_unsigned (binary (ID_ashr, op));
537
+ return cast_bv_to_unsigned (binary (ID_ashr, cast_bv_to_signed (op)));
552
538
}
553
539
else if (id==" bvlshr" || id==" bvshr" )
554
540
{
@@ -608,9 +594,7 @@ exprt smt2_parsert::function_application()
608
594
}
609
595
else if (id==" bvsdiv" )
610
596
{
611
- op[0 ]=cast_bv_to_signed (op[0 ]);
612
- op[1 ]=cast_bv_to_signed (op[1 ]);
613
- return cast_bv_to_unsigned (binary (ID_div, op));
597
+ return cast_bv_to_unsigned (binary (ID_div, cast_bv_to_signed (op)));
614
598
}
615
599
else if (id==" bvudiv" )
616
600
{
@@ -624,17 +608,13 @@ exprt smt2_parsert::function_application()
624
608
{
625
609
// 2's complement signed remainder (sign follows dividend)
626
610
// This matches our ID_mod, and what C does since C99.
627
- op[0 ]=cast_bv_to_signed (op[0 ]);
628
- op[1 ]=cast_bv_to_signed (op[1 ]);
629
- return cast_bv_to_unsigned (binary (ID_mod, op));
611
+ return cast_bv_to_unsigned (binary (ID_mod, cast_bv_to_signed (op)));
630
612
}
631
613
else if (id==" bvsmod" )
632
614
{
633
615
// 2's complement signed remainder (sign follows divisor)
634
616
// We don't have that.
635
- op[0 ]=cast_bv_to_signed (op[0 ]);
636
- op[1 ]=cast_bv_to_signed (op[1 ]);
637
- return cast_bv_to_unsigned (binary (ID_mod, op));
617
+ return cast_bv_to_unsigned (binary (ID_mod, cast_bv_to_signed (op)));
638
618
}
639
619
else if (id==" bvurem" || id==" %" )
640
620
{
0 commit comments