renamed getCanonicalSignature

added externalTypes instead of types for interface functions
added simple test

todo
testing
This commit is contained in:
Liana Husikyan 2015-03-23 18:08:45 +01:00
parent e3ea90e997
commit 701b34fbeb
6 changed files with 17 additions and 14 deletions

11
AST.cpp
View File

@ -88,7 +88,7 @@ void ContractDefinition::checkTypeRequirements()
if (hashes.count(hash))
BOOST_THROW_EXCEPTION(createTypeError(
std::string("Function signature hash collision for ") +
it.second->getCanonicalSignature()));
it.second->externalTypes()));
hashes.insert(hash);
}
}
@ -192,7 +192,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface())
{
functionsSeen.insert(f->getName());
FixedHash<4> hash(dev::sha3(f->getCanonicalSignature()));
FixedHash<4> hash(dev::sha3(f->externalTypes()));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false)));
}
@ -200,8 +200,9 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(v->getName()) == 0 && v->isPartOfExternalInterface())
{
FunctionType ftype(*v);
solAssert(v->getType().get(), "");
functionsSeen.insert(v->getName());
FixedHash<4> hash(dev::sha3(ftype.getCanonicalSignature(v->getName())));
FixedHash<4> hash(dev::sha3(ftype.externalTypes(v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
}
}
@ -319,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements();
}
string FunctionDefinition::getCanonicalSignature() const
string FunctionDefinition::externalTypes() const
{
return FunctionType(*this).getCanonicalSignature(getName());
return FunctionType(*this).externalTypes(getName());
}
bool VariableDeclaration::isLValue() const

2
AST.h
View File

@ -424,7 +424,7 @@ public:
/// @returns the canonical signature of the function
/// That consists of the name of the function followed by the types of the
/// arguments separated by commas all enclosed in parentheses without any spaces.
std::string getCanonicalSignature() const;
std::string externalTypes() const;
private:
bool m_isConstructor;

View File

@ -544,7 +544,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
}
if (!event.isAnonymous())
{
m_context << u256(h256::Arith(dev::sha3(function.getCanonicalSignature(event.getName()))));
m_context << u256(h256::Arith(dev::sha3(function.externalTypes(event.getName()))));
++numIndexed;
}
solAssert(numIndexed <= 4, "Too many indexed arguments.");

View File

@ -129,7 +129,7 @@ std::unique_ptr<std::string> InterfaceHandler::getUserDocumentation(ContractDefi
if (!m_notice.empty())
{// since @notice is the only user tag if missing function should not appear
user["notice"] = Json::Value(m_notice);
methods[it.second->getCanonicalSignature()] = user;
methods[it.second->externalTypes()] = user;
}
}
}
@ -185,7 +185,7 @@ std::unique_ptr<std::string> InterfaceHandler::getDevDocumentation(ContractDefin
method["return"] = m_return;
if (!method.empty()) // add the function, only if we have any documentation to add
methods[it.second->getCanonicalSignature()] = method;
methods[it.second->externalTypes()] = method;
}
}
doc["methods"] = methods;

View File

@ -1127,7 +1127,7 @@ MemberList const& FunctionType::getMembers() const
}
}
string FunctionType::getCanonicalSignature(std::string const& _name) const
string FunctionType::externalTypes(std::string const& _name) const
{
std::string funcName = _name;
if (_name == "")
@ -1138,8 +1138,10 @@ string FunctionType::getCanonicalSignature(std::string const& _name) const
string ret = funcName + "(";
for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it)
ret += (*it)->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ",");
{
solAssert(!!(*it)->externalType(), "Parameter should have external type");
ret += (*it)->externalType()->toString() + (it + 1 == m_parameterTypes.cend() ? "" : ",");
}
return ret + ")";
}

View File

@ -550,10 +550,10 @@ public:
virtual MemberList const& getMembers() const override;
Location const& getLocation() const { return m_location; }
/// @returns the canonical signature of this function type given the function name
/// @returns the external type of this function type given the function name
/// 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;
std::string externalTypes(std::string const& _name = "") const;
Declaration const& getDeclaration() const
{
solAssert(m_declaration, "Requested declaration from a FunctionType that has none");