X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramsyntax.h;h=6a03f40fab67b2f4b02d17de5873587edf1d3e88;hp=88f333ac1559d2e662dbaeca7903aecfbdbfa1ed;hb=d901696935a6bf9fdad6ac8abe65ffab79bd297d;hpb=5945ad9b63bbc55c3ed21f0c023d17f73aaac370 diff --git a/source/programsyntax.h b/source/programsyntax.h index 88f333ac..6a03f40f 100644 --- a/source/programsyntax.h +++ b/source/programsyntax.h @@ -5,6 +5,12 @@ #include #include #include +#include +#include "extension.h" +#include "uniform.h" + +#pragma push_macro("interface") +#undef interface namespace Msp { namespace GL { @@ -24,38 +30,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; @@ -126,19 +137,28 @@ struct BinaryExpression: Expression std::string oper; NodePtr right; std::string after; - bool assignment; - - BinaryExpression(); 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; + NodeArray arguments; FunctionCall(); @@ -154,21 +174,47 @@ struct ExpressionStatement: Node virtual void visit(NodeVisitor &); }; +struct Import: Node +{ + std::string module; + + virtual Import *clone() const { return new Import(*this); } + virtual void visit(NodeVisitor &); +}; + +struct Precision: Node +{ + 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; }; 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; @@ -184,7 +230,9 @@ struct VariableDeclaration: Node { bool constant; std::string sampling; + std::string interpolation; std::string interface; + std::string precision; std::string type; StructDeclaration *type_declaration; std::string name; @@ -192,6 +240,7 @@ struct VariableDeclaration: Node NodePtr array_size; NodePtr init_expression; VariableDeclaration *linked_declaration; + NodePtr layout; VariableDeclaration(); @@ -217,11 +266,12 @@ struct FunctionDeclaration: Node { std::string return_type; std::string name; - std::vector > parameters; - bool definition; + NodeArray parameters; + FunctionDeclaration *definition; Block body; FunctionDeclaration(); + FunctionDeclaration(const FunctionDeclaration &); virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); } virtual void visit(NodeVisitor &); @@ -264,6 +314,14 @@ struct Return: Node virtual void visit(NodeVisitor &); }; +struct Jump: Node +{ + std::string keyword; + + virtual Jump *clone() const { return new Jump(*this); } + virtual void visit(NodeVisitor &); +}; + struct NodeVisitor { virtual ~NodeVisitor() { } @@ -275,9 +333,13 @@ struct NodeVisitor 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(Precision &) { } virtual void visit(Layout &) { } + virtual void visit(InterfaceLayout &) { } virtual void visit(StructDeclaration &) { } virtual void visit(VariableDeclaration &) { } virtual void visit(InterfaceBlock &) { } @@ -286,10 +348,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 &); @@ -297,6 +361,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 &); @@ -322,6 +387,8 @@ struct Stage ProgramSyntax::Block content; std::map in_variables; std::map out_variables; + std::map locations; + Version required_version; Stage(StageType); }; @@ -338,4 +405,6 @@ struct Module } // namespace GL } // namespace Msp +#pragma pop_macro("interface") + #endif