]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/visitor.h
Add some documentation to the GLSL compiler
[libs/gl.git] / source / glsl / visitor.h
index 35dce52400fc74daf1c71ae538e8affa700121f4..4e48a1a11f112205ec10feedf2017d6c7099ddd1 100644 (file)
@@ -9,6 +9,7 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+/** Base class for all node visitors. */
 class NodeVisitor
 {
 protected:
@@ -20,6 +21,7 @@ public:
        virtual void visit(Literal &) { }
        virtual void visit(ParenthesizedExpression &) { }
        virtual void visit(VariableReference &) { }
+       virtual void visit(InterfaceBlockReference &) { }
        virtual void visit(MemberAccess &) { }
        virtual void visit(UnaryExpression &) { }
        virtual void visit(BinaryExpression &) { }
@@ -41,6 +43,7 @@ public:
        virtual void visit(Jump &) { }
 };
 
+/** An intermediate base visitor class which traverses the syntax tree. */
 class TraversingVisitor: public NodeVisitor
 {
 protected:
@@ -49,7 +52,7 @@ protected:
        TraversingVisitor(): current_block(0) { }
 
 public:
-       using NodeVisitor::visit;
+       virtual void enter(Block &) { }
        virtual void visit(Block &);
        virtual void visit(ParenthesizedExpression &);
        virtual void visit(MemberAccess &);
@@ -68,6 +71,7 @@ public:
        virtual void visit(Return &);
 };
 
+/** Gathers nodes of a particular type from the syntax tree. */
 template<typename T>
 class NodeGatherer: private TraversingVisitor
 {
@@ -75,20 +79,18 @@ private:
        std::vector<T *> nodes;
 
 public:
-       const std::vector<T *> &apply(Stage &s) { nodes.clear(); visit(s.content); return nodes; }
+       const std::vector<T *> &apply(Stage &s) { s.content.visit(*this); return nodes; }
 
 private:
-       using TraversingVisitor::visit;
        virtual void visit(T &n) { nodes.push_back(&n); }
 };
 
+/** Removes a set of nodes from the syntax tree. */
 class NodeRemover: private TraversingVisitor
 {
 private:
        Stage *stage;
        const std::set<Node *> *to_remove;
-       std::vector<Block *> blocks;
-       bool anonymous;
        bool recursive_remove;
 
 public:
@@ -97,9 +99,9 @@ public:
        void apply(Stage &, const std::set<Node *> &);
 
 private:
-       void remove_variable(std::map<std::string, VariableDeclaration *> &, VariableDeclaration &);
+       template<typename T>
+       void remove_from_map(std::map<std::string, T *> &, const std::string &, T &);
 
-       using TraversingVisitor::visit;
        virtual void visit(Block &);
        virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);