solidity/libsolidity/formal/SMTLib2Interface.h

80 lines
2.2 KiB
C
Raw Normal View History

2017-07-10 16:13:38 +00:00
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
2017-07-13 16:22:51 +00:00
#include <libsolidity/formal/SolverInterface.h>
2017-07-11 11:26:43 +00:00
#include <liblangutil/Exceptions.h>
2017-07-11 11:26:43 +00:00
#include <libsolidity/interface/ReadFile.h>
2017-07-10 19:21:11 +00:00
#include <libdevcore/Common.h>
2017-07-11 11:26:43 +00:00
#include <boost/noncopyable.hpp>
2017-07-10 16:13:38 +00:00
#include <map>
#include <string>
#include <vector>
2017-07-10 19:21:11 +00:00
#include <cstdio>
2018-04-17 21:46:53 +00:00
#include <set>
2017-07-10 16:13:38 +00:00
namespace dev
{
namespace solidity
{
namespace smt
{
2017-07-13 16:22:51 +00:00
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
2017-07-10 16:13:38 +00:00
{
public:
2017-08-30 21:43:01 +00:00
explicit SMTLib2Interface(ReadCallback::Callback const& _queryCallback);
2017-07-10 16:13:38 +00:00
2017-07-13 16:22:51 +00:00
void reset() override;
2017-07-10 16:13:38 +00:00
2017-07-13 16:22:51 +00:00
void push() override;
void pop() override;
2017-07-10 16:13:38 +00:00
void declareVariable(std::string const&, Sort const&) override;
2017-07-10 16:13:38 +00:00
2017-07-13 16:22:51 +00:00
void addAssertion(Expression const& _expr) override;
std::pair<CheckResult, std::vector<std::string>> check(std::vector<Expression> const& _expressionsToEvaluate) override;
2017-07-10 19:21:11 +00:00
private:
void declareFunction(std::string const&, Sort const&);
2017-07-13 16:22:51 +00:00
std::string toSExpr(Expression const& _expr);
std::string toSmtLibSort(Sort const& _sort);
std::string toSmtLibSort(std::vector<SortPointer> const& _sort);
2017-07-13 16:22:51 +00:00
2017-07-10 19:21:11 +00:00
void write(std::string _data);
2017-07-11 11:26:43 +00:00
std::string checkSatAndGetValuesCommand(std::vector<Expression> const& _expressionsToEvaluate);
2017-07-10 19:21:11 +00:00
std::vector<std::string> parseValues(std::string::const_iterator _start, std::string::const_iterator _end);
2017-07-13 19:06:29 +00:00
/// Communicates with the solver via the callback. Throws SMTSolverError on error.
std::string querySolver(std::string const& _input);
ReadCallback::Callback m_queryCallback;
2017-07-10 19:21:11 +00:00
std::vector<std::string> m_accumulatedOutput;
std::set<std::string> m_variables;
2017-07-10 16:13:38 +00:00
};
}
}
}