]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/validate.h
Validate return types of overloaded functions
[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         std::map<std::string, FunctionDeclaration *> overloaded_functions;
52         bool anonymous_block;
53
54 public:
55         DeclarationValidator();
56
57         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
58
59 private:
60         void multiple_definition(const std::string &, Statement &, Statement &);
61         Statement *find_definition(const std::string &);
62         void check_definition(const std::string &, Statement &);
63         void record_definition(const std::string &, Statement &);
64
65         virtual void visit(TypeDeclaration &);
66         virtual void visit(BasicTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
67         virtual void visit(ImageTypeDeclaration &t) { visit(static_cast<TypeDeclaration &>(t)); }
68         virtual void visit(StructDeclaration &);
69         virtual void visit(VariableDeclaration &);
70         virtual void visit(InterfaceBlock &);
71         virtual void visit(FunctionDeclaration &);
72 };
73
74 class ReferenceValidator: private Validator
75 {
76 public:
77         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
78
79 private:
80         virtual void visit(BasicTypeDeclaration &);
81         virtual void visit(ImageTypeDeclaration &);
82         virtual void visit(VariableReference &);
83         virtual void visit(MemberAccess &);
84         virtual void visit(InterfaceBlockReference &);
85         virtual void visit(VariableDeclaration &);
86         virtual void visit(InterfaceBlock &);
87         virtual void visit(FunctionDeclaration &);
88 };
89
90 class ExpressionValidator: private Validator
91 {
92 public:
93         void apply(Stage &s) { stage = &s; s.content.visit(*this); }
94
95 private:
96         virtual void visit(Swizzle &);
97         virtual void visit(UnaryExpression &);
98         virtual void visit(BinaryExpression &);
99         virtual void visit(Assignment &);
100         virtual void visit(VariableDeclaration &);
101 };
102
103 } // namespace SL
104 } // namespace GL
105 } // namespace Msp
106
107 #endif