diff options
author | chriseth <chris@ethereum.org> | 2017-06-01 21:47:11 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-16 17:56:21 +0800 |
commit | 78b49db779376b8ddedc0abb91a82a3384def4f1 (patch) | |
tree | 38aa28acbdf1e7c072a3fe301c8d7b06a105be50 /libsolidity/inlineasm | |
parent | 8e5c4bf21dfd9cfaa8de35aef034bb32be290a48 (diff) | |
download | dexon-solidity-78b49db779376b8ddedc0abb91a82a3384def4f1.tar.gz dexon-solidity-78b49db779376b8ddedc0abb91a82a3384def4f1.tar.zst dexon-solidity-78b49db779376b8ddedc0abb91a82a3384def4f1.zip |
Helper to count the number of variables in a scope.
Diffstat (limited to 'libsolidity/inlineasm')
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.cpp | 4 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmScope.cpp | 9 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmScope.h | 2 |
3 files changed, 12 insertions, 3 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 548f1a74..2891ec95 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -349,9 +349,7 @@ bool AsmAnalyzer::operator()(Block const& _block) if (!boost::apply_visitor(*this, s)) success = false; - for (auto const& identifier: scope(&_block).identifiers) - if (identifier.second.type() == typeid(Scope::Variable)) - --m_stackHeight; + m_stackHeight -= scope(&_block).numberOfVariables(); int const stackDiff = m_stackHeight - initialStackHeight; if (stackDiff != 0) diff --git a/libsolidity/inlineasm/AsmScope.cpp b/libsolidity/inlineasm/AsmScope.cpp index 1db5ca41..315d5953 100644 --- a/libsolidity/inlineasm/AsmScope.cpp +++ b/libsolidity/inlineasm/AsmScope.cpp @@ -80,6 +80,15 @@ bool Scope::exists(string const& _name) return false; } +size_t Scope::numberOfVariables() const +{ + size_t count = 0; + for (auto const& identifier: identifiers) + if (identifier.second.type() == typeid(Scope::Variable)) + count++; + return count; +} + bool Scope::insideFunction() const { for (Scope const* s = this; s; s = s->superScope) diff --git a/libsolidity/inlineasm/AsmScope.h b/libsolidity/inlineasm/AsmScope.h index de9119e0..cc240565 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libsolidity/inlineasm/AsmScope.h @@ -109,6 +109,8 @@ struct Scope /// across function and assembly boundaries). bool exists(std::string const& _name); + /// @returns the number of variables directly registered inside the scope. + size_t numberOfVariables() const; /// @returns true if this scope is inside a function. bool insideFunction() const; |