if(i->used_by.empty())
unused_nodes.insert(i->node);
- for(map<string, InterfaceBlock *>::const_iterator i=s.interface_blocks.begin(); i!=s.interface_blocks.end(); ++i)
- if(i->second->instance_name.empty())
- unused_nodes.insert(i->second);
-
for(BlockVariableMap::const_iterator i=variables.begin(); i!=variables.end(); ++i)
{
if(i->second.output)
void UnusedVariableRemover::visit(InterfaceBlock &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.block_name.compare(0, 3, "gl_")));
- }
+ VariableInfo &var_info = variables[&iface];
+ var_info.output = (iface.interface=="out" && (iface.linked_block || !iface.block_name.compare(0, 3, "gl_")));
}
void UnusedVariableRemover::merge_variables(const BlockVariableMap &other_vars)
source_line(1),
indent(0),
parameter_list(false),
- omit_builtin(false)
+ omit_builtin(false),
+ r_empty_name(false)
{ }
const string &Formatter::apply(Stage &s)
void Formatter::visit(VariableReference &var)
{
append(var.name);
+ r_empty_name = false;
}
void Formatter::visit(InterfaceBlockReference &iface)
{
- append(iface.name);
+ r_empty_name = iface.declaration->instance_name.empty();
+ if(!r_empty_name)
+ append(iface.declaration->instance_name);
}
void Formatter::visit(MemberAccess &memacc)
{
visit_expression(*memacc.left, memacc.oper, false);
- append(format(".%s", memacc.member));
+ if(!r_empty_name)
+ append('.');
+ append(memacc.member);
}
void Formatter::visit(Swizzle &swizzle)
{
const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
map<string, InterfaceBlock *>::const_iterator i = blocks.find(var.name);
+ if(i==blocks.end())
+ {
+ // Look for the variable in anonymous interface blocks.
+ for(i=blocks.begin(); i!=blocks.end(); ++i)
+ if(i->second->instance_name.empty() && i->second->struct_declaration)
+ if(i->second->struct_declaration->members.variables.count(var.name))
+ break;
+ }
+
if(i!=blocks.end())
{
- /* The name refers to an interface block with an instance name rather
- than a variable. Prepare a new syntax tree node accordingly. */
+ /* The name refers to either an interface block with an instance name
+ or a variable declared inside an anonymous interface block. Prepare
+ new syntax tree nodes accordingly. */
InterfaceBlockReference *iface_ref = new InterfaceBlockReference;
iface_ref->source = var.source;
iface_ref->line = var.line;
- iface_ref->name = var.name;
iface_ref->declaration = i->second;
- r_replacement_expr = iface_ref;
- }
- else
- {
- // Look for the variable in anonymous interface blocks.
- for(i=blocks.begin(); (!declaration && i!=blocks.end()); ++i)
- if(i->second->instance_name.empty() && i->second->struct_declaration)
- {
- const map<string, VariableDeclaration *> &iface_vars = i->second->struct_declaration->members.variables;
- map<string, VariableDeclaration *>::const_iterator j = iface_vars.find(var.name);
- if(j!=iface_vars.end())
- declaration = j->second;
- }
+
+ if(i->second->instance_name.empty())
+ {
+ iface_ref->name = format("%s %s", i->second->interface, i->second->block_name);
+
+ MemberAccess *memacc = new MemberAccess;
+ memacc->source = var.source;
+ memacc->line = var.line;
+ memacc->left = iface_ref;
+ memacc->member = var.name;
+
+ r_replacement_expr = memacc;
+ }
+ else
+ {
+ iface_ref->name = var.name;
+ r_replacement_expr = iface_ref;
+ }
}
}