mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Handle custom tuple sorts in a general way
This commit is contained in:
parent
742642ebae
commit
4ecaa476fd
@ -294,6 +294,21 @@ namespace
|
|||||||
public:
|
public:
|
||||||
SMTLibTranslationContext(SMTLib2Interface const& _smtlib2Interface) : m_smtlib2Interface(_smtlib2Interface) {}
|
SMTLibTranslationContext(SMTLib2Interface const& _smtlib2Interface) : m_smtlib2Interface(_smtlib2Interface) {}
|
||||||
|
|
||||||
|
std::optional<SortPointer> lookupKnownTupleSort(std::string const& name) {
|
||||||
|
std::string quotedName = "|" + name + "|";
|
||||||
|
auto it = ranges::find_if(m_smtlib2Interface.sortNames(), [&](auto const& entry) {
|
||||||
|
return entry.second == name || entry.second == quotedName;
|
||||||
|
});
|
||||||
|
if (it != m_smtlib2Interface.sortNames().end()) {
|
||||||
|
if (it->first->kind == Kind::Tuple) {
|
||||||
|
auto tupleSort = std::dynamic_pointer_cast<TupleSort>(it->first);
|
||||||
|
smtAssert(tupleSort);
|
||||||
|
return tupleSort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
SortPointer toSort(SMTLib2Expression const& expr)
|
SortPointer toSort(SMTLib2Expression const& expr)
|
||||||
{
|
{
|
||||||
if (isAtom(expr))
|
if (isAtom(expr))
|
||||||
@ -303,17 +318,9 @@ namespace
|
|||||||
return SortProvider::sintSort;
|
return SortProvider::sintSort;
|
||||||
if (name == "Bool")
|
if (name == "Bool")
|
||||||
return SortProvider::boolSort;
|
return SortProvider::boolSort;
|
||||||
std::string quotedName = "|" + name + "|";
|
auto tupleSort = lookupKnownTupleSort(name);
|
||||||
auto it = ranges::find_if(m_smtlib2Interface.sortNames(), [&](auto const& entry) {
|
if (tupleSort)
|
||||||
return entry.second == name || entry.second == quotedName;
|
return tupleSort.value();
|
||||||
});
|
|
||||||
if (it != m_smtlib2Interface.sortNames().end()) {
|
|
||||||
if (it->first->kind == Kind::Tuple) {
|
|
||||||
auto tupleSort = std::dynamic_pointer_cast<TupleSort>(it->first);
|
|
||||||
smtAssert(tupleSort);
|
|
||||||
return tupleSort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto const& args = asSubExpressions(expr);
|
auto const& args = asSubExpressions(expr);
|
||||||
if (asAtom(args[0]) == "Array")
|
if (asAtom(args[0]) == "Array")
|
||||||
@ -346,13 +353,9 @@ namespace
|
|||||||
for (size_t i = 1; i < _subExpr.size(); i++)
|
for (size_t i = 1; i < _subExpr.size(); i++)
|
||||||
arguments.emplace_back(toSMTUtilExpression(_subExpr[i]));
|
arguments.emplace_back(toSMTUtilExpression(_subExpr[i]));
|
||||||
std::string const& op = asAtom(_subExpr.front());
|
std::string const& op = asAtom(_subExpr.front());
|
||||||
if (boost::starts_with(op, "struct")) {
|
if (auto tupleSort = lookupKnownTupleSort(op); tupleSort)
|
||||||
auto sort = toSort(_subExpr.front());
|
{
|
||||||
auto sortSort = std::make_shared<SortSort>(sort);
|
auto sortSort = std::make_shared<SortSort>(tupleSort.value());
|
||||||
return Expression::tuple_constructor(Expression(sortSort), arguments);
|
|
||||||
} else if (op.find("array_tuple") != std::string::npos) {
|
|
||||||
auto sort = toSort(_subExpr.front());
|
|
||||||
auto sortSort = std::make_shared<SortSort>(sort);
|
|
||||||
return Expression::tuple_constructor(Expression(sortSort), arguments);
|
return Expression::tuple_constructor(Expression(sortSort), arguments);
|
||||||
} else {
|
} else {
|
||||||
std::set<std::string> boolOperators{"and", "or", "not", "=", "<", ">", "<=", ">=",
|
std::set<std::string> boolOperators{"and", "or", "not", "=", "<", ">", "<=", ">=",
|
||||||
|
Loading…
Reference in New Issue
Block a user