1 #ifndef MSP_GL_SL_VISITOR_H_
2 #define MSP_GL_SL_VISITOR_H_
12 /** Base class for all node visitors. */
16 NodeVisitor() = default;
18 virtual ~NodeVisitor() = default;
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
53 Block *current_block = 0;
55 TraversingVisitor() = default;
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 = 0;
86 bool recursive_remove = false;
89 void apply(Stage &, const std::set<Node *> &);
93 void remove_from_map(std::map<std::string, T *> &, const std::string &, T &);
95 virtual void visit(Block &);
96 void visit(TypeDeclaration &);
97 virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
98 virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
99 virtual void visit(StructDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
100 virtual void visit(VariableDeclaration &);
101 virtual void visit(InterfaceBlock &);
102 virtual void visit(FunctionDeclaration &);
103 virtual void visit(Iteration &);
106 /** Reorders a set of nodes so they appear before another node. Only nodes
107 on the same hierarchly level as the target node are reordered. */
108 class NodeReorderer: private TraversingVisitor
111 Node *reorder_before = 0;
112 const std::set<Node *> *to_reorder = 0;
115 void apply(Stage &, Node &, const std::set<Node *> &);
118 virtual void visit(Block &);