]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.h
Remove unnecessary std:: qualifiers
[libs/gl.git] / source / glsl / validate.h
index 63af3610a3b9a81e7bc3c73921eb6c16c3808964..d38849012e26fd4569919eaff31588fb144c3559 100644 (file)
@@ -10,6 +10,8 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
+/** Base class for validators.  Contains some utilities for adding diagnostic
+messages. */
 class Validator: protected TraversingVisitor
 {
 protected:
@@ -24,6 +26,7 @@ protected:
        void add_info(Node &, const std::string &);
 };
 
+/** Verifies that declarations are valid in isolation. */
 class DeclarationValidator: private Validator
 {
 private:
@@ -59,6 +62,8 @@ private:
        virtual void visit(FunctionDeclaration &);
 };
 
+/** Verifies that identifiers are unique or, in the case of functions, are
+overloaded only in valid ways. */
 class IdentifierValidator: private Validator
 {
 private:
@@ -89,6 +94,7 @@ private:
        virtual void visit(FunctionDeclaration &);
 };
 
+/** Verifies that there are no unresolved references. */
 class ReferenceValidator: private Validator
 {
 public:
@@ -106,10 +112,13 @@ private:
        virtual void visit(FunctionDeclaration &);
 };
 
+/** Verifies that expressions are valid.  In most cases an invalid expression
+is indicated by a null result type. */
 class ExpressionValidator: private Validator
 {
 private:
        FunctionDeclaration *current_function;
+       bool constant_expression;
 
 public:
        ExpressionValidator();
@@ -117,6 +126,8 @@ public:
        void apply(Stage &s) { stage = &s; s.content.visit(*this); }
 
 private:
+       virtual void visit(VariableReference &);
+       virtual void visit(InterfaceBlockReference &);
        virtual void visit(Swizzle &);
        virtual void visit(UnaryExpression &);
        virtual void visit(BinaryExpression &);
@@ -124,9 +135,35 @@ private:
        virtual void visit(TernaryExpression &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
        virtual void visit(Return &);
 };
 
+/** Verifies flow control constructs.  Functions returning non-void must have
+return statements.  Warnings are given about dead code. */
+class FlowControlValidator: private Validator
+{
+private:
+       bool reachable;
+
+public:
+       FlowControlValidator();
+
+       void apply(Stage &s) { stage = &s; s.content.visit(*this); }
+
+private:
+       virtual void visit(Block &);
+       virtual void visit(FunctionDeclaration &);
+       virtual void visit(Conditional &);
+       virtual void visit(Iteration &);
+       virtual void visit(Return &) { reachable = false; }
+       virtual void visit(Jump &) { reachable = false; }
+};
+
+/** Verifies that stage input and output interfaces are valid.  Linked
+variables must have matching types and locations and there must not be any
+overlap in locations. */
 class StageInterfaceValidator: private Validator
 {
 private:
@@ -142,27 +179,34 @@ private:
        virtual void visit(FunctionDeclaration &) { }
 };
 
+/** Verifies that uniform interfaces are valid across the entire module.
+Variables declared with the same binding must have the same name and type. */
 class GlobalInterfaceValidator: private Validator
 {
 private:
-       struct Binding
+       struct Uniform
        {
                Node *node;
                TypeDeclaration *type;
                std::string name;
+               int location;
+               unsigned loc_count;
+               int desc_set;
+               int bind_point;
 
-               Binding(VariableDeclaration &v): node(&v), type(v.type_declaration), name(v.name) { }
-               Binding(InterfaceBlock &i): node(&i), type(i.struct_declaration), name(i.block_name) { }
+               Uniform(): node(0), type(0), location(-1), loc_count(1), desc_set(0), bind_point(-1) { }
        };
 
-       std::map<unsigned, std::map<unsigned, Binding> > used_bindings;
+       std::list<Uniform> uniforms;
+       std::map<std::string, const Uniform *> used_names;
+       std::map<unsigned, const Uniform *> used_locations;
+       std::map<unsigned, std::map<unsigned, const Uniform *> > used_bindings;
 
 public:
        void apply(Module &);
 
 private:
-       void get_binding(const Layout &, unsigned &, int &);
-       void check_binding(const Layout &, const Binding &);
+       void check_uniform(const Uniform &);
 
        virtual void visit(VariableDeclaration &);
        virtual void visit(InterfaceBlock &);