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():
101 void Literal::visit(NodeVisitor &visitor)
103 visitor.visit(*this);
107 void ParenthesizedExpression::visit(NodeVisitor &visitor)
109 visitor.visit(*this);
113 VariableReference::VariableReference():
117 VariableReference::VariableReference(const VariableReference &other):
123 void VariableReference::visit(NodeVisitor &visitor)
125 visitor.visit(*this);
129 InterfaceBlockReference::InterfaceBlockReference():
133 InterfaceBlockReference::InterfaceBlockReference(const InterfaceBlockReference &other):
139 void InterfaceBlockReference::visit(NodeVisitor &visitor)
141 visitor.visit(*this);
145 MemberAccess::MemberAccess():
149 MemberAccess::MemberAccess(const MemberAccess &other):
152 member(other.member),
156 void MemberAccess::visit(NodeVisitor &visitor)
158 visitor.visit(*this);
162 void UnaryExpression::visit(NodeVisitor &visitor)
164 visitor.visit(*this);
168 void BinaryExpression::visit(NodeVisitor &visitor)
170 visitor.visit(*this);
174 Assignment::Assignment():
175 self_referencing(false),
176 target_declaration(0)
179 Assignment::Assignment(const Assignment &other):
180 BinaryExpression(other),
181 self_referencing(other.self_referencing),
182 target_declaration(0)
185 void Assignment::visit(NodeVisitor &visitor)
187 visitor.visit(*this);
191 FunctionCall::FunctionCall():
196 FunctionCall::FunctionCall(const FunctionCall &other):
199 constructor(other.constructor),
200 arguments(other.arguments),
204 void FunctionCall::visit(NodeVisitor &visitor)
206 visitor.visit(*this);
210 void ExpressionStatement::visit(NodeVisitor &visitor)
212 visitor.visit(*this);
216 void Import::visit(NodeVisitor &visitor)
218 visitor.visit(*this);
222 void Precision::visit(NodeVisitor &visitor)
224 visitor.visit(*this);
228 void Layout::visit(NodeVisitor &visitor)
230 visitor.visit(*this);
234 void InterfaceLayout::visit(NodeVisitor &visitor)
236 visitor.visit(*this);
240 BasicTypeDeclaration::BasicTypeDeclaration():
246 BasicTypeDeclaration::BasicTypeDeclaration(const BasicTypeDeclaration &other):
247 TypeDeclaration(other),
254 void BasicTypeDeclaration::visit(NodeVisitor &visitor)
256 visitor.visit(*this);
260 ImageTypeDeclaration::ImageTypeDeclaration():
267 void ImageTypeDeclaration::visit(NodeVisitor &visitor)
269 visitor.visit(*this);
273 StructDeclaration::StructDeclaration()
275 members.use_braces = true;
278 void StructDeclaration::visit(NodeVisitor &visitor)
280 visitor.visit(*this);
284 VariableDeclaration::VariableDeclaration():
288 linked_declaration(0)
291 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
293 layout(other.layout),
294 constant(other.constant),
295 sampling(other.sampling),
296 interpolation(other.interpolation),
297 interface(other.interface),
298 precision(other.precision),
302 array_size(other.array_size),
303 init_expression(other.init_expression),
305 linked_declaration(0)
308 VariableDeclaration::~VariableDeclaration()
310 if(linked_declaration && linked_declaration->linked_declaration==this)
311 linked_declaration->linked_declaration = 0;
314 void VariableDeclaration::visit(NodeVisitor &visitor)
316 visitor.visit(*this);
320 InterfaceBlock::InterfaceBlock():
324 members.use_braces = true;
327 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
329 interface(other.interface),
331 members(other.members),
332 instance_name(other.instance_name),
337 InterfaceBlock::~InterfaceBlock()
339 if(linked_block && linked_block->linked_block==this)
340 linked_block->linked_block = 0;
343 void InterfaceBlock::visit(NodeVisitor &visitor)
345 visitor.visit(*this);
349 FunctionDeclaration::FunctionDeclaration():
353 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
355 return_type(other.return_type),
357 parameters(other.parameters),
359 definition(other.definition==&other ? this : 0)
362 void FunctionDeclaration::visit(NodeVisitor &visitor)
364 visitor.visit(*this);
368 void Conditional::visit(NodeVisitor &visitor)
370 visitor.visit(*this);
374 void Iteration::visit(NodeVisitor &visitor)
376 visitor.visit(*this);
380 void Passthrough::visit(NodeVisitor &visitor)
382 visitor.visit(*this);
386 void Return::visit(NodeVisitor &visitor)
388 visitor.visit(*this);
392 void Jump::visit(NodeVisitor &visitor)
394 visitor.visit(*this);
398 Stage::Stage(Stage::Type t):
403 const char *Stage::get_stage_name(Type type)
405 static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
411 shared(Stage::SHARED)