]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.h
Validate GLSL flow control
[libs/gl.git] / source / glsl / validate.h
index fe52ff5aae1878aa0006c2dce8b4c60ca6b4b7af..d38849012e26fd4569919eaff31588fb144c3559 100644 (file)
@@ -140,6 +140,27 @@ private:
        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. */