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(BasicTypeDeclaration &);
39 virtual void visit(ImageTypeDeclaration &);
40 virtual void visit(StructDeclaration &);
41 virtual void visit(VariableDeclaration &);
44 /** Determines the number of interface locations required by a variable. */
45 class LocationCounter: private NodeVisitor
51 unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; }
54 virtual void visit(BasicTypeDeclaration &);
55 virtual void visit(ImageTypeDeclaration &);
56 virtual void visit(StructDeclaration &);
57 virtual void visit(VariableDeclaration &);
60 /** Determines the size and alignment of a variable or a type, in bytes. */
61 class MemoryRequirementsCalculator: private NodeVisitor
70 Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
74 unsigned r_alignment = 1;
78 Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
79 Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); }
82 virtual void visit(BasicTypeDeclaration &);
83 virtual void visit(StructDeclaration &);
84 virtual void visit(VariableDeclaration &);
87 /** Collects dependencies of a function. This includes global variables,
88 interface blocks, other functions and types. */
89 class DependencyCollector: private TraversingVisitor
92 std::set<Node *> dependencies;
93 std::set<Node *> locals;
94 std::set<FunctionDeclaration *> visited_functions;
97 std::set<Node *> apply(FunctionDeclaration &);
100 virtual void visit(VariableReference &);
101 virtual void visit(FunctionCall &);
102 virtual void visit(VariableDeclaration &);
103 virtual void visit(FunctionDeclaration &);
106 class AssignmentCollector: private TraversingVisitor
109 bool assignment_target = false;
110 std::set<Node *> assigned_variables;
113 std::set<Node *> apply(Node &);
116 virtual void visit(VariableReference &);
117 virtual void visit(UnaryExpression &);
118 virtual void visit(BinaryExpression &);
119 virtual void visit(Assignment &);