[cfe-dev] source to source transformation and includes

Benjamin Orgogozo benjamin.orgogozo at normalesup.org
Tue Aug 23 08:36:28 PDT 2011


Hello,

I try to do source to source transformation: for that I decided (but
maybe I'm wrong) to write a plugin with an ASTConsumer and use a
rewriter to insert text. This works well when I have one file.

When there are includes in the file, it becomes a bit more tricky, at
least for me... Since I do source-to-source transformation, I create a
new file in the same directory as the original one and output the
rewriter buffers.
When I have includes, I can't create a new file in the same directory as
the original one since this file may be installed in a /usr/include or
somewhere else where the programmer has no write access. That's why I
decided that I wanted to write all the rewriten code in a unique new
file.

I though that I could just use the rewriter, and, in
HandleTranslationUnit, parse the whole file, look for includes and
replace includes with rewrite buffers when there is actually one. The
problem is that I don't know how to check that a rewrite buffers comes
from a given included file. If I have a rewrite buffer of an file
included in the file included in the main file, I don't have the name of
the intermediate include file...

Do you have any idea of how to handle this problem?

For me, source to source transformation is really not a good idea: I
would simply like to modify the ast and continue the compilation process
but I read somewhere that TreeTransform was not really a good choice for
that so I'm stuck with my source to source transformation I guess...

Any comment, pointer, or even answer to tell me that I'm not clear
enough would be more than welcomed.

Thanks a lot,

-- 
 Benjamin Orgogozo



More information about the cfe-dev mailing list