@@ -354,6 +354,11 @@ inline bool can_cast_expr<unary_exprt>(const exprt &base)
354
354
return base.operands ().size () == 1 ;
355
355
}
356
356
357
+ inline void validate_expr (const unary_exprt &value)
358
+ {
359
+ validate_operands (value, 1 , " Unary expressions must have one operand" );
360
+ }
361
+
357
362
// / \brief Cast an exprt to a \ref unary_exprt
358
363
// /
359
364
// / \a expr must be known to be \ref unary_exprt.
@@ -774,6 +779,11 @@ inline bool can_cast_expr<binary_exprt>(const exprt &base)
774
779
return base.operands ().size () == 2 ;
775
780
}
776
781
782
+ inline void validate_expr (const binary_exprt &value)
783
+ {
784
+ validate_operands (value, 2 , " Binary expressions must have two operands" );
785
+ }
786
+
777
787
// / \brief Cast an exprt to a \ref binary_exprt
778
788
// /
779
789
// / \a expr must be known to be \ref binary_exprt.
@@ -912,6 +922,11 @@ inline bool can_cast_expr<binary_relation_exprt>(const exprt &base)
912
922
return can_cast_expr<binary_exprt>(base);
913
923
}
914
924
925
+ inline void validate_expr (const binary_relation_exprt &value)
926
+ {
927
+ validate_operands (value, 2 , " Binary relations must have two operands" );
928
+ }
929
+
915
930
// / \brief Cast an exprt to a \ref binary_relation_exprt
916
931
// /
917
932
// / \a expr must be known to be \ref binary_relation_exprt.
@@ -2657,10 +2672,10 @@ inline bool can_cast_expr<bitnot_exprt>(const exprt &base)
2657
2672
return base.id () == ID_bitnot;
2658
2673
}
2659
2674
2660
- // inline void validate_expr(const bitnot_exprt &value)
2661
- // {
2662
- // validate_operands(value, 1, "Bit-wise not must have one operand");
2663
- // }
2675
+ inline void validate_expr (const bitnot_exprt &value)
2676
+ {
2677
+ validate_operands (value, 1 , " Bit-wise not must have one operand" );
2678
+ }
2664
2679
2665
2680
// / \brief Cast an exprt to a \ref bitnot_exprt
2666
2681
// /
@@ -2671,17 +2686,17 @@ inline bool can_cast_expr<bitnot_exprt>(const exprt &base)
2671
2686
inline const bitnot_exprt &to_bitnot_expr (const exprt &expr)
2672
2687
{
2673
2688
PRECONDITION (expr.id ()==ID_bitnot);
2674
- // DATA_INVARIANT(expr.operands().size()==1,
2675
- // "Bit-wise not must have one operand");
2689
+ DATA_INVARIANT (
2690
+ expr. operands (). size () == 1 , " Bit-wise not must have one operand" );
2676
2691
return static_cast <const bitnot_exprt &>(expr);
2677
2692
}
2678
2693
2679
2694
// / \copydoc to_bitnot_expr(const exprt &)
2680
2695
inline bitnot_exprt &to_bitnot_expr (exprt &expr)
2681
2696
{
2682
2697
PRECONDITION (expr.id ()==ID_bitnot);
2683
- // DATA_INVARIANT(expr.operands().size()==1,
2684
- // "Bit-wise not must have one operand");
2698
+ DATA_INVARIANT (
2699
+ expr. operands (). size () == 1 , " Bit-wise not must have one operand" );
2685
2700
return static_cast <bitnot_exprt &>(expr);
2686
2701
}
2687
2702
@@ -2900,13 +2915,16 @@ class shift_exprt:public binary_exprt
2900
2915
}
2901
2916
};
2902
2917
2903
- // The to_*_expr function for this type doesn't do any checks before casting,
2904
- // therefore the implementation is essentially a static_cast.
2905
- // Enabling expr_dynamic_cast would hide this; instead use static_cast directly.
2906
- // inline void validate_expr(const shift_exprt &value)
2907
- // {
2908
- // validate_operands(value, 2, "Shifts must have two operands");
2909
- // }
2918
+ template <>
2919
+ inline bool can_cast_expr<shift_exprt>(const exprt &base)
2920
+ {
2921
+ return base.id () == ID_shl || base.id () == ID_ashr || base.id () == ID_lshr;
2922
+ }
2923
+
2924
+ inline void validate_expr (const shift_exprt &value)
2925
+ {
2926
+ validate_operands (value, 2 , " Shifts must have two operands" );
2927
+ }
2910
2928
2911
2929
// / \brief Cast an exprt to a \ref shift_exprt
2912
2930
// /
@@ -3516,6 +3534,8 @@ inline bool can_cast_expr<with_exprt>(const exprt &base)
3516
3534
3517
3535
inline void validate_expr (const with_exprt &value)
3518
3536
{
3537
+ validate_operands (
3538
+ value, 3 , " array/structure update must have at least 3 operands" , true );
3519
3539
DATA_INVARIANT (
3520
3540
value.operands ().size () % 2 == 1 ,
3521
3541
" array/structure update must have an odd number of operands" );
@@ -4286,18 +4306,18 @@ class ieee_float_op_exprt : public ternary_exprt
4286
4306
}
4287
4307
};
4288
4308
4289
- // The to_*_expr function for this type doesn't do any checks before casting,
4290
- // therefore the implementation is essentially a static_cast.
4291
- // Enabling expr_dynamic_cast would hide this; instead use static_cast directly.
4292
- // template<>
4293
- // inline void validate_expr<ieee_float_op_exprt>(
4294
- // const ieee_float_op_exprt &value)
4295
- // {
4296
- // validate_operands(
4297
- // value,
4298
- // 3,
4299
- // "IEEE float operations must have three arguments");
4300
- // }
4309
+ template <>
4310
+ inline bool can_cast_expr<ieee_float_op_exprt>( const exprt &base)
4311
+ {
4312
+ return base. id () == ID_floatbv_plus || base. id () == ID_floatbv_minus ||
4313
+ base. id () == ID_floatbv_div || base. id () == ID_floatbv_mult;
4314
+ }
4315
+
4316
+ inline void validate_expr ( const ieee_float_op_exprt &value)
4317
+ {
4318
+ validate_operands (
4319
+ value, 3 , " IEEE float operations must have three arguments" );
4320
+ }
4301
4321
4302
4322
// / \brief Cast an exprt to an \ref ieee_float_op_exprt
4303
4323
// /
@@ -4748,6 +4768,18 @@ class cond_exprt : public multi_ary_exprt
4748
4768
}
4749
4769
};
4750
4770
4771
+ template <>
4772
+ inline bool can_cast_expr<cond_exprt>(const exprt &base)
4773
+ {
4774
+ return base.id () == ID_cond;
4775
+ }
4776
+
4777
+ inline void validate_expr (const cond_exprt &value)
4778
+ {
4779
+ DATA_INVARIANT (
4780
+ value.operands ().size () % 2 == 0 , " cond must have even number of operands" );
4781
+ }
4782
+
4751
4783
// / \brief Cast an exprt to a \ref cond_exprt
4752
4784
// /
4753
4785
// / \a expr must be known to be \ref cond_exprt.
0 commit comments