]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/visitor.cpp
Improve support for interface blocks
[libs/gl.git] / source / glsl / visitor.cpp
index c27de11892607ec627e1a6bf7022e2aa267e0023..051d92f6adfc1e48f9117a32797d3004f9759e10 100644 (file)
@@ -134,10 +134,11 @@ void NodeRemover::apply(Stage &s, const set<Node *> &tr)
        s.content.visit(*this);
 }
 
-void NodeRemover::remove_variable(map<string, VariableDeclaration *> &vars, VariableDeclaration &decl)
+template<typename T>
+void NodeRemover::remove_from_map(map<string, T *> &vars, const string &key, T &node)
 {
-       map<string, VariableDeclaration *>::iterator i = vars.find(decl.name);
-       if(i!=vars.end() && i->second==&decl)
+       typename map<string, T *>::iterator i = vars.find(key);
+       if(i!=vars.end() && i->second==&node)
                vars.erase(i);
 }
 
@@ -157,14 +158,14 @@ void NodeRemover::visit(Block &block)
 void NodeRemover::visit(StructDeclaration &strct)
 {
        if(to_remove->count(&strct))
-               current_block->types.erase(strct.name);
+               remove_from_map(current_block->types, strct.name, strct);
 }
 
 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,7 +177,11 @@ void NodeRemover::visit(VariableDeclaration &var)
 void NodeRemover::visit(InterfaceBlock &iface)
 {
        if(to_remove->count(&iface))
-               current_block->interfaces.erase(&iface);
+       {
+               remove_from_map(current_block->interfaces, iface.name, iface);
+               if(!iface.instance_name.empty())
+                       remove_from_map(current_block->interfaces, iface.instance_name, iface);
+       }
        SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface));
        TraversingVisitor::visit(iface);
 }