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 &);
39 class VariableResolver: private TraversingVisitor
44 std::map<std::string, VariableDeclaration *> *members;
45 RefPtr<InterfaceBlockReference> iface_ref;
46 std::string block_interface;
48 VariableDeclaration *assignment_target;
49 bool self_referencing;
57 Block *next_block(Block &);
59 virtual void enter(Block &);
60 virtual void visit(VariableReference &);
61 virtual void visit(InterfaceBlockReference &);
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 &);
70 class FunctionResolver: private TraversingVisitor
73 std::map<std::string, std::vector<FunctionDeclaration *> > functions;
76 void apply(Stage &s) { s.content.visit(*this); }
79 virtual void visit(FunctionCall &);
80 virtual void visit(FunctionDeclaration &);
83 class InterfaceGenerator: private TraversingVisitor
87 std::string in_prefix;
88 std::string out_prefix;
90 InterfaceBlock *iface_block;
92 Block *iface_target_block;
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 bool generate_interface(InterfaceBlock &);
108 ExpressionStatement &insert_assignment(const std::string &, Expression *);
109 virtual void visit(VariableReference &);
110 virtual void visit(VariableDeclaration &);
111 virtual void visit(InterfaceBlock &);
112 virtual void visit(FunctionDeclaration &);
113 virtual void visit(Passthrough &);
116 class DeclarationReorderer: private TraversingVisitor
128 DeclarationKind kind;
129 std::set<Node *> ordered_funcs;
130 std::set<Node *> needed_funcs;
133 DeclarationReorderer();
135 void apply(Stage &s) { s.content.visit(*this); }
138 virtual void visit(Block &);
139 virtual void visit(FunctionCall &);
140 virtual void visit(InterfaceLayout &) { kind = LAYOUT; }
141 virtual void visit(StructDeclaration &) { kind = STRUCT; }
142 virtual void visit(VariableDeclaration &);
143 virtual void visit(InterfaceBlock &) { kind = VARIABLE; }
144 virtual void visit(FunctionDeclaration &);