mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor SSAVariable such that it only uses Type and not Declaration
This commit is contained in:
parent
0778fb2dfc
commit
4a4620ac95
@ -782,7 +782,7 @@ bool SMTChecker::createVariable(VariableDeclaration const& _varDecl)
|
|||||||
if (SSAVariable::isSupportedType(_varDecl.type()->category()))
|
if (SSAVariable::isSupportedType(_varDecl.type()->category()))
|
||||||
{
|
{
|
||||||
solAssert(m_variables.count(&_varDecl) == 0, "");
|
solAssert(m_variables.count(&_varDecl) == 0, "");
|
||||||
m_variables.emplace(&_varDecl, SSAVariable(_varDecl, *m_interface));
|
m_variables.emplace(&_varDecl, SSAVariable(*_varDecl.type(), _varDecl.name() + "_" + to_string(_varDecl.id()), *m_interface));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -27,16 +27,17 @@ using namespace dev;
|
|||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
SSAVariable::SSAVariable(
|
SSAVariable::SSAVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
resetIndex();
|
resetIndex();
|
||||||
|
|
||||||
if (isInteger(_decl.type()->category()))
|
if (isInteger(_type.category()))
|
||||||
m_symbolicVar = make_shared<SymbolicIntVariable>(_decl, _interface);
|
m_symbolicVar = make_shared<SymbolicIntVariable>(_type, _uniqueName, _interface);
|
||||||
else if (isBool(_decl.type()->category()))
|
else if (isBool(_type.category()))
|
||||||
m_symbolicVar = make_shared<SymbolicBoolVariable>(_decl, _interface);
|
m_symbolicVar = make_shared<SymbolicBoolVariable>(_type, _uniqueName, _interface);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
solAssert(false, "");
|
solAssert(false, "");
|
||||||
|
@ -26,18 +26,17 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
class Declaration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the SSA representation of a program variable.
|
* This class represents the SSA representation of a program variable.
|
||||||
*/
|
*/
|
||||||
class SSAVariable
|
class SSAVariable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// @param _decl Used to determine the type and forwarded to the symbolic var.
|
/// @param _type Forwarded to the symbolic var.
|
||||||
/// @param _interface Forwarded to the symbolic var such that it can give constraints to the solver.
|
/// @param _interface Forwarded to the symbolic var such that it can give constraints to the solver.
|
||||||
SSAVariable(
|
SSAVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
std::string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -24,12 +24,13 @@ using namespace dev;
|
|||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
SymbolicBoolVariable::SymbolicBoolVariable(
|
SymbolicBoolVariable::SymbolicBoolVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
string const& _uniqueName,
|
||||||
smt::SolverInterface&_interface
|
smt::SolverInterface&_interface
|
||||||
):
|
):
|
||||||
SymbolicVariable(_decl, _interface)
|
SymbolicVariable(_type, _uniqueName, _interface)
|
||||||
{
|
{
|
||||||
solAssert(m_declaration.type()->category() == Type::Category::Bool, "");
|
solAssert(_type.category() == Type::Category::Bool, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
smt::Expression SymbolicBoolVariable::valueAtSequence(int _seq) const
|
smt::Expression SymbolicBoolVariable::valueAtSequence(int _seq) const
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include <libsolidity/formal/SymbolicVariable.h>
|
#include <libsolidity/formal/SymbolicVariable.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/Types.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
namespace solidity
|
namespace solidity
|
||||||
@ -33,7 +31,8 @@ class SymbolicBoolVariable: public SymbolicVariable
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolicBoolVariable(
|
SymbolicBoolVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
std::string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -17,21 +17,20 @@
|
|||||||
|
|
||||||
#include <libsolidity/formal/SymbolicIntVariable.h>
|
#include <libsolidity/formal/SymbolicIntVariable.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/AST.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace dev;
|
using namespace dev;
|
||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
SymbolicIntVariable::SymbolicIntVariable(
|
SymbolicIntVariable::SymbolicIntVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
):
|
):
|
||||||
SymbolicVariable(_decl, _interface)
|
SymbolicVariable(_type, _uniqueName, _interface)
|
||||||
{
|
{
|
||||||
solAssert(
|
solAssert(
|
||||||
m_declaration.type()->category() == Type::Category::Integer ||
|
_type.category() == Type::Category::Integer ||
|
||||||
m_declaration.type()->category() == Type::Category::Address,
|
_type.category() == Type::Category::Address,
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,11 +47,20 @@ void SymbolicIntVariable::setZeroValue(int _seq)
|
|||||||
|
|
||||||
void SymbolicIntVariable::setUnknownValue(int _seq)
|
void SymbolicIntVariable::setUnknownValue(int _seq)
|
||||||
{
|
{
|
||||||
auto intType = dynamic_pointer_cast<IntegerType const>(m_declaration.type());
|
if (m_type.category() == Type::Category::Integer)
|
||||||
if (!intType)
|
{
|
||||||
intType = make_shared<IntegerType>(160);
|
auto intType = dynamic_cast<IntegerType const*>(&m_type);
|
||||||
m_interface.addAssertion(valueAtSequence(_seq) >= minValue(*intType));
|
solAssert(intType, "");
|
||||||
m_interface.addAssertion(valueAtSequence(_seq) <= maxValue(*intType));
|
m_interface.addAssertion(valueAtSequence(_seq) >= minValue(*intType));
|
||||||
|
m_interface.addAssertion(valueAtSequence(_seq) <= maxValue(*intType));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
solAssert(m_type.category() == Type::Category::Address, "");
|
||||||
|
IntegerType addrType{160};
|
||||||
|
m_interface.addAssertion(valueAtSequence(_seq) >= minValue(addrType));
|
||||||
|
m_interface.addAssertion(valueAtSequence(_seq) <= maxValue(addrType));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
smt::Expression SymbolicIntVariable::minValue(IntegerType const& _t)
|
smt::Expression SymbolicIntVariable::minValue(IntegerType const& _t)
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include <libsolidity/formal/SymbolicVariable.h>
|
#include <libsolidity/formal/SymbolicVariable.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/Types.h>
|
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
namespace solidity
|
namespace solidity
|
||||||
@ -33,7 +31,8 @@ class SymbolicIntVariable: public SymbolicVariable
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolicIntVariable(
|
SymbolicIntVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
std::string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -24,17 +24,19 @@ using namespace dev;
|
|||||||
using namespace dev::solidity;
|
using namespace dev::solidity;
|
||||||
|
|
||||||
SymbolicVariable::SymbolicVariable(
|
SymbolicVariable::SymbolicVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
):
|
):
|
||||||
m_declaration(_decl),
|
m_type(_type),
|
||||||
|
m_uniqueName(_uniqueName),
|
||||||
m_interface(_interface)
|
m_interface(_interface)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string SymbolicVariable::uniqueSymbol(int _seq) const
|
string SymbolicVariable::uniqueSymbol(int _seq) const
|
||||||
{
|
{
|
||||||
return m_declaration.name() + "_" + to_string(m_declaration.id()) + "_" + to_string(_seq);
|
return m_uniqueName + "_" + to_string(_seq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <libsolidity/formal/SolverInterface.h>
|
#include <libsolidity/formal/SolverInterface.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/Types.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ namespace dev
|
|||||||
namespace solidity
|
namespace solidity
|
||||||
{
|
{
|
||||||
|
|
||||||
class Declaration;
|
class Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the symbolic version of a program variable.
|
* This class represents the symbolic version of a program variable.
|
||||||
@ -37,7 +37,8 @@ class SymbolicVariable
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SymbolicVariable(
|
SymbolicVariable(
|
||||||
Declaration const& _decl,
|
Type const& _type,
|
||||||
|
std::string const& _uniqueName,
|
||||||
smt::SolverInterface& _interface
|
smt::SolverInterface& _interface
|
||||||
);
|
);
|
||||||
virtual ~SymbolicVariable() = default;
|
virtual ~SymbolicVariable() = default;
|
||||||
@ -58,7 +59,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual smt::Expression valueAtSequence(int _seq) const = 0;
|
virtual smt::Expression valueAtSequence(int _seq) const = 0;
|
||||||
|
|
||||||
Declaration const& m_declaration;
|
Type const& m_type;
|
||||||
|
std::string m_uniqueName;
|
||||||
smt::SolverInterface& m_interface;
|
smt::SolverInterface& m_interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user