diff options
Diffstat (limited to 'include/inja/statistics.hpp')
-rw-r--r-- | include/inja/statistics.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/include/inja/statistics.hpp b/include/inja/statistics.hpp new file mode 100644 index 0000000..71fc719 --- /dev/null +++ b/include/inja/statistics.hpp @@ -0,0 +1,68 @@ +// Copyright (c) 2019 Pantor. All rights reserved. + +#ifndef INCLUDE_INJA_STATISTICS_HPP_ +#define INCLUDE_INJA_STATISTICS_HPP_ + +#include "node.hpp" + + +namespace inja { + +/*! + * \brief A class for counting statistics on a Template. + */ +class StatisticsVisitor : public NodeVisitor { + void visit(const BlockNode& node) { + for (auto& n : node.nodes) { + n->accept(*this); + } + } + + void visit(const TextNode&) { } + void visit(const ExpressionNode&) { } + void visit(const LiteralNode&) { } + + void visit(const JsonNode&) { + variable_counter += 1; + } + + void visit(const FunctionNode&) { } + + void visit(const ExpressionListNode& node) { + for (auto& n : node.rpn_output) { + n->accept(*this); + } + } + + void visit(const StatementNode&) { } + void visit(const ForStatementNode&) { } + + void visit(const ForArrayStatementNode& node) { + node.condition.accept(*this); + node.body.accept(*this); + } + + void visit(const ForObjectStatementNode& node) { + node.condition.accept(*this); + node.body.accept(*this); + } + + void visit(const IfStatementNode& node) { + node.condition.accept(*this); + node.true_statement.accept(*this); + node.false_statement.accept(*this); + } + + void visit(const IncludeStatementNode&) { } + + void visit(const SetStatementNode&) { } + +public: + unsigned int variable_counter; + + explicit StatisticsVisitor() : variable_counter(0) { } +}; + +} // namespace inja + +#endif // INCLUDE_INJA_STATISTICS_HPP_ |