1 #include <msp/core/maputils.h>
11 const Operator Operator::operators[] =
13 { "[", 2, BINARY, LEFT_TO_RIGHT },
14 { "(", 2, POSTFIX, LEFT_TO_RIGHT },
15 { ".", 2, BINARY, LEFT_TO_RIGHT },
16 { "++", 2, POSTFIX, LEFT_TO_RIGHT },
17 { "--", 2, POSTFIX, LEFT_TO_RIGHT },
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 { "!", 3, PREFIX, RIGHT_TO_LEFT },
24 { "*", 4, BINARY, ASSOCIATIVE },
25 { "/", 4, BINARY, LEFT_TO_RIGHT },
26 { "%", 4, BINARY, LEFT_TO_RIGHT },
27 { "+", 5, BINARY, ASSOCIATIVE },
28 { "-", 5, BINARY, LEFT_TO_RIGHT },
29 { "<<", 6, BINARY, LEFT_TO_RIGHT },
30 { ">>", 6, BINARY, LEFT_TO_RIGHT },
31 { "<", 7, BINARY, LEFT_TO_RIGHT },
32 { ">", 7, BINARY, LEFT_TO_RIGHT },
33 { "<=", 7, BINARY, LEFT_TO_RIGHT },
34 { ">=", 7, BINARY, LEFT_TO_RIGHT },
35 { "==", 8, BINARY, LEFT_TO_RIGHT },
36 { "!=", 8, BINARY, LEFT_TO_RIGHT },
37 { "&", 9, BINARY, ASSOCIATIVE },
38 { "^", 10, BINARY, ASSOCIATIVE },
39 { "|", 11, BINARY, ASSOCIATIVE },
40 { "&&", 12, BINARY, ASSOCIATIVE },
41 { "^^", 13, BINARY, ASSOCIATIVE },
42 { "||", 14, BINARY, ASSOCIATIVE },
43 { "?", 15, BINARY, RIGHT_TO_LEFT },
44 { ":", 15, 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 { "|=", 16, BINARY, RIGHT_TO_LEFT },
56 { ",", 17, BINARY, LEFT_TO_RIGHT },
57 { { 0 }, 18, NO_OPERATOR, LEFT_TO_RIGHT }
60 const Operator &Operator::get_operator(const string &token, Type type)
62 for(const Operator *i=operators; i->type; ++i)
63 if(i->type==type && i->token==token)
65 throw key_error(token);
70 NodeContainer<C>::NodeContainer(const NodeContainer &c):
73 for(typename C::iterator i=this->begin(); i!=this->end(); ++i)
83 Block::Block(const Block &other):
86 use_braces(other.use_braces),
90 void Block::visit(NodeVisitor &visitor)
96 Expression::Expression():
103 void Literal::visit(NodeVisitor &visitor)
105 visitor.visit(*this);
109 void ParenthesizedExpression::visit(NodeVisitor &visitor)
111 visitor.visit(*this);
115 VariableReference::VariableReference():
119 VariableReference::VariableReference(const VariableReference &other):
125 void VariableReference::visit(NodeVisitor &visitor)
127 visitor.visit(*this);
131 InterfaceBlockReference::InterfaceBlockReference():
135 InterfaceBlockReference::InterfaceBlockReference(const InterfaceBlockReference &other):
141 void InterfaceBlockReference::visit(NodeVisitor &visitor)
143 visitor.visit(*this);
147 MemberAccess::MemberAccess():
151 MemberAccess::MemberAccess(const MemberAccess &other):
154 member(other.member),
158 void MemberAccess::visit(NodeVisitor &visitor)
160 visitor.visit(*this);
167 fill(components, components+4, 0);
170 void Swizzle::visit(NodeVisitor &visitor)
172 visitor.visit(*this);
176 void UnaryExpression::visit(NodeVisitor &visitor)
178 visitor.visit(*this);
182 void BinaryExpression::visit(NodeVisitor &visitor)
184 visitor.visit(*this);
188 Assignment::Assignment():
189 self_referencing(false)
192 Assignment::Assignment(const Assignment &other):
193 BinaryExpression(other),
194 self_referencing(other.self_referencing)
197 void Assignment::visit(NodeVisitor &visitor)
199 visitor.visit(*this);
203 Assignment::Target::Target(Statement *d):
207 fill(chain, chain+7, 0);
210 bool Assignment::Target::operator<(const Target &other) const
212 if(declaration!=other.declaration)
213 return declaration<other.declaration;
214 for(unsigned i=0; (i<7 && i<chain_len && i<other.chain_len); ++i)
215 if(chain[i]!=other.chain[i])
216 return chain[i]<other.chain[i];
217 return chain_len<other.chain_len;
221 FunctionCall::FunctionCall():
226 FunctionCall::FunctionCall(const FunctionCall &other):
229 constructor(other.constructor),
230 arguments(other.arguments),
234 void FunctionCall::visit(NodeVisitor &visitor)
236 visitor.visit(*this);
240 void ExpressionStatement::visit(NodeVisitor &visitor)
242 visitor.visit(*this);
246 void Import::visit(NodeVisitor &visitor)
248 visitor.visit(*this);
252 void Precision::visit(NodeVisitor &visitor)
254 visitor.visit(*this);
258 void Layout::visit(NodeVisitor &visitor)
260 visitor.visit(*this);
264 void InterfaceLayout::visit(NodeVisitor &visitor)
266 visitor.visit(*this);
270 BasicTypeDeclaration::BasicTypeDeclaration():
276 BasicTypeDeclaration::BasicTypeDeclaration(const BasicTypeDeclaration &other):
277 TypeDeclaration(other),
284 void BasicTypeDeclaration::visit(NodeVisitor &visitor)
286 visitor.visit(*this);
290 ImageTypeDeclaration::ImageTypeDeclaration():
297 void ImageTypeDeclaration::visit(NodeVisitor &visitor)
299 visitor.visit(*this);
303 StructDeclaration::StructDeclaration():
306 members.use_braces = true;
309 StructDeclaration::StructDeclaration(const StructDeclaration &other):
310 TypeDeclaration(other),
311 members(other.members),
315 StructDeclaration::~StructDeclaration()
317 if(interface_block && interface_block->struct_declaration==this)
318 interface_block->struct_declaration = 0;
321 void StructDeclaration::visit(NodeVisitor &visitor)
323 visitor.visit(*this);
327 VariableDeclaration::VariableDeclaration():
331 linked_declaration(0)
334 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
336 layout(other.layout),
337 constant(other.constant),
338 sampling(other.sampling),
339 interpolation(other.interpolation),
340 interface(other.interface),
341 precision(other.precision),
345 array_size(other.array_size),
346 init_expression(other.init_expression),
348 linked_declaration(0)
351 VariableDeclaration::~VariableDeclaration()
353 if(linked_declaration && linked_declaration->linked_declaration==this)
354 linked_declaration->linked_declaration = 0;
357 void VariableDeclaration::visit(NodeVisitor &visitor)
359 visitor.visit(*this);
363 InterfaceBlock::InterfaceBlock():
366 struct_declaration(0),
370 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
372 interface(other.interface),
374 members(other.members),
375 instance_name(other.instance_name),
378 struct_declaration(0),
382 InterfaceBlock::~InterfaceBlock()
384 if(linked_block && linked_block->linked_block==this)
385 linked_block->linked_block = 0;
386 if(struct_declaration && struct_declaration->interface_block==this)
387 struct_declaration->interface_block = 0;
390 void InterfaceBlock::visit(NodeVisitor &visitor)
392 visitor.visit(*this);
396 FunctionDeclaration::FunctionDeclaration():
398 return_type_declaration(0)
401 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
403 return_type(other.return_type),
405 parameters(other.parameters),
407 signature(other.signature),
408 definition(other.definition==&other ? this : 0),
409 return_type_declaration(0)
412 void FunctionDeclaration::visit(NodeVisitor &visitor)
414 visitor.visit(*this);
418 void Conditional::visit(NodeVisitor &visitor)
420 visitor.visit(*this);
424 void Iteration::visit(NodeVisitor &visitor)
426 visitor.visit(*this);
430 void Passthrough::visit(NodeVisitor &visitor)
432 visitor.visit(*this);
436 void Return::visit(NodeVisitor &visitor)
438 visitor.visit(*this);
442 void Jump::visit(NodeVisitor &visitor)
444 visitor.visit(*this);
448 Stage::Stage(Stage::Type t):
453 const char *Stage::get_stage_name(Type type)
455 static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
461 shared(Stage::SHARED)