From: Mikko Rasa Date: Sat, 13 Mar 2021 11:38:26 +0000 (+0200) Subject: Make it deprecated to redeclare non-builtin variables X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d684e9f3007a0113c65c016ceb694eeac56a128c;p=libs%2Fgl.git Make it deprecated to redeclare non-builtin variables This is no longer necessary now that specialization constants are supported. There's some additional rules for declaring builtins too, but I'll get back to those later. --- diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index a2fd3608..ce128372 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -219,6 +219,8 @@ bool VariableResolver::apply(Stage &s) s.interface_blocks.clear(); r_any_resolved = false; s.content.visit(*this); + for(vector::const_iterator i=redeclared_builtins.begin(); i!=redeclared_builtins.end(); ++i) + (*i)->source = GENERATED_SOURCE; NodeRemover().apply(s, nodes_to_remove); return r_any_resolved; } @@ -461,6 +463,12 @@ void VariableResolver::visit(VariableDeclaration &var) ptr = &var; else if(!current_block->parent && ptr->interface==var.interface && ptr->type==var.type) { + if(ptr->source==BUILTIN_SOURCE) + redeclared_builtins.push_back(&var); + else + stage->diagnostics.push_back(Diagnostic(Diagnostic::WARN, var.source, var.line, + format("Redeclaring non-builtin variable '%s' is deprecated", var.name))); + if(var.init_expression) ptr->init_expression = var.init_expression; if(var.layout) diff --git a/source/glsl/generate.h b/source/glsl/generate.h index 402f07f4..bfd15a69 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -82,6 +82,7 @@ private: bool record_target; bool r_self_referencing; Assignment::Target r_assignment_target; + std::vector redeclared_builtins; std::set nodes_to_remove; public: