]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/debug.h
Only remove load IDs of variables actually assigned in a loop
[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         std::string apply(Stage &);
41         std::string apply(Node &n) { n.visit(*this); return formatted; }
42
43 private:
44         void append(const std::string &);
45         void append(const Node &, const std::string &);
46         void append_subtree(const std::vector<Branch> &);
47         void append_subtree(Node &);
48         void begin_sub();
49         void last_branch();
50         void end_sub();
51         unsigned get_label(const Node &);
52         std::string format_type(TypeDeclaration *);
53
54         template<typename T>
55         typename T::const_iterator increment(typename T::const_iterator &, const T &);
56
57         virtual void visit(Block &);
58         virtual void visit(Literal &);
59         virtual void visit(VariableReference &);
60         virtual void visit(InterfaceBlockReference &);
61         virtual void visit(MemberAccess &);
62         virtual void visit(Swizzle &);
63         virtual void visit(UnaryExpression &);
64         virtual void visit(BinaryExpression &);
65         virtual void visit(Assignment &);
66         virtual void visit(TernaryExpression &);
67         virtual void visit(FunctionCall &);
68         virtual void visit(ExpressionStatement &);
69         virtual void visit(Import &);
70         virtual void visit(Precision &);
71         virtual void visit(Layout &);
72         virtual void visit(InterfaceLayout &);
73         virtual void visit(BasicTypeDeclaration &);
74         virtual void visit(ImageTypeDeclaration &);
75         virtual void visit(StructDeclaration &);
76         virtual void visit(VariableDeclaration &);
77         virtual void visit(InterfaceBlock &);
78         virtual void visit(FunctionDeclaration &);
79         virtual void visit(Conditional &);
80         virtual void visit(Iteration &);
81         virtual void visit(Passthrough &);
82         virtual void visit(Return &);
83         virtual void visit(Jump &);
84 };
85
86 } // namespace SL
87 } // namespace GL
88 } // namespace Msp
89
90 #endif