X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=051d92f6adfc1e48f9117a32797d3004f9759e10;hb=bd8816692056230c36504dcccd76c6946dff47b1;hp=fe0175c2214f51946fb7805fa866606964e335fc;hpb=14b46ca054f563d3d23073633feafc4a6fcc4e05;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index fe0175c2..051d92f6 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) { } @@ -135,16 +134,17 @@ void NodeRemover::apply(Stage &s, const set &tr) s.content.visit(*this); } -void NodeRemover::remove_variable(map &vars, VariableDeclaration &decl) +template +void NodeRemover::remove_from_map(map &vars, const string &key, T &node) { - map::iterator i = vars.find(decl.name); - if(i!=vars.end() && i->second==&decl) + typename map::iterator i = vars.find(key); + if(i!=vars.end() && i->second==&node) vars.erase(i); } 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,24 +153,19 @@ 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); + remove_from_map(current_block->types, strct.name, strct); } 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(stage->in_variables, var); - remove_variable(stage->out_variables, var); + remove_from_map(current_block->variables, var.name, var); stage->locations.erase(var.name); if(var.linked_declaration) var.linked_declaration->linked_declaration = 0; @@ -181,7 +176,12 @@ void NodeRemover::visit(VariableDeclaration &var) void NodeRemover::visit(InterfaceBlock &iface) { - SetFlag set_anon(anonymous); + if(to_remove->count(&iface)) + { + remove_from_map(current_block->interfaces, iface.name, iface); + if(!iface.instance_name.empty()) + remove_from_map(current_block->interfaces, iface.instance_name, iface); + } SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface)); TraversingVisitor::visit(iface); }