1 #ifndef MSP_GL_SL_SYNTAX_H_
2 #define MSP_GL_SL_SYNTAX_H_
9 #include <msp/core/refptr.h>
11 #include "glsl_error.h"
12 #include "sourcemap.h"
14 #pragma push_macro("interface")
43 static const Operator operators[];
45 static const Operator &get_operator(const std::string &, Type);
60 Node(const Node &) { }
62 Node &operator=(const Node &);
66 virtual Node *clone() const = 0;
67 virtual void visit(NodeVisitor &) = 0;
71 class NodePtr: public RefPtr<T>
75 NodePtr(T *p): RefPtr<T>(p) { }
76 NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
77 NodePtr &operator=(const NodePtr &p) { RefPtr<T>::operator=(p); return *this; }
80 NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
83 NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
87 class NodeContainer: public C
91 NodeContainer(const NodeContainer &);
95 class NodeList: public NodeContainer<std::list<RefPtr<T> > >
99 class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
102 struct StructDeclaration;
103 struct VariableDeclaration;
104 struct InterfaceBlock;
105 struct FunctionDeclaration;
107 struct Statement: Node
114 virtual Statement *clone() const = 0;
119 NodeList<Statement> body;
122 std::map<std::string, VariableDeclaration *> variables;
126 Block(const Block &);
128 virtual Block *clone() const { return new Block(*this); }
129 virtual void visit(NodeVisitor &);
132 struct Expression: Node
134 const Operator *oper;
138 virtual Expression *clone() const = 0;
141 struct Literal: Expression
145 virtual Literal *clone() const { return new Literal(*this); }
146 virtual void visit(NodeVisitor &);
149 struct ParenthesizedExpression: Expression
151 NodePtr<Expression> expression;
153 virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
154 virtual void visit(NodeVisitor &);
157 struct VariableReference: Expression
161 VariableDeclaration *declaration;
164 VariableReference(const VariableReference &);
166 virtual VariableReference *clone() const { return new VariableReference(*this); }
167 virtual void visit(NodeVisitor &);
170 struct InterfaceBlockReference: Expression
174 InterfaceBlock *declaration;
176 InterfaceBlockReference();
177 InterfaceBlockReference(const InterfaceBlockReference &);
179 virtual InterfaceBlockReference *clone() const { return new InterfaceBlockReference(*this); }
180 virtual void visit(NodeVisitor &);
183 struct MemberAccess: Expression
185 NodePtr<Expression> left;
188 VariableDeclaration *declaration;
191 MemberAccess(const MemberAccess &);
193 virtual MemberAccess *clone() const { return new MemberAccess(*this); }
194 virtual void visit(NodeVisitor &);
197 struct UnaryExpression: Expression
199 NodePtr<Expression> expression;
201 virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
202 virtual void visit(NodeVisitor &);
205 struct BinaryExpression: Expression
207 NodePtr<Expression> left;
208 NodePtr<Expression> right;
210 virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
211 virtual void visit(NodeVisitor &);
214 struct Assignment: BinaryExpression
216 bool self_referencing;
218 VariableDeclaration *target_declaration;
221 Assignment(const Assignment &);
223 virtual Assignment *clone() const { return new Assignment(*this); }
224 virtual void visit(NodeVisitor &);
227 struct FunctionCall: Expression
231 NodeArray<Expression> arguments;
233 FunctionDeclaration *declaration;
236 FunctionCall(const FunctionCall &);
238 virtual FunctionCall *clone() const { return new FunctionCall(*this); }
239 virtual void visit(NodeVisitor &);
242 struct ExpressionStatement: Statement
244 NodePtr<Expression> expression;
246 virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
247 virtual void visit(NodeVisitor &);
250 struct Import: Statement
254 virtual Import *clone() const { return new Import(*this); }
255 virtual void visit(NodeVisitor &);
258 struct Precision: Statement
260 std::string precision;
263 virtual Precision *clone() const { return new Precision(*this); }
264 virtual void visit(NodeVisitor &);
276 std::vector<Qualifier> qualifiers;
278 virtual Layout *clone() const { return new Layout(*this); }
279 virtual void visit(NodeVisitor &);
282 struct InterfaceLayout: Statement
284 std::string interface;
287 virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); }
288 virtual void visit(NodeVisitor &);
291 struct StructDeclaration: Statement
298 virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
299 virtual void visit(NodeVisitor &);
302 struct VariableDeclaration: Statement
304 NodePtr<Layout> layout;
306 std::string sampling;
307 std::string interpolation;
308 std::string interface;
309 std::string precision;
313 NodePtr<Expression> array_size;
314 NodePtr<Expression> init_expression;
316 StructDeclaration *type_declaration;
317 VariableDeclaration *linked_declaration;
319 VariableDeclaration();
320 VariableDeclaration(const VariableDeclaration &);
321 ~VariableDeclaration();
323 virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
324 virtual void visit(NodeVisitor &);
327 struct InterfaceBlock: Statement
329 std::string interface;
332 std::string instance_name;
335 InterfaceBlock *linked_block;
338 InterfaceBlock(const InterfaceBlock &);
341 virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
342 virtual void visit(NodeVisitor &);
345 struct FunctionDeclaration: Statement
347 std::string return_type;
349 NodeArray<VariableDeclaration> parameters;
352 FunctionDeclaration *definition;
354 FunctionDeclaration();
355 FunctionDeclaration(const FunctionDeclaration &);
357 virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
358 virtual void visit(NodeVisitor &);
361 struct Conditional: Statement
363 NodePtr<Expression> condition;
367 virtual Conditional *clone() const { return new Conditional(*this); }
368 virtual void visit(NodeVisitor &);
371 struct Iteration: Statement
373 NodePtr<Statement> init_statement;
374 NodePtr<Expression> condition;
375 NodePtr<Expression> loop_expression;
378 virtual Iteration *clone() const { return new Iteration(*this); }
379 virtual void visit(NodeVisitor &);
382 struct Passthrough: Statement
384 NodePtr<Expression> subscript;
386 virtual Passthrough *clone() const { return new Passthrough(*this); }
387 virtual void visit(NodeVisitor &);
390 struct Return: Statement
392 NodePtr<Expression> expression;
394 virtual Return *clone() const { return new Return(*this); }
395 virtual void visit(NodeVisitor &);
398 struct Jump: Statement
402 virtual Jump *clone() const { return new Jump(*this); }
403 virtual void visit(NodeVisitor &);
419 std::map<std::string, StructDeclaration *> types;
420 std::map<std::string, InterfaceBlock *> interface_blocks;
421 std::map<std::string, FunctionDeclaration *> functions;
422 std::map<std::string, unsigned> locations;
423 Features required_features;
424 std::vector<Diagnostic> diagnostics;
428 static const char *get_stage_name(Type);
433 SourceMap source_map;
435 std::list<Stage> stages;
444 #pragma pop_macro("interface")