X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fvisitor.cpp;h=ebcedb71242cc883bd2ef7b7c58ac6783867a19a;hb=041ba4b1acd55337239c5ce24cc310118c621206;hp=c27de11892607ec627e1a6bf7022e2aa267e0023;hpb=f08bd843fbe63a0bf5bcbc21308f2751d08f00c1;p=libs%2Fgl.git diff --git a/source/glsl/visitor.cpp b/source/glsl/visitor.cpp index c27de118..ebcedb71 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) @@ -43,6 +37,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 +76,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 +104,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) @@ -134,10 +135,11 @@ 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); } @@ -154,17 +156,17 @@ void NodeRemover::visit(Block &block) } } -void NodeRemover::visit(StructDeclaration &strct) +void NodeRemover::visit(TypeDeclaration &type) { - if(to_remove->count(&strct)) - current_block->types.erase(strct.name); + if(to_remove->count(&type)) + remove_from_map(stage->types, type.name, type); } void NodeRemover::visit(VariableDeclaration &var) { if(recursive_remove || to_remove->count(&var)) { - remove_variable(current_block->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; @@ -176,11 +178,22 @@ void NodeRemover::visit(VariableDeclaration &var) void NodeRemover::visit(InterfaceBlock &iface) { if(to_remove->count(&iface)) - current_block->interfaces.erase(&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); + } 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); + TraversingVisitor::visit(func); +} + void NodeRemover::visit(Iteration &iter) { if(to_remove->count(iter.init_statement.get())) @@ -188,6 +201,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