mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	enhance DeclarationContainer to use std::set so that it can handle overloaded function names
				
					
				
			This commit is contained in:
		
							parent
							
								
									1efef53cb3
								
							
						
					
					
						commit
						068bb5d731
					
				| @ -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*>({}); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -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; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user