X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fglsl%2Fvisitor.h;h=cd9dafb0b016338eb2f8a12c58e1eb94eeb48a8c;hb=0febee9a8fdf1f9b03d3f2e23e72f8194b3698c7;hp=a26e785c741e3b97e643d78f6353742feca04dd2;hpb=bd8816692056230c36504dcccd76c6946dff47b1;p=libs%2Fgl.git diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index a26e785c..cd9dafb0 100644 --- a/source/glsl/visitor.h +++ b/source/glsl/visitor.h @@ -9,6 +9,7 @@ namespace Msp { namespace GL { namespace SL { +/** Base class for all node visitors. */ class NodeVisitor { protected: @@ -24,7 +25,7 @@ public: virtual void visit(MemberAccess &) { } virtual void visit(UnaryExpression &) { } virtual void visit(BinaryExpression &) { } - virtual void visit(Assignment &); + virtual void visit(Assignment &) { } virtual void visit(FunctionCall &) { } virtual void visit(ExpressionStatement &) { } virtual void visit(Import &) { } @@ -42,6 +43,7 @@ public: virtual void visit(Jump &) { } }; +/** An intermediate base visitor class which traverses the syntax tree. */ class TraversingVisitor: public NodeVisitor { protected: @@ -56,6 +58,7 @@ public: 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(InterfaceLayout &); @@ -69,6 +72,7 @@ public: virtual void visit(Return &); }; +/** Gathers nodes of a particular type from the syntax tree. */ template class NodeGatherer: private TraversingVisitor { @@ -82,6 +86,7 @@ private: virtual void visit(T &n) { nodes.push_back(&n); } }; +/** Removes a set of nodes from the syntax tree. */ class NodeRemover: private TraversingVisitor { private: @@ -102,9 +107,27 @@ private: virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); + virtual void visit(FunctionDeclaration &); virtual void visit(Iteration &); }; +/** Reorders a set of nodes so they appear before another node. Only nodes +on the same hierarchly level as the target node are reordered. */ +class NodeReorderer: private TraversingVisitor +{ +private: + Node *reorder_before; + const std::set *to_reorder; + +public: + NodeReorderer(); + + void apply(Stage &, Node &, const std::set &); + +private: + virtual void visit(Block &); +}; + } // namespace SL } // namespace GL } // namespace Msp