mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Cleanup, style and additional test.
This commit is contained in:
parent
e3ed3623c7
commit
230f51efb7
@ -50,7 +50,9 @@ bool StaticAnalyzer::visit(FunctionDefinition const& _function)
|
|||||||
{
|
{
|
||||||
if (_function.isImplemented())
|
if (_function.isImplemented())
|
||||||
m_currentFunction = &_function;
|
m_currentFunction = &_function;
|
||||||
m_localVarUseCount.clear();
|
else
|
||||||
|
solAssert(!m_currentFunction, "");
|
||||||
|
solAssert(m_localVarUseCount.empty(), "");
|
||||||
m_nonPayablePublic = _function.isPublic() && !_function.isPayable();
|
m_nonPayablePublic = _function.isPublic() && !_function.isPayable();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -62,19 +64,18 @@ void StaticAnalyzer::endVisit(FunctionDefinition const&)
|
|||||||
for (auto const& var: m_localVarUseCount)
|
for (auto const& var: m_localVarUseCount)
|
||||||
if (var.second == 0)
|
if (var.second == 0)
|
||||||
warning(var.first->location(), "Unused local variable");
|
warning(var.first->location(), "Unused local variable");
|
||||||
|
m_localVarUseCount.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StaticAnalyzer::visit(Identifier const& _identifier)
|
bool StaticAnalyzer::visit(Identifier const& _identifier)
|
||||||
{
|
{
|
||||||
if (m_currentFunction)
|
if (m_currentFunction)
|
||||||
{
|
|
||||||
if (auto var = dynamic_cast<VariableDeclaration const*>(_identifier.annotation().referencedDeclaration))
|
if (auto var = dynamic_cast<VariableDeclaration const*>(_identifier.annotation().referencedDeclaration))
|
||||||
{
|
{
|
||||||
solAssert(!var->name().empty(), "");
|
solAssert(!var->name().empty(), "");
|
||||||
if (var->isLocalVariable())
|
if (var->isLocalVariable())
|
||||||
m_localVarUseCount[var] += 1;
|
m_localVarUseCount[var] += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,14 +85,8 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable)
|
|||||||
{
|
{
|
||||||
solAssert(_variable.isLocalVariable(), "");
|
solAssert(_variable.isLocalVariable(), "");
|
||||||
if (_variable.name() != "")
|
if (_variable.name() != "")
|
||||||
{
|
// This is not a no-op, the entry might pre-exist.
|
||||||
// The variable may have been used before reaching the
|
m_localVarUseCount[&_variable] += 0;
|
||||||
// declaration. If it was, we must not reset the counter,
|
|
||||||
// but since [] will insert the default 0, we really just
|
|
||||||
// need to access the map here and let it do the rest on its
|
|
||||||
// own.
|
|
||||||
m_localVarUseCount[&_variable];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,7 @@ private:
|
|||||||
/// Flag that indicates whether a public function does not contain the "payable" modifier.
|
/// Flag that indicates whether a public function does not contain the "payable" modifier.
|
||||||
bool m_nonPayablePublic = false;
|
bool m_nonPayablePublic = false;
|
||||||
|
|
||||||
|
/// Number of uses of each (named) local variable in a function, counter is initialized with zero.
|
||||||
std::map<VariableDeclaration const*, int> m_localVarUseCount;
|
std::map<VariableDeclaration const*, int> m_localVarUseCount;
|
||||||
|
|
||||||
FunctionDefinition const* m_currentFunction = nullptr;
|
FunctionDefinition const* m_currentFunction = nullptr;
|
||||||
|
@ -5656,6 +5656,14 @@ BOOST_AUTO_TEST_CASE(warn_unused_return_param)
|
|||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
CHECK_WARNING(text, "Unused");
|
CHECK_WARNING(text, "Unused");
|
||||||
|
text = R"(
|
||||||
|
contract C {
|
||||||
|
function f() returns (uint a) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_WARNING(text, "Unused");
|
||||||
text = R"(
|
text = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f() returns (uint) {
|
function f() returns (uint) {
|
||||||
|
Loading…
Reference in New Issue
Block a user