aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-09 23:53:25 +0800
committerchriseth <chris@ethereum.org>2018-02-27 19:17:25 +0800
commit5f20129e65f5b8b714189145d177067152a21ac1 (patch)
tree26c56df153f67bc2bf0f370216a81b314ec4987f /libsolidity/analysis
parent53289e15a2e1ea540a0c3abe28219c326a614fe5 (diff)
downloaddexon-solidity-5f20129e65f5b8b714189145d177067152a21ac1.tar.gz
dexon-solidity-5f20129e65f5b8b714189145d177067152a21ac1.tar.zst
dexon-solidity-5f20129e65f5b8b714189145d177067152a21ac1.zip
Scopes do not have to be declarations.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp29
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.h5
2 files changed, 23 insertions, 11 deletions
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index 2693eb97..953b788d 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -244,19 +244,24 @@ void NameAndTypeResolver::warnVariablesNamedLikeInstructions()
}
}
+void NameAndTypeResolver::setScope(ASTNode const* _node)
+{
+ m_currentScope = m_scopes[_node].get();
+}
+
bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode)
{
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(&_node))
{
bool success = true;
- m_currentScope = m_scopes[contract->scope()].get();
+ setScope(contract->scope());
solAssert(!!m_currentScope, "");
for (ASTPointer<InheritanceSpecifier> const& baseContract: contract->baseContracts())
if (!resolveNamesAndTypes(*baseContract, true))
success = false;
- m_currentScope = m_scopes[contract].get();
+ setScope(contract);
if (success)
{
@@ -273,7 +278,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
// these can contain code, only resolve parameters for now
for (ASTPointer<ASTNode> const& node: contract->subNodes())
{
- m_currentScope = m_scopes[contract].get();
+ setScope(contract);
if (!resolveNamesAndTypes(*node, false))
{
success = false;
@@ -287,12 +292,12 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
if (!_resolveInsideCode)
return success;
- m_currentScope = m_scopes[contract].get();
+ setScope(contract);
// now resolve references inside the code
for (ASTPointer<ASTNode> const& node: contract->subNodes())
{
- m_currentScope = m_scopes[contract].get();
+ setScope(contract);
if (!resolveNamesAndTypes(*node, true))
success = false;
}
@@ -301,7 +306,7 @@ bool NameAndTypeResolver::resolveNamesAndTypesInternal(ASTNode& _node, bool _res
else
{
if (m_scopes.count(&_node))
- m_currentScope = m_scopes[&_node].get();
+ setScope(&_node);
return ReferencesResolver(m_errorReporter, *this, _resolveInsideCode).resolve(_node);
}
}
@@ -632,14 +637,17 @@ void DeclarationRegistrationHelper::endVisit(EventDefinition&)
closeCurrentScope();
}
-void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declaration)
+void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _subScope)
{
+ if (auto s = dynamic_cast<Scopable*>(&_subScope))
+ s->setScope(m_currentScope);
+
map<ASTNode const*, shared_ptr<DeclarationContainer>>::iterator iter;
bool newlyAdded;
shared_ptr<DeclarationContainer> container(new DeclarationContainer(m_currentScope, m_scopes[m_currentScope].get()));
- tie(iter, newlyAdded) = m_scopes.emplace(&_declaration, move(container));
+ tie(iter, newlyAdded) = m_scopes.emplace(&_subScope, move(container));
solAssert(newlyAdded, "Unable to add new scope.");
- m_currentScope = &_declaration;
+ m_currentScope = &_subScope;
}
void DeclarationRegistrationHelper::closeCurrentScope()
@@ -669,9 +677,10 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio
registerDeclaration(*m_scopes[m_currentScope], _declaration, nullptr, nullptr, warnAboutShadowing, m_errorReporter);
- _declaration.setScope(m_currentScope);
if (_opensScope)
enterNewSubScope(_declaration);
+ else
+ _declaration.setScope(m_currentScope);
}
string DeclarationRegistrationHelper::currentCanonicalName() const
diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h
index 35f5d31e..d1fbe53c 100644
--- a/libsolidity/analysis/NameAndTypeResolver.h
+++ b/libsolidity/analysis/NameAndTypeResolver.h
@@ -97,6 +97,9 @@ public:
/// @returns a list of similar identifiers in the current and enclosing scopes. May return empty string if no suggestions.
std::string similarNameSuggestions(ASTString const& _name) const;
+ /// Sets the current scope.
+ void setScope(ASTNode const* _node);
+
private:
/// Internal version of @a resolveNamesAndTypes (called from there) throws exceptions on fatal errors.
bool resolveNamesAndTypesInternal(ASTNode& _node, bool _resolveInsideCode = true);
@@ -169,7 +172,7 @@ private:
bool visit(EventDefinition& _event) override;
void endVisit(EventDefinition& _event) override;
- void enterNewSubScope(Declaration const& _declaration);
+ void enterNewSubScope(ASTNode& _subScope);
void closeCurrentScope();
void registerDeclaration(Declaration& _declaration, bool _opensScope);