]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/visitor.cpp
Refactor block management in NodeRemover
[libs/gl.git] / source / glsl / visitor.cpp
index fe0175c2214f51946fb7805fa866606964e335fc..0577b5ab213f5e67296f87e0285323cc0e361433 100644 (file)
@@ -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<string, VariableDeclaration *> &vars, Vari
 
 void NodeRemover::visit(Block &block)
 {
-       blocks.push_back(&block);
+       SetForScope<Block *> set_block(current_block, &block);
        for(NodeList<Statement>::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);
 }