]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/reflect.h
Remove unnecessary std:: qualifiers
[libs/gl.git] / source / glsl / reflect.h
1 #ifndef MSP_GL_SL_REFLECT_H_
2 #define MSP_GL_SL_REFLECT_H_
3
4 #include "visitor.h"
5
6 namespace Msp {
7 namespace GL {
8 namespace SL {
9
10 bool is_scalar(const BasicTypeDeclaration &);
11 bool is_vector_or_matrix(const BasicTypeDeclaration &);
12 BasicTypeDeclaration *get_element_type(BasicTypeDeclaration &);
13 bool can_convert(const BasicTypeDeclaration &, const BasicTypeDeclaration &);
14
15 /** Compares two types for equality.  Struct types are compared recursively. */
16 class TypeComparer: private NodeVisitor
17 {
18 private:
19         Node *first;
20         Node *second;
21         unsigned first_tag;
22         bool r_result;
23
24         static unsigned next_tag;
25
26 public:
27         TypeComparer();
28
29         bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; }
30
31 private:
32         void compare(Node &, Node &);
33         template<typename T>
34         T *multi_visit(T &);
35         virtual void visit(Literal &);
36         virtual void visit(VariableReference &);
37         virtual void visit(BasicTypeDeclaration &);
38         virtual void visit(ImageTypeDeclaration &);
39         virtual void visit(StructDeclaration &);
40         virtual void visit(VariableDeclaration &);
41 };
42
43 /** Determines the number of interface locations required by a variable. */
44 class LocationCounter: private NodeVisitor
45 {
46 private:
47         unsigned r_count;
48
49 public:
50         LocationCounter();
51
52         unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; }
53
54 private:
55         virtual void visit(BasicTypeDeclaration &);
56         virtual void visit(ImageTypeDeclaration &);
57         virtual void visit(StructDeclaration &);
58         virtual void visit(VariableDeclaration &);
59 };
60
61 /** Determines the size and alignment of a variable or a type, in bytes. */
62 class MemoryRequirementsCalculator: private NodeVisitor
63 {
64 public:
65         struct Result
66         {
67                 unsigned size;
68                 unsigned alignment;
69                 unsigned stride;
70
71                 Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
72         };
73 private:
74         unsigned r_size;
75         unsigned r_alignment;
76         int r_offset;
77
78 public:
79         Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
80         Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); }
81
82 private:
83         virtual void visit(BasicTypeDeclaration &);
84         virtual void visit(StructDeclaration &);
85         virtual void visit(VariableDeclaration &);
86 };
87
88 /** Collects dependencies of a function.  This includes global variables,
89 interface blocks, other functions and types. */
90 class DependencyCollector: private TraversingVisitor
91 {
92 private:
93         std::set<Node *> dependencies;
94         std::set<Node *> locals;
95         std::set<FunctionDeclaration *> visited_functions;
96
97 public:
98         std::set<Node *> apply(FunctionDeclaration &);
99
100 private:
101         virtual void visit(VariableReference &);
102         virtual void visit(InterfaceBlockReference &);
103         virtual void visit(FunctionCall &);
104         virtual void visit(VariableDeclaration &);
105         virtual void visit(FunctionDeclaration &);
106 };
107
108 } // namespace SL
109 } // namespace GL
110 } // namespace Msp
111
112 #endif