1 #ifndef MSP_GL_SL_REFLECT_H_
2 #define MSP_GL_SL_REFLECT_H_
10 /** Compares two types for equality. Struct types are compared recursively. */
11 class TypeComparer: private NodeVisitor
19 static unsigned next_tag;
24 bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; }
27 void compare(Node &, Node &);
30 virtual void visit(Literal &);
31 virtual void visit(VariableReference &);
32 virtual void visit(BasicTypeDeclaration &);
33 virtual void visit(ImageTypeDeclaration &);
34 virtual void visit(StructDeclaration &);
35 virtual void visit(VariableDeclaration &);
38 /** Determines the number of interface locations required by a variable. */
39 class LocationCounter: private NodeVisitor
47 unsigned apply(VariableDeclaration &v) { v.visit(*this); return r_count; }
50 virtual void visit(BasicTypeDeclaration &);
51 virtual void visit(ImageTypeDeclaration &);
52 virtual void visit(StructDeclaration &);
53 virtual void visit(VariableDeclaration &);
56 /** Determines the size and alignment of a variable or a type, in bytes. */
57 class MemoryRequirementsCalculator: private NodeVisitor
66 Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { }
74 Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); }
75 Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); }
78 virtual void visit(BasicTypeDeclaration &);
79 virtual void visit(StructDeclaration &);
80 virtual void visit(VariableDeclaration &);
83 /** Collects dependencies of a function. This includes global variables,
84 interface blocks, other functions and types. */
85 class DependencyCollector: private TraversingVisitor
88 std::set<Node *> dependencies;
89 std::set<Node *> locals;
90 std::set<FunctionDeclaration *> visited_functions;
93 std::set<Node *> apply(FunctionDeclaration &);
96 virtual void visit(VariableReference &);
97 virtual void visit(InterfaceBlockReference &);
98 virtual void visit(FunctionCall &);
99 virtual void visit(VariableDeclaration &);
100 virtual void visit(FunctionDeclaration &);