tests for external types

This commit is contained in:
Liana Husikyan 2015-03-25 13:58:15 +01:00
parent 9986b072ad
commit 8f747aab0f
5 changed files with 14 additions and 16 deletions

14
AST.cpp
View File

@ -192,7 +192,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface()) if (functionsSeen.count(f->getName()) == 0 && f->isPartOfExternalInterface())
{ {
functionsSeen.insert(f->getName()); functionsSeen.insert(f->getName());
FixedHash<4> hash(dev::sha3(f->externalSignature())); FixedHash<4> hash(dev::sha3(f->externalSignature(true)));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*f, false))); 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); FunctionType ftype(*v);
solAssert(v->getType().get(), ""); solAssert(v->getType().get(), "");
functionsSeen.insert(v->getName()); functionsSeen.insert(v->getName());
FixedHash<4> hash(dev::sha3(ftype.externalSignature(v->getName()))); FixedHash<4> hash(dev::sha3(ftype.externalSignature(true, v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v))); m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
} }
} }
@ -309,7 +309,7 @@ void FunctionDefinition::checkTypeRequirements()
{ {
if (!var->getType()->canLiveOutsideStorage()) if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage.")); BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
if (!var->getType()->externalType() && getVisibility() >= Visibility::Public) if (!(var->getType()->externalType()) && getVisibility() >= Visibility::Public)
BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for function with external visibility")); BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for function with external visibility"));
} }
for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers) for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers)
@ -320,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->checkTypeRequirements(); m_body->checkTypeRequirements();
} }
string FunctionDefinition::externalSignature() const string FunctionDefinition::externalSignature(bool isExternalCall) const
{ {
return FunctionType(*this).externalSignature(getName()); return FunctionType(*this).externalSignature(isExternalCall, getName());
} }
bool VariableDeclaration::isLValue() const bool VariableDeclaration::isLValue() const
@ -663,10 +663,6 @@ void MemberAccess::checkTypeRequirements()
if (!m_type) if (!m_type)
BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found or not " BOOST_THROW_EXCEPTION(createTypeError("Member \"" + *m_memberName + "\" not found or not "
"visible in " + type.toString())); "visible in " + type.toString()));
// if (auto f = dynamic_cast<FunctionType const*>(m_expression->getType().get()))
// if (f->getLocation() == FunctionType::Location::External && !m_type->externalType())
// BOOST_THROW_EXCEPTION(createTypeError(*m_memberName + " member has an internal type."));
// This should probably move somewhere else. // This should probably move somewhere else.
if (type.getCategory() == Type::Category::Struct) if (type.getCategory() == Type::Category::Struct)
m_isLValue = true; m_isLValue = true;

4
AST.h
View File

@ -422,9 +422,9 @@ public:
void checkTypeRequirements(); void checkTypeRequirements();
/// @returns the external signature of the function /// @returns the external signature of the function
/// That consists of the name of the function followed by the external types of the /// That consists of the name of the function followed by the types(external types if isExternalCall) of the
/// arguments separated by commas all enclosed in parentheses without any spaces. /// arguments separated by commas all enclosed in parentheses without any spaces.
std::string externalSignature() const; std::string externalSignature(bool isExternalCall = false) const;
private: private:
bool m_isConstructor; bool m_isConstructor;

View File

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

View File

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

View File

@ -553,7 +553,8 @@ public:
/// @returns the external signature of this function type given the function name /// @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 /// If @a _name is not provided (empty string) then the @c m_declaration member of the
/// function type is used /// function type is used
std::string externalSignature(std::string const& _name = "") const; /// @a isExternalCall shows if it is external function call
std::string externalSignature(bool isExternalCall = false, std::string const& _name = "") const;
Declaration const& getDeclaration() const Declaration const& getDeclaration() const
{ {
solAssert(m_declaration, "Requested declaration from a FunctionType that has none"); solAssert(m_declaration, "Requested declaration from a FunctionType that has none");