X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.h;h=ed2534cb31b865900e142a141632fc4f35be497a;hb=c4aeeced7b397d46772577775bd3a0d6c4706cba;hp=582628bbedc49ecfe695c9eacd7909d861bfa071;hpb=696a97bd7411d69953c1a9e4b5f3dfb4c1d848f1;p=libs%2Fgl.git diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index 582628bb..ed2534cb 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: @@ -18,18 +19,22 @@ public: virtual void visit(Block &) { } virtual void visit(Literal &) { } - virtual void visit(ParenthesizedExpression &) { } virtual void visit(VariableReference &) { } + virtual void visit(InterfaceBlockReference &) { } virtual void visit(MemberAccess &) { } + virtual void visit(Swizzle &) { } virtual void visit(UnaryExpression &) { } virtual void visit(BinaryExpression &) { } - virtual void visit(Assignment &); + virtual void visit(Assignment &) { } + virtual void visit(TernaryExpression &) { } 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(BasicTypeDeclaration &) { } + virtual void visit(ImageTypeDeclaration &) { } virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &) { } virtual void visit(InterfaceBlock &) { } @@ -41,18 +46,24 @@ 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(RefPtr &); virtual void visit(MemberAccess &); + virtual void visit(Swizzle &); virtual void visit(UnaryExpression &); virtual void visit(BinaryExpression &); + virtual void visit(Assignment &); + virtual void visit(TernaryExpression &); virtual void visit(FunctionCall &); virtual void visit(ExpressionStatement &); virtual void visit(InterfaceLayout &); @@ -66,65 +77,49 @@ public: virtual void visit(Return &); }; -class StageVisitor: public TraversingVisitor +/** Removes a set of nodes from the syntax tree. */ +class NodeRemover: private TraversingVisitor { -public: - typedef void ResultType; - -protected: +private: Stage *stage; - - StageVisitor(); + const std::set *to_remove; + bool recursive_remove; public: - virtual void apply(Stage &); - void get_result() const { } -}; + NodeRemover(); -class BlockModifier: public StageVisitor -{ -protected: - bool remove_node; - std::vector > insert_nodes; + void apply(Stage &, const std::set &); - BlockModifier(); - - void flatten_block(Block &); - void apply_and_increment(Block &, NodeList::iterator &); +private: + template + void remove_from_map(std::map &, const std::string &, T &); -public: - using StageVisitor::visit; virtual void visit(Block &); + void visit(TypeDeclaration &); + virtual void visit(BasicTypeDeclaration &t) { visit(static_cast(t)); } + virtual void visit(ImageTypeDeclaration &t) { visit(static_cast(t)); } + virtual void visit(StructDeclaration &t) { visit(static_cast(t)); } + virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &); + virtual void visit(FunctionDeclaration &); + virtual void visit(Iteration &); }; -template -class NodeGatherer: public StageVisitor +/** 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 { -public: - typedef std::vector ResultType; - private: - std::vector nodes; + Node *reorder_before; + const std::set *to_reorder; public: - const ResultType &get_result() const { return nodes; } - using StageVisitor::visit; - virtual void visit(T &n) { nodes.push_back(&n); } -}; + NodeReorderer(); -class NodeRemover: public StageVisitor -{ -private: - std::set to_remove; - -public: - NodeRemover() { } - NodeRemover(const std::set &); + void apply(Stage &, Node &, const std::set &); - using StageVisitor::visit; +private: virtual void visit(Block &); - virtual void visit(VariableDeclaration &); - virtual void visit(Iteration &); }; } // namespace SL