Skip to content

Commit 12ae728

Browse files
author
Daniel Kroening
committed
fixes for integers in SMT2
This fixes output of formulas into SMT2 format that contain unbounded integers; conversely, values in satisfying assignments generated by SMT2 solvers that contain unbounded integers are now parsed.
1 parent 698ccdd commit 12ae728

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/goto-programs/goto_trace.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ std::string trace_value_binary(
143143
{
144144
return expr.is_true()?"1":"0";
145145
}
146+
else if(type.id()==ID_integer)
147+
{
148+
mp_integer i;
149+
if(!to_integer(expr, i) && i>=0)
150+
return integer2string(i, 2);
151+
}
146152
}
147153
else if(expr.id()==ID_array)
148154
{

src/solvers/smt2/smt2_conv.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ constant_exprt smt2_convt::parse_literal(
239239
value=string2integer(s.substr(2), 16);
240240
}
241241
else
242-
PARSERERROR("smt2_convt::parse_literal can't parse \""+s+"\"");
242+
{
243+
// Numeral
244+
value=string2integer(s);
245+
}
246+
}
247+
else if(src.get_sub().size()==2 &&
248+
src.get_sub()[0].id()=="-") // (- 100)
249+
{
250+
value=-string2integer(src.get_sub()[1].id_string());
243251
}
244252
else if(src.get_sub().size()==3 &&
245253
src.get_sub()[0].id()=="_" &&
@@ -433,6 +441,9 @@ exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
433441

434442
if(type.id()==ID_signedbv ||
435443
type.id()==ID_unsignedbv ||
444+
type.id()==ID_integer ||
445+
type.id()==ID_rational ||
446+
type.id()==ID_real ||
436447
type.id()==ID_bv ||
437448
type.id()==ID_fixedbv ||
438449
type.id()==ID_floatbv)
@@ -970,7 +981,9 @@ void smt2_convt::convert_expr(const exprt &expr)
970981
{
971982
assert(expr.operands().size()==1);
972983

973-
if(expr.type().id()==ID_rational)
984+
if(expr.type().id()==ID_rational ||
985+
expr.type().id()==ID_integer ||
986+
expr.type().id()==ID_real)
974987
{
975988
out << "(- ";
976989
convert_expr(expr.op0());
@@ -2898,9 +2911,11 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
28982911

28992912
out << ")";
29002913
}
2901-
else if(expr.type().id()==ID_rational)
2914+
else if(expr.type().id()==ID_rational ||
2915+
expr.type().id()==ID_integer ||
2916+
expr.type().id()==ID_real)
29022917
{
2903-
out << "(+";
2918+
out << "(+ ";
29042919
convert_expr(expr.op0());
29052920
out << " ";
29062921
convert_expr(expr.op1());
@@ -3285,7 +3300,9 @@ void smt2_convt::convert_mult(const mult_exprt &expr)
32853300

32863301
out << "))"; // bvmul, extract
32873302
}
3288-
else if(expr.type().id()==ID_rational)
3303+
else if(expr.type().id()==ID_rational ||
3304+
expr.type().id()==ID_integer ||
3305+
expr.type().id()==ID_real)
32893306
{
32903307
out << "(*";
32913308

@@ -4378,7 +4395,8 @@ void smt2_convt::convert_type(const typet &type)
43784395
out << "(_ BitVec "
43794396
<< floatbv_type.get_width() << ")";
43804397
}
4381-
else if(type.id()==ID_rational)
4398+
else if(type.id()==ID_rational ||
4399+
type.id()==ID_real)
43824400
out << "Real";
43834401
else if(type.id()==ID_integer)
43844402
out << "Int";

src/solvers/smt2/smt2_dec.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ decision_proceduret::resultt smt2_dect::read_result(std::istream &in)
198198
// Examples:
199199
// ( (B0 true) )
200200
// ( (|__CPROVER_pipe_count#1| (_ bv0 32)) )
201+
// ( (|some_integer| 0) )
202+
// ( (|some_integer| (- 10)) )
201203

202204
values[s0.id()]=s1;
203205
}

0 commit comments

Comments
 (0)