]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
Improve rules for interface blocks
[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         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(VariableDeclaration &);
45         virtual void visit(InterfaceBlock &);
46         virtual void visit(FunctionDeclaration &);
47 };
48
49 } // namespace SL
50 } // namespace GL
51 } // namespace Msp
52
53 #endif