1 #ifndef MSP_GL_SL_VALIDATE_H_
2 #define MSP_GL_SL_VALIDATE_H_
6 #include "glsl_error.h"
13 class Validator: protected TraversingVisitor
21 void diagnose(Node &, Node &, Diagnostic::Severity, const std::string &);
22 void diagnose(Node &n, Diagnostic::Severity s, const std::string &m) { diagnose(n, n, s, m); }
23 void error(Node &n, const std::string &m) { diagnose(n, Diagnostic::ERR, m); }
24 void add_info(Node &, const std::string &);
27 class DeclarationValidator: private Validator
40 InterfaceLayout *iface_layout;
41 InterfaceBlock *iface_block;
42 VariableDeclaration *variable;
45 DeclarationValidator();
47 void apply(Stage &s) { stage = &s; s.content.visit(*this); }
50 static const char *describe_variable(ScopeType);
52 virtual void visit(Layout &);
53 virtual void visit(InterfaceLayout &);
54 virtual void visit(BasicTypeDeclaration &);
55 virtual void visit(ImageTypeDeclaration &);
56 virtual void visit(StructDeclaration &);
57 virtual void visit(VariableDeclaration &);
58 virtual void visit(InterfaceBlock &);
59 virtual void visit(FunctionDeclaration &);
62 class IdentifierValidator: private Validator
65 typedef std::map<std::string, Statement *> BlockDeclarationMap;
67 std::map<Block *, BlockDeclarationMap> declarations;
68 std::map<std::string, InterfaceBlock *> interface_blocks;
69 std::map<std::string, FunctionDeclaration *> overloaded_functions;
73 IdentifierValidator();
75 void apply(Stage &s) { stage = &s; s.content.visit(*this); }
78 void multiple_definition(const std::string &, Statement &, Statement &);
79 Statement *find_definition(const std::string &);
80 void check_definition(const std::string &, Statement &);
81 void record_definition(const std::string &, Statement &);
83 virtual void visit(TypeDeclaration &);
84 virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
85 virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
86 virtual void visit(StructDeclaration &);
87 virtual void visit(VariableDeclaration &);
88 virtual void visit(InterfaceBlock &);
89 virtual void visit(FunctionDeclaration &);
92 class ReferenceValidator: private Validator
95 void apply(Stage &s) { stage = &s; s.content.visit(*this); }
98 virtual void visit(BasicTypeDeclaration &);
99 virtual void visit(ImageTypeDeclaration &);
100 virtual void visit(VariableReference &);
101 virtual void visit(MemberAccess &);
102 virtual void visit(InterfaceBlockReference &);
103 virtual void visit(FunctionCall &);
104 virtual void visit(VariableDeclaration &);
105 virtual void visit(InterfaceBlock &);
106 virtual void visit(FunctionDeclaration &);
109 class ExpressionValidator: private Validator
112 FunctionDeclaration *current_function;
115 ExpressionValidator();
117 void apply(Stage &s) { stage = &s; s.content.visit(*this); }
120 virtual void visit(Swizzle &);
121 virtual void visit(UnaryExpression &);
122 virtual void visit(BinaryExpression &);
123 virtual void visit(Assignment &);
124 virtual void visit(TernaryExpression &);
125 virtual void visit(VariableDeclaration &);
126 virtual void visit(FunctionDeclaration &);
127 virtual void visit(Return &);