X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=590429519118614f6a59a83796da97f50693ff9c;hp=c502ba47a90f32701bc885e44006ff48a8d93c24;hb=56beca9d8b4f7b4edac81411d31e24df88e84ac3;hpb=48e37a09b49cd4148db390170cfd07eef92c9d02 diff --git a/source/programsyntax.h b/source/programsyntax.h index c502ba47..59042951 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,7 +5,12 @@ #include #include #include +#include #include "extension.h" +#include "uniform.h" + +#pragma push_macro("interface") +#undef interface namespace Msp { namespace GL { @@ -25,39 +30,53 @@ 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 Statement: Node +{ + unsigned source; + unsigned line; + + Statement(); + + virtual Statement *clone() const = 0; +}; + struct Block: Node { - std::list > body; + NodeList body; bool use_braces; std::map types; std::map variables; @@ -149,7 +168,7 @@ struct FunctionCall: Expression std::string name; FunctionDeclaration *declaration; bool constructor; - std::vector > arguments; + NodeArray arguments; FunctionCall(); @@ -157,7 +176,7 @@ struct FunctionCall: Expression virtual void visit(NodeVisitor &); }; -struct ExpressionStatement: Node +struct ExpressionStatement: Statement { NodePtr expression; @@ -165,7 +184,7 @@ struct ExpressionStatement: Node virtual void visit(NodeVisitor &); }; -struct Import: Node +struct Import: Statement { std::string module; @@ -173,10 +192,20 @@ struct Import: Node virtual void visit(NodeVisitor &); }; +struct Precision: Statement +{ + std::string precision; + std::string type; + + virtual Precision *clone() const { return new Precision(*this); } + virtual void visit(NodeVisitor &); +}; + struct Layout: Node { struct Qualifier { + // TODO the standard calls this name, not identifier std::string identifier; std::string value; }; @@ -187,7 +216,7 @@ struct Layout: Node virtual void visit(NodeVisitor &); }; -struct InterfaceLayout: Node +struct InterfaceLayout: Statement { std::string interface; Layout layout; @@ -196,7 +225,7 @@ struct InterfaceLayout: Node virtual void visit(NodeVisitor &); }; -struct StructDeclaration: Node +struct StructDeclaration: Statement { std::string name; Block members; @@ -207,11 +236,13 @@ struct StructDeclaration: Node virtual void visit(NodeVisitor &); }; -struct VariableDeclaration: Node +struct VariableDeclaration: Statement { bool constant; std::string sampling; + std::string interpolation; std::string interface; + std::string precision; std::string type; StructDeclaration *type_declaration; std::string name; @@ -227,7 +258,7 @@ struct VariableDeclaration: Node virtual void visit(NodeVisitor &); }; -struct InterfaceBlock: Node +struct InterfaceBlock: Statement { std::string interface; std::string name; @@ -241,11 +272,11 @@ struct InterfaceBlock: Node virtual void visit(NodeVisitor &); }; -struct FunctionDeclaration: Node +struct FunctionDeclaration: Statement { std::string return_type; std::string name; - std::vector > parameters; + NodeArray parameters; FunctionDeclaration *definition; Block body; @@ -256,7 +287,7 @@ struct FunctionDeclaration: Node virtual void visit(NodeVisitor &); }; -struct Conditional: Node +struct Conditional: Statement { NodePtr condition; Block body; @@ -266,7 +297,7 @@ struct Conditional: Node virtual void visit(NodeVisitor &); }; -struct Iteration: Node +struct Iteration: Statement { NodePtr init_statement; NodePtr condition; @@ -277,7 +308,7 @@ struct Iteration: Node virtual void visit(NodeVisitor &); }; -struct Passthrough: Node +struct Passthrough: Statement { NodePtr subscript; @@ -285,7 +316,7 @@ struct Passthrough: Node virtual void visit(NodeVisitor &); }; -struct Return: Node +struct Return: Statement { NodePtr expression; @@ -293,6 +324,14 @@ struct Return: Node virtual void visit(NodeVisitor &); }; +struct Jump: Statement +{ + std::string keyword; + + virtual Jump *clone() const { return new Jump(*this); } + virtual void visit(NodeVisitor &); +}; + struct NodeVisitor { virtual ~NodeVisitor() { } @@ -308,6 +347,7 @@ struct NodeVisitor virtual void visit(FunctionCall &) { } virtual void visit(ExpressionStatement &) { } virtual void visit(Import &) { } + virtual void visit(Precision &) { } virtual void visit(Layout &) { } virtual void visit(InterfaceLayout &) { } virtual void visit(StructDeclaration &) { } @@ -318,10 +358,12 @@ struct NodeVisitor virtual void visit(Iteration &) { } virtual void visit(Passthrough &) { } virtual void visit(Return &) { } + virtual void visit(Jump &) { } }; struct TraversingVisitor: NodeVisitor { + using NodeVisitor::visit; virtual void visit(Block &); virtual void visit(ParenthesizedExpression &); virtual void visit(MemberAccess &); @@ -357,6 +399,7 @@ struct Stage std::map out_variables; std::map locations; Version required_version; + std::vector required_extensions; Stage(StageType); }; @@ -373,4 +416,6 @@ struct Module } // namespace GL } // namespace Msp +#pragma pop_macro("interface") + #endif