2018-01-17 20:02:23 +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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2018-01-17 20:02:23 +00:00
|
|
|
|
2018-10-22 08:29:03 +00:00
|
|
|
#include <libsolidity/formal/SymbolicVariables.h>
|
2018-01-17 20:02:23 +00:00
|
|
|
|
2020-09-29 08:36:20 +00:00
|
|
|
#include <libsolidity/formal/EncodingContext.h>
|
2018-10-17 13:56:44 +00:00
|
|
|
#include <libsolidity/formal/SymbolicTypes.h>
|
2018-10-22 08:29:03 +00:00
|
|
|
#include <libsolidity/ast/AST.h>
|
|
|
|
|
2020-08-25 14:58:09 +00:00
|
|
|
#include <libsolutil/Algorithms.h>
|
|
|
|
|
2018-01-17 20:02:23 +00:00
|
|
|
using namespace std;
|
2019-12-11 16:31:36 +00:00
|
|
|
using namespace solidity;
|
2020-08-25 14:58:09 +00:00
|
|
|
using namespace solidity::util;
|
2020-05-19 12:14:46 +00:00
|
|
|
using namespace solidity::smtutil;
|
2019-12-11 16:31:36 +00:00
|
|
|
using namespace solidity::frontend;
|
|
|
|
using namespace solidity::frontend::smt;
|
2018-01-17 20:02:23 +00:00
|
|
|
|
2018-10-22 08:29:03 +00:00
|
|
|
SymbolicVariable::SymbolicVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
TypePointer _type,
|
|
|
|
TypePointer _originalType,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-10-22 08:29:03 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
m_type(_type),
|
|
|
|
m_originalType(_originalType),
|
2019-04-12 12:44:18 +00:00
|
|
|
m_uniqueName(move(_uniqueName)),
|
2019-07-03 14:05:56 +00:00
|
|
|
m_context(_context),
|
2019-05-09 08:56:58 +00:00
|
|
|
m_ssa(make_unique<SSAVariable>())
|
2018-10-22 08:29:03 +00:00
|
|
|
{
|
2019-04-12 12:44:18 +00:00
|
|
|
solAssert(m_type, "");
|
|
|
|
m_sort = smtSort(*m_type);
|
|
|
|
solAssert(m_sort, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolicVariable::SymbolicVariable(
|
2019-05-09 10:16:52 +00:00
|
|
|
SortPointer _sort,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2019-04-12 12:44:18 +00:00
|
|
|
):
|
|
|
|
m_sort(move(_sort)),
|
|
|
|
m_uniqueName(move(_uniqueName)),
|
2019-07-03 14:05:56 +00:00
|
|
|
m_context(_context),
|
2019-05-09 08:56:58 +00:00
|
|
|
m_ssa(make_unique<SSAVariable>())
|
2019-04-12 12:44:18 +00:00
|
|
|
{
|
|
|
|
solAssert(m_sort, "");
|
2018-10-22 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicVariable::currentValue(frontend::TypePointer const&) const
|
2018-12-05 08:56:52 +00:00
|
|
|
{
|
|
|
|
return valueAtIndex(m_ssa->index());
|
|
|
|
}
|
|
|
|
|
2018-10-25 14:00:09 +00:00
|
|
|
string SymbolicVariable::currentName() const
|
|
|
|
{
|
|
|
|
return uniqueSymbol(m_ssa->index());
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:42:46 +00:00
|
|
|
smtutil::Expression SymbolicVariable::valueAtIndex(unsigned _index) const
|
2018-12-05 08:56:52 +00:00
|
|
|
{
|
2019-07-03 14:05:56 +00:00
|
|
|
return m_context.newVariable(uniqueSymbol(_index), m_sort);
|
2018-12-05 08:56:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 13:42:46 +00:00
|
|
|
string SymbolicVariable::nameAtIndex(unsigned _index) const
|
2019-07-03 14:16:42 +00:00
|
|
|
{
|
|
|
|
return uniqueSymbol(_index);
|
|
|
|
}
|
|
|
|
|
2018-10-22 08:29:03 +00:00
|
|
|
string SymbolicVariable::uniqueSymbol(unsigned _index) const
|
|
|
|
{
|
|
|
|
return m_uniqueName + "_" + to_string(_index);
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicVariable::resetIndex()
|
2019-07-25 12:10:09 +00:00
|
|
|
{
|
|
|
|
m_ssa->resetIndex();
|
|
|
|
return currentValue();
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicVariable::setIndex(unsigned _index)
|
2020-04-14 09:09:38 +00:00
|
|
|
{
|
|
|
|
m_ssa->setIndex(_index);
|
|
|
|
return currentValue();
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicVariable::increaseIndex()
|
2018-12-05 08:56:52 +00:00
|
|
|
{
|
|
|
|
++(*m_ssa);
|
|
|
|
return currentValue();
|
|
|
|
}
|
|
|
|
|
2018-10-22 08:29:03 +00:00
|
|
|
SymbolicBoolVariable::SymbolicBoolVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-10-22 08:29:03 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicVariable(_type, _type, move(_uniqueName), _context)
|
2018-10-22 08:29:03 +00:00
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
solAssert(m_type->category() == frontend::Type::Category::Bool, "");
|
2018-10-22 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 17:00:13 +00:00
|
|
|
SymbolicIntVariable::SymbolicIntVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
|
|
|
frontend::TypePointer _originalType,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-02-28 17:00:13 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicVariable(_type, _originalType, move(_uniqueName), _context)
|
2018-01-17 20:02:23 +00:00
|
|
|
{
|
2020-08-27 13:16:02 +00:00
|
|
|
solAssert(isNumber(*m_type), "");
|
2018-04-05 10:20:41 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 08:29:03 +00:00
|
|
|
SymbolicAddressVariable::SymbolicAddressVariable(
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-10-22 08:29:03 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicIntVariable(TypeProvider::uint(160), TypeProvider::uint(160), move(_uniqueName), _context)
|
2018-10-22 08:29:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolicFixedBytesVariable::SymbolicFixedBytesVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _originalType,
|
2018-10-22 08:29:03 +00:00
|
|
|
unsigned _numBytes,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-10-22 08:29:03 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicIntVariable(TypeProvider::uint(_numBytes * 8), _originalType, move(_uniqueName), _context)
|
2018-10-22 08:29:03 +00:00
|
|
|
{
|
|
|
|
}
|
2018-12-10 10:34:29 +00:00
|
|
|
|
|
|
|
SymbolicFunctionVariable::SymbolicFunctionVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-12-10 10:34:29 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicVariable(_type, _type, move(_uniqueName), _context),
|
2019-07-03 14:05:56 +00:00
|
|
|
m_declaration(m_context.newVariable(currentName(), m_sort))
|
2018-12-10 10:34:29 +00:00
|
|
|
{
|
2019-12-11 16:31:36 +00:00
|
|
|
solAssert(m_type->category() == frontend::Type::Category::Function, "");
|
2018-12-10 10:34:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 14:16:42 +00:00
|
|
|
SymbolicFunctionVariable::SymbolicFunctionVariable(
|
|
|
|
SortPointer _sort,
|
|
|
|
string _uniqueName,
|
|
|
|
EncodingContext& _context
|
|
|
|
):
|
|
|
|
SymbolicVariable(move(_sort), move(_uniqueName), _context),
|
|
|
|
m_declaration(m_context.newVariable(currentName(), m_sort))
|
|
|
|
{
|
|
|
|
solAssert(m_sort->kind == Kind::Function, "");
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::currentValue(frontend::TypePointer const& _targetType) const
|
2018-12-10 10:34:29 +00:00
|
|
|
{
|
2019-11-10 17:58:29 +00:00
|
|
|
return m_abstract.currentValue(_targetType);
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::currentFunctionValue() const
|
2019-11-10 17:58:29 +00:00
|
|
|
{
|
|
|
|
return m_declaration;
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:42:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::valueAtIndex(unsigned _index) const
|
2019-11-10 17:58:29 +00:00
|
|
|
{
|
|
|
|
return m_abstract.valueAtIndex(_index);
|
|
|
|
}
|
|
|
|
|
2020-06-02 13:42:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::functionValueAtIndex(unsigned _index) const
|
2019-11-10 17:58:29 +00:00
|
|
|
{
|
|
|
|
return SymbolicVariable::valueAtIndex(_index);
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::resetIndex()
|
2019-11-10 17:58:29 +00:00
|
|
|
{
|
|
|
|
SymbolicVariable::resetIndex();
|
|
|
|
return m_abstract.resetIndex();
|
2018-12-10 10:34:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::setIndex(unsigned _index)
|
2020-04-14 09:09:38 +00:00
|
|
|
{
|
|
|
|
SymbolicVariable::setIndex(_index);
|
|
|
|
return m_abstract.setIndex(_index);
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::increaseIndex()
|
2018-12-10 10:34:29 +00:00
|
|
|
{
|
|
|
|
++(*m_ssa);
|
|
|
|
resetDeclaration();
|
2019-11-10 17:58:29 +00:00
|
|
|
m_abstract.increaseIndex();
|
|
|
|
return m_abstract.currentValue();
|
2018-12-10 10:34:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicFunctionVariable::operator()(vector<smtutil::Expression> _arguments) const
|
2018-12-10 10:34:29 +00:00
|
|
|
{
|
|
|
|
return m_declaration(_arguments);
|
|
|
|
}
|
2018-11-09 16:06:30 +00:00
|
|
|
|
2019-11-10 17:58:29 +00:00
|
|
|
void SymbolicFunctionVariable::resetDeclaration()
|
|
|
|
{
|
|
|
|
m_declaration = m_context.newVariable(currentName(), m_sort);
|
|
|
|
}
|
|
|
|
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicEnumVariable::SymbolicEnumVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2018-11-09 16:06:30 +00:00
|
|
|
):
|
2019-08-07 08:48:09 +00:00
|
|
|
SymbolicVariable(_type, _type, move(_uniqueName), _context)
|
2018-11-09 16:06:30 +00:00
|
|
|
{
|
2020-08-27 13:16:02 +00:00
|
|
|
solAssert(isEnum(*m_type), "");
|
2018-11-09 16:06:30 +00:00
|
|
|
}
|
2019-02-20 11:34:52 +00:00
|
|
|
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicTupleVariable::SymbolicTupleVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2019-02-20 11:34:52 +00:00
|
|
|
):
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicVariable(_type, _type, move(_uniqueName), _context)
|
2019-02-20 11:34:52 +00:00
|
|
|
{
|
2020-08-27 13:16:02 +00:00
|
|
|
solAssert(isTuple(*m_type), "");
|
2019-02-20 11:34:52 +00:00
|
|
|
}
|
2019-03-06 00:10:43 +00:00
|
|
|
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicTupleVariable::SymbolicTupleVariable(
|
2020-04-06 08:50:00 +00:00
|
|
|
SortPointer _sort,
|
|
|
|
string _uniqueName,
|
|
|
|
EncodingContext& _context
|
|
|
|
):
|
|
|
|
SymbolicVariable(move(_sort), move(_uniqueName), _context)
|
|
|
|
{
|
2020-04-14 09:09:38 +00:00
|
|
|
solAssert(m_sort->kind == Kind::Tuple, "");
|
2020-04-06 08:50:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 21:04:34 +00:00
|
|
|
smtutil::Expression SymbolicTupleVariable::currentValue(frontend::TypePointer const& _targetType) const
|
|
|
|
{
|
|
|
|
if (!_targetType || sort() == smtSort(*_targetType))
|
|
|
|
return SymbolicVariable::currentValue();
|
|
|
|
|
|
|
|
auto thisTuple = dynamic_pointer_cast<TupleSort>(sort());
|
|
|
|
auto otherTuple = dynamic_pointer_cast<TupleSort>(smtSort(*_targetType));
|
|
|
|
solAssert(thisTuple && otherTuple, "");
|
|
|
|
solAssert(thisTuple->components.size() == otherTuple->components.size(), "");
|
|
|
|
vector<smtutil::Expression> args;
|
|
|
|
for (size_t i = 0; i < thisTuple->components.size(); ++i)
|
|
|
|
args.emplace_back(component(i, type(), _targetType));
|
|
|
|
return smtutil::Expression::tuple_constructor(
|
|
|
|
smtutil::Expression(make_shared<smtutil::SortSort>(smtSort(*_targetType)), ""),
|
|
|
|
args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<SortPointer> const& SymbolicTupleVariable::components() const
|
2019-08-07 08:48:09 +00:00
|
|
|
{
|
2020-04-14 09:09:38 +00:00
|
|
|
auto tupleSort = dynamic_pointer_cast<TupleSort>(m_sort);
|
|
|
|
solAssert(tupleSort, "");
|
|
|
|
return tupleSort->components;
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicTupleVariable::component(
|
2020-04-14 09:09:38 +00:00
|
|
|
size_t _index,
|
|
|
|
TypePointer _fromType,
|
|
|
|
TypePointer _toType
|
2020-10-21 21:04:34 +00:00
|
|
|
) const
|
2020-04-14 09:09:38 +00:00
|
|
|
{
|
2020-05-19 12:14:46 +00:00
|
|
|
optional<smtutil::Expression> conversion = symbolicTypeConversion(_fromType, _toType);
|
2020-04-03 13:10:16 +00:00
|
|
|
if (conversion)
|
|
|
|
return *conversion;
|
2019-08-07 08:48:09 +00:00
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
return smtutil::Expression::tuple_get(currentValue(), _index);
|
2019-08-07 08:48:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicArrayVariable::SymbolicArrayVariable(
|
2019-12-11 16:31:36 +00:00
|
|
|
frontend::TypePointer _type,
|
2020-04-14 09:09:38 +00:00
|
|
|
frontend::TypePointer _originalType,
|
2019-04-12 12:44:18 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2019-03-06 00:10:43 +00:00
|
|
|
):
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicVariable(_type, _originalType, move(_uniqueName), _context),
|
|
|
|
m_pair(
|
|
|
|
smtSort(*_type),
|
|
|
|
m_uniqueName + "_length_pair",
|
|
|
|
m_context
|
|
|
|
)
|
2019-03-06 00:10:43 +00:00
|
|
|
{
|
2020-08-27 13:16:02 +00:00
|
|
|
solAssert(isArray(*m_type) || isMapping(*m_type), "");
|
2019-03-06 00:10:43 +00:00
|
|
|
}
|
2019-04-26 12:57:29 +00:00
|
|
|
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicArrayVariable::SymbolicArrayVariable(
|
|
|
|
SortPointer _sort,
|
2019-04-26 12:57:29 +00:00
|
|
|
string _uniqueName,
|
2019-07-03 14:05:56 +00:00
|
|
|
EncodingContext& _context
|
2019-04-26 12:57:29 +00:00
|
|
|
):
|
2020-04-14 09:09:38 +00:00
|
|
|
SymbolicVariable(move(_sort), move(_uniqueName), _context),
|
|
|
|
m_pair(
|
|
|
|
std::make_shared<TupleSort>(
|
|
|
|
"array_length_pair",
|
|
|
|
std::vector<std::string>{"array", "length"},
|
2020-05-13 11:08:48 +00:00
|
|
|
std::vector<SortPointer>{m_sort, SortProvider::uintSort}
|
2020-04-14 09:09:38 +00:00
|
|
|
),
|
|
|
|
m_uniqueName + "_array_length_pair",
|
|
|
|
m_context
|
|
|
|
)
|
2019-04-26 12:57:29 +00:00
|
|
|
{
|
2020-04-14 09:09:38 +00:00
|
|
|
solAssert(m_sort->kind == Kind::Array, "");
|
2020-04-03 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 12:14:46 +00:00
|
|
|
smtutil::Expression SymbolicArrayVariable::currentValue(frontend::TypePointer const& _targetType) const
|
2020-04-03 13:10:16 +00:00
|
|
|
{
|
2020-05-19 12:14:46 +00:00
|
|
|
optional<smtutil::Expression> conversion = symbolicTypeConversion(m_originalType, _targetType);
|
2020-04-14 09:09:38 +00:00
|
|
|
if (conversion)
|
|
|
|
return *conversion;
|
|
|
|
|
|
|
|
return m_pair.currentValue();
|
2020-04-03 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 13:42:46 +00:00
|
|
|
smtutil::Expression SymbolicArrayVariable::valueAtIndex(unsigned _index) const
|
2020-04-03 13:10:16 +00:00
|
|
|
{
|
2020-04-14 09:09:38 +00:00
|
|
|
return m_pair.valueAtIndex(_index);
|
2020-04-03 13:10:16 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 16:16:27 +00:00
|
|
|
smtutil::Expression SymbolicArrayVariable::elements() const
|
2020-04-03 13:10:16 +00:00
|
|
|
{
|
2020-04-14 09:09:38 +00:00
|
|
|
return m_pair.component(0);
|
|
|
|
}
|
2020-04-03 13:10:16 +00:00
|
|
|
|
2020-10-26 16:16:27 +00:00
|
|
|
smtutil::Expression SymbolicArrayVariable::length() const
|
2020-04-14 09:09:38 +00:00
|
|
|
{
|
|
|
|
return m_pair.component(1);
|
2019-04-26 12:57:29 +00:00
|
|
|
}
|
2020-08-25 14:58:09 +00:00
|
|
|
|
|
|
|
SymbolicStructVariable::SymbolicStructVariable(
|
|
|
|
frontend::TypePointer _type,
|
|
|
|
string _uniqueName,
|
|
|
|
EncodingContext& _context
|
|
|
|
):
|
|
|
|
SymbolicVariable(_type, _type, move(_uniqueName), _context)
|
|
|
|
{
|
2020-08-27 13:16:02 +00:00
|
|
|
solAssert(isNonRecursiveStruct(*m_type), "");
|
2020-08-25 14:58:09 +00:00
|
|
|
auto const* structType = dynamic_cast<StructType const*>(_type);
|
|
|
|
solAssert(structType, "");
|
|
|
|
auto const& members = structType->structDefinition().members();
|
|
|
|
for (unsigned i = 0; i < members.size(); ++i)
|
|
|
|
{
|
|
|
|
solAssert(members.at(i), "");
|
|
|
|
m_memberIndices.emplace(members.at(i)->name(), i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 09:09:43 +00:00
|
|
|
smtutil::Expression SymbolicStructVariable::member(string const& _member) const
|
2020-08-25 14:58:09 +00:00
|
|
|
{
|
|
|
|
return smtutil::Expression::tuple_get(currentValue(), m_memberIndices.at(_member));
|
|
|
|
}
|
|
|
|
|
|
|
|
smtutil::Expression SymbolicStructVariable::assignMember(string const& _member, smtutil::Expression const& _memberValue)
|
|
|
|
{
|
|
|
|
auto const* structType = dynamic_cast<StructType const*>(m_type);
|
|
|
|
solAssert(structType, "");
|
|
|
|
auto const& structDef = structType->structDefinition();
|
|
|
|
auto const& structMembers = structDef.members();
|
|
|
|
auto oldMembers = applyMap(
|
|
|
|
structMembers,
|
|
|
|
[&](auto _member) { return member(_member->name()); }
|
|
|
|
);
|
|
|
|
increaseIndex();
|
|
|
|
for (unsigned i = 0; i < structMembers.size(); ++i)
|
|
|
|
{
|
|
|
|
auto const& memberName = structMembers.at(i)->name();
|
|
|
|
auto newMember = memberName == _member ? _memberValue : oldMembers.at(i);
|
|
|
|
m_context.addAssertion(member(memberName) == newMember);
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentValue();
|
|
|
|
}
|
2020-11-12 09:09:43 +00:00
|
|
|
|
|
|
|
smtutil::Expression SymbolicStructVariable::assignAllMembers(vector<smtutil::Expression> const& _memberValues)
|
|
|
|
{
|
|
|
|
auto structType = dynamic_cast<StructType const*>(m_type);
|
|
|
|
solAssert(structType, "");
|
|
|
|
|
|
|
|
auto const& structDef = structType->structDefinition();
|
|
|
|
auto const& structMembers = structDef.members();
|
|
|
|
solAssert(_memberValues.size() == structMembers.size(), "");
|
|
|
|
increaseIndex();
|
|
|
|
for (unsigned i = 0; i < _memberValues.size(); ++i)
|
|
|
|
m_context.addAssertion(_memberValues[i] == member(structMembers[i]->name()));
|
|
|
|
|
|
|
|
return currentValue();
|
2020-12-08 20:06:10 +00:00
|
|
|
}
|