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