Browse Source

extracted collectContracts

cl-refactor
arkpar 10 years ago
parent
commit
5a3a9abae6
  1. 53
      mix/CodeModel.cpp
  2. 1
      mix/CodeModel.h

53
mix/CodeModel.cpp

@ -249,7 +249,6 @@ void CodeModel::runCompilationJob(int _jobId)
{
if (_jobId != m_backgroundJobId)
return; //obsolete job
ContractMap result;
solidity::CompilerStack cs(true);
try
{
@ -260,22 +259,45 @@ void CodeModel::runCompilationJob(int _jobId)
cs.addSource(c.first.toStdString(), c.second.toStdString());
}
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 l(x_contractMap);
for (std::string n: cs.getContractNames())
ContractMap result;
for (std::string n: _cs.getContractNames())
{
if (c_predefinedContracts.count(n) != 0)
continue;
QString name = QString::fromStdString(n);
ContractDefinition const& contractDefinition = cs.getContractDefinition(n);
ContractDefinition const& contractDefinition = _cs.getContractDefinition(n);
if (!contractDefinition.isFullyImplemented())
continue;
QString sourceName = QString::fromStdString(*contractDefinition.getLocation().sourceName);
auto sourceIter = m_pendingContracts.find(sourceName);
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);
result[name] = contract;
CompiledContract* prevContract = nullptr;
@ -306,27 +328,6 @@ void CodeModel::runCompilationJob(int _jobId)
m_contractMap.swap(result);
emit codeChanged();
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

1
mix/CodeModel.h

@ -182,6 +182,7 @@ private:
void runCompilationJob(int _jobId);
void stop();
void releaseContracts();
void collectContracts(solidity::CompilerStack const& _cs);
std::atomic<bool> m_compiling;
mutable dev::Mutex x_contractMap;

Loading…
Cancel
Save