]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/syntax.cpp
Explicitly call base class copy constructor for expressions
[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(GENERATED_SOURCE),
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         Expression(other),
111         name(other.name),
112         declaration(0)
113 { }
114
115 void VariableReference::visit(NodeVisitor &visitor)
116 {
117         visitor.visit(*this);
118 }
119
120
121 InterfaceBlockReference::InterfaceBlockReference():
122         declaration(0)
123 { }
124
125 InterfaceBlockReference::InterfaceBlockReference(const InterfaceBlockReference &other):
126         Expression(other),
127         name(other.name),
128         declaration(0)
129 { }
130
131 void InterfaceBlockReference::visit(NodeVisitor &visitor)
132 {
133         visitor.visit(*this);
134 }
135
136
137 MemberAccess::MemberAccess():
138         declaration(0)
139 { }
140
141 MemberAccess::MemberAccess(const MemberAccess &other):
142         Expression(other),
143         left(other.left),
144         member(other.member),
145         declaration(0)
146 { }
147
148 void MemberAccess::visit(NodeVisitor &visitor)
149 {
150         visitor.visit(*this);
151 }
152
153
154 UnaryExpression::UnaryExpression():
155         prefix(true)
156 { }
157
158 void UnaryExpression::visit(NodeVisitor &visitor)
159 {
160         visitor.visit(*this);
161 }
162
163
164 void BinaryExpression::visit(NodeVisitor &visitor)
165 {
166         visitor.visit(*this);
167 }
168
169
170 Assignment::Assignment():
171         self_referencing(false),
172         target_declaration(0)
173 { }
174
175 Assignment::Assignment(const Assignment &other):
176         BinaryExpression(other),
177         self_referencing(other.self_referencing),
178         target_declaration(0)
179 { }
180
181 void Assignment::visit(NodeVisitor &visitor)
182 {
183         visitor.visit(*this);
184 }
185
186
187 FunctionCall::FunctionCall():
188         constructor(false),
189         declaration(0)
190 { }
191
192 FunctionCall::FunctionCall(const FunctionCall &other):
193         Expression(other),
194         name(other.name),
195         constructor(other.constructor),
196         arguments(other.arguments),
197         declaration(0)
198 { }
199
200 void FunctionCall::visit(NodeVisitor &visitor)
201 {
202         visitor.visit(*this);
203 }
204
205
206 void ExpressionStatement::visit(NodeVisitor &visitor)
207 {
208         visitor.visit(*this);
209 }
210
211
212 void Import::visit(NodeVisitor &visitor)
213 {
214         visitor.visit(*this);
215 }
216
217
218 void Precision::visit(NodeVisitor &visitor)
219 {
220         visitor.visit(*this);
221 }
222
223
224 void Layout::visit(NodeVisitor &visitor)
225 {
226         visitor.visit(*this);
227 }
228
229
230 void InterfaceLayout::visit(NodeVisitor &visitor)
231 {
232         visitor.visit(*this);
233 }
234
235
236 StructDeclaration::StructDeclaration()
237 {
238         members.use_braces = true;
239 }
240
241 void StructDeclaration::visit(NodeVisitor &visitor)
242 {
243         visitor.visit(*this);
244 }
245
246
247 VariableDeclaration::VariableDeclaration():
248         constant(false),
249         array(false),
250         type_declaration(0),
251         linked_declaration(0)
252 { }
253
254 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
255         Statement(other),
256         layout(other.layout),
257         constant(other.constant),
258         sampling(other.sampling),
259         interpolation(other.interpolation),
260         interface(other.interface),
261         precision(other.precision),
262         type(other.type),
263         name(other.name),
264         array(other.array),
265         array_size(other.array_size),
266         init_expression(other.init_expression),
267         type_declaration(0),
268         linked_declaration(0)
269 { }
270
271 VariableDeclaration::~VariableDeclaration()
272 {
273         if(linked_declaration && linked_declaration->linked_declaration==this)
274                 linked_declaration->linked_declaration = 0;
275 }
276
277 void VariableDeclaration::visit(NodeVisitor &visitor)
278 {
279         visitor.visit(*this);
280 }
281
282
283 InterfaceBlock::InterfaceBlock():
284         array(false),
285         linked_block(0)
286 {
287         members.use_braces = true;
288 }
289
290 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
291         Statement(other),
292         interface(other.interface),
293         name(other.name),
294         members(other.members),
295         instance_name(other.instance_name),
296         array(other.array),
297         linked_block(0)
298 { }
299
300 InterfaceBlock::~InterfaceBlock()
301 {
302         if(linked_block && linked_block->linked_block==this)
303                 linked_block->linked_block = 0;
304 }
305
306 void InterfaceBlock::visit(NodeVisitor &visitor)
307 {
308         visitor.visit(*this);
309 }
310
311
312 FunctionDeclaration::FunctionDeclaration():
313         definition(0)
314 { }
315
316 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
317         Statement(other),
318         return_type(other.return_type),
319         name(other.name),
320         parameters(other.parameters),
321         body(other.body),
322         definition(other.definition==&other ? this : 0)
323 { }
324
325 void FunctionDeclaration::visit(NodeVisitor &visitor)
326 {
327         visitor.visit(*this);
328 }
329
330
331 void Conditional::visit(NodeVisitor &visitor)
332 {
333         visitor.visit(*this);
334 }
335
336
337 void Iteration::visit(NodeVisitor &visitor)
338 {
339         visitor.visit(*this);
340 }
341
342
343 void Passthrough::visit(NodeVisitor &visitor)
344 {
345         visitor.visit(*this);
346 }
347
348
349 void Return::visit(NodeVisitor &visitor)
350 {
351         visitor.visit(*this);
352 }
353
354
355 void Jump::visit(NodeVisitor &visitor)
356 {
357         visitor.visit(*this);
358 }
359
360
361 Stage::Stage(Stage::Type t):
362         type(t),
363         previous(0)
364 { }
365
366 const char *Stage::get_stage_name(Type type)
367 {
368         static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
369         return names[type];
370 }
371
372
373 Module::Module():
374         shared(Stage::SHARED)
375 { }
376
377 } // namespace SL
378 } // namespace GL
379 } // namespace Msp