27
27
#include < util/namespace.h>
28
28
#include < util/pointer_expr.h>
29
29
#include < util/pointer_offset_size.h>
30
+ #include < util/prefix.h>
30
31
#include < util/range.h>
31
32
#include < util/simplify_expr.h>
32
33
#include < util/std_expr.h>
@@ -3051,6 +3052,11 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
3051
3052
else if (expr_type.id ()==ID_rational)
3052
3053
{
3053
3054
std::string value=id2string (expr.get_value ());
3055
+ const bool negative = has_prefix (value, " -" );
3056
+
3057
+ if (negative)
3058
+ out << " (- " ;
3059
+
3054
3060
size_t pos=value.find (" /" );
3055
3061
3056
3062
if (pos==std::string::npos)
@@ -3060,10 +3066,19 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
3060
3066
out << " (/ " << value.substr (0 , pos) << " .0 "
3061
3067
<< value.substr (pos+1 ) << " .0)" ;
3062
3068
}
3069
+
3070
+ if (negative)
3071
+ out << ' )' ;
3063
3072
}
3064
3073
else if (expr_type.id ()==ID_integer)
3065
3074
{
3066
- out << expr.get_value ();
3075
+ const auto value = id2string (expr.get_value ());
3076
+
3077
+ // SMT2 has no negative integer literals
3078
+ if (has_prefix (value, " -" ))
3079
+ out << " (- " << value.substr (1 , std::string::npos) << ' )' ;
3080
+ else
3081
+ out << value;
3067
3082
}
3068
3083
else
3069
3084
UNEXPECTEDCASE (" unknown constant: " +expr_type.id_string ());
0 commit comments