]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programsyntax.h
Add an intermediate node type for statements
[libs/gl.git] / source / programsyntax.h
index b72d401d1ffc1b81ccf2f70affc7e39250e8c147..3db059c4f4d79c4e6252537c5a1cfc27b90e223e 100644 (file)
@@ -7,6 +7,10 @@
 #include <vector>
 #include <msp/core/refptr.h>
 #include "extension.h"
+#include "uniform.h"
+
+#pragma push_macro("interface")
+#undef interface
 
 namespace Msp {
 namespace GL {
@@ -60,9 +64,14 @@ struct StructDeclaration;
 struct VariableDeclaration;
 struct FunctionDeclaration;
 
+struct Statement: Node
+{
+       virtual Statement *clone() const = 0;
+};
+
 struct Block: Node
 {
-       NodeList<Node> body;
+       NodeList<Statement> body;
        bool use_braces;
        std::map<std::string, StructDeclaration *> types;
        std::map<std::string, VariableDeclaration *> variables;
@@ -162,7 +171,7 @@ struct FunctionCall: Expression
        virtual void visit(NodeVisitor &);
 };
 
-struct ExpressionStatement: Node
+struct ExpressionStatement: Statement
 {
        NodePtr<Expression> expression;
 
@@ -170,7 +179,7 @@ struct ExpressionStatement: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Import: Node
+struct Import: Statement
 {
        std::string module;
 
@@ -178,10 +187,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;
        };
@@ -192,7 +211,7 @@ struct Layout: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct InterfaceLayout: Node
+struct InterfaceLayout: Statement
 {
        std::string interface;
        Layout layout;
@@ -201,7 +220,7 @@ struct InterfaceLayout: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct StructDeclaration: Node
+struct StructDeclaration: Statement
 {
        std::string name;
        Block members;
@@ -212,11 +231,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;
@@ -232,7 +253,7 @@ struct VariableDeclaration: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct InterfaceBlock: Node
+struct InterfaceBlock: Statement
 {
        std::string interface;
        std::string name;
@@ -246,7 +267,7 @@ struct InterfaceBlock: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct FunctionDeclaration: Node
+struct FunctionDeclaration: Statement
 {
        std::string return_type;
        std::string name;
@@ -261,7 +282,7 @@ struct FunctionDeclaration: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Conditional: Node
+struct Conditional: Statement
 {
        NodePtr<Expression> condition;
        Block body;
@@ -271,7 +292,7 @@ struct Conditional: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Iteration: Node
+struct Iteration: Statement
 {
        NodePtr<Node> init_statement;
        NodePtr<Expression> condition;
@@ -282,7 +303,7 @@ struct Iteration: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Passthrough: Node
+struct Passthrough: Statement
 {
        NodePtr<Expression> subscript;
 
@@ -290,7 +311,7 @@ struct Passthrough: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Return: Node
+struct Return: Statement
 {
        NodePtr<Expression> expression;
 
@@ -298,7 +319,7 @@ struct Return: Node
        virtual void visit(NodeVisitor &);
 };
 
-struct Jump: Node
+struct Jump: Statement
 {
        std::string keyword;
 
@@ -321,6 +342,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 &) { }
@@ -372,6 +394,7 @@ struct Stage
        std::map<std::string, VariableDeclaration *> out_variables;
        std::map<std::string, unsigned> locations;
        Version required_version;
+       std::vector<const Extension *> required_extensions;
 
        Stage(StageType);
 };
@@ -388,4 +411,6 @@ struct Module
 } // namespace GL
 } // namespace Msp
 
+#pragma pop_macro("interface")
+
 #endif