]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/syntax.h
Resolve the return types of functions
[libs/gl.git] / source / glsl / syntax.h
index 682a0f5aeeaa2246b01226df25536a23a91d9c7a..0379a91146c17c3cbb02680717bea4036bcfb83b 100644 (file)
@@ -8,6 +8,7 @@
 #include <vector>
 #include <msp/core/refptr.h>
 #include "features.h"
+#include "glsl_error.h"
 #include "sourcemap.h"
 
 #pragma push_macro("interface")
@@ -30,7 +31,8 @@ struct Operator
        enum Associativity
        {
                LEFT_TO_RIGHT,
-               RIGHT_TO_LEFT
+               RIGHT_TO_LEFT,
+               ASSOCIATIVE
        };
 
        char token[4];
@@ -53,9 +55,11 @@ struct NodeVisitor;
 
 struct Node
 {
-protected:
-       Node() { }
-       Node(const Node &) { }
+       int source;
+       unsigned line;
+
+       Node(): source(GENERATED_SOURCE), line(1) { }
+       Node(const Node &n): source(n.source), line(n.line) { }
 private:
        Node &operator=(const Node &);
 public:
@@ -104,11 +108,6 @@ struct FunctionDeclaration;
 
 struct Statement: Node
 {
-       int source;
-       unsigned line;
-
-       Statement();
-
        virtual Statement *clone() const = 0;
 };
 
@@ -286,9 +285,66 @@ struct InterfaceLayout: Statement
        virtual void visit(NodeVisitor &);
 };
 
-struct StructDeclaration: Statement
+struct TypeDeclaration: Statement
 {
        std::string name;
+
+       virtual TypeDeclaration *clone() const = 0;
+};
+
+struct BasicTypeDeclaration: TypeDeclaration
+{
+       enum Kind
+       {
+               ALIAS,
+               VOID,
+               BOOL,
+               INT,
+               FLOAT,
+               VECTOR,
+               MATRIX,
+               ARRAY
+       };
+
+       Kind kind;
+       unsigned size;
+       std::string base;
+
+       TypeDeclaration *base_type;
+
+       BasicTypeDeclaration();
+       BasicTypeDeclaration(const BasicTypeDeclaration &);
+
+       virtual BasicTypeDeclaration *clone() const { return new BasicTypeDeclaration(*this); }
+       virtual void visit(NodeVisitor &);
+};
+
+struct ImageTypeDeclaration: TypeDeclaration
+{
+       enum Dimensions
+       {
+               ONE = 1,
+               TWO,
+               THREE,
+               CUBE
+       };
+
+       Dimensions dimensions;
+       bool array;
+       bool sampled;
+       bool shadow;
+       std::string base;
+
+       TypeDeclaration *base_type;
+
+       ImageTypeDeclaration();
+
+       virtual ImageTypeDeclaration *clone() const { return new ImageTypeDeclaration(*this); }
+       virtual void visit(NodeVisitor &);
+};
+
+struct StructDeclaration: TypeDeclaration
+{
        Block members;
 
        StructDeclaration();
@@ -311,7 +367,7 @@ struct VariableDeclaration: Statement
        NodePtr<Expression> array_size;
        NodePtr<Expression> init_expression;
 
-       StructDeclaration *type_declaration;
+       TypeDeclaration *type_declaration;
        VariableDeclaration *linked_declaration;
 
        VariableDeclaration();
@@ -348,6 +404,7 @@ struct FunctionDeclaration: Statement
        Block body;
 
        FunctionDeclaration *definition;
+       TypeDeclaration *return_type_declaration;
 
        FunctionDeclaration();
        FunctionDeclaration(const FunctionDeclaration &);
@@ -368,7 +425,7 @@ struct Conditional: Statement
 
 struct Iteration: Statement
 {
-       NodePtr<Node> init_statement;
+       NodePtr<Statement> init_statement;
        NodePtr<Expression> condition;
        NodePtr<Expression> loop_expression;
        Block body;
@@ -414,11 +471,12 @@ struct Stage
        Type type;
        Stage *previous;
        Block content;
-       std::map<std::string, StructDeclaration *> types;
+       std::map<std::string, TypeDeclaration *> types;
        std::map<std::string, InterfaceBlock *> interface_blocks;
        std::map<std::string, FunctionDeclaration *> functions;
        std::map<std::string, unsigned> locations;
        Features required_features;
+       std::vector<Diagnostic> diagnostics;
 
        Stage(Type);