]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/syntax.cpp
Track source names in SL::Module
[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 void VariableReference::visit(NodeVisitor &visitor)
102 {
103         visitor.visit(*this);
104 }
105
106
107 void MemberAccess::visit(NodeVisitor &visitor)
108 {
109         visitor.visit(*this);
110 }
111
112
113 UnaryExpression::UnaryExpression():
114         prefix(true)
115 { }
116
117 void UnaryExpression::visit(NodeVisitor &visitor)
118 {
119         visitor.visit(*this);
120 }
121
122
123 void BinaryExpression::visit(NodeVisitor &visitor)
124 {
125         visitor.visit(*this);
126 }
127
128
129 Assignment::Assignment():
130         self_referencing(false),
131         target_declaration(0)
132 { }
133
134 void Assignment::visit(NodeVisitor &visitor)
135 {
136         visitor.visit(*this);
137 }
138
139
140 FunctionCall::FunctionCall():
141         declaration(0),
142         constructor(false)
143 { }
144
145 void FunctionCall::visit(NodeVisitor &visitor)
146 {
147         visitor.visit(*this);
148 }
149
150
151 void ExpressionStatement::visit(NodeVisitor &visitor)
152 {
153         visitor.visit(*this);
154 }
155
156
157 void Import::visit(NodeVisitor &visitor)
158 {
159         visitor.visit(*this);
160 }
161
162
163 void Precision::visit(NodeVisitor &visitor)
164 {
165         visitor.visit(*this);
166 }
167
168
169 void Layout::visit(NodeVisitor &visitor)
170 {
171         visitor.visit(*this);
172 }
173
174
175 void InterfaceLayout::visit(NodeVisitor &visitor)
176 {
177         visitor.visit(*this);
178 }
179
180
181 StructDeclaration::StructDeclaration()
182 {
183         members.use_braces = true;
184 }
185
186 void StructDeclaration::visit(NodeVisitor &visitor)
187 {
188         visitor.visit(*this);
189 }
190
191
192 VariableDeclaration::VariableDeclaration():
193         constant(false),
194         type_declaration(0),
195         array(false),
196         linked_declaration(0)
197 { }
198
199 void VariableDeclaration::visit(NodeVisitor &visitor)
200 {
201         visitor.visit(*this);
202 }
203
204
205 InterfaceBlock::InterfaceBlock():
206         array(false)
207 {
208         members.use_braces = true;
209 }
210
211 void InterfaceBlock::visit(NodeVisitor &visitor)
212 {
213         visitor.visit(*this);
214 }
215
216
217 FunctionDeclaration::FunctionDeclaration():
218         definition(0)
219 { }
220
221 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
222         return_type(other.return_type),
223         name(other.name),
224         parameters(other.parameters),
225         definition(other.definition==&other ? this : other.definition),
226         body(other.body)
227 { }
228
229 void FunctionDeclaration::visit(NodeVisitor &visitor)
230 {
231         visitor.visit(*this);
232 }
233
234
235 void Conditional::visit(NodeVisitor &visitor)
236 {
237         visitor.visit(*this);
238 }
239
240
241 void Iteration::visit(NodeVisitor &visitor)
242 {
243         visitor.visit(*this);
244 }
245
246
247 void Passthrough::visit(NodeVisitor &visitor)
248 {
249         visitor.visit(*this);
250 }
251
252
253 void Return::visit(NodeVisitor &visitor)
254 {
255         visitor.visit(*this);
256 }
257
258
259 void Jump::visit(NodeVisitor &visitor)
260 {
261         visitor.visit(*this);
262 }
263
264
265 Stage::Stage(Stage::Type t):
266         type(t),
267         previous(0)
268 { }
269
270 const char *Stage::get_stage_name(Type type)
271 {
272         static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
273         return names[type];
274 }
275
276
277 Module::Module():
278         shared(Stage::SHARED)
279 { }
280
281 } // namespace SL
282 } // namespace GL
283 } // namespace Msp