1 #ifndef MSP_GL_SL_SYNTAX_H_
2 #define MSP_GL_SL_SYNTAX_H_
8 #include <msp/core/refptr.h>
10 #include "sourcemap.h"
12 #pragma push_macro("interface")
40 static const Operator operators[];
49 Node(const Node &) { }
51 Node &operator=(const Node &);
55 virtual Node *clone() const = 0;
56 virtual void visit(NodeVisitor &) = 0;
60 class NodePtr: public RefPtr<T>
64 NodePtr(T *p): RefPtr<T>(p) { }
65 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
66 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
69 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
72 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
76 class NodeContainer: public C
80 NodeContainer(const NodeContainer &);
84 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
88 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
91 struct StructDeclaration;
92 struct VariableDeclaration;
93 struct FunctionDeclaration;
95 struct Statement: Node
102 virtual Statement *clone() const = 0;
107 NodeList<Statement> body;
110 std::map<std::string, StructDeclaration *> types;
111 std::map<std::string, VariableDeclaration *> variables;
115 Block(const Block &);
117 virtual Block *clone() const { return new Block(*this); }
118 virtual void visit(NodeVisitor &);
121 struct Expression: Node
123 virtual Expression *clone() const = 0;
126 struct Literal: Expression
130 virtual Literal *clone() const { return new Literal(*this); }
131 virtual void visit(NodeVisitor &);
134 struct ParenthesizedExpression: Expression
136 NodePtr<Expression> expression;
138 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
139 virtual void visit(NodeVisitor &);
142 struct VariableReference: Expression
145 VariableDeclaration *declaration;
148 VariableReference(const VariableReference &);
150 virtual VariableReference *clone() const { return new VariableReference(*this); }
151 virtual void visit(NodeVisitor &);
154 struct MemberAccess: Expression
156 NodePtr<Expression> left;
158 VariableDeclaration *declaration;
161 MemberAccess(const MemberAccess &);
163 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
164 virtual void visit(NodeVisitor &);
167 struct UnaryExpression: Expression
170 NodePtr<Expression> expression;
175 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
176 virtual void visit(NodeVisitor &);
179 struct BinaryExpression: Expression
181 NodePtr<Expression> left;
183 NodePtr<Expression> right;
186 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
187 virtual void visit(NodeVisitor &);
190 struct Assignment: BinaryExpression
192 bool self_referencing;
193 VariableDeclaration *target_declaration;
196 Assignment(const Assignment &);
198 virtual Assignment *clone() const { return new Assignment(*this); }
199 virtual void visit(NodeVisitor &);
202 struct FunctionCall: Expression
205 FunctionDeclaration *declaration;
207 NodeArray<Expression> arguments;
210 FunctionCall(const FunctionCall &);
212 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
213 virtual void visit(NodeVisitor &);
216 struct ExpressionStatement: Statement
218 NodePtr<Expression> expression;
220 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
221 virtual void visit(NodeVisitor &);
224 struct Import: Statement
228 virtual Import *clone() const { return new Import(*this); }
229 virtual void visit(NodeVisitor &);
232 struct Precision: Statement
234 std::string precision;
237 virtual Precision *clone() const { return new Precision(*this); }
238 virtual void visit(NodeVisitor &);
250 std::vector<Qualifier> qualifiers;
252 virtual Layout *clone() const { return new Layout(*this); }
253 virtual void visit(NodeVisitor &);
256 struct InterfaceLayout: Statement
258 std::string interface;
261 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
262 virtual void visit(NodeVisitor &);
265 struct StructDeclaration: Statement
272 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
273 virtual void visit(NodeVisitor &);
276 struct VariableDeclaration: Statement
279 std::string sampling;
280 std::string interpolation;
281 std::string interface;
282 std::string precision;
284 StructDeclaration *type_declaration;
287 NodePtr<Expression> array_size;
288 NodePtr<Expression> init_expression;
289 VariableDeclaration *linked_declaration;
290 NodePtr<Layout> layout;
292 VariableDeclaration();
293 VariableDeclaration(const VariableDeclaration &);
295 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
296 virtual void visit(NodeVisitor &);
299 struct InterfaceBlock: Statement
301 std::string interface;
304 std::string instance_name;
309 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
310 virtual void visit(NodeVisitor &);
313 struct FunctionDeclaration: Statement
315 std::string return_type;
317 NodeArray<VariableDeclaration> parameters;
318 FunctionDeclaration *definition;
321 FunctionDeclaration();
322 FunctionDeclaration(const FunctionDeclaration &);
324 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
325 virtual void visit(NodeVisitor &);
328 struct Conditional: Statement
330 NodePtr<Expression> condition;
334 virtual Conditional *clone() const { return new Conditional(*this); }
335 virtual void visit(NodeVisitor &);
338 struct Iteration: Statement
340 NodePtr<Node> init_statement;
341 NodePtr<Expression> condition;
342 NodePtr<Expression> loop_expression;
345 virtual Iteration *clone() const { return new Iteration(*this); }
346 virtual void visit(NodeVisitor &);
349 struct Passthrough: Statement
351 NodePtr<Expression> subscript;
353 virtual Passthrough *clone() const { return new Passthrough(*this); }
354 virtual void visit(NodeVisitor &);
357 struct Return: Statement
359 NodePtr<Expression> expression;
361 virtual Return *clone() const { return new Return(*this); }
362 virtual void visit(NodeVisitor &);
365 struct Jump: Statement
369 virtual Jump *clone() const { return new Jump(*this); }
370 virtual void visit(NodeVisitor &);
386 std::map<std::string, VariableDeclaration *> in_variables;
387 std::map<std::string, VariableDeclaration *> out_variables;
388 std::map<std::string, unsigned> locations;
389 Features required_features;
393 static const char *get_stage_name(Type);
398 SourceMap source_map;
400 std::list<Stage> stages;
409 #pragma pop_macro("interface")