X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=cf0cca9612e92132e9a89f16471f788c8f7d00a1;hb=ab5f2e6f1ddd35f8f117460530d76c0ba0c9bc87;hp=98777ae9b0541f97af5b4156a7725235d9cb24d6;hpb=947bb7477205c038aa1804b84452cddd2108550a;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 98777ae9..cf0cca96 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -114,41 +114,11 @@ void TraversingVisitor::visit(Return &ret) } -BlockModifier::BlockModifier(): - remove_node(false) -{ } - -void BlockModifier::flatten_block(Block &block) -{ - insert_nodes.insert(insert_nodes.end(), block.body.begin(), block.body.end()); - remove_node = true; -} - -void BlockModifier::apply_and_increment(Block &block, NodeList::iterator &i) -{ - block.body.insert(i, insert_nodes.begin(), insert_nodes.end()); - insert_nodes.clear(); - - if(remove_node) - block.body.erase(i++); - else - ++i; - remove_node = false; -} - -void BlockModifier::visit(Block &block) -{ - for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) - { - (*i)->visit(*this); - apply_and_increment(block, i); - } -} - - NodeRemover::NodeRemover(): stage(0), - to_remove(0) + to_remove(0), + anonymous(false), + recursive_remove(false) { } void NodeRemover::apply(Stage &s, const set &tr) @@ -158,8 +128,16 @@ void NodeRemover::apply(Stage &s, const set &tr) visit(s.content); } +void NodeRemover::remove_variable(map &vars, VariableDeclaration &decl) +{ + map::iterator i = vars.find(decl.name); + if(i!=vars.end() && i->second==&decl) + vars.erase(i); +} + void NodeRemover::visit(Block &block) { + blocks.push_back(&block); for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) { (*i)->visit(*this); @@ -168,14 +146,24 @@ 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); } void NodeRemover::visit(VariableDeclaration &var) { - if(to_remove->count(&var)) + if(recursive_remove || to_remove->count(&var)) { - stage->in_variables.erase(var.name); - stage->out_variables.erase(var.name); + 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); stage->locations.erase(var.name); if(var.linked_declaration) var.linked_declaration->linked_declaration = 0; @@ -184,6 +172,13 @@ void NodeRemover::visit(VariableDeclaration &var) var.init_expression = 0; } +void NodeRemover::visit(InterfaceBlock &iface) +{ + SetFlag set_anon(anonymous); + SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface)); + TraversingVisitor::visit(iface); +} + void NodeRemover::visit(Iteration &iter) { if(to_remove->count(iter.init_statement.get()))