[cfe-dev] clang rewriter
Xiaohui Chen
xchen422 at uwo.ca
Mon Dec 22 10:27:25 PST 2014
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/20141222/d4bb0f0a/attachment.html>
More information about the cfe-dev
mailing list