From 2be64c702609df67903fd89c42cf632d71aad6fd Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 20 May 2015 00:27:07 +0200 Subject: Gas estimation taking known state into account. --- ASTVisitor.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ASTVisitor.h') diff --git a/ASTVisitor.h b/ASTVisitor.h index fbda5079..f7847220 100644 --- a/ASTVisitor.h +++ b/ASTVisitor.h @@ -220,6 +220,26 @@ protected: virtual void endVisitNode(ASTNode const&) { } }; +/** + * Utility class that accepts std::functions and calls them for visitNode and endVisitNode. + */ +class SimpleASTVisitor: public ASTConstVisitor +{ +public: + SimpleASTVisitor( + std::function _onVisit, + std::function _onEndVisit + ): m_onVisit(_onVisit), m_onEndVisit(_onEndVisit) {} + +protected: + virtual bool visitNode(ASTNode const& _n) override { return m_onVisit ? m_onVisit(_n) : true; } + virtual void endVisitNode(ASTNode const& _n) override { m_onEndVisit(_n); } + +private: + std::function m_onVisit; + std::function m_onEndVisit; +}; + /** * Utility class that visits the AST in depth-first order and calls a function on each node and each edge. * Child nodes are only visited if the node callback of the parent returns true. -- cgit