X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=14e5d8e786cb679e36c448cf5ca68b1dfe387fd3;hp=089683323c507b81573b0c908163f9b28337de7d;hb=6a045019fbd68738b77849629e6dfd3dfd9a4d93;hpb=f1c6ef565577ac322693255d764eea1f2cab9e77 diff --git a/source/programsyntax.h b/source/programsyntax.h index 08968332..14e5d8e7 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include "extension.h" namespace Msp { namespace GL { @@ -24,39 +26,43 @@ public: }; template -class NodePtr +class NodePtr: public RefPtr { -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; } + NodePtr() { } + NodePtr(T *p): RefPtr(p) { } + NodePtr(const NodePtr &p): RefPtr(p ? p->clone() : 0) { } -private: - static T *clone(T *n) { return n ? n->clone() : 0; } + template + NodePtr(const RefPtr &p): RefPtr(p) { } + template + NodePtr(const NodePtr &p): RefPtr(p ? p->clone() : 0) { } +}; + +template +class NodeContainer: public C +{ 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; } + NodeContainer() { } + NodeContainer(const NodeContainer &); }; +template +class NodeList: public NodeContainer > > +{ }; + +template +class NodeArray: public NodeContainer > > +{ }; + struct StructDeclaration; struct VariableDeclaration; struct FunctionDeclaration; struct Block: Node { - std::list > body; + NodeList body; bool use_braces; std::map types; std::map variables; @@ -148,7 +154,7 @@ struct FunctionCall: Expression std::string name; FunctionDeclaration *declaration; bool constructor; - std::vector > arguments; + NodeArray arguments; FunctionCall(); @@ -181,12 +187,20 @@ struct Layout: Node }; std::vector qualifiers; - std::string interface; virtual Layout *clone() const { return new Layout(*this); } virtual void visit(NodeVisitor &); }; +struct InterfaceLayout: Node +{ + std::string interface; + Layout layout; + + virtual InterfaceLayout *clone() const { return new InterfaceLayout(*this); } + virtual void visit(NodeVisitor &); +}; + struct StructDeclaration: Node { std::string name; @@ -210,6 +224,7 @@ struct VariableDeclaration: Node NodePtr array_size; NodePtr init_expression; VariableDeclaration *linked_declaration; + NodePtr layout; VariableDeclaration(); @@ -235,7 +250,7 @@ struct FunctionDeclaration: Node { std::string return_type; std::string name; - std::vector > parameters; + NodeArray parameters; FunctionDeclaration *definition; Block body; @@ -299,6 +314,7 @@ struct NodeVisitor virtual void visit(ExpressionStatement &) { } virtual void visit(Import &) { } virtual void visit(Layout &) { } + virtual void visit(InterfaceLayout &) { } virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &) { } virtual void visit(InterfaceBlock &) { } @@ -318,6 +334,7 @@ struct TraversingVisitor: NodeVisitor virtual void visit(BinaryExpression &); virtual void visit(FunctionCall &); virtual void visit(ExpressionStatement &); + virtual void visit(InterfaceLayout &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); @@ -343,6 +360,8 @@ struct Stage ProgramSyntax::Block content; std::map in_variables; std::map out_variables; + std::map locations; + Version required_version; Stage(StageType); };