aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2015-02-28 16:15:27 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2015-03-08 22:48:53 +0800
commit068bb5d7316fea411ef8e20eb3f6844c9c10dd23 (patch)
tree7637e8982a18c48cc5faa327aa7a87945f916d54
parent1efef53cb373788a7980c85d7d038649214ee0ba (diff)
downloaddexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.gz
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.bz2
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.lz
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.xz
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.tar.zst
dexon-solidity-068bb5d7316fea411ef8e20eb3f6844c9c10dd23.zip
enhance DeclarationContainer to use `std::set` so that it can handle overloaded function names
-rw-r--r--DeclarationContainer.cpp29
-rw-r--r--DeclarationContainer.h6
2 files changed, 27 insertions, 8 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*>({});
}
}
diff --git a/DeclarationContainer.h b/DeclarationContainer.h
index f70881f5..42784ec2 100644
--- a/DeclarationContainer.h
+++ b/DeclarationContainer.h
@@ -48,14 +48,14 @@ public:
/// @param _update if true, replaces a potential declaration that is already present
/// @returns false if the name was already declared.
bool registerDeclaration(Declaration const& _declaration, bool _invisible = false, bool _update = false);
- Declaration const* resolveName(ASTString const& _name, bool _recursive = false) const;
+ std::set<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const;
Declaration const* getEnclosingDeclaration() const { return m_enclosingDeclaration; }
- std::map<ASTString, Declaration const*> const& getDeclarations() const { return m_declarations; }
+ std::map<ASTString, std::set<Declaration const*>> const& getDeclarations() const { return m_declarations; }
private:
Declaration const* m_enclosingDeclaration;
DeclarationContainer const* m_enclosingContainer;
- std::map<ASTString, Declaration const*> m_declarations;
+ std::map<ASTString, std::set<Declaration const*>> m_declarations;
std::set<ASTString> m_invisibleDeclarations;
};