1 #ifndef MSP_GL_SL_GENERATE_H_
2 #define MSP_GL_SL_GENERATE_H_
14 class DeclarationCombiner: private TraversingVisitor
17 std::map<std::string, std::vector<FunctionDeclaration *> > functions;
18 std::map<std::string, VariableDeclaration *> variables;
19 std::set<Node *> nodes_to_remove;
25 virtual void visit(Block &);
26 virtual void visit(FunctionDeclaration &);
27 virtual void visit(VariableDeclaration &);
28 using TraversingVisitor::visit;
31 class BlockResolver: private TraversingVisitor
34 void apply(Stage &s) { visit(s.content); }
37 virtual void visit(Block &);
38 virtual void visit(InterfaceBlock &);
39 using TraversingVisitor::visit;
42 class VariableResolver: private TraversingVisitor
46 StructDeclaration *type;
47 std::string block_interface;
49 VariableDeclaration *assignment_target;
50 bool self_referencing;
58 Block *next_block(Block &);
60 virtual void visit(Block &);
61 virtual void visit(VariableReference &);
62 virtual void visit(MemberAccess &);
63 virtual void visit(BinaryExpression &);
64 virtual void visit(Assignment &);
65 virtual void visit(StructDeclaration &);
66 virtual void visit(VariableDeclaration &);
67 virtual void visit(InterfaceBlock &);
68 virtual void visit(FunctionDeclaration &);
69 virtual void visit(Iteration &);
70 using TraversingVisitor::visit;
73 class FunctionResolver: private TraversingVisitor
76 std::map<std::string, std::vector<FunctionDeclaration *> > functions;
79 void apply(Stage &s) { visit(s.content); }
82 virtual void visit(FunctionCall &);
83 virtual void visit(FunctionDeclaration &);
84 using TraversingVisitor::visit;
87 class InterfaceGenerator: private TraversingVisitor
91 std::string in_prefix;
92 std::string out_prefix;
93 NodeList<Statement>::iterator iface_insert_point;
94 NodeList<Statement>::iterator assignment_insert_point;
95 std::set<Node *> nodes_to_remove;
103 static std::string get_out_prefix(Stage::Type);
104 std::string change_prefix(const std::string &, const std::string &) const;
105 virtual void visit(Block &);
106 bool generate_interface(VariableDeclaration &, const std::string &, const std::string &);
107 ExpressionStatement &insert_assignment(const std::string &, Expression *);
108 virtual void visit(VariableReference &);
109 virtual void visit(VariableDeclaration &);
110 virtual void visit(Passthrough &);
111 using TraversingVisitor::visit;
114 class DeclarationReorderer: private TraversingVisitor
126 DeclarationKind kind;
127 std::set<Node *> ordered_funcs;
128 std::set<Node *> needed_funcs;
131 DeclarationReorderer();
133 void apply(Stage &s) { visit(s.content); }
136 virtual void visit(Block &);
137 virtual void visit(FunctionCall &);
138 virtual void visit(InterfaceLayout &) { kind = LAYOUT; }
139 virtual void visit(StructDeclaration &) { kind = STRUCT; }
140 virtual void visit(VariableDeclaration &);
141 virtual void visit(InterfaceBlock &) { kind = VARIABLE; }
142 virtual void visit(FunctionDeclaration &);
143 using TraversingVisitor::visit;