]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/debug.h
Add a visitor to dump the AST for debugging purposes
[libs/gl.git] / source / glsl / debug.h
diff --git a/source/glsl/debug.h b/source/glsl/debug.h
new file mode 100644 (file)
index 0000000..9806d54
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef MSP_GL_SL_DEBUG_H_
+#define MSP_GL_SL_DEBUG_H_
+
+#include "syntax.h"
+#include "visitor.h"
+
+namespace Msp {
+namespace GL {
+namespace SL {
+
+class DumpTree: private TraversingVisitor
+{
+private:
+       enum TreeChars
+       {
+               EMPTY = 0x20,
+               STRAIGHT = 0x2502,     // │
+               BRANCH = 0x251C,       // ├
+               BRANCH_LAST = 0x2514,  // └
+               REACH = 0x2574         // ╴
+       };
+
+       std::map<const Node *, unsigned> node_labels;
+       std::string formatted;
+       std::vector<TreeChars> tree;
+
+public:
+       const std::string &apply(Stage &);
+
+private:
+       void append(const std::string &);
+       void begin_sub();
+       void last_branch();
+       void end_sub();
+       void annotated_branch(const std::string &, Node &);
+       unsigned get_label(const Node &);
+
+       template<typename T>
+       typename T::const_iterator increment(typename T::const_iterator &, const T &);
+
+       virtual void visit(Block &);
+       virtual void visit(Literal &);
+       virtual void visit(ParenthesizedExpression &);
+       virtual void visit(VariableReference &);
+       virtual void visit(MemberAccess &);
+       virtual void visit(UnaryExpression &);
+       virtual void visit(BinaryExpression &);
+       virtual void visit(Assignment &);
+       virtual void visit(FunctionCall &);
+       virtual void visit(ExpressionStatement &);
+       virtual void visit(Import &);
+       virtual void visit(Precision &);
+       virtual void visit(Layout &);
+       virtual void visit(InterfaceLayout &);
+       virtual void visit(StructDeclaration &);
+       virtual void visit(VariableDeclaration &);
+       virtual void visit(InterfaceBlock &);
+       virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
+       virtual void visit(Return &);
+       virtual void visit(Jump &);
+       using TraversingVisitor::visit;
+};
+
+} // namespace SL
+} // namespace GL
+} // namespace Msp
+
+#endif