Skip to content

Commit 57ecf15

Browse files
author
Daniel Kroening
committed
+ is multi-ary in SMT-LIB2
1 parent 12ae728 commit 57ecf15

File tree

1 file changed

+58
-43
lines changed

1 file changed

+58
-43
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,19 +2860,41 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
28602860
{
28612861
convert_expr(expr.op0());
28622862
}
2863-
else if(expr.operands().size()==2)
2863+
else
28642864
{
2865-
if(expr.type().id()==ID_unsignedbv ||
2866-
expr.type().id()==ID_signedbv ||
2867-
expr.type().id()==ID_fixedbv)
2865+
if(expr.type().id()==ID_rational ||
2866+
expr.type().id()==ID_integer ||
2867+
expr.type().id()==ID_real)
2868+
{
2869+
// these are multi-ary in SMT-LIB2
2870+
out << "(+";
2871+
2872+
for(const auto &op : expr.operands())
2873+
{
2874+
out << ' ';
2875+
convert_expr(op);
2876+
}
2877+
2878+
out << ')';
2879+
}
2880+
else if(expr.type().id()==ID_unsignedbv ||
2881+
expr.type().id()==ID_signedbv ||
2882+
expr.type().id()==ID_fixedbv)
28682883
{
28692884
// These could be chained, i.e., need not be binary,
28702885
// but at least MathSat doesn't like that.
2871-
out << "(bvadd ";
2872-
convert_expr(expr.op0());
2873-
out << " ";
2874-
convert_expr(expr.op1());
2875-
out << ")";
2886+
if(expr.operands().size()==2)
2887+
{
2888+
out << "(bvadd ";
2889+
convert_expr(expr.op0());
2890+
out << " ";
2891+
convert_expr(expr.op1());
2892+
out << ")";
2893+
}
2894+
else
2895+
{
2896+
convert_plus(to_plus_expr(make_binary(expr)));
2897+
}
28762898
}
28772899
else if(expr.type().id()==ID_floatbv)
28782900
{
@@ -2883,43 +2905,40 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
28832905
}
28842906
else if(expr.type().id()==ID_pointer)
28852907
{
2886-
exprt p=expr.op0(), i=expr.op1();
2908+
if(expr.operands().size()==2)
2909+
{
2910+
exprt p=expr.op0(), i=expr.op1();
28872911

2888-
if(p.type().id()!=ID_pointer)
2889-
p.swap(i);
2912+
if(p.type().id()!=ID_pointer)
2913+
p.swap(i);
28902914

2891-
if(p.type().id()!=ID_pointer)
2892-
INVALIDEXPR("unexpected mixture in pointer arithmetic");
2915+
if(p.type().id()!=ID_pointer)
2916+
INVALIDEXPR("unexpected mixture in pointer arithmetic");
28932917

2894-
mp_integer element_size=
2895-
pointer_offset_size(expr.type().subtype(), ns);
2896-
assert(element_size>0);
2918+
mp_integer element_size=
2919+
pointer_offset_size(expr.type().subtype(), ns);
2920+
assert(element_size>0);
28972921

2898-
out << "(bvadd ";
2899-
convert_expr(p);
2900-
out << " ";
2922+
out << "(bvadd ";
2923+
convert_expr(p);
2924+
out << " ";
29012925

2902-
if(element_size>=2)
2903-
{
2904-
out << "(bvmul ";
2905-
convert_expr(i);
2906-
out << " (_ bv" << element_size
2907-
<< " " << boolbv_width(expr.type()) << "))";
2926+
if(element_size>=2)
2927+
{
2928+
out << "(bvmul ";
2929+
convert_expr(i);
2930+
out << " (_ bv" << element_size
2931+
<< " " << boolbv_width(expr.type()) << "))";
2932+
}
2933+
else
2934+
convert_expr(i);
2935+
2936+
out << ')';
29082937
}
29092938
else
2910-
convert_expr(i);
2911-
2912-
out << ")";
2913-
}
2914-
else if(expr.type().id()==ID_rational ||
2915-
expr.type().id()==ID_integer ||
2916-
expr.type().id()==ID_real)
2917-
{
2918-
out << "(+ ";
2919-
convert_expr(expr.op0());
2920-
out << " ";
2921-
convert_expr(expr.op1());
2922-
out << ")";
2939+
{
2940+
convert_plus(to_plus_expr(make_binary(expr)));
2941+
}
29232942
}
29242943
else if(expr.type().id()==ID_vector)
29252944
{
@@ -2963,10 +2982,6 @@ void smt2_convt::convert_plus(const plus_exprt &expr)
29632982
else
29642983
UNEXPECTEDCASE("unsupported type for +: "+expr.type().id_string());
29652984
}
2966-
else
2967-
{
2968-
convert_plus(to_plus_expr(make_binary(expr)));
2969-
}
29702985
}
29712986

29722987
/// Converting a constant or symbolic rounding mode to SMT-LIB. Only called when

0 commit comments

Comments
 (0)