From 3cc04923015cc3f40ad285fba5ed71464bd9ff2a Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Thu, 22 Jan 2015 17:40:22 +0100 Subject: Work in progress for state variable accessors - Changed the code so that a generic declaration with the combination of a function type can be used wherer a function definition was used before - Since using an std::pair everywhere is really tiring with this commit I am in the process of abstracting it into a function --- AST.cpp | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) (limited to 'AST.cpp') diff --git a/AST.cpp b/AST.cpp index e5967caa..7620eeec 100644 --- a/AST.cpp +++ b/AST.cpp @@ -68,19 +68,21 @@ void ContractDefinition::checkTypeRequirements() set> hashes; for (auto const& hashAndFunction: getInterfaceFunctionList()) { - FixedHash<4> const& hash = hashAndFunction.first; + FixedHash<4> const& hash = std::get<0>(hashAndFunction); if (hashes.count(hash)) - BOOST_THROW_EXCEPTION(createTypeError("Function signature hash collision for " + - hashAndFunction.second->getCanonicalSignature())); + BOOST_THROW_EXCEPTION(createTypeError( + "Function signature hash collision for " + + std::get<1>(hashAndFunction)>->getCanonicalSignature(std::get<2>(hashAndFunction)->getName()))); hashes.insert(hash); } } -map, FunctionDefinition const*> ContractDefinition::getInterfaceFunctions() const +map, pair> ContractDefinition::getInterfaceFunctions() const { - vector, FunctionDefinition const*>> exportedFunctionList = getInterfaceFunctionList(); - map, FunctionDefinition const*> exportedFunctions(exportedFunctionList.begin(), - exportedFunctionList.end()); + vector, FunctionType const*, Declaration const*>>> exportedFunctionList = getInterfaceFunctionList(); + map, pair> exportedFunctions(exportedFunctionList.begin(), + exportedFunctionList.end()); + solAssert(exportedFunctionList.size() == exportedFunctions.size(), "Hash collision at Function Definition Hash calculation"); @@ -134,20 +136,31 @@ void ContractDefinition::checkIllegalOverrides() const } } -vector, FunctionDefinition const*>> const& ContractDefinition::getInterfaceFunctionList() const +vector, FunctionType const*, Declaration const*>> const& ContractDefinition::getInterfaceFunctionList() const { if (!m_interfaceFunctionList) { set functionsSeen; - m_interfaceFunctionList.reset(new vector, FunctionDefinition const*>>()); + m_interfaceFunctionList.reset(new vector, FunctionType const*, Declaration const*>>()); for (ContractDefinition const* contract: getLinearizedBaseContracts()) + { for (ASTPointer const& f: contract->getDefinedFunctions()) if (f->isPublic() && !f->isConstructor() && functionsSeen.count(f->getName()) == 0) { functionsSeen.insert(f->getName()); FixedHash<4> hash(dev::sha3(f->getCanonicalSignature())); - m_interfaceFunctionList->push_back(make_pair(hash, f.get())); + m_interfaceFunctionList->push_back(make_tuple(hash, FunctionType(*f), f.get())); } + + for (ASTPointer const& v: contract->getStateVariables()) + if (v->isPublic()) + { + FunctionType ftype(*v); + functionsSeen.insert(v->getName()); + FixedHash<4> hash(dev::sha3(ftype.getCanonicalSignature(v->getName())); + m_interfaceFunctionList->push_back(make_tuple(hash, ftype, v.get())); + } + } } return *m_interfaceFunctionList; } @@ -219,7 +232,7 @@ void FunctionDefinition::checkTypeRequirements() string FunctionDefinition::getCanonicalSignature() const { - return getName() + FunctionType(*this).getCanonicalSignature(); + return FunctionType(*this).getCanonicalSignature(getName()); } Declaration::LValueType VariableDeclaration::getLValueType() const @@ -504,5 +517,18 @@ void Literal::checkTypeRequirements() BOOST_THROW_EXCEPTION(createTypeError("Invalid literal value.")); } + +ASTPointer FunctionDescription::getDocumentation() +{ + auto function = dynamic_cast(m_description.second); + if (function) + return function->getDocumentation(); +} + +string FunctionDescription::getSignature() +{ + return m_description.first->getCanonicalSignature(m_description.second->getName()); +} + } } -- cgit