From 495d827eceb2f8160421d0f7ce86d1183b54b3de Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Thu, 7 May 2015 16:52:06 +0200 Subject: [PATCH] implemented cleanup of duplication in resolver --- AST.cpp | 3 +++ NameAndTypeResolver.cpp | 25 +++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/AST.cpp b/AST.cpp index 2f98ce4f6..2ef3b03e8 100644 --- a/AST.cpp +++ b/AST.cpp @@ -954,6 +954,9 @@ Declaration const& Identifier::getReferencedDeclaration() const void Identifier::overloadResolution(TypePointers const& _argumentTypes) { solAssert(!m_referencedDeclaration, "Referenced declaration should be null before overload resolution."); + //to delete + if (m_overloadedDeclarations.empty()) + //---------------------------> solAssert(!m_overloadedDeclarations.empty(), "No candidates for overload resolution found."); vector possibles; diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp index 4d33048dc..ac841fccc 100644 --- a/NameAndTypeResolver.cpp +++ b/NameAndTypeResolver.cpp @@ -132,12 +132,14 @@ vector NameAndTypeResolver::getNameFromCurrentScope(ASTStrin vector NameAndTypeResolver::cleanupedDeclarations(Identifier const& _identifier) { - vector result; - for (auto declaration : m_currentScope->resolveName(_identifier.getName())) + vector uniqueFunctions; + + auto declarations = m_currentScope->resolveName(_identifier.getName()); + for (auto it = declarations.begin(); it != declarations.end(); ++it) { - solAssert(declaration, ""); + solAssert(*it, ""); // the declaration is functionDefinition while declarations > 1 - FunctionDefinition const& functionDefinition = dynamic_cast(*declaration); + FunctionDefinition const& functionDefinition = dynamic_cast(**it); FunctionType functionType(functionDefinition); for(auto parameter: functionType.getParameterTypes() + functionType.getReturnParameterTypes()) if (!parameter) @@ -146,9 +148,20 @@ vector NameAndTypeResolver::cleanupedDeclarations(Identifier errinfo_sourceLocation(_identifier.getLocation()) << errinfo_comment("Function type can not be used in this context") ); - //////////delete repitations. check by hasequalparameter types of function type + if (uniqueFunctions.end() == find_if( + uniqueFunctions.begin(), + uniqueFunctions.end(), + [&](Declaration const* d) + { + FunctionDefinition const& newFunctionDefinition = dynamic_cast(*d); + FunctionType newFunctionType(newFunctionDefinition); + + return functionType.hasEqualArgumentTypes(newFunctionType); + } + )) + uniqueFunctions.push_back(*it); } - return result; + return uniqueFunctions; } void NameAndTypeResolver::importInheritedScope(ContractDefinition const& _base)