Browse Source

added externalTypes function to functionType

removed flag for externalSigniture
cl-refactor
Liana Husikyan 10 years ago
parent
commit
dd15c53ae4
  1. 8
      libsolidity/AST.cpp
  2. 4
      libsolidity/AST.h
  3. 2
      libsolidity/ExpressionCompiler.cpp
  4. 24
      libsolidity/Types.cpp
  5. 6
      libsolidity/Types.h
  6. 2
      test/SolidityNameAndTypeResolution.cpp

8
libsolidity/AST.cpp

@ -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(true))); FixedHash<4> hash(dev::sha3(f->externalSignature()));
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(true, v->getName()))); FixedHash<4> hash(dev::sha3(ftype.externalSignature(v->getName())));
m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v))); m_interfaceFunctionList->push_back(make_pair(hash, make_shared<FunctionType>(*v)));
} }
} }
@ -320,9 +320,9 @@ void FunctionDefinition::checkTypeRequirements()
m_body->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 bool VariableDeclaration::isLValue() const

4
libsolidity/AST.h

@ -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 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. /// arguments separated by commas all enclosed in parentheses without any spaces.
std::string externalSignature(bool isExternalCall = false) const; std::string externalSignature() const;
private: private:
bool m_isConstructor; bool m_isConstructor;

2
libsolidity/ExpressionCompiler.cpp

@ -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(false, event.getName())))); m_context << u256(h256::Arith(dev::sha3(function.externalSignature(event.getName()))));
++numIndexed; ++numIndexed;
} }
solAssert(numIndexed <= 4, "Too many indexed arguments."); solAssert(numIndexed <= 4, "Too many indexed arguments.");

24
libsolidity/Types.cpp

@ -1098,6 +1098,19 @@ unsigned FunctionType::getSizeOnStack() const
return size; 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 MemberList const& FunctionType::getMembers() const
{ {
switch (m_location) 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; std::string funcName = _name;
if (_name == "") if (_name == "")
@ -1137,12 +1150,13 @@ string FunctionType::externalSignature(bool isExternalCall, std::string const& _
} }
string ret = funcName + "("; 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), "Parameter should have external type");
solAssert(!!(*it)->externalType(), "Parameter should have external type"); ret += (*it)->toString() + (it + 1 == externalParameterTypes.cend() ? "" : ",");
ret += (isExternalCall ? (*it)->externalType()->toString() : (*it)->toString()) + (it + 1 == m_parameterTypes.cend() ? "" : ",");
} }
return ret + ")"; return ret + ")";
} }

6
libsolidity/Types.h

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

2
test/SolidityNameAndTypeResolution.cpp

@ -414,7 +414,7 @@ BOOST_AUTO_TEST_CASE(function_external_types)
auto functions = contract->getDefinedFunctions(); auto functions = contract->getDefinedFunctions();
if (functions.empty()) if (functions.empty())
continue; continue;
BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8,bool[2],uint256[],address)", functions[0]->externalSignature(true)); BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8,bool[2],uint256[],address)", functions[0]->externalSignature());
} }
} }

Loading…
Cancel
Save