mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Blocks and for loops can be scopes.
This commit is contained in:
@@ -610,6 +610,30 @@ void DeclarationRegistrationHelper::endVisit(ModifierDefinition&)
|
||||
closeCurrentScope();
|
||||
}
|
||||
|
||||
bool DeclarationRegistrationHelper::visit(Block& _block)
|
||||
{
|
||||
enterNewSubScope(_block);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeclarationRegistrationHelper::endVisit(Block&)
|
||||
{
|
||||
closeCurrentScope();
|
||||
}
|
||||
|
||||
bool DeclarationRegistrationHelper::visit(ForStatement& _for)
|
||||
{
|
||||
// TODO special scoping rules for the init statement - if it is a block, then it should
|
||||
// not open its own scope.
|
||||
enterNewSubScope(_for);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeclarationRegistrationHelper::endVisit(ForStatement&)
|
||||
{
|
||||
closeCurrentScope();
|
||||
}
|
||||
|
||||
void DeclarationRegistrationHelper::endVisit(VariableDeclarationStatement& _variableDeclarationStatement)
|
||||
{
|
||||
// Register the local variables with the function
|
||||
|
||||
@@ -167,6 +167,10 @@ private:
|
||||
void endVisit(FunctionDefinition& _function) override;
|
||||
bool visit(ModifierDefinition& _modifier) override;
|
||||
void endVisit(ModifierDefinition& _modifier) override;
|
||||
bool visit(Block& _block) override;
|
||||
void endVisit(Block& _block) override;
|
||||
bool visit(ForStatement& _forLoop) override;
|
||||
void endVisit(ForStatement& _forLoop) override;
|
||||
void endVisit(VariableDeclarationStatement& _variableDeclarationStatement) override;
|
||||
bool visit(VariableDeclaration& _declaration) override;
|
||||
bool visit(EventDefinition& _event) override;
|
||||
|
||||
@@ -43,6 +43,37 @@ bool ReferencesResolver::resolve(ASTNode const& _root)
|
||||
return !m_errorOccurred;
|
||||
}
|
||||
|
||||
bool ReferencesResolver::visit(Block const& _block)
|
||||
{
|
||||
if (!m_resolveInsideCode)
|
||||
return false;
|
||||
m_resolver.setScope(&_block);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReferencesResolver::endVisit(Block const& _block)
|
||||
{
|
||||
if (!m_resolveInsideCode)
|
||||
return;
|
||||
|
||||
m_resolver.setScope(_block.scope());
|
||||
}
|
||||
|
||||
bool ReferencesResolver::visit(ForStatement const& _for)
|
||||
{
|
||||
if (!m_resolveInsideCode)
|
||||
return false;
|
||||
m_resolver.setScope(&_for);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReferencesResolver::endVisit(ForStatement const& _for)
|
||||
{
|
||||
if (!m_resolveInsideCode)
|
||||
return;
|
||||
m_resolver.setScope(_for.scope());
|
||||
}
|
||||
|
||||
bool ReferencesResolver::visit(Identifier const& _identifier)
|
||||
{
|
||||
auto declarations = m_resolver.nameFromCurrentScope(_identifier.name());
|
||||
|
||||
@@ -57,7 +57,10 @@ public:
|
||||
bool resolve(ASTNode const& _root);
|
||||
|
||||
private:
|
||||
virtual bool visit(Block const&) override { return m_resolveInsideCode; }
|
||||
virtual bool visit(Block const& _block) override;
|
||||
virtual void endVisit(Block const& _block) override;
|
||||
virtual bool visit(ForStatement const& _for) override;
|
||||
virtual void endVisit(ForStatement const& _for) override;
|
||||
virtual bool visit(Identifier const& _identifier) override;
|
||||
virtual bool visit(ElementaryTypeName const& _typeName) override;
|
||||
virtual bool visit(FunctionDefinition const& _functionDefinition) override;
|
||||
|
||||
Reference in New Issue
Block a user