X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.h;h=4e48a1a11f112205ec10feedf2017d6c7099ddd1;hb=30465dd3b9f55ec42c4b19c3c2077eede7237a26;hp=ba345c450bee95953e2ecb45d0322fd7f127004e;hpb=5c33b56c3b97ca0381ac216a603c7553f4bea499;p=libs%2Fgl.git diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index ba345c45..4e48a1a1 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: @@ -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,6 +52,7 @@ protected: TraversingVisitor(): current_block(0) { } public: + virtual void enter(Block &) { } virtual void visit(Block &); virtual void visit(ParenthesizedExpression &); virtual void visit(MemberAccess &); @@ -67,6 +71,7 @@ public: virtual void visit(Return &); }; +/** Gathers nodes of a particular type from the syntax tree. */ template class NodeGatherer: private TraversingVisitor { @@ -80,13 +85,12 @@ private: 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 *to_remove; - std::vector blocks; - bool anonymous; bool recursive_remove; public: @@ -95,7 +99,8 @@ public: void apply(Stage &, const std::set &); private: - void remove_variable(std::map &, VariableDeclaration &); + template + void remove_from_map(std::map &, const std::string &, T &); virtual void visit(Block &); virtual void visit(StructDeclaration &);