1 #ifndef MSP_GL_SL_SYNTAX_H_
2 #define MSP_GL_SL_SYNTAX_H_
9 #include <msp/core/refptr.h>
11 #include "sourcemap.h"
13 #pragma push_macro("interface")
42 static const Operator operators[];
44 static const Operator &get_operator(const std::string &, Type);
59 Node(const Node &) { }
61 Node &operator=(const Node &);
65 virtual Node *clone() const = 0;
66 virtual void visit(NodeVisitor &) = 0;
70 class NodePtr: public RefPtr<T>
74 NodePtr(T *p): RefPtr<T>(p) { }
75 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
76 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
79 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
82 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
86 class NodeContainer: public C
90 NodeContainer(const NodeContainer &);
94 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
98 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
101 struct StructDeclaration;
102 struct VariableDeclaration;
103 struct InterfaceBlock;
104 struct FunctionDeclaration;
106 struct Statement: Node
113 virtual Statement *clone() const = 0;
118 NodeList<Statement> body;
121 std::map<std::string, VariableDeclaration *> variables;
125 Block(const Block &);
127 virtual Block *clone() const { return new Block(*this); }
128 virtual void visit(NodeVisitor &);
131 struct Expression: Node
133 const Operator *oper;
137 virtual Expression *clone() const = 0;
140 struct Literal: Expression
144 virtual Literal *clone() const { return new Literal(*this); }
145 virtual void visit(NodeVisitor &);
148 struct ParenthesizedExpression: Expression
150 NodePtr<Expression> expression;
152 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
153 virtual void visit(NodeVisitor &);
156 struct VariableReference: Expression
160 VariableDeclaration *declaration;
163 VariableReference(const VariableReference &);
165 virtual VariableReference *clone() const { return new VariableReference(*this); }
166 virtual void visit(NodeVisitor &);
169 struct InterfaceBlockReference: Expression
173 InterfaceBlock *declaration;
175 InterfaceBlockReference();
176 InterfaceBlockReference(const InterfaceBlockReference &);
178 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
179 virtual void visit(NodeVisitor &);
182 struct MemberAccess: Expression
184 NodePtr<Expression> left;
187 VariableDeclaration *declaration;
190 MemberAccess(const MemberAccess &);
192 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
193 virtual void visit(NodeVisitor &);
196 struct UnaryExpression: Expression
198 NodePtr<Expression> expression;
200 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
201 virtual void visit(NodeVisitor &);
204 struct BinaryExpression: Expression
206 NodePtr<Expression> left;
207 NodePtr<Expression> right;
209 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
210 virtual void visit(NodeVisitor &);
213 struct Assignment: BinaryExpression
215 bool self_referencing;
217 VariableDeclaration *target_declaration;
220 Assignment(const Assignment &);
222 virtual Assignment *clone() const { return new Assignment(*this); }
223 virtual void visit(NodeVisitor &);
226 struct FunctionCall: Expression
230 NodeArray<Expression> arguments;
232 FunctionDeclaration *declaration;
235 FunctionCall(const FunctionCall &);
237 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
238 virtual void visit(NodeVisitor &);
241 struct ExpressionStatement: Statement
243 NodePtr<Expression> expression;
245 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
246 virtual void visit(NodeVisitor &);
249 struct Import: Statement
253 virtual Import *clone() const { return new Import(*this); }
254 virtual void visit(NodeVisitor &);
257 struct Precision: Statement
259 std::string precision;
262 virtual Precision *clone() const { return new Precision(*this); }
263 virtual void visit(NodeVisitor &);
275 std::vector<Qualifier> qualifiers;
277 virtual Layout *clone() const { return new Layout(*this); }
278 virtual void visit(NodeVisitor &);
281 struct InterfaceLayout: Statement
283 std::string interface;
286 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
287 virtual void visit(NodeVisitor &);
290 struct StructDeclaration: Statement
297 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
298 virtual void visit(NodeVisitor &);
301 struct VariableDeclaration: Statement
303 NodePtr<Layout> layout;
305 std::string sampling;
306 std::string interpolation;
307 std::string interface;
308 std::string precision;
312 NodePtr<Expression> array_size;
313 NodePtr<Expression> init_expression;
315 StructDeclaration *type_declaration;
316 VariableDeclaration *linked_declaration;
318 VariableDeclaration();
319 VariableDeclaration(const VariableDeclaration &);
320 ~VariableDeclaration();
322 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
323 virtual void visit(NodeVisitor &);
326 struct InterfaceBlock: Statement
328 std::string interface;
331 std::string instance_name;
334 InterfaceBlock *linked_block;
337 InterfaceBlock(const InterfaceBlock &);
340 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
341 virtual void visit(NodeVisitor &);
344 struct FunctionDeclaration: Statement
346 std::string return_type;
348 NodeArray<VariableDeclaration> parameters;
351 FunctionDeclaration *definition;
353 FunctionDeclaration();
354 FunctionDeclaration(const FunctionDeclaration &);
356 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
357 virtual void visit(NodeVisitor &);
360 struct Conditional: Statement
362 NodePtr<Expression> condition;
366 virtual Conditional *clone() const { return new Conditional(*this); }
367 virtual void visit(NodeVisitor &);
370 struct Iteration: Statement
372 NodePtr<Statement> init_statement;
373 NodePtr<Expression> condition;
374 NodePtr<Expression> loop_expression;
377 virtual Iteration *clone() const { return new Iteration(*this); }
378 virtual void visit(NodeVisitor &);
381 struct Passthrough: Statement
383 NodePtr<Expression> subscript;
385 virtual Passthrough *clone() const { return new Passthrough(*this); }
386 virtual void visit(NodeVisitor &);
389 struct Return: Statement
391 NodePtr<Expression> expression;
393 virtual Return *clone() const { return new Return(*this); }
394 virtual void visit(NodeVisitor &);
397 struct Jump: Statement
401 virtual Jump *clone() const { return new Jump(*this); }
402 virtual void visit(NodeVisitor &);
418 std::map<std::string, StructDeclaration *> types;
419 std::map<std::string, InterfaceBlock *> interface_blocks;
420 std::map<std::string, FunctionDeclaration *> functions;
421 std::map<std::string, unsigned> locations;
422 Features required_features;
426 static const char *get_stage_name(Type);
431 SourceMap source_map;
433 std::list<Stage> stages;
442 #pragma pop_macro("interface")