Rather than having separate maps in Stage, pull the variables from the
content block's map.
{
formatted = format("Stage %s\n", Stage::get_stage_name(stage.type));
tree.push_back(BRANCH);
{
formatted = format("Stage %s\n", Stage::get_stage_name(stage.type));
tree.push_back(BRANCH);
- for(map<string, VariableDeclaration *>::const_iterator i=stage.in_variables.begin(); i!=stage.in_variables.end(); ++i)
- append(format("Input: %%%d %s %s", get_label(*i->second), i->second->type, i->first));
- for(map<string, VariableDeclaration *>::const_iterator i=stage.out_variables.begin(); i!=stage.out_variables.end(); ++i)
- append(format("Output: %%%d %s %s", get_label(*i->second), i->second->type, i->first));
last_branch();
stage.content.visit(*this);
return formatted;
last_branch();
stage.content.visit(*this);
return formatted;
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));
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));
+ for(std::set<InterfaceBlock *>::const_iterator i=block.interfaces.begin(); i!=block.interfaces.end(); ++i)
+ append(format("Interface %%%d %s %s", get_label(*i->second), i->second->interface, i->second->name));
+
bool labeled_body = (!block.types.empty() || !block.variables.empty());
if(labeled_body)
{
bool labeled_body = (!block.types.empty() || !block.variables.empty());
if(labeled_body)
{
void BlockResolver::visit(InterfaceBlock &iface)
{
void BlockResolver::visit(InterfaceBlock &iface)
{
- iface.members.anonymous = true;
+ current_block->interfaces.insert(&iface);
TraversingVisitor::visit(iface);
}
TraversingVisitor::visit(iface);
}
type = 0;
for(Block *block=current_block; block; block=next_block(*block))
{
type = 0;
for(Block *block=current_block; block; block=next_block(*block))
{
- map<string, VariableDeclaration *>::iterator j = block->variables.find(var.name);
- if(j!=block->variables.end())
+ map<string, VariableDeclaration *>::iterator i = block->variables.find(var.name);
+ if(i!=block->variables.end())
+ var.declaration = i->second;
+ else
+ {
+ const set<InterfaceBlock *> &ifaces = block->interfaces;
+ for(set<InterfaceBlock *>::const_iterator j=ifaces.begin(); (!var.declaration && j!=ifaces.end()); ++j)
+ {
+ i = (*j)->members.variables.find(var.name);
+ if(i!=(*j)->members.variables.end())
+ var.declaration = i->second;
+ }
+ }
+
+ if(var.declaration)
- var.declaration = j->second;
- type = j->second->type_declaration;
+ type = var.declaration->type_declaration;
TraversingVisitor::visit(var);
current_block->variables[var.name] = &var;
TraversingVisitor::visit(var);
current_block->variables[var.name] = &var;
- if(current_block->anonymous && current_block->parent)
- current_block->parent->variables[var.name] = &var;
}
void VariableResolver::visit(InterfaceBlock &iface)
}
void VariableResolver::visit(InterfaceBlock &iface)
bool InterfaceGenerator::generate_interface(VariableDeclaration &var, const string &iface, const string &name)
{
bool InterfaceGenerator::generate_interface(VariableDeclaration &var, const string &iface, const string &name)
{
- const map<string, VariableDeclaration *> &stage_vars = (iface=="in" ? stage->in_variables : stage->out_variables);
- if(stage_vars.count(name))
+ if(stage->content.variables.count(name))
return false;
VariableDeclaration* iface_var = new VariableDeclaration;
return false;
VariableDeclaration* iface_var = new VariableDeclaration;
if(iface_var->array)
iface_var->array_size = var.array_size;
if(iface=="in")
if(iface_var->array)
iface_var->array_size = var.array_size;
if(iface=="in")
- iface_var->linked_declaration = &var;
- stage->content.body.insert(iface_insert_point, iface_var);
- SetForScope<Block *> set_block(current_block, &stage->content);
- iface_var->visit(*this);
+ iface_var->linked_declaration = &var;
+ var.linked_declaration = iface_var;
+ stage->content.body.insert(iface_insert_point, iface_var);
+ stage->content.variables[name] = iface_var;
return;
/* Don't pull a variable from previous stage if we just generated an out
interface in this stage */
return;
/* Don't pull a variable from previous stage if we just generated an out
interface in this stage */
- if(stage->out_variables.count(var.name))
+ if(stage->content.variables.count(var.name))
- const map<string, VariableDeclaration *> &prev_out = stage->previous->out_variables;
- map<string, VariableDeclaration *>::const_iterator i = prev_out.find(var.name);
- if(i==prev_out.end())
- i = prev_out.find(in_prefix+var.name);
- if(i!=prev_out.end())
+ const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
+ map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
+ if(i==prev_vars.end() || i->second->interface!="out")
+ i = prev_vars.find(in_prefix+var.name);
+ if(i!=prev_vars.end() && i->second->interface=="out")
{
generate_interface(*i->second, "in", i->second->name);
var.name = i->second->name;
{
generate_interface(*i->second, "in", i->second->name);
var.name = i->second->name;
{
if(var.interface=="out")
{
{
if(var.interface=="out")
{
- if(current_block==&stage->content)
- stage->out_variables[var.name] = &var;
- else if(generate_interface(var, "out", change_prefix(var.name, string())))
+ if(current_block!=&stage->content && generate_interface(var, "out", change_prefix(var.name, string())))
{
nodes_to_remove.insert(&var);
if(var.init_expression)
{
nodes_to_remove.insert(&var);
if(var.init_expression)
}
else if(var.interface=="in")
{
}
else if(var.interface=="in")
{
- stage->in_variables[var.name] = &var;
- if(var.linked_declaration)
- var.linked_declaration->linked_declaration = &var;
- else if(stage->previous)
+ if(!var.linked_declaration && stage->previous)
- const map<string, VariableDeclaration *> &prev_out = stage->previous->out_variables;
- map<string, VariableDeclaration *>::const_iterator i = prev_out.find(var.name);
- if(i!=prev_out.end())
+ const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
+ map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
+ if(i!=prev_vars.end() && i->second->interface=="out")
{
var.linked_declaration = i->second;
i->second->linked_declaration = &var;
{
var.linked_declaration = i->second;
i->second->linked_declaration = &var;
{
vector<VariableDeclaration *> pass_vars;
{
vector<VariableDeclaration *> pass_vars;
- for(map<string, VariableDeclaration *>::const_iterator i=stage->in_variables.begin(); i!=stage->in_variables.end(); ++i)
- pass_vars.push_back(i->second);
+ for(map<string, VariableDeclaration *>::const_iterator i=stage->content.variables.begin(); i!=stage->content.variables.end(); ++i)
+ if(i->second->interface=="in")
+ pass_vars.push_back(i->second);
- const map<string, VariableDeclaration *> &prev_out = stage->previous->out_variables;
- for(map<string, VariableDeclaration *>::const_iterator i=prev_out.begin(); i!=prev_out.end(); ++i)
+ const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
+ for(map<string, VariableDeclaration *>::const_iterator i=prev_vars.begin(); i!=prev_vars.end(); ++i)
{
bool linked = false;
for(vector<VariableDeclaration *>::const_iterator j=pass_vars.begin(); (!linked && j!=pass_vars.end()); ++j)
{
bool linked = false;
for(vector<VariableDeclaration *>::const_iterator j=pass_vars.begin(); (!linked && j!=pass_vars.end()); ++j)
Block::Block():
use_braces(false),
Block::Block():
use_braces(false),
Node(other),
body(other.body),
use_braces(other.use_braces),
Node(other),
body(other.body),
use_braces(other.use_braces),
- anonymous(other.anonymous),
#include <list>
#include <map>
#include <list>
#include <map>
#include <string>
#include <vector>
#include <msp/core/refptr.h>
#include <string>
#include <vector>
#include <msp/core/refptr.h>
struct StructDeclaration;
struct VariableDeclaration;
struct StructDeclaration;
struct VariableDeclaration;
struct FunctionDeclaration;
struct Statement: Node
struct FunctionDeclaration;
struct Statement: Node
{
NodeList<Statement> body;
bool use_braces;
{
NodeList<Statement> body;
bool use_braces;
std::map<std::string, StructDeclaration *> types;
std::map<std::string, VariableDeclaration *> variables;
std::map<std::string, StructDeclaration *> types;
std::map<std::string, VariableDeclaration *> variables;
+ std::set<InterfaceBlock *> interfaces;
Type type;
Stage *previous;
Block content;
Type type;
Stage *previous;
Block content;
- std::map<std::string, VariableDeclaration *> in_variables;
- std::map<std::string, VariableDeclaration *> out_variables;
std::map<std::string, unsigned> locations;
Features required_features;
std::map<std::string, unsigned> locations;
Features required_features;
if(recursive_remove || to_remove->count(&var))
{
remove_variable(current_block->variables, var);
if(recursive_remove || to_remove->count(&var))
{
remove_variable(current_block->variables, var);
- if(current_block->anonymous && current_block->parent)
- remove_variable(current_block->parent->variables, var);
- remove_variable(stage->in_variables, var);
- remove_variable(stage->out_variables, var);
stage->locations.erase(var.name);
if(var.linked_declaration)
var.linked_declaration->linked_declaration = 0;
stage->locations.erase(var.name);
if(var.linked_declaration)
var.linked_declaration->linked_declaration = 0;
void NodeRemover::visit(InterfaceBlock &iface)
{
void NodeRemover::visit(InterfaceBlock &iface)
{
+ if(to_remove->count(&iface))
+ current_block->interfaces.erase(&iface);
SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface));
TraversingVisitor::visit(iface);
}
SetFlag set_recursive(recursive_remove, recursive_remove || to_remove->count(&iface));
TraversingVisitor::visit(iface);
}
private:
Stage *stage;
const std::set<Node *> *to_remove;
private:
Stage *stage;
const std::set<Node *> *to_remove;
bool recursive_remove;
public:
bool recursive_remove;
public: