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)
78 Statement::Statement():
79 source(GENERATED_SOURCE),
89 Block::Block(const Block &other):
92 use_braces(other.use_braces),
96 void Block::visit(NodeVisitor &visitor)
102 Expression::Expression():
107 void Literal::visit(NodeVisitor &visitor)
109 visitor.visit(*this);
113 void ParenthesizedExpression::visit(NodeVisitor &visitor)
115 visitor.visit(*this);
119 VariableReference::VariableReference():
123 VariableReference::VariableReference(const VariableReference &other):
129 void VariableReference::visit(NodeVisitor &visitor)
131 visitor.visit(*this);
135 InterfaceBlockReference::InterfaceBlockReference():
139 InterfaceBlockReference::InterfaceBlockReference(const InterfaceBlockReference &other):
145 void InterfaceBlockReference::visit(NodeVisitor &visitor)
147 visitor.visit(*this);
151 MemberAccess::MemberAccess():
155 MemberAccess::MemberAccess(const MemberAccess &other):
158 member(other.member),
162 void MemberAccess::visit(NodeVisitor &visitor)
164 visitor.visit(*this);
168 void UnaryExpression::visit(NodeVisitor &visitor)
170 visitor.visit(*this);
174 void BinaryExpression::visit(NodeVisitor &visitor)
176 visitor.visit(*this);
180 Assignment::Assignment():
181 self_referencing(false),
182 target_declaration(0)
185 Assignment::Assignment(const Assignment &other):
186 BinaryExpression(other),
187 self_referencing(other.self_referencing),
188 target_declaration(0)
191 void Assignment::visit(NodeVisitor &visitor)
193 visitor.visit(*this);
197 FunctionCall::FunctionCall():
202 FunctionCall::FunctionCall(const FunctionCall &other):
205 constructor(other.constructor),
206 arguments(other.arguments),
210 void FunctionCall::visit(NodeVisitor &visitor)
212 visitor.visit(*this);
216 void ExpressionStatement::visit(NodeVisitor &visitor)
218 visitor.visit(*this);
222 void Import::visit(NodeVisitor &visitor)
224 visitor.visit(*this);
228 void Precision::visit(NodeVisitor &visitor)
230 visitor.visit(*this);
234 void Layout::visit(NodeVisitor &visitor)
236 visitor.visit(*this);
240 void InterfaceLayout::visit(NodeVisitor &visitor)
242 visitor.visit(*this);
246 StructDeclaration::StructDeclaration()
248 members.use_braces = true;
251 void StructDeclaration::visit(NodeVisitor &visitor)
253 visitor.visit(*this);
257 VariableDeclaration::VariableDeclaration():
261 linked_declaration(0)
264 VariableDeclaration::VariableDeclaration(const VariableDeclaration &other):
266 layout(other.layout),
267 constant(other.constant),
268 sampling(other.sampling),
269 interpolation(other.interpolation),
270 interface(other.interface),
271 precision(other.precision),
275 array_size(other.array_size),
276 init_expression(other.init_expression),
278 linked_declaration(0)
281 VariableDeclaration::~VariableDeclaration()
283 if(linked_declaration && linked_declaration->linked_declaration==this)
284 linked_declaration->linked_declaration = 0;
287 void VariableDeclaration::visit(NodeVisitor &visitor)
289 visitor.visit(*this);
293 InterfaceBlock::InterfaceBlock():
297 members.use_braces = true;
300 InterfaceBlock::InterfaceBlock(const InterfaceBlock &other):
302 interface(other.interface),
304 members(other.members),
305 instance_name(other.instance_name),
310 InterfaceBlock::~InterfaceBlock()
312 if(linked_block && linked_block->linked_block==this)
313 linked_block->linked_block = 0;
316 void InterfaceBlock::visit(NodeVisitor &visitor)
318 visitor.visit(*this);
322 FunctionDeclaration::FunctionDeclaration():
326 FunctionDeclaration::FunctionDeclaration(const FunctionDeclaration &other):
328 return_type(other.return_type),
330 parameters(other.parameters),
332 definition(other.definition==&other ? this : 0)
335 void FunctionDeclaration::visit(NodeVisitor &visitor)
337 visitor.visit(*this);
341 void Conditional::visit(NodeVisitor &visitor)
343 visitor.visit(*this);
347 void Iteration::visit(NodeVisitor &visitor)
349 visitor.visit(*this);
353 void Passthrough::visit(NodeVisitor &visitor)
355 visitor.visit(*this);
359 void Return::visit(NodeVisitor &visitor)
361 visitor.visit(*this);
365 void Jump::visit(NodeVisitor &visitor)
367 visitor.visit(*this);
371 Stage::Stage(Stage::Type t):
376 const char *Stage::get_stage_name(Type type)
378 static const char *names[] = { "shared", "vertex", "geometry", "fragment" };
384 shared(Stage::SHARED)