[ExportSMTLIB] Fix printing of too many closing parentheses

The number of open parentheses should not be propagated to quantifier bodies and the first child expression of 'let' which declares the bound variable
This commit is contained in:
Martin Erhart 2024-04-20 09:21:17 +02:00
parent b4b4a7b6b1
commit 3a08dce574
4 changed files with 28 additions and 5 deletions

View File

@ -20,4 +20,4 @@ smt.solver () : () -> () {
// CHECK-NOT: ERROR // CHECK-NOT: ERROR
// CHECK-NOT: error // CHECK-NOT: error
// CHECK-NOT: unsat // CHECK-NOT: unsat
// CHECK: sat // CHECK: sat

View File

@ -158,7 +158,7 @@ struct ExpressionVisitor
info.stream << "(let ((" << name << " "; info.stream << "(let ((" << name << " ";
VisitorInfo newInfo(info.stream, info.valueMap, VisitorInfo newInfo(info.stream, info.valueMap,
info.indentLevel + 7 + name.size(), info.openParens); info.indentLevel + 8 + name.size(), 0);
if (failed(Base::dispatchSMTOpVisitor(op, newInfo))) if (failed(Base::dispatchSMTOpVisitor(op, newInfo)))
return failure(); return failure();
@ -332,14 +332,14 @@ struct ExpressionVisitor
worklist.push_back(yieldedValue); worklist.push_back(yieldedValue);
unsigned indentExt = operatorString.size() + 2; unsigned indentExt = operatorString.size() + 2;
VisitorInfo newInfo(info.stream, info.valueMap, VisitorInfo newInfo(info.stream, info.valueMap,
info.indentLevel + indentExt, info.openParens); info.indentLevel + indentExt, 0);
newInfo.stream.indent(newInfo.indentLevel); newInfo.stream.indent(newInfo.indentLevel);
if (failed(printExpression(worklist, newInfo))) if (failed(printExpression(worklist, newInfo)))
return failure(); return failure();
info.stream << info.valueMap.lookup(yieldedValue); info.stream << info.valueMap.lookup(yieldedValue);
for (int j = 0; j < newInfo.openParens; ++j) for (unsigned j = 0; j < newInfo.openParens; ++j)
info.stream << ")"; info.stream << ")";
if (weight != 0) if (weight != 0)

View File

@ -52,4 +52,4 @@ smt.solver () : () -> () {
// CHECK: (reset) // CHECK: (reset)
// CHECK-INLINED: (reset) // CHECK-INLINED: (reset)
} }

View File

@ -89,6 +89,29 @@ smt.solver () : () -> () {
} }
smt.assert %2 smt.assert %2
// Test: make sure that open parens from outside quantifier bodies are not
// propagated into the body.
// CHECK: (assert (let (([[V15:.+]] (exists (([[V16:.+]] Int) ([[V17:.+]] Int)){{$}}
// CHECK: (let (([[V18:.+]] (= [[V16]] [[V17]]))){{$}}
// CHECK: [[V18]])))){{$}}
// CHECK: (let (([[V19:.+]] (exists (([[V20:.+]] Int) ([[V21:.+]] Int)){{$}}
// CHECK: (let (([[V22:.+]] (= [[V20]] [[V21]]))){{$}}
// CHECK: [[V22]])))){{$}}
// CHECK: (let (([[V23:.+]] (and [[V19]] [[V15]]))){{$}}
// CHECK: [[V23]])))){{$}}
%3 = smt.exists {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%5 = smt.eq %arg2, %arg3 : !smt.int
smt.yield %5 : !smt.bool
}
%5 = smt.exists {
^bb0(%arg2: !smt.int, %arg3: !smt.int):
%6 = smt.eq %arg2, %arg3 : !smt.int
smt.yield %6 : !smt.bool
}
%6 = smt.and %3, %5
smt.assert %6
// CHECK: (check-sat) // CHECK: (check-sat)
// CHECK-INLINED: (check-sat) // CHECK-INLINED: (check-sat)
smt.check sat {} unknown {} unsat {} smt.check sat {} unknown {} unsat {}