VapourSynth-llvmexpr
Loading...
Searching...
No Matches
ASTPrinter.hpp
Go to the documentation of this file.
1
19
20#ifndef LLVMEXPR_FRONTEND_INFIX2POSTFIX_ASTPRINTER_HPP
21#define LLVMEXPR_FRONTEND_INFIX2POSTFIX_ASTPRINTER_HPP
22
23#include "AST.hpp"
24
25#include <format>
26#include <sstream>
27#include <string>
28#include <string_view>
29
30namespace infix2postfix {
31
33 public:
34 std::string print(const Program* program);
35
36 private:
37 void print(const Stmt* stmt);
38 void print(const Expr* expr);
39
40 // Stmt visitors
41 void visit(const ExprStmt& stmt);
42 void visit(const AssignStmt& stmt);
43 void visit(const ArrayAssignStmt& stmt);
44 void visit(const BlockStmt& stmt);
45 void visit(const IfStmt& stmt);
46 void visit(const WhileStmt& stmt);
47 void visit(const ReturnStmt& stmt);
48 void visit(const LabelStmt& stmt);
49 void visit(const GotoStmt& stmt);
50 void visit(const GlobalDecl& stmt);
51 void visit(const FunctionDef& stmt);
52
53 // Expr visitors
54 void visit(const NumberExpr& expr);
55 void visit(const VariableExpr& expr);
56 void visit(const UnaryExpr& expr);
57 void visit(const BinaryExpr& expr);
58 void visit(const TernaryExpr& expr);
59 void visit(const CallExpr& expr);
60 void visit(const PropAccessExpr& expr);
61 void visit(const StaticRelPixelAccessExpr& expr);
62 void visit(const FrameDimensionExpr& expr);
63 void visit(const ArrayAccessExpr& expr);
64
65 void indent();
66 void unindent();
67
68 template <typename... Args>
69 void line(const std::string_view format_str, Args&&... args) {
70 for (int i = 0; i < indent_level; ++i) {
71 ss << " ";
72 }
73 ss << std::vformat(format_str,
74 std::make_format_args(std::forward<Args>(args)...))
75 << "\n";
76 }
77
78 std::stringstream ss;
79 int indent_level = 0;
80};
81
82} // namespace infix2postfix
83
84#endif // LLVMEXPR_FRONTEND_INFIX2POSTFIX_ASTPRINTER_HPP
std::string print(const Program *program)