X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Fvalidate.h;h=c9a7b736035519e3d3767062e198cb22e5f8ba6b;hp=d38849012e26fd4569919eaff31588fb144c3559;hb=HEAD;hpb=9d9e008291a447b5d192e724e9022180503c8c3e diff --git a/source/glsl/validate.h b/source/glsl/validate.h index d3884901..3166c39b 100644 --- a/source/glsl/validate.h +++ b/source/glsl/validate.h @@ -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,15 +39,18 @@ private: FUNCTION }; - ScopeType scope; - InterfaceLayout *iface_layout; - InterfaceBlock *iface_block; - VariableDeclaration *variable; + Features features; + ScopeType scope = GLOBAL; + InterfaceLayout *iface_layout = 0; + VariableDeclaration *iface_block = 0; + VariableDeclaration *variable = 0; + bool have_input_primitive = false; + bool have_output_primitive = false; + bool have_output_vertex_count = false; + bool have_workgroup_size = false; public: - DeclarationValidator(); - - void apply(Stage &s) { stage = &s; s.content.visit(*this); } + void apply(Stage &, const Features &); private: static const char *describe_variable(ScopeType); @@ -58,7 +61,6 @@ private: virtual void visit(ImageTypeDeclaration &); virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); }; @@ -70,13 +72,11 @@ private: typedef std::map BlockDeclarationMap; std::map declarations; - std::map interface_blocks; + std::map interface_blocks; std::map overloaded_functions; - bool anonymous_block; + bool anonymous_block = false; public: - IdentifierValidator(); - void apply(Stage &s) { stage = &s; s.content.visit(*this); } private: @@ -90,7 +90,6 @@ private: virtual void visit(ImageTypeDeclaration &t) { visit(static_cast(t)); } virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); }; @@ -105,10 +104,8 @@ private: virtual void visit(ImageTypeDeclaration &); virtual void visit(VariableReference &); virtual void visit(MemberAccess &); - virtual void visit(InterfaceBlockReference &); virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &); }; @@ -117,22 +114,28 @@ is indicated by a null result type. */ class ExpressionValidator: private Validator { private: - FunctionDeclaration *current_function; - bool constant_expression; + enum ConstantKind + { + NOT_CONSTANT, + FIXED_CONSTANT, + SPEC_CONSTANT + }; -public: - ExpressionValidator(); + FunctionDeclaration *current_function = 0; + bool in_struct = false; + ConstantKind constant_expression = NOT_CONSTANT; +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 &); virtual void visit(Assignment &); virtual void visit(TernaryExpression &); + virtual void visit(StructDeclaration &); virtual void visit(VariableDeclaration &); virtual void visit(FunctionDeclaration &); virtual void visit(Conditional &); @@ -145,11 +148,9 @@ return statements. Warnings are given about dead code. */ class FlowControlValidator: private Validator { private: - bool reachable; + bool reachable = true; public: - FlowControlValidator(); - void apply(Stage &s) { stage = &s; s.content.visit(*this); } private: @@ -173,8 +174,6 @@ public: void apply(Stage &s) { stage = &s; s.content.visit(*this); } private: - int get_location(const Layout &); - virtual void visit(VariableDeclaration &); virtual void visit(FunctionDeclaration &) { } }; @@ -186,15 +185,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 uniforms; @@ -209,7 +206,6 @@ private: void check_uniform(const Uniform &); virtual void visit(VariableDeclaration &); - virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &) { } };