[cfe-dev] clang rewriter

Manuel Klimek klimek at google.com
Wed Jan 7 03:32:15 PST 2015


You'd use the Rewriter to modify the source buffers, and then use that
information to overlay the files and re-parse the translation unit.

On Mon Dec 22 2014 at 7:27:26 PM Xiaohui Chen <xchen422 at uwo.ca> wrote:

> Citing from the link below:
>
> " It is pretty much the same as editing the AST directly. You can do all
> the source editing in memory in a single tool, *and* do the compile step on
> the changed source from the same tool; no need to write anything to disk
> (in fact, the rewriting tools all have the source in memory before they
> edit the files on disk). "
>
> i think this is what i want. but i can not find any related APIs to do
> this job. Could any one point this out for me?
>
>
> To present my question again:
> i already have the AST for the following code:
> {
>         .......       // A
>         .......       //  B
> }
>
> For instance, i intend to insert Decl "int var"(say C) between A and B, i
> want to rebuild the AST, so
> i can get a new AST presenting the following code:
>
> {
>         .......       // A
>        int var;    // C
>         .......       //  B
> }
>
> i will do other transformation based on this new AST.
>
> Sincerely
> hui
>
> On 12/22/14, *mobi phil * <mobi at mobiphil.com> wrote:
>
> Hi,
>> thanks for your reply.
>> since the AST is immutable, what did you mean by saying "rebuild the AST
>> with the rewritten code "?
>>
>> do you mean i should save the modified code to a ".c" file and re-parse
>> it again?
>>
>> or there are some APIs i can use to insert a node into the AST without
>> re-parse the file?
>>
>>
> did not try it myself but according to Manuel (link below), you do not
> need to save the file to disk, you can re-compile (thus re-build the AST)
> from the buffer where you applied the rewrites
>
> check this one
> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-December/040616.html
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150107/d4a6d2e1/attachment.html>


More information about the cfe-dev mailing list