|
@ -249,7 +249,6 @@ void CodeModel::runCompilationJob(int _jobId) |
|
|
{ |
|
|
{ |
|
|
if (_jobId != m_backgroundJobId) |
|
|
if (_jobId != m_backgroundJobId) |
|
|
return; //obsolete job
|
|
|
return; //obsolete job
|
|
|
ContractMap result; |
|
|
|
|
|
solidity::CompilerStack cs(true); |
|
|
solidity::CompilerStack cs(true); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
@ -260,22 +259,45 @@ void CodeModel::runCompilationJob(int _jobId) |
|
|
cs.addSource(c.first.toStdString(), c.second.toStdString()); |
|
|
cs.addSource(c.first.toStdString(), c.second.toStdString()); |
|
|
} |
|
|
} |
|
|
cs.compile(false); |
|
|
cs.compile(false); |
|
|
|
|
|
collectContracts(cs); |
|
|
|
|
|
} |
|
|
|
|
|
catch (dev::Exception const& _exception) |
|
|
|
|
|
{ |
|
|
|
|
|
std::ostringstream error; |
|
|
|
|
|
solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs); |
|
|
|
|
|
QString message = QString::fromStdString(error.str()); |
|
|
|
|
|
QString sourceName; |
|
|
|
|
|
if (SourceLocation const* location = boost::get_error_info<solidity::errinfo_sourceLocation>(_exception)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (location->sourceName) |
|
|
|
|
|
sourceName = QString::fromStdString(*location->sourceName); |
|
|
|
|
|
if (!sourceName.isEmpty()) |
|
|
|
|
|
if (CompiledContract* contract = contractByDocumentId(sourceName)) |
|
|
|
|
|
message = message.replace(sourceName, contract->contract()->name()); //substitute the location to match our contract names
|
|
|
|
|
|
} |
|
|
|
|
|
compilationError(message, sourceName); |
|
|
|
|
|
} |
|
|
|
|
|
m_compiling = false; |
|
|
|
|
|
emit stateChanged(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void CodeModel::collectContracts(solidity::CompilerStack const& _cs) |
|
|
{ |
|
|
{ |
|
|
Guard pl(x_pendingContracts); |
|
|
Guard pl(x_pendingContracts); |
|
|
Guard l(x_contractMap); |
|
|
Guard l(x_contractMap); |
|
|
for (std::string n: cs.getContractNames()) |
|
|
ContractMap result; |
|
|
|
|
|
for (std::string n: _cs.getContractNames()) |
|
|
{ |
|
|
{ |
|
|
if (c_predefinedContracts.count(n) != 0) |
|
|
if (c_predefinedContracts.count(n) != 0) |
|
|
continue; |
|
|
continue; |
|
|
QString name = QString::fromStdString(n); |
|
|
QString name = QString::fromStdString(n); |
|
|
ContractDefinition const& contractDefinition = cs.getContractDefinition(n); |
|
|
ContractDefinition const& contractDefinition = _cs.getContractDefinition(n); |
|
|
if (!contractDefinition.isFullyImplemented()) |
|
|
if (!contractDefinition.isFullyImplemented()) |
|
|
continue; |
|
|
continue; |
|
|
QString sourceName = QString::fromStdString(*contractDefinition.getLocation().sourceName); |
|
|
QString sourceName = QString::fromStdString(*contractDefinition.getLocation().sourceName); |
|
|
auto sourceIter = m_pendingContracts.find(sourceName); |
|
|
auto sourceIter = m_pendingContracts.find(sourceName); |
|
|
QString source = sourceIter != m_pendingContracts.end() ? sourceIter->second : QString(); |
|
|
QString source = sourceIter != m_pendingContracts.end() ? sourceIter->second : QString(); |
|
|
CompiledContract* contract = new CompiledContract(cs, name, source); |
|
|
CompiledContract* contract = new CompiledContract(_cs, name, source); |
|
|
QQmlEngine::setObjectOwnership(contract, QQmlEngine::CppOwnership); |
|
|
QQmlEngine::setObjectOwnership(contract, QQmlEngine::CppOwnership); |
|
|
result[name] = contract; |
|
|
result[name] = contract; |
|
|
CompiledContract* prevContract = nullptr; |
|
|
CompiledContract* prevContract = nullptr; |
|
@ -307,27 +329,6 @@ void CodeModel::runCompilationJob(int _jobId) |
|
|
emit codeChanged(); |
|
|
emit codeChanged(); |
|
|
emit compilationComplete(); |
|
|
emit compilationComplete(); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
catch (dev::Exception const& _exception) |
|
|
|
|
|
{ |
|
|
|
|
|
std::ostringstream error; |
|
|
|
|
|
solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs); |
|
|
|
|
|
QString message = QString::fromStdString(error.str()); |
|
|
|
|
|
QString sourceName; |
|
|
|
|
|
if (SourceLocation const* location = boost::get_error_info<solidity::errinfo_sourceLocation>(_exception)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (location->sourceName) |
|
|
|
|
|
sourceName = QString::fromStdString(*location->sourceName); |
|
|
|
|
|
if (!sourceName.isEmpty()) |
|
|
|
|
|
if (CompiledContract* contract = contractByDocumentId(sourceName)) |
|
|
|
|
|
//substitute the location to match our contract names
|
|
|
|
|
|
message = message.replace(sourceName, contract->contract()->name()); |
|
|
|
|
|
} |
|
|
|
|
|
compilationError(message, sourceName); |
|
|
|
|
|
} |
|
|
|
|
|
m_compiling = false; |
|
|
|
|
|
emit stateChanged(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool CodeModel::hasContract() const |
|
|
bool CodeModel::hasContract() const |
|
|
{ |
|
|
{ |
|
|