added externalTypes function to functionType

removed flag for externalSigniture
This commit is contained in:
Liana Husikyan 2015-03-27 13:28:32 +01:00
parent b1ca27ea93
commit a3d829d074
5 changed files with 30 additions and 14 deletions

View File

@ -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->externalSignature(true)));
FixedHash<4> hash(dev::sha3(f->externalSignature()));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false)));
}
@ -202,7 +202,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
FunctionType ftype(*v);
solAssert(v->getType().get(), "");
functionsSeen.insert(v->getName());
FixedHash<4> hash(dev::sha3(ftype.externalSignature(true, v->getName())));
FixedHash<4> hash(dev::sha3(ftype.externalSignature(v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
}
}
@ -320,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements();
}
string FunctionDefinition::externalSignature(bool isExternalCall) const
string FunctionDefinition::externalSignature() const
{
return FunctionType(*this).externalSignature(isExternalCall, getName());
return FunctionType(*this).externalSignature(getName());
}
bool VariableDeclaration::isLValue() const

4
AST.h
View File

@ -422,9 +422,9 @@ public:
void checkTypeRequirements();
/// @returns the external signature of the function
/// That consists of the name of the function followed by the types (external types if isExternalCall) of the
/// 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 externalSignature(bool isExternalCall = false) const;
std::string externalSignature() 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.externalSignature(false, event.getName()))));
m_context << u256(h256::Arith(dev::sha3(function.externalSignature(event.getName()))));
++numIndexed;
}
solAssert(numIndexed <= 4, "Too many indexed arguments.");

View File

@ -1098,6 +1098,19 @@ unsigned FunctionType::getSizeOnStack() const
return size;
}
TypePointer FunctionType::externalType() const
{
TypePointers paramTypes;
TypePointers retParamTypes;
for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it)
paramTypes.push_back((*it)->externalType());
for (auto it = m_returnParameterTypes.cbegin(); it != m_returnParameterTypes.cend(); ++it)
retParamTypes.push_back((*it)->externalType());
return make_shared<FunctionType>(paramTypes, retParamTypes, m_location, m_arbitraryParameters);
}
MemberList const& FunctionType::getMembers() const
{
switch (m_location)
@ -1127,7 +1140,7 @@ MemberList const& FunctionType::getMembers() const
}
}
string FunctionType::externalSignature(bool isExternalCall, std::string const& _name) const
string FunctionType::externalSignature(std::string const& _name) const
{
std::string funcName = _name;
if (_name == "")
@ -1137,12 +1150,13 @@ string FunctionType::externalSignature(bool isExternalCall, std::string const& _
}
string ret = funcName + "(";
for (auto it = m_parameterTypes.cbegin(); it != m_parameterTypes.cend(); ++it)
TypePointers externalParameterTypes = dynamic_cast<FunctionType const&>(*externalType()).getParameterTypes();
for (auto it = externalParameterTypes.cbegin(); it != externalParameterTypes.cend(); ++it)
{
if (isExternalCall)
solAssert(!!(*it)->externalType(), "Parameter should have external type");
ret += (isExternalCall ? (*it)->externalType()->toString() : (*it)->toString()) + (it + 1 == m_parameterTypes.cend() ? "" : ",");
solAssert(!!(*it), "Parameter should have external type");
ret += (*it)->toString() + (it + 1 == externalParameterTypes.cend() ? "" : ",");
}
return ret + ")";
}

View File

@ -511,6 +511,9 @@ public:
Bare };
virtual Category getCategory() const override { return Category::Function; }
virtual TypePointer externalType() const override;
explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true);
explicit FunctionType(VariableDeclaration const& _varDecl);
explicit FunctionType(EventDefinition const& _event);
@ -553,8 +556,7 @@ public:
/// @returns the external signature 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
/// @a isExternalCall shows if it is external function call
std::string externalSignature(bool isExternalCall = false, std::string const& _name = "") const;
std::string externalSignature(std::string const& _name = "") const;
Declaration const& getDeclaration() const
{
solAssert(m_declaration, "Requested declaration from a FunctionType that has none");