aboutsummaryrefslogtreecommitdiffstats
path: root/NameAndTypeResolver.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-10-30 08:20:32 +0800
committerChristian <c@ethdev.com>2014-10-30 08:25:42 +0800
commit7f19f3d133b74bd7ebc96d18b09e145417b7daac (patch)
treea344a8faf9675882eb42f4f83e57f3a825844dcf /NameAndTypeResolver.cpp
parent51349bdae53e7d495732085c446ff9488473dcc8 (diff)
downloaddexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar.gz
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar.bz2
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar.lz
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar.xz
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.tar.zst
dexon-solidity-7f19f3d133b74bd7ebc96d18b09e145417b7daac.zip
Contract compiler and also add ExpressionStatement to AST.
ExpressionStatement functions as glue between Statements and Expressions. This way it is possible to detect when the border between statements and expressions is crossed while walking the AST. Note that ExpressionStatement is not the only border, almost every statement can contains expressions.
Diffstat (limited to 'NameAndTypeResolver.cpp')
-rw-r--r--NameAndTypeResolver.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp
index 9626ca84..4b77ed13 100644
--- a/NameAndTypeResolver.cpp
+++ b/NameAndTypeResolver.cpp
@@ -55,12 +55,15 @@ void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
m_currentScope = &m_scopes[function.get()];
function->getBody().checkTypeRequirements();
}
+ m_currentScope = &m_scopes[nullptr];
}
-void NameAndTypeResolver::reset()
+Declaration* NameAndTypeResolver::resolveName(ASTString const& _name, Declaration const* _scope) const
{
- m_scopes.clear();
- m_currentScope = nullptr;
+ auto iterator = m_scopes.find(_scope);
+ if (iterator == end(m_scopes))
+ return nullptr;
+ return iterator->second.resolveName(_name, false);
}
Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name, bool _recursive)
@@ -68,8 +71,13 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name
return m_currentScope->resolveName(_name, _recursive);
}
+void NameAndTypeResolver::reset()
+{
+ m_scopes.clear();
+ m_currentScope = nullptr;
+}
-DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode*, Scope>& _scopes,
+DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode const*, Scope>& _scopes,
ASTNode& _astRoot):
m_scopes(_scopes), m_currentScope(&m_scopes[nullptr])
{
@@ -101,27 +109,33 @@ void DeclarationRegistrationHelper::endVisit(StructDefinition&)
bool DeclarationRegistrationHelper::visit(FunctionDefinition& _function)
{
registerDeclaration(_function, true);
+ m_currentFunction = &_function;
return true;
}
void DeclarationRegistrationHelper::endVisit(FunctionDefinition&)
{
+ m_currentFunction = nullptr;
closeCurrentScope();
}
-bool DeclarationRegistrationHelper::visit(VariableDeclaration& _declaration)
+void DeclarationRegistrationHelper::endVisit(VariableDefinition& _variableDefinition)
{
- registerDeclaration(_declaration, false);
- return true;
+ // Register the local variables with the function
+ // This does not fit here perfectly, but it saves us another AST visit.
+ assert(m_currentFunction);
+ m_currentFunction->addLocalVariable(_variableDefinition.getDeclaration());
}
-void DeclarationRegistrationHelper::endVisit(VariableDeclaration&)
+bool DeclarationRegistrationHelper::visit(VariableDeclaration& _declaration)
{
+ registerDeclaration(_declaration, false);
+ return true;
}
void DeclarationRegistrationHelper::enterNewSubScope(ASTNode& _node)
{
- map<ASTNode*, Scope>::iterator iter;
+ map<ASTNode const*, Scope>::iterator iter;
bool newlyAdded;
tie(iter, newlyAdded) = m_scopes.emplace(&_node, Scope(m_currentScope));
assert(newlyAdded);