aboutsummaryrefslogtreecommitdiffstats
path: root/NameAndTypeResolver.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-12-01 22:22:45 +0800
committerChristian <c@ethdev.com>2014-12-02 00:33:21 +0800
commit9e91596c8d5683e79314fcd53a18e0e3df7b3390 (patch)
tree403740e7f56b4f6fc9d7b49b1c7383f5cdb99a5f /NameAndTypeResolver.cpp
parent3fc2708d657525162567b663a07cf8cb5b1c59aa (diff)
downloaddexon-solidity-9e91596c8d5683e79314fcd53a18e0e3df7b3390.tar.gz
dexon-solidity-9e91596c8d5683e79314fcd53a18e0e3df7b3390.tar.zst
dexon-solidity-9e91596c8d5683e79314fcd53a18e0e3df7b3390.zip
Save the scope for every declaration.
Diffstat (limited to 'NameAndTypeResolver.cpp')
-rw-r--r--NameAndTypeResolver.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp
index 225f2a78..d473348b 100644
--- a/NameAndTypeResolver.cpp
+++ b/NameAndTypeResolver.cpp
@@ -78,9 +78,9 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name
return m_currentScope->resolveName(_name, _recursive);
}
-DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode const*, Scope>& _scopes,
+DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode const*, DeclarationContainer>& _scopes,
ASTNode& _astRoot):
- m_scopes(_scopes), m_currentScope(&m_scopes[nullptr])
+ m_scopes(_scopes), m_currentScope(nullptr)
{
_astRoot.accept(*this);
}
@@ -135,31 +135,30 @@ bool DeclarationRegistrationHelper::visit(VariableDeclaration& _declaration)
return true;
}
-void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node)
+void DeclarationRegistrationHelper::enterNewSubScope(Declaration& _declaration)
{
- map<ASTNode const*, Scope>::iterator iter;
+ map<ASTNode const*, DeclarationContainer>::iterator iter;
bool newlyAdded;
- tie(iter, newlyAdded) = m_scopes.emplace(&_node, Scope(m_currentScope));
+ tie(iter, newlyAdded) = m_scopes.emplace(&_declaration, DeclarationContainer(m_currentScope, &m_scopes[m_currentScope]));
if (asserts(newlyAdded))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unable to add new scope."));
- m_currentScope = &iter->second;
+ m_currentScope = &_declaration;
}
void DeclarationRegistrationHelper::closeCurrentScope()
{
if (asserts(m_currentScope))
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Closed non-existing scope."));
- m_currentScope = m_currentScope->getEnclosingScope();
+ m_currentScope = m_scopes[m_currentScope].getEnclosingDeclaration();
}
void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaration, bool _opensScope)
{
- if (asserts(m_currentScope))
- BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Declaration registered without scope."));
- if (!m_currentScope->registerDeclaration(_declaration))
+ if (!m_scopes[m_currentScope].registerDeclaration(_declaration))
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_declaration.getLocation())
<< errinfo_comment("Identifier already declared."));
//@todo the exception should also contain the location of the first declaration
+ _declaration.setScope(m_currentScope);
if (_opensScope)
enterNewSubScope(_declaration);
}