Add shortcuts for formatting error information

This commit is contained in:
mingchuan 2019-04-05 23:49:39 +08:00
parent ef3a18999c
commit f1374066af
No known key found for this signature in database
GPG Key ID: 607CD25FA2D03651
13 changed files with 34 additions and 55 deletions

View File

@ -70,9 +70,17 @@ void SourceReferenceFormatter::printSourceName(SourceReference const& _ref)
m_stream << _ref.sourceName << ":" << (_ref.position.line + 1) << ":" << (_ref.position.column + 1) << ": ";
}
void SourceReferenceFormatter::printExceptionInformation(dev::Exception const& _error, std::string const& _category)
void SourceReferenceFormatter::printExceptionInformation(dev::Exception const& _exception, std::string const& _category)
{
printExceptionInformation(SourceReferenceExtractor::extract(_error, _category));
printExceptionInformation(SourceReferenceExtractor::extract(_exception, _category));
}
void SourceReferenceFormatter::printErrorInformation(Error const& _error)
{
printExceptionInformation(
_error,
(_error.type() == Error::Type::Warning) ? "Warning" : "Error"
);
}
void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtractor::Message const& _msg)

View File

@ -25,6 +25,7 @@
#include <ostream>
#include <sstream>
#include <functional>
#include <liblangutil/Exceptions.h>
#include <liblangutil/SourceReferenceExtractor.h>
namespace dev
@ -51,7 +52,16 @@ public:
virtual void printExceptionInformation(SourceReferenceExtractor::Message const& _msg);
virtual void printSourceLocation(SourceLocation const* _location);
virtual void printExceptionInformation(dev::Exception const& _error, std::string const& _category);
virtual void printExceptionInformation(dev::Exception const& _exception, std::string const& _category);
virtual void printErrorInformation(Error const& _error);
static std::string formatErrorInformation(Error const& _error)
{
return formatExceptionInformation(
_error,
(_error.type() == Error::Type::Warning) ? "Warning" : "Error"
);
}
static std::string formatExceptionInformation(
dev::Exception const& _exception,

View File

@ -396,10 +396,7 @@ void CompilerContext::appendInlineAssembly(
_assembly + "\n"
"------------------ Errors: ----------------\n";
for (auto const& error: errorReporter.errors())
message += SourceReferenceFormatter::formatExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
message += SourceReferenceFormatter::formatErrorInformation(*error);
message += "-------------------------------------------\n";
solAssert(false, message);

View File

@ -50,10 +50,7 @@ pair<string, string> IRGenerator::run(ContractDefinition const& _contract)
{
string errorMessage;
for (auto const& error: asmStack.errors())
errorMessage += langutil::SourceReferenceFormatter::formatExceptionInformation(
*error,
(error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error"
);
errorMessage += langutil::SourceReferenceFormatter::formatErrorInformation(*error);
solAssert(false, "Invalid IR generated:\n" + errorMessage + "\n" + ir);
}
asmStack.optimize();

View File

@ -937,10 +937,7 @@ bool CommandLineInterface::processInput()
for (auto const& error: m_compiler->errors())
{
g_hasOutput = true;
formatter->printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter->printErrorInformation(*error);
}
if (!successful)
@ -1294,10 +1291,7 @@ bool CommandLineInterface::assemble(
for (auto const& error: stack.errors())
{
g_hasOutput = true;
formatter->printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter->printErrorInformation(*error);
}
if (!Error::containsOnlyWarnings(stack.errors()))
successful = false;

View File

@ -125,10 +125,7 @@ string AnalysisFramework::formatErrors() const
string AnalysisFramework::formatError(Error const& _error) const
{
return SourceReferenceFormatter::formatExceptionInformation(
_error,
(_error.type() == Error::Type::Warning) ? "Warning" : "Error"
);
return SourceReferenceFormatter::formatErrorInformation(_error);
}
ContractDefinition const* AnalysisFramework::retrieveContractByName(SourceUnit const& _source, string const& _name)

View File

@ -83,10 +83,7 @@ public:
langutil::SourceReferenceFormatter formatter(std::cerr);
for (auto const& error: m_compiler.errors())
formatter.printExceptionInformation(
*error,
(error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
BOOST_ERROR("Compiling contract failed");
}
eth::LinkerObject obj;
@ -104,10 +101,7 @@ public:
langutil::SourceReferenceFormatter formatter(std::cerr);
for (auto const& error: m_compiler.errors())
formatter.printExceptionInformation(
*error,
(error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
BOOST_ERROR("Assembly contract failed. IR: " + m_compiler.yulIROptimized({}));
}
asmStack.optimize();

View File

@ -54,10 +54,7 @@ void yul::test::printErrors(ErrorList const& _errors)
SourceReferenceFormatter formatter(cout);
for (auto const& error: _errors)
formatter.printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
}

View File

@ -130,8 +130,5 @@ void ObjectCompilerTest::printErrors(ostream& _stream, ErrorList const& _errors)
SourceReferenceFormatter formatter(_stream);
for (auto const& error: _errors)
formatter.printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
}

View File

@ -159,8 +159,5 @@ void YulInterpreterTest::printErrors(ostream& _stream, ErrorList const& _errors)
SourceReferenceFormatter formatter(_stream);
for (auto const& error: _errors)
formatter.printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
}

View File

@ -353,8 +353,5 @@ void YulOptimizerTest::printErrors(ostream& _stream, ErrorList const& _errors)
SourceReferenceFormatter formatter(_stream);
for (auto const& error: _errors)
formatter.printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
}

View File

@ -80,10 +80,7 @@ public:
SourceReferenceFormatter formatter(cout);
for (auto const& error: m_errors)
formatter.printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
formatter.printErrorInformation(*error);
}
bool parse(string const& _input)

View File

@ -55,10 +55,7 @@ namespace
void printErrors(ErrorList const& _errors)
{
for (auto const& error: _errors)
SourceReferenceFormatter(cout).printExceptionInformation(
*error,
(error->type() == Error::Type::Warning) ? "Warning" : "Error"
);
SourceReferenceFormatter(cout).printErrorInformation(*error);
}
pair<shared_ptr<Block>, shared_ptr<AsmAnalysisInfo>> parse(string const& _source)