]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor block management in NodeRemover
authorMikko Rasa <tdb@tdb.fi>
Tue, 23 Feb 2021 23:15:33 +0000 (01:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 24 Feb 2021 16:25:25 +0000 (18:25 +0200)
This was supposed to go in 9971979 but I forgot.

source/glsl/visitor.cpp
source/glsl/visitor.h

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);
 }
index 86dd79dc10e2432913cf4e89b3201687c797dd54..685bb4eef7a8ee09745f0e026e57687b78491d36 100644 (file)
@@ -86,7 +86,6 @@ class NodeRemover: private TraversingVisitor
 private:
        Stage *stage;
        const std::set<Node *> *to_remove;
-       std::vector<Block *> blocks;
        bool anonymous;
        bool recursive_remove;