Skip to content

Commit

Permalink
Merge pull request #8123 from diffblue/smt2-assumptions
Browse files Browse the repository at this point in the history
SMT2: simplify interface
  • Loading branch information
tautschnig authored Feb 7, 2024
2 parents 3dcf5f9 + d656764 commit 547b1a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/solvers/smt2/smt2_conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void smt2_convt::write_footer()
{
out << "(check-sat-assuming (";
for(const auto &assumption : assumptions)
convert_literal(to_literal_expr(assumption).get_literal());
convert_literal(assumption);
out << "))\n";
}
else
Expand All @@ -227,7 +227,7 @@ void smt2_convt::write_footer()
for(const auto &assumption : assumptions)
{
out << "(assert ";
convert_literal(to_literal_expr(assumption).get_literal());
convert_literal(assumption);
out << ")"
<< "\n";
}
Expand Down Expand Up @@ -323,7 +323,7 @@ decision_proceduret::resultt smt2_convt::dec_solve(const exprt &assumption)
write_footer();
else
{
assumptions.push_back(literal_exprt(convert(assumption)));
assumptions.push_back(convert(assumption));
write_footer();
assumptions.pop_back();
}
Expand Down Expand Up @@ -987,7 +987,9 @@ void smt2_convt::push(const std::vector<exprt> &_assumptions)
{
INVARIANT(assumptions.empty(), "nested contexts are not supported");

assumptions = _assumptions;
assumptions.reserve(_assumptions.size());
for(auto &assumption : _assumptions)
assumptions.push_back(convert(assumption));
}

void smt2_convt::pop()
Expand Down
2 changes: 1 addition & 1 deletion src/solvers/smt2/smt2_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class smt2_convt : public stack_decision_proceduret
unordered_map<irep_idt, std::function<void(const exprt &)>, irep_id_hash>;
converterst converters;

std::vector<exprt> assumptions;
std::vector<literalt> assumptions;
boolbv_widtht boolbv_width;

std::size_t number_of_solver_calls = 0;
Expand Down
9 changes: 9 additions & 0 deletions src/solvers/smt2/smt2_dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,21 @@ decision_proceduret::resultt smt2_dect::dec_solve(const exprt &assumption)
temp_file_stderr("smt2_dec_stderr_", "");

const auto write_problem_to_file = [&](std::ofstream problem_out) {
if(assumption.is_not_nil())
assumptions.push_back(convert(assumption));

cached_output << stringstream.str();
stringstream.str(std::string{});

write_footer();

if(assumption.is_not_nil())
assumptions.pop_back();

problem_out << cached_output.str() << stringstream.str();
stringstream.str(std::string{});
};

write_problem_to_file(std::ofstream(
temp_file_problem(), std::ios_base::out | std::ios_base::trunc));

Expand Down

0 comments on commit 547b1a8

Please sign in to comment.