std::stringstream d_stream;
};
+class CVC4ApiRecoverableExceptionStream
+{
+ public:
+ CVC4ApiRecoverableExceptionStream() {}
+ /* Note: This needs to be explicitly set to 'noexcept(false)' since it is
+ * a destructor that throws an exception and in C++11 all destructors
+ * default to noexcept(true) (else this triggers a call to std::terminate). */
+ ~CVC4ApiRecoverableExceptionStream() noexcept(false)
+ {
+ if (!std::uncaught_exception())
+ {
+ throw CVC4ApiRecoverableException(d_stream.str());
+ }
+ }
+
+ std::ostream& ostream() { return d_stream; }
+
+ private:
+ std::stringstream d_stream;
+};
+
#define CVC4_API_CHECK(cond) \
CVC4_PREDICT_TRUE(cond) \
? (void)0 : OstreamVoider() & CVC4ApiExceptionStream().ostream()
+#define CVC4_API_RECOVERABLE_CHECK(cond) \
+ CVC4_PREDICT_TRUE(cond) \
+ ? (void)0 : OstreamVoider() & CVC4ApiRecoverableExceptionStream().ostream()
+
#define CVC4_API_CHECK_NOT_NULL \
CVC4_API_CHECK(!isNullHelper()) \
<< "Invalid call to '" << __PRETTY_FUNCTION__ \
CVC4_API_CHECK(d_smtEngine->getOptions()[options::unsatCores])
<< "Cannot get unsat core unless explicitly enabled "
"(try --produce-unsat-cores)";
- CVC4_API_CHECK(d_smtEngine->getSmtMode() == SmtMode::UNSAT)
+ CVC4_API_RECOVERABLE_CHECK(d_smtEngine->getSmtMode() == SmtMode::UNSAT)
<< "Cannot get unsat core unless in unsat mode.";
UnsatCore core = d_smtEngine->getUnsatCore();
/* Can not use
{
NodeManager* nm = solver->getNodeManager();
smt::SmtScope scope(solver->getSmtEngine());
- std::vector<Node> result;
- for (const Expr& e :
- solver->getSmtEngine()->getValues(api::termVectorToExprs(d_terms)))
- {
- result.push_back(Node::fromExpr(e));
- }
+ std::vector<Node> result =
+ api::termVectorToNodes(solver->getValue(d_terms));
Assert(result.size() == d_terms.size());
for (int i = 0, size = d_terms.size(); i < size; i++)
{
d_result = api::Term(solver, nm->mkNode(kind::SEXPR, result));
d_commandStatus = CommandSuccess::instance();
}
- catch (RecoverableModalException& e)
+ catch (api::CVC4ApiRecoverableException& e)
{
d_commandStatus = new CommandRecoverableFailure(e.what());
}
{
try
{
- std::vector<std::pair<Expr, Expr>> assignments =
- solver->getSmtEngine()->getAssignment();
+ std::vector<std::pair<api::Term, api::Term>> assignments =
+ solver->getAssignment();
vector<SExpr> sexprs;
for (const auto& p : assignments)
{
d_result = SExpr(sexprs);
d_commandStatus = CommandSuccess::instance();
}
- catch (RecoverableModalException& e)
+ catch (api::CVC4ApiRecoverableException& e)
{
d_commandStatus = new CommandRecoverableFailure(e.what());
}
/* class GetModelCommand */
/* -------------------------------------------------------------------------- */
-GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
+GetModelCommand::GetModelCommand() : d_result(nullptr) {}
void GetModelCommand::invoke(api::Solver* solver)
{
try
{
d_result = solver->getSmtEngine()->getModel();
- d_smtEngine = solver->getSmtEngine();
d_commandStatus = CommandSuccess::instance();
}
catch (RecoverableModalException& e)
{
GetModelCommand* c = new GetModelCommand();
c->d_result = d_result;
- c->d_smtEngine = d_smtEngine;
return c;
}
/* class GetSynthSolutionCommand */
/* -------------------------------------------------------------------------- */
-GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
+GetSynthSolutionCommand::GetSynthSolutionCommand() : d_solver(nullptr) {}
void GetSynthSolutionCommand::invoke(api::Solver* solver)
{
try
{
- d_smtEngine = solver->getSmtEngine();
+ d_solver = solver;
d_commandStatus = CommandSuccess::instance();
}
catch (exception& e)
}
else
{
- d_smtEngine->printSynthSolution(out);
+ d_solver->printSynthSolution(out);
}
}
Command* GetSynthSolutionCommand::clone() const
{
GetSynthSolutionCommand* c = new GetSynthSolutionCommand();
- c->d_smtEngine = d_smtEngine;
+ c->d_solver = d_solver;
return c;
}
d_result = solver->getUnsatAssumptions();
d_commandStatus = CommandSuccess::instance();
}
- catch (RecoverableModalException& e)
+ catch (api::CVC4ApiRecoverableException& e)
{
d_commandStatus = new CommandRecoverableFailure(e.what());
}
{
try
{
- d_result = solver->getSmtEngine()->getUnsatCore();
+ d_result = UnsatCore(solver->getSmtEngine(),
+ api::termVectorToExprs(solver->getUnsatCore()));
+
d_commandStatus = CommandSuccess::instance();
}
- catch (RecoverableModalException& e)
+ catch (api::CVC4ApiRecoverableException& e)
{
d_commandStatus = new CommandRecoverableFailure(e.what());
}