append(text);
}
+ for(std::map<string, FunctionDeclaration *>::const_iterator i=stage.functions.begin(); i!=stage.functions.end(); ++i)
+ append(format("Function: %%%d %s", get_label(*i->second), i->first));
+
last_branch();
stage.content.visit(*this);
return formatted;
}
+void FunctionResolver::apply(Stage &s)
+{
+ stage = &s;
+ s.content.visit(*this);
+}
+
void FunctionResolver::visit(FunctionCall &call)
{
- map<string, vector<FunctionDeclaration *> >::iterator i = functions.find(call.name);
- if(i!=functions.end())
- call.declaration = i->second.back();
+ map<string, FunctionDeclaration *>::iterator i = stage->functions.find(call.name);
+ if(i!=stage->functions.end())
+ call.declaration = i->second;
TraversingVisitor::visit(call);
}
void FunctionResolver::visit(FunctionDeclaration &func)
{
- vector<FunctionDeclaration *> &decls = functions[func.name];
+ FunctionDeclaration *&stage_decl = stage->functions[func.name];
+ vector<FunctionDeclaration *> &decls = declarations[func.name];
if(func.definition==&func)
{
+ stage_decl = &func;
+
for(vector<FunctionDeclaration *>::iterator i=decls.begin(); i!=decls.end(); ++i)
{
(*i)->definition = func.definition;
(*i)->body.body.clear();
}
}
- else if(!decls.empty() && decls.back()->definition)
- func.definition = decls.back()->definition;
+ else
+ {
+ if(!stage_decl)
+ stage_decl = &func;
+
+ func.definition = stage_decl->definition;
+ }
decls.push_back(&func);
TraversingVisitor::visit(func);
{
private:
Stage *stage;
- std::map<std::string, std::vector<FunctionDeclaration *> > functions;
+ std::map<std::string, std::vector<FunctionDeclaration *> > declarations;
public:
void apply(Stage &);
Block content;
std::map<std::string, StructDeclaration *> types;
std::map<std::string, InterfaceBlock *> interface_blocks;
+ std::map<std::string, FunctionDeclaration *> functions;
std::map<std::string, unsigned> locations;
Features required_features;
TraversingVisitor::visit(iface);
}
+void NodeRemover::visit(FunctionDeclaration &func)
+{
+ if(to_remove->count(&func))
+ remove_from_map(stage->functions, func.name+func.signature, func);
+ TraversingVisitor::visit(func);
+}
+
void NodeRemover::visit(Iteration &iter)
{
if(to_remove->count(iter.init_statement.get()))
virtual void visit(StructDeclaration &);
virtual void visit(VariableDeclaration &);
virtual void visit(InterfaceBlock &);
+ virtual void visit(FunctionDeclaration &);
virtual void visit(Iteration &);
};