]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
Record location information in all syntax nodes
[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(StructDeclaration &);
45         virtual void visit(VariableDeclaration &);
46         virtual void visit(InterfaceBlock &);
47         virtual void visit(FunctionDeclaration &);
48 };
49
50 } // namespace SL
51 } // namespace GL
52 } // namespace Msp
53
54 #endif