]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/validate.h
Use default member initializers for simple types
[libs/gl.git] / source / glsl / validate.h
index 7f8339f678adf71e17418ee26eff983f9c36fc23..52ae136bb61da6053f425cd1d70cc2ad87231be9 100644 (file)
@@ -15,10 +15,10 @@ messages. */
 class Validator: protected TraversingVisitor
 {
 protected:
-       Stage *stage;
-       Node *last_provoker;
+       Stage *stage = 0;
+       Node *last_provoker = 0;
 
-       Validator();
+       Validator() = default;
 
        void diagnose(Node &, Node &, Diagnostic::Severity, const std::string &);
        void diagnose(Node &n, Diagnostic::Severity s, const std::string &m) { diagnose(n, n, s, m); }
@@ -39,14 +39,12 @@ private:
                FUNCTION
        };
 
-       ScopeType scope;
-       InterfaceLayout *iface_layout;
-       InterfaceBlock *iface_block;
-       VariableDeclaration *variable;
+       ScopeType scope = GLOBAL;
+       InterfaceLayout *iface_layout = 0;
+       InterfaceBlock *iface_block = 0;
+       VariableDeclaration *variable = 0;
 
 public:
-       DeclarationValidator();
-
        void apply(Stage &s) { stage = &s; s.content.visit(*this); }
 
 private:
@@ -72,11 +70,9 @@ private:
        std::map<Block *, BlockDeclarationMap> declarations;
        std::map<std::string, InterfaceBlock *> interface_blocks;
        std::map<std::string, FunctionDeclaration *> overloaded_functions;
-       bool anonymous_block;
+       bool anonymous_block = false;
 
 public:
-       IdentifierValidator();
-
        void apply(Stage &s) { stage = &s; s.content.visit(*this); }
 
 private:
@@ -117,14 +113,15 @@ is indicated by a null result type. */
 class ExpressionValidator: private Validator
 {
 private:
-       FunctionDeclaration *current_function;
+       FunctionDeclaration *current_function = 0;
+       bool constant_expression = false;
 
 public:
-       ExpressionValidator();
-
        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 &);
@@ -132,9 +129,30 @@ 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 = true;
+
+public:
+       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. */
@@ -160,15 +178,13 @@ class GlobalInterfaceValidator: private Validator
 private:
        struct Uniform
        {
-               Node *node;
-               TypeDeclaration *type;
+               Node *node = 0;
+               TypeDeclaration *type = 0;
                std::string name;
-               int location;
-               unsigned loc_count;
-               int desc_set;
-               int bind_point;
-
-               Uniform(): node(0), type(0), location(-1), loc_count(1), desc_set(0), bind_point(-1) { }
+               int location = -1;
+               unsigned loc_count = 1;
+               int desc_set = 0;
+               int bind_point = -1;
        };
 
        std::list<Uniform> uniforms;