mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Helper to count the number of variables in a scope.
This commit is contained in:
parent
8e5c4bf21d
commit
78b49db779
@ -43,8 +43,7 @@ void CodeTransform::run(Block const& _block)
|
|||||||
m_assembly.setSourceLocation(_block.location);
|
m_assembly.setSourceLocation(_block.location);
|
||||||
|
|
||||||
// pop variables
|
// pop variables
|
||||||
for (auto const& identifier: m_scope->identifiers)
|
for (size_t i = 0; i < m_scope->numberOfVariables(); ++i)
|
||||||
if (identifier.second.type() == typeid(Scope::Variable))
|
|
||||||
m_assembly.appendInstruction(solidity::Instruction::POP);
|
m_assembly.appendInstruction(solidity::Instruction::POP);
|
||||||
|
|
||||||
int deposit = m_assembly.stackHeight() - blockStartStackHeight;
|
int deposit = m_assembly.stackHeight() - blockStartStackHeight;
|
||||||
|
@ -349,9 +349,7 @@ bool AsmAnalyzer::operator()(Block const& _block)
|
|||||||
if (!boost::apply_visitor(*this, s))
|
if (!boost::apply_visitor(*this, s))
|
||||||
success = false;
|
success = false;
|
||||||
|
|
||||||
for (auto const& identifier: scope(&_block).identifiers)
|
m_stackHeight -= scope(&_block).numberOfVariables();
|
||||||
if (identifier.second.type() == typeid(Scope::Variable))
|
|
||||||
--m_stackHeight;
|
|
||||||
|
|
||||||
int const stackDiff = m_stackHeight - initialStackHeight;
|
int const stackDiff = m_stackHeight - initialStackHeight;
|
||||||
if (stackDiff != 0)
|
if (stackDiff != 0)
|
||||||
|
@ -80,6 +80,15 @@ bool Scope::exists(string const& _name)
|
|||||||
return false;
|
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
|
bool Scope::insideFunction() const
|
||||||
{
|
{
|
||||||
for (Scope const* s = this; s; s = s->superScope)
|
for (Scope const* s = this; s; s = s->superScope)
|
||||||
|
@ -109,6 +109,8 @@ struct Scope
|
|||||||
/// across function and assembly boundaries).
|
/// across function and assembly boundaries).
|
||||||
bool exists(std::string const& _name);
|
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.
|
/// @returns true if this scope is inside a function.
|
||||||
bool insideFunction() const;
|
bool insideFunction() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user