]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/syntax.cpp
Avoid copying raw pointers in the syntax tree
[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 { }
78
79 void Block::visit(NodeVisitor &visitor)
80 {
81         visitor.visit(*this);
82 }
83
84
85 void Literal::visit(NodeVisitor &visitor)
86 {
87         visitor.visit(*this);
88 }
89
90
91 void ParenthesizedExpression::visit(NodeVisitor &visitor)
92 {
93         visitor.visit(*this);
94 }
95
96
97 VariableReference::VariableReference():
98         declaration(0)
99 { }
100
101 VariableReference::VariableReference(const VariableReference &other):
102         name(other.name),
103         declaration(0)
104 { }
105
106 void VariableReference::visit(NodeVisitor &visitor)
107 {
108         visitor.visit(*this);
109 }
110
111
112 MemberAccess::MemberAccess():
113         declaration(0)
114 { }
115
116 MemberAccess::MemberAccess(const MemberAccess &other):
117         left(other.left),
118         member(other.member),
119         declaration(0)
120 { }
121
122 void MemberAccess::visit(NodeVisitor &visitor)
123 {
124         visitor.visit(*this);
125 }
126
127
128 UnaryExpression::UnaryExpression():
129         prefix(true)
130 { }
131
132 void UnaryExpression::visit(NodeVisitor &visitor)
133 {
134         visitor.visit(*this);
135 }
136
137
138 void BinaryExpression::visit(NodeVisitor &visitor)
139 {
140         visitor.visit(*this);
141 }
142
143
144 Assignment::Assignment():
145         self_referencing(false),
146         target_declaration(0)
147 { }
148
149 Assignment::Assignment(const Assignment &other):
150         self_referencing(other.self_referencing),
151         target_declaration(0)
152 { }
153
154 void Assignment::visit(NodeVisitor &visitor)
155 {
156         visitor.visit(*this);
157 }
158
159
160 FunctionCall::FunctionCall():
161         declaration(0),
162         constructor(false)
163 { }
164
165 FunctionCall::FunctionCall(const FunctionCall &other):
166         name(other.name),
167         declaration(0),
168         constructor(other.constructor),
169         arguments(other.arguments)
170 { }
171
172 void FunctionCall::visit(NodeVisitor &visitor)
173 {
174         visitor.visit(*this);
175 }
176
177
178 void ExpressionStatement::visit(NodeVisitor &visitor)
179 {
180         visitor.visit(*this);
181 }
182
183
184 void Import::visit(NodeVisitor &visitor)
185 {
186         visitor.visit(*this);
187 }
188
189
190 void Precision::visit(NodeVisitor &visitor)
191 {
192         visitor.visit(*this);
193 }
194
195
196 void Layout::visit(NodeVisitor &visitor)
197 {
198         visitor.visit(*this);
199 }
200
201
202 void InterfaceLayout::visit(NodeVisitor &visitor)
203 {
204         visitor.visit(*this);
205 }
206
207
208 StructDeclaration::StructDeclaration()
209 {
210         members.use_braces = true;
211 }
212
213 void StructDeclaration::visit(NodeVisitor &visitor)
214 {
215         visitor.visit(*this);
216 }
217
218
219 VariableDeclaration::VariableDeclaration():
220         constant(false),
221         type_declaration(0),
222         array(false),
223         linked_declaration(0)
224 { }
225
226 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
227         constant(other.constant),
228         sampling(other.sampling),
229         interpolation(other.interpolation),
230         interface(other.interface),
231         precision(other.precision),
232         type(other.type),
233         type_declaration(0),
234         name(other.name),
235         array(other.array),
236         array_size(other.array_size),
237         init_expression(other.init_expression),
238         linked_declaration(0),
239         layout(other.layout)
240 { }
241
242 void VariableDeclaration::visit(NodeVisitor &visitor)
243 {
244         visitor.visit(*this);
245 }
246
247
248 InterfaceBlock::InterfaceBlock():
249         array(false)
250 {
251         members.use_braces = true;
252 }
253
254 void InterfaceBlock::visit(NodeVisitor &visitor)
255 {
256         visitor.visit(*this);
257 }
258
259
260 FunctionDeclaration::FunctionDeclaration():
261         definition(0)
262 { }
263
264 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
265         return_type(other.return_type),
266         name(other.name),
267         parameters(other.parameters),
268         definition(other.definition==&other ? this : 0),
269         body(other.body)
270 { }
271
272 void FunctionDeclaration::visit(NodeVisitor &visitor)
273 {
274         visitor.visit(*this);
275 }
276
277
278 void Conditional::visit(NodeVisitor &visitor)
279 {
280         visitor.visit(*this);
281 }
282
283
284 void Iteration::visit(NodeVisitor &visitor)
285 {
286         visitor.visit(*this);
287 }
288
289
290 void Passthrough::visit(NodeVisitor &visitor)
291 {
292         visitor.visit(*this);
293 }
294
295
296 void Return::visit(NodeVisitor &visitor)
297 {
298         visitor.visit(*this);
299 }
300
301
302 void Jump::visit(NodeVisitor &visitor)
303 {
304         visitor.visit(*this);
305 }
306
307
308 Stage::Stage(Stage::Type t):
309         type(t),
310         previous(0)
311 { }
312
313 const char *Stage::get_stage_name(Type type)
314 {
315         static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
316         return names[type];
317 }
318
319
320 Module::Module():
321         shared(Stage::SHARED)
322 { }
323
324 } // namespace SL
325 } // namespace GL
326 } // namespace Msp