X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=9bbd4914b1a0a289caa3c48a3504fa6c79e0c11d;hb=518f751d385b733adbf43fe4056403740709edec;hp=051d92f6adfc1e48f9117a32797d3004f9759e10;hpb=bd8816692056230c36504dcccd76c6946dff47b1;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index 051d92f6..9bbd4914 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -158,7 +158,7 @@ void NodeRemover::visit(Block &block) void NodeRemover::visit(StructDeclaration &strct) { if(to_remove->count(&strct)) - remove_from_map(current_block->types, strct.name, strct); + remove_from_map(stage->types, strct.name, strct); } void NodeRemover::visit(VariableDeclaration &var) @@ -178,14 +178,21 @@ void NodeRemover::visit(InterfaceBlock &iface) { if(to_remove->count(&iface)) { - remove_from_map(current_block->interfaces, iface.name, iface); + remove_from_map(stage->interface_blocks, iface.name, iface); if(!iface.instance_name.empty()) - remove_from_map(current_block->interfaces, iface.instance_name, iface); + remove_from_map(stage->interface_blocks, iface.instance_name, iface); } SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface)); TraversingVisitor::visit(iface); } +void NodeRemover::visit(FunctionDeclaration &func) +{ + if(to_remove->count(&func)) + remove_from_map(stage->functions, func.name+func.signature, func); + TraversingVisitor::visit(func); +} + void NodeRemover::visit(Iteration &iter) { if(to_remove->count(iter.init_statement.get())) @@ -193,6 +200,39 @@ void NodeRemover::visit(Iteration &iter) TraversingVisitor::visit(iter); } + +NodeReorderer::NodeReorderer(): + reorder_before(0), + to_reorder(0) +{ } + +void NodeReorderer::apply(Stage &stage, Node &before, const set &tr) +{ + reorder_before = &before; + to_reorder = &tr; + stage.content.visit(*this); +} + +void NodeReorderer::visit(Block &block) +{ + NodeList::iterator insert_point = block.body.end(); + for(NodeList::iterator i=block.body.begin(); i!=block.body.end(); ) + { + (*i)->visit(*this); + if(insert_point!=block.body.end() && to_reorder->count(i->get())) + { + NodeList::iterator j = i++; + block.body.splice(insert_point, block.body, j); + } + else + { + if(i->get()==reorder_before) + insert_point = i; + ++i; + } + } +} + } // namespace SL } // namespace GL } // namespace Msp