]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
Check that variable references refer do declared variables
[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(Node &, Diagnostic::Severity, const std::string &);
21         void error(Node &n, const std::string &m) { diagnose(n, 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         std::map<std::string, InterfaceBlock *> interface_blocks;
31         bool anonymous_block;
32
33 public:
34         DeclarationValidator();
35
36         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
37
38 private:
39         void multiple_definition(const std::string &, Statement &, Statement &);
40         Statement *find_definition(const std::string &);
41         void check_definition(const std::string &, Statement &);
42         void record_definition(const std::string &, Statement &);
43
44         virtual void visit(TypeDeclaration &);
45         virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
46         virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
47         virtual void visit(StructDeclaration &);
48         virtual void visit(VariableDeclaration &);
49         virtual void visit(InterfaceBlock &);
50         virtual void visit(FunctionDeclaration &);
51 };
52
53 class ReferenceValidator: private Validator
54 {
55 public:
56         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
57
58 private:
59         virtual void visit(VariableReference &);
60         virtual void visit(InterfaceBlockReference &);
61         virtual void visit(VariableDeclaration &);
62 };
63
64 } // namespace SL
65 } // namespace GL
66 } // namespace Msp
67
68 #endif