aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/jinja2cpp/src/ast_visitor.h
diff options
context:
space:
mode:
authorMaxim Yurchuk <maxim-yurchuk@ydb.tech>2024-10-18 20:31:38 +0300
committerGitHub <noreply@github.com>2024-10-18 20:31:38 +0300
commit2a74bac2d2d3bccb4e10120f1ead805640ec9dd0 (patch)
tree047e4818ced5aaf73f58517629e5260b5291f9f0 /contrib/libs/jinja2cpp/src/ast_visitor.h
parent2d9656823e9521d8c29ea4c9a1d0eab78391abfc (diff)
parent3d834a1923bbf9403cd4a448e7f32b670aa4124f (diff)
downloadydb-2a74bac2d2d3bccb4e10120f1ead805640ec9dd0.tar.gz
Merge pull request #10502 from ydb-platform/mergelibs-241016-1210
Library import 241016-1210
Diffstat (limited to 'contrib/libs/jinja2cpp/src/ast_visitor.h')
-rw-r--r--contrib/libs/jinja2cpp/src/ast_visitor.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/contrib/libs/jinja2cpp/src/ast_visitor.h b/contrib/libs/jinja2cpp/src/ast_visitor.h
new file mode 100644
index 0000000000..01b519829b
--- /dev/null
+++ b/contrib/libs/jinja2cpp/src/ast_visitor.h
@@ -0,0 +1,117 @@
+#ifndef JINJA2CPP_SRC_AST_VISITOR_H
+#define JINJA2CPP_SRC_AST_VISITOR_H
+
+namespace jinja2
+{
+class IRendererBase;
+class ExpressionEvaluatorBase;
+class Statement;
+class ForStatement;
+class IfStatement;
+class ElseBranchStatement;
+class SetStatement;
+class ParentBlockStatement;
+class BlockStatement;
+class ExtendsStatement;
+class IncludeStatement;
+class ImportStatement;
+class MacroStatement;
+class MacroCallStatement;
+class ComposedRenderer;
+class RawTextRenderer;
+class ExpressionRenderer;
+
+class StatementVisitor;
+
+class VisitableStatement
+{
+public:
+ virtual ~VisitableStatement() = default;
+
+ virtual void ApplyVisitor(StatementVisitor* visitor) = 0;
+ virtual void ApplyVisitor(StatementVisitor* visitor) const = 0;
+};
+
+#define VISITABLE_STATEMENT() \
+ void ApplyVisitor(StatementVisitor* visitor) override {visitor->DoVisit(this);} \
+ void ApplyVisitor(StatementVisitor* visitor) const override {visitor->DoVisit(this);} \
+
+namespace detail
+{
+template<typename Base, typename Type>
+class VisitorIfaceImpl : public Base
+{
+public:
+ using Base::DoVisit;
+
+ virtual void DoVisit(Type*) {}
+ virtual void DoVisit(const Type*) {}
+};
+
+template<typename Type>
+class VisitorIfaceImpl<void, Type>
+{
+public:
+ virtual void DoVisit(Type*) {}
+ virtual void DoVisit(const Type*) {}
+};
+
+template<typename Base, typename ... Types>
+struct VisitorBaseImpl;
+
+template<typename Base, typename T, typename ... Types>
+struct VisitorBaseImpl<Base, T, Types...>
+{
+ using current_base = VisitorIfaceImpl<Base, T>;
+ using base_type = typename VisitorBaseImpl<current_base, Types...>::base_type;
+};
+
+template<typename Base, typename T>
+struct VisitorBaseImpl<Base, T>
+{
+ using base_type = VisitorIfaceImpl<Base, T>;
+};
+
+
+template<typename ... Types>
+struct VisitorBase
+{
+ using type = typename VisitorBaseImpl<void, Types ...>::base_type;
+};
+} // namespace detail
+
+template<typename ... Types>
+using VisitorBase = typename detail::VisitorBase<Types...>::type;
+
+class StatementVisitor : public VisitorBase<
+ IRendererBase,
+ Statement,
+ ForStatement,
+ IfStatement,
+ ElseBranchStatement,
+ SetStatement,
+ ParentBlockStatement,
+ BlockStatement,
+ ExtendsStatement,
+ IncludeStatement,
+ ImportStatement,
+ MacroStatement,
+ MacroCallStatement,
+ ComposedRenderer,
+ RawTextRenderer,
+ ExpressionRenderer>
+{
+public:
+ void Visit(VisitableStatement* stmt)
+ {
+ stmt->ApplyVisitor(this);
+ }
+ void Visit(const VisitableStatement* stmt)
+ {
+ stmt->ApplyVisitor(this);
+ }
+};
+} // namespace jinja2
+
+
+#endif