]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programsyntax.h
Disable mipmaps from various render target textures
[libs/gl.git] / source / programsyntax.h
index 99ce8b9c1c47ebd20c202042d35218e67cfe17a8..b0ad02b394c480708d1b871173b37cff3c3df6fd 100644 (file)
@@ -1,9 +1,12 @@
 #ifndef MSP_GL_PROGRAMSYNTAX_H_
 #define MSP_GL_PROGRAMSYNTAX_H_
 
+#include <list>
 #include <map>
 #include <string>
 #include <vector>
+#include <msp/core/refptr.h>
+#include "extension.h"
 
 namespace Msp {
 namespace GL {
@@ -23,32 +26,46 @@ 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; }
-       ~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; }
-       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::vector<NodePtr<Node> > body;
+       NodeList<Node> body;
        bool use_braces;
+       std::map<std::string, StructDeclaration *> types;
+       std::map<std::string, VariableDeclaration *> variables;
 
        Block();
 
@@ -80,6 +97,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 &);
@@ -89,6 +109,7 @@ struct MemberAccess: Expression
 {
        NodePtr<Expression> left;
        std::string member;
+       VariableDeclaration *declaration;
 
        virtual MemberAccess *clone() const { return new MemberAccess(*this); }
        virtual void visit(NodeVisitor &);
@@ -112,19 +133,28 @@ struct BinaryExpression: Expression
        std::string oper;
        NodePtr<Expression> 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<NodePtr<Expression> > arguments;
+       NodeArray<Expression> arguments;
 
        FunctionCall();
 
@@ -140,21 +170,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<Qualifier> 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;
@@ -171,11 +227,15 @@ struct VariableDeclaration: Node
        bool constant;
        std::string sampling;
        std::string interface;
+       std::string precision;
        std::string type;
+       StructDeclaration *type_declaration;
        std::string name;
        bool array;
        NodePtr<Expression> array_size;
        NodePtr<Expression> init_expression;
+       VariableDeclaration *linked_declaration;
+       NodePtr<Layout> layout;
 
        VariableDeclaration();
 
@@ -188,6 +248,8 @@ struct InterfaceBlock: Node
        std::string interface;
        std::string name;
        Block members;
+       std::string instance_name;
+       bool array;
 
        InterfaceBlock();
 
@@ -199,11 +261,12 @@ struct FunctionDeclaration: Node
 {
        std::string return_type;
        std::string name;
-       std::vector<NodePtr<VariableDeclaration> > parameters;
-       bool definition;
+       NodeArray<VariableDeclaration> parameters;
+       FunctionDeclaration *definition;
        Block body;
 
        FunctionDeclaration();
+       FunctionDeclaration(const FunctionDeclaration &);
 
        virtual FunctionDeclaration *clone() const { return new FunctionDeclaration(*this); }
        virtual void visit(NodeVisitor &);
@@ -211,7 +274,7 @@ struct FunctionDeclaration: Node
 
 struct Conditional: Node
 {
-       Expression *condition;
+       NodePtr<Expression> condition;
        Block body;
        Block else_body;
 
@@ -230,6 +293,14 @@ struct Iteration: Node
        virtual void visit(NodeVisitor &);
 };
 
+struct Passthrough: Node
+{
+       NodePtr<Expression> subscript;
+
+       virtual Passthrough *clone() const { return new Passthrough(*this); }
+       virtual void visit(NodeVisitor &);
+};
+
 struct Return: Node
 {
        NodePtr<Expression> expression;
@@ -238,6 +309,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() { }
@@ -249,42 +328,70 @@ 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 &) { }
        virtual void visit(FunctionDeclaration &) { }
        virtual void visit(Conditional &) { }
        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 &);
+       virtual void visit(UnaryExpression &);
+       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 &);
+       virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
+       virtual void visit(Passthrough &);
+       virtual void visit(Return &);
 };
 
-enum ContextType
+enum StageType
 {
-       GLOBAL,
+       SHARED,
        VERTEX,
        GEOMETRY,
        FRAGMENT
 };
 
-struct Context
+struct Stage
 {
-       ContextType type;
-       bool present;
+       StageType type;
+       Stage *previous;
        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;
 
-       Context(ContextType);
+       Stage(StageType);
 };
 
 struct Module
 {
-       Context global_context;
-       Context vertex_context;
-       Context geometry_context;
-       Context fragment_context;
-       std::map<std::string, StructDeclaration *> structs;
+       Stage shared;
+       std::list<Stage> stages;
 
        Module();
 };