]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programsyntax.h
Add overloads of keyframe uniform statements without size suffixes
[libs/gl.git] / source / programsyntax.h
index 796c4b938f10f6f84eb1fbcdcdd0c3fd9bd6f062..6a03f40fab67b2f4b02d17de5873587edf1d3e88 100644 (file)
@@ -5,7 +5,12 @@
 #include <map>
 #include <string>
 #include <vector>
+#include <msp/core/refptr.h>
 #include "extension.h"
+#include "uniform.h"
+
+#pragma push_macro("interface")
+#undef interface
 
 namespace Msp {
 namespace GL {
@@ -25,39 +30,43 @@ public:
 };
 
 template<typename T>
-class NodePtr
+class NodePtr: public RefPtr<T>
 {
-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<T>(p) { }
+       NodePtr(const NodePtr &p): RefPtr<T>(p ? p->clone() : 0) { }
 
-private:
-       static T *clone(T *n) { return n ? n->clone() : 0; }
+       template<typename U>
+       NodePtr(const RefPtr<U> &p): RefPtr<T>(p) { }
+
+       template<typename U>
+       NodePtr(const NodePtr<U> &p): RefPtr<T>(p ? p->clone() : 0) { }
+};
 
+template<typename C>
+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<typename T>
+class NodeList: public NodeContainer<std::list<RefPtr<T> > >
+{ };
+
+template<typename T>
+class NodeArray: public NodeContainer<std::vector<RefPtr<T> > >
+{ };
+
 struct StructDeclaration;
 struct VariableDeclaration;
 struct FunctionDeclaration;
 
 struct Block: Node
 {
-       std::list<NodePtr<Node> > body;
+       NodeList<Node> body;
        bool use_braces;
        std::map<std::string, StructDeclaration *> types;
        std::map<std::string, VariableDeclaration *> variables;
@@ -149,7 +158,7 @@ struct FunctionCall: Expression
        std::string name;
        FunctionDeclaration *declaration;
        bool constructor;
-       std::vector<NodePtr<Expression> > arguments;
+       NodeArray<Expression> arguments;
 
        FunctionCall();
 
@@ -173,10 +182,20 @@ struct Import: Node
        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;
        };
@@ -211,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;
@@ -245,7 +266,7 @@ struct FunctionDeclaration: Node
 {
        std::string return_type;
        std::string name;
-       std::vector<NodePtr<VariableDeclaration> > parameters;
+       NodeArray<VariableDeclaration> parameters;
        FunctionDeclaration *definition;
        Block body;
 
@@ -293,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() { }
@@ -308,6 +337,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 +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 &);
@@ -355,6 +387,7 @@ struct Stage
        ProgramSyntax::Block content;
        std::map<std::string, VariableDeclaration *> in_variables;
        std::map<std::string, VariableDeclaration *> out_variables;
+       std::map<std::string, unsigned> locations;
        Version required_version;
 
        Stage(StageType);
@@ -372,4 +405,6 @@ struct Module
 } // namespace GL
 } // namespace Msp
 
+#pragma pop_macro("interface")
+
 #endif