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(MemberAccess &) { }
24 virtual void visit(Swizzle &) { }
25 virtual void visit(UnaryExpression &) { }
26 virtual void visit(BinaryExpression &) { }
27 virtual void visit(Assignment &) { }
28 virtual void visit(TernaryExpression &) { }
29 virtual void visit(FunctionCall &) { }
30 virtual void visit(ExpressionStatement &) { }
31 virtual void visit(Import &) { }
32 virtual void visit(Precision &) { }
33 virtual void visit(Layout &) { }
34 virtual void visit(InterfaceLayout &) { }
35 virtual void visit(BasicTypeDeclaration &) { }
36 virtual void visit(ImageTypeDeclaration &) { }
37 virtual void visit(StructDeclaration &) { }
38 virtual void visit(VariableDeclaration &) { }
39 virtual void visit(FunctionDeclaration &) { }
40 virtual void visit(Conditional &) { }
41 virtual void visit(Iteration &) { }
42 virtual void visit(Passthrough &) { }
43 virtual void visit(Return &) { }
44 virtual void visit(Jump &) { }
47 /** An intermediate base visitor class which traverses the syntax tree. */
48 class TraversingVisitor: public NodeVisitor
51 Block *current_block = 0;
53 TraversingVisitor() = default;
56 virtual void enter(Block &) { }
57 virtual void visit(Block &);
58 virtual void visit(RefPtr<Expression> &);
59 virtual void visit(MemberAccess &);
60 virtual void visit(Swizzle &);
61 virtual void visit(UnaryExpression &);
62 virtual void visit(BinaryExpression &);
63 virtual void visit(Assignment &);
64 virtual void visit(TernaryExpression &);
65 virtual void visit(FunctionCall &);
66 virtual void visit(ExpressionStatement &);
67 virtual void visit(InterfaceLayout &);
68 virtual void visit(StructDeclaration &);
69 virtual void visit(VariableDeclaration &);
70 virtual void visit(FunctionDeclaration &);
71 virtual void visit(Conditional &);
72 virtual void visit(Iteration &);
73 virtual void visit(Passthrough &);
74 virtual void visit(Return &);
77 /** Removes a set of nodes from the syntax tree. */
78 class NodeRemover: private TraversingVisitor
82 const std::set<Node *> *to_remove = 0;
85 void apply(Stage &, const std::set<Node *> &);
89 void remove_from_map(std::map<std::string, T *> &, const std::string &, T &);
91 virtual void visit(Block &);
92 void visit(TypeDeclaration &);
93 virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
94 virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
95 virtual void visit(StructDeclaration &);
96 virtual void visit(VariableDeclaration &);
97 virtual void visit(FunctionDeclaration &);
98 virtual void visit(Iteration &);
101 /** Reorders a set of nodes so they appear before another node. Only nodes
102 on the same hierarchly level as the target node are reordered. */
103 class NodeReorderer: private TraversingVisitor
106 Node *reorder_before = 0;
107 const std::set<Node *> *to_reorder = 0;
110 void apply(Stage &, Node &, const std::set<Node *> &);
113 virtual void visit(Block &);