|
@ -33,6 +33,8 @@ |
|
|
#include <libsolidity/CompilerStack.h> |
|
|
#include <libsolidity/CompilerStack.h> |
|
|
#include <libsolidity/SourceReferenceFormatter.h> |
|
|
#include <libsolidity/SourceReferenceFormatter.h> |
|
|
#include <libsolidity/InterfaceHandler.h> |
|
|
#include <libsolidity/InterfaceHandler.h> |
|
|
|
|
|
#include <libsolidity/StructuralGasEstimator.h> |
|
|
|
|
|
#include <libsolidity/SourceReferenceFormatter.h> |
|
|
#include <libevmcore/Instruction.h> |
|
|
#include <libevmcore/Instruction.h> |
|
|
#include <libethcore/CommonJS.h> |
|
|
#include <libethcore/CommonJS.h> |
|
|
#include "QContractDefinition.h" |
|
|
#include "QContractDefinition.h" |
|
@ -41,6 +43,7 @@ |
|
|
#include "CodeHighlighter.h" |
|
|
#include "CodeHighlighter.h" |
|
|
#include "FileIo.h" |
|
|
#include "FileIo.h" |
|
|
#include "CodeModel.h" |
|
|
#include "CodeModel.h" |
|
|
|
|
|
#include "QBigInt.h" |
|
|
|
|
|
|
|
|
using namespace dev::mix; |
|
|
using namespace dev::mix; |
|
|
|
|
|
|
|
@ -50,6 +53,7 @@ const std::set<std::string> c_predefinedContracts = |
|
|
|
|
|
|
|
|
namespace |
|
|
namespace |
|
|
{ |
|
|
{ |
|
|
|
|
|
using namespace dev::eth; |
|
|
using namespace dev::solidity; |
|
|
using namespace dev::solidity; |
|
|
|
|
|
|
|
|
class CollectLocalsVisitor: public ASTConstVisitor |
|
|
class CollectLocalsVisitor: public ASTConstVisitor |
|
@ -185,6 +189,7 @@ CodeModel::CodeModel(): |
|
|
qRegisterMetaType<QContractDefinition*>("QContractDefinition*"); |
|
|
qRegisterMetaType<QContractDefinition*>("QContractDefinition*"); |
|
|
qRegisterMetaType<QFunctionDefinition*>("QFunctionDefinition*"); |
|
|
qRegisterMetaType<QFunctionDefinition*>("QFunctionDefinition*"); |
|
|
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*"); |
|
|
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*"); |
|
|
|
|
|
//qRegisterMetaType<GasMap>("GasMap");
|
|
|
qmlRegisterType<QFunctionDefinition>("org.ethereum.qml", 1, 0, "QFunctionDefinition"); |
|
|
qmlRegisterType<QFunctionDefinition>("org.ethereum.qml", 1, 0, "QFunctionDefinition"); |
|
|
qmlRegisterType<QVariableDeclaration>("org.ethereum.qml", 1, 0, "QVariableDeclaration"); |
|
|
qmlRegisterType<QVariableDeclaration>("org.ethereum.qml", 1, 0, "QVariableDeclaration"); |
|
|
} |
|
|
} |
|
@ -292,6 +297,7 @@ void CodeModel::runCompilationJob(int _jobId) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
cs.compile(false); |
|
|
cs.compile(false); |
|
|
|
|
|
gasEstimation(cs); |
|
|
collectContracts(cs, sourceNames); |
|
|
collectContracts(cs, sourceNames); |
|
|
} |
|
|
} |
|
|
catch (dev::Exception const& _exception) |
|
|
catch (dev::Exception const& _exception) |
|
@ -314,6 +320,49 @@ void CodeModel::runCompilationJob(int _jobId) |
|
|
emit stateChanged(); |
|
|
emit stateChanged(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CodeModel::gasEstimation(solidity::CompilerStack const& _cs) |
|
|
|
|
|
{ |
|
|
|
|
|
m_gasCostsMaps.clear(); |
|
|
|
|
|
for (std::string n: _cs.getContractNames()) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
ContractDefinition const& contractDefinition = _cs.getContractDefinition(n); |
|
|
|
|
|
QString sourceName = QString::fromStdString(*contractDefinition.getLocation().sourceName); |
|
|
|
|
|
|
|
|
|
|
|
if (!m_gasCostsMaps.contains(sourceName)) |
|
|
|
|
|
m_gasCostsMaps.insert(sourceName, QVariantList()); |
|
|
|
|
|
|
|
|
|
|
|
if (!contractDefinition.isFullyImplemented()) |
|
|
|
|
|
continue; |
|
|
|
|
|
dev::solidity::SourceUnit const& sourceUnit = _cs.getAST(*contractDefinition.getLocation().sourceName); |
|
|
|
|
|
AssemblyItems const* items = _cs.getRuntimeAssemblyItems(n); |
|
|
|
|
|
|
|
|
|
|
|
StructuralGasEstimator estimator; |
|
|
|
|
|
std::map<ASTNode const*, GasMeter::GasConsumption> gasCosts = estimator.breakToStatementLevel(estimator.performEstimation(*items, std::vector<ASTNode const*>({&sourceUnit})), {&sourceUnit}); |
|
|
|
|
|
|
|
|
|
|
|
for (auto gasIte = gasCosts.begin(); gasIte != gasCosts.end(); ++gasIte) |
|
|
|
|
|
{ |
|
|
|
|
|
SourceLocation location = gasIte->first->getLocation(); |
|
|
|
|
|
GasMeter::GasConsumption cost = gasIte->second; |
|
|
|
|
|
GasMap* gas = new GasMap(location.start, location.end, (new QBigInt(cost.value))->value()); |
|
|
|
|
|
m_gasCostsMaps.find(sourceName).value().push_back(QVariant::fromValue(gas)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QVariantList CodeModel::gasCostByDocumentId(QString const& _documentId) const |
|
|
|
|
|
{ |
|
|
|
|
|
if (m_gasCostsMaps.contains(_documentId)) |
|
|
|
|
|
{ |
|
|
|
|
|
auto sourceMapIter = m_gasCostsMaps.find(_documentId); |
|
|
|
|
|
int gg = sourceMapIter.value().size(); |
|
|
|
|
|
Q_UNUSED(gg); |
|
|
|
|
|
return sourceMapIter.value(); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
return QVariantList(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void CodeModel::collectContracts(dev::solidity::CompilerStack const& _cs, std::vector<std::string> const& _sourceNames) |
|
|
void CodeModel::collectContracts(dev::solidity::CompilerStack const& _cs, std::vector<std::string> const& _sourceNames) |
|
|
{ |
|
|
{ |
|
|
Guard pl(x_pendingContracts); |
|
|
Guard pl(x_pendingContracts); |
|
|