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 &);
30 class BlockResolver: private TraversingVisitor
33 void apply(Stage &s) { s.content.visit(*this); }
36 virtual void enter(Block &);
37 virtual void visit(InterfaceBlock &);
40 class VariableResolver: private TraversingVisitor
44 StructDeclaration *type;
45 std::string block_interface;
47 VariableDeclaration *assignment_target;
48 bool self_referencing;
56 Block *next_block(Block &);
58 virtual void enter(Block &);
59 virtual void visit(VariableReference &);
60 virtual void visit(MemberAccess &);
61 virtual void visit(BinaryExpression &);
62 virtual void visit(Assignment &);
63 virtual void visit(StructDeclaration &);
64 virtual void visit(VariableDeclaration &);
65 virtual void visit(InterfaceBlock &);
68 class FunctionResolver: private TraversingVisitor
71 std::map<std::string, std::vector<FunctionDeclaration *> > functions;
74 void apply(Stage &s) { s.content.visit(*this); }
77 virtual void visit(FunctionCall &);
78 virtual void visit(FunctionDeclaration &);
81 class InterfaceGenerator: private TraversingVisitor
85 std::string in_prefix;
86 std::string out_prefix;
87 NodeList<Statement>::iterator iface_insert_point;
88 NodeList<Statement>::iterator assignment_insert_point;
89 std::set<Node *> nodes_to_remove;
97 static std::string get_out_prefix(Stage::Type);
98 std::string change_prefix(const std::string &, const std::string &) const;
99 virtual void visit(Block &);
100 bool generate_interface(VariableDeclaration &, const std::string &, const std::string &);
101 ExpressionStatement &insert_assignment(const std::string &, Expression *);
102 virtual void visit(VariableReference &);
103 virtual void visit(VariableDeclaration &);
104 virtual void visit(FunctionDeclaration &);
105 virtual void visit(Passthrough &);
108 class DeclarationReorderer: private TraversingVisitor
120 DeclarationKind kind;
121 std::set<Node *> ordered_funcs;
122 std::set<Node *> needed_funcs;
125 DeclarationReorderer();
127 void apply(Stage &s) { s.content.visit(*this); }
130 virtual void visit(Block &);
131 virtual void visit(FunctionCall &);
132 virtual void visit(InterfaceLayout &) { kind = LAYOUT; }
133 virtual void visit(StructDeclaration &) { kind = STRUCT; }
134 virtual void visit(VariableDeclaration &);
135 virtual void visit(InterfaceBlock &) { kind = VARIABLE; }
136 virtual void visit(FunctionDeclaration &);