1 #ifndef MSP_GL_SL_REFLECT_H_
2 #define MSP_GL_SL_REFLECT_H_
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 &);
15 /** Compares two types for equality. Struct types are compared recursively. */
16 class TypeComparer: private NodeVisitor
21 unsigned first_tag = 0;
22 bool r_result = false;
24 static unsigned next_tag;
27 bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; }
30 void compare(Node &, Node &);
33 virtual void visit(Literal &);
34 virtual void visit(VariableReference &);
35 virtual void visit(UnaryExpression &);
36 virtual void visit(BinaryExpression &);
37 virtual void visit(TernaryExpression &);
38 virtual void visit(FunctionCall &);
39 virtual void visit(BasicTypeDeclaration &);
40 virtual void visit(ImageTypeDeclaration &);
41 virtual void visit(StructDeclaration &);
42 virtual void visit(VariableDeclaration &);
45 /** Determines the number of interface locations required by a variable. */
46 class LocationCounter: private NodeVisitor
52 unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; }
55 virtual void visit(BasicTypeDeclaration &);
56 virtual void visit(ImageTypeDeclaration &);
57 virtual void visit(StructDeclaration &);
58 virtual void visit(VariableDeclaration &);
61 /** Determines the size and alignment of a variable or a type, in bytes. */
62 class MemoryRequirementsCalculator: private NodeVisitor
71 Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
75 unsigned r_alignment = 1;
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); }
83 virtual void visit(BasicTypeDeclaration &);
84 virtual void visit(StructDeclaration &);
85 virtual void visit(VariableDeclaration &);
88 /** Collects dependencies of a function. This includes global variables,
89 interface blocks, other functions and types. */
90 class DependencyCollector: private TraversingVisitor
93 std::set<Node *> dependencies;
94 std::set<Node *> locals;
95 std::set<FunctionDeclaration *> visited_functions;
98 std::set<Node *> apply(FunctionDeclaration &);
101 virtual void visit(VariableReference &);
102 virtual void visit(FunctionCall &);
103 virtual void visit(VariableDeclaration &);
104 virtual void visit(FunctionDeclaration &);
107 class AssignmentCollector: private TraversingVisitor
110 bool assignment_target = false;
111 std::set<Node *> assigned_variables;
114 std::set<Node *> apply(Node &);
117 virtual void visit(VariableReference &);
118 virtual void visit(UnaryExpression &);
119 virtual void visit(BinaryExpression &);
120 virtual void visit(Assignment &);