Enable C99-scoping with the 0.5.0-experimental pragma.

This commit is contained in:
chriseth
2018-02-27 12:17:25 +01:00
parent e227bdbfa7
commit 6b9dda06f3
6 changed files with 98 additions and 40 deletions
+17 -13
View File
@@ -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
+13 -4
View File
@@ -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)
@@ -93,6 +93,7 @@ private:
std::vector<ParameterList const*> m_returnParameters;
bool const m_resolveInsideCode;
bool m_errorOccurred = false;
bool m_experimental050Mode = false;
};
}