{
target_block = &tgt_blk;
source_func = &src;
+ remap_prefix = source_func->name;
+
+ 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)
{
r_inlined_statement = 0;
if(!r_inlined_statement)
r_inlined_statement = (*i)->clone();
- SetFlag set_remap(remap_names);
+ SetForScope<unsigned> set_remap(remap_names, 2);
r_inlined_statement->visit(*this);
- tgt_blk.body.insert(ins_pt, r_inlined_statement);
+ inlined.push_back(r_inlined_statement);
}
+ SetForScope<unsigned> set_remap(remap_names, 1);
+ SetForScope<string> set_prefix(remap_prefix, target_func.name);
+ variable_map.clear();
+ target_func.visit(*this);
+
+ tgt_blk.body.insert(ins_pt, inlined.begin(), inlined.end());
+
NodeReorderer().apply(stage, target_func, dependencies);
return r_result_name;
else if(var.declaration)
{
SetFlag set_deps(deps_only);
- dependencies.insert(var.declaration);
+ if(!variable_map.count(var.name))
+ {
+ dependencies.insert(var.declaration);
+ referenced_names.insert(var.name);
+ }
var.declaration->visit(*this);
}
}
{
SetFlag set_deps(deps_only);
dependencies.insert(iface.declaration);
+ referenced_names.insert(iface.name);
iface.declaration->visit(*this);
}
}
void InlineContentInjector::visit(FunctionCall &call)
{
if(!remap_names && call.declaration)
+ {
dependencies.insert(call.declaration);
+ referenced_names.insert(call.name);
+ }
TraversingVisitor::visit(call);
}
{
TraversingVisitor::visit(var);
- if(var.type_declaration)
+ if(remap_names)
+ {
+ if(remap_names==2 || referenced_names.count(var.name))
+ {
+ string mapped_name = get_unused_variable_name(*target_block, var.name, remap_prefix);
+ variable_map[var.name] = &var;
+ var.name = mapped_name;
+ }
+ }
+ else if(var.type_declaration)
{
SetFlag set_deps(deps_only);
dependencies.insert(var.type_declaration);
+ referenced_names.insert(var.type_declaration->name);
var.type_declaration->visit(*this);
}
-
- if(!remap_names && !deps_only)
- {
- RefPtr<VariableDeclaration> inlined_var = var.clone();
- inlined_var->name = get_unused_variable_name(*target_block, var.name, source_func->name);
- r_inlined_statement = inlined_var;
-
- variable_map[var.name] = inlined_var.get();
- }
}
void InlineContentInjector::visit(Return &ret)
{
TraversingVisitor::visit(ret);
- if(ret.expression)
+ if(!remap_names && ret.expression)
{
/* Create a new variable to hold the return value of the inlined
function. */
--- /dev/null
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+layout(location=2) in float size;
+float func()
+{
+ float scale = size*2.0;
+ return scale*scale;
+}
+void main()
+{
+ float size = scale+1.0;
+ float s = func()+1.0;
+ gl_Position = position*size*size*s*s;
+}
+
+/* Expected output: vertex
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+layout(location=2) in float size;
+void main()
+{
+ float _main_size = scale+1.0;
+ float _func_scale = size*2.0;
+ float s = _func_scale*_func_scale+1.0;
+ gl_Position = position*_main_size*_main_size*s*s;
+}
+*/