1 #ifndef MSP_GL_SL_SYNTAX_H_
2 #define MSP_GL_SL_SYNTAX_H_
8 #include <msp/core/refptr.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;
109 std::map<std::string, StructDeclaration *> types;
110 std::map<std::string, VariableDeclaration *> variables;
114 virtual Block *clone() const { return new Block(*this); }
115 virtual void visit(NodeVisitor &);
118 struct Expression: Node
120 virtual Expression *clone() const = 0;
123 struct Literal: Expression
127 virtual Literal *clone() const { return new Literal(*this); }
128 virtual void visit(NodeVisitor &);
131 struct ParenthesizedExpression: Expression
133 NodePtr<Expression> expression;
135 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
136 virtual void visit(NodeVisitor &);
139 struct VariableReference: Expression
142 VariableDeclaration *declaration;
146 virtual VariableReference *clone() const { return new VariableReference(*this); }
147 virtual void visit(NodeVisitor &);
150 struct MemberAccess: Expression
152 NodePtr<Expression> left;
154 VariableDeclaration *declaration;
156 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
157 virtual void visit(NodeVisitor &);
160 struct UnaryExpression: Expression
163 NodePtr<Expression> expression;
168 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
169 virtual void visit(NodeVisitor &);
172 struct BinaryExpression: Expression
174 NodePtr<Expression> left;
176 NodePtr<Expression> right;
179 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
180 virtual void visit(NodeVisitor &);
183 struct Assignment: BinaryExpression
185 bool self_referencing;
186 VariableDeclaration *target_declaration;
190 virtual Assignment *clone() const { return new Assignment(*this); }
191 virtual void visit(NodeVisitor &);
194 struct FunctionCall: Expression
197 FunctionDeclaration *declaration;
199 NodeArray<Expression> arguments;
203 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
204 virtual void visit(NodeVisitor &);
207 struct ExpressionStatement: Statement
209 NodePtr<Expression> expression;
211 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
212 virtual void visit(NodeVisitor &);
215 struct Import: Statement
219 virtual Import *clone() const { return new Import(*this); }
220 virtual void visit(NodeVisitor &);
223 struct Precision: Statement
225 std::string precision;
228 virtual Precision *clone() const { return new Precision(*this); }
229 virtual void visit(NodeVisitor &);
236 // TODO the standard calls this name, not identifier
237 std::string identifier;
241 std::vector<Qualifier> qualifiers;
243 virtual Layout *clone() const { return new Layout(*this); }
244 virtual void visit(NodeVisitor &);
247 struct InterfaceLayout: Statement
249 std::string interface;
252 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
253 virtual void visit(NodeVisitor &);
256 struct StructDeclaration: Statement
263 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
264 virtual void visit(NodeVisitor &);
267 struct VariableDeclaration: Statement
270 std::string sampling;
271 std::string interpolation;
272 std::string interface;
273 std::string precision;
275 StructDeclaration *type_declaration;
278 NodePtr<Expression> array_size;
279 NodePtr<Expression> init_expression;
280 VariableDeclaration *linked_declaration;
281 NodePtr<Layout> layout;
283 VariableDeclaration();
285 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
286 virtual void visit(NodeVisitor &);
289 struct InterfaceBlock: Statement
291 std::string interface;
294 std::string instance_name;
299 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
300 virtual void visit(NodeVisitor &);
303 struct FunctionDeclaration: Statement
305 std::string return_type;
307 NodeArray<VariableDeclaration> parameters;
308 FunctionDeclaration *definition;
311 FunctionDeclaration();
312 FunctionDeclaration(const FunctionDeclaration &);
314 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
315 virtual void visit(NodeVisitor &);
318 struct Conditional: Statement
320 NodePtr<Expression> condition;
324 virtual Conditional *clone() const { return new Conditional(*this); }
325 virtual void visit(NodeVisitor &);
328 struct Iteration: Statement
330 NodePtr<Node> init_statement;
331 NodePtr<Expression> condition;
332 NodePtr<Expression> loop_expression;
335 virtual Iteration *clone() const { return new Iteration(*this); }
336 virtual void visit(NodeVisitor &);
339 struct Passthrough: Statement
341 NodePtr<Expression> subscript;
343 virtual Passthrough *clone() const { return new Passthrough(*this); }
344 virtual void visit(NodeVisitor &);
347 struct Return: Statement
349 NodePtr<Expression> expression;
351 virtual Return *clone() const { return new Return(*this); }
352 virtual void visit(NodeVisitor &);
355 struct Jump: Statement
359 virtual Jump *clone() const { return new Jump(*this); }
360 virtual void visit(NodeVisitor &);
376 std::map<std::string, VariableDeclaration *> in_variables;
377 std::map<std::string, VariableDeclaration *> out_variables;
378 std::map<std::string, unsigned> locations;
379 Version required_version;
380 std::vector<const Extension *> required_extensions;
388 std::list<Stage> stages;
397 #pragma pop_macro("interface")