mirror of
https://github.com/pantor/inja.git
synced 2026-05-18 10:15:26 +00:00
95af782ca2
* add block and extend feature * constify, code cleaning * update single include * add html language to readme * clean tests * constantify, update year
77 lines
1.6 KiB
C++
77 lines
1.6 KiB
C++
// Copyright (c) 2021 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& node) {
|
|
for (auto& n : node.arguments) {
|
|
n->accept(*this);
|
|
}
|
|
}
|
|
|
|
void visit(const ExpressionListNode& node) {
|
|
node.root->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 ExtendsStatementNode&) { }
|
|
|
|
void visit(const BlockStatementNode& node) {
|
|
node.block.accept(*this);
|
|
}
|
|
|
|
void visit(const SetStatementNode&) { }
|
|
|
|
public:
|
|
unsigned int variable_counter;
|
|
|
|
explicit StatisticsVisitor() : variable_counter(0) { }
|
|
};
|
|
|
|
} // namespace inja
|
|
|
|
#endif // INCLUDE_INJA_STATISTICS_HPP_
|