@ -392,6 +392,7 @@ void CodeModel::gasEstimation(solidity::CompilerStack const& _cs)
}
eth : : AssemblyItems const & runtimeAssembly = * _cs . getRuntimeAssemblyItems ( n ) ;
QString contractName = QString : : fromStdString ( contractDefinition . getName ( ) ) ;
// Functional gas costs (per function, but also for accessors)
for ( auto it : contractDefinition . getInterfaceFunctions ( ) )
{
@ -399,13 +400,15 @@ void CodeModel::gasEstimation(solidity::CompilerStack const& _cs)
continue ;
SourceLocation loc = it . second - > getDeclaration ( ) . getLocation ( ) ;
GasMeter : : GasConsumption cost = GasEstimator : : functionalEstimation ( runtimeAssembly , it . second - > externalSignature ( ) ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ,
contractName , QString : : fromStdString ( it . second - > getDeclaration ( ) . getName ( ) ) ) ;
}
if ( auto const * fallback = contractDefinition . getFallbackFunction ( ) )
{
SourceLocation loc = fallback - > getLocation ( ) ;
GasMeter : : GasConsumption cost = GasEstimator : : functionalEstimation ( runtimeAssembly , " INVALID " ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ,
contractName , " fallback " ) ;
}
for ( auto const & it : contractDefinition . getDefinedFunctions ( ) )
{
@ -416,13 +419,15 @@ void CodeModel::gasEstimation(solidity::CompilerStack const& _cs)
GasEstimator : : GasConsumption cost = GasEstimator : : GasConsumption : : infinite ( ) ;
if ( entry > 0 )
cost = GasEstimator : : functionalEstimation ( runtimeAssembly , entry , * it ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Function ,
contractName , QString : : fromStdString ( it - > getName ( ) ) ) ;
}
if ( auto const * constructor = contractDefinition . getConstructor ( ) )
{
SourceLocation loc = constructor - > getLocation ( ) ;
GasMeter : : GasConsumption cost = GasEstimator : : functionalEstimation ( * _cs . getAssemblyItems ( n ) ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Constructor ) ;
m_gasCostsMaps - > push ( sourceName , loc . start , loc . end , gasToString ( cost ) , cost . isInfinite , GasMap : : type : : Constructor ,
contractName , contractName ) ;
}
}
}
@ -435,6 +440,14 @@ QVariantList CodeModel::gasCostByDocumentId(QString const& _documentId) const
return QVariantList ( ) ;
}
QVariantList CodeModel : : gasCostBy ( QString const & _contractName , QString const & _functionName ) const
{
if ( m_gasCostsMaps )
return m_gasCostsMaps - > gasCostsBy ( _contractName , _functionName ) ;
else
return QVariantList ( ) ;
}
void CodeModel : : collectContracts ( dev : : solidity : : CompilerStack const & _cs , std : : vector < std : : string > const & _sourceNames )
{
Guard pl ( x_pendingContracts ) ;
@ -643,9 +656,9 @@ void CodeModel::setOptimizeCode(bool _value)
emit scheduleCompilationJob ( + + m_backgroundJobId ) ;
}
void GasMapWrapper : : push ( QString _source , int _start , int _end , QString _value , bool _isInfinite , GasMap : : type _type )
void GasMapWrapper : : push ( QString _source , int _start , int _end , QString _value , bool _isInfinite , GasMap : : type _type , QString _contractName , QString _functionName )
{
GasMap * gas = new GasMap ( _start , _end , _value , _isInfinite , _type , this ) ;
GasMap * gas = new GasMap ( _start , _end , _value , _isInfinite , _type , _contractName , _functionName , this ) ;
m_gasMaps . find ( _source ) . value ( ) . push_back ( QVariant : : fromValue ( gas ) ) ;
}
@ -668,3 +681,17 @@ QVariantList GasMapWrapper::gasCostsByDocId(QString _source)
return QVariantList ( ) ;
}
QVariantList GasMapWrapper : : gasCostsBy ( QString _contractName , QString _functionName )
{
QVariantList gasMap ;
for ( auto const & map : m_gasMaps )
{
for ( auto const & gas : map )
{
if ( gas . value < GasMap * > ( ) - > contractName ( ) = = _contractName & & ( _functionName . isEmpty ( ) | | gas . value < GasMap * > ( ) - > functionName ( ) = = _functionName ) )
gasMap . push_back ( gas ) ;
}
}
return gasMap ;
}