]> 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 9a0cc6ea3f4bc8c867a2d381494b816b937495eb..b0ad02b394c480708d1b871173b37cff3c3df6fd 100644 (file)
@@ -25,13 +25,44 @@ public:
        virtual void visit(NodeVisitor &) = 0;
 };
 
+template<typename T>
+class NodePtr: public RefPtr<T>
+{
+public:
+       NodePtr() { }
+       NodePtr(T *p): RefPtr<T>(p) { }
+       NodePtr(const NodePtr &p): RefPtr<T>(p ? p->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:
+       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<RefPtr<Node> > body;
+       NodeList<Node> body;
        bool use_braces;
        std::map<std::string, StructDeclaration *> types;
        std::map<std::string, VariableDeclaration *> variables;
@@ -57,7 +88,7 @@ struct Literal: Expression
 
 struct ParenthesizedExpression: Expression
 {
-       RefPtr<Expression> expression;
+       NodePtr<Expression> expression;
 
        virtual ParenthesizedExpression *clone() const { return new ParenthesizedExpression(*this); }
        virtual void visit(NodeVisitor &);
@@ -76,7 +107,7 @@ struct VariableReference: Expression
 
 struct MemberAccess: Expression
 {
-       RefPtr<Expression> left;
+       NodePtr<Expression> left;
        std::string member;
        VariableDeclaration *declaration;
 
@@ -87,7 +118,7 @@ struct MemberAccess: Expression
 struct UnaryExpression: Expression
 {
        std::string oper;
-       RefPtr<Expression> expression;
+       NodePtr<Expression> expression;
        bool prefix;
 
        UnaryExpression();
@@ -98,9 +129,9 @@ struct UnaryExpression: Expression
 
 struct BinaryExpression: Expression
 {
-       RefPtr<Expression> left;
+       NodePtr<Expression> left;
        std::string oper;
-       RefPtr<Expression> right;
+       NodePtr<Expression> right;
        std::string after;
 
        virtual BinaryExpression *clone() const { return new BinaryExpression(*this); }
@@ -123,7 +154,7 @@ struct FunctionCall: Expression
        std::string name;
        FunctionDeclaration *declaration;
        bool constructor;
-       std::vector<RefPtr<Expression> > arguments;
+       NodeArray<Expression> arguments;
 
        FunctionCall();
 
@@ -133,7 +164,7 @@ struct FunctionCall: Expression
 
 struct ExpressionStatement: Node
 {
-       RefPtr<Expression> expression;
+       NodePtr<Expression> expression;
 
        virtual ExpressionStatement *clone() const { return new ExpressionStatement(*this); }
        virtual void visit(NodeVisitor &);
@@ -147,10 +178,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;
        };
@@ -186,14 +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;
-       RefPtr<Expression> array_size;
-       RefPtr<Expression> init_expression;
+       NodePtr<Expression> array_size;
+       NodePtr<Expression> init_expression;
        VariableDeclaration *linked_declaration;
-       RefPtr<Layout> layout;
+       NodePtr<Layout> layout;
 
        VariableDeclaration();
 
@@ -219,7 +261,7 @@ struct FunctionDeclaration: Node
 {
        std::string return_type;
        std::string name;
-       std::vector<RefPtr<VariableDeclaration> > parameters;
+       NodeArray<VariableDeclaration> parameters;
        FunctionDeclaration *definition;
        Block body;
 
@@ -232,7 +274,7 @@ struct FunctionDeclaration: Node
 
 struct Conditional: Node
 {
-       RefPtr<Expression> condition;
+       NodePtr<Expression> condition;
        Block body;
        Block else_body;
 
@@ -242,9 +284,9 @@ struct Conditional: Node
 
 struct Iteration: Node
 {
-       RefPtr<Node> init_statement;
-       RefPtr<Expression> condition;
-       RefPtr<Expression> loop_expression;
+       NodePtr<Node> init_statement;
+       NodePtr<Expression> condition;
+       NodePtr<Expression> loop_expression;
        Block body;
 
        virtual Iteration *clone() const { return new Iteration(*this); }
@@ -253,7 +295,7 @@ struct Iteration: Node
 
 struct Passthrough: Node
 {
-       RefPtr<Expression> subscript;
+       NodePtr<Expression> subscript;
 
        virtual Passthrough *clone() const { return new Passthrough(*this); }
        virtual void visit(NodeVisitor &);
@@ -261,12 +303,20 @@ struct Passthrough: Node
 
 struct Return: Node
 {
-       RefPtr<Expression> expression;
+       NodePtr<Expression> expression;
 
        virtual Return *clone() const { return new Return(*this); }
        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() { }
@@ -282,6 +332,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 &) { }
@@ -292,10 +343,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 &);