]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/reflect.h
Consider expressions in array sizes when comparing types for equality
[libs/gl.git] / source / glsl / reflect.h
index 9520feb6a924c797ee50b7e8a062dbd7b1f74795..6c00bca8de3d7f5f8dc3372dfd45cc8937b0568f 100644 (file)
@@ -7,6 +7,11 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+bool is_scalar(const BasicTypeDeclaration &);
+bool is_vector_or_matrix(const BasicTypeDeclaration &);
+BasicTypeDeclaration *get_element_type(BasicTypeDeclaration &);
+bool can_convert(const BasicTypeDeclaration &, const BasicTypeDeclaration &);
+
 /** Compares two types for equality.  Struct types are compared recursively. */
 class TypeComparer: private NodeVisitor
 {
@@ -27,6 +32,11 @@ private:
        void compare(Node &, Node &);
        template<typename T>
        T *multi_visit(T &);
+       virtual void visit(Literal &);
+       virtual void visit(VariableReference &);
+       virtual void visit(UnaryExpression &);
+       virtual void visit(BinaryExpression &);
+       virtual void visit(TernaryExpression &);
        virtual void visit(BasicTypeDeclaration &);
        virtual void visit(ImageTypeDeclaration &);
        virtual void visit(StructDeclaration &);
@@ -51,7 +61,7 @@ private:
        virtual void visit(VariableDeclaration &);
 };
 
-/** Determines the size and alignment of a variable, in bytes. */
+/** Determines the size and alignment of a variable or a type, in bytes. */
 class MemoryRequirementsCalculator: private NodeVisitor
 {
 public:
@@ -59,8 +69,9 @@ public:
        {
                unsigned size;
                unsigned alignment;
+               unsigned stride;
 
-               Result(unsigned s, unsigned a): size(s), alignment(a) { }
+               Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
        };
 private:
        unsigned r_size;
@@ -69,6 +80,7 @@ private:
 
 public:
        Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
+       Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); }
 
 private:
        virtual void visit(BasicTypeDeclaration &);
@@ -83,6 +95,7 @@ class DependencyCollector: private TraversingVisitor
 private:
        std::set<Node *> dependencies;
        std::set<Node *> locals;
+       std::set<FunctionDeclaration *> visited_functions;
 
 public:
        std::set<Node *> apply(FunctionDeclaration &);
@@ -92,6 +105,7 @@ private:
        virtual void visit(InterfaceBlockReference &);
        virtual void visit(FunctionCall &);
        virtual void visit(VariableDeclaration &);
+       virtual void visit(FunctionDeclaration &);
 };
 
 } // namespace SL