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[];
56 Node(const Node &) { }
58 Node &operator=(const Node &);
62 virtual Node *clone() const = 0;
63 virtual void visit(NodeVisitor &) = 0;
67 class NodePtr: public RefPtr<T>
71 NodePtr(T *p): RefPtr<T>(p) { }
72 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
73 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
76 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
79 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
83 class NodeContainer: public C
87 NodeContainer(const NodeContainer &);
91 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
95 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
98 struct StructDeclaration;
99 struct VariableDeclaration;
100 struct InterfaceBlock;
101 struct FunctionDeclaration;
103 struct Statement: Node
110 virtual Statement *clone() const = 0;
115 NodeList<Statement> body;
118 std::map<std::string, VariableDeclaration *> variables;
122 Block(const Block &);
124 virtual Block *clone() const { return new Block(*this); }
125 virtual void visit(NodeVisitor &);
128 struct Expression: Node
130 virtual Expression *clone() const = 0;
133 struct Literal: Expression
137 virtual Literal *clone() const { return new Literal(*this); }
138 virtual void visit(NodeVisitor &);
141 struct ParenthesizedExpression: Expression
143 NodePtr<Expression> expression;
145 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
146 virtual void visit(NodeVisitor &);
149 struct VariableReference: Expression
153 VariableDeclaration *declaration;
156 VariableReference(const VariableReference &);
158 virtual VariableReference *clone() const { return new VariableReference(*this); }
159 virtual void visit(NodeVisitor &);
162 struct InterfaceBlockReference: Expression
166 InterfaceBlock *declaration;
168 InterfaceBlockReference();
169 InterfaceBlockReference(const InterfaceBlockReference &);
171 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
172 virtual void visit(NodeVisitor &);
175 struct MemberAccess: Expression
177 NodePtr<Expression> left;
180 VariableDeclaration *declaration;
183 MemberAccess(const MemberAccess &);
185 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
186 virtual void visit(NodeVisitor &);
189 struct UnaryExpression: Expression
192 NodePtr<Expression> expression;
197 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
198 virtual void visit(NodeVisitor &);
201 struct BinaryExpression: Expression
203 NodePtr<Expression> left;
205 NodePtr<Expression> right;
208 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
209 virtual void visit(NodeVisitor &);
212 struct Assignment: BinaryExpression
214 bool self_referencing;
216 VariableDeclaration *target_declaration;
219 Assignment(const Assignment &);
221 virtual Assignment *clone() const { return new Assignment(*this); }
222 virtual void visit(NodeVisitor &);
225 struct FunctionCall: Expression
229 NodeArray<Expression> arguments;
231 FunctionDeclaration *declaration;
234 FunctionCall(const FunctionCall &);
236 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
237 virtual void visit(NodeVisitor &);
240 struct ExpressionStatement: Statement
242 NodePtr<Expression> expression;
244 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
245 virtual void visit(NodeVisitor &);
248 struct Import: Statement
252 virtual Import *clone() const { return new Import(*this); }
253 virtual void visit(NodeVisitor &);
256 struct Precision: Statement
258 std::string precision;
261 virtual Precision *clone() const { return new Precision(*this); }
262 virtual void visit(NodeVisitor &);
274 std::vector<Qualifier> qualifiers;
276 virtual Layout *clone() const { return new Layout(*this); }
277 virtual void visit(NodeVisitor &);
280 struct InterfaceLayout: Statement
282 std::string interface;
285 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
286 virtual void visit(NodeVisitor &);
289 struct StructDeclaration: Statement
296 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
297 virtual void visit(NodeVisitor &);
300 struct VariableDeclaration: Statement
302 NodePtr<Layout> layout;
304 std::string sampling;
305 std::string interpolation;
306 std::string interface;
307 std::string precision;
311 NodePtr<Expression> array_size;
312 NodePtr<Expression> init_expression;
314 StructDeclaration *type_declaration;
315 VariableDeclaration *linked_declaration;
317 VariableDeclaration();
318 VariableDeclaration(const VariableDeclaration &);
319 ~VariableDeclaration();
321 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
322 virtual void visit(NodeVisitor &);
325 struct InterfaceBlock: Statement
327 std::string interface;
330 std::string instance_name;
333 InterfaceBlock *linked_block;
336 InterfaceBlock(const InterfaceBlock &);
339 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
340 virtual void visit(NodeVisitor &);
343 struct FunctionDeclaration: Statement
345 std::string return_type;
347 NodeArray<VariableDeclaration> parameters;
350 FunctionDeclaration *definition;
352 FunctionDeclaration();
353 FunctionDeclaration(const FunctionDeclaration &);
355 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
356 virtual void visit(NodeVisitor &);
359 struct Conditional: Statement
361 NodePtr<Expression> condition;
365 virtual Conditional *clone() const { return new Conditional(*this); }
366 virtual void visit(NodeVisitor &);
369 struct Iteration: Statement
371 NodePtr<Node> init_statement;
372 NodePtr<Expression> condition;
373 NodePtr<Expression> loop_expression;
376 virtual Iteration *clone() const { return new Iteration(*this); }
377 virtual void visit(NodeVisitor &);
380 struct Passthrough: Statement
382 NodePtr<Expression> subscript;
384 virtual Passthrough *clone() const { return new Passthrough(*this); }
385 virtual void visit(NodeVisitor &);
388 struct Return: Statement
390 NodePtr<Expression> expression;
392 virtual Return *clone() const { return new Return(*this); }
393 virtual void visit(NodeVisitor &);
396 struct Jump: Statement
400 virtual Jump *clone() const { return new Jump(*this); }
401 virtual void visit(NodeVisitor &);
417 std::map<std::string, StructDeclaration *> types;
418 std::map<std::string, InterfaceBlock *> interface_blocks;
419 std::map<std::string, FunctionDeclaration *> functions;
420 std::map<std::string, unsigned> locations;
421 Features required_features;
425 static const char *get_stage_name(Type);
430 SourceMap source_map;
432 std::list<Stage> stages;
441 #pragma pop_macro("interface")