formatted = format("Stage: %s\n", Stage::get_stage_name(stage.type));
tree.push_back(BRANCH);
append(format("Version: %d.%02d", stage.required_features.glsl_version.major, stage.required_features.glsl_version.minor));
+
+ for(std::map<string, StructDeclaration *>::const_iterator i=stage.types.begin(); i!=stage.types.end(); ++i)
+ append(format("Type: %%%d %s", get_label(*i->second), i->first));
+
+ set<InterfaceBlock *> seen_interfaces;
+ for(std::map<string, InterfaceBlock *>::const_iterator i=stage.interface_blocks.begin(); i!=stage.interface_blocks.end(); ++i)
+ if(seen_interfaces.insert(i->second).second)
+ {
+ string text = format("Interface block: %%%d %s %s", get_label(*i->second), i->second->interface, i->second->name);
+ if(!i->second->instance_name.empty())
+ text += format(" %s", i->second->instance_name);
+ append(text);
+ }
+
last_branch();
stage.content.visit(*this);
return formatted;
append(format("Block %s", (block.use_braces ? "{}" : "(inline)")));
begin_sub();
- for(std::map<string, StructDeclaration *>::const_iterator i=block.types.begin(); i!=block.types.end(); ++i)
- append(format("Type: %%%d %s", get_label(*i->second), i->first));
-
for(std::map<string, VariableDeclaration *>::const_iterator i=block.variables.begin(); i!=block.variables.end(); ++i)
append(format("Variable: %%%d %s %s", get_label(*i->second), i->second->type, i->first));
- set<InterfaceBlock *> seen_interfaces;
- for(std::map<string, InterfaceBlock *>::const_iterator i=block.interfaces.begin(); i!=block.interfaces.end(); ++i)
- if(seen_interfaces.insert(i->second).second)
- {
- string text = format("Interface: %%%d %s %s", get_label(*i->second), i->second->interface, i->second->name);
- if(!i->second->instance_name.empty())
- text += format(" %s", i->second->instance_name);
- append(text);
- }
-
- bool labeled_body = (!block.types.empty() || !block.variables.empty());
+ bool labeled_body = !block.variables.empty();
if(labeled_body)
{
last_branch();
VariableResolver::VariableResolver():
+ stage(0),
builtins(0),
members(0),
record_target(false),
self_referencing(false)
{ }
-void VariableResolver::apply(Stage &stage)
+void VariableResolver::apply(Stage &s)
{
- Stage *builtin_stage = get_builtins(stage.type);
+ stage = &s;
+ Stage *builtin_stage = get_builtins(s.type);
builtins = (builtin_stage ? &builtin_stage->content : 0);
- stage.content.visit(*this);
+ s.content.visit(*this);
}
Block *VariableResolver::next_block(Block &block)
{
var.declaration = 0;
members = 0;
- for(Block *block=current_block; block; block=next_block(*block))
+ for(Block *block=current_block; (!var.declaration && block); block=next_block(*block))
{
map<string, VariableDeclaration *>::iterator i = block->variables.find(var.name);
if(i!=block->variables.end())
var.declaration = i->second;
- else
- {
- const map<string, InterfaceBlock *> &ifaces = block->interfaces;
- for(map<string, InterfaceBlock *>::const_iterator j=ifaces.begin(); (!var.declaration && j!=ifaces.end()); ++j)
- if(j->second->instance_name.empty())
- {
- i = j->second->members.variables.find(var.name);
- if(i!=j->second->members.variables.end())
- var.declaration = i->second;
- }
- }
-
- if(var.declaration)
- {
- if(var.declaration->type_declaration)
- members = &var.declaration->type_declaration->members.variables;
- break;
- }
+ }
- map<string, InterfaceBlock *>::iterator j = block->interfaces.find(var.name);
- if(j!=block->interfaces.end() && j->second->instance_name==var.name)
+ if(var.declaration)
+ {
+ if(var.declaration->type_declaration)
+ members = &var.declaration->type_declaration->members.variables;
+ }
+ else
+ {
+ const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
+ map<string, InterfaceBlock *>::const_iterator i = blocks.find(var.name);
+ if(i!=blocks.end() && i->second->instance_name==var.name)
{
iface_ref = new InterfaceBlockReference;
iface_ref->name = var.name;
- iface_ref->declaration = j->second;
- members = &j->second->members.variables;
- break;
+ iface_ref->declaration = i->second;
+ members = &i->second->members.variables;
+ }
+ else
+ {
+ for(i=blocks.begin(); (!var.declaration && i!=blocks.end()); ++i)
+ if(i->second->instance_name.empty())
+ {
+ map<string, VariableDeclaration *>::iterator j = i->second->members.variables.find(var.name);
+ if(j!=i->second->members.variables.end())
+ var.declaration = j->second;
+ }
}
}
iface.declaration = 0;
for(Block *block=current_block; block; block=next_block(*block))
{
- map<string, InterfaceBlock *>::iterator j = block->interfaces.find(iface.name);
- if(j!=block->interfaces.end())
+ map<string, InterfaceBlock *>::iterator i = stage->interface_blocks.find(iface.name);
+ if(i!=stage->interface_blocks.end())
{
- iface.declaration = j->second;
- members = &j->second->members.variables;
+ iface.declaration = i->second;
+ members = &i->second->members.variables;
break;
}
}
void VariableResolver::visit(StructDeclaration &strct)
{
TraversingVisitor::visit(strct);
- current_block->types[strct.name] = &strct;
+ stage->types[strct.name] = &strct;
}
void VariableResolver::visit(VariableDeclaration &var)
{
- for(Block *block=current_block; block; block=next_block(*block))
- {
- map<string, StructDeclaration *>::iterator j = block->types.find(var.type);
- if(j!=block->types.end())
- var.type_declaration = j->second;
- }
+ map<string, StructDeclaration *>::iterator i = stage->types.find(var.type);
+ if(i!=stage->types.end())
+ var.type_declaration = i->second;
if(!block_interface.empty() && var.interface.empty())
var.interface = block_interface;
{
/* Block names can't be used for any other identifiers so we can put them
in the same map with instance names. */
- current_block->interfaces[iface.name] = &iface;
+ stage->interface_blocks[iface.name] = &iface;
if(!iface.instance_name.empty())
- current_block->interfaces[iface.instance_name] = &iface;
+ stage->interface_blocks[iface.instance_name] = &iface;
SetForScope<string> set_iface(block_interface, iface.interface);
TraversingVisitor::visit(iface);
bool InterfaceGenerator::generate_interface(InterfaceBlock &out_block)
{
- if(stage->content.interfaces.count(out_block.name))
+ if(stage->interface_blocks.count(out_block.name))
return false;
InterfaceBlock *in_block = new InterfaceBlock;
}
iface_target_block->body.insert(iface_insert_point, in_block);
- iface_target_block->interfaces[in_block->name] = in_block;
+ stage->interface_blocks[in_block->name] = in_block;
if(!in_block->instance_name.empty())
- stage->content.interfaces[in_block->instance_name] = in_block;
+ stage->interface_blocks[in_block->instance_name] = in_block;
SetFlag set_scope(function_scope, false);
SetForScope<Block *> set_block(current_block, &stage->content);
return;
}
- const map<string, InterfaceBlock *> &prev_blocks = stage->previous->content.interfaces;
+ const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
map<string, InterfaceBlock *>::const_iterator j = prev_blocks.find(var.name);
if(j!=prev_blocks.end() && j->second->interface=="out" && j->second->instance_name==var.name)
{
{
if(!iface.linked_block && stage->previous)
{
- const map<string, InterfaceBlock *> &prev_blocks = stage->previous->content.interfaces;
+ const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
map<string, InterfaceBlock *>::const_iterator i = prev_blocks.find(iface.name);
if(i!=prev_blocks.end() && i->second->interface=="out" && i->second->name==iface.name)
{