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")
41 static const Operator operators[];
50 Node(const Node &) { }
52 Node &operator=(const Node &);
56 virtual Node *clone() const = 0;
57 virtual void visit(NodeVisitor &) = 0;
61 class NodePtr: public RefPtr<T>
65 NodePtr(T *p): RefPtr<T>(p) { }
66 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
67 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
70 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
73 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
77 class NodeContainer: public C
81 NodeContainer(const NodeContainer &);
85 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
89 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
92 struct StructDeclaration;
93 struct VariableDeclaration;
94 struct InterfaceBlock;
95 struct FunctionDeclaration;
97 struct Statement: Node
104 virtual Statement *clone() const = 0;
109 NodeList<Statement> body;
111 std::map<std::string, StructDeclaration *> types;
112 std::map<std::string, VariableDeclaration *> variables;
113 std::map<std::string, InterfaceBlock *> interfaces;
117 Block(const Block &);
119 virtual Block *clone() const { return new Block(*this); }
120 virtual void visit(NodeVisitor &);
123 struct Expression: Node
125 virtual Expression *clone() const = 0;
128 struct Literal: Expression
132 virtual Literal *clone() const { return new Literal(*this); }
133 virtual void visit(NodeVisitor &);
136 struct ParenthesizedExpression: Expression
138 NodePtr<Expression> expression;
140 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
141 virtual void visit(NodeVisitor &);
144 struct VariableReference: Expression
147 VariableDeclaration *declaration;
150 VariableReference(const VariableReference &);
152 virtual VariableReference *clone() const { return new VariableReference(*this); }
153 virtual void visit(NodeVisitor &);
156 struct InterfaceBlockReference: Expression
159 InterfaceBlock *declaration;
161 InterfaceBlockReference();
162 InterfaceBlockReference(const InterfaceBlockReference &);
164 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
165 virtual void visit(NodeVisitor &);
168 struct MemberAccess: Expression
170 NodePtr<Expression> left;
172 VariableDeclaration *declaration;
175 MemberAccess(const MemberAccess &);
177 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
178 virtual void visit(NodeVisitor &);
181 struct UnaryExpression: Expression
184 NodePtr<Expression> expression;
189 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
190 virtual void visit(NodeVisitor &);
193 struct BinaryExpression: Expression
195 NodePtr<Expression> left;
197 NodePtr<Expression> right;
200 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
201 virtual void visit(NodeVisitor &);
204 struct Assignment: BinaryExpression
206 bool self_referencing;
207 VariableDeclaration *target_declaration;
210 Assignment(const Assignment &);
212 virtual Assignment *clone() const { return new Assignment(*this); }
213 virtual void visit(NodeVisitor &);
216 struct FunctionCall: Expression
219 FunctionDeclaration *declaration;
221 NodeArray<Expression> arguments;
224 FunctionCall(const FunctionCall &);
226 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
227 virtual void visit(NodeVisitor &);
230 struct ExpressionStatement: Statement
232 NodePtr<Expression> expression;
234 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
235 virtual void visit(NodeVisitor &);
238 struct Import: Statement
242 virtual Import *clone() const { return new Import(*this); }
243 virtual void visit(NodeVisitor &);
246 struct Precision: Statement
248 std::string precision;
251 virtual Precision *clone() const { return new Precision(*this); }
252 virtual void visit(NodeVisitor &);
264 std::vector<Qualifier> qualifiers;
266 virtual Layout *clone() const { return new Layout(*this); }
267 virtual void visit(NodeVisitor &);
270 struct InterfaceLayout: Statement
272 std::string interface;
275 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
276 virtual void visit(NodeVisitor &);
279 struct StructDeclaration: Statement
286 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
287 virtual void visit(NodeVisitor &);
290 struct VariableDeclaration: Statement
293 std::string sampling;
294 std::string interpolation;
295 std::string interface;
296 std::string precision;
298 StructDeclaration *type_declaration;
301 NodePtr<Expression> array_size;
302 NodePtr<Expression> init_expression;
303 VariableDeclaration *linked_declaration;
304 NodePtr<Layout> layout;
306 VariableDeclaration();
307 VariableDeclaration(const VariableDeclaration &);
309 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
310 virtual void visit(NodeVisitor &);
313 struct InterfaceBlock: Statement
315 std::string interface;
318 std::string instance_name;
320 InterfaceBlock *linked_block;
323 InterfaceBlock(const InterfaceBlock &);
325 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
326 virtual void visit(NodeVisitor &);
329 struct FunctionDeclaration: Statement
331 std::string return_type;
333 NodeArray<VariableDeclaration> parameters;
334 FunctionDeclaration *definition;
337 FunctionDeclaration();
338 FunctionDeclaration(const FunctionDeclaration &);
340 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
341 virtual void visit(NodeVisitor &);
344 struct Conditional: Statement
346 NodePtr<Expression> condition;
350 virtual Conditional *clone() const { return new Conditional(*this); }
351 virtual void visit(NodeVisitor &);
354 struct Iteration: Statement
356 NodePtr<Node> init_statement;
357 NodePtr<Expression> condition;
358 NodePtr<Expression> loop_expression;
361 virtual Iteration *clone() const { return new Iteration(*this); }
362 virtual void visit(NodeVisitor &);
365 struct Passthrough: Statement
367 NodePtr<Expression> subscript;
369 virtual Passthrough *clone() const { return new Passthrough(*this); }
370 virtual void visit(NodeVisitor &);
373 struct Return: Statement
375 NodePtr<Expression> expression;
377 virtual Return *clone() const { return new Return(*this); }
378 virtual void visit(NodeVisitor &);
381 struct Jump: Statement
385 virtual Jump *clone() const { return new Jump(*this); }
386 virtual void visit(NodeVisitor &);
402 std::map<std::string, unsigned> locations;
403 Features required_features;
407 static const char *get_stage_name(Type);
412 SourceMap source_map;
414 std::list<Stage> stages;
423 #pragma pop_macro("interface")