@@ -189,6 +189,15 @@ exprt smt2_convt::get(const exprt &expr) const
189
189
if (it!=identifier_map.end ())
190
190
return it->second .value ;
191
191
}
192
+ else if (expr.id ()==ID_nondet_symbol)
193
+ {
194
+ const irep_idt &id=to_nondet_symbol_expr (expr).get_identifier ();
195
+
196
+ identifier_mapt::const_iterator it=identifier_map.find (id);
197
+
198
+ if (it!=identifier_map.end ())
199
+ return it->second .value ;
200
+ }
192
201
else if (expr.id ()==ID_member)
193
202
{
194
203
const member_exprt &member_expr=to_member_expr (expr);
@@ -239,7 +248,15 @@ constant_exprt smt2_convt::parse_literal(
239
248
value=string2integer (s.substr (2 ), 16 );
240
249
}
241
250
else
242
- PARSERERROR (" smt2_convt::parse_literal can't parse \" " +s+" \" " );
251
+ {
252
+ // Numeral
253
+ value=string2integer (s);
254
+ }
255
+ }
256
+ else if (src.get_sub ().size ()==2 &&
257
+ src.get_sub ()[0 ].id ()==" -" ) // (- 100)
258
+ {
259
+ value=-string2integer (src.get_sub ()[1 ].id_string ());
243
260
}
244
261
else if (src.get_sub ().size ()==3 &&
245
262
src.get_sub ()[0 ].id ()==" _" &&
@@ -433,6 +450,9 @@ exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
433
450
434
451
if (type.id ()==ID_signedbv ||
435
452
type.id ()==ID_unsignedbv ||
453
+ type.id ()==ID_integer ||
454
+ type.id ()==ID_rational ||
455
+ type.id ()==ID_real ||
436
456
type.id ()==ID_bv ||
437
457
type.id ()==ID_fixedbv ||
438
458
type.id ()==ID_floatbv)
@@ -970,7 +990,9 @@ void smt2_convt::convert_expr(const exprt &expr)
970
990
{
971
991
assert (expr.operands ().size ()==1 );
972
992
973
- if (expr.type ().id ()==ID_rational)
993
+ if (expr.type ().id ()==ID_rational ||
994
+ expr.type ().id ()==ID_integer ||
995
+ expr.type ().id ()==ID_real)
974
996
{
975
997
out << " (- " ;
976
998
convert_expr (expr.op0 ());
@@ -1816,7 +1838,8 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
1816
1838
src_type.id ()==ID_unsignedbv ||
1817
1839
src_type.id ()==ID_c_bool ||
1818
1840
src_type.id ()==ID_fixedbv ||
1819
- src_type.id ()==ID_pointer)
1841
+ src_type.id ()==ID_pointer ||
1842
+ src_type.id ()==ID_integer)
1820
1843
{
1821
1844
out << " (not (= " ;
1822
1845
convert_expr (src);
@@ -2261,6 +2284,17 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
2261
2284
else
2262
2285
UNEXPECTEDCASE (" Unknown typecast " +src_type.id_string ()+" -> float" );
2263
2286
}
2287
+ else if (dest_type.id ()==ID_integer)
2288
+ {
2289
+ if (src_type.id ()==ID_bool)
2290
+ {
2291
+ out << " (ite " ;
2292
+ convert_expr (src);
2293
+ out <<" 1 0)" ;
2294
+ }
2295
+ else
2296
+ UNEXPECTEDCASE (" Unknown typecast " +src_type.id_string ()+" -> integer" );
2297
+ }
2264
2298
else if (dest_type.id ()==ID_c_bit_field)
2265
2299
{
2266
2300
std::size_t from_width=boolbv_width (src_type);
@@ -2847,19 +2881,41 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
2847
2881
{
2848
2882
convert_expr (expr.op0 ());
2849
2883
}
2850
- else if (expr. operands (). size ()== 2 )
2884
+ else
2851
2885
{
2852
- if (expr.type ().id ()==ID_unsignedbv ||
2853
- expr.type ().id ()==ID_signedbv ||
2854
- expr.type ().id ()==ID_fixedbv)
2886
+ if (expr.type ().id ()==ID_rational ||
2887
+ expr.type ().id ()==ID_integer ||
2888
+ expr.type ().id ()==ID_real)
2889
+ {
2890
+ // these are multi-ary in SMT-LIB2
2891
+ out << " (+" ;
2892
+
2893
+ for (const auto &op : expr.operands ())
2894
+ {
2895
+ out << ' ' ;
2896
+ convert_expr (op);
2897
+ }
2898
+
2899
+ out << ' )' ;
2900
+ }
2901
+ else if (expr.type ().id ()==ID_unsignedbv ||
2902
+ expr.type ().id ()==ID_signedbv ||
2903
+ expr.type ().id ()==ID_fixedbv)
2855
2904
{
2856
2905
// These could be chained, i.e., need not be binary,
2857
2906
// but at least MathSat doesn't like that.
2858
- out << " (bvadd " ;
2859
- convert_expr (expr.op0 ());
2860
- out << " " ;
2861
- convert_expr (expr.op1 ());
2862
- out << " )" ;
2907
+ if (expr.operands ().size ()==2 )
2908
+ {
2909
+ out << " (bvadd " ;
2910
+ convert_expr (expr.op0 ());
2911
+ out << " " ;
2912
+ convert_expr (expr.op1 ());
2913
+ out << " )" ;
2914
+ }
2915
+ else
2916
+ {
2917
+ convert_plus (to_plus_expr (make_binary (expr)));
2918
+ }
2863
2919
}
2864
2920
else if (expr.type ().id ()==ID_floatbv)
2865
2921
{
@@ -2870,41 +2926,40 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
2870
2926
}
2871
2927
else if (expr.type ().id ()==ID_pointer)
2872
2928
{
2873
- exprt p=expr.op0 (), i=expr.op1 ();
2929
+ if (expr.operands ().size ()==2 )
2930
+ {
2931
+ exprt p=expr.op0 (), i=expr.op1 ();
2874
2932
2875
- if (p.type ().id ()!=ID_pointer)
2876
- p.swap (i);
2933
+ if (p.type ().id ()!=ID_pointer)
2934
+ p.swap (i);
2877
2935
2878
- if (p.type ().id ()!=ID_pointer)
2879
- INVALIDEXPR (" unexpected mixture in pointer arithmetic" );
2936
+ if (p.type ().id ()!=ID_pointer)
2937
+ INVALIDEXPR (" unexpected mixture in pointer arithmetic" );
2880
2938
2881
- mp_integer element_size=
2882
- pointer_offset_size (expr.type ().subtype (), ns);
2883
- assert (element_size>0 );
2939
+ mp_integer element_size=
2940
+ pointer_offset_size (expr.type ().subtype (), ns);
2941
+ CHECK_RETURN (element_size>0 );
2884
2942
2885
- out << " (bvadd " ;
2886
- convert_expr (p);
2887
- out << " " ;
2943
+ out << " (bvadd " ;
2944
+ convert_expr (p);
2945
+ out << " " ;
2888
2946
2889
- if (element_size>=2 )
2890
- {
2891
- out << " (bvmul " ;
2892
- convert_expr (i);
2893
- out << " (_ bv" << element_size
2894
- << " " << boolbv_width (expr.type ()) << " ))" ;
2947
+ if (element_size>=2 )
2948
+ {
2949
+ out << " (bvmul " ;
2950
+ convert_expr (i);
2951
+ out << " (_ bv" << element_size
2952
+ << " " << boolbv_width (expr.type ()) << " ))" ;
2953
+ }
2954
+ else
2955
+ convert_expr (i);
2956
+
2957
+ out << ' )' ;
2895
2958
}
2896
2959
else
2897
- convert_expr (i);
2898
-
2899
- out << " )" ;
2900
- }
2901
- else if (expr.type ().id ()==ID_rational)
2902
- {
2903
- out << " (+" ;
2904
- convert_expr (expr.op0 ());
2905
- out << " " ;
2906
- convert_expr (expr.op1 ());
2907
- out << " )" ;
2960
+ {
2961
+ convert_plus (to_plus_expr (make_binary (expr)));
2962
+ }
2908
2963
}
2909
2964
else if (expr.type ().id ()==ID_vector)
2910
2965
{
@@ -2948,10 +3003,6 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
2948
3003
else
2949
3004
UNEXPECTEDCASE (" unsupported type for +: " +expr.type ().id_string ());
2950
3005
}
2951
- else
2952
- {
2953
- convert_plus (to_plus_expr (make_binary (expr)));
2954
- }
2955
3006
}
2956
3007
2957
3008
// / Converting a constant or symbolic rounding mode to SMT-LIB. Only called when
@@ -3054,7 +3105,15 @@ void smt2_convt::convert_minus(const minus_exprt &expr)
3054
3105
{
3055
3106
assert (expr.operands ().size ()==2 );
3056
3107
3057
- if (expr.type ().id ()==ID_unsignedbv ||
3108
+ if (expr.type ().id ()==ID_integer)
3109
+ {
3110
+ out << " (- " ;
3111
+ convert_expr (expr.op0 ());
3112
+ out << " " ;
3113
+ convert_expr (expr.op1 ());
3114
+ out << " )" ;
3115
+ }
3116
+ else if (expr.type ().id ()==ID_unsignedbv ||
3058
3117
expr.type ().id ()==ID_signedbv ||
3059
3118
expr.type ().id ()==ID_fixedbv)
3060
3119
{
@@ -3285,7 +3344,9 @@ void smt2_convt::convert_mult(const mult_exprt &expr)
3285
3344
3286
3345
out << " ))" ; // bvmul, extract
3287
3346
}
3288
- else if (expr.type ().id ()==ID_rational)
3347
+ else if (expr.type ().id ()==ID_rational ||
3348
+ expr.type ().id ()==ID_integer ||
3349
+ expr.type ().id ()==ID_real)
3289
3350
{
3290
3351
out << " (*" ;
3291
3352
@@ -4378,7 +4439,8 @@ void smt2_convt::convert_type(const typet &type)
4378
4439
out << " (_ BitVec "
4379
4440
<< floatbv_type.get_width () << " )" ;
4380
4441
}
4381
- else if (type.id ()==ID_rational)
4442
+ else if (type.id ()==ID_rational ||
4443
+ type.id ()==ID_real)
4382
4444
out << " Real" ;
4383
4445
else if (type.id ()==ID_integer)
4384
4446
out << " Int" ;
0 commit comments