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;
112 std::map<std::string, VariableDeclaration *> variables;
116 Block(const Block &);
118 virtual Block *clone() const { return new Block(*this); }
119 virtual void visit(NodeVisitor &);
122 struct Expression: Node
124 virtual Expression *clone() const = 0;
127 struct Literal: Expression
131 virtual Literal *clone() const { return new Literal(*this); }
132 virtual void visit(NodeVisitor &);
135 struct ParenthesizedExpression: Expression
137 NodePtr<Expression> expression;
139 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
140 virtual void visit(NodeVisitor &);
143 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
160 InterfaceBlock *declaration;
162 InterfaceBlockReference();
163 InterfaceBlockReference(const InterfaceBlockReference &);
165 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
166 virtual void visit(NodeVisitor &);
169 struct MemberAccess: Expression
171 NodePtr<Expression> left;
174 VariableDeclaration *declaration;
177 MemberAccess(const MemberAccess &);
179 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
180 virtual void visit(NodeVisitor &);
183 struct UnaryExpression: Expression
186 NodePtr<Expression> expression;
191 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
192 virtual void visit(NodeVisitor &);
195 struct BinaryExpression: Expression
197 NodePtr<Expression> left;
199 NodePtr<Expression> right;
202 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
203 virtual void visit(NodeVisitor &);
206 struct Assignment: BinaryExpression
208 bool self_referencing;
210 VariableDeclaration *target_declaration;
213 Assignment(const Assignment &);
215 virtual Assignment *clone() const { return new Assignment(*this); }
216 virtual void visit(NodeVisitor &);
219 struct FunctionCall: Expression
223 NodeArray<Expression> arguments;
225 FunctionDeclaration *declaration;
228 FunctionCall(const FunctionCall &);
230 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
231 virtual void visit(NodeVisitor &);
234 struct ExpressionStatement: Statement
236 NodePtr<Expression> expression;
238 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
239 virtual void visit(NodeVisitor &);
242 struct Import: Statement
246 virtual Import *clone() const { return new Import(*this); }
247 virtual void visit(NodeVisitor &);
250 struct Precision: Statement
252 std::string precision;
255 virtual Precision *clone() const { return new Precision(*this); }
256 virtual void visit(NodeVisitor &);
268 std::vector<Qualifier> qualifiers;
270 virtual Layout *clone() const { return new Layout(*this); }
271 virtual void visit(NodeVisitor &);
274 struct InterfaceLayout: Statement
276 std::string interface;
279 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
280 virtual void visit(NodeVisitor &);
283 struct StructDeclaration: Statement
290 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
291 virtual void visit(NodeVisitor &);
294 struct VariableDeclaration: Statement
296 NodePtr<Layout> layout;
298 std::string sampling;
299 std::string interpolation;
300 std::string interface;
301 std::string precision;
305 NodePtr<Expression> array_size;
306 NodePtr<Expression> init_expression;
308 StructDeclaration *type_declaration;
309 VariableDeclaration *linked_declaration;
311 VariableDeclaration();
312 VariableDeclaration(const VariableDeclaration &);
313 ~VariableDeclaration();
315 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
316 virtual void visit(NodeVisitor &);
319 struct InterfaceBlock: Statement
321 std::string interface;
324 std::string instance_name;
327 InterfaceBlock *linked_block;
330 InterfaceBlock(const InterfaceBlock &);
333 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
334 virtual void visit(NodeVisitor &);
337 struct FunctionDeclaration: Statement
339 std::string return_type;
341 NodeArray<VariableDeclaration> parameters;
344 FunctionDeclaration *definition;
346 FunctionDeclaration();
347 FunctionDeclaration(const FunctionDeclaration &);
349 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
350 virtual void visit(NodeVisitor &);
353 struct Conditional: Statement
355 NodePtr<Expression> condition;
359 virtual Conditional *clone() const { return new Conditional(*this); }
360 virtual void visit(NodeVisitor &);
363 struct Iteration: Statement
365 NodePtr<Node> init_statement;
366 NodePtr<Expression> condition;
367 NodePtr<Expression> loop_expression;
370 virtual Iteration *clone() const { return new Iteration(*this); }
371 virtual void visit(NodeVisitor &);
374 struct Passthrough: Statement
376 NodePtr<Expression> subscript;
378 virtual Passthrough *clone() const { return new Passthrough(*this); }
379 virtual void visit(NodeVisitor &);
382 struct Return: Statement
384 NodePtr<Expression> expression;
386 virtual Return *clone() const { return new Return(*this); }
387 virtual void visit(NodeVisitor &);
390 struct Jump: Statement
394 virtual Jump *clone() const { return new Jump(*this); }
395 virtual void visit(NodeVisitor &);
411 std::map<std::string, StructDeclaration *> types;
412 std::map<std::string, InterfaceBlock *> interface_blocks;
413 std::map<std::string, unsigned> locations;
414 Features required_features;
418 static const char *get_stage_name(Type);
423 SourceMap source_map;
425 std::list<Stage> stages;
434 #pragma pop_macro("interface")