transform local vars captured in closure as object ref
generated functions should be inside corresponding class/namespace definition