From b6bd85202c0e5e6bae0dcc71b9ebcfea17de5f9a Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 1 Dec 2021 12:30:36 +0100 Subject: [PATCH] Accessors for exceptions. --- liblangutil/Exceptions.cpp | 10 ++++++++++ liblangutil/Exceptions.h | 5 ++++- libsolidity/interface/StandardCompiler.cpp | 2 +- libsolutil/Exceptions.h | 2 -- test/libsolidity/AnalysisFramework.cpp | 2 +- test/libsolidity/SyntaxTest.cpp | 5 +++-- test/libyul/SyntaxTest.cpp | 2 +- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/liblangutil/Exceptions.cpp b/liblangutil/Exceptions.cpp index a410a9863..2595c7755 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 0c8f03cb9..10fca8029 100644 --- a/liblangutil/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -197,6 +197,9 @@ public: 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 @@ public: 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 da28cf29f..39ed7c10f 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 d83d8004b..9d351a28d 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 84c7a5e0b..5dce2211f 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 4998b628b..d3e512450 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 4668773e9..8ab5bb953 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;