29
29
#include < libsolidity/ast/TypeProvider.h>
30
30
#include < libsolutil/Keccak256.h>
31
31
32
+ #include < range/v3/view/tail.hpp>
33
+
32
34
#include < boost/algorithm/string.hpp>
33
35
34
36
#include < functional>
@@ -38,6 +40,17 @@ using namespace std;
38
40
using namespace solidity ;
39
41
using namespace solidity ::frontend;
40
42
43
+ namespace
44
+ {
45
+ TryCatchClause const * findClause (vector<ASTPointer<TryCatchClause>> const & _clauses, optional<string> _errorName = {})
46
+ {
47
+ for (auto const & clause: ranges::views::tail (_clauses))
48
+ if (_errorName.has_value () ? clause->errorName () == _errorName : clause->errorName ().empty ())
49
+ return clause.get ();
50
+ return nullptr ;
51
+ }
52
+ }
53
+
41
54
ASTNode::ASTNode (int64_t _id, SourceLocation _location):
42
55
m_id(static_cast <size_t >(_id)),
43
56
m_location(std::move(_location))
@@ -981,26 +994,14 @@ TryCatchClause const* TryStatement::successClause() const
981
994
return m_clauses[0 ].get ();
982
995
}
983
996
984
- TryCatchClause const * TryStatement::panicClause () const
985
- {
986
- for (size_t i = 1 ; i < m_clauses.size (); ++i)
987
- if (m_clauses[i]->errorName () == " Panic" )
988
- return m_clauses[i].get ();
989
- return nullptr ;
997
+ TryCatchClause const * TryStatement::panicClause () const {
998
+ return findClause (m_clauses, " Panic" );
990
999
}
991
1000
992
- TryCatchClause const * TryStatement::errorClause () const
993
- {
994
- for (size_t i = 1 ; i < m_clauses.size (); ++i)
995
- if (m_clauses[i]->errorName () == " Error" )
996
- return m_clauses[i].get ();
997
- return nullptr ;
1001
+ TryCatchClause const * TryStatement::errorClause () const {
1002
+ return findClause (m_clauses, " Error" );
998
1003
}
999
1004
1000
- TryCatchClause const * TryStatement::fallbackClause () const
1001
- {
1002
- for (size_t i = 1 ; i < m_clauses.size (); ++i)
1003
- if (m_clauses[i]->errorName ().empty ())
1004
- return m_clauses[i].get ();
1005
- return nullptr ;
1005
+ TryCatchClause const * TryStatement::fallbackClause () const {
1006
+ return findClause (m_clauses);
1006
1007
}
0 commit comments