X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=dfe2d8d46523a00d83b024f1e13dc261db36703d;hb=f526938b407e061c7424adedc34af4d1ff687f90;hp=d8b1813959f17e4535ea1ea8c60001c22a36d76f;hpb=39141d961e55f56d540b3678f9f8fe94868f2652;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index d8b18139..dfe2d8d4 100644 --- a/source/glsl/visitor.cpp +++ b/source/glsl/visitor.cpp @@ -7,12 +7,6 @@ namespace Msp { namespace GL { namespace SL { -void NodeVisitor::visit(Assignment &assign) -{ - visit(static_cast(assign)); -} - - void TraversingVisitor::visit(Block &block) { if(&block!=current_block) @@ -32,6 +26,11 @@ void TraversingVisitor::visit(MemberAccess &memacc) memacc.left->visit(*this); } +void TraversingVisitor::visit(Swizzle &swizzle) +{ + swizzle.left->visit(*this); +} + void TraversingVisitor::visit(UnaryExpression &unary) { unary.expression->visit(*this); @@ -43,6 +42,12 @@ void TraversingVisitor::visit(BinaryExpression &binary) binary.right->visit(*this); } +void TraversingVisitor::visit(Assignment &assign) +{ + assign.left->visit(*this); + assign.right->visit(*this); +} + void TraversingVisitor::visit(FunctionCall &call) { for(NodeArray::iterator i=call.arguments.begin(); i!=call.arguments.end(); ++i) @@ -76,7 +81,8 @@ void TraversingVisitor::visit(VariableDeclaration &var) void TraversingVisitor::visit(InterfaceBlock &iface) { - iface.members.visit(*this); + if(iface.members) + iface.members->visit(*this); } void TraversingVisitor::visit(FunctionDeclaration &func) @@ -103,9 +109,9 @@ void TraversingVisitor::visit(Iteration &iter) iter.init_statement->visit(*this); if(iter.condition) iter.condition->visit(*this); + iter.body.visit(*this); if(iter.loop_expression) iter.loop_expression->visit(*this); - iter.body.visit(*this); } void TraversingVisitor::visit(Passthrough &pass) @@ -155,10 +161,10 @@ void NodeRemover::visit(Block &block) } } -void NodeRemover::visit(StructDeclaration &strct) +void NodeRemover::visit(TypeDeclaration &type) { - if(to_remove->count(&strct)) - remove_from_map(stage->types, strct.name, strct); + if(to_remove->count(&type)) + remove_from_map(stage->types, type.name, type); } void NodeRemover::visit(VariableDeclaration &var) @@ -178,9 +184,9 @@ void NodeRemover::visit(InterfaceBlock &iface) { if(to_remove->count(&iface)) { - remove_from_map(stage->interface_blocks, iface.name, iface); + remove_from_map(stage->interface_blocks, iface.interface+iface.name, iface); if(!iface.instance_name.empty()) - remove_from_map(stage->interface_blocks, 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); @@ -189,7 +195,7 @@ void NodeRemover::visit(InterfaceBlock &iface) void NodeRemover::visit(FunctionDeclaration &func) { if(to_remove->count(&func)) - remove_from_map(stage->functions, func.name+func.signature, func); + remove_from_map(stage->functions, func.name, func); TraversingVisitor::visit(func); } @@ -200,6 +206,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