@@ -82,6 +82,7 @@ class smv_typecheckt:public typecheckt
82
82
void convert (smv_parse_treet::modulet::itemt &);
83
83
void typecheck (smv_parse_treet::modulet::itemt &);
84
84
void typecheck_expr_rec (exprt &, const typet &, modet);
85
+ void convert_expr_to (exprt &, const typet &dest);
85
86
86
87
smv_parse_treet::modulet *modulep;
87
88
@@ -581,7 +582,7 @@ Function: smv_typecheckt::typecheck_expr_rec
581
582
582
583
void smv_typecheckt::typecheck_expr_rec (
583
584
exprt &expr,
584
- const typet &type ,
585
+ const typet &dest_type ,
585
586
modet mode)
586
587
{
587
588
const auto static nil_type = static_cast <const typet &>(get_nil_irep ());
@@ -631,12 +632,12 @@ void smv_typecheckt::typecheck_expr_rec(
631
632
}
632
633
else if (expr.id ()==ID_nondet_symbol)
633
634
{
634
- if (!type .is_nil ())
635
- expr.type ()=type ;
635
+ if (!dest_type .is_nil ())
636
+ expr.type () = dest_type ;
636
637
}
637
638
else if (expr.id ()==ID_constraint_select_one)
638
639
{
639
- typecheck_op (expr, type , mode);
640
+ typecheck_op (expr, dest_type , mode);
640
641
641
642
typet op_type;
642
643
op_type.make_nil ();
@@ -702,23 +703,23 @@ void smv_typecheckt::typecheck_expr_rec(
702
703
auto &true_case = if_expr.true_case ();
703
704
auto &false_case = if_expr.false_case ();
704
705
typecheck_expr_rec (if_expr.cond (), bool_typet{}, mode);
705
- typecheck_expr_rec (true_case, type , mode);
706
- typecheck_expr_rec (false_case, type , mode);
707
- expr.type () = type ;
706
+ typecheck_expr_rec (true_case, dest_type , mode);
707
+ typecheck_expr_rec (false_case, dest_type , mode);
708
+ expr.type () = dest_type ;
708
709
}
709
710
else if (expr.id ()==ID_plus || expr.id ()==ID_minus ||
710
711
expr.id ()==ID_mult || expr.id ()==ID_div ||
711
712
expr.id ()==ID_mod)
712
713
{
713
- typecheck_op (expr, type , mode);
714
-
714
+ typecheck_op (expr, dest_type , mode);
715
+
715
716
if (expr.operands ().size ()!=2 )
716
717
{
717
718
throw errort ().with_location (expr.find_source_location ())
718
719
<< " Expected two operands for " << expr.id ();
719
720
}
720
-
721
- if (type .is_nil ())
721
+
722
+ if (dest_type .is_nil ())
722
723
{
723
724
if (expr.type ().id ()==ID_range ||
724
725
expr.type ().id ()==ID_bool)
@@ -745,7 +746,7 @@ void smv_typecheckt::typecheck_expr_rec(
745
746
new_range.to_type (expr.type ());
746
747
}
747
748
}
748
- else if (type .id ()!= ID_range)
749
+ else if (dest_type .id () != ID_range)
749
750
{
750
751
throw errort ().with_location (expr.find_source_location ())
751
752
<< " Expected number type for " << to_string (expr);
@@ -758,17 +759,17 @@ void smv_typecheckt::typecheck_expr_rec(
758
759
const std::string &value=expr.get_string (ID_value);
759
760
mp_integer int_value=string2integer (value);
760
761
761
- if (type .is_nil ())
762
+ if (dest_type .is_nil ())
762
763
{
763
764
expr.type ()=typet (ID_range);
764
765
expr.type ().set (ID_from, integer2string (int_value));
765
766
expr.type ().set (ID_to, integer2string (int_value));
766
767
}
767
768
else
768
769
{
769
- expr.type ()=type ;
770
+ expr.type () = dest_type ;
770
771
771
- if (type .id ()== ID_bool)
772
+ if (dest_type .id () == ID_bool)
772
773
{
773
774
if (int_value==0 )
774
775
expr=false_exprt ();
@@ -780,9 +781,9 @@ void smv_typecheckt::typecheck_expr_rec(
780
781
<< " expected 0 or 1 here, but got " << value;
781
782
}
782
783
}
783
- else if (type .id ()== ID_range)
784
+ else if (dest_type .id () == ID_range)
784
785
{
785
- smv_ranget smv_range= convert_type (type );
786
+ smv_ranget smv_range = convert_type (dest_type );
786
787
787
788
if (int_value<smv_range.from || int_value>smv_range.to )
788
789
{
@@ -800,13 +801,13 @@ void smv_typecheckt::typecheck_expr_rec(
800
801
}
801
802
else if (expr.type ().id ()==ID_enumeration)
802
803
{
803
- if (type .id ()== ID_enumeration)
804
+ if (dest_type .id () == ID_enumeration)
804
805
{
805
806
if (to_enumeration_type (expr.type ()).elements ().empty ())
806
- expr.type ()=type ;
807
+ expr.type () = dest_type ;
807
808
}
808
809
}
809
- else if (type .is_not_nil () && type!= expr.type ())
810
+ else if (dest_type .is_not_nil () && dest_type != expr.type ())
810
811
{
811
812
// already done, but maybe need to change the type
812
813
mp_integer int_value;
@@ -825,21 +826,21 @@ void smv_typecheckt::typecheck_expr_rec(
825
826
826
827
if (have_int_value)
827
828
{
828
- if (type .id ()== ID_bool)
829
+ if (dest_type .id () == ID_bool)
829
830
{
830
831
if (int_value==0 )
831
832
expr=false_exprt ();
832
833
else if (int_value==1 )
833
834
expr=true_exprt ();
834
835
}
835
- else if (type .id ()== ID_range)
836
+ else if (dest_type .id () == ID_range)
836
837
{
837
- mp_integer from= string2integer (type .get_string (ID_from)),
838
- to= string2integer (type .get_string (ID_to));
838
+ mp_integer from = string2integer (dest_type .get_string (ID_from)),
839
+ to = string2integer (dest_type .get_string (ID_to));
839
840
840
841
if (int_value>=from && int_value<=to)
841
842
{
842
- expr= exprt (ID_constant, type );
843
+ expr = exprt (ID_constant, dest_type );
843
844
expr.set (ID_value, integer2string (int_value));
844
845
}
845
846
}
@@ -848,7 +849,7 @@ void smv_typecheckt::typecheck_expr_rec(
848
849
}
849
850
else if (expr.id ()==ID_cond)
850
851
{
851
- if (type .is_nil ())
852
+ if (dest_type .is_nil ())
852
853
{
853
854
bool condition=true ;
854
855
@@ -870,7 +871,7 @@ void smv_typecheckt::typecheck_expr_rec(
870
871
}
871
872
else
872
873
{
873
- expr.type ()=type ;
874
+ expr.type () = dest_type ;
874
875
875
876
bool condition=true ;
876
877
@@ -942,7 +943,27 @@ void smv_typecheckt::typecheck_expr_rec(
942
943
<< " No type checking for " << expr.id ();
943
944
}
944
945
945
- if (!type.is_nil () && expr.type ()!=type)
946
+ if (!dest_type.is_nil ())
947
+ convert_expr_to (expr, dest_type);
948
+ }
949
+
950
+ /* ******************************************************************\
951
+
952
+ Function: smv_typecheckt::convert_expr_to
953
+
954
+ Inputs:
955
+
956
+ Outputs:
957
+
958
+ Purpose:
959
+
960
+ \*******************************************************************/
961
+
962
+ void smv_typecheckt::convert_expr_to (exprt &expr, const typet &type)
963
+ {
964
+ PRECONDITION (type.is_not_nil ());
965
+
966
+ if (expr.type () != type)
946
967
{
947
968
smv_ranget e=convert_type (expr.type ());
948
969
smv_ranget t=convert_type (type);
0 commit comments