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[];
43 static const Operator &get_operator(const std::string &, Type);
58 Node(const Node &) { }
60 Node &operator=(const Node &);
64 virtual Node *clone() const = 0;
65 virtual void visit(NodeVisitor &) = 0;
69 class NodePtr: public RefPtr<T>
73 NodePtr(T *p): RefPtr<T>(p) { }
74 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
75 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
78 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
81 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
85 class NodeContainer: public C
89 NodeContainer(const NodeContainer &);
93 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
97 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
100 struct StructDeclaration;
101 struct VariableDeclaration;
102 struct InterfaceBlock;
103 struct FunctionDeclaration;
105 struct Statement: Node
112 virtual Statement *clone() const = 0;
117 NodeList<Statement> body;
120 std::map<std::string, VariableDeclaration *> variables;
124 Block(const Block &);
126 virtual Block *clone() const { return new Block(*this); }
127 virtual void visit(NodeVisitor &);
130 struct Expression: Node
132 const Operator *oper;
136 virtual Expression *clone() const = 0;
139 struct Literal: Expression
143 virtual Literal *clone() const { return new Literal(*this); }
144 virtual void visit(NodeVisitor &);
147 struct ParenthesizedExpression: Expression
149 NodePtr<Expression> expression;
151 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
152 virtual void visit(NodeVisitor &);
155 struct VariableReference: Expression
159 VariableDeclaration *declaration;
162 VariableReference(const VariableReference &);
164 virtual VariableReference *clone() const { return new VariableReference(*this); }
165 virtual void visit(NodeVisitor &);
168 struct InterfaceBlockReference: Expression
172 InterfaceBlock *declaration;
174 InterfaceBlockReference();
175 InterfaceBlockReference(const InterfaceBlockReference &);
177 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
178 virtual void visit(NodeVisitor &);
181 struct MemberAccess: Expression
183 NodePtr<Expression> left;
186 VariableDeclaration *declaration;
189 MemberAccess(const MemberAccess &);
191 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
192 virtual void visit(NodeVisitor &);
195 struct UnaryExpression: Expression
197 NodePtr<Expression> expression;
199 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
200 virtual void visit(NodeVisitor &);
203 struct BinaryExpression: Expression
205 NodePtr<Expression> left;
206 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")