diff options
author | Lu Guanqun <guanqun.lu@gmail.com> | 2015-02-28 16:15:27 +0800 |
---|---|---|
committer | Lu Guanqun <guanqun.lu@gmail.com> | 2015-03-08 22:48:53 +0800 |
commit | 068bb5d7316fea411ef8e20eb3f6844c9c10dd23 (patch) | |
tree | 7637e8982a18c48cc5faa327aa7a87945f916d54 /DeclarationContainer.cpp | |
parent | 1efef53cb373788a7980c85d7d038649214ee0ba (diff) | |
download | dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.gz dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.zst dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.zip |
enhance DeclarationContainer to use `std::set` so that it can handle overloaded function names
Diffstat (limited to 'DeclarationContainer.cpp')
-rw-r--r-- | DeclarationContainer.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/DeclarationContainer.cpp b/DeclarationContainer.cpp index 2594d428..226b9d68 100644 --- a/DeclarationContainer.cpp +++ b/DeclarationContainer.cpp @@ -22,6 +22,7 @@ #include <libsolidity/DeclarationContainer.h> #include <libsolidity/AST.h> +#include <libsolidity/Types.h> namespace dev { @@ -34,17 +35,35 @@ bool DeclarationContainer::registerDeclaration(Declaration const& _declaration, if (name.empty()) return true; - if (!_update && (m_declarations.count(name) || m_invisibleDeclarations.count(name))) - return false; + if (!_update) + { + if (dynamic_cast<FunctionDefinition const*>(&_declaration)) + { + // other declarations must be FunctionDefinition, otherwise clash with other declarations. + for (auto&& declaration: m_declarations[_declaration.getName()]) + if (dynamic_cast<FunctionDefinition const*>(declaration) == nullptr) + return false; + } + else if (m_declarations.count(_declaration.getName()) != 0) + return false; + } + else + { + // update declaration + solAssert(dynamic_cast<FunctionDefinition const*>(&_declaration) == nullptr, "cannot be FunctionDefinition"); + + m_declarations[_declaration.getName()].clear(); + } if (_invisible) m_invisibleDeclarations.insert(name); else - m_declarations[name] = &_declaration; + m_declarations[_declaration.getName()].insert(&_declaration); + return true; } -Declaration const* DeclarationContainer::resolveName(ASTString const& _name, bool _recursive) const +std::set<Declaration const*> DeclarationContainer::resolveName(ASTString const& _name, bool _recursive) const { solAssert(!_name.empty(), "Attempt to resolve empty name."); auto result = m_declarations.find(_name); @@ -52,7 +71,7 @@ Declaration const* DeclarationContainer::resolveName(ASTString const& _name, boo return result->second; if (_recursive && m_enclosingContainer) return m_enclosingContainer->resolveName(_name, true); - return nullptr; + return std::set<Declaration const*>({}); } } |