<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 10/07/2012 11:37 PM, Richard Smith
wrote:<br>
</div>
<blockquote
cite="mid:CAOfiQqnW_Y=YdJKWD0G3OEazsOd5fa4yhn4Tg-ySD6pm587Ogg@mail.gmail.com"
type="cite">
<meta http-equiv="Context-Type" content="text/html;
charset=ISO-8859-1">
On Sun, Oct 7, 2012 at 2:17 PM, Grzegorz Jablonski <span
dir="ltr"><<a moz-do-not-send="true"
href="mailto:grzejabl@gmail.com" target="_blank">grzejabl@gmail.com</a>></span>
wrote:<br>
<div class="gmail_quote">
<blockquote class="gmail_quote">
Hi,<br>
<br>
there is a bug <a moz-do-not-send="true"
href="http://llvm.org/bugs/show_bug.cgi?id=11806"
target="_blank">http://llvm.org/bugs/show_bug.cgi?id=11806</a>
about -ast-print not being production quality. I am using
clang to rewrite C++ source. Is anyone else using clang in
that way? Some comments on the bug pages suggest, that nobody
is using this feature.<br>
</blockquote>
<div><br>
</div>
<div>Yes, various people use Clang to rewrite C++ source, but
mainly not by pretty-printing. Instead, targeted rewrites are
performed on the original source file in each place that needs
to be changed (see the Rewriter class). This has the advantage
of preserving source formatting, comments, macros, header
inclusions, etc. Generally speaking, pretty-printing isn't a
good way to perform rewrites if you want to produce code for a
person to maintain, because it loses all this information.
Also, since the AST is intended to be essentially immutable,
if you want to perform rewrites you are likely to find it
easier to perform them textually rather than writing a pass to
build a rewritten AST.</div>
<div><br>
</div>
<br>
</div>
</blockquote>
My work is based on the Scout project:<br>
<br>
<a class="moz-txt-link-freetext" href="https://fusionforge.zih.tu-dresden.de/scm/viewvc.php?root=hicfd&view=rev">https://fusionforge.zih.tu-dresden.de/scm/viewvc.php?root=hicfd&view=rev</a><br>
<br>
They have provided quite extensive AST rewrite facilities, including
cloning of the subtrees, and their approach seems quite elegant to
me. They use a hybrid approach - they use pretty printing on the
modified functions, the rest is copied from the original. It is a
pity, that it is not possible to clone all kinds of AST nodes.<br>
<br>
-- <br>
Grzegorz<br>
</body>
</html>