From: Mikko Rasa Date: Sun, 21 Feb 2021 02:31:35 +0000 (+0200) Subject: Fix scoping of GLSL loop variables and function parameters X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=488ffa4e7136cb163004befa67f20f553bc82f2e;p=libs%2Fgl.git Fix scoping of GLSL loop variables and function parameters TraversingVisitor visits those before the body, so they were being inserted into the enclosing scope's variables map. --- diff --git a/source/glsl/generate.cpp b/source/glsl/generate.cpp index ac16c31f..3707e4ed 100644 --- a/source/glsl/generate.cpp +++ b/source/glsl/generate.cpp @@ -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) { diff --git a/source/glsl/generate.h b/source/glsl/generate.h index ce95754e..1867cc3e 100644 --- a/source/glsl/generate.h +++ b/source/glsl/generate.h @@ -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; };