diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2017-04-29 04:28:03 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-05-03 17:26:21 +0800 |
commit | a6faa5acf324a127aad11b354e48d7bb2bcf0fbc (patch) | |
tree | 1ec5c56660c185e945ed2f8c1999fc1c6e172623 /libsolidity/analysis | |
parent | a40c8cfb68f75c22c0082714d99e9c3a24a31051 (diff) | |
download | dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar.gz dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar.bz2 dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar.lz dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar.xz dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.tar.zst dexon-solidity-a6faa5acf324a127aad11b354e48d7bb2bcf0fbc.zip |
Treat returns with expressions as return param use
There are many cases of code where the return parameters exist mostly
as a form of documentation. This change ensures that they do not have
to be used in the function body so long as there is a return supplying
values
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.cpp | 12 | ||||
-rw-r--r-- | libsolidity/analysis/StaticAnalyzer.h | 3 |
2 files changed, 14 insertions, 1 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 55e7cb59..21c97c3b 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -50,6 +50,7 @@ bool StaticAnalyzer::visit(FunctionDefinition const& _function) { if (_function.isImplemented()) m_inFunction = true; + m_currentFunction = &_function; m_localVarUseCount.clear(); m_nonPayablePublic = _function.isPublic() && !_function.isPayable(); return true; @@ -96,6 +97,17 @@ bool StaticAnalyzer::visit(VariableDeclaration const& _variable) return true; } +bool StaticAnalyzer::visit(Return const& _return) +{ + // If the return has an expression, it counts as + // a "use" of the return parameters. + if (m_inFunction && _return.expression() != NULL) + for (auto const& var: m_currentFunction->returnParameterList()->parameters()) + if (var->name() != "") + m_localVarUseCount[var.get()] += 1; + return true; +} + bool StaticAnalyzer::visit(ExpressionStatement const& _statement) { if (_statement.expression().annotation().isPure) diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index 134ff95a..c1ff6b24 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -63,7 +63,7 @@ private: virtual bool visit(ExpressionStatement const& _statement) override; virtual bool visit(VariableDeclaration const& _variable) override; virtual bool visit(Identifier const& _identifier) override; - + virtual bool visit(Return const& _return) override; virtual bool visit(MemberAccess const& _memberAccess) override; ErrorList& m_errors; @@ -76,6 +76,7 @@ private: std::map<VariableDeclaration const*, int> m_localVarUseCount; + const FunctionDefinition *m_currentFunction; bool m_inFunction = false; }; |