- vector<RefPtr<Statement> > inlined;
- inlined.reserve(src.body.body.size());
- for(NodeList<Statement>::iterator i=src.body.body.begin(); i!=src.body.body.end(); ++i)
+ // Collect all declarations the inlined function depends on.
+ pass = DEPENDS;
+ source_func->visit(*this);
+
+ /* Populate referenced_names from the target function so we can rename
+ variables from the inlined function that would conflict. */
+ pass = REFERENCED;
+ target_func.visit(*this);
+
+ /* Inline and rename passes must be interleaved so used variable names are
+ known when inlining the return statement. */
+ pass = INLINE;
+ staging_block.parent = &tgt_blk;
+ staging_block.variables.clear();
+
+ std::vector<RefPtr<VariableDeclaration> > params;
+ params.reserve(source_func->parameters.size());
+ for(NodeArray<VariableDeclaration>::iterator i=source_func->parameters.begin(); i!=source_func->parameters.end(); ++i)
+ {
+ RefPtr<VariableDeclaration> var = (*i)->clone();
+ var->interface.clear();
+
+ SetForScope<Pass> set_pass(pass, RENAME);
+ var->visit(*this);
+
+ staging_block.body.push_back_nocopy(var);
+ params.push_back(var);
+ }
+
+ for(NodeList<Statement>::iterator i=source_func->body.body.begin(); i!=source_func->body.body.end(); ++i)