From 4a4620ac955d3c61b4778dfab3a9e05a91e4fc33 Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Fri, 12 Oct 2018 15:44:46 +0200 Subject: Refactor SSAVariable such that it only uses Type and not Declaration --- libsolidity/formal/SymbolicIntVariable.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'libsolidity/formal/SymbolicIntVariable.cpp') diff --git a/libsolidity/formal/SymbolicIntVariable.cpp b/libsolidity/formal/SymbolicIntVariable.cpp index 4f65b1fd..0adb9d09 100644 --- a/libsolidity/formal/SymbolicIntVariable.cpp +++ b/libsolidity/formal/SymbolicIntVariable.cpp @@ -17,21 +17,20 @@ #include -#include - using namespace std; using namespace dev; using namespace dev::solidity; SymbolicIntVariable::SymbolicIntVariable( - Declaration const& _decl, + Type const& _type, + string const& _uniqueName, smt::SolverInterface& _interface ): - SymbolicVariable(_decl, _interface) + SymbolicVariable(_type, _uniqueName, _interface) { solAssert( - m_declaration.type()->category() == Type::Category::Integer || - m_declaration.type()->category() == Type::Category::Address, + _type.category() == Type::Category::Integer || + _type.category() == Type::Category::Address, "" ); } @@ -48,11 +47,20 @@ void SymbolicIntVariable::setZeroValue(int _seq) void SymbolicIntVariable::setUnknownValue(int _seq) { - auto intType = dynamic_pointer_cast(m_declaration.type()); - if (!intType) - intType = make_shared(160); - m_interface.addAssertion(valueAtSequence(_seq) >= minValue(*intType)); - m_interface.addAssertion(valueAtSequence(_seq) <= maxValue(*intType)); + if (m_type.category() == Type::Category::Integer) + { + auto intType = dynamic_cast(&m_type); + solAssert(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) -- cgit