X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=88f333ac1559d2e662dbaeca7903aecfbdbfa1ed;hb=5945ad9b63bbc55c3ed21f0c023d17f73aaac370;hp=8f72a0bdfc7258a4af9bdb048e0aad114b4a83a2;hpb=70f9fe2964700fc199ab3cabb26f9b14d078c56b;p=libs%2Fgl.git diff --git a/source/programsyntax.h b/source/programsyntax.h index 8f72a0bd..88f333ac 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -33,6 +33,10 @@ 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: @@ -41,15 +45,20 @@ private: 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 > body; bool use_braces; + std::map types; + std::map variables; Block(); @@ -81,6 +90,9 @@ struct ParenthesizedExpression: Expression struct VariableReference: Expression { std::string name; + VariableDeclaration *declaration; + + VariableReference(); virtual VariableReference *clone() const { return new VariableReference(*this); } virtual void visit(NodeVisitor &); @@ -90,6 +102,7 @@ struct MemberAccess: Expression { NodePtr left; std::string member; + VariableDeclaration *declaration; virtual MemberAccess *clone() const { return new MemberAccess(*this); } virtual void visit(NodeVisitor &); @@ -173,10 +186,12 @@ struct VariableDeclaration: Node 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(); @@ -189,6 +204,8 @@ struct InterfaceBlock: Node std::string interface; std::string name; Block members; + std::string instance_name; + bool array; InterfaceBlock(); @@ -212,7 +229,7 @@ struct FunctionDeclaration: Node struct Conditional: Node { - Expression *condition; + NodePtr condition; Block body; Block else_body; @@ -231,6 +248,14 @@ struct Iteration: Node 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; @@ -259,33 +284,52 @@ struct NodeVisitor virtual void visit(FunctionDeclaration &) { } virtual void visit(Conditional &) { } virtual void visit(Iteration &) { } + virtual void visit(Passthrough &) { } virtual void visit(Return &) { } }; -enum ContextType +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 { - GLOBAL, + SHARED, VERTEX, GEOMETRY, FRAGMENT }; -struct Context +struct Stage { - ContextType type; - bool present; + StageType type; + Stage *previous; ProgramSyntax::Block content; + std::map in_variables; + std::map out_variables; - Context(ContextType); + Stage(StageType); }; struct Module { - Context global_context; - Context vertex_context; - Context geometry_context; - Context fragment_context; - std::map structs; + Stage shared; + std::list stages; Module(); };