1 #ifndef MSP_GL_SL_VISITOR_H_
2 #define MSP_GL_SL_VISITOR_H_
12 /** Base class for all node visitors. */
18 virtual ~NodeVisitor() { }
20 virtual void visit(Block &) { }
21 virtual void visit(Literal &) { }
22 virtual void visit(VariableReference &) { }
23 virtual void visit(InterfaceBlockReference &) { }
24 virtual void visit(MemberAccess &) { }
25 virtual void visit(Swizzle &) { }
26 virtual void visit(UnaryExpression &) { }
27 virtual void visit(BinaryExpression &) { }
28 virtual void visit(Assignment &) { }
29 virtual void visit(TernaryExpression &) { }
30 virtual void visit(FunctionCall &) { }
31 virtual void visit(ExpressionStatement &) { }
32 virtual void visit(Import &) { }
33 virtual void visit(Precision &) { }
34 virtual void visit(Layout &) { }
35 virtual void visit(InterfaceLayout &) { }
36 virtual void visit(BasicTypeDeclaration &) { }
37 virtual void visit(ImageTypeDeclaration &) { }
38 virtual void visit(StructDeclaration &) { }
39 virtual void visit(VariableDeclaration &) { }
40 virtual void visit(InterfaceBlock &) { }
41 virtual void visit(FunctionDeclaration &) { }
42 virtual void visit(Conditional &) { }
43 virtual void visit(Iteration &) { }
44 virtual void visit(Passthrough &) { }
45 virtual void visit(Return &) { }
46 virtual void visit(Jump &) { }
49 /** An intermediate base visitor class which traverses the syntax tree. */
50 class TraversingVisitor: public NodeVisitor
55 TraversingVisitor(): current_block(0) { }
58 virtual void enter(Block &) { }
59 virtual void visit(Block &);
60 virtual void visit(RefPtr<Expression> &);
61 virtual void visit(MemberAccess &);
62 virtual void visit(Swizzle &);
63 virtual void visit(UnaryExpression &);
64 virtual void visit(BinaryExpression &);
65 virtual void visit(Assignment &);
66 virtual void visit(TernaryExpression &);
67 virtual void visit(FunctionCall &);
68 virtual void visit(ExpressionStatement &);
69 virtual void visit(InterfaceLayout &);
70 virtual void visit(StructDeclaration &);
71 virtual void visit(VariableDeclaration &);
72 virtual void visit(InterfaceBlock &);
73 virtual void visit(FunctionDeclaration &);
74 virtual void visit(Conditional &);
75 virtual void visit(Iteration &);
76 virtual void visit(Passthrough &);
77 virtual void visit(Return &);
80 /** Removes a set of nodes from the syntax tree. */
81 class NodeRemover: private TraversingVisitor
85 const std::set<Node *> *to_remove;
86 bool recursive_remove;
91 void apply(Stage &, const std::set<Node *> &);
95 void remove_from_map(std::map<std::string, T *> &, const std::string &, T &);
97 virtual void visit(Block &);
98 void visit(TypeDeclaration &);
99 virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
100 virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
101 virtual void visit(StructDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
102 virtual void visit(VariableDeclaration &);
103 virtual void visit(InterfaceBlock &);
104 virtual void visit(FunctionDeclaration &);
105 virtual void visit(Iteration &);
108 /** Reorders a set of nodes so they appear before another node. Only nodes
109 on the same hierarchly level as the target node are reordered. */
110 class NodeReorderer: private TraversingVisitor
113 Node *reorder_before;
114 const std::set<Node *> *to_reorder;
119 void apply(Stage &, Node &, const std::set<Node *> &);
122 virtual void visit(Block &);