Rewriting #include in a source-to-source translator

Hi all,

I am writing a source to source translator for C. I have a rewriter
similar to RewriteObjC.cpp.
I am rewriting all header files and hence during the rewriting phase,
I want to change the #includes " .." in the file being translated to
the appropriate translated file.

To accomplish this, my rewriter currently inherits the ASTConsumer and
PPCallbacks. I have defined the function InclusionDirective in my
rewriter. However the callback is not being called when I test it on
a simple test file which has #includes.

What am I doing wrong? Any suggestions?

Thanks,
Santosh

} To accomplish this, my rewriter currently inherits the ASTConsumer
} and PPCallbacks. I have defined the function InclusionDirective in
} my rewriter. However the callback is not being called when I test it
} on a simple test file which has #includes.

Are you registering your callback? (If you could provide your file,
that would definitely be helpful for debugging.)

Here's what we do in include-what-you-use:

I have not registered the callback. What are the steps I need to
follow to create PPCallbacks? Is there any other pass in clang which
does the same?

I see you create an instance of IwyuPPCallbacks with a ast_consumer as
an argument? Does IwyuPPCallbacks just inherit from PPCallabacks? Is
this code available somewhere to look at?

Thanks,
Santosh

} I have not registered the callback. What are the steps I need to
} follow to create PPCallbacks? Is there any other pass in clang which
} does the same?

I'm not sure, exactly -- at Google we have some magic that does some
of the registration work, which I'm not familiar with. But there
might be examples inside clang? Or you could try google code search
for ASTFrontendAction and see if there are any other examples out
there that do this.

I'm hoping to opensource include-what-you-use, and one thing I'll have
to figure out is how to rewrite the driver to not use the google
libraries. But I haven't had a chance to look at that yet.

craig