]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/debug.h
Easier way of adding complex subtrees to GLSL debug dump
[libs/gl.git] / source / glsl / debug.h
1 #ifndef MSP_GL_SL_DEBUG_H_
2 #define MSP_GL_SL_DEBUG_H_
3
4 #include "syntax.h"
5 #include "visitor.h"
6
7 namespace Msp {
8 namespace GL {
9 namespace SL {
10
11 /** Creates a textual representation of the syntax tree.  The result is encoded
12 as UTF-8. */
13 class DumpTree: private TraversingVisitor
14 {
15 private:
16         enum TreeChars
17         {
18                 EMPTY = 0x20,
19                 STRAIGHT = 0x2502,     // │
20                 BRANCH = 0x251C,       // ├
21                 BRANCH_LAST = 0x2514,  // └
22                 REACH = 0x2574         // ╴
23         };
24
25         struct Branch
26         {
27                 std::string text;
28                 Node *node;
29
30                 Branch(const char *t, Node *n = 0): text(t), node(n) { }
31                 Branch(const std::string &t, Node *n = 0): text(t), node(n) { }
32                 Branch(Node *n): node(n) { }
33         };
34
35         std::map<const Node *, unsigned> node_labels;
36         std::string formatted;
37         std::vector<TreeChars> tree;
38
39 public:
40         const std::string &apply(Stage &);
41
42 private:
43         void append(const std::string &);
44         void append_subtree(const std::vector<Branch> &);
45         void begin_sub();
46         void last_branch();
47         void end_sub();
48         void annotated_branch(const std::string &, Node &);
49         unsigned get_label(const Node &);
50         std::string format_type(TypeDeclaration *);
51
52         template<typename T>
53         typename T::const_iterator increment(typename T::const_iterator &, const T &);
54
55         virtual void visit(Block &);
56         virtual void visit(Literal &);
57         virtual void visit(ParenthesizedExpression &);
58         virtual void visit(VariableReference &);
59         virtual void visit(InterfaceBlockReference &);
60         virtual void visit(MemberAccess &);
61         virtual void visit(UnaryExpression &);
62         virtual void visit(BinaryExpression &);
63         virtual void visit(Assignment &);
64         virtual void visit(FunctionCall &);
65         virtual void visit(ExpressionStatement &);
66         virtual void visit(Import &);
67         virtual void visit(Precision &);
68         virtual void visit(Layout &);
69         virtual void visit(InterfaceLayout &);
70         virtual void visit(BasicTypeDeclaration &);
71         virtual void visit(ImageTypeDeclaration &);
72         virtual void visit(StructDeclaration &);
73         virtual void visit(VariableDeclaration &);
74         virtual void visit(InterfaceBlock &);
75         virtual void visit(FunctionDeclaration &);
76         virtual void visit(Conditional &);
77         virtual void visit(Iteration &);
78         virtual void visit(Passthrough &);
79         virtual void visit(Return &);
80         virtual void visit(Jump &);
81 };
82
83 } // namespace SL
84 } // namespace GL
85 } // namespace Msp
86
87 #endif