FunctionType now returns const ref for Declaration

This commit is contained in:
Lefteris Karapetsas 2015-01-29 18:44:14 +01:00
parent 04190798eb
commit 3701543ae8
4 changed files with 11 additions and 8 deletions

View File

@ -164,7 +164,7 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract)
m_context << callDataUnpackerEntryPoints.at(it.first); m_context << callDataUnpackerEntryPoints.at(it.first);
eth::AssemblyItem returnTag = m_context.pushNewTag(); eth::AssemblyItem returnTag = m_context.pushNewTag();
appendCalldataUnpacker(functionType->getParameterTypes()); appendCalldataUnpacker(functionType->getParameterTypes());
m_context.appendJumpTo(m_context.getFunctionEntryLabel(*it.second->getDeclaration())); m_context.appendJumpTo(m_context.getFunctionEntryLabel(it.second->getDeclaration()));
m_context << returnTag; m_context << returnTag;
appendReturnValuePacker(functionType->getReturnParameterTypes()); appendReturnValuePacker(functionType->getReturnParameterTypes());
} }

View File

@ -59,9 +59,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
} }
return params; return params;
}; };
method["name"] = it.second->getDeclaration().getName();
solAssert(it.second->getDeclaration(), "All function interface types should contain a declaration");
method["name"] = it.second->getDeclaration()->getName();
method["constant"] = it.second->isConstant(); method["constant"] = it.second->isConstant();
method["inputs"] = populateParameters(it.second->getParameterNames(), method["inputs"] = populateParameters(it.second->getParameterNames(),
it.second->getParameterTypeNames()); it.second->getParameterTypeNames());
@ -86,7 +84,7 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i]; r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i];
return r.size() ? r + ")" : "()"; return r.size() ? r + ")" : "()";
}; };
ret += "function " + it.second->getDeclaration()->getName() + ret += "function " + it.second->getDeclaration().getName() +
populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()) + populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()) +
(it.second->isConstant() ? "constant " : ""); (it.second->isConstant() ? "constant " : "");
if (it.second->getReturnParameterTypes().size()) if (it.second->getReturnParameterTypes().size())

View File

@ -499,7 +499,7 @@ MemberList const& ContractType::getMembers() const
} }
else else
for (auto const& it: m_contract.getInterfaceFunctions()) for (auto const& it: m_contract.getInterfaceFunctions())
members[it.second->getDeclaration()->getName()] = it.second; members[it.second->getDeclaration().getName()] = it.second;
m_members.reset(new MemberList(members)); m_members.reset(new MemberList(members));
} }
return *m_members; return *m_members;
@ -522,7 +522,7 @@ u256 ContractType::getFunctionIdentifier(string const& _functionName) const
{ {
auto interfaceFunctions = m_contract.getInterfaceFunctions(); auto interfaceFunctions = m_contract.getInterfaceFunctions();
for (auto const& it: m_contract.getInterfaceFunctions()) for (auto const& it: m_contract.getInterfaceFunctions())
if (it.second->getDeclaration()->getName() == _functionName) if (it.second->getDeclaration().getName() == _functionName)
return FixedHash<4>::Arith(it.first); return FixedHash<4>::Arith(it.first);
return Invalid256; return Invalid256;

View File

@ -390,7 +390,12 @@ public:
/// If @a _name is not provided (empty string) then the @c m_declaration member of the /// If @a _name is not provided (empty string) then the @c m_declaration member of the
/// function type is used /// function type is used
std::string getCanonicalSignature(std::string const& _name = "") const; std::string getCanonicalSignature(std::string const& _name = "") const;
Declaration const* getDeclaration() const { return m_declaration; } Declaration const& getDeclaration() const
{
solAssert(m_declaration, "Requested declaration from a FunctionType that has none");
return *m_declaration;
}
bool hasDeclaration() const { return !!m_declaration; }
bool isConstant() const { return m_isConstant; } bool isConstant() const { return m_isConstant; }
/// @return A shared pointer of an ASTString. /// @return A shared pointer of an ASTString.
/// Can contain a nullptr in which case indicates absence of documentation /// Can contain a nullptr in which case indicates absence of documentation