X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=265b11d41215da3bae6cebdbfcaa1b92e0919f24;hb=836eeb313874d4f0c406f154ecb0dff366f362c4;hp=98777ae9b0541f97af5b4156a7725235d9cb24d6;hpb=ff8a0248f1a3c0c1f48f670867bc9106c898c55b;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 98777ae9..265b11d4 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -15,6 +15,7 @@ void NodeVisitor::visit(Assignment &assign) void TraversingVisitor::visit(Block &block) { + SetForScope set_block(current_block, &block); for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ++i) (*i)->visit(*this); } @@ -114,41 +115,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 +129,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 +147,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 +173,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()))