X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Freflect.h;h=6e6f9d8316bf2c5af1522a03b097bf301c057df6;hb=08d3b5a55fad7439b47fc93d8ba604cbeb7e19ca;hp=9520feb6a924c797ee50b7e8a062dbd7b1f74795;hpb=c701c8787cb19fbb6dc5b0bfae1a94e2b07dd549;p=libs%2Fgl.git diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index 9520feb6..6e6f9d83 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -7,26 +7,34 @@ 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 { private: - Node *first; - Node *second; - unsigned first_tag; - bool r_result; + Node *first = 0; + Node *second = 0; + unsigned first_tag = 0; + bool r_result = false; static unsigned next_tag; public: - TypeComparer(); - bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; } private: void compare(Node &, Node &); template 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 &); @@ -37,11 +45,9 @@ private: class LocationCounter: private NodeVisitor { private: - unsigned r_count; + unsigned r_count = 0; public: - LocationCounter(); - unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; } private: @@ -51,7 +57,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,16 +65,18 @@ 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; - unsigned r_alignment; - int r_offset; + unsigned r_size = 0; + unsigned r_alignment = 1; + int r_offset = -1; 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,15 +91,32 @@ class DependencyCollector: private TraversingVisitor private: std::set dependencies; std::set locals; + std::set visited_functions; public: std::set apply(FunctionDeclaration &); private: virtual void visit(VariableReference &); - virtual void visit(InterfaceBlockReference &); virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); +}; + +class AssignmentCollector: private TraversingVisitor +{ +private: + bool assignment_target = false; + std::set assigned_variables; + +public: + std::set apply(Node &); + +private: + virtual void visit(VariableReference &); + virtual void visit(UnaryExpression &); + virtual void visit(BinaryExpression &); + virtual void visit(Assignment &); }; } // namespace SL