TraversingVisitor::visit(block);
}
-void DeclarationCombiner::visit(FunctionDeclaration &func)
-{
- vector<FunctionDeclaration *> &decls = functions[func.name];
- if(func.definition)
- {
- for(vector<FunctionDeclaration *>::iterator i=decls.begin(); i!=decls.end(); ++i)
- {
- (*i)->definition = func.definition;
- (*i)->body.body.clear();
- }
- }
- decls.push_back(&func);
-}
-
void DeclarationCombiner::visit(VariableDeclaration &var)
{
VariableDeclaration *&ptr = variables[var.name];
}
+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];
- if(func.definition)
+ 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;
- decls.clear();
- decls.push_back(&func);
+ (*i)->body.body.clear();
+ }
}
- else if(!decls.empty() && decls.back()->definition)
- func.definition = decls.back()->definition;
else
- decls.push_back(&func);
+ {
+ if(!stage_decl)
+ stage_decl = &func;
+
+ func.definition = stage_decl->definition;
+ }
+ decls.push_back(&func);
TraversingVisitor::visit(func);
}