mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
ast: condense duplicate code
AST.cpp: * Added findClause() helper function to anonymous namespace.
This commit is contained in:
parent
22a0c46eae
commit
3d54bfd0c3
@ -29,6 +29,8 @@
|
|||||||
#include <libsolidity/ast/TypeProvider.h>
|
#include <libsolidity/ast/TypeProvider.h>
|
||||||
#include <libsolutil/Keccak256.h>
|
#include <libsolutil/Keccak256.h>
|
||||||
|
|
||||||
|
#include <range/v3/view/tail.hpp>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -38,6 +40,17 @@ using namespace std;
|
|||||||
using namespace solidity;
|
using namespace solidity;
|
||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
TryCatchClause const* findClause(vector<ASTPointer<TryCatchClause>> const& _clauses, optional<string> _errorName = {})
|
||||||
|
{
|
||||||
|
for (auto const& clause: ranges::views::tail(_clauses))
|
||||||
|
if (_errorName.has_value() ? clause->errorName() == _errorName : clause->errorName().empty())
|
||||||
|
return clause.get();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ASTNode::ASTNode(int64_t _id, SourceLocation _location):
|
ASTNode::ASTNode(int64_t _id, SourceLocation _location):
|
||||||
m_id(static_cast<size_t>(_id)),
|
m_id(static_cast<size_t>(_id)),
|
||||||
m_location(std::move(_location))
|
m_location(std::move(_location))
|
||||||
@ -981,26 +994,14 @@ TryCatchClause const* TryStatement::successClause() const
|
|||||||
return m_clauses[0].get();
|
return m_clauses[0].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
TryCatchClause const* TryStatement::panicClause() const
|
TryCatchClause const* TryStatement::panicClause() const {
|
||||||
{
|
return findClause(m_clauses, "Panic");
|
||||||
for (size_t i = 1; i < m_clauses.size(); ++i)
|
|
||||||
if (m_clauses[i]->errorName() == "Panic")
|
|
||||||
return m_clauses[i].get();
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TryCatchClause const* TryStatement::errorClause() const
|
TryCatchClause const* TryStatement::errorClause() const {
|
||||||
{
|
return findClause(m_clauses, "Error");
|
||||||
for (size_t i = 1; i < m_clauses.size(); ++i)
|
|
||||||
if (m_clauses[i]->errorName() == "Error")
|
|
||||||
return m_clauses[i].get();
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TryCatchClause const* TryStatement::fallbackClause() const
|
TryCatchClause const* TryStatement::fallbackClause() const {
|
||||||
{
|
return findClause(m_clauses);
|
||||||
for (size_t i = 1; i < m_clauses.size(); ++i)
|
|
||||||
if (m_clauses[i]->errorName().empty())
|
|
||||||
return m_clauses[i].get();
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user