Browse Source

FunctionType now returns const ref for Declaration

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
93abe45771
  1. 2
      alethzero/MainWin.cpp
  2. 2
      libsolidity/Compiler.cpp
  3. 6
      libsolidity/InterfaceHandler.cpp
  4. 4
      libsolidity/Types.cpp
  5. 7
      libsolidity/Types.h
  6. 2
      mix/QFunctionDefinition.cpp
  7. 2
      test/SolidityNameAndTypeResolution.cpp

2
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;
}

2
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());
}

6
libsolidity/InterfaceHandler.cpp

@ -59,9 +59,7 @@ std::unique_ptr<std::string> 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<string> 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())

4
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;

7
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

2
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();

2
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());

Loading…
Cancel
Save