diff --git a/liblangutil/Exceptions.cpp b/liblangutil/Exceptions.cpp index a410a986354d..2595c7755c3a 100644 --- a/liblangutil/Exceptions.cpp +++ b/liblangutil/Exceptions.cpp @@ -75,6 +75,16 @@ Error::Error( *this << util::errinfo_comment(_description); } +SourceLocation const* Error::sourceLocation() const noexcept +{ + return boost::get_error_info(*this); +} + +SecondarySourceLocation const* Error::secondarySourceLocation() const noexcept +{ + return boost::get_error_info(*this); +} + optional Error::severityFromString(string _input) { boost::algorithm::to_lower(_input); diff --git a/liblangutil/Exceptions.h b/liblangutil/Exceptions.h index 0c8f03cb94c4..10fca802937f 100644 --- a/liblangutil/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -197,6 +197,9 @@ class Error: virtual public util::Exception Type type() const { return m_type; } std::string const& typeName() const { return m_typeName; } + SourceLocation const* sourceLocation() const noexcept; + SecondarySourceLocation const* secondarySourceLocation() const noexcept; + /// helper functions static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type) { @@ -206,7 +209,7 @@ class Error: virtual public util::Exception return nullptr; } - static Severity errorSeverity(Type _type) + static constexpr Severity errorSeverity(Type _type) { if (_type == Type::Info) return Severity::Info; diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index da28cf29f2b5..39ed7c10fb7e 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -129,7 +129,7 @@ Json::Value formatErrorWithException( _charStreamProvider ); - if (string const* description = boost::get_error_info(_exception)) + if (string const* description = _exception.comment()) message = ((_message.length() > 0) ? (_message + ":") : "") + *description; else message = _message; diff --git a/libsolutil/Exceptions.h b/libsolutil/Exceptions.h index d83d8004b406..9d351a28d2e4 100644 --- a/libsolutil/Exceptions.h +++ b/libsolutil/Exceptions.h @@ -39,8 +39,6 @@ struct Exception: virtual std::exception, virtual boost::exception /// @returns the errinfo_comment of this exception. std::string const* comment() const noexcept; - -private: }; /// Throws an exception with a given description and extra information about the location the diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index 84c7a5e0bddf..5dce2211f938 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -100,7 +100,7 @@ ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _inc for (auto const& messagePrefix: m_messagesToCut) if (currentError->comment()->find(messagePrefix) == 0) { - SourceLocation const* location = boost::get_error_info(*currentError); + SourceLocation const* location = currentError->sourceLocation(); // sufficient for now, but in future we might clone the error completely, including the secondary location newError = make_shared( currentError->errorId(), diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 4998b628b38b..d3e5124508e6 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -118,9 +118,10 @@ void SyntaxTest::filterObtainedErrors() { for (auto const& currentError: filterErrors(compiler().errors(), true)) { - int locationStart = -1, locationEnd = -1; + int locationStart = -1; + int locationEnd = -1; string sourceName; - if (auto location = boost::get_error_info(*currentError)) + if (SourceLocation const* location = currentError->sourceLocation()) { solAssert(location->sourceName, ""); sourceName = *location->sourceName; diff --git a/test/libyul/SyntaxTest.cpp b/test/libyul/SyntaxTest.cpp index 4668773e933c..8ab5bb953084 100644 --- a/test/libyul/SyntaxTest.cpp +++ b/test/libyul/SyntaxTest.cpp @@ -54,7 +54,7 @@ void SyntaxTest::parseAndAnalyze() int locationStart = -1; int locationEnd = -1; - if (auto location = boost::get_error_info(*error)) + if (SourceLocation const* location = error->sourceLocation()) { locationStart = location->start; locationEnd = location->end;