solidity/libsolidity/formal/SMTLib2Interface.h

86 lines
2.6 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 <libsolidity/interface/ReadFile.h>
2018-12-17 17:26:10 +00:00
#include <liblangutil/Exceptions.h>
#include <libsolutil/Common.h>
#include <libsolutil/FixedHash.h>
2017-07-10 19:21:11 +00:00
2017-07-11 11:26:43 +00:00
#include <boost/noncopyable.hpp>
2018-12-17 17:26:10 +00:00
#include <cstdio>
2017-07-10 16:13:38 +00:00
#include <map>
2018-12-17 17:26:10 +00:00
#include <set>
2017-07-10 16:13:38 +00:00
#include <string>
#include <vector>
2019-12-11 16:31:36 +00:00
namespace solidity::frontend::smt
2017-07-10 16:13:38 +00:00
{
2017-07-13 16:22:51 +00:00
class SMTLib2Interface: public SolverInterface, public boost::noncopyable
2017-07-10 16:13:38 +00:00
{
public:
explicit SMTLib2Interface(
2019-12-11 16:31:36 +00:00
std::map<util::h256, std::string> const& _queryResponses,
2020-04-01 03:04:29 +00:00
ReadCallback::Callback _smtCallback
);
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
2019-09-24 15:35:31 +00:00
void declareVariable(std::string const&, SortPointer const&) override;
2017-07-10 16:13:38 +00:00
2019-09-02 12:27:35 +00:00
void addAssertion(smt::Expression const& _expr) override;
std::pair<CheckResult, std::vector<std::string>> check(std::vector<smt::Expression> const& _expressionsToEvaluate) override;
2017-07-10 19:21:11 +00:00
std::vector<std::string> unhandledQueries() override { return m_unhandledQueries; }
2019-09-24 15:35:31 +00:00
// Used by CHCSmtLib2Interface
2019-09-02 12:27:35 +00:00
std::string toSExpr(smt::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
2019-09-24 15:35:31 +00:00
std::map<std::string, SortPointer> variables() { return m_variables; }
private:
void declareFunction(std::string const& _name, SortPointer const& _sort);
2017-07-10 19:21:11 +00:00
void write(std::string _data);
2019-09-02 12:27:35 +00:00
std::string checkSatAndGetValuesCommand(std::vector<smt::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);
2017-07-10 19:21:11 +00:00
std::vector<std::string> m_accumulatedOutput;
2019-09-24 15:35:31 +00:00
std::map<std::string, SortPointer> m_variables;
2020-04-03 13:10:16 +00:00
std::set<std::string> m_userSorts;
2019-12-11 16:31:36 +00:00
std::map<util::h256, std::string> const& m_queryResponses;
std::vector<std::string> m_unhandledQueries;
ReadCallback::Callback m_smtCallback;
2017-07-10 16:13:38 +00:00
};
}