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;
111 std::map<std::string, StructDeclaration *> types;
112 std::map<std::string, VariableDeclaration *> variables;
116 Block(const Block &);
118 virtual Block *clone() const { return new Block(*this); }
119 virtual void visit(NodeVisitor &);
122 struct Expression: Node
124 virtual Expression *clone() const = 0;
127 struct Literal: Expression
131 virtual Literal *clone() const { return new Literal(*this); }
132 virtual void visit(NodeVisitor &);
135 struct ParenthesizedExpression: Expression
137 NodePtr<Expression> expression;
139 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
140 virtual void visit(NodeVisitor &);
143 struct VariableReference: Expression
146 VariableDeclaration *declaration;
149 VariableReference(const VariableReference &);
151 virtual VariableReference *clone() const { return new VariableReference(*this); }
152 virtual void visit(NodeVisitor &);
155 struct MemberAccess: Expression
157 NodePtr<Expression> left;
159 VariableDeclaration *declaration;
162 MemberAccess(const MemberAccess &);
164 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
165 virtual void visit(NodeVisitor &);
168 struct UnaryExpression: Expression
171 NodePtr<Expression> expression;
176 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
177 virtual void visit(NodeVisitor &);
180 struct BinaryExpression: Expression
182 NodePtr<Expression> left;
184 NodePtr<Expression> right;
187 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
188 virtual void visit(NodeVisitor &);
191 struct Assignment: BinaryExpression
193 bool self_referencing;
194 VariableDeclaration *target_declaration;
197 Assignment(const Assignment &);
199 virtual Assignment *clone() const { return new Assignment(*this); }
200 virtual void visit(NodeVisitor &);
203 struct FunctionCall: Expression
206 FunctionDeclaration *declaration;
208 NodeArray<Expression> arguments;
211 FunctionCall(const FunctionCall &);
213 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
214 virtual void visit(NodeVisitor &);
217 struct ExpressionStatement: Statement
219 NodePtr<Expression> expression;
221 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
222 virtual void visit(NodeVisitor &);
225 struct Import: Statement
229 virtual Import *clone() const { return new Import(*this); }
230 virtual void visit(NodeVisitor &);
233 struct Precision: Statement
235 std::string precision;
238 virtual Precision *clone() const { return new Precision(*this); }
239 virtual void visit(NodeVisitor &);
246 // TODO the standard calls this name, not identifier
247 std::string identifier;
251 std::vector<Qualifier> qualifiers;
253 virtual Layout *clone() const { return new Layout(*this); }
254 virtual void visit(NodeVisitor &);
257 struct InterfaceLayout: Statement
259 std::string interface;
262 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
263 virtual void visit(NodeVisitor &);
266 struct StructDeclaration: Statement
273 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
274 virtual void visit(NodeVisitor &);
277 struct VariableDeclaration: Statement
280 std::string sampling;
281 std::string interpolation;
282 std::string interface;
283 std::string precision;
285 StructDeclaration *type_declaration;
288 NodePtr<Expression> array_size;
289 NodePtr<Expression> init_expression;
290 VariableDeclaration *linked_declaration;
291 NodePtr<Layout> layout;
293 VariableDeclaration();
294 VariableDeclaration(const VariableDeclaration &);
296 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
297 virtual void visit(NodeVisitor &);
300 struct InterfaceBlock: Statement
302 std::string interface;
305 std::string instance_name;
310 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
311 virtual void visit(NodeVisitor &);
314 struct FunctionDeclaration: Statement
316 std::string return_type;
318 NodeArray<VariableDeclaration> parameters;
319 FunctionDeclaration *definition;
322 FunctionDeclaration();
323 FunctionDeclaration(const FunctionDeclaration &);
325 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
326 virtual void visit(NodeVisitor &);
329 struct Conditional: Statement
331 NodePtr<Expression> condition;
335 virtual Conditional *clone() const { return new Conditional(*this); }
336 virtual void visit(NodeVisitor &);
339 struct Iteration: Statement
341 NodePtr<Node> init_statement;
342 NodePtr<Expression> condition;
343 NodePtr<Expression> loop_expression;
346 virtual Iteration *clone() const { return new Iteration(*this); }
347 virtual void visit(NodeVisitor &);
350 struct Passthrough: Statement
352 NodePtr<Expression> subscript;
354 virtual Passthrough *clone() const { return new Passthrough(*this); }
355 virtual void visit(NodeVisitor &);
358 struct Return: Statement
360 NodePtr<Expression> expression;
362 virtual Return *clone() const { return new Return(*this); }
363 virtual void visit(NodeVisitor &);
366 struct Jump: Statement
370 virtual Jump *clone() const { return new Jump(*this); }
371 virtual void visit(NodeVisitor &);
387 std::map<std::string, VariableDeclaration *> in_variables;
388 std::map<std::string, VariableDeclaration *> out_variables;
389 std::map<std::string, unsigned> locations;
390 Version required_version;
391 std::vector<const Extension *> required_extensions;
395 static const char *get_stage_name(Type);
400 SourceMap source_map;
402 std::list<Stage> stages;
411 #pragma pop_macro("interface")