Nice, I was guessing that probably TreeTransform could be a solution, now with your answer I'm sure of it, ;)<div><br></div><div>Thank you so much!<br><br><div class="gmail_quote">2012/5/3 Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On May 3, 2012, at 5:14 AM, Jorge Fernández Fabeiro <<a href="mailto:fabeirojorge@gmail.com">fabeirojorge@gmail.com</a>> wrote:<br>
<br>
> Hi!<br>
><br>
> I'm working on a tool that do some source-to-source transformations of an OpenCL kernel mainly using the Rewriter class of the Clang C++ API. However, now I want to do some more complex transformations, and in order to do them I'd need to clone a ForStmt node of an AST and add its copy at the same level of the tree (i.e., I want to create a copy of the node and just after add it to the tree as a sibling node of the original ForStmt).<br>


><br>
> I know that I can do it very simply using the Rewriter class, but the cloning is just the first step of a more complex transformation that can't be done properly if I just rewrite the loop: I want to do some auxiliary transformations in the cloned loop and I need to access to its different parts using the ForStmt functions (GetBody(), GetInc(), GetCond()...).<br>


><br>
> In summary, and returning to the subject of this mail, is it possible to clone a node in an AST using the Clang C++ API?<br>
<br>
</div></div>There is no AST-cloning facility in Clang. The closest thing we have is Sema's TreeTransform, which recursively rebuilds (and re-type checks) nodes. You may be able to build a tweaked clone with it.<br>
<br>
        - Doug<br>
<br>
</blockquote></div><br></div>