namespace GL {
namespace SL {
+/** Base class for all node visitors. */
class NodeVisitor
{
protected:
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 &) { }
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<Expression> &);
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 &);
virtual void visit(Return &);
};
-class BlockModifier: public TraversingVisitor
+/** Removes a set of nodes from the syntax tree. */
+class NodeRemover: private TraversingVisitor
{
-protected:
- bool remove_node;
- std::vector<RefPtr<Statement> > insert_nodes;
-
- BlockModifier();
-
- void flatten_block(Block &);
- void apply_and_increment(Block &, NodeList<Statement>::iterator &);
+private:
+ Stage *stage;
+ const std::set<Node *> *to_remove;
+ bool recursive_remove;
public:
- using TraversingVisitor::visit;
- virtual void visit(Block &);
-};
+ NodeRemover();
-template<typename T>
-class NodeGatherer: public TraversingVisitor
-{
-private:
- std::vector<T *> nodes;
+ void apply(Stage &, const std::set<Node *> &);
-public:
- const std::vector<T *> &apply(Stage &s) { visit(s.content); return nodes; }
+private:
+ template<typename T>
+ void remove_from_map(std::map<std::string, T *> &, const std::string &, T &);
- using TraversingVisitor::visit;
- virtual void visit(T &n) { nodes.push_back(&n); }
+ virtual void visit(Block &);
+ void visit(TypeDeclaration &);
+ virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
+ virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
+ virtual void visit(StructDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
+ virtual void visit(VariableDeclaration &);
+ virtual void visit(InterfaceBlock &);
+ virtual void visit(FunctionDeclaration &);
+ virtual void visit(Iteration &);
};
-class NodeRemover: public TraversingVisitor
+/** 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:
- Stage *stage;
- std::set<Node *> to_remove;
+ Node *reorder_before;
+ const std::set<Node *> *to_reorder;
public:
- NodeRemover(const std::set<Node *> &);
+ NodeReorderer();
- void apply(Stage &);
+ void apply(Stage &, Node &, const std::set<Node *> &);
- using TraversingVisitor::visit;
+private:
virtual void visit(Block &);
- virtual void visit(VariableDeclaration &);
- virtual void visit(Iteration &);
};
} // namespace SL