diff --git a/liblangutil/SourceReferenceFormatter.cpp b/liblangutil/SourceReferenceFormatter.cpp index 4bc47a656..01c1dd5ff 100644 --- a/liblangutil/SourceReferenceFormatter.cpp +++ b/liblangutil/SourceReferenceFormatter.cpp @@ -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) diff --git a/liblangutil/SourceReferenceFormatter.h b/liblangutil/SourceReferenceFormatter.h index c01b360eb..fee223088 100644 --- a/liblangutil/SourceReferenceFormatter.h +++ b/liblangutil/SourceReferenceFormatter.h @@ -25,6 +25,7 @@ #include #include #include +#include #include 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, diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index 033a05fe3..153ee5b8a 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -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); diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 34fbe35a7..9b1ad3413 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -53,10 +53,7 @@ pair 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(); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index f2d82f274..d89a8108e 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -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; diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 92db75901..f5c592906 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -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) diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index fbd1814e6..a04b5373d 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -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(); diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index e4ee599c4..485590fec 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -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); } diff --git a/test/libyul/ObjectCompilerTest.cpp b/test/libyul/ObjectCompilerTest.cpp index 0363cc298..d350f54d0 100644 --- a/test/libyul/ObjectCompilerTest.cpp +++ b/test/libyul/ObjectCompilerTest.cpp @@ -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); } diff --git a/test/libyul/YulInterpreterTest.cpp b/test/libyul/YulInterpreterTest.cpp index a04cabe02..cfbb2ab08 100644 --- a/test/libyul/YulInterpreterTest.cpp +++ b/test/libyul/YulInterpreterTest.cpp @@ -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); } diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 4d34b03cb..e5fe097f7 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -354,8 +354,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); } diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index d5d72831b..776759ebe 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -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) diff --git a/test/tools/yulrun.cpp b/test/tools/yulrun.cpp index 04e773d1e..c1461d61e 100644 --- a/test/tools/yulrun.cpp +++ b/test/tools/yulrun.cpp @@ -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> parse(string const& _source)