@@ -1805,6 +1805,23 @@ FunctionType::FunctionType(EventDefinition const& _event):
1805
1805
swap (paramNames, m_parameterNames);
1806
1806
}
1807
1807
1808
+ FunctionType::FunctionType (FunctionTypeName const & _typeName):
1809
+ m_location(_typeName.visibility() == VariableDeclaration::Visibility::External ? Location::External : Location::Internal),
1810
+ m_isConstant(_typeName.isDeclaredConst()),
1811
+ m_isPayable(_typeName.isPayable())
1812
+ {
1813
+ for (auto const & t: _typeName.parameterTypes ())
1814
+ {
1815
+ solAssert (t->annotation ().type , " Type not set for parameter." );
1816
+ m_parameterTypes.push_back (t->annotation ().type );
1817
+ }
1818
+ for (auto const & t: _typeName.returnParameterTypes ())
1819
+ {
1820
+ solAssert (t->annotation ().type , " Type not set for return parameter." );
1821
+ m_returnParameterTypes.push_back (t->annotation ().type );
1822
+ }
1823
+ }
1824
+
1808
1825
FunctionTypePointer FunctionType::newExpressionType (ContractDefinition const & _contract)
1809
1826
{
1810
1827
FunctionDefinition const * constructor = _contract.constructor ();
@@ -1885,17 +1902,47 @@ string FunctionType::toString(bool _short) const
1885
1902
string name = " function (" ;
1886
1903
for (auto it = m_parameterTypes.begin (); it != m_parameterTypes.end (); ++it)
1887
1904
name += (*it)->toString (_short) + (it + 1 == m_parameterTypes.end () ? " " : " ," );
1888
- name += " ) returns (" ;
1905
+ name += " ) " ;
1906
+ if (m_isConstant)
1907
+ name += " constant " ;
1908
+ if (m_isPayable)
1909
+ name += " payable " ;
1910
+ if (m_location == Location::External)
1911
+ name += " external " ;
1912
+ name += " returns (" ;
1889
1913
for (auto it = m_returnParameterTypes.begin (); it != m_returnParameterTypes.end (); ++it)
1890
1914
name += (*it)->toString (_short) + (it + 1 == m_returnParameterTypes.end () ? " " : " ," );
1891
1915
return name + " )" ;
1892
1916
}
1893
1917
1918
+ unsigned FunctionType::calldataEncodedSize (bool _padded) const
1919
+ {
1920
+ unsigned size = storageBytes ();
1921
+ if (_padded)
1922
+ size = ((size + 31 ) / 32 ) * 32 ;
1923
+ return size;
1924
+ }
1925
+
1894
1926
u256 FunctionType::storageSize () const
1895
1927
{
1896
- BOOST_THROW_EXCEPTION (
1897
- InternalCompilerError ()
1898
- << errinfo_comment (" Storage size of non-storable function type requested." ));
1928
+ if (m_location == Location::External || m_location == Location::Internal)
1929
+ return 1 ;
1930
+ else
1931
+ BOOST_THROW_EXCEPTION (
1932
+ InternalCompilerError ()
1933
+ << errinfo_comment (" Storage size of non-storable function type requested." ));
1934
+ }
1935
+
1936
+ unsigned FunctionType::storageBytes () const
1937
+ {
1938
+ if (m_location == Location::External)
1939
+ return 20 + 4 ;
1940
+ else if (m_location == Location::Internal)
1941
+ return 8 ; // it should really not be possible to create larger programs
1942
+ else
1943
+ BOOST_THROW_EXCEPTION (
1944
+ InternalCompilerError ()
1945
+ << errinfo_comment (" Storage size of non-storable function type requested." ));
1899
1946
}
1900
1947
1901
1948
unsigned FunctionType::sizeOnStack () const
@@ -2018,6 +2065,16 @@ MemberList::MemberMap FunctionType::nativeMembers(ContractDefinition const*) con
2018
2065
}
2019
2066
}
2020
2067
2068
+ TypePointer FunctionType::interfaceType (bool _inLibrary) const
2069
+ {
2070
+ if (m_location != Location::External && m_location != Location::Internal)
2071
+ return TypePointer ();
2072
+ if (_inLibrary)
2073
+ return shared_from_this ();
2074
+ else
2075
+ return make_shared<FixedBytesType>(storageBytes ());
2076
+ }
2077
+
2021
2078
bool FunctionType::canTakeArguments (TypePointers const & _argumentTypes, TypePointer const & _selfType) const
2022
2079
{
2023
2080
solAssert (!bound () || _selfType, " " );
0 commit comments