]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/generate.h
Ignore function parameters in InterfaceGenerator
[libs/gl.git] / source / glsl / generate.h
1 #ifndef MSP_GL_SL_GENERATE_H_
2 #define MSP_GL_SL_GENERATE_H_
3
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <vector>
8 #include "visitor.h"
9
10 namespace Msp {
11 namespace GL {
12 namespace SL {
13
14 class DeclarationCombiner: private TraversingVisitor
15 {
16 private:
17         std::map<std::string, std::vector<FunctionDeclaration *> > functions;
18         std::map<std::string, VariableDeclaration *> variables;
19         std::set<Node *> nodes_to_remove;
20
21 public:
22         void apply(Stage &);
23
24 private:
25         virtual void visit(Block &);
26         virtual void visit(FunctionDeclaration &);
27         virtual void visit(VariableDeclaration &);
28 };
29
30 class BlockResolver: private TraversingVisitor
31 {
32 public:
33         void apply(Stage &s) { s.content.visit(*this); }
34
35 private:
36         virtual void enter(Block &);
37         virtual void visit(InterfaceBlock &);
38 };
39
40 class VariableResolver: private TraversingVisitor
41 {
42 private:
43         Block *builtins;
44         StructDeclaration *type;
45         std::string block_interface;
46         bool record_target;
47         VariableDeclaration *assignment_target;
48         bool self_referencing;
49
50 public:
51         VariableResolver();
52
53         void apply(Stage &);
54
55 private:
56         Block *next_block(Block &);
57
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 &);
66 };
67
68 class FunctionResolver: private TraversingVisitor
69 {
70 private:
71         std::map<std::string, std::vector<FunctionDeclaration *> > functions;
72
73 public:
74         void apply(Stage &s) { s.content.visit(*this); }
75
76 private:
77         virtual void visit(FunctionCall &);
78         virtual void visit(FunctionDeclaration &);
79 };
80
81 class InterfaceGenerator: private TraversingVisitor
82 {
83 private:
84         Stage *stage;
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;
90
91 public:
92         InterfaceGenerator();
93
94         void apply(Stage &);
95
96 private:
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 &);
106 };
107
108 class DeclarationReorderer: private TraversingVisitor
109 {
110 private:
111         enum DeclarationKind
112         {
113                 NO_DECLARATION,
114                 LAYOUT,
115                 STRUCT,
116                 VARIABLE,
117                 FUNCTION
118         };
119
120         DeclarationKind kind;
121         std::set<Node *> ordered_funcs;
122         std::set<Node *> needed_funcs;
123
124 public:
125         DeclarationReorderer();
126
127         void apply(Stage &s) { s.content.visit(*this); }
128
129 private:
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 &);
137 };
138
139 } // namespace SL
140 } // namespace GL
141 } // namespace Msp
142
143 #endif