2017-09-28 13:24:24 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <libsolidity/formal/VariableUsage.h>
|
|
|
|
|
2019-03-25 14:01:07 +00:00
|
|
|
#include <libsolidity/formal/SMTChecker.h>
|
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
#include <algorithm>
|
2017-09-28 13:24:24 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace dev;
|
|
|
|
using namespace dev::solidity;
|
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
void VariableUsage::endVisit(Identifier const& _identifier)
|
2017-09-28 13:24:24 +00:00
|
|
|
{
|
2019-04-01 09:10:28 +00:00
|
|
|
Declaration const* declaration = _identifier.annotation().referencedDeclaration;
|
|
|
|
solAssert(declaration, "");
|
|
|
|
if (VariableDeclaration const* varDecl = dynamic_cast<VariableDeclaration const*>(declaration))
|
|
|
|
if (_identifier.annotation().lValueRequested)
|
|
|
|
m_touchedVariables.insert(varDecl);
|
2017-09-28 13:24:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
void VariableUsage::endVisit(FunctionCall const& _funCall)
|
2017-09-28 13:24:24 +00:00
|
|
|
{
|
2019-04-01 09:10:28 +00:00
|
|
|
if (auto const& funDef = SMTChecker::inlinedFunctionCallToDefinition(_funCall))
|
|
|
|
if (find(m_functionPath.begin(), m_functionPath.end(), funDef) == m_functionPath.end())
|
|
|
|
funDef->accept(*this);
|
|
|
|
}
|
2017-09-28 13:24:24 +00:00
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
bool VariableUsage::visit(FunctionDefinition const& _function)
|
|
|
|
{
|
|
|
|
m_functionPath.push_back(&_function);
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-28 13:24:24 +00:00
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
void VariableUsage::endVisit(FunctionDefinition const&)
|
|
|
|
{
|
|
|
|
solAssert(!m_functionPath.empty(), "");
|
|
|
|
m_functionPath.pop_back();
|
|
|
|
}
|
2019-03-25 14:01:07 +00:00
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
void VariableUsage::endVisit(ModifierInvocation const& _modifierInv)
|
|
|
|
{
|
|
|
|
auto const& modifierDef = dynamic_cast<ModifierDefinition const*>(_modifierInv.name()->annotation().referencedDeclaration);
|
|
|
|
if (modifierDef)
|
|
|
|
modifierDef->accept(*this);
|
|
|
|
}
|
2019-03-25 14:01:07 +00:00
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
void VariableUsage::endVisit(PlaceholderStatement const&)
|
|
|
|
{
|
|
|
|
solAssert(!m_functionPath.empty(), "");
|
|
|
|
FunctionDefinition const* function = m_functionPath.back();
|
|
|
|
solAssert(function, "");
|
|
|
|
if (function->isImplemented())
|
|
|
|
function->body().accept(*this);
|
|
|
|
}
|
2017-09-28 13:24:24 +00:00
|
|
|
|
2019-04-01 09:10:28 +00:00
|
|
|
set<VariableDeclaration const*> VariableUsage::touchedVariables(ASTNode const& _node, vector<FunctionDefinition const*> const& _outerCallstack)
|
|
|
|
{
|
|
|
|
m_touchedVariables.clear();
|
|
|
|
m_functionPath.clear();
|
|
|
|
m_functionPath += _outerCallstack;
|
|
|
|
_node.accept(*this);
|
|
|
|
return m_touchedVariables;
|
2017-09-28 13:24:24 +00:00
|
|
|
}
|