]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/syntax.cpp
Refactor interface management
[libs/gl.git] / source / glsl / syntax.cpp
1 #include "syntax.h"
2 #include "visitor.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8 namespace SL {
9
10 const Operator Operator::operators[] =
11 {
12         { "[", 2, BINARY, LEFT_TO_RIGHT },
13         { "(", 2, BINARY, LEFT_TO_RIGHT },
14         { ".", 2, BINARY, LEFT_TO_RIGHT },
15         { "++", 2, POSTFIX, LEFT_TO_RIGHT },
16         { "--", 2, POSTFIX, LEFT_TO_RIGHT },
17         { "++", 3, PREFIX, RIGHT_TO_LEFT },
18         { "--", 3, PREFIX, RIGHT_TO_LEFT },
19         { "+", 3, PREFIX, RIGHT_TO_LEFT },
20         { "-", 3, PREFIX, RIGHT_TO_LEFT },
21         { "~", 3, PREFIX, RIGHT_TO_LEFT },
22         { "!", 3, PREFIX, RIGHT_TO_LEFT },
23         { "*", 4, BINARY, LEFT_TO_RIGHT },
24         { "/", 4, BINARY, LEFT_TO_RIGHT },
25         { "%", 4, BINARY, LEFT_TO_RIGHT },
26         { "+", 5, BINARY, LEFT_TO_RIGHT },
27         { "-", 5, BINARY, LEFT_TO_RIGHT },
28         { "<<", 6, BINARY, LEFT_TO_RIGHT },
29         { ">>", 6, BINARY, LEFT_TO_RIGHT },
30         { "<", 7, BINARY, LEFT_TO_RIGHT },
31         { ">", 7, BINARY, LEFT_TO_RIGHT },
32         { "<=", 7, BINARY, LEFT_TO_RIGHT },
33         { ">=", 7, BINARY, LEFT_TO_RIGHT },
34         { "==", 8, BINARY, LEFT_TO_RIGHT },
35         { "!=", 8, BINARY, LEFT_TO_RIGHT },
36         { "&", 9, BINARY, LEFT_TO_RIGHT },
37         { "^", 10, BINARY, LEFT_TO_RIGHT },
38         { "|", 11, BINARY, LEFT_TO_RIGHT },
39         { "&&", 12, BINARY, LEFT_TO_RIGHT },
40         { "^^", 13, BINARY, LEFT_TO_RIGHT },
41         { "||", 14, BINARY, LEFT_TO_RIGHT },
42         { "?", 15, BINARY, RIGHT_TO_LEFT },
43         { ":", 15, BINARY, RIGHT_TO_LEFT },
44         { "=", 16, BINARY, RIGHT_TO_LEFT },
45         { "+=", 16, BINARY, RIGHT_TO_LEFT },
46         { "-=", 16, BINARY, RIGHT_TO_LEFT },
47         { "*=", 16, BINARY, RIGHT_TO_LEFT },
48         { "/=", 16, BINARY, RIGHT_TO_LEFT },
49         { "%=", 16, BINARY, RIGHT_TO_LEFT },
50         { "<<=", 16, BINARY, RIGHT_TO_LEFT },
51         { ">>=", 16, BINARY, RIGHT_TO_LEFT },
52         { "&=", 16, BINARY, RIGHT_TO_LEFT },
53         { "^=", 16, BINARY, RIGHT_TO_LEFT },
54         { "|=", 16, BINARY, RIGHT_TO_LEFT },
55         { ",", 17, BINARY, LEFT_TO_RIGHT },
56         { { 0 }, 18, NO_OPERATOR, LEFT_TO_RIGHT }
57 };
58
59
60 template<typename C>
61 NodeContainer<C>::NodeContainer(const NodeContainer &c):
62         C(c)
63 {
64         for(typename C::iterator i=this->begin(); i!=this->end(); ++i)
65                 *i = (*i)->clone();
66 }
67
68
69 Statement::Statement():
70         source(0),
71         line(1)
72 { }
73
74
75 Block::Block():
76         use_braces(false),
77         parent(0)
78 { }
79
80 Block::Block(const Block &other):
81         Node(other),
82         body(other.body),
83         use_braces(other.use_braces),
84         parent(0)
85 { }
86
87 void Block::visit(NodeVisitor &visitor)
88 {
89         visitor.visit(*this);
90 }
91
92
93 void Literal::visit(NodeVisitor &visitor)
94 {
95         visitor.visit(*this);
96 }
97
98
99 void ParenthesizedExpression::visit(NodeVisitor &visitor)
100 {
101         visitor.visit(*this);
102 }
103
104
105 VariableReference::VariableReference():
106         declaration(0)
107 { }
108
109 VariableReference::VariableReference(const VariableReference &other):
110         name(other.name),
111         declaration(0)
112 { }
113
114 void VariableReference::visit(NodeVisitor &visitor)
115 {
116         visitor.visit(*this);
117 }
118
119
120 MemberAccess::MemberAccess():
121         declaration(0)
122 { }
123
124 MemberAccess::MemberAccess(const MemberAccess &other):
125         left(other.left),
126         member(other.member),
127         declaration(0)
128 { }
129
130 void MemberAccess::visit(NodeVisitor &visitor)
131 {
132         visitor.visit(*this);
133 }
134
135
136 UnaryExpression::UnaryExpression():
137         prefix(true)
138 { }
139
140 void UnaryExpression::visit(NodeVisitor &visitor)
141 {
142         visitor.visit(*this);
143 }
144
145
146 void BinaryExpression::visit(NodeVisitor &visitor)
147 {
148         visitor.visit(*this);
149 }
150
151
152 Assignment::Assignment():
153         self_referencing(false),
154         target_declaration(0)
155 { }
156
157 Assignment::Assignment(const Assignment &other):
158         self_referencing(other.self_referencing),
159         target_declaration(0)
160 { }
161
162 void Assignment::visit(NodeVisitor &visitor)
163 {
164         visitor.visit(*this);
165 }
166
167
168 FunctionCall::FunctionCall():
169         declaration(0),
170         constructor(false)
171 { }
172
173 FunctionCall::FunctionCall(const FunctionCall &other):
174         name(other.name),
175         declaration(0),
176         constructor(other.constructor),
177         arguments(other.arguments)
178 { }
179
180 void FunctionCall::visit(NodeVisitor &visitor)
181 {
182         visitor.visit(*this);
183 }
184
185
186 void ExpressionStatement::visit(NodeVisitor &visitor)
187 {
188         visitor.visit(*this);
189 }
190
191
192 void Import::visit(NodeVisitor &visitor)
193 {
194         visitor.visit(*this);
195 }
196
197
198 void Precision::visit(NodeVisitor &visitor)
199 {
200         visitor.visit(*this);
201 }
202
203
204 void Layout::visit(NodeVisitor &visitor)
205 {
206         visitor.visit(*this);
207 }
208
209
210 void InterfaceLayout::visit(NodeVisitor &visitor)
211 {
212         visitor.visit(*this);
213 }
214
215
216 StructDeclaration::StructDeclaration()
217 {
218         members.use_braces = true;
219 }
220
221 void StructDeclaration::visit(NodeVisitor &visitor)
222 {
223         visitor.visit(*this);
224 }
225
226
227 VariableDeclaration::VariableDeclaration():
228         constant(false),
229         type_declaration(0),
230         array(false),
231         linked_declaration(0)
232 { }
233
234 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
235         constant(other.constant),
236         sampling(other.sampling),
237         interpolation(other.interpolation),
238         interface(other.interface),
239         precision(other.precision),
240         type(other.type),
241         type_declaration(0),
242         name(other.name),
243         array(other.array),
244         array_size(other.array_size),
245         init_expression(other.init_expression),
246         linked_declaration(0),
247         layout(other.layout)
248 { }
249
250 void VariableDeclaration::visit(NodeVisitor &visitor)
251 {
252         visitor.visit(*this);
253 }
254
255
256 InterfaceBlock::InterfaceBlock():
257         array(false)
258 {
259         members.use_braces = true;
260 }
261
262 void InterfaceBlock::visit(NodeVisitor &visitor)
263 {
264         visitor.visit(*this);
265 }
266
267
268 FunctionDeclaration::FunctionDeclaration():
269         definition(0)
270 { }
271
272 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
273         return_type(other.return_type),
274         name(other.name),
275         parameters(other.parameters),
276         definition(other.definition==&other ? this : 0),
277         body(other.body)
278 { }
279
280 void FunctionDeclaration::visit(NodeVisitor &visitor)
281 {
282         visitor.visit(*this);
283 }
284
285
286 void Conditional::visit(NodeVisitor &visitor)
287 {
288         visitor.visit(*this);
289 }
290
291
292 void Iteration::visit(NodeVisitor &visitor)
293 {
294         visitor.visit(*this);
295 }
296
297
298 void Passthrough::visit(NodeVisitor &visitor)
299 {
300         visitor.visit(*this);
301 }
302
303
304 void Return::visit(NodeVisitor &visitor)
305 {
306         visitor.visit(*this);
307 }
308
309
310 void Jump::visit(NodeVisitor &visitor)
311 {
312         visitor.visit(*this);
313 }
314
315
316 Stage::Stage(Stage::Type t):
317         type(t),
318         previous(0)
319 { }
320
321 const char *Stage::get_stage_name(Type type)
322 {
323         static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
324         return names[type];
325 }
326
327
328 Module::Module():
329         shared(Stage::SHARED)
330 { }
331
332 } // namespace SL
333 } // namespace GL
334 } // namespace Msp