I am attempting to use TreeTransform to copy a function, with some modifications to the function calls within that function. I have that part of the transformation working by implementing TransformDecl. However, I am trying to solve an issue where it does not appear that TreeTransform is transforming VarDecls in the old function to the new function. When I try to use a local variable in a function using my TreeTransform, I get the following error (paraphrased):
error: reference to local variable ‘x’ declared in enclosing function ‘f’
note: ‘x’ declared here …
where ‘x’ is a local variable in a function ‘f’ that I’m using my transform on.
My TransformDecl checks if the Decl is the original function decl, and if so, maps it to the new function decl.
I can fix this by creating copies of every VarDecl (in the new function) in TransformDecl, but I would prefer to use the existing functionality. Copying VarDecls without losing information is non-trivial, and I worry that there are other elements of the AST that will have the same problem.
Surely there is a way to have TreeTransform handle this situation already?
Thanks for any suggestions.