mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Catch more exceptions in jsonCompiler.
This commit is contained in:
parent
b5d941d3d9
commit
52ee47190d
@ -203,51 +203,65 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
|
|||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
output["contracts"] = Json::Value(Json::objectValue);
|
try
|
||||||
for (string const& contractName: compiler.contractNames())
|
|
||||||
{
|
{
|
||||||
Json::Value contractData(Json::objectValue);
|
output["contracts"] = Json::Value(Json::objectValue);
|
||||||
contractData["interface"] = compiler.interface(contractName);
|
for (string const& contractName: compiler.contractNames())
|
||||||
contractData["bytecode"] = compiler.object(contractName).toHex();
|
{
|
||||||
contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
|
Json::Value contractData(Json::objectValue);
|
||||||
contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
|
contractData["interface"] = compiler.interface(contractName);
|
||||||
contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName));
|
contractData["bytecode"] = compiler.object(contractName).toHex();
|
||||||
contractData["gasEstimates"] = estimateGas(compiler, contractName);
|
contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
|
||||||
auto sourceMap = compiler.sourceMapping(contractName);
|
contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
|
||||||
contractData["srcmap"] = sourceMap ? *sourceMap : "";
|
contractData["functionHashes"] = functionHashes(compiler.contractDefinition(contractName));
|
||||||
auto runtimeSourceMap = compiler.runtimeSourceMapping(contractName);
|
contractData["gasEstimates"] = estimateGas(compiler, contractName);
|
||||||
contractData["srcmapRuntime"] = runtimeSourceMap ? *runtimeSourceMap : "";
|
auto sourceMap = compiler.sourceMapping(contractName);
|
||||||
ostringstream unused;
|
contractData["srcmap"] = sourceMap ? *sourceMap : "";
|
||||||
contractData["assembly"] = compiler.streamAssembly(unused, contractName, _sources, true);
|
auto runtimeSourceMap = compiler.runtimeSourceMapping(contractName);
|
||||||
output["contracts"][contractName] = contractData;
|
contractData["srcmapRuntime"] = runtimeSourceMap ? *runtimeSourceMap : "";
|
||||||
}
|
ostringstream unused;
|
||||||
|
contractData["assembly"] = compiler.streamAssembly(unused, contractName, _sources, true);
|
||||||
|
output["contracts"][contractName] = contractData;
|
||||||
|
}
|
||||||
|
|
||||||
// Do not taint the internal error list
|
// Do not taint the internal error list
|
||||||
ErrorList formalErrors;
|
ErrorList formalErrors;
|
||||||
if (compiler.prepareFormalAnalysis(&formalErrors))
|
if (compiler.prepareFormalAnalysis(&formalErrors))
|
||||||
output["formal"]["why3"] = compiler.formalTranslation();
|
output["formal"]["why3"] = compiler.formalTranslation();
|
||||||
if (!formalErrors.empty())
|
if (!formalErrors.empty())
|
||||||
|
{
|
||||||
|
Json::Value errors(Json::arrayValue);
|
||||||
|
for (auto const& error: formalErrors)
|
||||||
|
errors.append(formatError(
|
||||||
|
*error,
|
||||||
|
(error->type() == Error::Type::Warning) ? "Warning" : "Error",
|
||||||
|
scannerFromSourceName
|
||||||
|
));
|
||||||
|
output["formal"]["errors"] = errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indices into this array are used to abbreviate source names in source locations.
|
||||||
|
output["sourceList"] = Json::Value(Json::arrayValue);
|
||||||
|
for (auto const& source: compiler.sourceNames())
|
||||||
|
output["sourceList"].append(source);
|
||||||
|
output["sources"] = Json::Value(Json::objectValue);
|
||||||
|
for (auto const& source: compiler.sourceNames())
|
||||||
|
output["sources"][source]["AST"] = ASTJsonConverter(compiler.ast(source), compiler.sourceIndices()).json();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
{
|
{
|
||||||
Json::Value errors(Json::arrayValue);
|
output["errors"].append("Unknown exception while generating compiler output.");
|
||||||
for (auto const& error: formalErrors)
|
|
||||||
errors.append(formatError(
|
|
||||||
*error,
|
|
||||||
(error->type() == Error::Type::Warning) ? "Warning" : "Error",
|
|
||||||
scannerFromSourceName
|
|
||||||
));
|
|
||||||
output["formal"]["errors"] = errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indices into this array are used to abbreviate source names in source locations.
|
|
||||||
output["sourceList"] = Json::Value(Json::arrayValue);
|
|
||||||
for (auto const& source: compiler.sourceNames())
|
|
||||||
output["sourceList"].append(source);
|
|
||||||
output["sources"] = Json::Value(Json::objectValue);
|
|
||||||
for (auto const& source: compiler.sourceNames())
|
|
||||||
output["sources"][source]["AST"] = ASTJsonConverter(compiler.ast(source), compiler.sourceIndices()).json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Json::FastWriter().write(output);
|
try
|
||||||
|
{
|
||||||
|
return Json::FastWriter().write(output);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return "{\"errors\":[\"Unknown error while generating JSON.\"]}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string compileMulti(string const& _input, bool _optimize, CStyleReadFileCallback _readCallback = nullptr)
|
string compileMulti(string const& _input, bool _optimize, CStyleReadFileCallback _readCallback = nullptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user