From: Mikko Rasa Date: Tue, 23 Feb 2021 23:15:33 +0000 (+0200) Subject: Refactor block management in NodeRemover X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=33dcf183c6394b403b340095f0cf6ac58bd8090d;p=libs%2Fgl.git Refactor block management in NodeRemover This was supposed to go in 9971979 but I forgot. --- diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index fe0175c2..0577b5ab 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -124,7 +124,6 @@ void TraversingVisitor::visit(Return &ret) NodeRemover::NodeRemover(): stage(0), to_remove(0), - anonymous(false), recursive_remove(false) { } @@ -144,7 +143,7 @@ void NodeRemover::remove_variable(map &vars, Vari void NodeRemover::visit(Block &block) { - blocks.push_back(&block); + SetForScope set_block(current_block, &block); for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) { (*i)->visit(*this); @@ -153,22 +152,21 @@ void NodeRemover::visit(Block &block) else ++i; } - blocks.pop_back(); } void NodeRemover::visit(StructDeclaration &strct) { if(to_remove->count(&strct)) - blocks.back()->types.erase(strct.name); + current_block->types.erase(strct.name); } void NodeRemover::visit(VariableDeclaration &var) { if(recursive_remove || to_remove->count(&var)) { - remove_variable(blocks.back()->variables, var); - if(anonymous && blocks.size()>1) - remove_variable(blocks[blocks.size()-2]->variables, var); + remove_variable(current_block->variables, var); + if(current_block->anonymous && current_block->parent) + remove_variable(current_block->parent->variables, var); remove_variable(stage->in_variables, var); remove_variable(stage->out_variables, var); stage->locations.erase(var.name); @@ -181,7 +179,6 @@ void NodeRemover::visit(VariableDeclaration &var) void NodeRemover::visit(InterfaceBlock &iface) { - SetFlag set_anon(anonymous); SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface)); TraversingVisitor::visit(iface); } diff --git a/source/glsl/visitor.h b/source/glsl/visitor.h index 86dd79dc..685bb4ee 100644 --- a/source/glsl/visitor.h +++ b/source/glsl/visitor.h @@ -86,7 +86,6 @@ class NodeRemover: private TraversingVisitor private: Stage *stage; const std::set *to_remove; - std::vector blocks; bool anonymous; bool recursive_remove;