aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-14 08:48:40 +0800
committerchriseth <chris@ethereum.org>2018-02-27 19:17:25 +0800
commit6b9dda06f3d85344a70efb2f868760a0dde9dc45 (patch)
tree860f6e2c040387261969907fc1214b6aa9bc234d /libsolidity/analysis
parente227bdbfa7157d2675c177c75d44e13f0bd82214 (diff)
downloaddexon-solidity-6b9dda06f3d85344a70efb2f868760a0dde9dc45.tar.gz
dexon-solidity-6b9dda06f3d85344a70efb2f868760a0dde9dc45.tar.zst
dexon-solidity-6b9dda06f3d85344a70efb2f868760a0dde9dc45.zip
Enable C99-scoping with the 0.5.0-experimental pragma.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp30
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp17
-rw-r--r--libsolidity/analysis/ReferencesResolver.h1
3 files changed, 31 insertions, 17 deletions
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index 1566df94..40021771 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -612,26 +612,34 @@ void DeclarationRegistrationHelper::endVisit(ModifierDefinition&)
bool DeclarationRegistrationHelper::visit(Block& _block)
{
- enterNewSubScope(_block);
+ _block.setScope(m_currentScope);
+ // Enable C99-scoped variables.
+ if (_block.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
+ enterNewSubScope(_block);
return true;
}
-void DeclarationRegistrationHelper::endVisit(Block&)
+void DeclarationRegistrationHelper::endVisit(Block& _block)
{
- closeCurrentScope();
+ // Enable C99-scoped variables.
+ if (_block.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
+ 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);
+ _for.setScope(m_currentScope);
+ if (_for.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
+ // 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&)
+void DeclarationRegistrationHelper::endVisit(ForStatement& _for)
{
- closeCurrentScope();
+ if (_for.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
+ closeCurrentScope();
}
void DeclarationRegistrationHelper::endVisit(VariableDeclarationStatement& _variableDeclarationStatement)
@@ -663,9 +671,6 @@ void DeclarationRegistrationHelper::endVisit(EventDefinition&)
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()));
@@ -701,10 +706,9 @@ 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/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index bee42e77..4d919f2b 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -47,7 +47,10 @@ bool ReferencesResolver::visit(Block const& _block)
{
if (!m_resolveInsideCode)
return false;
- m_resolver.setScope(&_block);
+ m_experimental050Mode = _block.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
+ // C99-scoped variables
+ if (m_experimental050Mode)
+ m_resolver.setScope(&_block);
return true;
}
@@ -56,14 +59,19 @@ void ReferencesResolver::endVisit(Block const& _block)
if (!m_resolveInsideCode)
return;
- m_resolver.setScope(_block.scope());
+ // C99-scoped variables
+ if (m_experimental050Mode)
+ m_resolver.setScope(_block.scope());
}
bool ReferencesResolver::visit(ForStatement const& _for)
{
if (!m_resolveInsideCode)
return false;
- m_resolver.setScope(&_for);
+ m_experimental050Mode = _for.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
+ // C99-scoped variables
+ if (m_experimental050Mode)
+ m_resolver.setScope(&_for);
return true;
}
@@ -71,7 +79,8 @@ void ReferencesResolver::endVisit(ForStatement const& _for)
{
if (!m_resolveInsideCode)
return;
- m_resolver.setScope(_for.scope());
+ if (m_experimental050Mode)
+ m_resolver.setScope(_for.scope());
}
bool ReferencesResolver::visit(Identifier const& _identifier)
diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h
index 5bfd6c5a..ab7c987e 100644
--- a/libsolidity/analysis/ReferencesResolver.h
+++ b/libsolidity/analysis/ReferencesResolver.h
@@ -93,6 +93,7 @@ private:
std::vector<ParameterList const*> m_returnParameters;
bool const m_resolveInsideCode;
bool m_errorOccurred = false;
+ bool m_experimental050Mode = false;
};
}