]> git.tdb.fi Git - libs/gl.git/commitdiff
Make it deprecated to redeclare non-builtin variables
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 11:38:26 +0000 (13:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 14:14:07 +0000 (16:14 +0200)
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.

source/glsl/generate.cpp
source/glsl/generate.h

index a2fd3608220e836d268d2310ad1ec6c8915e4550..ce1283721d6f7b0796e40808b3425acd49d49b64 100644 (file)
@@ -219,6 +219,8 @@ bool VariableResolver::apply(Stage &s)
        s.interface_blocks.clear();
        r_any_resolved = false;
        s.content.visit(*this);
+       for(vector<VariableDeclaration *>::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)
index 402f07f480b239e39f76dd7334656337955b2ff3..bfd15a694d8341e6e281a529cc5ae77d185a4274 100644 (file)
@@ -82,6 +82,7 @@ private:
        bool record_target;
        bool r_self_referencing;
        Assignment::Target r_assignment_target;
+       std::vector<VariableDeclaration *> redeclared_builtins;
        std::set<Node *> nodes_to_remove;
 
 public: