]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
9477b67d70cb7a7ecc9acc38ad81e76d81af1c97
[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         Node *last_provoker;
18
19         Validator();
20
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 &);
25 };
26
27 class TypeValidator: private Validator
28 {
29 private:
30         bool in_struct;
31
32 public:
33         TypeValidator();
34
35         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
36
37 private:
38         virtual void visit(BasicTypeDeclaration &);
39         virtual void visit(ImageTypeDeclaration &);
40         virtual void visit(StructDeclaration &);
41         virtual void visit(VariableDeclaration &);
42 };
43
44 class DeclarationValidator: private Validator
45 {
46 private:
47         typedef std::map<std::string, Statement *> BlockDeclarationMap;
48
49         std::map<Block *, BlockDeclarationMap> declarations;
50         std::map<std::string, InterfaceBlock *> interface_blocks;
51         bool anonymous_block;
52
53 public:
54         DeclarationValidator();
55
56         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
57
58 private:
59         void multiple_definition(const std::string &, Statement &, Statement &);
60         Statement *find_definition(const std::string &);
61         void check_definition(const std::string &, Statement &);
62         void record_definition(const std::string &, Statement &);
63
64         virtual void visit(TypeDeclaration &);
65         virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
66         virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
67         virtual void visit(StructDeclaration &);
68         virtual void visit(VariableDeclaration &);
69         virtual void visit(InterfaceBlock &);
70         virtual void visit(FunctionDeclaration &);
71 };
72
73 class ReferenceValidator: private Validator
74 {
75 public:
76         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
77
78 private:
79         virtual void visit(BasicTypeDeclaration &);
80         virtual void visit(ImageTypeDeclaration &);
81         virtual void visit(VariableReference &);
82         virtual void visit(MemberAccess &);
83         virtual void visit(InterfaceBlockReference &);
84         virtual void visit(VariableDeclaration &);
85         virtual void visit(InterfaceBlock &);
86         virtual void visit(FunctionDeclaration &);
87 };
88
89 class ExpressionValidator: private Validator
90 {
91 public:
92         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
93
94 private:
95         virtual void visit(Swizzle &);
96         virtual void visit(UnaryExpression &);
97         virtual void visit(BinaryExpression &);
98         virtual void visit(Assignment &);
99         virtual void visit(VariableDeclaration &);
100 };
101
102 } // namespace SL
103 } // namespace GL
104 } // namespace Msp
105
106 #endif