[cfe-dev] preferred way to translate and output source code?

Lou Wynn via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 31 08:36:37 PDT 2018

Hi Michael,

I looked into two methods of traversing the AST. One is using libClang 
and its CXCursor, and the other using libTooling. From the document, it 
seems that libClang is good enough to traverse the AST, but when I 
started doing it, it isn't easy to get the content of a node. For 
example, there is no interface that gives the content of a binary 
operator directly. For this reason, I prefer to use the libTooling 
library. Do you have any suggestions about which way to go?


On 10/24/18 12:41 AM, Michael Kruse wrote:
> The Rewriter is useful if you want to make small changes and keep the
> remaining untouched (formatting, whitespace, ...). If you target a
> different language, you probably do not want/need to preserve
> anything, so a recursive traversal is the right thing to do. It also
> saves you from having to handle #include and forward declarations,
> which probably do not have the same semantics in your target language.
> "Probably", because there are two language rewriters in clang:
> RewriteObjC/RewriteModernObjC (Objective C -> C) and HTMLRewriter
> (ObjC/C/C++ -> HTML)
> Michael
> Am Di., 23. Okt. 2018 um 03:59 Uhr schrieb Lou Wynn via cfe-dev
> <cfe-dev at lists.llvm.org>:
>> Hi,
>> I'm writing a source to source translation tool which accepts Clang AST and outputs source code of another language. My original plan was to traverse the AST of a translation unit and outputs corresponding source code of the target language, but I've noticed that there is a Rewriter and I'm not sure if the Rewriter works for my purpose.
>> I've just started using Clang AST, and I appreciate any suggestion and example.
>> --
>> Love,
>> Lou
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181031/bd42534a/attachment.html>

More information about the cfe-dev mailing list