diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 289603b60..8d889730c 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1674,7 +1674,7 @@ string const Main::getFunctionHashes(dev::solidity::CompilerStack const &_compil { ret += it.first.abridged(); ret += " :"; - ret += it.second->getDeclaration()->getName() + "\n"; + ret += it.second->getDeclaration().getName() + "\n"; } return ret; } diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 79672ca10..1fa31ce7d 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -164,7 +164,7 @@ void Compiler::appendFunctionSelector(ContractDefinition const& _contract) m_context << callDataUnpackerEntryPoints.at(it.first); eth::AssemblyItem returnTag = m_context.pushNewTag(); appendCalldataUnpacker(functionType->getParameterTypes()); - m_context.appendJumpTo(m_context.getFunctionEntryLabel(*it.second->getDeclaration())); + m_context.appendJumpTo(m_context.getFunctionEntryLabel(it.second->getDeclaration())); m_context << returnTag; appendReturnValuePacker(functionType->getReturnParameterTypes()); } diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index 4d3ec4d50..92cd51562 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -59,9 +59,7 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio } return params; }; - - solAssert(it.second->getDeclaration(), "All function interface types should contain a declaration"); - method["name"] = it.second->getDeclaration()->getName(); + method["name"] = it.second->getDeclaration().getName(); method["constant"] = it.second->isConstant(); method["inputs"] = populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()); @@ -86,7 +84,7 @@ unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition r += (r.size() ? "," : "(") + _paramTypes[i] + " " + _paramNames[i]; return r.size() ? r + ")" : "()"; }; - ret += "function " + it.second->getDeclaration()->getName() + + ret += "function " + it.second->getDeclaration().getName() + populateParameters(it.second->getParameterNames(), it.second->getParameterTypeNames()) + (it.second->isConstant() ? "constant " : ""); if (it.second->getReturnParameterTypes().size()) diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 38caaf8ff..bebb4be17 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -499,7 +499,7 @@ MemberList const& ContractType::getMembers() const } else 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)); } return *m_members; @@ -522,7 +522,7 @@ u256 ContractType::getFunctionIdentifier(string const& _functionName) const { auto interfaceFunctions = 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 Invalid256; diff --git a/libsolidity/Types.h b/libsolidity/Types.h index b8ad7449e..4b4d17d0a 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -390,7 +390,12 @@ public: /// If @a _name is not provided (empty string) then the @c m_declaration member of the /// function type is used 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; } /// @return A shared pointer of an ASTString. /// Can contain a nullptr in which case indicates absence of documentation diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 3aaec2cb3..20dbe070b 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -28,7 +28,7 @@ using namespace dev::solidity; using namespace dev::mix; -QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(_f->getDeclaration()), m_hash(dev::sha3(_f->getCanonicalSignature())) +QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(&_f->getDeclaration()), m_hash(dev::sha3(_f->getCanonicalSignature())) { auto paramNames = _f->getParameterNames(); auto paramTypes = _f->getParameterTypeNames(); diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index e330d772c..07f2d638a 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -644,7 +644,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr); FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); - BOOST_CHECK_MESSAGE(function->getDeclaration() != nullptr, "Could not find the accessor function"); + BOOST_REQUIRE(function->hasDeclaration()); auto returnParams = function->getReturnParameterTypeNames(); BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); BOOST_CHECK(function->isConstant());