+++ /dev/null
-#ifndef MSP_GL_PROGRAMSYNTAX_H_
-#define MSP_GL_PROGRAMSYNTAX_H_
-
-#include <list>
-#include <map>
-#include <string>
-#include <vector>
-
-namespace Msp {
-namespace GL {
-namespace ProgramSyntax {
-
-struct NodeVisitor;
-
-struct Node
-{
-private:
- Node &operator=(const Node &);
-public:
- virtual ~Node() { }
-
- virtual Node *clone() const = 0;
- virtual void visit(NodeVisitor &) = 0;
-};
-
-template<typename T>
-class NodePtr
-{
-private:
- T *node;
-
-public:
- NodePtr(T *n = 0): node(n) { }
- NodePtr(const NodePtr &p): node(clone(p.node)) { }
- NodePtr &operator=(const NodePtr &p) { delete node; node = clone(p.node); return *this; }
- ~NodePtr() { delete node; }
-
-private:
- static T *clone(T *n) { return n ? n->clone() : 0; }
-
-public:
- T *operator->() { return node; }
- const T *operator->() const { return node; }
- T &operator*() { return *node; }
- const T &operator*() const { return *node; }
- operator void *() const { return node; }
-};
-
-struct StructDeclaration;
-struct VariableDeclaration;
-
-struct Block: Node
-{
- std::list<NodePtr<Node> > body;
- bool use_braces;
- std::map<std::string, StructDeclaration *> types;
- std::map<std::string, VariableDeclaration *> variables;
-
- Block();
-
- virtual Block *clone() const { return new Block(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Expression: Node
-{
- virtual Expression *clone() const = 0;
-};
-
-struct Literal: Expression
-{
- std::string token;
-
- virtual Literal *clone() const { return new Literal(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct ParenthesizedExpression: Expression
-{
- NodePtr<Expression> expression;
-
- virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct VariableReference: Expression
-{
- std::string name;
- VariableDeclaration *declaration;
-
- VariableReference();
-
- virtual VariableReference *clone() const { return new VariableReference(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct MemberAccess: Expression
-{
- NodePtr<Expression> left;
- std::string member;
- VariableDeclaration *declaration;
-
- virtual MemberAccess *clone() const { return new MemberAccess(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct UnaryExpression: Expression
-{
- std::string oper;
- NodePtr<Expression> expression;
- bool prefix;
-
- UnaryExpression();
-
- virtual UnaryExpression *clone() const { return new UnaryExpression(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct BinaryExpression: Expression
-{
- NodePtr<Expression> left;
- std::string oper;
- NodePtr<Expression> right;
- std::string after;
- bool assignment;
-
- BinaryExpression();
-
- virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct FunctionCall: Expression
-{
- std::string name;
- bool constructor;
- std::vector<NodePtr<Expression> > arguments;
-
- FunctionCall();
-
- virtual FunctionCall *clone() const { return new FunctionCall(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct ExpressionStatement: Node
-{
- NodePtr<Expression> expression;
-
- virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Layout: Node
-{
- struct Qualifier
- {
- std::string identifier;
- std::string value;
- };
-
- std::vector<Qualifier> qualifiers;
- std::string interface;
-
- virtual Layout *clone() const { return new Layout(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct StructDeclaration: Node
-{
- std::string name;
- Block members;
-
- StructDeclaration();
-
- virtual StructDeclaration *clone() const { return new StructDeclaration(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct VariableDeclaration: Node
-{
- bool constant;
- std::string sampling;
- std::string interface;
- std::string type;
- StructDeclaration *type_declaration;
- std::string name;
- bool array;
- NodePtr<Expression> array_size;
- NodePtr<Expression> init_expression;
- VariableDeclaration *linked_declaration;
-
- VariableDeclaration();
-
- virtual VariableDeclaration *clone() const { return new VariableDeclaration(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct InterfaceBlock: Node
-{
- std::string interface;
- std::string name;
- Block members;
-
- InterfaceBlock();
-
- virtual InterfaceBlock *clone() const { return new InterfaceBlock(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct FunctionDeclaration: Node
-{
- std::string return_type;
- std::string name;
- std::vector<NodePtr<VariableDeclaration> > parameters;
- bool definition;
- Block body;
-
- FunctionDeclaration();
-
- virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Conditional: Node
-{
- Expression *condition;
- Block body;
- Block else_body;
-
- virtual Conditional *clone() const { return new Conditional(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Iteration: Node
-{
- NodePtr<Node> init_statement;
- NodePtr<Expression> condition;
- NodePtr<Expression> loop_expression;
- Block body;
-
- virtual Iteration *clone() const { return new Iteration(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Passthrough: Node
-{
- NodePtr<Expression> subscript;
-
- virtual Passthrough *clone() const { return new Passthrough(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct Return: Node
-{
- NodePtr<Expression> expression;
-
- virtual Return *clone() const { return new Return(*this); }
- virtual void visit(NodeVisitor &);
-};
-
-struct NodeVisitor
-{
- virtual ~NodeVisitor() { }
-
- virtual void visit(Block &) { }
- virtual void visit(Literal &) { }
- virtual void visit(ParenthesizedExpression &) { }
- virtual void visit(VariableReference &) { }
- virtual void visit(MemberAccess &) { }
- virtual void visit(UnaryExpression &) { }
- virtual void visit(BinaryExpression &) { }
- virtual void visit(FunctionCall &) { }
- virtual void visit(ExpressionStatement &) { }
- virtual void visit(Layout &) { }
- virtual void visit(StructDeclaration &) { }
- virtual void visit(VariableDeclaration &) { }
- virtual void visit(InterfaceBlock &) { }
- virtual void visit(FunctionDeclaration &) { }
- virtual void visit(Conditional &) { }
- virtual void visit(Iteration &) { }
- virtual void visit(Passthrough &) { }
- virtual void visit(Return &) { }
-};
-
-struct TraversingVisitor: NodeVisitor
-{
- virtual void visit(Block &);
- virtual void visit(ParenthesizedExpression &);
- virtual void visit(MemberAccess &);
- virtual void visit(UnaryExpression &);
- virtual void visit(BinaryExpression &);
- virtual void visit(FunctionCall &);
- virtual void visit(ExpressionStatement &);
- virtual void visit(StructDeclaration &);
- virtual void visit(VariableDeclaration &);
- virtual void visit(InterfaceBlock &);
- virtual void visit(FunctionDeclaration &);
- virtual void visit(Conditional &);
- virtual void visit(Iteration &);
- virtual void visit(Passthrough &);
- virtual void visit(Return &);
-};
-
-enum StageType
-{
- SHARED,
- VERTEX,
- GEOMETRY,
- FRAGMENT
-};
-
-struct Stage
-{
- StageType type;
- bool present;
- Stage *previous;
- ProgramSyntax::Block content;
- std::map<std::string, VariableDeclaration *> in_variables;
- std::map<std::string, VariableDeclaration *> out_variables;
-
- Stage(StageType);
-};
-
-struct Module
-{
- Stage shared;
- Stage vertex_stage;
- Stage geometry_stage;
- Stage fragment_stage;
-
- Module();
-};
-
-} // namespace ProgramSyntax
-} // namespace GL
-} // namespace Msp
-
-#endif