Merge pull request #4603 from ethereum/smtlib2

[SMTLib2] Fix repeated declarations
This commit is contained in:
Alex Beregszaszi 2018-08-02 12:04:58 +01:00 committed by GitHub
commit 6003ed2abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 18 deletions

View File

@ -51,18 +51,23 @@ void CVC4Interface::pop()
}
void CVC4Interface::declareFunction(string _name, Sort _domain, Sort _codomain)
{
if (!m_functions.count(_name))
{
CVC4::Type fType = m_context.mkFunctionType(cvc4Sort(_domain), cvc4Sort(_codomain));
m_functions.insert({_name, m_context.mkVar(_name.c_str(), fType)});
}
}
void CVC4Interface::declareInteger(string _name)
{
if (!m_constants.count(_name))
m_constants.insert({_name, m_context.mkVar(_name.c_str(), m_context.integerType())});
}
void CVC4Interface::declareBool(string _name)
{
if (!m_constants.count(_name))
m_constants.insert({_name, m_context.mkVar(_name.c_str(), m_context.booleanType())});
}

View File

@ -47,6 +47,8 @@ void SMTLib2Interface::reset()
{
m_accumulatedOutput.clear();
m_accumulatedOutput.emplace_back();
m_constants.clear();
m_functions.clear();
write("(set-option :produce-models true)");
write("(set-logic QF_UFLIA)");
}
@ -64,6 +66,10 @@ void SMTLib2Interface::pop()
void SMTLib2Interface::declareFunction(string _name, Sort _domain, Sort _codomain)
{
// TODO Use domain and codomain as key as well
if (!m_functions.count(_name))
{
m_functions.insert(_name);
write(
"(declare-fun |" +
_name +
@ -74,16 +80,25 @@ void SMTLib2Interface::declareFunction(string _name, Sort _domain, Sort _codomai
")"
);
}
}
void SMTLib2Interface::declareInteger(string _name)
{
if (!m_constants.count(_name))
{
m_constants.insert(_name);
write("(declare-const |" + _name + "| Int)");
}
}
void SMTLib2Interface::declareBool(string _name)
{
if (!m_constants.count(_name))
{
m_constants.insert(_name);
write("(declare-const |" + _name + "| Bool)");
}
}
void SMTLib2Interface::addAssertion(Expression const& _expr)
{

View File

@ -30,6 +30,7 @@
#include <string>
#include <vector>
#include <cstdio>
#include <set>
namespace dev
{
@ -68,6 +69,8 @@ private:
ReadCallback::Callback m_queryCallback;
std::vector<std::string> m_accumulatedOutput;
std::set<std::string> m_constants;
std::set<std::string> m_functions;
};
}

View File

@ -53,16 +53,19 @@ void Z3Interface::pop()
void Z3Interface::declareFunction(string _name, Sort _domain, Sort _codomain)
{
if (!m_functions.count(_name))
m_functions.insert({_name, m_context.function(_name.c_str(), z3Sort(_domain), z3Sort(_codomain))});
}
void Z3Interface::declareInteger(string _name)
{
if (!m_constants.count(_name))
m_constants.insert({_name, m_context.int_const(_name.c_str())});
}
void Z3Interface::declareBool(string _name)
{
if (!m_constants.count(_name))
m_constants.insert({_name, m_context.bool_const(_name.c_str())});
}