@@ -27,6 +27,7 @@ Author: Daniel Kroening, kroening@kroening.com
2727#include < util/namespace.h>
2828#include < util/pointer_expr.h>
2929#include < util/pointer_offset_size.h>
30+ #include < util/prefix.h>
3031#include < util/range.h>
3132#include < util/simplify_expr.h>
3233#include < util/std_expr.h>
@@ -3051,6 +3052,11 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
30513052 else if (expr_type.id ()==ID_rational)
30523053 {
30533054 std::string value=id2string (expr.get_value ());
3055+ const bool negative = has_prefix (value, " -" );
3056+
3057+ if (negative)
3058+ out << " (- " ;
3059+
30543060 size_t pos=value.find (" /" );
30553061
30563062 if (pos==std::string::npos)
@@ -3060,10 +3066,19 @@ void smt2_convt::convert_constant(const constant_exprt &expr)
30603066 out << " (/ " << value.substr (0 , pos) << " .0 "
30613067 << value.substr (pos+1 ) << " .0)" ;
30623068 }
3069+
3070+ if (negative)
3071+ out << ' )' ;
30633072 }
30643073 else if (expr_type.id ()==ID_integer)
30653074 {
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;
30673082 }
30683083 else
30693084 UNEXPECTEDCASE (" unknown constant: " +expr_type.id_string ());
0 commit comments