[cfe-dev] Source-to-source translation using LibTooling

Antoine Trouve trouve at isit.or.jp
Wed Jan 9 23:44:56 PST 2013


Hello everybody,

I have successfully written a source-to-source translator using LibTooling, and I am now willing to go further and do some source-to-source translation.
However, I can't figure out how to output modified code with LibTooling.

I have used in the past the class "Rewriter", coupled with a "RewriterBuffer" to do this job, but without the LibTooling (I was manipulating "CompilerInstance" object directly).
However, a "RewriterBuffer" requires a file ID (that I used to get from a "SourceManager") to be created, and I don't have access to such information anymore, because I'm calling my tool using "Tool.run" from a custom "FrontEndAction".

I've spotted the example called "loop-convert" in the clang-tools-extra repository, that is using class derived from "RefactoringTool" to do source-to-source transformation. I kind of made sense of this code, but the way it works would require me to change my code deeply in order to fill the so-called replacement list.

Does someone has any experience on this matter in order to give some advices on the best approach I should adopt ?

Best regards,

- Antoine



More information about the cfe-dev mailing list