@ -71,17 +71,19 @@ void ContractDefinition::checkTypeRequirements()
FixedHash < 4 > const & hash = std : : get < 0 > ( hashAndFunction ) ;
if ( hashes . count ( hash ) )
BOOST_THROW_EXCEPTION ( createTypeError (
" Function signature hash collision for " +
std : : get < 1 > ( hashAndFunction ) > - > getCanonicalSignature ( std : : get < 2 > ( hashAndFunction ) - > getName ( ) ) ) ) ;
std : : string ( " Function signature hash collision for " ) +
std : : get < 1 > ( hashAndFunction ) - > getCanonicalSignature ( std : : get < 2 > ( hashAndFunction ) - > getName ( ) ) ) ) ;
hashes . insert ( hash ) ;
}
}
map < FixedHash < 4 > , pair < FunctionType const * , FunctionDefinition const * > > ContractDefinition : : getInterfaceFunctions ( ) const
map < FixedHash < 4 > , FunctionDescription > ContractDefinition : : getInterfaceFunctions ( ) const
{
vector < tuple < FixedHash < 4 > , FunctionType const * , Declaration const * > > > exportedFunctionList = getInterfaceFunctionList ( ) ;
map < FixedHash < 4 > , pair < FunctionType * , Declaration const * > > exportedFunctions ( exportedFunctionList . begin ( ) ,
exportedFunctionList . end ( ) ) ;
auto exportedFunctionList = getInterfaceFunctionList ( ) ;
map < FixedHash < 4 > , FunctionDescription > exportedFunctions ;
for ( auto const & it : exportedFunctionList )
exportedFunctions [ std : : get < 0 > ( it ) ] = std : : move ( FunctionDescription ( std : : get < 1 > ( it ) , std : : get < 2 > ( it ) ) ) ;
solAssert ( exportedFunctionList . size ( ) = = exportedFunctions . size ( ) ,
" Hash collision at Function Definition Hash calculation " ) ;
@ -136,12 +138,12 @@ void ContractDefinition::checkIllegalOverrides() const
}
}
vector < tuple < FixedHash < 4 > , FunctionType const * , Declaration const * > > const & ContractDefinition : : getInterfaceFunctionList ( ) const
vector < tuple < FixedHash < 4 > , std : : shared_ptr < FunctionType const > , Declaration const * > > const & ContractDefinition : : getInterfaceFunctionList ( ) const
{
if ( ! m_interfaceFunctionList )
{
set < string > functionsSeen ;
m_interfaceFunctionList . reset ( new vector < tuple < FixedHash < 4 > , FunctionType const * , Declaration const * > > ( ) ) ;
m_interfaceFunctionList . reset ( new vector < tuple < FixedHash < 4 > , std : : shared_ptr < FunctionType const > , Declaration const * > > ( ) ) ;
for ( ContractDefinition const * contract : getLinearizedBaseContracts ( ) )
{
for ( ASTPointer < FunctionDefinition > const & f : contract - > getDefinedFunctions ( ) )
@ -149,7 +151,7 @@ vector<tuple<FixedHash<4>, FunctionType const*, Declaration const*>> const& Cont
{
functionsSeen . insert ( f - > getName ( ) ) ;
FixedHash < 4 > hash ( dev : : sha3 ( f - > getCanonicalSignature ( ) ) ) ;
m_interfaceFunctionList - > push_back ( make_tuple ( hash , FunctionType ( * f ) , f . get ( ) ) ) ;
m_interfaceFunctionList - > push_back ( make_tuple ( hash , make_shared < FunctionType > ( * f ) , f . get ( ) ) ) ;
}
for ( ASTPointer < VariableDeclaration > const & v : contract - > getStateVariables ( ) )
@ -157,8 +159,8 @@ vector<tuple<FixedHash<4>, FunctionType const*, Declaration const*>> const& Cont
{
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 ( ) ) ) ;
FixedHash < 4 > hash ( dev : : sha3 ( ftype . getCanonicalSignature ( v - > getName ( ) ) ) ) ;
m_interfaceFunctionList - > push_back ( make_tuple ( hash , make_shared < FunctionType > ( * v ) , v . get ( ) ) ) ;
}
}
}
@ -518,17 +520,104 @@ void Literal::checkTypeRequirements()
}
ASTPointer < ASTString > FunctionDescription : : getDocumentation ( )
bool ParamDescription : : operator ! = ( ParamDescription const & _other ) const
{
return m_description . first = = _other . getName ( ) & & m_description . second = = _other . getType ( ) ;
}
std : : ostream & ParamDescription : : operator < < ( std : : ostream & os ) const
{
return os < < m_description . first < < " : " < < m_description . second ;
}
std : : string ParamDescription : : getName ( ) const
{
return m_description . first ;
}
std : : string ParamDescription : : getType ( ) const
{
return m_description . second ;
}
ASTPointer < ASTString > FunctionDescription : : getDocumentation ( ) const
{
auto function = dynamic_cast < FunctionDefinition const * > ( m_description . second ) ;
if ( function )
return function - > getDocumentation ( ) ;
return ASTPointer < ASTString > ( ) ;
}
string FunctionDescription : : getSignature ( )
string FunctionDescription : : getSignature ( ) const
{
return m_description . first - > getCanonicalSignature ( m_description . second - > getName ( ) ) ;
}
string FunctionDescription : : getName ( ) const
{
return m_description . second - > getName ( ) ;
}
bool FunctionDescription : : isConstant ( ) const
{
auto function = dynamic_cast < FunctionDefinition const * > ( m_description . second ) ;
if ( function )
return function - > isDeclaredConst ( ) ;
return true ;
}
vector < ParamDescription > const FunctionDescription : : getParameters ( ) const
{
auto function = dynamic_cast < FunctionDefinition const * > ( m_description . second ) ;
if ( function )
{
vector < ParamDescription > paramsDescription ;
for ( auto const & param : function - > getParameters ( ) )
paramsDescription . push_back ( ParamDescription ( param - > getName ( ) , param - > getType ( ) - > toString ( ) ) ) ;
return paramsDescription ;
}
// else for now let's assume no parameters to accessors
// LTODO: fix this for mapping types
return { } ;
}
vector < ParamDescription > const FunctionDescription : : getReturnParameters ( ) const
{
auto function = dynamic_cast < FunctionDefinition const * > ( m_description . second ) ;
if ( function )
{
vector < ParamDescription > paramsDescription ;
for ( auto const & param : function - > getParameters ( ) )
paramsDescription . push_back ( ParamDescription ( param - > getName ( ) , param - > getType ( ) - > toString ( ) ) ) ;
return paramsDescription ;
}
auto vardecl = dynamic_cast < VariableDeclaration const * > ( m_description . second ) ;
return { ParamDescription ( vardecl - > getName ( ) , vardecl - > getType ( ) - > toString ( ) ) } ;
}
Declaration const * FunctionDescription : : getDeclaration ( ) const
{
return m_description . second ;
}
shared_ptr < FunctionType const > FunctionDescription : : getFunctionTypeShared ( ) const
{
return m_description . first ;
}
FunctionType const * FunctionDescription : : getFunctionType ( ) const
{
return m_description . first . get ( ) ;
}
}
}