- SetForScope<Node *> set(aggregate, &iface);
- unused_nodes.insert(&iface);
- TraversingVisitor::visit(iface);
+ if(iface.instance_name.empty())
+ {
+ SetForScope<InterfaceBlock *> set_block(interface_block, &iface);
+ iface.struct_declaration->members.visit(*this);
+ }
+ else
+ {
+ VariableInfo &var_info = variables[&iface];
+ var_info.output = (iface.interface=="out" && (iface.linked_block || !iface.name.compare(0, 3, "gl_")));
+ }
+}
+
+void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars)
+{
+ for(BlockVariableMap::const_iterator i=other_vars.begin(); i!=other_vars.end(); ++i)
+ {
+ BlockVariableMap::iterator j = variables.find(i->first);
+ if(j!=variables.end())
+ {
+ /* The merged blocks started as copies of each other so any common
+ assignments must be in the beginning. */
+ unsigned k = 0;
+ for(; (k<i->second.assignments.size() && k<j->second.assignments.size()); ++k)
+ if(i->second.assignments[k]!=j->second.assignments[k])
+ break;
+
+ // Remaining assignments are unique to each block; merge them.
+ j->second.assignments.insert(j->second.assignments.end(), i->second.assignments.begin()+k, i->second.assignments.end());
+ j->second.referenced |= i->second.referenced;
+ }
+ else
+ variables.insert(*i);
+ }