[cfe-dev] Need Help Printing Preprocessed Code and Modifying CFG

Kevin Boos kevinaboos at gmail.com
Thu Jul 4 11:45:51 PDT 2013


Oh, I see.  So that's the best way to perform changes -- sort of lexical
edits to the source code itself, not edits to the AST data structures.
Something along the lines of the Rewriter's "RemoveText"  method.

Thanks to you, David, Beatrice, and everyone for your help. I really
appreciate your patience and advice.

Regards,
Kevin
 On Jul 4, 2013, at 10:46 AM, Kevin Boos <kevinaboos at gmail.com> wrote:

Now, once I have access to the AST node, what is a good way to remove it
from the AST? (Ideally in a clean manner)....  I assume this is possible
because I have seen several prior works that use Clang for refactoring, and
many refactoring operations involve deleting or at least
replacing/reordering nodes.


Hi Kevin,

I think David addressed this point pretty well.  If you goal is
source-to-source translation, there is no need to modify the original AST.
 Instead, generate “edits” to the original source by deleting the old
source range and inserting new source code.  You can then emit edits +
original source.  There are several examples of rewriters like this in the
Clang tree, such as the Objective-C rewriter, etc., that take this
approach.  The nice thing about this approach is that it preserves
comments, and essentially all elements of the original source that you
didn’t need to touch.

Ted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130704/549b6d12/attachment.html>


More information about the cfe-dev mailing list