1 #ifndef MSP_GL_SL_SYNTAX_H_
2 #define MSP_GL_SL_SYNTAX_H_
8 #include <msp/core/refptr.h>
10 #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 FunctionDeclaration;
96 struct Statement: Node
103 virtual Statement *clone() const = 0;
108 NodeList<Statement> body;
110 std::map<std::string, StructDeclaration *> types;
111 std::map<std::string, VariableDeclaration *> variables;
115 virtual Block *clone() const { return new Block(*this); }
116 virtual void visit(NodeVisitor &);
119 struct Expression: Node
121 virtual Expression *clone() const = 0;
124 struct Literal: Expression
128 virtual Literal *clone() const { return new Literal(*this); }
129 virtual void visit(NodeVisitor &);
132 struct ParenthesizedExpression: Expression
134 NodePtr<Expression> expression;
136 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
137 virtual void visit(NodeVisitor &);
140 struct VariableReference: Expression
143 VariableDeclaration *declaration;
147 virtual VariableReference *clone() const { return new VariableReference(*this); }
148 virtual void visit(NodeVisitor &);
151 struct MemberAccess: Expression
153 NodePtr<Expression> left;
155 VariableDeclaration *declaration;
157 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
158 virtual void visit(NodeVisitor &);
161 struct UnaryExpression: Expression
164 NodePtr<Expression> expression;
169 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
170 virtual void visit(NodeVisitor &);
173 struct BinaryExpression: Expression
175 NodePtr<Expression> left;
177 NodePtr<Expression> right;
180 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
181 virtual void visit(NodeVisitor &);
184 struct Assignment: BinaryExpression
186 bool self_referencing;
187 VariableDeclaration *target_declaration;
191 virtual Assignment *clone() const { return new Assignment(*this); }
192 virtual void visit(NodeVisitor &);
195 struct FunctionCall: Expression
198 FunctionDeclaration *declaration;
200 NodeArray<Expression> arguments;
204 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
205 virtual void visit(NodeVisitor &);
208 struct ExpressionStatement: Statement
210 NodePtr<Expression> expression;
212 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
213 virtual void visit(NodeVisitor &);
216 struct Import: Statement
220 virtual Import *clone() const { return new Import(*this); }
221 virtual void visit(NodeVisitor &);
224 struct Precision: Statement
226 std::string precision;
229 virtual Precision *clone() const { return new Precision(*this); }
230 virtual void visit(NodeVisitor &);
237 // TODO the standard calls this name, not identifier
238 std::string identifier;
242 std::vector<Qualifier> qualifiers;
244 virtual Layout *clone() const { return new Layout(*this); }
245 virtual void visit(NodeVisitor &);
248 struct InterfaceLayout: Statement
250 std::string interface;
253 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
254 virtual void visit(NodeVisitor &);
257 struct StructDeclaration: Statement
264 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
265 virtual void visit(NodeVisitor &);
268 struct VariableDeclaration: Statement
271 std::string sampling;
272 std::string interpolation;
273 std::string interface;
274 std::string precision;
276 StructDeclaration *type_declaration;
279 NodePtr<Expression> array_size;
280 NodePtr<Expression> init_expression;
281 VariableDeclaration *linked_declaration;
282 NodePtr<Layout> layout;
284 VariableDeclaration();
286 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
287 virtual void visit(NodeVisitor &);
290 struct InterfaceBlock: Statement
292 std::string interface;
295 std::string instance_name;
300 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
301 virtual void visit(NodeVisitor &);
304 struct FunctionDeclaration: Statement
306 std::string return_type;
308 NodeArray<VariableDeclaration> parameters;
309 FunctionDeclaration *definition;
312 FunctionDeclaration();
313 FunctionDeclaration(const FunctionDeclaration &);
315 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
316 virtual void visit(NodeVisitor &);
319 struct Conditional: Statement
321 NodePtr<Expression> condition;
325 virtual Conditional *clone() const { return new Conditional(*this); }
326 virtual void visit(NodeVisitor &);
329 struct Iteration: Statement
331 NodePtr<Node> init_statement;
332 NodePtr<Expression> condition;
333 NodePtr<Expression> loop_expression;
336 virtual Iteration *clone() const { return new Iteration(*this); }
337 virtual void visit(NodeVisitor &);
340 struct Passthrough: Statement
342 NodePtr<Expression> subscript;
344 virtual Passthrough *clone() const { return new Passthrough(*this); }
345 virtual void visit(NodeVisitor &);
348 struct Return: Statement
350 NodePtr<Expression> expression;
352 virtual Return *clone() const { return new Return(*this); }
353 virtual void visit(NodeVisitor &);
356 struct Jump: Statement
360 virtual Jump *clone() const { return new Jump(*this); }
361 virtual void visit(NodeVisitor &);
377 std::map<std::string, VariableDeclaration *> in_variables;
378 std::map<std::string, VariableDeclaration *> out_variables;
379 std::map<std::string, unsigned> locations;
380 Version required_version;
381 std::vector<const Extension *> required_extensions;
385 static const char *get_stage_name(Type);
390 SourceMap source_map;
392 std::list<Stage> stages;
401 #pragma pop_macro("interface")