Skip to content

Commit b6bd852

Browse files
committed
Accessors for exceptions.
1 parent cc2a860 commit b6bd852

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

liblangutil/Exceptions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ Error::Error(
7575
*this << util::errinfo_comment(_description);
7676
}
7777

78+
SourceLocation const* Error::sourceLocation() const noexcept
79+
{
80+
return boost::get_error_info<errinfo_sourceLocation>(*this);
81+
}
82+
83+
SecondarySourceLocation const* Error::secondarySourceLocation() const noexcept
84+
{
85+
return boost::get_error_info<errinfo_secondarySourceLocation>(*this);
86+
}
87+
7888
optional<Error::Severity> Error::severityFromString(string _input)
7989
{
8090
boost::algorithm::to_lower(_input);

liblangutil/Exceptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ class Error: virtual public util::Exception
197197
Type type() const { return m_type; }
198198
std::string const& typeName() const { return m_typeName; }
199199

200+
SourceLocation const* sourceLocation() const noexcept;
201+
SecondarySourceLocation const* secondarySourceLocation() const noexcept;
202+
200203
/// helper functions
201204
static Error const* containsErrorOfType(ErrorList const& _list, Error::Type _type)
202205
{
@@ -206,7 +209,7 @@ class Error: virtual public util::Exception
206209
return nullptr;
207210
}
208211

209-
static Severity errorSeverity(Type _type)
212+
static constexpr Severity errorSeverity(Type _type)
210213
{
211214
if (_type == Type::Info)
212215
return Severity::Info;

libsolidity/interface/StandardCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Json::Value formatErrorWithException(
129129
_charStreamProvider
130130
);
131131

132-
if (string const* description = boost::get_error_info<util::errinfo_comment>(_exception))
132+
if (string const* description = _exception.comment())
133133
message = ((_message.length() > 0) ? (_message + ":") : "") + *description;
134134
else
135135
message = _message;

libsolutil/Exceptions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ struct Exception: virtual std::exception, virtual boost::exception
3939

4040
/// @returns the errinfo_comment of this exception.
4141
std::string const* comment() const noexcept;
42-
43-
private:
4442
};
4543

4644
/// Throws an exception with a given description and extra information about the location the

test/libsolidity/AnalysisFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ErrorList AnalysisFramework::filterErrors(ErrorList const& _errorList, bool _inc
100100
for (auto const& messagePrefix: m_messagesToCut)
101101
if (currentError->comment()->find(messagePrefix) == 0)
102102
{
103-
SourceLocation const* location = boost::get_error_info<errinfo_sourceLocation>(*currentError);
103+
SourceLocation const* location = currentError->sourceLocation();
104104
// sufficient for now, but in future we might clone the error completely, including the secondary location
105105
newError = make_shared<Error>(
106106
currentError->errorId(),

test/libsolidity/SyntaxTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ void SyntaxTest::filterObtainedErrors()
118118
{
119119
for (auto const& currentError: filterErrors(compiler().errors(), true))
120120
{
121-
int locationStart = -1, locationEnd = -1;
121+
int locationStart = -1;
122+
int locationEnd = -1;
122123
string sourceName;
123-
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*currentError))
124+
if (SourceLocation const* location = currentError->sourceLocation())
124125
{
125126
solAssert(location->sourceName, "");
126127
sourceName = *location->sourceName;

test/libyul/SyntaxTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void SyntaxTest::parseAndAnalyze()
5454
int locationStart = -1;
5555
int locationEnd = -1;
5656

57-
if (auto location = boost::get_error_info<errinfo_sourceLocation>(*error))
57+
if (SourceLocation const* location = error->sourceLocation())
5858
{
5959
locationStart = location->start;
6060
locationEnd = location->end;

0 commit comments

Comments
 (0)