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
24 static unsigned next_tag;
29 bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; }
32 void compare(Node &, Node &);
35 virtual void visit(Literal &);
36 virtual void visit(VariableReference &);
37 virtual void visit(UnaryExpression &);
38 virtual void visit(BinaryExpression &);
39 virtual void visit(TernaryExpression &);
40 virtual void visit(BasicTypeDeclaration &);
41 virtual void visit(ImageTypeDeclaration &);
42 virtual void visit(StructDeclaration &);
43 virtual void visit(VariableDeclaration &);
46 /** Determines the number of interface locations required by a variable. */
47 class LocationCounter: private NodeVisitor
55 unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; }
58 virtual void visit(BasicTypeDeclaration &);
59 virtual void visit(ImageTypeDeclaration &);
60 virtual void visit(StructDeclaration &);
61 virtual void visit(VariableDeclaration &);
64 /** Determines the size and alignment of a variable or a type, in bytes. */
65 class MemoryRequirementsCalculator: private NodeVisitor
74 Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
82 Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
83 Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); }
86 virtual void visit(BasicTypeDeclaration &);
87 virtual void visit(StructDeclaration &);
88 virtual void visit(VariableDeclaration &);
91 /** Collects dependencies of a function. This includes global variables,
92 interface blocks, other functions and types. */
93 class DependencyCollector: private TraversingVisitor
96 std::set<Node *> dependencies;
97 std::set<Node *> locals;
98 std::set<FunctionDeclaration *> visited_functions;
101 std::set<Node *> apply(FunctionDeclaration &);
104 virtual void visit(VariableReference &);
105 virtual void visit(InterfaceBlockReference &);
106 virtual void visit(FunctionCall &);
107 virtual void visit(VariableDeclaration &);
108 virtual void visit(FunctionDeclaration &);