X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=590429519118614f6a59a83796da97f50693ff9c;hp=089683323c507b81573b0c908163f9b28337de7d;hb=HEAD;hpb=f1c6ef565577ac322693255d764eea1f2cab9e77 diff --git a/source/programsyntax.h b/source/programsyntax.h deleted file mode 100644 index 08968332..00000000 --- a/source/programsyntax.h +++ /dev/null @@ -1,362 +0,0 @@ -#ifndef MSP_GL_PROGRAMSYNTAX_H_ -#define MSP_GL_PROGRAMSYNTAX_H_ - -#include -#include -#include -#include - -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 -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; } -#if __cplusplus>=201103L - NodePtr(NodePtr &&p): node(p.node) { p.node = 0; } - NodePtr &operator=(NodePtr &&p) { delete node; node = p.node; p.node = 0; return *this; } -#endif - ~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 FunctionDeclaration; - -struct Block: Node -{ - std::list > body; - bool use_braces; - std::map types; - std::map 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; - - 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 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; - bool prefix; - - UnaryExpression(); - - virtual UnaryExpression *clone() const { return new UnaryExpression(*this); } - virtual void visit(NodeVisitor &); -}; - -struct BinaryExpression: Expression -{ - NodePtr left; - std::string oper; - NodePtr right; - std::string after; - - virtual BinaryExpression *clone() const { return new BinaryExpression(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Assignment: BinaryExpression -{ - bool self_referencing; - VariableDeclaration *target_declaration; - - Assignment(); - - virtual Assignment *clone() const { return new Assignment(*this); } - virtual void visit(NodeVisitor &); -}; - -struct FunctionCall: Expression -{ - std::string name; - FunctionDeclaration *declaration; - bool constructor; - std::vector > arguments; - - FunctionCall(); - - virtual FunctionCall *clone() const { return new FunctionCall(*this); } - virtual void visit(NodeVisitor &); -}; - -struct ExpressionStatement: Node -{ - NodePtr expression; - - virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Import: Node -{ - std::string module; - - virtual Import *clone() const { return new Import(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Layout: Node -{ - struct Qualifier - { - std::string identifier; - std::string value; - }; - - std::vector 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 array_size; - NodePtr 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; - std::string instance_name; - bool array; - - 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 > parameters; - FunctionDeclaration *definition; - Block body; - - FunctionDeclaration(); - FunctionDeclaration(const FunctionDeclaration &); - - virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Conditional: Node -{ - NodePtr condition; - Block body; - Block else_body; - - virtual Conditional *clone() const { return new Conditional(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Iteration: Node -{ - NodePtr init_statement; - NodePtr condition; - NodePtr loop_expression; - Block body; - - virtual Iteration *clone() const { return new Iteration(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Passthrough: Node -{ - NodePtr subscript; - - virtual Passthrough *clone() const { return new Passthrough(*this); } - virtual void visit(NodeVisitor &); -}; - -struct Return: Node -{ - NodePtr 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(Assignment &); - virtual void visit(FunctionCall &) { } - virtual void visit(ExpressionStatement &) { } - virtual void visit(Import &) { } - 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; - Stage *previous; - ProgramSyntax::Block content; - std::map in_variables; - std::map out_variables; - - Stage(StageType); -}; - -struct Module -{ - Stage shared; - std::list stages; - - Module(); -}; - -} // namespace ProgramSyntax -} // namespace GL -} // namespace Msp - -#endif