]> git.tdb.fi Git - libs/gl.git/commitdiff
Fix scoping of GLSL loop variables and function parameters
authorMikko Rasa <tdb@tdb.fi>
Sun, 21 Feb 2021 02:31:35 +0000 (04:31 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 21 Feb 2021 03:02:28 +0000 (05:02 +0200)
TraversingVisitor visits those before the body, so they were being
inserted into the enclosing scope's variables map.

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

index ac16c31f889dce86ae02541121802d84b59a496e..3707e4eda2cabc902397f0d9a344950462f24fcc 100644 (file)
@@ -96,6 +96,9 @@ void VariableResolver::apply(Stage &stage)
 
 void VariableResolver::visit(Block &block)
 {
+       if(!blocks.empty() && blocks.back()==&block)
+               return TraversingVisitor::visit(block);
+
        blocks.push_back(&block);
        block.variables.clear();
        TraversingVisitor::visit(block);
@@ -215,6 +218,22 @@ void VariableResolver::visit(InterfaceBlock &iface)
        TraversingVisitor::visit(iface);
 }
 
+void VariableResolver::visit(FunctionDeclaration &func)
+{
+       blocks.push_back(&func.body);
+       func.body.variables.clear();
+       TraversingVisitor::visit(func);
+       blocks.pop_back();
+}
+
+void VariableResolver::visit(Iteration &iter)
+{
+       blocks.push_back(&iter.body);
+       iter.body.variables.clear();
+       TraversingVisitor::visit(iter);
+       blocks.pop_back();
+}
+
 
 void FunctionResolver::visit(FunctionCall &call)
 {
index ce95754eb4d68f9d28addbbceaa06839988be507..1867cc3e2a7d1a909ec3f59368216f6d69e17d23 100644 (file)
@@ -56,6 +56,8 @@ private:
        virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(InterfaceBlock &);
+       virtual void visit(FunctionDeclaration &);
+       virtual void visit(Iteration &);
        using TraversingVisitor::visit;
 };