]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
Add basic validation to the GLSL compiler
[libs/gl.git] / source / glsl / validate.h
1 #ifndef MSP_GL_SL_VALIDATE_H_
2 #define MSP_GL_SL_VALIDATE_H_
3
4 #include <string>
5 #include <vector>
6 #include "glsl_error.h"
7 #include "visitor.h"
8
9 namespace Msp {
10 namespace GL {
11 namespace SL {
12
13 class Validator: protected TraversingVisitor
14 {
15 protected:
16         Stage *stage;
17
18         Validator();
19
20         void diagnose(Statement *, Diagnostic::Severity, const std::string &);
21         void error(Statement *s, const std::string &m) { diagnose(s, Diagnostic::ERR, m); }
22 };
23
24 class DeclarationValidator: private Validator
25 {
26 private:
27         typedef std::map<std::string, Statement *> BlockDeclarationMap;
28
29         std::map<Block *, BlockDeclarationMap> declarations;
30         bool anonymous_block;
31
32 public:
33         DeclarationValidator();
34
35         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
36
37 private:
38         Statement *find_definition(const std::string &);
39         void check_definition(const std::string &, Statement &);
40
41         virtual void visit(VariableDeclaration &);
42         virtual void visit(InterfaceBlock &);
43         virtual void visit(FunctionDeclaration &);
44 };
45
46 } // namespace SL
47 } // namespace GL
48 } // namespace Msp
49
50 #endif