X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.h;h=4e48a1a11f112205ec10feedf2017d6c7099ddd1;hb=7b73b63df12b3ace4231842aa291d6e1d7b3f948;hp=756584c2e262289783a6f58ec75cbfc2c6ec5a46;hpb=05597fbb3671dfed4776bc5223958c85e780345e;p=libs%2Fgl.git diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index 756584c2..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,13 +43,16 @@ public: virtual void visit(Jump &) { } }; +/** An intermediate base visitor class which traverses the syntax tree. */ class TraversingVisitor: public NodeVisitor { protected: - TraversingVisitor() { } + Block *current_block; + + TraversingVisitor(): current_block(0) { } public: - using NodeVisitor::visit; + virtual void enter(Block &) { } virtual void visit(Block &); virtual void visit(ParenthesizedExpression &); virtual void visit(MemberAccess &); @@ -66,22 +71,7 @@ public: virtual void visit(Return &); }; -class BlockModifier: public TraversingVisitor -{ -protected: - bool remove_node; - std::vector > insert_nodes; - - BlockModifier(); - - void flatten_block(Block &); - void apply_and_increment(Block &, NodeList::iterator &); - -public: - using TraversingVisitor::visit; - virtual void visit(Block &); -}; - +/** Gathers nodes of a particular type from the syntax tree. */ template class NodeGatherer: private TraversingVisitor { @@ -89,28 +79,33 @@ private: std::vector nodes; public: - const std::vector &apply(Stage &s) { visit(s.content); return nodes; } + const std::vector &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; - std::set to_remove; + const std::set *to_remove; + bool recursive_remove; public: - NodeRemover(const std::set &); + NodeRemover(); - void apply(Stage &); + void apply(Stage &, const std::set &); private: - using TraversingVisitor::visit; + template + void remove_from_map(std::map &, const std::string &, T &); + virtual void visit(Block &); + virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &); virtual void visit(Iteration &); };